posthog-node 3.5.0 → 3.6.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/lib/index.d.ts CHANGED
@@ -45,7 +45,10 @@ declare type PostHogFetchOptions = {
45
45
  body?: string;
46
46
  signal?: AbortSignal;
47
47
  };
48
- declare type PosthogCaptureOptions = {
48
+ declare type PostHogCaptureOptions = {
49
+ /** If provided overrides the auto-generated event ID */
50
+ uuid?: string;
51
+ /** If provided overrides the auto-generated timestamp */
49
52
  timestamp?: Date;
50
53
  disableGeoip?: boolean;
51
54
  };
@@ -132,17 +135,17 @@ declare abstract class PostHogCoreStateless {
132
135
  /***
133
136
  *** TRACKING
134
137
  ***/
135
- protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
138
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
136
139
  protected captureStateless(distinctId: string, event: string, properties?: {
137
140
  [key: string]: any;
138
- }, options?: PosthogCaptureOptions): this;
141
+ }, options?: PostHogCaptureOptions): this;
139
142
  protected aliasStateless(alias: string, distinctId: string, properties?: {
140
143
  [key: string]: any;
141
- }, options?: PosthogCaptureOptions): this;
144
+ }, options?: PostHogCaptureOptions): this;
142
145
  /***
143
146
  *** GROUPS
144
147
  ***/
145
- protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
148
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
146
149
  /***
147
150
  *** FEATURE FLAGS
148
151
  ***/
@@ -159,7 +162,7 @@ declare abstract class PostHogCoreStateless {
159
162
  /***
160
163
  *** QUEUEING AND FLUSHING
161
164
  ***/
162
- protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
165
+ protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
163
166
  flushAsync(): Promise<any>;
164
167
  flush(callback?: (err?: any, data?: any) => void): void;
165
168
  private fetchWithRetry;
@@ -167,16 +170,17 @@ declare abstract class PostHogCoreStateless {
167
170
  shutdown(): void;
168
171
  }
169
172
 
170
- interface IdentifyMessageV1 {
173
+ interface IdentifyMessage {
171
174
  distinctId: string;
172
175
  properties?: Record<string | number, any>;
173
176
  disableGeoip?: boolean;
174
177
  }
175
- interface EventMessageV1 extends IdentifyMessageV1 {
178
+ interface EventMessage extends IdentifyMessage {
176
179
  event: string;
177
180
  groups?: Record<string, string | number>;
178
181
  sendFeatureFlags?: boolean;
179
182
  timestamp?: Date;
183
+ uuid?: string;
180
184
  }
181
185
  interface GroupIdentifyMessage {
182
186
  groupType: string;
@@ -197,7 +201,7 @@ declare type PostHogNodeV1 = {
197
201
  * @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
198
202
  * @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
199
203
  */
200
- capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
204
+ capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
201
205
  /**
202
206
  * @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,
203
207
  * and even do things like segment users by these properties.
@@ -205,7 +209,7 @@ declare type PostHogNodeV1 = {
205
209
  * @param distinctId which uniquely identifies your user
206
210
  * @param properties with a dict with any key: value pairs
207
211
  */
208
- identify({ distinctId, properties }: IdentifyMessageV1): void;
212
+ identify({ distinctId, properties }: IdentifyMessage): void;
209
213
  /**
210
214
  * @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
211
215
  * This will allow you to answer questions like "Which marketing channels leads to users churning after a month?"
@@ -329,8 +333,8 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
329
333
  enable(): void;
330
334
  disable(): void;
331
335
  debug(enabled?: boolean): void;
332
- capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void;
333
- identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void;
336
+ capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid, }: EventMessage): void;
337
+ identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
334
338
  alias(data: {
335
339
  distinctId: string;
336
340
  alias: string;
package/lib/index.esm.js CHANGED
@@ -154,7 +154,7 @@ function __spreadArray(to, from, pack) {
154
154
  return to.concat(ar || Array.prototype.slice.call(from));
155
155
  }
156
156
 
157
- var version = "3.5.0";
157
+ var version = "3.6.1";
158
158
 
159
159
  var PostHogPersistedProperty;
160
160
  (function (PostHogPersistedProperty) {
@@ -1012,7 +1012,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1012
1012
  this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1013
1013
  return;
1014
1014
  }
1015
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime() });
1015
+ var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : generateUUID(globalThis) });
1016
1016
  var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
1017
1017
  if (addGeoipDisableProperty) {
1018
1018
  if (!message.properties) {
@@ -2446,14 +2446,10 @@ function matchProperty(property, propertyValues) {
2446
2446
 
2447
2447
  case 'is_date_after':
2448
2448
  case 'is_date_before':
2449
- case 'is_relative_date_before':
2450
- case 'is_relative_date_after':
2451
2449
  {
2452
- var parsedDate = null;
2450
+ var parsedDate = relativeDateParseForFeatureFlagMatching(String(value));
2453
2451
 
2454
- if (['is_relative_date_before', 'is_relative_date_after'].includes(operator)) {
2455
- parsedDate = relativeDateParseForFeatureFlagMatching(String(value));
2456
- } else {
2452
+ if (parsedDate == null) {
2457
2453
  parsedDate = convertToDateTime(value);
2458
2454
  }
2459
2455
 
@@ -2463,7 +2459,7 @@ function matchProperty(property, propertyValues) {
2463
2459
 
2464
2460
  var overrideDate = convertToDateTime(overrideValue);
2465
2461
 
2466
- if (['is_date_before', 'is_relative_date_before'].includes(operator)) {
2462
+ if (['is_date_before'].includes(operator)) {
2467
2463
  return overrideDate < parsedDate;
2468
2464
  }
2469
2465
 
@@ -2614,7 +2610,7 @@ function convertToDateTime(value) {
2614
2610
  }
2615
2611
 
2616
2612
  function relativeDateParseForFeatureFlagMatching(value) {
2617
- var regex = /^(?<number>[0-9]+)(?<interval>[a-z])$/;
2613
+ var regex = /^-?(?<number>[0-9]+)(?<interval>[a-z])$/;
2618
2614
  var match = value.match(regex);
2619
2615
  var parsedDt = new Date(new Date().toISOString());
2620
2616
 
@@ -2746,12 +2742,14 @@ function (_super) {
2746
2742
  groups = _a.groups,
2747
2743
  sendFeatureFlags = _a.sendFeatureFlags,
2748
2744
  timestamp = _a.timestamp,
2749
- disableGeoip = _a.disableGeoip;
2745
+ disableGeoip = _a.disableGeoip,
2746
+ uuid = _a.uuid;
2750
2747
 
2751
2748
  var _capture = function (props) {
2752
2749
  _super.prototype.captureStateless.call(_this, distinctId, event, props, {
2753
2750
  timestamp: timestamp,
2754
- disableGeoip: disableGeoip
2751
+ disableGeoip: disableGeoip,
2752
+ uuid: uuid
2755
2753
  });
2756
2754
  }; // :TRICKY: If we flush, or need to shut down, to not lose events we want this promise to resolve before we flush
2757
2755
 
@@ -3183,7 +3181,7 @@ function (_super) {
3183
3181
 
3184
3182
  PostHog.prototype.addLocalPersonAndGroupProperties = function (distinctId, groups, personProperties, groupProperties) {
3185
3183
  var allPersonProperties = __assign({
3186
- $current_distinct_id: distinctId
3184
+ distinct_id: distinctId
3187
3185
  }, personProperties || {});
3188
3186
 
3189
3187
  var allGroupProperties = {};