@replayio-app-building/netlify-recorder 0.51.0 → 0.52.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.
Files changed (2) hide show
  1. package/dist/index.js +43 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -206,8 +206,11 @@ function replayHttpRequest(url, _method, calls, consumed, callback, silent) {
206
206
  fakeRes.statusMessage = "";
207
207
  fakeRes.headers = {};
208
208
  if (call.responseHeaders) {
209
+ const skipHeaders = /* @__PURE__ */ new Set(["content-encoding", "transfer-encoding"]);
209
210
  for (const [k, v] of Object.entries(call.responseHeaders)) {
210
- fakeRes.headers[k.toLowerCase()] = v;
211
+ if (!skipHeaders.has(k.toLowerCase())) {
212
+ fakeRes.headers[k.toLowerCase()] = v;
213
+ }
211
214
  }
212
215
  }
213
216
  const fakeReq = new Writable({
@@ -405,6 +408,26 @@ function installNetworkInterceptor(mode, calls, options) {
405
408
  break;
406
409
  }
407
410
  }
411
+ if (matchIdx === -1) {
412
+ for (let i = 0; i < calls.length; i++) {
413
+ if (consumed.has(i)) continue;
414
+ const c = calls[i];
415
+ if (c && c.url === url) {
416
+ matchIdx = i;
417
+ break;
418
+ }
419
+ }
420
+ }
421
+ if (matchIdx === -1 && requestBody) {
422
+ for (let i = 0; i < calls.length; i++) {
423
+ if (consumed.has(i)) continue;
424
+ const c = calls[i];
425
+ if (c && c.requestBody === requestBody) {
426
+ matchIdx = i;
427
+ break;
428
+ }
429
+ }
430
+ }
408
431
  if (matchIdx === -1) {
409
432
  for (let i = 0; i < calls.length; i++) {
410
433
  if (!consumed.has(i)) {
@@ -435,15 +458,22 @@ function installNetworkInterceptor(mode, calls, options) {
435
458
  }
436
459
  const body = call.responseBody ?? "";
437
460
  const status = isPending ? 200 : call.responseStatus;
461
+ const skipHeaders = /* @__PURE__ */ new Set(["content-encoding", "transfer-encoding"]);
462
+ const filteredHeaders = {};
463
+ for (const [k, v] of Object.entries(call.responseHeaders ?? {})) {
464
+ if (!skipHeaders.has(k.toLowerCase())) {
465
+ filteredHeaders[k.toLowerCase()] = v;
466
+ }
467
+ }
438
468
  return {
439
469
  ok: status >= 200 && status < 300,
440
470
  status,
441
471
  statusText: "",
442
472
  headers: {
443
- get: (name) => (call.responseHeaders ?? {})[name.toLowerCase()] ?? null,
444
- has: (name) => name.toLowerCase() in (call.responseHeaders ?? {}),
473
+ get: (name) => filteredHeaders[name.toLowerCase()] ?? null,
474
+ has: (name) => name.toLowerCase() in filteredHeaders,
445
475
  forEach: (cb) => {
446
- for (const [k, v] of Object.entries(call.responseHeaders ?? {})) cb(v, k);
476
+ for (const [k, v] of Object.entries(filteredHeaders)) cb(v, k);
447
477
  }
448
478
  },
449
479
  text: async () => body,
@@ -1089,6 +1119,14 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1089
1119
  blobData.capturedData.envReads
1090
1120
  );
1091
1121
  globalThis.__REPLAY_RECORDING_MODE__ = true;
1122
+ const origMathRandom = Math.random;
1123
+ let prngState = 305419896;
1124
+ Math.random = () => {
1125
+ prngState = prngState + 1831565813 | 0;
1126
+ let t = Math.imul(prngState ^ prngState >>> 15, 1 | prngState);
1127
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
1128
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
1129
+ };
1092
1130
  const g = globalThis;
1093
1131
  if (typeof g.Blob === "undefined") {
1094
1132
  try {
@@ -1452,6 +1490,7 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1452
1490
  globalThis.__REPLAY_RECORDING_MODE__ = false;
1453
1491
  delete g.__REPLAY_REQUEST_COOKIES__;
1454
1492
  delete g.__REPLAY_REQUEST_HEADERS__;
1493
+ Math.random = origMathRandom;
1455
1494
  networkHandle.restore();
1456
1495
  envHandle.restore();
1457
1496
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {