@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.d.mts
CHANGED
|
@@ -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 };
|
package/dist/identity/web.d.ts
CHANGED
|
@@ -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 };
|
package/dist/identity/web.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
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
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
readX402PaymentHeader,
|
|
810
|
-
verificationAgentInstructions,
|
|
811
|
-
withAgentScoreGate
|
|
761
|
+
createConditionalAgentScoreGate,
|
|
762
|
+
withAgentScoreGate,
|
|
763
|
+
withConditionalAgentScoreGate
|
|
812
764
|
});
|
|
813
765
|
//# sourceMappingURL=web.js.map
|