posthog-node 2.5.2 → 2.5.4
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 +7 -0
- package/lib/index.cjs.js +43 -6
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.esm.js +43 -6
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +1 -0
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/lib/posthog-node/src/posthog-node.d.ts +2 -1
- package/lib/posthog-node/src/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +11 -1
- package/src/posthog-node.ts +12 -4
- package/src/types.ts +1 -0
- package/test/posthog-node.spec.ts +24 -1
package/lib/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ declare abstract class PostHogCoreStateless {
|
|
|
103
103
|
private requestTimeout;
|
|
104
104
|
private captureMode;
|
|
105
105
|
private removeDebugCallback?;
|
|
106
|
+
private debugMode;
|
|
106
107
|
private pendingPromises;
|
|
107
108
|
private _optoutOverride;
|
|
108
109
|
protected _events: SimpleEventEmitter;
|
|
@@ -174,6 +175,7 @@ interface GroupIdentifyMessage {
|
|
|
174
175
|
groupType: string;
|
|
175
176
|
groupKey: string;
|
|
176
177
|
properties?: Record<string | number, any>;
|
|
178
|
+
distinctId?: string;
|
|
177
179
|
}
|
|
178
180
|
declare type PostHogNodeV1 = {
|
|
179
181
|
/**
|
|
@@ -318,6 +320,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
318
320
|
getCustomUserAgent(): string;
|
|
319
321
|
enable(): void;
|
|
320
322
|
disable(): void;
|
|
323
|
+
debug(enabled?: boolean): void;
|
|
321
324
|
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
|
|
322
325
|
identify({ distinctId, properties }: IdentifyMessageV1): void;
|
|
323
326
|
alias(data: {
|
|
@@ -357,7 +360,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
357
360
|
groupProperties?: Record<string, Record<string, string>>;
|
|
358
361
|
onlyEvaluateLocally?: boolean;
|
|
359
362
|
}): Promise<PosthogFlagsAndPayloadsResponse>;
|
|
360
|
-
groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
|
|
363
|
+
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void;
|
|
361
364
|
reloadFeatureFlags(): Promise<void>;
|
|
362
365
|
shutdown(): void;
|
|
363
366
|
shutdownAsync(): Promise<void>;
|
package/lib/index.esm.js
CHANGED
|
@@ -155,7 +155,7 @@ function __spreadArray(to, from, pack) {
|
|
|
155
155
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
var version = "2.5.
|
|
158
|
+
var version = "2.5.4";
|
|
159
159
|
|
|
160
160
|
var PostHogPersistedProperty;
|
|
161
161
|
(function (PostHogPersistedProperty) {
|
|
@@ -717,6 +717,7 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
717
717
|
var PostHogCoreStateless = /** @class */ (function () {
|
|
718
718
|
function PostHogCoreStateless(apiKey, options) {
|
|
719
719
|
var _a, _b, _c, _d;
|
|
720
|
+
this.debugMode = false;
|
|
720
721
|
this.pendingPromises = {};
|
|
721
722
|
// internal
|
|
722
723
|
this._events = new SimpleEventEmitter();
|
|
@@ -761,6 +762,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
761
762
|
var _a;
|
|
762
763
|
if (enabled === void 0) { enabled = true; }
|
|
763
764
|
(_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
765
|
+
this.debugMode = enabled;
|
|
764
766
|
if (enabled) {
|
|
765
767
|
this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
|
|
766
768
|
}
|
|
@@ -1590,6 +1592,7 @@ function () {
|
|
|
1590
1592
|
host = _a.host,
|
|
1591
1593
|
options = __rest(_a, ["pollingInterval", "personalApiKey", "projectApiKey", "timeout", "host"]);
|
|
1592
1594
|
|
|
1595
|
+
this.debugMode = false;
|
|
1593
1596
|
this.pollingInterval = pollingInterval;
|
|
1594
1597
|
this.personalApiKey = personalApiKey;
|
|
1595
1598
|
this.featureFlags = [];
|
|
@@ -1605,6 +1608,14 @@ function () {
|
|
|
1605
1608
|
void this.loadFeatureFlags();
|
|
1606
1609
|
}
|
|
1607
1610
|
|
|
1611
|
+
FeatureFlagsPoller.prototype.debug = function (enabled) {
|
|
1612
|
+
if (enabled === void 0) {
|
|
1613
|
+
enabled = true;
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
this.debugMode = enabled;
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1608
1619
|
FeatureFlagsPoller.prototype.getFeatureFlag = function (key, distinctId, groups, personProperties, groupProperties) {
|
|
1609
1620
|
if (groups === void 0) {
|
|
1610
1621
|
groups = {};
|
|
@@ -1652,9 +1663,15 @@ function () {
|
|
|
1652
1663
|
if (featureFlag !== undefined) {
|
|
1653
1664
|
try {
|
|
1654
1665
|
response = this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties);
|
|
1666
|
+
|
|
1667
|
+
if (this.debugMode) {
|
|
1668
|
+
console.debug("Successfully computed flag locally: ".concat(key, " -> ").concat(response));
|
|
1669
|
+
}
|
|
1655
1670
|
} catch (e) {
|
|
1656
1671
|
if (e instanceof InconclusiveMatchError) {
|
|
1657
|
-
|
|
1672
|
+
if (this.debugMode) {
|
|
1673
|
+
console.debug("InconclusiveMatchError when computing flag locally: ".concat(key, ": ").concat(e));
|
|
1674
|
+
}
|
|
1658
1675
|
} else if (e instanceof Error) {
|
|
1659
1676
|
console.error("Error computing flag locally: ".concat(key, ": ").concat(e));
|
|
1660
1677
|
}
|
|
@@ -2322,6 +2339,18 @@ function (_super) {
|
|
|
2322
2339
|
return _super.prototype.optOut.call(this);
|
|
2323
2340
|
};
|
|
2324
2341
|
|
|
2342
|
+
PostHog.prototype.debug = function (enabled) {
|
|
2343
|
+
var _a;
|
|
2344
|
+
|
|
2345
|
+
if (enabled === void 0) {
|
|
2346
|
+
enabled = true;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
_super.prototype.debug.call(this, enabled);
|
|
2350
|
+
|
|
2351
|
+
(_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.debug(enabled);
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2325
2354
|
PostHog.prototype.capture = function (_a) {
|
|
2326
2355
|
var _this = this;
|
|
2327
2356
|
|
|
@@ -2347,12 +2376,19 @@ function (_super) {
|
|
|
2347
2376
|
var _b = _a[_i],
|
|
2348
2377
|
feature = _b[0],
|
|
2349
2378
|
variant = _b[1];
|
|
2350
|
-
|
|
2379
|
+
|
|
2380
|
+
if (variant !== false) {
|
|
2381
|
+
featureVariantProperties["$feature/".concat(feature)] = variant;
|
|
2382
|
+
}
|
|
2351
2383
|
}
|
|
2352
2384
|
}
|
|
2353
2385
|
|
|
2386
|
+
var activeFlags = Object.keys(flags || {}).filter(function (flag) {
|
|
2387
|
+
return (flags === null || flags === void 0 ? void 0 : flags[flag]) !== false;
|
|
2388
|
+
});
|
|
2389
|
+
|
|
2354
2390
|
var flagProperties = __assign({
|
|
2355
|
-
$active_feature_flags:
|
|
2391
|
+
$active_feature_flags: activeFlags || undefined
|
|
2356
2392
|
}, featureVariantProperties);
|
|
2357
2393
|
|
|
2358
2394
|
_capture(__assign(__assign(__assign({}, properties), {
|
|
@@ -2639,9 +2675,10 @@ function (_super) {
|
|
|
2639
2675
|
PostHog.prototype.groupIdentify = function (_a) {
|
|
2640
2676
|
var groupType = _a.groupType,
|
|
2641
2677
|
groupKey = _a.groupKey,
|
|
2642
|
-
properties = _a.properties
|
|
2678
|
+
properties = _a.properties,
|
|
2679
|
+
distinctId = _a.distinctId;
|
|
2643
2680
|
|
|
2644
|
-
_super.prototype.groupIdentifyStateless.call(this, groupType, groupKey, properties);
|
|
2681
|
+
_super.prototype.groupIdentifyStateless.call(this, groupType, groupKey, properties, undefined, distinctId);
|
|
2645
2682
|
};
|
|
2646
2683
|
|
|
2647
2684
|
PostHog.prototype.reloadFeatureFlags = function () {
|