posthog-node 5.51.5 → 5.51.7
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/ai-capture/batching.js +12 -8
- package/dist/ai-capture/routing.js +18 -14
- package/dist/capture-v1/config.js +16 -12
- package/dist/capture-v1/config.mjs +1 -1
- package/dist/capture-v1/errors.js +15 -11
- package/dist/capture-v1/routing.js +18 -13
- package/dist/capture-v1/sender.js +12 -8
- package/dist/capture-v1/transform.js +18 -14
- package/dist/capture-v1/types.js +2 -2
- package/dist/capture-v1/types.mjs +1 -0
- package/dist/client.d.ts +16 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -14
- package/dist/client.mjs +4 -4
- package/dist/entrypoints/index.edge.js +35 -33
- package/dist/entrypoints/index.node.js +50 -48
- package/dist/entrypoints/nestjs.js +16 -14
- package/dist/experimental.js +2 -2
- package/dist/experimental.mjs +1 -0
- package/dist/exports.js +61 -63
- package/dist/exports.mjs +2 -3
- package/dist/extensions/context/context.js +12 -8
- package/dist/extensions/context/types.js +2 -2
- package/dist/extensions/context/types.mjs +1 -0
- package/dist/extensions/error-tracking/autocapture.js +17 -13
- package/dist/extensions/error-tracking/index.js +12 -8
- package/dist/extensions/error-tracking/index.mjs +1 -1
- package/dist/extensions/error-tracking/modifiers/context-lines.node.js +15 -11
- package/dist/extensions/error-tracking/modifiers/module.node.js +12 -8
- package/dist/extensions/error-tracking/modifiers/relative-path.node.js +12 -8
- package/dist/extensions/express.js +14 -10
- package/dist/extensions/feature-flags/cache.js +2 -2
- package/dist/extensions/feature-flags/cache.mjs +1 -0
- package/dist/extensions/feature-flags/crypto.js +12 -8
- package/dist/extensions/feature-flags/crypto.mjs +1 -2
- package/dist/extensions/feature-flags/feature-flags.js +17 -13
- package/dist/extensions/nestjs.js +12 -8
- package/dist/extensions/sentry-integration.js +17 -11
- package/dist/extensions/sentry-integration.mjs +3 -1
- package/dist/extensions/tracing-headers.js +20 -15
- package/dist/extensions/url-utils.js +14 -10
- package/dist/feature-flag-evaluations.d.ts +7 -4
- package/dist/feature-flag-evaluations.d.ts.map +1 -1
- package/dist/feature-flag-evaluations.js +12 -8
- package/dist/gzip.node.js +12 -8
- package/dist/storage-memory.js +15 -11
- package/dist/types.d.ts +23 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +15 -11
- package/dist/version.mjs +1 -1
- package/package.json +10 -10
- package/src/client.ts +16 -6
- package/src/extensions/error-tracking/modifiers/module.node.ts +1 -1
- package/src/extensions/tracing-headers.ts +1 -1
- package/src/feature-flag-evaluations.ts +7 -4
- package/src/types.ts +36 -2
- package/src/version.ts +1 -1
package/src/client.ts
CHANGED
|
@@ -1188,7 +1188,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1188
1188
|
* @param distinctId - The user's distinct ID
|
|
1189
1189
|
* @param options - Evaluation options (includes sendFeatureFlagEvents, defaults to true)
|
|
1190
1190
|
* @param matchValue - Optional match value for payload lookup (used by getFeatureFlagPayload)
|
|
1191
|
-
* @returns Promise that resolves to the flag result or undefined
|
|
1191
|
+
* @returns Promise that resolves to the flag result, or undefined when no evaluation is available
|
|
1192
1192
|
*/
|
|
1193
1193
|
private async _getFeatureFlagResult(
|
|
1194
1194
|
key: string,
|
|
@@ -1415,6 +1415,11 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1415
1415
|
/**
|
|
1416
1416
|
* Get the value of a feature flag for a specific user.
|
|
1417
1417
|
*
|
|
1418
|
+
* A boolean `false` is a conclusive off evaluation. `undefined` means no result is available,
|
|
1419
|
+
* for example because the key was not returned or local-only evaluation was inconclusive.
|
|
1420
|
+
* Local evaluation resolves cached inactive definitions to `false`; remote evaluation omits
|
|
1421
|
+
* globally inactive flags, so the result depends on which evaluation path is available.
|
|
1422
|
+
*
|
|
1418
1423
|
* @example
|
|
1419
1424
|
* ```ts
|
|
1420
1425
|
* // Basic feature flag check
|
|
@@ -1424,7 +1429,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1424
1429
|
* } else if (flagValue === 'variant-b') {
|
|
1425
1430
|
* // Show variant B
|
|
1426
1431
|
* } else {
|
|
1427
|
-
* // Flag
|
|
1432
|
+
* // Flag evaluated off, or no value was returned
|
|
1428
1433
|
* }
|
|
1429
1434
|
* ```
|
|
1430
1435
|
*
|
|
@@ -1456,7 +1461,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1456
1461
|
* @param key - The feature flag key
|
|
1457
1462
|
* @param distinctId - The user's distinct ID
|
|
1458
1463
|
* @param options - Optional configuration for flag evaluation
|
|
1459
|
-
* @returns Promise that resolves to the flag value or undefined
|
|
1464
|
+
* @returns Promise that resolves to the flag value, or undefined when no evaluation is available
|
|
1460
1465
|
*/
|
|
1461
1466
|
async getFeatureFlag(
|
|
1462
1467
|
key: string,
|
|
@@ -1576,6 +1581,9 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1576
1581
|
/**
|
|
1577
1582
|
* Get the result of evaluating a feature flag, including its value and payload.
|
|
1578
1583
|
* This is more efficient than calling getFeatureFlag and getFeatureFlagPayload separately when you need both.
|
|
1584
|
+
* A result with `enabled: false` is a conclusive off evaluation; `undefined` means no evaluation
|
|
1585
|
+
* is available. Local evaluation resolves cached inactive definitions to `enabled: false`, while
|
|
1586
|
+
* remote evaluation omits globally inactive flags.
|
|
1579
1587
|
*
|
|
1580
1588
|
* @example
|
|
1581
1589
|
* ```ts
|
|
@@ -1691,7 +1699,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1691
1699
|
* // Feature is enabled
|
|
1692
1700
|
* console.log('New feature is active')
|
|
1693
1701
|
* } else {
|
|
1694
|
-
* //
|
|
1702
|
+
* // Flag evaluated off, or no value was returned
|
|
1695
1703
|
* console.log('New feature is not active')
|
|
1696
1704
|
* }
|
|
1697
1705
|
* ```
|
|
@@ -1714,7 +1722,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1714
1722
|
* @param key - The feature flag key
|
|
1715
1723
|
* @param distinctId - The user's distinct ID
|
|
1716
1724
|
* @param options - Optional configuration for flag evaluation
|
|
1717
|
-
* @returns Promise that resolves to true if
|
|
1725
|
+
* @returns Promise that resolves to true if the flag evaluates on, false if it conclusively evaluates off, or undefined when no evaluation is available
|
|
1718
1726
|
*/
|
|
1719
1727
|
async isFeatureEnabled(
|
|
1720
1728
|
key: string,
|
|
@@ -1944,7 +1952,9 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1944
1952
|
* cached definitions, no network call is made and the snapshot's `$feature_flag_called`
|
|
1945
1953
|
* events are tagged `locally_evaluated: true`. A requested key missing from local
|
|
1946
1954
|
* definitions is included in a `/flags` fallback unless `onlyEvaluateLocally` is true.
|
|
1947
|
-
* Locally resolved values remain authoritative when remote results are merged.
|
|
1955
|
+
* Locally resolved values remain authoritative when remote results are merged. In particular,
|
|
1956
|
+
* a cached inactive definition is a conclusive `false` result locally, while remote evaluation
|
|
1957
|
+
* omits globally inactive flags and therefore leaves those keys absent.
|
|
1948
1958
|
*
|
|
1949
1959
|
* **Trim the request.** Pass `flagKeys` to scope local evaluation, the underlying
|
|
1950
1960
|
* `/flags` request, and the returned snapshot to a subset of flags. Remote evaluation
|
|
@@ -29,7 +29,7 @@ function createGetModuleFromFilename(
|
|
|
29
29
|
|
|
30
30
|
const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// oxlint-disable-next-line prefer-const
|
|
33
33
|
let { dir, base: file, ext } = posix.parse(normalizedFilename)
|
|
34
34
|
|
|
35
35
|
if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
|
|
@@ -2,7 +2,7 @@ import type { IncomingHttpHeaders } from 'node:http'
|
|
|
2
2
|
|
|
3
3
|
const TRACING_HEADER_MAX_LENGTH = 1000
|
|
4
4
|
// Remove C0 controls, DEL, and C1 controls from PostHog tracing IDs only.
|
|
5
|
-
//
|
|
5
|
+
// oxlint-disable-next-line no-control-regex
|
|
6
6
|
const TRACING_HEADER_CONTROL_CHARS_REGEX = /[\x00-\x1f\x7f-\x9f]/g
|
|
7
7
|
|
|
8
8
|
type HeaderValue = IncomingHttpHeaders[string]
|
|
@@ -121,7 +121,8 @@ export class FeatureFlagEvaluations {
|
|
|
121
121
|
*
|
|
122
122
|
* Flags that were not returned from the underlying evaluation resolve to
|
|
123
123
|
* `options.defaultValue` (`false` unless overridden). A flag that has a value —
|
|
124
|
-
* including `false` and variant strings — always wins over
|
|
124
|
+
* including a conclusive `false` result and variant strings — always wins over
|
|
125
|
+
* `options.defaultValue`. Use `getFlag()` to distinguish an absent result from `false`.
|
|
125
126
|
*/
|
|
126
127
|
isEnabled(key: string, options: { defaultValue?: boolean } = {}): boolean {
|
|
127
128
|
const flag = this._flags[key]
|
|
@@ -133,9 +134,11 @@ export class FeatureFlagEvaluations {
|
|
|
133
134
|
* Get the evaluated value of a feature flag. Fires a `$feature_flag_called` event
|
|
134
135
|
* on the first access per (distinctId, flag, value) tuple.
|
|
135
136
|
*
|
|
136
|
-
* Returns the variant string for multivariate flags, `true` for
|
|
137
|
-
*
|
|
138
|
-
* were not returned by the evaluation.
|
|
137
|
+
* Returns the variant string for multivariate flags, `true` for boolean flags that
|
|
138
|
+
* evaluate on, `false` for boolean flags that conclusively evaluate off, and `undefined`
|
|
139
|
+
* for flags that were not returned by the evaluation. Cached inactive definitions are
|
|
140
|
+
* conclusive `false` results during local evaluation, while remote evaluation omits
|
|
141
|
+
* globally inactive flags.
|
|
139
142
|
*/
|
|
140
143
|
getFlag(key: string): FeatureFlagValue | undefined {
|
|
141
144
|
const flag = this._flags[key]
|
package/src/types.ts
CHANGED
|
@@ -422,6 +422,7 @@ export type FeatureFlagErrorType = (typeof FeatureFlagError)[keyof typeof Featur
|
|
|
422
422
|
*/
|
|
423
423
|
export type FeatureFlagResult = {
|
|
424
424
|
key: string
|
|
425
|
+
/** Whether the returned feature flag evaluation is enabled. `false` is a conclusive off result. */
|
|
425
426
|
enabled: boolean
|
|
426
427
|
variant: string | undefined
|
|
427
428
|
payload: JsonType | undefined
|
|
@@ -453,6 +454,36 @@ export interface IPostHog {
|
|
|
453
454
|
*/
|
|
454
455
|
captureImmediate({ distinctId, event, properties, groups, flags, sendFeatureFlags }: EventMessage): Promise<void>
|
|
455
456
|
|
|
457
|
+
/**
|
|
458
|
+
* @description Capture an exception as a $exception event.
|
|
459
|
+
* @param error The error to capture.
|
|
460
|
+
* @param distinctId Optional user distinct ID.
|
|
461
|
+
* @param additionalProperties Optional additional properties to include.
|
|
462
|
+
* @param uuid Optional event UUID.
|
|
463
|
+
* @param flags Optional `FeatureFlagEvaluations` snapshot to attach to the event.
|
|
464
|
+
*/
|
|
465
|
+
captureException(
|
|
466
|
+
error: unknown,
|
|
467
|
+
distinctId?: string,
|
|
468
|
+
additionalProperties?: Record<string | number, any>,
|
|
469
|
+
uuid?: EventMessage['uuid'],
|
|
470
|
+
flags?: FeatureFlagEvaluations
|
|
471
|
+
): void
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @description Capture an exception as a $exception event immediately.
|
|
475
|
+
* @param error The error to capture.
|
|
476
|
+
* @param distinctId Optional user distinct ID.
|
|
477
|
+
* @param additionalProperties Optional additional properties to include.
|
|
478
|
+
* @param flags Optional `FeatureFlagEvaluations` snapshot to attach to the event.
|
|
479
|
+
*/
|
|
480
|
+
captureExceptionImmediate(
|
|
481
|
+
error: unknown,
|
|
482
|
+
distinctId?: string,
|
|
483
|
+
additionalProperties?: Record<string | number, any>,
|
|
484
|
+
flags?: FeatureFlagEvaluations
|
|
485
|
+
): Promise<void>
|
|
486
|
+
|
|
456
487
|
/**
|
|
457
488
|
* @description Capture an AI event on the dedicated AI capture endpoint.
|
|
458
489
|
* Beta: the signature is stable; operational limits (per-event size cap, batching, endpoint) may change without notice. Delivery is async, and no redaction or truncation is applied to the payload.
|
|
@@ -552,7 +583,7 @@ export interface IPostHog {
|
|
|
552
583
|
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
553
584
|
* @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
|
|
554
585
|
*
|
|
555
|
-
* @returns true if the flag
|
|
586
|
+
* @returns true if the flag evaluates on, false if it conclusively evaluates off, or undefined if no result is available. Local evaluation resolves cached inactive definitions to false; remote evaluation omits globally inactive flags, leaving no result.
|
|
556
587
|
*
|
|
557
588
|
* @deprecated Use {@link IPostHog.evaluateFlags} and call `flags.isEnabled(key)` on the
|
|
558
589
|
* returned snapshot. Will be removed in the next major version.
|
|
@@ -583,7 +614,7 @@ export interface IPostHog {
|
|
|
583
614
|
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
584
615
|
* @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
|
|
585
616
|
*
|
|
586
|
-
* @returns true or string
|
|
617
|
+
* @returns true or a variant string if the flag evaluates on, false if it conclusively evaluates off, or undefined if no result is available. Local evaluation resolves cached inactive definitions to false; remote evaluation omits globally inactive flags, leaving no result.
|
|
587
618
|
*
|
|
588
619
|
* @deprecated Use {@link IPostHog.evaluateFlags} and call `flags.getFlag(key)` on the
|
|
589
620
|
* returned snapshot. Will be removed in the next major version.
|
|
@@ -715,6 +746,9 @@ export interface IPostHog {
|
|
|
715
746
|
* posthog.capture({ distinctId: 'user_123', event: 'page_viewed', flags })
|
|
716
747
|
* ```
|
|
717
748
|
*
|
|
749
|
+
* Local evaluation resolves cached inactive definitions to `false`. Remote evaluation omits
|
|
750
|
+
* globally inactive flags, so those keys are absent when no local definition is available.
|
|
751
|
+
*
|
|
718
752
|
* @param options - Optional configuration for flag evaluation. `flagKeys` scopes local evaluation, the `/flags` request, and the returned snapshot. Missing local keys trigger fallback unless `onlyEvaluateLocally` is true.
|
|
719
753
|
*/
|
|
720
754
|
evaluateFlags(options?: AllFlagsOptions): Promise<FeatureFlagEvaluations>
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.51.
|
|
1
|
+
export const version = '5.51.7'
|