@agent-score/commerce 2.1.0 → 2.1.1

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 (64) hide show
  1. package/README.md +1 -1
  2. package/dist/challenge/index.js.map +1 -1
  3. package/dist/challenge/index.mjs.map +1 -1
  4. package/dist/{checkout-Bd_4aQ6c.d.mts → checkout-BRw_caGr.d.mts} +1 -22
  5. package/dist/{checkout-BH-I_Ns8.d.ts → checkout-CuSNUJFX.d.ts} +1 -22
  6. package/dist/core.js +1 -1
  7. package/dist/core.js.map +1 -1
  8. package/dist/core.mjs +1 -1
  9. package/dist/core.mjs.map +1 -1
  10. package/dist/{default_rails-BxBzcCA1.d.ts → default_rails-C5gKZJMI.d.ts} +11 -1
  11. package/dist/{default_rails-BWAquZeu.d.mts → default_rails-XFCuRddA.d.mts} +11 -1
  12. package/dist/discovery/index.d.mts +1 -1
  13. package/dist/discovery/index.d.ts +1 -1
  14. package/dist/identity/express.js +1 -1
  15. package/dist/identity/express.js.map +1 -1
  16. package/dist/identity/express.mjs +1 -1
  17. package/dist/identity/express.mjs.map +1 -1
  18. package/dist/identity/fastify.js +1 -1
  19. package/dist/identity/fastify.js.map +1 -1
  20. package/dist/identity/fastify.mjs +1 -1
  21. package/dist/identity/fastify.mjs.map +1 -1
  22. package/dist/identity/hono.js +1 -1
  23. package/dist/identity/hono.js.map +1 -1
  24. package/dist/identity/hono.mjs +1 -1
  25. package/dist/identity/hono.mjs.map +1 -1
  26. package/dist/identity/nextjs.js +1 -1
  27. package/dist/identity/nextjs.js.map +1 -1
  28. package/dist/identity/nextjs.mjs +1 -1
  29. package/dist/identity/nextjs.mjs.map +1 -1
  30. package/dist/identity/policy.js +22 -23363
  31. package/dist/identity/policy.js.map +1 -1
  32. package/dist/identity/policy.mjs +1 -23366
  33. package/dist/identity/policy.mjs.map +1 -1
  34. package/dist/identity/web.js +1 -1
  35. package/dist/identity/web.js.map +1 -1
  36. package/dist/identity/web.mjs +1 -1
  37. package/dist/identity/web.mjs.map +1 -1
  38. package/dist/index.d.mts +72 -5
  39. package/dist/index.d.ts +72 -5
  40. package/dist/index.js +256 -136
  41. package/dist/index.js.map +1 -1
  42. package/dist/index.mjs +253 -134
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/middleware/express.js.map +1 -1
  45. package/dist/middleware/express.mjs.map +1 -1
  46. package/dist/middleware/fastify.js.map +1 -1
  47. package/dist/middleware/fastify.mjs.map +1 -1
  48. package/dist/middleware/hono.js.map +1 -1
  49. package/dist/middleware/hono.mjs.map +1 -1
  50. package/dist/middleware/nextjs.js.map +1 -1
  51. package/dist/middleware/nextjs.mjs.map +1 -1
  52. package/dist/middleware/web.js.map +1 -1
  53. package/dist/middleware/web.mjs.map +1 -1
  54. package/dist/payment/index.d.mts +13 -17
  55. package/dist/payment/index.d.ts +13 -17
  56. package/dist/payment/index.js +80 -4
  57. package/dist/payment/index.js.map +1 -1
  58. package/dist/payment/index.mjs +79 -4
  59. package/dist/payment/index.mjs.map +1 -1
  60. package/dist/stripe-multichain/index.js +53 -4
  61. package/dist/stripe-multichain/index.js.map +1 -1
  62. package/dist/stripe-multichain/index.mjs +53 -4
  63. package/dist/stripe-multichain/index.mjs.map +1 -1
  64. package/package.json +4 -4
@@ -19660,6 +19660,22 @@ __export(stripe_multichain_exports, {
19660
19660
  });
19661
19661
  module.exports = __toCommonJS(stripe_multichain_exports);
19662
19662
 
19663
+ // src/errors.ts
19664
+ var CheckoutValidationError = class extends Error {
19665
+ code;
19666
+ action;
19667
+ status;
19668
+ extra;
19669
+ constructor(opts) {
19670
+ super(opts.message);
19671
+ this.name = "CheckoutValidationError";
19672
+ this.code = opts.code;
19673
+ this.action = opts.action ?? "fix_request";
19674
+ this.status = opts.status ?? 400;
19675
+ this.extra = opts.extra;
19676
+ }
19677
+ };
19678
+
19663
19679
  // src/stripe-multichain/payment_intent.ts
19664
19680
  async function createMultichainPaymentIntent({
19665
19681
  stripe,
@@ -19692,7 +19708,12 @@ async function createMultichainPaymentIntent({
19692
19708
  if (info?.address) depositAddresses[network] = info.address;
19693
19709
  }
19694
19710
  if (Object.keys(depositAddresses).length === 0) {
19695
- throw new Error("No deposit addresses returned from Stripe PaymentIntent");
19711
+ throw new CheckoutValidationError({
19712
+ code: "payment_provider_unavailable",
19713
+ message: "Stripe returned no crypto deposit addresses for this PaymentIntent. The account may not be enrolled in the Stablecoins and Crypto preview, or the feature was revoked.",
19714
+ action: "retry_later",
19715
+ status: 503
19716
+ });
19696
19717
  }
19697
19718
  return { paymentIntentId: pi.id, depositAddresses };
19698
19719
  }
@@ -19703,12 +19724,35 @@ async function createPayToAddressFromStripePI(opts) {
19703
19724
  if (authHeader) {
19704
19725
  const { Credential } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
19705
19726
  if (Credential.extractPaymentScheme(authHeader)) {
19706
- const credential = Credential.fromRequest(opts.request);
19727
+ let credential;
19728
+ try {
19729
+ credential = Credential.fromRequest(opts.request);
19730
+ } catch {
19731
+ throw new CheckoutValidationError({
19732
+ code: "invalid_credential",
19733
+ message: "The Authorization: Payment header is not a valid MPP credential.",
19734
+ action: "retry_without_credential",
19735
+ status: 401
19736
+ });
19737
+ }
19707
19738
  const method = credential.challenge.method;
19708
19739
  if (method === "tempo" || method === "solana") {
19709
19740
  const toAddress = credential.challenge.request.recipient;
19741
+ if (typeof toAddress !== "string" || !toAddress) {
19742
+ throw new CheckoutValidationError({
19743
+ code: "invalid_credential",
19744
+ message: "The MPP credential is missing its recipient field.",
19745
+ action: "retry_without_credential",
19746
+ status: 401
19747
+ });
19748
+ }
19710
19749
  if (!await opts.piCache.hasAddress(toAddress)) {
19711
- throw new Error("Invalid payTo address: not found in cache or expired");
19750
+ throw new CheckoutValidationError({
19751
+ code: "invalid_credential",
19752
+ 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.",
19753
+ action: "retry_without_credential",
19754
+ status: 401
19755
+ });
19712
19756
  }
19713
19757
  return toAddress;
19714
19758
  }
@@ -19730,7 +19774,12 @@ async function createPayToAddressFromStripePI(opts) {
19730
19774
  const preferred = opts.preferredNetwork ?? "tempo";
19731
19775
  const payTo = depositAddresses[preferred] ?? depositAddresses.base ?? depositAddresses.tempo;
19732
19776
  if (!payTo) {
19733
- throw new Error("Failed to resolve pay_to address from Stripe PaymentIntent");
19777
+ throw new CheckoutValidationError({
19778
+ code: "payment_provider_unavailable",
19779
+ 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.",
19780
+ action: "retry_later",
19781
+ status: 503
19782
+ });
19734
19783
  }
19735
19784
  return payTo;
19736
19785
  }