@checkly/playwright-core 1.48.22 → 1.48.24-beta.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 (91) hide show
  1. package/lib/checkly/secretsFilter.js +29 -6
  2. package/lib/client/clientStackTrace.js +65 -0
  3. package/lib/client/fileUtils.js +31 -0
  4. package/lib/client/platform.js +71 -0
  5. package/lib/client/timeoutSettings.js +65 -0
  6. package/lib/client/webSocket.js +106 -0
  7. package/lib/server/callLog.js +79 -0
  8. package/lib/server/harBackend.js +157 -0
  9. package/lib/server/localUtils.js +203 -0
  10. package/lib/server/recorder/chat.js +177 -0
  11. package/lib/server/storageScript.js +160 -0
  12. package/lib/server/timeoutSettings.js +74 -0
  13. package/lib/server/utils/ascii.js +31 -0
  14. package/lib/server/utils/comparators.js +159 -0
  15. package/lib/server/utils/crypto.js +171 -0
  16. package/lib/server/utils/debug.js +38 -0
  17. package/lib/server/utils/debugLogger.js +93 -0
  18. package/lib/server/utils/env.js +53 -0
  19. package/lib/server/utils/eventsHelper.js +38 -0
  20. package/lib/server/utils/expectUtils.js +33 -0
  21. package/lib/server/utils/fileUtils.js +204 -0
  22. package/lib/server/utils/happyEyeballs.js +209 -0
  23. package/lib/server/utils/hostPlatform.js +145 -0
  24. package/lib/server/utils/httpServer.js +233 -0
  25. package/lib/server/utils/image_tools/colorUtils.js +98 -0
  26. package/lib/server/utils/image_tools/compare.js +108 -0
  27. package/lib/server/utils/image_tools/imageChannel.js +70 -0
  28. package/lib/server/utils/image_tools/stats.js +102 -0
  29. package/lib/server/utils/linuxUtils.js +58 -0
  30. package/lib/server/utils/network.js +160 -0
  31. package/lib/server/utils/nodePlatform.js +140 -0
  32. package/lib/server/utils/pipeTransport.js +82 -0
  33. package/lib/server/utils/processLauncher.js +248 -0
  34. package/lib/server/utils/profiler.js +52 -0
  35. package/lib/server/utils/socksProxy.js +570 -0
  36. package/lib/server/utils/spawnAsync.js +45 -0
  37. package/lib/server/utils/task.js +58 -0
  38. package/lib/server/utils/userAgent.js +91 -0
  39. package/lib/server/utils/wsServer.js +128 -0
  40. package/lib/server/utils/zipFile.js +75 -0
  41. package/lib/server/utils/zones.js +54 -0
  42. package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
  43. package/lib/utils/isomorphic/assert.js +25 -0
  44. package/lib/utils/isomorphic/colors.js +65 -0
  45. package/lib/utils/isomorphic/headers.js +52 -0
  46. package/lib/utils/isomorphic/manualPromise.js +107 -0
  47. package/lib/utils/isomorphic/multimap.js +73 -0
  48. package/lib/utils/isomorphic/rtti.js +41 -0
  49. package/lib/utils/isomorphic/semaphore.js +51 -0
  50. package/lib/utils/isomorphic/stackTrace.js +169 -0
  51. package/lib/utils/isomorphic/time.js +25 -0
  52. package/lib/utils/isomorphic/timeoutRunner.js +66 -0
  53. package/lib/utils/isomorphic/types.js +5 -0
  54. package/lib/utils.js +447 -0
  55. package/lib/vite/recorder/assets/codeMirrorModule-xqJWdfrS.js +24 -0
  56. package/lib/vite/recorder/assets/{index-Bxxcmxlu.js → index-DDT9w7gI.js} +2 -2
  57. package/lib/vite/recorder/index.html +1 -1
  58. package/lib/vite/traceViewer/assets/{codeMirrorModule-pBPtArIT.js → codeMirrorModule-Bh1rfd2w.js} +14 -14
  59. package/lib/vite/traceViewer/assets/codeMirrorModule-DZoSgqUd.js +24 -0
  60. package/lib/vite/traceViewer/assets/codeMirrorModule-lDjkI8Ax.js +24 -0
  61. package/lib/vite/{recorder/assets/codeMirrorModule-d0KhC1qL.js → traceViewer/assets/codeMirrorModule-xvopPhZ4.js} +1 -1
  62. package/lib/vite/traceViewer/assets/{inspectorTab-Soeeuvzv.js → inspectorTab-7GHnKvSD.js} +2 -2
  63. package/lib/vite/traceViewer/assets/{inspectorTab-BuJ3wAX_.js → inspectorTab-BHcfR9dD.js} +3 -3
  64. package/lib/vite/traceViewer/assets/inspectorTab-BPzhNk9r.js +64 -0
  65. package/lib/vite/traceViewer/assets/inspectorTab-wfvwpMHs.js +64 -0
  66. package/lib/vite/traceViewer/assets/{workbench-DdmJ9AJV.js → workbench-C6nMfKVy.js} +1 -1
  67. package/lib/vite/traceViewer/assets/{workbench-lypYlf00.js → workbench-DLv_q9ji.js} +1 -1
  68. package/lib/vite/traceViewer/assets/workbench-DZqNXdoV.js +9 -0
  69. package/lib/vite/traceViewer/assets/workbench-LKskf2Iy.js +9 -0
  70. package/lib/vite/traceViewer/{embedded.BkvOrz5Z.js → embedded.BIubxTi3.js} +1 -1
  71. package/lib/vite/traceViewer/{embedded.DInvAijy.js → embedded.BXYl5zRv.js} +1 -1
  72. package/lib/vite/traceViewer/embedded.CShPz96b.js +2 -0
  73. package/lib/vite/traceViewer/embedded.Dxe2heQk.js +2 -0
  74. package/lib/vite/traceViewer/embedded.html +3 -3
  75. package/lib/vite/traceViewer/{index.Dha3cgqs.js → index.BZ9CE8t3.js} +1 -1
  76. package/lib/vite/traceViewer/{index._Iolt-uE.js → index.CB297BuW.js} +1 -1
  77. package/lib/vite/traceViewer/index.DPD22sZn.js +2 -0
  78. package/lib/vite/traceViewer/index.DZkJsFod.js +2 -0
  79. package/lib/vite/traceViewer/index.html +3 -3
  80. package/lib/vite/traceViewer/{recorder.DNMfnSiu.js → recorder.BVExlUUk.js} +1 -1
  81. package/lib/vite/traceViewer/{recorder.DTSaNaly.js → recorder.BaRuS6Pc.js} +1 -1
  82. package/lib/vite/traceViewer/recorder.C4zxcvd2.js +2 -0
  83. package/lib/vite/traceViewer/recorder.C88JDknq.js +2 -0
  84. package/lib/vite/traceViewer/recorder.html +2 -2
  85. package/lib/vite/traceViewer/{uiMode.BM7yhjzl.js → uiMode.2tr9k625.js} +1 -1
  86. package/lib/vite/traceViewer/{uiMode.Cr1tvTWS.js → uiMode.B11wexdJ.js} +1 -1
  87. package/lib/vite/traceViewer/uiMode.DXa41vt9.js +5 -0
  88. package/lib/vite/traceViewer/uiMode.DjTS7tqC.js +5 -0
  89. package/lib/vite/traceViewer/uiMode.html +3 -3
  90. package/package.json +1 -1
  91. package/lib/vite/traceViewer/assets/codeMirrorModule-tzBrK1V4.js +0 -24
@@ -13,11 +13,34 @@ const IdentityFunction = s => s;
13
13
  const secretsFilter = () => {
14
14
  const disabled = process.env['CHECKLY_INTERNAL_ENABLE_PATCHED_TRACING'] !== 'true';
15
15
  if (disabled) return IdentityFunction;
16
- const keys = process.env['CHECKLY_INTERNAL_REPLACE_TRACE_KEYS'] || '[]';
17
- const keylist = JSON.parse(keys);
18
- if (keylist.length === 0) return IdentityFunction;
19
- const escapedList = keylist.map(_escapeRegExp.default);
20
- const regex = new RegExp(escapedList.join('|'), 'g');
21
- return s => s.replaceAll(regex, '*********');
16
+
17
+ // Cache for regex to avoid recompiling on every call
18
+ let cachedRegex = null;
19
+ let cachedKeys = '';
20
+
21
+ // Regex to filter out console markers
22
+ const consoleMarkerRegex = /\[CHECKLY_RUNTIME_SECRET\].*?\[\/CHECKLY_RUNTIME_SECRET\]/g;
23
+ return s => {
24
+ const keys = process.env['CHECKLY_INTERNAL_REPLACE_TRACE_KEYS'] || '[]';
25
+
26
+ // Only recompile regex if keys have changed (handles runtime CHECKLY_SECRET_ variables)
27
+ if (keys !== cachedKeys) {
28
+ const keylist = JSON.parse(keys);
29
+ if (keylist.length === 0) {
30
+ cachedRegex = null;
31
+ } else {
32
+ const escapedList = keylist.map(_escapeRegExp.default);
33
+ cachedRegex = new RegExp(escapedList.join('|'), 'g');
34
+ }
35
+ cachedKeys = keys;
36
+ }
37
+
38
+ // First filter out console markers entirely
39
+ let filtered = s.replace(consoleMarkerRegex, '');
40
+
41
+ // Scrub secrets
42
+ if (cachedRegex) filtered = filtered.replaceAll(cachedRegex, '*********');
43
+ return filtered;
44
+ };
22
45
  };
23
46
  exports.secretsFilter = secretsFilter;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.captureLibraryStackTrace = captureLibraryStackTrace;
7
+ var _stackTrace = require("../utils/isomorphic/stackTrace");
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ function captureLibraryStackTrace(platform) {
25
+ const stack = (0, _stackTrace.captureRawStack)();
26
+ let parsedFrames = stack.map(line => {
27
+ const frame = (0, _stackTrace.parseStackFrame)(line, platform.pathSeparator, platform.showInternalStackFrames());
28
+ if (!frame || !frame.file) return null;
29
+ const isPlaywrightLibrary = !!platform.coreDir && frame.file.startsWith(platform.coreDir);
30
+ const parsed = {
31
+ frame,
32
+ frameText: line,
33
+ isPlaywrightLibrary
34
+ };
35
+ return parsed;
36
+ }).filter(Boolean);
37
+ let apiName = '';
38
+
39
+ // Deepest transition between non-client code calling into client
40
+ // code is the api entry.
41
+ for (let i = 0; i < parsedFrames.length - 1; i++) {
42
+ const parsedFrame = parsedFrames[i];
43
+ if (parsedFrame.isPlaywrightLibrary && !parsedFrames[i + 1].isPlaywrightLibrary) {
44
+ apiName = apiName || normalizeAPIName(parsedFrame.frame.function);
45
+ break;
46
+ }
47
+ }
48
+ function normalizeAPIName(name) {
49
+ if (!name) return '';
50
+ const match = name.match(/(API|JS|CDP|[A-Z])(.*)/);
51
+ if (!match) return name;
52
+ return match[1].toLowerCase() + match[2];
53
+ }
54
+
55
+ // This is for the inspector so that it did not include the test runner stack frames.
56
+ const filterPrefixes = platform.boxedStackPrefixes();
57
+ parsedFrames = parsedFrames.filter(f => {
58
+ if (filterPrefixes.some(prefix => f.frame.file.startsWith(prefix))) return false;
59
+ return true;
60
+ });
61
+ return {
62
+ frames: parsedFrames.map(p => p.frame),
63
+ apiName
64
+ };
65
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fileUploadSizeLimit = void 0;
7
+ exports.mkdirIfNeeded = mkdirIfNeeded;
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ // Keep in sync with the server.
25
+ const fileUploadSizeLimit = exports.fileUploadSizeLimit = 50 * 1024 * 1024;
26
+ async function mkdirIfNeeded(platform, filePath) {
27
+ // This will harmlessly throw on windows if the dirname is the root directory.
28
+ await platform.fs().promises.mkdir(platform.path().dirname(filePath), {
29
+ recursive: true
30
+ }).catch(() => {});
31
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.emptyPlatform = void 0;
7
+ var _colors = require("../utils/isomorphic/colors");
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ const noopZone = {
25
+ push: () => noopZone,
26
+ pop: () => noopZone,
27
+ run: func => func(),
28
+ data: () => undefined
29
+ };
30
+ const emptyPlatform = exports.emptyPlatform = {
31
+ name: 'empty',
32
+ boxedStackPrefixes: () => [],
33
+ calculateSha1: async () => {
34
+ throw new Error('Not implemented');
35
+ },
36
+ colors: _colors.webColors,
37
+ createGuid: () => {
38
+ throw new Error('Not implemented');
39
+ },
40
+ defaultMaxListeners: () => 10,
41
+ env: {},
42
+ fs: () => {
43
+ throw new Error('Not implemented');
44
+ },
45
+ inspectCustom: undefined,
46
+ isDebugMode: () => false,
47
+ isJSDebuggerAttached: () => false,
48
+ isLogEnabled(name) {
49
+ return false;
50
+ },
51
+ isUnderTest: () => false,
52
+ log(name, message) {},
53
+ path: () => {
54
+ throw new Error('Function not implemented.');
55
+ },
56
+ pathSeparator: '/',
57
+ showInternalStackFrames: () => false,
58
+ streamFile(path, writable) {
59
+ throw new Error('Streams are not available');
60
+ },
61
+ streamReadable: channel => {
62
+ throw new Error('Streams are not available');
63
+ },
64
+ streamWritable: channel => {
65
+ throw new Error('Streams are not available');
66
+ },
67
+ zones: {
68
+ empty: noopZone,
69
+ current: () => noopZone
70
+ }
71
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TimeoutSettings = exports.DEFAULT_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = void 0;
7
+ /**
8
+ * Copyright 2019 Google Inc. All rights reserved.
9
+ * Modifications copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ // Keep in sync with server.
25
+ const DEFAULT_TIMEOUT = exports.DEFAULT_TIMEOUT = 30000;
26
+ const DEFAULT_LAUNCH_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes
27
+
28
+ class TimeoutSettings {
29
+ constructor(platform, parent) {
30
+ this._parent = void 0;
31
+ this._defaultTimeout = void 0;
32
+ this._defaultNavigationTimeout = void 0;
33
+ this._platform = void 0;
34
+ this._parent = parent;
35
+ this._platform = platform;
36
+ }
37
+ setDefaultTimeout(timeout) {
38
+ this._defaultTimeout = timeout;
39
+ }
40
+ setDefaultNavigationTimeout(timeout) {
41
+ this._defaultNavigationTimeout = timeout;
42
+ }
43
+ defaultNavigationTimeout() {
44
+ return this._defaultNavigationTimeout;
45
+ }
46
+ defaultTimeout() {
47
+ return this._defaultTimeout;
48
+ }
49
+ navigationTimeout(options) {
50
+ if (typeof options.timeout === 'number') return options.timeout;
51
+ if (this._defaultNavigationTimeout !== undefined) return this._defaultNavigationTimeout;
52
+ if (this._platform.isDebugMode()) return 0;
53
+ if (this._defaultTimeout !== undefined) return this._defaultTimeout;
54
+ if (this._parent) return this._parent.navigationTimeout(options);
55
+ return DEFAULT_TIMEOUT;
56
+ }
57
+ timeout(options) {
58
+ if (typeof options.timeout === 'number') return options.timeout;
59
+ if (this._platform.isDebugMode()) return 0;
60
+ if (this._defaultTimeout !== undefined) return this._defaultTimeout;
61
+ if (this._parent) return this._parent.timeout(options);
62
+ return DEFAULT_TIMEOUT;
63
+ }
64
+ }
65
+ exports.TimeoutSettings = TimeoutSettings;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.connectOverWebSocket = connectOverWebSocket;
7
+ var _connection = require("./connection");
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ async function connectOverWebSocket(parentConnection, params) {
25
+ const localUtils = parentConnection.localUtils();
26
+ const transport = localUtils ? new JsonPipeTransport(localUtils) : new WebSocketTransport();
27
+ const connectHeaders = await transport.connect(params);
28
+ const connection = new _connection.Connection(parentConnection._platform, localUtils, parentConnection._instrumentation, connectHeaders);
29
+ connection.markAsRemote();
30
+ connection.on('close', () => transport.close());
31
+ let closeError;
32
+ const onTransportClosed = reason => {
33
+ connection.close(reason || closeError);
34
+ };
35
+ transport.onClose(reason => onTransportClosed(reason));
36
+ connection.onmessage = message => transport.send(message).catch(() => onTransportClosed());
37
+ transport.onMessage(message => {
38
+ try {
39
+ connection.dispatch(message);
40
+ } catch (e) {
41
+ closeError = String(e);
42
+ transport.close().catch(() => {});
43
+ }
44
+ });
45
+ return connection;
46
+ }
47
+ class JsonPipeTransport {
48
+ constructor(owner) {
49
+ this._pipe = void 0;
50
+ this._owner = void 0;
51
+ this._owner = owner;
52
+ }
53
+ async connect(params) {
54
+ const {
55
+ pipe,
56
+ headers: connectHeaders
57
+ } = await this._owner._wrapApiCall(async () => {
58
+ return await this._owner._channel.connect(params);
59
+ }, /* isInternal */true);
60
+ this._pipe = pipe;
61
+ return connectHeaders;
62
+ }
63
+ async send(message) {
64
+ await this._owner._wrapApiCall(async () => {
65
+ await this._pipe.send({
66
+ message
67
+ });
68
+ }, /* isInternal */true);
69
+ }
70
+ onMessage(callback) {
71
+ this._pipe.on('message', ({
72
+ message
73
+ }) => callback(message));
74
+ }
75
+ onClose(callback) {
76
+ this._pipe.on('closed', ({
77
+ reason
78
+ }) => callback(reason));
79
+ }
80
+ async close() {
81
+ await this._owner._wrapApiCall(async () => {
82
+ await this._pipe.close().catch(() => {});
83
+ }, /* isInternal */true);
84
+ }
85
+ }
86
+ class WebSocketTransport {
87
+ constructor() {
88
+ this._ws = void 0;
89
+ }
90
+ async connect(params) {
91
+ this._ws = new window.WebSocket(params.wsEndpoint);
92
+ return [];
93
+ }
94
+ async send(message) {
95
+ this._ws.send(JSON.stringify(message));
96
+ }
97
+ onMessage(callback) {
98
+ this._ws.addEventListener('message', event => callback(JSON.parse(event.data)));
99
+ }
100
+ onClose(callback) {
101
+ this._ws.addEventListener('close', () => callback());
102
+ }
103
+ async close() {
104
+ this._ws.close();
105
+ }
106
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.compressCallLog = compressCallLog;
7
+ exports.findRepeatedSubsequencesForTest = void 0;
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the 'License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ function compressCallLog(log) {
25
+ const lines = [];
26
+ for (const block of findRepeatedSubsequences(log)) {
27
+ for (let i = 0; i < block.sequence.length; i++) {
28
+ const line = block.sequence[i];
29
+ const leadingWhitespace = line.match(/^\s*/);
30
+ const whitespacePrefix = ' ' + (leadingWhitespace === null || leadingWhitespace === void 0 ? void 0 : leadingWhitespace[0]) || '';
31
+ const countPrefix = `${block.count} × `;
32
+ if (block.count > 1 && i === 0) lines.push(whitespacePrefix + countPrefix + line.trim());else if (block.count > 1) lines.push(whitespacePrefix + ' '.repeat(countPrefix.length - 2) + '- ' + line.trim());else lines.push(whitespacePrefix + '- ' + line.trim());
33
+ }
34
+ }
35
+ return lines;
36
+ }
37
+ function findRepeatedSubsequences(s) {
38
+ const n = s.length;
39
+ const result = [];
40
+ let i = 0;
41
+ const arraysEqual = (a1, a2) => {
42
+ if (a1.length !== a2.length) return false;
43
+ for (let j = 0; j < a1.length; j++) {
44
+ if (a1[j] !== a2[j]) return false;
45
+ }
46
+ return true;
47
+ };
48
+ while (i < n) {
49
+ let maxRepeatCount = 1;
50
+ let maxRepeatSubstr = [s[i]]; // Initialize with the element at index i
51
+ let maxRepeatLength = 1;
52
+
53
+ // Try substrings of length from 1 to the remaining length of the array
54
+ for (let p = 1; p <= n - i; p++) {
55
+ const substr = s.slice(i, i + p); // Extract substring as array
56
+ let k = 1;
57
+
58
+ // Count how many times the substring repeats consecutively
59
+ while (i + p * k <= n && arraysEqual(s.slice(i + p * (k - 1), i + p * k), substr)) k += 1;
60
+ k -= 1; // Adjust k since it increments one extra time in the loop
61
+
62
+ // Update the maximal repeating substring if necessary
63
+ if (k > 1 && k * p > maxRepeatCount * maxRepeatLength) {
64
+ maxRepeatCount = k;
65
+ maxRepeatSubstr = substr;
66
+ maxRepeatLength = p;
67
+ }
68
+ }
69
+
70
+ // Record the substring and its count
71
+ result.push({
72
+ sequence: maxRepeatSubstr,
73
+ count: maxRepeatCount
74
+ });
75
+ i += maxRepeatLength * maxRepeatCount; // Move index forward
76
+ }
77
+ return result;
78
+ }
79
+ const findRepeatedSubsequencesForTest = exports.findRepeatedSubsequencesForTest = findRepeatedSubsequences;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HarBackend = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _crypto = require("./utils/crypto");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /**
12
+ * Copyright (c) Microsoft Corporation.
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the 'License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+
27
+ const redirectStatus = [301, 302, 303, 307, 308];
28
+ class HarBackend {
29
+ constructor(harFile, baseDir, zipFile) {
30
+ this.id = void 0;
31
+ this._harFile = void 0;
32
+ this._zipFile = void 0;
33
+ this._baseDir = void 0;
34
+ this.id = (0, _crypto.createGuid)();
35
+ this._harFile = harFile;
36
+ this._baseDir = baseDir;
37
+ this._zipFile = zipFile;
38
+ }
39
+ async lookup(url, method, headers, postData, isNavigationRequest) {
40
+ let entry;
41
+ try {
42
+ entry = await this._harFindResponse(url, method, headers, postData);
43
+ } catch (e) {
44
+ return {
45
+ action: 'error',
46
+ message: 'HAR error: ' + e.message
47
+ };
48
+ }
49
+ if (!entry) return {
50
+ action: 'noentry'
51
+ };
52
+
53
+ // If navigation is being redirected, restart it with the final url to ensure the document's url changes.
54
+ if (entry.request.url !== url && isNavigationRequest) return {
55
+ action: 'redirect',
56
+ redirectURL: entry.request.url
57
+ };
58
+ const response = entry.response;
59
+ try {
60
+ const buffer = await this._loadContent(response.content);
61
+ return {
62
+ action: 'fulfill',
63
+ status: response.status,
64
+ headers: response.headers,
65
+ body: buffer
66
+ };
67
+ } catch (e) {
68
+ return {
69
+ action: 'error',
70
+ message: e.message
71
+ };
72
+ }
73
+ }
74
+ async _loadContent(content) {
75
+ const file = content._file;
76
+ let buffer;
77
+ if (file) {
78
+ if (this._zipFile) buffer = await this._zipFile.read(file);else buffer = await _fs.default.promises.readFile(_path.default.resolve(this._baseDir, file));
79
+ } else {
80
+ buffer = Buffer.from(content.text || '', content.encoding === 'base64' ? 'base64' : 'utf-8');
81
+ }
82
+ return buffer;
83
+ }
84
+ async _harFindResponse(url, method, headers, postData) {
85
+ const harLog = this._harFile.log;
86
+ const visited = new Set();
87
+ while (true) {
88
+ const entries = [];
89
+ for (const candidate of harLog.entries) {
90
+ if (candidate.request.url !== url || candidate.request.method !== method) continue;
91
+ if (method === 'POST' && postData && candidate.request.postData) {
92
+ const buffer = await this._loadContent(candidate.request.postData);
93
+ if (!buffer.equals(postData)) {
94
+ const boundary = multipartBoundary(headers);
95
+ if (!boundary) continue;
96
+ const candidataBoundary = multipartBoundary(candidate.request.headers);
97
+ if (!candidataBoundary) continue;
98
+ // Try to match multipart/form-data ignroing boundary as it changes between requests.
99
+ if (postData.toString().replaceAll(boundary, '') !== buffer.toString().replaceAll(candidataBoundary, '')) continue;
100
+ }
101
+ }
102
+ entries.push(candidate);
103
+ }
104
+ if (!entries.length) return;
105
+ let entry = entries[0];
106
+
107
+ // Disambiguate using headers - then one with most matching headers wins.
108
+ if (entries.length > 1) {
109
+ const list = [];
110
+ for (const candidate of entries) {
111
+ const matchingHeaders = countMatchingHeaders(candidate.request.headers, headers);
112
+ list.push({
113
+ candidate,
114
+ matchingHeaders
115
+ });
116
+ }
117
+ list.sort((a, b) => b.matchingHeaders - a.matchingHeaders);
118
+ entry = list[0].candidate;
119
+ }
120
+ if (visited.has(entry)) throw new Error(`Found redirect cycle for ${url}`);
121
+ visited.add(entry);
122
+
123
+ // Follow redirects.
124
+ const locationHeader = entry.response.headers.find(h => h.name.toLowerCase() === 'location');
125
+ if (redirectStatus.includes(entry.response.status) && locationHeader) {
126
+ const locationURL = new URL(locationHeader.value, url);
127
+ url = locationURL.toString();
128
+ if ((entry.response.status === 301 || entry.response.status === 302) && method === 'POST' || entry.response.status === 303 && !['GET', 'HEAD'].includes(method)) {
129
+ // HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
130
+ method = 'GET';
131
+ }
132
+ continue;
133
+ }
134
+ return entry;
135
+ }
136
+ }
137
+ dispose() {
138
+ var _this$_zipFile;
139
+ (_this$_zipFile = this._zipFile) === null || _this$_zipFile === void 0 || _this$_zipFile.close();
140
+ }
141
+ }
142
+ exports.HarBackend = HarBackend;
143
+ function countMatchingHeaders(harHeaders, headers) {
144
+ const set = new Set(headers.map(h => h.name.toLowerCase() + ':' + h.value));
145
+ let matches = 0;
146
+ for (const h of harHeaders) {
147
+ if (set.has(h.name.toLowerCase() + ':' + h.value)) ++matches;
148
+ }
149
+ return matches;
150
+ }
151
+ function multipartBoundary(headers) {
152
+ const contentType = headers.find(h => h.name.toLowerCase() === 'content-type');
153
+ if (!(contentType !== null && contentType !== void 0 && contentType.value.includes('multipart/form-data'))) return undefined;
154
+ const boundary = contentType.value.match(/boundary=(\S+)/);
155
+ if (boundary) return boundary[1];
156
+ return undefined;
157
+ }