@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.
- package/README.md +26 -11
- package/dist/_core-kI7FRAiZ.d.mts +10 -0
- package/dist/_core-kI7FRAiZ.d.ts +10 -0
- package/dist/challenge/index.d.mts +3 -3
- package/dist/challenge/index.d.ts +3 -3
- package/dist/challenge/index.js +21 -14
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +21 -14
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-jNUIql6D.d.mts → checkout-BRw_caGr.d.mts} +13 -33
- package/dist/{checkout-DhSj_h94.d.ts → checkout-CuSNUJFX.d.ts} +13 -33
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/default_rails-C5gKZJMI.d.ts +198 -0
- package/dist/default_rails-XFCuRddA.d.mts +198 -0
- package/dist/discovery/index.d.mts +5 -5
- package/dist/discovery/index.d.ts +5 -5
- package/dist/discovery/index.js +14 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +14 -1
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +7 -3
- package/dist/identity/express.d.ts +7 -3
- package/dist/identity/express.js +39 -96
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +37 -87
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +4 -4
- package/dist/identity/fastify.d.ts +4 -4
- package/dist/identity/fastify.js +60 -96
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +58 -87
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +11 -3
- package/dist/identity/hono.d.ts +11 -3
- package/dist/identity/hono.js +39 -93
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +37 -84
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +10 -3
- package/dist/identity/nextjs.d.ts +10 -3
- package/dist/identity/nextjs.js +49 -93
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +46 -84
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js +22 -23317
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +1 -23320
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +9 -3
- package/dist/identity/web.d.ts +9 -3
- package/dist/identity/web.js +45 -93
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +42 -84
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +621 -90
- package/dist/index.d.ts +621 -90
- package/dist/index.js +1202 -328
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1188 -327
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/express.d.mts +10 -0
- package/dist/middleware/express.d.ts +10 -0
- package/dist/middleware/express.js +128 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/express.mjs +91 -0
- package/dist/middleware/express.mjs.map +1 -0
- package/dist/middleware/fastify.d.mts +10 -0
- package/dist/middleware/fastify.d.ts +10 -0
- package/dist/middleware/fastify.js +127 -0
- package/dist/middleware/fastify.js.map +1 -0
- package/dist/middleware/fastify.mjs +90 -0
- package/dist/middleware/fastify.mjs.map +1 -0
- package/dist/middleware/hono.d.mts +10 -0
- package/dist/middleware/hono.d.ts +10 -0
- package/dist/middleware/hono.js +122 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/hono.mjs +85 -0
- package/dist/middleware/hono.mjs.map +1 -0
- package/dist/middleware/nextjs.d.mts +22 -0
- package/dist/middleware/nextjs.d.ts +22 -0
- package/dist/middleware/nextjs.js +143 -0
- package/dist/middleware/nextjs.js.map +1 -0
- package/dist/middleware/nextjs.mjs +105 -0
- package/dist/middleware/nextjs.mjs.map +1 -0
- package/dist/middleware/web.d.mts +25 -0
- package/dist/middleware/web.d.ts +25 -0
- package/dist/middleware/web.js +128 -0
- package/dist/middleware/web.js.map +1 -0
- package/dist/middleware/web.mjs +91 -0
- package/dist/middleware/web.mjs.map +1 -0
- package/dist/payment/index.d.mts +32 -21
- package/dist/payment/index.d.ts +32 -21
- package/dist/payment/index.js +215 -12
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +205 -12
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
- package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
- package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
- package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
- package/dist/stripe-multichain/index.d.mts +150 -47
- package/dist/stripe-multichain/index.d.ts +150 -47
- package/dist/stripe-multichain/index.js +19799 -43
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +19808 -28
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
- package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
- package/package.json +43 -5
- package/dist/_response-BFYN3b6i.d.mts +0 -142
- package/dist/_response-_iPD5AIj.d.ts +0 -142
- package/dist/solana-Cds87OTu.d.mts +0 -67
- package/dist/solana-Cds87OTu.d.ts +0 -67
package/dist/identity/fastify.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|