@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
@@ -5,7 +5,7 @@ export { B as BuildX402AcceptsForOptions, C as CreateX402ServerOptions, X as X40
5
5
  export { a as aliasAmountFields, p as paymentRequiredHeader, w as wwwAuthenticateHeader } from '../wwwauthenticate-D_FMnPgU.js';
6
6
  import { S as SignerNetwork } from '../signer-3FAit11j.js';
7
7
  export { P as PaymentSigner, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from '../signer-3FAit11j.js';
8
- export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../default_rails-BxBzcCA1.js';
8
+ export { B as BuildDefaultCheckoutRailsOptions, a as BuildMppxComposeRailsOptions, H as HeadersLike, b as asHeaders, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, l as loadSolanaFeePayer, r as readHeader, u as usdToAtomic } from '../default_rails-C5gKZJMI.js';
9
9
 
10
10
  /**
11
11
  * Build the base64-encoded `request` blob for an MPP Payment directive (per the
@@ -569,21 +569,17 @@ type MppxComposeResult = {
569
569
  challenge: Response;
570
570
  [k: string]: unknown;
571
571
  };
572
- /**
573
- * Run `mppx.compose(...intents)(request)` with a typed return. Replaces the
574
- * `(mppx as any).compose(...intents)(request)` cast every hand-rolled
575
- * `composeMppx` hook ends up writing.
576
- *
577
- * @example
578
- * ```ts
579
- * const result = await composeMppxRequest(mppx, [
580
- * ['tempo/charge', { amount, currency, decimals, recipient }],
581
- * ['stripe/charge', { amount, currency: 'usd', decimals: 2 }],
582
- * ], ctx.request.raw);
583
- * if (result.status === 402) return { status: 402, headers: mppxChallengeHeaders(result) };
584
- * return { status: 200, raw: result };
585
- * ```
586
- */
572
+ /** Run `fn` inside an async context that captures the inner mppx
573
+ * verification error (when one fires). Returns the function's result
574
+ * plus the captured `failureReason` string (null if no error fired or
575
+ * no console.error hit during this scope). Used by `Checkout.handleMppx`
576
+ * to surface typed error codes (`tempo_key_not_registered`, etc.) on
577
+ * the 402 path without changing the per-merchant `composeMppx` API.
578
+ */
579
+ declare function runWithMppxFailureCapture<T>(fn: () => Promise<T>): Promise<{
580
+ result: T;
581
+ failureReason: string | null;
582
+ }>;
587
583
  declare function composeMppxRequest(mppx: unknown, intents: readonly unknown[], request: Request): Promise<MppxComposeResult>;
588
584
  /**
589
585
  * Extract the 402 challenge response's headers as a plain `Record<string, string>`,
@@ -894,4 +890,4 @@ declare function isEvmNetwork(input: NetworkLike): boolean;
894
890
  * network spec — this helper treats it as false. */
895
891
  declare function isSolanaNetwork(input: NetworkLike): boolean;
896
892
 
897
- export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleResult, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, isEvmNetwork, isSolanaNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
893
+ export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleResult, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, isEvmNetwork, isSolanaNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
@@ -64,6 +64,7 @@ __export(payment_exports, {
64
64
  readX402PaymentHeader: () => readX402PaymentHeader,
65
65
  registerX402SchemesV1V2: () => registerX402SchemesV1V2,
66
66
  resolveRecipient: () => resolveRecipient,
67
+ runWithMppxFailureCapture: () => runWithMppxFailureCapture,
67
68
  settlementOverrideHeader: () => settlementOverrideHeader,
68
69
  usdToAtomic: () => usdToAtomic,
69
70
  validateX402NetworkConfig: () => validateX402NetworkConfig,
@@ -641,6 +642,9 @@ async function verifyX402Request({
641
642
  return { ok: true, payload, signedNetwork, signedPayTo };
642
643
  }
643
644
 
645
+ // src/payment/mppx_server.ts
646
+ var import_node_async_hooks = require("async_hooks");
647
+
644
648
  // src/stripe-multichain/mppx_stripe.ts
645
649
  async function createMppxStripe({
646
650
  profileId,
@@ -819,6 +823,31 @@ function wrapSolanaChargeWithFinalizedBlockhash(baseMethod, rpcUrl) {
819
823
  }
820
824
  };
821
825
  }
826
+ var mppxCapture = new import_node_async_hooks.AsyncLocalStorage();
827
+ var consoleErrorPatched = false;
828
+ function ensureConsoleErrorPatch() {
829
+ if (consoleErrorPatched) return;
830
+ consoleErrorPatched = true;
831
+ const original = console.error.bind(console);
832
+ console.error = function captureMppxInternal(...args) {
833
+ if (args[0] === "mppx: internal verification error" && args[1] !== void 0) {
834
+ const ctx = mppxCapture.getStore();
835
+ if (ctx) {
836
+ const e = args[1];
837
+ const reason = typeof e?.shortMessage === "string" ? e.shortMessage : typeof e?.message === "string" ? e.message : String(args[1]);
838
+ const details = e?.details;
839
+ ctx.reason = typeof details === "string" && details.length > 0 ? `${reason} (${details})` : reason;
840
+ }
841
+ }
842
+ return original(...args);
843
+ };
844
+ }
845
+ async function runWithMppxFailureCapture(fn) {
846
+ ensureConsoleErrorPatch();
847
+ const ctx = { reason: null };
848
+ const result = await mppxCapture.run(ctx, fn);
849
+ return { result, failureReason: ctx.reason };
850
+ }
822
851
  async function composeMppxRequest(mppx, intents, request) {
823
852
  if (!mppx || typeof mppx !== "object" || !("compose" in mppx)) {
824
853
  throw new Error("composeMppxRequest: argument is not an mppx server instance");
@@ -827,6 +856,7 @@ async function composeMppxRequest(mppx, intents, request) {
827
856
  if (typeof compose !== "function") {
828
857
  throw new Error("composeMppxRequest: mppx.compose is not a function");
829
858
  }
859
+ ensureConsoleErrorPatch();
830
860
  const typedCompose = compose;
831
861
  const handler = typedCompose.apply(mppx, [...intents]);
832
862
  return handler(request);
@@ -835,6 +865,22 @@ function mppxChallengeHeaders(result) {
835
865
  return Object.fromEntries(result.challenge.headers);
836
866
  }
837
867
 
868
+ // src/errors.ts
869
+ var CheckoutValidationError = class extends Error {
870
+ code;
871
+ action;
872
+ status;
873
+ extra;
874
+ constructor(opts) {
875
+ super(opts.message);
876
+ this.name = "CheckoutValidationError";
877
+ this.code = opts.code;
878
+ this.action = opts.action ?? "fix_request";
879
+ this.status = opts.status ?? 400;
880
+ this.extra = opts.extra;
881
+ }
882
+ };
883
+
838
884
  // src/payment/dispatch.ts
839
885
  function detectRailFromHeaders(headers) {
840
886
  const get = (name) => {
@@ -863,17 +909,32 @@ async function dispatchSettlementByNetwork(payload, handlers) {
863
909
  const network = payload.accepted.network;
864
910
  if (network.startsWith("eip155:")) {
865
911
  if (!handlers.evm) {
866
- throw new Error(`No EVM settlement handler registered (network: ${network})`);
912
+ throw new CheckoutValidationError({
913
+ code: "payment_provider_unavailable",
914
+ message: `No EVM settlement handler registered (network: ${network})`,
915
+ action: "retry_later",
916
+ status: 503
917
+ });
867
918
  }
868
919
  return handlers.evm(payload);
869
920
  }
870
921
  if (network.startsWith("solana:")) {
871
922
  if (!handlers.svm) {
872
- throw new Error(`No Solana settlement handler registered (network: ${network})`);
923
+ throw new CheckoutValidationError({
924
+ code: "payment_provider_unavailable",
925
+ message: `No Solana settlement handler registered (network: ${network})`,
926
+ action: "retry_later",
927
+ status: 503
928
+ });
873
929
  }
874
930
  return handlers.svm(payload);
875
931
  }
876
- throw new Error(`Unrecognized network in settlement payload: ${network}`);
932
+ throw new CheckoutValidationError({
933
+ code: "payment_provider_unavailable",
934
+ message: `Unrecognized network in settlement payload: ${network}`,
935
+ action: "retry_later",
936
+ status: 503
937
+ });
877
938
  }
878
939
 
879
940
  // src/payment/wwwauthenticate.ts
@@ -1248,7 +1309,11 @@ async function loadSolanaFeePayer(opts) {
1248
1309
  return kit.createKeyPairSignerFromPrivateKeyBytes(bytes);
1249
1310
  }
1250
1311
 
1312
+ // src/payment/constants.ts
1313
+ var STRIPE_MIN_CHARGE_USD = 0.5;
1314
+
1251
1315
  // src/payment/compose_rails.ts
1316
+ var warnedStripeBelowMinimum = false;
1252
1317
  function buildMppxComposeRails(opts) {
1253
1318
  const rails2 = [];
1254
1319
  if (opts.tempoRecipient) {
@@ -1270,7 +1335,17 @@ function buildMppxComposeRails(opts) {
1270
1335
  }]);
1271
1336
  }
1272
1337
  if (opts.includeStripe !== false) {
1273
- rails2.push(["stripe/charge", { amount: opts.amountUsd, currency: "usd", decimals: 2 }]);
1338
+ const amountUsdNumeric = Number(opts.amountUsd);
1339
+ if (Number.isFinite(amountUsdNumeric) && amountUsdNumeric < STRIPE_MIN_CHARGE_USD) {
1340
+ if (!warnedStripeBelowMinimum) {
1341
+ warnedStripeBelowMinimum = true;
1342
+ console.warn(
1343
+ `[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.`
1344
+ );
1345
+ }
1346
+ } else {
1347
+ rails2.push(["stripe/charge", { amount: opts.amountUsd, currency: "usd", decimals: 2 }]);
1348
+ }
1274
1349
  }
1275
1350
  return rails2;
1276
1351
  }
@@ -1399,6 +1474,7 @@ function isSolanaNetwork(input) {
1399
1474
  readX402PaymentHeader,
1400
1475
  registerX402SchemesV1V2,
1401
1476
  resolveRecipient,
1477
+ runWithMppxFailureCapture,
1402
1478
  settlementOverrideHeader,
1403
1479
  usdToAtomic,
1404
1480
  validateX402NetworkConfig,