import {z} from 'zod' export type GetApiV1ConfigOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiV1ConfigResponse = z.object({jurisdictions: z.object({stats: z.object({totalJurisdictions: z.number(), usStates: z.number(), countries: z.number()}), supported: z.object({us: z.array(z.object({name: z.string(), code: z.string(), capabilities: z.object({search: z.boolean(), entityLookup: z.boolean(), supportsQuick: z.boolean(), supportsDeep: z.boolean(), availableFields: z.array(z.string())})})), international: z.array(z.object({name: z.string(), code: z.string(), capabilities: z.object({search: z.boolean(), entityLookup: z.boolean(), supportsQuick: z.boolean(), supportsDeep: z.boolean(), availableFields: z.array(z.string())})})), comingSoon: z.array(z.object({name: z.string(), code: z.string()}))})}), checker: z.object({jurisdictions: z.array(z.object({label: z.string(), code: z.string()}))}), pricing: z.object({creditCosts: z.object({quick: z.number(), deep: z.number(), deepForceRefresh: z.number(), search: z.number(), entityHistory: z.number(), entityLookup: z.number()}), freeTier: z.object({credits: z.number(), replenish: z.string(), rateLimit: z.string()}), packages: z.array(z.object({name: z.string(), credits: z.number(), price: z.string(), pricePerCredit: z.string(), highlighted: z.boolean(), badge: z.string().optional()}))}), features: z.object({webhooks: z.boolean(), pagination: z.boolean(), asyncJobs: z.boolean()}), rateLimits: z.object({default: z.number()}), status: z.object({api: z.string(), lastUpdated: z.string()}), legal: z.object({terms_url: z.string(), privacy_url: z.string(), acceptable_use_url: z.string(), version: z.string()}), docs: z.object({openapi: z.string(), interactive: z.string()})}); 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 }; /** * Get public configuration including supported jurisdictions, credit pricing, available features, and API status. No authentication required. Use this to discover supported jurisdictions and understand credit costs before making API calls. * * GET /v1/config */ export const getApiV1Config = async (options: GetApiV1ConfigOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/config${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(getApiV1ConfigResponse, await res.json()) };