posthog-node 4.3.0 → 4.3.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 +55 -29
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +55 -29
- package/lib/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/posthog-node.ts +51 -30
- package/test/posthog-node.spec.ts +35 -2
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'rusha';
|
|
2
2
|
|
|
3
|
-
var version = "4.3.
|
|
3
|
+
var version = "4.3.1";
|
|
4
4
|
|
|
5
5
|
var PostHogPersistedProperty;
|
|
6
6
|
(function (PostHogPersistedProperty) {
|
|
@@ -2230,44 +2230,70 @@ class PostHog extends PostHogCoreStateless {
|
|
|
2230
2230
|
async getFeatureFlagPayload(key, distinctId, matchValue, options) {
|
|
2231
2231
|
const {
|
|
2232
2232
|
groups,
|
|
2233
|
-
disableGeoip
|
|
2234
|
-
|
|
2235
|
-
let {
|
|
2236
|
-
onlyEvaluateLocally,
|
|
2237
|
-
sendFeatureFlagEvents,
|
|
2233
|
+
disableGeoip,
|
|
2234
|
+
onlyEvaluateLocally = false,
|
|
2238
2235
|
personProperties,
|
|
2239
2236
|
groupProperties
|
|
2240
2237
|
} = options || {};
|
|
2241
|
-
const
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
if (!matchValue) {
|
|
2238
|
+
const {
|
|
2239
|
+
allPersonProperties,
|
|
2240
|
+
allGroupProperties
|
|
2241
|
+
} = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
2242
|
+
if (matchValue === undefined) {
|
|
2247
2243
|
matchValue = await this.getFeatureFlag(key, distinctId, {
|
|
2248
2244
|
...options,
|
|
2249
|
-
onlyEvaluateLocally: true
|
|
2245
|
+
onlyEvaluateLocally: true,
|
|
2246
|
+
sendFeatureFlagEvents: false
|
|
2250
2247
|
});
|
|
2251
2248
|
}
|
|
2249
|
+
let response;
|
|
2250
|
+
let payload;
|
|
2252
2251
|
if (matchValue) {
|
|
2253
|
-
response =
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
}
|
|
2259
|
-
if (sendFeatureFlagEvents == undefined) {
|
|
2260
|
-
sendFeatureFlagEvents = true;
|
|
2261
|
-
}
|
|
2262
|
-
// set defaults
|
|
2263
|
-
if (onlyEvaluateLocally == undefined) {
|
|
2264
|
-
onlyEvaluateLocally = false;
|
|
2252
|
+
response = matchValue;
|
|
2253
|
+
payload = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
|
|
2254
|
+
} else {
|
|
2255
|
+
response = undefined;
|
|
2256
|
+
payload = undefined;
|
|
2265
2257
|
}
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2258
|
+
// Determine if the payload was evaluated locally
|
|
2259
|
+
const payloadWasLocallyEvaluated = payload !== undefined;
|
|
2260
|
+
// Fetch final flags and payloads either locally or from the remote server
|
|
2261
|
+
let fetchedOrLocalFlags;
|
|
2262
|
+
let fetchedOrLocalPayloads;
|
|
2263
|
+
if (payloadWasLocallyEvaluated || onlyEvaluateLocally) {
|
|
2264
|
+
if (response !== undefined) {
|
|
2265
|
+
fetchedOrLocalFlags = {
|
|
2266
|
+
[key]: response
|
|
2267
|
+
};
|
|
2268
|
+
fetchedOrLocalPayloads = {
|
|
2269
|
+
[key]: payload
|
|
2270
|
+
};
|
|
2271
|
+
} else {
|
|
2272
|
+
fetchedOrLocalFlags = {};
|
|
2273
|
+
fetchedOrLocalPayloads = {};
|
|
2274
|
+
}
|
|
2275
|
+
} else {
|
|
2276
|
+
const fetchedData = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, allPersonProperties, allGroupProperties, disableGeoip);
|
|
2277
|
+
fetchedOrLocalFlags = fetchedData.flags || {};
|
|
2278
|
+
fetchedOrLocalPayloads = fetchedData.payloads || {};
|
|
2269
2279
|
}
|
|
2270
|
-
|
|
2280
|
+
const finalResponse = fetchedOrLocalFlags[key];
|
|
2281
|
+
const finalPayload = fetchedOrLocalPayloads[key];
|
|
2282
|
+
const finalLocallyEvaluated = payloadWasLocallyEvaluated;
|
|
2283
|
+
this.capture({
|
|
2284
|
+
distinctId,
|
|
2285
|
+
event: '$feature_flag_called',
|
|
2286
|
+
properties: {
|
|
2287
|
+
$feature_flag: key,
|
|
2288
|
+
$feature_flag_response: finalResponse,
|
|
2289
|
+
$feature_flag_payload: finalPayload,
|
|
2290
|
+
locally_evaluated: finalLocallyEvaluated,
|
|
2291
|
+
[`$feature/${key}`]: finalResponse
|
|
2292
|
+
},
|
|
2293
|
+
groups,
|
|
2294
|
+
disableGeoip
|
|
2295
|
+
});
|
|
2296
|
+
return finalPayload;
|
|
2271
2297
|
}
|
|
2272
2298
|
async isFeatureEnabled(key, distinctId, options) {
|
|
2273
2299
|
const feat = await this.getFeatureFlag(key, distinctId, options);
|