@replayio-app-building/netlify-recorder 0.35.0 → 0.37.0
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.js +34 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -716,8 +716,8 @@ async function finishRequest(requestContext, callbacks, response, options) {
|
|
|
716
716
|
startTime: requestContext.startTime,
|
|
717
717
|
endTime: Date.now(),
|
|
718
718
|
handlerResponse: {
|
|
719
|
-
statusCode: response.statusCode,
|
|
720
|
-
body: response.body
|
|
719
|
+
statusCode: response.statusCode ?? response.status ?? 0,
|
|
720
|
+
body: typeof response.body === "string" ? response.body : void 0
|
|
721
721
|
}
|
|
722
722
|
};
|
|
723
723
|
const blobData = redactBlobData(rawBlobData);
|
|
@@ -756,7 +756,18 @@ function createRecordingRequestHandler(handler, options) {
|
|
|
756
756
|
const reqContext = startRequest(event);
|
|
757
757
|
let response;
|
|
758
758
|
try {
|
|
759
|
-
|
|
759
|
+
const rawResponse = await handler(event, context);
|
|
760
|
+
if (rawResponse && typeof rawResponse.status === "number" && typeof rawResponse.text === "function") {
|
|
761
|
+
const v2 = rawResponse;
|
|
762
|
+
const bodyText = await v2.text();
|
|
763
|
+
response = {
|
|
764
|
+
statusCode: v2.status,
|
|
765
|
+
body: bodyText,
|
|
766
|
+
headers: v2.headers?.entries ? Object.fromEntries(v2.headers.entries()) : void 0
|
|
767
|
+
};
|
|
768
|
+
} else {
|
|
769
|
+
response = rawResponse;
|
|
770
|
+
}
|
|
760
771
|
} catch (handlerErr) {
|
|
761
772
|
const errorMessage = handlerErr instanceof Error ? handlerErr.message : String(handlerErr);
|
|
762
773
|
const errorResponse = {
|
|
@@ -1021,6 +1032,24 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo) {
|
|
|
1021
1032
|
handler = handlerModule;
|
|
1022
1033
|
isV2 = true;
|
|
1023
1034
|
}
|
|
1035
|
+
if (!handler && requestInfo.method) {
|
|
1036
|
+
const httpMethodNames = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
|
|
1037
|
+
let target = handlerModule;
|
|
1038
|
+
for (let depth = 0; depth < 6 && target && typeof target === "object"; depth++) {
|
|
1039
|
+
const obj = target;
|
|
1040
|
+
const method = requestInfo.method.toUpperCase();
|
|
1041
|
+
if (httpMethodNames.includes(method) && typeof obj[method] === "function") {
|
|
1042
|
+
handler = obj[method];
|
|
1043
|
+
isV2 = true;
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
if (obj.default && typeof obj.default === "object") {
|
|
1047
|
+
target = obj.default;
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
break;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1024
1053
|
if (!handler) {
|
|
1025
1054
|
throw new Error(
|
|
1026
1055
|
`Could not resolve handler from ${handlerPath}. Module exports: [${Object.keys(handlerModule).join(", ")}]`
|
|
@@ -1094,8 +1123,8 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo) {
|
|
|
1094
1123
|
);
|
|
1095
1124
|
}
|
|
1096
1125
|
if (bodyMismatch) {
|
|
1097
|
-
const capturedPreview = (blobData.handlerResponse.body ?? "").slice(0, 200);
|
|
1098
|
-
const replayPreview = (replayResponse.body ?? "").slice(0, 200);
|
|
1126
|
+
const capturedPreview = String(blobData.handlerResponse.body ?? "").slice(0, 200);
|
|
1127
|
+
const replayPreview = String(replayResponse.body ?? "").slice(0, 200);
|
|
1099
1128
|
details.push(
|
|
1100
1129
|
`Body differs: captured=${JSON.stringify(capturedPreview)}, replay=${JSON.stringify(replayPreview)}`
|
|
1101
1130
|
);
|