@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 +20 -23
- package/dist/index.js +20 -23
- package/package.json +1 -1
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 (
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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 (
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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 (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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 (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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")) {
|