posthog-node 4.0.0-beta.2 → 4.0.0-beta.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 +11 -7
- package/lib/index.cjs.js +23 -14
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +23 -14
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +3 -0
- package/lib/posthog-node/src/feature-flags.d.ts +7 -1
- package/package.json +1 -1
- package/src/feature-flags.ts +5 -2
- package/src/posthog-node.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
# 4.0.0-beta.3 - 2024-03-13
|
|
2
|
+
|
|
3
|
+
1. Sets `User-Agent` headers with SDK name and version for RN
|
|
4
|
+
|
|
1
5
|
# 4.0.0-beta.2 - 2024-03-12
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
1. `flushAsync` and `shutdownAsync` are removed with `flush` and `shutdown` now being the async methods.
|
|
8
|
+
2. Fixed an issue where `shutdown` would potentially exit early if a flush was already in progress
|
|
9
|
+
3. Flushes will now try to flush up to `maxBatchSize` (default 100) in one go
|
|
6
10
|
|
|
7
11
|
# 4.0.0-beta.1 - 2024-03-04
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
1. Adds a `disabled` option and the ability to change it later via `posthog.disabled = true`. Useful for disabling PostHog tracking for example in a testing environment without having complex conditional checking
|
|
14
|
+
2. Fixes some typos in types
|
|
15
|
+
3. `shutdown` and `shutdownAsync` takes a `shutdownTimeoutMs` param with a default of 30000 (30s). This is the time to wait for flushing events before shutting down the client. If the timeout is reached, the client will be shut down regardless of pending events.
|
|
16
|
+
4. Adds a new `featureFlagsRequestTimeoutMs` timeout parameter for feature flags which defaults to 3 seconds, updated from the default 10s for all other API calls.
|
|
13
17
|
|
|
14
18
|
# 3.6.3 - 2024-02-15
|
|
15
19
|
|
package/lib/index.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var rusha = require('rusha');
|
|
6
6
|
|
|
7
|
-
var version = "4.0.0-beta.
|
|
7
|
+
var version = "4.0.0-beta.3";
|
|
8
8
|
|
|
9
9
|
var PostHogPersistedProperty;
|
|
10
10
|
(function (PostHogPersistedProperty) {
|
|
@@ -1111,7 +1111,7 @@ class PostHogCoreStateless {
|
|
|
1111
1111
|
const url = `${this.host}/decide/?v=3`;
|
|
1112
1112
|
const fetchOptions = {
|
|
1113
1113
|
method: 'POST',
|
|
1114
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1114
|
+
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
1115
1115
|
body: JSON.stringify({
|
|
1116
1116
|
token: this.apiKey,
|
|
1117
1117
|
distinct_id: distinctId,
|
|
@@ -1255,6 +1255,18 @@ class PostHogCoreStateless {
|
|
|
1255
1255
|
}
|
|
1256
1256
|
return this.flushPromise;
|
|
1257
1257
|
}
|
|
1258
|
+
getCustomHeaders() {
|
|
1259
|
+
// Don't set the user agent if we're not on a browser. The latest spec allows
|
|
1260
|
+
// the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
|
|
1261
|
+
// and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
|
|
1262
|
+
// but browsers such as Chrome and Safari have not caught up.
|
|
1263
|
+
const customUserAgent = this.getCustomUserAgent();
|
|
1264
|
+
const headers = {};
|
|
1265
|
+
if (customUserAgent && customUserAgent !== '') {
|
|
1266
|
+
headers['User-Agent'] = customUserAgent;
|
|
1267
|
+
}
|
|
1268
|
+
return headers;
|
|
1269
|
+
}
|
|
1258
1270
|
async _flush() {
|
|
1259
1271
|
this.clearFlushTimer();
|
|
1260
1272
|
await this._initPromise;
|
|
@@ -1273,11 +1285,6 @@ class PostHogCoreStateless {
|
|
|
1273
1285
|
batch: messages,
|
|
1274
1286
|
sent_at: currentISOTime(),
|
|
1275
1287
|
};
|
|
1276
|
-
// Don't set the user agent if we're not on a browser. The latest spec allows
|
|
1277
|
-
// the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
|
|
1278
|
-
// and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
|
|
1279
|
-
// but browsers such as Chrome and Safari have not caught up.
|
|
1280
|
-
this.getCustomUserAgent();
|
|
1281
1288
|
const payload = JSON.stringify(data);
|
|
1282
1289
|
const url = this.captureMode === 'form'
|
|
1283
1290
|
? `${this.host}/e/?ip=1&_=${currentTimestamp()}&v=${this.getLibraryVersion()}`
|
|
@@ -1287,12 +1294,12 @@ class PostHogCoreStateless {
|
|
|
1287
1294
|
method: 'POST',
|
|
1288
1295
|
mode: 'no-cors',
|
|
1289
1296
|
credentials: 'omit',
|
|
1290
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1297
|
+
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1291
1298
|
body: `data=${encodeURIComponent(LZString.compressToBase64(payload))}&compression=lz64`,
|
|
1292
1299
|
}
|
|
1293
1300
|
: {
|
|
1294
1301
|
method: 'POST',
|
|
1295
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1302
|
+
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
1296
1303
|
body: payload,
|
|
1297
1304
|
};
|
|
1298
1305
|
try {
|
|
@@ -1453,6 +1460,7 @@ class FeatureFlagsPoller {
|
|
|
1453
1460
|
projectApiKey,
|
|
1454
1461
|
timeout,
|
|
1455
1462
|
host,
|
|
1463
|
+
customHeaders,
|
|
1456
1464
|
...options
|
|
1457
1465
|
}) {
|
|
1458
1466
|
this.debugMode = false;
|
|
@@ -1470,6 +1478,7 @@ class FeatureFlagsPoller {
|
|
|
1470
1478
|
|
|
1471
1479
|
this.fetch = options.fetch || fetch$1;
|
|
1472
1480
|
this.onError = options.onError;
|
|
1481
|
+
this.customHeaders = customHeaders;
|
|
1473
1482
|
void this.loadFeatureFlags();
|
|
1474
1483
|
}
|
|
1475
1484
|
|
|
@@ -1772,10 +1781,9 @@ class FeatureFlagsPoller {
|
|
|
1772
1781
|
const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`;
|
|
1773
1782
|
const options = {
|
|
1774
1783
|
method: 'GET',
|
|
1775
|
-
headers: {
|
|
1784
|
+
headers: { ...this.customHeaders,
|
|
1776
1785
|
'Content-Type': 'application/json',
|
|
1777
|
-
Authorization: `Bearer ${this.personalApiKey}
|
|
1778
|
-
'user-agent': `posthog-node/${version}`
|
|
1786
|
+
Authorization: `Bearer ${this.personalApiKey}`
|
|
1779
1787
|
}
|
|
1780
1788
|
};
|
|
1781
1789
|
let abortTimeout = null;
|
|
@@ -2117,7 +2125,8 @@ class PostHog extends PostHogCoreStateless {
|
|
|
2117
2125
|
fetch: options.fetch,
|
|
2118
2126
|
onError: err => {
|
|
2119
2127
|
this._events.emit('error', err);
|
|
2120
|
-
}
|
|
2128
|
+
},
|
|
2129
|
+
customHeaders: this.getCustomHeaders()
|
|
2121
2130
|
});
|
|
2122
2131
|
}
|
|
2123
2132
|
|
|
@@ -2146,7 +2155,7 @@ class PostHog extends PostHogCoreStateless {
|
|
|
2146
2155
|
}
|
|
2147
2156
|
|
|
2148
2157
|
getCustomUserAgent() {
|
|
2149
|
-
return
|
|
2158
|
+
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
2150
2159
|
}
|
|
2151
2160
|
|
|
2152
2161
|
enable() {
|