import {z} from 'zod' export type Id = string; export type Authorizations = Array<{id?: string | undefined, description?: string | undefined, availableForEmployerUser?: boolean | undefined, isEnabled?: boolean | undefined}>; export type AuthorizationSets = {id?: Id | undefined, description?: string | undefined, authorizations?: Authorizations | undefined}; export type UpdateApiV2ProvidersAuthorizationsetsAuthorizationSetIdArgs = {authorizationSetId: string, Authorization: string, Accept: string, body: AuthorizationSets}; export type UpdateApiV2ProvidersAuthorizationsetsAuthorizationSetIdOptions = {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 authorizations = z.array(z.object({id: z.string().optional(), description: z.string().max(50).optional(), availableForEmployerUser: z.boolean().optional(), isEnabled: z.boolean().optional()})); export const authorizationSets = z.object({id: id.optional(), description: z.string().max(50).optional(), authorizations: authorizations.optional()}); export const updateApiV2ProvidersAuthorizationsetsAuthorizationSetIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: authorizationSets.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 authorizationset * * PUT /v2/providers/authorizationsets/{authorizationSetId} */ export const updateApiV2ProvidersAuthorizationsetsAuthorizationSetId = async (args: UpdateApiV2ProvidersAuthorizationsetsAuthorizationSetIdArgs, options?: UpdateApiV2ProvidersAuthorizationsetsAuthorizationSetIdOptions) => { 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/authorizationsets/${encodeURIComponent(String(args.authorizationSetId))}${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(updateApiV2ProvidersAuthorizationsetsAuthorizationSetIdResponse, await res.json()) };