import {z} from 'zod' export type GetApiV1EntityEntityIdArgs = {entityId: string}; export type GetApiV1EntityEntityIdOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1EntityEntityIdResponse = z.object({id: z.string(), jurisdiction: z.string(), jurisdiction_id: z.string().nullable(), entity_name: z.string(), entity_type: z.enum(["llc", "corporation", "lp", "llp", "sole_proprietorship", "nonprofit", "general_partnership", "other"]), status: z.enum(["active", "inactive", "dissolved", "suspended", "revoked", "merged", "withdrawn", "unknown"]), good_standing: z.boolean().nullable(), formation_date: z.string().nullable(), registered_agent: z.object({name: z.string(), address: z.object({line1: z.string(), line2: z.string().nullable(), city: z.string(), state: z.string().nullable(), postal_code: z.string().nullable(), country: z.string()}).nullable()}).nullable(), officers: z.array(z.object({name: z.string(), title: z.string(), address: z.object({line1: z.string(), line2: z.string().nullable(), city: z.string(), state: z.string().nullable(), postal_code: z.string().nullable(), country: z.string()}).nullable()})), principal_address: z.object({line1: z.string(), line2: z.string().nullable(), city: z.string(), state: z.string().nullable(), postal_code: z.string().nullable(), country: z.string()}).nullable(), filing_history_summary: z.array(z.object({date: z.string(), type: z.string(), description: z.string().nullable()})), last_verified_at: z.string().nullable(), snapshots: z.number(), created_at: z.string(), updated_at: 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 a cached entity by ID. Returns the most recent verification data for the entity. Entity IDs are returned by POST /v1/verify and POST /v1/search. No credits charged. * * GET /v1/entity/{entityId} */ export const getApiV1EntityEntityId = async (args: GetApiV1EntityEntityIdArgs, options: GetApiV1EntityEntityIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/entity/${encodeURIComponent(String(args.entityId))}${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(getApiV1EntityEntityIdResponse, await res.json()) };