posthog-node 5.9.2 → 5.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +0 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -7
- package/dist/client.mjs +5 -7
- package/dist/extensions/feature-flags/crypto.d.ts.map +1 -1
- package/dist/extensions/feature-flags/crypto.js +5 -10
- package/dist/extensions/feature-flags/crypto.mjs +5 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +3 -4
- package/src/client.ts +5 -13
- package/src/extensions/feature-flags/crypto.ts +6 -16
- package/src/version.ts +1 -1
- package/dist/extensions/feature-flags/crypto-helpers.d.ts +0 -3
- package/dist/extensions/feature-flags/crypto-helpers.d.ts.map +0 -1
- package/dist/extensions/feature-flags/crypto-helpers.js +0 -77
- package/dist/extensions/feature-flags/crypto-helpers.mjs +0 -22
- package/dist/extensions/feature-flags/lazy.d.ts +0 -24
- package/dist/extensions/feature-flags/lazy.d.ts.map +0 -1
- package/dist/extensions/feature-flags/lazy.js +0 -60
- package/dist/extensions/feature-flags/lazy.mjs +0 -26
- package/dist/utils/logger.d.ts +0 -3
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -63
- package/dist/utils/logger.mjs +0 -29
- package/src/extensions/feature-flags/crypto-helpers.ts +0 -36
- package/src/extensions/feature-flags/lazy.ts +0 -55
- package/src/utils/logger.ts +0 -39
package/dist/client.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
|
|
|
8
8
|
private featureFlagsPoller?;
|
|
9
9
|
protected errorTracking: ErrorTracking;
|
|
10
10
|
private maxCacheSize;
|
|
11
|
-
private logger;
|
|
12
11
|
readonly options: PostHogOptions;
|
|
13
12
|
distinctIdHasSentFlagCalls: Record<string, string[]>;
|
|
14
13
|
/**
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,oBAAoB,EAEpB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAC/B,wBAAwB,EAExB,qBAAqB,EAEtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAAqB,gBAAgB,EAAuB,MAAM,eAAe,CAAA;AAExF,OAAO,aAAa,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAkB,sBAAsB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,oBAAoB,EAEpB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAC/B,wBAAwB,EAExB,qBAAqB,EAEtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAAqB,gBAAgB,EAAuB,MAAM,eAAe,CAAA;AAExF,OAAO,aAAa,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAkB,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAUtE,8BAAsB,oBAAqB,SAAQ,oBAAqB,YAAW,QAAQ;IACzF,OAAO,CAAC,cAAc,CAA6B;IAEnD,OAAO,CAAC,kBAAkB,CAAC,CAAoB;IAC/C,SAAS,CAAC,aAAa,EAAE,aAAa,CAAA;IACtC,OAAO,CAAC,YAAY,CAAQ;IAC5B,SAAgB,OAAO,EAAE,cAAc,CAAA;IAEvC,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;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AM,GAAG,OAAO,CAAC,IAAI,CAAC;YAM5C,2BAA2B;IAqCzC,OAAO,CAAC,0BAA0B;YA+BpB,uBAAuB;IAiErC,OAAO,CAAC,gCAAgC;IAqBxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAShH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,yBAAyB,CAC7B,KAAK,EAAE,OAAO,EACd,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAClD,OAAO,CAAC,IAAI,CAAC;IASH,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC;QAC7D,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;QACb,UAAU,EAAE,sBAAsB,CAAA;QAClC,OAAO,EAAE,qBAAqB,CAAA;KAC/B,CAAC;IA8EF,OAAO,CAAC,cAAc;CAuBvB"}
|
package/dist/client.js
CHANGED
|
@@ -41,7 +41,6 @@ const feature_flags_js_namespaceObject = require("./extensions/feature-flags/fea
|
|
|
41
41
|
const index_js_namespaceObject = require("./extensions/error-tracking/index.js");
|
|
42
42
|
var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
|
|
43
43
|
const external_storage_memory_js_namespaceObject = require("./storage-memory.js");
|
|
44
|
-
const logger_js_namespaceObject = require("./utils/logger.js");
|
|
45
44
|
const MINIMUM_POLLING_INTERVAL = 100;
|
|
46
45
|
const THIRTY_SECONDS = 30000;
|
|
47
46
|
const MAX_CACHE_SIZE = 50000;
|
|
@@ -49,7 +48,6 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
49
48
|
constructor(apiKey, options = {}){
|
|
50
49
|
super(apiKey, options), this._memoryStorage = new external_storage_memory_js_namespaceObject.PostHogMemoryStorage();
|
|
51
50
|
this.options = options;
|
|
52
|
-
this.logger = (0, logger_js_namespaceObject.createLogger)(this.logMsgIfDebug.bind(this));
|
|
53
51
|
this.options.featureFlagsPollingInterval = 'number' == typeof options.featureFlagsPollingInterval ? Math.max(options.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
54
52
|
if (options.personalApiKey) {
|
|
55
53
|
if (options.personalApiKey.includes('phc_')) throw new Error('Your Personal API key is invalid. These keys are prefixed with "phx_" and can be created in PostHog project settings.');
|
|
@@ -70,7 +68,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
70
68
|
customHeaders: this.getCustomHeaders()
|
|
71
69
|
});
|
|
72
70
|
}
|
|
73
|
-
this.errorTracking = new (index_js_default())(this, options, this.
|
|
71
|
+
this.errorTracking = new (index_js_default())(this, options, this._logger);
|
|
74
72
|
this.distinctIdHasSentFlagCalls = {};
|
|
75
73
|
this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE;
|
|
76
74
|
}
|
|
@@ -100,7 +98,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
100
98
|
this.featureFlagsPoller?.debug(enabled);
|
|
101
99
|
}
|
|
102
100
|
capture(props) {
|
|
103
|
-
if ('string' == typeof props) this.
|
|
101
|
+
if ('string' == typeof props) this._logger.warn('Called capture() with a string as the first argument when an object was expected.');
|
|
104
102
|
this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStateless(distinctId, event, properties, {
|
|
105
103
|
timestamp: options.timestamp,
|
|
106
104
|
disableGeoip: options.disableGeoip,
|
|
@@ -110,7 +108,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
110
108
|
}));
|
|
111
109
|
}
|
|
112
110
|
async captureImmediate(props) {
|
|
113
|
-
if ('string' == typeof props) this.
|
|
111
|
+
if ('string' == typeof props) this._logger.warn('Called captureImmediate() with a string as the first argument when an object was expected.');
|
|
114
112
|
return this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStatelessImmediate(distinctId, event, properties, {
|
|
115
113
|
timestamp: options.timestamp,
|
|
116
114
|
disableGeoip: options.disableGeoip,
|
|
@@ -460,12 +458,12 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
460
458
|
for (const fn of fns){
|
|
461
459
|
result = fn(result);
|
|
462
460
|
if (!result) {
|
|
463
|
-
this.
|
|
461
|
+
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`);
|
|
464
462
|
return null;
|
|
465
463
|
}
|
|
466
464
|
if (!result.properties || 0 === Object.keys(result.properties).length) {
|
|
467
465
|
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
468
|
-
this.
|
|
466
|
+
this._logger.warn(message);
|
|
469
467
|
}
|
|
470
468
|
}
|
|
471
469
|
return result;
|
package/dist/client.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { PostHogCoreStateless, getFeatureFlagValue, isPlainObject, safeSetTimeou
|
|
|
3
3
|
import { FeatureFlagsPoller } from "./extensions/feature-flags/feature-flags.mjs";
|
|
4
4
|
import error_tracking from "./extensions/error-tracking/index.mjs";
|
|
5
5
|
import { PostHogMemoryStorage } from "./storage-memory.mjs";
|
|
6
|
-
import { createLogger } from "./utils/logger.mjs";
|
|
7
6
|
const MINIMUM_POLLING_INTERVAL = 100;
|
|
8
7
|
const THIRTY_SECONDS = 30000;
|
|
9
8
|
const MAX_CACHE_SIZE = 50000;
|
|
@@ -11,7 +10,6 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
11
10
|
constructor(apiKey, options = {}){
|
|
12
11
|
super(apiKey, options), this._memoryStorage = new PostHogMemoryStorage();
|
|
13
12
|
this.options = options;
|
|
14
|
-
this.logger = createLogger(this.logMsgIfDebug.bind(this));
|
|
15
13
|
this.options.featureFlagsPollingInterval = 'number' == typeof options.featureFlagsPollingInterval ? Math.max(options.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
16
14
|
if (options.personalApiKey) {
|
|
17
15
|
if (options.personalApiKey.includes('phc_')) throw new Error('Your Personal API key is invalid. These keys are prefixed with "phx_" and can be created in PostHog project settings.');
|
|
@@ -32,7 +30,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
32
30
|
customHeaders: this.getCustomHeaders()
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
|
-
this.errorTracking = new error_tracking(this, options, this.
|
|
33
|
+
this.errorTracking = new error_tracking(this, options, this._logger);
|
|
36
34
|
this.distinctIdHasSentFlagCalls = {};
|
|
37
35
|
this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE;
|
|
38
36
|
}
|
|
@@ -62,7 +60,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
62
60
|
this.featureFlagsPoller?.debug(enabled);
|
|
63
61
|
}
|
|
64
62
|
capture(props) {
|
|
65
|
-
if ('string' == typeof props) this.
|
|
63
|
+
if ('string' == typeof props) this._logger.warn('Called capture() with a string as the first argument when an object was expected.');
|
|
66
64
|
this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStateless(distinctId, event, properties, {
|
|
67
65
|
timestamp: options.timestamp,
|
|
68
66
|
disableGeoip: options.disableGeoip,
|
|
@@ -72,7 +70,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
72
70
|
}));
|
|
73
71
|
}
|
|
74
72
|
async captureImmediate(props) {
|
|
75
|
-
if ('string' == typeof props) this.
|
|
73
|
+
if ('string' == typeof props) this._logger.warn('Called captureImmediate() with a string as the first argument when an object was expected.');
|
|
76
74
|
return this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStatelessImmediate(distinctId, event, properties, {
|
|
77
75
|
timestamp: options.timestamp,
|
|
78
76
|
disableGeoip: options.disableGeoip,
|
|
@@ -422,12 +420,12 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
422
420
|
for (const fn of fns){
|
|
423
421
|
result = fn(result);
|
|
424
422
|
if (!result) {
|
|
425
|
-
this.
|
|
423
|
+
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`);
|
|
426
424
|
return null;
|
|
427
425
|
}
|
|
428
426
|
if (!result.properties || 0 === Object.keys(result.properties).length) {
|
|
429
427
|
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
430
|
-
this.
|
|
428
|
+
this._logger.warn(message);
|
|
431
429
|
}
|
|
432
430
|
}
|
|
433
431
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/crypto.ts"],"names":[],"mappings":"AAEA,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5D"}
|
|
@@ -26,17 +26,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
hashSHA1: ()=>hashSHA1
|
|
28
28
|
});
|
|
29
|
-
const external_crypto_helpers_js_namespaceObject = require("./crypto-helpers.js");
|
|
30
29
|
async function hashSHA1(text) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
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');
|
|
30
|
+
const subtle = globalThis.crypto?.subtle;
|
|
31
|
+
if (!subtle) throw new Error('SubtleCrypto API not available');
|
|
32
|
+
const hashBuffer = await subtle.digest('SHA-1', new TextEncoder().encode(text));
|
|
33
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
34
|
+
return hashArray.map((byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
40
35
|
}
|
|
41
36
|
exports.hashSHA1 = __webpack_exports__.hashSHA1;
|
|
42
37
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { getNodeCrypto, getWebCrypto } from "./crypto-helpers.mjs";
|
|
2
1
|
async function hashSHA1(text) {
|
|
3
|
-
const
|
|
4
|
-
if (
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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');
|
|
2
|
+
const subtle = globalThis.crypto?.subtle;
|
|
3
|
+
if (!subtle) throw new Error('SubtleCrypto API not available');
|
|
4
|
+
const hashBuffer = await subtle.digest('SHA-1', new TextEncoder().encode(text));
|
|
5
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
6
|
+
return hashArray.map((byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
12
7
|
}
|
|
13
8
|
export { hashSHA1 };
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.9.
|
|
1
|
+
export declare const version = "5.9.4";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
version: ()=>version
|
|
28
28
|
});
|
|
29
|
-
const version = '5.9.
|
|
29
|
+
const version = '5.9.4';
|
|
30
30
|
exports.version = __webpack_exports__.version;
|
|
31
31
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
32
32
|
"version"
|
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '5.9.
|
|
1
|
+
const version = '5.9.4';
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.4",
|
|
4
4
|
"description": "PostHog Node.js integration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"module": "dist/entrypoints/index.node.mjs",
|
|
26
26
|
"types": "dist/entrypoints/index.node.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@posthog/core": "1.2.
|
|
28
|
+
"@posthog/core": "1.2.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.0.0",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"build": "rslib build",
|
|
76
76
|
"dev": "rslib build -w",
|
|
77
77
|
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz",
|
|
78
|
-
"
|
|
79
|
-
"parse-specs": "node scripts/generate-docs.mjs"
|
|
78
|
+
"generate-references": "pnpm build && pnpm exec api-extractor run --config ./api-extractor.jsonc --local && node scripts/generate-docs.mjs"
|
|
80
79
|
}
|
|
81
80
|
}
|
package/src/client.ts
CHANGED
|
@@ -25,7 +25,6 @@ import { FeatureFlagsPoller } from './extensions/feature-flags/feature-flags'
|
|
|
25
25
|
import ErrorTracking from './extensions/error-tracking'
|
|
26
26
|
import { safeSetTimeout, PostHogEventProperties } from '@posthog/core'
|
|
27
27
|
import { PostHogMemoryStorage } from './storage-memory'
|
|
28
|
-
import { createLogger } from './utils/logger'
|
|
29
28
|
|
|
30
29
|
// Standard local evaluation rate limit is 600 per minute (10 per second),
|
|
31
30
|
// so the fastest a poller should ever be set is 100ms.
|
|
@@ -40,7 +39,6 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
40
39
|
private featureFlagsPoller?: FeatureFlagsPoller
|
|
41
40
|
protected errorTracking: ErrorTracking
|
|
42
41
|
private maxCacheSize: number
|
|
43
|
-
private logger: Logger
|
|
44
42
|
public readonly options: PostHogOptions
|
|
45
43
|
|
|
46
44
|
distinctIdHasSentFlagCalls: Record<string, string[]>
|
|
@@ -79,8 +77,6 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
79
77
|
|
|
80
78
|
this.options = options
|
|
81
79
|
|
|
82
|
-
this.logger = createLogger(this.logMsgIfDebug.bind(this))
|
|
83
|
-
|
|
84
80
|
this.options.featureFlagsPollingInterval =
|
|
85
81
|
typeof options.featureFlagsPollingInterval === 'number'
|
|
86
82
|
? Math.max(options.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL)
|
|
@@ -115,7 +111,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
113
|
|
|
118
|
-
this.errorTracking = new ErrorTracking(this, options, this.
|
|
114
|
+
this.errorTracking = new ErrorTracking(this, options, this._logger)
|
|
119
115
|
this.distinctIdHasSentFlagCalls = {}
|
|
120
116
|
this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE
|
|
121
117
|
}
|
|
@@ -309,9 +305,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
309
305
|
*/
|
|
310
306
|
capture(props: EventMessage): void {
|
|
311
307
|
if (typeof props === 'string') {
|
|
312
|
-
this.
|
|
313
|
-
console.warn('Called capture() with a string as the first argument when an object was expected.')
|
|
314
|
-
)
|
|
308
|
+
this._logger.warn('Called capture() with a string as the first argument when an object was expected.')
|
|
315
309
|
}
|
|
316
310
|
this.addPendingPromise(
|
|
317
311
|
this.prepareEventMessage(props)
|
|
@@ -375,9 +369,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
375
369
|
*/
|
|
376
370
|
async captureImmediate(props: EventMessage): Promise<void> {
|
|
377
371
|
if (typeof props === 'string') {
|
|
378
|
-
this.
|
|
379
|
-
console.warn('Called captureImmediate() with a string as the first argument when an object was expected.')
|
|
380
|
-
)
|
|
372
|
+
this._logger.warn('Called captureImmediate() with a string as the first argument when an object was expected.')
|
|
381
373
|
}
|
|
382
374
|
return this.addPendingPromise(
|
|
383
375
|
this.prepareEventMessage(props)
|
|
@@ -1518,12 +1510,12 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1518
1510
|
for (const fn of fns) {
|
|
1519
1511
|
result = fn(result)
|
|
1520
1512
|
if (!result) {
|
|
1521
|
-
this.
|
|
1513
|
+
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`)
|
|
1522
1514
|
return null
|
|
1523
1515
|
}
|
|
1524
1516
|
if (!result.properties || Object.keys(result.properties).length === 0) {
|
|
1525
1517
|
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`
|
|
1526
|
-
this.
|
|
1518
|
+
this._logger.warn(message)
|
|
1527
1519
|
}
|
|
1528
1520
|
}
|
|
1529
1521
|
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
|
|
3
|
-
import { getNodeCrypto, getWebCrypto } from './crypto-helpers'
|
|
4
|
-
|
|
5
3
|
export async function hashSHA1(text: string): Promise<string> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return nodeCrypto.createHash('sha1').update(text).digest('hex')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const webCrypto = await getWebCrypto()
|
|
13
|
-
|
|
14
|
-
// Fall back to Web Crypto API
|
|
15
|
-
if (webCrypto) {
|
|
16
|
-
const hashBuffer = await webCrypto.digest('SHA-1', new TextEncoder().encode(text))
|
|
17
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
18
|
-
return hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('')
|
|
4
|
+
const subtle = globalThis.crypto?.subtle
|
|
5
|
+
if (!subtle) {
|
|
6
|
+
throw new Error('SubtleCrypto API not available')
|
|
19
7
|
}
|
|
20
8
|
|
|
21
|
-
|
|
9
|
+
const hashBuffer = await subtle.digest('SHA-1', new TextEncoder().encode(text))
|
|
10
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
11
|
+
return hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('')
|
|
22
12
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.9.
|
|
1
|
+
export const version = '5.9.4'
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
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 };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
|
|
3
|
-
*/
|
|
4
|
-
export declare class Lazy<T> {
|
|
5
|
-
private value;
|
|
6
|
-
private factory;
|
|
7
|
-
private initializationPromise;
|
|
8
|
-
constructor(factory: () => Promise<T>);
|
|
9
|
-
/**
|
|
10
|
-
* Gets the value, initializing it if necessary.
|
|
11
|
-
* Multiple concurrent calls will share the same initialization promise.
|
|
12
|
-
*/
|
|
13
|
-
getValue(): Promise<T>;
|
|
14
|
-
/**
|
|
15
|
-
* Returns true if the value has been initialized.
|
|
16
|
-
*/
|
|
17
|
-
isInitialized(): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Returns a promise that resolves when the value is initialized.
|
|
20
|
-
* If already initialized, resolves immediately.
|
|
21
|
-
*/
|
|
22
|
-
waitForInitialization(): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/lazy.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,IAAI,CAAC,CAAC;IACjB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,qBAAqB,CAAwB;gBAEzC,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAIrC;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC;IAqB5B;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7C"}
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
Lazy: ()=>Lazy
|
|
28
|
-
});
|
|
29
|
-
class Lazy {
|
|
30
|
-
constructor(factory){
|
|
31
|
-
this.factory = factory;
|
|
32
|
-
}
|
|
33
|
-
async getValue() {
|
|
34
|
-
if (void 0 !== this.value) return this.value;
|
|
35
|
-
if (void 0 === this.initializationPromise) this.initializationPromise = (async ()=>{
|
|
36
|
-
try {
|
|
37
|
-
const result = await this.factory();
|
|
38
|
-
this.value = result;
|
|
39
|
-
return result;
|
|
40
|
-
} finally{
|
|
41
|
-
this.initializationPromise = void 0;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
return this.initializationPromise;
|
|
45
|
-
}
|
|
46
|
-
isInitialized() {
|
|
47
|
-
return void 0 !== this.value;
|
|
48
|
-
}
|
|
49
|
-
async waitForInitialization() {
|
|
50
|
-
if (this.isInitialized()) return;
|
|
51
|
-
await this.getValue();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.Lazy = __webpack_exports__.Lazy;
|
|
55
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
56
|
-
"Lazy"
|
|
57
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
58
|
-
Object.defineProperty(exports, '__esModule', {
|
|
59
|
-
value: true
|
|
60
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
class Lazy {
|
|
2
|
-
constructor(factory){
|
|
3
|
-
this.factory = factory;
|
|
4
|
-
}
|
|
5
|
-
async getValue() {
|
|
6
|
-
if (void 0 !== this.value) return this.value;
|
|
7
|
-
if (void 0 === this.initializationPromise) this.initializationPromise = (async ()=>{
|
|
8
|
-
try {
|
|
9
|
-
const result = await this.factory();
|
|
10
|
-
this.value = result;
|
|
11
|
-
return result;
|
|
12
|
-
} finally{
|
|
13
|
-
this.initializationPromise = void 0;
|
|
14
|
-
}
|
|
15
|
-
})();
|
|
16
|
-
return this.initializationPromise;
|
|
17
|
-
}
|
|
18
|
-
isInitialized() {
|
|
19
|
-
return void 0 !== this.value;
|
|
20
|
-
}
|
|
21
|
-
async waitForInitialization() {
|
|
22
|
-
if (this.isInitialized()) return;
|
|
23
|
-
await this.getValue();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export { Lazy };
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAsCtC,eAAO,MAAM,YAAY,GAAI,eAAe,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,WAAiD,CAAA"}
|
package/dist/utils/logger.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
});
|
|
29
|
-
const _createLogger = (prefix, logMsgIfDebug)=>{
|
|
30
|
-
const logger = {
|
|
31
|
-
_log: (level, ...args)=>{
|
|
32
|
-
logMsgIfDebug(()=>{
|
|
33
|
-
const consoleLog = console[level];
|
|
34
|
-
consoleLog(prefix, ...args);
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
info: (...args)=>{
|
|
38
|
-
logger._log('log', ...args);
|
|
39
|
-
},
|
|
40
|
-
warn: (...args)=>{
|
|
41
|
-
logger._log('warn', ...args);
|
|
42
|
-
},
|
|
43
|
-
error: (...args)=>{
|
|
44
|
-
logger._log('error', ...args);
|
|
45
|
-
},
|
|
46
|
-
critical: (...args)=>{
|
|
47
|
-
console.error(prefix, ...args);
|
|
48
|
-
},
|
|
49
|
-
uninitializedWarning: (methodName)=>{
|
|
50
|
-
logger.error(`You must initialize PostHog before calling ${methodName}`);
|
|
51
|
-
},
|
|
52
|
-
createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, logMsgIfDebug)
|
|
53
|
-
};
|
|
54
|
-
return logger;
|
|
55
|
-
};
|
|
56
|
-
const createLogger = (logMsgIfDebug)=>_createLogger('[PostHog.js]', logMsgIfDebug);
|
|
57
|
-
exports.createLogger = __webpack_exports__.createLogger;
|
|
58
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
59
|
-
"createLogger"
|
|
60
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
61
|
-
Object.defineProperty(exports, '__esModule', {
|
|
62
|
-
value: true
|
|
63
|
-
});
|
package/dist/utils/logger.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const _createLogger = (prefix, logMsgIfDebug)=>{
|
|
2
|
-
const logger = {
|
|
3
|
-
_log: (level, ...args)=>{
|
|
4
|
-
logMsgIfDebug(()=>{
|
|
5
|
-
const consoleLog = console[level];
|
|
6
|
-
consoleLog(prefix, ...args);
|
|
7
|
-
});
|
|
8
|
-
},
|
|
9
|
-
info: (...args)=>{
|
|
10
|
-
logger._log('log', ...args);
|
|
11
|
-
},
|
|
12
|
-
warn: (...args)=>{
|
|
13
|
-
logger._log('warn', ...args);
|
|
14
|
-
},
|
|
15
|
-
error: (...args)=>{
|
|
16
|
-
logger._log('error', ...args);
|
|
17
|
-
},
|
|
18
|
-
critical: (...args)=>{
|
|
19
|
-
console.error(prefix, ...args);
|
|
20
|
-
},
|
|
21
|
-
uninitializedWarning: (methodName)=>{
|
|
22
|
-
logger.error(`You must initialize PostHog before calling ${methodName}`);
|
|
23
|
-
},
|
|
24
|
-
createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, logMsgIfDebug)
|
|
25
|
-
};
|
|
26
|
-
return logger;
|
|
27
|
-
};
|
|
28
|
-
const createLogger = (logMsgIfDebug)=>_createLogger('[PostHog.js]', logMsgIfDebug);
|
|
29
|
-
export { createLogger };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { Lazy } from './lazy'
|
|
3
|
-
|
|
4
|
-
const nodeCrypto = new Lazy(async () => {
|
|
5
|
-
try {
|
|
6
|
-
return await import('crypto')
|
|
7
|
-
} catch {
|
|
8
|
-
return undefined
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
export async function getNodeCrypto(): Promise<typeof import('crypto') | undefined> {
|
|
13
|
-
return await nodeCrypto.getValue()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const webCrypto = new Lazy(async (): Promise<SubtleCrypto | undefined> => {
|
|
17
|
-
if (typeof globalThis.crypto?.subtle !== 'undefined') {
|
|
18
|
-
return globalThis.crypto.subtle
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Node.js: use built-in webcrypto and assign it if needed
|
|
23
|
-
const crypto = await nodeCrypto.getValue()
|
|
24
|
-
if (crypto?.webcrypto?.subtle) {
|
|
25
|
-
return crypto.webcrypto.subtle as SubtleCrypto
|
|
26
|
-
}
|
|
27
|
-
} catch {
|
|
28
|
-
// Ignore if not available
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return undefined
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
export async function getWebCrypto(): Promise<SubtleCrypto | undefined> {
|
|
35
|
-
return await webCrypto.getValue()
|
|
36
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
|
|
3
|
-
*/
|
|
4
|
-
export class Lazy<T> {
|
|
5
|
-
private value: T | undefined
|
|
6
|
-
private factory: () => Promise<T>
|
|
7
|
-
private initializationPromise: Promise<T> | undefined
|
|
8
|
-
|
|
9
|
-
constructor(factory: () => Promise<T>) {
|
|
10
|
-
this.factory = factory
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gets the value, initializing it if necessary.
|
|
15
|
-
* Multiple concurrent calls will share the same initialization promise.
|
|
16
|
-
*/
|
|
17
|
-
async getValue(): Promise<T> {
|
|
18
|
-
if (this.value !== undefined) {
|
|
19
|
-
return this.value
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (this.initializationPromise === undefined) {
|
|
23
|
-
this.initializationPromise = (async () => {
|
|
24
|
-
try {
|
|
25
|
-
const result = await this.factory()
|
|
26
|
-
this.value = result
|
|
27
|
-
return result
|
|
28
|
-
} finally {
|
|
29
|
-
// Clear the promise so we can retry if needed
|
|
30
|
-
this.initializationPromise = undefined
|
|
31
|
-
}
|
|
32
|
-
})()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return this.initializationPromise
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Returns true if the value has been initialized.
|
|
40
|
-
*/
|
|
41
|
-
isInitialized(): boolean {
|
|
42
|
-
return this.value !== undefined
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns a promise that resolves when the value is initialized.
|
|
47
|
-
* If already initialized, resolves immediately.
|
|
48
|
-
*/
|
|
49
|
-
async waitForInitialization(): Promise<void> {
|
|
50
|
-
if (this.isInitialized()) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
await this.getValue()
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/utils/logger.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@posthog/core'
|
|
2
|
-
|
|
3
|
-
const _createLogger = (prefix: string, logMsgIfDebug: (fn: () => void) => void): Logger => {
|
|
4
|
-
const logger: Logger = {
|
|
5
|
-
_log: (level: 'log' | 'warn' | 'error', ...args: any[]) => {
|
|
6
|
-
logMsgIfDebug(() => {
|
|
7
|
-
const consoleLog = console[level]
|
|
8
|
-
consoleLog(prefix, ...args)
|
|
9
|
-
})
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
info: (...args: any[]) => {
|
|
13
|
-
logger._log('log', ...args)
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
warn: (...args: any[]) => {
|
|
17
|
-
logger._log('warn', ...args)
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
error: (...args: any[]) => {
|
|
21
|
-
logger._log('error', ...args)
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
critical: (...args: any[]) => {
|
|
25
|
-
// Critical errors are always logged to the console
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.error(prefix, ...args)
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
uninitializedWarning: (methodName: string) => {
|
|
31
|
-
logger.error(`You must initialize PostHog before calling ${methodName}`)
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
createLogger: (additionalPrefix: string) => _createLogger(`${prefix} ${additionalPrefix}`, logMsgIfDebug),
|
|
35
|
-
}
|
|
36
|
-
return logger
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const createLogger = (logMsgIfDebug: (fn: () => void) => void) => _createLogger('[PostHog.js]', logMsgIfDebug)
|