@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,6 +1,5 @@
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, SignerVerdict, FailOpenInfraReason, GateQuotaInfo } from '../core.mjs';
2
+ import '../signer-3FAit11j.mjs';
4
3
 
5
4
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
6
5
  /** Custom function to extract agent identity from a Request. */
@@ -90,5 +89,12 @@ declare function withAgentScoreGate<TCtx = unknown>(options: AgentScoreGateOptio
90
89
  /** Per-account assess quota observability from X-Quota-* response headers. */
91
90
  quota?: GateQuotaInfo;
92
91
  }, ctx?: TCtx) => Response | Promise<Response>): (req: Request, ctx?: TCtx) => Promise<Response>;
92
+ /** Wrap `createAgentScoreGate(...)` so it only fires when a payment credential
93
+ * is attached. Discovery legs flow through allowed (with `data: undefined`)
94
+ * and the handler emits a 402 with all rails; settle legs run the full gate. */
95
+ declare function createConditionalAgentScoreGate(options: AgentScoreGateOptions): (req: Request) => Promise<GuardResult>;
96
+ /** Wrapper variant matching `withAgentScoreGate(opts, handler)` that only
97
+ * invokes the gate when a payment credential is attached. */
98
+ declare function withConditionalAgentScoreGate<TCtx = unknown>(options: AgentScoreGateOptions, handler: Parameters<typeof withAgentScoreGate<TCtx>>[1]): (req: Request, ctx: TCtx) => Promise<Response>;
93
99
 
94
- export { type GuardResult, createAgentScoreGate, withAgentScoreGate };
100
+ export { type GuardResult, createAgentScoreGate, createConditionalAgentScoreGate, withAgentScoreGate, withConditionalAgentScoreGate };
@@ -1,6 +1,5 @@
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, SignerVerdict, FailOpenInfraReason, GateQuotaInfo } from '../core.js';
2
+ import '../signer-3FAit11j.js';
4
3
 
5
4
  interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
6
5
  /** Custom function to extract agent identity from a Request. */
@@ -90,5 +89,12 @@ declare function withAgentScoreGate<TCtx = unknown>(options: AgentScoreGateOptio
90
89
  /** Per-account assess quota observability from X-Quota-* response headers. */
91
90
  quota?: GateQuotaInfo;
92
91
  }, ctx?: TCtx) => Response | Promise<Response>): (req: Request, ctx?: TCtx) => Promise<Response>;
92
+ /** Wrap `createAgentScoreGate(...)` so it only fires when a payment credential
93
+ * is attached. Discovery legs flow through allowed (with `data: undefined`)
94
+ * and the handler emits a 402 with all rails; settle legs run the full gate. */
95
+ declare function createConditionalAgentScoreGate(options: AgentScoreGateOptions): (req: Request) => Promise<GuardResult>;
96
+ /** Wrapper variant matching `withAgentScoreGate(opts, handler)` that only
97
+ * invokes the gate when a payment credential is attached. */
98
+ declare function withConditionalAgentScoreGate<TCtx = unknown>(options: AgentScoreGateOptions, handler: Parameters<typeof withAgentScoreGate<TCtx>>[1]): (req: Request, ctx: TCtx) => Promise<Response>;
93
99
 
94
- export { type GuardResult, createAgentScoreGate, withAgentScoreGate };
100
+ export { type GuardResult, createAgentScoreGate, createConditionalAgentScoreGate, withAgentScoreGate, withConditionalAgentScoreGate };
@@ -20,16 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/identity/web.ts
21
21
  var web_exports = {};
22
22
  __export(web_exports, {
23
- FIXABLE_DENIAL_REASONS: () => FIXABLE_DENIAL_REASONS,
24
- buildContactSupportNextSteps: () => buildContactSupportNextSteps,
25
- buildSignerMismatchBody: () => buildSignerMismatchBody,
26
23
  createAgentScoreGate: () => createAgentScoreGate,
27
- denialReasonStatus: () => denialReasonStatus,
28
- denialReasonToBody: () => denialReasonToBody,
29
- isFixableDenial: () => isFixableDenial,
30
- readX402PaymentHeader: () => readX402PaymentHeader,
31
- verificationAgentInstructions: () => verificationAgentInstructions,
32
- withAgentScoreGate: () => withAgentScoreGate
24
+ createConditionalAgentScoreGate: () => createConditionalAgentScoreGate,
25
+ withAgentScoreGate: () => withAgentScoreGate,
26
+ withConditionalAgentScoreGate: () => withConditionalAgentScoreGate
33
27
  });
34
28
  module.exports = __toCommonJS(web_exports);
35
29
 
@@ -48,80 +42,6 @@ function denialReasonStatus(reason) {
48
42
  if (reason.code === "api_error") return 503;
49
43
  return 403;
50
44
  }
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
45
 
126
46
  // src/_response.ts
127
47
  var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
@@ -371,7 +291,7 @@ function createAgentScoreCore(options) {
371
291
  } = options;
372
292
  const baseUrl = stripTrailingSlashes(rawBaseUrl);
373
293
  const agentMemoryHint = buildAgentMemoryHint();
374
- const defaultUa = `@agent-score/commerce@${"2.0.1"}`;
294
+ const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
375
295
  const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
376
296
  const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
377
297
  const sessionSdkCache = /* @__PURE__ */ new Map();
@@ -663,6 +583,30 @@ function createAgentScoreCore(options) {
663
583
  return { evaluate, captureWallet, getSignerVerdict };
664
584
  }
665
585
 
586
+ // src/payment/payment_header.ts
587
+ function toTitleCase(name) {
588
+ return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
589
+ }
590
+ function readHeader(headers, name) {
591
+ if (typeof headers.get === "function") {
592
+ return headers.get(name);
593
+ }
594
+ const rec = headers;
595
+ const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
596
+ if (typeof v === "string") return v;
597
+ if (Array.isArray(v) && typeof v[0] === "string") return v[0];
598
+ return null;
599
+ }
600
+ function asHeaders(input) {
601
+ return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
602
+ }
603
+ function hasPaymentHeader(input) {
604
+ const headers = asHeaders(input);
605
+ return Boolean(
606
+ readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
607
+ );
608
+ }
609
+
666
610
  // src/signer.ts
667
611
  var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
668
612
  var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
@@ -797,17 +741,25 @@ function withAgentScoreGate(options, handler) {
797
741
  );
798
742
  };
799
743
  }
744
+ function createConditionalAgentScoreGate(options) {
745
+ const guard = createAgentScoreGate(options);
746
+ return async (req) => {
747
+ if (!hasPaymentHeader(req)) return { allowed: true };
748
+ return guard(req);
749
+ };
750
+ }
751
+ function withConditionalAgentScoreGate(options, handler) {
752
+ const wrapped = withAgentScoreGate(options, handler);
753
+ return async (req, ctx) => {
754
+ if (!hasPaymentHeader(req)) return handler(req, {}, ctx);
755
+ return wrapped(req, ctx);
756
+ };
757
+ }
800
758
  // Annotate the CommonJS export names for ESM import in node:
801
759
  0 && (module.exports = {
802
- FIXABLE_DENIAL_REASONS,
803
- buildContactSupportNextSteps,
804
- buildSignerMismatchBody,
805
760
  createAgentScoreGate,
806
- denialReasonStatus,
807
- denialReasonToBody,
808
- isFixableDenial,
809
- readX402PaymentHeader,
810
- verificationAgentInstructions,
811
- withAgentScoreGate
761
+ createConditionalAgentScoreGate,
762
+ withAgentScoreGate,
763
+ withConditionalAgentScoreGate
812
764
  });
813
765
  //# sourceMappingURL=web.js.map