posthog-node 4.10.2 → 4.11.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
@@ -245,7 +245,7 @@ type PostHogCoreOptions = {
245
245
  bootstrap?: {
246
246
  distinctId?: string;
247
247
  isIdentifiedId?: boolean;
248
- featureFlags?: Record<string, boolean | string>;
248
+ featureFlags?: Record<string, FeatureFlagValue>;
249
249
  featureFlagPayloads?: Record<string, JsonType>;
250
250
  };
251
251
  /** How many times we will retry HTTP requests. Defaults to 3. */
@@ -270,8 +270,10 @@ declare enum PostHogPersistedProperty {
270
270
  AnonymousId = "anonymous_id",
271
271
  DistinctId = "distinct_id",
272
272
  Props = "props",
273
+ FeatureFlagDetails = "feature_flag_details",
273
274
  FeatureFlags = "feature_flags",
274
275
  FeatureFlagPayloads = "feature_flag_payloads",
276
+ BootstrapFeatureFlagDetails = "bootstrap_feature_flag_details",
275
277
  BootstrapFeatureFlags = "bootstrap_feature_flags",
276
278
  BootstrapFeatureFlagPayloads = "bootstrap_feature_flag_payloads",
277
279
  OverrideFeatureFlags = "override_feature_flags",
@@ -328,13 +330,17 @@ interface PostHogRemoteConfig {
328
330
  */
329
331
  hasFeatureFlags?: boolean;
330
332
  }
333
+ type FeatureFlagValue = string | boolean;
331
334
  interface PostHogDecideResponse extends Omit<PostHogRemoteConfig, 'surveys' | 'hasFeatureFlags'> {
332
335
  featureFlags: {
333
- [key: string]: string | boolean;
336
+ [key: string]: FeatureFlagValue;
334
337
  };
335
338
  featureFlagPayloads: {
336
339
  [key: string]: JsonType;
337
340
  };
341
+ flags: {
342
+ [key: string]: FeatureFlagDetail;
343
+ };
338
344
  errorsWhileComputingFlags: boolean;
339
345
  sessionRecording?: boolean | {
340
346
  [key: string]: JsonType;
@@ -342,13 +348,63 @@ interface PostHogDecideResponse extends Omit<PostHogRemoteConfig, 'surveys' | 'h
342
348
  quotaLimited?: string[];
343
349
  requestId?: string;
344
350
  }
345
- type PostHogFlagsAndPayloadsResponse = {
346
- featureFlags: PostHogDecideResponse['featureFlags'];
347
- featureFlagPayloads: PostHogDecideResponse['featureFlagPayloads'];
351
+ /**
352
+ * Creates a type with all properties of T, but makes only K properties required while the rest remain optional.
353
+ *
354
+ * @template T - The base type containing all properties
355
+ * @template K - Union type of keys from T that should be required
356
+ *
357
+ * @example
358
+ * interface User {
359
+ * id: number;
360
+ * name: string;
361
+ * email?: string;
362
+ * age?: number;
363
+ * }
364
+ *
365
+ * // Makes 'id' and 'name' required, but 'email' and 'age' optional
366
+ * type RequiredUser = PartialWithRequired<User, 'id' | 'name'>;
367
+ *
368
+ * const user: RequiredUser = {
369
+ * id: 1, // Must be provided
370
+ * name: "John" // Must be provided
371
+ * // email and age are optional
372
+ * };
373
+ */
374
+ type PartialWithRequired<T, K extends keyof T> = {
375
+ [P in K]: T[P];
376
+ } & {
377
+ [P in Exclude<keyof T, K>]?: T[P];
348
378
  };
379
+ /**
380
+ * These are the fields we care about from PostHogDecideResponse for feature flags.
381
+ */
382
+ type PostHogFeatureFlagDetails = PartialWithRequired<PostHogDecideResponse, 'flags' | 'featureFlags' | 'featureFlagPayloads' | 'requestId'>;
383
+ /**
384
+ * Models legacy flags and payloads return type for many public methods.
385
+ */
386
+ type PostHogFlagsAndPayloadsResponse = Partial<Pick<PostHogDecideResponse, 'featureFlags' | 'featureFlagPayloads'>>;
349
387
  type JsonType = string | number | boolean | null | {
350
388
  [key: string]: JsonType;
351
- } | Array<JsonType>;
389
+ } | Array<JsonType>;
390
+ type FeatureFlagDetail = {
391
+ key: string;
392
+ enabled: boolean;
393
+ variant: string | undefined;
394
+ reason: EvaluationReason | undefined;
395
+ metadata: FeatureFlagMetadata | undefined;
396
+ };
397
+ type FeatureFlagMetadata = {
398
+ id: number | undefined;
399
+ version: number | undefined;
400
+ description: string | undefined;
401
+ payload: string | undefined;
402
+ };
403
+ type EvaluationReason = {
404
+ code: string | undefined;
405
+ condition_index: number | undefined;
406
+ description: string | undefined;
407
+ };
352
408
 
353
409
  interface RetriableOptions {
354
410
  retryCount: number;
@@ -430,12 +486,15 @@ declare abstract class PostHogCoreStateless {
430
486
  ***/
431
487
  protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>;
432
488
  protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
433
- response: boolean | string | undefined;
489
+ response: FeatureFlagValue | undefined;
434
490
  requestId: string | undefined;
435
491
  }>;
492
+ protected getFeatureFlagDetailStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
493
+ response: FeatureFlagDetail | undefined;
494
+ requestId: string | undefined;
495
+ } | undefined>;
436
496
  protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>;
437
497
  protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
438
- protected _parsePayload(response: any): any;
439
498
  protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<{
440
499
  flags: PostHogDecideResponse['featureFlags'] | undefined;
441
500
  payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
@@ -446,6 +505,7 @@ declare abstract class PostHogCoreStateless {
446
505
  payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
447
506
  requestId: PostHogDecideResponse['requestId'] | undefined;
448
507
  }>;
508
+ protected getFeatureFlagDetailsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogFeatureFlagDetails | undefined>;
449
509
  /***
450
510
  *** SURVEYS
451
511
  ***/
@@ -569,7 +629,7 @@ type PostHogNodeV1 = {
569
629
  groupProperties?: Record<string, Record<string, string>>;
570
630
  onlyEvaluateLocally?: boolean;
571
631
  sendFeatureFlagEvents?: boolean;
572
- }): Promise<string | boolean | undefined>;
632
+ }): Promise<FeatureFlagValue | undefined>;
573
633
  /**
574
634
  * @description Retrieves payload associated with the specified flag and matched value that is passed in.
575
635
  *
@@ -596,7 +656,7 @@ type PostHogNodeV1 = {
596
656
  *
597
657
  * @returns payload of a json type object
598
658
  */
599
- getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: {
659
+ getFeatureFlagPayload(key: string, distinctId: string, matchValue?: FeatureFlagValue, options?: {
600
660
  onlyEvaluateLocally?: boolean;
601
661
  }): Promise<JsonType | undefined>;
602
662
  /**
@@ -687,8 +747,8 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
687
747
  onlyEvaluateLocally?: boolean;
688
748
  sendFeatureFlagEvents?: boolean;
689
749
  disableGeoip?: boolean;
690
- }): Promise<string | boolean | undefined>;
691
- getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: {
750
+ }): Promise<FeatureFlagValue | undefined>;
751
+ getFeatureFlagPayload(key: string, distinctId: string, matchValue?: FeatureFlagValue, options?: {
692
752
  groups?: Record<string, string>;
693
753
  personProperties?: Record<string, string>;
694
754
  groupProperties?: Record<string, Record<string, string>>;
@@ -711,7 +771,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
711
771
  groupProperties?: Record<string, Record<string, string>>;
712
772
  onlyEvaluateLocally?: boolean;
713
773
  disableGeoip?: boolean;
714
- }): Promise<Record<string, string | boolean>>;
774
+ }): Promise<Record<string, FeatureFlagValue>>;
715
775
  getAllFlagsAndPayloads(distinctId: string, options?: {
716
776
  groups?: Record<string, string>;
717
777
  personProperties?: Record<string, string>;