import {z} from 'zod' export type GetApiV2IndividualsEntityIdDocumentsArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined}; export type GetApiV2IndividualsEntityIdDocumentsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const documentID = z.string(); export const entityID = z.string(); export const dateType = z.enum(["BUDDHIST", "DISCORDIAN", "GREGORIAN", "HEBREW", "ISLAMIC", "JULIAN", "LUNAR", "MESO_AMERICAN", "PERSIAN", "OTHER"]); export const date = z.object({year: z.string().optional(), month: z.string().optional(), day: z.string().optional(), unstructured: z.string().optional(), type: dateType.optional(), normalized: z.string().optional()}); export const documentType = z.enum(["OTHER", "DRIVERS_LICENSE", "PASSPORT", "VISA", "IMMIGRATION", "NATIONAL_ID", "TAX_ID", "NATIONAL_HEALTH_ID", "CONCESSION", "HEALTH_CONCESSION", "PENSION", "MILITARY_ID", "BIRTH_CERT", "CITIZENSHIP", "MARRIAGE_CERT", "DEATH_CERT", "NAME_CHANGE", "UTILITY_BILL", "BANK_STATEMENT", "BANK_ACCOUNT", "INTENT_PROOF", "ATTESTATION", "SELF_IMAGE", "DEVICE", "VEHICLE_REGISTRATION", "PROOF_OF_ADDRESS", "HOUSE_REGISTRATION", "YELLOW_HOUSE_REGISTRATION", "WORK_PERMIT", "EMPLOYMENT_CERTIFICATE", "NOTARY_PUBLIC_ID", "EXTERNAL_ADMIN", "CHARGES", "PRE_ASIC", "ANNUAL_RETURN", "REPORT", "TRUST_DEED", "PARTNERSHIP_AGREEMENT", "ADMIN_CHANGE", "COMPANY_REPORT", "CHECK_RESULTS", "AVIATION_SECURITY_ID", "MARITIME_SECURITY_ID"]); export const documentSupplementaryData = z.discriminatedUnion("type", [z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), reference: z.string().optional(), nameOnCardLine1: z.string().optional(), nameOnCardLine2: z.string().optional(), nameOnCardLine3: z.string().optional(), nameOnCardLine4: z.string().optional(), middleNameOnCard: z.string().optional()}), z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), registrationDate: z.string().optional(), registrationDistrict: z.string().optional(), dateOfPrint: z.string().optional(), givenName: z.string().optional(), otherNames: z.string().optional(), familyName: z.string().optional()}), z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), homeCountryFullName: z.string().optional(), paternalFamilyName: z.string().optional(), maternalFamilyName: z.string().optional()}), z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), acquisitionDate: z.string().optional(), primaryCountry: z.string().optional(), secondaryCountry: z.string().optional()}), z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), homeCountryFullName: z.string().optional()}), z.object({type: z.enum(["NATIONAL_HEALTH_ID", "BIRTH_CERT", "NATIONAL_ID", "CITIZENSHIP", "PASSPORT", "MARRIAGE_CERT"]), partner1GivenName: z.string().optional(), partner1FamilyName: z.string().optional(), partner1OtherName: z.string().optional(), partner2GivenName: z.string().optional(), partner2FamilyName: z.string().optional(), partner2OtherName: z.string().optional(), registrationDate: z.string().optional(), marriageDate: z.string().optional(), dateOfPrint: z.string().optional()})]); export const attribute = z.object({type: z.string().max(64), value: z.string()}); export const customAttributes = z.record(z.string(), attribute); export const documentAttachmentID = z.string(); export const documentAttachmentSide = z.enum(["FRONT", "BACK"]); export const documentAttachmentType = z.string(); export const dataURIBase64 = z.union([z.object({uri: z.string()}), z.object({base64: z.string()})]); export const documentAttachmentRetrievalStatus = z.enum(["NORMAL", "EXCLUDED", "FAILED"]); export const documentAttachment = z.object({attachmentId: documentAttachmentID.optional(), sourceId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), filename: z.string().optional(), mimeType: z.string().optional(), pageNumber: z.number().int().optional(), side: documentAttachmentSide.optional(), type: documentAttachmentType.optional(), location: z.string().optional(), data: dataURIBase64, lastMalwareScanAt: z.string().optional(), retrievalStatus: documentAttachmentRetrievalStatus.optional()}); export const documentInformation = z.object({documentId: documentID.optional(), entityId: entityID.optional(), expiryDate: date.optional(), issueDate: date.optional(), primaryIdentifier: z.string().optional(), secondaryIdentifier: z.string().optional(), type: documentType, subtype: z.string().optional(), subdivision: z.string().optional(), country: z.string().max(3), createdAt: z.string().optional(), updatedAt: z.string().optional(), validFrom: date.optional(), validTo: date.optional(), sourceId: z.string().optional(), supplementaryData: documentSupplementaryData.optional(), customAttributes: customAttributes.optional(), attachments: z.array(documentAttachment).optional()}); export const entityDocuments = z.object({REPORT: z.array(documentInformation).optional(), SUPPORTING: z.array(documentInformation).optional(), IDENTITY: z.array(documentInformation).optional(), OTHER: z.array(documentInformation).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 }; /** * Get all documents for an entity * * GET /v2/individuals/{entityId}/documents * * Also accepts auth: jwt */ export const getApiV2IndividualsEntityIdDocuments = async (args: GetApiV2IndividualsEntityIdDocumentsArgs, options?: GetApiV2IndividualsEntityIdDocumentsOptions) => { const {baseUrl = "https://api.uat.frankie.one", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.api_key != null) headers.set("api_key", String(args.api_key)) if (args['X-Frankie-CustomerID'] != null) headers.set("X-Frankie-CustomerID", String(args['X-Frankie-CustomerID'])) if (args['X-Frankie-CustomerChildID'] != null) headers.set("X-Frankie-CustomerChildID", String(args['X-Frankie-CustomerChildID'])) if (args['X-Frankie-Channel'] != null) headers.set("X-Frankie-Channel", String(args['X-Frankie-Channel'])) if (args['X-Frankie-Username'] != null) headers.set("X-Frankie-Username", String(args['X-Frankie-Username'])) if (ApiKey !== undefined) headers.set("api_key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/individuals/${encodeURIComponent(String(args.entityId))}/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(entityDocuments, await res.json()) };