@agent-score/commerce 2.6.3 → 2.6.4
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/dist/{checkout-C4RD7M0Z.d.ts → checkout-B-Z5_EQP.d.ts} +9 -0
- package/dist/{checkout-CzB9f_jf.d.mts → checkout-BtdHSF_w.d.mts} +9 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/discovery/index.d.mts +1 -1
- package/dist/discovery/index.d.ts +1 -1
- package/dist/identity/express.js +1 -1
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +1 -1
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.js +1 -1
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +1 -1
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.js +1 -1
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +1 -1
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.js +1 -1
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +1 -1
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/web.js +1 -1
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +1 -1
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +35 -17
- package/dist/index.d.ts +35 -17
- package/dist/index.js +80 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{network_kind-BIJM2peR.d.ts → network_kind-BmbWKNud.d.ts} +23 -1
- package/dist/{network_kind-C0EMkdzz.d.mts → network_kind-D2xpo2Fj.d.mts} +23 -1
- package/dist/payment/index.d.mts +27 -20
- package/dist/payment/index.d.ts +27 -20
- package/dist/payment/index.js +35 -0
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +34 -0
- package/dist/payment/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -22574,7 +22574,7 @@ function createAgentScoreCore(options) {
|
|
|
22574
22574
|
} = options;
|
|
22575
22575
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
22576
22576
|
const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
|
|
22577
|
-
const defaultUa = `@agent-score/commerce@${"2.6.
|
|
22577
|
+
const defaultUa = `@agent-score/commerce@${"2.6.4"}`;
|
|
22578
22578
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
22579
22579
|
const sdk = new AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
22580
22580
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -23201,6 +23201,39 @@ function hasMppxHeader(input) {
|
|
|
23201
23201
|
const headers = asHeaders(input);
|
|
23202
23202
|
return Boolean(readHeader(headers, "authorization")?.startsWith("Payment "));
|
|
23203
23203
|
}
|
|
23204
|
+
var JWT_SHAPE_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
23205
|
+
function decodesToJsonObject(token) {
|
|
23206
|
+
try {
|
|
23207
|
+
const parsed = JSON.parse(Buffer.from(token, "base64").toString("utf8"));
|
|
23208
|
+
return typeof parsed === "object" && parsed !== null;
|
|
23209
|
+
} catch {
|
|
23210
|
+
return false;
|
|
23211
|
+
}
|
|
23212
|
+
}
|
|
23213
|
+
function malformedPaymentCredential(input) {
|
|
23214
|
+
const headers = asHeaders(input);
|
|
23215
|
+
const x402Token = readHeader(headers, "payment-signature") ?? readHeader(headers, "x-payment");
|
|
23216
|
+
if (x402Token !== null && x402Token.length > 0) {
|
|
23217
|
+
if (!decodesToJsonObject(x402Token)) {
|
|
23218
|
+
return {
|
|
23219
|
+
channel: "x402",
|
|
23220
|
+
message: "X-Payment header is not decodable base64 JSON."
|
|
23221
|
+
};
|
|
23222
|
+
}
|
|
23223
|
+
return null;
|
|
23224
|
+
}
|
|
23225
|
+
const auth = readHeader(headers, "authorization");
|
|
23226
|
+
if (auth !== null && auth.startsWith("Payment ")) {
|
|
23227
|
+
const token = auth.slice("Payment ".length).trim();
|
|
23228
|
+
if (token.length === 0 || !decodesToJsonObject(token) && !JWT_SHAPE_RE.test(token)) {
|
|
23229
|
+
return {
|
|
23230
|
+
channel: "mpp",
|
|
23231
|
+
message: "Authorization: Payment credential is neither base64-encoded JSON nor a token-shaped value."
|
|
23232
|
+
};
|
|
23233
|
+
}
|
|
23234
|
+
}
|
|
23235
|
+
return null;
|
|
23236
|
+
}
|
|
23204
23237
|
|
|
23205
23238
|
// src/identity/tokens.ts
|
|
23206
23239
|
function hashOperatorToken(plaintext) {
|
|
@@ -25440,6 +25473,7 @@ var Checkout = class {
|
|
|
25440
25473
|
* agent-supplied `payTo` to this set (anti funds-drain). Empty for pure per-order minting. */
|
|
25441
25474
|
x402StaticRecipients;
|
|
25442
25475
|
zeroSettleCarveOut;
|
|
25476
|
+
credentialPreCheck;
|
|
25443
25477
|
gate;
|
|
25444
25478
|
discoveryExtensions;
|
|
25445
25479
|
resourceInfo;
|
|
@@ -25521,6 +25555,7 @@ var Checkout = class {
|
|
|
25521
25555
|
this.isCachedAddress = opts.isCachedAddress;
|
|
25522
25556
|
this.x402StaticRecipients = collectStaticX402Recipients(opts.rails);
|
|
25523
25557
|
this.zeroSettleCarveOut = opts.zeroSettleCarveOut ?? false;
|
|
25558
|
+
this.credentialPreCheck = opts.credentialPreCheck ?? true;
|
|
25524
25559
|
this.gate = opts.gate;
|
|
25525
25560
|
this.discoveryExtensions = opts.discoveryExtensions;
|
|
25526
25561
|
this.resourceInfo = opts.resourceInfo;
|
|
@@ -25658,6 +25693,27 @@ var Checkout = class {
|
|
|
25658
25693
|
};
|
|
25659
25694
|
}
|
|
25660
25695
|
}
|
|
25696
|
+
if (this.credentialPreCheck) {
|
|
25697
|
+
const malformed = malformedPaymentCredential(request.headers);
|
|
25698
|
+
const enforced = malformed !== null && (malformed.channel === "x402" ? this.x402ServerAvailable() && this.x402BaseNetwork !== null : this.composeMppx !== void 0);
|
|
25699
|
+
if (enforced) {
|
|
25700
|
+
return {
|
|
25701
|
+
status: 400,
|
|
25702
|
+
body: buildValidationError({
|
|
25703
|
+
code: "payment_proof_invalid",
|
|
25704
|
+
message: malformed.message,
|
|
25705
|
+
nextSteps: {
|
|
25706
|
+
action: "regenerate_payment_credential",
|
|
25707
|
+
user_message: "The payment credential could not be decoded. Rebuild it from a fresh 402 challenge and retry."
|
|
25708
|
+
}
|
|
25709
|
+
}),
|
|
25710
|
+
headers: {},
|
|
25711
|
+
referenceId: ctx.referenceId,
|
|
25712
|
+
settled: false,
|
|
25713
|
+
settlePhase: "credential_malformed"
|
|
25714
|
+
};
|
|
25715
|
+
}
|
|
25716
|
+
}
|
|
25661
25717
|
if (this.preValidate !== void 0) {
|
|
25662
25718
|
try {
|
|
25663
25719
|
const state = await this.preValidate(ctx);
|
|
@@ -26005,7 +26061,8 @@ var Checkout = class {
|
|
|
26005
26061
|
railKey = this.x402RailKey();
|
|
26006
26062
|
} else {
|
|
26007
26063
|
zero = zeroAmountCarveOut({ rail, authorizationHeader: headers["authorization"] });
|
|
26008
|
-
|
|
26064
|
+
if (zero.signerNetwork !== "solana") return null;
|
|
26065
|
+
railKey = this.railsKeyForMppxMethod("solana") ?? this.mppRailKey();
|
|
26009
26066
|
}
|
|
26010
26067
|
const outcome = {
|
|
26011
26068
|
rail: rail === "x402-base" ? "x402" : "mpp",
|
|
@@ -26802,11 +26859,11 @@ function canonicalize2(value) {
|
|
|
26802
26859
|
}
|
|
26803
26860
|
return value;
|
|
26804
26861
|
}
|
|
26805
|
-
function
|
|
26862
|
+
function createResultCache(opts = {}) {
|
|
26806
26863
|
const ttlMs = opts.ttlMs ?? 5 * 6e4;
|
|
26807
|
-
const keyPrefix = opts.keyPrefix ?? "
|
|
26864
|
+
const keyPrefix = opts.keyPrefix ?? "result:";
|
|
26808
26865
|
const memMap = /* @__PURE__ */ new Map();
|
|
26809
|
-
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "
|
|
26866
|
+
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "result-cache" });
|
|
26810
26867
|
const evictExpired = () => {
|
|
26811
26868
|
const now = Date.now();
|
|
26812
26869
|
for (const [k, v] of memMap.entries()) {
|
|
@@ -26833,17 +26890,16 @@ function createQuoteCache(opts = {}) {
|
|
|
26833
26890
|
const entry = memMap.get(key);
|
|
26834
26891
|
return entry ? entry.entry : null;
|
|
26835
26892
|
},
|
|
26836
|
-
async write(key,
|
|
26837
|
-
const cached2 = { body, priceCents, recipients };
|
|
26893
|
+
async write(key, value) {
|
|
26838
26894
|
const r = await getRedis();
|
|
26839
26895
|
if (r) {
|
|
26840
26896
|
try {
|
|
26841
|
-
await r.set(`${keyPrefix}${key}`, JSON.stringify(
|
|
26897
|
+
await r.set(`${keyPrefix}${key}`, JSON.stringify(value), "PX", ttlMs);
|
|
26842
26898
|
return;
|
|
26843
26899
|
} catch {
|
|
26844
26900
|
}
|
|
26845
26901
|
}
|
|
26846
|
-
memMap.set(key, { entry:
|
|
26902
|
+
memMap.set(key, { entry: value, expiresAt: Date.now() + ttlMs });
|
|
26847
26903
|
},
|
|
26848
26904
|
async clear() {
|
|
26849
26905
|
memMap.clear();
|
|
@@ -26857,6 +26913,17 @@ function createQuoteCache(opts = {}) {
|
|
|
26857
26913
|
}
|
|
26858
26914
|
};
|
|
26859
26915
|
}
|
|
26916
|
+
function createQuoteCache(opts = {}) {
|
|
26917
|
+
const cache = createResultCache({ ...opts, keyPrefix: opts.keyPrefix ?? "quote:" });
|
|
26918
|
+
return {
|
|
26919
|
+
bodyHashKey: cache.bodyHashKey,
|
|
26920
|
+
read: cache.read,
|
|
26921
|
+
async write(key, body, priceCents, recipients = {}) {
|
|
26922
|
+
await cache.write(key, { body, priceCents, recipients });
|
|
26923
|
+
},
|
|
26924
|
+
clear: cache.clear
|
|
26925
|
+
};
|
|
26926
|
+
}
|
|
26860
26927
|
|
|
26861
26928
|
// src/checkout_compute_first.ts
|
|
26862
26929
|
var DEFAULT_TTL_MS = 5 * 6e4;
|
|
@@ -27373,6 +27440,7 @@ export {
|
|
|
27373
27440
|
computeFirstCheckout,
|
|
27374
27441
|
createDefaultOnDenied,
|
|
27375
27442
|
createQuoteCache,
|
|
27443
|
+
createResultCache,
|
|
27376
27444
|
defaultReadOnlyOnDenied,
|
|
27377
27445
|
denialReasonStatus,
|
|
27378
27446
|
denialReasonToBody,
|
|
@@ -27397,6 +27465,7 @@ export {
|
|
|
27397
27465
|
loadSolanaFeePayer,
|
|
27398
27466
|
loadUCPSigningKeyFromEnv,
|
|
27399
27467
|
makeMppxComposeHook,
|
|
27468
|
+
malformedPaymentCredential,
|
|
27400
27469
|
mppPaymentHandler,
|
|
27401
27470
|
normalizeAddress,
|
|
27402
27471
|
pricingResult,
|