@posthog/core 1.2.1 → 1.2.3
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/error-tracking/parsers/base.d.ts +0 -5
- package/dist/error-tracking/parsers/base.d.ts.map +1 -1
- package/dist/error-tracking/parsers/base.js +1 -21
- package/dist/error-tracking/parsers/base.mjs +1 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -20
- package/dist/index.mjs +1 -2
- package/dist/logger.d.ts +11 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +74 -0
- package/dist/logger.mjs +37 -0
- package/dist/posthog-core-stateless.d.ts +2 -1
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +31 -29
- package/dist/posthog-core-stateless.mjs +31 -29
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +9 -9
- package/dist/posthog-core.mjs +9 -9
- package/dist/testing/test-utils.d.ts.map +1 -1
- package/dist/testing/test-utils.js +4 -6
- package/dist/testing/test-utils.mjs +4 -6
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/error-tracking/parsers/base.ts +0 -5
- package/src/index.ts +0 -1
- package/src/logger.ts +58 -0
- package/src/posthog-core-stateless.ts +35 -35
- package/src/posthog-core.ts +9 -17
- package/src/testing/test-utils.ts +4 -6
- package/src/types.ts +1 -3
- package/src/__tests__/featureFlagUtils.spec.ts +0 -427
- package/src/__tests__/gzip.spec.ts +0 -69
- package/src/__tests__/posthog.ai.spec.ts +0 -110
- package/src/__tests__/posthog.capture.spec.ts +0 -91
- package/src/__tests__/posthog.core.spec.ts +0 -135
- package/src/__tests__/posthog.debug.spec.ts +0 -36
- package/src/__tests__/posthog.enqueue.spec.ts +0 -93
- package/src/__tests__/posthog.featureflags.spec.ts +0 -1106
- package/src/__tests__/posthog.featureflags.v1.spec.ts +0 -922
- package/src/__tests__/posthog.flush.spec.ts +0 -237
- package/src/__tests__/posthog.gdpr.spec.ts +0 -50
- package/src/__tests__/posthog.groups.spec.ts +0 -96
- package/src/__tests__/posthog.identify.spec.ts +0 -194
- package/src/__tests__/posthog.init.spec.ts +0 -110
- package/src/__tests__/posthog.listeners.spec.ts +0 -51
- package/src/__tests__/posthog.register.spec.ts +0 -47
- package/src/__tests__/posthog.reset.spec.ts +0 -76
- package/src/__tests__/posthog.sessions.spec.ts +0 -63
- package/src/__tests__/posthog.setProperties.spec.ts +0 -102
- package/src/__tests__/posthog.shutdown.spec.ts +0 -88
- package/src/__tests__/utils.spec.ts +0 -36
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { StackFrame } from '../types';
|
|
2
2
|
export declare const UNKNOWN_FUNCTION = "?";
|
|
3
|
-
export declare const OPERA10_PRIORITY = 10;
|
|
4
|
-
export declare const OPERA11_PRIORITY = 20;
|
|
5
|
-
export declare const CHROME_PRIORITY = 30;
|
|
6
|
-
export declare const WINJS_PRIORITY = 40;
|
|
7
|
-
export declare const GECKO_PRIORITY = 50;
|
|
8
3
|
export declare function createFrame(filename: string, func: string, lineno?: number, colno?: number): StackFrame;
|
|
9
4
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAkBvG"}
|
|
@@ -24,21 +24,11 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
OPERA10_PRIORITY: ()=>OPERA10_PRIORITY,
|
|
28
|
-
CHROME_PRIORITY: ()=>CHROME_PRIORITY,
|
|
29
27
|
UNKNOWN_FUNCTION: ()=>UNKNOWN_FUNCTION,
|
|
30
|
-
|
|
31
|
-
createFrame: ()=>createFrame,
|
|
32
|
-
OPERA11_PRIORITY: ()=>OPERA11_PRIORITY,
|
|
33
|
-
GECKO_PRIORITY: ()=>GECKO_PRIORITY
|
|
28
|
+
createFrame: ()=>createFrame
|
|
34
29
|
});
|
|
35
30
|
const index_js_namespaceObject = require("../../utils/index.js");
|
|
36
31
|
const UNKNOWN_FUNCTION = '?';
|
|
37
|
-
const OPERA10_PRIORITY = 10;
|
|
38
|
-
const OPERA11_PRIORITY = 20;
|
|
39
|
-
const CHROME_PRIORITY = 30;
|
|
40
|
-
const WINJS_PRIORITY = 40;
|
|
41
|
-
const GECKO_PRIORITY = 50;
|
|
42
32
|
function createFrame(filename, func, lineno, colno) {
|
|
43
33
|
const frame = {
|
|
44
34
|
platform: "web:javascript",
|
|
@@ -50,20 +40,10 @@ function createFrame(filename, func, lineno, colno) {
|
|
|
50
40
|
if (!(0, index_js_namespaceObject.isUndefined)(colno)) frame.colno = colno;
|
|
51
41
|
return frame;
|
|
52
42
|
}
|
|
53
|
-
exports.CHROME_PRIORITY = __webpack_exports__.CHROME_PRIORITY;
|
|
54
|
-
exports.GECKO_PRIORITY = __webpack_exports__.GECKO_PRIORITY;
|
|
55
|
-
exports.OPERA10_PRIORITY = __webpack_exports__.OPERA10_PRIORITY;
|
|
56
|
-
exports.OPERA11_PRIORITY = __webpack_exports__.OPERA11_PRIORITY;
|
|
57
43
|
exports.UNKNOWN_FUNCTION = __webpack_exports__.UNKNOWN_FUNCTION;
|
|
58
|
-
exports.WINJS_PRIORITY = __webpack_exports__.WINJS_PRIORITY;
|
|
59
44
|
exports.createFrame = __webpack_exports__.createFrame;
|
|
60
45
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
61
|
-
"CHROME_PRIORITY",
|
|
62
|
-
"GECKO_PRIORITY",
|
|
63
|
-
"OPERA10_PRIORITY",
|
|
64
|
-
"OPERA11_PRIORITY",
|
|
65
46
|
"UNKNOWN_FUNCTION",
|
|
66
|
-
"WINJS_PRIORITY",
|
|
67
47
|
"createFrame"
|
|
68
48
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
69
49
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { isUndefined } from "../../utils/index.mjs";
|
|
2
2
|
const UNKNOWN_FUNCTION = '?';
|
|
3
|
-
const OPERA10_PRIORITY = 10;
|
|
4
|
-
const OPERA11_PRIORITY = 20;
|
|
5
|
-
const CHROME_PRIORITY = 30;
|
|
6
|
-
const WINJS_PRIORITY = 40;
|
|
7
|
-
const GECKO_PRIORITY = 50;
|
|
8
3
|
function createFrame(filename, func, lineno, colno) {
|
|
9
4
|
const frame = {
|
|
10
5
|
platform: "web:javascript",
|
|
@@ -16,4 +11,4 @@ function createFrame(filename, func, lineno, colno) {
|
|
|
16
11
|
if (!isUndefined(colno)) frame.colno = colno;
|
|
17
12
|
return frame;
|
|
18
13
|
}
|
|
19
|
-
export {
|
|
14
|
+
export { UNKNOWN_FUNCTION, createFrame };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export { getFeatureFlagValue } from './featureFlagUtils';
|
|
|
2
2
|
export * from './utils';
|
|
3
3
|
export * as ErrorTracking from './error-tracking';
|
|
4
4
|
export { uuidv7 } from './vendor/uuidv7';
|
|
5
|
-
export * as testing from './testing';
|
|
6
5
|
export * from './posthog-core';
|
|
7
6
|
export * from './posthog-core-stateless';
|
|
8
7
|
export * from './types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,0BAA0B,CAAA;AACxC,cAAc,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,6 @@ var __webpack_modules__ = {
|
|
|
12
12
|
"./posthog-core": function(module) {
|
|
13
13
|
module.exports = require("./posthog-core.js");
|
|
14
14
|
},
|
|
15
|
-
"./testing": function(module) {
|
|
16
|
-
module.exports = require("./testing/index.js");
|
|
17
|
-
},
|
|
18
15
|
"./types": function(module) {
|
|
19
16
|
module.exports = require("./types.js");
|
|
20
17
|
},
|
|
@@ -71,7 +68,6 @@ var __webpack_exports__ = {};
|
|
|
71
68
|
__webpack_require__.d(__webpack_exports__, {
|
|
72
69
|
ErrorTracking: ()=>_error_tracking__WEBPACK_IMPORTED_MODULE_2__,
|
|
73
70
|
getFeatureFlagValue: ()=>_featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__.getFeatureFlagValue,
|
|
74
|
-
testing: ()=>_testing__WEBPACK_IMPORTED_MODULE_4__,
|
|
75
71
|
uuidv7: ()=>_vendor_uuidv7__WEBPACK_IMPORTED_MODULE_3__.uuidv7
|
|
76
72
|
});
|
|
77
73
|
var _featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./featureFlagUtils");
|
|
@@ -79,7 +75,6 @@ var __webpack_exports__ = {};
|
|
|
79
75
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
80
76
|
for(var __WEBPACK_IMPORT_KEY__ in _utils__WEBPACK_IMPORTED_MODULE_1__)if ([
|
|
81
77
|
"ErrorTracking",
|
|
82
|
-
"testing",
|
|
83
78
|
"default",
|
|
84
79
|
"getFeatureFlagValue",
|
|
85
80
|
"uuidv7"
|
|
@@ -89,52 +84,46 @@ var __webpack_exports__ = {};
|
|
|
89
84
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
90
85
|
var _error_tracking__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./error-tracking");
|
|
91
86
|
var _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./vendor/uuidv7");
|
|
92
|
-
var
|
|
93
|
-
var _posthog_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./posthog-core");
|
|
87
|
+
var _posthog_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./posthog-core");
|
|
94
88
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
95
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
89
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core__WEBPACK_IMPORTED_MODULE_4__)if ([
|
|
96
90
|
"ErrorTracking",
|
|
97
|
-
"testing",
|
|
98
91
|
"default",
|
|
99
92
|
"getFeatureFlagValue",
|
|
100
93
|
"uuidv7"
|
|
101
94
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
102
|
-
return
|
|
95
|
+
return _posthog_core__WEBPACK_IMPORTED_MODULE_4__[key];
|
|
103
96
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
104
97
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
105
|
-
var
|
|
98
|
+
var _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./posthog-core-stateless");
|
|
106
99
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
107
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
100
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_5__)if ([
|
|
108
101
|
"ErrorTracking",
|
|
109
|
-
"testing",
|
|
110
102
|
"default",
|
|
111
103
|
"getFeatureFlagValue",
|
|
112
104
|
"uuidv7"
|
|
113
105
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
114
|
-
return
|
|
106
|
+
return _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_5__[key];
|
|
115
107
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
116
108
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
117
|
-
var
|
|
109
|
+
var _types__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./types");
|
|
118
110
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
119
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
111
|
+
for(var __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_6__)if ([
|
|
120
112
|
"ErrorTracking",
|
|
121
|
-
"testing",
|
|
122
113
|
"default",
|
|
123
114
|
"getFeatureFlagValue",
|
|
124
115
|
"uuidv7"
|
|
125
116
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
126
|
-
return
|
|
117
|
+
return _types__WEBPACK_IMPORTED_MODULE_6__[key];
|
|
127
118
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
128
119
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
129
120
|
})();
|
|
130
121
|
exports.ErrorTracking = __webpack_exports__.ErrorTracking;
|
|
131
122
|
exports.getFeatureFlagValue = __webpack_exports__.getFeatureFlagValue;
|
|
132
|
-
exports.testing = __webpack_exports__.testing;
|
|
133
123
|
exports.uuidv7 = __webpack_exports__.uuidv7;
|
|
134
124
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
135
125
|
"ErrorTracking",
|
|
136
126
|
"getFeatureFlagValue",
|
|
137
|
-
"testing",
|
|
138
127
|
"uuidv7"
|
|
139
128
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
140
129
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/index.mjs
CHANGED
|
@@ -5,5 +5,4 @@ export * from "./posthog-core.mjs";
|
|
|
5
5
|
export * from "./posthog-core-stateless.mjs";
|
|
6
6
|
export * from "./types.mjs";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ from "./error-tracking/index.mjs";
|
|
8
|
-
|
|
9
|
-
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, getFeatureFlagValue, __WEBPACK_EXTERNAL_MODULE__testing_index_mjs_6f0b91da__ as testing, uuidv7 };
|
|
8
|
+
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, getFeatureFlagValue, uuidv7 };
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from './types';
|
|
2
|
+
type ConsoleLike = {
|
|
3
|
+
log: (...args: any[]) => void;
|
|
4
|
+
warn: (...args: any[]) => void;
|
|
5
|
+
error: (...args: any[]) => void;
|
|
6
|
+
debug: (...args: any[]) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const _createLogger: (prefix: string, maybeCall: (fn: () => void) => void, consoleLike: ConsoleLike) => Logger;
|
|
9
|
+
export declare function createLogger(prefix: string, maybeCall: (fn: () => void) => void): Logger;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGhC,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC7B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAChC,CAAA;AAYD,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,EACnC,aAAa,WAAW,KACvB,MA6BF,CAAA;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,UAE/E"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
_createLogger: ()=>_createLogger,
|
|
28
|
+
createLogger: ()=>createLogger
|
|
29
|
+
});
|
|
30
|
+
function createConsole(consoleLike = console) {
|
|
31
|
+
const lockedMethods = {
|
|
32
|
+
log: consoleLike.log.bind(consoleLike),
|
|
33
|
+
warn: consoleLike.warn.bind(consoleLike),
|
|
34
|
+
error: consoleLike.error.bind(consoleLike),
|
|
35
|
+
debug: consoleLike.debug.bind(consoleLike)
|
|
36
|
+
};
|
|
37
|
+
return lockedMethods;
|
|
38
|
+
}
|
|
39
|
+
const _createLogger = (prefix, maybeCall, consoleLike)=>{
|
|
40
|
+
function _log(level, ...args) {
|
|
41
|
+
maybeCall(()=>{
|
|
42
|
+
const consoleMethod = consoleLike[level];
|
|
43
|
+
consoleMethod(prefix, ...args);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const logger = {
|
|
47
|
+
info: (...args)=>{
|
|
48
|
+
_log('log', ...args);
|
|
49
|
+
},
|
|
50
|
+
warn: (...args)=>{
|
|
51
|
+
_log('warn', ...args);
|
|
52
|
+
},
|
|
53
|
+
error: (...args)=>{
|
|
54
|
+
_log('error', ...args);
|
|
55
|
+
},
|
|
56
|
+
critical: (...args)=>{
|
|
57
|
+
consoleLike['error'](prefix, ...args);
|
|
58
|
+
},
|
|
59
|
+
createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, maybeCall, consoleLike)
|
|
60
|
+
};
|
|
61
|
+
return logger;
|
|
62
|
+
};
|
|
63
|
+
function createLogger(prefix, maybeCall) {
|
|
64
|
+
return _createLogger(prefix, maybeCall, createConsole());
|
|
65
|
+
}
|
|
66
|
+
exports._createLogger = __webpack_exports__._createLogger;
|
|
67
|
+
exports.createLogger = __webpack_exports__.createLogger;
|
|
68
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
69
|
+
"_createLogger",
|
|
70
|
+
"createLogger"
|
|
71
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
72
|
+
Object.defineProperty(exports, '__esModule', {
|
|
73
|
+
value: true
|
|
74
|
+
});
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function createConsole(consoleLike = console) {
|
|
2
|
+
const lockedMethods = {
|
|
3
|
+
log: consoleLike.log.bind(consoleLike),
|
|
4
|
+
warn: consoleLike.warn.bind(consoleLike),
|
|
5
|
+
error: consoleLike.error.bind(consoleLike),
|
|
6
|
+
debug: consoleLike.debug.bind(consoleLike)
|
|
7
|
+
};
|
|
8
|
+
return lockedMethods;
|
|
9
|
+
}
|
|
10
|
+
const _createLogger = (prefix, maybeCall, consoleLike)=>{
|
|
11
|
+
function _log(level, ...args) {
|
|
12
|
+
maybeCall(()=>{
|
|
13
|
+
const consoleMethod = consoleLike[level];
|
|
14
|
+
consoleMethod(prefix, ...args);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const logger = {
|
|
18
|
+
info: (...args)=>{
|
|
19
|
+
_log('log', ...args);
|
|
20
|
+
},
|
|
21
|
+
warn: (...args)=>{
|
|
22
|
+
_log('warn', ...args);
|
|
23
|
+
},
|
|
24
|
+
error: (...args)=>{
|
|
25
|
+
_log('error', ...args);
|
|
26
|
+
},
|
|
27
|
+
critical: (...args)=>{
|
|
28
|
+
consoleLike['error'](prefix, ...args);
|
|
29
|
+
},
|
|
30
|
+
createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, maybeCall, consoleLike)
|
|
31
|
+
};
|
|
32
|
+
return logger;
|
|
33
|
+
};
|
|
34
|
+
function createLogger(prefix, maybeCall) {
|
|
35
|
+
return _createLogger(prefix, maybeCall, createConsole());
|
|
36
|
+
}
|
|
37
|
+
export { _createLogger, createLogger };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SimpleEventEmitter } from './eventemitter';
|
|
2
|
-
import { PostHogFlagsResponse, PostHogCoreOptions, PostHogEventProperties, PostHogCaptureOptions, JsonType, PostHogRemoteConfig, FeatureFlagValue, PostHogFeatureFlagDetails, FeatureFlagDetail, SurveyResponse, PostHogFetchResponse, PostHogFetchOptions, PostHogPersistedProperty } from './types';
|
|
2
|
+
import { PostHogFlagsResponse, PostHogCoreOptions, PostHogEventProperties, PostHogCaptureOptions, JsonType, PostHogRemoteConfig, FeatureFlagValue, PostHogFeatureFlagDetails, FeatureFlagDetail, SurveyResponse, PostHogFetchResponse, PostHogFetchOptions, PostHogPersistedProperty, Logger } from './types';
|
|
3
3
|
import { RetriableOptions } from './utils';
|
|
4
4
|
export declare const maybeAdd: (key: string, value: JsonType | undefined) => Record<string, JsonType>;
|
|
5
5
|
export declare function logFlushError(err: any): Promise<void>;
|
|
@@ -34,6 +34,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
34
34
|
protected _initPromise: Promise<void>;
|
|
35
35
|
protected _isInitialized: boolean;
|
|
36
36
|
protected _remoteConfigResponsePromise?: Promise<PostHogRemoteConfig | undefined>;
|
|
37
|
+
protected _logger: Logger;
|
|
37
38
|
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
38
39
|
abstract getLibraryId(): string;
|
|
39
40
|
abstract getLibraryVersion(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAInD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,EACP,MAAM,SAAS,CAAA;AAChB,OAAO,EAOL,gBAAgB,EAGjB,MAAM,SAAS,CAAA;AAqChB,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAO,QAAQ,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAC9C,CAAA;AAE7C,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3D;AAUD,oBAAY,mBAAmB;IAC7B,YAAY,kBAAkB;IAC9B,UAAU,eAAe;CAC1B;AAED,8BAAsB,oBAAoB;IAExC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAA;IACrC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;I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AAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;YAazC,MAAM;YA0FN,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -32,6 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
const external_eventemitter_js_namespaceObject = require("./eventemitter.js");
|
|
33
33
|
const external_featureFlagUtils_js_namespaceObject = require("./featureFlagUtils.js");
|
|
34
34
|
const external_gzip_js_namespaceObject = require("./gzip.js");
|
|
35
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
35
36
|
const external_types_js_namespaceObject = require("./types.js");
|
|
36
37
|
const index_js_namespaceObject = require("./utils/index.js");
|
|
37
38
|
const uuidv7_js_namespaceObject = require("./vendor/uuidv7.js");
|
|
@@ -81,7 +82,7 @@ var posthog_core_stateless_QuotaLimitedFeature = /*#__PURE__*/ function(QuotaLim
|
|
|
81
82
|
return QuotaLimitedFeature;
|
|
82
83
|
}({});
|
|
83
84
|
class PostHogCoreStateless {
|
|
84
|
-
constructor(apiKey, options){
|
|
85
|
+
constructor(apiKey, options = {}){
|
|
85
86
|
this.flushPromise = null;
|
|
86
87
|
this.shutdownPromise = null;
|
|
87
88
|
this.promiseQueue = new index_js_namespaceObject.PromiseQueue();
|
|
@@ -89,34 +90,35 @@ class PostHogCoreStateless {
|
|
|
89
90
|
this._isInitialized = false;
|
|
90
91
|
(0, index_js_namespaceObject.assert)(apiKey, "You must pass your PostHog project's api key.");
|
|
91
92
|
this.apiKey = apiKey;
|
|
92
|
-
this.host = (0, index_js_namespaceObject.removeTrailingSlash)(options
|
|
93
|
-
this.flushAt = options
|
|
94
|
-
this.maxBatchSize = Math.max(this.flushAt, options
|
|
95
|
-
this.maxQueueSize = Math.max(this.flushAt, options
|
|
96
|
-
this.flushInterval = options
|
|
97
|
-
this.preloadFeatureFlags = options
|
|
98
|
-
this.defaultOptIn = options
|
|
99
|
-
this.disableSurveys = options
|
|
93
|
+
this.host = (0, index_js_namespaceObject.removeTrailingSlash)(options.host || 'https://us.i.posthog.com');
|
|
94
|
+
this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
|
|
95
|
+
this.maxBatchSize = Math.max(this.flushAt, options.maxBatchSize ?? 100);
|
|
96
|
+
this.maxQueueSize = Math.max(this.flushAt, options.maxQueueSize ?? 1000);
|
|
97
|
+
this.flushInterval = options.flushInterval ?? 10000;
|
|
98
|
+
this.preloadFeatureFlags = options.preloadFeatureFlags ?? true;
|
|
99
|
+
this.defaultOptIn = options.defaultOptIn ?? true;
|
|
100
|
+
this.disableSurveys = options.disableSurveys ?? false;
|
|
100
101
|
this._retryOptions = {
|
|
101
|
-
retryCount: options
|
|
102
|
-
retryDelay: options
|
|
102
|
+
retryCount: options.fetchRetryCount ?? 3,
|
|
103
|
+
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
103
104
|
retryCheck: isPostHogFetchError
|
|
104
105
|
};
|
|
105
|
-
this.requestTimeout = options
|
|
106
|
-
this.featureFlagsRequestTimeoutMs = options
|
|
107
|
-
this.remoteConfigRequestTimeoutMs = options
|
|
108
|
-
this.disableGeoip = options
|
|
109
|
-
this.disabled = options
|
|
106
|
+
this.requestTimeout = options.requestTimeout ?? 10000;
|
|
107
|
+
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
108
|
+
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
109
|
+
this.disableGeoip = options.disableGeoip ?? true;
|
|
110
|
+
this.disabled = options.disabled ?? false;
|
|
110
111
|
this.historicalMigration = options?.historicalMigration ?? false;
|
|
111
112
|
this._initPromise = Promise.resolve();
|
|
112
113
|
this._isInitialized = true;
|
|
114
|
+
this._logger = (0, external_logger_js_namespaceObject.createLogger)('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
113
115
|
this.disableCompression = !(0, external_gzip_js_namespaceObject.isGzipSupported)() || (options?.disableCompression ?? false);
|
|
114
116
|
}
|
|
115
117
|
logMsgIfDebug(fn) {
|
|
116
118
|
if (this.isDebug) fn();
|
|
117
119
|
}
|
|
118
120
|
wrap(fn) {
|
|
119
|
-
if (this.disabled) return void this.
|
|
121
|
+
if (this.disabled) return void this._logger.warn('The client is disabled');
|
|
120
122
|
if (this._isInitialized) return fn();
|
|
121
123
|
this._initPromise.then(()=>fn());
|
|
122
124
|
}
|
|
@@ -145,7 +147,7 @@ class PostHogCoreStateless {
|
|
|
145
147
|
debug(enabled = true) {
|
|
146
148
|
this.removeDebugCallback?.();
|
|
147
149
|
if (enabled) {
|
|
148
|
-
const removeDebugCallback = this.on('*', (event, payload)=>
|
|
150
|
+
const removeDebugCallback = this.on('*', (event, payload)=>this._logger.info(event, payload));
|
|
149
151
|
this.removeDebugCallback = ()=>{
|
|
150
152
|
removeDebugCallback();
|
|
151
153
|
this.removeDebugCallback = void 0;
|
|
@@ -268,7 +270,7 @@ class PostHogCoreStateless {
|
|
|
268
270
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
269
271
|
retryCount: 0
|
|
270
272
|
}, this.remoteConfigRequestTimeoutMs).then((response)=>response.json()).catch((error)=>{
|
|
271
|
-
this.
|
|
273
|
+
this._logger.error('Remote config could not be loaded', error);
|
|
272
274
|
this._events.emit('error', error);
|
|
273
275
|
});
|
|
274
276
|
}
|
|
@@ -290,7 +292,7 @@ class PostHogCoreStateless {
|
|
|
290
292
|
...extraPayload
|
|
291
293
|
})
|
|
292
294
|
};
|
|
293
|
-
this.
|
|
295
|
+
this._logger.info('Flags URL', url);
|
|
294
296
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
295
297
|
retryCount: 0
|
|
296
298
|
}, this.featureFlagsRequestTimeoutMs).then((response)=>response.json()).then((response)=>(0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(response)).catch((error)=>{
|
|
@@ -379,7 +381,7 @@ class PostHogCoreStateless {
|
|
|
379
381
|
async getSurveysStateless() {
|
|
380
382
|
await this._initPromise;
|
|
381
383
|
if (true === this.disableSurveys) {
|
|
382
|
-
this.
|
|
384
|
+
this._logger.info('Loading surveys is disabled.');
|
|
383
385
|
return [];
|
|
384
386
|
}
|
|
385
387
|
const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
|
|
@@ -394,17 +396,17 @@ class PostHogCoreStateless {
|
|
|
394
396
|
if (200 !== response.status || !response.json) {
|
|
395
397
|
const msg = `Surveys API could not be loaded: ${response.status}`;
|
|
396
398
|
const error = new Error(msg);
|
|
397
|
-
this.
|
|
399
|
+
this._logger.error(error);
|
|
398
400
|
this._events.emit('error', new Error(msg));
|
|
399
401
|
return;
|
|
400
402
|
}
|
|
401
403
|
return response.json();
|
|
402
404
|
}).catch((error)=>{
|
|
403
|
-
this.
|
|
405
|
+
this._logger.error('Surveys API could not be loaded', error);
|
|
404
406
|
this._events.emit('error', error);
|
|
405
407
|
});
|
|
406
408
|
const newSurveys = response?.surveys;
|
|
407
|
-
if (newSurveys) this.
|
|
409
|
+
if (newSurveys) this._logger.info('Surveys fetched from API: ', JSON.stringify(newSurveys));
|
|
408
410
|
return newSurveys ?? [];
|
|
409
411
|
}
|
|
410
412
|
get props() {
|
|
@@ -436,7 +438,7 @@ class PostHogCoreStateless {
|
|
|
436
438
|
const queue = this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.Queue) || [];
|
|
437
439
|
if (queue.length >= this.maxQueueSize) {
|
|
438
440
|
queue.shift();
|
|
439
|
-
this.
|
|
441
|
+
this._logger.info('Queue is full, the oldest event is dropped.');
|
|
440
442
|
}
|
|
441
443
|
queue.push({
|
|
442
444
|
message
|
|
@@ -448,7 +450,7 @@ class PostHogCoreStateless {
|
|
|
448
450
|
});
|
|
449
451
|
}
|
|
450
452
|
async sendImmediate(type, _message, options) {
|
|
451
|
-
if (this.disabled) return void this.
|
|
453
|
+
if (this.disabled) return void this._logger.warn('The client is disabled');
|
|
452
454
|
if (!this._isInitialized) await this._initPromise;
|
|
453
455
|
if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
454
456
|
const data = {
|
|
@@ -576,7 +578,7 @@ class PostHogCoreStateless {
|
|
|
576
578
|
} catch (err) {
|
|
577
579
|
if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
|
|
578
580
|
this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
|
|
579
|
-
this.
|
|
581
|
+
this._logger.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`);
|
|
580
582
|
continue;
|
|
581
583
|
}
|
|
582
584
|
if (!(err instanceof PostHogFetchNetworkError)) persistQueueChange();
|
|
@@ -644,7 +646,7 @@ class PostHogCoreStateless {
|
|
|
644
646
|
return Promise.race([
|
|
645
647
|
new Promise((_, reject)=>{
|
|
646
648
|
(0, index_js_namespaceObject.safeSetTimeout)(()=>{
|
|
647
|
-
this.
|
|
649
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
648
650
|
hasTimedOut = true;
|
|
649
651
|
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
650
652
|
}, shutdownTimeoutMs);
|
|
@@ -653,7 +655,7 @@ class PostHogCoreStateless {
|
|
|
653
655
|
]);
|
|
654
656
|
}
|
|
655
657
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
656
|
-
if (this.shutdownPromise) this.
|
|
658
|
+
if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
|
|
657
659
|
else this.shutdownPromise = this._shutdown(shutdownTimeoutMs).finally(()=>{
|
|
658
660
|
this.shutdownPromise = null;
|
|
659
661
|
});
|