import {z} from 'zod' export type GetApiInboxEmbedsArgs = {status?: ('active' | 'revoked') | undefined, scope_type?: ('project' | 'customer' | 'phone_number') | undefined, scope_id?: string | undefined, assigned_user_id?: string | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiInboxEmbedsOptions = {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 paginationMeta = z.object({page: z.number().int().gte(1), per_page: z.number().int().gte(1), total_pages: z.number().int().gte(0), total_count: z.number().int().gte(0)}); export const inboxEmbedListResponse = z.object({data: z.array(inboxEmbed), meta: paginationMeta}); 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 }; /** * List inbox embeds * * GET /inbox_embeds */ export const getApiInboxEmbeds = async (args: GetApiInboxEmbedsArgs, options?: GetApiInboxEmbedsOptions) => { const {baseUrl = "https://api.kapso.ai/platform/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.scope_type != null) query.append("scope_type", String(args.scope_type)) if (args.scope_id != null) query.append("scope_id", String(args.scope_id)) if (args.assigned_user_id != null) query.append("assigned_user_id", String(args.assigned_user_id)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/inbox_embeds${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(inboxEmbedListResponse, await res.json()) };