@posthog/types 1.313.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.
Files changed (48) hide show
  1. package/LICENSE +299 -0
  2. package/README.md +103 -0
  3. package/dist/capture.d.ts +65 -0
  4. package/dist/capture.d.ts.map +1 -0
  5. package/dist/capture.js +18 -0
  6. package/dist/capture.mjs +0 -0
  7. package/dist/common.d.ts +10 -0
  8. package/dist/common.d.ts.map +1 -0
  9. package/dist/common.js +18 -0
  10. package/dist/common.mjs +0 -0
  11. package/dist/feature-flags.d.ts +44 -0
  12. package/dist/feature-flags.d.ts.map +1 -0
  13. package/dist/feature-flags.js +18 -0
  14. package/dist/feature-flags.mjs +0 -0
  15. package/dist/index.d.ts +15 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +18 -0
  18. package/dist/index.mjs +0 -0
  19. package/dist/posthog-config.d.ts +1218 -0
  20. package/dist/posthog-config.d.ts.map +1 -0
  21. package/dist/posthog-config.js +18 -0
  22. package/dist/posthog-config.mjs +0 -0
  23. package/dist/posthog.d.ts +395 -0
  24. package/dist/posthog.d.ts.map +1 -0
  25. package/dist/posthog.js +18 -0
  26. package/dist/posthog.mjs +0 -0
  27. package/dist/request.d.ts +11 -0
  28. package/dist/request.d.ts.map +1 -0
  29. package/dist/request.js +18 -0
  30. package/dist/request.mjs +0 -0
  31. package/dist/segment.d.ts +52 -0
  32. package/dist/segment.d.ts.map +1 -0
  33. package/dist/segment.js +18 -0
  34. package/dist/segment.mjs +0 -0
  35. package/dist/session-recording.d.ts +60 -0
  36. package/dist/session-recording.d.ts.map +1 -0
  37. package/dist/session-recording.js +18 -0
  38. package/dist/session-recording.mjs +0 -0
  39. package/package.json +43 -0
  40. package/src/capture.ts +101 -0
  41. package/src/common.ts +9 -0
  42. package/src/feature-flags.ts +60 -0
  43. package/src/index.ts +74 -0
  44. package/src/posthog-config.ts +1395 -0
  45. package/src/posthog.ts +490 -0
  46. package/src/request.ts +14 -0
  47. package/src/segment.ts +56 -0
  48. package/src/session-recording.ts +106 -0
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
File without changes
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@posthog/types",
3
+ "version": "1.313.0",
4
+ "description": "Type definitions for the PostHog JavaScript SDK",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/PostHog/posthog-js.git",
12
+ "directory": "packages/types"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "!src/__tests__"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "require": "./dist/index.js",
23
+ "import": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "devDependencies": {
27
+ "@rslib/core": "0.10.6",
28
+ "@types/jest": "^29.5.14",
29
+ "jest": "29.7.0",
30
+ "ts-jest": "29.4.0",
31
+ "typescript": "5.8.2",
32
+ "@posthog-tooling/tsconfig-base": "1.1.1"
33
+ },
34
+ "scripts": {
35
+ "clean": "rimraf dist",
36
+ "lint": "eslint src",
37
+ "lint:fix": "eslint src --fix",
38
+ "build": "rslib build",
39
+ "dev": "rslib build -w",
40
+ "test:unit": "jest",
41
+ "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
42
+ }
43
+ }
package/src/capture.ts ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Capture-related types
3
+ */
4
+
5
+ import type { Properties } from './common'
6
+
7
+ /**
8
+ * These are known events PostHog events that can be processed by the `beforeCapture` function
9
+ * That means PostHog functionality does not rely on receiving 100% of these for calculations
10
+ * So, it is safe to sample them to reduce the volume of events sent to PostHog
11
+ */
12
+ export type KnownEventName =
13
+ | '$heatmaps_data'
14
+ | '$opt_in'
15
+ | '$exception'
16
+ | '$$heatmap'
17
+ | '$web_vitals'
18
+ | '$dead_click'
19
+ | '$autocapture'
20
+ | '$copy_autocapture'
21
+ | '$rageclick'
22
+
23
+ /**
24
+ * Known events that can be safely edited in beforeCapture without breaking PostHog functionality
25
+ */
26
+ export type KnownUnsafeEditableEvent =
27
+ | '$set'
28
+ | '$pageview'
29
+ | '$pageleave'
30
+ | '$identify'
31
+ | '$groupidentify'
32
+ | '$create_alias'
33
+ | '$feature_flag_called'
34
+
35
+ export type EventName =
36
+ | KnownUnsafeEditableEvent
37
+ | KnownEventName
38
+ // magic value so that the type of EventName is a set of known strings or any other string
39
+ // which means you get autocomplete for known strings
40
+ // but no type complaints when you add an arbitrary string
41
+ | (string & {})
42
+
43
+ export interface CaptureResult {
44
+ uuid: string
45
+ event: EventName
46
+ properties: Properties
47
+ $set?: Properties
48
+ $set_once?: Properties
49
+ timestamp?: Date
50
+ }
51
+
52
+ export interface CaptureOptions {
53
+ /**
54
+ * Used when `$identify` is called
55
+ * Will set person properties overriding previous values
56
+ */
57
+ $set?: Properties
58
+
59
+ /**
60
+ * Used when `$identify` is called
61
+ * Will set person properties but only once, it will NOT override previous values
62
+ */
63
+ $set_once?: Properties
64
+
65
+ /**
66
+ * Used to override the desired endpoint for the captured event
67
+ */
68
+ _url?: string
69
+
70
+ /**
71
+ * key of queue, e.g. 'sessionRecording' vs 'event'
72
+ */
73
+ _batchKey?: string
74
+
75
+ /**
76
+ * If set, overrides and disables config.properties_string_max_length
77
+ */
78
+ _noTruncate?: boolean
79
+
80
+ /**
81
+ * If set, skips the batched queue
82
+ */
83
+ send_instantly?: boolean
84
+
85
+ /**
86
+ * If set, skips the client side rate limiting
87
+ */
88
+ skip_client_rate_limiting?: boolean
89
+
90
+ /**
91
+ * If set, overrides the desired transport method
92
+ */
93
+ transport?: 'XHR' | 'fetch' | 'sendBeacon'
94
+
95
+ /**
96
+ * If set, overrides the current timestamp
97
+ */
98
+ timestamp?: Date
99
+ }
100
+
101
+ export type BeforeSendFn = (cr: CaptureResult | null) => CaptureResult | null
package/src/common.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Common types shared across PostHog SDKs
3
+ */
4
+
5
+ export type Property = any
6
+ export type Properties = Record<string, Property>
7
+
8
+ export type JsonRecord = { [key: string]: JsonType }
9
+ export type JsonType = string | number | boolean | null | undefined | JsonRecord | Array<JsonType>
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Feature flag types
3
+ */
4
+
5
+ import type { JsonType } from './common'
6
+
7
+ export type FeatureFlagsCallback = (
8
+ flags: string[],
9
+ variants: Record<string, string | boolean>,
10
+ context?: {
11
+ errorsLoading?: boolean
12
+ }
13
+ ) => void
14
+
15
+ export type FeatureFlagDetail = {
16
+ key: string
17
+ enabled: boolean
18
+ // Only used when overriding a flag payload.
19
+ original_enabled?: boolean | undefined
20
+ variant: string | undefined
21
+ // Only used when overriding a flag payload.
22
+ original_variant?: string | undefined
23
+ reason: EvaluationReason | undefined
24
+ metadata: FeatureFlagMetadata | undefined
25
+ }
26
+
27
+ export type FeatureFlagMetadata = {
28
+ id: number
29
+ version: number | undefined
30
+ description: string | undefined
31
+ payload: JsonType | undefined
32
+ // Only used when overriding a flag payload.
33
+ original_payload?: JsonType | undefined
34
+ }
35
+
36
+ export type EvaluationReason = {
37
+ code: string
38
+ condition_index: number | undefined
39
+ description: string | undefined
40
+ }
41
+
42
+ export type RemoteConfigFeatureFlagCallback = (payload: JsonType) => void
43
+
44
+ // Sync this with the backend's EarlyAccessFeatureSerializer!
45
+ /** A feature that isn't publicly available yet.*/
46
+ export interface EarlyAccessFeature {
47
+ name: string
48
+ description: string
49
+ stage: 'concept' | 'alpha' | 'beta'
50
+ documentationUrl: string | null
51
+ payload: JsonType
52
+ flagKey: string | null
53
+ }
54
+
55
+ export type EarlyAccessFeatureStage = 'concept' | 'alpha' | 'beta' | 'general-availability'
56
+ export type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void
57
+
58
+ export interface EarlyAccessFeatureResponse {
59
+ earlyAccessFeatures: EarlyAccessFeature[]
60
+ }
package/src/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @posthog/types - Type definitions for the PostHog JavaScript SDK
3
+ *
4
+ * This package provides TypeScript type definitions for the PostHog SDK,
5
+ * allowing you to type the PostHog instance and its configuration options.
6
+ */
7
+
8
+ // PostHog instance type
9
+ export type { PostHog } from './posthog'
10
+
11
+ // Common types
12
+ export type { Property, Properties, JsonType, JsonRecord } from './common'
13
+
14
+ // Capture types
15
+ export type {
16
+ KnownEventName,
17
+ KnownUnsafeEditableEvent,
18
+ EventName,
19
+ CaptureResult,
20
+ CaptureOptions,
21
+ BeforeSendFn,
22
+ } from './capture'
23
+
24
+ // Feature flag types
25
+ export type {
26
+ FeatureFlagsCallback,
27
+ FeatureFlagDetail,
28
+ FeatureFlagMetadata,
29
+ EvaluationReason,
30
+ RemoteConfigFeatureFlagCallback,
31
+ EarlyAccessFeature,
32
+ EarlyAccessFeatureStage,
33
+ EarlyAccessFeatureCallback,
34
+ EarlyAccessFeatureResponse,
35
+ } from './feature-flags'
36
+
37
+ // Request types
38
+ export type { Headers, RequestResponse, RequestCallback } from './request'
39
+
40
+ // Session recording types
41
+ export type {
42
+ SessionRecordingCanvasOptions,
43
+ InitiatorType,
44
+ NetworkRequest,
45
+ CapturedNetworkRequest,
46
+ SessionIdChangedCallback,
47
+ SeverityLevel,
48
+ } from './session-recording'
49
+
50
+ // Config types
51
+ export type {
52
+ AutocaptureCompatibleElement,
53
+ DomAutocaptureEvents,
54
+ AutocaptureConfig,
55
+ RageclickConfig,
56
+ BootstrapConfig,
57
+ SupportedWebVitalsMetrics,
58
+ PerformanceCaptureConfig,
59
+ DeadClickCandidate,
60
+ ExceptionAutoCaptureConfig,
61
+ DeadClicksAutoCaptureConfig,
62
+ HeatmapConfig,
63
+ ConfigDefaults,
64
+ ExternalIntegrationKind,
65
+ ErrorTrackingOptions,
66
+ MaskInputOptions,
67
+ SlimDOMOptions,
68
+ SessionRecordingOptions,
69
+ RequestQueueConfig,
70
+ PostHogConfig,
71
+ } from './posthog-config'
72
+
73
+ // Segment integration types
74
+ export type { SegmentUser, SegmentAnalytics, SegmentPlugin, SegmentContext, SegmentFunction } from './segment'