posthog-node 5.8.8 → 5.9.1

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 (99) hide show
  1. package/dist/{index.d.ts → client.d.ts} +7 -378
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +480 -0
  4. package/dist/client.mjs +436 -0
  5. package/dist/entrypoints/index.edge.d.ts +6 -0
  6. package/dist/entrypoints/index.edge.d.ts.map +1 -0
  7. package/dist/entrypoints/index.edge.js +96 -0
  8. package/dist/entrypoints/index.edge.mjs +19 -0
  9. package/dist/entrypoints/index.node.d.ts +6 -0
  10. package/dist/entrypoints/index.node.d.ts.map +1 -0
  11. package/dist/entrypoints/index.node.js +107 -0
  12. package/dist/entrypoints/index.node.mjs +24 -0
  13. package/dist/exports.d.ts +4 -0
  14. package/dist/exports.d.ts.map +1 -0
  15. package/dist/exports.js +78 -0
  16. package/dist/exports.mjs +3 -0
  17. package/dist/extensions/error-tracking/autocapture.d.ts +4 -0
  18. package/dist/extensions/error-tracking/autocapture.d.ts.map +1 -0
  19. package/dist/extensions/error-tracking/autocapture.js +68 -0
  20. package/dist/extensions/error-tracking/autocapture.mjs +31 -0
  21. package/dist/extensions/error-tracking/index.d.ts +19 -0
  22. package/dist/extensions/error-tracking/index.d.ts.map +1 -0
  23. package/dist/extensions/error-tracking/index.js +97 -0
  24. package/dist/extensions/error-tracking/index.mjs +63 -0
  25. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts +5 -0
  26. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts.map +1 -0
  27. package/dist/extensions/error-tracking/modifiers/context-lines.node.js +227 -0
  28. package/dist/extensions/error-tracking/modifiers/context-lines.node.mjs +187 -0
  29. package/dist/extensions/error-tracking/modifiers/module.node.d.ts +3 -0
  30. package/dist/extensions/error-tracking/modifiers/module.node.d.ts.map +1 -0
  31. package/dist/extensions/error-tracking/modifiers/module.node.js +64 -0
  32. package/dist/extensions/error-tracking/modifiers/module.node.mjs +30 -0
  33. package/dist/extensions/express.d.ts +17 -0
  34. package/dist/extensions/express.d.ts.map +1 -0
  35. package/dist/extensions/express.js +61 -0
  36. package/dist/extensions/express.mjs +17 -0
  37. package/dist/extensions/feature-flags/crypto-helpers.d.ts +3 -0
  38. package/dist/extensions/feature-flags/crypto-helpers.d.ts.map +1 -0
  39. package/dist/extensions/feature-flags/crypto-helpers.js +77 -0
  40. package/dist/extensions/feature-flags/crypto-helpers.mjs +22 -0
  41. package/dist/extensions/feature-flags/crypto.d.ts +2 -0
  42. package/dist/extensions/feature-flags/crypto.d.ts.map +1 -0
  43. package/dist/extensions/feature-flags/crypto.js +47 -0
  44. package/dist/extensions/feature-flags/crypto.mjs +13 -0
  45. package/dist/extensions/feature-flags/feature-flags.d.ts +89 -0
  46. package/dist/extensions/feature-flags/feature-flags.d.ts.map +1 -0
  47. package/dist/extensions/feature-flags/feature-flags.js +529 -0
  48. package/dist/extensions/feature-flags/feature-flags.mjs +483 -0
  49. package/dist/extensions/feature-flags/lazy.d.ts +24 -0
  50. package/dist/extensions/feature-flags/lazy.d.ts.map +1 -0
  51. package/dist/extensions/feature-flags/lazy.js +60 -0
  52. package/dist/extensions/feature-flags/lazy.mjs +26 -0
  53. package/dist/extensions/sentry-integration.d.ts +54 -0
  54. package/dist/extensions/sentry-integration.d.ts.map +1 -0
  55. package/dist/extensions/sentry-integration.js +113 -0
  56. package/dist/extensions/sentry-integration.mjs +73 -0
  57. package/dist/storage-memory.d.ts +7 -0
  58. package/dist/storage-memory.d.ts.map +1 -0
  59. package/dist/storage-memory.js +46 -0
  60. package/dist/storage-memory.mjs +12 -0
  61. package/dist/types.d.ts +253 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +18 -0
  64. package/dist/types.mjs +0 -0
  65. package/dist/utils/logger.d.ts +3 -0
  66. package/dist/utils/logger.d.ts.map +1 -0
  67. package/dist/utils/logger.js +63 -0
  68. package/dist/utils/logger.mjs +29 -0
  69. package/dist/version.d.ts +2 -0
  70. package/dist/version.d.ts.map +1 -0
  71. package/dist/version.js +36 -0
  72. package/dist/version.mjs +2 -0
  73. package/package.json +32 -31
  74. package/src/client.ts +1532 -0
  75. package/src/entrypoints/index.edge.ts +22 -0
  76. package/src/entrypoints/index.node.ts +26 -0
  77. package/src/exports.ts +3 -0
  78. package/src/extensions/error-tracking/autocapture.ts +67 -0
  79. package/src/extensions/error-tracking/index.ts +104 -0
  80. package/src/extensions/error-tracking/modifiers/context-lines.node.ts +404 -0
  81. package/src/extensions/error-tracking/modifiers/module.node.ts +68 -0
  82. package/src/extensions/express.ts +40 -0
  83. package/src/extensions/feature-flags/crypto-helpers.ts +36 -0
  84. package/src/extensions/feature-flags/crypto.ts +22 -0
  85. package/src/extensions/feature-flags/feature-flags.ts +1003 -0
  86. package/src/extensions/feature-flags/lazy.ts +55 -0
  87. package/src/extensions/sentry-integration.ts +216 -0
  88. package/src/storage-memory.ts +13 -0
  89. package/src/types.ts +294 -0
  90. package/src/utils/logger.ts +39 -0
  91. package/src/version.ts +1 -0
  92. package/dist/edge/index.cjs +0 -3150
  93. package/dist/edge/index.cjs.map +0 -1
  94. package/dist/edge/index.mjs +0 -3144
  95. package/dist/edge/index.mjs.map +0 -1
  96. package/dist/node/index.cjs +0 -3556
  97. package/dist/node/index.cjs.map +0 -1
  98. package/dist/node/index.mjs +0 -3550
  99. package/dist/node/index.mjs.map +0 -1
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ PostHogSentryIntegration: ()=>PostHogSentryIntegration,
28
+ createEventProcessor: ()=>createEventProcessor,
29
+ sentryIntegration: ()=>sentryIntegration
30
+ });
31
+ const NAME = 'posthog-node';
32
+ function createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList = [
33
+ 'error'
34
+ ], sendExceptionsToPostHog = true } = {}) {
35
+ return (event)=>{
36
+ const shouldProcessLevel = '*' === severityAllowList || severityAllowList.includes(event.level);
37
+ if (!shouldProcessLevel) return event;
38
+ if (!event.tags) event.tags = {};
39
+ const userId = event.tags[PostHogSentryIntegration.POSTHOG_ID_TAG];
40
+ if (void 0 === userId) return event;
41
+ const uiHost = _posthog.options.host ?? 'https://us.i.posthog.com';
42
+ const personUrl = new URL(`/project/${_posthog.apiKey}/person/${userId}`, uiHost).toString();
43
+ event.tags['PostHog Person URL'] = personUrl;
44
+ const exceptions = event.exception?.values || [];
45
+ const exceptionList = exceptions.map((exception)=>({
46
+ ...exception,
47
+ stacktrace: exception.stacktrace ? {
48
+ ...exception.stacktrace,
49
+ type: 'raw',
50
+ frames: (exception.stacktrace.frames || []).map((frame)=>({
51
+ ...frame,
52
+ platform: "node:javascript"
53
+ }))
54
+ } : void 0
55
+ }));
56
+ const properties = {
57
+ $exception_message: exceptions[0]?.value || event.message,
58
+ $exception_type: exceptions[0]?.type,
59
+ $exception_personURL: personUrl,
60
+ $exception_level: event.level,
61
+ $exception_list: exceptionList,
62
+ $sentry_event_id: event.event_id,
63
+ $sentry_exception: event.exception,
64
+ $sentry_exception_message: exceptions[0]?.value || event.message,
65
+ $sentry_exception_type: exceptions[0]?.type,
66
+ $sentry_tags: event.tags
67
+ };
68
+ if (organization && projectId) properties['$sentry_url'] = (prefix || 'https://sentry.io/organizations/') + organization + '/issues/?project=' + projectId + '&query=' + event.event_id;
69
+ if (sendExceptionsToPostHog) _posthog.capture({
70
+ event: '$exception',
71
+ distinctId: userId,
72
+ properties
73
+ });
74
+ return event;
75
+ };
76
+ }
77
+ function sentryIntegration(_posthog, options) {
78
+ const processor = createEventProcessor(_posthog, options);
79
+ return {
80
+ name: NAME,
81
+ processEvent (event) {
82
+ return processor(event);
83
+ }
84
+ };
85
+ }
86
+ class PostHogSentryIntegration {
87
+ static #_ = this.POSTHOG_ID_TAG = 'posthog_distinct_id';
88
+ constructor(_posthog, organization, prefix, severityAllowList, sendExceptionsToPostHog){
89
+ this.name = NAME;
90
+ this.name = NAME;
91
+ this.setupOnce = function(addGlobalEventProcessor, getCurrentHub) {
92
+ const projectId = getCurrentHub()?.getClient()?.getDsn()?.projectId;
93
+ addGlobalEventProcessor(createEventProcessor(_posthog, {
94
+ organization,
95
+ projectId,
96
+ prefix,
97
+ severityAllowList,
98
+ sendExceptionsToPostHog: sendExceptionsToPostHog ?? true
99
+ }));
100
+ };
101
+ }
102
+ }
103
+ exports.PostHogSentryIntegration = __webpack_exports__.PostHogSentryIntegration;
104
+ exports.createEventProcessor = __webpack_exports__.createEventProcessor;
105
+ exports.sentryIntegration = __webpack_exports__.sentryIntegration;
106
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
107
+ "PostHogSentryIntegration",
108
+ "createEventProcessor",
109
+ "sentryIntegration"
110
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
111
+ Object.defineProperty(exports, '__esModule', {
112
+ value: true
113
+ });
@@ -0,0 +1,73 @@
1
+ const NAME = 'posthog-node';
2
+ function createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList = [
3
+ 'error'
4
+ ], sendExceptionsToPostHog = true } = {}) {
5
+ return (event)=>{
6
+ const shouldProcessLevel = '*' === severityAllowList || severityAllowList.includes(event.level);
7
+ if (!shouldProcessLevel) return event;
8
+ if (!event.tags) event.tags = {};
9
+ const userId = event.tags[PostHogSentryIntegration.POSTHOG_ID_TAG];
10
+ if (void 0 === userId) return event;
11
+ const uiHost = _posthog.options.host ?? 'https://us.i.posthog.com';
12
+ const personUrl = new URL(`/project/${_posthog.apiKey}/person/${userId}`, uiHost).toString();
13
+ event.tags['PostHog Person URL'] = personUrl;
14
+ const exceptions = event.exception?.values || [];
15
+ const exceptionList = exceptions.map((exception)=>({
16
+ ...exception,
17
+ stacktrace: exception.stacktrace ? {
18
+ ...exception.stacktrace,
19
+ type: 'raw',
20
+ frames: (exception.stacktrace.frames || []).map((frame)=>({
21
+ ...frame,
22
+ platform: "node:javascript"
23
+ }))
24
+ } : void 0
25
+ }));
26
+ const properties = {
27
+ $exception_message: exceptions[0]?.value || event.message,
28
+ $exception_type: exceptions[0]?.type,
29
+ $exception_personURL: personUrl,
30
+ $exception_level: event.level,
31
+ $exception_list: exceptionList,
32
+ $sentry_event_id: event.event_id,
33
+ $sentry_exception: event.exception,
34
+ $sentry_exception_message: exceptions[0]?.value || event.message,
35
+ $sentry_exception_type: exceptions[0]?.type,
36
+ $sentry_tags: event.tags
37
+ };
38
+ if (organization && projectId) properties['$sentry_url'] = (prefix || 'https://sentry.io/organizations/') + organization + '/issues/?project=' + projectId + '&query=' + event.event_id;
39
+ if (sendExceptionsToPostHog) _posthog.capture({
40
+ event: '$exception',
41
+ distinctId: userId,
42
+ properties
43
+ });
44
+ return event;
45
+ };
46
+ }
47
+ function sentryIntegration(_posthog, options) {
48
+ const processor = createEventProcessor(_posthog, options);
49
+ return {
50
+ name: NAME,
51
+ processEvent (event) {
52
+ return processor(event);
53
+ }
54
+ };
55
+ }
56
+ class PostHogSentryIntegration {
57
+ static #_ = this.POSTHOG_ID_TAG = 'posthog_distinct_id';
58
+ constructor(_posthog, organization, prefix, severityAllowList, sendExceptionsToPostHog){
59
+ this.name = NAME;
60
+ this.name = NAME;
61
+ this.setupOnce = function(addGlobalEventProcessor, getCurrentHub) {
62
+ const projectId = getCurrentHub()?.getClient()?.getDsn()?.projectId;
63
+ addGlobalEventProcessor(createEventProcessor(_posthog, {
64
+ organization,
65
+ projectId,
66
+ prefix,
67
+ severityAllowList,
68
+ sendExceptionsToPostHog: sendExceptionsToPostHog ?? true
69
+ }));
70
+ };
71
+ }
72
+ }
73
+ export { PostHogSentryIntegration, createEventProcessor, sentryIntegration };
@@ -0,0 +1,7 @@
1
+ import { PostHogPersistedProperty } from '@posthog/core';
2
+ export declare class PostHogMemoryStorage {
3
+ private _memoryStorage;
4
+ getProperty(key: PostHogPersistedProperty): any | undefined;
5
+ setProperty(key: PostHogPersistedProperty, value: any | null): void;
6
+ }
7
+ //# sourceMappingURL=storage-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-memory.d.ts","sourceRoot":"","sources":["../src/storage-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAExD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,cAAc,CAAyC;IAE/D,WAAW,CAAC,GAAG,EAAE,wBAAwB,GAAG,GAAG,GAAG,SAAS;IAI3D,WAAW,CAAC,GAAG,EAAE,wBAAwB,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;CAGpE"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ PostHogMemoryStorage: ()=>PostHogMemoryStorage
28
+ });
29
+ class PostHogMemoryStorage {
30
+ getProperty(key) {
31
+ return this._memoryStorage[key];
32
+ }
33
+ setProperty(key, value) {
34
+ this._memoryStorage[key] = null !== value ? value : void 0;
35
+ }
36
+ constructor(){
37
+ this._memoryStorage = {};
38
+ }
39
+ }
40
+ exports.PostHogMemoryStorage = __webpack_exports__.PostHogMemoryStorage;
41
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
42
+ "PostHogMemoryStorage"
43
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
44
+ Object.defineProperty(exports, '__esModule', {
45
+ value: true
46
+ });
@@ -0,0 +1,12 @@
1
+ class PostHogMemoryStorage {
2
+ getProperty(key) {
3
+ return this._memoryStorage[key];
4
+ }
5
+ setProperty(key, value) {
6
+ this._memoryStorage[key] = null !== value ? value : void 0;
7
+ }
8
+ constructor(){
9
+ this._memoryStorage = {};
10
+ }
11
+ }
12
+ export { PostHogMemoryStorage };
@@ -0,0 +1,253 @@
1
+ import type { PostHogCoreOptions, FeatureFlagValue, JsonType, PostHogFetchOptions, PostHogFetchResponse } from '@posthog/core';
2
+ export interface IdentifyMessage {
3
+ distinctId: string;
4
+ properties?: Record<string | number, any>;
5
+ disableGeoip?: boolean;
6
+ }
7
+ export interface SendFeatureFlagsOptions {
8
+ onlyEvaluateLocally?: boolean;
9
+ personProperties?: Record<string, any>;
10
+ groupProperties?: Record<string, Record<string, any>>;
11
+ flagKeys?: string[];
12
+ }
13
+ export interface EventMessage extends IdentifyMessage {
14
+ event: string;
15
+ groups?: Record<string, string | number>;
16
+ sendFeatureFlags?: boolean | SendFeatureFlagsOptions;
17
+ timestamp?: Date;
18
+ uuid?: string;
19
+ }
20
+ export interface GroupIdentifyMessage {
21
+ groupType: string;
22
+ groupKey: string;
23
+ properties?: Record<string | number, any>;
24
+ distinctId?: string;
25
+ disableGeoip?: boolean;
26
+ }
27
+ export type PropertyGroup = {
28
+ type: 'AND' | 'OR';
29
+ values: PropertyGroup[] | FlagProperty[];
30
+ };
31
+ export type FlagProperty = {
32
+ key: string;
33
+ type?: string;
34
+ value: FlagPropertyValue;
35
+ operator?: string;
36
+ negation?: boolean;
37
+ dependency_chain?: string[];
38
+ };
39
+ export type FlagPropertyValue = string | number | (string | number)[] | boolean;
40
+ export type FeatureFlagCondition = {
41
+ properties: FlagProperty[];
42
+ rollout_percentage?: number;
43
+ variant?: string;
44
+ };
45
+ export type BeforeSendFn = (event: EventMessage | null) => EventMessage | null;
46
+ export type PostHogOptions = PostHogCoreOptions & {
47
+ persistence?: 'memory';
48
+ personalApiKey?: string;
49
+ privacyMode?: boolean;
50
+ enableExceptionAutocapture?: boolean;
51
+ featureFlagsPollingInterval?: number;
52
+ maxCacheSize?: number;
53
+ fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
54
+ enableLocalEvaluation?: boolean;
55
+ /**
56
+ * Allows modification or dropping of events before they're sent to PostHog.
57
+ * If an array is provided, the functions are run in order.
58
+ * If a function returns null, the event will be dropped.
59
+ */
60
+ before_send?: BeforeSendFn | BeforeSendFn[];
61
+ };
62
+ export type PostHogFeatureFlag = {
63
+ id: number;
64
+ name: string;
65
+ key: string;
66
+ filters?: {
67
+ aggregation_group_type_index?: number;
68
+ groups?: FeatureFlagCondition[];
69
+ multivariate?: {
70
+ variants: {
71
+ key: string;
72
+ rollout_percentage: number;
73
+ }[];
74
+ };
75
+ payloads?: Record<string, string>;
76
+ };
77
+ deleted: boolean;
78
+ active: boolean;
79
+ rollout_percentage: null | number;
80
+ ensure_experience_continuity: boolean;
81
+ experiment_set: number[];
82
+ };
83
+ export interface IPostHog {
84
+ /**
85
+ * @description Capture allows you to capture anything a user does within your system,
86
+ * which you can later use in PostHog to find patterns in usage,
87
+ * work out which features to improve or where people are giving up.
88
+ * A capture call requires:
89
+ * @param distinctId which uniquely identifies your user
90
+ * @param event We recommend using [verb] [noun], like movie played or movie updated to easily identify what your events mean later on.
91
+ * @param properties OPTIONAL | which can be a object with any information you'd like to add
92
+ * @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
93
+ * @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
94
+ */
95
+ capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
96
+ /**
97
+ * @description Capture an event immediately. Useful for edge environments where the usual queue-based sending is not preferable. Do not mix immediate and non-immediate calls.
98
+ * @param distinctId which uniquely identifies your user
99
+ * @param event We recommend using [verb] [noun], like movie played or movie updated to easily identify what your events mean later on.
100
+ * @param properties OPTIONAL | which can be a object with any information you'd like to add
101
+ * @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
102
+ * @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
103
+ */
104
+ captureImmediate({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): Promise<void>;
105
+ /**
106
+ * @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,
107
+ * and even do things like segment users by these properties.
108
+ * An identify call requires:
109
+ * @param distinctId which uniquely identifies your user
110
+ * @param properties with a dict with any key: value pairs
111
+ */
112
+ identify({ distinctId, properties }: IdentifyMessage): void;
113
+ /**
114
+ * @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog.
115
+ * Useful for edge environments where the usual queue-based sending is not preferable. Do not mix immediate and non-immediate calls.
116
+ * @param distinctId which uniquely identifies your user
117
+ * @param properties with a dict with any key: value pairs
118
+ */
119
+ identifyImmediate({ distinctId, properties }: IdentifyMessage): Promise<void>;
120
+ /**
121
+ * @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
122
+ * This will allow you to answer questions like "Which marketing channels leads to users churning after a month?"
123
+ * or "What do users do on our website before signing up?"
124
+ * In a purely back-end implementation, this means whenever an anonymous user does something, you'll want to send a session ID with the capture call.
125
+ * Then, when that users signs up, you want to do an alias call with the session ID and the newly created user ID.
126
+ * The same concept applies for when a user logs in. If you're using PostHog in the front-end and back-end,
127
+ * doing the identify call in the frontend will be enough.:
128
+ * @param distinctId the current unique id
129
+ * @param alias the unique ID of the user before
130
+ */
131
+ alias(data: {
132
+ distinctId: string;
133
+ alias: string;
134
+ }): void;
135
+ /**
136
+ * @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
137
+ * Useful for edge environments where the usual queue-based sending is not preferable. Do not mix immediate and non-immediate calls.
138
+ * @param distinctId the current unique id
139
+ * @param alias the unique ID of the user before
140
+ */
141
+ aliasImmediate(data: {
142
+ distinctId: string;
143
+ alias: string;
144
+ }): Promise<void>;
145
+ /**
146
+ * @description PostHog feature flags (https://posthog.com/docs/features/feature-flags)
147
+ * allow you to safely deploy and roll back new features. Once you've created a feature flag in PostHog,
148
+ * you can use this method to check if the flag is on for a given user, allowing you to create logic to turn
149
+ * features on and off for different user groups or individual users.
150
+ * @param key the unique key of your feature flag
151
+ * @param distinctId the current unique id
152
+ * @param options: dict with optional parameters below
153
+ * @param groups optional - what groups are currently active (group analytics). Required if the flag depends on groups.
154
+ * @param personProperties optional - what person properties are known. Used to compute flags locally, if personalApiKey is present.
155
+ * @param groupProperties optional - what group properties are known. Used to compute flags locally, if personalApiKey is present.
156
+ * @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
157
+ * @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
158
+ *
159
+ * @returns true if the flag is on, false if the flag is off, undefined if there was an error.
160
+ */
161
+ isFeatureEnabled(key: string, distinctId: string, options?: {
162
+ groups?: Record<string, string>;
163
+ personProperties?: Record<string, string>;
164
+ groupProperties?: Record<string, Record<string, string>>;
165
+ onlyEvaluateLocally?: boolean;
166
+ sendFeatureFlagEvents?: boolean;
167
+ }): Promise<boolean | undefined>;
168
+ /**
169
+ * @description PostHog feature flags (https://posthog.com/docs/features/feature-flags)
170
+ * allow you to safely deploy and roll back new features. Once you've created a feature flag in PostHog,
171
+ * you can use this method to check if the flag is on for a given user, allowing you to create logic to turn
172
+ * features on and off for different user groups or individual users.
173
+ * @param key the unique key of your feature flag
174
+ * @param distinctId the current unique id
175
+ * @param options: dict with optional parameters below
176
+ * @param groups optional - what groups are currently active (group analytics). Required if the flag depends on groups.
177
+ * @param personProperties optional - what person properties are known. Used to compute flags locally, if personalApiKey is present.
178
+ * @param groupProperties optional - what group properties are known. Used to compute flags locally, if personalApiKey is present.
179
+ * @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
180
+ * @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
181
+ *
182
+ * @returns true or string(for multivariates) if the flag is on, false if the flag is off, undefined if there was an error.
183
+ */
184
+ getFeatureFlag(key: string, distinctId: string, options?: {
185
+ groups?: Record<string, string>;
186
+ personProperties?: Record<string, string>;
187
+ groupProperties?: Record<string, Record<string, string>>;
188
+ onlyEvaluateLocally?: boolean;
189
+ sendFeatureFlagEvents?: boolean;
190
+ }): Promise<FeatureFlagValue | undefined>;
191
+ /**
192
+ * @description Retrieves payload associated with the specified flag and matched value that is passed in.
193
+ *
194
+ * IMPORTANT: The `matchValue` parameter should be the value you previously obtained from `getFeatureFlag()`.
195
+ * If matchValue isn't passed (or is undefined), this method will automatically call `getFeatureFlag()`
196
+ * internally to fetch the flag value, which could result in a network call to the PostHog server if this flag can
197
+ * not be evaluated locally. This means that omitting `matchValue` will potentially:
198
+ * - Bypass local evaluation
199
+ * - Count as an additional flag evaluation against your quota
200
+ * - Impact performance due to the extra network request
201
+ *
202
+ * Example usage:
203
+ * ```js
204
+ * const flagValue = await client.getFeatureFlag('my-flag', distinctId);
205
+ * const payload = await client.getFeatureFlagPayload('my-flag', distinctId, flagValue);
206
+ * ```
207
+ *
208
+ * @param key the unique key of your feature flag
209
+ * @param distinctId the current unique id
210
+ * @param matchValue The flag value previously obtained from calling `getFeatureFlag()`. Can be a string or boolean.
211
+ * To avoid extra network calls, pass this parameter when you can.
212
+ * @param options: dict with optional parameters below
213
+ * @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
214
+ *
215
+ * @returns payload of a json type object
216
+ */
217
+ getFeatureFlagPayload(key: string, distinctId: string, matchValue?: FeatureFlagValue, options?: {
218
+ onlyEvaluateLocally?: boolean;
219
+ }): Promise<JsonType | undefined>;
220
+ /**
221
+ * @description Sets a groups properties, which allows asking questions like "Who are the most active companies"
222
+ * using my product in PostHog.
223
+ *
224
+ * @param groupType Type of group (ex: 'company'). Limited to 5 per project
225
+ * @param groupKey Unique identifier for that type of group (ex: 'id:5')
226
+ * @param properties OPTIONAL | which can be a object with any information you'd like to add
227
+ */
228
+ groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
229
+ /**
230
+ * @description Force an immediate reload of the polled feature flags. Please note that they are
231
+ * already polled automatically at a regular interval.
232
+ */
233
+ reloadFeatureFlags(): Promise<void>;
234
+ /**
235
+ * @description Flushes the events still in the queue and clears the feature flags poller to allow for
236
+ * a clean shutdown.
237
+ *
238
+ * @param shutdownTimeoutMs The shutdown timeout, in milliseconds. Defaults to 30000 (30s).
239
+ */
240
+ shutdown(shutdownTimeoutMs?: number): void;
241
+ /**
242
+ * @description Waits for local evaluation to be ready, with an optional timeout.
243
+ * @param timeoutMs - Maximum time to wait in milliseconds. Defaults to 30 seconds.
244
+ * @returns A promise that resolves to true if local evaluation is ready, false if the timeout was reached.
245
+ */
246
+ waitForLocalEvaluationReady(timeoutMs?: number): Promise<boolean>;
247
+ /**
248
+ * @description Returns true if local evaluation is ready, false if it's not.
249
+ * @returns true if local evaluation is ready, false if it's not.
250
+ */
251
+ isLocalEvaluationReady(): boolean;
252
+ }
253
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,eAAe,CAAA;AAEtB,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;IACzC,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IACrD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACxC,gBAAgB,CAAC,EAAE,OAAO,GAAG,uBAAuB,CAAA;IACpD,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;IACzC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO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;;;;;;;;OAyBG;IACH,qBAAqB,CACnB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE;QACR,mBAAmB,CAAC,EAAE,OAAO,CAAA;KAC9B,GACA,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IAEhC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,oBAAoB,GAAG,IAAI,CAAA;IAE9E;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAE1C;;;;OAIG;IACH,2BAA2B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAEjE;;;OAGG;IACH,sBAAsB,IAAI,OAAO,CAAA;CAClC"}
package/dist/types.js ADDED
@@ -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
+ });
package/dist/types.mjs ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ import { Logger } from '@posthog/core';
2
+ export declare const createLogger: (logMsgIfDebug: (fn: () => void) => void) => Logger;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAsCtC,eAAO,MAAM,YAAY,GAAI,eAAe,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,WAAiD,CAAA"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createLogger: ()=>createLogger
28
+ });
29
+ const _createLogger = (prefix, logMsgIfDebug)=>{
30
+ const logger = {
31
+ _log: (level, ...args)=>{
32
+ logMsgIfDebug(()=>{
33
+ const consoleLog = console[level];
34
+ consoleLog(prefix, ...args);
35
+ });
36
+ },
37
+ info: (...args)=>{
38
+ logger._log('log', ...args);
39
+ },
40
+ warn: (...args)=>{
41
+ logger._log('warn', ...args);
42
+ },
43
+ error: (...args)=>{
44
+ logger._log('error', ...args);
45
+ },
46
+ critical: (...args)=>{
47
+ console.error(prefix, ...args);
48
+ },
49
+ uninitializedWarning: (methodName)=>{
50
+ logger.error(`You must initialize PostHog before calling ${methodName}`);
51
+ },
52
+ createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, logMsgIfDebug)
53
+ };
54
+ return logger;
55
+ };
56
+ const createLogger = (logMsgIfDebug)=>_createLogger('[PostHog.js]', logMsgIfDebug);
57
+ exports.createLogger = __webpack_exports__.createLogger;
58
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
59
+ "createLogger"
60
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
61
+ Object.defineProperty(exports, '__esModule', {
62
+ value: true
63
+ });
@@ -0,0 +1,29 @@
1
+ const _createLogger = (prefix, logMsgIfDebug)=>{
2
+ const logger = {
3
+ _log: (level, ...args)=>{
4
+ logMsgIfDebug(()=>{
5
+ const consoleLog = console[level];
6
+ consoleLog(prefix, ...args);
7
+ });
8
+ },
9
+ info: (...args)=>{
10
+ logger._log('log', ...args);
11
+ },
12
+ warn: (...args)=>{
13
+ logger._log('warn', ...args);
14
+ },
15
+ error: (...args)=>{
16
+ logger._log('error', ...args);
17
+ },
18
+ critical: (...args)=>{
19
+ console.error(prefix, ...args);
20
+ },
21
+ uninitializedWarning: (methodName)=>{
22
+ logger.error(`You must initialize PostHog before calling ${methodName}`);
23
+ },
24
+ createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, logMsgIfDebug)
25
+ };
26
+ return logger;
27
+ };
28
+ const createLogger = (logMsgIfDebug)=>_createLogger('[PostHog.js]', logMsgIfDebug);
29
+ export { createLogger };
@@ -0,0 +1,2 @@
1
+ export declare const version = "5.9.1";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAA"}