import {z} from 'zod' export type PatchedDepartment = {id?: number | undefined, parent_name?: string | undefined, tags?: Array<{[key: string]: unknown}> | undefined, last_modified_at?: string | undefined, active?: boolean | undefined, code?: string | undefined, name?: (string | null) | undefined, display_name?: (string | null) | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, created_at?: string | undefined, customer?: number | undefined, parent?: (number | null) | undefined}; export type PatchApiCoaApiDepartmentIdArgs = {id: number, body: PatchedDepartment}; export type PatchApiCoaApiDepartmentIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const department = z.object({id: z.number().int(), parent_name: z.string(), tags: z.array(z.record(z.string(), z.unknown())), last_modified_at: z.string(), active: z.boolean().optional(), code: z.string().max(250), name: z.string().max(250).nullable(), display_name: z.string().max(600).nullable().optional(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), created_at: z.string(), customer: z.number().int(), parent: z.number().int().nullable().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 }; /** * Partial Update Department * * PATCH /coa/api/department/{id} */ export const patchApiCoaApiDepartmentId = async (args: PatchApiCoaApiDepartmentIdArgs, options?: PatchApiCoaApiDepartmentIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/department/${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(department, await res.json()) };