posthog-node 5.57.2 → 5.59.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/README.md +39 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +17 -7
- package/dist/client.mjs +17 -7
- package/dist/entrypoints/otel.d.ts +18 -0
- package/dist/entrypoints/otel.d.ts.map +1 -0
- package/dist/entrypoints/otel.js +99 -0
- package/dist/entrypoints/otel.mjs +58 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +30 -20
- package/dist/exports.mjs +1 -0
- package/dist/extensions/context/context.d.ts.map +1 -1
- package/dist/extensions/context/context.js +12 -8
- package/dist/extensions/context/context.mjs +12 -8
- package/dist/extensions/context/event-context.d.ts +5 -0
- package/dist/extensions/context/event-context.d.ts.map +1 -0
- package/dist/extensions/context/event-context.js +57 -0
- package/dist/extensions/context/event-context.mjs +16 -0
- package/dist/extensions/context/lifetime.d.ts +8 -0
- package/dist/extensions/context/lifetime.d.ts.map +1 -0
- package/dist/extensions/context/lifetime.js +60 -0
- package/dist/extensions/context/lifetime.mjs +19 -0
- package/dist/extensions/context/listeners.d.ts +11 -0
- package/dist/extensions/context/listeners.d.ts.map +1 -0
- package/dist/extensions/context/listeners.js +65 -0
- package/dist/extensions/context/listeners.mjs +21 -0
- package/dist/extensions/context/types.d.ts +5 -0
- package/dist/extensions/context/types.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.d.ts +2 -1
- package/dist/extensions/error-tracking/index.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.js +6 -4
- package/dist/extensions/error-tracking/index.mjs +6 -4
- package/dist/extensions/express.d.ts.map +1 -1
- package/dist/extensions/express.js +10 -3
- package/dist/extensions/express.mjs +10 -3
- package/dist/extensions/nestjs.d.ts.map +1 -1
- package/dist/extensions/nestjs.js +2 -0
- package/dist/extensions/nestjs.mjs +2 -0
- package/dist/feature-flag-evaluations.d.ts +29 -4
- package/dist/feature-flag-evaluations.d.ts.map +1 -1
- package/dist/feature-flag-evaluations.js +5 -4
- package/dist/feature-flag-evaluations.mjs +5 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +12 -5
- package/src/client.ts +36 -7
- package/src/entrypoints/otel.ts +75 -0
- package/src/exports.ts +1 -0
- package/src/extensions/context/context.ts +16 -10
- package/src/extensions/context/event-context.ts +14 -0
- package/src/extensions/context/lifetime.ts +28 -0
- package/src/extensions/context/listeners.ts +36 -0
- package/src/extensions/context/types.ts +5 -0
- package/src/extensions/error-tracking/index.ts +11 -4
- package/src/extensions/express.ts +11 -3
- package/src/extensions/nestjs.ts +2 -0
- package/src/feature-flag-evaluations.ts +36 -8
- package/src/version.ts +1 -1
package/src/extensions/nestjs.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { catchError } from 'rxjs/operators'
|
|
|
5
5
|
import ErrorTracking from './error-tracking'
|
|
6
6
|
import { addProperty, getFirstHeaderValue, getPostHogTracingHeaderValues } from './tracing-headers'
|
|
7
7
|
import { normalizeRequestCurrentUrl, normalizeRequestPath } from './url-utils'
|
|
8
|
+
import { notifyContextListeners } from './context/listeners'
|
|
8
9
|
import { PostHogBackendClient } from '../client'
|
|
9
10
|
|
|
10
11
|
// Local interfaces to avoid runtime dependency on @nestjs/common
|
|
@@ -99,6 +100,7 @@ export class PostHogInterceptor implements NestInterceptor {
|
|
|
99
100
|
this.posthog.withContext(
|
|
100
101
|
contextData,
|
|
101
102
|
() => {
|
|
103
|
+
notifyContextListeners(this.posthog, true)
|
|
102
104
|
let source = next.handle()
|
|
103
105
|
|
|
104
106
|
if (this.captureExceptions) {
|
|
@@ -43,6 +43,11 @@ export type FlagCalledEventParams = {
|
|
|
43
43
|
*/
|
|
44
44
|
export interface FeatureFlagEvaluationsHost {
|
|
45
45
|
captureFlagCalledEventIfNeeded(params: FlagCalledEventParams): void
|
|
46
|
+
/**
|
|
47
|
+
* Whether a read sends `$feature_flag_called`: the per-read option, then the client's
|
|
48
|
+
* `sendFeatureFlagEvent` option, then `true`.
|
|
49
|
+
*/
|
|
50
|
+
resolveSendFeatureFlagEvents(perRead: boolean | undefined): boolean
|
|
46
51
|
logWarning(message: string): void
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -120,32 +125,48 @@ export class FeatureFlagEvaluations {
|
|
|
120
125
|
/**
|
|
121
126
|
* Check whether a feature flag is enabled. Fires a `$feature_flag_called` event
|
|
122
127
|
* on the first access per (distinctId, flag, value) tuple, deduped via the SDK's
|
|
123
|
-
* existing cache.
|
|
128
|
+
* existing cache, unless events are off for this read (see `options.sendFeatureFlagEvents`).
|
|
124
129
|
*
|
|
125
130
|
* Flags that were not returned from the underlying evaluation resolve to
|
|
126
131
|
* `options.defaultValue` (`false` unless overridden). A flag that has a value —
|
|
127
132
|
* including a conclusive `false` result and variant strings — always wins over
|
|
128
133
|
* `options.defaultValue`. Use `getFlag()` to distinguish an absent result from `false`.
|
|
134
|
+
*
|
|
135
|
+
* @param key - The feature flag key
|
|
136
|
+
* @param options - `defaultValue`: the result when the flag is not in the snapshot.
|
|
137
|
+
* `sendFeatureFlagEvents`: whether this read sends a `$feature_flag_called` event.
|
|
138
|
+
* Defaults to the client's `sendFeatureFlagEvent` option, which defaults to `true`.
|
|
139
|
+
* When `false`, the read sends nothing and does not mark the flag as reported, so a
|
|
140
|
+
* later read that sends events still reports it. The flag still counts as accessed
|
|
141
|
+
* for `onlyAccessed()`.
|
|
129
142
|
*/
|
|
130
|
-
isEnabled(key: string, options: { defaultValue?: boolean } = {}): boolean {
|
|
143
|
+
isEnabled(key: string, options: { defaultValue?: boolean; sendFeatureFlagEvents?: boolean } = {}): boolean {
|
|
131
144
|
const flag = this._flags[key]
|
|
132
|
-
this._recordAccess(key)
|
|
145
|
+
this._recordAccess(key, options.sendFeatureFlagEvents)
|
|
133
146
|
return flag?.enabled ?? options.defaultValue ?? false
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
/**
|
|
137
150
|
* Get the evaluated value of a feature flag. Fires a `$feature_flag_called` event
|
|
138
|
-
* on the first access per (distinctId, flag, value) tuple
|
|
151
|
+
* on the first access per (distinctId, flag, value) tuple, unless events are off for
|
|
152
|
+
* this read (see `options.sendFeatureFlagEvents`).
|
|
139
153
|
*
|
|
140
154
|
* Returns the variant string for multivariate flags, `true` for boolean flags that
|
|
141
155
|
* evaluate on, `false` for boolean flags that conclusively evaluate off, and `undefined`
|
|
142
156
|
* for flags that were not returned by the evaluation. Cached inactive definitions are
|
|
143
157
|
* conclusive `false` results during local evaluation, while remote evaluation omits
|
|
144
158
|
* globally inactive flags.
|
|
159
|
+
*
|
|
160
|
+
* @param key - The feature flag key
|
|
161
|
+
* @param options - `sendFeatureFlagEvents`: whether this read sends a `$feature_flag_called`
|
|
162
|
+
* event. Defaults to the client's `sendFeatureFlagEvent` option, which defaults to `true`.
|
|
163
|
+
* When `false`, the read sends nothing and does not mark the flag as reported, so a
|
|
164
|
+
* later read that sends events still reports it. The flag still counts as accessed
|
|
165
|
+
* for `onlyAccessed()`.
|
|
145
166
|
*/
|
|
146
|
-
getFlag(key: string): FeatureFlagValue | undefined {
|
|
167
|
+
getFlag(key: string, options: { sendFeatureFlagEvents?: boolean } = {}): FeatureFlagValue | undefined {
|
|
147
168
|
const flag = this._flags[key]
|
|
148
|
-
this._recordAccess(key)
|
|
169
|
+
this._recordAccess(key, options.sendFeatureFlagEvents)
|
|
149
170
|
if (!flag) {
|
|
150
171
|
return undefined
|
|
151
172
|
}
|
|
@@ -165,7 +186,8 @@ export class FeatureFlagEvaluations {
|
|
|
165
186
|
|
|
166
187
|
/**
|
|
167
188
|
* Return a filtered copy containing only flags that have been accessed via
|
|
168
|
-
* `isEnabled()` or `getFlag()` before this call
|
|
189
|
+
* `isEnabled()` or `getFlag()` before this call, including reads that sent no
|
|
190
|
+
* `$feature_flag_called` event.
|
|
169
191
|
*
|
|
170
192
|
* Order-dependent: if nothing has been accessed yet, the returned snapshot is
|
|
171
193
|
* empty. The method honors its name — pre-access if you want a populated result.
|
|
@@ -276,9 +298,15 @@ export class FeatureFlagEvaluations {
|
|
|
276
298
|
})
|
|
277
299
|
}
|
|
278
300
|
|
|
279
|
-
private _recordAccess(key: string): void {
|
|
301
|
+
private _recordAccess(key: string, sendFeatureFlagEvents: boolean | undefined): void {
|
|
280
302
|
this._accessed.add(key)
|
|
281
303
|
|
|
304
|
+
// Return before the dedupe cache is touched, so a later read that sends events still
|
|
305
|
+
// reports this flag.
|
|
306
|
+
if (!this._host.resolveSendFeatureFlagEvents(sendFeatureFlagEvents)) {
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
|
|
282
310
|
// Empty snapshots (no resolvable distinctId) are returned by `evaluateFlags()` as a
|
|
283
311
|
// safety fallback. Firing $feature_flag_called for them would emit events with an
|
|
284
312
|
// empty distinct_id, polluting analytics — short-circuit here instead.
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.
|
|
1
|
+
export const version = "5.59.0"
|