@agent-score/commerce 2.7.6 → 2.7.7

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.
@@ -24,11 +24,11 @@ var __export = (target, all) => {
24
24
  for (var name in all)
25
25
  __defProp(target, name, { get: all[name], enumerable: true });
26
26
  };
27
- var __copyProps = (to, from9, except, desc) => {
28
- if (from9 && typeof from9 === "object" || typeof from9 === "function") {
29
- for (let key of __getOwnPropNames(from9))
27
+ var __copyProps = (to, from10, except, desc) => {
28
+ if (from10 && typeof from10 === "object" || typeof from10 === "function") {
29
+ for (let key of __getOwnPropNames(from10))
30
30
  if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from9[key], enumerable: !(desc = __getOwnPropDesc(from9, key)) || desc.enumerable });
31
+ __defProp(to, key, { get: () => from10[key], enumerable: !(desc = __getOwnPropDesc(from10, key)) || desc.enumerable });
32
32
  }
33
33
  return to;
34
34
  };
@@ -19244,10 +19244,16 @@ var init_Errors2 = __esm({
19244
19244
  methodUnsupported: "Use a supported wallet to pay for this resource using one of the supported payment methods returned in the WWW-Authenticate header. See https://mpp.dev/tools/wallet.md"
19245
19245
  };
19246
19246
  PaymentError = class extends Error {
19247
+ /** Safe method-specific context for diagnostics and relay responses. */
19248
+ details;
19247
19249
  /** HTTP status code. */
19248
19250
  status = 402;
19249
19251
  /** Actionable hint for resolving the error (RFC 9457 extension member). */
19250
19252
  hint;
19253
+ constructor(message, options = {}) {
19254
+ super(message);
19255
+ this.details = options.details;
19256
+ }
19251
19257
  /** Converts the error to RFC 9457 Problem Details format. */
19252
19258
  toProblemDetails(challengeId) {
19253
19259
  return {
@@ -19255,6 +19261,7 @@ var init_Errors2 = __esm({
19255
19261
  title: this.title,
19256
19262
  status: this.status,
19257
19263
  detail: this.message,
19264
+ ...this.details && Object.keys(this.details).length > 0 && { details: this.details },
19258
19265
  ...this.hint && { hint: this.hint },
19259
19266
  ...challengeId && { challengeId }
19260
19267
  };
@@ -19288,8 +19295,10 @@ var init_Errors2 = __esm({
19288
19295
  title = "Verification Failed";
19289
19296
  type = "https://paymentauth.org/problems/verification-failed";
19290
19297
  constructor(options = {}) {
19291
- const { reason } = options;
19292
- super(reason ? `Payment verification failed: ${reason}.` : "Payment verification failed.");
19298
+ const { details, reason } = options;
19299
+ super(reason ? `Payment verification failed: ${reason}.` : "Payment verification failed.", {
19300
+ details
19301
+ });
19293
19302
  }
19294
19303
  };
19295
19304
  PaymentActionRequiredError = class extends PaymentError {
@@ -19521,7 +19530,7 @@ var version3;
19521
19530
  var init_version2 = __esm({
19522
19531
  "node_modules/viem/_esm/errors/version.js"() {
19523
19532
  "use strict";
19524
- version3 = "2.55.2";
19533
+ version3 = "2.55.8";
19525
19534
  }
19526
19535
  });
19527
19536
 
@@ -20006,60 +20015,93 @@ var init_isAddress = __esm({
20006
20015
  }
20007
20016
  });
20008
20017
 
20009
- // node_modules/viem/_esm/errors/unit.js
20010
- var InvalidDecimalNumberError;
20011
- var init_unit = __esm({
20012
- "node_modules/viem/_esm/errors/unit.js"() {
20013
- "use strict";
20014
- init_base();
20015
- InvalidDecimalNumberError = class extends BaseError3 {
20016
- constructor({ value }) {
20017
- super(`Number \`${value}\` is not a valid decimal number.`, {
20018
- name: "InvalidDecimalNumberError"
20019
- });
20020
- }
20021
- };
20022
- }
20023
- });
20024
-
20025
- // node_modules/viem/_esm/utils/unit/parseUnits.js
20026
- function parseUnits(value, decimals) {
20027
- if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value))
20018
+ // node_modules/viem/_esm/utils/unit/Value.js
20019
+ function from6(value, decimals = 0) {
20020
+ if (!Number.isInteger(decimals) || decimals < 0)
20021
+ throw new InvalidDecimalsError({ decimals });
20022
+ if (!/^-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/.test(value))
20028
20023
  throw new InvalidDecimalNumberError({ value });
20029
- let [integer2, fraction = "0"] = value.split(".");
20024
+ let [integer2 = "", fraction = "0"] = value.split(".");
20030
20025
  const negative = integer2.startsWith("-");
20031
20026
  if (negative)
20032
20027
  integer2 = integer2.slice(1);
20028
+ if (integer2 === "")
20029
+ integer2 = "0";
20033
20030
  fraction = fraction.replace(/(0+)$/, "");
20034
20031
  if (decimals === 0) {
20035
- if (Math.round(Number(`.${fraction}`)) === 1)
20032
+ if (fraction.length > 0 && Number.parseInt(fraction[0], 10) >= 5)
20036
20033
  integer2 = `${BigInt(integer2) + 1n}`;
20037
20034
  fraction = "";
20038
20035
  } else if (fraction.length > decimals) {
20039
- const [left, unit, right] = [
20040
- fraction.slice(0, decimals - 1),
20041
- fraction.slice(decimals - 1, decimals),
20042
- fraction.slice(decimals)
20043
- ];
20044
- const rounded = Math.round(Number(`${unit}.${right}`));
20045
- if (rounded > 9)
20046
- fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, "0");
20047
- else
20048
- fraction = `${left}${rounded}`;
20049
- if (fraction.length > decimals) {
20050
- fraction = fraction.slice(1);
20051
- integer2 = `${BigInt(integer2) + 1n}`;
20036
+ const left = fraction.slice(0, decimals);
20037
+ const roundDigit = Number.parseInt(fraction.slice(decimals, decimals + 1), 10);
20038
+ if (roundDigit >= 5) {
20039
+ const carried = carry(left);
20040
+ if (carried.length > decimals) {
20041
+ fraction = carried.slice(1);
20042
+ integer2 = `${BigInt(integer2) + 1n}`;
20043
+ } else {
20044
+ fraction = carried;
20045
+ }
20046
+ } else {
20047
+ fraction = left;
20052
20048
  }
20053
- fraction = fraction.slice(0, decimals);
20054
20049
  } else {
20055
20050
  fraction = fraction.padEnd(decimals, "0");
20056
20051
  }
20057
20052
  return BigInt(`${negative ? "-" : ""}${integer2}${fraction}`);
20058
20053
  }
20054
+ function carry(digits) {
20055
+ const out = digits.split("");
20056
+ let i = out.length - 1;
20057
+ while (i >= 0) {
20058
+ const d = Number.parseInt(out[i], 10) + 1;
20059
+ if (d < 10) {
20060
+ out[i] = String(d);
20061
+ return out.join("");
20062
+ }
20063
+ out[i] = "0";
20064
+ i--;
20065
+ }
20066
+ return `1${out.join("")}`;
20067
+ }
20068
+ var InvalidDecimalNumberError, InvalidDecimalsError;
20069
+ var init_Value2 = __esm({
20070
+ "node_modules/viem/_esm/utils/unit/Value.js"() {
20071
+ "use strict";
20072
+ InvalidDecimalNumberError = class extends Error {
20073
+ constructor({ value }) {
20074
+ super(`Value \`${value}\` is not a valid decimal number.`);
20075
+ Object.defineProperty(this, "name", {
20076
+ enumerable: true,
20077
+ configurable: true,
20078
+ writable: true,
20079
+ value: "Value.InvalidDecimalNumberError"
20080
+ });
20081
+ }
20082
+ };
20083
+ InvalidDecimalsError = class extends Error {
20084
+ constructor({ decimals }) {
20085
+ super(`\`decimals\` must be a non-negative integer. Got \`${decimals}\`.`);
20086
+ Object.defineProperty(this, "name", {
20087
+ enumerable: true,
20088
+ configurable: true,
20089
+ writable: true,
20090
+ value: "Value.InvalidDecimalsError"
20091
+ });
20092
+ }
20093
+ };
20094
+ }
20095
+ });
20096
+
20097
+ // node_modules/viem/_esm/utils/unit/parseUnits.js
20098
+ function parseUnits(value, decimals) {
20099
+ return from6(value, decimals);
20100
+ }
20059
20101
  var init_parseUnits = __esm({
20060
20102
  "node_modules/viem/_esm/utils/unit/parseUnits.js"() {
20061
20103
  "use strict";
20062
- init_unit();
20104
+ init_Value2();
20063
20105
  }
20064
20106
  });
20065
20107
 
@@ -20283,13 +20325,70 @@ var init_Chains = __esm({
20283
20325
  // node_modules/mppx/dist/Method.js
20284
20326
  var Method_exports = {};
20285
20327
  __export(Method_exports, {
20286
- from: () => from6,
20328
+ broadcastCredential: () => broadcastCredential,
20329
+ from: () => from7,
20330
+ selectServerMethod: () => selectServerMethod,
20287
20331
  toClient: () => toClient,
20288
- toServer: () => toServer
20332
+ toServer: () => toServer,
20333
+ validateCredential: () => validateCredential
20289
20334
  });
20290
- function from6(method) {
20335
+ function from7(method) {
20291
20336
  return method;
20292
20337
  }
20338
+ async function validateCredential(methods, input) {
20339
+ const prepared = prepareCredential(methods, input);
20340
+ if (!prepared.method.validate)
20341
+ throw new VerificationFailedError({
20342
+ details: { intent: prepared.method.intent, method: prepared.method.name },
20343
+ reason: `${prepared.method.name}/${prepared.method.intent} does not support non-mutating credential validation`
20344
+ });
20345
+ return prepared.method.validate({
20346
+ credential: prepared.credential,
20347
+ request: prepared.request
20348
+ });
20349
+ }
20350
+ async function broadcastCredential(methods, input) {
20351
+ const prepared = prepareCredential(methods, input);
20352
+ const { method } = prepared;
20353
+ if (method.broadcast && method.validate)
20354
+ await method.validate({ credential: prepared.credential, request: prepared.request });
20355
+ const broadcast = method.broadcast ?? method.verify;
20356
+ return broadcast({ credential: prepared.credential, request: prepared.request });
20357
+ }
20358
+ function prepareCredential(methods, input) {
20359
+ const credential = typeof input === "string" ? deserialize3(input) : input;
20360
+ const candidates = methods.filter((method2) => method2.name === credential.challenge.method && method2.intent === credential.challenge.intent);
20361
+ const method = selectServerMethod(candidates, credential.challenge);
20362
+ if (!method)
20363
+ throw new InvalidChallengeError({
20364
+ id: credential.challenge.id,
20365
+ reason: `no registered method for ${credential.challenge.method}/${credential.challenge.intent}`
20366
+ });
20367
+ assert5(credential.challenge.expires, credential.challenge.id);
20368
+ let payload;
20369
+ try {
20370
+ payload = method.schema.credential.payload.parse(credential.payload);
20371
+ } catch (error51) {
20372
+ throw new InvalidPayloadError(error51 instanceof Error ? { reason: error51.message } : {});
20373
+ }
20374
+ return {
20375
+ credential: { ...credential, payload },
20376
+ method,
20377
+ request: credential.challenge.request
20378
+ };
20379
+ }
20380
+ function selectServerMethod(methods, challenge) {
20381
+ if (methods.length <= 1)
20382
+ return methods[0];
20383
+ if (challenge.method !== Methods.tempo || challenge.intent !== Intents.session)
20384
+ return methods[0];
20385
+ const sessionProtocol = getMethodDetail(challenge.request.methodDetails, MethodDetailKeys.sessionProtocol);
20386
+ if (sessionProtocol === void 0 || sessionProtocol === SessionProtocols.v1)
20387
+ return methods.find((method) => method.alias === "sessionLegacy") ?? methods[0];
20388
+ if (sessionProtocol === SessionProtocols.v2)
20389
+ return methods.find((method) => method.alias === void 0) ?? methods[0];
20390
+ return void 0;
20391
+ }
20293
20392
  function toClient(method, options) {
20294
20393
  const { canHandleChallenge, context, createCredential } = options;
20295
20394
  return {
@@ -20300,7 +20399,16 @@ function toClient(method, options) {
20300
20399
  };
20301
20400
  }
20302
20401
  function toServer(method, options) {
20303
- const { alias, authorize, defaults, extensions, html, preflight, request, respond, stableBinding, transport, verify: verify3 } = options;
20402
+ const { alias, authorize, defaults, extensions, html, preflight, request, respond, broadcast, stableBinding, transport, validate: validate4, verify: verify3 } = options;
20403
+ const effectiveVerify = verify3 ?? (async (parameters) => {
20404
+ if (validate4)
20405
+ await validate4(parameters);
20406
+ if (!broadcast)
20407
+ throw new VerificationFailedError({
20408
+ reason: `${method.name}/${method.intent} does not support credential broadcast`
20409
+ });
20410
+ return broadcast(parameters);
20411
+ });
20304
20412
  return {
20305
20413
  ...method,
20306
20414
  alias,
@@ -20311,14 +20419,20 @@ function toServer(method, options) {
20311
20419
  preflight,
20312
20420
  request,
20313
20421
  respond,
20422
+ broadcast,
20314
20423
  stableBinding,
20315
20424
  transport,
20316
- verify: verify3
20425
+ validate: validate4,
20426
+ verify: effectiveVerify
20317
20427
  };
20318
20428
  }
20319
20429
  var init_Method = __esm({
20320
20430
  "node_modules/mppx/dist/Method.js"() {
20321
20431
  "use strict";
20432
+ init_Constants();
20433
+ init_Credential();
20434
+ init_Errors2();
20435
+ init_Expires();
20322
20436
  }
20323
20437
  });
20324
20438
 
@@ -20447,7 +20561,7 @@ var init_Methods = __esm({
20447
20561
  init_Method();
20448
20562
  init_zod();
20449
20563
  init_Types();
20450
- charge = from6({
20564
+ charge = from7({
20451
20565
  name: paymentMethod,
20452
20566
  intent: chargeIntent,
20453
20567
  schema: {
@@ -20539,15 +20653,15 @@ var Receipt_exports = {};
20539
20653
  __export(Receipt_exports, {
20540
20654
  Schema: () => Schema2,
20541
20655
  deserialize: () => deserialize4,
20542
- from: () => from7,
20656
+ from: () => from8,
20543
20657
  fromResponse: () => fromResponse2,
20544
20658
  serialize: () => serialize4
20545
20659
  });
20546
20660
  function deserialize4(encoded) {
20547
20661
  const json2 = Base64_exports.toString(encoded);
20548
- return from7(JSON.parse(json2));
20662
+ return from8(JSON.parse(json2));
20549
20663
  }
20550
- function from7(parameters) {
20664
+ function from8(parameters) {
20551
20665
  return Schema2.parse(parameters);
20552
20666
  }
20553
20667
  function serialize4(receipt) {
@@ -20590,12 +20704,12 @@ var init_Receipt = __esm({
20590
20704
  var Store_exports = {};
20591
20705
  __export(Store_exports, {
20592
20706
  cloudflare: () => cloudflare,
20593
- from: () => from8,
20707
+ from: () => from9,
20594
20708
  memory: () => memory,
20595
20709
  redis: () => redis,
20596
20710
  upstash: () => upstash
20597
20711
  });
20598
- function from8(store, options) {
20712
+ function from9(store, options) {
20599
20713
  return withKeyPrefix(store, options?.keyPrefix);
20600
20714
  }
20601
20715
  function withKeyPrefix(store, keyPrefix = "") {
@@ -20606,7 +20720,7 @@ function withKeyPrefix(store, keyPrefix = "") {
20606
20720
  return cached2;
20607
20721
  const backing = store;
20608
20722
  const prefixedKey = (key) => `${keyPrefix}${key}`;
20609
- const prefixed = from8({
20723
+ const prefixed = from9({
20610
20724
  async get(key) {
20611
20725
  return backing.get(prefixedKey(key));
20612
20726
  },
@@ -20643,7 +20757,7 @@ function wrapJsonUpdate(update) {
20643
20757
  };
20644
20758
  }
20645
20759
  function cloudflare(kv, options) {
20646
- return from8({
20760
+ return from9({
20647
20761
  async get(key) {
20648
20762
  const raw = await kv.get(key);
20649
20763
  if (raw == null)
@@ -20661,7 +20775,7 @@ function cloudflare(kv, options) {
20661
20775
  }
20662
20776
  function memory(options) {
20663
20777
  const store = /* @__PURE__ */ new Map();
20664
- return from8({
20778
+ return from9({
20665
20779
  async get(key) {
20666
20780
  const raw = store.get(key);
20667
20781
  if (raw === void 0)
@@ -20686,7 +20800,7 @@ function memory(options) {
20686
20800
  }, options);
20687
20801
  }
20688
20802
  function redis(client, options) {
20689
- return from8({
20803
+ return from9({
20690
20804
  async get(key) {
20691
20805
  const raw = await client.get(key);
20692
20806
  if (raw == null)
@@ -20703,7 +20817,7 @@ function redis(client, options) {
20703
20817
  }, options);
20704
20818
  }
20705
20819
  function upstash(redis2, options) {
20706
- return from8({
20820
+ return from9({
20707
20821
  async get(key) {
20708
20822
  return await redis2.get(key);
20709
20823
  },