@agentcash/router 0.4.9 → 0.5.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/dist/index.cjs +14 -5
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +14 -5
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1448,12 +1448,20 @@ function createRouter(config) {
|
|
|
1448
1448
|
const registry = new RouteRegistry();
|
|
1449
1449
|
const nonceStore = config.siwx?.nonceStore ?? new MemoryNonceStore();
|
|
1450
1450
|
const network = config.network ?? "eip155:8453";
|
|
1451
|
-
const baseUrl = typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL
|
|
1451
|
+
const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL : void 0);
|
|
1452
1452
|
if (config.protocols && config.protocols.length === 0) {
|
|
1453
1453
|
throw new Error(
|
|
1454
1454
|
"RouterConfig.protocols cannot be empty. Omit the field to use default ['x402'] or specify protocols explicitly."
|
|
1455
1455
|
);
|
|
1456
1456
|
}
|
|
1457
|
+
if (!baseUrl) {
|
|
1458
|
+
const msg = "baseUrl is required. Pass it in RouterConfig or set NEXT_PUBLIC_BASE_URL (e.g. https://myapp.com). It is used for discovery URLs, OpenAPI servers, and MPP realm.";
|
|
1459
|
+
if (process.env.NODE_ENV === "production") {
|
|
1460
|
+
throw new Error(msg);
|
|
1461
|
+
}
|
|
1462
|
+
console.warn(`[router] ${msg}`);
|
|
1463
|
+
}
|
|
1464
|
+
const resolvedBaseUrl = baseUrl ?? "http://localhost:3000";
|
|
1457
1465
|
let x402ConfigError;
|
|
1458
1466
|
let mppConfigError;
|
|
1459
1467
|
if ((!config.protocols || config.protocols.includes("x402")) && !config.payeeAddress) {
|
|
@@ -1477,7 +1485,7 @@ function createRouter(config) {
|
|
|
1477
1485
|
}
|
|
1478
1486
|
if (config.plugin?.init) {
|
|
1479
1487
|
try {
|
|
1480
|
-
const result = config.plugin.init({ origin:
|
|
1488
|
+
const result = config.plugin.init({ origin: resolvedBaseUrl });
|
|
1481
1489
|
if (result && typeof result.catch === "function") {
|
|
1482
1490
|
result.catch(() => {
|
|
1483
1491
|
});
|
|
@@ -1526,7 +1534,8 @@ function createRouter(config) {
|
|
|
1526
1534
|
}
|
|
1527
1535
|
})
|
|
1528
1536
|
],
|
|
1529
|
-
secretKey: config.mpp.secretKey
|
|
1537
|
+
secretKey: config.mpp.secretKey,
|
|
1538
|
+
realm: new URL(resolvedBaseUrl).host
|
|
1530
1539
|
});
|
|
1531
1540
|
} catch (err) {
|
|
1532
1541
|
deps.mppx = null;
|
|
@@ -1546,10 +1555,10 @@ function createRouter(config) {
|
|
|
1546
1555
|
return builder;
|
|
1547
1556
|
},
|
|
1548
1557
|
wellKnown(options) {
|
|
1549
|
-
return createWellKnownHandler(registry,
|
|
1558
|
+
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys, options);
|
|
1550
1559
|
},
|
|
1551
1560
|
openapi(options) {
|
|
1552
|
-
return createOpenAPIHandler(registry,
|
|
1561
|
+
return createOpenAPIHandler(registry, resolvedBaseUrl, pricesKeys, options);
|
|
1553
1562
|
},
|
|
1554
1563
|
monitors() {
|
|
1555
1564
|
const result = [];
|
package/dist/index.d.cts
CHANGED
|
@@ -227,6 +227,14 @@ interface RouteEntry {
|
|
|
227
227
|
}
|
|
228
228
|
interface RouterConfig {
|
|
229
229
|
payeeAddress: string;
|
|
230
|
+
/**
|
|
231
|
+
* Production origin URL (e.g. `https://myapp.com`).
|
|
232
|
+
* Used for discovery URLs, OpenAPI servers, and MPP realm.
|
|
233
|
+
*
|
|
234
|
+
* Falls back to `NEXT_PUBLIC_BASE_URL` env var.
|
|
235
|
+
* Required in production — `next build` will fail without it.
|
|
236
|
+
*/
|
|
237
|
+
baseUrl?: string;
|
|
230
238
|
network?: string;
|
|
231
239
|
facilitatorUrl?: string;
|
|
232
240
|
plugin?: RouterPlugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -227,6 +227,14 @@ interface RouteEntry {
|
|
|
227
227
|
}
|
|
228
228
|
interface RouterConfig {
|
|
229
229
|
payeeAddress: string;
|
|
230
|
+
/**
|
|
231
|
+
* Production origin URL (e.g. `https://myapp.com`).
|
|
232
|
+
* Used for discovery URLs, OpenAPI servers, and MPP realm.
|
|
233
|
+
*
|
|
234
|
+
* Falls back to `NEXT_PUBLIC_BASE_URL` env var.
|
|
235
|
+
* Required in production — `next build` will fail without it.
|
|
236
|
+
*/
|
|
237
|
+
baseUrl?: string;
|
|
230
238
|
network?: string;
|
|
231
239
|
facilitatorUrl?: string;
|
|
232
240
|
plugin?: RouterPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1411,12 +1411,20 @@ function createRouter(config) {
|
|
|
1411
1411
|
const registry = new RouteRegistry();
|
|
1412
1412
|
const nonceStore = config.siwx?.nonceStore ?? new MemoryNonceStore();
|
|
1413
1413
|
const network = config.network ?? "eip155:8453";
|
|
1414
|
-
const baseUrl = typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL
|
|
1414
|
+
const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL : void 0);
|
|
1415
1415
|
if (config.protocols && config.protocols.length === 0) {
|
|
1416
1416
|
throw new Error(
|
|
1417
1417
|
"RouterConfig.protocols cannot be empty. Omit the field to use default ['x402'] or specify protocols explicitly."
|
|
1418
1418
|
);
|
|
1419
1419
|
}
|
|
1420
|
+
if (!baseUrl) {
|
|
1421
|
+
const msg = "baseUrl is required. Pass it in RouterConfig or set NEXT_PUBLIC_BASE_URL (e.g. https://myapp.com). It is used for discovery URLs, OpenAPI servers, and MPP realm.";
|
|
1422
|
+
if (process.env.NODE_ENV === "production") {
|
|
1423
|
+
throw new Error(msg);
|
|
1424
|
+
}
|
|
1425
|
+
console.warn(`[router] ${msg}`);
|
|
1426
|
+
}
|
|
1427
|
+
const resolvedBaseUrl = baseUrl ?? "http://localhost:3000";
|
|
1420
1428
|
let x402ConfigError;
|
|
1421
1429
|
let mppConfigError;
|
|
1422
1430
|
if ((!config.protocols || config.protocols.includes("x402")) && !config.payeeAddress) {
|
|
@@ -1440,7 +1448,7 @@ function createRouter(config) {
|
|
|
1440
1448
|
}
|
|
1441
1449
|
if (config.plugin?.init) {
|
|
1442
1450
|
try {
|
|
1443
|
-
const result = config.plugin.init({ origin:
|
|
1451
|
+
const result = config.plugin.init({ origin: resolvedBaseUrl });
|
|
1444
1452
|
if (result && typeof result.catch === "function") {
|
|
1445
1453
|
result.catch(() => {
|
|
1446
1454
|
});
|
|
@@ -1489,7 +1497,8 @@ function createRouter(config) {
|
|
|
1489
1497
|
}
|
|
1490
1498
|
})
|
|
1491
1499
|
],
|
|
1492
|
-
secretKey: config.mpp.secretKey
|
|
1500
|
+
secretKey: config.mpp.secretKey,
|
|
1501
|
+
realm: new URL(resolvedBaseUrl).host
|
|
1493
1502
|
});
|
|
1494
1503
|
} catch (err) {
|
|
1495
1504
|
deps.mppx = null;
|
|
@@ -1509,10 +1518,10 @@ function createRouter(config) {
|
|
|
1509
1518
|
return builder;
|
|
1510
1519
|
},
|
|
1511
1520
|
wellKnown(options) {
|
|
1512
|
-
return createWellKnownHandler(registry,
|
|
1521
|
+
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys, options);
|
|
1513
1522
|
},
|
|
1514
1523
|
openapi(options) {
|
|
1515
|
-
return createOpenAPIHandler(registry,
|
|
1524
|
+
return createOpenAPIHandler(registry, resolvedBaseUrl, pricesKeys, options);
|
|
1516
1525
|
},
|
|
1517
1526
|
monitors() {
|
|
1518
1527
|
const result = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentcash/router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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.
|
|
31
|
+
"mppx": "^0.2.6",
|
|
32
32
|
"next": ">=15.0.0",
|
|
33
33
|
"zod": "^4.0.0",
|
|
34
34
|
"zod-openapi": "^5.0.0"
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"@changesets/cli": "^2.29.8",
|
|
43
43
|
"@coinbase/x402": "^2.1.0",
|
|
44
44
|
"@eslint/js": "^10.0.1",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
45
46
|
"@types/node": "^22.0.0",
|
|
46
47
|
"@x402/core": "^2.3.0",
|
|
47
48
|
"@x402/evm": "^2.3.0",
|
|
48
49
|
"@x402/extensions": "^2.3.0",
|
|
49
50
|
"eslint": "^10.0.0",
|
|
51
|
+
"mppx": "^0.2.6",
|
|
50
52
|
"next": "^15.0.0",
|
|
51
|
-
"mppx": "^0.2.3",
|
|
52
53
|
"prettier": "^3.8.1",
|
|
53
54
|
"react": "^19.0.0",
|
|
54
55
|
"tsup": "^8.0.0",
|