posthog-node 3.1.1 → 3.1.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/CHANGELOG.md +8 -0
- package/lib/index.cjs.js +39 -26
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +39 -26
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +7 -2
- package/lib/posthog-core/src/types.d.ts +3 -1
- package/package.json +2 -2
- package/src/feature-flags.ts +2 -3
- package/src/posthog-node.ts +1 -0
- package/test/posthog-node.spec.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 3.1.3 - 2023-10-27
|
|
2
|
+
|
|
3
|
+
1. Updates axios dependency
|
|
4
|
+
|
|
5
|
+
# 3.1.2 - 2023-08-17
|
|
6
|
+
|
|
7
|
+
1. Returns the current flag property with $feature_flag_called events, to make it easier to use in experiments
|
|
8
|
+
|
|
1
9
|
# 3.1.1 - 2023-04-26
|
|
2
10
|
|
|
3
11
|
1. Replace crypto library with pure-js rusha library which makes posthog-node work with Cloudflare Workers in Next.js edge runtime.
|
package/lib/index.cjs.js
CHANGED
|
@@ -163,7 +163,7 @@ function __spreadArray(to, from, pack) {
|
|
|
163
163
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
var version = "3.1.
|
|
166
|
+
var version = "3.1.3";
|
|
167
167
|
|
|
168
168
|
var PostHogPersistedProperty;
|
|
169
169
|
(function (PostHogPersistedProperty) {
|
|
@@ -179,6 +179,8 @@ var PostHogPersistedProperty;
|
|
|
179
179
|
PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
|
|
180
180
|
PostHogPersistedProperty["PersonProperties"] = "person_properties";
|
|
181
181
|
PostHogPersistedProperty["GroupProperties"] = "group_properties";
|
|
182
|
+
PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
|
|
183
|
+
PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
|
|
182
184
|
})(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
|
|
183
185
|
|
|
184
186
|
function assert(truthyValue, message) {
|
|
@@ -737,7 +739,10 @@ var PostHogFetchHttpError = /** @class */ (function (_super) {
|
|
|
737
739
|
var PostHogFetchNetworkError = /** @class */ (function (_super) {
|
|
738
740
|
__extends(PostHogFetchNetworkError, _super);
|
|
739
741
|
function PostHogFetchNetworkError(error) {
|
|
740
|
-
var _this =
|
|
742
|
+
var _this =
|
|
743
|
+
// TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
|
|
744
|
+
// @ts-ignore
|
|
745
|
+
_super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
|
|
741
746
|
_this.error = error;
|
|
742
747
|
_this.name = 'PostHogFetchNetworkError';
|
|
743
748
|
return _this;
|
|
@@ -1187,6 +1192,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1187
1192
|
var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
|
|
1188
1193
|
_this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
|
|
1189
1194
|
_this.flagCallReported = {};
|
|
1195
|
+
_this.sessionProps = {};
|
|
1190
1196
|
_this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
|
|
1191
1197
|
_this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
|
|
1192
1198
|
return _this;
|
|
@@ -1228,6 +1234,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1228
1234
|
});
|
|
1229
1235
|
PostHogCore.prototype.clearProps = function () {
|
|
1230
1236
|
this.props = undefined;
|
|
1237
|
+
this.sessionProps = {};
|
|
1231
1238
|
};
|
|
1232
1239
|
PostHogCore.prototype.on = function (event, cb) {
|
|
1233
1240
|
return this._events.on(event, cb);
|
|
@@ -1255,7 +1262,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1255
1262
|
return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
|
|
1256
1263
|
};
|
|
1257
1264
|
PostHogCore.prototype.enrichProperties = function (properties) {
|
|
1258
|
-
return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
|
|
1265
|
+
return __assign(__assign(__assign(__assign(__assign({}, this.props), this.sessionProps), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
|
|
1259
1266
|
};
|
|
1260
1267
|
PostHogCore.prototype.getSessionId = function () {
|
|
1261
1268
|
var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
|
|
@@ -1281,13 +1288,19 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1281
1288
|
PostHogCore.prototype.getDistinctId = function () {
|
|
1282
1289
|
return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
|
|
1283
1290
|
};
|
|
1291
|
+
PostHogCore.prototype.unregister = function (property) {
|
|
1292
|
+
delete this.props[property];
|
|
1293
|
+
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1294
|
+
};
|
|
1284
1295
|
PostHogCore.prototype.register = function (properties) {
|
|
1285
1296
|
this.props = __assign(__assign({}, this.props), properties);
|
|
1286
1297
|
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1287
1298
|
};
|
|
1288
|
-
PostHogCore.prototype.
|
|
1289
|
-
|
|
1290
|
-
|
|
1299
|
+
PostHogCore.prototype.registerForSession = function (properties) {
|
|
1300
|
+
this.sessionProps = __assign(__assign({}, this.sessionProps), properties);
|
|
1301
|
+
};
|
|
1302
|
+
PostHogCore.prototype.unregisterForSession = function (property) {
|
|
1303
|
+
delete this.sessionProps[property];
|
|
1291
1304
|
};
|
|
1292
1305
|
/***
|
|
1293
1306
|
*** TRACKING
|
|
@@ -2214,7 +2227,7 @@ function () {
|
|
|
2214
2227
|
|
|
2215
2228
|
FeatureFlagsPoller.prototype._requestFeatureFlagDefinitions = function () {
|
|
2216
2229
|
return __awaiter(this, void 0, void 0, function () {
|
|
2217
|
-
var url, options, abortTimeout, controller_1
|
|
2230
|
+
var url, options, abortTimeout, controller_1;
|
|
2218
2231
|
return __generator(this, function (_a) {
|
|
2219
2232
|
switch (_a.label) {
|
|
2220
2233
|
case 0:
|
|
@@ -2240,7 +2253,7 @@ function () {
|
|
|
2240
2253
|
_a.label = 1;
|
|
2241
2254
|
|
|
2242
2255
|
case 1:
|
|
2243
|
-
_a.trys.push([1
|
|
2256
|
+
_a.trys.push([1,, 3, 4]);
|
|
2244
2257
|
|
|
2245
2258
|
return [4
|
|
2246
2259
|
/*yield*/
|
|
@@ -2252,16 +2265,12 @@ function () {
|
|
|
2252
2265
|
, _a.sent()];
|
|
2253
2266
|
|
|
2254
2267
|
case 3:
|
|
2255
|
-
err_2 = _a.sent();
|
|
2256
|
-
throw err_2;
|
|
2257
|
-
|
|
2258
|
-
case 4:
|
|
2259
2268
|
clearTimeout(abortTimeout);
|
|
2260
2269
|
return [7
|
|
2261
2270
|
/*endfinally*/
|
|
2262
2271
|
];
|
|
2263
2272
|
|
|
2264
|
-
case
|
|
2273
|
+
case 4:
|
|
2265
2274
|
return [2
|
|
2266
2275
|
/*return*/
|
|
2267
2276
|
];
|
|
@@ -2341,14 +2350,16 @@ function matchProperty(property, propertyValues) {
|
|
|
2341
2350
|
|
|
2342
2351
|
case 'is_date_after':
|
|
2343
2352
|
case 'is_date_before':
|
|
2344
|
-
|
|
2345
|
-
|
|
2353
|
+
{
|
|
2354
|
+
var parsedDate = convertToDateTime(value);
|
|
2355
|
+
var overrideDate = convertToDateTime(overrideValue);
|
|
2346
2356
|
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2357
|
+
if (operator === 'is_date_before') {
|
|
2358
|
+
return overrideDate < parsedDate;
|
|
2359
|
+
}
|
|
2350
2360
|
|
|
2351
|
-
|
|
2361
|
+
return overrideDate > parsedDate;
|
|
2362
|
+
}
|
|
2352
2363
|
|
|
2353
2364
|
default:
|
|
2354
2365
|
console.error("Unknown operator: ".concat(operator));
|
|
@@ -2655,8 +2666,10 @@ function (_super) {
|
|
|
2655
2666
|
return __awaiter(this, void 0, void 0, function () {
|
|
2656
2667
|
var _b, groups, personProperties, groupProperties, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, response, flagWasLocallyEvaluated, featureFlagReportedKey;
|
|
2657
2668
|
|
|
2658
|
-
|
|
2659
|
-
|
|
2669
|
+
var _d;
|
|
2670
|
+
|
|
2671
|
+
return __generator(this, function (_e) {
|
|
2672
|
+
switch (_e.label) {
|
|
2660
2673
|
case 0:
|
|
2661
2674
|
_b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
|
|
2662
2675
|
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents; // set defaults
|
|
@@ -2674,7 +2687,7 @@ function (_super) {
|
|
|
2674
2687
|
, (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getFeatureFlag(key, distinctId, groups, personProperties, groupProperties)];
|
|
2675
2688
|
|
|
2676
2689
|
case 1:
|
|
2677
|
-
response =
|
|
2690
|
+
response = _e.sent();
|
|
2678
2691
|
flagWasLocallyEvaluated = response !== undefined;
|
|
2679
2692
|
if (!(!flagWasLocallyEvaluated && !onlyEvaluateLocally)) return [3
|
|
2680
2693
|
/*break*/
|
|
@@ -2684,8 +2697,8 @@ function (_super) {
|
|
|
2684
2697
|
, _super.prototype.getFeatureFlagStateless.call(this, key, distinctId, groups, personProperties, groupProperties, disableGeoip)];
|
|
2685
2698
|
|
|
2686
2699
|
case 2:
|
|
2687
|
-
response =
|
|
2688
|
-
|
|
2700
|
+
response = _e.sent();
|
|
2701
|
+
_e.label = 3;
|
|
2689
2702
|
|
|
2690
2703
|
case 3:
|
|
2691
2704
|
featureFlagReportedKey = "".concat(key, "_").concat(response);
|
|
@@ -2704,11 +2717,11 @@ function (_super) {
|
|
|
2704
2717
|
this.capture({
|
|
2705
2718
|
distinctId: distinctId,
|
|
2706
2719
|
event: '$feature_flag_called',
|
|
2707
|
-
properties: {
|
|
2720
|
+
properties: (_d = {
|
|
2708
2721
|
$feature_flag: key,
|
|
2709
2722
|
$feature_flag_response: response,
|
|
2710
2723
|
locally_evaluated: flagWasLocallyEvaluated
|
|
2711
|
-
},
|
|
2724
|
+
}, _d["$feature/".concat(key)] = response, _d),
|
|
2712
2725
|
groups: groups,
|
|
2713
2726
|
disableGeoip: disableGeoip
|
|
2714
2727
|
});
|