import {z} from 'zod' export type SetupLinkUpdateRequest = {setup_link: {success_redirect_url?: (string | null) | undefined, failure_redirect_url?: (string | null) | undefined, provision_phone_number?: boolean | undefined, phone_number_area_code?: (string | null) | undefined, expires_at?: (string | null) | undefined, status?: ('active' | 'used' | 'expired' | 'revoked') | undefined, allowed_connection_types?: (Array<'coexistence' | 'dedicated'>) | undefined, theme_config?: ({primary_color?: string | undefined, primary_foreground_color?: string | undefined, background_color?: string | undefined, text_color?: string | undefined, muted_text_color?: string | undefined, card_color?: string | undefined, muted_color?: string | undefined, border_color?: string | undefined, secondary_color?: string | undefined, secondary_foreground_color?: string | undefined, destructive_color?: string | undefined, destructive_foreground_color?: string | undefined} | null) | undefined, phone_number_country_isos?: Array | undefined, language?: ('en' | 'es' | 'pt' | 'hi' | 'id' | 'ar' | 'null' | null) | undefined}}; export type PatchApiCustomersCustomerIdSetupLinksSetupLinkIdArgs = {body: SetupLinkUpdateRequest}; export type PatchApiCustomersCustomerIdSetupLinksSetupLinkIdOptions = {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 setupLinkResponse = z.object({data: setupLink}); 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 setup link * * PATCH /customers/{customer_id}/setup_links/{setup_link_id} */ export const patchApiCustomersCustomerIdSetupLinksSetupLinkId = async (args: PatchApiCustomersCustomerIdSetupLinksSetupLinkIdArgs, options?: PatchApiCustomersCustomerIdSetupLinksSetupLinkIdOptions) => { 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(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customer_id))}/setup_links/${encodeURIComponent(String(args.setup_link_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(setupLinkResponse, await res.json()) };