import {z} from 'zod' export type Id = string; export type UserBasicNotNullable = {id?: Id | undefined, initials?: string | undefined, prefix?: (string | null) | undefined, lastName?: string | undefined, formattedName?: string | undefined}; export type WorkflowTriggerMapping = {id?: Id | undefined, trigger?: ({id?: string | undefined, description?: string | undefined}) | undefined, workflowTemplate?: ({id?: string | undefined, description?: string | undefined}) | undefined, createdOn?: string | undefined, createdBy?: UserBasicNotNullable | undefined, lastModifiedOn?: string | undefined, lastModifiedBy?: UserBasicNotNullable | undefined} | null; export type UpdateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdArgs = {workflowTriggerMappingId: string, Authorization: string, Accept: string, body: WorkflowTriggerMapping}; export type UpdateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdOptions = {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 userBasicNotNullable = z.object({id: id.optional(), initials: z.string().max(6).optional(), prefix: z.string().max(10).nullable().optional(), lastName: z.string().max(25).optional(), formattedName: z.string().optional()}); export const workflowTriggerMapping = z.object({id: id.optional(), trigger: z.object({id: z.string().optional(), description: z.string().max(256).optional()}).optional(), workflowTemplate: z.object({id: z.string().optional(), description: z.string().max(256).optional()}).optional(), createdOn: z.string().optional(), createdBy: userBasicNotNullable.optional(), lastModifiedOn: z.string().optional(), lastModifiedBy: userBasicNotNullable.optional()}).nullable(); export const updateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: workflowTriggerMapping.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 }; /** * Edit the details of a workflow trigger mapping record * * PUT /v2/providers/employers/workflowtriggermappings/{workflowTriggerMappingId} */ export const updateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingId = async (args: UpdateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdArgs, options?: UpdateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdOptions) => { 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/employers/workflowtriggermappings/${encodeURIComponent(String(args.workflowTriggerMappingId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2ProvidersEmployersWorkflowtriggermappingsWorkflowTriggerMappingIdResponse, await res.json()) };