import {z} from 'zod' export type GetApiApiV1PartnerAccountsArgs = {page?: number | undefined, per_page?: number | undefined, search?: string | undefined}; export type GetApiApiV1PartnerAccountsOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PartnerAccountsResponse = z.object({accounts: z.array(z.object({name: z.string(), email: z.string(), phone: z.string(), description: z.string().nullable(), gstin: z.string().nullable(), gst_status: z.string().nullable(), tds_enabled: z.boolean(), tds_percentage: z.number().int(), business_type: z.string(), id: z.string(), auth_id: z.string(), api_id: z.string(), account_type: z.string(), role: z.string(), postpaid: z.boolean(), address: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), timezone: z.string().nullable(), country: z.string(), zip_code: z.string().nullable(), company: z.string(), billing_mode: z.string(), auto_recharge: z.boolean(), cash_credits: z.string(), cps_limit: z.number().int(), concurrent_calls_limit: z.number().int(), base_cps_limit: z.unknown(), base_concurrent_calls_limit: z.unknown(), purchased_cps: z.unknown(), purchased_concurrent_calls: z.unknown(), is_active: z.boolean(), is_verified: z.boolean(), is_trial_account: z.boolean(), enabled: z.boolean(), kyc_status: z.string(), google_id: z.unknown(), referral_code: z.string().nullable(), referral_disabled: z.boolean(), custom_referrer_reward_amount: z.unknown(), custom_referee_reward_amount: z.unknown(), created_at: z.string(), updated_at: z.string(), last_login: z.string().nullable(), pricing_tier_id: z.string(), pricing_tier: z.object({id: z.string(), name: z.string(), currency: z.string(), rate_per_minute: z.number(), streaming_rate_per_minute: z.number(), recording_rate_per_minute: z.number(), whatsapp_voice_rate: z.number(), transcription_rate_per_minute: z.number(), pii_redaction_rate_per_minute: z.number(), charge_non_connected_calls: z.boolean(), non_connected_call_fee: z.number(), did_release_fee: z.number().int(), is_active: z.boolean(), is_default: z.boolean(), partner_id: z.unknown()}), partner_id: z.string(), auto_recharge_config: z.unknown(), resource_uri: z.string(), auth_token: z.string()})), total: z.number().int(), page: z.number().int(), size: z.number().int()}); 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 customer accounts * * GET /api/v1/partner/accounts */ export const getApiApiV1PartnerAccounts = async (args: GetApiApiV1PartnerAccountsArgs, options?: GetApiApiV1PartnerAccountsOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.search != null) query.append("search", String(args.search)) if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/accounts${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(getApiApiV1PartnerAccountsResponse, await res.json()) };