import {z} from 'zod' export type GetApiCustomersCustomerIdSetupLinksArgs = {status?: ('active' | 'used' | 'expired' | 'revoked') | undefined, created_after?: string | undefined, created_before?: string | undefined, per_page?: number | undefined, page?: number | undefined}; export type GetApiCustomersCustomerIdSetupLinksOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneNumberReference = z.object({id: z.string(), phone_number: z.string(), status: z.string(), area_code: z.string().nullable().optional(), country_iso: z.string(), country_dial_code: z.string(), display_number: z.string().nullable().optional()}); export const setupLink = z.object({id: z.string(), status: z.enum(["active", "used", "expired", "revoked"]), created_at: z.string(), expires_at: z.string().nullable().optional(), url: z.string(), success_redirect_url: z.string().nullable().optional(), failure_redirect_url: z.string().nullable().optional(), allowed_connection_types: z.array(z.enum(["coexistence", "dedicated"])).optional(), meta_billing_mode: z.enum(["customer_managed", "partner_managed"]), theme_config: z.object({primary_color: z.string().optional(), primary_foreground_color: z.string().optional(), background_color: z.string().optional(), text_color: z.string().optional(), muted_text_color: z.string().optional(), card_color: z.string().optional(), muted_color: z.string().optional(), border_color: z.string().optional(), secondary_color: z.string().optional(), secondary_foreground_color: z.string().optional(), destructive_color: z.string().optional(), destructive_foreground_color: z.string().optional()}).nullable().optional(), provision_phone_number: z.boolean().nullable().optional(), phone_number_area_code: z.string().nullable().optional(), phone_number_country_isos: z.array(z.string()).optional(), reconnect_phone_number: z.string().nullable().optional(), language: z.enum(["en", "es", "pt", "hi", "id", "ar", "null"]).nullable().optional(), whatsapp_setup_status: z.enum(["pending", "processing", "completed", "failed"]).optional(), whatsapp_setup_error: z.string().nullable().optional(), provisioned_phone_number: phoneNumberReference.optional()}); 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 setupLinkListResponse = z.object({data: z.array(setupLink), 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 setup links * * GET /customers/{customer_id}/setup_links */ export const getApiCustomersCustomerIdSetupLinks = async (args: GetApiCustomersCustomerIdSetupLinksArgs, options?: GetApiCustomersCustomerIdSetupLinksOptions) => { 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.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customer_id))}/setup_links${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(setupLinkListResponse, await res.json()) };