posthog-node 4.4.0 → 4.5.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 +11 -0
- package/index.ts +1 -0
- package/lib/index.cjs.js +911 -7
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +44 -3
- package/lib/index.esm.js +911 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +6 -0
- package/lib/posthog-core/src/types.d.ts +1 -0
- package/lib/posthog-core/src/utils.d.ts +2 -0
- package/lib/posthog-node/index.d.ts +1 -0
- package/lib/posthog-node/src/error-tracking.d.ts +12 -0
- package/lib/posthog-node/src/extensions/error-tracking/autocapture.d.ts +3 -0
- package/lib/posthog-node/src/extensions/error-tracking/context-lines.d.ts +4 -0
- package/lib/posthog-node/src/extensions/error-tracking/error-conversion.d.ts +5 -0
- package/lib/posthog-node/src/extensions/error-tracking/reduceable-cache.d.ts +12 -0
- package/lib/posthog-node/src/extensions/error-tracking/stack-trace.d.ts +15 -0
- package/lib/posthog-node/src/extensions/error-tracking/type-checking.d.ts +7 -0
- package/lib/posthog-node/src/extensions/error-tracking/types.d.ts +57 -0
- package/lib/posthog-node/src/extensions/express.d.ts +17 -0
- package/lib/posthog-node/src/extensions/sentry-integration.d.ts +1 -2
- package/lib/posthog-node/src/fetch.d.ts +1 -2
- package/lib/posthog-node/src/posthog-node.d.ts +5 -0
- package/package.json +1 -1
- package/src/error-tracking.ts +66 -0
- package/src/extensions/error-tracking/autocapture.ts +62 -0
- package/src/extensions/error-tracking/context-lines.ts +389 -0
- package/src/extensions/error-tracking/error-conversion.ts +250 -0
- package/src/extensions/error-tracking/reduceable-cache.ts +36 -0
- package/src/extensions/error-tracking/stack-trace.ts +269 -0
- package/src/extensions/error-tracking/type-checking.ts +37 -0
- package/src/extensions/error-tracking/types.ts +62 -0
- package/src/extensions/express.ts +37 -0
- package/src/extensions/sentry-integration.ts +1 -3
- package/src/fetch.ts +3 -7
- package/src/posthog-node.ts +10 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { SeverityLevel } from 'posthog-node/src/extensions/error-tracking/types';
|
|
3
|
+
import * as http from 'node:http';
|
|
4
|
+
|
|
2
5
|
type PostHogCoreOptions = {
|
|
3
6
|
/** PostHog API host, usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com' */
|
|
4
7
|
host?: string;
|
|
@@ -372,9 +375,33 @@ type PostHogNodeV1 = {
|
|
|
372
375
|
shutdown(shutdownTimeoutMs?: number): void;
|
|
373
376
|
};
|
|
374
377
|
|
|
378
|
+
interface EventHint {
|
|
379
|
+
mechanism?: Partial<Mechanism>;
|
|
380
|
+
syntheticException?: Error | null;
|
|
381
|
+
}
|
|
382
|
+
interface Mechanism {
|
|
383
|
+
handled?: boolean;
|
|
384
|
+
type?: string;
|
|
385
|
+
source?: string;
|
|
386
|
+
synthetic?: boolean;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
declare class ErrorTracking {
|
|
390
|
+
private client;
|
|
391
|
+
private _exceptionAutocaptureEnabled;
|
|
392
|
+
static captureException(client: PostHog, error: unknown, distinctId: string, hint: EventHint, additionalProperties?: Record<string | number, any>): Promise<void>;
|
|
393
|
+
constructor(client: PostHog, options: PostHogOptions);
|
|
394
|
+
private startAutocaptureIfEnabled;
|
|
395
|
+
private onException;
|
|
396
|
+
private onFatalError;
|
|
397
|
+
isEnabled(): boolean;
|
|
398
|
+
}
|
|
399
|
+
|
|
375
400
|
type PostHogOptions = PostHogCoreOptions & {
|
|
376
401
|
persistence?: 'memory';
|
|
377
402
|
personalApiKey?: string;
|
|
403
|
+
privacyMode?: boolean;
|
|
404
|
+
enableExceptionAutocapture?: boolean;
|
|
378
405
|
featureFlagsPollingInterval?: number;
|
|
379
406
|
maxCacheSize?: number;
|
|
380
407
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
@@ -382,6 +409,7 @@ type PostHogOptions = PostHogCoreOptions & {
|
|
|
382
409
|
declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
383
410
|
private _memoryStorage;
|
|
384
411
|
private featureFlagsPoller?;
|
|
412
|
+
protected errorTracking: ErrorTracking;
|
|
385
413
|
private maxCacheSize;
|
|
386
414
|
readonly options: PostHogOptions;
|
|
387
415
|
distinctIdHasSentFlagCalls: Record<string, string[]>;
|
|
@@ -444,14 +472,13 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
444
472
|
reloadFeatureFlags(): Promise<void>;
|
|
445
473
|
shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
446
474
|
private addLocalPersonAndGroupProperties;
|
|
475
|
+
captureException(error: unknown, distinctId: string, additionalProperties?: Record<string | number, any>): void;
|
|
447
476
|
}
|
|
448
477
|
|
|
449
478
|
/**
|
|
450
479
|
* @file Adapted from [posthog-js](https://github.com/PostHog/posthog-js/blob/8157df935a4d0e71d2fefef7127aa85ee51c82d1/src/extensions/sentry-integration.ts) with modifications for the Node SDK.
|
|
451
480
|
*/
|
|
452
481
|
|
|
453
|
-
declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"];
|
|
454
|
-
declare type SeverityLevel = (typeof severityLevels)[number];
|
|
455
482
|
type _SentryEvent = any;
|
|
456
483
|
type _SentryEventProcessor = any;
|
|
457
484
|
type _SentryHub = any;
|
|
@@ -478,4 +505,18 @@ declare class PostHogSentryIntegration implements _SentryIntegrationClass {
|
|
|
478
505
|
constructor(_posthog: PostHog, organization?: string, prefix?: string, severityAllowList?: SeverityLevel[] | '*');
|
|
479
506
|
}
|
|
480
507
|
|
|
481
|
-
|
|
508
|
+
type ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;
|
|
509
|
+
type ExpressErrorMiddleware = (error: MiddlewareError, req: http.IncomingMessage, res: http.ServerResponse, next: (error: MiddlewareError) => void) => void;
|
|
510
|
+
interface MiddlewareError extends Error {
|
|
511
|
+
status?: number | string;
|
|
512
|
+
statusCode?: number | string;
|
|
513
|
+
status_code?: number | string;
|
|
514
|
+
output?: {
|
|
515
|
+
statusCode?: number | string;
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
declare function setupExpressErrorHandler(_posthog: PostHog, app: {
|
|
519
|
+
use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown;
|
|
520
|
+
}): void;
|
|
521
|
+
|
|
522
|
+
export { PostHog, PostHogOptions, PostHogSentryIntegration, SentryIntegrationOptions, createEventProcessor, sentryIntegration, setupExpressErrorHandler };
|