import {z} from 'zod' export type Id = string; export type ExternalPartyReadOnlyFalse = {key?: number | undefined, value?: string | undefined}; export type ExternalIdentification = string; export type ExternalPartyIdentificationPost = {id?: Id | undefined, externalParty?: ExternalPartyReadOnlyFalse | undefined, externalIdentification?: ExternalIdentification | undefined}; export type CreateApiV2ProvidersProviderIdExternalPartyIdentificationsArgs = {providerId: string, Authorization: string, Accept: string, body: ExternalPartyIdentificationPost}; export type CreateApiV2ProvidersProviderIdExternalPartyIdentificationsOptions = {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 externalPartyReadOnlyTrue = z.object({key: z.number().int().optional(), value: z.string().optional()}); export const externalIdentification = z.string().max(9); export const externalPartyIdentificationPut = z.object({id: id.optional(), externalParty: externalPartyReadOnlyTrue.optional(), externalIdentification: externalIdentification.optional()}); export const createApiV2ProvidersProviderIdExternalPartyIdentificationsResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: externalPartyIdentificationPut.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 }; /** * Add the identification data for an external party for a provider * * POST /v2/providers/{providerId}/ExternalPartyIdentifications */ export const createApiV2ProvidersProviderIdExternalPartyIdentifications = async (args: CreateApiV2ProvidersProviderIdExternalPartyIdentificationsArgs, options?: CreateApiV2ProvidersProviderIdExternalPartyIdentificationsOptions) => { 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))}/ExternalPartyIdentifications${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(createApiV2ProvidersProviderIdExternalPartyIdentificationsResponse, await res.json()) };