@agentcash/router 0.6.4 → 0.6.5

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/.claude/CLAUDE.md CHANGED
@@ -131,6 +131,20 @@ router
131
131
 
132
132
  ## Environment Variables
133
133
 
134
+ ### Base URL Resolution
135
+
136
+ `baseUrl` is auto-detected — most consumers don't need to pass it:
137
+
138
+ 1. **`config.baseUrl`** — Explicit override (for non-Vercel deployments)
139
+ 2. **`VERCEL_URL`** — Auto-detected on Vercel (set by the platform on every build and deployment)
140
+ 3. **`localhost:PORT`** — Fallback for local dev (`PORT` env var, defaults to 3000)
141
+
142
+ In production on a non-Vercel host, pass `baseUrl` explicitly. On Vercel, it just works. In dev, it just works. No custom env vars needed.
143
+
144
+ **Do NOT use `NEXT_PUBLIC_BASE_URL`.** It was removed in 0.6.5. The library handles base URL resolution internally.
145
+
146
+ ### CDP API Keys
147
+
134
148
  The router uses the default facilitator from `@coinbase/x402`, which requires CDP API keys in `process.env`:
135
149
 
136
150
  - `CDP_API_KEY_ID` — Coinbase Developer Platform API key ID
package/dist/index.cjs CHANGED
@@ -1467,20 +1467,21 @@ function createRouter(config) {
1467
1467
  const registry = new RouteRegistry();
1468
1468
  const nonceStore = config.siwx?.nonceStore ?? new MemoryNonceStore();
1469
1469
  const network = config.network ?? "eip155:8453";
1470
- const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL : void 0);
1470
+ const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" && process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : void 0);
1471
1471
  if (config.protocols && config.protocols.length === 0) {
1472
1472
  throw new Error(
1473
1473
  "RouterConfig.protocols cannot be empty. Omit the field to use default ['x402'] or specify protocols explicitly."
1474
1474
  );
1475
1475
  }
1476
- if (!baseUrl) {
1477
- 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.";
1478
- if (process.env.NODE_ENV === "production") {
1479
- throw new Error(msg);
1480
- }
1481
- console.warn(`[router] ${msg}`);
1476
+ if (!baseUrl && process.env.NODE_ENV === "production") {
1477
+ console.warn(
1478
+ "[router] baseUrl was not provided and VERCEL_URL is not set. Falling back to localhost. Pass baseUrl in RouterConfig for non-Vercel deployments."
1479
+ );
1482
1480
  }
1483
- const resolvedBaseUrl = (baseUrl ?? "http://localhost:3000").replace(/\/+$/, "");
1481
+ const resolvedBaseUrl = (baseUrl ?? `http://localhost:${process.env.PORT ?? 3e3}`).replace(
1482
+ /\/+$/,
1483
+ ""
1484
+ );
1484
1485
  let x402ConfigError;
1485
1486
  let mppConfigError;
1486
1487
  if ((!config.protocols || config.protocols.includes("x402")) && !config.payeeAddress) {
package/dist/index.d.cts CHANGED
@@ -235,11 +235,11 @@ interface RouteEntry {
235
235
  interface RouterConfig {
236
236
  payeeAddress: string;
237
237
  /**
238
- * Production origin URL (e.g. `https://myapp.com`).
238
+ * Origin URL (e.g. `https://myapp.com`).
239
239
  * Used for discovery URLs, OpenAPI servers, and MPP realm.
240
240
  *
241
- * Falls back to `NEXT_PUBLIC_BASE_URL` env var.
242
- * Required in production `next build` will fail without it.
241
+ * Auto-detected on Vercel via `VERCEL_URL`. Falls back to `localhost:PORT` in dev.
242
+ * Only needed for non-Vercel production deployments.
243
243
  */
244
244
  baseUrl?: string;
245
245
  network?: string;
package/dist/index.d.ts CHANGED
@@ -235,11 +235,11 @@ interface RouteEntry {
235
235
  interface RouterConfig {
236
236
  payeeAddress: string;
237
237
  /**
238
- * Production origin URL (e.g. `https://myapp.com`).
238
+ * Origin URL (e.g. `https://myapp.com`).
239
239
  * Used for discovery URLs, OpenAPI servers, and MPP realm.
240
240
  *
241
- * Falls back to `NEXT_PUBLIC_BASE_URL` env var.
242
- * Required in production `next build` will fail without it.
241
+ * Auto-detected on Vercel via `VERCEL_URL`. Falls back to `localhost:PORT` in dev.
242
+ * Only needed for non-Vercel production deployments.
243
243
  */
244
244
  baseUrl?: string;
245
245
  network?: string;
package/dist/index.js CHANGED
@@ -1430,20 +1430,21 @@ function createRouter(config) {
1430
1430
  const registry = new RouteRegistry();
1431
1431
  const nonceStore = config.siwx?.nonceStore ?? new MemoryNonceStore();
1432
1432
  const network = config.network ?? "eip155:8453";
1433
- const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" ? process.env.NEXT_PUBLIC_BASE_URL : void 0);
1433
+ const baseUrl = config.baseUrl ?? (typeof globalThis.process !== "undefined" && process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : void 0);
1434
1434
  if (config.protocols && config.protocols.length === 0) {
1435
1435
  throw new Error(
1436
1436
  "RouterConfig.protocols cannot be empty. Omit the field to use default ['x402'] or specify protocols explicitly."
1437
1437
  );
1438
1438
  }
1439
- if (!baseUrl) {
1440
- 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.";
1441
- if (process.env.NODE_ENV === "production") {
1442
- throw new Error(msg);
1443
- }
1444
- console.warn(`[router] ${msg}`);
1439
+ if (!baseUrl && process.env.NODE_ENV === "production") {
1440
+ console.warn(
1441
+ "[router] baseUrl was not provided and VERCEL_URL is not set. Falling back to localhost. Pass baseUrl in RouterConfig for non-Vercel deployments."
1442
+ );
1445
1443
  }
1446
- const resolvedBaseUrl = (baseUrl ?? "http://localhost:3000").replace(/\/+$/, "");
1444
+ const resolvedBaseUrl = (baseUrl ?? `http://localhost:${process.env.PORT ?? 3e3}`).replace(
1445
+ /\/+$/,
1446
+ ""
1447
+ );
1447
1448
  let x402ConfigError;
1448
1449
  let mppConfigError;
1449
1450
  if ((!config.protocols || config.protocols.includes("x402")) && !config.payeeAddress) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
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": {