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