posthog-node 4.5.2 → 4.7.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/CHANGELOG.md +12 -0
- package/lib/index.cjs.js +28 -5
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +28 -5
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +13 -0
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/lib/posthog-node/src/posthog-node.d.ts +1 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +29 -5
- package/src/posthog-node.ts +4 -0
|
@@ -189,6 +189,19 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
189
189
|
captureException(error: Error, additionalProperties?: {
|
|
190
190
|
[key: string]: any;
|
|
191
191
|
}): void;
|
|
192
|
+
/**
|
|
193
|
+
* Capture written user feedback for a LLM trace. Numeric values are converted to strings.
|
|
194
|
+
* @param traceId The trace ID to capture feedback for.
|
|
195
|
+
* @param userFeedback The feedback to capture.
|
|
196
|
+
*/
|
|
197
|
+
captureTraceFeedback(traceId: string | number, userFeedback: string): void;
|
|
198
|
+
/**
|
|
199
|
+
* Capture a metric for a LLM trace. Numeric values are converted to strings.
|
|
200
|
+
* @param traceId The trace ID to capture the metric for.
|
|
201
|
+
* @param metricName The name of the metric to capture.
|
|
202
|
+
* @param metricValue The value of the metric to capture.
|
|
203
|
+
*/
|
|
204
|
+
captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
|
|
192
205
|
}
|
|
193
206
|
export * from './types';
|
|
194
207
|
export { LZString };
|
|
@@ -58,8 +58,10 @@ declare class FeatureFlagsPoller {
|
|
|
58
58
|
}[];
|
|
59
59
|
loadFeatureFlags(forceReload?: boolean): Promise<void>;
|
|
60
60
|
_loadFeatureFlags(): Promise<void>;
|
|
61
|
+
private getPersonalApiKeyRequestOptions;
|
|
61
62
|
_requestFeatureFlagDefinitions(): Promise<PostHogFetchResponse>;
|
|
62
63
|
stopPoller(): void;
|
|
64
|
+
_requestRemoteConfigPayload(flagKey: string): Promise<PostHogFetchResponse>;
|
|
63
65
|
}
|
|
64
66
|
declare function matchProperty(property: FeatureFlagCondition['properties'][number], propertyValues: Record<string, any>, warnFunction?: (msg: string) => void): boolean;
|
|
65
67
|
declare function relativeDateParseForFeatureFlagMatching(value: string): Date | null;
|
|
@@ -50,6 +50,7 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
50
50
|
sendFeatureFlagEvents?: boolean;
|
|
51
51
|
disableGeoip?: boolean;
|
|
52
52
|
}): Promise<JsonType | undefined>;
|
|
53
|
+
getRemoteConfigPayload(flagKey: string): Promise<JsonType | undefined>;
|
|
53
54
|
isFeatureEnabled(key: string, distinctId: string, options?: {
|
|
54
55
|
groups?: Record<string, string>;
|
|
55
56
|
personProperties?: Record<string, string>;
|
package/package.json
CHANGED
package/src/feature-flags.ts
CHANGED
|
@@ -419,17 +419,21 @@ class FeatureFlagsPoller {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const options: PostHogFetchOptions = {
|
|
426
|
-
method: 'GET',
|
|
422
|
+
private getPersonalApiKeyRequestOptions(method: 'GET' | 'POST' | 'PUT' | 'PATCH' = 'GET'): PostHogFetchOptions {
|
|
423
|
+
return {
|
|
424
|
+
method,
|
|
427
425
|
headers: {
|
|
428
426
|
...this.customHeaders,
|
|
429
427
|
'Content-Type': 'application/json',
|
|
430
428
|
Authorization: `Bearer ${this.personalApiKey}`,
|
|
431
429
|
},
|
|
432
430
|
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async _requestFeatureFlagDefinitions(): Promise<PostHogFetchResponse> {
|
|
434
|
+
const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`
|
|
435
|
+
|
|
436
|
+
const options = this.getPersonalApiKeyRequestOptions()
|
|
433
437
|
|
|
434
438
|
let abortTimeout = null
|
|
435
439
|
|
|
@@ -451,6 +455,26 @@ class FeatureFlagsPoller {
|
|
|
451
455
|
stopPoller(): void {
|
|
452
456
|
clearTimeout(this.poller)
|
|
453
457
|
}
|
|
458
|
+
|
|
459
|
+
_requestRemoteConfigPayload(flagKey: string): Promise<PostHogFetchResponse> {
|
|
460
|
+
const url = `${this.host}/api/projects/@current/feature_flags/${flagKey}/remote_config/`
|
|
461
|
+
|
|
462
|
+
const options = this.getPersonalApiKeyRequestOptions()
|
|
463
|
+
|
|
464
|
+
let abortTimeout = null
|
|
465
|
+
if (this.timeout && typeof this.timeout === 'number') {
|
|
466
|
+
const controller = new AbortController()
|
|
467
|
+
abortTimeout = safeSetTimeout(() => {
|
|
468
|
+
controller.abort()
|
|
469
|
+
}, this.timeout)
|
|
470
|
+
options.signal = controller.signal
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
return this.fetch(url, options)
|
|
474
|
+
} finally {
|
|
475
|
+
clearTimeout(abortTimeout)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
454
478
|
}
|
|
455
479
|
|
|
456
480
|
// # This function takes a distinct_id and a feature flag key and returns a float between 0 and 1.
|
package/src/posthog-node.ts
CHANGED
|
@@ -359,6 +359,10 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
359
359
|
return response
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
async getRemoteConfigPayload(flagKey: string): Promise<JsonType | undefined> {
|
|
363
|
+
return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json()
|
|
364
|
+
}
|
|
365
|
+
|
|
362
366
|
async isFeatureEnabled(
|
|
363
367
|
key: string,
|
|
364
368
|
distinctId: string,
|