posthog-node 3.2.0 → 3.2.1
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/CHANGELOG.md +4 -0
- package/lib/index.cjs.js +26 -17
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +26 -17
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +5 -2
- package/src/posthog-node.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 3.2.1 - 2023-12-15
|
|
2
|
+
|
|
3
|
+
1. Fixes issue where a background refresh of feature flags could throw an unhandled error. It now emits to be detected by `.on('error', ...)`
|
|
4
|
+
|
|
1
5
|
# 3.2.0 - 2023-12-05
|
|
2
6
|
|
|
3
7
|
1. Fixes issues with Axios imports for non-node environments like Cloudflare workers
|
package/lib/index.cjs.js
CHANGED
|
@@ -158,7 +158,7 @@ function __spreadArray(to, from, pack) {
|
|
|
158
158
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
var version = "3.2.
|
|
161
|
+
var version = "3.2.1";
|
|
162
162
|
|
|
163
163
|
var PostHogPersistedProperty;
|
|
164
164
|
(function (PostHogPersistedProperty) {
|
|
@@ -1004,7 +1004,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1004
1004
|
var _this = this;
|
|
1005
1005
|
var _a;
|
|
1006
1006
|
if (this.optedOut) {
|
|
1007
|
-
this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.
|
|
1007
|
+
this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
1008
1008
|
return;
|
|
1009
1009
|
}
|
|
1010
1010
|
var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime() });
|
|
@@ -1747,6 +1747,7 @@ function () {
|
|
|
1747
1747
|
this.poller = undefined; // NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
1748
1748
|
|
|
1749
1749
|
this.fetch = options.fetch || fetch$1;
|
|
1750
|
+
this.onError = options.onError;
|
|
1750
1751
|
void this.loadFeatureFlags();
|
|
1751
1752
|
}
|
|
1752
1753
|
|
|
@@ -1906,10 +1907,13 @@ function () {
|
|
|
1906
1907
|
this.featureFlags.map(function (flag) {
|
|
1907
1908
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1908
1909
|
var matchValue, matchPayload, e_1;
|
|
1909
|
-
|
|
1910
|
-
|
|
1910
|
+
|
|
1911
|
+
var _a;
|
|
1912
|
+
|
|
1913
|
+
return __generator(this, function (_b) {
|
|
1914
|
+
switch (_b.label) {
|
|
1911
1915
|
case 0:
|
|
1912
|
-
|
|
1916
|
+
_b.trys.push([0, 2,, 3]);
|
|
1913
1917
|
|
|
1914
1918
|
matchValue = this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
|
|
1915
1919
|
response[flag.key] = matchValue;
|
|
@@ -1918,7 +1922,7 @@ function () {
|
|
|
1918
1922
|
, this.computeFeatureFlagPayloadLocally(flag.key, matchValue)];
|
|
1919
1923
|
|
|
1920
1924
|
case 1:
|
|
1921
|
-
matchPayload =
|
|
1925
|
+
matchPayload = _b.sent();
|
|
1922
1926
|
|
|
1923
1927
|
if (matchPayload) {
|
|
1924
1928
|
payloads[flag.key] = matchPayload;
|
|
@@ -1929,10 +1933,10 @@ function () {
|
|
|
1929
1933
|
, 3];
|
|
1930
1934
|
|
|
1931
1935
|
case 2:
|
|
1932
|
-
e_1 =
|
|
1936
|
+
e_1 = _b.sent();
|
|
1933
1937
|
|
|
1934
1938
|
if (e_1 instanceof InconclusiveMatchError) ; else if (e_1 instanceof Error) {
|
|
1935
|
-
|
|
1939
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Error computing flag locally: ".concat(flag.key, ": ").concat(e_1)));
|
|
1936
1940
|
}
|
|
1937
1941
|
|
|
1938
1942
|
fallbackToDecide = true;
|
|
@@ -2170,13 +2174,15 @@ function () {
|
|
|
2170
2174
|
};
|
|
2171
2175
|
|
|
2172
2176
|
FeatureFlagsPoller.prototype._loadFeatureFlags = function () {
|
|
2177
|
+
var _a;
|
|
2178
|
+
|
|
2173
2179
|
return __awaiter(this, void 0, void 0, function () {
|
|
2174
2180
|
var res, responseJson, err_1;
|
|
2175
2181
|
|
|
2176
2182
|
var _this = this;
|
|
2177
2183
|
|
|
2178
|
-
return __generator(this, function (
|
|
2179
|
-
switch (
|
|
2184
|
+
return __generator(this, function (_b) {
|
|
2185
|
+
switch (_b.label) {
|
|
2180
2186
|
case 0:
|
|
2181
2187
|
if (this.poller) {
|
|
2182
2188
|
clearTimeout(this.poller);
|
|
@@ -2186,17 +2192,17 @@ function () {
|
|
|
2186
2192
|
this.poller = setTimeout(function () {
|
|
2187
2193
|
return _this._loadFeatureFlags();
|
|
2188
2194
|
}, this.pollingInterval);
|
|
2189
|
-
|
|
2195
|
+
_b.label = 1;
|
|
2190
2196
|
|
|
2191
2197
|
case 1:
|
|
2192
|
-
|
|
2198
|
+
_b.trys.push([1, 4,, 5]);
|
|
2193
2199
|
|
|
2194
2200
|
return [4
|
|
2195
2201
|
/*yield*/
|
|
2196
2202
|
, this._requestFeatureFlagDefinitions()];
|
|
2197
2203
|
|
|
2198
2204
|
case 2:
|
|
2199
|
-
res =
|
|
2205
|
+
res = _b.sent();
|
|
2200
2206
|
|
|
2201
2207
|
if (res && res.status === 401) {
|
|
2202
2208
|
throw new ClientError("Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview");
|
|
@@ -2215,7 +2221,7 @@ function () {
|
|
|
2215
2221
|
, res.json()];
|
|
2216
2222
|
|
|
2217
2223
|
case 3:
|
|
2218
|
-
responseJson =
|
|
2224
|
+
responseJson = _b.sent();
|
|
2219
2225
|
|
|
2220
2226
|
if (!('flags' in responseJson)) {
|
|
2221
2227
|
console.error("Invalid response when getting feature flags: ".concat(JSON.stringify(responseJson)));
|
|
@@ -2233,11 +2239,11 @@ function () {
|
|
|
2233
2239
|
, 5];
|
|
2234
2240
|
|
|
2235
2241
|
case 4:
|
|
2236
|
-
err_1 =
|
|
2242
|
+
err_1 = _b.sent(); // if an error that is not an instance of ClientError is thrown
|
|
2237
2243
|
// we silently ignore the error when reloading feature flags
|
|
2238
2244
|
|
|
2239
2245
|
if (err_1 instanceof ClientError) {
|
|
2240
|
-
|
|
2246
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, err_1);
|
|
2241
2247
|
}
|
|
2242
2248
|
|
|
2243
2249
|
return [3
|
|
@@ -2562,7 +2568,10 @@ function (_super) {
|
|
|
2562
2568
|
projectApiKey: apiKey,
|
|
2563
2569
|
timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10000,
|
|
2564
2570
|
host: _this.host,
|
|
2565
|
-
fetch: options.fetch
|
|
2571
|
+
fetch: options.fetch,
|
|
2572
|
+
onError: function (err) {
|
|
2573
|
+
_this._events.emit('error', err);
|
|
2574
|
+
}
|
|
2566
2575
|
});
|
|
2567
2576
|
}
|
|
2568
2577
|
|