posthog-node 5.4.0 → 5.5.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 +49 -1
- package/lib/edge/index.cjs +35 -14
- package/lib/edge/index.cjs.map +1 -1
- package/lib/edge/index.mjs +35 -14
- package/lib/edge/index.mjs.map +1 -1
- package/lib/index.d.ts +7 -2
- package/lib/node/index.cjs +35 -14
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.mjs +35 -14
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -588,10 +588,15 @@ interface IdentifyMessage {
|
|
|
588
588
|
properties?: Record<string | number, any>;
|
|
589
589
|
disableGeoip?: boolean;
|
|
590
590
|
}
|
|
591
|
+
interface SendFeatureFlagsOptions {
|
|
592
|
+
onlyEvaluateLocally?: boolean;
|
|
593
|
+
personProperties?: Record<string, any>;
|
|
594
|
+
groupProperties?: Record<string, Record<string, any>>;
|
|
595
|
+
}
|
|
591
596
|
interface EventMessage extends IdentifyMessage {
|
|
592
597
|
event: string;
|
|
593
598
|
groups?: Record<string, string | number>;
|
|
594
|
-
sendFeatureFlags?: boolean;
|
|
599
|
+
sendFeatureFlags?: boolean | SendFeatureFlagsOptions;
|
|
595
600
|
timestamp?: Date;
|
|
596
601
|
uuid?: string;
|
|
597
602
|
}
|
|
@@ -967,4 +972,4 @@ declare class PostHog extends PostHogBackendClient {
|
|
|
967
972
|
getLibraryId(): string;
|
|
968
973
|
}
|
|
969
974
|
|
|
970
|
-
export { EventMessage, FeatureFlagCondition, FlagProperty, GroupIdentifyMessage, IPostHog, IdentifyMessage, PostHog, PostHogFeatureFlag, PostHogOptions, PostHogSentryIntegration, PropertyGroup, SentryIntegrationOptions, createEventProcessor, sentryIntegration, setupExpressErrorHandler };
|
|
975
|
+
export { EventMessage, FeatureFlagCondition, FlagProperty, GroupIdentifyMessage, IPostHog, IdentifyMessage, PostHog, PostHogFeatureFlag, PostHogOptions, PostHogSentryIntegration, PropertyGroup, SendFeatureFlagsOptions, SentryIntegrationOptions, createEventProcessor, sentryIntegration, setupExpressErrorHandler };
|
package/lib/node/index.cjs
CHANGED
|
@@ -1342,7 +1342,7 @@ function snipLine(line, colno) {
|
|
|
1342
1342
|
return newLine;
|
|
1343
1343
|
}
|
|
1344
1344
|
|
|
1345
|
-
var version = "5.
|
|
1345
|
+
var version = "5.5.0";
|
|
1346
1346
|
|
|
1347
1347
|
var PostHogPersistedProperty;
|
|
1348
1348
|
(function (PostHogPersistedProperty) {
|
|
@@ -3266,7 +3266,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3266
3266
|
const capturePromise = Promise.resolve().then(async () => {
|
|
3267
3267
|
if (sendFeatureFlags) {
|
|
3268
3268
|
// If we are sending feature flags, we evaluate them locally if the user prefers it, otherwise we fall back to remote evaluation
|
|
3269
|
-
|
|
3269
|
+
const sendFeatureFlagsOptions = typeof sendFeatureFlags === 'object' ? sendFeatureFlags : undefined;
|
|
3270
|
+
return await this.getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions);
|
|
3270
3271
|
}
|
|
3271
3272
|
if (event === '$feature_flag_called') {
|
|
3272
3273
|
// If we're capturing a $feature_flag_called event, we don't want to enrich the event with cached flags that may be out of date.
|
|
@@ -3323,7 +3324,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3323
3324
|
const capturePromise = Promise.resolve().then(async () => {
|
|
3324
3325
|
if (sendFeatureFlags) {
|
|
3325
3326
|
// If we are sending feature flags, we evaluate them locally if the user prefers it, otherwise we fall back to remote evaluation
|
|
3326
|
-
|
|
3327
|
+
const sendFeatureFlagsOptions = typeof sendFeatureFlags === 'object' ? sendFeatureFlags : undefined;
|
|
3328
|
+
return await this.getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions);
|
|
3327
3329
|
}
|
|
3328
3330
|
if (event === '$feature_flag_called') {
|
|
3329
3331
|
// If we're capturing a $feature_flag_called event, we don't want to enrich the event with cached flags that may be out of date.
|
|
@@ -3690,13 +3692,32 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3690
3692
|
groupProperties
|
|
3691
3693
|
};
|
|
3692
3694
|
}
|
|
3693
|
-
async getFeatureFlagsForEvent(distinctId, groups,
|
|
3694
|
-
//
|
|
3695
|
-
const {
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
//
|
|
3695
|
+
async getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions) {
|
|
3696
|
+
// Use properties directly from options if they exist
|
|
3697
|
+
const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
|
|
3698
|
+
const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
|
|
3699
|
+
// Check if we should only evaluate locally
|
|
3700
|
+
const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
|
|
3701
|
+
// If onlyEvaluateLocally is true, only use local evaluation
|
|
3702
|
+
if (onlyEvaluateLocally) {
|
|
3703
|
+
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
3704
|
+
const groupsWithStringValues = {};
|
|
3705
|
+
for (const [key, value] of Object.entries(groups || {})) {
|
|
3706
|
+
groupsWithStringValues[key] = String(value);
|
|
3707
|
+
}
|
|
3708
|
+
return await this.getAllFlags(distinctId, {
|
|
3709
|
+
groups: groupsWithStringValues,
|
|
3710
|
+
personProperties: finalPersonProperties,
|
|
3711
|
+
groupProperties: finalGroupProperties,
|
|
3712
|
+
disableGeoip,
|
|
3713
|
+
onlyEvaluateLocally: true
|
|
3714
|
+
});
|
|
3715
|
+
} else {
|
|
3716
|
+
// If onlyEvaluateLocally is true but we don't have local flags, return empty
|
|
3717
|
+
return {};
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
// Prefer local evaluation if available (default behavior; I'd rather not penalize users who haven't updated to the new API but still want to use local evaluation)
|
|
3700
3721
|
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
3701
3722
|
const groupsWithStringValues = {};
|
|
3702
3723
|
for (const [key, value] of Object.entries(groups || {})) {
|
|
@@ -3704,14 +3725,14 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3704
3725
|
}
|
|
3705
3726
|
return await this.getAllFlags(distinctId, {
|
|
3706
3727
|
groups: groupsWithStringValues,
|
|
3707
|
-
personProperties:
|
|
3708
|
-
groupProperties:
|
|
3728
|
+
personProperties: finalPersonProperties,
|
|
3729
|
+
groupProperties: finalGroupProperties,
|
|
3709
3730
|
disableGeoip,
|
|
3710
3731
|
onlyEvaluateLocally: true
|
|
3711
3732
|
});
|
|
3712
3733
|
}
|
|
3713
|
-
// Fall back to remote evaluation if local evaluation is not available
|
|
3714
|
-
return (await super.getFeatureFlagsStateless(distinctId, groups,
|
|
3734
|
+
// Fall back to remote evaluation if local evaluation is not available
|
|
3735
|
+
return (await super.getFeatureFlagsStateless(distinctId, groups, finalPersonProperties, finalGroupProperties, disableGeoip)).flags;
|
|
3715
3736
|
}
|
|
3716
3737
|
addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties) {
|
|
3717
3738
|
const allPersonProperties = {
|