posthog-node 3.1.2 → 3.2.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/CHANGELOG.md +9 -0
- package/lib/index.cjs.js +103 -72
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +103 -68
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +10 -0
- package/lib/posthog-core/src/types.d.ts +3 -1
- package/lib/posthog-node/src/fetch.d.ts +11 -1
- package/package.json +2 -2
- package/src/feature-flags.ts +3 -4
- package/src/fetch.ts +38 -17
- package/src/posthog-node.ts +1 -1
- package/test/feature-flags.spec.ts +2 -2
- package/test/posthog-node.spec.ts +2 -2
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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createHash } from 'rusha';
|
|
2
|
-
import axios from 'axios';
|
|
3
2
|
|
|
4
3
|
/******************************************************************************
|
|
5
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -155,7 +154,7 @@ function __spreadArray(to, from, pack) {
|
|
|
155
154
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
var version = "3.
|
|
157
|
+
var version = "3.2.0";
|
|
159
158
|
|
|
160
159
|
var PostHogPersistedProperty;
|
|
161
160
|
(function (PostHogPersistedProperty) {
|
|
@@ -171,6 +170,8 @@ var PostHogPersistedProperty;
|
|
|
171
170
|
PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
|
|
172
171
|
PostHogPersistedProperty["PersonProperties"] = "person_properties";
|
|
173
172
|
PostHogPersistedProperty["GroupProperties"] = "group_properties";
|
|
173
|
+
PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
|
|
174
|
+
PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
|
|
174
175
|
})(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
|
|
175
176
|
|
|
176
177
|
function assert(truthyValue, message) {
|
|
@@ -729,7 +730,10 @@ var PostHogFetchHttpError = /** @class */ (function (_super) {
|
|
|
729
730
|
var PostHogFetchNetworkError = /** @class */ (function (_super) {
|
|
730
731
|
__extends(PostHogFetchNetworkError, _super);
|
|
731
732
|
function PostHogFetchNetworkError(error) {
|
|
732
|
-
var _this =
|
|
733
|
+
var _this =
|
|
734
|
+
// TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
|
|
735
|
+
// @ts-ignore
|
|
736
|
+
_super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
|
|
733
737
|
_this.error = error;
|
|
734
738
|
_this.name = 'PostHogFetchNetworkError';
|
|
735
739
|
return _this;
|
|
@@ -1367,13 +1371,20 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1367
1371
|
/***
|
|
1368
1372
|
* PROPERTIES
|
|
1369
1373
|
***/
|
|
1370
|
-
PostHogCore.prototype.
|
|
1374
|
+
PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
|
|
1371
1375
|
// Get persisted person properties
|
|
1372
1376
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
1373
1377
|
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
|
|
1374
1378
|
return this;
|
|
1375
1379
|
};
|
|
1376
|
-
PostHogCore.prototype.
|
|
1380
|
+
PostHogCore.prototype.resetPersonPropertiesForFlags = function () {
|
|
1381
|
+
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {});
|
|
1382
|
+
};
|
|
1383
|
+
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
1384
|
+
PostHogCore.prototype.personProperties = function (properties) {
|
|
1385
|
+
return this.setPersonPropertiesForFlags(properties);
|
|
1386
|
+
};
|
|
1387
|
+
PostHogCore.prototype.setGroupPropertiesForFlags = function (properties) {
|
|
1377
1388
|
// Get persisted group properties
|
|
1378
1389
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
|
|
1379
1390
|
if (Object.keys(existingProperties).length !== 0) {
|
|
@@ -1385,6 +1396,13 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1385
1396
|
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
|
|
1386
1397
|
return this;
|
|
1387
1398
|
};
|
|
1399
|
+
PostHogCore.prototype.resetGroupPropertiesForFlags = function () {
|
|
1400
|
+
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {});
|
|
1401
|
+
};
|
|
1402
|
+
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
1403
|
+
PostHogCore.prototype.groupProperties = function (properties) {
|
|
1404
|
+
return this.setGroupPropertiesForFlags(properties);
|
|
1405
|
+
};
|
|
1388
1406
|
/***
|
|
1389
1407
|
*** FEATURE FLAGS
|
|
1390
1408
|
***/
|
|
@@ -1589,57 +1607,76 @@ var PostHogMemoryStorage = /** @class */ (function () {
|
|
|
1589
1607
|
return PostHogMemoryStorage;
|
|
1590
1608
|
}());
|
|
1591
1609
|
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1610
|
+
/**
|
|
1611
|
+
* Fetch wrapper
|
|
1612
|
+
*
|
|
1613
|
+
* We want to polyfill fetch when not available with axios but use it when it is.
|
|
1614
|
+
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
|
|
1615
|
+
* This is currently solved by using the global fetch if available instead.
|
|
1616
|
+
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
|
|
1617
|
+
*/
|
|
1618
|
+
|
|
1619
|
+
var _fetch = // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
1620
|
+
// @ts-ignore
|
|
1621
|
+
typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
|
|
1622
|
+
|
|
1623
|
+
if (!_fetch) {
|
|
1624
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1625
|
+
var axios_1 = require('axios');
|
|
1626
|
+
|
|
1627
|
+
_fetch = function (url, options) {
|
|
1628
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1629
|
+
var res;
|
|
1630
|
+
return __generator(this, function (_a) {
|
|
1631
|
+
switch (_a.label) {
|
|
1632
|
+
case 0:
|
|
1633
|
+
return [4
|
|
1634
|
+
/*yield*/
|
|
1635
|
+
, axios_1.request({
|
|
1636
|
+
url: url,
|
|
1637
|
+
headers: options.headers,
|
|
1638
|
+
method: options.method.toLowerCase(),
|
|
1639
|
+
data: options.body,
|
|
1640
|
+
signal: options.signal,
|
|
1641
|
+
// fetch only throws on network errors, not on HTTP errors
|
|
1642
|
+
validateStatus: function () {
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
})];
|
|
1646
|
+
|
|
1647
|
+
case 1:
|
|
1648
|
+
res = _a.sent();
|
|
1649
|
+
return [2
|
|
1650
|
+
/*return*/
|
|
1651
|
+
, {
|
|
1652
|
+
status: res.status,
|
|
1653
|
+
text: function () {
|
|
1654
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1655
|
+
return __generator(this, function (_a) {
|
|
1656
|
+
return [2
|
|
1657
|
+
/*return*/
|
|
1658
|
+
, res.data];
|
|
1659
|
+
});
|
|
1626
1660
|
});
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1661
|
+
},
|
|
1662
|
+
json: function () {
|
|
1663
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1664
|
+
return __generator(this, function (_a) {
|
|
1665
|
+
return [2
|
|
1666
|
+
/*return*/
|
|
1667
|
+
, res.data];
|
|
1668
|
+
});
|
|
1635
1669
|
});
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
}
|
|
1670
|
+
}
|
|
1671
|
+
}];
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1640
1674
|
});
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1675
|
+
};
|
|
1676
|
+
} // NOTE: We have to export this as default, even though we prefer named exports as we are relying on detecting "fetch" in the global scope
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
var fetch$1 = _fetch;
|
|
1643
1680
|
|
|
1644
1681
|
var LONG_SCALE = 0xfffffffffffffff;
|
|
1645
1682
|
|
|
@@ -1705,7 +1742,7 @@ function () {
|
|
|
1705
1742
|
this.host = host;
|
|
1706
1743
|
this.poller = undefined; // NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
1707
1744
|
|
|
1708
|
-
this.fetch = options.fetch || fetch;
|
|
1745
|
+
this.fetch = options.fetch || fetch$1;
|
|
1709
1746
|
void this.loadFeatureFlags();
|
|
1710
1747
|
}
|
|
1711
1748
|
|
|
@@ -2214,7 +2251,7 @@ function () {
|
|
|
2214
2251
|
|
|
2215
2252
|
FeatureFlagsPoller.prototype._requestFeatureFlagDefinitions = function () {
|
|
2216
2253
|
return __awaiter(this, void 0, void 0, function () {
|
|
2217
|
-
var url, options, abortTimeout, controller_1
|
|
2254
|
+
var url, options, abortTimeout, controller_1;
|
|
2218
2255
|
return __generator(this, function (_a) {
|
|
2219
2256
|
switch (_a.label) {
|
|
2220
2257
|
case 0:
|
|
@@ -2240,7 +2277,7 @@ function () {
|
|
|
2240
2277
|
_a.label = 1;
|
|
2241
2278
|
|
|
2242
2279
|
case 1:
|
|
2243
|
-
_a.trys.push([1
|
|
2280
|
+
_a.trys.push([1,, 3, 4]);
|
|
2244
2281
|
|
|
2245
2282
|
return [4
|
|
2246
2283
|
/*yield*/
|
|
@@ -2252,16 +2289,12 @@ function () {
|
|
|
2252
2289
|
, _a.sent()];
|
|
2253
2290
|
|
|
2254
2291
|
case 3:
|
|
2255
|
-
err_2 = _a.sent();
|
|
2256
|
-
throw err_2;
|
|
2257
|
-
|
|
2258
|
-
case 4:
|
|
2259
2292
|
clearTimeout(abortTimeout);
|
|
2260
2293
|
return [7
|
|
2261
2294
|
/*endfinally*/
|
|
2262
2295
|
];
|
|
2263
2296
|
|
|
2264
|
-
case
|
|
2297
|
+
case 4:
|
|
2265
2298
|
return [2
|
|
2266
2299
|
/*return*/
|
|
2267
2300
|
];
|
|
@@ -2341,14 +2374,16 @@ function matchProperty(property, propertyValues) {
|
|
|
2341
2374
|
|
|
2342
2375
|
case 'is_date_after':
|
|
2343
2376
|
case 'is_date_before':
|
|
2344
|
-
|
|
2345
|
-
|
|
2377
|
+
{
|
|
2378
|
+
var parsedDate = convertToDateTime(value);
|
|
2379
|
+
var overrideDate = convertToDateTime(overrideValue);
|
|
2346
2380
|
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2381
|
+
if (operator === 'is_date_before') {
|
|
2382
|
+
return overrideDate < parsedDate;
|
|
2383
|
+
}
|
|
2350
2384
|
|
|
2351
|
-
|
|
2385
|
+
return overrideDate > parsedDate;
|
|
2386
|
+
}
|
|
2352
2387
|
|
|
2353
2388
|
default:
|
|
2354
2389
|
console.error("Unknown operator: ".concat(operator));
|
|
@@ -2541,7 +2576,7 @@ function (_super) {
|
|
|
2541
2576
|
};
|
|
2542
2577
|
|
|
2543
2578
|
PostHog.prototype.fetch = function (url, options) {
|
|
2544
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
2579
|
+
return this.options.fetch ? this.options.fetch(url, options) : fetch$1(url, options);
|
|
2545
2580
|
};
|
|
2546
2581
|
|
|
2547
2582
|
PostHog.prototype.getLibraryId = function () {
|