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/lib/index.d.ts CHANGED
@@ -31,7 +31,9 @@ declare enum PostHogPersistedProperty {
31
31
  SessionId = "session_id",
32
32
  SessionLastTimestamp = "session_timestamp",
33
33
  PersonProperties = "person_properties",
34
- GroupProperties = "group_properties"
34
+ GroupProperties = "group_properties",
35
+ InstalledAppBuild = "installed_app_build",
36
+ InstalledAppVersion = "installed_app_version"
35
37
  }
36
38
  declare type PostHogFetchOptions = {
37
39
  method: 'GET' | 'POST' | 'PUT' | 'PATCH';
package/lib/index.esm.js CHANGED
@@ -155,7 +155,7 @@ function __spreadArray(to, from, pack) {
155
155
  return to.concat(ar || Array.prototype.slice.call(from));
156
156
  }
157
157
 
158
- var version = "3.1.1";
158
+ var version = "3.1.3";
159
159
 
160
160
  var PostHogPersistedProperty;
161
161
  (function (PostHogPersistedProperty) {
@@ -171,6 +171,8 @@ var PostHogPersistedProperty;
171
171
  PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
172
172
  PostHogPersistedProperty["PersonProperties"] = "person_properties";
173
173
  PostHogPersistedProperty["GroupProperties"] = "group_properties";
174
+ PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
175
+ PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
174
176
  })(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
175
177
 
176
178
  function assert(truthyValue, message) {
@@ -729,7 +731,10 @@ var PostHogFetchHttpError = /** @class */ (function (_super) {
729
731
  var PostHogFetchNetworkError = /** @class */ (function (_super) {
730
732
  __extends(PostHogFetchNetworkError, _super);
731
733
  function PostHogFetchNetworkError(error) {
732
- var _this = _super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
734
+ var _this =
735
+ // TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
736
+ // @ts-ignore
737
+ _super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
733
738
  _this.error = error;
734
739
  _this.name = 'PostHogFetchNetworkError';
735
740
  return _this;
@@ -1179,6 +1184,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1179
1184
  var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
1180
1185
  _this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
1181
1186
  _this.flagCallReported = {};
1187
+ _this.sessionProps = {};
1182
1188
  _this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
1183
1189
  _this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
1184
1190
  return _this;
@@ -1220,6 +1226,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1220
1226
  });
1221
1227
  PostHogCore.prototype.clearProps = function () {
1222
1228
  this.props = undefined;
1229
+ this.sessionProps = {};
1223
1230
  };
1224
1231
  PostHogCore.prototype.on = function (event, cb) {
1225
1232
  return this._events.on(event, cb);
@@ -1247,7 +1254,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1247
1254
  return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
1248
1255
  };
1249
1256
  PostHogCore.prototype.enrichProperties = function (properties) {
1250
- return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1257
+ return __assign(__assign(__assign(__assign(__assign({}, this.props), this.sessionProps), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
1251
1258
  };
1252
1259
  PostHogCore.prototype.getSessionId = function () {
1253
1260
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
@@ -1273,13 +1280,19 @@ var PostHogCoreStateless = /** @class */ (function () {
1273
1280
  PostHogCore.prototype.getDistinctId = function () {
1274
1281
  return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
1275
1282
  };
1283
+ PostHogCore.prototype.unregister = function (property) {
1284
+ delete this.props[property];
1285
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1286
+ };
1276
1287
  PostHogCore.prototype.register = function (properties) {
1277
1288
  this.props = __assign(__assign({}, this.props), properties);
1278
1289
  this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1279
1290
  };
1280
- PostHogCore.prototype.unregister = function (property) {
1281
- delete this.props[property];
1282
- this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1291
+ PostHogCore.prototype.registerForSession = function (properties) {
1292
+ this.sessionProps = __assign(__assign({}, this.sessionProps), properties);
1293
+ };
1294
+ PostHogCore.prototype.unregisterForSession = function (property) {
1295
+ delete this.sessionProps[property];
1283
1296
  };
1284
1297
  /***
1285
1298
  *** TRACKING
@@ -2206,7 +2219,7 @@ function () {
2206
2219
 
2207
2220
  FeatureFlagsPoller.prototype._requestFeatureFlagDefinitions = function () {
2208
2221
  return __awaiter(this, void 0, void 0, function () {
2209
- var url, options, abortTimeout, controller_1, err_2;
2222
+ var url, options, abortTimeout, controller_1;
2210
2223
  return __generator(this, function (_a) {
2211
2224
  switch (_a.label) {
2212
2225
  case 0:
@@ -2232,7 +2245,7 @@ function () {
2232
2245
  _a.label = 1;
2233
2246
 
2234
2247
  case 1:
2235
- _a.trys.push([1, 3, 4, 5]);
2248
+ _a.trys.push([1,, 3, 4]);
2236
2249
 
2237
2250
  return [4
2238
2251
  /*yield*/
@@ -2244,16 +2257,12 @@ function () {
2244
2257
  , _a.sent()];
2245
2258
 
2246
2259
  case 3:
2247
- err_2 = _a.sent();
2248
- throw err_2;
2249
-
2250
- case 4:
2251
2260
  clearTimeout(abortTimeout);
2252
2261
  return [7
2253
2262
  /*endfinally*/
2254
2263
  ];
2255
2264
 
2256
- case 5:
2265
+ case 4:
2257
2266
  return [2
2258
2267
  /*return*/
2259
2268
  ];
@@ -2333,14 +2342,16 @@ function matchProperty(property, propertyValues) {
2333
2342
 
2334
2343
  case 'is_date_after':
2335
2344
  case 'is_date_before':
2336
- var parsedDate = convertToDateTime(value);
2337
- var overrideDate = convertToDateTime(overrideValue);
2345
+ {
2346
+ var parsedDate = convertToDateTime(value);
2347
+ var overrideDate = convertToDateTime(overrideValue);
2338
2348
 
2339
- if (operator === 'is_date_before') {
2340
- return overrideDate < parsedDate;
2341
- }
2349
+ if (operator === 'is_date_before') {
2350
+ return overrideDate < parsedDate;
2351
+ }
2342
2352
 
2343
- return overrideDate > parsedDate;
2353
+ return overrideDate > parsedDate;
2354
+ }
2344
2355
 
2345
2356
  default:
2346
2357
  console.error("Unknown operator: ".concat(operator));
@@ -2647,8 +2658,10 @@ function (_super) {
2647
2658
  return __awaiter(this, void 0, void 0, function () {
2648
2659
  var _b, groups, personProperties, groupProperties, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, response, flagWasLocallyEvaluated, featureFlagReportedKey;
2649
2660
 
2650
- return __generator(this, function (_d) {
2651
- switch (_d.label) {
2661
+ var _d;
2662
+
2663
+ return __generator(this, function (_e) {
2664
+ switch (_e.label) {
2652
2665
  case 0:
2653
2666
  _b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
2654
2667
  _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents; // set defaults
@@ -2666,7 +2679,7 @@ function (_super) {
2666
2679
  , (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getFeatureFlag(key, distinctId, groups, personProperties, groupProperties)];
2667
2680
 
2668
2681
  case 1:
2669
- response = _d.sent();
2682
+ response = _e.sent();
2670
2683
  flagWasLocallyEvaluated = response !== undefined;
2671
2684
  if (!(!flagWasLocallyEvaluated && !onlyEvaluateLocally)) return [3
2672
2685
  /*break*/
@@ -2676,8 +2689,8 @@ function (_super) {
2676
2689
  , _super.prototype.getFeatureFlagStateless.call(this, key, distinctId, groups, personProperties, groupProperties, disableGeoip)];
2677
2690
 
2678
2691
  case 2:
2679
- response = _d.sent();
2680
- _d.label = 3;
2692
+ response = _e.sent();
2693
+ _e.label = 3;
2681
2694
 
2682
2695
  case 3:
2683
2696
  featureFlagReportedKey = "".concat(key, "_").concat(response);
@@ -2696,11 +2709,11 @@ function (_super) {
2696
2709
  this.capture({
2697
2710
  distinctId: distinctId,
2698
2711
  event: '$feature_flag_called',
2699
- properties: {
2712
+ properties: (_d = {
2700
2713
  $feature_flag: key,
2701
2714
  $feature_flag_response: response,
2702
2715
  locally_evaluated: flagWasLocallyEvaluated
2703
- },
2716
+ }, _d["$feature/".concat(key)] = response, _d),
2704
2717
  groups: groups,
2705
2718
  disableGeoip: disableGeoip
2706
2719
  });