import {z} from 'zod' export type AccountAuthenticationRequest = {accountId: string, additionalAuthenticationMethod?: ({correlationId: string, documentVerification?: ({address?: ({address1?: (string | null) | undefined, address2?: (string | null) | undefined, city?: (string | null) | undefined, company?: (string | null) | undefined, country: string, region?: (string | null) | undefined, savedData?: ({choseToSaveData?: (boolean | null) | undefined, usedSavedData?: (boolean | null) | undefined} | null) | undefined, zip?: (string | null) | undefined} | null) | undefined, documentDateOfBirth?: (string | null) | undefined, documentExpiration?: (string | null) | undefined, documentFirstName?: (string | null) | undefined, documentIssuingState?: (string | null) | undefined, documentLastName?: (string | null) | undefined, documentNumber?: (string | null) | undefined, documentSource: 'CAMERA_CAPTURED' | 'UPLOADED_FILE' | 'TYPED' | 'OTHER', documentStatus?: ('SENT_TO_CLIENT' | 'RECEIVED_FROM_CLIENT' | 'ABANDONED_BY_CLIENT' | 'RECEIVED_FROM_CLIENT_FAULTY' | null) | undefined, documentType: string, documentVerificationServiceAnswer?: (string | null) | undefined, documentVerificationServiceName?: (string | null) | undefined, documentVerificationServiceResponsePayload?: ({[key: string]: unknown} | null) | undefined, documentVerified?: (boolean | null) | undefined, eventTime?: (number | null) | undefined, nationality?: (string | null) | undefined} | null) | undefined, emailVerification?: ({email: string, emailVerification?: ({sent?: (boolean | null) | undefined, timeSent?: (number | null) | undefined, verified: boolean} | null) | undefined} | null) | undefined, oneTimePasswordVerification?: ({timeVerified?: (number | null) | undefined, verificationMethod: string, verified: boolean} | null) | undefined, paymentInstrumentVerification?: ({cameraCaptured?: (boolean | null) | undefined, creditCardManuallyTypedIn?: (boolean | null) | undefined, cvvManuallyTypedIn?: (boolean | null) | undefined, lastFourDigits?: (string | null) | undefined, token?: (string | null) | undefined} | null) | undefined, phoneVerification?: ({phone: string, smsVerified?: ({sent?: (boolean | null) | undefined, timeSent?: (number | null) | undefined, verified: boolean} | null) | undefined} | null) | undefined, verificationOutcome: 'SUCCESS' | 'FAILURE' | 'NONE_ATTEMPTED'} | null) | undefined, additionalInformation?: ({[key: string]: unknown} | null) | undefined, bankTransferVerificationResults?: ({accountHolderFirstName?: (string | null) | undefined, accountHolderLastName?: (string | null) | undefined, achProcessingType?: (string | null) | undefined, bankAccountIdentifier: string, bankAccountType?: (string | null) | undefined, bankName?: (string | null) | undefined, paymentGatewayData?: ({gatewayName?: (string | null) | undefined, gatewayTransactionId?: (string | null) | undefined} | null) | undefined, paymentSuccessStatus?: (string | null) | undefined, serviceName?: (string | null) | undefined} | null) | undefined, connectionInformation?: ({checkoutToolsSessionId?: (string | null) | undefined, customerIP: string, forterMobileUID?: (string | null) | undefined, forterTokenCookie?: (string | null) | undefined, merchantDeviceIdentifier?: (string | null) | undefined, merchantProvidedSessionId?: (string | null) | undefined, userAgent: string} | null) | undefined, eventTime: number, merchantIdentifiers?: ({merchantDomain?: (string | null) | undefined, merchantName?: (string | null) | undefined} | null) | undefined, paymentAuthorizationResults?: ({authorizationCode?: (string | null) | undefined, authorizationProcessedWith3DS?: (boolean | null) | undefined, avsFullResult?: (string | null) | undefined, avsNameResult?: (string | null) | undefined, avsStreetResult?: (string | null) | undefined, avsZipResult?: (string | null) | undefined, cavvResult?: (string | null) | undefined, cvvResult?: (string | null) | undefined, eciValue?: (string | null) | undefined, exemptionStatus?: (string | null) | undefined, external3dsVendorPayload?: ({[key: string]: unknown} | null) | undefined, issuerResponseCode?: (string | null) | undefined, issuerResponseText?: (string | null) | undefined, liabilityShift?: (boolean | null) | undefined, partyExecuted3DS?: ('PSP' | 'FORTER' | 'BOTH' | null) | undefined, processorResponseCode?: (string | null) | undefined, processorResponseText?: (string | null) | undefined, threeDsInteractionMode?: ('FRICTIONLESS' | 'CHALLENGED' | null) | undefined, threeDsStatus?: (string | null) | undefined, threeDsVersion?: (string | null) | undefined} | null) | undefined, paypalVerificationResults?: ({authorizationId?: (string | null) | undefined, fullPaypalResponsePayload?: ({[key: string]: unknown} | null) | undefined, payerAccountCountry?: (string | null) | undefined, payerAddressStatus?: (string | null) | undefined, payerEmail: string, payerId: string, payerStatus?: (string | null) | undefined, paymentGatewayData?: ({gatewayName?: (string | null) | undefined, gatewayTransactionId?: (string | null) | undefined} | null) | undefined, paymentId?: (string | null) | undefined, paymentStatus: string, protectionEligibility?: (string | null) | undefined} | null) | undefined}; export type CreateApiV2AccountsAuthenticationResultIdArgs = {id: string, 'api-version': string, 'x-forter-siteid': string, Authorization: string, body: AccountAuthenticationRequest}; export type CreateApiV2AccountsAuthenticationResultIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const verificationData = z.object({ThreeDS: z.object({ACSUrl: z.string().max(2048), ECIValue: z.string().max(300), acsChallengeMandated: z.string().max(1), acsReferenceNumber: z.string().max(32), acsSignedContent: z.string().max(1000), acsTransID: z.string().max(36), authenticationType: z.string().max(2), authenticationValue: z.string().max(28), bankLiabilityShift: z.boolean(), cardEnrolled: z.string().max(1), cavvAlgorithm: z.string().max(1), challengeCancel: z.string().max(2), challengeStatus: z.string().max(1), dsTransID: z.string().max(100), encodedChallengeRequest: z.string(), exemption: z.enum(["LOW_VALUE", "TRANSACTION_RISK_ANALYSIS", "SECURE_CORPORATE", "TRUSTED_BENEFICIARY"]).nullable().optional(), interactionCounter: z.string().max(2), isFallback: z.boolean(), messageCategory: z.string().max(2), outOfScopeForPSD2: z.enum(["ANONYMOUS_PREPAID_CARD", "MERCHANT_INITIATED_TRANSACTIONS", "ONE_LEG_OUT_EEA", "MAIL_ORDER_TELEPHONE_ORDER"]).nullable().optional(), threeDSServerTransID: z.string().max(100), threeDSecureMode: z.string().max(15), threeDSecurePreference: z.string().max(15), threeDSecureResult: z.string().max(6), transStatus: z.string().max(1), transStatusReason: z.string().max(2), verifyStatus: z.string().max(1), version: z.string().max(50)}).nullable().optional(), email: z.object({email: z.string().max(256), emailVerification: z.object({sent: z.boolean().nullable().optional(), timeSent: z.number().nullable().optional(), verified: z.boolean()}).nullable().optional()}).nullable().optional(), phone: z.object({phone: z.string().max(25), smsVerified: z.object({sent: z.boolean().nullable().optional(), timeSent: z.number().nullable().optional(), verified: z.boolean()}).nullable().optional()}).nullable().optional()}); export const verificationMethod = z.object({correlationId: z.string(), status: z.string().max(50), statusCode: z.string().max(50), statusMessage: z.string().max(50), type: z.enum(["OTP_SMS", "OTP_EMAIL", "THREE_DS"]).max(50), verificationId: z.string(), verificationSpecificData: verificationData}); export const adaptiveAuthAccountsResponse = z.object({accountId: z.string(), correlationId: z.string(), decisionReason: z.string().max(1000), forterDecision: z.enum(["APPROVE", "DECLINE", "VERIFICATION_REQUIRED", "NOT_REVIEWED"]), merchantPolicyId: z.string(), recommendation: z.string().max(1000), verificationMethod: verificationMethod}); 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 }; /** * Authentication result * * POST /v2/accounts/authentication-result/{id} */ export const createApiV2AccountsAuthenticationResultId = async (args: CreateApiV2AccountsAuthenticationResultIdArgs, options?: CreateApiV2AccountsAuthenticationResultIdOptions) => { const {baseUrl = "https://api.forter-secure.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['api-version'] != null) headers.set("api-version", String(args['api-version'])) if (args['x-forter-siteid'] != null) headers.set("x-forter-siteid", String(args['x-forter-siteid'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts/authentication-result/${encodeURIComponent(String(args.id))}${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(adaptiveAuthAccountsResponse, await res.json()) };