posthog-node 2.0.0-alpha2 → 2.0.0-alpha5
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/lib/index.cjs.js +42 -9
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.esm.js +42 -9
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/eventemitter.d.ts +2 -2
- package/lib/posthog-core/src/index.d.ts +4 -1
- package/lib/posthog-core/src/storage-memory.d.ts +6 -0
- package/lib/posthog-node/src/posthog-node.d.ts +5 -1
- package/package.json +1 -1
- package/src/posthog-node.ts +15 -4
package/lib/index.d.ts
CHANGED
|
@@ -96,11 +96,15 @@ declare type PostHogNodeV1 = {
|
|
|
96
96
|
shutdown(): void;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
declare type PostHogOptions = PosthogCoreOptions
|
|
99
|
+
declare type PostHogOptions = PosthogCoreOptions & {
|
|
100
|
+
persistence?: 'memory';
|
|
101
|
+
};
|
|
100
102
|
declare class PostHogGlobal implements PostHogNodeV1 {
|
|
101
103
|
private _sharedClient;
|
|
102
104
|
constructor(apiKey: string, options?: PostHogOptions);
|
|
103
105
|
private reInit;
|
|
106
|
+
enable(): void;
|
|
107
|
+
disable(): void;
|
|
104
108
|
capture({ distinctId, event, properties, groups }: EventMessageV1): void;
|
|
105
109
|
identify({ distinctId, properties }: IdentifyMessageV1): void;
|
|
106
110
|
alias(data: {
|
package/lib/index.esm.js
CHANGED
|
@@ -131,7 +131,7 @@ function __generator(thisArg, body) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
var version = "2.0.0-
|
|
134
|
+
var version = "2.0.0-alpha5";
|
|
135
135
|
|
|
136
136
|
var PostHogPersistedProperty;
|
|
137
137
|
(function (PostHogPersistedProperty) {
|
|
@@ -160,7 +160,7 @@ function retriable(fn, props) {
|
|
|
160
160
|
return __generator(this, function (_d) {
|
|
161
161
|
switch (_d.label) {
|
|
162
162
|
case 0:
|
|
163
|
-
_a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ?
|
|
163
|
+
_a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ? 5000 : _b, _c = props.retryCheck, retryCheck = _c === void 0 ? function () { return true; } : _c;
|
|
164
164
|
lastError = null;
|
|
165
165
|
i = 0;
|
|
166
166
|
_d.label = 1;
|
|
@@ -674,13 +674,14 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
674
674
|
};
|
|
675
675
|
};
|
|
676
676
|
SimpleEventEmitter.prototype.emit = function (event, payload) {
|
|
677
|
-
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
for (var _i = 0, _a = this.events[event]; _i < _a.length; _i++) {
|
|
677
|
+
for (var _i = 0, _a = this.events[event] || []; _i < _a.length; _i++) {
|
|
681
678
|
var listener = _a[_i];
|
|
682
679
|
listener(payload);
|
|
683
680
|
}
|
|
681
|
+
for (var _b = 0, _c = this.events['*'] || []; _b < _c.length; _b++) {
|
|
682
|
+
var listener = _c[_b];
|
|
683
|
+
listener(event, payload);
|
|
684
|
+
}
|
|
684
685
|
};
|
|
685
686
|
return SimpleEventEmitter;
|
|
686
687
|
}());
|
|
@@ -760,6 +761,14 @@ var PostHogCore = /** @class */ (function () {
|
|
|
760
761
|
}
|
|
761
762
|
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, generateUUID(globalThis));
|
|
762
763
|
};
|
|
764
|
+
PostHogCore.prototype.debug = function (enabled) {
|
|
765
|
+
var _a;
|
|
766
|
+
if (enabled === void 0) { enabled = true; }
|
|
767
|
+
(_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
768
|
+
if (enabled) {
|
|
769
|
+
this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
|
|
770
|
+
}
|
|
771
|
+
};
|
|
763
772
|
PostHogCore.prototype.buildPayload = function (payload) {
|
|
764
773
|
return {
|
|
765
774
|
distinct_id: payload.distinct_id || this.getDistinctId(),
|
|
@@ -777,6 +786,9 @@ var PostHogCore = /** @class */ (function () {
|
|
|
777
786
|
this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
|
|
778
787
|
return sessionId;
|
|
779
788
|
};
|
|
789
|
+
PostHogCore.prototype.resetSessionId = function () {
|
|
790
|
+
this.setPersistedProperty(PostHogPersistedProperty.SessionId, null);
|
|
791
|
+
};
|
|
780
792
|
PostHogCore.prototype.getDistinctId = function () {
|
|
781
793
|
var distinctId = this.getPersistedProperty(PostHogPersistedProperty.DistinctId);
|
|
782
794
|
if (!distinctId) {
|
|
@@ -1113,6 +1125,19 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1113
1125
|
return PostHogCore;
|
|
1114
1126
|
}());
|
|
1115
1127
|
|
|
1128
|
+
var PostHogMemoryStorage = /** @class */ (function () {
|
|
1129
|
+
function PostHogMemoryStorage() {
|
|
1130
|
+
this._memoryStorage = {};
|
|
1131
|
+
}
|
|
1132
|
+
PostHogMemoryStorage.prototype.getProperty = function (key) {
|
|
1133
|
+
return this._memoryStorage[key];
|
|
1134
|
+
};
|
|
1135
|
+
PostHogMemoryStorage.prototype.setProperty = function (key, value) {
|
|
1136
|
+
this._memoryStorage[key] = value !== null ? value : undefined;
|
|
1137
|
+
};
|
|
1138
|
+
return PostHogMemoryStorage;
|
|
1139
|
+
}());
|
|
1140
|
+
|
|
1116
1141
|
var PostHog =
|
|
1117
1142
|
/** @class */
|
|
1118
1143
|
function (_super) {
|
|
@@ -1129,16 +1154,16 @@ function (_super) {
|
|
|
1129
1154
|
options.preloadFeatureFlags = false; // Don't preload as this makes no sense without a distinctId
|
|
1130
1155
|
|
|
1131
1156
|
_this = _super.call(this, apiKey, options) || this;
|
|
1132
|
-
_this._memoryStorage =
|
|
1157
|
+
_this._memoryStorage = new PostHogMemoryStorage();
|
|
1133
1158
|
return _this;
|
|
1134
1159
|
}
|
|
1135
1160
|
|
|
1136
1161
|
PostHog.prototype.getPersistedProperty = function (key) {
|
|
1137
|
-
return this._memoryStorage
|
|
1162
|
+
return this._memoryStorage.getProperty(key);
|
|
1138
1163
|
};
|
|
1139
1164
|
|
|
1140
1165
|
PostHog.prototype.setPersistedProperty = function (key, value) {
|
|
1141
|
-
this._memoryStorage
|
|
1166
|
+
return this._memoryStorage.setProperty(key, value);
|
|
1142
1167
|
};
|
|
1143
1168
|
|
|
1144
1169
|
PostHog.prototype.getSessionId = function () {
|
|
@@ -1190,6 +1215,14 @@ function () {
|
|
|
1190
1215
|
this._sharedClient.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
|
|
1191
1216
|
};
|
|
1192
1217
|
|
|
1218
|
+
PostHogGlobal.prototype.enable = function () {
|
|
1219
|
+
return this._sharedClient.optIn();
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
PostHogGlobal.prototype.disable = function () {
|
|
1223
|
+
return this._sharedClient.optOut();
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1193
1226
|
PostHogGlobal.prototype.capture = function (_a) {
|
|
1194
1227
|
var distinctId = _a.distinctId,
|
|
1195
1228
|
event = _a.event,
|