@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
@@ -565,6 +565,9 @@ async function verifyX402Request({
565
565
  return { ok: true, payload, signedNetwork, signedPayTo };
566
566
  }
567
567
 
568
+ // src/payment/mppx_server.ts
569
+ import { AsyncLocalStorage } from "async_hooks";
570
+
568
571
  // src/stripe-multichain/mppx_stripe.ts
569
572
  async function createMppxStripe({
570
573
  profileId,
@@ -743,6 +746,31 @@ function wrapSolanaChargeWithFinalizedBlockhash(baseMethod, rpcUrl) {
743
746
  }
744
747
  };
745
748
  }
749
+ var mppxCapture = new AsyncLocalStorage();
750
+ var consoleErrorPatched = false;
751
+ function ensureConsoleErrorPatch() {
752
+ if (consoleErrorPatched) return;
753
+ consoleErrorPatched = true;
754
+ const original = console.error.bind(console);
755
+ console.error = function captureMppxInternal(...args) {
756
+ if (args[0] === "mppx: internal verification error" && args[1] !== void 0) {
757
+ const ctx = mppxCapture.getStore();
758
+ if (ctx) {
759
+ const e = args[1];
760
+ const reason = typeof e?.shortMessage === "string" ? e.shortMessage : typeof e?.message === "string" ? e.message : String(args[1]);
761
+ const details = e?.details;
762
+ ctx.reason = typeof details === "string" && details.length > 0 ? `${reason} (${details})` : reason;
763
+ }
764
+ }
765
+ return original(...args);
766
+ };
767
+ }
768
+ async function runWithMppxFailureCapture(fn) {
769
+ ensureConsoleErrorPatch();
770
+ const ctx = { reason: null };
771
+ const result = await mppxCapture.run(ctx, fn);
772
+ return { result, failureReason: ctx.reason };
773
+ }
746
774
  async function composeMppxRequest(mppx, intents, request) {
747
775
  if (!mppx || typeof mppx !== "object" || !("compose" in mppx)) {
748
776
  throw new Error("composeMppxRequest: argument is not an mppx server instance");
@@ -751,6 +779,7 @@ async function composeMppxRequest(mppx, intents, request) {
751
779
  if (typeof compose !== "function") {
752
780
  throw new Error("composeMppxRequest: mppx.compose is not a function");
753
781
  }
782
+ ensureConsoleErrorPatch();
754
783
  const typedCompose = compose;
755
784
  const handler = typedCompose.apply(mppx, [...intents]);
756
785
  return handler(request);
@@ -759,6 +788,22 @@ function mppxChallengeHeaders(result) {
759
788
  return Object.fromEntries(result.challenge.headers);
760
789
  }
761
790
 
791
+ // src/errors.ts
792
+ var CheckoutValidationError = class extends Error {
793
+ code;
794
+ action;
795
+ status;
796
+ extra;
797
+ constructor(opts) {
798
+ super(opts.message);
799
+ this.name = "CheckoutValidationError";
800
+ this.code = opts.code;
801
+ this.action = opts.action ?? "fix_request";
802
+ this.status = opts.status ?? 400;
803
+ this.extra = opts.extra;
804
+ }
805
+ };
806
+
762
807
  // src/payment/dispatch.ts
763
808
  function detectRailFromHeaders(headers) {
764
809
  const get = (name) => {
@@ -787,17 +832,32 @@ async function dispatchSettlementByNetwork(payload, handlers) {
787
832
  const network = payload.accepted.network;
788
833
  if (network.startsWith("eip155:")) {
789
834
  if (!handlers.evm) {
790
- throw new Error(`No EVM settlement handler registered (network: ${network})`);
835
+ throw new CheckoutValidationError({
836
+ code: "payment_provider_unavailable",
837
+ message: `No EVM settlement handler registered (network: ${network})`,
838
+ action: "retry_later",
839
+ status: 503
840
+ });
791
841
  }
792
842
  return handlers.evm(payload);
793
843
  }
794
844
  if (network.startsWith("solana:")) {
795
845
  if (!handlers.svm) {
796
- throw new Error(`No Solana settlement handler registered (network: ${network})`);
846
+ throw new CheckoutValidationError({
847
+ code: "payment_provider_unavailable",
848
+ message: `No Solana settlement handler registered (network: ${network})`,
849
+ action: "retry_later",
850
+ status: 503
851
+ });
797
852
  }
798
853
  return handlers.svm(payload);
799
854
  }
800
- throw new Error(`Unrecognized network in settlement payload: ${network}`);
855
+ throw new CheckoutValidationError({
856
+ code: "payment_provider_unavailable",
857
+ message: `Unrecognized network in settlement payload: ${network}`,
858
+ action: "retry_later",
859
+ status: 503
860
+ });
801
861
  }
802
862
 
803
863
  // src/payment/wwwauthenticate.ts
@@ -1172,7 +1232,11 @@ async function loadSolanaFeePayer(opts) {
1172
1232
  return kit.createKeyPairSignerFromPrivateKeyBytes(bytes);
1173
1233
  }
1174
1234
 
1235
+ // src/payment/constants.ts
1236
+ var STRIPE_MIN_CHARGE_USD = 0.5;
1237
+
1175
1238
  // src/payment/compose_rails.ts
1239
+ var warnedStripeBelowMinimum = false;
1176
1240
  function buildMppxComposeRails(opts) {
1177
1241
  const rails2 = [];
1178
1242
  if (opts.tempoRecipient) {
@@ -1194,7 +1258,17 @@ function buildMppxComposeRails(opts) {
1194
1258
  }]);
1195
1259
  }
1196
1260
  if (opts.includeStripe !== false) {
1197
- rails2.push(["stripe/charge", { amount: opts.amountUsd, currency: "usd", decimals: 2 }]);
1261
+ const amountUsdNumeric = Number(opts.amountUsd);
1262
+ if (Number.isFinite(amountUsdNumeric) && amountUsdNumeric < STRIPE_MIN_CHARGE_USD) {
1263
+ if (!warnedStripeBelowMinimum) {
1264
+ warnedStripeBelowMinimum = true;
1265
+ console.warn(
1266
+ `[buildMppxComposeRails] Dropping stripe/charge rail: amountUsd=${opts.amountUsd} is below Stripe's $${STRIPE_MIN_CHARGE_USD.toFixed(2)} USD minimum. Stripe's fixed ~$0.30 fee makes sub-50-cent charges unprofitable (and many accounts reject PI creation with amount_too_small below this floor). Pass includeStripe: false to suppress this warning.`
1267
+ );
1268
+ }
1269
+ } else {
1270
+ rails2.push(["stripe/charge", { amount: opts.amountUsd, currency: "usd", decimals: 2 }]);
1271
+ }
1198
1272
  }
1199
1273
  return rails2;
1200
1274
  }
@@ -1322,6 +1396,7 @@ export {
1322
1396
  readX402PaymentHeader,
1323
1397
  registerX402SchemesV1V2,
1324
1398
  resolveRecipient,
1399
+ runWithMppxFailureCapture,
1325
1400
  settlementOverrideHeader,
1326
1401
  usdToAtomic,
1327
1402
  validateX402NetworkConfig,