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/lib/index.esm.js
CHANGED
|
@@ -154,7 +154,7 @@ function __spreadArray(to, from, pack) {
|
|
|
154
154
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
var version = "3.2.
|
|
157
|
+
var version = "3.2.1";
|
|
158
158
|
|
|
159
159
|
var PostHogPersistedProperty;
|
|
160
160
|
(function (PostHogPersistedProperty) {
|
|
@@ -1000,7 +1000,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1000
1000
|
var _this = this;
|
|
1001
1001
|
var _a;
|
|
1002
1002
|
if (this.optedOut) {
|
|
1003
|
-
this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.
|
|
1003
|
+
this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
1004
1004
|
return;
|
|
1005
1005
|
}
|
|
1006
1006
|
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() });
|
|
@@ -1743,6 +1743,7 @@ function () {
|
|
|
1743
1743
|
this.poller = undefined; // NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
1744
1744
|
|
|
1745
1745
|
this.fetch = options.fetch || fetch$1;
|
|
1746
|
+
this.onError = options.onError;
|
|
1746
1747
|
void this.loadFeatureFlags();
|
|
1747
1748
|
}
|
|
1748
1749
|
|
|
@@ -1902,10 +1903,13 @@ function () {
|
|
|
1902
1903
|
this.featureFlags.map(function (flag) {
|
|
1903
1904
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1904
1905
|
var matchValue, matchPayload, e_1;
|
|
1905
|
-
|
|
1906
|
-
|
|
1906
|
+
|
|
1907
|
+
var _a;
|
|
1908
|
+
|
|
1909
|
+
return __generator(this, function (_b) {
|
|
1910
|
+
switch (_b.label) {
|
|
1907
1911
|
case 0:
|
|
1908
|
-
|
|
1912
|
+
_b.trys.push([0, 2,, 3]);
|
|
1909
1913
|
|
|
1910
1914
|
matchValue = this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
|
|
1911
1915
|
response[flag.key] = matchValue;
|
|
@@ -1914,7 +1918,7 @@ function () {
|
|
|
1914
1918
|
, this.computeFeatureFlagPayloadLocally(flag.key, matchValue)];
|
|
1915
1919
|
|
|
1916
1920
|
case 1:
|
|
1917
|
-
matchPayload =
|
|
1921
|
+
matchPayload = _b.sent();
|
|
1918
1922
|
|
|
1919
1923
|
if (matchPayload) {
|
|
1920
1924
|
payloads[flag.key] = matchPayload;
|
|
@@ -1925,10 +1929,10 @@ function () {
|
|
|
1925
1929
|
, 3];
|
|
1926
1930
|
|
|
1927
1931
|
case 2:
|
|
1928
|
-
e_1 =
|
|
1932
|
+
e_1 = _b.sent();
|
|
1929
1933
|
|
|
1930
1934
|
if (e_1 instanceof InconclusiveMatchError) ; else if (e_1 instanceof Error) {
|
|
1931
|
-
|
|
1935
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Error computing flag locally: ".concat(flag.key, ": ").concat(e_1)));
|
|
1932
1936
|
}
|
|
1933
1937
|
|
|
1934
1938
|
fallbackToDecide = true;
|
|
@@ -2166,13 +2170,15 @@ function () {
|
|
|
2166
2170
|
};
|
|
2167
2171
|
|
|
2168
2172
|
FeatureFlagsPoller.prototype._loadFeatureFlags = function () {
|
|
2173
|
+
var _a;
|
|
2174
|
+
|
|
2169
2175
|
return __awaiter(this, void 0, void 0, function () {
|
|
2170
2176
|
var res, responseJson, err_1;
|
|
2171
2177
|
|
|
2172
2178
|
var _this = this;
|
|
2173
2179
|
|
|
2174
|
-
return __generator(this, function (
|
|
2175
|
-
switch (
|
|
2180
|
+
return __generator(this, function (_b) {
|
|
2181
|
+
switch (_b.label) {
|
|
2176
2182
|
case 0:
|
|
2177
2183
|
if (this.poller) {
|
|
2178
2184
|
clearTimeout(this.poller);
|
|
@@ -2182,17 +2188,17 @@ function () {
|
|
|
2182
2188
|
this.poller = setTimeout(function () {
|
|
2183
2189
|
return _this._loadFeatureFlags();
|
|
2184
2190
|
}, this.pollingInterval);
|
|
2185
|
-
|
|
2191
|
+
_b.label = 1;
|
|
2186
2192
|
|
|
2187
2193
|
case 1:
|
|
2188
|
-
|
|
2194
|
+
_b.trys.push([1, 4,, 5]);
|
|
2189
2195
|
|
|
2190
2196
|
return [4
|
|
2191
2197
|
/*yield*/
|
|
2192
2198
|
, this._requestFeatureFlagDefinitions()];
|
|
2193
2199
|
|
|
2194
2200
|
case 2:
|
|
2195
|
-
res =
|
|
2201
|
+
res = _b.sent();
|
|
2196
2202
|
|
|
2197
2203
|
if (res && res.status === 401) {
|
|
2198
2204
|
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");
|
|
@@ -2211,7 +2217,7 @@ function () {
|
|
|
2211
2217
|
, res.json()];
|
|
2212
2218
|
|
|
2213
2219
|
case 3:
|
|
2214
|
-
responseJson =
|
|
2220
|
+
responseJson = _b.sent();
|
|
2215
2221
|
|
|
2216
2222
|
if (!('flags' in responseJson)) {
|
|
2217
2223
|
console.error("Invalid response when getting feature flags: ".concat(JSON.stringify(responseJson)));
|
|
@@ -2229,11 +2235,11 @@ function () {
|
|
|
2229
2235
|
, 5];
|
|
2230
2236
|
|
|
2231
2237
|
case 4:
|
|
2232
|
-
err_1 =
|
|
2238
|
+
err_1 = _b.sent(); // if an error that is not an instance of ClientError is thrown
|
|
2233
2239
|
// we silently ignore the error when reloading feature flags
|
|
2234
2240
|
|
|
2235
2241
|
if (err_1 instanceof ClientError) {
|
|
2236
|
-
|
|
2242
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, err_1);
|
|
2237
2243
|
}
|
|
2238
2244
|
|
|
2239
2245
|
return [3
|
|
@@ -2558,7 +2564,10 @@ function (_super) {
|
|
|
2558
2564
|
projectApiKey: apiKey,
|
|
2559
2565
|
timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10000,
|
|
2560
2566
|
host: _this.host,
|
|
2561
|
-
fetch: options.fetch
|
|
2567
|
+
fetch: options.fetch,
|
|
2568
|
+
onError: function (err) {
|
|
2569
|
+
_this._events.emit('error', err);
|
|
2570
|
+
}
|
|
2562
2571
|
});
|
|
2563
2572
|
}
|
|
2564
2573
|
|