posthog-node 5.8.8 → 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 (99) hide show
  1. package/dist/{index.d.ts → client.d.ts} +7 -378
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +480 -0
  4. package/dist/client.mjs +436 -0
  5. package/dist/entrypoints/index.edge.d.ts +6 -0
  6. package/dist/entrypoints/index.edge.d.ts.map +1 -0
  7. package/dist/entrypoints/index.edge.js +96 -0
  8. package/dist/entrypoints/index.edge.mjs +19 -0
  9. package/dist/entrypoints/index.node.d.ts +6 -0
  10. package/dist/entrypoints/index.node.d.ts.map +1 -0
  11. package/dist/entrypoints/index.node.js +107 -0
  12. package/dist/entrypoints/index.node.mjs +24 -0
  13. package/dist/exports.d.ts +4 -0
  14. package/dist/exports.d.ts.map +1 -0
  15. package/dist/exports.js +78 -0
  16. package/dist/exports.mjs +3 -0
  17. package/dist/extensions/error-tracking/autocapture.d.ts +4 -0
  18. package/dist/extensions/error-tracking/autocapture.d.ts.map +1 -0
  19. package/dist/extensions/error-tracking/autocapture.js +68 -0
  20. package/dist/extensions/error-tracking/autocapture.mjs +31 -0
  21. package/dist/extensions/error-tracking/index.d.ts +19 -0
  22. package/dist/extensions/error-tracking/index.d.ts.map +1 -0
  23. package/dist/extensions/error-tracking/index.js +97 -0
  24. package/dist/extensions/error-tracking/index.mjs +63 -0
  25. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts +5 -0
  26. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts.map +1 -0
  27. package/dist/extensions/error-tracking/modifiers/context-lines.node.js +227 -0
  28. package/dist/extensions/error-tracking/modifiers/context-lines.node.mjs +187 -0
  29. package/dist/extensions/error-tracking/modifiers/module.node.d.ts +3 -0
  30. package/dist/extensions/error-tracking/modifiers/module.node.d.ts.map +1 -0
  31. package/dist/extensions/error-tracking/modifiers/module.node.js +64 -0
  32. package/dist/extensions/error-tracking/modifiers/module.node.mjs +30 -0
  33. package/dist/extensions/express.d.ts +17 -0
  34. package/dist/extensions/express.d.ts.map +1 -0
  35. package/dist/extensions/express.js +61 -0
  36. package/dist/extensions/express.mjs +17 -0
  37. package/dist/extensions/feature-flags/crypto-helpers.d.ts +3 -0
  38. package/dist/extensions/feature-flags/crypto-helpers.d.ts.map +1 -0
  39. package/dist/extensions/feature-flags/crypto-helpers.js +77 -0
  40. package/dist/extensions/feature-flags/crypto-helpers.mjs +22 -0
  41. package/dist/extensions/feature-flags/crypto.d.ts +2 -0
  42. package/dist/extensions/feature-flags/crypto.d.ts.map +1 -0
  43. package/dist/extensions/feature-flags/crypto.js +47 -0
  44. package/dist/extensions/feature-flags/crypto.mjs +13 -0
  45. package/dist/extensions/feature-flags/feature-flags.d.ts +89 -0
  46. package/dist/extensions/feature-flags/feature-flags.d.ts.map +1 -0
  47. package/dist/extensions/feature-flags/feature-flags.js +529 -0
  48. package/dist/extensions/feature-flags/feature-flags.mjs +483 -0
  49. package/dist/extensions/feature-flags/lazy.d.ts +24 -0
  50. package/dist/extensions/feature-flags/lazy.d.ts.map +1 -0
  51. package/dist/extensions/feature-flags/lazy.js +60 -0
  52. package/dist/extensions/feature-flags/lazy.mjs +26 -0
  53. package/dist/extensions/sentry-integration.d.ts +54 -0
  54. package/dist/extensions/sentry-integration.d.ts.map +1 -0
  55. package/dist/extensions/sentry-integration.js +113 -0
  56. package/dist/extensions/sentry-integration.mjs +73 -0
  57. package/dist/storage-memory.d.ts +7 -0
  58. package/dist/storage-memory.d.ts.map +1 -0
  59. package/dist/storage-memory.js +46 -0
  60. package/dist/storage-memory.mjs +12 -0
  61. package/dist/types.d.ts +253 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +18 -0
  64. package/dist/types.mjs +0 -0
  65. package/dist/utils/logger.d.ts +3 -0
  66. package/dist/utils/logger.d.ts.map +1 -0
  67. package/dist/utils/logger.js +63 -0
  68. package/dist/utils/logger.mjs +29 -0
  69. package/dist/version.d.ts +2 -0
  70. package/dist/version.d.ts.map +1 -0
  71. package/dist/version.js +36 -0
  72. package/dist/version.mjs +2 -0
  73. package/package.json +32 -31
  74. package/src/client.ts +1532 -0
  75. package/src/entrypoints/index.edge.ts +22 -0
  76. package/src/entrypoints/index.node.ts +26 -0
  77. package/src/exports.ts +3 -0
  78. package/src/extensions/error-tracking/autocapture.ts +67 -0
  79. package/src/extensions/error-tracking/index.ts +104 -0
  80. package/src/extensions/error-tracking/modifiers/context-lines.node.ts +404 -0
  81. package/src/extensions/error-tracking/modifiers/module.node.ts +68 -0
  82. package/src/extensions/express.ts +40 -0
  83. package/src/extensions/feature-flags/crypto-helpers.ts +36 -0
  84. package/src/extensions/feature-flags/crypto.ts +22 -0
  85. package/src/extensions/feature-flags/feature-flags.ts +1003 -0
  86. package/src/extensions/feature-flags/lazy.ts +55 -0
  87. package/src/extensions/sentry-integration.ts +216 -0
  88. package/src/storage-memory.ts +13 -0
  89. package/src/types.ts +294 -0
  90. package/src/utils/logger.ts +39 -0
  91. package/src/version.ts +1 -0
  92. package/dist/edge/index.cjs +0 -3150
  93. package/dist/edge/index.cjs.map +0 -1
  94. package/dist/edge/index.mjs +0 -3144
  95. package/dist/edge/index.mjs.map +0 -1
  96. package/dist/node/index.cjs +0 -3556
  97. package/dist/node/index.cjs.map +0 -1
  98. package/dist/node/index.mjs +0 -3550
  99. package/dist/node/index.mjs.map +0 -1
@@ -0,0 +1,187 @@
1
+ import { ErrorTracking } from "@posthog/core";
2
+ import { createReadStream } from "node:fs";
3
+ import { createInterface } from "node:readline";
4
+ const LRU_FILE_CONTENTS_CACHE = new ErrorTracking.ReduceableCache(25);
5
+ const LRU_FILE_CONTENTS_FS_READ_FAILED = new ErrorTracking.ReduceableCache(20);
6
+ const DEFAULT_LINES_OF_CONTEXT = 7;
7
+ const MAX_CONTEXTLINES_COLNO = 1000;
8
+ const MAX_CONTEXTLINES_LINENO = 10000;
9
+ async function addSourceContext(frames) {
10
+ const filesToLines = {};
11
+ for(let i = frames.length - 1; i >= 0; i--){
12
+ const frame = frames[i];
13
+ const filename = frame?.filename;
14
+ if (!frame || 'string' != typeof filename || 'number' != typeof frame.lineno || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame)) continue;
15
+ const filesToLinesOutput = filesToLines[filename];
16
+ if (!filesToLinesOutput) filesToLines[filename] = [];
17
+ filesToLines[filename].push(frame.lineno);
18
+ }
19
+ const files = Object.keys(filesToLines);
20
+ if (0 == files.length) return frames;
21
+ const readlinePromises = [];
22
+ for (const file of files){
23
+ if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(file)) continue;
24
+ const filesToLineRanges = filesToLines[file];
25
+ if (!filesToLineRanges) continue;
26
+ filesToLineRanges.sort((a, b)=>a - b);
27
+ const ranges = makeLineReaderRanges(filesToLineRanges);
28
+ if (ranges.every((r)=>rangeExistsInContentCache(file, r))) continue;
29
+ const cache = emplace(LRU_FILE_CONTENTS_CACHE, file, {});
30
+ readlinePromises.push(getContextLinesFromFile(file, ranges, cache));
31
+ }
32
+ await Promise.all(readlinePromises).catch(()=>{});
33
+ if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
34
+ LRU_FILE_CONTENTS_CACHE.reduce();
35
+ return frames;
36
+ }
37
+ function getContextLinesFromFile(path, ranges, output) {
38
+ return new Promise((resolve)=>{
39
+ const stream = createReadStream(path);
40
+ const lineReaded = createInterface({
41
+ input: stream
42
+ });
43
+ function destroyStreamAndResolve() {
44
+ stream.destroy();
45
+ resolve();
46
+ }
47
+ let lineNumber = 0;
48
+ let currentRangeIndex = 0;
49
+ const range = ranges[currentRangeIndex];
50
+ if (void 0 === range) return void destroyStreamAndResolve();
51
+ let rangeStart = range[0];
52
+ let rangeEnd = range[1];
53
+ function onStreamError() {
54
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
55
+ lineReaded.close();
56
+ lineReaded.removeAllListeners();
57
+ destroyStreamAndResolve();
58
+ }
59
+ stream.on('error', onStreamError);
60
+ lineReaded.on('error', onStreamError);
61
+ lineReaded.on('close', destroyStreamAndResolve);
62
+ lineReaded.on('line', (line)=>{
63
+ lineNumber++;
64
+ if (lineNumber < rangeStart) return;
65
+ output[lineNumber] = snipLine(line, 0);
66
+ if (lineNumber >= rangeEnd) {
67
+ if (currentRangeIndex === ranges.length - 1) {
68
+ lineReaded.close();
69
+ lineReaded.removeAllListeners();
70
+ return;
71
+ }
72
+ currentRangeIndex++;
73
+ const range = ranges[currentRangeIndex];
74
+ if (void 0 === range) {
75
+ lineReaded.close();
76
+ lineReaded.removeAllListeners();
77
+ return;
78
+ }
79
+ rangeStart = range[0];
80
+ rangeEnd = range[1];
81
+ }
82
+ });
83
+ });
84
+ }
85
+ function addSourceContextToFrames(frames, cache) {
86
+ for (const frame of frames)if (frame.filename && void 0 === frame.context_line && 'number' == typeof frame.lineno) {
87
+ const contents = cache.get(frame.filename);
88
+ if (void 0 === contents) continue;
89
+ addContextToFrame(frame.lineno, frame, contents);
90
+ }
91
+ }
92
+ function addContextToFrame(lineno, frame, contents) {
93
+ if (void 0 === frame.lineno || void 0 === contents) return;
94
+ frame.pre_context = [];
95
+ for(let i = makeRangeStart(lineno); i < lineno; i++){
96
+ const line = contents[i];
97
+ if (void 0 === line) return void clearLineContext(frame);
98
+ frame.pre_context.push(line);
99
+ }
100
+ if (void 0 === contents[lineno]) return void clearLineContext(frame);
101
+ frame.context_line = contents[lineno];
102
+ const end = makeRangeEnd(lineno);
103
+ frame.post_context = [];
104
+ for(let i = lineno + 1; i <= end; i++){
105
+ const line = contents[i];
106
+ if (void 0 === line) break;
107
+ frame.post_context.push(line);
108
+ }
109
+ }
110
+ function clearLineContext(frame) {
111
+ delete frame.pre_context;
112
+ delete frame.context_line;
113
+ delete frame.post_context;
114
+ }
115
+ function shouldSkipContextLinesForFile(path) {
116
+ return path.startsWith('node:') || path.endsWith('.min.js') || path.endsWith('.min.cjs') || path.endsWith('.min.mjs') || path.startsWith('data:');
117
+ }
118
+ function shouldSkipContextLinesForFrame(frame) {
119
+ if (void 0 !== frame.lineno && frame.lineno > MAX_CONTEXTLINES_LINENO) return true;
120
+ if (void 0 !== frame.colno && frame.colno > MAX_CONTEXTLINES_COLNO) return true;
121
+ return false;
122
+ }
123
+ function rangeExistsInContentCache(file, range) {
124
+ const contents = LRU_FILE_CONTENTS_CACHE.get(file);
125
+ if (void 0 === contents) return false;
126
+ for(let i = range[0]; i <= range[1]; i++)if (void 0 === contents[i]) return false;
127
+ return true;
128
+ }
129
+ function makeLineReaderRanges(lines) {
130
+ if (!lines.length) return [];
131
+ let i = 0;
132
+ const line = lines[0];
133
+ if ('number' != typeof line) return [];
134
+ let current = makeContextRange(line);
135
+ const out = [];
136
+ while(true){
137
+ if (i === lines.length - 1) {
138
+ out.push(current);
139
+ break;
140
+ }
141
+ const next = lines[i + 1];
142
+ if ('number' != typeof next) break;
143
+ if (next <= current[1]) current[1] = next + DEFAULT_LINES_OF_CONTEXT;
144
+ else {
145
+ out.push(current);
146
+ current = makeContextRange(next);
147
+ }
148
+ i++;
149
+ }
150
+ return out;
151
+ }
152
+ function makeContextRange(line) {
153
+ return [
154
+ makeRangeStart(line),
155
+ makeRangeEnd(line)
156
+ ];
157
+ }
158
+ function makeRangeStart(line) {
159
+ return Math.max(1, line - DEFAULT_LINES_OF_CONTEXT);
160
+ }
161
+ function makeRangeEnd(line) {
162
+ return line + DEFAULT_LINES_OF_CONTEXT;
163
+ }
164
+ function emplace(map, key, contents) {
165
+ const value = map.get(key);
166
+ if (void 0 === value) {
167
+ map.set(key, contents);
168
+ return contents;
169
+ }
170
+ return value;
171
+ }
172
+ function snipLine(line, colno) {
173
+ let newLine = line;
174
+ const lineLength = newLine.length;
175
+ if (lineLength <= 150) return newLine;
176
+ if (colno > lineLength) colno = lineLength;
177
+ let start = Math.max(colno - 60, 0);
178
+ if (start < 5) start = 0;
179
+ let end = Math.min(start + 140, lineLength);
180
+ if (end > lineLength - 5) end = lineLength;
181
+ if (end === lineLength) start = Math.max(end - 140, 0);
182
+ newLine = newLine.slice(start, end);
183
+ if (start > 0) newLine = `...${newLine}`;
184
+ if (end < lineLength) newLine += '...';
185
+ return newLine;
186
+ }
187
+ export { MAX_CONTEXTLINES_COLNO, MAX_CONTEXTLINES_LINENO, addSourceContext };
@@ -0,0 +1,3 @@
1
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core';
2
+ export declare function createModulerModifier(): (frames: CoreErrorTracking.StackFrame[]) => Promise<CoreErrorTracking.StackFrame[]>;
3
+ //# sourceMappingURL=module.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.node.d.ts","sourceRoot":"","sources":["../../../../src/extensions/error-tracking/modifiers/module.node.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGlE,wBAAgB,qBAAqB,KAErB,QAAQ,iBAAiB,CAAC,UAAU,EAAE,KAAG,OAAO,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAM/F"}
@@ -0,0 +1,64 @@
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
+ createModulerModifier: ()=>createModulerModifier
28
+ });
29
+ const external_path_namespaceObject = require("path");
30
+ function createModulerModifier() {
31
+ const getModuleFromFileName = createGetModuleFromFilename();
32
+ return async (frames)=>{
33
+ for (const frame of frames)frame.module = getModuleFromFileName(frame.filename);
34
+ return frames;
35
+ };
36
+ }
37
+ function createGetModuleFromFilename(basePath = process.argv[1] ? (0, external_path_namespaceObject.dirname)(process.argv[1]) : process.cwd(), isWindows = '\\' === external_path_namespaceObject.sep) {
38
+ const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath;
39
+ return (filename)=>{
40
+ if (!filename) return;
41
+ const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename;
42
+ let { dir, base: file, ext } = external_path_namespaceObject.posix.parse(normalizedFilename);
43
+ if ('.js' === ext || '.mjs' === ext || '.cjs' === ext) file = file.slice(0, -1 * ext.length);
44
+ const decodedFile = decodeURIComponent(file);
45
+ if (!dir) dir = '.';
46
+ const n = dir.lastIndexOf('/node_modules');
47
+ if (n > -1) return `${dir.slice(n + 14).replace(/\//g, '.')}:${decodedFile}`;
48
+ if (dir.startsWith(normalizedBase)) {
49
+ const moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, '.');
50
+ return moduleName ? `${moduleName}:${decodedFile}` : decodedFile;
51
+ }
52
+ return decodedFile;
53
+ };
54
+ }
55
+ function normalizeWindowsPath(path) {
56
+ return path.replace(/^[A-Z]:/, '').replace(/\\/g, '/');
57
+ }
58
+ exports.createModulerModifier = __webpack_exports__.createModulerModifier;
59
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
60
+ "createModulerModifier"
61
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
62
+ Object.defineProperty(exports, '__esModule', {
63
+ value: true
64
+ });
@@ -0,0 +1,30 @@
1
+ import { dirname, posix, sep } from "path";
2
+ function createModulerModifier() {
3
+ const getModuleFromFileName = createGetModuleFromFilename();
4
+ return async (frames)=>{
5
+ for (const frame of frames)frame.module = getModuleFromFileName(frame.filename);
6
+ return frames;
7
+ };
8
+ }
9
+ function createGetModuleFromFilename(basePath = process.argv[1] ? dirname(process.argv[1]) : process.cwd(), isWindows = '\\' === sep) {
10
+ const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath;
11
+ return (filename)=>{
12
+ if (!filename) return;
13
+ const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename;
14
+ let { dir, base: file, ext } = posix.parse(normalizedFilename);
15
+ if ('.js' === ext || '.mjs' === ext || '.cjs' === ext) file = file.slice(0, -1 * ext.length);
16
+ const decodedFile = decodeURIComponent(file);
17
+ if (!dir) dir = '.';
18
+ const n = dir.lastIndexOf('/node_modules');
19
+ if (n > -1) return `${dir.slice(n + 14).replace(/\//g, '.')}:${decodedFile}`;
20
+ if (dir.startsWith(normalizedBase)) {
21
+ const moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, '.');
22
+ return moduleName ? `${moduleName}:${decodedFile}` : decodedFile;
23
+ }
24
+ return decodedFile;
25
+ };
26
+ }
27
+ function normalizeWindowsPath(path) {
28
+ return path.replace(/^[A-Z]:/, '').replace(/\\/g, '/');
29
+ }
30
+ export { createModulerModifier };
@@ -0,0 +1,17 @@
1
+ import type * as http from 'node:http';
2
+ import { PostHogBackendClient } from '../client';
3
+ type ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;
4
+ type ExpressErrorMiddleware = (error: MiddlewareError, req: http.IncomingMessage, res: http.ServerResponse, next: (error: MiddlewareError) => void) => void;
5
+ interface MiddlewareError extends Error {
6
+ status?: number | string;
7
+ statusCode?: number | string;
8
+ status_code?: number | string;
9
+ output?: {
10
+ statusCode?: number | string;
11
+ };
12
+ }
13
+ export declare function setupExpressErrorHandler(_posthog: PostHogBackendClient, app: {
14
+ use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown;
15
+ }): void;
16
+ export {};
17
+ //# sourceMappingURL=express.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/extensions/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAGtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGhD,KAAK,iBAAiB,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAExG,KAAK,sBAAsB,GAAG,CAC5B,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,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,CAUN"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ setupExpressErrorHandler: ()=>setupExpressErrorHandler
37
+ });
38
+ const core_namespaceObject = require("@posthog/core");
39
+ const index_js_namespaceObject = require("./error-tracking/index.js");
40
+ var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
41
+ function setupExpressErrorHandler(_posthog, app) {
42
+ app.use((error, _, __, next)=>{
43
+ const hint = {
44
+ mechanism: {
45
+ type: 'middleware',
46
+ handled: false
47
+ }
48
+ };
49
+ index_js_default().buildEventMessage(error, hint, (0, core_namespaceObject.uuidv7)(), {
50
+ $process_person_profile: false
51
+ }).then((msg)=>_posthog.capture(msg));
52
+ next(error);
53
+ });
54
+ }
55
+ exports.setupExpressErrorHandler = __webpack_exports__.setupExpressErrorHandler;
56
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
57
+ "setupExpressErrorHandler"
58
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
59
+ Object.defineProperty(exports, '__esModule', {
60
+ value: true
61
+ });
@@ -0,0 +1,17 @@
1
+ import { uuidv7 } from "@posthog/core";
2
+ import error_tracking from "./error-tracking/index.mjs";
3
+ function setupExpressErrorHandler(_posthog, app) {
4
+ app.use((error, _, __, next)=>{
5
+ const hint = {
6
+ mechanism: {
7
+ type: 'middleware',
8
+ handled: false
9
+ }
10
+ };
11
+ error_tracking.buildEventMessage(error, hint, uuidv7(), {
12
+ $process_person_profile: false
13
+ }).then((msg)=>_posthog.capture(msg));
14
+ next(error);
15
+ });
16
+ }
17
+ export { setupExpressErrorHandler };
@@ -0,0 +1,3 @@
1
+ export declare function getNodeCrypto(): Promise<typeof import('crypto') | undefined>;
2
+ export declare function getWebCrypto(): Promise<SubtleCrypto | undefined>;
3
+ //# sourceMappingURL=crypto-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-helpers.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/crypto-helpers.ts"],"names":[],"mappings":"AAWA,wBAAsB,aAAa,IAAI,OAAO,CAAC,cAAc,QAAQ,CAAC,GAAG,SAAS,CAAC,CAElF;AAoBD,wBAAsB,YAAY,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAEtE"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ crypto: function(module) {
4
+ module.exports = import("crypto").then(function(module) {
5
+ return module;
6
+ });
7
+ }
8
+ };
9
+ var __webpack_module_cache__ = {};
10
+ function __webpack_require__(moduleId) {
11
+ var cachedModule = __webpack_module_cache__[moduleId];
12
+ if (void 0 !== cachedModule) return cachedModule.exports;
13
+ var module = __webpack_module_cache__[moduleId] = {
14
+ exports: {}
15
+ };
16
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
17
+ return module.exports;
18
+ }
19
+ (()=>{
20
+ __webpack_require__.d = (exports1, definition)=>{
21
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
22
+ enumerable: true,
23
+ get: definition[key]
24
+ });
25
+ };
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
29
+ })();
30
+ (()=>{
31
+ __webpack_require__.r = (exports1)=>{
32
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
33
+ value: 'Module'
34
+ });
35
+ Object.defineProperty(exports1, '__esModule', {
36
+ value: true
37
+ });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ (()=>{
42
+ __webpack_require__.r(__webpack_exports__);
43
+ __webpack_require__.d(__webpack_exports__, {
44
+ getNodeCrypto: ()=>getNodeCrypto,
45
+ getWebCrypto: ()=>getWebCrypto
46
+ });
47
+ const external_lazy_js_namespaceObject = require("./lazy.js");
48
+ const nodeCrypto = new external_lazy_js_namespaceObject.Lazy(async ()=>{
49
+ try {
50
+ return await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "crypto"));
51
+ } catch {
52
+ return;
53
+ }
54
+ });
55
+ async function getNodeCrypto() {
56
+ return await nodeCrypto.getValue();
57
+ }
58
+ const webCrypto = new external_lazy_js_namespaceObject.Lazy(async ()=>{
59
+ if (void 0 !== globalThis.crypto?.subtle) return globalThis.crypto.subtle;
60
+ try {
61
+ const crypto = await nodeCrypto.getValue();
62
+ if (crypto?.webcrypto?.subtle) return crypto.webcrypto.subtle;
63
+ } catch {}
64
+ });
65
+ async function getWebCrypto() {
66
+ return await webCrypto.getValue();
67
+ }
68
+ })();
69
+ exports.getNodeCrypto = __webpack_exports__.getNodeCrypto;
70
+ exports.getWebCrypto = __webpack_exports__.getWebCrypto;
71
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
72
+ "getNodeCrypto",
73
+ "getWebCrypto"
74
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
75
+ Object.defineProperty(exports, '__esModule', {
76
+ value: true
77
+ });
@@ -0,0 +1,22 @@
1
+ import { Lazy } from "./lazy.mjs";
2
+ const nodeCrypto = new Lazy(async ()=>{
3
+ try {
4
+ return await import("crypto");
5
+ } catch {
6
+ return;
7
+ }
8
+ });
9
+ async function getNodeCrypto() {
10
+ return await nodeCrypto.getValue();
11
+ }
12
+ const webCrypto = new Lazy(async ()=>{
13
+ if (void 0 !== globalThis.crypto?.subtle) return globalThis.crypto.subtle;
14
+ try {
15
+ const crypto = await nodeCrypto.getValue();
16
+ if (crypto?.webcrypto?.subtle) return crypto.webcrypto.subtle;
17
+ } catch {}
18
+ });
19
+ async function getWebCrypto() {
20
+ return await webCrypto.getValue();
21
+ }
22
+ export { getNodeCrypto, getWebCrypto };
@@ -0,0 +1,2 @@
1
+ export declare function hashSHA1(text: string): Promise<string>;
2
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/crypto.ts"],"names":[],"mappings":"AAIA,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB5D"}
@@ -0,0 +1,47 @@
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
+ hashSHA1: ()=>hashSHA1
28
+ });
29
+ const external_crypto_helpers_js_namespaceObject = require("./crypto-helpers.js");
30
+ async function hashSHA1(text) {
31
+ const nodeCrypto = await (0, external_crypto_helpers_js_namespaceObject.getNodeCrypto)();
32
+ if (nodeCrypto) return nodeCrypto.createHash('sha1').update(text).digest('hex');
33
+ const webCrypto = await (0, external_crypto_helpers_js_namespaceObject.getWebCrypto)();
34
+ if (webCrypto) {
35
+ const hashBuffer = await webCrypto.digest('SHA-1', new TextEncoder().encode(text));
36
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
37
+ return hashArray.map((byte)=>byte.toString(16).padStart(2, '0')).join('');
38
+ }
39
+ throw new Error('No crypto implementation available. Tried Node Crypto API and Web SubtleCrypto API');
40
+ }
41
+ exports.hashSHA1 = __webpack_exports__.hashSHA1;
42
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
43
+ "hashSHA1"
44
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
45
+ Object.defineProperty(exports, '__esModule', {
46
+ value: true
47
+ });
@@ -0,0 +1,13 @@
1
+ import { getNodeCrypto, getWebCrypto } from "./crypto-helpers.mjs";
2
+ async function hashSHA1(text) {
3
+ const nodeCrypto = await getNodeCrypto();
4
+ if (nodeCrypto) return nodeCrypto.createHash('sha1').update(text).digest('hex');
5
+ const webCrypto = await getWebCrypto();
6
+ if (webCrypto) {
7
+ const hashBuffer = await webCrypto.digest('SHA-1', new TextEncoder().encode(text));
8
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
9
+ return hashArray.map((byte)=>byte.toString(16).padStart(2, '0')).join('');
10
+ }
11
+ throw new Error('No crypto implementation available. Tried Node Crypto API and Web SubtleCrypto API');
12
+ }
13
+ export { hashSHA1 };
@@ -0,0 +1,89 @@
1
+ import { FeatureFlagCondition, PostHogFeatureFlag, PropertyGroup } from '../../types';
2
+ import type { FeatureFlagValue, JsonType, PostHogFetchOptions, PostHogFetchResponse } from '@posthog/core';
3
+ declare class ClientError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ declare class InconclusiveMatchError extends Error {
7
+ constructor(message: string);
8
+ }
9
+ type FeatureFlagsPollerOptions = {
10
+ personalApiKey: string;
11
+ projectApiKey: string;
12
+ host: string;
13
+ pollingInterval: number;
14
+ timeout?: number;
15
+ fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
16
+ onError?: (error: Error) => void;
17
+ onLoad?: (count: number) => void;
18
+ customHeaders?: {
19
+ [key: string]: string;
20
+ };
21
+ };
22
+ declare class FeatureFlagsPoller {
23
+ pollingInterval: number;
24
+ personalApiKey: string;
25
+ projectApiKey: string;
26
+ featureFlags: Array<PostHogFeatureFlag>;
27
+ featureFlagsByKey: Record<string, PostHogFeatureFlag>;
28
+ groupTypeMapping: Record<string, string>;
29
+ cohorts: Record<string, PropertyGroup>;
30
+ loadedSuccessfullyOnce: boolean;
31
+ timeout?: number;
32
+ host: FeatureFlagsPollerOptions['host'];
33
+ poller?: NodeJS.Timeout;
34
+ fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
35
+ debugMode: boolean;
36
+ onError?: (error: Error) => void;
37
+ customHeaders?: {
38
+ [key: string]: string;
39
+ };
40
+ shouldBeginExponentialBackoff: boolean;
41
+ backOffCount: number;
42
+ onLoad?: (count: number) => void;
43
+ constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }: FeatureFlagsPollerOptions);
44
+ debug(enabled?: boolean): void;
45
+ private logMsgIfDebug;
46
+ getFeatureFlag(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<FeatureFlagValue | undefined>;
47
+ getAllFlagsAndPayloads(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, flagKeysToExplicitlyEvaluate?: string[]): Promise<{
48
+ response: Record<string, FeatureFlagValue>;
49
+ payloads: Record<string, JsonType>;
50
+ fallbackToFlags: boolean;
51
+ }>;
52
+ computeFlagAndPayloadLocally(flag: PostHogFeatureFlag, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, matchValue?: FeatureFlagValue, evaluationCache?: Record<string, FeatureFlagValue>, skipLoadCheck?: boolean): Promise<{
53
+ value: FeatureFlagValue;
54
+ payload: JsonType | null;
55
+ }>;
56
+ private computeFlagValueLocally;
57
+ private getFeatureFlagPayload;
58
+ private evaluateFlagDependency;
59
+ private flagEvaluatesToExpectedValue;
60
+ matchFeatureFlagProperties(flag: PostHogFeatureFlag, distinctId: string, properties: Record<string, string>, evaluationCache?: Record<string, FeatureFlagValue>): Promise<FeatureFlagValue>;
61
+ isConditionMatch(flag: PostHogFeatureFlag, distinctId: string, condition: FeatureFlagCondition, properties: Record<string, string>, evaluationCache?: Record<string, FeatureFlagValue>): Promise<boolean>;
62
+ getMatchingVariant(flag: PostHogFeatureFlag, distinctId: string): Promise<FeatureFlagValue | undefined>;
63
+ variantLookupTable(flag: PostHogFeatureFlag): {
64
+ valueMin: number;
65
+ valueMax: number;
66
+ key: string;
67
+ }[];
68
+ loadFeatureFlags(forceReload?: boolean): Promise<void>;
69
+ /**
70
+ * Returns true if the feature flags poller has loaded successfully at least once and has more than 0 feature flags.
71
+ * This is useful to check if local evaluation is ready before calling getFeatureFlag.
72
+ */
73
+ isLocalEvaluationReady(): boolean;
74
+ /**
75
+ * If a client is misconfigured with an invalid or improper API key, the polling interval is doubled each time
76
+ * until a successful request is made, up to a maximum of 60 seconds.
77
+ *
78
+ * @returns The polling interval to use for the next request.
79
+ */
80
+ private getPollingInterval;
81
+ _loadFeatureFlags(): Promise<void>;
82
+ private getPersonalApiKeyRequestOptions;
83
+ _requestFeatureFlagDefinitions(): Promise<PostHogFetchResponse>;
84
+ stopPoller(): void;
85
+ }
86
+ declare function matchProperty(property: FeatureFlagCondition['properties'][number], propertyValues: Record<string, any>, warnFunction?: (msg: string) => void): boolean;
87
+ declare function relativeDateParseForFeatureFlagMatching(value: string): Date | null;
88
+ export { FeatureFlagsPoller, matchProperty, relativeDateParseForFeatureFlagMatching, InconclusiveMatchError, ClientError, };
89
+ //# sourceMappingURL=feature-flags.d.ts.map