posthog-node 5.5.0 → 5.6.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 +8 -0
- package/lib/edge/index.cjs +23 -15
- package/lib/edge/index.cjs.map +1 -1
- package/lib/edge/index.mjs +23 -15
- package/lib/edge/index.mjs.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/node/index.cjs +23 -15
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.mjs +23 -15
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/edge/index.mjs
CHANGED
|
@@ -915,7 +915,7 @@ function setupExpressErrorHandler(_posthog, app) {
|
|
|
915
915
|
});
|
|
916
916
|
}
|
|
917
917
|
|
|
918
|
-
var version = "5.
|
|
918
|
+
var version = "5.6.0";
|
|
919
919
|
|
|
920
920
|
var PostHogPersistedProperty;
|
|
921
921
|
(function (PostHogPersistedProperty) {
|
|
@@ -2154,12 +2154,7 @@ class FeatureFlagsPoller {
|
|
|
2154
2154
|
if (!this.loadedSuccessfullyOnce) {
|
|
2155
2155
|
return response;
|
|
2156
2156
|
}
|
|
2157
|
-
|
|
2158
|
-
if (key === flag.key) {
|
|
2159
|
-
featureFlag = flag;
|
|
2160
|
-
break;
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2157
|
+
featureFlag = this.featureFlagsByKey[key];
|
|
2163
2158
|
if (featureFlag !== undefined) {
|
|
2164
2159
|
try {
|
|
2165
2160
|
response = await this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties);
|
|
@@ -2195,12 +2190,13 @@ class FeatureFlagsPoller {
|
|
|
2195
2190
|
return response;
|
|
2196
2191
|
}
|
|
2197
2192
|
}
|
|
2198
|
-
async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}) {
|
|
2193
|
+
async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}, flagKeysToExplicitlyEvaluate) {
|
|
2199
2194
|
await this.loadFeatureFlags();
|
|
2200
2195
|
const response = {};
|
|
2201
2196
|
const payloads = {};
|
|
2202
2197
|
let fallbackToFlags = this.featureFlags.length == 0;
|
|
2203
|
-
|
|
2198
|
+
const flagsToEvaluate = flagKeysToExplicitlyEvaluate ? flagKeysToExplicitlyEvaluate.map(key => this.featureFlagsByKey[key]).filter(Boolean) : this.featureFlags;
|
|
2199
|
+
await Promise.all(flagsToEvaluate.map(async flag => {
|
|
2204
2200
|
try {
|
|
2205
2201
|
const matchValue = await this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
|
|
2206
2202
|
response[flag.key] = matchValue;
|
|
@@ -2210,7 +2206,7 @@ class FeatureFlagsPoller {
|
|
|
2210
2206
|
}
|
|
2211
2207
|
} catch (e) {
|
|
2212
2208
|
if (e instanceof InconclusiveMatchError) {
|
|
2213
|
-
this.
|
|
2209
|
+
this.logMsgIfDebug(() => console.debug(`InconclusiveMatchError when computing flag locally: ${flag.key}: ${e}`));
|
|
2214
2210
|
} else if (e instanceof Error) {
|
|
2215
2211
|
this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`));
|
|
2216
2212
|
}
|
|
@@ -2307,6 +2303,9 @@ class FeatureFlagsPoller {
|
|
|
2307
2303
|
let matches = false;
|
|
2308
2304
|
if (propertyType === 'cohort') {
|
|
2309
2305
|
matches = matchCohort(prop, properties, this.cohorts, this.debugMode);
|
|
2306
|
+
} else if (propertyType === 'flag') {
|
|
2307
|
+
this.logMsgIfDebug(() => console.warn(`[FEATURE FLAGS] Flag dependency filters are not supported in local evaluation. ` + `Skipping condition for flag '${flag.key}' with dependency on flag '${prop.key || 'unknown'}'`));
|
|
2308
|
+
continue;
|
|
2310
2309
|
} else {
|
|
2311
2310
|
matches = matchProperty(prop, properties, warnFunction);
|
|
2312
2311
|
}
|
|
@@ -2644,6 +2643,11 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
2644
2643
|
let matches;
|
|
2645
2644
|
if (prop.type === 'cohort') {
|
|
2646
2645
|
matches = matchCohort(prop, propertyValues, cohortProperties, debugMode);
|
|
2646
|
+
} else if (prop.type === 'flag') {
|
|
2647
|
+
if (debugMode) {
|
|
2648
|
+
console.warn(`[FEATURE FLAGS] Flag dependency filters are not supported in local evaluation. ` + `Skipping condition with dependency on flag '${prop.key || 'unknown'}'`);
|
|
2649
|
+
}
|
|
2650
|
+
continue;
|
|
2647
2651
|
} else {
|
|
2648
2652
|
matches = matchProperty(prop, propertyValues);
|
|
2649
2653
|
}
|
|
@@ -3145,7 +3149,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3145
3149
|
async getAllFlagsAndPayloads(distinctId, options) {
|
|
3146
3150
|
const {
|
|
3147
3151
|
groups,
|
|
3148
|
-
disableGeoip
|
|
3152
|
+
disableGeoip,
|
|
3153
|
+
flagKeys
|
|
3149
3154
|
} = options || {};
|
|
3150
3155
|
let {
|
|
3151
3156
|
onlyEvaluateLocally,
|
|
@@ -3159,7 +3164,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3159
3164
|
if (onlyEvaluateLocally == undefined) {
|
|
3160
3165
|
onlyEvaluateLocally = false;
|
|
3161
3166
|
}
|
|
3162
|
-
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties);
|
|
3167
|
+
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties, flagKeys);
|
|
3163
3168
|
let featureFlags = {};
|
|
3164
3169
|
let featureFlagPayloads = {};
|
|
3165
3170
|
let fallbackToFlags = true;
|
|
@@ -3169,7 +3174,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3169
3174
|
fallbackToFlags = localEvaluationResult.fallbackToFlags;
|
|
3170
3175
|
}
|
|
3171
3176
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
3172
|
-
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip);
|
|
3177
|
+
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
3173
3178
|
featureFlags = {
|
|
3174
3179
|
...featureFlags,
|
|
3175
3180
|
...(remoteEvaluationResult.flags || {})
|
|
@@ -3269,6 +3274,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3269
3274
|
// Use properties directly from options if they exist
|
|
3270
3275
|
const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
|
|
3271
3276
|
const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
|
|
3277
|
+
const flagKeys = sendFeatureFlagsOptions?.flagKeys;
|
|
3272
3278
|
// Check if we should only evaluate locally
|
|
3273
3279
|
const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
|
|
3274
3280
|
// If onlyEvaluateLocally is true, only use local evaluation
|
|
@@ -3283,7 +3289,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3283
3289
|
personProperties: finalPersonProperties,
|
|
3284
3290
|
groupProperties: finalGroupProperties,
|
|
3285
3291
|
disableGeoip,
|
|
3286
|
-
onlyEvaluateLocally: true
|
|
3292
|
+
onlyEvaluateLocally: true,
|
|
3293
|
+
flagKeys
|
|
3287
3294
|
});
|
|
3288
3295
|
} else {
|
|
3289
3296
|
// If onlyEvaluateLocally is true but we don't have local flags, return empty
|
|
@@ -3301,7 +3308,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3301
3308
|
personProperties: finalPersonProperties,
|
|
3302
3309
|
groupProperties: finalGroupProperties,
|
|
3303
3310
|
disableGeoip,
|
|
3304
|
-
onlyEvaluateLocally: true
|
|
3311
|
+
onlyEvaluateLocally: true,
|
|
3312
|
+
flagKeys
|
|
3305
3313
|
});
|
|
3306
3314
|
}
|
|
3307
3315
|
// Fall back to remote evaluation if local evaluation is not available
|