import {z} from 'zod' export type ServiceProfileStatePatch = 'ARCHIVED' | 'INACTIVE'; export type ServiceProfilePatch = {assignee?: string | undefined, reviewer?: string | undefined, currentWorkflowName?: string | undefined, state?: ServiceProfileStatePatch | undefined}; export type Comment = {commentId?: string | undefined, text?: string | undefined}; export type PatchApiV2IndividualsEntityIdServiceprofilesServiceNameArgs = {api_key: string, 'X-Frankie-CustomerID': string, 'X-Frankie-CustomerChildID'?: string | undefined, 'X-Frankie-Channel'?: string | undefined, 'X-Frankie-Username'?: string | undefined, body: {serviceProfile?: ServiceProfilePatch | undefined, comment?: Comment | undefined}}; export type PatchApiV2IndividualsEntityIdServiceprofilesServiceNameOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; 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 patchApiV2IndividualsEntityIdServiceprofilesServiceNameResponse = z.object({requestId: requestID.optional(), serviceProfile: serviceProfile.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 }; /** * Update a profile for a given individual entity. * * PATCH /v2/individuals/{entityId}/serviceprofiles/{serviceName} * * Also accepts auth: jwt */ export const patchApiV2IndividualsEntityIdServiceprofilesServiceName = async (args: PatchApiV2IndividualsEntityIdServiceprofilesServiceNameArgs, options?: PatchApiV2IndividualsEntityIdServiceprofilesServiceNameOptions) => { 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/individuals/${encodeURIComponent(String(args.entityId))}/serviceprofiles/${encodeURIComponent(String(args.serviceName))}${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(patchApiV2IndividualsEntityIdServiceprofilesServiceNameResponse, await res.json()) };