@replayio-app-building/netlify-recorder 0.20.0 → 0.21.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 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -423,13 +423,21 @@ function replaceAll(text, searchValue, mask) {
423
423
  function buildMask(value) {
424
424
  return "*".repeat(value.length);
425
425
  }
426
+ function buildPlaceholder(key) {
427
+ if (key === "DATABASE_URL" || key.endsWith("_DATABASE_URL")) {
428
+ return "postgresql://replay:replay@localhost:5432/replay";
429
+ }
430
+ return `placeholder_${key.toLowerCase()}`;
431
+ }
426
432
  function redactBlobData(blobData) {
427
433
  const redactions = /* @__PURE__ */ new Map();
434
+ const placeholders = /* @__PURE__ */ new Map();
428
435
  const redactedEnvReads = blobData.capturedData.envReads.map(
429
436
  (read) => {
430
437
  if (shouldRedact(read.key, read.value) && read.value !== void 0) {
431
438
  const mask = buildMask(read.value);
432
439
  redactions.set(read.value, mask);
440
+ placeholders.set(read.value, buildPlaceholder(read.key));
433
441
  return { ...read, value: mask };
434
442
  }
435
443
  return { ...read };
@@ -462,11 +470,29 @@ function redactBlobData(blobData) {
462
470
  }
463
471
  return out;
464
472
  }
473
+ const sortedPlaceholders = [...placeholders.entries()].sort(
474
+ (a, b) => b[0].length - a[0].length
475
+ );
476
+ function scrubForRequest(text) {
477
+ if (text === void 0) return void 0;
478
+ let result = text;
479
+ for (const [original, placeholder] of sortedPlaceholders) {
480
+ result = replaceAll(result, original, placeholder);
481
+ }
482
+ return result;
483
+ }
484
+ function scrubHeadersForRequest(headers) {
485
+ const out = {};
486
+ for (const [k, v] of Object.entries(headers)) {
487
+ out[k] = scrubForRequest(v) ?? v;
488
+ }
489
+ return out;
490
+ }
465
491
  const redactedRequestInfo = {
466
492
  ...blobData.requestInfo,
467
- url: scrub(blobData.requestInfo.url) ?? blobData.requestInfo.url,
468
- headers: scrubHeaders(blobData.requestInfo.headers),
469
- body: scrub(blobData.requestInfo.body)
493
+ url: scrubForRequest(blobData.requestInfo.url) ?? blobData.requestInfo.url,
494
+ headers: scrubHeadersForRequest(blobData.requestInfo.headers),
495
+ body: scrubForRequest(blobData.requestInfo.body)
470
496
  };
471
497
  const redactedNetworkCalls = blobData.capturedData.networkCalls.map(
472
498
  (call) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {