import {z} from 'zod' export type SearchType = 'EXACT' | 'FUZZY'; export type SearchField = 'NAME' | 'GIVEN_NAME' | 'FAMILY_NAME' | 'MIDDLE_NAME' | 'DISPLAY_NAME' | 'OTHER_NAME' | 'ADDRESS' | 'EMAIL_ADDRESS' | 'PHONE_NUMBER' | 'DOCUMENT_IDENTIFIER' | 'EXTERNAL_REFERENCE' | 'REGISTERED_NAME' | 'ALTERNATE_NAME' | 'REGISTRATION_NUMBER'; export type SearchTerm = {term: string, field: SearchField}; export type SearchCriteria = {type: SearchType, terms: Array}; export type SearchFilterEntityType = 'INDIVIDUAL' | 'ORGANIZATION'; export type ServiceProfileState = 'INIT' | 'AUTO' | 'ACTIVE' | 'ARCHIVED' | 'BLOCKLISTED' | 'INACTIVE' | 'DELETED' | 'DUPLICATE'; export type StatusOverrideTypeFilter = 'ONLY_OVERRIDDEN' | 'EXCLUDE_OVERRIDDEN' | 'ALL'; export type WorkflowExecutionResultEnum = 'UNCHECKED' | 'IN_PROGRESS' | 'REVIEW' | 'PASS' | 'FAIL' | 'COMPLETE' | 'INCOMPLETE' | 'NEEDS_APPROVAL' | 'APPROVED' | 'REJECTED' | 'BLOCKED' | 'CLEAR' | 'URGENT' | 'MONITOR'; export type WorkflowExecutionStatuses = {overrideType: StatusOverrideTypeFilter, status: Array}; export type WorkflowIssueCategory = 'AML' | 'BAD_DATA' | 'BIOMETRICS' | 'BLOCKLISTED' | 'DECEASED' | 'DEVICE' | 'DOCUMENT' | 'DUPLICATE' | 'EXPIRY' | 'FRAUD' | 'IDV' | 'INFORMATIONAL' | 'KYC' | 'SYSTEM' | 'VERIFY' | 'VISA' | 'WATCHLIST' | 'ACTIVITY'; export type WorkflowIssueSeverity = 'INFO' | 'REVIEW' | 'BLOCK' | 'WARNING' | 'CRITICAL' | 'ERROR'; export type RiskLevel = 'UNKNOWN' | 'LOW' | 'MEDIUM' | 'HIGH' | 'UNACCEPTABLE'; export type WorkflowIssueType = 'AML_ISSUE' | 'BAD_DATA_ADDRESS' | 'BAD_DATA_DOB' | 'BAD_DATA_EMAIL' | 'BAD_DATA_ID' | 'BAD_DATA_MOBILE' | 'BAD_DATA_NAME' | 'BLOCKED' | 'COMPROMISED_DOCUMENT' | 'CREDIT_HEADER' | 'DATA_COMPARISON' | 'DATA_CONSISTENCY' | 'DATA_VALIDATION' | 'DENY_LIST' | 'DECEASED' | 'DEVICE_FRAUD_MATCH' | 'DEVICE_INVALID' | 'DOCUMENT_COMPARISON' | 'DUPLICATE' | 'FRAUD_CHECK' | 'FRAUD_DEVICE' | 'FRAUD_IP_ADDRESS' | 'FRAUD_EMAIL_ADDRESS' | 'FRAUD_PHONE_NUMBER' | 'FRAUD_ISSUE' | 'FRAUD_LIST' | 'IMAGE_INTEGRITY' | 'INTERNAL_MATCH' | 'LIVENESS_DETECTION' | 'MATCHED_EXTERNAL' | 'MATCHED_INTERNAL' | 'MATCHED_SHARED' | 'MEDIA' | 'NOT_FOUND' | 'OCR' | 'PARTIAL' | 'PEP' | 'REQUIRES_AML' | 'REQUIRES_IDV' | 'REQUIRES_KYC' | 'REQUIRES_VISA' | 'SANCTION' | 'SERVICE_ERROR' | 'SERVICE_TIMEOUT' | 'VISA_FAILED' | 'VISUAL_AUTHENTICITY' | 'WATCHLIST' | 'ACTIVITY_AML' | 'ACTIVITY_FRAUD' | 'ACTIVITY_DEVICE'; export type WorkflowExecutionScopeEnum = 'LAST' | 'ANY'; export type SearchFilters = {entityIds?: Array | undefined, entityTypes?: Array | undefined, createdAtBefore?: string | undefined, createdAtAfter?: string | undefined, updatedAtAfter?: string | undefined, updatedAtBefore?: string | undefined, assignees?: Array | undefined, reviewers?: Array | undefined, states?: Array | undefined, workflowNames?: Array | undefined, workflowExecutionStatuses?: Array | undefined, statusOverrideType?: ('ONLY_OVERRIDDEN' | 'EXCLUDE_OVERRIDDEN' | 'ALL') | undefined, workflowStatuses?: Array | undefined, issueCategories?: Array | undefined, issueSeverities?: Array | undefined, riskLevels?: Array | undefined, issues?: Array | undefined, workflowExecutionScope?: WorkflowExecutionScopeEnum | undefined}; export type SearchProfile = {search?: SearchCriteria | undefined, filters?: SearchFilters | undefined}; export type CreateApiV2SearchServiceprofilesArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined, body: SearchProfile}; export type CreateApiV2SearchServiceprofilesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listOperationMeta = z.object({page: z.number().int().optional(), total: z.number().int().optional(), limit: z.number().int().optional(), count: z.number().int().optional(), sort: z.enum(["asc", "desc"]).optional(), sortFields: z.array(z.enum(["createdAt", "updatedAt"])).optional()}); export const requestID = z.string(); export const riskAssessmentID = z.string(); export const workflowExecutionStateEnum = z.enum(["COMPLETED", "CANCELED", "TERMINATED", "ERROR", "TIMEOUT", "IN_PROGRESS"]); export const workflowExecutionResultEnum = z.enum(["UNCHECKED", "IN_PROGRESS", "REVIEW", "PASS", "FAIL", "COMPLETE", "INCOMPLETE", "NEEDS_APPROVAL", "APPROVED", "REJECTED", "BLOCKED", "CLEAR", "URGENT", "MONITOR"]); export const profileID = z.string(); export const riskLevel = z.enum(["UNKNOWN", "LOW", "MEDIUM", "HIGH", "UNACCEPTABLE"]); export const riskFactorID = z.string(); export const riskFactorStatus = z.enum(["VALID", "STALE", "OVERRIDDEN", "DISCARDED"]); export const riskFactor = z.object({riskFactorId: riskFactorID.optional(), factor: z.string().optional(), value: z.string().optional(), score: z.number().optional(), description: z.string().optional(), workflowExecutionId: z.string().optional(), stepResultId: z.string().optional(), manualOverrideScore: z.number().optional(), status: riskFactorStatus.optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional(), updatedRequestId: z.string().optional(), createdServiceProfileId: z.string().optional(), createdWorkflowExecutionId: z.string().optional(), createdStepResultId: z.string().optional()}); export const riskAssessment = z.object({serviceProfileId: profileID, riskAssessmentId: riskAssessmentID.optional(), workflowId: z.string(), workflowExecutionId: z.string(), entityId: z.string(), schemaVersion: z.number().int().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional(), updatedRequestId: z.string().optional(), workflowRiskScore: z.number().optional(), workflowRiskLevel: riskLevel.optional(), riskScore: z.number().optional(), riskLevel: riskLevel.optional(), isOutdated: z.boolean().optional(), riskFactors: z.array(riskFactor).optional()}); export const workflowExecutionSteps = z.object({order: z.array(z.string()).optional(), passed: z.array(z.string()).optional(), failed: z.array(z.string()).optional(), incomplete: z.array(z.string()).optional(), notApplicable: z.array(z.string()).optional()}); export const issueID = z.string(); export const workflowIssueCategory = z.enum(["AML", "BAD_DATA", "BIOMETRICS", "BLOCKLISTED", "DECEASED", "DEVICE", "DOCUMENT", "DUPLICATE", "EXPIRY", "FRAUD", "IDV", "INFORMATIONAL", "KYC", "SYSTEM", "VERIFY", "VISA", "WATCHLIST", "ACTIVITY"]); export const workflowIssueType = z.enum(["AML_ISSUE", "BAD_DATA_ADDRESS", "BAD_DATA_DOB", "BAD_DATA_EMAIL", "BAD_DATA_ID", "BAD_DATA_MOBILE", "BAD_DATA_NAME", "BLOCKED", "COMPROMISED_DOCUMENT", "CREDIT_HEADER", "DATA_COMPARISON", "DATA_CONSISTENCY", "DATA_VALIDATION", "DENY_LIST", "DECEASED", "DEVICE_FRAUD_MATCH", "DEVICE_INVALID", "DOCUMENT_COMPARISON", "DUPLICATE", "FRAUD_CHECK", "FRAUD_DEVICE", "FRAUD_IP_ADDRESS", "FRAUD_EMAIL_ADDRESS", "FRAUD_PHONE_NUMBER", "FRAUD_ISSUE", "FRAUD_LIST", "IMAGE_INTEGRITY", "INTERNAL_MATCH", "LIVENESS_DETECTION", "MATCHED_EXTERNAL", "MATCHED_INTERNAL", "MATCHED_SHARED", "MEDIA", "NOT_FOUND", "OCR", "PARTIAL", "PEP", "REQUIRES_AML", "REQUIRES_IDV", "REQUIRES_KYC", "REQUIRES_VISA", "SANCTION", "SERVICE_ERROR", "SERVICE_TIMEOUT", "VISA_FAILED", "VISUAL_AUTHENTICITY", "WATCHLIST", "ACTIVITY_AML", "ACTIVITY_FRAUD", "ACTIVITY_DEVICE"]); export const workflowIssueSeverity = z.enum(["INFO", "REVIEW", "BLOCK", "WARNING", "CRITICAL", "ERROR"]); export const workflowIssue = z.object({issueId: issueID.optional(), category: workflowIssueCategory, issue: workflowIssueType, workflowExecutionId: z.string().optional(), stepResultId: z.string().optional(), isCleared: z.boolean().optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional(), updatedRequestId: z.string().optional(), severity: workflowIssueSeverity}); export const workflowLifecyclePhaseEnum = z.enum(["ONBOARDING", "MONITORING", "OTHER"]); export const monitoringType = z.enum(["AML", "ACTIVITY"]); export const workflowExecutionSummary = z.object({schemaVersion: z.number().int().optional(), workflowName: z.string().optional(), workflowExecutionId: z.string().optional(), workflowExecutionState: workflowExecutionStateEnum.optional(), status: workflowExecutionResultEnum.optional(), statusOverrideAt: z.string().optional(), statusOverrideRequestId: z.string().optional(), statusOverrideBy: z.string().optional(), riskAssessment: riskAssessment.optional(), isManual: z.boolean().optional(), steps: workflowExecutionSteps.optional(), startedAt: z.string().optional(), endedAt: z.string().optional(), issues: z.array(workflowIssue).optional(), lifecyclePhase: workflowLifecyclePhaseEnum.optional(), monitoringTypes: z.array(monitoringType).optional()}); export const subscriptionType = z.enum(["AML", "ACTIVITY"]); export const serviceProfileSubscription = z.object({serviceProfileId: z.string().optional(), status: z.enum(["ENABLED", "DISABLED"]).optional(), type: subscriptionType.optional(), workflowName: z.string().optional(), workflowId: z.string().optional(), enabledAt: z.string().optional(), enabledRequestId: z.string().optional(), enabledBy: z.string().optional(), disabledAt: z.string().optional(), disabledRequestId: z.string().optional(), disabledBy: z.string().optional()}); export const serviceProfileState = z.enum(["INIT", "AUTO", "ACTIVE", "ARCHIVED", "BLOCKLISTED", "INACTIVE", "DELETED", "DUPLICATE"]); export const serviceProfile = z.object({serviceProfileId: z.string().optional(), latestRiskAssessmentId: riskAssessmentID.optional(), latestWorkflowExecutionId: z.string().optional(), entityId: z.string().optional(), entityName: z.string().optional(), entityType: z.string().optional(), organizationType: z.string().optional(), country: z.string().optional(), schemaVersion: z.number().int().optional(), createdAt: z.string().optional(), createdRequestId: z.string().optional(), createdBy: z.string().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional(), updatedRequestId: z.string().optional(), assignee: z.string().optional(), reviewer: z.string().optional(), currentWorkflowId: z.string().optional(), currentWorkflowName: z.string().optional(), workflowSummaries: z.array(workflowExecutionSummary).optional(), serviceName: z.string().optional(), customerReference: z.string().optional(), subscriptions: z.array(serviceProfileSubscription).optional(), state: serviceProfileState.optional()}); export const searchConfidence = z.number().gte(0).lte(1); export const searchField = z.enum(["NAME", "GIVEN_NAME", "FAMILY_NAME", "MIDDLE_NAME", "DISPLAY_NAME", "OTHER_NAME", "ADDRESS", "EMAIL_ADDRESS", "PHONE_NUMBER", "DOCUMENT_IDENTIFIER", "EXTERNAL_REFERENCE", "REGISTERED_NAME", "ALTERNATE_NAME", "REGISTRATION_NUMBER"]); export const searchFieldMatch = z.object({field: searchField.optional(), confidence: searchConfidence.optional()}); export const searchMatch = z.object({serviceProfile: serviceProfile.optional(), confidence: searchConfidence.optional(), fieldsMatched: z.array(searchFieldMatch).optional()}); export const searchMatches = z.array(searchMatch); export const createApiV2SearchServiceprofilesResponse = z.object({meta: listOperationMeta.optional(), requestId: requestID.optional(), matches: z.array(searchMatches).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 }; /** * Search for individual profiles * * POST /v2/search/serviceprofiles * * Also accepts auth: jwt */ export const createApiV2SearchServiceprofiles = async (args: CreateApiV2SearchServiceprofilesArgs, options?: CreateApiV2SearchServiceprofilesOptions) => { 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 (ApiKey !== undefined) headers.set("api_key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/search/serviceprofiles${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(createApiV2SearchServiceprofilesResponse, await res.json()) };