@replayio-app-building/netlify-recorder 0.57.0 → 0.59.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 +46 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -984,7 +984,7 @@ async function finishRequest(requestContext, callbacks, response, options) {
|
|
|
984
984
|
body: typeof response.body === "string" ? response.body : void 0
|
|
985
985
|
},
|
|
986
986
|
originalRequestId: options?.originalRequestId,
|
|
987
|
-
packageVersion: "0.
|
|
987
|
+
packageVersion: "0.59.0"
|
|
988
988
|
};
|
|
989
989
|
const blobData = redactBlobData(rawBlobData);
|
|
990
990
|
const blobContent = JSON.stringify(blobData);
|
|
@@ -1146,6 +1146,9 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1146
1146
|
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
1147
1147
|
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
1148
1148
|
};
|
|
1149
|
+
const origDateNow = Date.now;
|
|
1150
|
+
let dateNowCounter = 17e11;
|
|
1151
|
+
Date.now = () => dateNowCounter++;
|
|
1149
1152
|
const cryptoMod = __require("crypto");
|
|
1150
1153
|
const origRandomBytes = cryptoMod.randomBytes;
|
|
1151
1154
|
const origRandomUUID = cryptoMod.randomUUID;
|
|
@@ -1175,16 +1178,16 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1175
1178
|
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
1176
1179
|
};
|
|
1177
1180
|
}
|
|
1178
|
-
const
|
|
1179
|
-
if (typeof
|
|
1181
|
+
const g2 = globalThis;
|
|
1182
|
+
if (typeof g2.Blob === "undefined") {
|
|
1180
1183
|
try {
|
|
1181
1184
|
const { Blob: Blob2 } = __require("buffer");
|
|
1182
|
-
|
|
1185
|
+
g2.Blob = Blob2;
|
|
1183
1186
|
} catch {
|
|
1184
1187
|
}
|
|
1185
1188
|
}
|
|
1186
|
-
if (typeof
|
|
1187
|
-
const B =
|
|
1189
|
+
if (typeof g2.File === "undefined") {
|
|
1190
|
+
const B = g2.Blob ?? Object;
|
|
1188
1191
|
const FileShim = class File {
|
|
1189
1192
|
name;
|
|
1190
1193
|
lastModified;
|
|
@@ -1194,12 +1197,12 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1194
1197
|
this.lastModified = Date.now();
|
|
1195
1198
|
}
|
|
1196
1199
|
};
|
|
1197
|
-
|
|
1200
|
+
g2.File = FileShim;
|
|
1198
1201
|
}
|
|
1199
|
-
if (typeof
|
|
1202
|
+
if (typeof g2.crypto === "undefined") {
|
|
1200
1203
|
try {
|
|
1201
1204
|
const nodeCrypto = __require("crypto");
|
|
1202
|
-
|
|
1205
|
+
g2.crypto = {
|
|
1203
1206
|
randomUUID: () => nodeCrypto.randomUUID(),
|
|
1204
1207
|
getRandomValues: (buf) => nodeCrypto.getRandomValues(buf),
|
|
1205
1208
|
subtle: nodeCrypto.webcrypto?.subtle
|
|
@@ -1207,16 +1210,16 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1207
1210
|
} catch {
|
|
1208
1211
|
}
|
|
1209
1212
|
}
|
|
1210
|
-
if (
|
|
1213
|
+
if (g2.crypto && typeof g2.crypto.subtle === "undefined") {
|
|
1211
1214
|
try {
|
|
1212
1215
|
const nodeCrypto = __require("crypto");
|
|
1213
1216
|
if (nodeCrypto.webcrypto?.subtle) {
|
|
1214
|
-
|
|
1217
|
+
g2.crypto.subtle = nodeCrypto.webcrypto.subtle;
|
|
1215
1218
|
}
|
|
1216
1219
|
} catch {
|
|
1217
1220
|
}
|
|
1218
1221
|
}
|
|
1219
|
-
if (typeof
|
|
1222
|
+
if (typeof g2.Headers === "undefined") {
|
|
1220
1223
|
const HeadersShim = class Headers {
|
|
1221
1224
|
_map;
|
|
1222
1225
|
constructor(init) {
|
|
@@ -1254,10 +1257,10 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1254
1257
|
return this._map.entries();
|
|
1255
1258
|
}
|
|
1256
1259
|
};
|
|
1257
|
-
|
|
1260
|
+
g2.Headers = HeadersShim;
|
|
1258
1261
|
}
|
|
1259
|
-
if (typeof
|
|
1260
|
-
const H =
|
|
1262
|
+
if (typeof g2.Request === "undefined") {
|
|
1263
|
+
const H = g2.Headers;
|
|
1261
1264
|
const RequestShim = class Request {
|
|
1262
1265
|
method;
|
|
1263
1266
|
url;
|
|
@@ -1275,6 +1278,10 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1275
1278
|
async json() {
|
|
1276
1279
|
return JSON.parse(this._body ?? "null");
|
|
1277
1280
|
}
|
|
1281
|
+
async arrayBuffer() {
|
|
1282
|
+
const buf = Buffer.from(this._body ?? "");
|
|
1283
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
1284
|
+
}
|
|
1278
1285
|
clone() {
|
|
1279
1286
|
return new RequestShim(this.url, {
|
|
1280
1287
|
method: this.method,
|
|
@@ -1283,10 +1290,10 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1283
1290
|
});
|
|
1284
1291
|
}
|
|
1285
1292
|
};
|
|
1286
|
-
|
|
1293
|
+
g2.Request = RequestShim;
|
|
1287
1294
|
}
|
|
1288
|
-
if (typeof
|
|
1289
|
-
const H =
|
|
1295
|
+
if (typeof g2.Response === "undefined") {
|
|
1296
|
+
const H = g2.Headers;
|
|
1290
1297
|
const ResponseShim = class Response {
|
|
1291
1298
|
status;
|
|
1292
1299
|
statusText;
|
|
@@ -1323,7 +1330,7 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1323
1330
|
});
|
|
1324
1331
|
}
|
|
1325
1332
|
};
|
|
1326
|
-
|
|
1333
|
+
g2.Response = ResponseShim;
|
|
1327
1334
|
}
|
|
1328
1335
|
const result = { responseMismatch: false, unconsumedNetworkCalls: false };
|
|
1329
1336
|
const handlerModule = await import(handlerPath);
|
|
@@ -1389,12 +1396,12 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1389
1396
|
if (pb.requestInfo.body && pb.requestInfo.method !== "GET" && pb.requestInfo.method !== "HEAD") {
|
|
1390
1397
|
reqInit.body = pb.requestInfo.body;
|
|
1391
1398
|
}
|
|
1392
|
-
const RequestCtor =
|
|
1399
|
+
const RequestCtor = g2.Request;
|
|
1393
1400
|
if (RequestCtor) {
|
|
1394
1401
|
const req = new RequestCtor(url, reqInit);
|
|
1395
1402
|
const ctx = { geo: {}, ip: "127.0.0.1", requestId: "replay-warmup", server: { region: "local" } };
|
|
1396
|
-
|
|
1397
|
-
|
|
1403
|
+
g2.__REPLAY_REQUEST_COOKIES__ = Object.keys(pb.requestInfo.headers).find((k) => k.toLowerCase() === "cookie") ? pb.requestInfo.headers[Object.keys(pb.requestInfo.headers).find((k) => k.toLowerCase() === "cookie")] : "";
|
|
1404
|
+
g2.__REPLAY_REQUEST_HEADERS__ = pb.requestInfo.headers;
|
|
1398
1405
|
await handler(req, ctx);
|
|
1399
1406
|
}
|
|
1400
1407
|
} else {
|
|
@@ -1445,8 +1452,8 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1445
1452
|
}
|
|
1446
1453
|
const req = new RequestCtor(url, reqInit);
|
|
1447
1454
|
const cookieKey = Object.keys(requestInfo.headers).find((k) => k.toLowerCase() === "cookie");
|
|
1448
|
-
|
|
1449
|
-
|
|
1455
|
+
g2.__REPLAY_REQUEST_COOKIES__ = cookieKey ? requestInfo.headers[cookieKey] : "";
|
|
1456
|
+
g2.__REPLAY_REQUEST_HEADERS__ = requestInfo.headers;
|
|
1450
1457
|
const context = { geo: {}, ip: "127.0.0.1", requestId: "replay", server: { region: "local" } };
|
|
1451
1458
|
const response = await handler(req, context);
|
|
1452
1459
|
if (response && typeof response === "object" && typeof response.status === "number" && typeof response.text === "function") {
|
|
@@ -1487,7 +1494,7 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1487
1494
|
result.replayResponse = replayResponse;
|
|
1488
1495
|
result.capturedResponse = blobData.handlerResponse;
|
|
1489
1496
|
const statusMismatch = replayResponse.statusCode !== blobData.handlerResponse.statusCode;
|
|
1490
|
-
const bodyMismatch = replayResponse.body !== blobData.handlerResponse.body;
|
|
1497
|
+
const bodyMismatch = (replayResponse.body || "") !== (blobData.handlerResponse.body || "");
|
|
1491
1498
|
if (statusMismatch || bodyMismatch) {
|
|
1492
1499
|
result.responseMismatch = true;
|
|
1493
1500
|
const details = [];
|
|
@@ -1536,9 +1543,10 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1536
1543
|
console.log(` [network-replay] All ${total} recorded network call(s) were consumed.`);
|
|
1537
1544
|
}
|
|
1538
1545
|
globalThis.__REPLAY_RECORDING_MODE__ = false;
|
|
1539
|
-
delete
|
|
1540
|
-
delete
|
|
1546
|
+
delete g2.__REPLAY_REQUEST_COOKIES__;
|
|
1547
|
+
delete g2.__REPLAY_REQUEST_HEADERS__;
|
|
1541
1548
|
Math.random = origMathRandom;
|
|
1549
|
+
Date.now = origDateNow;
|
|
1542
1550
|
cryptoMod.randomBytes = origRandomBytes;
|
|
1543
1551
|
if (origRandomUUID) cryptoMod.randomUUID = origRandomUUID;
|
|
1544
1552
|
networkHandle.restore();
|
|
@@ -1548,8 +1556,19 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
|
|
|
1548
1556
|
}
|
|
1549
1557
|
|
|
1550
1558
|
// src/backendRequests.ts
|
|
1559
|
+
import { webcrypto } from "crypto";
|
|
1551
1560
|
import { gzipSync } from "zlib";
|
|
1552
1561
|
import { UTApi } from "uploadthing/server";
|
|
1562
|
+
var g = globalThis;
|
|
1563
|
+
if (typeof g.crypto === "undefined") {
|
|
1564
|
+
g.crypto = {
|
|
1565
|
+
randomUUID: () => webcrypto.randomUUID(),
|
|
1566
|
+
getRandomValues: (buf) => webcrypto.getRandomValues(buf),
|
|
1567
|
+
subtle: webcrypto.subtle
|
|
1568
|
+
};
|
|
1569
|
+
} else if (typeof g.crypto.subtle === "undefined") {
|
|
1570
|
+
g.crypto.subtle = webcrypto.subtle;
|
|
1571
|
+
}
|
|
1553
1572
|
async function backendRequestsEnsureTable(sql) {
|
|
1554
1573
|
await sql`
|
|
1555
1574
|
CREATE TABLE IF NOT EXISTS backend_requests (
|