import {z} from 'zod' export type IUserCreate = {first_name: string, last_name: string, email: string, is_active?: boolean | undefined, is_superuser?: boolean | undefined, birthdate?: (string | null) | undefined, is_enterprise?: (boolean | null) | undefined, role_id?: (string | null) | undefined, phone?: (string | null) | undefined, state?: (string | null) | undefined, country?: (string | null) | undefined, address?: (string | null) | undefined, active_billing_plan_id?: (string | null) | undefined, next_billing_plan_id?: (string | null) | undefined, stripe_customer_id?: (string | null) | undefined, stripe_subscription_id?: (string | null) | undefined, stripe_subscription_status?: (string | null) | undefined, stripe_has_payment_method?: (boolean | null) | undefined, stripe_card_brand?: (string | null) | undefined, stripe_card_last4?: (string | null) | undefined, is_trial?: (boolean | null) | undefined, used_trial?: (boolean | null) | undefined, is_paying?: (boolean | null) | undefined, stripe_last_payment_date?: (string | null) | undefined, billing_updated_at?: (string | null) | undefined, last_credits_refresh?: (string | null) | undefined, next_credits_refresh?: (string | null) | undefined, tutorial_completed_at?: (string | null) | undefined, password: string}; export type CreateApiApiV1UserCreateLiveAgentArgs = {body: IUserCreate}; export type CreateApiApiV1UserCreateLiveAgentOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iPostResponseBase = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: z.unknown()}); 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 Live Agent * * POST /api/v1/user/create_live_agent * * Also accepts auth: HTTPBearer */ export const createApiApiV1UserCreateLiveAgent = async (args: CreateApiApiV1UserCreateLiveAgentArgs, options: CreateApiApiV1UserCreateLiveAgentOptions) => { 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/user/create_live_agent${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(iPostResponseBase, await res.json()) };