import {z} from 'zod' export type CreateApiV1OnboardingCasesCaseIdConfirmationArgs = {caseId: string, body: {[key: string]: unknown}}; export type CreateApiV1OnboardingCasesCaseIdConfirmationOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const onboardingCaseStatus = z.enum(["draft", "collecting_information", "ready_for_submission", "submitted", "action_required", "pending_admin_review", "in_review", "approved", "rejected", "failed", "expired"]); export const onboardingFeature = z.enum(["offramp", "onramp_payment_order", "onramp_virtual_account"]); export const customerOnboardingCase = z.object({id: z.string(), businessId: z.string(), customerId: z.string(), providerId: z.string(), subjectType: z.literal("customer"), status: onboardingCaseStatus, mode: z.enum(["api_only", "hosted_only", "hybrid", "manual"]), feature: z.union([onboardingFeature, z.string()]).nullable().optional(), providerReference: z.string().nullable().optional(), routeIntent: z.object({}).nullable().optional(), data: z.object({}).nullable().optional(), hostedSessions: z.array(z.object({})).nullable().optional(), reason: z.string().nullable().optional(), metadata: z.object({}).nullable().optional(), createdAt: z.string(), updatedAt: z.string()}); export const onboardingCaseResponse = z.object({statusCode: z.number().int(), message: z.string(), data: customerOnboardingCase}); 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 }; /** * Submit Customer Onboarding Confirmation * * POST /v1/onboarding/cases/{caseId}/confirmation */ export const createApiV1OnboardingCasesCaseIdConfirmation = async (args: CreateApiV1OnboardingCasesCaseIdConfirmationArgs, options?: CreateApiV1OnboardingCasesCaseIdConfirmationOptions) => { const {baseUrl = "https://api.blockradar.co", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/onboarding/cases/${encodeURIComponent(String(args.caseId))}/confirmation${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(onboardingCaseResponse, await res.json()) };