import {z} from 'zod' export type AppSchema = {allowed_origins?: Array | undefined, allowed_scopes?: Array | undefined, client_id?: string | undefined, date_created?: string | undefined, date_modified?: string | undefined, default_user_id?: (string | null) | undefined, description?: (string | null) | undefined, id?: string | undefined, name: string, oauth_client_type?: ('public' | 'confidential' | null) | undefined, redirect_uris?: Array | undefined, system_domain_id?: string | undefined, type?: ('PAT' | 'OAUTH') | undefined, url?: (string | null) | undefined}; export type PatchApiV1AppsAppIdArgs = {'App-ID': string, 'Auth-Token': string, app_id: string, body: AppSchema}; export type PatchApiV1AppsAppIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const appSchema = z.object({allowed_origins: z.array(z.string()).optional(), allowed_scopes: z.array(z.string()).optional(), client_id: z.string().optional(), date_created: z.string().optional(), date_modified: z.string().optional(), default_user_id: z.string().nullable().optional(), description: z.string().nullable().optional(), id: z.string().optional(), name: z.string(), oauth_client_type: z.enum(["public", "confidential"]).nullable().optional(), redirect_uris: z.array(z.string()).optional(), system_domain_id: z.string().optional(), type: z.enum(["PAT", "OAUTH"]).optional(), url: z.string().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 }; /** * Update app * * PATCH /v1/apps/{app_id}/ */ export const patchApiV1AppsAppId = async (args: PatchApiV1AppsAppIdArgs, options: PatchApiV1AppsAppIdOptions) => { 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") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/apps/${encodeURIComponent(String(args.app_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(appSchema, await res.json()) };