import {z} from 'zod' export type IBillingPlanCreate = {name: string, description: string, bots_count: number, queries_count: number, words_count: number, voice_seconds: number, premium_support: boolean, default_plan?: (boolean | null) | undefined, remove_branding?: (boolean | null) | undefined, advanced_intents?: (boolean | null) | undefined, auto_intents?: (boolean | null) | undefined, billing_plan_group?: (string | null) | undefined, credits?: {[key: string]: unknown} | undefined, attributes?: {[key: string]: unknown} | undefined, agency_id?: (string | null) | undefined, plan_lookup_key?: (string | null) | undefined}; export type CreateApiApiV1AgencyBillingAgencyIdBillingPlanArgs = {agency_id: string, body: IBillingPlanCreate}; export type CreateApiApiV1AgencyBillingAgencyIdBillingPlanOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iBillingPlanCreate = z.object({name: z.string(), description: z.string(), bots_count: z.number().int(), queries_count: z.number().int(), words_count: z.number().int(), voice_seconds: z.number().int(), premium_support: z.boolean(), default_plan: z.boolean().nullable().optional(), remove_branding: z.boolean().nullable().optional(), advanced_intents: z.boolean().nullable().optional(), auto_intents: z.boolean().nullable().optional(), billing_plan_group: z.string().nullable().optional(), credits: z.record(z.string(), z.unknown()).optional(), attributes: z.record(z.string(), z.unknown()).optional(), agency_id: z.string().nullable().optional(), plan_lookup_key: z.string().nullable().optional()}); export const iPostResponseBaseIBillingPlanCreate = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iBillingPlanCreate.nullable().optional()}); 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 }; /** * Create Agency Billing Plan * * POST /api/v1/agency/billing/{agency_id}/billing_plan * * Also accepts auth: HTTPBearer */ export const createApiApiV1AgencyBillingAgencyIdBillingPlan = async (args: CreateApiApiV1AgencyBillingAgencyIdBillingPlanArgs, options: CreateApiApiV1AgencyBillingAgencyIdBillingPlanOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/agency/billing/${encodeURIComponent(String(args.agency_id))}/billing_plan${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(iPostResponseBaseIBillingPlanCreate, await res.json()) };