@agent-cards/sdk 0.21.0 → 0.22.0

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/PREFLIGHT.md +30 -0
  3. package/README.md +1070 -21
  4. package/dist/aci.d.ts +173 -0
  5. package/dist/aci.generated.d.ts +87 -0
  6. package/dist/aci.generated.js +306 -0
  7. package/dist/aci.js +371 -0
  8. package/dist/adyen-merchant-hosted.generated.d.ts +3 -3
  9. package/dist/adyen-merchant-hosted.generated.js +283 -49
  10. package/dist/agentcard.d.ts +9 -2
  11. package/dist/agentcard.js +4 -2
  12. package/dist/amadeus-checkout.generated.d.ts +57 -0
  13. package/dist/amadeus-checkout.generated.js +549 -0
  14. package/dist/amadeus.d.ts +41 -0
  15. package/dist/amadeus.js +81 -0
  16. package/dist/builtin-registry.generated.js +1 -1
  17. package/dist/card-endpoint.d.ts +177 -0
  18. package/dist/card-endpoint.js +286 -0
  19. package/dist/card-fields.generated.d.ts +5 -3
  20. package/dist/card-fields.generated.js +284 -7
  21. package/dist/cdp.d.ts +5 -1
  22. package/dist/cdp.js +841 -135
  23. package/dist/client.d.ts +403 -19
  24. package/dist/client.js +949 -98
  25. package/dist/creditguard.generated.d.ts +79 -0
  26. package/dist/creditguard.generated.js +662 -0
  27. package/dist/cse-body.js +11 -1
  28. package/dist/datatrans.d.ts +96 -0
  29. package/dist/datatrans.generated.d.ts +64 -0
  30. package/dist/datatrans.generated.js +426 -0
  31. package/dist/datatrans.js +178 -0
  32. package/dist/elavon-converge.d.ts +37 -0
  33. package/dist/elavon-converge.generated.d.ts +49 -0
  34. package/dist/elavon-converge.generated.js +439 -0
  35. package/dist/elavon-converge.js +84 -0
  36. package/dist/eprotect.d.ts +152 -0
  37. package/dist/eprotect.generated.d.ts +77 -0
  38. package/dist/eprotect.generated.js +498 -0
  39. package/dist/eprotect.js +222 -0
  40. package/dist/hosted-form.d.ts +3 -2
  41. package/dist/hosted-form.js +3 -2
  42. package/dist/index.d.ts +17 -3
  43. package/dist/index.js +6 -1
  44. package/dist/juspay-gate.d.ts +82 -0
  45. package/dist/juspay-gate.js +126 -0
  46. package/dist/juspay.generated.d.ts +89 -0
  47. package/dist/juspay.generated.js +705 -0
  48. package/dist/lifecycle.d.ts +57 -6
  49. package/dist/lifecycle.js +119 -8
  50. package/dist/merchant-card-endpoints.generated.d.ts +63 -0
  51. package/dist/merchant-card-endpoints.generated.js +1103 -0
  52. package/dist/merchant-hosted.d.ts +4 -1
  53. package/dist/merchant-hosted.js +5 -2
  54. package/dist/merchant-session-probe.d.ts +48 -0
  55. package/dist/merchant-session-probe.js +53 -0
  56. package/dist/merchant-session.generated.d.ts +69 -0
  57. package/dist/merchant-session.generated.js +919 -0
  58. package/dist/payrails.d.ts +133 -0
  59. package/dist/payrails.generated.d.ts +73 -0
  60. package/dist/payrails.generated.js +596 -0
  61. package/dist/payrails.js +305 -0
  62. package/dist/pelecard.d.ts +32 -0
  63. package/dist/pelecard.generated.d.ts +32 -0
  64. package/dist/pelecard.generated.js +283 -0
  65. package/dist/pelecard.js +42 -0
  66. package/dist/pre-claim.d.ts +72 -2
  67. package/dist/pre-claim.js +857 -5
  68. package/dist/preflight-catalog.json +2218 -287
  69. package/dist/preflight-schemas.json +179 -6
  70. package/dist/preflight.generated.d.ts +1 -1
  71. package/dist/preflight.generated.js +233 -4
  72. package/dist/preparation.d.ts +5 -2
  73. package/dist/preparation.js +36 -10
  74. package/dist/prepared-processor.d.ts +84 -5
  75. package/dist/prepared-processor.js +147 -6
  76. package/dist/primer.d.ts +53 -0
  77. package/dist/primer.generated.d.ts +38 -0
  78. package/dist/primer.generated.js +624 -0
  79. package/dist/primer.js +82 -0
  80. package/dist/registry.d.ts +100 -8
  81. package/dist/registry.js +85 -11
  82. package/dist/shiji-sts.d.ts +144 -0
  83. package/dist/shiji-sts.generated.d.ts +72 -0
  84. package/dist/shiji-sts.generated.js +913 -0
  85. package/dist/shiji-sts.js +222 -0
  86. package/dist/stripe-checkout.generated.d.ts +1 -1
  87. package/dist/stripe-checkout.generated.js +699 -9
  88. package/dist/stripe-setup.d.ts +16 -0
  89. package/dist/stripe-setup.js +61 -0
  90. package/dist/substitutions.generated.js +187 -29
  91. package/dist/verifone.d.ts +68 -0
  92. package/dist/verifone.generated.d.ts +51 -0
  93. package/dist/verifone.generated.js +1401 -0
  94. package/dist/verifone.js +119 -0
  95. package/dist/voice-types.d.ts +27 -0
  96. package/dist/voice.d.ts +6 -1
  97. package/dist/voice.js +6 -1
  98. package/dist/wspay.d.ts +41 -0
  99. package/dist/wspay.generated.d.ts +41 -0
  100. package/dist/wspay.generated.js +370 -0
  101. package/dist/wspay.js +65 -0
  102. package/examples/preflight/kernel-native/inventory.json +1 -1
  103. package/package.json +3 -3
@@ -0,0 +1,662 @@
1
+ // @ts-nocheck
2
+ // Generated from @agent-cards/payment-core. Do not edit.
3
+ // artifact-sha256: 83caafdf10afb4617e5eb3a896d3a1ba4b5c098747495658529c5d13798051cc
4
+ // src/creditguard.js
5
+ var CREDITGUARD_PPS_HOSTS = Object.freeze(["pps.creditguard.co.il", "pps2.creditguard.co.il", "ppsuat.creditguard.co.il"]);
6
+ var CREDITGUARD_SANDBOX_HOST = "ppsuat.creditguard.co.il";
7
+ var CREDITGUARD_OPERATION = "creditguard.card_request";
8
+ var CREDITGUARD_JWE_HEADER = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ";
9
+ var CREDITGUARD_RECAPTCHA_WINDOW_MS = 11e4;
10
+ var CREDITGUARD_PAGE_WINDOW_MS = 6e5;
11
+ var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
12
+ var PROCESS_PATH = new RegExp(`^/services/v1/txn/(${UUID})/process$`);
13
+ var TXID = new RegExp(`^${UUID}$`);
14
+ var PROCESS_ENDPOINT = /^\/services\/v1\/txn\/[^/]+\/process\/?$/i;
15
+ var NUVEI_HOSTS = ["secure.safecharge.com", "ppp-test.safecharge.com"];
16
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
17
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
18
+ var owns = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
19
+ var exact = (pattern, value) => typeof value === "string" && pattern.exec(value)?.[0] === value;
20
+ var text = (value, max) => typeof value === "string" && value.length <= max && !/[\u0000-\u001f\u007f]/.test(value);
21
+ var digits = (value, min, max) => typeof value === "string" && value.length >= min && value.length <= max && !/[^0-9]/.test(value);
22
+ var HOSTNAME = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/;
23
+ function readCreditguardJson(body, limit = 65536, maxNodes = 1024) {
24
+ if (typeof body !== "string" || body === "" || body.length > limit)
25
+ return null;
26
+ let at = 0, nodes = 0;
27
+ const fail = () => {
28
+ throw new Error("invalid_creditguard_json");
29
+ };
30
+ const space = () => {
31
+ while (at < body.length && " \r\n".includes(body[at]))
32
+ at++;
33
+ };
34
+ const string = () => {
35
+ space();
36
+ const start = at;
37
+ if (body[at++] !== '"')
38
+ fail();
39
+ while (at < body.length) {
40
+ const char = body[at++];
41
+ if (char === "\\") {
42
+ at++;
43
+ continue;
44
+ }
45
+ if (char === '"')
46
+ return JSON.parse(body.slice(start, at));
47
+ }
48
+ return fail();
49
+ };
50
+ const value = (depth) => {
51
+ if (depth > 8 || ++nodes > maxNodes)
52
+ fail();
53
+ space();
54
+ const char = body[at];
55
+ if (char === '"')
56
+ return string();
57
+ if (char === "{") {
58
+ at++;
59
+ const result = /* @__PURE__ */ Object.create(null), seen = /* @__PURE__ */ new Set();
60
+ space();
61
+ if (body[at] === "}") {
62
+ at++;
63
+ return result;
64
+ }
65
+ for (;;) {
66
+ const key = string();
67
+ if (seen.has(key) || FORBIDDEN_KEYS.has(key))
68
+ fail();
69
+ seen.add(key);
70
+ space();
71
+ if (body[at++] !== ":")
72
+ fail();
73
+ result[key] = value(depth + 1);
74
+ space();
75
+ const next = body[at++];
76
+ if (next === "}")
77
+ return result;
78
+ if (next !== ",")
79
+ fail();
80
+ }
81
+ }
82
+ if (char === "[") {
83
+ at++;
84
+ const result = [];
85
+ space();
86
+ if (body[at] === "]") {
87
+ at++;
88
+ return result;
89
+ }
90
+ for (;;) {
91
+ result.push(value(depth + 1));
92
+ space();
93
+ const next = body[at++];
94
+ if (next === "]")
95
+ return result;
96
+ if (next !== ",")
97
+ fail();
98
+ }
99
+ }
100
+ for (const literal of ["true", "false", "null"]) {
101
+ if (body.startsWith(literal, at)) {
102
+ at += literal.length;
103
+ return JSON.parse(literal);
104
+ }
105
+ }
106
+ const number = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(body.slice(at, at + 32));
107
+ if (!number)
108
+ fail();
109
+ at += number[0].length;
110
+ const parsed = Number(number[0]);
111
+ if (!Number.isFinite(parsed))
112
+ fail();
113
+ return parsed;
114
+ };
115
+ try {
116
+ const parsed = value(0);
117
+ space();
118
+ return at === body.length && record(parsed) ? parsed : null;
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ }
124
+ function httpsUrl(url, maxLength = 512) {
125
+ if (typeof url !== "string" || url.length > maxLength)
126
+ return null;
127
+ let parsed;
128
+ try {
129
+ parsed = new URL(url);
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ if (parsed.protocol !== "https:" || parsed.port || parsed.username || parsed.password)
135
+ return null;
136
+ return parsed;
137
+ }
138
+ function creditguardProcessTxId(url) {
139
+ if (typeof url !== "string" || url.includes("?") || url.includes("#"))
140
+ return null;
141
+ const parsed = httpsUrl(url);
142
+ if (!parsed || parsed.href !== url || !CREDITGUARD_PPS_HOSTS.includes(parsed.hostname))
143
+ return null;
144
+ return PROCESS_PATH.exec(parsed.pathname)?.[1] ?? null;
145
+ }
146
+ function isCreditguardProcessUrl(url, method = "POST") {
147
+ return method === "POST" && creditguardProcessTxId(url) !== null;
148
+ }
149
+ function isProcessEndpoint(url) {
150
+ const parsed = httpsUrl(url, 4096);
151
+ return !!parsed && CREDITGUARD_PPS_HOSTS.includes(parsed.hostname.toLowerCase()) && PROCESS_ENDPOINT.test(parsed.pathname);
152
+ }
153
+ function creditguardPreparationEnvironment(hostname) {
154
+ const host = typeof hostname === "string" ? hostname.toLowerCase() : "";
155
+ if (host === CREDITGUARD_SANDBOX_HOST)
156
+ return "sandbox";
157
+ return CREDITGUARD_PPS_HOSTS.includes(host) ? "production" : null;
158
+ }
159
+ function creditguardTransactionReadUrl(processUrl) {
160
+ const txId = creditguardProcessTxId(processUrl);
161
+ return txId === null ? null : `https://${new URL(processUrl).hostname}/services/v1/txn/${txId}`;
162
+ }
163
+ function creditguardPageProcessUrl(pageUrl) {
164
+ if (typeof pageUrl !== "string" || pageUrl.length > 2048 || pageUrl.includes("#"))
165
+ return null;
166
+ const page = httpsUrl(pageUrl, 2048);
167
+ if (!page || page.pathname !== "/")
168
+ return null;
169
+ const ids = page.searchParams.getAll("txId");
170
+ if (ids.length !== 1 || !TXID.test(ids[0]))
171
+ return null;
172
+ const processUrl = `https://${page.hostname}/services/v1/txn/${ids[0]}/process`;
173
+ return creditguardProcessTxId(processUrl) === ids[0] ? processUrl : null;
174
+ }
175
+ function isCreditguardPpsDocument(url) {
176
+ const parsed = httpsUrl(url, 4096);
177
+ return !!parsed && CREDITGUARD_PPS_HOSTS.includes(parsed.hostname.toLowerCase());
178
+ }
179
+ function creditguardNuveiRefusal(requestUrl, initiatorUrl) {
180
+ const request = httpsUrl(requestUrl, 4096);
181
+ if (!request || !NUVEI_HOSTS.includes(request.hostname.toLowerCase()))
182
+ return null;
183
+ return isCreditguardPpsDocument(initiatorUrl) ? "creditguard_three_d_secure" : null;
184
+ }
185
+ var CARD_KEYS = ["cardNumber", "expMonth", "expYear", "cvv"];
186
+ var REFUSED_KEYS = Object.freeze({
187
+ cardId: "saved_card",
188
+ track2CardNo: "saved_card",
189
+ last4d: "saved_card",
190
+ enteredOTP: "otp",
191
+ googlePayToken: "wallet",
192
+ applePayToken: "wallet"
193
+ });
194
+ var JWE_MOVED_KEYS = ["cardNumber", "expMonth", "expYear", "track2CardNo", "cvv", "last4d", "personalId"];
195
+ var USER_DATA_KEYS = Array.from({ length: 10 }, (_, index) => `userData${index + 1}`);
196
+ var OTHER_KEYS = /* @__PURE__ */ new Set([
197
+ "personalId",
198
+ "expDateMMYY",
199
+ "txId",
200
+ "recaptchaValue",
201
+ "recaptchaV3Value",
202
+ "recaptchaChallenge",
203
+ "numberOfPayments",
204
+ "keepCCDetails",
205
+ "pendingGiftCards",
206
+ "useDcc",
207
+ "dccOption",
208
+ "isIframe",
209
+ "ppDomain",
210
+ "windowSize",
211
+ "jwePayload",
212
+ ...USER_DATA_KEYS
213
+ ]);
214
+ var TOKEN = /^[A-Za-z0-9_.:+/=-]{1,8192}$/;
215
+ var BASE64URL_SEGMENT = /^[A-Za-z0-9_-]+$/;
216
+ var absent = (value, key) => !owns(value, key) || value[key] === null;
217
+ var optionalFlag = (value, key) => absent(value, key) || value[key] === false;
218
+ function isCreditguardJweCompact(value) {
219
+ if (typeof value !== "string" || value.length > 4096)
220
+ return false;
221
+ const parts = value.split(".");
222
+ if (parts.length !== 5 || !parts.every((part) => BASE64URL_SEGMENT.test(part)))
223
+ return false;
224
+ const [header, key, iv, ciphertext, tag] = parts;
225
+ return header === CREDITGUARD_JWE_HEADER && key.length >= 342 && key.length <= 683 && iv.length === 16 && tag.length === 22 && ciphertext.length >= 2 && ciphertext.length <= 2048;
226
+ }
227
+ function creditguardPpDomainHost(ppDomain) {
228
+ if (ppDomain === "")
229
+ return "";
230
+ if (typeof ppDomain !== "string" || ppDomain.length > 400 || !/^[A-Za-z0-9+/]+={0,2}$/.test(ppDomain) || ppDomain.length % 4 !== 0)
231
+ return null;
232
+ let decoded;
233
+ try {
234
+ decoded = atob(ppDomain);
235
+ }
236
+ catch {
237
+ return null;
238
+ }
239
+ return HOSTNAME.test(decoded) ? decoded : null;
240
+ }
241
+ function installmentsRefusal(value) {
242
+ if (absent(value, "numberOfPayments"))
243
+ return null;
244
+ const count = value.numberOfPayments;
245
+ if (count === "" || count === 0 || count === "0")
246
+ return null;
247
+ return "installments";
248
+ }
249
+ function boundMerchantHost(options) {
250
+ if (!record(options) || !owns(options, "merchantHost") || options.merchantHost === void 0)
251
+ return void 0;
252
+ const host = typeof options.merchantHost === "string" ? options.merchantHost.toLowerCase() : "";
253
+ return HOSTNAME.test(host) ? host : null;
254
+ }
255
+ function cardFieldsRefusal(value) {
256
+ if (!CARD_KEYS.every((key) => owns(value, key)))
257
+ return "card_fields";
258
+ 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))
259
+ return "card_fields";
260
+ if (owns(value, "expDateMMYY") && value.expDateMMYY !== `${value.expMonth}/${value.expYear}`)
261
+ return "card_fields";
262
+ return null;
263
+ }
264
+ function bodyRefusal(value, txId, options) {
265
+ const merchant = boundMerchantHost(options);
266
+ if (merchant === null)
267
+ return "pp_domain_unbound";
268
+ if (!record(value))
269
+ return "malformed_body";
270
+ for (const [key, reason] of Object.entries(REFUSED_KEYS))
271
+ if (owns(value, key))
272
+ return reason;
273
+ for (const key of Object.keys(value))
274
+ if (!CARD_KEYS.includes(key) && !OTHER_KEYS.has(key))
275
+ return "unexpected_field";
276
+ if (!optionalFlag(value, "keepCCDetails"))
277
+ return "keep_on_file";
278
+ if (!optionalFlag(value, "pendingGiftCards"))
279
+ return "gift_card";
280
+ if (!optionalFlag(value, "useDcc"))
281
+ return "dcc";
282
+ const installments = installmentsRefusal(value);
283
+ if (installments)
284
+ return installments;
285
+ if (!absent(value, "personalId") && value.personalId !== "")
286
+ return "personal_id";
287
+ if (owns(value, "txId") && (!exact(TXID, value.txId) || txId !== void 0 && value.txId !== txId))
288
+ return "txid_mismatch";
289
+ if (!absent(value, "ppDomain")) {
290
+ const host = creditguardPpDomainHost(value.ppDomain);
291
+ if (host === null)
292
+ return "pp_domain";
293
+ if (merchant !== void 0 && host !== merchant)
294
+ return "pp_domain";
295
+ }
296
+ else if (merchant !== void 0)
297
+ return "pp_domain";
298
+ if (!absent(value, "isIframe") && typeof value.isIframe !== "boolean")
299
+ return "malformed_body";
300
+ if (!absent(value, "windowSize") && !exact(/^[0-9]{1,5}x[0-9]{1,5}$/, value.windowSize))
301
+ return "malformed_body";
302
+ for (const key of ["recaptchaValue", "recaptchaV3Value"]) {
303
+ if (!absent(value, key) && value[key] !== "" && !exact(TOKEN, value[key]))
304
+ return "malformed_body";
305
+ }
306
+ if (!absent(value, "recaptchaChallenge") && typeof value.recaptchaChallenge !== "boolean" && !exact(TOKEN, value.recaptchaChallenge))
307
+ return "malformed_body";
308
+ if (!absent(value, "dccOption") && typeof value.dccOption !== "boolean" && !exact(/^[A-Za-z0-9_-]{1,32}$/, value.dccOption))
309
+ return "malformed_body";
310
+ for (const key of USER_DATA_KEYS) {
311
+ if (!absent(value, key) && !text(value[key], 2048) && !Number.isSafeInteger(value[key]))
312
+ return "malformed_body";
313
+ }
314
+ if (owns(value, "jwePayload")) {
315
+ if (typeof value.jwePayload !== "string" || !isCreditguardJweCompact(value.jwePayload))
316
+ return "jwe_fallback";
317
+ if (JWE_MOVED_KEYS.some((key) => owns(value, key)) || owns(value, "expDateMMYY"))
318
+ return "jwe_fallback";
319
+ return record(options) && options.jwe === true ? null : "jwe_unsupported";
320
+ }
321
+ return cardFieldsRefusal(value);
322
+ }
323
+ function creditguardBodyRefusal(body, txId, options) {
324
+ return bodyRefusal(readCreditguardJson(body), txId, options);
325
+ }
326
+ function classifyCreditguardRequest(url, method, body, options) {
327
+ if (!isProcessEndpoint(url))
328
+ return null;
329
+ if (method !== "POST")
330
+ return "unsupported";
331
+ const txId = creditguardProcessTxId(url);
332
+ if (txId === null)
333
+ return "unsupported";
334
+ return creditguardBodyRefusal(typeof body === "string" ? body : "", txId, options) === null ? "card" : "unsupported";
335
+ }
336
+ var CONTENT_TYPE = /^application\/json(?:;\s*charset=utf-8)?$/i;
337
+ var ACCEPT_RANGES = /* @__PURE__ */ new Set(["application/json", "text/plain", "*/*"]);
338
+ function headersRefusal(headers) {
339
+ if (headers === void 0)
340
+ return null;
341
+ if (!record(headers))
342
+ return "headers";
343
+ const seen = /* @__PURE__ */ new Map();
344
+ for (const [name, value] of Object.entries(headers)) {
345
+ const lower = name.toLowerCase();
346
+ if (seen.has(lower) || typeof value !== "string")
347
+ return "headers";
348
+ seen.set(lower, value);
349
+ }
350
+ if (seen.has("content-type") && !exact(CONTENT_TYPE, seen.get("content-type")))
351
+ return "headers";
352
+ if (seen.has("accept")) {
353
+ if (!text(seen.get("accept"), 1024))
354
+ return "headers";
355
+ const ranges = seen.get("accept").split(",").map((range) => range.trim().toLowerCase());
356
+ if (!ranges.includes("application/json") || !ranges.every((range) => ACCEPT_RANGES.has(range)))
357
+ return "headers";
358
+ }
359
+ return null;
360
+ }
361
+ function creditguardProcessRefusal(request, options) {
362
+ if (!record(request) || request.method !== "POST")
363
+ return "not_process_request";
364
+ const txId = creditguardProcessTxId(request.url);
365
+ if (txId === null)
366
+ return "not_process_request";
367
+ return headersRefusal(request.headers) ?? creditguardBodyRefusal(request.body, txId, options);
368
+ }
369
+ function isCreditguardProcessRequest(request, options) {
370
+ return creditguardProcessRefusal(request, options) === null;
371
+ }
372
+ function creditguardReplayRefusal(request, options) {
373
+ return creditguardProcessRefusal(request, options) ?? (boundMerchantHost(options) === void 0 ? "pp_domain_unbound" : null);
374
+ }
375
+ function creditguardRefusalMessage(reason) {
376
+ const code = typeof reason === "string" && /^[a-z_]{1,40}$/.test(reason) ? reason : "unsupported";
377
+ return `Refusing to pay: this CreditGuard request is not the reviewed card payment (${code}). Nothing was sent.`;
378
+ }
379
+ var FILL_REFUSAL = "Could not fill the card fields for CreditGuard. Nothing was sent.";
380
+ function cardParts(card) {
381
+ const month = card && (Number.isInteger(card.month) || digits(card.month, 1, 2)) ? Number(card.month) : NaN;
382
+ const year = card && (Number.isInteger(card.year) || digits(card.year, 2, 4)) ? Number(card.year) : NaN;
383
+ if (!card || !digits(card.number, 12, 19) || !digits(card.cvc, 3, 4) || !(month >= 1 && month <= 12) || !(year >= 0 && year <= 99 || year >= 2e3 && year <= 2099))
384
+ throw new Error(FILL_REFUSAL);
385
+ return { number: card.number, month: String(month).padStart(2, "0"), year: String(year % 100).padStart(2, "0"), cvc: card.cvc };
386
+ }
387
+ function injectCreditguardCard(body, card, options) {
388
+ const value = readCreditguardJson(body);
389
+ const reason = bodyRefusal(value, void 0, options);
390
+ if (reason !== null)
391
+ throw new Error(creditguardRefusalMessage(reason));
392
+ if (owns(value, "jwePayload"))
393
+ throw new Error(creditguardRefusalMessage("jwe_unsupported"));
394
+ const parts = cardParts(card);
395
+ value.cardNumber = parts.number;
396
+ value.expMonth = parts.month;
397
+ value.expYear = parts.year;
398
+ value.cvv = parts.cvc;
399
+ const where = ["cardNumber", "expMonth", "expYear", "cvv"];
400
+ if (owns(value, "expDateMMYY")) {
401
+ value.expDateMMYY = `${parts.month}/${parts.year}`;
402
+ where.push("expDateMMYY");
403
+ }
404
+ return { body: JSON.stringify(value), where };
405
+ }
406
+ var b64url = (bytes) => {
407
+ let binary = "";
408
+ for (const byte of bytes)
409
+ binary += String.fromCharCode(byte);
410
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
411
+ };
412
+ function fromB64url(value) {
413
+ if (typeof value !== "string" || !BASE64URL_SEGMENT.test(value) || value.length % 4 === 1)
414
+ return null;
415
+ try {
416
+ const binary = atob(value.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - value.length % 4) % 4));
417
+ return Uint8Array.from(binary, (char) => char.charCodeAt(0));
418
+ }
419
+ catch {
420
+ return null;
421
+ }
422
+ }
423
+ var stripLeadingZeros = (bytes) => {
424
+ let start = 0;
425
+ while (start < bytes.length - 1 && bytes[start] === 0)
426
+ start++;
427
+ return bytes.slice(start);
428
+ };
429
+ function parseCreditguardJwePublicKey(key) {
430
+ let value = key;
431
+ if (typeof value === "string") {
432
+ if (value.length > 8192)
433
+ return null;
434
+ try {
435
+ value = JSON.parse(value);
436
+ }
437
+ catch {
438
+ return null;
439
+ }
440
+ }
441
+ if (!record(value) || owns(value, "kty") && value.kty !== "RSA")
442
+ return null;
443
+ let modulus = null;
444
+ if (typeof value.n === "string" && value.n.length <= 2048 && /^(?:[0-9a-fA-F]{2}:)+[0-9a-fA-F]{2}$/.test(value.n)) {
445
+ modulus = Uint8Array.from(value.n.split(":"), (pair) => parseInt(pair, 16));
446
+ }
447
+ else
448
+ modulus = fromB64url(value.n);
449
+ if (!modulus)
450
+ return null;
451
+ modulus = stripLeadingZeros(modulus);
452
+ const bits = modulus.length === 0 || modulus[0] === 0 ? 0 : (modulus.length - 1) * 8 + (32 - Math.clz32(modulus[0]));
453
+ let exponent = null;
454
+ if (typeof value.e === "number")
455
+ exponent = value.e === 65537 ? new Uint8Array([1, 0, 1]) : null;
456
+ else {
457
+ const bytes = fromB64url(value.e);
458
+ exponent = bytes && stripLeadingZeros(bytes).join(",") === "1,0,1" ? new Uint8Array([1, 0, 1]) : null;
459
+ }
460
+ if (!exponent || bits < 2048 || bits > 4096)
461
+ return null;
462
+ return { kty: "RSA", n: b64url(modulus), e: b64url(exponent), bits };
463
+ }
464
+ async function encryptCreditguardJwe(plaintext, publicKey, facilities = {}) {
465
+ const crypto = facilities.crypto ?? globalThis.crypto;
466
+ if (!crypto?.subtle || typeof crypto.getRandomValues !== "function")
467
+ throw new Error("Processor cryptography is unavailable.");
468
+ const jwk = parseCreditguardJwePublicKey(publicKey);
469
+ if (!jwk || typeof plaintext !== "string")
470
+ throw new Error("Refusing to encrypt: the CreditGuard key is malformed.");
471
+ const key = await crypto.subtle.importKey("jwk", { kty: "RSA", n: jwk.n, e: jwk.e, ext: true }, { name: "RSA-OAEP", hash: "SHA-1" }, false, ["encrypt"]);
472
+ const cek = crypto.getRandomValues(new Uint8Array(32));
473
+ const iv = crypto.getRandomValues(new Uint8Array(12));
474
+ const encryptedKey = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, key, cek));
475
+ const aes = await crypto.subtle.importKey("raw", cek, { name: "AES-GCM" }, false, ["encrypt"]);
476
+ cek.fill(0);
477
+ const bytes = new TextEncoder().encode(plaintext);
478
+ const sealed = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv, additionalData: new TextEncoder().encode(CREDITGUARD_JWE_HEADER), tagLength: 128 }, aes, bytes));
479
+ bytes.fill(0);
480
+ return [
481
+ CREDITGUARD_JWE_HEADER,
482
+ b64url(encryptedKey),
483
+ b64url(iv),
484
+ b64url(sealed.subarray(0, sealed.length - 16)),
485
+ b64url(sealed.subarray(sealed.length - 16))
486
+ ].join(".");
487
+ }
488
+ async function injectCreditguardJweCard(body, card, publicKey, facilities) {
489
+ const value = readCreditguardJson(body);
490
+ const reason = bodyRefusal(value, void 0, { jwe: true });
491
+ if (reason !== null)
492
+ throw new Error(creditguardRefusalMessage(reason));
493
+ if (!owns(value, "jwePayload"))
494
+ throw new Error(creditguardRefusalMessage("jwe_fallback"));
495
+ const parts = cardParts(card);
496
+ value.jwePayload = await encryptCreditguardJwe(JSON.stringify({
497
+ cardNumber: parts.number,
498
+ expYear: parts.year,
499
+ expMonth: parts.month,
500
+ cvv: parts.cvc
501
+ }), publicKey, facilities);
502
+ return { body: JSON.stringify(value), where: ["jwePayload"] };
503
+ }
504
+ var INPUT_NAMES = /^[A-Za-z][A-Za-z0-9_]{0,39}$/;
505
+ var flag = (value) => value === true;
506
+ var inputFlag = (value) => value === void 0 || typeof value === "boolean";
507
+ function parseCreditguardTransaction(body, txId) {
508
+ const value = readCreditguardJson(body, 65536, 8192);
509
+ const trx = value && value.transactionData;
510
+ if (!record(trx) || typeof txId !== "string" || trx.txId !== txId || !exact(TXID, txId))
511
+ return null;
512
+ if (!Number.isSafeInteger(trx.amount) || trx.amount <= 0 || !exact(/^[A-Z]{3}$/, trx.currency) || trx.envType !== "prod" && trx.envType !== "test")
513
+ return null;
514
+ const count = (key, max) => Number.isSafeInteger(trx[key]) && trx[key] >= 0 && trx[key] <= max ? trx[key] : null;
515
+ const ui = record(value.uiCustomData) ? value.uiCustomData : {};
516
+ const inputData = record(value.formConfig) && Array.isArray(value.formConfig.inputData) ? value.formConfig.inputData : [];
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
+ let jwePublicKey = "absent";
519
+ if (owns(trx, "jwePublicKey") && trx.jwePublicKey !== null && trx.jwePublicKey !== "") {
520
+ jwePublicKey = parseCreditguardJwePublicKey(trx.jwePublicKey) ?? "malformed";
521
+ }
522
+ return {
523
+ txId,
524
+ amount: trx.amount,
525
+ currency: trx.currency,
526
+ envType: trx.envType,
527
+ mid: exact(/^[0-9]{1,12}$/, trx.mid) ? trx.mid : null,
528
+ transactionType: exact(/^[A-Za-z]{1,32}$/, trx.transactionType) ? trx.transactionType : null,
529
+ creditType: record(trx.creditTypeData) && exact(/^[A-Za-z]{1,32}$/, trx.creditTypeData.type) ? trx.creditTypeData.type : null,
530
+ numberOfPayments: count("numberOfPayments", 99),
531
+ remainingSubmitRetries: count("remainingSubmitRetries", 99),
532
+ threeDS: flag(trx.CG3DSV2),
533
+ threeDSProvider: exact(/^[a-z]{2}$/, trx.cg3DSProvider) ? trx.cg3DSProvider : null,
534
+ otpActive: flag(trx.otpActive),
535
+ dccActive: flag(trx.dccActive),
536
+ recaptcha: ["googleRecaptchaKey", "googleRecaptchaV3Key"].some((key) => typeof trx[key] === "string" && trx[key] !== ""),
537
+ jwePublicKey,
538
+ personalIdAlwaysEnabled: flag(ui.personalIdAlwaysEnabled),
539
+ inputs
540
+ };
541
+ }
542
+ var CARD_INPUTS = /* @__PURE__ */ new Set(["cardNumber", "expMonth", "expYear", "expDateMMYY", "cvv"]);
543
+ var PAGE_INPUTS = /* @__PURE__ */ new Set([...CARD_INPUTS, "personalId", "numberOfPayments", "keepCCDetails"]);
544
+ function formInputsRefusal(inputs) {
545
+ if (!Array.isArray(inputs))
546
+ return "form_inputs";
547
+ for (const input of inputs) {
548
+ if (CARD_INPUTS.has(input.inputName) && !input.visible)
549
+ return "card_field_hidden";
550
+ if (input.inputName === "keepCCDetails" && input.required)
551
+ return "keep_on_file";
552
+ if (!PAGE_INPUTS.has(input.inputName) && (input.required || input.visible))
553
+ return "form_inputs";
554
+ }
555
+ return null;
556
+ }
557
+ function creditguardTransactionRefusal(txn, expectation) {
558
+ if (!record(txn) || !record(expectation))
559
+ return "transaction_unreadable";
560
+ if (txn.threeDS)
561
+ return "three_d_secure";
562
+ if (txn.otpActive)
563
+ return "otp";
564
+ if (txn.dccActive)
565
+ return "dcc";
566
+ if (txn.transactionType !== "Debit")
567
+ return "transaction_type";
568
+ if (txn.creditType !== "RegularCredit" || txn.numberOfPayments === null || txn.numberOfPayments > 0)
569
+ return "installments";
570
+ if (txn.personalIdAlwaysEnabled)
571
+ return "personal_id";
572
+ const form = formInputsRefusal(txn.inputs);
573
+ if (form)
574
+ return form;
575
+ if (txn.remainingSubmitRetries === null || txn.remainingSubmitRetries === 0)
576
+ return "no_retries_left";
577
+ const environment = creditguardPreparationEnvironment(expectation.hostname);
578
+ if (environment === null || environment === "sandbox" !== (txn.envType === "test") || typeof expectation.sandbox !== "boolean" || expectation.sandbox !== (environment === "sandbox"))
579
+ return "environment_mismatch";
580
+ if (txn.jwePublicKey === "malformed")
581
+ return "jwe_public_key_malformed";
582
+ if (txn.jwePublicKey !== "absent" && expectation.jwe !== true)
583
+ return "jwe_unsupported";
584
+ if (!Number.isSafeInteger(expectation.amount) || expectation.amount !== txn.amount)
585
+ return "amount_mismatch";
586
+ if (typeof expectation.currency !== "string" || expectation.currency.toUpperCase() !== txn.currency)
587
+ return "currency_mismatch";
588
+ return null;
589
+ }
590
+ function creditguardSendWindowRefusal(timing) {
591
+ if (!record(timing) || !Number.isFinite(timing.now))
592
+ return "timing_unknown";
593
+ if (!Number.isFinite(timing.readAt) || timing.now - timing.readAt > CREDITGUARD_PAGE_WINDOW_MS)
594
+ return "page_expired";
595
+ if (timing.recaptcha === true && (!Number.isFinite(timing.pausedAt) || timing.now - timing.pausedAt > CREDITGUARD_RECAPTCHA_WINDOW_MS))
596
+ return "recaptcha_expired";
597
+ return null;
598
+ }
599
+ var ERROR_CODE = /^-?[0-9]{1,4}$/;
600
+ var CREDITGUARD_REFUSAL_CODES = Object.freeze(["681", "682", "683", "687", "689"]);
601
+ function landingUrl(value) {
602
+ if (typeof value !== "string" || value.length > 4096 || /[\s\u0000-\u001f\u007f]/.test(value))
603
+ return false;
604
+ return httpsUrl(value, 4096) !== null;
605
+ }
606
+ var retries = (value) => Number.isSafeInteger(value) && value >= 0 && value <= 99;
607
+ function creditguardResponseOutcome(status, body, options) {
608
+ const clientError = Number.isInteger(status) && status >= 400 && status < 500;
609
+ if (status !== 200 && !clientError)
610
+ return { outcome: "unknown", reason: "creditguard_status_unconfirmed" };
611
+ const value = readCreditguardJson(body);
612
+ if (!value)
613
+ return { outcome: "unknown", reason: "creditguard_unreadable" };
614
+ if (!exact(ERROR_CODE, value.errorCode))
615
+ return { outcome: "unknown", reason: "creditguard_unexpected_response" };
616
+ if (!absent(value, "enhancedAuthActive") && typeof value.enhancedAuthActive !== "boolean")
617
+ return { outcome: "unknown", reason: "creditguard_unexpected_response" };
618
+ if (value.enhancedAuthActive === true)
619
+ return { outcome: "unknown", reason: "creditguard_enhanced_auth" };
620
+ const bound = record(options) && typeof options.txId === "string" ? options.txId : null;
621
+ if (owns(value, "txId") && (!exact(TXID, value.txId) || bound !== null && value.txId !== bound))
622
+ return { outcome: "unknown", reason: "creditguard_txid_mismatch" };
623
+ if (value.errorCode !== "000") {
624
+ return CREDITGUARD_REFUSAL_CODES.includes(value.errorCode) ? { outcome: "refused", code: value.errorCode } : { outcome: "unknown", reason: "creditguard_not_approved" };
625
+ }
626
+ if (clientError)
627
+ return { outcome: "unknown", reason: "creditguard_status_unconfirmed" };
628
+ if (!landingUrl(value.url) || !absent(value, "remainingSubmitRetries") && !retries(value.remainingSubmitRetries) || !absent(value, "clientRedirectMethod") && !exact(/^(?:GET|POST)$/i, value.clientRedirectMethod) || !absent(value, "clientRedirectCharset") && !exact(/^[A-Za-z0-9._-]{1,32}$/, value.clientRedirectCharset)) {
629
+ return { outcome: "unknown", reason: "creditguard_unconfirmed" };
630
+ }
631
+ const number = record(options) && digits(options.cardNumber, 12, 19) ? options.cardNumber : null;
632
+ if (number !== null && (body.includes(number) || JSON.stringify(value).includes(number)))
633
+ return { outcome: "unknown", reason: "creditguard_card_echo" };
634
+ return { outcome: "approved" };
635
+ }
636
+ function sanitizeCreditguardResponse(body, options) {
637
+ if (creditguardResponseOutcome(200, body, options).outcome !== "approved")
638
+ throw new Error("Invalid CreditGuard payment response.");
639
+ const value = readCreditguardJson(body);
640
+ const safe = { errorCode: "000", url: value.url };
641
+ if (!absent(value, "remainingSubmitRetries"))
642
+ safe.remainingSubmitRetries = value.remainingSubmitRetries;
643
+ if (value.enhancedAuthActive === false)
644
+ safe.enhancedAuthActive = false;
645
+ if (!absent(value, "clientRedirectMethod"))
646
+ safe.clientRedirectMethod = value.clientRedirectMethod;
647
+ if (!absent(value, "clientRedirectCharset"))
648
+ safe.clientRedirectCharset = value.clientRedirectCharset;
649
+ if (owns(value, "txId"))
650
+ safe.txId = value.txId;
651
+ return JSON.stringify(safe);
652
+ }
653
+ function creditguardFacts(status, body) {
654
+ const verdict = creditguardResponseOutcome(status, body);
655
+ const value = readCreditguardJson(body);
656
+ return {
657
+ outcome: verdict.outcome,
658
+ errorCode: value && exact(ERROR_CODE, value.errorCode) ? value.errorCode : null,
659
+ refusalCode: verdict.outcome === "refused" ? verdict.code : null
660
+ };
661
+ }
662
+ 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 };