import {z} from 'zod' export type GetApiApiV2GovOrderedDocumentsAvailableDocumentsArgs = {countryCode: 'AL' | 'AM' | 'AR' | 'AT' | 'AU' | 'AW' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BG' | 'BH' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CH' | 'CN' | 'CO' | 'CR' | 'CW' | 'CY' | 'CZ' | 'DE' | 'DK' | 'DO' | 'EC' | 'EE' | 'ES' | 'FI' | 'FR' | 'GB' | 'GE' | 'GG' | 'GH' | 'GI' | 'GR' | 'HK' | 'HR' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IS' | 'IT' | 'JE' | 'JO' | 'KH' | 'KW' | 'KY' | 'LI' | 'LK' | 'LS' | 'LT' | 'LU' | 'LV' | 'MA' | 'ME' | 'MH' | 'MM' | 'MT' | 'MU' | 'MY' | 'NL' | 'NO' | 'NZ' | 'PE' | 'PH' | 'PK' | 'PL' | 'PR' | 'PT' | 'QA' | 'RO' | 'RS' | 'RU' | 'SB' | 'SE' | 'SG' | 'SI' | 'SK' | 'TH' | 'TN' | 'TO' | 'TR' | 'TT' | 'TW' | 'UG' | 'US' | 'UY' | 'VG' | 'VI' | 'VN' | 'VU' | 'WS' | 'ZA', region?: string | undefined, registrationNumber: string}; export type GetApiApiV2GovOrderedDocumentsAvailableDocumentsOptions = {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 govRegistersFilingResult = z.object({id: z.string(), productCode: z.string().optional(), price: z.number().int().nullable(), productFormat: z.string().nullable(), productTitle: z.string().optional(), deliveryTimeMinutes: z.number().int().optional(), type: z.string().optional(), displayDate: z.string().optional(), priceTag: z.string().optional(), companyName: z.string().optional(), countryISO: z.string().optional(), noVatPrice: z.string().optional(), vatCharge: z.string().optional(), currency: z.string().optional(), companyCode: z.string().optional(), productDetails: z.record(z.string(), z.unknown()).optional(), downloadURL: z.string().optional(), propertyChanged: z.string().optional(), tierCode: z.string().optional(), tierValue: z.string().optional(), status: govDocumentOrderStatusEnum.optional(), canOrder: z.boolean(), file: z.string().optional()}); export const govRegistersAvailableDocuments = z.object({products: z.array(govRegistersFilingResult)}); 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 }; /** * Retrieve available documents to order * * GET /api/v2/gov-ordered-documents/available-documents/ */ export const getApiApiV2GovOrderedDocumentsAvailableDocuments = async (args: GetApiApiV2GovOrderedDocumentsAvailableDocumentsArgs, options?: GetApiApiV2GovOrderedDocumentsAvailableDocumentsOptions) => { const {baseUrl = "https://ivs.idenfy.com", fetch: fetchFn = fetch, apiKeyPair} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.countryCode != null) query.append("countryCode", String(args.countryCode)) if (args.region != null) query.append("region", String(args.region)) if (args.registrationNumber != null) query.append("registrationNumber", String(args.registrationNumber)) if (apiKeyPair !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKeyPair.username}:${apiKeyPair.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/gov-ordered-documents/available-documents/${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(govRegistersAvailableDocuments, await res.json()) };