import {z} from 'zod' export type Notifications2 = Array<{notificationType?: ({key?: number | undefined, value?: string | undefined}) | undefined, createNumberOfDaysBeforeEvent?: number | undefined, sendMailWhenNotificationIsCreated?: boolean | undefined, receiveDepartmentSignalsOnly?: boolean | undefined, isEnabled?: boolean | undefined}>; export type NotificationSetPatch = {description?: string | undefined, notifications?: Notifications2 | undefined}; export type PatchApiV2ProvidersNotificationsetsNotificationSetIdArgs = {notificationSetId: string, Authorization: string, Accept: string, body: NotificationSetPatch}; export type PatchApiV2ProvidersNotificationsetsNotificationSetIdOptions = {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 notifications2 = z.array(z.object({notificationType: z.object({key: z.number().int().optional(), value: z.string().max(70).optional()}).optional(), createNumberOfDaysBeforeEvent: z.number().int().gte(0).lte(99).optional(), sendMailWhenNotificationIsCreated: z.boolean().optional(), receiveDepartmentSignalsOnly: z.boolean().optional(), isEnabled: z.boolean().optional()})); export const notificationSets = z.object({id: id.optional(), description: z.string().max(50).optional(), numberOfLinkedEmployerUsers: z.number().int().optional(), notifications: notifications2.optional()}); export const patchApiV2ProvidersNotificationsetsNotificationSetIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: notificationSets.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 an notification set * * PATCH /v2/providers/notificationsets/{notificationSetId} */ export const patchApiV2ProvidersNotificationsetsNotificationSetId = async (args: PatchApiV2ProvidersNotificationsetsNotificationSetIdArgs, options?: PatchApiV2ProvidersNotificationsetsNotificationSetIdOptions) => { 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/notificationsets/${encodeURIComponent(String(args.notificationSetId))}${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(patchApiV2ProvidersNotificationsetsNotificationSetIdResponse, await res.json()) };