@agent-score/commerce 2.2.0 → 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 (46) 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.map +1 -1
  5. package/dist/challenge/index.mjs.map +1 -1
  6. package/dist/{checkout-CKQE2QpJ.d.mts → checkout-Ceo1_rVJ.d.mts} +2 -2
  7. package/dist/{checkout-CfgxgPZL.d.ts → checkout-ChyOi7aU.d.ts} +2 -2
  8. package/dist/core.js +1 -1
  9. package/dist/core.mjs +1 -1
  10. package/dist/{default_rails-C5gKZJMI.d.ts → default_rails-DtR_E9N9.d.ts} +1 -1
  11. package/dist/{default_rails-XFCuRddA.d.mts → default_rails-K25PtWrL.d.mts} +1 -1
  12. package/dist/discovery/index.d.mts +4 -4
  13. package/dist/discovery/index.d.ts +4 -4
  14. package/dist/identity/express.js +1 -1
  15. package/dist/identity/express.mjs +1 -1
  16. package/dist/identity/fastify.js +1 -1
  17. package/dist/identity/fastify.mjs +1 -1
  18. package/dist/identity/hono.js +1 -1
  19. package/dist/identity/hono.mjs +1 -1
  20. package/dist/identity/nextjs.js +1 -1
  21. package/dist/identity/nextjs.mjs +1 -1
  22. package/dist/identity/web.js +1 -1
  23. package/dist/identity/web.mjs +1 -1
  24. package/dist/index.d.mts +7 -7
  25. package/dist/index.d.ts +7 -7
  26. package/dist/index.js +3 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +3 -1
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/payment/index.d.mts +3 -3
  31. package/dist/payment/index.d.ts +3 -3
  32. package/dist/payment/index.js +2 -0
  33. package/dist/payment/index.js.map +1 -1
  34. package/dist/payment/index.mjs +2 -0
  35. package/dist/payment/index.mjs.map +1 -1
  36. package/dist/{pricing-uFGRNoGl.d.ts → pricing-B3-aKxSz.d.ts} +1 -1
  37. package/dist/{pricing-dSI3ePmE.d.mts → pricing-BReyZiqN.d.mts} +1 -1
  38. package/dist/{rail_spec-D6qzh3J0.d.mts → rail_spec-B1239jPp.d.mts} +25 -0
  39. package/dist/{rail_spec-D6qzh3J0.d.ts → rail_spec-B1239jPp.d.ts} +25 -0
  40. package/dist/stripe-multichain/index.d.mts +61 -11
  41. package/dist/stripe-multichain/index.d.ts +61 -11
  42. package/dist/stripe-multichain/index.js +82 -42
  43. package/dist/stripe-multichain/index.js.map +1 -1
  44. package/dist/stripe-multichain/index.mjs +81 -42
  45. package/dist/stripe-multichain/index.mjs.map +1 -1
  46. package/package.json +5 -5
@@ -19702,50 +19702,76 @@ async function createMultichainPaymentIntent({
19702
19702
  }
19703
19703
 
19704
19704
  // src/stripe-multichain/pay_to_address.ts
19705
+ var DEFAULT_NETWORKS = ["tempo", "base", "solana"];
19705
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) {
19706
19728
  const authHeader = opts.request.headers.get("authorization");
19707
- if (authHeader) {
19708
- const { Credential } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
19709
- if (Credential.extractPaymentScheme(authHeader)) {
19710
- let credential;
19711
- try {
19712
- credential = Credential.fromRequest(opts.request);
19713
- } catch {
19714
- throw new CheckoutValidationError({
19715
- code: "invalid_credential",
19716
- message: "The Authorization: Payment header is not a valid MPP credential.",
19717
- action: "retry_without_credential",
19718
- status: 401
19719
- });
19720
- }
19721
- const method = credential.challenge.method;
19722
- if (method === "tempo" || method === "solana") {
19723
- const toAddress = credential.challenge.request.recipient;
19724
- if (typeof toAddress !== "string" || !toAddress) {
19725
- throw new CheckoutValidationError({
19726
- code: "invalid_credential",
19727
- message: "The MPP credential is missing its recipient field.",
19728
- action: "retry_without_credential",
19729
- status: 401
19730
- });
19731
- }
19732
- if (!await opts.piCache.hasAddress(toAddress)) {
19733
- throw new CheckoutValidationError({
19734
- code: "invalid_credential",
19735
- 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.",
19736
- action: "retry_without_credential",
19737
- status: 401
19738
- });
19739
- }
19740
- return toAddress;
19741
- }
19742
- }
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
+ });
19743
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));
19744
19770
  const idempotencyKey = opts.orderId ? `pi-${opts.orderId}-${opts.amountCents}` : void 0;
19745
19771
  const { paymentIntentId, depositAddresses } = await createMultichainPaymentIntent({
19746
19772
  stripe: opts.stripe,
19747
19773
  amount: opts.amountCents,
19748
- networks: opts.networks ?? ["tempo", "base", "solana"],
19774
+ networks: stripeNetworks,
19749
19775
  ...opts.metadata ? { metadata: opts.metadata } : {},
19750
19776
  ...idempotencyKey ? { idempotencyKey } : {}
19751
19777
  });
@@ -19753,10 +19779,14 @@ async function createPayToAddressFromStripePI(opts) {
19753
19779
  await opts.piCache.cacheAddress(address2);
19754
19780
  opts.piCache.cachePaymentIntent(address2, paymentIntentId);
19755
19781
  }
19756
- opts.piCache.cacheNetworkAddresses(paymentIntentId, depositAddresses);
19757
- const preferred = opts.preferredNetwork ?? "tempo";
19758
- const payTo = depositAddresses[preferred] ?? depositAddresses.base ?? depositAddresses.tempo;
19759
- 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) {
19760
19790
  throw new CheckoutValidationError({
19761
19791
  code: "payment_provider_unavailable",
19762
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.",
@@ -19764,7 +19794,15 @@ async function createPayToAddressFromStripePI(opts) {
19764
19794
  status: 503
19765
19795
  });
19766
19796
  }
19767
- 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);
19768
19806
  }
19769
19807
 
19770
19808
  // src/stripe-multichain/simulate_deposit.ts
@@ -19988,6 +20026,7 @@ export {
19988
20026
  createMultichainPaymentIntent,
19989
20027
  createPayToAddressFromStripePI,
19990
20028
  createPiCache,
20029
+ mintMultichainRecipients,
19991
20030
  networkForOutcome,
19992
20031
  simulateCryptoDeposit,
19993
20032
  simulateDepositForOutcome,