posthog-node 5.18.1 → 5.20.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/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JsonType, PostHogCoreStateless, PostHogFetchOptions, PostHogFetchResponse, PostHogFlagsAndPayloadsResponse, PostHogPersistedProperty, PostHogCaptureOptions } from '@posthog/core';
2
- import { EventMessage, GroupIdentifyMessage, IdentifyMessage, IPostHog, PostHogOptions } from './types';
2
+ import { EventMessage, GroupIdentifyMessage, IdentifyMessage, IPostHog, OverrideFeatureFlagsOptions, PostHogOptions } from './types';
3
3
  import { FeatureFlagValue } from '@posthog/core';
4
4
  import ErrorTracking from './extensions/error-tracking';
5
5
  import { PostHogEventProperties } from '@posthog/core';
@@ -11,6 +11,8 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
11
11
  private maxCacheSize;
12
12
  readonly options: PostHogOptions;
13
13
  protected readonly context?: IPostHogContext;
14
+ private _flagOverrides?;
15
+ private _payloadOverrides?;
14
16
  distinctIdHasSentFlagCalls: Record<string, string[]>;
15
17
  /**
16
18
  * Initialize a new PostHog client instance.
@@ -686,6 +688,41 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
686
688
  * @returns Promise that resolves when flags are reloaded
687
689
  */
688
690
  reloadFeatureFlags(): Promise<void>;
691
+ /**
692
+ * Override feature flags locally. Useful for testing and local development.
693
+ * Overridden flags take precedence over both local evaluation and remote evaluation.
694
+ *
695
+ * @example
696
+ * ```ts
697
+ * // Clear all overrides
698
+ * client.overrideFeatureFlags(false)
699
+ *
700
+ * // Enable a list of flags (sets them to true)
701
+ * client.overrideFeatureFlags(['flag-a', 'flag-b'])
702
+ *
703
+ * // Set specific flag values/variants
704
+ * client.overrideFeatureFlags({ 'my-flag': 'variant-a', 'other-flag': true })
705
+ *
706
+ * // Set both flags and payloads
707
+ * client.overrideFeatureFlags({
708
+ * flags: { 'my-flag': 'variant-a' },
709
+ * payloads: { 'my-flag': { discount: 20 } }
710
+ * })
711
+ * ```
712
+ *
713
+ * {@label Feature flags}
714
+ *
715
+ * @param overrides - Flag overrides configuration
716
+ */
717
+ overrideFeatureFlags(overrides: OverrideFeatureFlagsOptions): void;
718
+ /**
719
+ * Type guard to check if overrides is a FeatureFlagOverrideOptions object.
720
+ *
721
+ * This distinguishes between:
722
+ * - { flags: { 'flag-a': true } } -> FeatureFlagOverrideOptions (flags is an object/array/false)
723
+ * - { flags: true } -> Record<string, FeatureFlagValue> (a flag named "flags" with value true)
724
+ */
725
+ private _isFeatureFlagOverrideOptions;
689
726
  protected abstract initializeContext(): IPostHogContext | undefined;
690
727
  /**
691
728
  * Run a function with specific context that will be applied to all events captured within that context.
@@ -784,7 +821,7 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
784
821
  * @param distinctId - Optional user distinct ID
785
822
  * @param additionalProperties - Optional additional properties to include
786
823
  */
787
- captureException(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>): void;
824
+ captureException(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>, uuid?: EventMessage['uuid']): void;
788
825
  /**
789
826
  * Capture an error exception as an event immediately (synchronously).
790
827
  *
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,oBAAoB,EAEpB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAC/B,wBAAwB,EACxB,qBAAqB,EAGtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,YAAY,EAGZ,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAAqB,gBAAgB,EAAuB,MAAM,eAAe,CAAA;AAMxF,OAAO,aAAa,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAkB,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAGtE,OAAO,EAA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EAAE,qBAAqB,CAAA;KAC/B,CAAC;IAiHF,OAAO,CAAC,cAAc;CAuBvB"}
package/dist/client.js CHANGED
@@ -175,6 +175,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
175
175
  });
176
176
  }
177
177
  async getFeatureFlag(key, distinctId, options) {
178
+ if (void 0 !== this._flagOverrides && key in this._flagOverrides) return this._flagOverrides[key];
178
179
  const { groups, disableGeoip } = options || {};
179
180
  let { onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties } = options || {};
180
181
  const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
@@ -235,6 +236,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
235
236
  return response;
236
237
  }
237
238
  async getFeatureFlagPayload(key, distinctId, matchValue, options) {
239
+ if (void 0 !== this._payloadOverrides && key in this._payloadOverrides) return this._payloadOverrides[key];
238
240
  const { groups, disableGeoip } = options || {};
239
241
  let { onlyEvaluateLocally, personProperties, groupProperties } = options || {};
240
242
  const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
@@ -307,6 +309,14 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
307
309
  ...remoteEvaluationResult.payloads || {}
308
310
  };
309
311
  }
312
+ if (void 0 !== this._flagOverrides) featureFlags = {
313
+ ...featureFlags,
314
+ ...this._flagOverrides
315
+ };
316
+ if (void 0 !== this._payloadOverrides) featureFlagPayloads = {
317
+ ...featureFlagPayloads,
318
+ ...this._payloadOverrides
319
+ };
310
320
  return {
311
321
  featureFlags,
312
322
  featureFlagPayloads
@@ -320,6 +330,53 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
320
330
  async reloadFeatureFlags() {
321
331
  await this.featureFlagsPoller?.loadFeatureFlags(true);
322
332
  }
333
+ overrideFeatureFlags(overrides) {
334
+ const flagArrayToRecord = (flags)=>Object.fromEntries(flags.map((f)=>[
335
+ f,
336
+ true
337
+ ]));
338
+ if (false === overrides) {
339
+ this._flagOverrides = void 0;
340
+ this._payloadOverrides = void 0;
341
+ return;
342
+ }
343
+ if (Array.isArray(overrides)) {
344
+ this._flagOverrides = flagArrayToRecord(overrides);
345
+ return;
346
+ }
347
+ if (this._isFeatureFlagOverrideOptions(overrides)) {
348
+ if ('flags' in overrides) {
349
+ if (false === overrides.flags) this._flagOverrides = void 0;
350
+ else if (Array.isArray(overrides.flags)) this._flagOverrides = flagArrayToRecord(overrides.flags);
351
+ else if (void 0 !== overrides.flags) this._flagOverrides = {
352
+ ...overrides.flags
353
+ };
354
+ }
355
+ if ('payloads' in overrides) {
356
+ if (false === overrides.payloads) this._payloadOverrides = void 0;
357
+ else if (void 0 !== overrides.payloads) this._payloadOverrides = {
358
+ ...overrides.payloads
359
+ };
360
+ }
361
+ return;
362
+ }
363
+ this._flagOverrides = {
364
+ ...overrides
365
+ };
366
+ }
367
+ _isFeatureFlagOverrideOptions(overrides) {
368
+ if ('object' != typeof overrides || null === overrides || Array.isArray(overrides)) return false;
369
+ const obj = overrides;
370
+ if ('flags' in obj) {
371
+ const flagsValue = obj['flags'];
372
+ if (false === flagsValue || Array.isArray(flagsValue) || 'object' == typeof flagsValue && null !== flagsValue) return true;
373
+ }
374
+ if ('payloads' in obj) {
375
+ const payloadsValue = obj['payloads'];
376
+ if (false === payloadsValue || 'object' == typeof payloadsValue && null !== payloadsValue) return true;
377
+ }
378
+ return false;
379
+ }
323
380
  withContext(data, fn, options) {
324
381
  if (!this.context) return fn();
325
382
  return this.context.run(data, fn, options);
@@ -424,17 +481,24 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
424
481
  allGroupProperties
425
482
  };
426
483
  }
427
- captureException(error, distinctId, additionalProperties) {
428
- const syntheticException = new Error('PostHog syntheticException');
429
- this.addPendingPromise(index_js_default().buildEventMessage(error, {
430
- syntheticException
431
- }, distinctId, additionalProperties).then((msg)=>this.capture(msg)));
484
+ captureException(error, distinctId, additionalProperties, uuid) {
485
+ if (!index_js_default().isPreviouslyCapturedError(error)) {
486
+ const syntheticException = new Error('PostHog syntheticException');
487
+ this.addPendingPromise(index_js_default().buildEventMessage(error, {
488
+ syntheticException
489
+ }, distinctId, additionalProperties).then((msg)=>this.capture({
490
+ ...msg,
491
+ uuid
492
+ })));
493
+ }
432
494
  }
433
495
  async captureExceptionImmediate(error, distinctId, additionalProperties) {
434
- const syntheticException = new Error('PostHog syntheticException');
435
- this.addPendingPromise(index_js_default().buildEventMessage(error, {
436
- syntheticException
437
- }, distinctId, additionalProperties).then((msg)=>this.captureImmediate(msg)));
496
+ if (!index_js_default().isPreviouslyCapturedError(error)) {
497
+ const syntheticException = new Error('PostHog syntheticException');
498
+ this.addPendingPromise(index_js_default().buildEventMessage(error, {
499
+ syntheticException
500
+ }, distinctId, additionalProperties).then((msg)=>this.captureImmediate(msg)));
501
+ }
438
502
  }
439
503
  async prepareEventMessage(props) {
440
504
  const { distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid } = props;
package/dist/client.mjs CHANGED
@@ -137,6 +137,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
137
137
  });
138
138
  }
139
139
  async getFeatureFlag(key, distinctId, options) {
140
+ if (void 0 !== this._flagOverrides && key in this._flagOverrides) return this._flagOverrides[key];
140
141
  const { groups, disableGeoip } = options || {};
141
142
  let { onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties } = options || {};
142
143
  const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
@@ -197,6 +198,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
197
198
  return response;
198
199
  }
199
200
  async getFeatureFlagPayload(key, distinctId, matchValue, options) {
201
+ if (void 0 !== this._payloadOverrides && key in this._payloadOverrides) return this._payloadOverrides[key];
200
202
  const { groups, disableGeoip } = options || {};
201
203
  let { onlyEvaluateLocally, personProperties, groupProperties } = options || {};
202
204
  const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
@@ -269,6 +271,14 @@ class PostHogBackendClient extends PostHogCoreStateless {
269
271
  ...remoteEvaluationResult.payloads || {}
270
272
  };
271
273
  }
274
+ if (void 0 !== this._flagOverrides) featureFlags = {
275
+ ...featureFlags,
276
+ ...this._flagOverrides
277
+ };
278
+ if (void 0 !== this._payloadOverrides) featureFlagPayloads = {
279
+ ...featureFlagPayloads,
280
+ ...this._payloadOverrides
281
+ };
272
282
  return {
273
283
  featureFlags,
274
284
  featureFlagPayloads
@@ -282,6 +292,53 @@ class PostHogBackendClient extends PostHogCoreStateless {
282
292
  async reloadFeatureFlags() {
283
293
  await this.featureFlagsPoller?.loadFeatureFlags(true);
284
294
  }
295
+ overrideFeatureFlags(overrides) {
296
+ const flagArrayToRecord = (flags)=>Object.fromEntries(flags.map((f)=>[
297
+ f,
298
+ true
299
+ ]));
300
+ if (false === overrides) {
301
+ this._flagOverrides = void 0;
302
+ this._payloadOverrides = void 0;
303
+ return;
304
+ }
305
+ if (Array.isArray(overrides)) {
306
+ this._flagOverrides = flagArrayToRecord(overrides);
307
+ return;
308
+ }
309
+ if (this._isFeatureFlagOverrideOptions(overrides)) {
310
+ if ('flags' in overrides) {
311
+ if (false === overrides.flags) this._flagOverrides = void 0;
312
+ else if (Array.isArray(overrides.flags)) this._flagOverrides = flagArrayToRecord(overrides.flags);
313
+ else if (void 0 !== overrides.flags) this._flagOverrides = {
314
+ ...overrides.flags
315
+ };
316
+ }
317
+ if ('payloads' in overrides) {
318
+ if (false === overrides.payloads) this._payloadOverrides = void 0;
319
+ else if (void 0 !== overrides.payloads) this._payloadOverrides = {
320
+ ...overrides.payloads
321
+ };
322
+ }
323
+ return;
324
+ }
325
+ this._flagOverrides = {
326
+ ...overrides
327
+ };
328
+ }
329
+ _isFeatureFlagOverrideOptions(overrides) {
330
+ if ('object' != typeof overrides || null === overrides || Array.isArray(overrides)) return false;
331
+ const obj = overrides;
332
+ if ('flags' in obj) {
333
+ const flagsValue = obj['flags'];
334
+ if (false === flagsValue || Array.isArray(flagsValue) || 'object' == typeof flagsValue && null !== flagsValue) return true;
335
+ }
336
+ if ('payloads' in obj) {
337
+ const payloadsValue = obj['payloads'];
338
+ if (false === payloadsValue || 'object' == typeof payloadsValue && null !== payloadsValue) return true;
339
+ }
340
+ return false;
341
+ }
285
342
  withContext(data, fn, options) {
286
343
  if (!this.context) return fn();
287
344
  return this.context.run(data, fn, options);
@@ -386,17 +443,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
386
443
  allGroupProperties
387
444
  };
388
445
  }
389
- captureException(error, distinctId, additionalProperties) {
390
- const syntheticException = new Error('PostHog syntheticException');
391
- this.addPendingPromise(error_tracking.buildEventMessage(error, {
392
- syntheticException
393
- }, distinctId, additionalProperties).then((msg)=>this.capture(msg)));
446
+ captureException(error, distinctId, additionalProperties, uuid) {
447
+ if (!error_tracking.isPreviouslyCapturedError(error)) {
448
+ const syntheticException = new Error('PostHog syntheticException');
449
+ this.addPendingPromise(error_tracking.buildEventMessage(error, {
450
+ syntheticException
451
+ }, distinctId, additionalProperties).then((msg)=>this.capture({
452
+ ...msg,
453
+ uuid
454
+ })));
455
+ }
394
456
  }
395
457
  async captureExceptionImmediate(error, distinctId, additionalProperties) {
396
- const syntheticException = new Error('PostHog syntheticException');
397
- this.addPendingPromise(error_tracking.buildEventMessage(error, {
398
- syntheticException
399
- }, distinctId, additionalProperties).then((msg)=>this.captureImmediate(msg)));
458
+ if (!error_tracking.isPreviouslyCapturedError(error)) {
459
+ const syntheticException = new Error('PostHog syntheticException');
460
+ this.addPendingPromise(error_tracking.buildEventMessage(error, {
461
+ syntheticException
462
+ }, distinctId, additionalProperties).then((msg)=>this.captureImmediate(msg)));
463
+ }
400
464
  }
401
465
  async prepareEventMessage(props) {
402
466
  const { distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid } = props;
@@ -9,6 +9,7 @@ export default class ErrorTracking {
9
9
  private _logger;
10
10
  static errorPropertiesBuilder: CoreErrorTracking.ErrorPropertiesBuilder;
11
11
  constructor(client: PostHogBackendClient, options: PostHogOptions, _logger: Logger);
12
+ static isPreviouslyCapturedError(x: unknown): boolean;
12
13
  static buildEventMessage(error: unknown, hint: CoreErrorTracking.EventHint, distinctId?: string, additionalProperties?: Record<string | number, any>): Promise<EventMessage>;
13
14
  private startAutocaptureIfEnabled;
14
15
  private onException;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAIlE,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,4BAA4B,CAAS;IAC7C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,OAAO,CAAQ;IAEvB,MAAM,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,sBAAsB,CAAA;gBAE3D,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;WAkBrE,iBAAiB,CAC5B,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,iBAAiB,CAAC,SAAS,EACjC,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAClD,OAAO,CAAC,YAAY,CAAC;IAwBxB,OAAO,CAAC,yBAAyB;IAOjC,OAAO,CAAC,WAAW;YAkBL,YAAY;IAM1B,SAAS,IAAI,OAAO;IAIpB,QAAQ,IAAI,IAAI;CAGjB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAIlE,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,4BAA4B,CAAS;IAC7C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,OAAO,CAAQ;IAEvB,MAAM,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,sBAAsB,CAAA;gBAE3D,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;IAkBlF,MAAM,CAAC,yBAAyB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;WAIxC,iBAAiB,CAC5B,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,iBAAiB,CAAC,SAAS,EACjC,UAAU,CAAC,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAClD,OAAO,CAAC,YAAY,CAAC;IAwBxB,OAAO,CAAC,yBAAyB;IAOjC,OAAO,CAAC,WAAW;YAoBL,YAAY;IAM1B,SAAS,IAAI,OAAO;IAIpB,QAAQ,IAAI,IAAI;CAGjB"}
@@ -42,6 +42,9 @@ class ErrorTracking {
42
42
  });
43
43
  this.startAutocaptureIfEnabled();
44
44
  }
45
+ static isPreviouslyCapturedError(x) {
46
+ return (0, core_namespaceObject.isObject)(x) && '__posthog_previously_captured_error' in x && true === x.__posthog_previously_captured_error;
47
+ }
45
48
  static async buildEventMessage(error, hint, distinctId, additionalProperties) {
46
49
  const properties = {
47
50
  ...additionalProperties
@@ -66,14 +69,16 @@ class ErrorTracking {
66
69
  }
67
70
  onException(exception, hint) {
68
71
  this.client.addPendingPromise((async ()=>{
69
- const eventMessage = await ErrorTracking.buildEventMessage(exception, hint);
70
- const exceptionProperties = eventMessage.properties;
71
- const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception';
72
- const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
73
- if (isRateLimited) return void this._logger.info('Skipping exception capture because of client rate limiting.', {
74
- exception: exceptionType
75
- });
76
- return this.client.capture(eventMessage);
72
+ if (!ErrorTracking.isPreviouslyCapturedError(exception)) {
73
+ const eventMessage = await ErrorTracking.buildEventMessage(exception, hint);
74
+ const exceptionProperties = eventMessage.properties;
75
+ const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception';
76
+ const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
77
+ if (isRateLimited) return void this._logger.info('Skipping exception capture because of client rate limiting.', {
78
+ exception: exceptionType
79
+ });
80
+ return this.client.capture(eventMessage);
81
+ }
77
82
  })());
78
83
  }
79
84
  async onFatalError(exception) {
@@ -1,5 +1,5 @@
1
1
  import { addUncaughtExceptionListener, addUnhandledRejectionListener } from "./autocapture.mjs";
2
- import { BucketedRateLimiter, uuidv7 } from "@posthog/core";
2
+ import { BucketedRateLimiter, isObject, uuidv7 } from "@posthog/core";
3
3
  const SHUTDOWN_TIMEOUT = 2000;
4
4
  class ErrorTracking {
5
5
  constructor(client, options, _logger){
@@ -14,6 +14,9 @@ class ErrorTracking {
14
14
  });
15
15
  this.startAutocaptureIfEnabled();
16
16
  }
17
+ static isPreviouslyCapturedError(x) {
18
+ return isObject(x) && '__posthog_previously_captured_error' in x && true === x.__posthog_previously_captured_error;
19
+ }
17
20
  static async buildEventMessage(error, hint, distinctId, additionalProperties) {
18
21
  const properties = {
19
22
  ...additionalProperties
@@ -38,14 +41,16 @@ class ErrorTracking {
38
41
  }
39
42
  onException(exception, hint) {
40
43
  this.client.addPendingPromise((async ()=>{
41
- const eventMessage = await ErrorTracking.buildEventMessage(exception, hint);
42
- const exceptionProperties = eventMessage.properties;
43
- const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception';
44
- const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
45
- if (isRateLimited) return void this._logger.info('Skipping exception capture because of client rate limiting.', {
46
- exception: exceptionType
47
- });
48
- return this.client.capture(eventMessage);
44
+ if (!ErrorTracking.isPreviouslyCapturedError(exception)) {
45
+ const eventMessage = await ErrorTracking.buildEventMessage(exception, hint);
46
+ const exceptionProperties = eventMessage.properties;
47
+ const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception';
48
+ const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
49
+ if (isRateLimited) return void this._logger.info('Skipping exception capture because of client rate limiting.', {
50
+ exception: exceptionType
51
+ });
52
+ return this.client.capture(eventMessage);
53
+ }
49
54
  })());
50
55
  }
51
56
  async onFatalError(exception) {
@@ -42,6 +42,7 @@ function setupExpressErrorHandler(_posthog, app) {
42
42
  }
43
43
  function posthogErrorHandler(posthog) {
44
44
  return (error, req, res, next)=>{
45
+ if (index_js_default().isPreviouslyCapturedError(error)) return void next(error);
45
46
  const sessionId = req.headers['x-posthog-session-id'];
46
47
  const distinctId = req.headers['x-posthog-distinct-id'];
47
48
  const syntheticException = new Error('Synthetic exception');
@@ -4,6 +4,7 @@ function setupExpressErrorHandler(_posthog, app) {
4
4
  }
5
5
  function posthogErrorHandler(posthog) {
6
6
  return (error, req, res, next)=>{
7
+ if (error_tracking.isPreviouslyCapturedError(error)) return void next(error);
7
8
  const sessionId = req.headers['x-posthog-session-id'];
8
9
  const distinctId = req.headers['x-posthog-distinct-id'];
9
10
  const syntheticException = new Error('Synthetic exception');
package/dist/types.d.ts CHANGED
@@ -40,6 +40,31 @@ export type FlagProperty = {
40
40
  dependency_chain?: string[];
41
41
  };
42
42
  export type FlagPropertyValue = string | number | (string | number)[] | boolean;
43
+ /**
44
+ * Options for overriding feature flags.
45
+ *
46
+ * Supports multiple formats:
47
+ * - `false` - Clear all overrides
48
+ * - `string[]` - Enable a list of flags (sets them to `true`)
49
+ * - `Record<string, FeatureFlagValue>` - Set specific flag values/variants
50
+ * - `FeatureFlagOverrideOptions` - Set both flag values and payloads
51
+ */
52
+ export type OverrideFeatureFlagsOptions = false | string[] | Record<string, FeatureFlagValue> | FeatureFlagOverrideOptions;
53
+ export type FeatureFlagOverrideOptions = {
54
+ /**
55
+ * Flag overrides. Can be:
56
+ * - `false` to clear flag overrides
57
+ * - `string[]` to enable a list of flags
58
+ * - `Record<string, FeatureFlagValue>` to set specific values/variants
59
+ */
60
+ flags?: false | string[] | Record<string, FeatureFlagValue>;
61
+ /**
62
+ * Payload overrides for flags.
63
+ * - `false` to clear payload overrides
64
+ * - `Record<string, JsonType>` to set specific payloads
65
+ */
66
+ payloads?: false | Record<string, JsonType>;
67
+ };
43
68
  export type FeatureFlagCondition = {
44
69
  properties: FlagProperty[];
45
70
  rollout_percentage?: number;
@@ -316,6 +341,31 @@ export interface IPostHog {
316
341
  * already polled automatically at a regular interval.
317
342
  */
318
343
  reloadFeatureFlags(): Promise<void>;
344
+ /**
345
+ * @description Override feature flags locally. Useful for testing and local development.
346
+ * Overridden flags take precedence over both local evaluation and remote evaluation.
347
+ *
348
+ * @example
349
+ * ```ts
350
+ * // Clear all overrides
351
+ * posthog.overrideFeatureFlags(false)
352
+ *
353
+ * // Enable a list of flags (sets them to true)
354
+ * posthog.overrideFeatureFlags(['flag-a', 'flag-b'])
355
+ *
356
+ * // Set specific flag values/variants
357
+ * posthog.overrideFeatureFlags({ 'my-flag': 'variant-a', 'other-flag': true })
358
+ *
359
+ * // Set both flags and payloads
360
+ * posthog.overrideFeatureFlags({
361
+ * flags: { 'my-flag': 'variant-a' },
362
+ * payloads: { 'my-flag': { discount: 20 } }
363
+ * })
364
+ * ```
365
+ *
366
+ * @param overrides - Flag overrides configuration
367
+ */
368
+ overrideFeatureFlags(overrides: OverrideFeatureFlagsOptions): void;
319
369
  /**
320
370
  * @description Run a function with specific context that will be applied to all events captured within that context.
321
371
  * @param data Context data to apply (sessionId, distinctId, properties, enableExceptionAutocapture)
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAExE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAEnF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;IACzC,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IACrD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACxC,gBAAgB,CAAC,EAAE,OAAO,GAAG,uBAAuB,CAAA;IACpD,SAAS,CAAC,EAAE,IAAI,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C,EAAE,OAAO,CAAA;QAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAChC,GACA,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAA;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,qBAAqB,CACnB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE;QACR,mBAAmB,CAAC,EAAE,OAAO,CAAA;KAC9B,GACA,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IAEhC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,oBAAoB,GAAG,IAAI,CAAA;IAE9E;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,oBAAoB,CAAC,SAAS,EAAE,2BAA2B,GAAG,IAAI,CAAA;IAElE;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC,CAAA;IAEpF;;;OAGG;IACH,UAAU,IAAI,WAAW,GAAG,SAAS,CAAA;IAErC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAE1C;;;;OAIG;IACH,2BAA2B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAEjE;;;OAGG;IACH,sBAAsB,IAAI,OAAO,CAAA;CAClC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "5.18.1";
1
+ export declare const version = "5.20.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  version: ()=>version
28
28
  });
29
- const version = '5.18.1';
29
+ const version = '5.20.0';
30
30
  exports.version = __webpack_exports__.version;
31
31
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
32
32
  "version"
package/dist/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const version = '5.18.1';
1
+ const version = '5.20.0';
2
2
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "5.18.1",
3
+ "version": "5.20.0",
4
4
  "description": "PostHog Node.js integration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "module": "dist/entrypoints/index.node.mjs",
26
26
  "types": "dist/entrypoints/index.node.d.ts",
27
27
  "dependencies": {
28
- "@posthog/core": "1.9.0"
28
+ "@posthog/core": "1.9.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@rslib/core": "0.10.6",
package/src/client.ts CHANGED
@@ -16,9 +16,11 @@ import {
16
16
  EventMessage,
17
17
  FeatureFlagError,
18
18
  FeatureFlagErrorType,
19
+ FeatureFlagOverrideOptions,
19
20
  GroupIdentifyMessage,
20
21
  IdentifyMessage,
21
22
  IPostHog,
23
+ OverrideFeatureFlagsOptions,
22
24
  PostHogOptions,
23
25
  SendFeatureFlagsOptions,
24
26
  } from './types'
@@ -50,6 +52,10 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
50
52
  public readonly options: PostHogOptions
51
53
  protected readonly context?: IPostHogContext
52
54
 
55
+ // Feature flag overrides for local testing/development
56
+ private _flagOverrides?: Record<string, FeatureFlagValue>
57
+ private _payloadOverrides?: Record<string, JsonType>
58
+
53
59
  distinctIdHasSentFlagCalls: Record<string, string[]>
54
60
 
55
61
  /**
@@ -645,6 +651,11 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
645
651
  disableGeoip?: boolean
646
652
  }
647
653
  ): Promise<FeatureFlagValue | undefined> {
654
+ // Check for overrides first - they take precedence over all evaluation
655
+ if (this._flagOverrides !== undefined && key in this._flagOverrides) {
656
+ return this._flagOverrides[key]
657
+ }
658
+
648
659
  const { groups, disableGeoip } = options || {}
649
660
  let { onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties } = options || {}
650
661
 
@@ -815,6 +826,11 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
815
826
  disableGeoip?: boolean
816
827
  }
817
828
  ): Promise<JsonType | undefined> {
829
+ // Check for payload overrides first - they take precedence over all evaluation
830
+ if (this._payloadOverrides !== undefined && key in this._payloadOverrides) {
831
+ return this._payloadOverrides[key]
832
+ }
833
+
818
834
  const { groups, disableGeoip } = options || {}
819
835
  let { onlyEvaluateLocally, personProperties, groupProperties } = options || {}
820
836
 
@@ -1123,6 +1139,20 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
1123
1139
  }
1124
1140
  }
1125
1141
 
1142
+ // Apply overrides last - they take precedence over all evaluation
1143
+ if (this._flagOverrides !== undefined) {
1144
+ featureFlags = {
1145
+ ...featureFlags,
1146
+ ...this._flagOverrides,
1147
+ }
1148
+ }
1149
+ if (this._payloadOverrides !== undefined) {
1150
+ featureFlagPayloads = {
1151
+ ...featureFlagPayloads,
1152
+ ...this._payloadOverrides,
1153
+ }
1154
+ }
1155
+
1126
1156
  return { featureFlags, featureFlagPayloads }
1127
1157
  }
1128
1158
 
@@ -1190,6 +1220,116 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
1190
1220
  await this.featureFlagsPoller?.loadFeatureFlags(true)
1191
1221
  }
1192
1222
 
1223
+ /**
1224
+ * Override feature flags locally. Useful for testing and local development.
1225
+ * Overridden flags take precedence over both local evaluation and remote evaluation.
1226
+ *
1227
+ * @example
1228
+ * ```ts
1229
+ * // Clear all overrides
1230
+ * client.overrideFeatureFlags(false)
1231
+ *
1232
+ * // Enable a list of flags (sets them to true)
1233
+ * client.overrideFeatureFlags(['flag-a', 'flag-b'])
1234
+ *
1235
+ * // Set specific flag values/variants
1236
+ * client.overrideFeatureFlags({ 'my-flag': 'variant-a', 'other-flag': true })
1237
+ *
1238
+ * // Set both flags and payloads
1239
+ * client.overrideFeatureFlags({
1240
+ * flags: { 'my-flag': 'variant-a' },
1241
+ * payloads: { 'my-flag': { discount: 20 } }
1242
+ * })
1243
+ * ```
1244
+ *
1245
+ * {@label Feature flags}
1246
+ *
1247
+ * @param overrides - Flag overrides configuration
1248
+ */
1249
+ overrideFeatureFlags(overrides: OverrideFeatureFlagsOptions): void {
1250
+ const flagArrayToRecord = (flags: string[]) => Object.fromEntries(flags.map((f) => [f, true]))
1251
+
1252
+ if (overrides === false) {
1253
+ this._flagOverrides = undefined
1254
+ this._payloadOverrides = undefined
1255
+ return
1256
+ }
1257
+
1258
+ // Array syntax: ['flag-a', 'flag-b'] -> { 'flag-a': true, 'flag-b': true }
1259
+ if (Array.isArray(overrides)) {
1260
+ this._flagOverrides = flagArrayToRecord(overrides)
1261
+ return
1262
+ }
1263
+
1264
+ if (this._isFeatureFlagOverrideOptions(overrides)) {
1265
+ if ('flags' in overrides) {
1266
+ if (overrides.flags === false) {
1267
+ this._flagOverrides = undefined
1268
+ } else if (Array.isArray(overrides.flags)) {
1269
+ this._flagOverrides = flagArrayToRecord(overrides.flags)
1270
+ } else if (overrides.flags !== undefined) {
1271
+ this._flagOverrides = { ...overrides.flags }
1272
+ }
1273
+ }
1274
+
1275
+ if ('payloads' in overrides) {
1276
+ if (overrides.payloads === false) {
1277
+ this._payloadOverrides = undefined
1278
+ } else if (overrides.payloads !== undefined) {
1279
+ this._payloadOverrides = { ...overrides.payloads }
1280
+ }
1281
+ }
1282
+
1283
+ return
1284
+ }
1285
+
1286
+ // Fallback: treat as Record<string, FeatureFlagValue>
1287
+ this._flagOverrides = { ...overrides }
1288
+ }
1289
+
1290
+ /**
1291
+ * Type guard to check if overrides is a FeatureFlagOverrideOptions object.
1292
+ *
1293
+ * This distinguishes between:
1294
+ * - { flags: { 'flag-a': true } } -> FeatureFlagOverrideOptions (flags is an object/array/false)
1295
+ * - { flags: true } -> Record<string, FeatureFlagValue> (a flag named "flags" with value true)
1296
+ */
1297
+ private _isFeatureFlagOverrideOptions(overrides: unknown): overrides is FeatureFlagOverrideOptions {
1298
+ if (typeof overrides !== 'object' || overrides === null || Array.isArray(overrides)) {
1299
+ return false
1300
+ }
1301
+
1302
+ const obj = overrides as Record<string, unknown>
1303
+
1304
+ // Check if 'flags' key exists and has a valid structure for FeatureFlagOverrideOptions
1305
+ // Valid values: false, string[], or Record<string, FeatureFlagValue> (an object)
1306
+ if ('flags' in obj) {
1307
+ const flagsValue = obj['flags']
1308
+ // If flags is false, an array, or a plain object - it's FeatureFlagOverrideOptions
1309
+ // If flags is a boolean true or a string - it's a flag named "flags" with that value
1310
+ if (
1311
+ flagsValue === false ||
1312
+ Array.isArray(flagsValue) ||
1313
+ (typeof flagsValue === 'object' && flagsValue !== null)
1314
+ ) {
1315
+ return true
1316
+ }
1317
+ }
1318
+
1319
+ // Check if 'payloads' key exists and has a valid structure for FeatureFlagOverrideOptions
1320
+ // Valid values: false or Record<string, JsonType> (an object)
1321
+ if ('payloads' in obj) {
1322
+ const payloadsValue = obj['payloads']
1323
+ // If payloads is false or a plain object - it's FeatureFlagOverrideOptions
1324
+ // If payloads is a string or boolean true - it's a flag named "payloads" with that value
1325
+ if (payloadsValue === false || (typeof payloadsValue === 'object' && payloadsValue !== null)) {
1326
+ return true
1327
+ }
1328
+ }
1329
+
1330
+ return false
1331
+ }
1332
+
1193
1333
  protected abstract initializeContext(): IPostHogContext | undefined
1194
1334
 
1195
1335
  /**
@@ -1455,13 +1595,20 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
1455
1595
  * @param distinctId - Optional user distinct ID
1456
1596
  * @param additionalProperties - Optional additional properties to include
1457
1597
  */
1458
- captureException(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>): void {
1459
- const syntheticException = new Error('PostHog syntheticException')
1460
- this.addPendingPromise(
1461
- ErrorTracking.buildEventMessage(error, { syntheticException }, distinctId, additionalProperties).then((msg) =>
1462
- this.capture(msg)
1598
+ captureException(
1599
+ error: unknown,
1600
+ distinctId?: string,
1601
+ additionalProperties?: Record<string | number, any>,
1602
+ uuid?: EventMessage['uuid']
1603
+ ): void {
1604
+ if (!ErrorTracking.isPreviouslyCapturedError(error)) {
1605
+ const syntheticException = new Error('PostHog syntheticException')
1606
+ this.addPendingPromise(
1607
+ ErrorTracking.buildEventMessage(error, { syntheticException }, distinctId, additionalProperties).then((msg) =>
1608
+ this.capture({ ...msg, uuid })
1609
+ )
1463
1610
  )
1464
- )
1611
+ }
1465
1612
  }
1466
1613
 
1467
1614
  /**
@@ -1504,12 +1651,14 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
1504
1651
  distinctId?: string,
1505
1652
  additionalProperties?: Record<string | number, any>
1506
1653
  ): Promise<void> {
1507
- const syntheticException = new Error('PostHog syntheticException')
1508
- this.addPendingPromise(
1509
- ErrorTracking.buildEventMessage(error, { syntheticException }, distinctId, additionalProperties).then((msg) =>
1510
- this.captureImmediate(msg)
1654
+ if (!ErrorTracking.isPreviouslyCapturedError(error)) {
1655
+ const syntheticException = new Error('PostHog syntheticException')
1656
+ this.addPendingPromise(
1657
+ ErrorTracking.buildEventMessage(error, { syntheticException }, distinctId, additionalProperties).then((msg) =>
1658
+ this.captureImmediate(msg)
1659
+ )
1511
1660
  )
1512
- )
1661
+ }
1513
1662
  }
1514
1663
 
1515
1664
  public async prepareEventMessage(props: EventMessage): Promise<{
@@ -1,6 +1,6 @@
1
1
  import { addUncaughtExceptionListener, addUnhandledRejectionListener } from './autocapture'
2
2
  import { PostHogBackendClient } from '@/client'
3
- import { uuidv7 } from '@posthog/core'
3
+ import { isObject, uuidv7 } from '@posthog/core'
4
4
  import { EventMessage, PostHogOptions } from '@/types'
5
5
  import type { Logger } from '@posthog/core'
6
6
  import { BucketedRateLimiter } from '@posthog/core'
@@ -34,6 +34,10 @@ export default class ErrorTracking {
34
34
  this.startAutocaptureIfEnabled()
35
35
  }
36
36
 
37
+ static isPreviouslyCapturedError(x: unknown): boolean {
38
+ return isObject(x) && '__posthog_previously_captured_error' in x && x.__posthog_previously_captured_error === true
39
+ }
40
+
37
41
  static async buildEventMessage(
38
42
  error: unknown,
39
43
  hint: CoreErrorTracking.EventHint,
@@ -73,17 +77,19 @@ export default class ErrorTracking {
73
77
  private onException(exception: unknown, hint: CoreErrorTracking.EventHint): void {
74
78
  this.client.addPendingPromise(
75
79
  (async () => {
76
- const eventMessage = await ErrorTracking.buildEventMessage(exception, hint)
77
- const exceptionProperties = eventMessage.properties
78
- const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception'
79
- const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType)
80
- if (isRateLimited) {
81
- this._logger.info('Skipping exception capture because of client rate limiting.', {
82
- exception: exceptionType,
83
- })
84
- return
80
+ if (!ErrorTracking.isPreviouslyCapturedError(exception)) {
81
+ const eventMessage = await ErrorTracking.buildEventMessage(exception, hint)
82
+ const exceptionProperties = eventMessage.properties
83
+ const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? 'Exception'
84
+ const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType)
85
+ if (isRateLimited) {
86
+ this._logger.info('Skipping exception capture because of client rate limiting.', {
87
+ exception: exceptionType,
88
+ })
89
+ return
90
+ }
91
+ return this.client.capture(eventMessage)
85
92
  }
86
- return this.client.capture(eventMessage)
87
93
  })()
88
94
  )
89
95
  }
@@ -32,6 +32,11 @@ export function setupExpressErrorHandler(
32
32
 
33
33
  function posthogErrorHandler(posthog: PostHogBackendClient): ExpressErrorMiddleware {
34
34
  return (error: MiddlewareError, req, res, next: (error: MiddlewareError) => void): void => {
35
+ if (ErrorTracking.isPreviouslyCapturedError(error)) {
36
+ next(error)
37
+ return
38
+ }
39
+
35
40
  const sessionId: string | undefined = req.headers['x-posthog-session-id'] as string | undefined
36
41
  const distinctId: string | undefined = req.headers['x-posthog-distinct-id'] as string | undefined
37
42
  const syntheticException = new Error('Synthetic exception')
package/src/types.ts CHANGED
@@ -55,6 +55,37 @@ export type FlagProperty = {
55
55
 
56
56
  export type FlagPropertyValue = string | number | (string | number)[] | boolean
57
57
 
58
+ /**
59
+ * Options for overriding feature flags.
60
+ *
61
+ * Supports multiple formats:
62
+ * - `false` - Clear all overrides
63
+ * - `string[]` - Enable a list of flags (sets them to `true`)
64
+ * - `Record<string, FeatureFlagValue>` - Set specific flag values/variants
65
+ * - `FeatureFlagOverrideOptions` - Set both flag values and payloads
66
+ */
67
+ export type OverrideFeatureFlagsOptions =
68
+ | false
69
+ | string[]
70
+ | Record<string, FeatureFlagValue>
71
+ | FeatureFlagOverrideOptions
72
+
73
+ export type FeatureFlagOverrideOptions = {
74
+ /**
75
+ * Flag overrides. Can be:
76
+ * - `false` to clear flag overrides
77
+ * - `string[]` to enable a list of flags
78
+ * - `Record<string, FeatureFlagValue>` to set specific values/variants
79
+ */
80
+ flags?: false | string[] | Record<string, FeatureFlagValue>
81
+ /**
82
+ * Payload overrides for flags.
83
+ * - `false` to clear payload overrides
84
+ * - `Record<string, JsonType>` to set specific payloads
85
+ */
86
+ payloads?: false | Record<string, JsonType>
87
+ }
88
+
58
89
  export type FeatureFlagCondition = {
59
90
  properties: FlagProperty[]
60
91
  rollout_percentage?: number
@@ -359,6 +390,32 @@ export interface IPostHog {
359
390
  */
360
391
  reloadFeatureFlags(): Promise<void>
361
392
 
393
+ /**
394
+ * @description Override feature flags locally. Useful for testing and local development.
395
+ * Overridden flags take precedence over both local evaluation and remote evaluation.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * // Clear all overrides
400
+ * posthog.overrideFeatureFlags(false)
401
+ *
402
+ * // Enable a list of flags (sets them to true)
403
+ * posthog.overrideFeatureFlags(['flag-a', 'flag-b'])
404
+ *
405
+ * // Set specific flag values/variants
406
+ * posthog.overrideFeatureFlags({ 'my-flag': 'variant-a', 'other-flag': true })
407
+ *
408
+ * // Set both flags and payloads
409
+ * posthog.overrideFeatureFlags({
410
+ * flags: { 'my-flag': 'variant-a' },
411
+ * payloads: { 'my-flag': { discount: 20 } }
412
+ * })
413
+ * ```
414
+ *
415
+ * @param overrides - Flag overrides configuration
416
+ */
417
+ overrideFeatureFlags(overrides: OverrideFeatureFlagsOptions): void
418
+
362
419
  /**
363
420
  * @description Run a function with specific context that will be applied to all events captured within that context.
364
421
  * @param data Context data to apply (sessionId, distinctId, properties, enableExceptionAutocapture)
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.18.1'
1
+ export const version = '5.20.0'