@agent-score/commerce 2.0.2 → 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 (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-jNUIql6D.d.mts → checkout-BRw_caGr.d.mts} +13 -33
  11. package/dist/{checkout-DhSj_h94.d.ts → checkout-CuSNUJFX.d.ts} +13 -33
  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-C5gKZJMI.d.ts +198 -0
  17. package/dist/default_rails-XFCuRddA.d.mts +198 -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 +22 -23317
  49. package/dist/identity/policy.js.map +1 -1
  50. package/dist/identity/policy.mjs +1 -23320
  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 +621 -90
  59. package/dist/index.d.ts +621 -90
  60. package/dist/index.js +1202 -328
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +1188 -327
  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 +32 -21
  95. package/dist/payment/index.d.ts +32 -21
  96. package/dist/payment/index.js +215 -12
  97. package/dist/payment/index.js.map +1 -1
  98. package/dist/payment/index.mjs +205 -12
  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 +19799 -43
  107. package/dist/stripe-multichain/index.js.map +1 -1
  108. package/dist/stripe-multichain/index.mjs +19808 -28
  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,21 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/identity/fastify.ts
21
21
  var fastify_exports = {};
22
22
  __export(fastify_exports, {
23
- FIXABLE_DENIAL_REASONS: () => FIXABLE_DENIAL_REASONS,
24
23
  agentscoreGate: () => agentscoreGate,
25
- buildContactSupportNextSteps: () => buildContactSupportNextSteps,
26
- buildSignerMismatchBody: () => buildSignerMismatchBody,
27
24
  captureWallet: () => captureWallet,
25
+ conditionalAgentscoreGate: () => conditionalAgentscoreGate,
28
26
  default: () => fastify_default,
29
- denialReasonStatus: () => denialReasonStatus,
30
- denialReasonToBody: () => denialReasonToBody,
31
27
  getAgentScoreData: () => getAgentScoreData,
32
28
  getGateDegradedState: () => getGateDegradedState,
33
29
  getGateQuotaInfo: () => getGateQuotaInfo,
34
- getSignerVerdict: () => getSignerVerdict,
35
- isFixableDenial: () => isFixableDenial,
36
- readX402PaymentHeader: () => readX402PaymentHeader,
37
- verificationAgentInstructions: () => verificationAgentInstructions
30
+ getSignerVerdict: () => getSignerVerdict
38
31
  });
39
32
  module.exports = __toCommonJS(fastify_exports);
40
33
 
@@ -53,80 +46,6 @@ function denialReasonStatus(reason) {
53
46
  if (reason.code === "api_error") return 503;
54
47
  return 403;
55
48
  }
56
- function buildSignerMismatchBody({
57
- result,
58
- userMessage,
59
- learnMoreUrl
60
- }) {
61
- if (result.kind === "pass") return null;
62
- const learnMoreUrlResolved = learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
63
- if (result.kind === "wallet_signer_mismatch") {
64
- const linkedWallets = result.linkedWallets ?? [];
65
- 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.");
66
- return {
67
- error: {
68
- code: "wallet_signer_mismatch",
69
- 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."
70
- },
71
- claimed_operator: result.claimedOperator,
72
- actual_signer_operator: result.actualSignerOperator ?? null,
73
- expected_signer: result.expectedSigner,
74
- actual_signer: result.actualSigner,
75
- linked_wallets: linkedWallets,
76
- next_steps: {
77
- action: "regenerate_payment_from_linked_wallet",
78
- user_message: userMessageResolved,
79
- learn_more_url: learnMoreUrlResolved
80
- }
81
- };
82
- }
83
- return {
84
- error: {
85
- code: "wallet_auth_requires_wallet_signing",
86
- 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."
87
- },
88
- next_steps: {
89
- action: "switch_to_operator_token",
90
- user_message: userMessage ?? "Drop the X-Wallet-Address header and retry with X-Operator-Token (works on every payment rail).",
91
- learn_more_url: learnMoreUrlResolved
92
- }
93
- };
94
- }
95
- function buildContactSupportNextSteps(supportEmail, message) {
96
- return {
97
- action: "contact_support",
98
- support_email: supportEmail,
99
- user_message: message ?? `If you believe this denial is in error, contact support at ${supportEmail} with the details of your request.`
100
- };
101
- }
102
- function verificationAgentInstructions({
103
- userAction,
104
- retryStep,
105
- extraSteps,
106
- pollIntervalSeconds = 5,
107
- timeoutSeconds = 3600,
108
- orderTtl,
109
- extra
110
- } = {}) {
111
- const baseSteps = [
112
- "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.",
113
- `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.`,
114
- "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.",
115
- '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.',
116
- retryStep ?? "Retry the original merchant request with header X-Operator-Token set to the operator_token value."
117
- ];
118
- return {
119
- action: "poll_for_credential",
120
- user_action: userAction ?? "The user must visit verify_url to complete identity verification before this request can proceed",
121
- steps: extraSteps ? [...baseSteps, ...extraSteps] : baseSteps,
122
- poll_interval_seconds: pollIntervalSeconds,
123
- poll_secret_header: "X-Poll-Secret",
124
- retry_token_header: "X-Operator-Token",
125
- timeout_seconds: timeoutSeconds,
126
- ...orderTtl ? { order_ttl: orderTtl } : {},
127
- ...extra ?? {}
128
- };
129
- }
130
49
 
131
50
  // src/_response.ts
132
51
  var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
@@ -376,7 +295,7 @@ function createAgentScoreCore(options) {
376
295
  } = options;
377
296
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
378
297
  const agentMemoryHint = buildAgentMemoryHint();
379
- const defaultUa = `@agent-score/commerce@${"2.0.2"}`;
298
+ const defaultUa = `@agent-score/commerce@${"2.1.1"}`;
380
299
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
381
300
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
382
301
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -668,6 +587,30 @@ function createAgentScoreCore(options) {
668
587
  return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
669
588
  }
670
589
 
590
+ // src/payment/payment_header.ts
591
+ function toTitleCase(name) {
592
+ return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
593
+ }
594
+ function readHeader(headers, name) {
595
+ if (typeof headers.get === "function") {
596
+ return headers.get(name);
597
+ }
598
+ const rec = headers;
599
+ const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
600
+ if (typeof v === "string") return v;
601
+ if (Array.isArray(v) && typeof v[0] === "string") return v[0];
602
+ return null;
603
+ }
604
+ function asHeaders(input) {
605
+ return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
606
+ }
607
+ function hasPaymentHeader(input) {
608
+ const headers = asHeaders(input);
609
+ return Boolean(
610
+ readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
611
+ );
612
+ }
613
+
671
614
  // src/signer.ts
672
615
  var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
673
616
  var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
@@ -747,9 +690,6 @@ async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
747
690
  });
748
691
  return extractPaymentSigner(request, x402PaymentHeader);
749
692
  }
750
- function readX402PaymentHeader(request) {
751
- return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
752
- }
753
693
 
754
694
  // src/identity/fastify.ts
755
695
  var GATE_STATE_KEY = "__agentscoreGate";
@@ -823,21 +763,45 @@ function getSignerVerdict(request) {
823
763
  agentscoreGatePlugin[/* @__PURE__ */ Symbol.for("skip-override")] = true;
824
764
  var agentscoreGate = agentscoreGatePlugin;
825
765
  var fastify_default = agentscoreGatePlugin;
766
+ var conditionalAgentscoreGatePlugin = async (fastify, options) => {
767
+ const { extractIdentity = defaultExtractIdentity, onDenied = defaultOnDenied, ...coreOptions } = options;
768
+ const core = createAgentScoreCore(coreOptions);
769
+ fastify.addHook("preHandler", async (request, reply) => {
770
+ if (!hasPaymentHeader(request.headers)) return;
771
+ const identity = extractIdentity(request);
772
+ request[GATE_STATE_KEY] = {
773
+ core,
774
+ operatorToken: identity?.operatorToken,
775
+ walletAddress: identity?.address
776
+ };
777
+ const authHeader = request.headers.authorization ?? null;
778
+ const x402Header = request.headers["payment-signature"] ?? request.headers["x-payment"];
779
+ const signer = await extractPaymentSignerFromAuth(authHeader, x402Header);
780
+ const outcome = await core.evaluate(identity, request, signer);
781
+ if (outcome.kind === "allow") {
782
+ const state = request[GATE_STATE_KEY];
783
+ if (state) {
784
+ if (outcome.degraded) {
785
+ state.degraded = true;
786
+ state.infraReason = outcome.infraReason;
787
+ }
788
+ if (outcome.quota) state.quota = outcome.quota;
789
+ }
790
+ return;
791
+ }
792
+ return onDenied(request, reply, outcome.reason);
793
+ });
794
+ };
795
+ conditionalAgentscoreGatePlugin[/* @__PURE__ */ Symbol.for("skip-override")] = true;
796
+ var conditionalAgentscoreGate = conditionalAgentscoreGatePlugin;
826
797
  // Annotate the CommonJS export names for ESM import in node:
827
798
  0 && (module.exports = {
828
- FIXABLE_DENIAL_REASONS,
829
799
  agentscoreGate,
830
- buildContactSupportNextSteps,
831
- buildSignerMismatchBody,
832
800
  captureWallet,
833
- denialReasonStatus,
834
- denialReasonToBody,
801
+ conditionalAgentscoreGate,
835
802
  getAgentScoreData,
836
803
  getGateDegradedState,
837
804
  getGateQuotaInfo,
838
- getSignerVerdict,
839
- isFixableDenial,
840
- readX402PaymentHeader,
841
- verificationAgentInstructions
805
+ getSignerVerdict
842
806
  });
843
807
  //# sourceMappingURL=fastify.js.map