posthog-node 5.0.0-alpha.1 → 5.1.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 (65) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/lib/edge/index.cjs +3455 -0
  3. package/lib/edge/index.cjs.map +1 -0
  4. package/lib/edge/index.mjs +3429 -0
  5. package/lib/edge/index.mjs.map +1 -0
  6. package/lib/index.d.ts +938 -810
  7. package/lib/{index.cjs.js → node/index.cjs} +2910 -3107
  8. package/lib/node/index.cjs.map +1 -0
  9. package/lib/{index.esm.js → node/index.mjs} +2911 -3105
  10. package/lib/node/index.mjs.map +1 -0
  11. package/package.json +33 -6
  12. package/index.ts +0 -3
  13. package/lib/index.cjs.js.map +0 -1
  14. package/lib/index.esm.js.map +0 -1
  15. package/lib/posthog-core/src/eventemitter.d.ts +0 -8
  16. package/lib/posthog-core/src/featureFlagUtils.d.ts +0 -34
  17. package/lib/posthog-core/src/index.d.ts +0 -242
  18. package/lib/posthog-core/src/lz-string.d.ts +0 -8
  19. package/lib/posthog-core/src/storage-memory.d.ts +0 -6
  20. package/lib/posthog-core/src/types.d.ts +0 -422
  21. package/lib/posthog-core/src/utils.d.ts +0 -19
  22. package/lib/posthog-core/src/vendor/uuidv7.d.ts +0 -179
  23. package/lib/posthog-node/index.d.ts +0 -3
  24. package/lib/posthog-node/src/crypto-helpers.d.ts +0 -3
  25. package/lib/posthog-node/src/crypto.d.ts +0 -2
  26. package/lib/posthog-node/src/error-tracking.d.ts +0 -12
  27. package/lib/posthog-node/src/extensions/error-tracking/autocapture.d.ts +0 -3
  28. package/lib/posthog-node/src/extensions/error-tracking/context-lines.d.ts +0 -6
  29. package/lib/posthog-node/src/extensions/error-tracking/error-conversion.d.ts +0 -2
  30. package/lib/posthog-node/src/extensions/error-tracking/reduceable-cache.d.ts +0 -12
  31. package/lib/posthog-node/src/extensions/error-tracking/stack-trace.d.ts +0 -15
  32. package/lib/posthog-node/src/extensions/error-tracking/type-checking.d.ts +0 -7
  33. package/lib/posthog-node/src/extensions/error-tracking/types.d.ts +0 -57
  34. package/lib/posthog-node/src/extensions/express.d.ts +0 -17
  35. package/lib/posthog-node/src/extensions/sentry-integration.d.ts +0 -51
  36. package/lib/posthog-node/src/feature-flags.d.ts +0 -84
  37. package/lib/posthog-node/src/lazy.d.ts +0 -23
  38. package/lib/posthog-node/src/posthog-node.d.ts +0 -91
  39. package/lib/posthog-node/src/types.d.ts +0 -203
  40. package/lib/posthog-node/test/test-utils.d.ts +0 -17
  41. package/src/crypto-helpers.ts +0 -36
  42. package/src/crypto.ts +0 -22
  43. package/src/error-tracking.ts +0 -67
  44. package/src/extensions/error-tracking/autocapture.ts +0 -65
  45. package/src/extensions/error-tracking/context-lines.ts +0 -425
  46. package/src/extensions/error-tracking/error-conversion.ts +0 -262
  47. package/src/extensions/error-tracking/reduceable-cache.ts +0 -39
  48. package/src/extensions/error-tracking/stack-trace.ts +0 -269
  49. package/src/extensions/error-tracking/type-checking.ts +0 -40
  50. package/src/extensions/error-tracking/types.ts +0 -65
  51. package/src/extensions/express.ts +0 -37
  52. package/src/extensions/sentry-integration.ts +0 -196
  53. package/src/feature-flags.ts +0 -863
  54. package/src/lazy.ts +0 -55
  55. package/src/posthog-node.ts +0 -567
  56. package/src/types.ts +0 -231
  57. package/test/crypto.spec.ts +0 -36
  58. package/test/extensions/error-conversion.spec.ts +0 -44
  59. package/test/extensions/sentry-integration.spec.ts +0 -162
  60. package/test/feature-flags.decide.spec.ts +0 -378
  61. package/test/feature-flags.spec.ts +0 -4681
  62. package/test/lazy.spec.ts +0 -71
  63. package/test/posthog-node.spec.ts +0 -1341
  64. package/test/test-utils.ts +0 -106
  65. package/tsconfig.json +0 -7
@@ -1,262 +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 { isError, isErrorEvent, isEvent, isPlainObject } from './type-checking'
5
- import { ErrorProperties, EventHint, Exception, Mechanism, StackFrame, StackParser } from './types'
6
- import { addSourceContext } from './context-lines'
7
-
8
- export async function propertiesFromUnknownInput(
9
- stackParser: StackParser,
10
- input: unknown,
11
- hint?: EventHint
12
- ): Promise<ErrorProperties> {
13
- const providedMechanism = hint && hint.mechanism
14
- const mechanism = providedMechanism || {
15
- handled: true,
16
- type: 'generic',
17
- }
18
-
19
- const errorList = getErrorList(mechanism, input, hint)
20
- const exceptionList = await Promise.all(
21
- errorList.map(async (error) => {
22
- const exception = await exceptionFromError(stackParser, error)
23
- exception.value = exception.value || ''
24
- exception.type = exception.type || 'Error'
25
- exception.mechanism = mechanism
26
- return exception
27
- })
28
- )
29
-
30
- const properties = { $exception_list: exceptionList }
31
- return properties
32
- }
33
-
34
- // Flatten error causes into a list of errors
35
- // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
36
- function getErrorList(mechanism: Mechanism, input: unknown, hint?: EventHint): Error[] {
37
- const error = getError(mechanism, input, hint)
38
- if (error.cause) {
39
- return [error, ...getErrorList(mechanism, error.cause, hint)]
40
- }
41
- return [error]
42
- }
43
-
44
- function getError(mechanism: Mechanism, exception: unknown, hint?: EventHint): Error {
45
- if (isError(exception)) {
46
- return exception
47
- }
48
-
49
- mechanism.synthetic = true
50
-
51
- if (isPlainObject(exception)) {
52
- const errorFromProp = getErrorPropertyFromObject(exception)
53
- if (errorFromProp) {
54
- return errorFromProp
55
- }
56
-
57
- const message = getMessageForObject(exception)
58
- const ex = hint?.syntheticException || new Error(message)
59
- ex.message = message
60
-
61
- return ex
62
- }
63
-
64
- // This handles when someone does: `throw "something awesome";`
65
- // We use synthesized Error here so we can extract a (rough) stack trace.
66
- const ex = hint?.syntheticException || new Error(exception as string)
67
- ex.message = `${exception}`
68
-
69
- return ex
70
- }
71
-
72
- /** If a plain object has a property that is an `Error`, return this error. */
73
- function getErrorPropertyFromObject(obj: Record<string, unknown>): Error | undefined {
74
- for (const prop in obj) {
75
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
76
- const value = obj[prop]
77
- if (isError(value)) {
78
- return value
79
- }
80
- }
81
- }
82
-
83
- return undefined
84
- }
85
-
86
- function getMessageForObject(exception: Record<string, unknown>): string {
87
- if ('name' in exception && typeof exception.name === 'string') {
88
- let message = `'${exception.name}' captured as exception`
89
-
90
- if ('message' in exception && typeof exception.message === 'string') {
91
- message += ` with message '${exception.message}'`
92
- }
93
-
94
- return message
95
- } else if ('message' in exception && typeof exception.message === 'string') {
96
- return exception.message
97
- }
98
-
99
- const keys = extractExceptionKeysForMessage(exception)
100
-
101
- // Some ErrorEvent instances do not have an `error` property, which is why they are not handled before
102
- // We still want to try to get a decent message for these cases
103
- if (isErrorEvent(exception)) {
104
- return `Event \`ErrorEvent\` captured as exception with message \`${exception.message}\``
105
- }
106
-
107
- const className = getObjectClassName(exception)
108
-
109
- return `${className && className !== 'Object' ? `'${className}'` : 'Object'} captured as exception with keys: ${keys}`
110
- }
111
-
112
- function getObjectClassName(obj: unknown): string | undefined | void {
113
- try {
114
- const prototype: unknown | null = Object.getPrototypeOf(obj)
115
- return prototype ? prototype.constructor.name : undefined
116
- } catch (e) {
117
- // ignore errors here
118
- }
119
- }
120
-
121
- /**
122
- * Given any captured exception, extract its keys and create a sorted
123
- * and truncated list that will be used inside the event message.
124
- * eg. `Non-error exception captured with keys: foo, bar, baz`
125
- */
126
- function extractExceptionKeysForMessage(exception: Record<string, unknown>, maxLength: number = 40): string {
127
- const keys = Object.keys(convertToPlainObject(exception))
128
- keys.sort()
129
-
130
- const firstKey = keys[0]
131
-
132
- if (!firstKey) {
133
- return '[object has no keys]'
134
- }
135
-
136
- if (firstKey.length >= maxLength) {
137
- return truncate(firstKey, maxLength)
138
- }
139
-
140
- for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) {
141
- const serialized = keys.slice(0, includedKeys).join(', ')
142
- if (serialized.length > maxLength) {
143
- continue
144
- }
145
- if (includedKeys === keys.length) {
146
- return serialized
147
- }
148
- return truncate(serialized, maxLength)
149
- }
150
-
151
- return ''
152
- }
153
-
154
- function truncate(str: string, max: number = 0): string {
155
- if (typeof str !== 'string' || max === 0) {
156
- return str
157
- }
158
- return str.length <= max ? str : `${str.slice(0, max)}...`
159
- }
160
-
161
- /**
162
- * Transforms any `Error` or `Event` into a plain object with all of their enumerable properties, and some of their
163
- * non-enumerable properties attached.
164
- *
165
- * @param value Initial source that we have to transform in order for it to be usable by the serializer
166
- * @returns An Event or Error turned into an object - or the value argument itself, when value is neither an Event nor
167
- * an Error.
168
- */
169
- function convertToPlainObject<V>(value: V):
170
- | {
171
- [ownProps: string]: unknown
172
- type: string
173
- target: string
174
- currentTarget: string
175
- detail?: unknown
176
- }
177
- | {
178
- [ownProps: string]: unknown
179
- message: string
180
- name: string
181
- stack?: string
182
- }
183
- | V {
184
- if (isError(value)) {
185
- return {
186
- message: value.message,
187
- name: value.name,
188
- stack: value.stack,
189
- ...getOwnProperties(value),
190
- }
191
- } else if (isEvent(value)) {
192
- const newObj: {
193
- [ownProps: string]: unknown
194
- type: string
195
- target: string
196
- currentTarget: string
197
- detail?: unknown
198
- } = {
199
- type: value.type,
200
- target: serializeEventTarget(value.target),
201
- currentTarget: serializeEventTarget(value.currentTarget),
202
- ...getOwnProperties(value),
203
- }
204
-
205
- // TODO: figure out why this fails typing (I think CustomEvent is only supported in Node 19 onwards)
206
- // if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) {
207
- // newObj.detail = (value as unknown as CustomEvent).detail
208
- // }
209
-
210
- return newObj
211
- } else {
212
- return value
213
- }
214
- }
215
-
216
- /** Filters out all but an object's own properties */
217
- function getOwnProperties(obj: unknown): { [key: string]: unknown } {
218
- if (typeof obj === 'object' && obj !== null) {
219
- const extractedProps: { [key: string]: unknown } = {}
220
- for (const property in obj) {
221
- if (Object.prototype.hasOwnProperty.call(obj, property)) {
222
- extractedProps[property] = (obj as Record<string, unknown>)[property]
223
- }
224
- }
225
- return extractedProps
226
- } else {
227
- return {}
228
- }
229
- }
230
-
231
- /** Creates a string representation of the target of an `Event` object */
232
- function serializeEventTarget(target: unknown): string {
233
- try {
234
- return Object.prototype.toString.call(target)
235
- } catch (_oO) {
236
- return '<unknown>'
237
- }
238
- }
239
-
240
- /**
241
- * Extracts stack frames from the error and builds an Exception
242
- */
243
- async function exceptionFromError(stackParser: StackParser, error: Error): Promise<Exception> {
244
- const exception: Exception = {
245
- type: error.name || error.constructor.name,
246
- value: error.message,
247
- }
248
-
249
- const frames = await addSourceContext(parseStackFrames(stackParser, error))
250
- if (frames.length) {
251
- exception.stacktrace = { frames, type: 'raw' }
252
- }
253
-
254
- return exception
255
- }
256
-
257
- /**
258
- * Extracts stack frames from the error.stack string
259
- */
260
- function parseStackFrames(stackParser: StackParser, error: Error): StackFrame[] {
261
- return stackParser(error.stack || '', 1)
262
- }
@@ -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
- }
@@ -1,269 +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 { posix, sep, dirname } from 'path'
5
- import { StackFrame, StackLineParser, StackLineParserFn, StackParser } from './types'
6
-
7
- type GetModuleFn = (filename: string | undefined) => string | undefined
8
-
9
- // This was originally forked from https://github.com/csnover/TraceKit, and was largely
10
- // re-written as part of raven - js.
11
- //
12
- // This code was later copied to the JavaScript mono - repo and further modified and
13
- // refactored over the years.
14
-
15
- // Copyright (c) 2013 Onur Can Cakmak onur.cakmak@gmail.com and all TraceKit contributors.
16
- //
17
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this
18
- // software and associated documentation files(the 'Software'), to deal in the Software
19
- // without restriction, including without limitation the rights to use, copy, modify,
20
- // merge, publish, distribute, sublicense, and / or sell copies of the Software, and to
21
- // permit persons to whom the Software is furnished to do so, subject to the following
22
- // conditions:
23
- //
24
- // The above copyright notice and this permission notice shall be included in all copies
25
- // or substantial portions of the Software.
26
- //
27
- // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
28
- // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29
- // PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
31
- // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
32
- // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
-
34
- const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/
35
- const STACKTRACE_FRAME_LIMIT = 50
36
-
37
- const UNKNOWN_FUNCTION = '?'
38
-
39
- /** Node Stack line parser */
40
- export function node(getModule?: GetModuleFn): StackLineParserFn {
41
- const FILENAME_MATCH = /^\s*[-]{4,}$/
42
- const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/
43
-
44
- return (line: string) => {
45
- const lineMatch = line.match(FULL_MATCH)
46
-
47
- if (lineMatch) {
48
- let object: string | undefined
49
- let method: string | undefined
50
- let functionName: string | undefined
51
- let typeName: string | undefined
52
- let methodName: string | undefined
53
-
54
- if (lineMatch[1]) {
55
- functionName = lineMatch[1]
56
-
57
- let methodStart = functionName.lastIndexOf('.')
58
- if (functionName[methodStart - 1] === '.') {
59
- methodStart--
60
- }
61
-
62
- if (methodStart > 0) {
63
- object = functionName.slice(0, methodStart)
64
- method = functionName.slice(methodStart + 1)
65
- const objectEnd = object.indexOf('.Module')
66
- if (objectEnd > 0) {
67
- functionName = functionName.slice(objectEnd + 1)
68
- object = object.slice(0, objectEnd)
69
- }
70
- }
71
- typeName = undefined
72
- }
73
-
74
- if (method) {
75
- typeName = object
76
- methodName = method
77
- }
78
-
79
- if (method === '<anonymous>') {
80
- methodName = undefined
81
- functionName = undefined
82
- }
83
-
84
- if (functionName === undefined) {
85
- methodName = methodName || UNKNOWN_FUNCTION
86
- functionName = typeName ? `${typeName}.${methodName}` : methodName
87
- }
88
-
89
- let filename = lineMatch[2]?.startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2]
90
- const isNative = lineMatch[5] === 'native'
91
-
92
- // If it's a Windows path, trim the leading slash so that `/C:/foo` becomes `C:/foo`
93
- if (filename?.match(/\/[A-Z]:/)) {
94
- filename = filename.slice(1)
95
- }
96
-
97
- if (!filename && lineMatch[5] && !isNative) {
98
- filename = lineMatch[5]
99
- }
100
-
101
- return {
102
- filename: filename ? decodeURI(filename) : undefined,
103
- module: getModule ? getModule(filename) : undefined,
104
- function: functionName,
105
- lineno: _parseIntOrUndefined(lineMatch[3]),
106
- colno: _parseIntOrUndefined(lineMatch[4]),
107
- in_app: filenameIsInApp(filename || '', isNative),
108
- platform: 'node:javascript',
109
- }
110
- }
111
-
112
- if (line.match(FILENAME_MATCH)) {
113
- return {
114
- filename: line,
115
- platform: 'node:javascript',
116
- }
117
- }
118
-
119
- return undefined
120
- }
121
- }
122
-
123
- /**
124
- * Does this filename look like it's part of the app code?
125
- */
126
- export function filenameIsInApp(filename: string, isNative: boolean = false): boolean {
127
- const isInternal =
128
- isNative ||
129
- (filename &&
130
- // It's not internal if it's an absolute linux path
131
- !filename.startsWith('/') &&
132
- // It's not internal if it's an absolute windows path
133
- !filename.match(/^[A-Z]:/) &&
134
- // It's not internal if the path is starting with a dot
135
- !filename.startsWith('.') &&
136
- // It's not internal if the frame has a protocol. In node, this is usually the case if the file got pre-processed with a bundler like webpack
137
- !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)) // Schema from: https://stackoverflow.com/a/3641782
138
-
139
- // in_app is all that's not an internal Node function or a module within node_modules
140
- // note that isNative appears to return true even for node core libraries
141
- // see https://github.com/getsentry/raven-node/issues/176
142
-
143
- return !isInternal && filename !== undefined && !filename.includes('node_modules/')
144
- }
145
-
146
- function _parseIntOrUndefined(input: string | undefined): number | undefined {
147
- return parseInt(input || '', 10) || undefined
148
- }
149
-
150
- export function nodeStackLineParser(getModule?: GetModuleFn): StackLineParser {
151
- return [90, node(getModule)]
152
- }
153
-
154
- export const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(createGetModuleFromFilename()))
155
-
156
- /** Creates a function that gets the module name from a filename */
157
- export function createGetModuleFromFilename(
158
- basePath: string = process.argv[1] ? dirname(process.argv[1]) : process.cwd(),
159
- isWindows: boolean = sep === '\\'
160
- ): (filename: string | undefined) => string | undefined {
161
- const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath
162
-
163
- return (filename: string | undefined) => {
164
- if (!filename) {
165
- return
166
- }
167
-
168
- const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename
169
-
170
- // eslint-disable-next-line prefer-const
171
- let { dir, base: file, ext } = posix.parse(normalizedFilename)
172
-
173
- if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
174
- file = file.slice(0, ext.length * -1)
175
- }
176
-
177
- // The file name might be URI-encoded which we want to decode to
178
- // the original file name.
179
- const decodedFile = decodeURIComponent(file)
180
-
181
- if (!dir) {
182
- // No dirname whatsoever
183
- dir = '.'
184
- }
185
-
186
- const n = dir.lastIndexOf('/node_modules')
187
- if (n > -1) {
188
- return `${dir.slice(n + 14).replace(/\//g, '.')}:${decodedFile}`
189
- }
190
-
191
- // Let's see if it's a part of the main module
192
- // To be a part of main module, it has to share the same base
193
- if (dir.startsWith(normalizedBase)) {
194
- const moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, '.')
195
- return moduleName ? `${moduleName}:${decodedFile}` : decodedFile
196
- }
197
-
198
- return decodedFile
199
- }
200
- }
201
-
202
- /** normalizes Windows paths */
203
- function normalizeWindowsPath(path: string): string {
204
- return path
205
- .replace(/^[A-Z]:/, '') // remove Windows-style prefix
206
- .replace(/\\/g, '/') // replace all `\` instances with `/`
207
- }
208
-
209
- export function createStackParser(...parsers: StackLineParser[]): StackParser {
210
- const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map((p) => p[1])
211
-
212
- return (stack: string, skipFirstLines: number = 0): StackFrame[] => {
213
- const frames: StackFrame[] = []
214
- const lines = stack.split('\n')
215
-
216
- for (let i = skipFirstLines; i < lines.length; i++) {
217
- const line = lines[i] as string
218
- // Ignore lines over 1kb as they are unlikely to be stack frames.
219
- if (line.length > 1024) {
220
- continue
221
- }
222
-
223
- // https://github.com/getsentry/sentry-javascript/issues/5459
224
- // Remove webpack (error: *) wrappers
225
- const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, '$1') : line
226
-
227
- // https://github.com/getsentry/sentry-javascript/issues/7813
228
- // Skip Error: lines
229
- if (cleanedLine.match(/\S*Error: /)) {
230
- continue
231
- }
232
-
233
- for (const parser of sortedParsers) {
234
- const frame = parser(cleanedLine)
235
-
236
- if (frame) {
237
- frames.push(frame)
238
- break
239
- }
240
- }
241
-
242
- if (frames.length >= STACKTRACE_FRAME_LIMIT) {
243
- break
244
- }
245
- }
246
-
247
- return reverseAndStripFrames(frames)
248
- }
249
- }
250
-
251
- export function reverseAndStripFrames(stack: ReadonlyArray<StackFrame>): StackFrame[] {
252
- if (!stack.length) {
253
- return []
254
- }
255
-
256
- const localStack = Array.from(stack)
257
-
258
- localStack.reverse()
259
-
260
- return localStack.slice(0, STACKTRACE_FRAME_LIMIT).map((frame) => ({
261
- ...frame,
262
- filename: frame.filename || getLastStackFrame(localStack).filename,
263
- function: frame.function || UNKNOWN_FUNCTION,
264
- }))
265
- }
266
-
267
- function getLastStackFrame(arr: StackFrame[]): StackFrame {
268
- return arr[arr.length - 1] || {}
269
- }
@@ -1,40 +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 { PolymorphicEvent } from './types'
5
-
6
- export function isEvent(candidate: unknown): candidate is PolymorphicEvent {
7
- return typeof Event !== 'undefined' && isInstanceOf(candidate, Event)
8
- }
9
-
10
- export function isPlainObject(candidate: unknown): candidate is Record<string, unknown> {
11
- return isBuiltin(candidate, 'Object')
12
- }
13
-
14
- export function isError(candidate: unknown): candidate is Error {
15
- switch (Object.prototype.toString.call(candidate)) {
16
- case '[object Error]':
17
- case '[object Exception]':
18
- case '[object DOMException]':
19
- case '[object WebAssembly.Exception]':
20
- return true
21
- default:
22
- return isInstanceOf(candidate, Error)
23
- }
24
- }
25
-
26
- export function isInstanceOf(candidate: unknown, base: any): boolean {
27
- try {
28
- return candidate instanceof base
29
- } catch {
30
- return false
31
- }
32
- }
33
-
34
- export function isErrorEvent(event: unknown): boolean {
35
- return isBuiltin(event, 'ErrorEvent')
36
- }
37
-
38
- export function isBuiltin(candidate: unknown, className: string): boolean {
39
- return Object.prototype.toString.call(candidate) === `[object ${className}]`
40
- }
@@ -1,65 +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
- // levels originally copied from Sentry to work with the sentry integration
5
- // and to avoid relying on a frequently changing @sentry/types dependency
6
- // but provided as an array of literal types, so we can constrain the level below
7
- export const severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const
8
- export declare type SeverityLevel = (typeof severityLevels)[number]
9
-
10
- export interface PolymorphicEvent {
11
- [key: string]: unknown
12
- readonly type: string
13
- readonly target?: unknown
14
- readonly currentTarget?: unknown
15
- }
16
-
17
- export interface EventHint {
18
- mechanism?: Partial<Mechanism>
19
- syntheticException?: Error | null
20
- }
21
-
22
- export interface ErrorProperties {
23
- $exception_list: Exception[]
24
- $exception_level?: SeverityLevel
25
- $exception_DOMException_code?: string
26
- $exception_personURL?: string
27
- }
28
-
29
- export interface Exception {
30
- type?: string
31
- value?: string
32
- mechanism?: Mechanism
33
- module?: string
34
- thread_id?: number
35
- stacktrace?: { frames?: StackFrame[]; type: 'raw' }
36
- }
37
-
38
- export interface Mechanism {
39
- handled?: boolean
40
- type?: string
41
- source?: string
42
- synthetic?: boolean
43
- }
44
-
45
- export type StackParser = (stack: string, skipFirstLines?: number) => StackFrame[]
46
- export type StackLineParserFn = (line: string) => StackFrame | undefined
47
- export type StackLineParser = [number, StackLineParserFn]
48
-
49
- export interface StackFrame {
50
- platform: string
51
- filename?: string
52
- function?: string
53
- module?: string
54
- lineno?: number
55
- colno?: number
56
- abs_path?: string
57
- context_line?: string
58
- pre_context?: string[]
59
- post_context?: string[]
60
- in_app?: boolean
61
- instruction_addr?: string
62
- addr_mode?: string
63
- vars?: { [key: string]: any }
64
- debug_id?: string
65
- }