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.
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -2
- package/dist/client.mjs +1 -2
- package/dist/entrypoints/index.edge.d.ts.map +1 -1
- package/dist/entrypoints/index.edge.js +12 -5
- package/dist/entrypoints/index.edge.mjs +10 -3
- package/dist/entrypoints/index.node.d.ts.map +1 -1
- package/dist/entrypoints/index.node.js +23 -15
- package/dist/entrypoints/index.node.mjs +14 -6
- package/dist/extensions/error-tracking/autocapture.d.ts +3 -3
- package/dist/extensions/error-tracking/autocapture.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.d.ts +3 -4
- package/dist/extensions/error-tracking/index.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.js +3 -3
- package/dist/extensions/error-tracking/index.mjs +3 -3
- package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts +5 -0
- package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts.map +1 -0
- package/dist/extensions/error-tracking/{context-lines.node.js → modifiers/context-lines.node.js} +3 -3
- package/dist/extensions/error-tracking/{context-lines.node.mjs → modifiers/context-lines.node.mjs} +3 -3
- package/dist/extensions/error-tracking/modifiers/module.node.d.ts +3 -0
- package/dist/extensions/error-tracking/modifiers/module.node.d.ts.map +1 -0
- package/dist/extensions/error-tracking/{get-module.node.js → modifiers/module.node.js} +10 -3
- package/dist/extensions/error-tracking/{get-module.node.mjs → modifiers/module.node.mjs} +8 -1
- package/dist/extensions/express.d.ts.map +1 -1
- package/dist/extensions/sentry-integration.d.ts +3 -3
- package/dist/extensions/sentry-integration.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +2 -2
- package/src/client.ts +1 -1
- package/src/entrypoints/index.edge.ts +11 -4
- package/src/entrypoints/index.node.ts +14 -5
- package/src/extensions/error-tracking/autocapture.ts +6 -4
- package/src/extensions/error-tracking/index.ts +10 -9
- package/src/extensions/error-tracking/{context-lines.node.ts → modifiers/context-lines.node.ts} +23 -11
- package/src/extensions/error-tracking/{get-module.node.ts → modifiers/module.node.ts} +12 -1
- package/src/extensions/express.ts +2 -1
- package/src/extensions/sentry-integration.ts +4 -4
- package/src/version.ts +1 -1
- package/dist/extensions/error-tracking/chunk-ids.d.ts +0 -5
- package/dist/extensions/error-tracking/chunk-ids.d.ts.map +0 -1
- package/dist/extensions/error-tracking/chunk-ids.js +0 -68
- package/dist/extensions/error-tracking/chunk-ids.mjs +0 -34
- package/dist/extensions/error-tracking/context-lines.node.d.ts +0 -5
- package/dist/extensions/error-tracking/context-lines.node.d.ts.map +0 -1
- package/dist/extensions/error-tracking/error-conversion.d.ts +0 -4
- package/dist/extensions/error-tracking/error-conversion.d.ts.map +0 -1
- package/dist/extensions/error-tracking/error-conversion.js +0 -183
- package/dist/extensions/error-tracking/error-conversion.mjs +0 -146
- package/dist/extensions/error-tracking/get-module.node.d.ts +0 -3
- package/dist/extensions/error-tracking/get-module.node.d.ts.map +0 -1
- package/dist/extensions/error-tracking/reduceable-cache.d.ts +0 -13
- package/dist/extensions/error-tracking/reduceable-cache.d.ts.map +0 -1
- package/dist/extensions/error-tracking/reduceable-cache.js +0 -57
- package/dist/extensions/error-tracking/reduceable-cache.mjs +0 -23
- package/dist/extensions/error-tracking/stack-parser.d.ts +0 -3
- package/dist/extensions/error-tracking/stack-parser.d.ts.map +0 -1
- package/dist/extensions/error-tracking/stack-parser.js +0 -148
- package/dist/extensions/error-tracking/stack-parser.mjs +0 -114
- package/dist/extensions/error-tracking/type-checking.d.ts +0 -8
- package/dist/extensions/error-tracking/type-checking.d.ts.map +0 -1
- package/dist/extensions/error-tracking/type-checking.js +0 -80
- package/dist/extensions/error-tracking/type-checking.mjs +0 -31
- package/dist/extensions/error-tracking/types.d.ts +0 -61
- package/dist/extensions/error-tracking/types.d.ts.map +0 -1
- package/dist/extensions/error-tracking/types.js +0 -43
- package/dist/extensions/error-tracking/types.mjs +0 -9
- package/src/extensions/error-tracking/chunk-ids.ts +0 -58
- package/src/extensions/error-tracking/error-conversion.ts +0 -291
- package/src/extensions/error-tracking/reduceable-cache.ts +0 -39
- package/src/extensions/error-tracking/stack-parser.ts +0 -212
- package/src/extensions/error-tracking/type-checking.ts +0 -40
- package/src/extensions/error-tracking/types.ts +0 -71
|
@@ -1,212 +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 { GetModuleFn, StackFrame, StackLineParser, StackLineParserFn, StackParser } from './types'
|
|
5
|
-
|
|
6
|
-
// This was originally forked from https://github.com/csnover/TraceKit, and was largely
|
|
7
|
-
// re-written as part of raven - js.
|
|
8
|
-
//
|
|
9
|
-
// This code was later copied to the JavaScript mono - repo and further modified and
|
|
10
|
-
// refactored over the years.
|
|
11
|
-
|
|
12
|
-
// Copyright (c) 2013 Onur Can Cakmak onur.cakmak@gmail.com and all TraceKit contributors.
|
|
13
|
-
//
|
|
14
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
15
|
-
// software and associated documentation files(the 'Software'), to deal in the Software
|
|
16
|
-
// without restriction, including without limitation the rights to use, copy, modify,
|
|
17
|
-
// merge, publish, distribute, sublicense, and / or sell copies of the Software, and to
|
|
18
|
-
// permit persons to whom the Software is furnished to do so, subject to the following
|
|
19
|
-
// conditions:
|
|
20
|
-
//
|
|
21
|
-
// The above copyright notice and this permission notice shall be included in all copies
|
|
22
|
-
// or substantial portions of the Software.
|
|
23
|
-
//
|
|
24
|
-
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
25
|
-
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
26
|
-
// PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
27
|
-
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
28
|
-
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
29
|
-
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
-
|
|
31
|
-
const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/
|
|
32
|
-
const STACKTRACE_FRAME_LIMIT = 50
|
|
33
|
-
|
|
34
|
-
const UNKNOWN_FUNCTION = '?'
|
|
35
|
-
|
|
36
|
-
/** Node Stack line parser */
|
|
37
|
-
function node(getModule?: GetModuleFn): StackLineParserFn {
|
|
38
|
-
const FILENAME_MATCH = /^\s*[-]{4,}$/
|
|
39
|
-
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/
|
|
40
|
-
|
|
41
|
-
return (line: string) => {
|
|
42
|
-
const lineMatch = line.match(FULL_MATCH)
|
|
43
|
-
|
|
44
|
-
if (lineMatch) {
|
|
45
|
-
let object: string | undefined
|
|
46
|
-
let method: string | undefined
|
|
47
|
-
let functionName: string | undefined
|
|
48
|
-
let typeName: string | undefined
|
|
49
|
-
let methodName: string | undefined
|
|
50
|
-
|
|
51
|
-
if (lineMatch[1]) {
|
|
52
|
-
functionName = lineMatch[1]
|
|
53
|
-
|
|
54
|
-
let methodStart = functionName.lastIndexOf('.')
|
|
55
|
-
if (functionName[methodStart - 1] === '.') {
|
|
56
|
-
methodStart--
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (methodStart > 0) {
|
|
60
|
-
object = functionName.slice(0, methodStart)
|
|
61
|
-
method = functionName.slice(methodStart + 1)
|
|
62
|
-
const objectEnd = object.indexOf('.Module')
|
|
63
|
-
if (objectEnd > 0) {
|
|
64
|
-
functionName = functionName.slice(objectEnd + 1)
|
|
65
|
-
object = object.slice(0, objectEnd)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
typeName = undefined
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (method) {
|
|
72
|
-
typeName = object
|
|
73
|
-
methodName = method
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (method === '<anonymous>') {
|
|
77
|
-
methodName = undefined
|
|
78
|
-
functionName = undefined
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (functionName === undefined) {
|
|
82
|
-
methodName = methodName || UNKNOWN_FUNCTION
|
|
83
|
-
functionName = typeName ? `${typeName}.${methodName}` : methodName
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let filename = lineMatch[2]?.startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2]
|
|
87
|
-
const isNative = lineMatch[5] === 'native'
|
|
88
|
-
|
|
89
|
-
// If it's a Windows path, trim the leading slash so that `/C:/foo` becomes `C:/foo`
|
|
90
|
-
if (filename?.match(/\/[A-Z]:/)) {
|
|
91
|
-
filename = filename.slice(1)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!filename && lineMatch[5] && !isNative) {
|
|
95
|
-
filename = lineMatch[5]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
filename: filename ? decodeURI(filename) : undefined,
|
|
100
|
-
module: getModule ? getModule(filename) : undefined,
|
|
101
|
-
function: functionName,
|
|
102
|
-
lineno: _parseIntOrUndefined(lineMatch[3]),
|
|
103
|
-
colno: _parseIntOrUndefined(lineMatch[4]),
|
|
104
|
-
in_app: filenameIsInApp(filename || '', isNative),
|
|
105
|
-
platform: 'node:javascript',
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (line.match(FILENAME_MATCH)) {
|
|
110
|
-
return {
|
|
111
|
-
filename: line,
|
|
112
|
-
platform: 'node:javascript',
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return undefined
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Does this filename look like it's part of the app code?
|
|
122
|
-
*/
|
|
123
|
-
function filenameIsInApp(filename: string, isNative: boolean = false): boolean {
|
|
124
|
-
const isInternal =
|
|
125
|
-
isNative ||
|
|
126
|
-
(filename &&
|
|
127
|
-
// It's not internal if it's an absolute linux path
|
|
128
|
-
!filename.startsWith('/') &&
|
|
129
|
-
// It's not internal if it's an absolute windows path
|
|
130
|
-
!filename.match(/^[A-Z]:/) &&
|
|
131
|
-
// It's not internal if the path is starting with a dot
|
|
132
|
-
!filename.startsWith('.') &&
|
|
133
|
-
// 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
|
|
134
|
-
!filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)) // Schema from: https://stackoverflow.com/a/3641782
|
|
135
|
-
|
|
136
|
-
// in_app is all that's not an internal Node function or a module within node_modules
|
|
137
|
-
// note that isNative appears to return true even for node core libraries
|
|
138
|
-
// see https://github.com/getsentry/raven-node/issues/176
|
|
139
|
-
|
|
140
|
-
return !isInternal && filename !== undefined && !filename.includes('node_modules/')
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function _parseIntOrUndefined(input: string | undefined): number | undefined {
|
|
144
|
-
return parseInt(input || '', 10) || undefined
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function nodeStackLineParser(getModule?: GetModuleFn): StackLineParser {
|
|
148
|
-
return [90, node(getModule)]
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function createStackParser(getModule?: GetModuleFn): StackParser {
|
|
152
|
-
const parsers = [nodeStackLineParser(getModule)]
|
|
153
|
-
const sortedParsers = parsers.sort((a, b) => a[0] - b[0]).map((p) => p[1])
|
|
154
|
-
|
|
155
|
-
return (stack: string, skipFirstLines: number = 0): StackFrame[] => {
|
|
156
|
-
const frames: StackFrame[] = []
|
|
157
|
-
const lines = stack.split('\n')
|
|
158
|
-
|
|
159
|
-
for (let i = skipFirstLines; i < lines.length; i++) {
|
|
160
|
-
const line = lines[i] as string
|
|
161
|
-
// Ignore lines over 1kb as they are unlikely to be stack frames.
|
|
162
|
-
if (line.length > 1024) {
|
|
163
|
-
continue
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// https://github.com/getsentry/sentry-javascript/issues/5459
|
|
167
|
-
// Remove webpack (error: *) wrappers
|
|
168
|
-
const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, '$1') : line
|
|
169
|
-
|
|
170
|
-
// https://github.com/getsentry/sentry-javascript/issues/7813
|
|
171
|
-
// Skip Error: lines
|
|
172
|
-
if (cleanedLine.match(/\S*Error: /)) {
|
|
173
|
-
continue
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
for (const parser of sortedParsers) {
|
|
177
|
-
const frame = parser(cleanedLine)
|
|
178
|
-
|
|
179
|
-
if (frame) {
|
|
180
|
-
frames.push(frame)
|
|
181
|
-
break
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (frames.length >= STACKTRACE_FRAME_LIMIT) {
|
|
186
|
-
break
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return reverseAndStripFrames(frames)
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function reverseAndStripFrames(stack: ReadonlyArray<StackFrame>): StackFrame[] {
|
|
195
|
-
if (!stack.length) {
|
|
196
|
-
return []
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const localStack = Array.from(stack)
|
|
200
|
-
|
|
201
|
-
localStack.reverse()
|
|
202
|
-
|
|
203
|
-
return localStack.slice(0, STACKTRACE_FRAME_LIMIT).map((frame) => ({
|
|
204
|
-
...frame,
|
|
205
|
-
filename: frame.filename || getLastStackFrame(localStack).filename,
|
|
206
|
-
function: frame.function || UNKNOWN_FUNCTION,
|
|
207
|
-
}))
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function getLastStackFrame(arr: StackFrame[]): StackFrame {
|
|
211
|
-
return arr[arr.length - 1] || {}
|
|
212
|
-
}
|
|
@@ -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,71 +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 { JsonType } from '@posthog/core'
|
|
5
|
-
|
|
6
|
-
// levels originally copied from Sentry to work with the sentry integration
|
|
7
|
-
// and to avoid relying on a frequently changing @sentry/types dependency
|
|
8
|
-
// but provided as an array of literal types, so we can constrain the level below
|
|
9
|
-
export const severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const
|
|
10
|
-
export declare type SeverityLevel = (typeof severityLevels)[number]
|
|
11
|
-
|
|
12
|
-
export interface PolymorphicEvent {
|
|
13
|
-
[key: string]: unknown
|
|
14
|
-
readonly type: string
|
|
15
|
-
readonly target?: unknown
|
|
16
|
-
readonly currentTarget?: unknown
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface EventHint {
|
|
20
|
-
mechanism?: Partial<Mechanism>
|
|
21
|
-
syntheticException?: Error | null
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ErrorProperties {
|
|
25
|
-
$exception_list: Exception[]
|
|
26
|
-
$exception_level?: SeverityLevel
|
|
27
|
-
$exception_DOMException_code?: string
|
|
28
|
-
$exception_personURL?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface Exception {
|
|
32
|
-
type?: string
|
|
33
|
-
value?: string
|
|
34
|
-
mechanism?: Mechanism
|
|
35
|
-
module?: string
|
|
36
|
-
thread_id?: number
|
|
37
|
-
stacktrace?: { frames?: StackFrame[]; type: 'raw' }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface Mechanism {
|
|
41
|
-
handled?: boolean
|
|
42
|
-
type?: string
|
|
43
|
-
source?: string
|
|
44
|
-
synthetic?: boolean
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type GetModuleFn = (filename: string | undefined) => string | undefined
|
|
48
|
-
|
|
49
|
-
export type StackParser = (stack: string, skipFirstLines?: number) => StackFrame[]
|
|
50
|
-
export type StackLineParserFn = (line: string) => StackFrame | undefined
|
|
51
|
-
export type StackLineParser = [number, StackLineParserFn]
|
|
52
|
-
|
|
53
|
-
export type StackFrameModifierFn = (frames: StackFrame[]) => Promise<StackFrame[]>
|
|
54
|
-
|
|
55
|
-
export interface StackFrame {
|
|
56
|
-
platform: string
|
|
57
|
-
filename?: string
|
|
58
|
-
function?: string
|
|
59
|
-
module?: string
|
|
60
|
-
lineno?: number
|
|
61
|
-
colno?: number
|
|
62
|
-
abs_path?: string
|
|
63
|
-
context_line?: string
|
|
64
|
-
pre_context?: string[]
|
|
65
|
-
post_context?: string[]
|
|
66
|
-
in_app?: boolean
|
|
67
|
-
instruction_addr?: string
|
|
68
|
-
addr_mode?: string
|
|
69
|
-
vars?: { [key: string]: JsonType }
|
|
70
|
-
chunk_id?: string
|
|
71
|
-
}
|