@agentcash/router 0.6.2 → 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 +42 -41
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +42 -41
- 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
|
|
@@ -536,13 +537,13 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
536
537
|
}, ctx);
|
|
537
538
|
return { response, rawResult };
|
|
538
539
|
}
|
|
539
|
-
function finalize(response, rawResult, meta, pluginCtx) {
|
|
540
|
+
function finalize(response, rawResult, meta, pluginCtx, requestBody) {
|
|
540
541
|
fireProviderQuota(routeEntry, response, rawResult, deps, pluginCtx);
|
|
541
|
-
firePluginResponse(deps, pluginCtx, meta, response);
|
|
542
|
+
firePluginResponse(deps, pluginCtx, meta, response, requestBody, rawResult);
|
|
542
543
|
}
|
|
543
|
-
function fail(status, message, meta, pluginCtx) {
|
|
544
|
+
function fail(status, message, meta, pluginCtx, requestBody) {
|
|
544
545
|
const response = import_server2.NextResponse.json({ success: false, error: message }, { status });
|
|
545
|
-
firePluginResponse(deps, pluginCtx, meta, response);
|
|
546
|
+
firePluginResponse(deps, pluginCtx, meta, response, requestBody);
|
|
546
547
|
return response;
|
|
547
548
|
}
|
|
548
549
|
return async (request) => {
|
|
@@ -561,7 +562,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
561
562
|
} catch (err) {
|
|
562
563
|
const status = err.status ?? 400;
|
|
563
564
|
const message = err instanceof Error ? err.message : "Validation failed";
|
|
564
|
-
return fail(status, message, meta, pluginCtx);
|
|
565
|
+
return fail(status, message, meta, pluginCtx, body2.data);
|
|
565
566
|
}
|
|
566
567
|
}
|
|
567
568
|
const { response, rawResult } = await invoke(
|
|
@@ -572,7 +573,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
572
573
|
account2,
|
|
573
574
|
body2.data
|
|
574
575
|
);
|
|
575
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
576
|
+
finalize(response, rawResult, meta, pluginCtx, body2.data);
|
|
576
577
|
return response;
|
|
577
578
|
}
|
|
578
579
|
if (routeEntry.authMode === "unprotected") {
|
|
@@ -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);
|
|
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);
|
|
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")) {
|
|
@@ -739,7 +736,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
739
736
|
} catch (err) {
|
|
740
737
|
const status = err.status ?? 400;
|
|
741
738
|
const message = err instanceof Error ? err.message : "Validation failed";
|
|
742
|
-
return fail(status, message, meta, pluginCtx);
|
|
739
|
+
return fail(status, message, meta, pluginCtx, body.data);
|
|
743
740
|
}
|
|
744
741
|
}
|
|
745
742
|
let price;
|
|
@@ -750,7 +747,8 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
750
747
|
err.status ?? 500,
|
|
751
748
|
err instanceof Error ? err.message : "Price resolution failed",
|
|
752
749
|
meta,
|
|
753
|
-
pluginCtx
|
|
750
|
+
pluginCtx,
|
|
751
|
+
body.data
|
|
754
752
|
);
|
|
755
753
|
}
|
|
756
754
|
if (!routeEntry.protocols.includes(protocol)) {
|
|
@@ -762,14 +760,15 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
762
760
|
400,
|
|
763
761
|
`This route does not accept ${protocol} payments. Accepted protocols: ${accepted}`,
|
|
764
762
|
meta,
|
|
765
|
-
pluginCtx
|
|
763
|
+
pluginCtx,
|
|
764
|
+
body.data
|
|
766
765
|
);
|
|
767
766
|
}
|
|
768
767
|
if (protocol === "x402") {
|
|
769
768
|
if (!deps.x402Server) {
|
|
770
769
|
const reason = deps.x402InitError ? `x402 facilitator initialization failed: ${deps.x402InitError}` : "x402 server not initialized \u2014 ensure @x402/core, @x402/evm, and @coinbase/x402 are installed";
|
|
771
770
|
console.error(`[router] ${routeEntry.key}: ${reason}`);
|
|
772
|
-
return fail(500, reason, meta, pluginCtx);
|
|
771
|
+
return fail(500, reason, meta, pluginCtx, body.data);
|
|
773
772
|
}
|
|
774
773
|
const payTo = await resolvePayTo(routeEntry, request, deps.payeeAddress);
|
|
775
774
|
const verify = await verifyX402Payment(
|
|
@@ -835,17 +834,17 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
835
834
|
message: `Settlement failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
836
835
|
route: routeEntry.key
|
|
837
836
|
});
|
|
838
|
-
return fail(500, "Settlement failed", meta, pluginCtx);
|
|
837
|
+
return fail(500, "Settlement failed", meta, pluginCtx, body.data);
|
|
839
838
|
}
|
|
840
839
|
}
|
|
841
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
840
|
+
finalize(response, rawResult, meta, pluginCtx, body.data);
|
|
842
841
|
return response;
|
|
843
842
|
}
|
|
844
843
|
if (protocol === "mpp") {
|
|
845
844
|
if (!deps.mppx) {
|
|
846
845
|
const reason = deps.mppInitError ? `MPP initialization failed: ${deps.mppInitError}` : "MPP not initialized \u2014 ensure mppx is installed and mpp config (secretKey, currency, recipient) is correct";
|
|
847
846
|
console.error(`[router] ${routeEntry.key}: ${reason}`);
|
|
848
|
-
return fail(500, reason, meta, pluginCtx);
|
|
847
|
+
return fail(500, reason, meta, pluginCtx, body.data);
|
|
849
848
|
}
|
|
850
849
|
let mppResult;
|
|
851
850
|
try {
|
|
@@ -858,7 +857,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
858
857
|
message: `MPP charge failed: ${message}`,
|
|
859
858
|
route: routeEntry.key
|
|
860
859
|
});
|
|
861
|
-
return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx);
|
|
860
|
+
return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx, body.data);
|
|
862
861
|
}
|
|
863
862
|
if (mppResult.status === 402) {
|
|
864
863
|
console.warn(
|
|
@@ -890,10 +889,10 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
890
889
|
);
|
|
891
890
|
if (response.status < 400) {
|
|
892
891
|
const receiptResponse = mppResult.withReceipt(response);
|
|
893
|
-
finalize(receiptResponse, rawResult, meta, pluginCtx);
|
|
892
|
+
finalize(receiptResponse, rawResult, meta, pluginCtx, body.data);
|
|
894
893
|
return receiptResponse;
|
|
895
894
|
}
|
|
896
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
895
|
+
finalize(response, rawResult, meta, pluginCtx, body.data);
|
|
897
896
|
return response;
|
|
898
897
|
}
|
|
899
898
|
return await build402(request, routeEntry, deps, meta, pluginCtx);
|
|
@@ -1056,13 +1055,15 @@ async function build402(request, routeEntry, deps, meta, pluginCtx, bodyData) {
|
|
|
1056
1055
|
firePluginResponse(deps, pluginCtx, meta, response);
|
|
1057
1056
|
return response;
|
|
1058
1057
|
}
|
|
1059
|
-
function firePluginResponse(deps, pluginCtx, meta, response) {
|
|
1058
|
+
function firePluginResponse(deps, pluginCtx, meta, response, requestBody, responseBody) {
|
|
1060
1059
|
firePluginHook(deps.plugin, "onResponse", pluginCtx, {
|
|
1061
1060
|
statusCode: response.status,
|
|
1062
1061
|
statusText: response.statusText,
|
|
1063
1062
|
duration: Date.now() - meta.startTime,
|
|
1064
1063
|
contentType: response.headers.get("content-type"),
|
|
1065
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1064
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1065
|
+
requestBody,
|
|
1066
|
+
responseBody
|
|
1066
1067
|
});
|
|
1067
1068
|
if (response.status >= 400 && response.status !== 402) {
|
|
1068
1069
|
firePluginHook(deps.plugin, "onError", pluginCtx, {
|
package/dist/index.d.cts
CHANGED
|
@@ -89,6 +89,10 @@ interface ResponseMeta {
|
|
|
89
89
|
duration: number;
|
|
90
90
|
contentType: string | null;
|
|
91
91
|
headers: Record<string, string>;
|
|
92
|
+
/** Parsed request body (when .body() was used). undefined when no body was parsed. */
|
|
93
|
+
requestBody?: unknown;
|
|
94
|
+
/** Handler return value. undefined for raw Response returns (streams) or error paths. */
|
|
95
|
+
responseBody?: unknown;
|
|
92
96
|
}
|
|
93
97
|
interface ErrorEvent {
|
|
94
98
|
status: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -89,6 +89,10 @@ interface ResponseMeta {
|
|
|
89
89
|
duration: number;
|
|
90
90
|
contentType: string | null;
|
|
91
91
|
headers: Record<string, string>;
|
|
92
|
+
/** Parsed request body (when .body() was used). undefined when no body was parsed. */
|
|
93
|
+
requestBody?: unknown;
|
|
94
|
+
/** Handler return value. undefined for raw Response returns (streams) or error paths. */
|
|
95
|
+
responseBody?: unknown;
|
|
92
96
|
}
|
|
93
97
|
interface ErrorEvent {
|
|
94
98
|
status: number;
|
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
|
|
@@ -499,13 +500,13 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
499
500
|
}, ctx);
|
|
500
501
|
return { response, rawResult };
|
|
501
502
|
}
|
|
502
|
-
function finalize(response, rawResult, meta, pluginCtx) {
|
|
503
|
+
function finalize(response, rawResult, meta, pluginCtx, requestBody) {
|
|
503
504
|
fireProviderQuota(routeEntry, response, rawResult, deps, pluginCtx);
|
|
504
|
-
firePluginResponse(deps, pluginCtx, meta, response);
|
|
505
|
+
firePluginResponse(deps, pluginCtx, meta, response, requestBody, rawResult);
|
|
505
506
|
}
|
|
506
|
-
function fail(status, message, meta, pluginCtx) {
|
|
507
|
+
function fail(status, message, meta, pluginCtx, requestBody) {
|
|
507
508
|
const response = NextResponse2.json({ success: false, error: message }, { status });
|
|
508
|
-
firePluginResponse(deps, pluginCtx, meta, response);
|
|
509
|
+
firePluginResponse(deps, pluginCtx, meta, response, requestBody);
|
|
509
510
|
return response;
|
|
510
511
|
}
|
|
511
512
|
return async (request) => {
|
|
@@ -524,7 +525,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
524
525
|
} catch (err) {
|
|
525
526
|
const status = err.status ?? 400;
|
|
526
527
|
const message = err instanceof Error ? err.message : "Validation failed";
|
|
527
|
-
return fail(status, message, meta, pluginCtx);
|
|
528
|
+
return fail(status, message, meta, pluginCtx, body2.data);
|
|
528
529
|
}
|
|
529
530
|
}
|
|
530
531
|
const { response, rawResult } = await invoke(
|
|
@@ -535,7 +536,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
535
536
|
account2,
|
|
536
537
|
body2.data
|
|
537
538
|
);
|
|
538
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
539
|
+
finalize(response, rawResult, meta, pluginCtx, body2.data);
|
|
539
540
|
return response;
|
|
540
541
|
}
|
|
541
542
|
if (routeEntry.authMode === "unprotected") {
|
|
@@ -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);
|
|
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);
|
|
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")) {
|
|
@@ -702,7 +699,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
702
699
|
} catch (err) {
|
|
703
700
|
const status = err.status ?? 400;
|
|
704
701
|
const message = err instanceof Error ? err.message : "Validation failed";
|
|
705
|
-
return fail(status, message, meta, pluginCtx);
|
|
702
|
+
return fail(status, message, meta, pluginCtx, body.data);
|
|
706
703
|
}
|
|
707
704
|
}
|
|
708
705
|
let price;
|
|
@@ -713,7 +710,8 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
713
710
|
err.status ?? 500,
|
|
714
711
|
err instanceof Error ? err.message : "Price resolution failed",
|
|
715
712
|
meta,
|
|
716
|
-
pluginCtx
|
|
713
|
+
pluginCtx,
|
|
714
|
+
body.data
|
|
717
715
|
);
|
|
718
716
|
}
|
|
719
717
|
if (!routeEntry.protocols.includes(protocol)) {
|
|
@@ -725,14 +723,15 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
725
723
|
400,
|
|
726
724
|
`This route does not accept ${protocol} payments. Accepted protocols: ${accepted}`,
|
|
727
725
|
meta,
|
|
728
|
-
pluginCtx
|
|
726
|
+
pluginCtx,
|
|
727
|
+
body.data
|
|
729
728
|
);
|
|
730
729
|
}
|
|
731
730
|
if (protocol === "x402") {
|
|
732
731
|
if (!deps.x402Server) {
|
|
733
732
|
const reason = deps.x402InitError ? `x402 facilitator initialization failed: ${deps.x402InitError}` : "x402 server not initialized \u2014 ensure @x402/core, @x402/evm, and @coinbase/x402 are installed";
|
|
734
733
|
console.error(`[router] ${routeEntry.key}: ${reason}`);
|
|
735
|
-
return fail(500, reason, meta, pluginCtx);
|
|
734
|
+
return fail(500, reason, meta, pluginCtx, body.data);
|
|
736
735
|
}
|
|
737
736
|
const payTo = await resolvePayTo(routeEntry, request, deps.payeeAddress);
|
|
738
737
|
const verify = await verifyX402Payment(
|
|
@@ -798,17 +797,17 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
798
797
|
message: `Settlement failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
799
798
|
route: routeEntry.key
|
|
800
799
|
});
|
|
801
|
-
return fail(500, "Settlement failed", meta, pluginCtx);
|
|
800
|
+
return fail(500, "Settlement failed", meta, pluginCtx, body.data);
|
|
802
801
|
}
|
|
803
802
|
}
|
|
804
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
803
|
+
finalize(response, rawResult, meta, pluginCtx, body.data);
|
|
805
804
|
return response;
|
|
806
805
|
}
|
|
807
806
|
if (protocol === "mpp") {
|
|
808
807
|
if (!deps.mppx) {
|
|
809
808
|
const reason = deps.mppInitError ? `MPP initialization failed: ${deps.mppInitError}` : "MPP not initialized \u2014 ensure mppx is installed and mpp config (secretKey, currency, recipient) is correct";
|
|
810
809
|
console.error(`[router] ${routeEntry.key}: ${reason}`);
|
|
811
|
-
return fail(500, reason, meta, pluginCtx);
|
|
810
|
+
return fail(500, reason, meta, pluginCtx, body.data);
|
|
812
811
|
}
|
|
813
812
|
let mppResult;
|
|
814
813
|
try {
|
|
@@ -821,7 +820,7 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
821
820
|
message: `MPP charge failed: ${message}`,
|
|
822
821
|
route: routeEntry.key
|
|
823
822
|
});
|
|
824
|
-
return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx);
|
|
823
|
+
return fail(500, `MPP payment processing failed: ${message}`, meta, pluginCtx, body.data);
|
|
825
824
|
}
|
|
826
825
|
if (mppResult.status === 402) {
|
|
827
826
|
console.warn(
|
|
@@ -853,10 +852,10 @@ function createRequestHandler(routeEntry, handler, deps) {
|
|
|
853
852
|
);
|
|
854
853
|
if (response.status < 400) {
|
|
855
854
|
const receiptResponse = mppResult.withReceipt(response);
|
|
856
|
-
finalize(receiptResponse, rawResult, meta, pluginCtx);
|
|
855
|
+
finalize(receiptResponse, rawResult, meta, pluginCtx, body.data);
|
|
857
856
|
return receiptResponse;
|
|
858
857
|
}
|
|
859
|
-
finalize(response, rawResult, meta, pluginCtx);
|
|
858
|
+
finalize(response, rawResult, meta, pluginCtx, body.data);
|
|
860
859
|
return response;
|
|
861
860
|
}
|
|
862
861
|
return await build402(request, routeEntry, deps, meta, pluginCtx);
|
|
@@ -1019,13 +1018,15 @@ async function build402(request, routeEntry, deps, meta, pluginCtx, bodyData) {
|
|
|
1019
1018
|
firePluginResponse(deps, pluginCtx, meta, response);
|
|
1020
1019
|
return response;
|
|
1021
1020
|
}
|
|
1022
|
-
function firePluginResponse(deps, pluginCtx, meta, response) {
|
|
1021
|
+
function firePluginResponse(deps, pluginCtx, meta, response, requestBody, responseBody) {
|
|
1023
1022
|
firePluginHook(deps.plugin, "onResponse", pluginCtx, {
|
|
1024
1023
|
statusCode: response.status,
|
|
1025
1024
|
statusText: response.statusText,
|
|
1026
1025
|
duration: Date.now() - meta.startTime,
|
|
1027
1026
|
contentType: response.headers.get("content-type"),
|
|
1028
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1027
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1028
|
+
requestBody,
|
|
1029
|
+
responseBody
|
|
1029
1030
|
});
|
|
1030
1031
|
if (response.status >= 400 && response.status !== 402) {
|
|
1031
1032
|
firePluginHook(deps.plugin, "onError", pluginCtx, {
|