@posthog/core 1.2.2 → 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/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 +0 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/error-tracking/parsers/base.ts +0 -5
- 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 +0 -2
|
@@ -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/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,C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AG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI;cAgCrE,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+C1G,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,eAAe;IAOvB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,KAAK,IAAI,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
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SimpleEventEmitter } from "./eventemitter.mjs";
|
|
2
2
|
import { getFeatureFlagValue, normalizeFlagsResponse } from "./featureFlagUtils.mjs";
|
|
3
3
|
import { gzipCompress, isGzipSupported } from "./gzip.mjs";
|
|
4
|
+
import { createLogger } from "./logger.mjs";
|
|
4
5
|
import { PostHogPersistedProperty } from "./types.mjs";
|
|
5
6
|
import { PromiseQueue, STRING_FORMAT, allSettled, assert, currentISOTime, removeTrailingSlash, retriable, safeSetTimeout } from "./utils/index.mjs";
|
|
6
7
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
@@ -50,7 +51,7 @@ var posthog_core_stateless_QuotaLimitedFeature = /*#__PURE__*/ function(QuotaLim
|
|
|
50
51
|
return QuotaLimitedFeature;
|
|
51
52
|
}({});
|
|
52
53
|
class PostHogCoreStateless {
|
|
53
|
-
constructor(apiKey, options){
|
|
54
|
+
constructor(apiKey, options = {}){
|
|
54
55
|
this.flushPromise = null;
|
|
55
56
|
this.shutdownPromise = null;
|
|
56
57
|
this.promiseQueue = new PromiseQueue();
|
|
@@ -58,34 +59,35 @@ class PostHogCoreStateless {
|
|
|
58
59
|
this._isInitialized = false;
|
|
59
60
|
assert(apiKey, "You must pass your PostHog project's api key.");
|
|
60
61
|
this.apiKey = apiKey;
|
|
61
|
-
this.host = removeTrailingSlash(options
|
|
62
|
-
this.flushAt = options
|
|
63
|
-
this.maxBatchSize = Math.max(this.flushAt, options
|
|
64
|
-
this.maxQueueSize = Math.max(this.flushAt, options
|
|
65
|
-
this.flushInterval = options
|
|
66
|
-
this.preloadFeatureFlags = options
|
|
67
|
-
this.defaultOptIn = options
|
|
68
|
-
this.disableSurveys = options
|
|
62
|
+
this.host = removeTrailingSlash(options.host || 'https://us.i.posthog.com');
|
|
63
|
+
this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
|
|
64
|
+
this.maxBatchSize = Math.max(this.flushAt, options.maxBatchSize ?? 100);
|
|
65
|
+
this.maxQueueSize = Math.max(this.flushAt, options.maxQueueSize ?? 1000);
|
|
66
|
+
this.flushInterval = options.flushInterval ?? 10000;
|
|
67
|
+
this.preloadFeatureFlags = options.preloadFeatureFlags ?? true;
|
|
68
|
+
this.defaultOptIn = options.defaultOptIn ?? true;
|
|
69
|
+
this.disableSurveys = options.disableSurveys ?? false;
|
|
69
70
|
this._retryOptions = {
|
|
70
|
-
retryCount: options
|
|
71
|
-
retryDelay: options
|
|
71
|
+
retryCount: options.fetchRetryCount ?? 3,
|
|
72
|
+
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
72
73
|
retryCheck: isPostHogFetchError
|
|
73
74
|
};
|
|
74
|
-
this.requestTimeout = options
|
|
75
|
-
this.featureFlagsRequestTimeoutMs = options
|
|
76
|
-
this.remoteConfigRequestTimeoutMs = options
|
|
77
|
-
this.disableGeoip = options
|
|
78
|
-
this.disabled = options
|
|
75
|
+
this.requestTimeout = options.requestTimeout ?? 10000;
|
|
76
|
+
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
77
|
+
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
78
|
+
this.disableGeoip = options.disableGeoip ?? true;
|
|
79
|
+
this.disabled = options.disabled ?? false;
|
|
79
80
|
this.historicalMigration = options?.historicalMigration ?? false;
|
|
80
81
|
this._initPromise = Promise.resolve();
|
|
81
82
|
this._isInitialized = true;
|
|
83
|
+
this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this));
|
|
82
84
|
this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false);
|
|
83
85
|
}
|
|
84
86
|
logMsgIfDebug(fn) {
|
|
85
87
|
if (this.isDebug) fn();
|
|
86
88
|
}
|
|
87
89
|
wrap(fn) {
|
|
88
|
-
if (this.disabled) return void this.
|
|
90
|
+
if (this.disabled) return void this._logger.warn('The client is disabled');
|
|
89
91
|
if (this._isInitialized) return fn();
|
|
90
92
|
this._initPromise.then(()=>fn());
|
|
91
93
|
}
|
|
@@ -114,7 +116,7 @@ class PostHogCoreStateless {
|
|
|
114
116
|
debug(enabled = true) {
|
|
115
117
|
this.removeDebugCallback?.();
|
|
116
118
|
if (enabled) {
|
|
117
|
-
const removeDebugCallback = this.on('*', (event, payload)=>
|
|
119
|
+
const removeDebugCallback = this.on('*', (event, payload)=>this._logger.info(event, payload));
|
|
118
120
|
this.removeDebugCallback = ()=>{
|
|
119
121
|
removeDebugCallback();
|
|
120
122
|
this.removeDebugCallback = void 0;
|
|
@@ -237,7 +239,7 @@ class PostHogCoreStateless {
|
|
|
237
239
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
238
240
|
retryCount: 0
|
|
239
241
|
}, this.remoteConfigRequestTimeoutMs).then((response)=>response.json()).catch((error)=>{
|
|
240
|
-
this.
|
|
242
|
+
this._logger.error('Remote config could not be loaded', error);
|
|
241
243
|
this._events.emit('error', error);
|
|
242
244
|
});
|
|
243
245
|
}
|
|
@@ -259,7 +261,7 @@ class PostHogCoreStateless {
|
|
|
259
261
|
...extraPayload
|
|
260
262
|
})
|
|
261
263
|
};
|
|
262
|
-
this.
|
|
264
|
+
this._logger.info('Flags URL', url);
|
|
263
265
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
264
266
|
retryCount: 0
|
|
265
267
|
}, this.featureFlagsRequestTimeoutMs).then((response)=>response.json()).then((response)=>normalizeFlagsResponse(response)).catch((error)=>{
|
|
@@ -348,7 +350,7 @@ class PostHogCoreStateless {
|
|
|
348
350
|
async getSurveysStateless() {
|
|
349
351
|
await this._initPromise;
|
|
350
352
|
if (true === this.disableSurveys) {
|
|
351
|
-
this.
|
|
353
|
+
this._logger.info('Loading surveys is disabled.');
|
|
352
354
|
return [];
|
|
353
355
|
}
|
|
354
356
|
const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
|
|
@@ -363,17 +365,17 @@ class PostHogCoreStateless {
|
|
|
363
365
|
if (200 !== response.status || !response.json) {
|
|
364
366
|
const msg = `Surveys API could not be loaded: ${response.status}`;
|
|
365
367
|
const error = new Error(msg);
|
|
366
|
-
this.
|
|
368
|
+
this._logger.error(error);
|
|
367
369
|
this._events.emit('error', new Error(msg));
|
|
368
370
|
return;
|
|
369
371
|
}
|
|
370
372
|
return response.json();
|
|
371
373
|
}).catch((error)=>{
|
|
372
|
-
this.
|
|
374
|
+
this._logger.error('Surveys API could not be loaded', error);
|
|
373
375
|
this._events.emit('error', error);
|
|
374
376
|
});
|
|
375
377
|
const newSurveys = response?.surveys;
|
|
376
|
-
if (newSurveys) this.
|
|
378
|
+
if (newSurveys) this._logger.info('Surveys fetched from API: ', JSON.stringify(newSurveys));
|
|
377
379
|
return newSurveys ?? [];
|
|
378
380
|
}
|
|
379
381
|
get props() {
|
|
@@ -405,7 +407,7 @@ class PostHogCoreStateless {
|
|
|
405
407
|
const queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
|
|
406
408
|
if (queue.length >= this.maxQueueSize) {
|
|
407
409
|
queue.shift();
|
|
408
|
-
this.
|
|
410
|
+
this._logger.info('Queue is full, the oldest event is dropped.');
|
|
409
411
|
}
|
|
410
412
|
queue.push({
|
|
411
413
|
message
|
|
@@ -417,7 +419,7 @@ class PostHogCoreStateless {
|
|
|
417
419
|
});
|
|
418
420
|
}
|
|
419
421
|
async sendImmediate(type, _message, options) {
|
|
420
|
-
if (this.disabled) return void this.
|
|
422
|
+
if (this.disabled) return void this._logger.warn('The client is disabled');
|
|
421
423
|
if (!this._isInitialized) await this._initPromise;
|
|
422
424
|
if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
423
425
|
const data = {
|
|
@@ -545,7 +547,7 @@ class PostHogCoreStateless {
|
|
|
545
547
|
} catch (err) {
|
|
546
548
|
if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
|
|
547
549
|
this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
|
|
548
|
-
this.
|
|
550
|
+
this._logger.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`);
|
|
549
551
|
continue;
|
|
550
552
|
}
|
|
551
553
|
if (!(err instanceof PostHogFetchNetworkError)) persistQueueChange();
|
|
@@ -613,7 +615,7 @@ class PostHogCoreStateless {
|
|
|
613
615
|
return Promise.race([
|
|
614
616
|
new Promise((_, reject)=>{
|
|
615
617
|
safeSetTimeout(()=>{
|
|
616
|
-
this.
|
|
618
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
617
619
|
hasTimedOut = true;
|
|
618
620
|
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
619
621
|
}, shutdownTimeoutMs);
|
|
@@ -622,7 +624,7 @@ class PostHogCoreStateless {
|
|
|
622
624
|
]);
|
|
623
625
|
}
|
|
624
626
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
625
|
-
if (this.shutdownPromise) this.
|
|
627
|
+
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');
|
|
626
628
|
else this.shutdownPromise = this._shutdown(shutdownTimeoutMs).finally(()=>{
|
|
627
629
|
this.shutdownPromise = null;
|
|
628
630
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core.d.ts","sourceRoot":"","sources":["../src/posthog-core.ts"],"names":[],"mappings":"A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