@agent-cards/sdk 0.23.13 → 0.23.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  // Generated from @agent-cards/payment-core. Do not edit.
3
- // artifact-sha256: 58593275ccbce7e76a1aa68065eb63063cdf0ed00d533706bec557cb8a21cbc8
3
+ // artifact-sha256: 0110d9fe2e862aad2c1191c5927ebb98dcc4be9905554ed46e18719a0bad05fb
4
4
  // src/creditguard.js
5
5
  var CREDITGUARD_PPS_HOSTS = Object.freeze(["pps.creditguard.co.il", "pps2.creditguard.co.il", "ppsuat.creditguard.co.il"]);
6
6
  var CREDITGUARD_SANDBOX_HOST = "ppsuat.creditguard.co.il";
@@ -516,8 +516,11 @@ function parseCreditguardTransaction(body, txId) {
516
516
  const inputData = record(value.formConfig) && Array.isArray(value.formConfig.inputData) ? value.formConfig.inputData : [];
517
517
  const inputs = inputData.length <= 32 && inputData.every((input) => record(input) && exact(INPUT_NAMES, input.inputName) && inputFlag(input.required) && inputFlag(input.visible)) ? inputData.map((input) => ({ inputName: input.inputName, required: input.required === true, visible: input.visible === true })) : null;
518
518
  let jwePublicKey = "absent";
519
+ let jwePublicKeyJson = null;
519
520
  if (owns(trx, "jwePublicKey") && trx.jwePublicKey !== null && trx.jwePublicKey !== "") {
520
521
  jwePublicKey = parseCreditguardJwePublicKey(trx.jwePublicKey) ?? "malformed";
522
+ if (jwePublicKey !== "malformed")
523
+ jwePublicKeyJson = typeof trx.jwePublicKey === "string" ? trx.jwePublicKey : JSON.stringify(trx.jwePublicKey);
521
524
  }
522
525
  return {
523
526
  txId,
@@ -535,6 +538,7 @@ function parseCreditguardTransaction(body, txId) {
535
538
  dccActive: flag(trx.dccActive),
536
539
  recaptcha: ["googleRecaptchaKey", "googleRecaptchaV3Key"].some((key) => typeof trx[key] === "string" && trx[key] !== ""),
537
540
  jwePublicKey,
541
+ jwePublicKeyJson,
538
542
  personalIdAlwaysEnabled: flag(ui.personalIdAlwaysEnabled),
539
543
  inputs
540
544
  };
@@ -557,7 +561,7 @@ function formInputsRefusal(inputs) {
557
561
  function creditguardTransactionRefusal(txn, expectation) {
558
562
  if (!record(txn) || !record(expectation))
559
563
  return "transaction_unreadable";
560
- if (txn.threeDS)
564
+ if (txn.threeDS && !(expectation.threeDS === "device" && txn.threeDSProvider === "cc" && !txn.recaptcha))
561
565
  return "three_d_secure";
562
566
  if (txn.otpActive)
563
567
  return "otp";
@@ -594,6 +598,12 @@ function creditguardSendWindowRefusal(timing) {
594
598
  return "recaptcha_expired";
595
599
  return null;
596
600
  }
601
+ function creditguardBodyTransactionRefusal(body, txn) {
602
+ const value = readCreditguardJson(body);
603
+ if (!value || !record(txn))
604
+ return null;
605
+ return owns(value, "jwePayload") === (txn.jwePublicKey !== "absent") ? null : "jwe_mismatch";
606
+ }
597
607
  var ERROR_CODE = /^-?[0-9]{1,4}$/;
598
608
  var CREDITGUARD_REFUSAL_CODES = Object.freeze(["681", "682", "683", "687", "689"]);
599
609
  function landingUrl(value) {
@@ -657,4 +667,324 @@ function creditguardFacts(status, body) {
657
667
  refusalCode: verdict.outcome === "refused" ? verdict.code : null
658
668
  };
659
669
  }
660
- export { CREDITGUARD_JWE_HEADER, CREDITGUARD_OPERATION, CREDITGUARD_PAGE_WINDOW_MS, CREDITGUARD_PPS_HOSTS, CREDITGUARD_RECAPTCHA_WINDOW_MS, CREDITGUARD_REFUSAL_CODES, CREDITGUARD_SANDBOX_HOST, classifyCreditguardRequest, creditguardBodyRefusal, creditguardFacts, creditguardNuveiRefusal, creditguardPageProcessUrl, creditguardPpDomainHost, creditguardPreparationEnvironment, creditguardProcessRefusal, creditguardProcessTxId, creditguardRefusalMessage, creditguardReplayRefusal, creditguardResponseOutcome, creditguardSendWindowRefusal, creditguardTransactionReadUrl, creditguardTransactionRefusal, encryptCreditguardJwe, injectCreditguardCard, injectCreditguardJweCard, isCreditguardJweCompact, isCreditguardPpsDocument, isCreditguardProcessRequest, isCreditguardProcessUrl, parseCreditguardJwePublicKey, parseCreditguardTransaction, readCreditguardJson, sanitizeCreditguardResponse };
670
+ var CREDITGUARD_COMPANION_PATHS = Object.freeze({
671
+ card_details: "/card/details",
672
+ ddc_init: "/cc/ddc/init",
673
+ threeds_init: "/cg3ds/process/init",
674
+ threeds_outcome: "/cg3ds/process/outcome"
675
+ });
676
+ var CREDITGUARD_DEVICE_STEPS = Object.freeze(["ddc_init", "threeds_init", "threeds_outcome"]);
677
+ var CREDITGUARD_CARDINAL_HOSTS = Object.freeze({
678
+ production: Object.freeze(["client.cardinaltrusted.com", "centinelapi.cardinalcommerce.com"]),
679
+ sandbox: Object.freeze(["cas.client.cardinaltrusted.com", "centinelapistag.cardinalcommerce.com"])
680
+ });
681
+ var CREDITGUARD_CARDINAL_COLLECT_URLS = Object.freeze({
682
+ production: "https://client.cardinaltrusted.com/centinelapi/V2/Cruise/Collect",
683
+ sandbox: "https://cas.client.cardinaltrusted.com/centinelapi/V2/Cruise/Collect"
684
+ });
685
+ var CARDINAL_PATHS = Object.freeze({
686
+ collect: /^\/(?:centinelapi\/)?V[12]\/Cruise\/Collect$/,
687
+ step_up: /^\/(?:centinelapi\/)?V[12]\/Cruise\/StepUp$/
688
+ });
689
+ var COMPANION_PATH = new RegExp(`^/services/v1/txn/(${UUID})(/card/details|/cc/ddc/init|/cg3ds/process/init|/cg3ds/process/outcome)$`);
690
+ var COMPANION_ENDPOINT = /^\/services\/v1\/txn\/[^/]+\/(?:card\/details|cc\/ddc\/init|cg3ds\/process\/(?:init|outcome))\/?$/i;
691
+ var STEP_BY_PATH = Object.freeze(Object.fromEntries(Object.entries(CREDITGUARD_COMPANION_PATHS).map(([step, path]) => [path, step])));
692
+ var COMPANION_ANSWERS = Object.freeze({
693
+ card_details: '{"creditCompany":"Foreign","cardType":"Foreign"}',
694
+ ddc_init: "{}",
695
+ threeds_init: '{"challengeRequired":false}',
696
+ threeds_outcome: "{}"
697
+ });
698
+ var JWT = /^[A-Za-z0-9_-]{2,4096}\.[A-Za-z0-9_-]{2,4096}\.[A-Za-z0-9_-]{0,1024}$/;
699
+ var SESSION_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
700
+ var LANGUAGE = /^[A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8}){0,4}$/;
701
+ var THREE_DS_REFUSAL = "Refusing to pay: this CreditGuard 3-D Secure step is not the reviewed one. Nothing was sent.";
702
+ var BROWSER_HEADER = "text/html;charset=UTF-8";
703
+ var THREE_DS_INIT_KEYS = Object.freeze([
704
+ "cardNumber",
705
+ "expMonth",
706
+ "expYear",
707
+ "cvv",
708
+ "isGooglePayTxn",
709
+ "isPayboxTxn",
710
+ "useDcc",
711
+ "acsWindowSize",
712
+ "browserColorDepth",
713
+ "browserHeader",
714
+ "browserJavaEnabled",
715
+ "browserJavascriptEnabled",
716
+ "browserLanguage",
717
+ "browserScreenHeight",
718
+ "browserScreenWidth",
719
+ "browserTimeZone",
720
+ "txId",
721
+ "pendingGiftCards",
722
+ "userAgent",
723
+ "jwePublicKey",
724
+ "ccDdcSessionId"
725
+ ]);
726
+ var DEVICE_HEADERS = Object.freeze({ "content-type": "application/json", accept: "application/json" });
727
+ function creditguardCompanionStep(url) {
728
+ if (typeof url !== "string" || url.includes("?") || url.includes("#"))
729
+ return null;
730
+ const parsed = httpsUrl(url);
731
+ if (!parsed || parsed.href !== url || !CREDITGUARD_PPS_HOSTS.includes(parsed.hostname))
732
+ return null;
733
+ const match = COMPANION_PATH.exec(parsed.pathname);
734
+ return match ? { step: STEP_BY_PATH[match[2]], txId: match[1] } : null;
735
+ }
736
+ function isCompanionEndpoint(url) {
737
+ const parsed = httpsUrl(url, 4096);
738
+ return !!parsed && CREDITGUARD_PPS_HOSTS.includes(parsed.hostname.toLowerCase()) && COMPANION_ENDPOINT.test(parsed.pathname);
739
+ }
740
+ function creditguardDeviceStepUrl(processUrl, step) {
741
+ const txId = creditguardProcessTxId(processUrl);
742
+ if (txId === null || !CREDITGUARD_DEVICE_STEPS.includes(step))
743
+ return null;
744
+ return `https://${new URL(processUrl).hostname}/services/v1/txn/${txId}${CREDITGUARD_COMPANION_PATHS[step]}`;
745
+ }
746
+ function companionBodyRefusal(step, txId, body) {
747
+ if (step === "threeds_outcome")
748
+ return body === "null" || readCreditguardJson(body) ? null : "malformed_body";
749
+ const value = readCreditguardJson(body);
750
+ if (!value)
751
+ return "malformed_body";
752
+ if (step === "card_details") {
753
+ const keys = Object.keys(value);
754
+ if (keys.length !== 1)
755
+ return "malformed_body";
756
+ if (keys[0] === "cardNo")
757
+ return digits(value.cardNo, 12, 19) ? null : "card_fields";
758
+ return keys[0] === "cardNoEnc" && isCreditguardJweCompact(value.cardNoEnc) ? null : "malformed_body";
759
+ }
760
+ if (step === "ddc_init") {
761
+ if (value.isGooglePayTxn === true)
762
+ return "wallet";
763
+ if (value.isGooglePayTxn !== false || Object.keys(value).some((key) => !["cardNo", "encryptedCardNo", "isGooglePayTxn"].includes(key)))
764
+ return "malformed_body";
765
+ if (owns(value, "cardNo"))
766
+ return digits(value.cardNo, 12, 19) && value.encryptedCardNo === null ? null : "card_fields";
767
+ return isCreditguardJweCompact(value.encryptedCardNo) ? null : "card_fields";
768
+ }
769
+ if (value.isGooglePayTxn === true || value.isPayboxTxn === true)
770
+ return "wallet";
771
+ if (value.pendingGiftCards === true)
772
+ return "gift_card";
773
+ if (value.useDcc === true)
774
+ return "dcc";
775
+ if (owns(value, "txId") && value.txId !== txId)
776
+ return "txid_mismatch";
777
+ return digits(value.cardNumber, 12, 19) ? null : "card_fields";
778
+ }
779
+ function creditguardCompanionCall(url, method, body) {
780
+ if (!isCompanionEndpoint(url))
781
+ return null;
782
+ const exactStep = creditguardCompanionStep(url);
783
+ if (exactStep === null)
784
+ return { step: null, txId: null, refusal: "not_companion_request" };
785
+ if (method !== "POST")
786
+ return { ...exactStep, refusal: "not_companion_request" };
787
+ return { ...exactStep, refusal: companionBodyRefusal(exactStep.step, exactStep.txId, body) };
788
+ }
789
+ function creditguardCompanionAnswer(step) {
790
+ return typeof step === "string" && owns(COMPANION_ANSWERS, step) ? { status: 200, headers: { "content-type": "application/json" }, body: COMPANION_ANSWERS[step] } : null;
791
+ }
792
+ function deviceBrowser(browser) {
793
+ const int = (value, min, max) => Number.isSafeInteger(value) && value >= min && value <= max;
794
+ if (!record(browser) || !int(browser.colorDepth, 1, 64) || typeof browser.javaEnabled !== "boolean" || !exact(LANGUAGE, browser.language) || !int(browser.screenHeight, 1, 1e5) || !int(browser.screenWidth, 1, 1e5) || !int(browser.timeZoneOffset, -900, 900) || typeof browser.userAgent !== "string" || browser.userAgent.length < 1 || browser.userAgent.length > 1024 || /[^\x20-\x7e]/.test(browser.userAgent)) {
795
+ throw new Error(THREE_DS_REFUSAL);
796
+ }
797
+ return {
798
+ colorDepth: browser.colorDepth,
799
+ javaEnabled: browser.javaEnabled,
800
+ language: browser.language,
801
+ screenHeight: browser.screenHeight,
802
+ screenWidth: browser.screenWidth,
803
+ timeZoneOffset: browser.timeZoneOffset,
804
+ userAgent: browser.userAgent
805
+ };
806
+ }
807
+ function deviceKey(key) {
808
+ if (key === void 0 || key === null)
809
+ return null;
810
+ if (typeof key !== "string" || !parseCreditguardJwePublicKey(key))
811
+ throw new Error(THREE_DS_REFUSAL);
812
+ return { text: key, object: JSON.parse(key) };
813
+ }
814
+ async function creditguardDeviceDdcRequest(processUrl, card, options = {}) {
815
+ const url = creditguardDeviceStepUrl(processUrl, "ddc_init");
816
+ if (!url)
817
+ throw new Error(THREE_DS_REFUSAL);
818
+ const parts = cardParts(card);
819
+ const key = deviceKey(record(options) ? options.jwePublicKey : void 0);
820
+ const body = key === null ? JSON.stringify({ cardNo: parts.number, encryptedCardNo: null, isGooglePayTxn: false }) : JSON.stringify({ encryptedCardNo: await encryptCreditguardJwe(parts.number, key.text, options), isGooglePayTxn: false });
821
+ return { url, method: "POST", headers: { ...DEVICE_HEADERS }, body };
822
+ }
823
+ function creditguardDeviceThreeDSInitRequest(processUrl, card, options = {}) {
824
+ const url = creditguardDeviceStepUrl(processUrl, "threeds_init");
825
+ if (!url || !record(options))
826
+ throw new Error(THREE_DS_REFUSAL);
827
+ const parts = cardParts(card);
828
+ const browser = deviceBrowser(options.browser);
829
+ const key = deviceKey(options.jwePublicKey);
830
+ const session = options.ddcSessionId ?? null;
831
+ if (session !== null && !exact(SESSION_ID, session))
832
+ throw new Error(THREE_DS_REFUSAL);
833
+ const body = {
834
+ cardNumber: parts.number,
835
+ expMonth: parts.month,
836
+ expYear: parts.year,
837
+ cvv: parts.cvc,
838
+ isGooglePayTxn: false,
839
+ isPayboxTxn: false,
840
+ useDcc: false,
841
+ acsWindowSize: "4",
842
+ browserColorDepth: browser.colorDepth,
843
+ browserHeader: BROWSER_HEADER,
844
+ browserJavaEnabled: browser.javaEnabled,
845
+ browserJavascriptEnabled: true,
846
+ browserLanguage: browser.language,
847
+ browserScreenHeight: browser.screenHeight,
848
+ browserScreenWidth: browser.screenWidth,
849
+ browserTimeZone: browser.timeZoneOffset,
850
+ txId: creditguardProcessTxId(processUrl),
851
+ pendingGiftCards: false,
852
+ userAgent: browser.userAgent,
853
+ jwePublicKey: key === null ? "" : key.object,
854
+ ccDdcSessionId: session
855
+ };
856
+ return { url, method: "POST", headers: { ...DEVICE_HEADERS }, body: JSON.stringify(body) };
857
+ }
858
+ function creditguardDeviceThreeDSOutcomeRequest(processUrl) {
859
+ const url = creditguardDeviceStepUrl(processUrl, "threeds_outcome");
860
+ if (!url)
861
+ throw new Error(THREE_DS_REFUSAL);
862
+ return { url, method: "POST", headers: { ...DEVICE_HEADERS }, body: "null" };
863
+ }
864
+ function deviceStepBodyRefusal(step, txId, body) {
865
+ if (step === "threeds_outcome")
866
+ return body === "null" ? null : "malformed_body";
867
+ const value = readCreditguardJson(body);
868
+ if (!value)
869
+ return "malformed_body";
870
+ const keys = Object.keys(value).join(",");
871
+ if (step === "ddc_init") {
872
+ if (keys === "cardNo,encryptedCardNo,isGooglePayTxn")
873
+ return digits(value.cardNo, 12, 19) && value.encryptedCardNo === null && value.isGooglePayTxn === false ? null : "card_fields";
874
+ if (keys === "encryptedCardNo,isGooglePayTxn")
875
+ return isCreditguardJweCompact(value.encryptedCardNo) && value.isGooglePayTxn === false ? null : "card_fields";
876
+ return "unexpected_field";
877
+ }
878
+ if (keys !== THREE_DS_INIT_KEYS.join(","))
879
+ return "unexpected_field";
880
+ if (!digits(value.cardNumber, 12, 19) || !exact(/^(?:0[1-9]|1[0-2])$/, value.expMonth) || !exact(/^[0-9]{2}$/, value.expYear) || !digits(value.cvv, 3, 4))
881
+ return "card_fields";
882
+ if (value.isGooglePayTxn !== false || value.isPayboxTxn !== false)
883
+ return "wallet";
884
+ if (value.pendingGiftCards !== false)
885
+ return "gift_card";
886
+ if (value.useDcc !== false)
887
+ return "dcc";
888
+ if (value.txId !== txId)
889
+ return "txid_mismatch";
890
+ if (value.acsWindowSize !== "4" || value.browserHeader !== BROWSER_HEADER || value.browserJavascriptEnabled !== true)
891
+ return "malformed_body";
892
+ try {
893
+ deviceBrowser({
894
+ colorDepth: value.browserColorDepth,
895
+ javaEnabled: value.browserJavaEnabled,
896
+ language: value.browserLanguage,
897
+ screenHeight: value.browserScreenHeight,
898
+ screenWidth: value.browserScreenWidth,
899
+ timeZoneOffset: value.browserTimeZone,
900
+ userAgent: value.userAgent
901
+ });
902
+ }
903
+ catch {
904
+ return "malformed_body";
905
+ }
906
+ if (value.jwePublicKey !== "" && !(record(value.jwePublicKey) && parseCreditguardJwePublicKey(value.jwePublicKey)))
907
+ return "malformed_body";
908
+ return value.ccDdcSessionId === null || exact(SESSION_ID, value.ccDdcSessionId) ? null : "malformed_body";
909
+ }
910
+ function creditguardDeviceStepRefusal(request, processUrl) {
911
+ if (!record(request) || request.method !== "POST")
912
+ return "not_companion_request";
913
+ const exactStep = creditguardCompanionStep(request.url);
914
+ if (!exactStep || creditguardDeviceStepUrl(processUrl, exactStep.step) !== request.url)
915
+ return "not_companion_request";
916
+ if (!record(request.headers))
917
+ return "headers";
918
+ const names = Object.keys(request.headers).map((name) => name.toLowerCase()).sort().join(",");
919
+ if (names !== "accept,content-type" || headersRefusal(request.headers) !== null)
920
+ return "headers";
921
+ return deviceStepBodyRefusal(exactStep.step, exactStep.txId, request.body);
922
+ }
923
+ function creditguardCardinalUrl(url, purpose, environment) {
924
+ const hosts = typeof environment === "string" && owns(CREDITGUARD_CARDINAL_HOSTS, environment) ? CREDITGUARD_CARDINAL_HOSTS[environment] : null;
925
+ const path = typeof purpose === "string" && owns(CARDINAL_PATHS, purpose) ? CARDINAL_PATHS[purpose] : null;
926
+ if (!hosts || !path || typeof url !== "string" || url.includes("?") || url.includes("#"))
927
+ return null;
928
+ const parsed = httpsUrl(url, 1024);
929
+ return parsed && parsed.href === url && hosts.includes(parsed.hostname) && path.test(parsed.pathname) ? parsed.href : null;
930
+ }
931
+ function isCreditguardCardinalOrigin(origin) {
932
+ if (typeof origin !== "string" || origin.length > 256)
933
+ return false;
934
+ let parsed;
935
+ try {
936
+ parsed = new URL(origin);
937
+ }
938
+ catch {
939
+ return false;
940
+ }
941
+ return parsed.protocol === "https:" && parsed.origin === origin && !parsed.port && /(?:^|\.)(?:cardinaltrusted|cardinalcommerce)\.com$/.test(parsed.hostname);
942
+ }
943
+ function creditguardCardinalMessage(data) {
944
+ if (typeof data !== "string" || data.length > 16384)
945
+ return null;
946
+ let value;
947
+ try {
948
+ value = JSON.parse(data);
949
+ }
950
+ catch {
951
+ return null;
952
+ }
953
+ if (!record(value))
954
+ return null;
955
+ const payload = value.Payload || value.TransactionId;
956
+ return { sessionId: record(payload) && exact(SESSION_ID, payload.SessionId) ? payload.SessionId : null };
957
+ }
958
+ function creditguardDdcAnswer(status, body, environment) {
959
+ if (status !== 200)
960
+ return null;
961
+ const value = readCreditguardJson(body);
962
+ if (!value || typeof value.ddcJwt !== "string" || value.ddcJwt.length > 8192 || !JWT.test(value.ddcJwt))
963
+ return null;
964
+ const named = typeof value.clientDdcUrl === "string" && value.clientDdcUrl !== "" ? value.clientDdcUrl : null;
965
+ if (named === null && !absent(value, "clientDdcUrl") && value.clientDdcUrl !== "")
966
+ return null;
967
+ const collectUrl = named === null ? typeof environment === "string" && owns(CREDITGUARD_CARDINAL_COLLECT_URLS, environment) ? CREDITGUARD_CARDINAL_COLLECT_URLS[environment] : null : creditguardCardinalUrl(named, "collect", environment);
968
+ return collectUrl ? { collectUrl, ddcJwt: value.ddcJwt } : null;
969
+ }
970
+ function creditguardThreeDSInitAnswer(status, body, environment) {
971
+ if (status !== 200)
972
+ return { outcome: "stop", reason: "threeds_init_status" };
973
+ const value = readCreditguardJson(body);
974
+ if (!value)
975
+ return { outcome: "stop", reason: "threeds_init_unreadable" };
976
+ if (value.challengeRequired !== true)
977
+ return { outcome: "frictionless" };
978
+ const stepUpUrl = creditguardCardinalUrl(value.stepUpUrl, "step_up", environment);
979
+ if (!stepUpUrl || typeof value.stepUpJwt !== "string" || value.stepUpJwt.length > 8192 || !JWT.test(value.stepUpJwt)) {
980
+ return { outcome: "stop", reason: "threeds_step_up_unreviewed" };
981
+ }
982
+ return { outcome: "challenge", stepUpUrl, stepUpJwt: value.stepUpJwt };
983
+ }
984
+ function creditguardThreeDSOutcomeAnswer(status, body) {
985
+ const value = status === 200 ? readCreditguardJson(body) : null;
986
+ if (!value)
987
+ return { outcome: "stop", reason: "threeds_outcome_unreadable" };
988
+ return value.cancelled === true ? { outcome: "stop", reason: "threeds_cancelled" } : { outcome: "authenticated" };
989
+ }
990
+ export { CREDITGUARD_CARDINAL_COLLECT_URLS, CREDITGUARD_CARDINAL_HOSTS, CREDITGUARD_COMPANION_PATHS, CREDITGUARD_DEVICE_STEPS, CREDITGUARD_JWE_HEADER, CREDITGUARD_OPERATION, CREDITGUARD_PAGE_WINDOW_MS, CREDITGUARD_PPS_HOSTS, CREDITGUARD_RECAPTCHA_WINDOW_MS, CREDITGUARD_REFUSAL_CODES, CREDITGUARD_SANDBOX_HOST, classifyCreditguardRequest, creditguardBodyRefusal, creditguardBodyTransactionRefusal, creditguardCardinalMessage, creditguardCardinalUrl, creditguardCompanionAnswer, creditguardCompanionCall, creditguardCompanionStep, creditguardDdcAnswer, creditguardDeviceDdcRequest, creditguardDeviceStepRefusal, creditguardDeviceStepUrl, creditguardDeviceThreeDSInitRequest, creditguardDeviceThreeDSOutcomeRequest, creditguardFacts, creditguardNuveiRefusal, creditguardPageProcessUrl, creditguardPpDomainHost, creditguardPreparationEnvironment, creditguardProcessRefusal, creditguardProcessTxId, creditguardRefusalMessage, creditguardReplayRefusal, creditguardResponseOutcome, creditguardSendWindowRefusal, creditguardThreeDSInitAnswer, creditguardThreeDSOutcomeAnswer, creditguardTransactionReadUrl, creditguardTransactionRefusal, encryptCreditguardJwe, injectCreditguardCard, injectCreditguardJweCard, isCreditguardCardinalOrigin, isCreditguardJweCompact, isCreditguardPpsDocument, isCreditguardProcessRequest, isCreditguardProcessUrl, parseCreditguardJwePublicKey, parseCreditguardTransaction, readCreditguardJson, sanitizeCreditguardResponse };
@@ -6,9 +6,15 @@ declare var DATATRANS_CARD_ON_FILE_REFUSED: string;
6
6
  declare var DATATRANS_REGISTRATION_POLICIES: readonly string[];
7
7
  declare var DATATRANS_REGISTRATION_POLICY: string;
8
8
  declare var DATATRANS_REVIEWED_MERCHANT_IDS: Readonly<{
9
- "pay.datatrans.com": readonly never[];
9
+ "pay.datatrans.com": readonly string[];
10
10
  "pay.sandbox.datatrans.com": readonly string[];
11
11
  }>;
12
+ declare var DATATRANS_MERCHANT_ACCOUNT_NAMES: Readonly<{
13
+ "pay.datatrans.com": Readonly<{
14
+ "3000022877": "RaiseNow";
15
+ }>;
16
+ "pay.sandbox.datatrans.com": Readonly<{}>;
17
+ }>;
12
18
  declare var DATATRANS_PAYMENT_METHODS: readonly string[];
13
19
  declare var DATATRANS_TEST_PANS: readonly string[];
14
20
  declare function encodeDatatransFormValue(value: any): string;
@@ -28,11 +34,20 @@ declare function classifyDatatransRequest(url: any, method: any, body: any, head
28
34
  declare function datatransTokenizeRefusal(request: any, card: any, policy?: string): "unsupported" | "card_on_file" | null;
29
35
  declare function isDatatransTokenizeRequest(request: any, card: any): boolean;
30
36
  declare function datatransMerchantRefusal(url: any, body: any, merchants?: Readonly<{
31
- "pay.datatrans.com": readonly never[];
37
+ "pay.datatrans.com": readonly string[];
32
38
  "pay.sandbox.datatrans.com": readonly string[];
33
39
  }>): "unregistered_merchant" | null;
40
+ declare function datatransMerchantAccountName(url: any, body: any, merchants?: Readonly<{
41
+ "pay.datatrans.com": readonly string[];
42
+ "pay.sandbox.datatrans.com": readonly string[];
43
+ }>, names?: Readonly<{
44
+ "pay.datatrans.com": Readonly<{
45
+ "3000022877": "RaiseNow";
46
+ }>;
47
+ "pay.sandbox.datatrans.com": Readonly<{}>;
48
+ }>): string | null;
34
49
  declare function datatransDeviceRefusal(request: any, card: any, policy?: string, merchants?: Readonly<{
35
- "pay.datatrans.com": readonly never[];
50
+ "pay.datatrans.com": readonly string[];
36
51
  "pay.sandbox.datatrans.com": readonly string[];
37
52
  }>): "unsupported" | "card_on_file" | "brand_mismatch" | "unregistered_merchant" | null;
38
53
  declare function datatransRefusalMessage(reason: any): string;
@@ -61,4 +76,4 @@ declare function datatransFacts(status: any, body: any): {
61
76
  outcome: string;
62
77
  refusalCode: string | RegExp | null | undefined;
63
78
  };
64
- export { DATATRANS_CARD_ON_FILE_REFUSED, DATATRANS_HOSTS, DATATRANS_INVALID_REQUEST, DATATRANS_PAYMENT_METHODS, DATATRANS_REFUSAL_REASONS, DATATRANS_REGISTRATION_POLICIES, DATATRANS_REGISTRATION_POLICY, DATATRANS_REVIEWED_MERCHANT_IDS, DATATRANS_TEST_PANS, DATATRANS_TOKENIZE_PATH, classifyDatatransRequest, datatransBodyRefusal, datatransBrandRefusal, datatransCardBrand, datatransCardOnFileDisclosure, datatransDeviceRefusal, datatransErrorCode, datatransFacts, datatransMerchantId, datatransMerchantRefusal, datatransRefusalMessage, datatransRegistrationRefusal, datatransResponseOutcome, datatransTokenizeRefusal, encodeDatatransFormValue, injectDatatransCard, isDatatransTokenizeRequest, isDatatransTokenizeUrl, parseDatatransForm, sanitizeDatatransTokenResponse, serializeDatatransForm };
79
+ export { DATATRANS_CARD_ON_FILE_REFUSED, DATATRANS_HOSTS, DATATRANS_INVALID_REQUEST, DATATRANS_MERCHANT_ACCOUNT_NAMES, DATATRANS_PAYMENT_METHODS, DATATRANS_REFUSAL_REASONS, DATATRANS_REGISTRATION_POLICIES, DATATRANS_REGISTRATION_POLICY, DATATRANS_REVIEWED_MERCHANT_IDS, DATATRANS_TEST_PANS, DATATRANS_TOKENIZE_PATH, classifyDatatransRequest, datatransBodyRefusal, datatransBrandRefusal, datatransCardBrand, datatransCardOnFileDisclosure, datatransDeviceRefusal, datatransErrorCode, datatransFacts, datatransMerchantAccountName, datatransMerchantId, datatransMerchantRefusal, datatransRefusalMessage, datatransRegistrationRefusal, datatransResponseOutcome, datatransTokenizeRefusal, encodeDatatransFormValue, injectDatatransCard, isDatatransTokenizeRequest, isDatatransTokenizeUrl, parseDatatransForm, sanitizeDatatransTokenResponse, serializeDatatransForm };
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  // Generated from @agent-cards/payment-core. Do not edit.
3
- // artifact-sha256: fdee611015d42dc0a679e93a64766ac971b190fcc8f17a107d761c414569e5f9
3
+ // artifact-sha256: 9c00d227ed43d3b5346dba02fe0431f4cc4762fc7d2d9333eeeb34233b0c9844
4
4
  // src/datatrans.js
5
5
  var DATATRANS_HOSTS = Object.freeze(["pay.datatrans.com", "pay.sandbox.datatrans.com"]);
6
6
  var DATATRANS_TOKENIZE_PATH = "/upp/payment/SecureFields/paymentField";
@@ -10,9 +10,13 @@ var DATATRANS_CARD_ON_FILE_REFUSED = "datatrans_card_on_file_refused";
10
10
  var DATATRANS_REGISTRATION_POLICIES = Object.freeze(["refuse", "disclose", "agentcard_single_use"]);
11
11
  var DATATRANS_REGISTRATION_POLICY = "refuse";
12
12
  var DATATRANS_REVIEWED_MERCHANT_IDS = Object.freeze({
13
- "pay.datatrans.com": Object.freeze([]),
13
+ "pay.datatrans.com": Object.freeze(["3000022877"]),
14
14
  "pay.sandbox.datatrans.com": Object.freeze(["1110022968", "1100007006"])
15
15
  });
16
+ var DATATRANS_MERCHANT_ACCOUNT_NAMES = Object.freeze({
17
+ "pay.datatrans.com": Object.freeze({ "3000022877": "RaiseNow" }),
18
+ "pay.sandbox.datatrans.com": Object.freeze({})
19
+ });
16
20
  var DATATRANS_PAYMENT_METHODS = Object.freeze(["VIS", "ECA", "AMX", "DIN", "DIS", "JCB", "CUP", "MAU", "UAP", "DNK"]);
17
21
  var DATATRANS_TEST_PANS = Object.freeze([
18
22
  "4242424242424242",
@@ -268,6 +272,14 @@ function datatransMerchantRefusal(url, body, merchants = DATATRANS_REVIEWED_MERC
268
272
  const listed = record(merchants) && owns(merchants, host) && Array.isArray(merchants[host]) ? merchants[host] : [];
269
273
  return merchantId !== null && listed.includes(merchantId) ? null : "unregistered_merchant";
270
274
  }
275
+ function datatransMerchantAccountName(url, body, merchants = DATATRANS_REVIEWED_MERCHANT_IDS, names = DATATRANS_MERCHANT_ACCOUNT_NAMES) {
276
+ if (!isDatatransTokenizeUrl(url) || datatransMerchantRefusal(url, body, merchants) !== null)
277
+ return null;
278
+ const host = new URL(url).hostname, merchantId = datatransMerchantId(body);
279
+ const named = record(names) && owns(names, host) && record(names[host]) ? names[host] : null;
280
+ const name = named && owns(named, merchantId) ? named[merchantId] : null;
281
+ return typeof name === "string" && name.trim() !== "" && plain(name, 64) ? name : null;
282
+ }
271
283
  function datatransDeviceRefusal(request, card, policy = DATATRANS_REGISTRATION_POLICY, merchants = DATATRANS_REVIEWED_MERCHANT_IDS) {
272
284
  const refusal = datatransTokenizeRefusal(request, card, policy);
273
285
  if (refusal)
@@ -426,4 +438,4 @@ function datatransFacts(status, body) {
426
438
  const verdict = datatransResponseOutcome(status, body);
427
439
  return { outcome: verdict.outcome, refusalCode: verdict.outcome === "refused" ? verdict.code : null };
428
440
  }
429
- export { DATATRANS_CARD_ON_FILE_REFUSED, DATATRANS_HOSTS, DATATRANS_INVALID_REQUEST, DATATRANS_PAYMENT_METHODS, DATATRANS_REFUSAL_REASONS, DATATRANS_REGISTRATION_POLICIES, DATATRANS_REGISTRATION_POLICY, DATATRANS_REVIEWED_MERCHANT_IDS, DATATRANS_TEST_PANS, DATATRANS_TOKENIZE_PATH, classifyDatatransRequest, datatransBodyRefusal, datatransBrandRefusal, datatransCardBrand, datatransCardOnFileDisclosure, datatransDeviceRefusal, datatransErrorCode, datatransFacts, datatransMerchantId, datatransMerchantRefusal, datatransRefusalMessage, datatransRegistrationRefusal, datatransResponseOutcome, datatransTokenizeRefusal, encodeDatatransFormValue, injectDatatransCard, isDatatransTokenizeRequest, isDatatransTokenizeUrl, parseDatatransForm, sanitizeDatatransTokenResponse, serializeDatatransForm };
441
+ export { DATATRANS_CARD_ON_FILE_REFUSED, DATATRANS_HOSTS, DATATRANS_INVALID_REQUEST, DATATRANS_MERCHANT_ACCOUNT_NAMES, DATATRANS_PAYMENT_METHODS, DATATRANS_REFUSAL_REASONS, DATATRANS_REGISTRATION_POLICIES, DATATRANS_REGISTRATION_POLICY, DATATRANS_REVIEWED_MERCHANT_IDS, DATATRANS_TEST_PANS, DATATRANS_TOKENIZE_PATH, classifyDatatransRequest, datatransBodyRefusal, datatransBrandRefusal, datatransCardBrand, datatransCardOnFileDisclosure, datatransDeviceRefusal, datatransErrorCode, datatransFacts, datatransMerchantAccountName, datatransMerchantId, datatransMerchantRefusal, datatransRefusalMessage, datatransRegistrationRefusal, datatransResponseOutcome, datatransTokenizeRefusal, encodeDatatransFormValue, injectDatatransCard, isDatatransTokenizeRequest, isDatatransTokenizeUrl, parseDatatransForm, sanitizeDatatransTokenResponse, serializeDatatransForm };
@@ -0,0 +1,107 @@
1
+ export declare const EBANX_RESEND_REASON: "unsupported_ebanx_card_resend";
2
+ /** Why the gate refuses a request (payment-core EBANX_RESEND_REFUSALS). */
3
+ export type EbanxResendRefusal = 'three_ds_card' | 'confirm_card_code' | 'unreadable';
4
+ /** The sends one approval covers, in EBANX.js's order (payment-core EBANX_FOLLOW_UP_KINDS). */
5
+ export type EbanxFollowUpKind = 'generate_token' | 'authentications' | 'authentication_results' | 'confirm';
6
+ /** EBANX's hosts for these requests (payment-core EBANX_RESEND_HOSTS). */
7
+ export declare const EBANX_RESEND_HOSTS: readonly string[];
8
+ /**
9
+ * CDP Fetch patterns for the 3-D Secure calls and the confirm on each of EBANX's hosts, armed on every attachment.
10
+ * The card recognizer already arms every request on the hosts it names; these keep both requests armed for a client
11
+ * whose registry names no EBANX host. The -record call matches the 3-D Secure pattern too and continues untouched.
12
+ * The third pattern arms any address on the host that holds a percent-escape, since CDP matches the address as written
13
+ * and a server may decode /ws/%63heckout-v2/confirm to the confirm: the gate decodes the path the same way
14
+ * (payment-core ebanxResendKind) and continues every one that is not a card send. CDP matches literally and in one
15
+ * letter case, so the tenant host only the confirm uses (CONFIRM_TENANT_HOST) is armed whole, its host text anywhere
16
+ * in the address as the card recognizer arms its own hosts: /WS/CHECKOUT-V2/CONFIRM, //, ;x=1 and a trailing-dot
17
+ * host all pause, and the gate judges each one.
18
+ */
19
+ export declare const EBANX_RESEND_PATTERNS: readonly string[];
20
+ /**
21
+ * Whether this URL is one of the three 3-D Secure calls that carry the card or the hosted page's confirm on an EBANX
22
+ * host, or an EBANX path still percent-encoded after the last decoding round, which the gate refuses as unreadable.
23
+ */
24
+ export declare function isEbanxResendUrl(url: string): boolean;
25
+ /**
26
+ * Why this request must not leave the browser with the card the page holds, or null when it may. The body is read
27
+ * only for a confirm, through `readBody`, and a reader that throws reads as a body nobody could read.
28
+ */
29
+ export declare function ebanxResendRefusalOf(url: string, method: string, readBody: () => string | null): EbanxResendRefusal | null;
30
+ /**
31
+ * A send the cardholder's device did not answer with EBANX's own answer. `reason` is the API's word for it:
32
+ * `not_picked_up` (no device started it in time: the Vault page was closed or asleep), `not_sent` (the device
33
+ * refused it before the card left), `no_answer`, `answer_withheld` (EBANX's answer carried the card),
34
+ * `answer_refused`, `answer_late`, `response_expired`, or the API's refusal code when it did not take the send at
35
+ * all (`follow_up_refused`, `follow_up_not_covered`, `follow_up_window_closed`). `cardSent` says whether the card
36
+ * may have reached EBANX: false only when the API confirmed it never left the device. Nothing in it names the
37
+ * request, the card or EBANX's answer.
38
+ */
39
+ export declare class EbanxFollowUpError extends Error {
40
+ readonly reason: string;
41
+ readonly cardSent: boolean;
42
+ readonly authorizationId: string;
43
+ constructor(reason: string, cardSent: boolean, authorizationId: string);
44
+ }
45
+ /** A send this attachment claimed: the approval it goes under, its kind, the request to send, and how it ended. */
46
+ export interface EbanxFollowUpClaim {
47
+ readonly authorizationId: string;
48
+ readonly kind: EbanxFollowUpKind;
49
+ readonly until: number;
50
+ readonly request: {
51
+ url: string;
52
+ method: 'POST';
53
+ headers: Record<string, string>;
54
+ body: string;
55
+ };
56
+ /** Record the answer the page received, or null when the send failed. */
57
+ settle(answer: {
58
+ status: number;
59
+ text: string;
60
+ } | null): void;
61
+ }
62
+ /**
63
+ * What one attachment keeps of its approved EBANX token request: the request and EBANX's answer as the page received
64
+ * them, until when the API said the approval covers sends after it, and the sends it claimed since, in order. Only
65
+ * a token approval whose read named that window (`followUpsUntil`, served for a company Agentcard turned it on for)
66
+ * is kept; a later approval replaces it, and a send the window has passed is never claimed. Once the gate refuses a
67
+ * send or a send fails, the attachment stops (stop()): nothing after it is claimed, a later approval included, so
68
+ * a page the controller already reads as stopped cannot finish 3-D Secure and pay through the confirm.
69
+ */
70
+ export declare class EbanxFollowUps {
71
+ private parent;
72
+ private sent;
73
+ private stopped;
74
+ /** After a refused or failed send: no later request on this attachment is claimed. */
75
+ stop(): void;
76
+ /**
77
+ * The approval the remembered token request went under, or null when none is remembered. The gate sends nothing
78
+ * unless the checkout's own state names this same approval (pre-claim.ts ebanxMaySend).
79
+ */
80
+ get authorizationId(): string | null;
81
+ /**
82
+ * As the adapter hands an approved token request's answer to the page: before the answer lands, since the page may
83
+ * send its first 3-D Secure call at once. A handoff that fails then stops the attachment (stop()).
84
+ */
85
+ remember(request: {
86
+ url: string;
87
+ body: string;
88
+ }, replay: {
89
+ mode?: string;
90
+ authorizationId: string;
91
+ status: number;
92
+ body: string;
93
+ followUpsUntil?: string;
94
+ }): void;
95
+ /**
96
+ * The claim for a paused request the remembered approval covers, or null: no approval covers sends here, its
97
+ * window has passed, or payment-core's rule refuses the request against the sends already claimed (the amount
98
+ * is left to the API and the device, which hold the approved figure). Synchronous, and it reserves the send, so
99
+ * two requests can never both be claimed as the next one.
100
+ */
101
+ claim(request: {
102
+ url: string;
103
+ method: string;
104
+ headers: Record<string, string>;
105
+ body: string | null;
106
+ }, now?: number): EbanxFollowUpClaim | null;
107
+ }
@@ -0,0 +1,78 @@
1
+ declare var EBANX_RESEND_HOSTS: readonly string[];
2
+ declare var EBANX_THREE_DS_CARD_PATHS: readonly string[];
3
+ declare var EBANX_CONFIRM_PATH: string;
4
+ declare var EBANX_RESEND_REFUSALS: readonly string[];
5
+ declare function ebanxResendKind(url: any): "unreadable" | "confirm" | "three_ds" | null;
6
+ declare function ebanxResendRefusal(request: any): "unreadable" | "three_ds_card" | "confirm_card_code" | null;
7
+ declare var EBANX_FOLLOW_UP_KINDS: readonly string[];
8
+ declare var EBANX_FOLLOW_UP_LIMITS: Readonly<{
9
+ generate_token: 1;
10
+ authentications: 1;
11
+ authentication_results: 48;
12
+ confirm: 1;
13
+ }>;
14
+ declare var EBANX_FOLLOW_UP_MAX: number;
15
+ declare var EBANX_FOLLOW_UP_WINDOW_MS: number;
16
+ declare var EBANX_FOLLOW_UP_IDLE_MS: number;
17
+ declare var EBANX_FOLLOW_UP_CHALLENGE_MS: number;
18
+ declare var EBANX_FOLLOW_UP_BODY_LIMIT: number;
19
+ declare var EBANX_FOLLOW_UP_ANSWER_LIMIT: number;
20
+ declare var EBANX_FOLLOW_UP_REFUSALS: readonly string[];
21
+ declare function ebanxFollowUpKind(url: any): "confirm" | "generate_token" | "authentications" | "authentication_results" | null;
22
+ declare function readEbanxTokenRequest(template: any): Readonly<{
23
+ host: string;
24
+ number: string;
25
+ month: number;
26
+ year: number;
27
+ cvv: string | null;
28
+ name: string | null;
29
+ publicIntegrationKey: any;
30
+ country: any;
31
+ }> | null;
32
+ declare function readEbanxTokenAnswer(answer: any): Readonly<{
33
+ token: any;
34
+ paymentTypeCode: any;
35
+ cardUniqueId: any;
36
+ }> | null;
37
+ declare var EBANX_PAYING_STATUSES: readonly string[];
38
+ declare function ebanxAnswerRefusal(status: any, answerText: any): string | null;
39
+ declare var EBANX_THREE_DS_FAILED: string;
40
+ declare var EBANX_THREE_DS_FAILED_CODE: string;
41
+ declare function ebanxAnswerOutcome(status: any, answerText: any, url: any): {
42
+ outcome: string;
43
+ code: string;
44
+ reason?: undefined;
45
+ } | {
46
+ outcome: string;
47
+ code?: undefined;
48
+ reason?: undefined;
49
+ } | {
50
+ outcome: string;
51
+ reason: string;
52
+ code?: undefined;
53
+ } | null;
54
+ declare function ebanxAnswerSession(answerText: any): Readonly<{
55
+ paymentId: any;
56
+ accessToken: any;
57
+ status: any;
58
+ }>;
59
+ declare function ebanxFollowUpIdleMs(kind: any, answerText: any): number;
60
+ declare function ebanxFollowUpVerdict(input: any, options?: {}): Readonly<{
61
+ ok: false;
62
+ refusal: any;
63
+ }> | Readonly<{
64
+ ok: true;
65
+ kind: "confirm";
66
+ slot: number;
67
+ }> | Readonly<{
68
+ ok: true;
69
+ kind: "generate_token";
70
+ slot: number;
71
+ }> | Readonly<{
72
+ ok: true;
73
+ kind: "authentications" | "authentication_results";
74
+ slot: number;
75
+ }>;
76
+ declare function ebanxFollowUpAnswerRefusal(answerText: any): "answer_unreadable" | "card_in_answer" | null;
77
+ declare function isEbanxThreeDsFollowUp(kind: any): boolean;
78
+ export { EBANX_CONFIRM_PATH, EBANX_FOLLOW_UP_ANSWER_LIMIT, EBANX_FOLLOW_UP_BODY_LIMIT, EBANX_FOLLOW_UP_CHALLENGE_MS, EBANX_FOLLOW_UP_IDLE_MS, EBANX_FOLLOW_UP_KINDS, EBANX_FOLLOW_UP_LIMITS, EBANX_FOLLOW_UP_MAX, EBANX_FOLLOW_UP_REFUSALS, EBANX_FOLLOW_UP_WINDOW_MS, EBANX_PAYING_STATUSES, EBANX_RESEND_HOSTS, EBANX_RESEND_REFUSALS, EBANX_THREE_DS_CARD_PATHS, EBANX_THREE_DS_FAILED, EBANX_THREE_DS_FAILED_CODE, ebanxAnswerOutcome, ebanxAnswerRefusal, ebanxAnswerSession, ebanxFollowUpAnswerRefusal, ebanxFollowUpIdleMs, ebanxFollowUpKind, ebanxFollowUpVerdict, ebanxResendKind, ebanxResendRefusal, isEbanxThreeDsFollowUp, readEbanxTokenAnswer, readEbanxTokenRequest };