import {z} from 'zod' export type CreateApiV1VerifyArgs = {'idempotency-key'?: string | undefined, body: {entity_name: string, jurisdiction: string, entity_type?: ('llc' | 'corporation' | 'lp' | 'llp' | 'sole_proprietorship' | 'nonprofit' | 'general_partnership' | 'other') | undefined, verification_level?: ('quick' | 'deep') | undefined, force_refresh?: boolean | undefined, webhook_url?: string | undefined}}; export type CreateApiV1VerifyOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1VerifyResponse = z.object({status: z.string(), verification_level: z.enum(["quick", "deep"]), full_verification_available: z.boolean(), reason: z.object({code: z.literal("jurisdiction_quick_only"), message: z.string()}).optional(), data: z.unknown(), job_id: z.string().optional(), entity_id: z.string().optional(), cached: z.boolean(), credits_charged: z.number()}); 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 }; /** * Verify a business entity by name in a specific jurisdiction. Returns verification results synchronously if available within timeout, or a job ID for async retrieval via GET /v1/verify/status/:jobId. Charges credits based on tier: quick (1 credit), deep (15 credits), deep + force_refresh (25 credits). The response includes `full_verification_available` indicating whether deep verification is supported for the jurisdiction. When deep is not available, a `reason` object is returned. When webhook_url is provided, the result is delivered as a POST request to that URL once the async job completes, fails, or is refunded. * * POST /v1/verify */ export const createApiV1Verify = async (args: CreateApiV1VerifyArgs, options: CreateApiV1VerifyOptions) => { const {baseUrl, 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 (args['idempotency-key'] != null) headers.set("idempotency-key", String(args['idempotency-key'])) if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/verify${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(createApiV1VerifyResponse, await res.json()) };