import {z} from 'zod' export type GetApiV2ProvidersEmployersEmployerIdDocumentsArgs = {employerId: string, Authorization: string, Accept: string, filter?: string | undefined, orderBy?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiV2ProvidersEmployersEmployerIdDocumentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const totalSize = z.number().int(); export const pageSize = z.number().int(); export const totalPages = z.number().int(); export const currentPage = z.number().int(); 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 qwoaterDocumentId = z.string(); export const description7 = z.string().min(1).max(250); export const category = z.string().max(4000); export const year3 = z.number().int().gte(1000).lte(9999).nullable(); export const attribute = z.string().max(250).nullable(); export const dateOfSubmission = z.string(); export const dateOfAlert = z.string().nullable(); export const submittedBy = z.string().max(4000).nullable(); export const isReadBy = z.object({provider: z.boolean().optional(), employer: z.boolean().optional(), departmentManager: z.boolean().optional(), employee: z.boolean().optional()}); export const filename = z.string().min(1).max(255); export const qwoaterDirectUrl = z.string().max(1024); export const documentGetObject2 = z.object({qwoaterDocumentId: qwoaterDocumentId.optional(), description: description7.optional(), category: category.optional(), year: year3.optional(), attribute: attribute.optional(), dateOfSubmission: dateOfSubmission.optional(), dateOfAlert: dateOfAlert.optional(), submittedBy: submittedBy.optional(), isReadBy: isReadBy.optional(), filename: filename.optional(), qwoaterDirectUrl: qwoaterDirectUrl.optional()}); export const getApiV2ProvidersEmployersEmployerIdDocumentsResponse = z.object({totalSize: totalSize.optional(), pageSize: pageSize.optional(), totalPages: totalPages.optional(), currentPage: currentPage.optional(), version: version.optional(), messages: messageWarning.optional(), _embedded: z.array(documentGetObject2).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 }; /** * Get a list of employer dossier documents * * GET /v2/providers/employers/{employerId}/documents */ export const getApiV2ProvidersEmployersEmployerIdDocuments = async (args: GetApiV2ProvidersEmployersEmployerIdDocumentsArgs, options?: GetApiV2ProvidersEmployersEmployerIdDocumentsOptions) => { const {baseUrl = "https://api.loket.nl", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/providers/employers/${encodeURIComponent(String(args.employerId))}/documents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2ProvidersEmployersEmployerIdDocumentsResponse, await res.json()) };