@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
@@ -1,7 +1,6 @@
1
- export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-BFYN3b6i.mjs';
2
- export { r as readX402PaymentHeader } from '../signer-3FAit11j.mjs';
3
1
  import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo, SignerVerdict } from '../core.mjs';
4
2
  import { Request, Response, NextFunction } from 'express';
3
+ import '../signer-3FAit11j.mjs';
5
4
 
6
5
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
7
6
  /** Custom function to extract agent identity (wallet address and/or operator token). */
@@ -55,5 +54,10 @@ declare function captureWallet(req: Request, options: {
55
54
  * only needs to consume this getter for the `signer_match` wallet-binding verdict.
56
55
  */
57
56
  declare function getSignerVerdict(req: Request): SignerVerdict | undefined;
57
+ /** Wrap `agentscoreGate(...)` so it only fires when a payment credential is
58
+ * attached to the request. Discovery legs (no payment header) flow through
59
+ * unauthenticated and the handler emits a 402 with all rails; settle legs
60
+ * trigger the full gate. */
61
+ declare function conditionalAgentscoreGate(options: AgentScoreGateOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
58
62
 
59
- export { agentscoreGate, captureWallet, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
63
+ export { agentscoreGate, captureWallet, conditionalAgentscoreGate, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
@@ -1,7 +1,6 @@
1
- export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-_iPD5AIj.js';
2
- export { r as readX402PaymentHeader } from '../signer-3FAit11j.js';
3
1
  import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo, SignerVerdict } from '../core.js';
4
2
  import { Request, Response, NextFunction } from 'express';
3
+ import '../signer-3FAit11j.js';
5
4
 
6
5
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
7
6
  /** Custom function to extract agent identity (wallet address and/or operator token). */
@@ -55,5 +54,10 @@ declare function captureWallet(req: Request, options: {
55
54
  * only needs to consume this getter for the `signer_match` wallet-binding verdict.
56
55
  */
57
56
  declare function getSignerVerdict(req: Request): SignerVerdict | undefined;
57
+ /** Wrap `agentscoreGate(...)` so it only fires when a payment credential is
58
+ * attached to the request. Discovery legs (no payment header) flow through
59
+ * unauthenticated and the handler emits a 402 with all rails; settle legs
60
+ * trigger the full gate. */
61
+ declare function conditionalAgentscoreGate(options: AgentScoreGateOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
58
62
 
59
- export { agentscoreGate, captureWallet, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
63
+ export { agentscoreGate, captureWallet, conditionalAgentscoreGate, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
@@ -20,20 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/identity/express.ts
21
21
  var express_exports = {};
22
22
  __export(express_exports, {
23
- FIXABLE_DENIAL_REASONS: () => FIXABLE_DENIAL_REASONS,
24
23
  agentscoreGate: () => agentscoreGate,
25
- buildContactSupportNextSteps: () => buildContactSupportNextSteps,
26
- buildSignerMismatchBody: () => buildSignerMismatchBody,
27
24
  captureWallet: () => captureWallet,
28
- denialReasonStatus: () => denialReasonStatus,
29
- denialReasonToBody: () => denialReasonToBody,
25
+ conditionalAgentscoreGate: () => conditionalAgentscoreGate,
30
26
  getAgentScoreData: () => getAgentScoreData,
31
27
  getGateDegradedState: () => getGateDegradedState,
32
28
  getGateQuotaInfo: () => getGateQuotaInfo,
33
- getSignerVerdict: () => getSignerVerdict,
34
- isFixableDenial: () => isFixableDenial,
35
- readX402PaymentHeader: () => readX402PaymentHeader,
36
- verificationAgentInstructions: () => verificationAgentInstructions
29
+ getSignerVerdict: () => getSignerVerdict
37
30
  });
38
31
  module.exports = __toCommonJS(express_exports);
39
32
 
@@ -52,80 +45,6 @@ function denialReasonStatus(reason) {
52
45
  if (reason.code === "api_error") return 503;
53
46
  return 403;
54
47
  }
55
- function buildSignerMismatchBody({
56
- result,
57
- userMessage,
58
- learnMoreUrl
59
- }) {
60
- if (result.kind === "pass") return null;
61
- const learnMoreUrlResolved = learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
62
- if (result.kind === "wallet_signer_mismatch") {
63
- const linkedWallets = result.linkedWallets ?? [];
64
- 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.");
65
- return {
66
- error: {
67
- code: "wallet_signer_mismatch",
68
- 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."
69
- },
70
- claimed_operator: result.claimedOperator,
71
- actual_signer_operator: result.actualSignerOperator ?? null,
72
- expected_signer: result.expectedSigner,
73
- actual_signer: result.actualSigner,
74
- linked_wallets: linkedWallets,
75
- next_steps: {
76
- action: "regenerate_payment_from_linked_wallet",
77
- user_message: userMessageResolved,
78
- learn_more_url: learnMoreUrlResolved
79
- }
80
- };
81
- }
82
- return {
83
- error: {
84
- code: "wallet_auth_requires_wallet_signing",
85
- 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."
86
- },
87
- next_steps: {
88
- action: "switch_to_operator_token",
89
- user_message: userMessage ?? "Drop the X-Wallet-Address header and retry with X-Operator-Token (works on every payment rail).",
90
- learn_more_url: learnMoreUrlResolved
91
- }
92
- };
93
- }
94
- function buildContactSupportNextSteps(supportEmail, message) {
95
- return {
96
- action: "contact_support",
97
- support_email: supportEmail,
98
- user_message: message ?? `If you believe this denial is in error, contact support at ${supportEmail} with the details of your request.`
99
- };
100
- }
101
- function verificationAgentInstructions({
102
- userAction,
103
- retryStep,
104
- extraSteps,
105
- pollIntervalSeconds = 5,
106
- timeoutSeconds = 3600,
107
- orderTtl,
108
- extra
109
- } = {}) {
110
- const baseSteps = [
111
- "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.",
112
- `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.`,
113
- "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.",
114
- '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.',
115
- retryStep ?? "Retry the original merchant request with header X-Operator-Token set to the operator_token value."
116
- ];
117
- return {
118
- action: "poll_for_credential",
119
- user_action: userAction ?? "The user must visit verify_url to complete identity verification before this request can proceed",
120
- steps: extraSteps ? [...baseSteps, ...extraSteps] : baseSteps,
121
- poll_interval_seconds: pollIntervalSeconds,
122
- poll_secret_header: "X-Poll-Secret",
123
- retry_token_header: "X-Operator-Token",
124
- timeout_seconds: timeoutSeconds,
125
- ...orderTtl ? { order_ttl: orderTtl } : {},
126
- ...extra ?? {}
127
- };
128
- }
129
48
 
130
49
  // src/_response.ts
131
50
  var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
@@ -375,7 +294,7 @@ function createAgentScoreCore(options) {
375
294
  } = options;
376
295
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
377
296
  const agentMemoryHint = buildAgentMemoryHint();
378
- const defaultUa = `@agent-score/commerce@${"2.0.1"}`;
297
+ const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
379
298
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
380
299
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
381
300
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -667,6 +586,30 @@ function createAgentScoreCore(options) {
667
586
  return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
668
587
  }
669
588
 
589
+ // src/payment/payment_header.ts
590
+ function toTitleCase(name) {
591
+ return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
592
+ }
593
+ function readHeader(headers, name) {
594
+ if (typeof headers.get === "function") {
595
+ return headers.get(name);
596
+ }
597
+ const rec = headers;
598
+ const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
599
+ if (typeof v === "string") return v;
600
+ if (Array.isArray(v) && typeof v[0] === "string") return v[0];
601
+ return null;
602
+ }
603
+ function asHeaders(input) {
604
+ return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
605
+ }
606
+ function hasPaymentHeader(input) {
607
+ const headers = asHeaders(input);
608
+ return Boolean(
609
+ readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
610
+ );
611
+ }
612
+
670
613
  // src/signer.ts
671
614
  var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
672
615
  var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
@@ -746,9 +689,6 @@ async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
746
689
  });
747
690
  return extractPaymentSigner(request, x402PaymentHeader);
748
691
  }
749
- function readX402PaymentHeader(request) {
750
- return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
751
- }
752
692
 
753
693
  // src/identity/express.ts
754
694
  var GATE_STATE_KEY = "__agentscoreGate";
@@ -820,21 +760,24 @@ function getSignerVerdict(req) {
820
760
  if (!state?.walletAddress) return void 0;
821
761
  return state.core.getSignerVerdict(state.walletAddress);
822
762
  }
763
+ function conditionalAgentscoreGate(options) {
764
+ const gate = agentscoreGate(options);
765
+ return async function conditionalGateMiddleware(req, res, next) {
766
+ if (!hasPaymentHeader(req.headers)) {
767
+ next();
768
+ return;
769
+ }
770
+ return gate(req, res, next);
771
+ };
772
+ }
823
773
  // Annotate the CommonJS export names for ESM import in node:
824
774
  0 && (module.exports = {
825
- FIXABLE_DENIAL_REASONS,
826
775
  agentscoreGate,
827
- buildContactSupportNextSteps,
828
- buildSignerMismatchBody,
829
776
  captureWallet,
830
- denialReasonStatus,
831
- denialReasonToBody,
777
+ conditionalAgentscoreGate,
832
778
  getAgentScoreData,
833
779
  getGateDegradedState,
834
780
  getGateQuotaInfo,
835
- getSignerVerdict,
836
- isFixableDenial,
837
- readX402PaymentHeader,
838
- verificationAgentInstructions
781
+ getSignerVerdict
839
782
  });
840
783
  //# sourceMappingURL=express.js.map