@agentcash/router 0.6.3 → 0.6.4

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
@@ -382,7 +382,8 @@ async function buildX402Challenge(server, routeEntry, request, price, payeeAddre
382
382
  const resource = {
383
383
  url: request.url,
384
384
  method: routeEntry.method,
385
- description: routeEntry.description
385
+ description: routeEntry.description,
386
+ mimeType: "application/json"
386
387
  };
387
388
  const requirements = await server.buildPaymentRequirementsFromOptions([options], {
388
389
  request
@@ -605,18 +606,16 @@ function createRequestHandler(routeEntry, handler, deps) {
605
606
  if (needsEarlyParse) {
606
607
  const requestForPricing = request.clone();
607
608
  const earlyBodyResult = await parseBody(requestForPricing, routeEntry);
608
- if (!earlyBodyResult.ok) {
609
- firePluginResponse(deps, pluginCtx, meta, earlyBodyResult.response);
610
- return earlyBodyResult.response;
611
- }
612
- earlyBodyData = earlyBodyResult.data;
613
- if (routeEntry.validateFn) {
614
- try {
615
- await routeEntry.validateFn(earlyBodyData);
616
- } catch (err) {
617
- const status = err.status ?? 400;
618
- const message = err instanceof Error ? err.message : "Validation failed";
619
- return fail(status, message, meta, pluginCtx, earlyBodyData);
609
+ if (earlyBodyResult.ok) {
610
+ earlyBodyData = earlyBodyResult.data;
611
+ if (routeEntry.validateFn) {
612
+ try {
613
+ await routeEntry.validateFn(earlyBodyData);
614
+ } catch (err) {
615
+ const status = err.status ?? 400;
616
+ const message = err instanceof Error ? err.message : "Validation failed";
617
+ return fail(status, message, meta, pluginCtx, earlyBodyData);
618
+ }
620
619
  }
621
620
  }
622
621
  }
@@ -624,16 +623,14 @@ function createRequestHandler(routeEntry, handler, deps) {
624
623
  if (routeEntry.validateFn && routeEntry.bodySchema && !request.headers.get("SIGN-IN-WITH-X")) {
625
624
  const requestForValidation = request.clone();
626
625
  const earlyBodyResult = await parseBody(requestForValidation, routeEntry);
627
- if (!earlyBodyResult.ok) {
628
- firePluginResponse(deps, pluginCtx, meta, earlyBodyResult.response);
629
- return earlyBodyResult.response;
630
- }
631
- try {
632
- await routeEntry.validateFn(earlyBodyResult.data);
633
- } catch (err) {
634
- const status = err.status ?? 400;
635
- const message = err instanceof Error ? err.message : "Validation failed";
636
- return fail(status, message, meta, pluginCtx, earlyBodyResult.data);
626
+ if (earlyBodyResult.ok) {
627
+ try {
628
+ await routeEntry.validateFn(earlyBodyResult.data);
629
+ } catch (err) {
630
+ const status = err.status ?? 400;
631
+ const message = err instanceof Error ? err.message : "Validation failed";
632
+ return fail(status, message, meta, pluginCtx, earlyBodyResult.data);
633
+ }
637
634
  }
638
635
  }
639
636
  if (!request.headers.get("SIGN-IN-WITH-X")) {
package/dist/index.js CHANGED
@@ -345,7 +345,8 @@ async function buildX402Challenge(server, routeEntry, request, price, payeeAddre
345
345
  const resource = {
346
346
  url: request.url,
347
347
  method: routeEntry.method,
348
- description: routeEntry.description
348
+ description: routeEntry.description,
349
+ mimeType: "application/json"
349
350
  };
350
351
  const requirements = await server.buildPaymentRequirementsFromOptions([options], {
351
352
  request
@@ -568,18 +569,16 @@ function createRequestHandler(routeEntry, handler, deps) {
568
569
  if (needsEarlyParse) {
569
570
  const requestForPricing = request.clone();
570
571
  const earlyBodyResult = await parseBody(requestForPricing, routeEntry);
571
- if (!earlyBodyResult.ok) {
572
- firePluginResponse(deps, pluginCtx, meta, earlyBodyResult.response);
573
- return earlyBodyResult.response;
574
- }
575
- earlyBodyData = earlyBodyResult.data;
576
- if (routeEntry.validateFn) {
577
- try {
578
- await routeEntry.validateFn(earlyBodyData);
579
- } catch (err) {
580
- const status = err.status ?? 400;
581
- const message = err instanceof Error ? err.message : "Validation failed";
582
- return fail(status, message, meta, pluginCtx, earlyBodyData);
572
+ if (earlyBodyResult.ok) {
573
+ earlyBodyData = earlyBodyResult.data;
574
+ if (routeEntry.validateFn) {
575
+ try {
576
+ await routeEntry.validateFn(earlyBodyData);
577
+ } catch (err) {
578
+ const status = err.status ?? 400;
579
+ const message = err instanceof Error ? err.message : "Validation failed";
580
+ return fail(status, message, meta, pluginCtx, earlyBodyData);
581
+ }
583
582
  }
584
583
  }
585
584
  }
@@ -587,16 +586,14 @@ function createRequestHandler(routeEntry, handler, deps) {
587
586
  if (routeEntry.validateFn && routeEntry.bodySchema && !request.headers.get("SIGN-IN-WITH-X")) {
588
587
  const requestForValidation = request.clone();
589
588
  const earlyBodyResult = await parseBody(requestForValidation, routeEntry);
590
- if (!earlyBodyResult.ok) {
591
- firePluginResponse(deps, pluginCtx, meta, earlyBodyResult.response);
592
- return earlyBodyResult.response;
593
- }
594
- try {
595
- await routeEntry.validateFn(earlyBodyResult.data);
596
- } catch (err) {
597
- const status = err.status ?? 400;
598
- const message = err instanceof Error ? err.message : "Validation failed";
599
- return fail(status, message, meta, pluginCtx, earlyBodyResult.data);
589
+ if (earlyBodyResult.ok) {
590
+ try {
591
+ await routeEntry.validateFn(earlyBodyResult.data);
592
+ } catch (err) {
593
+ const status = err.status ?? 400;
594
+ const message = err instanceof Error ? err.message : "Validation failed";
595
+ return fail(status, message, meta, pluginCtx, earlyBodyResult.data);
596
+ }
600
597
  }
601
598
  }
602
599
  if (!request.headers.get("SIGN-IN-WITH-X")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
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": {