import {z} from 'zod' export type UpdateOrganizationDesignRequest = {extraInstructions?: (string | null) | undefined, description?: (string | null) | undefined, name?: string | undefined}; export type PatchApiApiV1OrgDesignsDesignUuidArgs = {designUuid: string, body: UpdateOrganizationDesignRequest}; export type PatchApiApiV1OrgDesignsDesignUuidOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const organizationDesignFileKind = z.enum(["instruction", "css", "font", "image"]); export const apiOrganizationDesignFile = z.object({createdAt: z.string(), sizeBytes: z.number(), contentType: z.string(), filename: z.string(), kind: organizationDesignFileKind, fileUuid: z.string()}); export const apiOrganizationDesign = z.object({files: z.array(apiOrganizationDesignFile), createdByUserUuid: z.string().nullable(), updatedAt: z.string(), createdAt: z.string(), isDefault: z.boolean(), extraInstructions: z.string().nullable(), description: z.string().nullable(), name: z.string(), organizationUuid: z.string(), designUuid: z.string()}); export const apiOrganizationDesignResponse = z.object({results: apiOrganizationDesign, status: z.literal("ok")}); 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 organization design * * PATCH /api/v1/org/designs/{designUuid} */ export const patchApiApiV1OrgDesignsDesignUuid = async (args: PatchApiApiV1OrgDesignsDesignUuidArgs, options: PatchApiApiV1OrgDesignsDesignUuidOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/org/designs/${encodeURIComponent(String(args.designUuid))}${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(apiOrganizationDesignResponse, await res.json()) };