import {z} from 'zod' export type StateEnum = 'AK' | 'AL' | 'AR' | 'AZ' | 'CA' | 'CO' | 'CT' | 'DE' | 'FL' | 'GA' | 'HI' | 'IA' | 'ID' | 'IL' | 'IN' | 'KS' | 'KY' | 'LA' | 'MA' | 'MD' | 'ME' | 'MI' | 'MN' | 'MO' | 'MS' | 'MT' | 'NC' | 'ND' | 'NE' | 'NH' | 'NJ' | 'NM' | 'NV' | 'NY' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VA' | 'VT' | 'WA' | 'WI' | 'WV' | 'WY'; export type SosReportParameterRequest = {companyName: string, state: StateEnum, city: string, street: string, postalCode: string}; export type CreateApiApiV2SosFilingDocumentsArgs = {body: SosReportParameterRequest}; export type CreateApiApiV2SosFilingDocumentsOptions = {baseUrl?: string | undefined, apiKeyPair?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const govDocumentOrderStatusEnum = z.enum(["NOT_ORDERED", "IN_PROGRESS", "FINISHED", "FAILED", "TIMED_OUT"]); export const sosEntityTypeEnum = z.enum(["CORPORATION", "LLC", "PARTNERSHIP", "NON_PROFIT", "TRUST", "SOLE_PROPRIETORSHIP"]); export const sosReportDocument = z.object({id: z.string(), checkedAt: z.string().nullable().optional(), status: govDocumentOrderStatusEnum.optional(), dataFile: z.string().nullable().optional(), reportFile: z.string().nullable().optional(), companyName: z.string().max(100).nullable().optional(), formationDate: z.string().nullable().optional(), entityType: sosEntityTypeEnum.nullable().optional(), watchlistHitsCount: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional()}); 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 }; /** * Order SOS filing document * * POST /api/v2/sos-filing-documents/ */ export const createApiApiV2SosFilingDocuments = async (args: CreateApiApiV2SosFilingDocumentsArgs, options?: CreateApiApiV2SosFilingDocumentsOptions) => { const {baseUrl = "https://ivs.idenfy.com", fetch: fetchFn = fetch, apiKeyPair} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyPair !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKeyPair.username}:${apiKeyPair.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/sos-filing-documents/${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(sosReportDocument, await res.json()) };