posthog-node 5.29.1 → 5.29.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/client.d.ts.map +1 -1
- package/dist/client.js +34 -16
- package/dist/client.mjs +34 -16
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +3 -3
- package/src/client.ts +41 -19
- package/src/version.ts +1 -1
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,gBAAgB,EAGhB,QAAQ,EACR,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAE/B,wBAAwB,EACzB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EAIZ,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,2BAA2B,EAC3B,cAAc,EAEd,qBAAqB,EACrB,eAAe,EAChB,MAAM,SAAS,CAAA;AAOhB,OAAO,aAAa,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAkB,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAGtE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAGhB,QAAQ,EACR,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAE/B,wBAAwB,EACzB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EAIZ,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,2BAA2B,EAC3B,cAAc,EAEd,qBAAqB,EACrB,eAAe,EAChB,MAAM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;;;;;;;;;;;;;;;;;;;OAmBG;IACG,SAAS,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAa5C,2BAA2B;IAqCzC,OAAO,CAAC,0BAA0B;YA+BpB,uBAAuB;IAkErC,OAAO,CAAC,gCAAgC;IAqBxC,OAAO,CAAC,kCAAkC;IAe1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,gBAAgB,CACd,KAAK,EAAE,OAAO,EACd,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EACnD,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,GAC1B,IAAI;IAWP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAWH,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;IAkHF,OAAO,CAAC,cAAc;CAuBvB"}
|
package/dist/client.js
CHANGED
|
@@ -47,24 +47,42 @@ const THIRTY_SECONDS = 30000;
|
|
|
47
47
|
const MAX_CACHE_SIZE = 50000;
|
|
48
48
|
const WAITUNTIL_DEBOUNCE_MS = 50;
|
|
49
49
|
const WAITUNTIL_MAX_WAIT_MS = 500;
|
|
50
|
+
const DEFAULT_NODE_HOST = 'https://us.i.posthog.com';
|
|
51
|
+
function normalizeApiKey(value) {
|
|
52
|
+
return 'string' == typeof value ? value.trim() : '';
|
|
53
|
+
}
|
|
54
|
+
function normalizePersonalApiKey(value) {
|
|
55
|
+
const normalizedValue = 'string' == typeof value ? value.trim() : '';
|
|
56
|
+
return normalizedValue || void 0;
|
|
57
|
+
}
|
|
58
|
+
function normalizeHost(value) {
|
|
59
|
+
const normalizedValue = 'string' == typeof value ? value.trim() : '';
|
|
60
|
+
return normalizedValue || DEFAULT_NODE_HOST;
|
|
61
|
+
}
|
|
50
62
|
class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
51
63
|
constructor(apiKey, options = {}){
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
const normalizedApiKey = normalizeApiKey(apiKey);
|
|
65
|
+
const normalizedOptions = {
|
|
66
|
+
...options,
|
|
67
|
+
host: normalizeHost(options.host),
|
|
68
|
+
personalApiKey: normalizePersonalApiKey(options.personalApiKey)
|
|
69
|
+
};
|
|
70
|
+
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new external_storage_memory_js_namespaceObject.PostHogMemoryStorage();
|
|
71
|
+
this.options = normalizedOptions;
|
|
54
72
|
this.context = this.initializeContext();
|
|
55
|
-
this.options.featureFlagsPollingInterval = 'number' == typeof
|
|
56
|
-
if ('number' == typeof
|
|
57
|
-
if ('number' == typeof
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
const shouldEnableLocalEvaluation = false !==
|
|
73
|
+
this.options.featureFlagsPollingInterval = 'number' == typeof normalizedOptions.featureFlagsPollingInterval ? Math.max(normalizedOptions.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
74
|
+
if ('number' == typeof normalizedOptions.waitUntilDebounceMs) this.options.waitUntilDebounceMs = Math.max(normalizedOptions.waitUntilDebounceMs, 0);
|
|
75
|
+
if ('number' == typeof normalizedOptions.waitUntilMaxWaitMs) this.options.waitUntilMaxWaitMs = Math.max(normalizedOptions.waitUntilMaxWaitMs, 0);
|
|
76
|
+
if (normalizedOptions.personalApiKey) {
|
|
77
|
+
if (normalizedOptions.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.');
|
|
78
|
+
const shouldEnableLocalEvaluation = false !== normalizedOptions.enableLocalEvaluation;
|
|
61
79
|
if (shouldEnableLocalEvaluation) this.featureFlagsPoller = new feature_flags_js_namespaceObject.FeatureFlagsPoller({
|
|
62
80
|
pollingInterval: this.options.featureFlagsPollingInterval,
|
|
63
|
-
personalApiKey:
|
|
64
|
-
projectApiKey:
|
|
65
|
-
timeout:
|
|
81
|
+
personalApiKey: normalizedOptions.personalApiKey,
|
|
82
|
+
projectApiKey: normalizedApiKey,
|
|
83
|
+
timeout: normalizedOptions.requestTimeout ?? 10000,
|
|
66
84
|
host: this.host,
|
|
67
|
-
fetch:
|
|
85
|
+
fetch: normalizedOptions.fetch,
|
|
68
86
|
onError: (err)=>{
|
|
69
87
|
this._events.emit('error', err);
|
|
70
88
|
},
|
|
@@ -72,13 +90,13 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
72
90
|
this._events.emit('localEvaluationFlagsLoaded', count);
|
|
73
91
|
},
|
|
74
92
|
customHeaders: this.getCustomHeaders(),
|
|
75
|
-
cacheProvider:
|
|
76
|
-
strictLocalEvaluation:
|
|
93
|
+
cacheProvider: normalizedOptions.flagDefinitionCacheProvider,
|
|
94
|
+
strictLocalEvaluation: normalizedOptions.strictLocalEvaluation
|
|
77
95
|
});
|
|
78
96
|
}
|
|
79
|
-
this.errorTracking = new (index_js_default())(this,
|
|
97
|
+
this.errorTracking = new (index_js_default())(this, normalizedOptions, this._logger);
|
|
80
98
|
this.distinctIdHasSentFlagCalls = {};
|
|
81
|
-
this.maxCacheSize =
|
|
99
|
+
this.maxCacheSize = normalizedOptions.maxCacheSize || MAX_CACHE_SIZE;
|
|
82
100
|
}
|
|
83
101
|
enqueue(type, message, options) {
|
|
84
102
|
super.enqueue(type, message, options);
|
package/dist/client.mjs
CHANGED
|
@@ -9,24 +9,42 @@ const THIRTY_SECONDS = 30000;
|
|
|
9
9
|
const MAX_CACHE_SIZE = 50000;
|
|
10
10
|
const WAITUNTIL_DEBOUNCE_MS = 50;
|
|
11
11
|
const WAITUNTIL_MAX_WAIT_MS = 500;
|
|
12
|
+
const DEFAULT_NODE_HOST = 'https://us.i.posthog.com';
|
|
13
|
+
function normalizeApiKey(value) {
|
|
14
|
+
return 'string' == typeof value ? value.trim() : '';
|
|
15
|
+
}
|
|
16
|
+
function normalizePersonalApiKey(value) {
|
|
17
|
+
const normalizedValue = 'string' == typeof value ? value.trim() : '';
|
|
18
|
+
return normalizedValue || void 0;
|
|
19
|
+
}
|
|
20
|
+
function normalizeHost(value) {
|
|
21
|
+
const normalizedValue = 'string' == typeof value ? value.trim() : '';
|
|
22
|
+
return normalizedValue || DEFAULT_NODE_HOST;
|
|
23
|
+
}
|
|
12
24
|
class PostHogBackendClient extends PostHogCoreStateless {
|
|
13
25
|
constructor(apiKey, options = {}){
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
const normalizedApiKey = normalizeApiKey(apiKey);
|
|
27
|
+
const normalizedOptions = {
|
|
28
|
+
...options,
|
|
29
|
+
host: normalizeHost(options.host),
|
|
30
|
+
personalApiKey: normalizePersonalApiKey(options.personalApiKey)
|
|
31
|
+
};
|
|
32
|
+
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new PostHogMemoryStorage();
|
|
33
|
+
this.options = normalizedOptions;
|
|
16
34
|
this.context = this.initializeContext();
|
|
17
|
-
this.options.featureFlagsPollingInterval = 'number' == typeof
|
|
18
|
-
if ('number' == typeof
|
|
19
|
-
if ('number' == typeof
|
|
20
|
-
if (
|
|
21
|
-
if (
|
|
22
|
-
const shouldEnableLocalEvaluation = false !==
|
|
35
|
+
this.options.featureFlagsPollingInterval = 'number' == typeof normalizedOptions.featureFlagsPollingInterval ? Math.max(normalizedOptions.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
36
|
+
if ('number' == typeof normalizedOptions.waitUntilDebounceMs) this.options.waitUntilDebounceMs = Math.max(normalizedOptions.waitUntilDebounceMs, 0);
|
|
37
|
+
if ('number' == typeof normalizedOptions.waitUntilMaxWaitMs) this.options.waitUntilMaxWaitMs = Math.max(normalizedOptions.waitUntilMaxWaitMs, 0);
|
|
38
|
+
if (normalizedOptions.personalApiKey) {
|
|
39
|
+
if (normalizedOptions.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.');
|
|
40
|
+
const shouldEnableLocalEvaluation = false !== normalizedOptions.enableLocalEvaluation;
|
|
23
41
|
if (shouldEnableLocalEvaluation) this.featureFlagsPoller = new FeatureFlagsPoller({
|
|
24
42
|
pollingInterval: this.options.featureFlagsPollingInterval,
|
|
25
|
-
personalApiKey:
|
|
26
|
-
projectApiKey:
|
|
27
|
-
timeout:
|
|
43
|
+
personalApiKey: normalizedOptions.personalApiKey,
|
|
44
|
+
projectApiKey: normalizedApiKey,
|
|
45
|
+
timeout: normalizedOptions.requestTimeout ?? 10000,
|
|
28
46
|
host: this.host,
|
|
29
|
-
fetch:
|
|
47
|
+
fetch: normalizedOptions.fetch,
|
|
30
48
|
onError: (err)=>{
|
|
31
49
|
this._events.emit('error', err);
|
|
32
50
|
},
|
|
@@ -34,13 +52,13 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
34
52
|
this._events.emit('localEvaluationFlagsLoaded', count);
|
|
35
53
|
},
|
|
36
54
|
customHeaders: this.getCustomHeaders(),
|
|
37
|
-
cacheProvider:
|
|
38
|
-
strictLocalEvaluation:
|
|
55
|
+
cacheProvider: normalizedOptions.flagDefinitionCacheProvider,
|
|
56
|
+
strictLocalEvaluation: normalizedOptions.strictLocalEvaluation
|
|
39
57
|
});
|
|
40
58
|
}
|
|
41
|
-
this.errorTracking = new error_tracking(this,
|
|
59
|
+
this.errorTracking = new error_tracking(this, normalizedOptions, this._logger);
|
|
42
60
|
this.distinctIdHasSentFlagCalls = {};
|
|
43
|
-
this.maxCacheSize =
|
|
61
|
+
this.maxCacheSize = normalizedOptions.maxCacheSize || MAX_CACHE_SIZE;
|
|
44
62
|
}
|
|
45
63
|
enqueue(type, message, options) {
|
|
46
64
|
super.enqueue(type, message, options);
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.29.
|
|
1
|
+
export declare const version = "5.29.3";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
version: ()=>version
|
|
28
28
|
});
|
|
29
|
-
const version = '5.29.
|
|
29
|
+
const version = '5.29.3';
|
|
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.29.
|
|
1
|
+
const version = '5.29.3';
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "5.29.
|
|
3
|
+
"version": "5.29.3",
|
|
4
4
|
"description": "PostHog Node.js integration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "PostHog",
|
|
21
|
-
"email": "
|
|
21
|
+
"email": "engineering@posthog.com",
|
|
22
22
|
"url": "https://posthog.com"
|
|
23
23
|
},
|
|
24
24
|
"main": "dist/entrypoints/index.node.js",
|
|
25
25
|
"module": "dist/entrypoints/index.node.mjs",
|
|
26
26
|
"types": "dist/entrypoints/index.node.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@posthog/core": "1.25.
|
|
28
|
+
"@posthog/core": "1.25.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@edge-runtime/jest-environment": "^4.0.0",
|
package/src/client.ts
CHANGED
|
@@ -48,6 +48,21 @@ const MAX_CACHE_SIZE = 50 * 1000
|
|
|
48
48
|
|
|
49
49
|
const WAITUNTIL_DEBOUNCE_MS = 50
|
|
50
50
|
const WAITUNTIL_MAX_WAIT_MS = 500
|
|
51
|
+
const DEFAULT_NODE_HOST = 'https://us.i.posthog.com'
|
|
52
|
+
|
|
53
|
+
function normalizeApiKey(value?: unknown): string {
|
|
54
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function normalizePersonalApiKey(value?: unknown): string | undefined {
|
|
58
|
+
const normalizedValue = typeof value === 'string' ? value.trim() : ''
|
|
59
|
+
return normalizedValue || undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function normalizeHost(value?: unknown): string {
|
|
63
|
+
const normalizedValue = typeof value === 'string' ? value.trim() : ''
|
|
64
|
+
return normalizedValue || DEFAULT_NODE_HOST
|
|
65
|
+
}
|
|
51
66
|
|
|
52
67
|
// The actual exported Nodejs API.
|
|
53
68
|
export abstract class PostHogBackendClient extends PostHogCoreStateless implements IPostHog {
|
|
@@ -102,41 +117,48 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
102
117
|
* @param options - Configuration options for the client
|
|
103
118
|
*/
|
|
104
119
|
constructor(apiKey: string, options: PostHogOptions = {}) {
|
|
105
|
-
|
|
120
|
+
const normalizedApiKey = normalizeApiKey(apiKey)
|
|
121
|
+
const normalizedOptions = {
|
|
122
|
+
...options,
|
|
123
|
+
host: normalizeHost(options.host),
|
|
124
|
+
personalApiKey: normalizePersonalApiKey(options.personalApiKey),
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
super(normalizedApiKey, normalizedOptions)
|
|
106
128
|
|
|
107
|
-
this.options =
|
|
129
|
+
this.options = normalizedOptions
|
|
108
130
|
this.context = this.initializeContext()
|
|
109
131
|
|
|
110
132
|
this.options.featureFlagsPollingInterval =
|
|
111
|
-
typeof
|
|
112
|
-
? Math.max(
|
|
133
|
+
typeof normalizedOptions.featureFlagsPollingInterval === 'number'
|
|
134
|
+
? Math.max(normalizedOptions.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL)
|
|
113
135
|
: THIRTY_SECONDS
|
|
114
136
|
|
|
115
|
-
if (typeof
|
|
116
|
-
this.options.waitUntilDebounceMs = Math.max(
|
|
137
|
+
if (typeof normalizedOptions.waitUntilDebounceMs === 'number') {
|
|
138
|
+
this.options.waitUntilDebounceMs = Math.max(normalizedOptions.waitUntilDebounceMs, 0)
|
|
117
139
|
}
|
|
118
|
-
if (typeof
|
|
119
|
-
this.options.waitUntilMaxWaitMs = Math.max(
|
|
140
|
+
if (typeof normalizedOptions.waitUntilMaxWaitMs === 'number') {
|
|
141
|
+
this.options.waitUntilMaxWaitMs = Math.max(normalizedOptions.waitUntilMaxWaitMs, 0)
|
|
120
142
|
}
|
|
121
143
|
|
|
122
|
-
if (
|
|
123
|
-
if (
|
|
144
|
+
if (normalizedOptions.personalApiKey) {
|
|
145
|
+
if (normalizedOptions.personalApiKey.includes('phc_')) {
|
|
124
146
|
throw new Error(
|
|
125
147
|
'Your Personal API key is invalid. These keys are prefixed with "phx_" and can be created in PostHog project settings.'
|
|
126
148
|
)
|
|
127
149
|
}
|
|
128
150
|
|
|
129
151
|
// Only start the poller if local evaluation is enabled (defaults to true for backward compatibility)
|
|
130
|
-
const shouldEnableLocalEvaluation =
|
|
152
|
+
const shouldEnableLocalEvaluation = normalizedOptions.enableLocalEvaluation !== false
|
|
131
153
|
|
|
132
154
|
if (shouldEnableLocalEvaluation) {
|
|
133
155
|
this.featureFlagsPoller = new FeatureFlagsPoller({
|
|
134
156
|
pollingInterval: this.options.featureFlagsPollingInterval,
|
|
135
|
-
personalApiKey:
|
|
136
|
-
projectApiKey:
|
|
137
|
-
timeout:
|
|
157
|
+
personalApiKey: normalizedOptions.personalApiKey,
|
|
158
|
+
projectApiKey: normalizedApiKey,
|
|
159
|
+
timeout: normalizedOptions.requestTimeout ?? 10000, // 10 seconds
|
|
138
160
|
host: this.host,
|
|
139
|
-
fetch:
|
|
161
|
+
fetch: normalizedOptions.fetch,
|
|
140
162
|
onError: (err: Error) => {
|
|
141
163
|
this._events.emit('error', err)
|
|
142
164
|
},
|
|
@@ -144,15 +166,15 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
144
166
|
this._events.emit('localEvaluationFlagsLoaded', count)
|
|
145
167
|
},
|
|
146
168
|
customHeaders: this.getCustomHeaders(),
|
|
147
|
-
cacheProvider:
|
|
148
|
-
strictLocalEvaluation:
|
|
169
|
+
cacheProvider: normalizedOptions.flagDefinitionCacheProvider,
|
|
170
|
+
strictLocalEvaluation: normalizedOptions.strictLocalEvaluation,
|
|
149
171
|
})
|
|
150
172
|
}
|
|
151
173
|
}
|
|
152
174
|
|
|
153
|
-
this.errorTracking = new ErrorTracking(this,
|
|
175
|
+
this.errorTracking = new ErrorTracking(this, normalizedOptions, this._logger)
|
|
154
176
|
this.distinctIdHasSentFlagCalls = {}
|
|
155
|
-
this.maxCacheSize =
|
|
177
|
+
this.maxCacheSize = normalizedOptions.maxCacheSize || MAX_CACHE_SIZE
|
|
156
178
|
}
|
|
157
179
|
|
|
158
180
|
protected override enqueue(type: string, message: any, options?: PostHogCaptureOptions): void {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.29.
|
|
1
|
+
export const version = '5.29.3'
|