@replayio-app-building/netlify-recorder 0.53.0 → 0.55.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 +48 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ function incrementCallIndex() {
34
34
  // src/interceptors/network.ts
35
35
  import http from "http";
36
36
  import https from "https";
37
+ import zlib from "zlib";
37
38
  import { Readable, Writable } from "stream";
38
39
  function isNeonQuery(obj) {
39
40
  return typeof obj === "object" && obj !== null && "query" in obj && "params" in obj;
@@ -138,7 +139,21 @@ function patchHttpModules(mode, calls, consumed, silent) {
138
139
  entry.requestBody = bodyChunks.length > 0 ? Buffer.concat(bodyChunks).toString("utf-8") : void 0;
139
140
  entry.responseStatus = res.statusCode ?? 0;
140
141
  entry.responseHeaders = responseHeaders;
141
- entry.responseBody = Buffer.concat(resChunks).toString("utf-8");
142
+ const raw = Buffer.concat(resChunks);
143
+ const encoding = (res.headers["content-encoding"] || "").toLowerCase();
144
+ try {
145
+ if (encoding === "gzip" || encoding === "x-gzip") {
146
+ entry.responseBody = zlib.gunzipSync(raw).toString("utf-8");
147
+ } else if (encoding === "deflate") {
148
+ entry.responseBody = zlib.inflateSync(raw).toString("utf-8");
149
+ } else if (encoding === "br") {
150
+ entry.responseBody = zlib.brotliDecompressSync(raw).toString("utf-8");
151
+ } else {
152
+ entry.responseBody = raw.toString("utf-8");
153
+ }
154
+ } catch {
155
+ entry.responseBody = raw.toString("utf-8");
156
+ }
142
157
  entry.timestamp = endTime;
143
158
  entry.endTime = endTime;
144
159
  entry.pending = false;
@@ -969,7 +984,7 @@ async function finishRequest(requestContext, callbacks, response, options) {
969
984
  body: typeof response.body === "string" ? response.body : void 0
970
985
  },
971
986
  originalRequestId: options?.originalRequestId,
972
- packageVersion: "0.53.0"
987
+ packageVersion: "0.55.0"
973
988
  };
974
989
  const blobData = redactBlobData(rawBlobData);
975
990
  const blobContent = JSON.stringify(blobData);
@@ -1128,6 +1143,35 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1128
1143
  t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
1129
1144
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
1130
1145
  };
1146
+ const cryptoMod = __require("crypto");
1147
+ const origRandomBytes = cryptoMod.randomBytes;
1148
+ const origRandomUUID = cryptoMod.randomUUID;
1149
+ let cryptoSeed = 3735928559;
1150
+ const nextByte = () => {
1151
+ cryptoSeed = cryptoSeed + 1831565813 | 0;
1152
+ let t = Math.imul(cryptoSeed ^ cryptoSeed >>> 15, 1 | cryptoSeed);
1153
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
1154
+ return (t ^ t >>> 14) >>> 0 & 255;
1155
+ };
1156
+ cryptoMod.randomBytes = (size, cb) => {
1157
+ const buf = Buffer.alloc(size);
1158
+ for (let i = 0; i < size; i++) buf[i] = nextByte();
1159
+ if (cb) {
1160
+ cb(null, buf);
1161
+ return void 0;
1162
+ }
1163
+ return buf;
1164
+ };
1165
+ if (origRandomUUID) {
1166
+ cryptoMod.randomUUID = () => {
1167
+ const bytes = new Uint8Array(16);
1168
+ for (let i = 0; i < 16; i++) bytes[i] = nextByte();
1169
+ bytes[6] = bytes[6] & 15 | 64;
1170
+ bytes[8] = bytes[8] & 63 | 128;
1171
+ const h = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
1172
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
1173
+ };
1174
+ }
1131
1175
  const g = globalThis;
1132
1176
  if (typeof g.Blob === "undefined") {
1133
1177
  try {
@@ -1492,6 +1536,8 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1492
1536
  delete g.__REPLAY_REQUEST_COOKIES__;
1493
1537
  delete g.__REPLAY_REQUEST_HEADERS__;
1494
1538
  Math.random = origMathRandom;
1539
+ cryptoMod.randomBytes = origRandomBytes;
1540
+ if (origRandomUUID) cryptoMod.randomUUID = origRandomUUID;
1495
1541
  networkHandle.restore();
1496
1542
  envHandle.restore();
1497
1543
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.53.0",
3
+ "version": "0.55.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {