posthog-node 5.9.0 → 5.9.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 (74) hide show
  1. package/dist/client.d.ts.map +1 -1
  2. package/dist/client.js +1 -2
  3. package/dist/client.mjs +1 -2
  4. package/dist/entrypoints/index.edge.d.ts.map +1 -1
  5. package/dist/entrypoints/index.edge.js +12 -5
  6. package/dist/entrypoints/index.edge.mjs +10 -3
  7. package/dist/entrypoints/index.node.d.ts.map +1 -1
  8. package/dist/entrypoints/index.node.js +23 -15
  9. package/dist/entrypoints/index.node.mjs +14 -6
  10. package/dist/extensions/error-tracking/autocapture.d.ts +3 -3
  11. package/dist/extensions/error-tracking/autocapture.d.ts.map +1 -1
  12. package/dist/extensions/error-tracking/index.d.ts +3 -4
  13. package/dist/extensions/error-tracking/index.d.ts.map +1 -1
  14. package/dist/extensions/error-tracking/index.js +3 -3
  15. package/dist/extensions/error-tracking/index.mjs +3 -3
  16. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts +5 -0
  17. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts.map +1 -0
  18. package/dist/extensions/error-tracking/{context-lines.node.js → modifiers/context-lines.node.js} +3 -3
  19. package/dist/extensions/error-tracking/{context-lines.node.mjs → modifiers/context-lines.node.mjs} +3 -3
  20. package/dist/extensions/error-tracking/modifiers/module.node.d.ts +3 -0
  21. package/dist/extensions/error-tracking/modifiers/module.node.d.ts.map +1 -0
  22. package/dist/extensions/error-tracking/{get-module.node.js → modifiers/module.node.js} +10 -3
  23. package/dist/extensions/error-tracking/{get-module.node.mjs → modifiers/module.node.mjs} +8 -1
  24. package/dist/extensions/express.d.ts.map +1 -1
  25. package/dist/extensions/sentry-integration.d.ts +3 -3
  26. package/dist/extensions/sentry-integration.d.ts.map +1 -1
  27. package/dist/version.d.ts +1 -1
  28. package/dist/version.js +1 -1
  29. package/dist/version.mjs +1 -1
  30. package/package.json +2 -2
  31. package/src/client.ts +1 -1
  32. package/src/entrypoints/index.edge.ts +11 -4
  33. package/src/entrypoints/index.node.ts +14 -5
  34. package/src/extensions/error-tracking/autocapture.ts +6 -4
  35. package/src/extensions/error-tracking/index.ts +10 -9
  36. package/src/extensions/error-tracking/{context-lines.node.ts → modifiers/context-lines.node.ts} +23 -11
  37. package/src/extensions/error-tracking/{get-module.node.ts → modifiers/module.node.ts} +12 -1
  38. package/src/extensions/express.ts +2 -1
  39. package/src/extensions/sentry-integration.ts +4 -4
  40. package/src/version.ts +1 -1
  41. package/dist/extensions/error-tracking/chunk-ids.d.ts +0 -5
  42. package/dist/extensions/error-tracking/chunk-ids.d.ts.map +0 -1
  43. package/dist/extensions/error-tracking/chunk-ids.js +0 -68
  44. package/dist/extensions/error-tracking/chunk-ids.mjs +0 -34
  45. package/dist/extensions/error-tracking/context-lines.node.d.ts +0 -5
  46. package/dist/extensions/error-tracking/context-lines.node.d.ts.map +0 -1
  47. package/dist/extensions/error-tracking/error-conversion.d.ts +0 -4
  48. package/dist/extensions/error-tracking/error-conversion.d.ts.map +0 -1
  49. package/dist/extensions/error-tracking/error-conversion.js +0 -183
  50. package/dist/extensions/error-tracking/error-conversion.mjs +0 -146
  51. package/dist/extensions/error-tracking/get-module.node.d.ts +0 -3
  52. package/dist/extensions/error-tracking/get-module.node.d.ts.map +0 -1
  53. package/dist/extensions/error-tracking/reduceable-cache.d.ts +0 -13
  54. package/dist/extensions/error-tracking/reduceable-cache.d.ts.map +0 -1
  55. package/dist/extensions/error-tracking/reduceable-cache.js +0 -57
  56. package/dist/extensions/error-tracking/reduceable-cache.mjs +0 -23
  57. package/dist/extensions/error-tracking/stack-parser.d.ts +0 -3
  58. package/dist/extensions/error-tracking/stack-parser.d.ts.map +0 -1
  59. package/dist/extensions/error-tracking/stack-parser.js +0 -148
  60. package/dist/extensions/error-tracking/stack-parser.mjs +0 -114
  61. package/dist/extensions/error-tracking/type-checking.d.ts +0 -8
  62. package/dist/extensions/error-tracking/type-checking.d.ts.map +0 -1
  63. package/dist/extensions/error-tracking/type-checking.js +0 -80
  64. package/dist/extensions/error-tracking/type-checking.mjs +0 -31
  65. package/dist/extensions/error-tracking/types.d.ts +0 -61
  66. package/dist/extensions/error-tracking/types.d.ts.map +0 -1
  67. package/dist/extensions/error-tracking/types.js +0 -43
  68. package/dist/extensions/error-tracking/types.mjs +0 -9
  69. package/src/extensions/error-tracking/chunk-ids.ts +0 -58
  70. package/src/extensions/error-tracking/error-conversion.ts +0 -291
  71. package/src/extensions/error-tracking/reduceable-cache.ts +0 -39
  72. package/src/extensions/error-tracking/stack-parser.ts +0 -212
  73. package/src/extensions/error-tracking/type-checking.ts +0 -40
  74. package/src/extensions/error-tracking/types.ts +0 -71
@@ -1,61 +0,0 @@
1
- import { JsonType } from '@posthog/core';
2
- export declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"];
3
- export declare type SeverityLevel = (typeof severityLevels)[number];
4
- export interface PolymorphicEvent {
5
- [key: string]: unknown;
6
- readonly type: string;
7
- readonly target?: unknown;
8
- readonly currentTarget?: unknown;
9
- }
10
- export interface EventHint {
11
- mechanism?: Partial<Mechanism>;
12
- syntheticException?: Error | null;
13
- }
14
- export interface ErrorProperties {
15
- $exception_list: Exception[];
16
- $exception_level?: SeverityLevel;
17
- $exception_DOMException_code?: string;
18
- $exception_personURL?: string;
19
- }
20
- export interface Exception {
21
- type?: string;
22
- value?: string;
23
- mechanism?: Mechanism;
24
- module?: string;
25
- thread_id?: number;
26
- stacktrace?: {
27
- frames?: StackFrame[];
28
- type: 'raw';
29
- };
30
- }
31
- export interface Mechanism {
32
- handled?: boolean;
33
- type?: string;
34
- source?: string;
35
- synthetic?: boolean;
36
- }
37
- export type GetModuleFn = (filename: string | undefined) => string | undefined;
38
- export type StackParser = (stack: string, skipFirstLines?: number) => StackFrame[];
39
- export type StackLineParserFn = (line: string) => StackFrame | undefined;
40
- export type StackLineParser = [number, StackLineParserFn];
41
- export type StackFrameModifierFn = (frames: StackFrame[]) => Promise<StackFrame[]>;
42
- export interface StackFrame {
43
- platform: string;
44
- filename?: string;
45
- function?: string;
46
- module?: string;
47
- lineno?: number;
48
- colno?: number;
49
- abs_path?: string;
50
- context_line?: string;
51
- pre_context?: string[];
52
- post_context?: string[];
53
- in_app?: boolean;
54
- instruction_addr?: string;
55
- addr_mode?: string;
56
- vars?: {
57
- [key: string]: JsonType;
58
- };
59
- chunk_id?: string;
60
- }
61
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAKxC,eAAO,MAAM,cAAc,gEAAiE,CAAA;AAC5F,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9B,kBAAkB,CAAC,EAAE,KAAK,GAAG,IAAI,CAAA;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,SAAS,EAAE,CAAA;IAC5B,gBAAgB,CAAC,EAAE,aAAa,CAAA;IAChC,4BAA4B,CAAC,EAAE,MAAM,CAAA;IACrC,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;QAAC,IAAI,EAAE,KAAK,CAAA;KAAE,CAAA;CACpD;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,KAAK,UAAU,EAAE,CAAA;AAClF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAA;AACxE,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;AAEzD,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;AAElF,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,CAAA;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- severityLevels: ()=>severityLevels
28
- });
29
- const severityLevels = [
30
- 'fatal',
31
- 'error',
32
- 'warning',
33
- 'log',
34
- 'info',
35
- 'debug'
36
- ];
37
- exports.severityLevels = __webpack_exports__.severityLevels;
38
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
39
- "severityLevels"
40
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
41
- Object.defineProperty(exports, '__esModule', {
42
- value: true
43
- });
@@ -1,9 +0,0 @@
1
- const severityLevels = [
2
- 'fatal',
3
- 'error',
4
- 'warning',
5
- 'log',
6
- 'info',
7
- 'debug'
8
- ];
9
- export { severityLevels };
@@ -1,58 +0,0 @@
1
- // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2
- // Licensed under the MIT License
3
-
4
- import type { StackParser } from './types'
5
-
6
- type StackString = string
7
- type CachedResult = [string, string]
8
-
9
- type ChunkIdMapType = Record<string, string>
10
-
11
- let parsedStackResults: Record<StackString, CachedResult> | undefined
12
- let lastKeysCount: number | undefined
13
- let cachedFilenameChunkIds: ChunkIdMapType | undefined
14
-
15
- export function getFilenameToChunkIdMap(stackParser: StackParser): ChunkIdMapType | null {
16
- const chunkIdMap = (globalThis as any)._posthogChunkIds as ChunkIdMapType | undefined
17
- if (!chunkIdMap) {
18
- return null
19
- }
20
-
21
- const chunkIdKeys = Object.keys(chunkIdMap)
22
-
23
- if (cachedFilenameChunkIds && chunkIdKeys.length === lastKeysCount) {
24
- return cachedFilenameChunkIds
25
- }
26
-
27
- lastKeysCount = chunkIdKeys.length
28
-
29
- cachedFilenameChunkIds = chunkIdKeys.reduce<Record<string, string>>((acc, stackKey) => {
30
- if (!parsedStackResults) {
31
- parsedStackResults = {}
32
- }
33
-
34
- const result = parsedStackResults[stackKey]
35
-
36
- if (result) {
37
- acc[result[0]] = result[1]
38
- } else {
39
- const parsedStack = stackParser(stackKey)
40
-
41
- for (let i = parsedStack.length - 1; i >= 0; i--) {
42
- const stackFrame = parsedStack[i]
43
- const filename = stackFrame?.filename
44
- const chunkId = chunkIdMap[stackKey]
45
-
46
- if (filename && chunkId) {
47
- acc[filename] = chunkId
48
- parsedStackResults[stackKey] = [filename, chunkId]
49
- break
50
- }
51
- }
52
- }
53
-
54
- return acc
55
- }, {})
56
-
57
- return cachedFilenameChunkIds
58
- }
@@ -1,291 +0,0 @@
1
- // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2
- // Licensed under the MIT License
3
-
4
- import { getFilenameToChunkIdMap } from './chunk-ids'
5
- import { isError, isErrorEvent, isEvent, isPlainObject } from './type-checking'
6
- import {
7
- ErrorProperties,
8
- EventHint,
9
- Exception,
10
- Mechanism,
11
- StackFrame,
12
- StackFrameModifierFn,
13
- StackParser,
14
- } from './types'
15
-
16
- export async function propertiesFromUnknownInput(
17
- stackParser: StackParser,
18
- frameModifiers: StackFrameModifierFn[],
19
- input: unknown,
20
- hint?: EventHint
21
- ): Promise<ErrorProperties> {
22
- const providedMechanism = hint && hint.mechanism
23
- const mechanism = providedMechanism || {
24
- handled: true,
25
- type: 'generic',
26
- }
27
-
28
- const errorList = getErrorList(mechanism, input, hint)
29
- const exceptionList = await Promise.all(
30
- errorList.map(async (error) => {
31
- const exception = await exceptionFromError(stackParser, frameModifiers, error)
32
- exception.value = exception.value || ''
33
- exception.type = exception.type || 'Error'
34
- exception.mechanism = mechanism
35
- return exception
36
- })
37
- )
38
-
39
- const properties = { $exception_list: exceptionList }
40
- return properties
41
- }
42
-
43
- // Flatten error causes into a list of errors
44
- // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
45
- function getErrorList(mechanism: Mechanism, input: unknown, hint?: EventHint): Error[] {
46
- const error = getError(mechanism, input, hint)
47
- if (error.cause) {
48
- return [error, ...getErrorList(mechanism, error.cause, hint)]
49
- }
50
- return [error]
51
- }
52
-
53
- function getError(mechanism: Mechanism, exception: unknown, hint?: EventHint): Error {
54
- if (isError(exception)) {
55
- return exception
56
- }
57
-
58
- mechanism.synthetic = true
59
-
60
- if (isPlainObject(exception)) {
61
- const errorFromProp = getErrorPropertyFromObject(exception)
62
- if (errorFromProp) {
63
- return errorFromProp
64
- }
65
-
66
- const message = getMessageForObject(exception)
67
- const ex = hint?.syntheticException || new Error(message)
68
- ex.message = message
69
-
70
- return ex
71
- }
72
-
73
- // This handles when someone does: `throw "something awesome";`
74
- // We use synthesized Error here so we can extract a (rough) stack trace.
75
- const ex = hint?.syntheticException || new Error(exception as string)
76
- ex.message = `${exception}`
77
-
78
- return ex
79
- }
80
-
81
- /** If a plain object has a property that is an `Error`, return this error. */
82
- function getErrorPropertyFromObject(obj: Record<string, unknown>): Error | undefined {
83
- for (const prop in obj) {
84
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
85
- const value = obj[prop]
86
- if (isError(value)) {
87
- return value
88
- }
89
- }
90
- }
91
-
92
- return undefined
93
- }
94
-
95
- function getMessageForObject(exception: Record<string, unknown>): string {
96
- if ('name' in exception && typeof exception.name === 'string') {
97
- let message = `'${exception.name}' captured as exception`
98
-
99
- if ('message' in exception && typeof exception.message === 'string') {
100
- message += ` with message '${exception.message}'`
101
- }
102
-
103
- return message
104
- } else if ('message' in exception && typeof exception.message === 'string') {
105
- return exception.message
106
- }
107
-
108
- const keys = extractExceptionKeysForMessage(exception)
109
-
110
- // Some ErrorEvent instances do not have an `error` property, which is why they are not handled before
111
- // We still want to try to get a decent message for these cases
112
- if (isErrorEvent(exception)) {
113
- return `Event \`ErrorEvent\` captured as exception with message \`${exception.message}\``
114
- }
115
-
116
- const className = getObjectClassName(exception)
117
-
118
- return `${className && className !== 'Object' ? `'${className}'` : 'Object'} captured as exception with keys: ${keys}`
119
- }
120
-
121
- function getObjectClassName(obj: unknown): string | undefined | void {
122
- try {
123
- const prototype: unknown | null = Object.getPrototypeOf(obj)
124
- return prototype ? prototype.constructor.name : undefined
125
- } catch (e) {
126
- // ignore errors here
127
- }
128
- }
129
-
130
- /**
131
- * Given any captured exception, extract its keys and create a sorted
132
- * and truncated list that will be used inside the event message.
133
- * eg. `Non-error exception captured with keys: foo, bar, baz`
134
- */
135
- function extractExceptionKeysForMessage(exception: Record<string, unknown>, maxLength: number = 40): string {
136
- const keys = Object.keys(convertToPlainObject(exception))
137
- keys.sort()
138
-
139
- const firstKey = keys[0]
140
-
141
- if (!firstKey) {
142
- return '[object has no keys]'
143
- }
144
-
145
- if (firstKey.length >= maxLength) {
146
- return truncate(firstKey, maxLength)
147
- }
148
-
149
- for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) {
150
- const serialized = keys.slice(0, includedKeys).join(', ')
151
- if (serialized.length > maxLength) {
152
- continue
153
- }
154
- if (includedKeys === keys.length) {
155
- return serialized
156
- }
157
- return truncate(serialized, maxLength)
158
- }
159
-
160
- return ''
161
- }
162
-
163
- function truncate(str: string, max: number = 0): string {
164
- if (typeof str !== 'string' || max === 0) {
165
- return str
166
- }
167
- return str.length <= max ? str : `${str.slice(0, max)}...`
168
- }
169
-
170
- /**
171
- * Transforms any `Error` or `Event` into a plain object with all of their enumerable properties, and some of their
172
- * non-enumerable properties attached.
173
- *
174
- * @param value Initial source that we have to transform in order for it to be usable by the serializer
175
- * @returns An Event or Error turned into an object - or the value argument itself, when value is neither an Event nor
176
- * an Error.
177
- */
178
- function convertToPlainObject<V>(value: V):
179
- | {
180
- [ownProps: string]: unknown
181
- type: string
182
- target: string
183
- currentTarget: string
184
- detail?: unknown
185
- }
186
- | {
187
- [ownProps: string]: unknown
188
- message: string
189
- name: string
190
- stack?: string
191
- }
192
- | V {
193
- if (isError(value)) {
194
- return {
195
- message: value.message,
196
- name: value.name,
197
- stack: value.stack,
198
- ...getOwnProperties(value),
199
- }
200
- } else if (isEvent(value)) {
201
- const newObj: {
202
- [ownProps: string]: unknown
203
- type: string
204
- target: string
205
- currentTarget: string
206
- detail?: unknown
207
- } = {
208
- type: value.type,
209
- target: serializeEventTarget(value.target),
210
- currentTarget: serializeEventTarget(value.currentTarget),
211
- ...getOwnProperties(value),
212
- }
213
-
214
- // TODO: figure out why this fails typing (I think CustomEvent is only supported in Node 19 onwards)
215
- // if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {
216
- // newObj.detail = (value as unknown as CustomEvent).detail
217
- // }
218
-
219
- return newObj
220
- } else {
221
- return value
222
- }
223
- }
224
-
225
- /** Filters out all but an object's own properties */
226
- function getOwnProperties(obj: unknown): { [key: string]: unknown } {
227
- if (typeof obj === 'object' && obj !== null) {
228
- const extractedProps: { [key: string]: unknown } = {}
229
- for (const property in obj) {
230
- if (Object.prototype.hasOwnProperty.call(obj, property)) {
231
- extractedProps[property] = (obj as Record<string, unknown>)[property]
232
- }
233
- }
234
- return extractedProps
235
- } else {
236
- return {}
237
- }
238
- }
239
-
240
- /** Creates a string representation of the target of an `Event` object */
241
- function serializeEventTarget(target: unknown): string {
242
- try {
243
- return Object.prototype.toString.call(target)
244
- } catch (_oO) {
245
- return '<unknown>'
246
- }
247
- }
248
-
249
- /**
250
- * Extracts stack frames from the error and builds an Exception
251
- */
252
- async function exceptionFromError(
253
- stackParser: StackParser,
254
- frameModifiers: StackFrameModifierFn[],
255
- error: Error
256
- ): Promise<Exception> {
257
- const exception: Exception = {
258
- type: error.name || error.constructor.name,
259
- value: error.message,
260
- }
261
-
262
- let frames = parseStackFrames(stackParser, error)
263
-
264
- for (const modifier of frameModifiers) {
265
- frames = await modifier(frames)
266
- }
267
-
268
- if (frames.length) {
269
- exception.stacktrace = { frames, type: 'raw' }
270
- }
271
-
272
- return exception
273
- }
274
-
275
- /**
276
- * Extracts stack frames from the error.stack string
277
- */
278
- function parseStackFrames(stackParser: StackParser, error: Error): StackFrame[] {
279
- return applyChunkIds(stackParser(error.stack || '', 1), stackParser)
280
- }
281
-
282
- export function applyChunkIds(frames: StackFrame[], parser: StackParser): StackFrame[] {
283
- const filenameChunkIdMap = getFilenameToChunkIdMap(parser)
284
- frames.forEach((frame) => {
285
- if (frame.filename && filenameChunkIdMap) {
286
- frame.chunk_id = filenameChunkIdMap[frame.filename]
287
- }
288
- })
289
-
290
- return frames
291
- }
@@ -1,39 +0,0 @@
1
- // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2
- // Licensed under the MIT License
3
-
4
- /** A simple Least Recently Used map */
5
- export class ReduceableCache<K, V> {
6
- private readonly _cache: Map<K, V>
7
-
8
- public constructor(private readonly _maxSize: number) {
9
- this._cache = new Map<K, V>()
10
- }
11
-
12
- /** Get an entry or undefined if it was not in the cache. Re-inserts to update the recently used order */
13
- public get(key: K): V | undefined {
14
- const value = this._cache.get(key)
15
- if (value === undefined) {
16
- return undefined
17
- }
18
- // Remove and re-insert to update the order
19
- this._cache.delete(key)
20
- this._cache.set(key, value)
21
- return value
22
- }
23
-
24
- /** Insert an entry and evict an older entry if we've reached maxSize */
25
- public set(key: K, value: V): void {
26
- this._cache.set(key, value)
27
- }
28
-
29
- /** Remove an entry and return the entry if it was in the cache */
30
- public reduce(): void {
31
- while (this._cache.size >= this._maxSize) {
32
- const value = this._cache.keys().next().value
33
- if (value) {
34
- // keys() returns an iterator in insertion order so keys().next() gives us the oldest key
35
- this._cache.delete(value)
36
- }
37
- }
38
- }
39
- }