posthog-node 5.13.4 → 5.14.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/README.md +1 -1
- package/dist/extensions/express.d.ts +3 -3
- package/dist/extensions/express.d.ts.map +1 -1
- package/dist/extensions/express.js +21 -7
- package/dist/extensions/express.mjs +21 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +6 -5
- package/src/extensions/express.ts +28 -12
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type * as http from 'node:http';
|
|
2
1
|
import { PostHogBackendClient } from '../client';
|
|
3
|
-
type
|
|
4
|
-
type
|
|
2
|
+
import type { Request, Response } from 'express';
|
|
3
|
+
type ExpressMiddleware = (req: Request, res: Response, next: () => void) => void;
|
|
4
|
+
type ExpressErrorMiddleware = (error: MiddlewareError, req: Request, res: Response, next: (error: MiddlewareError) => void) => void;
|
|
5
5
|
interface MiddlewareError extends Error {
|
|
6
6
|
status?: number | string;
|
|
7
7
|
statusCode?: number | string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/extensions/express.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/extensions/express.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEhD,KAAK,iBAAiB,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAEhF,KAAK,sBAAsB,GAAG,CAC5B,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,KACnC,IAAI,CAAA;AAET,UAAU,eAAgB,SAAQ,KAAK;IACrC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,MAAM,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC7B,CAAA;CACF;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,EAAE;IACH,GAAG,EAAE,CAAC,UAAU,EAAE,iBAAiB,GAAG,sBAAsB,KAAK,OAAO,CAAA;CACzE,GACA,IAAI,CAEN"}
|
|
@@ -35,22 +35,36 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
setupExpressErrorHandler: ()=>setupExpressErrorHandler
|
|
37
37
|
});
|
|
38
|
-
const core_namespaceObject = require("@posthog/core");
|
|
39
38
|
const index_js_namespaceObject = require("./error-tracking/index.js");
|
|
40
39
|
var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
|
|
41
40
|
function setupExpressErrorHandler(_posthog, app) {
|
|
42
|
-
app.use((
|
|
41
|
+
app.use(posthogErrorHandler(_posthog));
|
|
42
|
+
}
|
|
43
|
+
function posthogErrorHandler(posthog) {
|
|
44
|
+
return (error, req, res, next)=>{
|
|
45
|
+
const sessionId = req.headers['x-posthog-session-id'];
|
|
46
|
+
const distinctId = req.headers['x-posthog-distinct-id'];
|
|
47
|
+
const syntheticException = new Error('Synthetic exception');
|
|
43
48
|
const hint = {
|
|
44
49
|
mechanism: {
|
|
45
50
|
type: 'middleware',
|
|
46
51
|
handled: false
|
|
47
|
-
}
|
|
52
|
+
},
|
|
53
|
+
syntheticException
|
|
48
54
|
};
|
|
49
|
-
index_js_default().buildEventMessage(error, hint,
|
|
50
|
-
$
|
|
51
|
-
|
|
55
|
+
posthog.addPendingPromise(index_js_default().buildEventMessage(error, hint, distinctId, {
|
|
56
|
+
$session_id: sessionId,
|
|
57
|
+
$current_url: req.url,
|
|
58
|
+
$request_method: req.method,
|
|
59
|
+
$request_path: req.path,
|
|
60
|
+
$user_agent: req.headers['user-agent'],
|
|
61
|
+
$response_status_code: res.statusCode,
|
|
62
|
+
$ip: req.headers['x-forwarded-for'] || req?.socket?.remoteAddress
|
|
63
|
+
}).then((msg)=>{
|
|
64
|
+
posthog.capture(msg);
|
|
65
|
+
}));
|
|
52
66
|
next(error);
|
|
53
|
-
}
|
|
67
|
+
};
|
|
54
68
|
}
|
|
55
69
|
exports.setupExpressErrorHandler = __webpack_exports__.setupExpressErrorHandler;
|
|
56
70
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import { uuidv7 } from "@posthog/core";
|
|
2
1
|
import error_tracking from "./error-tracking/index.mjs";
|
|
3
2
|
function setupExpressErrorHandler(_posthog, app) {
|
|
4
|
-
app.use((
|
|
3
|
+
app.use(posthogErrorHandler(_posthog));
|
|
4
|
+
}
|
|
5
|
+
function posthogErrorHandler(posthog) {
|
|
6
|
+
return (error, req, res, next)=>{
|
|
7
|
+
const sessionId = req.headers['x-posthog-session-id'];
|
|
8
|
+
const distinctId = req.headers['x-posthog-distinct-id'];
|
|
9
|
+
const syntheticException = new Error('Synthetic exception');
|
|
5
10
|
const hint = {
|
|
6
11
|
mechanism: {
|
|
7
12
|
type: 'middleware',
|
|
8
13
|
handled: false
|
|
9
|
-
}
|
|
14
|
+
},
|
|
15
|
+
syntheticException
|
|
10
16
|
};
|
|
11
|
-
error_tracking.buildEventMessage(error, hint,
|
|
12
|
-
$
|
|
13
|
-
|
|
17
|
+
posthog.addPendingPromise(error_tracking.buildEventMessage(error, hint, distinctId, {
|
|
18
|
+
$session_id: sessionId,
|
|
19
|
+
$current_url: req.url,
|
|
20
|
+
$request_method: req.method,
|
|
21
|
+
$request_path: req.path,
|
|
22
|
+
$user_agent: req.headers['user-agent'],
|
|
23
|
+
$response_status_code: res.statusCode,
|
|
24
|
+
$ip: req.headers['x-forwarded-for'] || req?.socket?.remoteAddress
|
|
25
|
+
}).then((msg)=>{
|
|
26
|
+
posthog.capture(msg);
|
|
27
|
+
}));
|
|
14
28
|
next(error);
|
|
15
|
-
}
|
|
29
|
+
};
|
|
16
30
|
}
|
|
17
31
|
export { setupExpressErrorHandler };
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.14.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
version: ()=>version
|
|
28
28
|
});
|
|
29
|
-
const version = '5.
|
|
29
|
+
const version = '5.14.1';
|
|
30
30
|
exports.version = __webpack_exports__.version;
|
|
31
31
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
32
32
|
"version"
|
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '5.
|
|
1
|
+
const version = '5.14.1';
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.14.1",
|
|
4
4
|
"description": "PostHog Node.js integration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,14 +25,15 @@
|
|
|
25
25
|
"module": "dist/entrypoints/index.node.mjs",
|
|
26
26
|
"types": "dist/entrypoints/index.node.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@posthog/core": "1.
|
|
28
|
+
"@posthog/core": "1.6.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@rslib/core": "0.10.6",
|
|
32
|
+
"@types/express": "^5.0.5",
|
|
33
|
+
"@types/jest": "^29.5.14",
|
|
31
34
|
"@types/node": "^20.0.0",
|
|
32
35
|
"jest": "29.7.0",
|
|
33
|
-
"@
|
|
34
|
-
"@rslib/core": "0.10.6",
|
|
35
|
-
"@posthog-tooling/tsconfig-base": "1.0.0"
|
|
36
|
+
"@posthog-tooling/tsconfig-base": "1.1.0"
|
|
36
37
|
},
|
|
37
38
|
"keywords": [
|
|
38
39
|
"posthog",
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type * as http from 'node:http'
|
|
2
|
-
import { uuidv7 } from '@posthog/core'
|
|
3
1
|
import ErrorTracking from './error-tracking'
|
|
4
2
|
import { PostHogBackendClient } from '../client'
|
|
5
3
|
import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
|
|
4
|
+
import type { Request, Response } from 'express'
|
|
6
5
|
|
|
7
|
-
type ExpressMiddleware = (req:
|
|
6
|
+
type ExpressMiddleware = (req: Request, res: Response, next: () => void) => void
|
|
8
7
|
|
|
9
8
|
type ExpressErrorMiddleware = (
|
|
10
9
|
error: MiddlewareError,
|
|
11
|
-
req:
|
|
12
|
-
res:
|
|
10
|
+
req: Request,
|
|
11
|
+
res: Response,
|
|
13
12
|
next: (error: MiddlewareError) => void
|
|
14
13
|
) => void
|
|
15
14
|
|
|
@@ -28,13 +27,30 @@ export function setupExpressErrorHandler(
|
|
|
28
27
|
use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown
|
|
29
28
|
}
|
|
30
29
|
): void {
|
|
31
|
-
app.use((
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
app.use(posthogErrorHandler(_posthog))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function posthogErrorHandler(posthog: PostHogBackendClient): ExpressErrorMiddleware {
|
|
34
|
+
return (error: MiddlewareError, req, res, next: (error: MiddlewareError) => void): void => {
|
|
35
|
+
const sessionId: string | undefined = req.headers['x-posthog-session-id'] as string | undefined
|
|
36
|
+
const distinctId: string | undefined = req.headers['x-posthog-distinct-id'] as string | undefined
|
|
37
|
+
const syntheticException = new Error('Synthetic exception')
|
|
38
|
+
const hint: CoreErrorTracking.EventHint = { mechanism: { type: 'middleware', handled: false }, syntheticException }
|
|
39
|
+
|
|
40
|
+
posthog.addPendingPromise(
|
|
41
|
+
ErrorTracking.buildEventMessage(error, hint, distinctId, {
|
|
42
|
+
$session_id: sessionId,
|
|
43
|
+
$current_url: req.url,
|
|
44
|
+
$request_method: req.method,
|
|
45
|
+
$request_path: req.path,
|
|
46
|
+
$user_agent: req.headers['user-agent'],
|
|
47
|
+
$response_status_code: res.statusCode,
|
|
48
|
+
$ip: req.headers['x-forwarded-for'] || req?.socket?.remoteAddress,
|
|
49
|
+
}).then((msg) => {
|
|
50
|
+
posthog.capture(msg)
|
|
51
|
+
})
|
|
37
52
|
)
|
|
53
|
+
|
|
38
54
|
next(error)
|
|
39
|
-
}
|
|
55
|
+
}
|
|
40
56
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.14.1'
|