@agentcash/router 1.1.5 → 1.1.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.
package/dist/index.cjs CHANGED
@@ -1225,7 +1225,8 @@ function createRequestHandler(routeEntry, handler, deps) {
1225
1225
  price,
1226
1226
  accepts
1227
1227
  });
1228
- if (!verify?.valid) return await build402(request, routeEntry, deps, meta, pluginCtx);
1228
+ if (!verify?.valid)
1229
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1229
1230
  const { payload: verifyPayload, requirements: verifyRequirements } = verify;
1230
1231
  const matchedNetwork = getRequirementNetwork(verifyRequirements, deps.network);
1231
1232
  const wallet = normalizeWalletAddress(verify.payer);
@@ -1317,15 +1318,23 @@ function createRequestHandler(routeEntry, handler, deps) {
1317
1318
  return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx, body.data);
1318
1319
  }
1319
1320
  if (mppResult.status === 402) {
1320
- console.warn(
1321
- `[router] ${routeEntry.key}: MPP credential present but charge() returned 402 \u2014 credential may be invalid, or check TEMPO_RPC_URL configuration`
1322
- );
1321
+ let rejectReason = "";
1322
+ try {
1323
+ const problemBody = await mppResult.challenge.clone().text();
1324
+ if (problemBody) {
1325
+ const problem = JSON.parse(problemBody);
1326
+ rejectReason = problem.detail || problem.title || "";
1327
+ }
1328
+ } catch {
1329
+ }
1330
+ const detail = rejectReason || "credential may be invalid, or check TEMPO_RPC_URL configuration";
1331
+ console.warn(`[router] ${routeEntry.key}: MPP credential rejected \u2014 ${detail}`);
1323
1332
  firePluginHook(deps.plugin, "onAlert", pluginCtx, {
1324
1333
  level: "warn",
1325
- message: "MPP payment rejected despite credential present \u2014 possible config issue (TEMPO_RPC_URL)",
1334
+ message: `MPP payment rejected: ${detail}`,
1326
1335
  route: routeEntry.key
1327
1336
  });
1328
- return await build402(request, routeEntry, deps, meta, pluginCtx);
1337
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1329
1338
  }
1330
1339
  const credential = import_mppx.Credential.fromRequest(request);
1331
1340
  const rawSource = credential?.source ?? "";
@@ -1367,7 +1376,7 @@ function createRequestHandler(routeEntry, handler, deps) {
1367
1376
  finalize(response, rawResult, meta, pluginCtx, body.data);
1368
1377
  return response;
1369
1378
  }
1370
- return await build402(request, routeEntry, deps, meta, pluginCtx);
1379
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1371
1380
  };
1372
1381
  }
1373
1382
  async function parseBody(request, routeEntry) {
@@ -2284,12 +2293,14 @@ function createRouter(config) {
2284
2293
  }
2285
2294
  let builder = new RouteBuilder(key, registry, deps);
2286
2295
  builder = builder.path(normalizedPath);
2296
+ if (config.protocols) {
2297
+ builder._protocols = [...config.protocols];
2298
+ }
2287
2299
  if (definition.method) {
2288
2300
  builder = builder.method(definition.method);
2289
2301
  }
2290
2302
  if (config.prices && key in config.prices) {
2291
- const options = config.protocols ? { protocols: config.protocols } : void 0;
2292
- return builder.paid(config.prices[key], options);
2303
+ return builder.paid(config.prices[key]);
2293
2304
  }
2294
2305
  return builder;
2295
2306
  },
package/dist/index.js CHANGED
@@ -1186,7 +1186,8 @@ function createRequestHandler(routeEntry, handler, deps) {
1186
1186
  price,
1187
1187
  accepts
1188
1188
  });
1189
- if (!verify?.valid) return await build402(request, routeEntry, deps, meta, pluginCtx);
1189
+ if (!verify?.valid)
1190
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1190
1191
  const { payload: verifyPayload, requirements: verifyRequirements } = verify;
1191
1192
  const matchedNetwork = getRequirementNetwork(verifyRequirements, deps.network);
1192
1193
  const wallet = normalizeWalletAddress(verify.payer);
@@ -1278,15 +1279,23 @@ function createRequestHandler(routeEntry, handler, deps) {
1278
1279
  return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx, body.data);
1279
1280
  }
1280
1281
  if (mppResult.status === 402) {
1281
- console.warn(
1282
- `[router] ${routeEntry.key}: MPP credential present but charge() returned 402 \u2014 credential may be invalid, or check TEMPO_RPC_URL configuration`
1283
- );
1282
+ let rejectReason = "";
1283
+ try {
1284
+ const problemBody = await mppResult.challenge.clone().text();
1285
+ if (problemBody) {
1286
+ const problem = JSON.parse(problemBody);
1287
+ rejectReason = problem.detail || problem.title || "";
1288
+ }
1289
+ } catch {
1290
+ }
1291
+ const detail = rejectReason || "credential may be invalid, or check TEMPO_RPC_URL configuration";
1292
+ console.warn(`[router] ${routeEntry.key}: MPP credential rejected \u2014 ${detail}`);
1284
1293
  firePluginHook(deps.plugin, "onAlert", pluginCtx, {
1285
1294
  level: "warn",
1286
- message: "MPP payment rejected despite credential present \u2014 possible config issue (TEMPO_RPC_URL)",
1295
+ message: `MPP payment rejected: ${detail}`,
1287
1296
  route: routeEntry.key
1288
1297
  });
1289
- return await build402(request, routeEntry, deps, meta, pluginCtx);
1298
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1290
1299
  }
1291
1300
  const credential = Credential.fromRequest(request);
1292
1301
  const rawSource = credential?.source ?? "";
@@ -1328,7 +1337,7 @@ function createRequestHandler(routeEntry, handler, deps) {
1328
1337
  finalize(response, rawResult, meta, pluginCtx, body.data);
1329
1338
  return response;
1330
1339
  }
1331
- return await build402(request, routeEntry, deps, meta, pluginCtx);
1340
+ return await build402(request, routeEntry, deps, meta, pluginCtx, body.data);
1332
1341
  };
1333
1342
  }
1334
1343
  async function parseBody(request, routeEntry) {
@@ -2245,12 +2254,14 @@ function createRouter(config) {
2245
2254
  }
2246
2255
  let builder = new RouteBuilder(key, registry, deps);
2247
2256
  builder = builder.path(normalizedPath);
2257
+ if (config.protocols) {
2258
+ builder._protocols = [...config.protocols];
2259
+ }
2248
2260
  if (definition.method) {
2249
2261
  builder = builder.method(definition.method);
2250
2262
  }
2251
2263
  if (config.prices && key in config.prices) {
2252
- const options = config.protocols ? { protocols: config.protocols } : void 0;
2253
- return builder.paid(config.prices[key], options);
2264
+ return builder.paid(config.prices[key]);
2254
2265
  }
2255
2266
  return builder;
2256
2267
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
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": {