@affogatosoftware/recorder 1.2.0 → 1.3.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.
|
@@ -22,6 +22,7 @@ interface NetworkRecorderSettings {
|
|
|
22
22
|
captureResponseBodies: boolean;
|
|
23
23
|
excludeHeaders: string[];
|
|
24
24
|
requestBodyMaskingFunction?: (body: string) => string;
|
|
25
|
+
responseBodyMaskingFunction?: (body: string) => string;
|
|
25
26
|
}
|
|
26
27
|
export declare class NetworkRecorder {
|
|
27
28
|
private window;
|
|
@@ -47,7 +48,8 @@ export declare class NetworkRecorder {
|
|
|
47
48
|
private shouldCaptureRequest;
|
|
48
49
|
private sanitizeUrl;
|
|
49
50
|
private filterHeaders;
|
|
50
|
-
private
|
|
51
|
+
private truncateRequestContent;
|
|
52
|
+
private truncateResponseContent;
|
|
51
53
|
private generateRequestId;
|
|
52
54
|
private addCompletedRequest;
|
|
53
55
|
private isErrorRequest;
|
|
@@ -152,7 +152,7 @@ export class NetworkRecorder {
|
|
|
152
152
|
}
|
|
153
153
|
const sanitizedUrl = self.sanitizeUrl(url);
|
|
154
154
|
const filteredHeaders = self.filterHeaders(requestHeaders);
|
|
155
|
-
const truncatedBody = self.
|
|
155
|
+
const truncatedBody = self.truncateRequestContent(requestBody, self.networkSettings.maxRequestBodySize);
|
|
156
156
|
// Create initial request record
|
|
157
157
|
const networkRequest = {
|
|
158
158
|
requestId,
|
|
@@ -178,7 +178,7 @@ export class NetworkRecorder {
|
|
|
178
178
|
try {
|
|
179
179
|
const clonedResponse = response.clone();
|
|
180
180
|
const text = await clonedResponse.text();
|
|
181
|
-
responseBody = self.
|
|
181
|
+
responseBody = self.truncateResponseContent(text, self.networkSettings.maxResponseBodySize);
|
|
182
182
|
}
|
|
183
183
|
catch (e) {
|
|
184
184
|
responseBody = "[Unable to read response body]";
|
|
@@ -249,7 +249,7 @@ export class NetworkRecorder {
|
|
|
249
249
|
method,
|
|
250
250
|
url,
|
|
251
251
|
requestHeaders: Object.keys(requestHeaders).length > 0 ? self.filterHeaders(requestHeaders) : undefined,
|
|
252
|
-
requestBody: self.
|
|
252
|
+
requestBody: self.truncateRequestContent(requestBody, self.networkSettings.maxRequestBodySize),
|
|
253
253
|
timestamp
|
|
254
254
|
};
|
|
255
255
|
self.pendingRequests.set(requestId, networkRequest);
|
|
@@ -273,7 +273,7 @@ export class NetworkRecorder {
|
|
|
273
273
|
}
|
|
274
274
|
if (self.networkSettings.captureResponseBodies) {
|
|
275
275
|
try {
|
|
276
|
-
responseBody = self.
|
|
276
|
+
responseBody = self.truncateResponseContent(xhr.responseText, self.networkSettings.maxResponseBodySize);
|
|
277
277
|
}
|
|
278
278
|
catch (e) {
|
|
279
279
|
responseBody = "[Unable to read response]";
|
|
@@ -353,13 +353,36 @@ export class NetworkRecorder {
|
|
|
353
353
|
}
|
|
354
354
|
return filtered;
|
|
355
355
|
}
|
|
356
|
-
|
|
356
|
+
truncateRequestContent(content, maxSize) {
|
|
357
357
|
if (!content)
|
|
358
358
|
return content;
|
|
359
|
-
// Apply masking function if provided
|
|
359
|
+
// Apply request masking function if provided
|
|
360
360
|
let processedContent = content;
|
|
361
361
|
if (this.networkSettings.requestBodyMaskingFunction) {
|
|
362
|
-
|
|
362
|
+
try {
|
|
363
|
+
processedContent = this.networkSettings.requestBodyMaskingFunction(content);
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
logger.error("Failed to apply request masking function");
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (processedContent.length > maxSize) {
|
|
370
|
+
return processedContent.substring(0, maxSize) + `... [truncated from ${processedContent.length} chars]`;
|
|
371
|
+
}
|
|
372
|
+
return processedContent;
|
|
373
|
+
}
|
|
374
|
+
truncateResponseContent(content, maxSize) {
|
|
375
|
+
if (!content)
|
|
376
|
+
return content;
|
|
377
|
+
// Apply response masking function if provided
|
|
378
|
+
let processedContent = content;
|
|
379
|
+
if (this.networkSettings.responseBodyMaskingFunction) {
|
|
380
|
+
try {
|
|
381
|
+
processedContent = this.networkSettings.responseBodyMaskingFunction(content);
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
logger.error("Failed to apply response masking function");
|
|
385
|
+
}
|
|
363
386
|
}
|
|
364
387
|
if (processedContent.length > maxSize) {
|
|
365
388
|
return processedContent.substring(0, maxSize) + `... [truncated from ${processedContent.length} chars]`;
|
|
@@ -37,6 +37,7 @@ export interface RecorderSettings {
|
|
|
37
37
|
captureResponseBodies: boolean;
|
|
38
38
|
excludeHeaders: string[];
|
|
39
39
|
requestBodyMaskingFunction?: (body: string) => string;
|
|
40
|
+
responseBodyMaskingFunction?: (body: string) => string;
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
export interface CapturedUserMetadata {
|