posthog-node 5.8.1 → 5.8.2
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/edge/index.cjs +693 -8
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.mjs +693 -8
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.ts +692 -2
- package/dist/node/index.cjs +693 -8
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +693 -8
- package/dist/node/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -311,31 +311,427 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
|
|
|
311
311
|
private logger;
|
|
312
312
|
readonly options: PostHogOptions;
|
|
313
313
|
distinctIdHasSentFlagCalls: Record<string, string[]>;
|
|
314
|
+
/**
|
|
315
|
+
* Initialize a new PostHog client instance.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* // Basic initialization
|
|
320
|
+
* const client = new PostHogBackendClient(
|
|
321
|
+
* 'your-api-key',
|
|
322
|
+
* { host: 'https://app.posthog.com' }
|
|
323
|
+
* )
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* // With personal API key
|
|
329
|
+
* const client = new PostHogBackendClient(
|
|
330
|
+
* 'your-api-key',
|
|
331
|
+
* {
|
|
332
|
+
* host: 'https://app.posthog.com',
|
|
333
|
+
* personalApiKey: 'your-personal-api-key'
|
|
334
|
+
* }
|
|
335
|
+
* )
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* {@label Initialization}
|
|
339
|
+
*
|
|
340
|
+
* @param apiKey - Your PostHog project API key
|
|
341
|
+
* @param options - Configuration options for the client
|
|
342
|
+
*/
|
|
314
343
|
constructor(apiKey: string, options?: PostHogOptions);
|
|
344
|
+
/**
|
|
345
|
+
* Get a persisted property value from memory storage.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* // Get user ID
|
|
350
|
+
* const userId = client.getPersistedProperty('userId')
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* // Get session ID
|
|
356
|
+
* const sessionId = client.getPersistedProperty('sessionId')
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* {@label Initialization}
|
|
360
|
+
*
|
|
361
|
+
* @param key - The property key to retrieve
|
|
362
|
+
* @returns The stored property value or undefined if not found
|
|
363
|
+
*/
|
|
315
364
|
getPersistedProperty(key: PostHogPersistedProperty): any | undefined;
|
|
365
|
+
/**
|
|
366
|
+
* Set a persisted property value in memory storage.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* // Set user ID
|
|
371
|
+
* client.setPersistedProperty('userId', 'user_123')
|
|
372
|
+
* ```
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* // Set session ID
|
|
377
|
+
* client.setPersistedProperty('sessionId', 'session_456')
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* {@label Initialization}
|
|
381
|
+
*
|
|
382
|
+
* @param key - The property key to set
|
|
383
|
+
* @param value - The value to store (null to remove)
|
|
384
|
+
*/
|
|
316
385
|
setPersistedProperty(key: PostHogPersistedProperty, value: any | null): void;
|
|
386
|
+
/**
|
|
387
|
+
* Make an HTTP request using the configured fetch function or default fetch.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* // POST request
|
|
392
|
+
* const response = await client.fetch('/api/endpoint', {
|
|
393
|
+
* method: 'POST',
|
|
394
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
395
|
+
* body: JSON.stringify(data)
|
|
396
|
+
* })
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* @internal
|
|
400
|
+
*
|
|
401
|
+
* {@label Initialization}
|
|
402
|
+
*
|
|
403
|
+
* @param url - The URL to fetch
|
|
404
|
+
* @param options - Fetch options
|
|
405
|
+
* @returns Promise resolving to the fetch response
|
|
406
|
+
*/
|
|
317
407
|
fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
408
|
+
/**
|
|
409
|
+
* Get the library version from package.json.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* // Get version
|
|
414
|
+
* const version = client.getLibraryVersion()
|
|
415
|
+
* console.log(`Using PostHog SDK version: ${version}`)
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* {@label Initialization}
|
|
419
|
+
*
|
|
420
|
+
* @returns The current library version string
|
|
421
|
+
*/
|
|
318
422
|
getLibraryVersion(): string;
|
|
423
|
+
/**
|
|
424
|
+
* Get the custom user agent string for this client.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* // Get user agent
|
|
429
|
+
* const userAgent = client.getCustomUserAgent()
|
|
430
|
+
* // Returns: "posthog-node/5.7.0"
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* {@label Identification}
|
|
434
|
+
*
|
|
435
|
+
* @returns The formatted user agent string
|
|
436
|
+
*/
|
|
319
437
|
getCustomUserAgent(): string;
|
|
438
|
+
/**
|
|
439
|
+
* Enable the PostHog client (opt-in).
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* // Enable client
|
|
444
|
+
* await client.enable()
|
|
445
|
+
* // Client is now enabled and will capture events
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* {@label Privacy}
|
|
449
|
+
*
|
|
450
|
+
* @returns Promise that resolves when the client is enabled
|
|
451
|
+
*/
|
|
320
452
|
enable(): Promise<void>;
|
|
453
|
+
/**
|
|
454
|
+
* Disable the PostHog client (opt-out).
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* // Disable client
|
|
459
|
+
* await client.disable()
|
|
460
|
+
* // Client is now disabled and will not capture events
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* {@label Privacy}
|
|
464
|
+
*
|
|
465
|
+
* @returns Promise that resolves when the client is disabled
|
|
466
|
+
*/
|
|
321
467
|
disable(): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Enable or disable debug logging.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* // Enable debug logging
|
|
474
|
+
* client.debug(true)
|
|
475
|
+
* ```
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* // Disable debug logging
|
|
480
|
+
* client.debug(false)
|
|
481
|
+
* ```
|
|
482
|
+
*
|
|
483
|
+
* {@label Initialization}
|
|
484
|
+
*
|
|
485
|
+
* @param enabled - Whether to enable debug logging
|
|
486
|
+
*/
|
|
322
487
|
debug(enabled?: boolean): void;
|
|
488
|
+
/**
|
|
489
|
+
* Capture an event manually.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* // Basic capture
|
|
494
|
+
* client.capture({
|
|
495
|
+
* distinctId: 'user_123',
|
|
496
|
+
* event: 'button_clicked',
|
|
497
|
+
* properties: { button_color: 'red' }
|
|
498
|
+
* })
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* {@label Capture}
|
|
502
|
+
*
|
|
503
|
+
* @param props - The event properties
|
|
504
|
+
* @returns void
|
|
505
|
+
*/
|
|
323
506
|
capture(props: EventMessage): void;
|
|
507
|
+
/**
|
|
508
|
+
* Capture an event immediately (synchronously).
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* // Basic immediate capture
|
|
513
|
+
* await client.captureImmediate({
|
|
514
|
+
* distinctId: 'user_123',
|
|
515
|
+
* event: 'button_clicked',
|
|
516
|
+
* properties: { button_color: 'red' }
|
|
517
|
+
* })
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* // With feature flags
|
|
523
|
+
* await client.captureImmediate({
|
|
524
|
+
* distinctId: 'user_123',
|
|
525
|
+
* event: 'user_action',
|
|
526
|
+
* sendFeatureFlags: true
|
|
527
|
+
* })
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```ts
|
|
532
|
+
* // With custom feature flags options
|
|
533
|
+
* await client.captureImmediate({
|
|
534
|
+
* distinctId: 'user_123',
|
|
535
|
+
* event: 'user_action',
|
|
536
|
+
* sendFeatureFlags: {
|
|
537
|
+
* onlyEvaluateLocally: true,
|
|
538
|
+
* personProperties: { plan: 'premium' },
|
|
539
|
+
* groupProperties: { org: { tier: 'enterprise' } }
|
|
540
|
+
* flagKeys: ['flag1', 'flag2']
|
|
541
|
+
* }
|
|
542
|
+
* })
|
|
543
|
+
* ```
|
|
544
|
+
*
|
|
545
|
+
* {@label Capture}
|
|
546
|
+
*
|
|
547
|
+
* @param props - The event properties
|
|
548
|
+
* @returns Promise that resolves when the event is captured
|
|
549
|
+
*/
|
|
324
550
|
captureImmediate(props: EventMessage): Promise<void>;
|
|
551
|
+
/**
|
|
552
|
+
* Identify a user and set their properties.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```ts
|
|
556
|
+
* // Basic identify with properties
|
|
557
|
+
* client.identify({
|
|
558
|
+
* distinctId: 'user_123',
|
|
559
|
+
* properties: {
|
|
560
|
+
* name: 'John Doe',
|
|
561
|
+
* email: 'john@example.com',
|
|
562
|
+
* plan: 'premium'
|
|
563
|
+
* }
|
|
564
|
+
* })
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts
|
|
569
|
+
* // Using $set and $set_once
|
|
570
|
+
* client.identify({
|
|
571
|
+
* distinctId: 'user_123',
|
|
572
|
+
* properties: {
|
|
573
|
+
* $set: { name: 'John Doe', email: 'john@example.com' },
|
|
574
|
+
* $set_once: { first_login: new Date().toISOString() }
|
|
575
|
+
* }
|
|
576
|
+
* })
|
|
577
|
+
* ```
|
|
578
|
+
*
|
|
579
|
+
* {@label Identification}
|
|
580
|
+
*
|
|
581
|
+
* @param data - The identify data containing distinctId and properties
|
|
582
|
+
*/
|
|
325
583
|
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
|
|
584
|
+
/**
|
|
585
|
+
* Identify a user and set their properties immediately (synchronously).
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* // Basic immediate identify
|
|
590
|
+
* await client.identifyImmediate({
|
|
591
|
+
* distinctId: 'user_123',
|
|
592
|
+
* properties: {
|
|
593
|
+
* name: 'John Doe',
|
|
594
|
+
* email: 'john@example.com'
|
|
595
|
+
* }
|
|
596
|
+
* })
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* {@label Identification}
|
|
600
|
+
*
|
|
601
|
+
* @param data - The identify data containing distinctId and properties
|
|
602
|
+
* @returns Promise that resolves when the identify is processed
|
|
603
|
+
*/
|
|
326
604
|
identifyImmediate({ distinctId, properties, disableGeoip }: IdentifyMessage): Promise<void>;
|
|
605
|
+
/**
|
|
606
|
+
* Create an alias to link two distinct IDs together.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* // Link an anonymous user to an identified user
|
|
611
|
+
* client.alias({
|
|
612
|
+
* distinctId: 'anonymous_123',
|
|
613
|
+
* alias: 'user_456'
|
|
614
|
+
* })
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* {@label Identification}
|
|
618
|
+
*
|
|
619
|
+
* @param data - The alias data containing distinctId and alias
|
|
620
|
+
*/
|
|
327
621
|
alias(data: {
|
|
328
622
|
distinctId: string;
|
|
329
623
|
alias: string;
|
|
330
624
|
disableGeoip?: boolean;
|
|
331
625
|
}): void;
|
|
626
|
+
/**
|
|
627
|
+
* Create an alias to link two distinct IDs together immediately (synchronously).
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```ts
|
|
631
|
+
* // Link an anonymous user to an identified user immediately
|
|
632
|
+
* await client.aliasImmediate({
|
|
633
|
+
* distinctId: 'anonymous_123',
|
|
634
|
+
* alias: 'user_456'
|
|
635
|
+
* })
|
|
636
|
+
* ```
|
|
637
|
+
*
|
|
638
|
+
* {@label Identification}
|
|
639
|
+
*
|
|
640
|
+
* @param data - The alias data containing distinctId and alias
|
|
641
|
+
* @returns Promise that resolves when the alias is processed
|
|
642
|
+
*/
|
|
332
643
|
aliasImmediate(data: {
|
|
333
644
|
distinctId: string;
|
|
334
645
|
alias: string;
|
|
335
646
|
disableGeoip?: boolean;
|
|
336
647
|
}): Promise<void>;
|
|
648
|
+
/**
|
|
649
|
+
* Check if local evaluation of feature flags is ready.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```ts
|
|
653
|
+
* // Check if ready
|
|
654
|
+
* if (client.isLocalEvaluationReady()) {
|
|
655
|
+
* // Local evaluation is ready, can evaluate flags locally
|
|
656
|
+
* const flag = await client.getFeatureFlag('flag-key', 'user_123')
|
|
657
|
+
* } else {
|
|
658
|
+
* // Local evaluation not ready, will use remote evaluation
|
|
659
|
+
* const flag = await client.getFeatureFlag('flag-key', 'user_123')
|
|
660
|
+
* }
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* {@label Feature flags}
|
|
664
|
+
*
|
|
665
|
+
* @returns true if local evaluation is ready, false otherwise
|
|
666
|
+
*/
|
|
337
667
|
isLocalEvaluationReady(): boolean;
|
|
668
|
+
/**
|
|
669
|
+
* Wait for local evaluation of feature flags to be ready.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* // Wait for local evaluation
|
|
674
|
+
* const isReady = await client.waitForLocalEvaluationReady()
|
|
675
|
+
* if (isReady) {
|
|
676
|
+
* console.log('Local evaluation is ready')
|
|
677
|
+
* } else {
|
|
678
|
+
* console.log('Local evaluation timed out')
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```ts
|
|
684
|
+
* // Wait with custom timeout
|
|
685
|
+
* const isReady = await client.waitForLocalEvaluationReady(10000) // 10 seconds
|
|
686
|
+
* ```
|
|
687
|
+
*
|
|
688
|
+
* {@label Feature flags}
|
|
689
|
+
*
|
|
690
|
+
* @param timeoutMs - Timeout in milliseconds (default: 30000)
|
|
691
|
+
* @returns Promise that resolves to true if ready, false if timed out
|
|
692
|
+
*/
|
|
338
693
|
waitForLocalEvaluationReady(timeoutMs?: number): Promise<boolean>;
|
|
694
|
+
/**
|
|
695
|
+
* Get the value of a feature flag for a specific user.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* // Basic feature flag check
|
|
700
|
+
* const flagValue = await client.getFeatureFlag('new-feature', 'user_123')
|
|
701
|
+
* if (flagValue === 'variant-a') {
|
|
702
|
+
* // Show variant A
|
|
703
|
+
* } else if (flagValue === 'variant-b') {
|
|
704
|
+
* // Show variant B
|
|
705
|
+
* } else {
|
|
706
|
+
* // Flag is disabled or not found
|
|
707
|
+
* }
|
|
708
|
+
* ```
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* ```ts
|
|
712
|
+
* // With groups and properties
|
|
713
|
+
* const flagValue = await client.getFeatureFlag('org-feature', 'user_123', {
|
|
714
|
+
* groups: { organization: 'acme-corp' },
|
|
715
|
+
* personProperties: { plan: 'enterprise' },
|
|
716
|
+
* groupProperties: { organization: { tier: 'premium' } }
|
|
717
|
+
* })
|
|
718
|
+
* ```
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* ```ts
|
|
722
|
+
* // Only evaluate locally
|
|
723
|
+
* const flagValue = await client.getFeatureFlag('local-flag', 'user_123', {
|
|
724
|
+
* onlyEvaluateLocally: true
|
|
725
|
+
* })
|
|
726
|
+
* ```
|
|
727
|
+
*
|
|
728
|
+
* {@label Feature flags}
|
|
729
|
+
*
|
|
730
|
+
* @param key - The feature flag key
|
|
731
|
+
* @param distinctId - The user's distinct ID
|
|
732
|
+
* @param options - Optional configuration for flag evaluation
|
|
733
|
+
* @returns Promise that resolves to the flag value or undefined
|
|
734
|
+
*/
|
|
339
735
|
getFeatureFlag(key: string, distinctId: string, options?: {
|
|
340
736
|
groups?: Record<string, string>;
|
|
341
737
|
personProperties?: Record<string, string>;
|
|
@@ -344,15 +740,101 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
|
|
|
344
740
|
sendFeatureFlagEvents?: boolean;
|
|
345
741
|
disableGeoip?: boolean;
|
|
346
742
|
}): Promise<FeatureFlagValue | undefined>;
|
|
743
|
+
/**
|
|
744
|
+
* Get the payload for a feature flag.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```ts
|
|
748
|
+
* // Get payload for a feature flag
|
|
749
|
+
* const payload = await client.getFeatureFlagPayload('flag-key', 'user_123')
|
|
750
|
+
* if (payload) {
|
|
751
|
+
* console.log('Flag payload:', payload)
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
* @example
|
|
756
|
+
* ```ts
|
|
757
|
+
* // Get payload with specific match value
|
|
758
|
+
* const payload = await client.getFeatureFlagPayload('flag-key', 'user_123', 'variant-a')
|
|
759
|
+
* ```
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* ```ts
|
|
763
|
+
* // With groups and properties
|
|
764
|
+
* const payload = await client.getFeatureFlagPayload('org-flag', 'user_123', undefined, {
|
|
765
|
+
* groups: { organization: 'acme-corp' },
|
|
766
|
+
* personProperties: { plan: 'enterprise' }
|
|
767
|
+
* })
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
770
|
+
* {@label Feature flags}
|
|
771
|
+
*
|
|
772
|
+
* @param key - The feature flag key
|
|
773
|
+
* @param distinctId - The user's distinct ID
|
|
774
|
+
* @param matchValue - Optional match value to get payload for
|
|
775
|
+
* @param options - Optional configuration for flag evaluation
|
|
776
|
+
* @returns Promise that resolves to the flag payload or undefined
|
|
777
|
+
*/
|
|
347
778
|
getFeatureFlagPayload(key: string, distinctId: string, matchValue?: FeatureFlagValue, options?: {
|
|
348
779
|
groups?: Record<string, string>;
|
|
349
780
|
personProperties?: Record<string, string>;
|
|
350
781
|
groupProperties?: Record<string, Record<string, string>>;
|
|
351
782
|
onlyEvaluateLocally?: boolean;
|
|
783
|
+
/** @deprecated THIS OPTION HAS NO EFFECT, kept here for backwards compatibility reasons. */
|
|
352
784
|
sendFeatureFlagEvents?: boolean;
|
|
353
785
|
disableGeoip?: boolean;
|
|
354
786
|
}): Promise<JsonType | undefined>;
|
|
787
|
+
/**
|
|
788
|
+
* Get the remote config payload for a feature flag.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* // Get remote config payload
|
|
793
|
+
* const payload = await client.getRemoteConfigPayload('flag-key')
|
|
794
|
+
* if (payload) {
|
|
795
|
+
* console.log('Remote config payload:', payload)
|
|
796
|
+
* }
|
|
797
|
+
* ```
|
|
798
|
+
*
|
|
799
|
+
* {@label Feature flags}
|
|
800
|
+
*
|
|
801
|
+
* @param flagKey - The feature flag key
|
|
802
|
+
* @returns Promise that resolves to the remote config payload or undefined
|
|
803
|
+
* @throws Error if personal API key is not provided
|
|
804
|
+
*/
|
|
355
805
|
getRemoteConfigPayload(flagKey: string): Promise<JsonType | undefined>;
|
|
806
|
+
/**
|
|
807
|
+
* Check if a feature flag is enabled for a specific user.
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* ```ts
|
|
811
|
+
* // Basic feature flag check
|
|
812
|
+
* const isEnabled = await client.isFeatureEnabled('new-feature', 'user_123')
|
|
813
|
+
* if (isEnabled) {
|
|
814
|
+
* // Feature is enabled
|
|
815
|
+
* console.log('New feature is active')
|
|
816
|
+
* } else {
|
|
817
|
+
* // Feature is disabled
|
|
818
|
+
* console.log('New feature is not active')
|
|
819
|
+
* }
|
|
820
|
+
* ```
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```ts
|
|
824
|
+
* // With groups and properties
|
|
825
|
+
* const isEnabled = await client.isFeatureEnabled('org-feature', 'user_123', {
|
|
826
|
+
* groups: { organization: 'acme-corp' },
|
|
827
|
+
* personProperties: { plan: 'enterprise' }
|
|
828
|
+
* })
|
|
829
|
+
* ```
|
|
830
|
+
*
|
|
831
|
+
* {@label Feature flags}
|
|
832
|
+
*
|
|
833
|
+
* @param key - The feature flag key
|
|
834
|
+
* @param distinctId - The user's distinct ID
|
|
835
|
+
* @param options - Optional configuration for flag evaluation
|
|
836
|
+
* @returns Promise that resolves to true if enabled, false if disabled, undefined if not found
|
|
837
|
+
*/
|
|
356
838
|
isFeatureEnabled(key: string, distinctId: string, options?: {
|
|
357
839
|
groups?: Record<string, string>;
|
|
358
840
|
personProperties?: Record<string, string>;
|
|
@@ -361,6 +843,40 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
|
|
|
361
843
|
sendFeatureFlagEvents?: boolean;
|
|
362
844
|
disableGeoip?: boolean;
|
|
363
845
|
}): Promise<boolean | undefined>;
|
|
846
|
+
/**
|
|
847
|
+
* Get all feature flag values for a specific user.
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```ts
|
|
851
|
+
* // Get all flags for a user
|
|
852
|
+
* const allFlags = await client.getAllFlags('user_123')
|
|
853
|
+
* console.log('User flags:', allFlags)
|
|
854
|
+
* // Output: { 'flag-1': 'variant-a', 'flag-2': false, 'flag-3': 'variant-b' }
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```ts
|
|
859
|
+
* // With specific flag keys
|
|
860
|
+
* const specificFlags = await client.getAllFlags('user_123', {
|
|
861
|
+
* flagKeys: ['flag-1', 'flag-2']
|
|
862
|
+
* })
|
|
863
|
+
* ```
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```ts
|
|
867
|
+
* // With groups and properties
|
|
868
|
+
* const orgFlags = await client.getAllFlags('user_123', {
|
|
869
|
+
* groups: { organization: 'acme-corp' },
|
|
870
|
+
* personProperties: { plan: 'enterprise' }
|
|
871
|
+
* })
|
|
872
|
+
* ```
|
|
873
|
+
*
|
|
874
|
+
* {@label Feature flags}
|
|
875
|
+
*
|
|
876
|
+
* @param distinctId - The user's distinct ID
|
|
877
|
+
* @param options - Optional configuration for flag evaluation
|
|
878
|
+
* @returns Promise that resolves to a record of flag keys and their values
|
|
879
|
+
*/
|
|
364
880
|
getAllFlags(distinctId: string, options?: {
|
|
365
881
|
groups?: Record<string, string>;
|
|
366
882
|
personProperties?: Record<string, string>;
|
|
@@ -369,6 +885,39 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
|
|
|
369
885
|
disableGeoip?: boolean;
|
|
370
886
|
flagKeys?: string[];
|
|
371
887
|
}): Promise<Record<string, FeatureFlagValue>>;
|
|
888
|
+
/**
|
|
889
|
+
* Get all feature flag values and payloads for a specific user.
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```ts
|
|
893
|
+
* // Get all flags and payloads for a user
|
|
894
|
+
* const result = await client.getAllFlagsAndPayloads('user_123')
|
|
895
|
+
* console.log('Flags:', result.featureFlags)
|
|
896
|
+
* console.log('Payloads:', result.featureFlagPayloads)
|
|
897
|
+
* ```
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* ```ts
|
|
901
|
+
* // With specific flag keys
|
|
902
|
+
* const result = await client.getAllFlagsAndPayloads('user_123', {
|
|
903
|
+
* flagKeys: ['flag-1', 'flag-2']
|
|
904
|
+
* })
|
|
905
|
+
* ```
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* ```ts
|
|
909
|
+
* // Only evaluate locally
|
|
910
|
+
* const result = await client.getAllFlagsAndPayloads('user_123', {
|
|
911
|
+
* onlyEvaluateLocally: true
|
|
912
|
+
* })
|
|
913
|
+
* ```
|
|
914
|
+
*
|
|
915
|
+
* {@label Feature flags}
|
|
916
|
+
*
|
|
917
|
+
* @param distinctId - The user's distinct ID
|
|
918
|
+
* @param options - Optional configuration for flag evaluation
|
|
919
|
+
* @returns Promise that resolves to flags and payloads
|
|
920
|
+
*/
|
|
372
921
|
getAllFlagsAndPayloads(distinctId: string, options?: {
|
|
373
922
|
groups?: Record<string, string>;
|
|
374
923
|
personProperties?: Record<string, string>;
|
|
@@ -377,18 +926,159 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
|
|
|
377
926
|
disableGeoip?: boolean;
|
|
378
927
|
flagKeys?: string[];
|
|
379
928
|
}): Promise<PostHogFlagsAndPayloadsResponse>;
|
|
929
|
+
/**
|
|
930
|
+
* Create or update a group and its properties.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* // Create a company group
|
|
935
|
+
* client.groupIdentify({
|
|
936
|
+
* groupType: 'company',
|
|
937
|
+
* groupKey: 'acme-corp',
|
|
938
|
+
* properties: {
|
|
939
|
+
* name: 'Acme Corporation',
|
|
940
|
+
* industry: 'Technology',
|
|
941
|
+
* employee_count: 500
|
|
942
|
+
* },
|
|
943
|
+
* distinctId: 'user_123'
|
|
944
|
+
* })
|
|
945
|
+
* ```
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* // Update organization properties
|
|
950
|
+
* client.groupIdentify({
|
|
951
|
+
* groupType: 'organization',
|
|
952
|
+
* groupKey: 'org-456',
|
|
953
|
+
* properties: {
|
|
954
|
+
* plan: 'enterprise',
|
|
955
|
+
* region: 'US-West'
|
|
956
|
+
* }
|
|
957
|
+
* })
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* {@label Identification}
|
|
961
|
+
*
|
|
962
|
+
* @param data - The group identify data
|
|
963
|
+
*/
|
|
380
964
|
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void;
|
|
381
965
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
966
|
+
* Reload feature flag definitions from the server for local evaluation.
|
|
967
|
+
*
|
|
968
|
+
* @example
|
|
969
|
+
* ```ts
|
|
970
|
+
* // Force reload of feature flags
|
|
971
|
+
* await client.reloadFeatureFlags()
|
|
972
|
+
* console.log('Feature flags reloaded')
|
|
973
|
+
* ```
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* // Reload before checking a specific flag
|
|
978
|
+
* await client.reloadFeatureFlags()
|
|
979
|
+
* const flag = await client.getFeatureFlag('flag-key', 'user_123')
|
|
980
|
+
* ```
|
|
981
|
+
*
|
|
982
|
+
* {@label Feature flags}
|
|
983
|
+
*
|
|
984
|
+
* @returns Promise that resolves when flags are reloaded
|
|
384
985
|
*/
|
|
385
986
|
reloadFeatureFlags(): Promise<void>;
|
|
987
|
+
/**
|
|
988
|
+
* Shutdown the PostHog client gracefully.
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* ```ts
|
|
992
|
+
* // Shutdown with default timeout
|
|
993
|
+
* await client._shutdown()
|
|
994
|
+
* ```
|
|
995
|
+
*
|
|
996
|
+
* @example
|
|
997
|
+
* ```ts
|
|
998
|
+
* // Shutdown with custom timeout
|
|
999
|
+
* await client._shutdown(5000) // 5 seconds
|
|
1000
|
+
* ```
|
|
1001
|
+
*
|
|
1002
|
+
* {@label Shutdown}
|
|
1003
|
+
*
|
|
1004
|
+
* @param shutdownTimeoutMs - Timeout in milliseconds for shutdown
|
|
1005
|
+
* @returns Promise that resolves when shutdown is complete
|
|
1006
|
+
*/
|
|
386
1007
|
_shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
387
1008
|
private _requestRemoteConfigPayload;
|
|
388
1009
|
private extractPropertiesFromEvent;
|
|
389
1010
|
private getFeatureFlagsForEvent;
|
|
390
1011
|
private addLocalPersonAndGroupProperties;
|
|
1012
|
+
/**
|
|
1013
|
+
* Capture an error exception as an event.
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```ts
|
|
1017
|
+
* // Capture an error with user ID
|
|
1018
|
+
* try {
|
|
1019
|
+
* // Some risky operation
|
|
1020
|
+
* riskyOperation()
|
|
1021
|
+
* } catch (error) {
|
|
1022
|
+
* client.captureException(error, 'user_123')
|
|
1023
|
+
* }
|
|
1024
|
+
* ```
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* // Capture with additional properties
|
|
1029
|
+
* try {
|
|
1030
|
+
* apiCall()
|
|
1031
|
+
* } catch (error) {
|
|
1032
|
+
* client.captureException(error, 'user_123', {
|
|
1033
|
+
* endpoint: '/api/users',
|
|
1034
|
+
* method: 'POST',
|
|
1035
|
+
* status_code: 500
|
|
1036
|
+
* })
|
|
1037
|
+
* }
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* {@label Error tracking}
|
|
1041
|
+
*
|
|
1042
|
+
* @param error - The error to capture
|
|
1043
|
+
* @param distinctId - Optional user distinct ID
|
|
1044
|
+
* @param additionalProperties - Optional additional properties to include
|
|
1045
|
+
*/
|
|
391
1046
|
captureException(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>): void;
|
|
1047
|
+
/**
|
|
1048
|
+
* Capture an error exception as an event immediately (synchronously).
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```ts
|
|
1052
|
+
* // Capture an error immediately with user ID
|
|
1053
|
+
* try {
|
|
1054
|
+
* // Some risky operation
|
|
1055
|
+
* riskyOperation()
|
|
1056
|
+
* } catch (error) {
|
|
1057
|
+
* await client.captureExceptionImmediate(error, 'user_123')
|
|
1058
|
+
* }
|
|
1059
|
+
* ```
|
|
1060
|
+
*
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```ts
|
|
1063
|
+
* // Capture with additional properties
|
|
1064
|
+
* try {
|
|
1065
|
+
* apiCall()
|
|
1066
|
+
* } catch (error) {
|
|
1067
|
+
* await client.captureExceptionImmediate(error, 'user_123', {
|
|
1068
|
+
* endpoint: '/api/users',
|
|
1069
|
+
* method: 'POST',
|
|
1070
|
+
* status_code: 500
|
|
1071
|
+
* })
|
|
1072
|
+
* }
|
|
1073
|
+
* ```
|
|
1074
|
+
*
|
|
1075
|
+
* {@label Error tracking}
|
|
1076
|
+
*
|
|
1077
|
+
* @param error - The error to capture
|
|
1078
|
+
* @param distinctId - Optional user distinct ID
|
|
1079
|
+
* @param additionalProperties - Optional additional properties to include
|
|
1080
|
+
* @returns Promise that resolves when the error is captured
|
|
1081
|
+
*/
|
|
392
1082
|
captureExceptionImmediate(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>): Promise<void>;
|
|
393
1083
|
prepareEventMessage(props: EventMessage): Promise<{
|
|
394
1084
|
distinctId: string;
|