@specific.dev/spectest 0.39.0 → 0.41.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 (100) hide show
  1. package/dist/components/supabase.d.ts +87 -27
  2. package/dist/components/supabase.js +352 -69
  3. package/dist/daemon.d.ts +38 -0
  4. package/dist/daemon.js +388 -941
  5. package/dist/harness/build-context.d.ts +82 -0
  6. package/dist/harness/build-context.js +113 -0
  7. package/dist/harness/buildkit-progress.d.ts +37 -0
  8. package/dist/harness/buildkit-progress.js +66 -0
  9. package/dist/harness/container-run.d.ts +89 -0
  10. package/dist/harness/container-run.js +118 -0
  11. package/dist/harness/file-mounts.d.ts +91 -0
  12. package/dist/harness/file-mounts.js +119 -0
  13. package/dist/harness/hostmatch.d.ts +65 -0
  14. package/dist/harness/hostmatch.js +108 -0
  15. package/dist/harness/http-proxy.d.ts +62 -0
  16. package/dist/harness/http-proxy.js +104 -0
  17. package/dist/harness/ingress-table.d.ts +148 -0
  18. package/dist/harness/ingress-table.js +129 -0
  19. package/dist/harness/log-delta.d.ts +54 -0
  20. package/dist/harness/log-delta.js +83 -0
  21. package/dist/harness/main.d.ts +47 -0
  22. package/dist/harness/main.js +164 -0
  23. package/dist/harness/methods.d.ts +54 -0
  24. package/dist/harness/methods.js +65 -0
  25. package/dist/harness/names-registry.d.ts +63 -0
  26. package/dist/harness/names-registry.js +90 -0
  27. package/dist/harness/protocol.d.ts +88 -0
  28. package/dist/harness/protocol.js +96 -0
  29. package/dist/harness/ready-poll.d.ts +47 -0
  30. package/dist/harness/ready-poll.js +67 -0
  31. package/dist/harness/service-graph.d.ts +29 -0
  32. package/dist/harness/service-graph.js +92 -0
  33. package/dist/harness/volume-paths.d.ts +70 -0
  34. package/dist/harness/volume-paths.js +81 -0
  35. package/dist/index.d.ts +3 -3
  36. package/dist/ingress.d.ts +1 -1
  37. package/dist/resolver.js +5 -8
  38. package/dist/vendor/rrweb-plugin-console-record.umd.js +521 -0
  39. package/dist/vendor/rrweb-record.min.js +5061 -0
  40. package/package.json +7 -1
  41. package/src/aws-sigv4.ts +218 -0
  42. package/src/browser.ts +2040 -0
  43. package/src/components/aws.ts +554 -0
  44. package/src/components/email.ts +398 -0
  45. package/src/components/expo.ts +167 -0
  46. package/src/components/index.ts +81 -0
  47. package/src/components/k3s.ts +2061 -0
  48. package/src/components/postgres.ts +132 -0
  49. package/src/components/replayFake.ts +1015 -0
  50. package/src/components/s3.ts +132 -0
  51. package/src/components/supabase.ts +1699 -0
  52. package/src/daemon.ts +5489 -0
  53. package/src/harness/build-context.test.ts +0 -0
  54. package/src/harness/build-context.ts +146 -0
  55. package/src/harness/buildkit-progress.test.ts +98 -0
  56. package/src/harness/buildkit-progress.ts +74 -0
  57. package/src/harness/container-run.test.ts +209 -0
  58. package/src/harness/container-run.ts +158 -0
  59. package/src/harness/file-mounts.test.ts +185 -0
  60. package/src/harness/file-mounts.ts +145 -0
  61. package/src/harness/hostmatch.test.ts +148 -0
  62. package/src/harness/hostmatch.ts +109 -0
  63. package/src/harness/http-proxy.test.ts +156 -0
  64. package/src/harness/http-proxy.ts +119 -0
  65. package/src/harness/ingress-rebind.test.ts +125 -0
  66. package/src/harness/ingress-table.test.ts +172 -0
  67. package/src/harness/ingress-table.ts +186 -0
  68. package/src/harness/log-delta.test.ts +125 -0
  69. package/src/harness/log-delta.ts +100 -0
  70. package/src/harness/main.test.ts +211 -0
  71. package/src/harness/main.ts +196 -0
  72. package/src/harness/methods.test.ts +63 -0
  73. package/src/harness/methods.ts +92 -0
  74. package/src/harness/names-registry.test.ts +137 -0
  75. package/src/harness/names-registry.ts +108 -0
  76. package/src/harness/protocol.test.ts +148 -0
  77. package/src/harness/protocol.ts +163 -0
  78. package/src/harness/ready-poll.test.ts +172 -0
  79. package/src/harness/ready-poll.ts +93 -0
  80. package/src/harness/service-graph.test.ts +97 -0
  81. package/src/harness/service-graph.ts +97 -0
  82. package/src/harness/volume-paths.test.ts +102 -0
  83. package/src/harness/volume-paths.ts +112 -0
  84. package/src/ids.ts +89 -0
  85. package/src/index.ts +2725 -0
  86. package/src/ingress.ts +305 -0
  87. package/src/inspect.ts +739 -0
  88. package/src/locator.ts +716 -0
  89. package/src/mobile.ts +133 -0
  90. package/src/record-secrets.ts +41 -0
  91. package/src/recorder.ts +846 -0
  92. package/src/redis.ts +202 -0
  93. package/src/replay-bundle.ts +108 -0
  94. package/src/resolver.ts +348 -0
  95. package/src/s3.ts +333 -0
  96. package/src/sql.ts +243 -0
  97. package/src/terminal.ts +740 -0
  98. package/src/url-match.ts +67 -0
  99. package/src/vendor/rrweb-plugin-console-record.umd.js +521 -0
  100. package/src/vendor/rrweb-record.min.js +5061 -0
package/dist/index.d.ts CHANGED
@@ -84,7 +84,7 @@ export interface ServiceConfig {
84
84
  hostnames?: readonly string[];
85
85
  /**
86
86
  * Expose this service over HTTPS via a TLS-terminating reverse proxy
87
- * hosted in the spectest-daemon. Each entry maps a fully-qualified
87
+ * hosted in the harness. Each entry maps a fully-qualified
88
88
  * hostname to the HTTP port the service listens on inside its
89
89
  * container; the daemon binds the hostname on `:443` (SNI-multiplexed,
90
90
  * with a leaf cert signed by the in-VM root CA) and on `:80`, and
@@ -1038,7 +1038,7 @@ export interface TestSuite<S extends ServicesMap = ServicesMap, F extends FakesM
1038
1038
  tests: TestCase<unknown, S, F>[];
1039
1039
  }
1040
1040
  /**
1041
- * A fake server hosted in the spectest-daemon. Use this to stand in for
1041
+ * A fake server hosted in the harness. Use this to stand in for
1042
1042
  * external HTTP APIs (auth providers, payment gateways, …) that you can't
1043
1043
  * call directly from the hermetic test VM.
1044
1044
  *
@@ -1176,7 +1176,7 @@ export interface TypedTest<S extends ServicesMap, F extends FakesMap = FakesMap>
1176
1176
  export interface Project<S extends ServicesMap = ServicesMap, F extends FakesMap = FakesMap> {
1177
1177
  environment: EnvironmentConfig<S>;
1178
1178
  /**
1179
- * Fake servers hosted in the spectest-daemon (see {@link defineFake}).
1179
+ * Fake servers hosted in the harness (see {@link defineFake}).
1180
1180
  * Keyed by stable fake name; the key becomes the slot in
1181
1181
  * `ctx.fakes.<key>` from test code. Populated from the `fakes` declared
1182
1182
  * in `defineEnvironment(...)`.
package/dist/ingress.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Project, ServiceConfig } from "./index.js";
2
- /** Where a DNS name points. `ingress` = the spectest-daemon listener on the
2
+ /** Where a DNS name points. `ingress` = the harness's listener on the
3
3
  * bridge gateway (fakes, TLS-terminated proxies); `service` = a container's
4
4
  * live IP on spectest-net (a plain peer alias, no daemon hop). */
5
5
  export type DnsTarget = {
package/dist/resolver.js CHANGED
@@ -27,6 +27,7 @@
27
27
  import { createSocket } from "node:dgram";
28
28
  import { request as httpRequest } from "node:http";
29
29
  import { readFile, stat } from "node:fs/promises";
30
+ import { lookup } from "./harness/names-registry.js";
30
31
  import * as dnsPacket from "dns-packet";
31
32
  const NETWORK_NAME = process.env.SPECTEST_NETWORK ?? "spectest-net";
32
33
  const DOCKER_SOCKET = process.env.DOCKER_SOCKET ?? "/var/run/docker.sock";
@@ -37,7 +38,7 @@ const UPSTREAM_PORT = Number(process.env.SPECTEST_UPSTREAM_PORT ?? "53");
37
38
  const LISTEN_ADDR = process.env.SPECTEST_RESOLVER_ADDR ?? "127.0.0.53";
38
39
  const LISTEN_PORT = Number(process.env.SPECTEST_RESOLVER_PORT ?? "53");
39
40
  const TTL_SECONDS = Number(process.env.SPECTEST_RESOLVER_TTL ?? "5");
40
- /** Path the spectest-daemon writes when it brings fakes up. */
41
+ /** Path the harness writes when it brings fakes up. */
41
42
  const FAKES_REGISTRY_PATH = process.env.SPECTEST_FAKES_REGISTRY ?? "/run/spectest-fakes.json";
42
43
  function dockerGet(path) {
43
44
  return new Promise((resolve) => {
@@ -129,13 +130,9 @@ async function lookupFake(name) {
129
130
  * longest (most specific) matching suffix wins. */
130
131
  async function lookupWildcard(name) {
131
132
  await refreshRegistry();
132
- let best = null;
133
- for (const w of registryCache.wildcards) {
134
- if (name.endsWith(w.suffix) && (!best || w.suffix.length > best.suffix.length)) {
135
- best = w;
136
- }
137
- }
138
- return best?.ip ?? null;
133
+ // Same module the harness writes with, so the two halves of this file
134
+ // format cannot drift apart.
135
+ return lookup({ hosts: {}, wildcards: registryCache.wildcards }, name);
139
136
  }
140
137
  async function forwardUpstream(query) {
141
138
  return new Promise((resolve) => {
@@ -0,0 +1,521 @@
1
+ (function (g, f) {
2
+ if ("object" == typeof exports && "object" == typeof module) {
3
+ module.exports = f();
4
+ } else if ("function" == typeof define && define.amd) {
5
+ define("rrwebPluginConsoleRecord", [], f);
6
+ } else if ("object" == typeof exports) {
7
+ exports["rrwebPluginConsoleRecord"] = f();
8
+ } else {
9
+ g["rrwebPluginConsoleRecord"] = f();
10
+ }
11
+ }(this, () => {
12
+ var exports = {};
13
+ var module = { exports };
14
+ "use strict";
15
+ var __defProp = Object.defineProperty;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
19
+ if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) ;
20
+ function patch(source, name, replacement) {
21
+ try {
22
+ if (!(name in source)) {
23
+ return () => {
24
+ };
25
+ }
26
+ const original = source[name];
27
+ const wrapped = replacement(original);
28
+ if (typeof wrapped === "function") {
29
+ wrapped.prototype = wrapped.prototype || {};
30
+ Object.defineProperties(wrapped, {
31
+ __rrweb_original__: {
32
+ enumerable: false,
33
+ value: original
34
+ }
35
+ });
36
+ }
37
+ source[name] = wrapped;
38
+ return () => {
39
+ source[name] = original;
40
+ };
41
+ } catch (e) {
42
+ return () => {
43
+ };
44
+ }
45
+ }
46
+ class StackFrame {
47
+ constructor(obj) {
48
+ __publicField(this, "fileName");
49
+ __publicField(this, "functionName");
50
+ __publicField(this, "lineNumber");
51
+ __publicField(this, "columnNumber");
52
+ this.fileName = obj.fileName || "";
53
+ this.functionName = obj.functionName || "";
54
+ this.lineNumber = obj.lineNumber;
55
+ this.columnNumber = obj.columnNumber;
56
+ }
57
+ toString() {
58
+ const lineNumber = this.lineNumber || "";
59
+ const columnNumber = this.columnNumber || "";
60
+ if (this.functionName)
61
+ return `${this.functionName} (${this.fileName}:${lineNumber}:${columnNumber})`;
62
+ return `${this.fileName}:${lineNumber}:${columnNumber}`;
63
+ }
64
+ }
65
+ const FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
66
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
67
+ const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
68
+ const ErrorStackParser = {
69
+ /**
70
+ * Given an Error object, extract the most information from it.
71
+ */
72
+ parse: function(error) {
73
+ if (!error) {
74
+ return [];
75
+ }
76
+ if (
77
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
78
+ // @ts-ignore
79
+ typeof error.stacktrace !== "undefined" || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
80
+ // @ts-ignore
81
+ typeof error["opera#sourceloc"] !== "undefined"
82
+ ) {
83
+ return this.parseOpera(
84
+ error
85
+ );
86
+ } else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
87
+ return this.parseV8OrIE(error);
88
+ } else if (error.stack) {
89
+ return this.parseFFOrSafari(error);
90
+ } else {
91
+ console.warn(
92
+ "[console-record-plugin]: Failed to parse error object:",
93
+ error
94
+ );
95
+ return [];
96
+ }
97
+ },
98
+ // Separate line and column numbers from a string of the form: (URI:Line:Column)
99
+ extractLocation: function(urlLike) {
100
+ if (urlLike.indexOf(":") === -1) {
101
+ return [urlLike];
102
+ }
103
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
104
+ const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
105
+ if (!parts) throw new Error(`Cannot parse given url: ${urlLike}`);
106
+ return [parts[1], parts[2] || void 0, parts[3] || void 0];
107
+ },
108
+ parseV8OrIE: function(error) {
109
+ const filtered = error.stack.split("\n").filter(function(line) {
110
+ return !!line.match(CHROME_IE_STACK_REGEXP);
111
+ }, this);
112
+ return filtered.map(function(line) {
113
+ if (line.indexOf("(eval ") > -1) {
114
+ line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(\),.*$)/g, "");
115
+ }
116
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(");
117
+ const location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
118
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
119
+ const tokens = sanitizedLine.split(/\s+/).slice(1);
120
+ const locationParts = this.extractLocation(
121
+ location ? location[1] : tokens.pop()
122
+ );
123
+ const functionName = tokens.join(" ") || void 0;
124
+ const fileName = ["eval", "<anonymous>"].indexOf(locationParts[0]) > -1 ? void 0 : locationParts[0];
125
+ return new StackFrame({
126
+ functionName,
127
+ fileName,
128
+ lineNumber: locationParts[1],
129
+ columnNumber: locationParts[2]
130
+ });
131
+ }, this);
132
+ },
133
+ parseFFOrSafari: function(error) {
134
+ const filtered = error.stack.split("\n").filter(function(line) {
135
+ return !line.match(SAFARI_NATIVE_CODE_REGEXP);
136
+ }, this);
137
+ return filtered.map(function(line) {
138
+ if (line.indexOf(" > eval") > -1) {
139
+ line = line.replace(
140
+ / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
141
+ ":$1"
142
+ );
143
+ }
144
+ if (line.indexOf("@") === -1 && line.indexOf(":") === -1) {
145
+ return new StackFrame({
146
+ functionName: line
147
+ });
148
+ } else {
149
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
150
+ const matches = line.match(functionNameRegex);
151
+ const functionName = matches && matches[1] ? matches[1] : void 0;
152
+ const locationParts = this.extractLocation(
153
+ line.replace(functionNameRegex, "")
154
+ );
155
+ return new StackFrame({
156
+ functionName,
157
+ fileName: locationParts[0],
158
+ lineNumber: locationParts[1],
159
+ columnNumber: locationParts[2]
160
+ });
161
+ }
162
+ }, this);
163
+ },
164
+ parseOpera: function(e) {
165
+ if (!e.stacktrace || e.message.indexOf("\n") > -1 && e.message.split("\n").length > e.stacktrace.split("\n").length) {
166
+ return this.parseOpera9(e);
167
+ } else if (!e.stack) {
168
+ return this.parseOpera10(e);
169
+ } else {
170
+ return this.parseOpera11(e);
171
+ }
172
+ },
173
+ parseOpera9: function(e) {
174
+ const lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
175
+ const lines = e.message.split("\n");
176
+ const result = [];
177
+ for (let i = 2, len = lines.length; i < len; i += 2) {
178
+ const match = lineRE.exec(lines[i]);
179
+ if (match) {
180
+ result.push(
181
+ new StackFrame({
182
+ fileName: match[2],
183
+ lineNumber: parseFloat(match[1])
184
+ })
185
+ );
186
+ }
187
+ }
188
+ return result;
189
+ },
190
+ parseOpera10: function(e) {
191
+ const lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
192
+ const lines = e.stacktrace.split("\n");
193
+ const result = [];
194
+ for (let i = 0, len = lines.length; i < len; i += 2) {
195
+ const match = lineRE.exec(lines[i]);
196
+ if (match) {
197
+ result.push(
198
+ new StackFrame({
199
+ functionName: match[3] || void 0,
200
+ fileName: match[2],
201
+ lineNumber: parseFloat(match[1])
202
+ })
203
+ );
204
+ }
205
+ }
206
+ return result;
207
+ },
208
+ // Opera 10.65+ Error.stack very similar to FF/Safari
209
+ parseOpera11: function(error) {
210
+ const filtered = error.stack.split("\n").filter(function(line) {
211
+ return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/);
212
+ }, this);
213
+ return filtered.map(function(line) {
214
+ const tokens = line.split("@");
215
+ const locationParts = this.extractLocation(tokens.pop());
216
+ const functionCall = tokens.shift() || "";
217
+ const functionName = functionCall.replace(/<anonymous function(: (\w+))?>/, "$2").replace(/\([^)]*\)/g, "") || void 0;
218
+ return new StackFrame({
219
+ functionName,
220
+ fileName: locationParts[0],
221
+ lineNumber: locationParts[1],
222
+ columnNumber: locationParts[2]
223
+ });
224
+ }, this);
225
+ }
226
+ };
227
+ function pathToSelector(node) {
228
+ if (!node || !node.outerHTML) {
229
+ return "";
230
+ }
231
+ let path = "";
232
+ while (node.parentElement) {
233
+ let name = node.localName;
234
+ if (!name) {
235
+ break;
236
+ }
237
+ name = name.toLowerCase();
238
+ const parent = node.parentElement;
239
+ const domSiblings = [];
240
+ if (parent.children && parent.children.length > 0) {
241
+ for (let i = 0; i < parent.children.length; i++) {
242
+ const sibling = parent.children[i];
243
+ if (sibling.localName && sibling.localName.toLowerCase) {
244
+ if (sibling.localName.toLowerCase() === name) {
245
+ domSiblings.push(sibling);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ if (domSiblings.length > 1) {
251
+ name += `:eq(${domSiblings.indexOf(node)})`;
252
+ }
253
+ path = name + (path ? ">" + path : "");
254
+ node = parent;
255
+ }
256
+ return path;
257
+ }
258
+ function isObject(obj) {
259
+ return Object.prototype.toString.call(obj) === "[object Object]";
260
+ }
261
+ function isObjTooDeep(obj, limit) {
262
+ if (limit === 0) {
263
+ return true;
264
+ }
265
+ const keys = Object.keys(obj);
266
+ for (const key of keys) {
267
+ if (isObject(obj[key]) && isObjTooDeep(obj[key], limit - 1)) {
268
+ return true;
269
+ }
270
+ }
271
+ return false;
272
+ }
273
+ function stringify(obj, stringifyOptions) {
274
+ const options = {
275
+ numOfKeysLimit: 50,
276
+ depthOfLimit: 4
277
+ };
278
+ Object.assign(options, stringifyOptions);
279
+ const stack = [];
280
+ const keys = [];
281
+ return JSON.stringify(
282
+ obj,
283
+ function(key, value) {
284
+ if (stack.length > 0) {
285
+ const thisPos = stack.indexOf(this);
286
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
287
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
288
+ if (~stack.indexOf(value)) {
289
+ if (stack[0] === value) {
290
+ value = "[Circular ~]";
291
+ } else {
292
+ value = "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
293
+ }
294
+ }
295
+ } else {
296
+ stack.push(value);
297
+ }
298
+ if (value === null) return value;
299
+ if (value === void 0) return "undefined";
300
+ if (shouldIgnore(value)) {
301
+ return toString(value);
302
+ }
303
+ if (typeof value === "bigint") {
304
+ return value.toString() + "n";
305
+ }
306
+ if (value instanceof Event) {
307
+ const eventResult = {};
308
+ for (const eventKey in value) {
309
+ const eventValue = value[eventKey];
310
+ if (Array.isArray(eventValue)) {
311
+ eventResult[eventKey] = pathToSelector(
312
+ eventValue.length ? eventValue[0] : null
313
+ );
314
+ } else {
315
+ eventResult[eventKey] = eventValue;
316
+ }
317
+ }
318
+ return eventResult;
319
+ } else if (value instanceof Node) {
320
+ if (value instanceof HTMLElement) {
321
+ return value ? value.outerHTML : "";
322
+ }
323
+ return value.nodeName;
324
+ } else if (value instanceof Error) {
325
+ return value.stack ? value.stack + "\nEnd of stack for Error object" : value.name + ": " + value.message;
326
+ }
327
+ return value;
328
+ }
329
+ );
330
+ function shouldIgnore(_obj) {
331
+ if (isObject(_obj) && Object.keys(_obj).length > options.numOfKeysLimit) {
332
+ return true;
333
+ }
334
+ if (typeof _obj === "function") {
335
+ return true;
336
+ }
337
+ if (isObject(_obj) && isObjTooDeep(_obj, options.depthOfLimit)) {
338
+ return true;
339
+ }
340
+ return false;
341
+ }
342
+ function toString(_obj) {
343
+ let str = _obj.toString();
344
+ if (options.stringLengthLimit && str.length > options.stringLengthLimit) {
345
+ str = `${str.slice(0, options.stringLengthLimit)}...`;
346
+ }
347
+ return str;
348
+ }
349
+ }
350
+ const defaultLogOptions = {
351
+ level: [
352
+ "assert",
353
+ "clear",
354
+ "count",
355
+ "countReset",
356
+ "debug",
357
+ "dir",
358
+ "dirxml",
359
+ "error",
360
+ "group",
361
+ "groupCollapsed",
362
+ "groupEnd",
363
+ "info",
364
+ "log",
365
+ "table",
366
+ "time",
367
+ "timeEnd",
368
+ "timeLog",
369
+ "trace",
370
+ "warn"
371
+ ],
372
+ lengthThreshold: 1e3,
373
+ logger: "console"
374
+ };
375
+ function initLogObserver(cb, win, options) {
376
+ const logOptions = options ? Object.assign({}, defaultLogOptions, options) : defaultLogOptions;
377
+ const loggerType = logOptions.logger;
378
+ if (!loggerType) {
379
+ return () => {
380
+ };
381
+ }
382
+ let logger;
383
+ if (typeof loggerType === "string") {
384
+ logger = win[loggerType];
385
+ } else {
386
+ logger = loggerType;
387
+ }
388
+ let logCount = 0;
389
+ let inStack = false;
390
+ const cancelHandlers = [];
391
+ if (logOptions.level.includes("error")) {
392
+ const errorHandler = (event) => {
393
+ const message = event.message, error = event.error;
394
+ const trace = ErrorStackParser.parse(error).map(
395
+ (stackFrame) => stackFrame.toString()
396
+ );
397
+ const payload = [stringify(message, logOptions.stringifyOptions)];
398
+ cb({
399
+ level: "error",
400
+ trace,
401
+ payload
402
+ });
403
+ };
404
+ win.addEventListener("error", errorHandler);
405
+ cancelHandlers.push(() => {
406
+ win.removeEventListener("error", errorHandler);
407
+ });
408
+ const unhandledrejectionHandler = (event) => {
409
+ let error;
410
+ let payload;
411
+ if (event.reason instanceof Error) {
412
+ error = event.reason;
413
+ payload = [
414
+ stringify(
415
+ `Uncaught (in promise) ${error.name}: ${error.message}`,
416
+ logOptions.stringifyOptions
417
+ )
418
+ ];
419
+ } else {
420
+ error = new Error();
421
+ payload = [
422
+ stringify("Uncaught (in promise)", logOptions.stringifyOptions),
423
+ stringify(event.reason, logOptions.stringifyOptions)
424
+ ];
425
+ }
426
+ const trace = ErrorStackParser.parse(error).map(
427
+ (stackFrame) => stackFrame.toString()
428
+ );
429
+ cb({
430
+ level: "error",
431
+ trace,
432
+ payload
433
+ });
434
+ };
435
+ win.addEventListener("unhandledrejection", unhandledrejectionHandler);
436
+ cancelHandlers.push(() => {
437
+ win.removeEventListener("unhandledrejection", unhandledrejectionHandler);
438
+ });
439
+ }
440
+ for (const levelType of logOptions.level) {
441
+ cancelHandlers.push(replace(logger, levelType));
442
+ }
443
+ return () => {
444
+ cancelHandlers.forEach((h) => h());
445
+ };
446
+ function replace(_logger, level) {
447
+ if (!_logger[level]) {
448
+ return () => {
449
+ };
450
+ }
451
+ return patch(
452
+ _logger,
453
+ level,
454
+ (original) => {
455
+ return (...args) => {
456
+ original.apply(this, args);
457
+ if (level === "assert" && !!args[0]) {
458
+ return;
459
+ }
460
+ if (inStack) {
461
+ return;
462
+ }
463
+ inStack = true;
464
+ try {
465
+ const trace = ErrorStackParser.parse(new Error()).map((stackFrame) => stackFrame.toString()).splice(1);
466
+ const argsForPayload = level === "assert" ? args.slice(1) : args;
467
+ const payload = argsForPayload.map(
468
+ (s) => stringify(s, logOptions.stringifyOptions)
469
+ );
470
+ logCount++;
471
+ if (logCount < logOptions.lengthThreshold) {
472
+ cb({
473
+ level,
474
+ trace,
475
+ payload
476
+ });
477
+ } else if (logCount === logOptions.lengthThreshold) {
478
+ cb({
479
+ level: "warn",
480
+ trace: [],
481
+ payload: [
482
+ stringify("The number of log records reached the threshold.")
483
+ ]
484
+ });
485
+ }
486
+ } catch (error) {
487
+ original("rrweb logger error:", error, ...args);
488
+ } finally {
489
+ inStack = false;
490
+ }
491
+ };
492
+ }
493
+ );
494
+ }
495
+ }
496
+ const PLUGIN_NAME = "rrweb/console@1";
497
+ const getRecordConsolePlugin = (options) => ({
498
+ name: PLUGIN_NAME,
499
+ observer: initLogObserver,
500
+ options
501
+ });
502
+ exports.PLUGIN_NAME = PLUGIN_NAME;
503
+ exports.getRecordConsolePlugin = getRecordConsolePlugin;
504
+ if (typeof module.exports == "object" && typeof exports == "object") {
505
+ var __cp = (to, from, except, desc) => {
506
+ if ((from && typeof from === "object") || typeof from === "function") {
507
+ for (let key of Object.getOwnPropertyNames(from)) {
508
+ if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
509
+ Object.defineProperty(to, key, {
510
+ get: () => from[key],
511
+ enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
512
+ });
513
+ }
514
+ }
515
+ return to;
516
+ };
517
+ module.exports = __cp(module.exports, exports);
518
+ }
519
+ return module.exports;
520
+ }))
521
+ //# sourceMappingURL=rrweb-plugin-console-record.umd.cjs.map