@posthog/core 1.1.0 → 1.2.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 (126) hide show
  1. package/dist/error-tracking/chunk-ids.js +1 -1
  2. package/dist/error-tracking/chunk-ids.mjs +1 -1
  3. package/dist/error-tracking/coercers/error-event-coercer.js +4 -5
  4. package/dist/error-tracking/coercers/error-event-coercer.mjs +4 -5
  5. package/dist/error-tracking/coercers/event-coercer.js +1 -2
  6. package/dist/error-tracking/coercers/event-coercer.mjs +1 -2
  7. package/dist/error-tracking/coercers/object-coercer.js +1 -2
  8. package/dist/error-tracking/coercers/object-coercer.mjs +1 -2
  9. package/dist/error-tracking/coercers/primitive-coercer.js +1 -2
  10. package/dist/error-tracking/coercers/primitive-coercer.mjs +1 -2
  11. package/dist/error-tracking/coercers/promise-rejection-event.js +4 -5
  12. package/dist/error-tracking/coercers/promise-rejection-event.mjs +4 -5
  13. package/dist/error-tracking/coercers/string-coercer.js +3 -4
  14. package/dist/error-tracking/coercers/string-coercer.mjs +3 -4
  15. package/dist/error-tracking/coercers/utils.js +2 -4
  16. package/dist/error-tracking/coercers/utils.mjs +2 -4
  17. package/dist/error-tracking/error-properties-builder.js +11 -15
  18. package/dist/error-tracking/error-properties-builder.mjs +11 -15
  19. package/dist/error-tracking/parsers/index.js +2 -4
  20. package/dist/error-tracking/parsers/index.mjs +2 -4
  21. package/dist/error-tracking/parsers/node.js +3 -5
  22. package/dist/error-tracking/parsers/node.mjs +3 -5
  23. package/dist/error-tracking/utils.js +4 -4
  24. package/dist/error-tracking/utils.mjs +4 -4
  25. package/dist/eventemitter.js +4 -4
  26. package/dist/eventemitter.mjs +4 -4
  27. package/dist/featureFlagUtils.js +20 -45
  28. package/dist/featureFlagUtils.mjs +20 -45
  29. package/dist/gzip.js +1 -2
  30. package/dist/gzip.mjs +1 -2
  31. package/dist/index.d.ts +4 -366
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +54 -1225
  34. package/dist/index.mjs +5 -1190
  35. package/dist/posthog-core-stateless.d.ts +204 -0
  36. package/dist/posthog-core-stateless.d.ts.map +1 -0
  37. package/dist/posthog-core-stateless.js +675 -0
  38. package/dist/posthog-core-stateless.mjs +632 -0
  39. package/dist/posthog-core.d.ts +171 -0
  40. package/dist/posthog-core.d.ts.map +1 -0
  41. package/dist/posthog-core.js +554 -0
  42. package/dist/posthog-core.mjs +520 -0
  43. package/dist/testing/PostHogCoreTestClient.d.ts +2 -1
  44. package/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
  45. package/dist/testing/PostHogCoreTestClient.js +9 -11
  46. package/dist/testing/PostHogCoreTestClient.mjs +8 -10
  47. package/dist/testing/test-utils.js +1 -1
  48. package/dist/testing/test-utils.mjs +1 -1
  49. package/dist/utils/bucketed-rate-limiter.js +8 -12
  50. package/dist/utils/bucketed-rate-limiter.mjs +8 -12
  51. package/dist/utils/index.js +3 -3
  52. package/dist/utils/index.mjs +3 -3
  53. package/dist/utils/type-utils.js +1 -1
  54. package/dist/utils/type-utils.mjs +1 -1
  55. package/dist/vendor/uuidv7.js +12 -16
  56. package/dist/vendor/uuidv7.mjs +12 -16
  57. package/package.json +3 -2
  58. package/src/__tests__/featureFlagUtils.spec.ts +427 -0
  59. package/src/__tests__/gzip.spec.ts +69 -0
  60. package/src/__tests__/posthog.ai.spec.ts +110 -0
  61. package/src/__tests__/posthog.capture.spec.ts +91 -0
  62. package/src/__tests__/posthog.core.spec.ts +135 -0
  63. package/src/__tests__/posthog.debug.spec.ts +36 -0
  64. package/src/__tests__/posthog.enqueue.spec.ts +93 -0
  65. package/src/__tests__/posthog.featureflags.spec.ts +1106 -0
  66. package/src/__tests__/posthog.featureflags.v1.spec.ts +922 -0
  67. package/src/__tests__/posthog.flush.spec.ts +237 -0
  68. package/src/__tests__/posthog.gdpr.spec.ts +50 -0
  69. package/src/__tests__/posthog.groups.spec.ts +96 -0
  70. package/src/__tests__/posthog.identify.spec.ts +194 -0
  71. package/src/__tests__/posthog.init.spec.ts +110 -0
  72. package/src/__tests__/posthog.listeners.spec.ts +51 -0
  73. package/src/__tests__/posthog.register.spec.ts +47 -0
  74. package/src/__tests__/posthog.reset.spec.ts +76 -0
  75. package/src/__tests__/posthog.sessions.spec.ts +63 -0
  76. package/src/__tests__/posthog.setProperties.spec.ts +102 -0
  77. package/src/__tests__/posthog.shutdown.spec.ts +88 -0
  78. package/src/__tests__/utils.spec.ts +36 -0
  79. package/src/error-tracking/chunk-ids.ts +58 -0
  80. package/src/error-tracking/coercers/dom-exception-coercer.ts +38 -0
  81. package/src/error-tracking/coercers/error-coercer.ts +36 -0
  82. package/src/error-tracking/coercers/error-event-coercer.ts +24 -0
  83. package/src/error-tracking/coercers/event-coercer.ts +19 -0
  84. package/src/error-tracking/coercers/index.ts +8 -0
  85. package/src/error-tracking/coercers/object-coercer.ts +76 -0
  86. package/src/error-tracking/coercers/primitive-coercer.ts +19 -0
  87. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +77 -0
  88. package/src/error-tracking/coercers/promise-rejection-event.ts +53 -0
  89. package/src/error-tracking/coercers/string-coercer.spec.ts +26 -0
  90. package/src/error-tracking/coercers/string-coercer.ts +31 -0
  91. package/src/error-tracking/coercers/utils.ts +33 -0
  92. package/src/error-tracking/error-properties-builder.coerce.spec.ts +202 -0
  93. package/src/error-tracking/error-properties-builder.parse.spec.ts +30 -0
  94. package/src/error-tracking/error-properties-builder.ts +169 -0
  95. package/src/error-tracking/index.ts +5 -0
  96. package/src/error-tracking/parsers/base.ts +29 -0
  97. package/src/error-tracking/parsers/chrome.ts +53 -0
  98. package/src/error-tracking/parsers/gecko.ts +38 -0
  99. package/src/error-tracking/parsers/index.ts +104 -0
  100. package/src/error-tracking/parsers/node.ts +111 -0
  101. package/src/error-tracking/parsers/opera.ts +18 -0
  102. package/src/error-tracking/parsers/react-native.ts +0 -0
  103. package/src/error-tracking/parsers/safari.ts +33 -0
  104. package/src/error-tracking/parsers/winjs.ts +12 -0
  105. package/src/error-tracking/types.ts +107 -0
  106. package/src/error-tracking/utils.ts +39 -0
  107. package/src/eventemitter.ts +27 -0
  108. package/src/featureFlagUtils.ts +192 -0
  109. package/src/gzip.ts +29 -0
  110. package/src/index.ts +8 -0
  111. package/src/posthog-core-stateless.ts +1226 -0
  112. package/src/posthog-core.ts +958 -0
  113. package/src/testing/PostHogCoreTestClient.ts +91 -0
  114. package/src/testing/index.ts +2 -0
  115. package/src/testing/test-utils.ts +47 -0
  116. package/src/types.ts +544 -0
  117. package/src/utils/bucketed-rate-limiter.spec.ts +33 -0
  118. package/src/utils/bucketed-rate-limiter.ts +85 -0
  119. package/src/utils/index.ts +98 -0
  120. package/src/utils/number-utils.spec.ts +89 -0
  121. package/src/utils/number-utils.ts +30 -0
  122. package/src/utils/promise-queue.spec.ts +55 -0
  123. package/src/utils/promise-queue.ts +30 -0
  124. package/src/utils/string-utils.ts +23 -0
  125. package/src/utils/type-utils.ts +134 -0
  126. package/src/vendor/uuidv7.ts +479 -0
@@ -43,7 +43,7 @@ function getFilenameToChunkIdMap(stackParser) {
43
43
  const parsedStack = stackParser(stackKey);
44
44
  for(let i = parsedStack.length - 1; i >= 0; i--){
45
45
  const stackFrame = parsedStack[i];
46
- const filename = null == stackFrame ? void 0 : stackFrame.filename;
46
+ const filename = stackFrame?.filename;
47
47
  const chunkId = chunkIdMap[stackKey];
48
48
  if (filename && chunkId) {
49
49
  acc[filename] = chunkId;
@@ -15,7 +15,7 @@ function getFilenameToChunkIdMap(stackParser) {
15
15
  const parsedStack = stackParser(stackKey);
16
16
  for(let i = parsedStack.length - 1; i >= 0; i--){
17
17
  const stackFrame = parsedStack[i];
18
- const filename = null == stackFrame ? void 0 : stackFrame.filename;
18
+ const filename = stackFrame?.filename;
19
19
  const chunkId = chunkIdMap[stackKey];
20
20
  if (filename && chunkId) {
21
21
  acc[filename] = chunkId;
@@ -28,21 +28,20 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  });
29
29
  const index_js_namespaceObject = require("../../utils/index.js");
30
30
  class ErrorEventCoercer {
31
+ constructor(){}
31
32
  match(err) {
32
33
  return (0, index_js_namespaceObject.isErrorEvent)(err) && void 0 != err.error;
33
34
  }
34
35
  coerce(err, ctx) {
35
36
  const exceptionLike = ctx.apply(err.error);
36
- if (exceptionLike) return exceptionLike;
37
- var _ctx_syntheticException;
38
- return {
37
+ if (!exceptionLike) return {
39
38
  type: 'ErrorEvent',
40
39
  value: err.message,
41
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
40
+ stack: ctx.syntheticException?.stack,
42
41
  synthetic: true
43
42
  };
43
+ return exceptionLike;
44
44
  }
45
- constructor(){}
46
45
  }
47
46
  exports.ErrorEventCoercer = __webpack_exports__.ErrorEventCoercer;
48
47
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -1,19 +1,18 @@
1
1
  import { isErrorEvent } from "../../utils/index.mjs";
2
2
  class ErrorEventCoercer {
3
+ constructor(){}
3
4
  match(err) {
4
5
  return isErrorEvent(err) && void 0 != err.error;
5
6
  }
6
7
  coerce(err, ctx) {
7
8
  const exceptionLike = ctx.apply(err.error);
8
- if (exceptionLike) return exceptionLike;
9
- var _ctx_syntheticException;
10
- return {
9
+ if (!exceptionLike) return {
11
10
  type: 'ErrorEvent',
12
11
  value: err.message,
13
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
12
+ stack: ctx.syntheticException?.stack,
14
13
  synthetic: true
15
14
  };
15
+ return exceptionLike;
16
16
  }
17
- constructor(){}
18
17
  }
19
18
  export { ErrorEventCoercer };
@@ -33,12 +33,11 @@ class EventCoercer {
33
33
  return (0, index_js_namespaceObject.isEvent)(err);
34
34
  }
35
35
  coerce(evt, ctx) {
36
- var _ctx_syntheticException;
37
36
  const constructorName = evt.constructor.name;
38
37
  return {
39
38
  type: constructorName,
40
39
  value: `${constructorName} captured as exception with keys: ${(0, external_utils_js_namespaceObject.extractExceptionKeysForMessage)(evt)}`,
41
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
40
+ stack: ctx.syntheticException?.stack,
42
41
  synthetic: true
43
42
  };
44
43
  }
@@ -5,12 +5,11 @@ class EventCoercer {
5
5
  return isEvent(err);
6
6
  }
7
7
  coerce(evt, ctx) {
8
- var _ctx_syntheticException;
9
8
  const constructorName = evt.constructor.name;
10
9
  return {
11
10
  type: constructorName,
12
11
  value: `${constructorName} captured as exception with keys: ${extractExceptionKeysForMessage(evt)}`,
13
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
12
+ stack: ctx.syntheticException?.stack,
14
13
  synthetic: true
15
14
  };
16
15
  }
@@ -36,11 +36,10 @@ class ObjectCoercer {
36
36
  coerce(candidate, ctx) {
37
37
  const errorProperty = this.getErrorPropertyFromObject(candidate);
38
38
  if (errorProperty) return ctx.apply(errorProperty);
39
- var _ctx_syntheticException;
40
39
  return {
41
40
  type: this.getType(candidate),
42
41
  value: this.getValue(candidate),
43
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
42
+ stack: ctx.syntheticException?.stack,
44
43
  level: this.isSeverityLevel(candidate.level) ? candidate.level : 'error',
45
44
  synthetic: true
46
45
  };
@@ -8,11 +8,10 @@ class ObjectCoercer {
8
8
  coerce(candidate, ctx) {
9
9
  const errorProperty = this.getErrorPropertyFromObject(candidate);
10
10
  if (errorProperty) return ctx.apply(errorProperty);
11
- var _ctx_syntheticException;
12
11
  return {
13
12
  type: this.getType(candidate),
14
13
  value: this.getValue(candidate),
15
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
14
+ stack: ctx.syntheticException?.stack,
16
15
  level: this.isSeverityLevel(candidate.level) ? candidate.level : 'error',
17
16
  synthetic: true
18
17
  };
@@ -32,11 +32,10 @@ class PrimitiveCoercer {
32
32
  return (0, index_js_namespaceObject.isPrimitive)(candidate);
33
33
  }
34
34
  coerce(value, ctx) {
35
- var _ctx_syntheticException;
36
35
  return {
37
36
  type: 'Error',
38
37
  value: `Primitive value captured as exception: ${String(value)}`,
39
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
38
+ stack: ctx.syntheticException?.stack,
40
39
  synthetic: true
41
40
  };
42
41
  }
@@ -4,11 +4,10 @@ class PrimitiveCoercer {
4
4
  return isPrimitive(candidate);
5
5
  }
6
6
  coerce(value, ctx) {
7
- var _ctx_syntheticException;
8
7
  return {
9
8
  type: 'Error',
10
9
  value: `Primitive value captured as exception: ${String(value)}`,
11
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
10
+ stack: ctx.syntheticException?.stack,
12
11
  synthetic: true
13
12
  };
14
13
  }
@@ -33,21 +33,20 @@ class PromiseRejectionEventCoercer {
33
33
  }
34
34
  coerce(err, ctx) {
35
35
  const reason = this.getUnhandledRejectionReason(err);
36
- if (!(0, index_js_namespaceObject.isPrimitive)(reason)) return ctx.apply(reason);
37
- var _ctx_syntheticException;
38
- return {
36
+ if ((0, index_js_namespaceObject.isPrimitive)(reason)) return {
39
37
  type: 'UnhandledRejection',
40
38
  value: `Non-Error promise rejection captured with value: ${String(reason)}`,
41
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
39
+ stack: ctx.syntheticException?.stack,
42
40
  synthetic: true
43
41
  };
42
+ return ctx.apply(reason);
44
43
  }
45
44
  getUnhandledRejectionReason(error) {
46
45
  if ((0, index_js_namespaceObject.isPrimitive)(error)) return error;
47
46
  try {
48
47
  if ('reason' in error) return error.reason;
49
48
  if ('detail' in error && 'reason' in error.detail) return error.detail.reason;
50
- } catch (e) {}
49
+ } catch {}
51
50
  return error;
52
51
  }
53
52
  }
@@ -5,21 +5,20 @@ class PromiseRejectionEventCoercer {
5
5
  }
6
6
  coerce(err, ctx) {
7
7
  const reason = this.getUnhandledRejectionReason(err);
8
- if (!isPrimitive(reason)) return ctx.apply(reason);
9
- var _ctx_syntheticException;
10
- return {
8
+ if (isPrimitive(reason)) return {
11
9
  type: 'UnhandledRejection',
12
10
  value: `Non-Error promise rejection captured with value: ${String(reason)}`,
13
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
11
+ stack: ctx.syntheticException?.stack,
14
12
  synthetic: true
15
13
  };
14
+ return ctx.apply(reason);
16
15
  }
17
16
  getUnhandledRejectionReason(error) {
18
17
  if (isPrimitive(error)) return error;
19
18
  try {
20
19
  if ('reason' in error) return error.reason;
21
20
  if ('detail' in error && 'reason' in error.detail) return error.detail.reason;
22
- } catch (e) {}
21
+ } catch {}
23
22
  return error;
24
23
  }
25
24
  }
@@ -32,12 +32,11 @@ class StringCoercer {
32
32
  return 'string' == typeof input;
33
33
  }
34
34
  coerce(input, ctx) {
35
- var _ctx_syntheticException;
36
35
  const [type, value] = this.getInfos(input);
37
36
  return {
38
- type: null != type ? type : 'Error',
39
- value: null != value ? value : input,
40
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
37
+ type: type ?? 'Error',
38
+ value: value ?? input,
39
+ stack: ctx.syntheticException?.stack,
41
40
  synthetic: true
42
41
  };
43
42
  }
@@ -4,12 +4,11 @@ class StringCoercer {
4
4
  return 'string' == typeof input;
5
5
  }
6
6
  coerce(input, ctx) {
7
- var _ctx_syntheticException;
8
7
  const [type, value] = this.getInfos(input);
9
8
  return {
10
- type: null != type ? type : 'Error',
11
- value: null != value ? value : input,
12
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
9
+ type: type ?? 'Error',
10
+ value: value ?? input,
11
+ stack: ctx.syntheticException?.stack,
13
12
  synthetic: true
14
13
  };
15
14
  }
@@ -27,13 +27,11 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  extractExceptionKeysForMessage: ()=>extractExceptionKeysForMessage,
28
28
  truncate: ()=>truncate
29
29
  });
30
- function truncate(str) {
31
- let max = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
30
+ function truncate(str, max = 0) {
32
31
  if ('string' != typeof str || 0 === max) return str;
33
32
  return str.length <= max ? str : `${str.slice(0, max)}...`;
34
33
  }
35
- function extractExceptionKeysForMessage(err) {
36
- let maxLength = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 40;
34
+ function extractExceptionKeysForMessage(err, maxLength = 40) {
37
35
  const keys = Object.keys(err);
38
36
  keys.sort();
39
37
  if (!keys.length) return '[object has no keys]';
@@ -1,10 +1,8 @@
1
- function truncate(str) {
2
- let max = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
1
+ function truncate(str, max = 0) {
3
2
  if ('string' != typeof str || 0 === max) return str;
4
3
  return str.length <= max ? str : `${str.slice(0, max)}...`;
5
4
  }
6
- function extractExceptionKeysForMessage(err) {
7
- let maxLength = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 40;
5
+ function extractExceptionKeysForMessage(err, maxLength = 40) {
8
6
  const keys = Object.keys(err);
9
7
  keys.sort();
10
8
  if (!keys.length) return '[object has no keys]';
@@ -30,8 +30,12 @@ const external_chunk_ids_js_namespaceObject = require("./chunk-ids.js");
30
30
  const index_js_namespaceObject = require("./parsers/index.js");
31
31
  const MAX_CAUSE_RECURSION = 4;
32
32
  class ErrorPropertiesBuilder {
33
- buildFromUnknown(input) {
34
- let hint = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
33
+ constructor(coercers = [], parsers = [], modifiers = []){
34
+ this.coercers = coercers;
35
+ this.modifiers = modifiers;
36
+ this.stackParser = (0, index_js_namespaceObject.createStackParser)(...parsers);
37
+ }
38
+ buildFromUnknown(input, hint = {}) {
35
39
  const providedMechanism = hint && hint.mechanism;
36
40
  const mechanism = providedMechanism || {
37
41
  handled: true,
@@ -48,11 +52,10 @@ class ErrorPropertiesBuilder {
48
52
  };
49
53
  }
50
54
  coerceFallback(ctx) {
51
- var _ctx_syntheticException;
52
55
  return {
53
56
  type: 'Error',
54
57
  value: 'Unknown error',
55
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
58
+ stack: ctx.syntheticException?.stack,
56
59
  synthetic: true
57
60
  };
58
61
  }
@@ -94,14 +97,13 @@ class ErrorPropertiesBuilder {
94
97
  };
95
98
  }
96
99
  convertToExceptionList(exceptionWithStack, mechanism) {
97
- var _mechanism_type, _mechanism_handled, _exceptionWithStack_synthetic;
98
100
  const currentException = {
99
101
  type: exceptionWithStack.type,
100
102
  value: exceptionWithStack.value,
101
103
  mechanism: {
102
- type: null != (_mechanism_type = mechanism.type) ? _mechanism_type : 'generic',
103
- handled: null != (_mechanism_handled = mechanism.handled) ? _mechanism_handled : true,
104
- synthetic: null != (_exceptionWithStack_synthetic = exceptionWithStack.synthetic) ? _exceptionWithStack_synthetic : false
104
+ type: mechanism.type ?? 'generic',
105
+ handled: mechanism.handled ?? true,
106
+ synthetic: exceptionWithStack.synthetic ?? false
105
107
  }
106
108
  };
107
109
  if (exceptionWithStack.stack) currentException.stacktrace = {
@@ -123,8 +125,7 @@ class ErrorPropertiesBuilder {
123
125
  };
124
126
  return context;
125
127
  }
126
- buildCoercingContext(mechanism, hint) {
127
- let depth = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0;
128
+ buildCoercingContext(mechanism, hint, depth = 0) {
128
129
  const coerce = (input, depth)=>{
129
130
  if (!(depth <= MAX_CAUSE_RECURSION)) return;
130
131
  {
@@ -141,11 +142,6 @@ class ErrorPropertiesBuilder {
141
142
  };
142
143
  return context;
143
144
  }
144
- constructor(coercers = [], parsers = [], modifiers = []){
145
- this.coercers = coercers;
146
- this.modifiers = modifiers;
147
- this.stackParser = (0, index_js_namespaceObject.createStackParser)(...parsers);
148
- }
149
145
  }
150
146
  exports.ErrorPropertiesBuilder = __webpack_exports__.ErrorPropertiesBuilder;
151
147
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -2,8 +2,12 @@ import { getFilenameToChunkIdMap } from "./chunk-ids.mjs";
2
2
  import { createStackParser } from "./parsers/index.mjs";
3
3
  const MAX_CAUSE_RECURSION = 4;
4
4
  class ErrorPropertiesBuilder {
5
- buildFromUnknown(input) {
6
- let hint = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
5
+ constructor(coercers = [], parsers = [], modifiers = []){
6
+ this.coercers = coercers;
7
+ this.modifiers = modifiers;
8
+ this.stackParser = createStackParser(...parsers);
9
+ }
10
+ buildFromUnknown(input, hint = {}) {
7
11
  const providedMechanism = hint && hint.mechanism;
8
12
  const mechanism = providedMechanism || {
9
13
  handled: true,
@@ -20,11 +24,10 @@ class ErrorPropertiesBuilder {
20
24
  };
21
25
  }
22
26
  coerceFallback(ctx) {
23
- var _ctx_syntheticException;
24
27
  return {
25
28
  type: 'Error',
26
29
  value: 'Unknown error',
27
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
30
+ stack: ctx.syntheticException?.stack,
28
31
  synthetic: true
29
32
  };
30
33
  }
@@ -66,14 +69,13 @@ class ErrorPropertiesBuilder {
66
69
  };
67
70
  }
68
71
  convertToExceptionList(exceptionWithStack, mechanism) {
69
- var _mechanism_type, _mechanism_handled, _exceptionWithStack_synthetic;
70
72
  const currentException = {
71
73
  type: exceptionWithStack.type,
72
74
  value: exceptionWithStack.value,
73
75
  mechanism: {
74
- type: null != (_mechanism_type = mechanism.type) ? _mechanism_type : 'generic',
75
- handled: null != (_mechanism_handled = mechanism.handled) ? _mechanism_handled : true,
76
- synthetic: null != (_exceptionWithStack_synthetic = exceptionWithStack.synthetic) ? _exceptionWithStack_synthetic : false
76
+ type: mechanism.type ?? 'generic',
77
+ handled: mechanism.handled ?? true,
78
+ synthetic: exceptionWithStack.synthetic ?? false
77
79
  }
78
80
  };
79
81
  if (exceptionWithStack.stack) currentException.stacktrace = {
@@ -95,8 +97,7 @@ class ErrorPropertiesBuilder {
95
97
  };
96
98
  return context;
97
99
  }
98
- buildCoercingContext(mechanism, hint) {
99
- let depth = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0;
100
+ buildCoercingContext(mechanism, hint, depth = 0) {
100
101
  const coerce = (input, depth)=>{
101
102
  if (!(depth <= MAX_CAUSE_RECURSION)) return;
102
103
  {
@@ -113,10 +114,5 @@ class ErrorPropertiesBuilder {
113
114
  };
114
115
  return context;
115
116
  }
116
- constructor(coercers = [], parsers = [], modifiers = []){
117
- this.coercers = coercers;
118
- this.modifiers = modifiers;
119
- this.stackParser = createStackParser(...parsers);
120
- }
121
117
  }
122
118
  export { ErrorPropertiesBuilder };
@@ -54,10 +54,8 @@ function reverseAndStripFrames(stack) {
54
54
  function getLastStackFrame(arr) {
55
55
  return arr[arr.length - 1] || {};
56
56
  }
57
- function createStackParser() {
58
- for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++)parsers[_key] = arguments[_key];
59
- return function(stack) {
60
- let skipFirstLines = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
57
+ function createStackParser(...parsers) {
58
+ return (stack, skipFirstLines = 0)=>{
61
59
  const frames = [];
62
60
  const lines = stack.split('\n');
63
61
  for(let i = skipFirstLines; i < lines.length; i++){
@@ -19,10 +19,8 @@ function reverseAndStripFrames(stack) {
19
19
  function getLastStackFrame(arr) {
20
20
  return arr[arr.length - 1] || {};
21
21
  }
22
- function createStackParser() {
23
- for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++)parsers[_key] = arguments[_key];
24
- return function(stack) {
25
- let skipFirstLines = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
22
+ function createStackParser(...parsers) {
23
+ return (stack, skipFirstLines = 0)=>{
26
24
  const frames = [];
27
25
  const lines = stack.split('\n');
28
26
  for(let i = skipFirstLines; i < lines.length; i++){
@@ -32,7 +32,6 @@ const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)
32
32
  const nodeStackLineParser = (line)=>{
33
33
  const lineMatch = line.match(FULL_MATCH);
34
34
  if (lineMatch) {
35
- var _lineMatch_;
36
35
  let object;
37
36
  let method;
38
37
  let functionName;
@@ -65,9 +64,9 @@ const nodeStackLineParser = (line)=>{
65
64
  methodName = methodName || external_base_js_namespaceObject.UNKNOWN_FUNCTION;
66
65
  functionName = typeName ? `${typeName}.${methodName}` : methodName;
67
66
  }
68
- let filename = (null == (_lineMatch_ = lineMatch[2]) ? void 0 : _lineMatch_.startsWith('file://')) ? lineMatch[2].slice(7) : lineMatch[2];
67
+ let filename = lineMatch[2]?.startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
69
68
  const isNative = 'native' === lineMatch[5];
70
- if (null == filename ? void 0 : filename.match(/\/[A-Z]:/)) filename = filename.slice(1);
69
+ if (filename?.match(/\/[A-Z]:/)) filename = filename.slice(1);
71
70
  if (!filename && lineMatch[5] && !isNative) filename = lineMatch[5];
72
71
  return {
73
72
  filename: filename ? decodeURI(filename) : void 0,
@@ -84,8 +83,7 @@ const nodeStackLineParser = (line)=>{
84
83
  platform: "node:javascript"
85
84
  };
86
85
  };
87
- function filenameIsInApp(filename) {
88
- let isNative = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
86
+ function filenameIsInApp(filename, isNative = false) {
89
87
  const isInternal = isNative || filename && !filename.startsWith('/') && !filename.match(/^[A-Z]:/) && !filename.startsWith('.') && !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//);
90
88
  return !isInternal && void 0 !== filename && !filename.includes('node_modules/');
91
89
  }
@@ -4,7 +4,6 @@ const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)
4
4
  const nodeStackLineParser = (line)=>{
5
5
  const lineMatch = line.match(FULL_MATCH);
6
6
  if (lineMatch) {
7
- var _lineMatch_;
8
7
  let object;
9
8
  let method;
10
9
  let functionName;
@@ -37,9 +36,9 @@ const nodeStackLineParser = (line)=>{
37
36
  methodName = methodName || UNKNOWN_FUNCTION;
38
37
  functionName = typeName ? `${typeName}.${methodName}` : methodName;
39
38
  }
40
- let filename = (null == (_lineMatch_ = lineMatch[2]) ? void 0 : _lineMatch_.startsWith('file://')) ? lineMatch[2].slice(7) : lineMatch[2];
39
+ let filename = lineMatch[2]?.startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
41
40
  const isNative = 'native' === lineMatch[5];
42
- if (null == filename ? void 0 : filename.match(/\/[A-Z]:/)) filename = filename.slice(1);
41
+ if (filename?.match(/\/[A-Z]:/)) filename = filename.slice(1);
43
42
  if (!filename && lineMatch[5] && !isNative) filename = lineMatch[5];
44
43
  return {
45
44
  filename: filename ? decodeURI(filename) : void 0,
@@ -56,8 +55,7 @@ const nodeStackLineParser = (line)=>{
56
55
  platform: "node:javascript"
57
56
  };
58
57
  };
59
- function filenameIsInApp(filename) {
60
- let isNative = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
58
+ function filenameIsInApp(filename, isNative = false) {
61
59
  const isInternal = isNative || filename && !filename.startsWith('/') && !filename.match(/^[A-Z]:/) && !filename.startsWith('.') && !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//);
62
60
  return !isInternal && void 0 !== filename && !filename.includes('node_modules/');
63
61
  }
@@ -27,6 +27,10 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  ReduceableCache: ()=>ReduceableCache
28
28
  });
29
29
  class ReduceableCache {
30
+ constructor(_maxSize){
31
+ this._maxSize = _maxSize;
32
+ this._cache = new Map();
33
+ }
30
34
  get(key) {
31
35
  const value = this._cache.get(key);
32
36
  if (void 0 === value) return;
@@ -43,10 +47,6 @@ class ReduceableCache {
43
47
  if (value) this._cache.delete(value);
44
48
  }
45
49
  }
46
- constructor(_maxSize){
47
- this._maxSize = _maxSize;
48
- this._cache = new Map();
49
- }
50
50
  }
51
51
  exports.ReduceableCache = __webpack_exports__.ReduceableCache;
52
52
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -1,4 +1,8 @@
1
1
  class ReduceableCache {
2
+ constructor(_maxSize){
3
+ this._maxSize = _maxSize;
4
+ this._cache = new Map();
5
+ }
2
6
  get(key) {
3
7
  const value = this._cache.get(key);
4
8
  if (void 0 === value) return;
@@ -15,9 +19,5 @@ class ReduceableCache {
15
19
  if (value) this._cache.delete(value);
16
20
  }
17
21
  }
18
- constructor(_maxSize){
19
- this._maxSize = _maxSize;
20
- this._cache = new Map();
21
- }
22
22
  }
23
23
  export { ReduceableCache };
@@ -27,6 +27,10 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  SimpleEventEmitter: ()=>SimpleEventEmitter
28
28
  });
29
29
  class SimpleEventEmitter {
30
+ constructor(){
31
+ this.events = {};
32
+ this.events = {};
33
+ }
30
34
  on(event, listener) {
31
35
  if (!this.events[event]) this.events[event] = [];
32
36
  this.events[event].push(listener);
@@ -38,10 +42,6 @@ class SimpleEventEmitter {
38
42
  for (const listener of this.events[event] || [])listener(payload);
39
43
  for (const listener of this.events['*'] || [])listener(event, payload);
40
44
  }
41
- constructor(){
42
- this.events = {};
43
- this.events = {};
44
- }
45
45
  }
46
46
  exports.SimpleEventEmitter = __webpack_exports__.SimpleEventEmitter;
47
47
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -1,4 +1,8 @@
1
1
  class SimpleEventEmitter {
2
+ constructor(){
3
+ this.events = {};
4
+ this.events = {};
5
+ }
2
6
  on(event, listener) {
3
7
  if (!this.events[event]) this.events[event] = [];
4
8
  this.events[event].push(listener);
@@ -10,9 +14,5 @@ class SimpleEventEmitter {
10
14
  for (const listener of this.events[event] || [])listener(payload);
11
15
  for (const listener of this.events['*'] || [])listener(event, payload);
12
16
  }
13
- constructor(){
14
- this.events = {};
15
- this.events = {};
16
- }
17
17
  }
18
18
  export { SimpleEventEmitter };