@agent-cards/sdk 0.23.21 → 0.23.22

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.
@@ -0,0 +1,113 @@
1
+ // @ts-nocheck
2
+ // Generated from @agent-cards/payment-core. Do not edit.
3
+ // artifact-sha256: d0c3bda9a5b7939a6984156929cbcb7ba7d427fa38c544aad65c4593cf272d05
4
+ // src/toast.js
5
+ var TOAST_PSP = "toast";
6
+ var TOAST_CAPABILITY = "toast_pinned_key";
7
+ var TOAST_OPERATION = "toast.encrypted_card";
8
+ var TOAST_PAYMENT_METHODS_URL = "https://payments.toasttab.com/v1/payment-methods";
9
+ var TOAST_KEY_ID = "RSA-OAEP-SHA1::bacb4887-8314-4c23-98fc-d5ef7bc99e94_oo-legacy-browsers";
10
+ var TOAST_KEY = /* @__PURE__ */ Object.freeze({
11
+ spki: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkq50dXdz/fQOwYUswZRXgh5Vghs1tcJZCv2goNsC5BO3dXC/EiejcApaE/fKVMespzDNSLsQHXrWHegpE2piyeBwMzpTbHrCG3v6MnG6Nu+9dBYxPS4T9cNMsf0V/iCPiiaTXib6r8IfOjVZTTas2nKGZEtiDfYJIS3bJ/f30SMP4dAFILvzXGALeqleB/psQ8AFc/qUZf7VZpRnoGtKoo8wD253xTmDdaiKqr09bcJZxhTWsCB9aYouqdbl6y9/5Lu+MtyBkj7LI05g5QqDSfVax0sp/Fe7RY5SYxwlR4GlMonwtbvFTMKsr6dZ1uLuNjHA/6dm+112Uqn/AxrKGwIDAQAB",
12
+ sha256: "5475b78c9577b1258615286307547aba18c52faa6fd7d60ad0cfcb996e21ad0e"
13
+ });
14
+ var TOAST_CIPHERTEXT_BYTES = 256;
15
+ var TOAST_SUBSTITUTION = /* @__PURE__ */ Object.freeze({ at: "card", fields: Object.freeze(["cardData"]) });
16
+ var TOAST_REFUSAL_CODES = /* @__PURE__ */ Object.freeze(["toast_url_refused", "toast_foreign_key", "toast_keeps_card", "toast_body_malformed"]);
17
+ var BODY_LIMIT = 8192;
18
+ var ROOT_KEYS = /* @__PURE__ */ Object.freeze(["type", "card", "sessionSecret", "usage", "setupFutureUsage", "billingDetails"]);
19
+ var CARD_KEYS = /* @__PURE__ */ Object.freeze(["keyId", "cardData"]);
20
+ var WALLETS = /* @__PURE__ */ Object.freeze(["APPLE_PAY", "GOOGLE_PAY"]);
21
+ var SESSION_SECRET = /^[\x21-\x7e]{1,1024}$/;
22
+ var POSTAL_CODE = /^[A-Za-z0-9 -]{0,16}$/;
23
+ var CIPHERTEXT_B64 = /^[A-Za-z0-9+/]{341}[AQgw]==$/;
24
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
25
+ var sameKeys = (value, keys) => {
26
+ const own = Object.keys(value);
27
+ return own.length === keys.length && own.every((key, at) => key === keys[at]);
28
+ };
29
+ var refuse = (code) => Object.freeze({ verdict: "refuse", code });
30
+ var failed = (code) => (
31
+ /** @type {ToastBodyReadJs} */
32
+ Object.freeze({ ok: false, code }));
33
+ var CARD = /* @__PURE__ */ Object.freeze({ verdict: "card" });
34
+ var CONTINUE = /* @__PURE__ */ Object.freeze({ verdict: "continue" });
35
+ function isWalletBody(parsed) {
36
+ const card = parsed.card;
37
+ const rootOk = sameKeys(parsed, ["type", "card", "sessionSecret"]) || sameKeys(parsed, ["type", "card", "sessionSecret", "billingDetails"]) && record(parsed.billingDetails);
38
+ return rootOk && WALLETS.includes(parsed.type) && record(card) && sameKeys(card, ["keyId", "cardData", "wallet"]) && card.keyId === null && typeof card.cardData === "string" && record(card.wallet) && sameKeys(card.wallet, ["type"]) && card.wallet.type === parsed.type && typeof parsed.sessionSecret === "string";
39
+ }
40
+ function isToastPaymentMethodsUrl(url) {
41
+ return url === TOAST_PAYMENT_METHODS_URL;
42
+ }
43
+ function isToastHost(url) {
44
+ if (typeof url !== "string")
45
+ return false;
46
+ try {
47
+ return new URL(url).hostname.toLowerCase().replace(/\.$/, "") === "payments.toasttab.com";
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ function isToastCiphertext(value) {
54
+ return typeof value === "string" && CIPHERTEXT_B64.test(value);
55
+ }
56
+ function readToastBody(body) {
57
+ const malformed = failed("toast_body_malformed");
58
+ if (typeof body !== "string" || body.length > BODY_LIMIT)
59
+ return malformed;
60
+ let parsed;
61
+ try {
62
+ parsed = JSON.parse(body);
63
+ }
64
+ catch {
65
+ return malformed;
66
+ }
67
+ if (!record(parsed) || JSON.stringify(parsed) !== body)
68
+ return malformed;
69
+ if (isWalletBody(parsed))
70
+ return (
71
+ /** @type {ToastBodyReadJs} */
72
+ Object.freeze({ ok: false, wallet: true }));
73
+ const card = parsed.card;
74
+ if (!sameKeys(parsed, ROOT_KEYS) || parsed.type !== "CARD" || !record(card) || !sameKeys(card, CARD_KEYS))
75
+ return malformed;
76
+ if (typeof card.keyId !== "string")
77
+ return malformed;
78
+ if (card.keyId !== TOAST_KEY_ID)
79
+ return failed("toast_foreign_key");
80
+ if (!isToastCiphertext(card.cardData))
81
+ return malformed;
82
+ if (typeof parsed.sessionSecret !== "string" || !SESSION_SECRET.test(parsed.sessionSecret))
83
+ return malformed;
84
+ if (parsed.usage !== null || parsed.setupFutureUsage !== null)
85
+ return failed("toast_keeps_card");
86
+ const billing = parsed.billingDetails;
87
+ if (!record(billing) || !sameKeys(billing, ["postalCode"]) || typeof billing.postalCode !== "string" || !POSTAL_CODE.test(billing.postalCode))
88
+ return malformed;
89
+ const read = { ok: true, sessionSecret: parsed.sessionSecret, postalCode: billing.postalCode, cardData: card.cardData };
90
+ return Object.freeze(read);
91
+ }
92
+ function toastBodyVerdict(body) {
93
+ const read = readToastBody(body);
94
+ if (read.ok)
95
+ return CARD;
96
+ return read.wallet ? CONTINUE : refuse(read.code);
97
+ }
98
+ function toastRequestRefusal(request) {
99
+ if (!record(request) || typeof request.method !== "string" || request.method.toUpperCase() !== "POST" || !isToastPaymentMethodsUrl(request.url))
100
+ return "toast_url_refused";
101
+ const read = readToastBody(request.body);
102
+ return read.ok ? null : read.code ?? "toast_body_malformed";
103
+ }
104
+ var REFUSAL_MESSAGES = /* @__PURE__ */ Object.freeze({
105
+ toast_url_refused: "Refusing to pay: this Toast card request does not go to the address Toast's card form sends cards to. Nothing was sent.",
106
+ toast_foreign_key: "Refusing to pay: this Toast card request is encrypted under a key Agentcard has not reviewed. Nothing was sent.",
107
+ toast_keeps_card: "Refusing to pay: this Toast checkout asks to keep the card for later payments, and Agentcard pays only a one-time guest checkout here. Nothing was sent.",
108
+ toast_body_malformed: "Refusing to pay: this is not the card request of Toast's card form. Nothing was sent."
109
+ });
110
+ function toastRefusalMessage(code) {
111
+ return Object.prototype.hasOwnProperty.call(REFUSAL_MESSAGES, code) ? REFUSAL_MESSAGES[code] : REFUSAL_MESSAGES.toast_body_malformed;
112
+ }
113
+ export { TOAST_CAPABILITY, TOAST_CIPHERTEXT_BYTES, TOAST_KEY, TOAST_KEY_ID, TOAST_OPERATION, TOAST_PAYMENT_METHODS_URL, TOAST_PSP, TOAST_REFUSAL_CODES, TOAST_SUBSTITUTION, isToastCiphertext, isToastHost, isToastPaymentMethodsUrl, readToastBody, toastBodyVerdict, toastRefusalMessage, toastRequestRefusal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-cards/sdk",
3
- "version": "0.23.21",
3
+ "version": "0.23.22",
4
4
  "description": "Agentcard's SDK: one client, Agentcard, with two modules. checkout pauses a browser purchase and pays it with the person's own card; voice connects a person to your product once and approves a purchase by voice inside it. Card data never enters your process.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "_comment_test": "check:built runs first and names the command when a file the build generates (the copies in src/, the preflight contracts in dist/, the Kernel inventory) is missing or stale; verify:pack runs last, on the same dist.",
31
31
  "check:built": "node scripts/generate-payment-core.mjs --check && node scripts/generate-voice-stream.mjs --check && node scripts/generate-preflight-contract.mjs --check && node scripts/generate-kernel-native-inventory.mjs --check",
32
32
  "verify:pack": "node scripts/verify-pack.mjs",
33
- "test": "npm run check:built && node test.mjs && node --test lifecycle.test.mjs merchant-abort.test.mjs preparation.test.mjs braintree.test.mjs pre-claim.test.mjs ekashu.test.mjs redsys.test.mjs quickpay.test.mjs paypal-hosted-fields.test.mjs paypal-card-forms.test.mjs cybersource-secure-acceptance.test.mjs ebanx.test.mjs autopilot.test.mjs stripe-checkout.test.mjs stripe-setup.test.mjs stripe-legacy-checkout.test.mjs payment-core.test.mjs prepared-processor.test.mjs merchant-hosted.test.mjs merchant-total.test.mjs sandbox-declaration.test.mjs minimum-delay.test.mjs paysafe.test.mjs wix-payments.test.mjs hipay.test.mjs payu.test.mjs attachment.test.mjs worker-targets.test.mjs mercado-checkout.test.mjs mercado-polling.test.mjs amadeus.test.mjs pelecard.test.mjs aci.test.mjs primer.test.mjs payrails.test.mjs elavon-converge.test.mjs voice.test.mjs agentcard.test.mjs buy.test.mjs readme.test.mjs gmo.test.mjs cybersource-flex.test.mjs juspay-gate.test.mjs card-endpoint.test.mjs card-endpoint-fastspring.test.mjs card-endpoint-navigation.test.mjs merchant-session-probe.test.mjs datatrans.test.mjs authorize-net-dpm.test.mjs creditguard.test.mjs eprotect.test.mjs wspay.test.mjs shiji-sts.test.mjs worldline-mycheckout.test.mjs verifone.test.mjs gravy.test.mjs paddle-vgs.test.mjs hold.test.mjs paddle-tokenex.test.mjs lyra.test.mjs gopay.test.mjs twoc2p.test.mjs pay-nl.test.mjs redact-url.test.mjs hosted-entry.test.mjs comgate.test.mjs przelewy24.test.mjs tokenex-iframe.test.mjs transbank.test.mjs sumup.test.mjs && node --test preflight-package.test.mjs preflight-collector.test.mjs browser-tests.test.mjs && node --test kernel-native-qualification.test.mjs && node --test ../vault/scripts/recurly-validation/watch-duty-sdk-result.test.mjs && node scripts/verify-pack.mjs",
33
+ "test": "npm run check:built && node test.mjs && node --test lifecycle.test.mjs merchant-abort.test.mjs preparation.test.mjs braintree.test.mjs pre-claim.test.mjs ekashu.test.mjs redsys.test.mjs quickpay.test.mjs paypal-hosted-fields.test.mjs paypal-card-forms.test.mjs cybersource-secure-acceptance.test.mjs ebanx.test.mjs payrexx.test.mjs payrexx-follow-ups.test.mjs payrexx-adapters.test.mjs autopilot.test.mjs stripe-checkout.test.mjs stripe-setup.test.mjs stripe-legacy-checkout.test.mjs payment-core.test.mjs prepared-processor.test.mjs merchant-hosted.test.mjs merchant-total.test.mjs sandbox-declaration.test.mjs minimum-delay.test.mjs paysafe.test.mjs wix-payments.test.mjs hipay.test.mjs payu.test.mjs attachment.test.mjs worker-targets.test.mjs mercado-checkout.test.mjs mercado-polling.test.mjs amadeus.test.mjs pelecard.test.mjs aci.test.mjs primer.test.mjs payrails.test.mjs elavon-converge.test.mjs voice.test.mjs agentcard.test.mjs buy.test.mjs readme.test.mjs gmo.test.mjs cybersource-flex.test.mjs juspay-gate.test.mjs card-endpoint.test.mjs card-endpoint-fastspring.test.mjs card-endpoint-navigation.test.mjs merchant-session-probe.test.mjs datatrans.test.mjs authorize-net-dpm.test.mjs creditguard.test.mjs eprotect.test.mjs wspay.test.mjs shiji-sts.test.mjs worldline-mycheckout.test.mjs verifone.test.mjs gravy.test.mjs paddle-vgs.test.mjs hold.test.mjs paddle-tokenex.test.mjs lyra.test.mjs gopay.test.mjs paygent.test.mjs twoc2p.test.mjs pay-nl.test.mjs toast.test.mjs redact-url.test.mjs hosted-entry.test.mjs comgate.test.mjs przelewy24.test.mjs tokenex-iframe.test.mjs transbank.test.mjs sumup.test.mjs clover.test.mjs eximbay.test.mjs && node --test preflight-package.test.mjs preflight-collector.test.mjs browser-tests.test.mjs && node --test kernel-native-qualification.test.mjs && node --test ../vault/scripts/recurly-validation/watch-duty-sdk-result.test.mjs && node scripts/verify-pack.mjs",
34
34
  "test:browser": "node browser-tests.mjs",
35
35
  "check:payment-core": "node scripts/generate-payment-core.mjs --check",
36
36
  "check:voice-stream": "node scripts/generate-voice-stream.mjs --check",