@agentcash/router 0.4.7 → 0.4.8

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.cjs CHANGED
@@ -434,6 +434,7 @@ async function settleX402Payment(server, payload, requirements) {
434
434
  // src/protocols/mpp.ts
435
435
  var import_mppx = require("mppx");
436
436
  var import_server2 = require("mppx/server");
437
+ var import_tempo = require("mppx/tempo");
437
438
  var import_viem = require("viem");
438
439
  var import_chains = require("viem/chains");
439
440
  function buildGetClient(rpcUrl) {
@@ -457,8 +458,7 @@ async function buildMPPChallenge(routeEntry, request, mppConfig, price) {
457
458
  const standardRequest = toStandardRequest(request);
458
459
  const currency = mppConfig.currency;
459
460
  const recipient = mppConfig.recipient ?? "";
460
- const methodIntent = import_server2.tempo.charge();
461
- const challenge = import_mppx.Challenge.fromIntent(methodIntent, {
461
+ const challenge = import_mppx.Challenge.fromMethod(import_tempo.Methods.charge, {
462
462
  secretKey: mppConfig.secretKey,
463
463
  realm: new URL(standardRequest.url).origin,
464
464
  request: {
@@ -1149,6 +1149,8 @@ var RouteBuilder = class {
1149
1149
  /** @internal */
1150
1150
  _maxPrice;
1151
1151
  /** @internal */
1152
+ _minPrice;
1153
+ /** @internal */
1152
1154
  _bodySchema;
1153
1155
  /** @internal */
1154
1156
  _querySchema;
@@ -1190,6 +1192,7 @@ var RouteBuilder = class {
1190
1192
  next._pricing = pricing;
1191
1193
  if (options?.protocols) next._protocols = options.protocols;
1192
1194
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1195
+ if (options?.minPrice) next._minPrice = options.minPrice;
1193
1196
  if (typeof pricing === "object" && "tiers" in pricing) {
1194
1197
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1195
1198
  if (!tierKey) {
@@ -1326,6 +1329,7 @@ var RouteBuilder = class {
1326
1329
  path: this._path,
1327
1330
  method: this._method,
1328
1331
  maxPrice: this._maxPrice,
1332
+ minPrice: this._minPrice,
1329
1333
  apiKeyResolver: this._apiKeyResolver,
1330
1334
  providerName: this._providerName,
1331
1335
  providerConfig: this._providerConfig,
@@ -1428,9 +1432,16 @@ function buildOperation(routeKey, entry, tag) {
1428
1432
  const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
1429
1433
  let price;
1430
1434
  if (typeof entry.pricing === "string") {
1431
- price = parseFloat(entry.pricing);
1435
+ price = entry.pricing;
1436
+ } else if (typeof entry.pricing === "object" && "tiers" in entry.pricing) {
1437
+ const tierPrices = Object.values(entry.pricing.tiers).map((t) => parseFloat(t.price));
1438
+ const min = Math.min(...tierPrices);
1439
+ const max = Math.max(...tierPrices);
1440
+ price = min === max ? String(min) : `${min}-${max}`;
1441
+ } else if (entry.minPrice && entry.maxPrice) {
1442
+ price = `${entry.minPrice}-${entry.maxPrice}`;
1432
1443
  } else if (entry.maxPrice) {
1433
- price = parseFloat(entry.maxPrice);
1444
+ price = entry.maxPrice;
1434
1445
  }
1435
1446
  const operation = {
1436
1447
  operationId: routeKey.replace(/\//g, "_"),
package/dist/index.d.cts CHANGED
@@ -170,6 +170,7 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
170
170
  interface PaidOptions {
171
171
  protocols?: ProtocolType[];
172
172
  maxPrice?: string;
173
+ minPrice?: string;
173
174
  }
174
175
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
175
176
  body: TBody;
@@ -218,6 +219,7 @@ interface RouteEntry {
218
219
  path?: string;
219
220
  method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
220
221
  maxPrice?: string;
222
+ minPrice?: string;
221
223
  apiKeyResolver?: (key: string) => unknown | Promise<unknown>;
222
224
  providerName?: string;
223
225
  providerConfig?: ProviderConfig;
@@ -308,6 +310,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, HasAuth extend
308
310
  /** @internal */ _pricing: PricingConfig | undefined;
309
311
  /** @internal */ _protocols: ProtocolType[];
310
312
  /** @internal */ _maxPrice: string | undefined;
313
+ /** @internal */ _minPrice: string | undefined;
311
314
  /** @internal */ _bodySchema: ZodType | undefined;
312
315
  /** @internal */ _querySchema: ZodType | undefined;
313
316
  /** @internal */ _outputSchema: ZodType | undefined;
package/dist/index.d.ts CHANGED
@@ -170,6 +170,7 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
170
170
  interface PaidOptions {
171
171
  protocols?: ProtocolType[];
172
172
  maxPrice?: string;
173
+ minPrice?: string;
173
174
  }
174
175
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
175
176
  body: TBody;
@@ -218,6 +219,7 @@ interface RouteEntry {
218
219
  path?: string;
219
220
  method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
220
221
  maxPrice?: string;
222
+ minPrice?: string;
221
223
  apiKeyResolver?: (key: string) => unknown | Promise<unknown>;
222
224
  providerName?: string;
223
225
  providerConfig?: ProviderConfig;
@@ -308,6 +310,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, HasAuth extend
308
310
  /** @internal */ _pricing: PricingConfig | undefined;
309
311
  /** @internal */ _protocols: ProtocolType[];
310
312
  /** @internal */ _maxPrice: string | undefined;
313
+ /** @internal */ _minPrice: string | undefined;
311
314
  /** @internal */ _bodySchema: ZodType | undefined;
312
315
  /** @internal */ _querySchema: ZodType | undefined;
313
316
  /** @internal */ _outputSchema: ZodType | undefined;
package/dist/index.js CHANGED
@@ -397,6 +397,7 @@ async function settleX402Payment(server, payload, requirements) {
397
397
  // src/protocols/mpp.ts
398
398
  import { Challenge, Credential, Receipt } from "mppx";
399
399
  import { tempo } from "mppx/server";
400
+ import { Methods } from "mppx/tempo";
400
401
  import { createClient, http } from "viem";
401
402
  import { tempo as tempoChain } from "viem/chains";
402
403
  function buildGetClient(rpcUrl) {
@@ -420,8 +421,7 @@ async function buildMPPChallenge(routeEntry, request, mppConfig, price) {
420
421
  const standardRequest = toStandardRequest(request);
421
422
  const currency = mppConfig.currency;
422
423
  const recipient = mppConfig.recipient ?? "";
423
- const methodIntent = tempo.charge();
424
- const challenge = Challenge.fromIntent(methodIntent, {
424
+ const challenge = Challenge.fromMethod(Methods.charge, {
425
425
  secretKey: mppConfig.secretKey,
426
426
  realm: new URL(standardRequest.url).origin,
427
427
  request: {
@@ -1112,6 +1112,8 @@ var RouteBuilder = class {
1112
1112
  /** @internal */
1113
1113
  _maxPrice;
1114
1114
  /** @internal */
1115
+ _minPrice;
1116
+ /** @internal */
1115
1117
  _bodySchema;
1116
1118
  /** @internal */
1117
1119
  _querySchema;
@@ -1153,6 +1155,7 @@ var RouteBuilder = class {
1153
1155
  next._pricing = pricing;
1154
1156
  if (options?.protocols) next._protocols = options.protocols;
1155
1157
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1158
+ if (options?.minPrice) next._minPrice = options.minPrice;
1156
1159
  if (typeof pricing === "object" && "tiers" in pricing) {
1157
1160
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1158
1161
  if (!tierKey) {
@@ -1289,6 +1292,7 @@ var RouteBuilder = class {
1289
1292
  path: this._path,
1290
1293
  method: this._method,
1291
1294
  maxPrice: this._maxPrice,
1295
+ minPrice: this._minPrice,
1292
1296
  apiKeyResolver: this._apiKeyResolver,
1293
1297
  providerName: this._providerName,
1294
1298
  providerConfig: this._providerConfig,
@@ -1391,9 +1395,16 @@ function buildOperation(routeKey, entry, tag) {
1391
1395
  const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
1392
1396
  let price;
1393
1397
  if (typeof entry.pricing === "string") {
1394
- price = parseFloat(entry.pricing);
1398
+ price = entry.pricing;
1399
+ } else if (typeof entry.pricing === "object" && "tiers" in entry.pricing) {
1400
+ const tierPrices = Object.values(entry.pricing.tiers).map((t) => parseFloat(t.price));
1401
+ const min = Math.min(...tierPrices);
1402
+ const max = Math.max(...tierPrices);
1403
+ price = min === max ? String(min) : `${min}-${max}`;
1404
+ } else if (entry.minPrice && entry.maxPrice) {
1405
+ price = `${entry.minPrice}-${entry.maxPrice}`;
1395
1406
  } else if (entry.maxPrice) {
1396
- price = parseFloat(entry.maxPrice);
1407
+ price = entry.maxPrice;
1397
1408
  }
1398
1409
  const operation = {
1399
1410
  operationId: routeKey.replace(/\//g, "_"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Unified route builder for Next.js App Router APIs with x402, MPP, SIWX, and API key auth",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,7 +28,7 @@
28
28
  "@x402/core": "^2.3.0",
29
29
  "@x402/evm": "^2.3.0",
30
30
  "@x402/extensions": "^2.3.0",
31
- "mppx": "^0.2.0",
31
+ "mppx": "^0.2.2",
32
32
  "next": ">=15.0.0",
33
33
  "zod": "^4.0.0",
34
34
  "zod-openapi": "^5.0.0"
@@ -47,8 +47,8 @@
47
47
  "@x402/evm": "^2.3.0",
48
48
  "@x402/extensions": "^2.3.0",
49
49
  "eslint": "^10.0.0",
50
- "mppx": "^0.2.0",
51
50
  "next": "^15.0.0",
51
+ "mppx": "^0.2.2",
52
52
  "prettier": "^3.8.1",
53
53
  "react": "^19.0.0",
54
54
  "tsup": "^8.0.0",