import {z} from 'zod' export type ComponentsSchemasAcceptorKeyRef = string; export type SchemasMerchantKey = string; export type SchemasAcceptorRoute = string; export type SchemasAcceptorResolver = {merchantAcceptorKey: ComponentsSchemasAcceptorKeyRef} | {merchantKey: SchemasMerchantKey, route?: SchemasAcceptorRoute | undefined}; export type ComponentsSchemasPan = string; export type ComponentsSchemasExpiryMonth = number; export type ComponentsSchemasExpiryYear = number; export type SchemasCvc = string; export type SchemasHolderName = string; export type SchemasProcessorTokenKey = string; export type MitChargeIntent = 'purchase' | 'reservation' | 'account-status'; export type MitCardEntry = 'card-on-file' | 'token-on-file'; export type MitChargeOrder = 'recurring' | 'ucof' | 'installment' | 'standing-order'; export type MitChargeType = {intent: MitChargeIntent, cardEntry: MitCardEntry, order: MitChargeOrder}; export type ComponentsSchemasAmountValue = number; export type CommonCurrencyCode = 'AED' | 'AFN' | 'ALL' | 'AMD' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XCG' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'; export type CommonAmount = {value: ComponentsSchemasAmountValue, currency: CommonCurrencyCode}; export type AmexInitialTransactionReference = {originalTransactionIdentifier: string}; export type DiscoverInitialTransactionReference = {originalNetworkReferenceId: string, originalAmountValue: number}; export type MastercardInitialTransactionReference = {initialTraceId: string, transactionLinkId?: string | undefined}; export type VisaInitialTransactionReference = {initialTransactionIdentifier: string}; export type DinersInitialTransactionReference = {originalNetworkReferenceId: string, originalRetrievalReferenceNumber: string, originalAmountValue: number}; export type SchemasEci = string; export type TokenCryptogram = string; export type ThreeDsCryptogram = string; export type TransactionType = 'cryptocurrency' | 'high-risk-securities' | 'central-bank-digital-currency' | 'stablecoin' | 'blockchain-native-coin' | 'non-fungible-token'; export type TransactionReference = string; export type LocalTransactionDateTime = unknown; export type AuthenticationValue3ds = string; export type ThreeDsAuthenticationResult = {version?: '2.2.0' | undefined, authenticationValue: AuthenticationValue3ds, directoryServerTransId: string, eci?: string | undefined}; export type ClearingMode = 'auto' | 'manual'; export type ClearAfter = unknown; export type SchemasCountryCodeAlpha3 = string; export type ComponentsSchemasCountryCodeAlpha3 = {alpha3: SchemasCountryCodeAlpha3}; export type SchemasCountryCodeAlpha2 = string; export type ComponentsSchemasCountryCodeAlpha2 = {alpha2: SchemasCountryCodeAlpha2}; export type SchemasCountryCodeNumeric = string; export type ComponentsSchemasCountryCodeNumeric = {numeric: SchemasCountryCodeNumeric}; export type OpenapiComponentsSchemasStateOrProvince = string; export type OpenapiComponentsSchemasCity = string; export type OpenapiComponentsSchemasLine1 = string; export type OpenapiComponentsSchemasLine2 = string; export type OpenapiComponentsSchemasPostalCode = string; export type BillingAddressInput = {countryCode?: (ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric) | undefined, stateOrProvince?: OpenapiComponentsSchemasStateOrProvince | undefined, city?: OpenapiComponentsSchemasCity | undefined, line1?: OpenapiComponentsSchemasLine1 | undefined, line2?: OpenapiComponentsSchemasLine2 | undefined, postalCode: OpenapiComponentsSchemasPostalCode}; export type Avs = boolean; export type SchemasDynamicDescriptor = {merchantName?: string | undefined, merchantCity?: string | undefined}; export type RiskAssessmentKey = string; export type ForeignRetailerDisabled = {indicator: false}; export type ForeignRetailerEnabled = {indicator: true, amount?: number | undefined}; export type SchemasForeignRetailer = ForeignRetailerDisabled | ForeignRetailerEnabled; export type SchemasAddressInput = {countryCode: ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric, stateOrProvince?: OpenapiComponentsSchemasStateOrProvince | undefined, city: OpenapiComponentsSchemasCity, line1: OpenapiComponentsSchemasLine1, line2?: OpenapiComponentsSchemasLine2 | undefined, postalCode: OpenapiComponentsSchemasPostalCode}; export type SubMerchant = {id?: string | undefined, address?: SchemasAddressInput | undefined}; export type EnhancedDataDestinationAddressInput = {countryCode?: (ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric) | undefined, postalCode?: string | undefined}; export type EnhancedDataShippingAddress = {postalCode?: string | undefined}; export type EnhancedDataLineItem = {commodityCode: string, description: string, discountAmount: number, productCode: string, quantity: number, unitOfMeasure: string, unitPrice: number, taxAmount: number, taxRate: number, totalAmount: number}; export type EnhancedDataInput = {taxAmount: number, customerCode?: string | undefined, customerTaxId?: string | undefined, destinationAddress?: EnhancedDataDestinationAddressInput | undefined, discountAmount?: number | undefined, invoiceNumber?: string | undefined, orderDate?: string | undefined, purchaseOrderNumber?: string | undefined, shippingAddress?: EnhancedDataShippingAddress | undefined, timeOfPurchase?: string | undefined, lineItems?: Array | undefined}; export type CreateMitChargeRequest = {merchantAcceptorResolver: SchemasAcceptorResolver, card: {number: ComponentsSchemasPan, expiryMonth: ComponentsSchemasExpiryMonth, expiryYear: ComponentsSchemasExpiryYear, cvc?: SchemasCvc | undefined, holderName?: SchemasHolderName | undefined} | {processorTokenKey: SchemasProcessorTokenKey, cvc?: string | undefined}, type: MitChargeType, amount: CommonAmount, initialTransactionReferences: AmexInitialTransactionReference | DiscoverInitialTransactionReference | MastercardInitialTransactionReference | VisaInitialTransactionReference | DinersInitialTransactionReference, tokenDetails?: ({type: 'network', eci?: SchemasEci | undefined, tokenCryptogram: TokenCryptogram} | {type: 'apple-pay' | 'google-pay', eci?: string | undefined, threeDsCryptogram: ThreeDsCryptogram}) | undefined, transactionType?: TransactionType | undefined, transactionReference?: TransactionReference | undefined, localTransactionDateTime?: LocalTransactionDateTime | undefined, threeDsAuthenticationResult?: ThreeDsAuthenticationResult | undefined, clearingMode?: ClearingMode | undefined, clearAfter?: ClearAfter | undefined, billingAddress?: BillingAddressInput | undefined, avs?: Avs | undefined, dynamicDescriptor?: SchemasDynamicDescriptor | undefined, riskAssessmentKey?: RiskAssessmentKey | undefined, foreignRetailer?: SchemasForeignRetailer | undefined, subMerchant?: SubMerchant | undefined, enhancedData?: EnhancedDataInput | undefined, allowPartialApproval?: boolean | undefined}; export type CreateApiChargesMitArgs = {'Idempotency-Key'?: string | undefined, body: CreateMitChargeRequest}; export type CreateApiChargesMitOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const chargeKey = z.string().min(5).max(120); export const componentsSchemasAcceptorKey = z.string().min(5).max(120); export const schemasVersion = z.number().int(); export const componentsSchemasAcceptorRef = z.object({key: componentsSchemasAcceptorKey, version: schemasVersion}); export const schemasProcessorTokenKey = z.string().min(5).max(120); export const outputCard = z.object({maskedNumber: z.string(), processorTokenKey: schemasProcessorTokenKey.optional()}); export const componentsSchemasAmountValue = z.number().int().gte(0).lte(999999999999); export const commonCurrencyCode = z.enum(["AED", "AFN", "ALL", "AMD", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWL"]); export const commonAmount = z.object({value: componentsSchemasAmountValue, currency: commonCurrencyCode}); export const mitChargeIntent = z.enum(["purchase", "reservation", "account-status"]); export const mitCardEntry = z.enum(["card-on-file", "token-on-file"]); export const mitChargeOrder = z.enum(["recurring", "ucof", "installment", "standing-order"]); export const mitResponseChargeType = z.object({intent: mitChargeIntent, cardEntry: mitCardEntry, order: mitChargeOrder, sequence: z.literal("subsequent").optional()}); export const authenticationStatus = z.enum(["none", "authenticated", "non-authenticated"]); export const authorizationStatus = z.enum(["none", "approved", "approved-partial", "declined", "reversed"]); export const clearingStatus = z.enum(["none", "manual", "pending", "completed", "cancelled", "abandoned"]); export const status = z.object({authentication: authenticationStatus, authorization: authorizationStatus, clearing: clearingStatus}); export const method = z.enum(["3ds1", "3ds2", "device"]); export const threeDsComplianceReason = z.enum(["mandated", "none", "ucof", "recurring", "installment", "incremental", "delayed-charges", "no-show", "reauthorization", "resubmission", "whitelist", "auto", "mit", "tra", "low-value", "delegation", "scp"]); export const threeDsAuthenticationResultResponse = z.object({version: z.literal("2.2.0").optional(), directoryServerTransId: z.string().optional()}); export const threeDsAuthentication = z.object({method: method, compliance: z.enum(["mandated", "mit", "exemption"]), complianceReason: threeDsComplianceReason, result: threeDsAuthenticationResultResponse}); export const methodBEP = z.literal("bep"); export const complianceBEP = z.literal("mandated"); export const complianceReasonBEP = z.literal("mandated"); export const bEPAuthenticationResult = z.object({trm: z.enum(["50", "51"])}); export const scaBEP = z.object({method: methodBEP, compliance: complianceBEP, complianceReason: complianceReasonBEP, result: bEPAuthenticationResult}); export const authenticationOutOfScope = z.object({method: z.literal("none"), compliance: z.literal("out-of-scope"), complianceReason: z.enum(["none", "moto", "one-leg", "anonymous-prepaid", "recurring"])}); export const authenticationExempt = z.object({method: z.literal("none"), compliance: z.literal("exemption"), complianceReason: z.enum(["whitelist", "auto", "mit", "tra", "recurring", "low-value", "delegation", "scp", "wip"])}); export const scaMit = z.object({method: z.literal("none"), compliance: z.literal("mit"), complianceReason: z.enum(["installment", "ucof"])}); export const sca = z.union([threeDsAuthentication, scaBEP, authenticationOutOfScope, authenticationExempt, scaMit]); export const avsResult = z.enum(["none", "match", "partial-match", "no-match", "not-processed"]); export const chargeAuthenticationMit = z.object({sca: sca, cvc: z.literal("none"), avs: avsResult}); export const localTransactionDateTime = z.string(); export const isoFieldResponseCode = z.string(); export const isoFieldResponseCodeDescription = z.string(); export const isoFieldAuthorizationCode = z.string(); export const isoFieldSystemTraceAuditNumber = z.string(); export const isoFieldRetrievalReferenceNumber = z.string(); export const isoFieldEciAmex = z.string(); export const amexSpecificFields = z.object({acquirerReferenceData: z.string(), cvcResult: z.string().optional(), avsResult: z.string().optional()}); export const authorizationIsoFieldsAmericanExpress = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("not-applicable"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciAmex, networkSpecificFields: amexSpecificFields}); export const bancontactSpecificFields = z.object({iban: z.string().optional()}); export const authorizationIsoFieldsBancontact = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("none"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: z.literal("none"), networkSpecificFields: bancontactSpecificFields}); export const isoFieldEciDiners = z.string(); export const dinersSpecificFields = z.object({network: z.literal("diners"), cvvIndicator: z.string().optional(), networkReferenceId: z.string().optional()}); export const authorizationIsoFieldsDiners = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.string(), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciDiners, networkSpecificFields: dinersSpecificFields}); export const isoFieldNetworkCode = z.string(); export const isoFieldEciDiscover = z.string(); export const discoverSpecificFields = z.object({network: z.literal("discover"), avsResponseCode: z.string().optional(), cidResultCode: z.string().optional(), networkReferenceId: z.string().optional()}); export const authorizationIsoFieldsDiscover = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciDiscover, networkSpecificFields: discoverSpecificFields}); export const isoFieldEciMastercard = z.string(); export const mastercardSpecificFields = z.object({banknetReference: z.string(), traceId: z.string(), merchantAdviceCode: z.string().optional(), cvcResult: z.string().optional(), nameValidationResult: z.string().optional(), avsResponse: z.string().optional(), paymentAccountReference: z.string().optional(), transactionLinkId: z.string().optional(), digitalCommerceProgramType: z.string().optional(), onBehalfServices: z.array(z.object({onBehalfService: z.string(), onBehalfResult1: z.string(), onBehalfResult2: z.string()})).optional()}); export const authorizationIsoFieldsMastercard = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciMastercard, networkSpecificFields: mastercardSpecificFields}); export const isoFieldEciUnionPay = z.string(); export const unionPaySpecificFields = z.object({network: z.literal("unionpay"), pvnCheckResult: z.string().optional()}); export const authorizationIsoFieldsUnionPay = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("not-applicable"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciUnionPay, networkSpecificFields: unionPaySpecificFields}); export const isoFieldEciVisa = z.string(); export const visaSpecificFields = z.object({transactionIdentifier: z.string(), cvv2ResultCode: z.string().optional(), avsResultCode: z.string().optional(), paymentAccountReference: z.string().optional(), aniResults: z.object({status: z.string(), fullNameMatch: z.string().optional(), firstNameMatch: z.string().optional(), middleNameMatch: z.string().optional(), lastNameMatch: z.string().optional()}).optional(), vaaiScore: z.string().optional(), tokenRequestorId: z.string().optional()}); export const authorizationIsoFieldsVisa = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciVisa, networkSpecificFields: visaSpecificFields}); export const authorizationIsoFields = z.union([authorizationIsoFieldsAmericanExpress, authorizationIsoFieldsBancontact, authorizationIsoFieldsDiners, authorizationIsoFieldsDiscover, authorizationIsoFieldsMastercard, authorizationIsoFieldsUnionPay, authorizationIsoFieldsVisa]); export const transactionType = z.enum(["cryptocurrency", "high-risk-securities", "central-bank-digital-currency", "stablecoin", "blockchain-native-coin", "non-fungible-token"]); export const transactionReference = z.string().min(1).max(120); export const clearingMode = z.enum(["auto", "manual"]); export const clearAfter = z.string(); export const schemasDynamicDescriptor = z.object({merchantName: z.string().min(1).max(22).optional(), merchantCity: z.string().min(1).max(13).optional()}); export const foreignRetailerDisabled = z.object({indicator: z.literal(false)}); export const foreignRetailerEnabled = z.object({indicator: z.literal(true), amount: z.number().int().gte(1).lte(999999999999).optional()}); export const schemasForeignRetailer = z.union([foreignRetailerDisabled, foreignRetailerEnabled]); export const schemasCountryCodeAlpha3 = z.string().min(3).max(3); export const schemasCountryCodeAlpha2 = z.string().min(2).max(2); export const schemasCountryCodeNumeric = z.string().min(3).max(3); export const schemasCountryCode = z.object({alpha3: schemasCountryCodeAlpha3, alpha2: schemasCountryCodeAlpha2, numeric: schemasCountryCodeNumeric}); export const openapiComponentsSchemasStateOrProvince = z.string().min(1).max(120); export const openapiComponentsSchemasCity = z.string().min(1).max(120); export const openapiComponentsSchemasLine1 = z.string().min(1).max(120); export const openapiComponentsSchemasLine2 = z.string().min(1).max(120); export const openapiComponentsSchemasPostalCode = z.string().min(1).max(10); export const componentsSchemasAddress = z.object({countryCode: schemasCountryCode, stateOrProvince: openapiComponentsSchemasStateOrProvince.optional(), city: openapiComponentsSchemasCity, line1: openapiComponentsSchemasLine1, line2: openapiComponentsSchemasLine2.optional(), postalCode: openapiComponentsSchemasPostalCode}); export const subMerchantResponse = z.object({id: z.string().min(1).max(15).optional(), address: componentsSchemasAddress.optional()}); export const schemasEci = z.string().min(2).max(2); export const allowPartialApproval = z.boolean(); export const componentsSchemasLastModified = z.string(); export const openapiComponentsSchemasCreated = z.string(); export const mitChargeResponse = z.object({key: chargeKey, merchantAcceptorRef: componentsSchemasAcceptorRef, card: outputCard, amount: commonAmount, type: mitResponseChargeType, status: status, authentication: chargeAuthenticationMit, localTransactionDateTime: localTransactionDateTime, authorizationIsoFields: authorizationIsoFields, transactionType: transactionType.optional(), transactionReference: transactionReference.optional(), clearingMode: clearingMode.optional(), clearAfter: clearAfter.optional(), dynamicDescriptor: schemasDynamicDescriptor.optional(), foreignRetailer: schemasForeignRetailer.optional(), subMerchant: subMerchantResponse.optional(), tokenDetails: z.union([z.object({type: z.literal("network"), eci: schemasEci.optional()}), z.object({type: z.enum(["apple-pay", "google-pay"]), eci: z.string().min(2).max(2).optional()})]).optional(), allowPartialApproval: allowPartialApproval.optional(), lastModified: componentsSchemasLastModified.optional(), created: openapiComponentsSchemasCreated, version: schemasVersion}); 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 }; /** * Create MIT Charge * * POST /charges/mit * * Also accepts auth: BearerToken */ export const createApiChargesMit = async (args: CreateApiChargesMitArgs, options?: CreateApiChargesMitOptions) => { const {baseUrl = "https://eu-west-1.api.silverflow.com/v1", 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['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/charges/mit${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(mitChargeResponse, await res.json()) };