posthog-node 5.11.2 → 5.13.0
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/LICENSE +56 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -2
- package/dist/client.mjs +3 -2
- package/dist/entrypoints/index.edge.js +1 -3
- package/dist/entrypoints/index.edge.mjs +1 -3
- package/dist/entrypoints/index.node.js +1 -3
- package/dist/entrypoints/index.node.mjs +1 -3
- package/dist/experimental.d.ts +11 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +18 -0
- package/dist/experimental.mjs +0 -0
- package/dist/extensions/feature-flags/cache.d.ts +110 -0
- package/dist/extensions/feature-flags/cache.d.ts.map +1 -0
- package/dist/extensions/feature-flags/cache.js +18 -0
- package/dist/extensions/feature-flags/cache.mjs +0 -0
- package/dist/extensions/feature-flags/feature-flags.d.ts +15 -1
- package/dist/extensions/feature-flags/feature-flags.d.ts.map +1 -1
- package/dist/extensions/feature-flags/feature-flags.js +71 -9
- package/dist/extensions/feature-flags/feature-flags.mjs +71 -9
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +6 -2
- package/src/client.ts +2 -1
- package/src/entrypoints/index.edge.ts +1 -1
- package/src/entrypoints/index.node.ts +1 -1
- package/src/experimental.ts +11 -0
- package/src/extensions/feature-flags/cache.ts +114 -0
- package/src/extensions/feature-flags/feature-flags.ts +141 -12
- package/src/types.ts +28 -0
- package/src/version.ts +1 -1
package/LICENSE
CHANGED
|
@@ -219,7 +219,7 @@ limitations under the License.
|
|
|
219
219
|
|
|
220
220
|
---
|
|
221
221
|
|
|
222
|
-
Some files in this codebase contain code from getsentry/sentry-javascript by Software, Inc. dba Sentry.
|
|
222
|
+
Some files in this codebase contain code from getsentry/sentry-javascript or getsentry/sentry-react-native by Software, Inc. dba Sentry.
|
|
223
223
|
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
224
224
|
|
|
225
225
|
MIT License
|
|
@@ -242,4 +242,58 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
242
242
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
243
243
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
244
244
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
245
|
-
SOFTWARE.
|
|
245
|
+
SOFTWARE.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
|
|
250
|
+
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
251
|
+
|
|
252
|
+
MIT License
|
|
253
|
+
|
|
254
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
255
|
+
|
|
256
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
257
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
258
|
+
in the Software without restriction, including without limitation the rights
|
|
259
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
260
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
261
|
+
furnished to do so, subject to the following conditions:
|
|
262
|
+
|
|
263
|
+
The above copyright notice and this permission notice shall be included in all
|
|
264
|
+
copies or substantial portions of the Software.
|
|
265
|
+
|
|
266
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
267
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
268
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
269
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
270
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
271
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
272
|
+
SOFTWARE.
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
|
|
277
|
+
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
278
|
+
|
|
279
|
+
The MIT License (MIT)
|
|
280
|
+
|
|
281
|
+
Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
|
|
282
|
+
|
|
283
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
284
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
285
|
+
in the Software without restriction, including without limitation the rights
|
|
286
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
287
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
288
|
+
furnished to do so, subject to the following conditions:
|
|
289
|
+
|
|
290
|
+
The above copyright notice and this permission notice shall be included in all
|
|
291
|
+
copies or substantial portions of the Software.
|
|
292
|
+
|
|
293
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
294
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
295
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
296
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
297
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
298
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
299
|
+
SOFTWARE.
|
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,EAGtB,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;AAMxF,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;IAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;
|
|
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,EAGtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,cAA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FF,OAAO,CAAC,cAAc;CAuBvB"}
|
package/dist/client.js
CHANGED
|
@@ -65,7 +65,8 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
65
65
|
onLoad: (count)=>{
|
|
66
66
|
this._events.emit('localEvaluationFlagsLoaded', count);
|
|
67
67
|
},
|
|
68
|
-
customHeaders: this.getCustomHeaders()
|
|
68
|
+
customHeaders: this.getCustomHeaders(),
|
|
69
|
+
cacheProvider: options.flagDefinitionCacheProvider
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
this.errorTracking = new (index_js_default())(this, options, this._logger);
|
|
@@ -299,7 +300,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
299
300
|
await this.featureFlagsPoller?.loadFeatureFlags(true);
|
|
300
301
|
}
|
|
301
302
|
async _shutdown(shutdownTimeoutMs) {
|
|
302
|
-
this.featureFlagsPoller?.stopPoller();
|
|
303
|
+
this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
|
|
303
304
|
this.errorTracking.shutdown();
|
|
304
305
|
return super._shutdown(shutdownTimeoutMs);
|
|
305
306
|
}
|
package/dist/client.mjs
CHANGED
|
@@ -27,7 +27,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
27
27
|
onLoad: (count)=>{
|
|
28
28
|
this._events.emit('localEvaluationFlagsLoaded', count);
|
|
29
29
|
},
|
|
30
|
-
customHeaders: this.getCustomHeaders()
|
|
30
|
+
customHeaders: this.getCustomHeaders(),
|
|
31
|
+
cacheProvider: options.flagDefinitionCacheProvider
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
this.errorTracking = new error_tracking(this, options, this._logger);
|
|
@@ -261,7 +262,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
261
262
|
await this.featureFlagsPoller?.loadFeatureFlags(true);
|
|
262
263
|
}
|
|
263
264
|
async _shutdown(shutdownTimeoutMs) {
|
|
264
|
-
this.featureFlagsPoller?.stopPoller();
|
|
265
|
+
this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
|
|
265
266
|
this.errorTracking.shutdown();
|
|
266
267
|
return super._shutdown(shutdownTimeoutMs);
|
|
267
268
|
}
|
|
@@ -78,9 +78,7 @@ var __webpack_exports__ = {};
|
|
|
78
78
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.ObjectCoercer(),
|
|
79
79
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.StringCoercer(),
|
|
80
80
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.PrimitiveCoercer()
|
|
81
|
-
],
|
|
82
|
-
_posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.nodeStackLineParser
|
|
83
|
-
]);
|
|
81
|
+
], _posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.createStackParser("node:javascript", _posthog_core__WEBPACK_IMPORTED_MODULE_3__.ErrorTracking.nodeStackLineParser));
|
|
84
82
|
class PostHog extends _client__WEBPACK_IMPORTED_MODULE_2__.PostHogBackendClient {
|
|
85
83
|
getLibraryId() {
|
|
86
84
|
return 'posthog-edge';
|
|
@@ -8,9 +8,7 @@ error_tracking.errorPropertiesBuilder = new ErrorTracking.ErrorPropertiesBuilder
|
|
|
8
8
|
new ErrorTracking.ObjectCoercer(),
|
|
9
9
|
new ErrorTracking.StringCoercer(),
|
|
10
10
|
new ErrorTracking.PrimitiveCoercer()
|
|
11
|
-
],
|
|
12
|
-
ErrorTracking.nodeStackLineParser
|
|
13
|
-
]);
|
|
11
|
+
], ErrorTracking.createStackParser("node:javascript", ErrorTracking.nodeStackLineParser));
|
|
14
12
|
class PostHog extends PostHogBackendClient {
|
|
15
13
|
getLibraryId() {
|
|
16
14
|
return 'posthog-edge';
|
|
@@ -86,9 +86,7 @@ var __webpack_exports__ = {};
|
|
|
86
86
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.ObjectCoercer(),
|
|
87
87
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.StringCoercer(),
|
|
88
88
|
new _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.PrimitiveCoercer()
|
|
89
|
-
], [
|
|
90
|
-
_posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.nodeStackLineParser
|
|
91
|
-
], [
|
|
89
|
+
], _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.createStackParser("node:javascript", _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.nodeStackLineParser), [
|
|
92
90
|
(0, _extensions_error_tracking_modifiers_module_node__WEBPACK_IMPORTED_MODULE_1__.createModulerModifier)(),
|
|
93
91
|
_extensions_error_tracking_modifiers_context_lines_node__WEBPACK_IMPORTED_MODULE_2__.addSourceContext
|
|
94
92
|
]);
|
|
@@ -10,9 +10,7 @@ error_tracking.errorPropertiesBuilder = new ErrorTracking.ErrorPropertiesBuilder
|
|
|
10
10
|
new ErrorTracking.ObjectCoercer(),
|
|
11
11
|
new ErrorTracking.StringCoercer(),
|
|
12
12
|
new ErrorTracking.PrimitiveCoercer()
|
|
13
|
-
], [
|
|
14
|
-
ErrorTracking.nodeStackLineParser
|
|
15
|
-
], [
|
|
13
|
+
], ErrorTracking.createStackParser("node:javascript", ErrorTracking.nodeStackLineParser), [
|
|
16
14
|
createModulerModifier(),
|
|
17
15
|
addSourceContext
|
|
18
16
|
]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experimental APIs
|
|
3
|
+
*
|
|
4
|
+
* This module exports experimental features that may change or be removed in minor versions.
|
|
5
|
+
* Use these APIs with caution and be prepared for breaking changes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
export type { FlagDefinitionCacheProvider, FlagDefinitionCacheData } from './extensions/feature-flags/cache';
|
|
11
|
+
//# sourceMappingURL=experimental.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experimental.d.ts","sourceRoot":"","sources":["../src/experimental.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { PostHogFeatureFlag, PropertyGroup } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the complete set of feature flag data needed for local evaluation.
|
|
4
|
+
*
|
|
5
|
+
* This includes flag definitions, group type mappings, and cohort property groups.
|
|
6
|
+
*/
|
|
7
|
+
export interface FlagDefinitionCacheData {
|
|
8
|
+
/** Array of feature flag definitions */
|
|
9
|
+
flags: PostHogFeatureFlag[];
|
|
10
|
+
/** Mapping of group type index to group name */
|
|
11
|
+
groupTypeMapping: Record<string, string>;
|
|
12
|
+
/** Cohort property groups for local evaluation */
|
|
13
|
+
cohorts: Record<string, PropertyGroup>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @experimental This API is experimental and may change in minor versions.
|
|
17
|
+
*
|
|
18
|
+
* Provider interface for caching feature flag definitions.
|
|
19
|
+
*
|
|
20
|
+
* Implementations can use this to control when flag definitions are fetched
|
|
21
|
+
* and how they're cached (Redis, database, filesystem, etc.).
|
|
22
|
+
*
|
|
23
|
+
* This interface is designed for server-side environments where multiple workers
|
|
24
|
+
* need to share flag definitions and coordinate fetching to reduce API calls.
|
|
25
|
+
*
|
|
26
|
+
* All methods may throw errors - the poller will catch and log them gracefully,
|
|
27
|
+
* ensuring cache provider errors never break flag evaluation.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { FlagDefinitionCacheProvider } from 'posthog-node/experimental'
|
|
32
|
+
*
|
|
33
|
+
* class RedisFlagCache implements FlagDefinitionCacheProvider {
|
|
34
|
+
* constructor(private redis: Redis, private teamKey: string) { }
|
|
35
|
+
*
|
|
36
|
+
* async getFlagDefinitions(): Promise<FlagDefinitionCacheData | undefined> {
|
|
37
|
+
* const cached = await this.redis.get(`posthog:flags:${this.teamKey}`)
|
|
38
|
+
* return cached ? JSON.parse(cached) : undefined
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* async shouldFetchFlagDefinitions(): Promise<boolean> {
|
|
42
|
+
* // Acquire distributed lock - only one worker fetches
|
|
43
|
+
* const acquired = await this.redis.set(`posthog:flags:${this.teamKey}:lock`, '1', 'EX', 60, 'NX')
|
|
44
|
+
* return acquired === 'OK'
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* async onFlagDefinitionsReceived(data: FlagDefinitionCacheData): Promise<void> {
|
|
48
|
+
* await this.redis.set(`posthog:flags:${this.teamKey}`, JSON.stringify(data), 'EX', 300)
|
|
49
|
+
* await this.redis.del(`posthog:flags:${this.teamKey}:lock`)
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* async shutdown(): Promise<void> {
|
|
53
|
+
* await this.redis.del(`posthog:flags:${this.teamKey}:lock`)
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export interface FlagDefinitionCacheProvider {
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve cached flag definitions.
|
|
61
|
+
*
|
|
62
|
+
* Called when the poller is refreshing in-memory flag definitions. If this returns undefined
|
|
63
|
+
* (or throws an error), the poller will fetch fresh data from the PostHog API if no flag
|
|
64
|
+
* definitions are in memory. Otherwise, stale cache data is used until the next poll cycle.
|
|
65
|
+
*
|
|
66
|
+
* @returns cached definitions if available, undefined if cache is empty
|
|
67
|
+
* @throws if an error occurs while accessing the cache (error will be logged)
|
|
68
|
+
*/
|
|
69
|
+
getFlagDefinitions(): Promise<FlagDefinitionCacheData | undefined> | FlagDefinitionCacheData | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Determines whether this instance should fetch new flag definitions.
|
|
72
|
+
*
|
|
73
|
+
* Use this to implement distributed coordination (e.g., via distributed locks)
|
|
74
|
+
* to ensure only one instance fetches at a time in a multi-worker setup.
|
|
75
|
+
*
|
|
76
|
+
* When multiple workers share a cache, typically only one should fetch while
|
|
77
|
+
* others use cached data. Implementations can use Redis locks, database locks,
|
|
78
|
+
* or other coordination mechanisms.
|
|
79
|
+
*
|
|
80
|
+
* @returns true if this instance should fetch, false to skip and read cache
|
|
81
|
+
* @throws if coordination backend is unavailable (error will be logged, fetch continues)
|
|
82
|
+
*/
|
|
83
|
+
shouldFetchFlagDefinitions(): Promise<boolean> | boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Called after successfully receiving new flag definitions from PostHog.
|
|
86
|
+
*
|
|
87
|
+
* Store the definitions in your cache backend here. This is called only
|
|
88
|
+
* after a successful API response with valid flag data.
|
|
89
|
+
*
|
|
90
|
+
* If this method throws, the error is logged but flag definitions are still
|
|
91
|
+
* stored in memory, ensuring local evaluation can still be performed.
|
|
92
|
+
*
|
|
93
|
+
* @param data - The complete flag definition data from PostHog
|
|
94
|
+
* @throws if storage backend is unavailable (error will be logged)
|
|
95
|
+
*/
|
|
96
|
+
onFlagDefinitionsReceived(data: FlagDefinitionCacheData): Promise<void> | void;
|
|
97
|
+
/**
|
|
98
|
+
* Called when the PostHog client shuts down.
|
|
99
|
+
*
|
|
100
|
+
* Release any held locks, close connections, or clean up resources here.
|
|
101
|
+
*
|
|
102
|
+
* Both sync and async cleanup are supported. Async cleanup has a timeout
|
|
103
|
+
* (default 30s, configurable via client shutdown options) to prevent the
|
|
104
|
+
* process shutdown from hanging indefinitely.
|
|
105
|
+
*
|
|
106
|
+
* @returns Promise that resolves when cleanup is complete, or void for sync cleanup
|
|
107
|
+
*/
|
|
108
|
+
shutdown(): Promise<void> | void;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEpE;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,KAAK,EAAE,kBAAkB,EAAE,CAAA;IAC3B,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;;;OASG;IACH,kBAAkB,IAAI,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,GAAG,uBAAuB,GAAG,SAAS,CAAA;IAExG;;;;;;;;;;;;OAYG;IACH,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;IAExD;;;;;;;;;;;OAWG;IACH,yBAAyB,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAE9E;;;;;;;;;;OAUG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
File without changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FeatureFlagCondition, PostHogFeatureFlag, PropertyGroup } from '../../types';
|
|
2
2
|
import type { FeatureFlagValue, JsonType, PostHogFetchOptions, PostHogFetchResponse } from '@posthog/core';
|
|
3
|
+
import { FlagDefinitionCacheProvider } from './cache';
|
|
3
4
|
declare class ClientError extends Error {
|
|
4
5
|
constructor(message: string);
|
|
5
6
|
}
|
|
@@ -21,6 +22,7 @@ type FeatureFlagsPollerOptions = {
|
|
|
21
22
|
customHeaders?: {
|
|
22
23
|
[key: string]: string;
|
|
23
24
|
};
|
|
25
|
+
cacheProvider?: FlagDefinitionCacheProvider;
|
|
24
26
|
};
|
|
25
27
|
declare class FeatureFlagsPoller {
|
|
26
28
|
pollingInterval: number;
|
|
@@ -43,6 +45,9 @@ declare class FeatureFlagsPoller {
|
|
|
43
45
|
shouldBeginExponentialBackoff: boolean;
|
|
44
46
|
backOffCount: number;
|
|
45
47
|
onLoad?: (count: number) => void;
|
|
48
|
+
private cacheProvider?;
|
|
49
|
+
private hasAttemptedCacheLoad;
|
|
50
|
+
private loadingPromise?;
|
|
46
51
|
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }: FeatureFlagsPollerOptions);
|
|
47
52
|
debug(enabled?: boolean): void;
|
|
48
53
|
private logMsgIfDebug;
|
|
@@ -68,6 +73,15 @@ declare class FeatureFlagsPoller {
|
|
|
68
73
|
valueMax: number;
|
|
69
74
|
key: string;
|
|
70
75
|
}[];
|
|
76
|
+
/**
|
|
77
|
+
* Updates the internal flag state with the provided flag data.
|
|
78
|
+
*/
|
|
79
|
+
private updateFlagState;
|
|
80
|
+
/**
|
|
81
|
+
* Attempts to load flags from cache and update internal state.
|
|
82
|
+
* Returns true if flags were successfully loaded from cache, false otherwise.
|
|
83
|
+
*/
|
|
84
|
+
private loadFromCache;
|
|
71
85
|
loadFeatureFlags(forceReload?: boolean): Promise<void>;
|
|
72
86
|
/**
|
|
73
87
|
* Returns true if the feature flags poller has loaded successfully at least once and has more than 0 feature flags.
|
|
@@ -84,7 +98,7 @@ declare class FeatureFlagsPoller {
|
|
|
84
98
|
_loadFeatureFlags(): Promise<void>;
|
|
85
99
|
private getPersonalApiKeyRequestOptions;
|
|
86
100
|
_requestFeatureFlagDefinitions(): Promise<PostHogFetchResponse>;
|
|
87
|
-
stopPoller(): void
|
|
101
|
+
stopPoller(timeoutMs?: number): Promise<void>;
|
|
88
102
|
}
|
|
89
103
|
declare function matchProperty(property: FeatureFlagCondition['properties'][number], propertyValues: Record<string, any>, warnFunction?: (msg: string) => void): boolean;
|
|
90
104
|
declare function relativeDateParseForFeatureFlagMatching(value: string): Date | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmC,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmC,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAG1G,OAAO,EAAE,2BAA2B,EAA2B,MAAM,SAAS,CAAA;AAQ9E,cAAM,WAAY,SAAQ,KAAK;gBACjB,OAAO,EAAE,MAAM;CAO5B;AAED,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAS5B;AAED,cAAM,wBAAyB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAS5B;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACpF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,aAAa,CAAC,EAAE;QAAE,CAAC,G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I,OAAO,CAAC,oBAAoB,CAAC;IAyBzD,UAAU,CAAC,SAAS,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAuB3D;AAWD,iBAAS,aAAa,CACpB,QAAQ,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EACpD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GACnC,OAAO,CA6GT;AAkKD,iBAAS,uCAAuC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAmC3E;AAED,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,uCAAuC,EACvC,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,GACZ,CAAA"}
|
|
@@ -68,6 +68,7 @@ class FeatureFlagsPoller {
|
|
|
68
68
|
this.debugMode = false;
|
|
69
69
|
this.shouldBeginExponentialBackoff = false;
|
|
70
70
|
this.backOffCount = 0;
|
|
71
|
+
this.hasAttemptedCacheLoad = false;
|
|
71
72
|
this.pollingInterval = pollingInterval;
|
|
72
73
|
this.personalApiKey = personalApiKey;
|
|
73
74
|
this.featureFlags = [];
|
|
@@ -83,6 +84,7 @@ class FeatureFlagsPoller {
|
|
|
83
84
|
this.onError = options.onError;
|
|
84
85
|
this.customHeaders = customHeaders;
|
|
85
86
|
this.onLoad = options.onLoad;
|
|
87
|
+
this.cacheProvider = options.cacheProvider;
|
|
86
88
|
this.loadFeatureFlags();
|
|
87
89
|
}
|
|
88
90
|
debug(enabled = true) {
|
|
@@ -270,8 +272,39 @@ class FeatureFlagsPoller {
|
|
|
270
272
|
});
|
|
271
273
|
return lookupTable;
|
|
272
274
|
}
|
|
275
|
+
updateFlagState(flagData) {
|
|
276
|
+
this.featureFlags = flagData.flags;
|
|
277
|
+
this.featureFlagsByKey = flagData.flags.reduce((acc, curr)=>(acc[curr.key] = curr, acc), {});
|
|
278
|
+
this.groupTypeMapping = flagData.groupTypeMapping;
|
|
279
|
+
this.cohorts = flagData.cohorts;
|
|
280
|
+
this.loadedSuccessfullyOnce = true;
|
|
281
|
+
}
|
|
282
|
+
async loadFromCache(debugMessage) {
|
|
283
|
+
if (!this.cacheProvider) return false;
|
|
284
|
+
try {
|
|
285
|
+
const cached = await this.cacheProvider.getFlagDefinitions();
|
|
286
|
+
if (cached) {
|
|
287
|
+
this.updateFlagState(cached);
|
|
288
|
+
this.logMsgIfDebug(()=>console.debug(`[FEATURE FLAGS] ${debugMessage} (${cached.flags.length} flags)`));
|
|
289
|
+
this.onLoad?.(this.featureFlags.length);
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
} catch (err) {
|
|
294
|
+
this.onError?.(new Error(`Failed to load from cache: ${err}`));
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
273
298
|
async loadFeatureFlags(forceReload = false) {
|
|
274
|
-
if (
|
|
299
|
+
if (this.cacheProvider && !this.hasAttemptedCacheLoad) {
|
|
300
|
+
this.hasAttemptedCacheLoad = true;
|
|
301
|
+
await this.loadFromCache('Loaded flags from cache');
|
|
302
|
+
}
|
|
303
|
+
if (this.loadingPromise) return this.loadingPromise;
|
|
304
|
+
if (!this.loadedSuccessfullyOnce || forceReload) {
|
|
305
|
+
this.loadingPromise = this._loadFeatureFlags();
|
|
306
|
+
await this.loadingPromise;
|
|
307
|
+
}
|
|
275
308
|
}
|
|
276
309
|
isLocalEvaluationReady() {
|
|
277
310
|
return (this.loadedSuccessfullyOnce ?? false) && (this.featureFlags?.length ?? 0) > 0;
|
|
@@ -287,6 +320,17 @@ class FeatureFlagsPoller {
|
|
|
287
320
|
}
|
|
288
321
|
this.poller = setTimeout(()=>this._loadFeatureFlags(), this.getPollingInterval());
|
|
289
322
|
try {
|
|
323
|
+
let shouldFetch = true;
|
|
324
|
+
if (this.cacheProvider) try {
|
|
325
|
+
shouldFetch = await this.cacheProvider.shouldFetchFlagDefinitions();
|
|
326
|
+
} catch (err) {
|
|
327
|
+
this.onError?.(new Error(`Error in shouldFetchFlagDefinitions: ${err}`));
|
|
328
|
+
}
|
|
329
|
+
if (!shouldFetch) {
|
|
330
|
+
const loaded = await this.loadFromCache('Loaded flags from cache (skipped fetch)');
|
|
331
|
+
if (loaded) return;
|
|
332
|
+
if (this.loadedSuccessfullyOnce) return;
|
|
333
|
+
}
|
|
290
334
|
const res = await this._requestFeatureFlagDefinitions();
|
|
291
335
|
if (!res) return;
|
|
292
336
|
switch(res.status){
|
|
@@ -313,13 +357,19 @@ class FeatureFlagsPoller {
|
|
|
313
357
|
{
|
|
314
358
|
const responseJson = await res.json() ?? {};
|
|
315
359
|
if (!('flags' in responseJson)) return void this.onError?.(new Error(`Invalid response when getting feature flags: ${JSON.stringify(responseJson)}`));
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
360
|
+
const flagData = {
|
|
361
|
+
flags: responseJson.flags ?? [],
|
|
362
|
+
groupTypeMapping: responseJson.group_type_mapping || {},
|
|
363
|
+
cohorts: responseJson.cohorts || {}
|
|
364
|
+
};
|
|
365
|
+
this.updateFlagState(flagData);
|
|
321
366
|
this.shouldBeginExponentialBackoff = false;
|
|
322
367
|
this.backOffCount = 0;
|
|
368
|
+
if (this.cacheProvider && shouldFetch) try {
|
|
369
|
+
await this.cacheProvider.onFlagDefinitionsReceived(flagData);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
this.onError?.(new Error(`Failed to store in cache: ${err}`));
|
|
372
|
+
}
|
|
323
373
|
this.onLoad?.(this.featureFlags.length);
|
|
324
374
|
break;
|
|
325
375
|
}
|
|
@@ -328,6 +378,8 @@ class FeatureFlagsPoller {
|
|
|
328
378
|
}
|
|
329
379
|
} catch (err) {
|
|
330
380
|
if (err instanceof ClientError) this.onError?.(err);
|
|
381
|
+
} finally{
|
|
382
|
+
this.loadingPromise = void 0;
|
|
331
383
|
}
|
|
332
384
|
}
|
|
333
385
|
getPersonalApiKeyRequestOptions(method = 'GET') {
|
|
@@ -340,7 +392,7 @@ class FeatureFlagsPoller {
|
|
|
340
392
|
}
|
|
341
393
|
};
|
|
342
394
|
}
|
|
343
|
-
|
|
395
|
+
_requestFeatureFlagDefinitions() {
|
|
344
396
|
const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`;
|
|
345
397
|
const options = this.getPersonalApiKeyRequestOptions();
|
|
346
398
|
let abortTimeout = null;
|
|
@@ -352,13 +404,23 @@ class FeatureFlagsPoller {
|
|
|
352
404
|
options.signal = controller.signal;
|
|
353
405
|
}
|
|
354
406
|
try {
|
|
355
|
-
|
|
407
|
+
const fetch1 = this.fetch;
|
|
408
|
+
return fetch1(url, options);
|
|
356
409
|
} finally{
|
|
357
410
|
clearTimeout(abortTimeout);
|
|
358
411
|
}
|
|
359
412
|
}
|
|
360
|
-
stopPoller() {
|
|
413
|
+
async stopPoller(timeoutMs = 30000) {
|
|
361
414
|
clearTimeout(this.poller);
|
|
415
|
+
if (this.cacheProvider) try {
|
|
416
|
+
const shutdownResult = this.cacheProvider.shutdown();
|
|
417
|
+
if (shutdownResult instanceof Promise) await Promise.race([
|
|
418
|
+
shutdownResult,
|
|
419
|
+
new Promise((_, reject)=>setTimeout(()=>reject(new Error(`Cache shutdown timeout after ${timeoutMs}ms`)), timeoutMs))
|
|
420
|
+
]);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
this.onError?.(new Error(`Error during cache shutdown: ${err}`));
|
|
423
|
+
}
|
|
362
424
|
}
|
|
363
425
|
}
|
|
364
426
|
async function _hash(key, distinctId, salt = '') {
|