import {z} from 'zod' export type Id = string; export type EmployerNumber = number; export type CompanyName = string; export type ChamberOfCommerceNumber = string | null; export type EmployerLogo = string | null; export type ProviderLogo = string | null; export type Sbi = {key?: number | undefined, value?: string | undefined, sbiCode?: string | undefined} | null; export type LegalForm = {key?: number | undefined, value?: string | undefined} | null; export type Branch = {key?: number | undefined, value?: string | undefined} | null; export type ProviderSettings = {administrationNumber?: (string | null) | undefined, groupCode?: (number | null) | undefined, parentEmployerForConsolidatedOverviews?: (number | null) | undefined, sendEmailWhenSalarySlipIsAvailable?: boolean | undefined}; export type Contact2 = {name?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, function?: (string | null) | undefined} | null; export type ContactInformation3 = {emailAddress?: (string | null) | undefined, faxNumber?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, website?: (string | null) | undefined} | null; export type Address = {street?: string | undefined, city?: string | undefined, houseNumber?: number | undefined, houseNumberAddition?: (string | null) | undefined, furtherIndication?: ({key?: number | undefined, value?: string | undefined} | null) | undefined, postalCode?: string | undefined, location?: (string | null) | undefined, country?: ({key?: number | undefined, value?: string | undefined, isoCode?: string | undefined}) | undefined, province?: ({key?: (number | null) | undefined, value?: (string | null) | undefined} | null) | undefined}; export type DeviatingPostalAddress = {street?: (string | null) | undefined, city?: string | undefined, houseNumber?: (number | null) | undefined, houseNumberAddition?: (string | null) | undefined, furtherIndication?: ({key?: number | undefined, value?: string | undefined} | null) | undefined, postalCode?: (string | null) | undefined, location?: (string | null) | undefined, country?: ({key?: number | undefined, value?: string | undefined, isoCode?: string | undefined}) | undefined, poBox?: (number | null) | undefined} | null; export type Employer = {id?: Id | undefined, employerNumber?: EmployerNumber | undefined, companyName?: CompanyName | undefined, chamberOfCommerceNumber?: ChamberOfCommerceNumber | undefined, employerLogo?: EmployerLogo | undefined, providerLogo?: ProviderLogo | undefined, sbi?: Sbi | undefined, legalForm?: LegalForm | undefined, branch?: Branch | undefined, providerSettings?: ProviderSettings | undefined, contact?: Contact2 | undefined, contactInformation?: ContactInformation3 | undefined, address?: Address | undefined, deviatingPostalAddress?: DeviatingPostalAddress | undefined}; export type CreateApiV2ProvidersProviderIdEmployersArgs = {providerId: string, Authorization: string, Accept: string, body: Employer}; export type CreateApiV2ProvidersProviderIdEmployersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const version = z.object({obsoleteDate: z.string().nullable().optional(), resourceVersion: z.string().optional()}); export const messageWarning = z.array(z.object({type: z.string().optional(), description: z.string().optional(), id: z.string().nullable().optional(), code: z.number().int().optional(), properties: z.array(z.string()).optional()})); export const id = z.string(); export const employerNumber = z.number().int(); export const companyName = z.string().max(70); export const chamberOfCommerceNumber = z.string().max(35).nullable(); export const employerLogo = z.string().nullable(); export const providerLogo = z.string().nullable(); export const sbi = z.object({key: z.number().int().optional(), value: z.string().max(255).optional(), sbiCode: z.string().max(32).optional()}).nullable(); export const legalForm = z.object({key: z.number().int().optional(), value: z.string().max(50).optional()}).nullable(); export const branch = z.object({key: z.number().int().optional(), value: z.string().max(50).optional()}).nullable(); export const providerSettings = z.object({administrationNumber: z.string().max(15).nullable().optional(), groupCode: z.number().int().nullable().optional(), parentEmployerForConsolidatedOverviews: z.number().int().nullable().optional(), sendEmailWhenSalarySlipIsAvailable: z.boolean().optional()}); export const contact2 = z.object({name: z.string().max(50).nullable().optional(), phoneNumber: z.string().max(15).nullable().optional(), function: z.string().max(50).nullable().optional()}).nullable(); export const contactInformation3 = z.object({emailAddress: z.string().max(255).nullable().optional(), faxNumber: z.string().max(15).nullable().optional(), phoneNumber: z.string().max(15).nullable().optional(), website: z.string().max(255).nullable().optional()}).nullable(); export const address = z.object({street: z.string().max(24).optional(), city: z.string().max(24).optional(), houseNumber: z.number().int().optional(), houseNumberAddition: z.string().max(4).nullable().optional(), furtherIndication: z.object({key: z.number().int().optional(), value: z.string().optional()}).nullable().optional(), postalCode: z.string().max(9).optional(), location: z.string().max(35).nullable().optional(), country: z.object({key: z.number().int().optional(), value: z.string().max(50).optional(), isoCode: z.string().max(2).optional()}).optional(), province: z.object({key: z.number().int().nullable().optional(), value: z.string().max(50).nullable().optional()}).nullable().optional()}); export const deviatingPostalAddress = z.object({street: z.string().max(24).nullable().optional(), city: z.string().max(24).optional(), houseNumber: z.number().int().nullable().optional(), houseNumberAddition: z.string().max(4).nullable().optional(), furtherIndication: z.object({key: z.number().int().optional(), value: z.string().optional()}).nullable().optional(), postalCode: z.string().min(1).max(9).nullable().optional(), location: z.string().max(35).nullable().optional(), country: z.object({key: z.number().int().optional(), value: z.string().max(50).optional(), isoCode: z.string().max(2).optional()}).optional(), poBox: z.number().int().nullable().optional()}).nullable(); export const employer = z.object({id: id.optional(), employerNumber: employerNumber.optional(), companyName: companyName.optional(), chamberOfCommerceNumber: chamberOfCommerceNumber.optional(), employerLogo: employerLogo.optional(), providerLogo: providerLogo.optional(), sbi: sbi.optional(), legalForm: legalForm.optional(), branch: branch.optional(), providerSettings: providerSettings.optional(), contact: contact2.optional(), contactInformation: contactInformation3.optional(), address: address.optional(), deviatingPostalAddress: deviatingPostalAddress.optional()}); export const createApiV2ProvidersProviderIdEmployersResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: employer.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 }; /** * Create an employer * * POST /v2/providers/{providerId}/employers */ export const createApiV2ProvidersProviderIdEmployers = async (args: CreateApiV2ProvidersProviderIdEmployersArgs, options?: CreateApiV2ProvidersProviderIdEmployersOptions) => { const {baseUrl = "https://api.loket.nl", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;version=2018-01-01") headers.set('accept', "application/json;version=2018-01-01") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/providers/${encodeURIComponent(String(args.providerId))}/employers${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV2ProvidersProviderIdEmployersResponse, await res.json()) };