@agent-score/commerce 2.1.1 → 2.3.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 (66) hide show
  1. package/README.md +2 -2
  2. package/dist/challenge/index.d.mts +3 -3
  3. package/dist/challenge/index.d.ts +3 -3
  4. package/dist/challenge/index.js +7 -5
  5. package/dist/challenge/index.js.map +1 -1
  6. package/dist/challenge/index.mjs +7 -5
  7. package/dist/challenge/index.mjs.map +1 -1
  8. package/dist/{checkout-BRw_caGr.d.mts → checkout-Ceo1_rVJ.d.mts} +38 -2
  9. package/dist/{checkout-CuSNUJFX.d.ts → checkout-ChyOi7aU.d.ts} +38 -2
  10. package/dist/core.js +4 -3
  11. package/dist/core.js.map +1 -1
  12. package/dist/core.mjs +4 -3
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/{default_rails-C5gKZJMI.d.ts → default_rails-DtR_E9N9.d.ts} +1 -1
  15. package/dist/{default_rails-XFCuRddA.d.mts → default_rails-K25PtWrL.d.mts} +1 -1
  16. package/dist/discovery/index.d.mts +4 -4
  17. package/dist/discovery/index.d.ts +4 -4
  18. package/dist/identity/express.d.mts +4 -3
  19. package/dist/identity/express.d.ts +4 -3
  20. package/dist/identity/express.js +4 -3
  21. package/dist/identity/express.js.map +1 -1
  22. package/dist/identity/express.mjs +4 -3
  23. package/dist/identity/express.mjs.map +1 -1
  24. package/dist/identity/fastify.d.mts +4 -3
  25. package/dist/identity/fastify.d.ts +4 -3
  26. package/dist/identity/fastify.js +4 -3
  27. package/dist/identity/fastify.js.map +1 -1
  28. package/dist/identity/fastify.mjs +4 -3
  29. package/dist/identity/fastify.mjs.map +1 -1
  30. package/dist/identity/hono.d.mts +4 -3
  31. package/dist/identity/hono.d.ts +4 -3
  32. package/dist/identity/hono.js +4 -3
  33. package/dist/identity/hono.js.map +1 -1
  34. package/dist/identity/hono.mjs +4 -3
  35. package/dist/identity/hono.mjs.map +1 -1
  36. package/dist/identity/nextjs.js +4 -3
  37. package/dist/identity/nextjs.js.map +1 -1
  38. package/dist/identity/nextjs.mjs +4 -3
  39. package/dist/identity/nextjs.mjs.map +1 -1
  40. package/dist/identity/web.js +4 -3
  41. package/dist/identity/web.js.map +1 -1
  42. package/dist/identity/web.mjs +4 -3
  43. package/dist/identity/web.mjs.map +1 -1
  44. package/dist/index.d.mts +7 -7
  45. package/dist/index.d.ts +7 -7
  46. package/dist/index.js +139 -13
  47. package/dist/index.js.map +1 -1
  48. package/dist/index.mjs +139 -13
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/payment/index.d.mts +3 -3
  51. package/dist/payment/index.d.ts +3 -3
  52. package/dist/payment/index.js +2 -0
  53. package/dist/payment/index.js.map +1 -1
  54. package/dist/payment/index.mjs +2 -0
  55. package/dist/payment/index.mjs.map +1 -1
  56. package/dist/{pricing-DHfH3ogG.d.ts → pricing-B3-aKxSz.d.ts} +5 -3
  57. package/dist/{pricing-4n5Ota0D.d.mts → pricing-BReyZiqN.d.mts} +5 -3
  58. package/dist/{rail_spec-D6qzh3J0.d.mts → rail_spec-B1239jPp.d.mts} +25 -0
  59. package/dist/{rail_spec-D6qzh3J0.d.ts → rail_spec-B1239jPp.d.ts} +25 -0
  60. package/dist/stripe-multichain/index.d.mts +61 -11
  61. package/dist/stripe-multichain/index.d.ts +61 -11
  62. package/dist/stripe-multichain/index.js +84 -43
  63. package/dist/stripe-multichain/index.js.map +1 -1
  64. package/dist/stripe-multichain/index.mjs +83 -43
  65. package/dist/stripe-multichain/index.mjs.map +1 -1
  66. package/package.json +9 -9
@@ -19432,11 +19432,12 @@ function toClient(method, options) {
19432
19432
  };
19433
19433
  }
19434
19434
  function toServer(method, options) {
19435
- const { authorize, defaults, html, request, respond, stableBinding, transport, verify: verify3 } = options;
19435
+ const { authorize, defaults, extensions, html, request, respond, stableBinding, transport, verify: verify3 } = options;
19436
19436
  return {
19437
19437
  ...method,
19438
19438
  authorize,
19439
19439
  defaults,
19440
+ extensions,
19440
19441
  html,
19441
19442
  request,
19442
19443
  respond,
@@ -19701,50 +19702,76 @@ async function createMultichainPaymentIntent({
19701
19702
  }
19702
19703
 
19703
19704
  // src/stripe-multichain/pay_to_address.ts
19705
+ var DEFAULT_NETWORKS = ["tempo", "base", "solana"];
19704
19706
  async function createPayToAddressFromStripePI(opts) {
19707
+ const fromCredential = await tryResolveFromCredential(opts);
19708
+ if (fromCredential !== null) return fromCredential;
19709
+ const { preferred } = await mintAndCache(opts);
19710
+ return preferred;
19711
+ }
19712
+ async function mintMultichainRecipients(opts) {
19713
+ const fromCredential = await tryResolveFromCredential(opts);
19714
+ if (fromCredential !== null) {
19715
+ const piId = opts.piCache.getPaymentIntentId(fromCredential);
19716
+ const networkMap = piId ? readNetworkMapFromCache(opts.piCache, piId) : {};
19717
+ const merged2 = { ...networkMap, ...opts.staticRecipients ?? {} };
19718
+ return {
19719
+ recipients: merged2,
19720
+ ...piId !== void 0 && { paymentIntentId: piId },
19721
+ reusedFromCredential: true
19722
+ };
19723
+ }
19724
+ const { merged, paymentIntentId } = await mintAndCache(opts);
19725
+ return { recipients: merged, paymentIntentId, reusedFromCredential: false };
19726
+ }
19727
+ async function tryResolveFromCredential(opts) {
19705
19728
  const authHeader = opts.request.headers.get("authorization");
19706
- if (authHeader) {
19707
- const { Credential } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
19708
- if (Credential.extractPaymentScheme(authHeader)) {
19709
- let credential;
19710
- try {
19711
- credential = Credential.fromRequest(opts.request);
19712
- } catch {
19713
- throw new CheckoutValidationError({
19714
- code: "invalid_credential",
19715
- message: "The Authorization: Payment header is not a valid MPP credential.",
19716
- action: "retry_without_credential",
19717
- status: 401
19718
- });
19719
- }
19720
- const method = credential.challenge.method;
19721
- if (method === "tempo" || method === "solana") {
19722
- const toAddress = credential.challenge.request.recipient;
19723
- if (typeof toAddress !== "string" || !toAddress) {
19724
- throw new CheckoutValidationError({
19725
- code: "invalid_credential",
19726
- message: "The MPP credential is missing its recipient field.",
19727
- action: "retry_without_credential",
19728
- status: 401
19729
- });
19730
- }
19731
- if (!await opts.piCache.hasAddress(toAddress)) {
19732
- throw new CheckoutValidationError({
19733
- code: "invalid_credential",
19734
- message: "The signed-against payTo recipient is not in this merchant's cache (unknown or expired). Retry without the Authorization: Payment header to receive a fresh 402 challenge.",
19735
- action: "retry_without_credential",
19736
- status: 401
19737
- });
19738
- }
19739
- return toAddress;
19740
- }
19741
- }
19729
+ if (!authHeader) return null;
19730
+ const { Credential } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
19731
+ if (!Credential.extractPaymentScheme(authHeader)) return null;
19732
+ let credential;
19733
+ try {
19734
+ credential = Credential.fromRequest(opts.request);
19735
+ } catch {
19736
+ throw new CheckoutValidationError({
19737
+ code: "invalid_credential",
19738
+ message: "The Authorization: Payment header is not a valid MPP credential.",
19739
+ action: "retry_without_credential",
19740
+ status: 401
19741
+ });
19742
+ }
19743
+ const method = credential.challenge.method;
19744
+ if (method !== "tempo" && method !== "solana") return null;
19745
+ const toAddress = credential.challenge.request.recipient;
19746
+ if (typeof toAddress !== "string" || !toAddress) {
19747
+ throw new CheckoutValidationError({
19748
+ code: "invalid_credential",
19749
+ message: "The MPP credential is missing its recipient field.",
19750
+ action: "retry_without_credential",
19751
+ status: 401
19752
+ });
19753
+ }
19754
+ const staticForMethod = opts.staticRecipients?.[method];
19755
+ if (staticForMethod && staticForMethod === toAddress) return toAddress;
19756
+ if (!await opts.piCache.hasAddress(toAddress)) {
19757
+ throw new CheckoutValidationError({
19758
+ code: "invalid_credential",
19759
+ message: "The signed-against payTo recipient is not in this merchant's cache (unknown or expired). Retry without the Authorization: Payment header to receive a fresh 402 challenge.",
19760
+ action: "retry_without_credential",
19761
+ status: 401
19762
+ });
19742
19763
  }
19764
+ return toAddress;
19765
+ }
19766
+ async function mintAndCache(opts) {
19767
+ const staticRecipients = opts.staticRecipients ?? {};
19768
+ const requestedNetworks = opts.networks ?? [...DEFAULT_NETWORKS];
19769
+ const stripeNetworks = requestedNetworks.filter((n) => !(n in staticRecipients));
19743
19770
  const idempotencyKey = opts.orderId ? `pi-${opts.orderId}-${opts.amountCents}` : void 0;
19744
19771
  const { paymentIntentId, depositAddresses } = await createMultichainPaymentIntent({
19745
19772
  stripe: opts.stripe,
19746
19773
  amount: opts.amountCents,
19747
- networks: opts.networks ?? ["tempo", "base", "solana"],
19774
+ networks: stripeNetworks,
19748
19775
  ...opts.metadata ? { metadata: opts.metadata } : {},
19749
19776
  ...idempotencyKey ? { idempotencyKey } : {}
19750
19777
  });
@@ -19752,10 +19779,14 @@ async function createPayToAddressFromStripePI(opts) {
19752
19779
  await opts.piCache.cacheAddress(address2);
19753
19780
  opts.piCache.cachePaymentIntent(address2, paymentIntentId);
19754
19781
  }
19755
- opts.piCache.cacheNetworkAddresses(paymentIntentId, depositAddresses);
19756
- const preferred = opts.preferredNetwork ?? "tempo";
19757
- const payTo = depositAddresses[preferred] ?? depositAddresses.base ?? depositAddresses.tempo;
19758
- if (!payTo) {
19782
+ for (const address2 of Object.values(staticRecipients)) {
19783
+ await opts.piCache.cacheAddress(address2);
19784
+ }
19785
+ const merged = { ...depositAddresses, ...staticRecipients };
19786
+ opts.piCache.cacheNetworkAddresses(paymentIntentId, merged);
19787
+ const preferredKey = opts.preferredNetwork ?? "tempo";
19788
+ const preferred = merged[preferredKey] ?? merged.base ?? merged.tempo;
19789
+ if (!preferred) {
19759
19790
  throw new CheckoutValidationError({
19760
19791
  code: "payment_provider_unavailable",
19761
19792
  message: "Stripe returned deposit addresses but none matched the requested network (tempo / base / solana). The account may have only a subset of multichain networks enabled.",
@@ -19763,7 +19794,15 @@ async function createPayToAddressFromStripePI(opts) {
19763
19794
  status: 503
19764
19795
  });
19765
19796
  }
19766
- return payTo;
19797
+ return { preferred, merged, paymentIntentId };
19798
+ }
19799
+ function readNetworkMapFromCache(piCache, paymentIntentId) {
19800
+ const entries = [];
19801
+ for (const n of DEFAULT_NETWORKS) {
19802
+ const addr = piCache.getNetworkDepositAddress(paymentIntentId, n);
19803
+ if (addr) entries.push([n, addr]);
19804
+ }
19805
+ return Object.fromEntries(entries);
19767
19806
  }
19768
19807
 
19769
19808
  // src/stripe-multichain/simulate_deposit.ts
@@ -19987,6 +20026,7 @@ export {
19987
20026
  createMultichainPaymentIntent,
19988
20027
  createPayToAddressFromStripePI,
19989
20028
  createPiCache,
20029
+ mintMultichainRecipients,
19990
20030
  networkForOutcome,
19991
20031
  simulateCryptoDeposit,
19992
20032
  simulateDepositForOutcome,