@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.
- 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-B1JuEcbx.d.ts → checkout-BH-I_Ns8.d.ts} +19 -12
- package/dist/{checkout-BN5i1Fi7.d.mts → checkout-Bd_4aQ6c.d.mts} +19 -12
- 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-BWAquZeu.d.mts +188 -0
- package/dist/default_rails-BxBzcCA1.d.ts +188 -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 +220 -129
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +222 -131
- 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 +554 -90
- package/dist/index.d.ts +554 -90
- package/dist/index.js +951 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +939 -152
- 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 +21 -6
- package/dist/payment/index.d.ts +21 -6
- package/dist/payment/index.js +136 -9
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +127 -9
- 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 +19749 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +19758 -27
- 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/web.mjs
CHANGED
|
@@ -13,80 +13,6 @@ function denialReasonStatus(reason) {
|
|
|
13
13
|
if (reason.code === "api_error") return 503;
|
|
14
14
|
return 403;
|
|
15
15
|
}
|
|
16
|
-
function buildSignerMismatchBody({
|
|
17
|
-
result,
|
|
18
|
-
userMessage,
|
|
19
|
-
learnMoreUrl
|
|
20
|
-
}) {
|
|
21
|
-
if (result.kind === "pass") return null;
|
|
22
|
-
const learnMoreUrlResolved = learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
|
|
23
|
-
if (result.kind === "wallet_signer_mismatch") {
|
|
24
|
-
const linkedWallets = result.linkedWallets ?? [];
|
|
25
|
-
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.");
|
|
26
|
-
return {
|
|
27
|
-
error: {
|
|
28
|
-
code: "wallet_signer_mismatch",
|
|
29
|
-
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."
|
|
30
|
-
},
|
|
31
|
-
claimed_operator: result.claimedOperator,
|
|
32
|
-
actual_signer_operator: result.actualSignerOperator ?? null,
|
|
33
|
-
expected_signer: result.expectedSigner,
|
|
34
|
-
actual_signer: result.actualSigner,
|
|
35
|
-
linked_wallets: linkedWallets,
|
|
36
|
-
next_steps: {
|
|
37
|
-
action: "regenerate_payment_from_linked_wallet",
|
|
38
|
-
user_message: userMessageResolved,
|
|
39
|
-
learn_more_url: learnMoreUrlResolved
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
error: {
|
|
45
|
-
code: "wallet_auth_requires_wallet_signing",
|
|
46
|
-
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."
|
|
47
|
-
},
|
|
48
|
-
next_steps: {
|
|
49
|
-
action: "switch_to_operator_token",
|
|
50
|
-
user_message: userMessage ?? "Drop the X-Wallet-Address header and retry with X-Operator-Token (works on every payment rail).",
|
|
51
|
-
learn_more_url: learnMoreUrlResolved
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function buildContactSupportNextSteps(supportEmail, message) {
|
|
56
|
-
return {
|
|
57
|
-
action: "contact_support",
|
|
58
|
-
support_email: supportEmail,
|
|
59
|
-
user_message: message ?? `If you believe this denial is in error, contact support at ${supportEmail} with the details of your request.`
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function verificationAgentInstructions({
|
|
63
|
-
userAction,
|
|
64
|
-
retryStep,
|
|
65
|
-
extraSteps,
|
|
66
|
-
pollIntervalSeconds = 5,
|
|
67
|
-
timeoutSeconds = 3600,
|
|
68
|
-
orderTtl,
|
|
69
|
-
extra
|
|
70
|
-
} = {}) {
|
|
71
|
-
const baseSteps = [
|
|
72
|
-
"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.",
|
|
73
|
-
`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.`,
|
|
74
|
-
"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.",
|
|
75
|
-
'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.',
|
|
76
|
-
retryStep ?? "Retry the original merchant request with header X-Operator-Token set to the operator_token value."
|
|
77
|
-
];
|
|
78
|
-
return {
|
|
79
|
-
action: "poll_for_credential",
|
|
80
|
-
user_action: userAction ?? "The user must visit verify_url to complete identity verification before this request can proceed",
|
|
81
|
-
steps: extraSteps ? [...baseSteps, ...extraSteps] : baseSteps,
|
|
82
|
-
poll_interval_seconds: pollIntervalSeconds,
|
|
83
|
-
poll_secret_header: "X-Poll-Secret",
|
|
84
|
-
retry_token_header: "X-Operator-Token",
|
|
85
|
-
timeout_seconds: timeoutSeconds,
|
|
86
|
-
...orderTtl ? { order_ttl: orderTtl } : {},
|
|
87
|
-
...extra ?? {}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
16
|
|
|
91
17
|
// src/_response.ts
|
|
92
18
|
var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
|
|
@@ -343,7 +269,7 @@ function createAgentScoreCore(options) {
|
|
|
343
269
|
} = options;
|
|
344
270
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
345
271
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
346
|
-
const defaultUa = `@agent-score/commerce@${"2.0
|
|
272
|
+
const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
|
|
347
273
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
348
274
|
const sdk = new AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
349
275
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -635,6 +561,30 @@ function createAgentScoreCore(options) {
|
|
|
635
561
|
return { evaluate, captureWallet, getSignerVerdict };
|
|
636
562
|
}
|
|
637
563
|
|
|
564
|
+
// src/payment/payment_header.ts
|
|
565
|
+
function toTitleCase(name) {
|
|
566
|
+
return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
|
|
567
|
+
}
|
|
568
|
+
function readHeader(headers, name) {
|
|
569
|
+
if (typeof headers.get === "function") {
|
|
570
|
+
return headers.get(name);
|
|
571
|
+
}
|
|
572
|
+
const rec = headers;
|
|
573
|
+
const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
|
|
574
|
+
if (typeof v === "string") return v;
|
|
575
|
+
if (Array.isArray(v) && typeof v[0] === "string") return v[0];
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
function asHeaders(input) {
|
|
579
|
+
return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
|
|
580
|
+
}
|
|
581
|
+
function hasPaymentHeader(input) {
|
|
582
|
+
const headers = asHeaders(input);
|
|
583
|
+
return Boolean(
|
|
584
|
+
readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
|
|
638
588
|
// src/signer.ts
|
|
639
589
|
var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
640
590
|
var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
@@ -769,16 +719,24 @@ function withAgentScoreGate(options, handler) {
|
|
|
769
719
|
);
|
|
770
720
|
};
|
|
771
721
|
}
|
|
722
|
+
function createConditionalAgentScoreGate(options) {
|
|
723
|
+
const guard = createAgentScoreGate(options);
|
|
724
|
+
return async (req) => {
|
|
725
|
+
if (!hasPaymentHeader(req)) return { allowed: true };
|
|
726
|
+
return guard(req);
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function withConditionalAgentScoreGate(options, handler) {
|
|
730
|
+
const wrapped = withAgentScoreGate(options, handler);
|
|
731
|
+
return async (req, ctx) => {
|
|
732
|
+
if (!hasPaymentHeader(req)) return handler(req, {}, ctx);
|
|
733
|
+
return wrapped(req, ctx);
|
|
734
|
+
};
|
|
735
|
+
}
|
|
772
736
|
export {
|
|
773
|
-
FIXABLE_DENIAL_REASONS,
|
|
774
|
-
buildContactSupportNextSteps,
|
|
775
|
-
buildSignerMismatchBody,
|
|
776
737
|
createAgentScoreGate,
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
readX402PaymentHeader,
|
|
781
|
-
verificationAgentInstructions,
|
|
782
|
-
withAgentScoreGate
|
|
738
|
+
createConditionalAgentScoreGate,
|
|
739
|
+
withAgentScoreGate,
|
|
740
|
+
withConditionalAgentScoreGate
|
|
783
741
|
};
|
|
784
742
|
//# sourceMappingURL=web.mjs.map
|