import {z} from 'zod' export type WorkspaceUpdate = {name?: (string | null) | undefined, icon?: (string | null) | undefined, color?: (string | null) | undefined, default_currency?: (string | null) | undefined, locale?: (string | null) | undefined, timezone?: (string | null) | undefined, tax_jurisdiction?: (string | null) | undefined}; export type PatchApiApiWorkspacesWorkspaceIdArgs = {workspace_id: string, body: WorkspaceUpdate}; export type PatchApiApiWorkspacesWorkspaceIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceRead = z.object({id: z.string(), name: z.string(), kind: z.string(), is_archived: z.boolean(), default_currency: z.string(), locale: z.string().nullable().optional(), timezone: z.string().nullable().optional(), tax_jurisdiction: z.string().nullable().optional(), icon: z.string().nullable().optional(), color: z.string().nullable().optional(), created_at: z.string(), created_by_user_id: z.string().nullable().optional(), managed_by_user_id: z.string().nullable().optional(), role: z.string().nullable().optional(), enabled_modules: z.array(z.string()).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 Workspace * * PATCH /api/workspaces/{workspace_id} */ export const patchApiApiWorkspacesWorkspaceId = async (args: PatchApiApiWorkspacesWorkspaceIdArgs, options: PatchApiApiWorkspacesWorkspaceIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/workspaces/${encodeURIComponent(String(args.workspace_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(workspaceRead, await res.json()) };