import {z} from 'zod' export type IntectCountry = {IsSupported?: boolean | undefined, DefaultLanguageId?: number | undefined, ReleaseNoteLink?: string | undefined, GetHelpOnlineLink?: string | undefined, OperatingStatus?: string | undefined, StaticDataId?: number | undefined, Key?: string | undefined, Id?: number | undefined, Name?: string | undefined, Description?: string | undefined, SortKey?: string | undefined}; export type IntectTaxCardType = {EIncomeReference?: number | undefined, AllowTaxRate?: boolean | undefined, AllowDeduction?: boolean | undefined, AllowFreeAmount?: boolean | undefined, RelevantCountries?: Array | undefined, StaticDataId?: number | undefined, Key?: string | undefined, Id?: number | undefined, Name?: string | undefined, Description?: string | undefined, SortKey?: string | undefined}; export type IntectWithholdingMonths = {Months?: number | undefined, RelevantCountries?: Array | undefined, StaticDataId?: number | undefined, Key?: string | undefined, Id?: number | undefined, Name?: string | undefined, Description?: string | undefined, SortKey?: string | undefined}; export type IntectUserTaxInfo = {TaxCardType?: IntectTaxCardType | undefined, IsCurrent?: boolean | undefined, WithholdingMonths?: IntectWithholdingMonths | undefined, HasFullYearWithholding?: boolean | undefined, Id?: number | undefined, ValidFrom?: string | undefined, ValidUntil?: (string | null) | undefined, TaxRate?: (number | null) | undefined, DeductionMonth?: (number | null) | undefined, FreeAmount?: (number | null) | undefined, UserEmploymentId?: number | undefined, IsActive?: boolean | undefined, TaxCardTypeId?: number | undefined, IsDummy?: boolean | undefined, MinimumRate?: (number | null) | undefined, MaximumDeductionMonth?: (number | null) | undefined, MaximumDeductionDay?: (number | null) | undefined, Created?: string | undefined, DeductionWeek?: (number | null) | undefined, DeductionDay?: (number | null) | undefined, IsManual?: boolean | undefined, ParsedFromFileName?: string | undefined, TaxCardRequestId?: (number | null) | undefined, Updated?: string | undefined, TaxCardYear?: (number | null) | undefined, ExternalTaxCardId?: string | undefined, TaxTable?: string | undefined, AdditionalInformation?: string | undefined, WithholdingMonthsId?: (number | null) | undefined, IsPaye?: boolean | undefined}; export type PatchApiApiEmploymentsTaxcardsArgs = {body: IntectUserTaxInfo}; export type PatchApiApiEmploymentsTaxcardsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectCountry = z.object({IsSupported: z.boolean().optional(), DefaultLanguageId: z.number().int().optional(), ReleaseNoteLink: z.string().optional(), GetHelpOnlineLink: z.string().optional(), OperatingStatus: z.string().optional(), StaticDataId: z.number().int().optional(), Key: z.string().optional(), Id: z.number().int().optional(), Name: z.string().optional(), Description: z.string().optional(), SortKey: z.string().optional()}); export const intectTaxCardType = z.object({EIncomeReference: z.number().int().optional(), AllowTaxRate: z.boolean().optional(), AllowDeduction: z.boolean().optional(), AllowFreeAmount: z.boolean().optional(), RelevantCountries: z.array(intectCountry).optional(), StaticDataId: z.number().int().optional(), Key: z.string().optional(), Id: z.number().int().optional(), Name: z.string().optional(), Description: z.string().optional(), SortKey: z.string().optional()}); export const intectWithholdingMonths = z.object({Months: z.number().optional(), RelevantCountries: z.array(intectCountry).optional(), StaticDataId: z.number().int().optional(), Key: z.string().optional(), Id: z.number().int().optional(), Name: z.string().optional(), Description: z.string().optional(), SortKey: z.string().optional()}); export const intectUserTaxInfo = z.object({TaxCardType: intectTaxCardType.optional(), IsCurrent: z.boolean().optional(), WithholdingMonths: intectWithholdingMonths.optional(), HasFullYearWithholding: z.boolean().optional(), Id: z.number().int().optional(), ValidFrom: z.string().optional(), ValidUntil: z.string().nullable().optional(), TaxRate: z.number().nullable().optional(), DeductionMonth: z.number().nullable().optional(), FreeAmount: z.number().nullable().optional(), UserEmploymentId: z.number().int().optional(), IsActive: z.boolean().optional(), TaxCardTypeId: z.number().int().optional(), IsDummy: z.boolean().optional(), MinimumRate: z.number().nullable().optional(), MaximumDeductionMonth: z.number().nullable().optional(), MaximumDeductionDay: z.number().nullable().optional(), Created: z.string().optional(), DeductionWeek: z.number().nullable().optional(), DeductionDay: z.number().nullable().optional(), IsManual: z.boolean().optional(), ParsedFromFileName: z.string().optional(), TaxCardRequestId: z.number().int().nullable().optional(), Updated: z.string().optional(), TaxCardYear: z.number().int().nullable().optional(), ExternalTaxCardId: z.string().optional(), TaxTable: z.string().optional(), AdditionalInformation: z.string().optional(), WithholdingMonthsId: z.number().int().nullable().optional(), IsPaye: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Updates a tax information record. A tax card created manually with a POST call can be edited; the daily and weekly deductions follow the monthly deduction. On a tax card retrieved from the tax authority (E-Income, Altinn) only Active can be changed (GS-7553). In Norway Valid until can be changed too, applied to every section of the tax card, and Type selects which section of the tax card payroll uses, on the tax card payroll uses now (GS-16135). * * PATCH /api/employments/taxcards */ export const patchApiApiEmploymentsTaxcards = async (args: PatchApiApiEmploymentsTaxcardsArgs, options?: PatchApiApiEmploymentsTaxcardsOptions) => { const {baseUrl = "https://api.intect.app", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/employments/taxcards${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(intectUserTaxInfo, await res.json()) };