import {z} from 'zod' export type Int64Array = Array; export type Template = {can_delete?: boolean | undefined, can_edit?: boolean | undefined, content?: string | undefined, created?: string | undefined, deleted?: boolean | undefined, id?: number | undefined, location_ids?: Int64Array | undefined, title?: string | undefined, updated?: string | undefined, user_id?: number | undefined}; export type PatchApiMessageTemplatesIdArgs = {id: number, body: Template}; export type PatchApiMessageTemplatesIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const int64Array = z.array(z.number().int()); export const template = z.object({can_delete: z.boolean().optional(), can_edit: z.boolean().optional(), content: z.string().optional(), created: z.string().optional(), deleted: z.boolean().optional(), id: z.number().int().optional(), location_ids: int64Array.optional(), title: z.string().optional(), updated: z.string().optional(), user_id: z.number().int().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 }; /** * Update message template by id * * PATCH /message-templates/{id} * * Also accepts auth: API-Key */ export const patchApiMessageTemplatesId = async (args: PatchApiMessageTemplatesIdArgs, options: PatchApiMessageTemplatesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/message-templates/${encodeURIComponent(String(args.id))}${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(template, await res.json()) };