@posthog/core 1.1.0 → 1.2.1

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 (128) 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.d.ts +6 -6
  18. package/dist/error-tracking/error-properties-builder.d.ts.map +1 -1
  19. package/dist/error-tracking/error-properties-builder.js +17 -27
  20. package/dist/error-tracking/error-properties-builder.mjs +16 -26
  21. package/dist/error-tracking/parsers/index.js +2 -4
  22. package/dist/error-tracking/parsers/index.mjs +2 -4
  23. package/dist/error-tracking/parsers/node.js +3 -5
  24. package/dist/error-tracking/parsers/node.mjs +3 -5
  25. package/dist/error-tracking/utils.js +4 -4
  26. package/dist/error-tracking/utils.mjs +4 -4
  27. package/dist/eventemitter.js +4 -4
  28. package/dist/eventemitter.mjs +4 -4
  29. package/dist/featureFlagUtils.js +20 -45
  30. package/dist/featureFlagUtils.mjs +20 -45
  31. package/dist/gzip.js +1 -2
  32. package/dist/gzip.mjs +1 -2
  33. package/dist/index.d.ts +4 -366
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +54 -1225
  36. package/dist/index.mjs +5 -1190
  37. package/dist/posthog-core-stateless.d.ts +204 -0
  38. package/dist/posthog-core-stateless.d.ts.map +1 -0
  39. package/dist/posthog-core-stateless.js +675 -0
  40. package/dist/posthog-core-stateless.mjs +632 -0
  41. package/dist/posthog-core.d.ts +171 -0
  42. package/dist/posthog-core.d.ts.map +1 -0
  43. package/dist/posthog-core.js +554 -0
  44. package/dist/posthog-core.mjs +520 -0
  45. package/dist/testing/PostHogCoreTestClient.d.ts +2 -1
  46. package/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
  47. package/dist/testing/PostHogCoreTestClient.js +9 -11
  48. package/dist/testing/PostHogCoreTestClient.mjs +8 -10
  49. package/dist/testing/test-utils.js +1 -1
  50. package/dist/testing/test-utils.mjs +1 -1
  51. package/dist/utils/bucketed-rate-limiter.js +8 -12
  52. package/dist/utils/bucketed-rate-limiter.mjs +8 -12
  53. package/dist/utils/index.js +3 -3
  54. package/dist/utils/index.mjs +3 -3
  55. package/dist/utils/type-utils.js +1 -1
  56. package/dist/utils/type-utils.mjs +1 -1
  57. package/dist/vendor/uuidv7.js +12 -16
  58. package/dist/vendor/uuidv7.mjs +12 -16
  59. package/package.json +3 -2
  60. package/src/__tests__/featureFlagUtils.spec.ts +427 -0
  61. package/src/__tests__/gzip.spec.ts +69 -0
  62. package/src/__tests__/posthog.ai.spec.ts +110 -0
  63. package/src/__tests__/posthog.capture.spec.ts +91 -0
  64. package/src/__tests__/posthog.core.spec.ts +135 -0
  65. package/src/__tests__/posthog.debug.spec.ts +36 -0
  66. package/src/__tests__/posthog.enqueue.spec.ts +93 -0
  67. package/src/__tests__/posthog.featureflags.spec.ts +1106 -0
  68. package/src/__tests__/posthog.featureflags.v1.spec.ts +922 -0
  69. package/src/__tests__/posthog.flush.spec.ts +237 -0
  70. package/src/__tests__/posthog.gdpr.spec.ts +50 -0
  71. package/src/__tests__/posthog.groups.spec.ts +96 -0
  72. package/src/__tests__/posthog.identify.spec.ts +194 -0
  73. package/src/__tests__/posthog.init.spec.ts +110 -0
  74. package/src/__tests__/posthog.listeners.spec.ts +51 -0
  75. package/src/__tests__/posthog.register.spec.ts +47 -0
  76. package/src/__tests__/posthog.reset.spec.ts +76 -0
  77. package/src/__tests__/posthog.sessions.spec.ts +63 -0
  78. package/src/__tests__/posthog.setProperties.spec.ts +102 -0
  79. package/src/__tests__/posthog.shutdown.spec.ts +88 -0
  80. package/src/__tests__/utils.spec.ts +36 -0
  81. package/src/error-tracking/chunk-ids.ts +58 -0
  82. package/src/error-tracking/coercers/dom-exception-coercer.ts +38 -0
  83. package/src/error-tracking/coercers/error-coercer.ts +36 -0
  84. package/src/error-tracking/coercers/error-event-coercer.ts +24 -0
  85. package/src/error-tracking/coercers/event-coercer.ts +19 -0
  86. package/src/error-tracking/coercers/index.ts +8 -0
  87. package/src/error-tracking/coercers/object-coercer.ts +76 -0
  88. package/src/error-tracking/coercers/primitive-coercer.ts +19 -0
  89. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +77 -0
  90. package/src/error-tracking/coercers/promise-rejection-event.ts +53 -0
  91. package/src/error-tracking/coercers/string-coercer.spec.ts +26 -0
  92. package/src/error-tracking/coercers/string-coercer.ts +31 -0
  93. package/src/error-tracking/coercers/utils.ts +33 -0
  94. package/src/error-tracking/error-properties-builder.coerce.spec.ts +202 -0
  95. package/src/error-tracking/error-properties-builder.parse.spec.ts +30 -0
  96. package/src/error-tracking/error-properties-builder.ts +167 -0
  97. package/src/error-tracking/index.ts +5 -0
  98. package/src/error-tracking/parsers/base.ts +29 -0
  99. package/src/error-tracking/parsers/chrome.ts +53 -0
  100. package/src/error-tracking/parsers/gecko.ts +38 -0
  101. package/src/error-tracking/parsers/index.ts +104 -0
  102. package/src/error-tracking/parsers/node.ts +111 -0
  103. package/src/error-tracking/parsers/opera.ts +18 -0
  104. package/src/error-tracking/parsers/react-native.ts +0 -0
  105. package/src/error-tracking/parsers/safari.ts +33 -0
  106. package/src/error-tracking/parsers/winjs.ts +12 -0
  107. package/src/error-tracking/types.ts +107 -0
  108. package/src/error-tracking/utils.ts +39 -0
  109. package/src/eventemitter.ts +27 -0
  110. package/src/featureFlagUtils.ts +192 -0
  111. package/src/gzip.ts +29 -0
  112. package/src/index.ts +8 -0
  113. package/src/posthog-core-stateless.ts +1226 -0
  114. package/src/posthog-core.ts +958 -0
  115. package/src/testing/PostHogCoreTestClient.ts +91 -0
  116. package/src/testing/index.ts +2 -0
  117. package/src/testing/test-utils.ts +47 -0
  118. package/src/types.ts +544 -0
  119. package/src/utils/bucketed-rate-limiter.spec.ts +33 -0
  120. package/src/utils/bucketed-rate-limiter.ts +85 -0
  121. package/src/utils/index.ts +98 -0
  122. package/src/utils/number-utils.spec.ts +89 -0
  123. package/src/utils/number-utils.ts +30 -0
  124. package/src/utils/promise-queue.spec.ts +55 -0
  125. package/src/utils/promise-queue.ts +30 -0
  126. package/src/utils/string-utils.ts +23 -0
  127. package/src/utils/type-utils.ts +134 -0
  128. 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]';
@@ -1,18 +1,18 @@
1
- import { ErrorProperties, ExceptionLike, CoercingContext, StackFrameModifierFn, StackParser, ErrorTrackingCoercer, EventHint, StackLineParser, ParsingContext, Mechanism, ParsedException } from './types';
1
+ import { ErrorProperties, StackFrameModifierFn, StackParser, ErrorTrackingCoercer, EventHint, StackLineParser } from './types';
2
2
  export declare class ErrorPropertiesBuilder {
3
3
  private coercers;
4
4
  private modifiers;
5
5
  stackParser: StackParser;
6
6
  constructor(coercers?: ErrorTrackingCoercer<any>[], parsers?: StackLineParser[], modifiers?: StackFrameModifierFn[]);
7
7
  buildFromUnknown(input: unknown, hint?: EventHint): ErrorProperties;
8
- coerceFallback(ctx: CoercingContext): ExceptionLike;
9
- parseStacktrace(err: ExceptionLike, ctx: ParsingContext): ParsedException;
8
+ modifyFrames(exceptionList: ErrorProperties['$exception_list']): Promise<ErrorProperties['$exception_list']>;
9
+ private coerceFallback;
10
+ private parseStacktrace;
10
11
  private applyChunkIds;
11
12
  private applyCoercers;
12
13
  private applyModifiers;
13
- private modifyFrames;
14
14
  private convertToExceptionList;
15
- buildParsingContext(): ParsingContext;
16
- buildCoercingContext(mechanism: Mechanism, hint: EventHint, depth?: number): CoercingContext;
15
+ private buildParsingContext;
16
+ private buildCoercingContext;
17
17
  }
18
18
  //# sourceMappingURL=error-properties-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-properties-builder.d.ts","sourceRoot":"","sources":["../../src/error-tracking/error-properties-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,aAAa,EAEb,eAAe,EAEf,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,eAAe,EACf,cAAc,EAEd,SAAS,EACT,eAAe,EAEhB,MAAM,SAAS,CAAA;AAIhB,qBAAa,sBAAsB;IAI/B,OAAO,CAAC,QAAQ;IAEhB,OAAO,CAAC,SAAS;IALnB,WAAW,EAAE,WAAW,CAAA;gBAGd,QAAQ,GAAE,oBAAoB,CAAC,GAAG,CAAC,EAAO,EAClD,OAAO,GAAE,eAAe,EAAO,EACvB,SAAS,GAAE,oBAAoB,EAAO;IAKhD,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,SAAc,GAAG,eAAe;IAiBvE,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,aAAa;IASnD,eAAe,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,GAAG,eAAe;IAYzE,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;YASP,cAAc;YAQd,YAAY;IAY1B,OAAO,CAAC,sBAAsB;IA6B9B,mBAAmB,IAAI,cAAc;IAOrC,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,GAAE,MAAU,GAAG,eAAe;CAuBhG"}
1
+ {"version":3,"file":"error-properties-builder.d.ts","sourceRoot":"","sources":["../../src/error-tracking/error-properties-builder.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EAKf,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,eAAe,EAMhB,MAAM,SAAS,CAAA;AAIhB,qBAAa,sBAAsB;IAI/B,OAAO,CAAC,QAAQ;IAEhB,OAAO,CAAC,SAAS;IALnB,WAAW,EAAE,WAAW,CAAA;gBAGd,QAAQ,GAAE,oBAAoB,CAAC,GAAG,CAAC,EAAO,EAClD,OAAO,GAAE,eAAe,EAAO,EACvB,SAAS,GAAE,oBAAoB,EAAO;IAKhD,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,SAAc,GAAG,eAAe;IAiBjE,YAAY,CAAC,aAAa,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IASlH,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;YASP,cAAc;IAQ5B,OAAO,CAAC,sBAAsB;IA6B9B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,oBAAoB;CAuB7B"}
@@ -26,12 +26,17 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  ErrorPropertiesBuilder: ()=>ErrorPropertiesBuilder
28
28
  });
29
+ const index_js_namespaceObject = require("../utils/index.js");
29
30
  const external_chunk_ids_js_namespaceObject = require("./chunk-ids.js");
30
- const index_js_namespaceObject = require("./parsers/index.js");
31
+ const external_parsers_index_js_namespaceObject = require("./parsers/index.js");
31
32
  const MAX_CAUSE_RECURSION = 4;
32
33
  class ErrorPropertiesBuilder {
33
- buildFromUnknown(input) {
34
- let hint = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
34
+ constructor(coercers = [], parsers = [], modifiers = []){
35
+ this.coercers = coercers;
36
+ this.modifiers = modifiers;
37
+ this.stackParser = (0, external_parsers_index_js_namespaceObject.createStackParser)(...parsers);
38
+ }
39
+ buildFromUnknown(input, hint = {}) {
35
40
  const providedMechanism = hint && hint.mechanism;
36
41
  const mechanism = providedMechanism || {
37
42
  handled: true,
@@ -47,12 +52,15 @@ class ErrorPropertiesBuilder {
47
52
  $exception_level: 'error'
48
53
  };
49
54
  }
55
+ async modifyFrames(exceptionList) {
56
+ for (const exc of exceptionList)if (exc.stacktrace && exc.stacktrace.frames && (0, index_js_namespaceObject.isArray)(exc.stacktrace.frames)) exc.stacktrace.frames = await this.applyModifiers(exc.stacktrace.frames);
57
+ return exceptionList;
58
+ }
50
59
  coerceFallback(ctx) {
51
- var _ctx_syntheticException;
52
60
  return {
53
61
  type: 'Error',
54
62
  value: 'Unknown error',
55
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
63
+ stack: ctx.syntheticException?.stack,
56
64
  synthetic: true
57
65
  };
58
66
  }
@@ -82,26 +90,14 @@ class ErrorPropertiesBuilder {
82
90
  for (const modifier of this.modifiers)newFrames = await modifier(newFrames);
83
91
  return newFrames;
84
92
  }
85
- async modifyFrames(exceptionWithStack) {
86
- let cause;
87
- if (null != exceptionWithStack.cause) cause = await this.modifyFrames(exceptionWithStack.cause);
88
- let stack = [];
89
- if (null != exceptionWithStack.stack) stack = await this.applyModifiers(exceptionWithStack.stack);
90
- return {
91
- ...exceptionWithStack,
92
- cause,
93
- stack
94
- };
95
- }
96
93
  convertToExceptionList(exceptionWithStack, mechanism) {
97
- var _mechanism_type, _mechanism_handled, _exceptionWithStack_synthetic;
98
94
  const currentException = {
99
95
  type: exceptionWithStack.type,
100
96
  value: exceptionWithStack.value,
101
97
  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
98
+ type: mechanism.type ?? 'generic',
99
+ handled: mechanism.handled ?? true,
100
+ synthetic: exceptionWithStack.synthetic ?? false
105
101
  }
106
102
  };
107
103
  if (exceptionWithStack.stack) currentException.stacktrace = {
@@ -123,8 +119,7 @@ class ErrorPropertiesBuilder {
123
119
  };
124
120
  return context;
125
121
  }
126
- buildCoercingContext(mechanism, hint) {
127
- let depth = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0;
122
+ buildCoercingContext(mechanism, hint, depth = 0) {
128
123
  const coerce = (input, depth)=>{
129
124
  if (!(depth <= MAX_CAUSE_RECURSION)) return;
130
125
  {
@@ -141,11 +136,6 @@ class ErrorPropertiesBuilder {
141
136
  };
142
137
  return context;
143
138
  }
144
- constructor(coercers = [], parsers = [], modifiers = []){
145
- this.coercers = coercers;
146
- this.modifiers = modifiers;
147
- this.stackParser = (0, index_js_namespaceObject.createStackParser)(...parsers);
148
- }
149
139
  }
150
140
  exports.ErrorPropertiesBuilder = __webpack_exports__.ErrorPropertiesBuilder;
151
141
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
@@ -1,9 +1,14 @@
1
+ import { isArray } from "../utils/index.mjs";
1
2
  import { getFilenameToChunkIdMap } from "./chunk-ids.mjs";
2
3
  import { createStackParser } from "./parsers/index.mjs";
3
4
  const MAX_CAUSE_RECURSION = 4;
4
5
  class ErrorPropertiesBuilder {
5
- buildFromUnknown(input) {
6
- let hint = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
6
+ constructor(coercers = [], parsers = [], modifiers = []){
7
+ this.coercers = coercers;
8
+ this.modifiers = modifiers;
9
+ this.stackParser = createStackParser(...parsers);
10
+ }
11
+ buildFromUnknown(input, hint = {}) {
7
12
  const providedMechanism = hint && hint.mechanism;
8
13
  const mechanism = providedMechanism || {
9
14
  handled: true,
@@ -19,12 +24,15 @@ class ErrorPropertiesBuilder {
19
24
  $exception_level: 'error'
20
25
  };
21
26
  }
27
+ async modifyFrames(exceptionList) {
28
+ for (const exc of exceptionList)if (exc.stacktrace && exc.stacktrace.frames && isArray(exc.stacktrace.frames)) exc.stacktrace.frames = await this.applyModifiers(exc.stacktrace.frames);
29
+ return exceptionList;
30
+ }
22
31
  coerceFallback(ctx) {
23
- var _ctx_syntheticException;
24
32
  return {
25
33
  type: 'Error',
26
34
  value: 'Unknown error',
27
- stack: null == (_ctx_syntheticException = ctx.syntheticException) ? void 0 : _ctx_syntheticException.stack,
35
+ stack: ctx.syntheticException?.stack,
28
36
  synthetic: true
29
37
  };
30
38
  }
@@ -54,26 +62,14 @@ class ErrorPropertiesBuilder {
54
62
  for (const modifier of this.modifiers)newFrames = await modifier(newFrames);
55
63
  return newFrames;
56
64
  }
57
- async modifyFrames(exceptionWithStack) {
58
- let cause;
59
- if (null != exceptionWithStack.cause) cause = await this.modifyFrames(exceptionWithStack.cause);
60
- let stack = [];
61
- if (null != exceptionWithStack.stack) stack = await this.applyModifiers(exceptionWithStack.stack);
62
- return {
63
- ...exceptionWithStack,
64
- cause,
65
- stack
66
- };
67
- }
68
65
  convertToExceptionList(exceptionWithStack, mechanism) {
69
- var _mechanism_type, _mechanism_handled, _exceptionWithStack_synthetic;
70
66
  const currentException = {
71
67
  type: exceptionWithStack.type,
72
68
  value: exceptionWithStack.value,
73
69
  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
70
+ type: mechanism.type ?? 'generic',
71
+ handled: mechanism.handled ?? true,
72
+ synthetic: exceptionWithStack.synthetic ?? false
77
73
  }
78
74
  };
79
75
  if (exceptionWithStack.stack) currentException.stacktrace = {
@@ -95,8 +91,7 @@ class ErrorPropertiesBuilder {
95
91
  };
96
92
  return context;
97
93
  }
98
- buildCoercingContext(mechanism, hint) {
99
- let depth = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0;
94
+ buildCoercingContext(mechanism, hint, depth = 0) {
100
95
  const coerce = (input, depth)=>{
101
96
  if (!(depth <= MAX_CAUSE_RECURSION)) return;
102
97
  {
@@ -113,10 +108,5 @@ class ErrorPropertiesBuilder {
113
108
  };
114
109
  return context;
115
110
  }
116
- constructor(coercers = [], parsers = [], modifiers = []){
117
- this.coercers = coercers;
118
- this.modifiers = modifiers;
119
- this.stackParser = createStackParser(...parsers);
120
- }
121
111
  }
122
112
  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 === [