@replayio-app-building/netlify-recorder 0.49.0 → 0.50.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 +29 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ function buildSetConfigQueries(requestId, callIndex) {
55
55
  { query: "SELECT set_config('app.replay_call_index', $1, true)", params: [String(callIndex)] }
56
56
  ];
57
57
  }
58
- function patchHttpModules(mode, calls, consumed) {
58
+ function patchHttpModules(mode, calls, consumed, silent) {
59
59
  const origHttpRequest = http.request;
60
60
  const origHttpsRequest = https.request;
61
61
  function makeInterceptedRequest(mod, origRequest, protocol, args) {
@@ -87,7 +87,7 @@ function patchHttpModules(mode, calls, consumed) {
87
87
  const urlStr = `${protocol}//${host}${port}${path}`;
88
88
  const method = (options.method || "GET").toUpperCase();
89
89
  if (mode === "replay") {
90
- return replayHttpRequest(urlStr, method, calls, consumed, callback);
90
+ return replayHttpRequest(urlStr, method, calls, consumed, callback, silent);
91
91
  }
92
92
  const req = origRequest.call(mod, ...args);
93
93
  const bodyChunks = [];
@@ -148,7 +148,7 @@ function patchHttpModules(mode, calls, consumed) {
148
148
  https.request = origHttpsRequest;
149
149
  };
150
150
  }
151
- function replayHttpRequest(url, _method, calls, consumed, callback) {
151
+ function replayHttpRequest(url, _method, calls, consumed, callback, silent) {
152
152
  let matchIdx = -1;
153
153
  for (let i = 0; i < calls.length; i++) {
154
154
  if (consumed.has(i)) continue;
@@ -173,10 +173,12 @@ function replayHttpRequest(url, _method, calls, consumed, callback) {
173
173
  );
174
174
  }
175
175
  consumed.add(matchIdx);
176
- const duration = call.endTime - call.startTime;
177
- console.log(
178
- ` [network-replay] Consumed call ${consumed.size}/${calls.length}: ${call.method} ${call.url} => ${call.responseStatus} (original: ${duration}ms)`
179
- );
176
+ if (!silent) {
177
+ const duration = call.endTime - call.startTime;
178
+ console.log(
179
+ ` [network-replay] Consumed call ${consumed.size}/${calls.length}: ${call.method} ${call.url} => ${call.responseStatus} (original: ${duration}ms)`
180
+ );
181
+ }
180
182
  const body = call.responseBody ?? "";
181
183
  const fakeRes = new Readable({
182
184
  read() {
@@ -267,7 +269,8 @@ function ensureCaptureInterceptor() {
267
269
  };
268
270
  globalThis.fetch = captureFetch;
269
271
  }
270
- function installNetworkInterceptor(mode, calls) {
272
+ function installNetworkInterceptor(mode, calls, options) {
273
+ const silent = options?.silent ?? false;
271
274
  if (mode === "capture") {
272
275
  const store = getRequestStore();
273
276
  if (store) {
@@ -385,10 +388,12 @@ function installNetworkInterceptor(mode, calls) {
385
388
  );
386
389
  }
387
390
  consumed.add(matchIdx);
388
- const duration = call.endTime - call.startTime;
389
- console.log(
390
- ` [network-replay] Consumed call ${consumed.size}/${calls.length}: ${call.method} ${call.url} => ${call.responseStatus} (original: ${duration}ms)`
391
- );
391
+ if (!silent) {
392
+ const duration = call.endTime - call.startTime;
393
+ console.log(
394
+ ` [network-replay] Consumed call ${consumed.size}/${calls.length}: ${call.method} ${call.url} => ${call.responseStatus} (original: ${duration}ms)`
395
+ );
396
+ }
392
397
  const body = call.responseBody ?? "";
393
398
  const status = call.responseStatus;
394
399
  return {
@@ -420,7 +425,7 @@ function installNetworkInterceptor(mode, calls) {
420
425
  };
421
426
  };
422
427
  globalThis.fetch = replayFetch;
423
- const restoreHttp = patchHttpModules("replay", calls, consumed);
428
+ const restoreHttp = patchHttpModules("replay", calls, consumed, silent);
424
429
  return {
425
430
  restore() {
426
431
  globalThis.fetch = originalFetch;
@@ -1249,9 +1254,9 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1249
1254
  console.log(` [warm-up] Replaying ${precedingBlobs.length} preceding request(s) to populate module-level state\u2026`);
1250
1255
  for (let i = 0; i < precedingBlobs.length; i++) {
1251
1256
  const pb = precedingBlobs[i];
1252
- console.log(` [warm-up ${i + 1}/${precedingBlobs.length}] ${pb.requestInfo.method} ${pb.requestInfo.url}`);
1253
- const netH = installNetworkInterceptor("replay", pb.capturedData.networkCalls);
1257
+ const netH = installNetworkInterceptor("replay", pb.capturedData.networkCalls, { silent: true });
1254
1258
  const envH = installEnvironmentInterceptor("replay", pb.capturedData.envReads);
1259
+ let warmupError;
1255
1260
  try {
1256
1261
  if (isV2) {
1257
1262
  const url = pb.requestInfo.rawUrl ?? `https://localhost${pb.requestInfo.url}`;
@@ -1280,10 +1285,18 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo, p
1280
1285
  isBase64Encoded: pb.requestInfo.isBase64Encoded ?? false
1281
1286
  });
1282
1287
  }
1283
- } catch {
1288
+ } catch (err) {
1289
+ warmupError = err instanceof Error ? err.message : String(err);
1284
1290
  }
1291
+ const consumed = netH.consumedCount();
1292
+ const total = netH.totalCount();
1285
1293
  netH.restore();
1286
1294
  envH.restore();
1295
+ if (warmupError) {
1296
+ console.error(` [warm-up ${i + 1}/${precedingBlobs.length}] ${pb.requestInfo.method} ${pb.requestInfo.url} \u2014 ERROR: ${warmupError} (${consumed}/${total} calls)`);
1297
+ } else {
1298
+ console.log(` [warm-up ${i + 1}/${precedingBlobs.length}] ${pb.requestInfo.method} ${pb.requestInfo.url} \u2014 OK (${consumed}/${total} network calls)`);
1299
+ }
1287
1300
  }
1288
1301
  console.log(` [warm-up] Done.`);
1289
1302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {