@agent-score/commerce 2.7.0 → 2.7.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/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.7.0"}`;
22577
+ const defaultUa = `@agent-score/commerce@${"2.7.1"}`;
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();
@@ -25711,7 +25711,7 @@ var Checkout = class {
25711
25711
  const malformed = malformedPaymentCredential(request.headers);
25712
25712
  const enforced = malformed !== null && (malformed.channel === "x402" ? this.x402ServerAvailable() && this.x402BaseNetwork !== null : this.composeMppx !== void 0);
25713
25713
  if (enforced) {
25714
- const result = await this.emitFreshChallenge(this.discoveryView(ctx));
25714
+ const result = await this.handle(this.stripPaymentHeaders(request));
25715
25715
  return { ...result, settlePhase: "credential_malformed" };
25716
25716
  }
25717
25717
  }
@@ -26230,12 +26230,10 @@ var Checkout = class {
26230
26230
  settlePhase: "verify_failed"
26231
26231
  };
26232
26232
  }
26233
- /** Emit a fresh 402 challenge: compute pricing, mint per-order recipients,
26234
- * ask the (optional) MPP compose hook for a fresh WWW-Authenticate, and
26235
- * build the rich 402 body. This is the discovery leg, factored out so the
26236
- * malformed-credential path can reuse it verbatim. Idempotent on already
26237
- * computed pricing / resolved recipients, so the normal discovery leg (which
26238
- * primes both) pays nothing extra. */
26233
+ /** Emit the discovery-leg 402: pricing (idempotent), mint per-order
26234
+ * recipients, ask the optional MPP compose hook for a fresh WWW-Authenticate,
26235
+ * and build the rich 402 body. preValidate + pricing already ran in the main
26236
+ * flow before this is reached, so it primes nothing twice. */
26239
26237
  async emitFreshChallenge(ctx) {
26240
26238
  if (ctx.pricing === null) ctx.pricing = await this.computePricing(ctx);
26241
26239
  await this.resolveRecipientsForCtx(ctx);
@@ -26249,25 +26247,23 @@ var Checkout = class {
26249
26247
  }
26250
26248
  return await this.emit402(ctx, mppxHeaders);
26251
26249
  }
26252
- /** Return a copy of `ctx` with every payment-credential header removed, so
26253
- * downstream recipient minting and MPP compose take their discovery
26254
- * (fresh-mint, fresh-challenge) path instead of trying to bind the inbound
26255
- * credential. Used to turn a malformed-credential request into a clean 402
26256
- * re-challenge. Pricing / recipients are reset so they mint fresh. */
26257
- discoveryView(ctx) {
26250
+ /** Return a copy of the request with every payment-credential header removed,
26251
+ * so re-entering handle() treats it as a discovery (no-credential) request:
26252
+ * preValidate + pricing + minting + compose all run their fresh path, and the
26253
+ * gate/assess and settle are skipped. Turns a malformed-credential request
26254
+ * into a clean 402 re-challenge. The raw request is left intact (its body may
26255
+ * already be consumed); MPP compose reads it only best-effort under a
26256
+ * try/catch, while the stripped headers are what the credential-shape check,
26257
+ * gate dispatch, and recipient minting read. */
26258
+ stripPaymentHeaders(request) {
26258
26259
  const headers = {};
26259
- for (const [k, v] of Object.entries(ctx.request.headers)) {
26260
+ for (const [k, v] of Object.entries(request.headers)) {
26260
26261
  const lk = k.toLowerCase();
26261
26262
  if (lk === "payment-signature" || lk === "x-payment") continue;
26262
26263
  if (lk === "authorization" && v.startsWith("Payment ")) continue;
26263
26264
  headers[k] = v;
26264
26265
  }
26265
- return {
26266
- ...ctx,
26267
- request: { ...ctx.request, headers },
26268
- pricing: null,
26269
- recipients: {}
26270
- };
26266
+ return { ...request, headers };
26271
26267
  }
26272
26268
  async emit402(ctx, mppxHeaders = {}) {
26273
26269
  if (ctx.pricing === null) {