@agent-score/commerce 2.0.1 → 2.1.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 (116) hide show
  1. package/README.md +26 -11
  2. package/dist/_core-kI7FRAiZ.d.mts +10 -0
  3. package/dist/_core-kI7FRAiZ.d.ts +10 -0
  4. package/dist/challenge/index.d.mts +3 -3
  5. package/dist/challenge/index.d.ts +3 -3
  6. package/dist/challenge/index.js +21 -14
  7. package/dist/challenge/index.js.map +1 -1
  8. package/dist/challenge/index.mjs +21 -14
  9. package/dist/challenge/index.mjs.map +1 -1
  10. package/dist/{checkout-B1JuEcbx.d.ts → checkout-BH-I_Ns8.d.ts} +19 -12
  11. package/dist/{checkout-BN5i1Fi7.d.mts → checkout-Bd_4aQ6c.d.mts} +19 -12
  12. package/dist/core.js +1 -1
  13. package/dist/core.js.map +1 -1
  14. package/dist/core.mjs +1 -1
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/default_rails-BWAquZeu.d.mts +188 -0
  17. package/dist/default_rails-BxBzcCA1.d.ts +188 -0
  18. package/dist/discovery/index.d.mts +5 -5
  19. package/dist/discovery/index.d.ts +5 -5
  20. package/dist/discovery/index.js +14 -1
  21. package/dist/discovery/index.js.map +1 -1
  22. package/dist/discovery/index.mjs +14 -1
  23. package/dist/discovery/index.mjs.map +1 -1
  24. package/dist/identity/express.d.mts +7 -3
  25. package/dist/identity/express.d.ts +7 -3
  26. package/dist/identity/express.js +39 -96
  27. package/dist/identity/express.js.map +1 -1
  28. package/dist/identity/express.mjs +37 -87
  29. package/dist/identity/express.mjs.map +1 -1
  30. package/dist/identity/fastify.d.mts +4 -4
  31. package/dist/identity/fastify.d.ts +4 -4
  32. package/dist/identity/fastify.js +60 -96
  33. package/dist/identity/fastify.js.map +1 -1
  34. package/dist/identity/fastify.mjs +58 -87
  35. package/dist/identity/fastify.mjs.map +1 -1
  36. package/dist/identity/hono.d.mts +11 -3
  37. package/dist/identity/hono.d.ts +11 -3
  38. package/dist/identity/hono.js +39 -93
  39. package/dist/identity/hono.js.map +1 -1
  40. package/dist/identity/hono.mjs +37 -84
  41. package/dist/identity/hono.mjs.map +1 -1
  42. package/dist/identity/nextjs.d.mts +10 -3
  43. package/dist/identity/nextjs.d.ts +10 -3
  44. package/dist/identity/nextjs.js +49 -93
  45. package/dist/identity/nextjs.js.map +1 -1
  46. package/dist/identity/nextjs.mjs +46 -84
  47. package/dist/identity/nextjs.mjs.map +1 -1
  48. package/dist/identity/policy.js +220 -129
  49. package/dist/identity/policy.js.map +1 -1
  50. package/dist/identity/policy.mjs +222 -131
  51. package/dist/identity/policy.mjs.map +1 -1
  52. package/dist/identity/web.d.mts +9 -3
  53. package/dist/identity/web.d.ts +9 -3
  54. package/dist/identity/web.js +45 -93
  55. package/dist/identity/web.js.map +1 -1
  56. package/dist/identity/web.mjs +42 -84
  57. package/dist/identity/web.mjs.map +1 -1
  58. package/dist/index.d.mts +554 -90
  59. package/dist/index.d.ts +554 -90
  60. package/dist/index.js +951 -152
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +939 -152
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/middleware/express.d.mts +10 -0
  65. package/dist/middleware/express.d.ts +10 -0
  66. package/dist/middleware/express.js +128 -0
  67. package/dist/middleware/express.js.map +1 -0
  68. package/dist/middleware/express.mjs +91 -0
  69. package/dist/middleware/express.mjs.map +1 -0
  70. package/dist/middleware/fastify.d.mts +10 -0
  71. package/dist/middleware/fastify.d.ts +10 -0
  72. package/dist/middleware/fastify.js +127 -0
  73. package/dist/middleware/fastify.js.map +1 -0
  74. package/dist/middleware/fastify.mjs +90 -0
  75. package/dist/middleware/fastify.mjs.map +1 -0
  76. package/dist/middleware/hono.d.mts +10 -0
  77. package/dist/middleware/hono.d.ts +10 -0
  78. package/dist/middleware/hono.js +122 -0
  79. package/dist/middleware/hono.js.map +1 -0
  80. package/dist/middleware/hono.mjs +85 -0
  81. package/dist/middleware/hono.mjs.map +1 -0
  82. package/dist/middleware/nextjs.d.mts +22 -0
  83. package/dist/middleware/nextjs.d.ts +22 -0
  84. package/dist/middleware/nextjs.js +143 -0
  85. package/dist/middleware/nextjs.js.map +1 -0
  86. package/dist/middleware/nextjs.mjs +105 -0
  87. package/dist/middleware/nextjs.mjs.map +1 -0
  88. package/dist/middleware/web.d.mts +25 -0
  89. package/dist/middleware/web.d.ts +25 -0
  90. package/dist/middleware/web.js +128 -0
  91. package/dist/middleware/web.js.map +1 -0
  92. package/dist/middleware/web.mjs +91 -0
  93. package/dist/middleware/web.mjs.map +1 -0
  94. package/dist/payment/index.d.mts +21 -6
  95. package/dist/payment/index.d.ts +21 -6
  96. package/dist/payment/index.js +136 -9
  97. package/dist/payment/index.js.map +1 -1
  98. package/dist/payment/index.mjs +127 -9
  99. package/dist/payment/index.mjs.map +1 -1
  100. package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
  101. package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
  102. package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
  103. package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
  104. package/dist/stripe-multichain/index.d.mts +150 -47
  105. package/dist/stripe-multichain/index.d.ts +150 -47
  106. package/dist/stripe-multichain/index.js +19749 -42
  107. package/dist/stripe-multichain/index.js.map +1 -1
  108. package/dist/stripe-multichain/index.mjs +19758 -27
  109. package/dist/stripe-multichain/index.mjs.map +1 -1
  110. package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
  111. package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
  112. package/package.json +43 -5
  113. package/dist/_response-BFYN3b6i.d.mts +0 -142
  114. package/dist/_response-_iPD5AIj.d.ts +0 -142
  115. package/dist/solana-Cds87OTu.d.mts +0 -67
  116. package/dist/solana-Cds87OTu.d.ts +0 -67
@@ -20,19 +20,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/identity/nextjs.ts
21
21
  var nextjs_exports = {};
22
22
  __export(nextjs_exports, {
23
- FIXABLE_DENIAL_REASONS: () => FIXABLE_DENIAL_REASONS,
24
23
  agentscoreMiddleware: () => agentscoreMiddleware,
25
- buildContactSupportNextSteps: () => buildContactSupportNextSteps,
26
- buildSignerMismatchBody: () => buildSignerMismatchBody,
27
- denialReasonStatus: () => denialReasonStatus,
28
- denialReasonToBody: () => denialReasonToBody,
29
- isFixableDenial: () => isFixableDenial,
30
- readX402PaymentHeader: () => readX402PaymentHeader,
31
- verificationAgentInstructions: () => verificationAgentInstructions,
32
- withAgentScoreGate: () => withAgentScoreGate
24
+ conditionalAgentscoreMiddleware: () => conditionalAgentscoreMiddleware,
25
+ withAgentScoreGate: () => withAgentScoreGate,
26
+ withConditionalAgentScoreGate: () => withConditionalAgentScoreGate
33
27
  });
34
28
  module.exports = __toCommonJS(nextjs_exports);
35
29
 
30
+ // src/payment/payment_header.ts
31
+ function toTitleCase(name) {
32
+ return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
33
+ }
34
+ function readHeader(headers, name) {
35
+ if (typeof headers.get === "function") {
36
+ return headers.get(name);
37
+ }
38
+ const rec = headers;
39
+ const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
40
+ if (typeof v === "string") return v;
41
+ if (Array.isArray(v) && typeof v[0] === "string") return v[0];
42
+ return null;
43
+ }
44
+ function asHeaders(input) {
45
+ return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
46
+ }
47
+ function hasPaymentHeader(input) {
48
+ const headers = asHeaders(input);
49
+ return Boolean(
50
+ readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
51
+ );
52
+ }
53
+
36
54
  // src/_denial.ts
37
55
  var FIXABLE_DENIAL_REASONS = /* @__PURE__ */ new Set([
38
56
  "kyc_required",
@@ -48,80 +66,6 @@ function denialReasonStatus(reason) {
48
66
  if (reason.code === "api_error") return 503;
49
67
  return 403;
50
68
  }
51
- function buildSignerMismatchBody({
52
- result,
53
- userMessage,
54
- learnMoreUrl
55
- }) {
56
- if (result.kind === "pass") return null;
57
- const learnMoreUrlResolved = learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
58
- if (result.kind === "wallet_signer_mismatch") {
59
- const linkedWallets = result.linkedWallets ?? [];
60
- const userMessageResolved = userMessage ?? (linkedWallets.length > 0 ? `Sign the payment with one of the wallets linked to this operator: ${linkedWallets.join(", ")}. Then retry.` : "Sign the payment with the same wallet you claimed via X-Wallet-Address, or switch to X-Operator-Token for rail-independent identity.");
61
- return {
62
- error: {
63
- code: "wallet_signer_mismatch",
64
- message: "Payment signer does not match the wallet claimed via X-Wallet-Address. The signer and the claimed wallet must both resolve to the same AgentScore operator."
65
- },
66
- claimed_operator: result.claimedOperator,
67
- actual_signer_operator: result.actualSignerOperator ?? null,
68
- expected_signer: result.expectedSigner,
69
- actual_signer: result.actualSigner,
70
- linked_wallets: linkedWallets,
71
- next_steps: {
72
- action: "regenerate_payment_from_linked_wallet",
73
- user_message: userMessageResolved,
74
- learn_more_url: learnMoreUrlResolved
75
- }
76
- };
77
- }
78
- return {
79
- error: {
80
- code: "wallet_auth_requires_wallet_signing",
81
- message: "Wallet-auth requires a payment rail that carries a wallet signature (Tempo MPP, x402). Stripe SPT and card rails have no wallet signer; switch to X-Operator-Token to use those."
82
- },
83
- next_steps: {
84
- action: "switch_to_operator_token",
85
- user_message: userMessage ?? "Drop the X-Wallet-Address header and retry with X-Operator-Token (works on every payment rail).",
86
- learn_more_url: learnMoreUrlResolved
87
- }
88
- };
89
- }
90
- function buildContactSupportNextSteps(supportEmail, message) {
91
- return {
92
- action: "contact_support",
93
- support_email: supportEmail,
94
- user_message: message ?? `If you believe this denial is in error, contact support at ${supportEmail} with the details of your request.`
95
- };
96
- }
97
- function verificationAgentInstructions({
98
- userAction,
99
- retryStep,
100
- extraSteps,
101
- pollIntervalSeconds = 5,
102
- timeoutSeconds = 3600,
103
- orderTtl,
104
- extra
105
- } = {}) {
106
- const baseSteps = [
107
- "Present the verify_url directly to the user \u2014 it is a complete, ready-to-open URL with the session token already embedded (e.g. https://agentscore.sh/verify?session=sess_...). Do NOT modify or construct the URL yourself.",
108
- `Immediately begin polling poll_url every ${pollIntervalSeconds} seconds with header X-Poll-Secret set to poll_secret. The user will complete verification in their browser while you poll in the background.`,
109
- "The user visits the URL, signs in, completes identity verification (photo ID + selfie via Stripe Identity), and closes the tab. They do NOT need to copy or paste anything back to you.",
110
- 'When your poll returns status "verified", extract operator_token from the response. This is a one-time value \u2014 save it immediately. Subsequent polls return status "consumed" without the token.',
111
- retryStep ?? "Retry the original merchant request with header X-Operator-Token set to the operator_token value."
112
- ];
113
- return {
114
- action: "poll_for_credential",
115
- user_action: userAction ?? "The user must visit verify_url to complete identity verification before this request can proceed",
116
- steps: extraSteps ? [...baseSteps, ...extraSteps] : baseSteps,
117
- poll_interval_seconds: pollIntervalSeconds,
118
- poll_secret_header: "X-Poll-Secret",
119
- retry_token_header: "X-Operator-Token",
120
- timeout_seconds: timeoutSeconds,
121
- ...orderTtl ? { order_ttl: orderTtl } : {},
122
- ...extra ?? {}
123
- };
124
- }
125
69
 
126
70
  // src/_response.ts
127
71
  var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
@@ -371,7 +315,7 @@ function createAgentScoreCore(options) {
371
315
  } = options;
372
316
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
373
317
  const agentMemoryHint = buildAgentMemoryHint();
374
- const defaultUa = `@agent-score/commerce@${"2.0.1"}`;
318
+ const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
375
319
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
376
320
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
377
321
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -806,17 +750,29 @@ function agentscoreMiddleware(options) {
806
750
  return result.allowed ? void 0 : result.response;
807
751
  };
808
752
  }
753
+ function withConditionalAgentScoreGate(options, handler) {
754
+ const wrapped = withAgentScoreGate(options, handler);
755
+ return async (req, ctx) => {
756
+ if (!hasPaymentHeader(req)) {
757
+ const result = handler(req, {}, ctx);
758
+ return result instanceof Promise ? result : Promise.resolve(result);
759
+ }
760
+ return wrapped(req, ctx);
761
+ };
762
+ }
763
+ function conditionalAgentscoreMiddleware(options) {
764
+ const guard = createAgentScoreGate(options);
765
+ return async (req) => {
766
+ if (!hasPaymentHeader(req)) return void 0;
767
+ const result = await guard(req);
768
+ return result.allowed ? void 0 : result.response;
769
+ };
770
+ }
809
771
  // Annotate the CommonJS export names for ESM import in node:
810
772
  0 && (module.exports = {
811
- FIXABLE_DENIAL_REASONS,
812
773
  agentscoreMiddleware,
813
- buildContactSupportNextSteps,
814
- buildSignerMismatchBody,
815
- denialReasonStatus,
816
- denialReasonToBody,
817
- isFixableDenial,
818
- readX402PaymentHeader,
819
- verificationAgentInstructions,
820
- withAgentScoreGate
774
+ conditionalAgentscoreMiddleware,
775
+ withAgentScoreGate,
776
+ withConditionalAgentScoreGate
821
777
  });
822
778
  //# sourceMappingURL=nextjs.js.map