import {z} from 'zod' export type InboxEmbedUpdateRequest = {inbox_embed: {name?: (string | null) | undefined, assigned_user_id?: (string | null) | undefined, allowed_origins?: Array | undefined, default_mode?: ('system' | 'light' | 'dark') | undefined, language?: ('en' | 'es') | undefined, expires_at?: (string | null) | undefined}}; export type PatchApiInboxEmbedsInboxEmbedIdArgs = {body: InboxEmbedUpdateRequest}; export type PatchApiInboxEmbedsInboxEmbedIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inboxEmbed = z.object({id: z.string(), name: z.string().nullable().optional(), scope_type: z.enum(["project", "customer", "phone_number"]), scope_id: z.string().nullable().optional(), scope_name: z.string().nullable().optional(), assigned_user_id: z.string().nullable().optional(), assigned_user_name: z.string().nullable().optional(), status: z.enum(["active", "revoked"]), allowed_origins: z.array(z.string()), default_mode: z.enum(["system", "light", "dark"]), language: z.enum(["en", "es"]), expires_at: z.string().nullable().optional(), last_used_at: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const inboxEmbedResponse = z.object({data: inboxEmbed}); 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 inbox embed * * PATCH /inbox_embeds/{inbox_embed_id} */ export const patchApiInboxEmbedsInboxEmbedId = async (args: PatchApiInboxEmbedsInboxEmbedIdArgs, options?: PatchApiInboxEmbedsInboxEmbedIdOptions) => { const {baseUrl = "https://api.kapso.ai/platform/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/inbox_embeds/${encodeURIComponent(String(args.inbox_embed_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(inboxEmbedResponse, await res.json()) };