import {z} from 'zod' export type DocumentID = string; export type EntityID = string; export type DateType = 'BUDDHIST' | 'DISCORDIAN' | 'GREGORIAN' | 'HEBREW' | 'ISLAMIC' | 'JULIAN' | 'LUNAR' | 'MESO_AMERICAN' | 'PERSIAN' | 'OTHER'; export type Date = {year?: string | undefined, month?: string | undefined, day?: string | undefined, unstructured?: string | undefined, type?: DateType | undefined, normalized?: string | undefined}; export type DocumentType = '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 type DocumentSupplementaryData = {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', reference?: string | undefined, nameOnCardLine1?: string | undefined, nameOnCardLine2?: string | undefined, nameOnCardLine3?: string | undefined, nameOnCardLine4?: string | undefined, middleNameOnCard?: string | undefined} | {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', registrationDate?: string | undefined, registrationDistrict?: string | undefined, dateOfPrint?: string | undefined, givenName?: string | undefined, otherNames?: string | undefined, familyName?: string | undefined} | {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', homeCountryFullName?: string | undefined, paternalFamilyName?: string | undefined, maternalFamilyName?: string | undefined} | {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', acquisitionDate?: string | undefined, primaryCountry?: string | undefined, secondaryCountry?: string | undefined} | {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', homeCountryFullName?: string | undefined} | {type: 'NATIONAL_HEALTH_ID' | 'BIRTH_CERT' | 'NATIONAL_ID' | 'CITIZENSHIP' | 'PASSPORT' | 'MARRIAGE_CERT', partner1GivenName?: string | undefined, partner1FamilyName?: string | undefined, partner1OtherName?: string | undefined, partner2GivenName?: string | undefined, partner2FamilyName?: string | undefined, partner2OtherName?: string | undefined, registrationDate?: string | undefined, marriageDate?: string | undefined, dateOfPrint?: string | undefined}; export type Attribute = {type: string, value: string}; export type CustomAttributes = {[key: string]: Attribute}; export type DocumentAttachmentID = string; export type DocumentAttachmentSide = 'FRONT' | 'BACK'; export type DocumentAttachmentType = string; export type DataURIBase64 = {uri: string} | {base64: string}; export type DocumentAttachmentRetrievalStatus = 'NORMAL' | 'EXCLUDED' | 'FAILED'; export type DocumentAttachment = {attachmentId?: DocumentAttachmentID | undefined, sourceId?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, filename?: string | undefined, mimeType?: string | undefined, pageNumber?: number | undefined, side?: DocumentAttachmentSide | undefined, type?: DocumentAttachmentType | undefined, location?: string | undefined, data: DataURIBase64, lastMalwareScanAt?: string | undefined, retrievalStatus?: DocumentAttachmentRetrievalStatus | undefined}; export type DocumentInformation = {documentId?: DocumentID | undefined, entityId?: EntityID | undefined, expiryDate?: Date | undefined, issueDate?: Date | undefined, primaryIdentifier?: string | undefined, secondaryIdentifier?: string | undefined, type: DocumentType, subtype?: string | undefined, subdivision?: string | undefined, country: string, createdAt?: string | undefined, updatedAt?: string | undefined, validFrom?: Date | undefined, validTo?: Date | undefined, sourceId?: string | undefined, supplementaryData?: DocumentSupplementaryData | undefined, customAttributes?: CustomAttributes | undefined, attachments?: Array | undefined}; export type Comment = {commentId?: string | undefined, text?: string | undefined}; export type PatchApiV2IndividualsEntityIdDocumentsDocumentIdArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined, level?: ('meta' | 'base64') | undefined, body: {document?: DocumentInformation | undefined, comment?: Comment | undefined}}; export type PatchApiV2IndividualsEntityIdDocumentsDocumentIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const entityID = z.string(); export const documentID = 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 requestID = z.string(); export const individualsEntityDocumentResponse = z.object({entity: entityID.optional(), document: documentInformation.optional(), requestId: requestID}); 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 }; /** * Update a single document by it's id. * * PATCH /v2/individuals/{entityId}/documents/{documentId} * * Also accepts auth: jwt */ export const patchApiV2IndividualsEntityIdDocumentsDocumentId = async (args: PatchApiV2IndividualsEntityIdDocumentsDocumentIdArgs, options?: PatchApiV2IndividualsEntityIdDocumentsDocumentIdOptions) => { const {baseUrl = "https://api.uat.frankie.one", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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 (args.level != null) query.append("level", String(args.level)) if (ApiKey !== undefined) headers.set("api_key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/individuals/${encodeURIComponent(String(args.entityId))}/documents/${encodeURIComponent(String(args.documentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(individualsEntityDocumentResponse, await res.json()) };