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/CHANGELOG.md +16 -2
- package/lib/index.cjs.js +293 -64
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +73 -13
- package/lib/index.esm.js +275 -64
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/featureFlagUtils.d.ts +34 -0
- package/lib/posthog-core/src/index.d.ts +18 -7
- package/lib/posthog-core/src/types.d.ts +74 -6
- package/lib/posthog-node/src/crypto-helpers.d.ts +3 -0
- package/lib/posthog-node/src/crypto.d.ts +2 -0
- package/lib/posthog-node/src/feature-flags.d.ts +8 -8
- package/lib/posthog-node/src/lazy.d.ts +23 -0
- package/lib/posthog-node/src/posthog-node.d.ts +4 -3
- package/lib/posthog-node/src/types.d.ts +3 -3
- package/lib/posthog-node/test/test-utils.d.ts +7 -0
- package/package.json +1 -1
- package/src/crypto-helpers.ts +36 -0
- package/src/crypto.ts +22 -0
- package/src/feature-flags.ts +42 -41
- package/src/lazy.ts +55 -0
- package/src/posthog-node.ts +36 -17
- package/src/types.ts +3 -3
- package/test/crypto.spec.ts +36 -0
- package/test/feature-flags.decide.spec.ts +380 -0
- package/test/feature-flags.spec.ts +3 -45
- package/test/lazy.spec.ts +71 -0
- package/test/posthog-node.spec.ts +19 -19
- package/test/test-utils.ts +36 -1
- package/benchmarks/rusha-vs-native.mjs +0 -70
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,
|
|
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]:
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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:
|
|
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<
|
|
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?:
|
|
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<
|
|
691
|
-
getFeatureFlagPayload(key: string, distinctId: string, matchValue?:
|
|
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,
|
|
774
|
+
}): Promise<Record<string, FeatureFlagValue>>;
|
|
715
775
|
getAllFlagsAndPayloads(distinctId: string, options?: {
|
|
716
776
|
groups?: Record<string, string>;
|
|
717
777
|
personProperties?: Record<string, string>;
|