@posthog/core 1.2.2 → 1.2.4

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 (46) hide show
  1. package/dist/error-tracking/parsers/base.d.ts +0 -5
  2. package/dist/error-tracking/parsers/base.d.ts.map +1 -1
  3. package/dist/error-tracking/parsers/base.js +1 -21
  4. package/dist/error-tracking/parsers/base.mjs +1 -6
  5. package/dist/error-tracking/types.d.ts +1 -1
  6. package/dist/error-tracking/types.d.ts.map +1 -1
  7. package/dist/logger.d.ts +11 -0
  8. package/dist/logger.d.ts.map +1 -0
  9. package/dist/logger.js +74 -0
  10. package/dist/logger.mjs +37 -0
  11. package/dist/posthog-core-stateless.d.ts +2 -1
  12. package/dist/posthog-core-stateless.d.ts.map +1 -1
  13. package/dist/posthog-core-stateless.js +31 -29
  14. package/dist/posthog-core-stateless.mjs +31 -29
  15. package/dist/posthog-core.d.ts.map +1 -1
  16. package/dist/posthog-core.js +9 -9
  17. package/dist/posthog-core.mjs +9 -9
  18. package/dist/process/index.d.ts +2 -0
  19. package/dist/process/index.d.ts.map +1 -0
  20. package/dist/process/index.js +60 -0
  21. package/dist/process/index.mjs +1 -0
  22. package/dist/process/spawn-local.d.ts +8 -0
  23. package/dist/process/spawn-local.d.ts.map +1 -0
  24. package/dist/process/spawn-local.js +64 -0
  25. package/dist/process/spawn-local.mjs +30 -0
  26. package/dist/process/utils.d.ts +3 -0
  27. package/dist/process/utils.d.ts.map +1 -0
  28. package/dist/process/utils.js +81 -0
  29. package/dist/process/utils.mjs +33 -0
  30. package/dist/testing/test-utils.d.ts.map +1 -1
  31. package/dist/testing/test-utils.js +4 -6
  32. package/dist/testing/test-utils.mjs +4 -6
  33. package/dist/types.d.ts +0 -2
  34. package/dist/types.d.ts.map +1 -1
  35. package/package.json +6 -1
  36. package/src/error-tracking/parsers/base.ts +0 -5
  37. package/src/error-tracking/types.ts +1 -1
  38. package/src/logger.ts +58 -0
  39. package/src/posthog-core-stateless.ts +35 -35
  40. package/src/posthog-core.ts +9 -17
  41. package/src/process/index.ts +1 -0
  42. package/src/process/spawn-local.ts +47 -0
  43. package/src/process/utils.spec.ts +11 -0
  44. package/src/process/utils.ts +41 -0
  45. package/src/testing/test-utils.ts +4 -6
  46. package/src/types.ts +0 -2
@@ -1,9 +1,4 @@
1
1
  import { StackFrame } from '../types';
2
2
  export declare const UNKNOWN_FUNCTION = "?";
3
- export declare const OPERA10_PRIORITY = 10;
4
- export declare const OPERA11_PRIORITY = 20;
5
- export declare const CHROME_PRIORITY = 30;
6
- export declare const WINJS_PRIORITY = 40;
7
- export declare const GECKO_PRIORITY = 50;
8
3
  export declare function createFrame(filename: string, func: string, lineno?: number, colno?: number): StackFrame;
9
4
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,eAAO,MAAM,eAAe,KAAK,CAAA;AACjC,eAAO,MAAM,cAAc,KAAK,CAAA;AAChC,eAAO,MAAM,cAAc,KAAK,CAAA;AAEhC,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAkBvG"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAkBvG"}
@@ -24,21 +24,11 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- OPERA10_PRIORITY: ()=>OPERA10_PRIORITY,
28
- CHROME_PRIORITY: ()=>CHROME_PRIORITY,
29
27
  UNKNOWN_FUNCTION: ()=>UNKNOWN_FUNCTION,
30
- WINJS_PRIORITY: ()=>WINJS_PRIORITY,
31
- createFrame: ()=>createFrame,
32
- OPERA11_PRIORITY: ()=>OPERA11_PRIORITY,
33
- GECKO_PRIORITY: ()=>GECKO_PRIORITY
28
+ createFrame: ()=>createFrame
34
29
  });
35
30
  const index_js_namespaceObject = require("../../utils/index.js");
36
31
  const UNKNOWN_FUNCTION = '?';
37
- const OPERA10_PRIORITY = 10;
38
- const OPERA11_PRIORITY = 20;
39
- const CHROME_PRIORITY = 30;
40
- const WINJS_PRIORITY = 40;
41
- const GECKO_PRIORITY = 50;
42
32
  function createFrame(filename, func, lineno, colno) {
43
33
  const frame = {
44
34
  platform: "web:javascript",
@@ -50,20 +40,10 @@ function createFrame(filename, func, lineno, colno) {
50
40
  if (!(0, index_js_namespaceObject.isUndefined)(colno)) frame.colno = colno;
51
41
  return frame;
52
42
  }
53
- exports.CHROME_PRIORITY = __webpack_exports__.CHROME_PRIORITY;
54
- exports.GECKO_PRIORITY = __webpack_exports__.GECKO_PRIORITY;
55
- exports.OPERA10_PRIORITY = __webpack_exports__.OPERA10_PRIORITY;
56
- exports.OPERA11_PRIORITY = __webpack_exports__.OPERA11_PRIORITY;
57
43
  exports.UNKNOWN_FUNCTION = __webpack_exports__.UNKNOWN_FUNCTION;
58
- exports.WINJS_PRIORITY = __webpack_exports__.WINJS_PRIORITY;
59
44
  exports.createFrame = __webpack_exports__.createFrame;
60
45
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
61
- "CHROME_PRIORITY",
62
- "GECKO_PRIORITY",
63
- "OPERA10_PRIORITY",
64
- "OPERA11_PRIORITY",
65
46
  "UNKNOWN_FUNCTION",
66
- "WINJS_PRIORITY",
67
47
  "createFrame"
68
48
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
69
49
  Object.defineProperty(exports, '__esModule', {
@@ -1,10 +1,5 @@
1
1
  import { isUndefined } from "../../utils/index.mjs";
2
2
  const UNKNOWN_FUNCTION = '?';
3
- const OPERA10_PRIORITY = 10;
4
- const OPERA11_PRIORITY = 20;
5
- const CHROME_PRIORITY = 30;
6
- const WINJS_PRIORITY = 40;
7
- const GECKO_PRIORITY = 50;
8
3
  function createFrame(filename, func, lineno, colno) {
9
4
  const frame = {
10
5
  platform: "web:javascript",
@@ -16,4 +11,4 @@ function createFrame(filename, func, lineno, colno) {
16
11
  if (!isUndefined(colno)) frame.colno = colno;
17
12
  return frame;
18
13
  }
19
- export { CHROME_PRIORITY, GECKO_PRIORITY, OPERA10_PRIORITY, OPERA11_PRIORITY, UNKNOWN_FUNCTION, WINJS_PRIORITY, createFrame };
14
+ export { UNKNOWN_FUNCTION, createFrame };
@@ -29,7 +29,7 @@ export interface Exception {
29
29
  export type ExceptionList = Exception[];
30
30
  export interface Mechanism {
31
31
  handled?: boolean;
32
- type?: 'generic' | 'onunhandledrejection' | 'onuncaughtexception' | 'middleware';
32
+ type?: 'generic' | 'onunhandledrejection' | 'onuncaughtexception' | 'onconsole' | 'middleware';
33
33
  source?: string;
34
34
  synthetic?: boolean;
35
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/error-tracking/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAKxC,eAAO,MAAM,cAAc,gEAAiE,CAAA;AAC5F,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG,CA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Z,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,KAAK,CAAC,EAAE,UAAU,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,eAAe,CAAA;CACxB"}
@@ -0,0 +1,11 @@
1
+ import { Logger } from './types';
2
+ type ConsoleLike = {
3
+ log: (...args: any[]) => void;
4
+ warn: (...args: any[]) => void;
5
+ error: (...args: any[]) => void;
6
+ debug: (...args: any[]) => void;
7
+ };
8
+ export declare const _createLogger: (prefix: string, maybeCall: (fn: () => void) => void, consoleLike: ConsoleLike) => Logger;
9
+ export declare function createLogger(prefix: string, maybeCall: (fn: () => void) => void): Logger;
10
+ export {};
11
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGhC,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC7B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAChC,CAAA;AAYD,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,WAAW,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,EACnC,aAAa,WAAW,KACvB,MA6BF,CAAA;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,UAE/E"}
package/dist/logger.js ADDED
@@ -0,0 +1,74 @@
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
+ createLogger: ()=>createLogger
29
+ });
30
+ function createConsole(consoleLike = console) {
31
+ const lockedMethods = {
32
+ log: consoleLike.log.bind(consoleLike),
33
+ warn: consoleLike.warn.bind(consoleLike),
34
+ error: consoleLike.error.bind(consoleLike),
35
+ debug: consoleLike.debug.bind(consoleLike)
36
+ };
37
+ return lockedMethods;
38
+ }
39
+ const _createLogger = (prefix, maybeCall, consoleLike)=>{
40
+ function _log(level, ...args) {
41
+ maybeCall(()=>{
42
+ const consoleMethod = consoleLike[level];
43
+ consoleMethod(prefix, ...args);
44
+ });
45
+ }
46
+ const logger = {
47
+ info: (...args)=>{
48
+ _log('log', ...args);
49
+ },
50
+ warn: (...args)=>{
51
+ _log('warn', ...args);
52
+ },
53
+ error: (...args)=>{
54
+ _log('error', ...args);
55
+ },
56
+ critical: (...args)=>{
57
+ consoleLike['error'](prefix, ...args);
58
+ },
59
+ createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, maybeCall, consoleLike)
60
+ };
61
+ return logger;
62
+ };
63
+ function createLogger(prefix, maybeCall) {
64
+ return _createLogger(prefix, maybeCall, createConsole());
65
+ }
66
+ exports._createLogger = __webpack_exports__._createLogger;
67
+ exports.createLogger = __webpack_exports__.createLogger;
68
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
69
+ "_createLogger",
70
+ "createLogger"
71
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
72
+ Object.defineProperty(exports, '__esModule', {
73
+ value: true
74
+ });
@@ -0,0 +1,37 @@
1
+ function createConsole(consoleLike = console) {
2
+ const lockedMethods = {
3
+ log: consoleLike.log.bind(consoleLike),
4
+ warn: consoleLike.warn.bind(consoleLike),
5
+ error: consoleLike.error.bind(consoleLike),
6
+ debug: consoleLike.debug.bind(consoleLike)
7
+ };
8
+ return lockedMethods;
9
+ }
10
+ const _createLogger = (prefix, maybeCall, consoleLike)=>{
11
+ function _log(level, ...args) {
12
+ maybeCall(()=>{
13
+ const consoleMethod = consoleLike[level];
14
+ consoleMethod(prefix, ...args);
15
+ });
16
+ }
17
+ const logger = {
18
+ info: (...args)=>{
19
+ _log('log', ...args);
20
+ },
21
+ warn: (...args)=>{
22
+ _log('warn', ...args);
23
+ },
24
+ error: (...args)=>{
25
+ _log('error', ...args);
26
+ },
27
+ critical: (...args)=>{
28
+ consoleLike['error'](prefix, ...args);
29
+ },
30
+ createLogger: (additionalPrefix)=>_createLogger(`${prefix} ${additionalPrefix}`, maybeCall, consoleLike)
31
+ };
32
+ return logger;
33
+ };
34
+ function createLogger(prefix, maybeCall) {
35
+ return _createLogger(prefix, maybeCall, createConsole());
36
+ }
37
+ export { _createLogger, createLogger };
@@ -1,5 +1,5 @@
1
1
  import { SimpleEventEmitter } from './eventemitter';
2
- import { PostHogFlagsResponse, PostHogCoreOptions, PostHogEventProperties, PostHogCaptureOptions, JsonType, PostHogRemoteConfig, FeatureFlagValue, PostHogFeatureFlagDetails, FeatureFlagDetail, SurveyResponse, PostHogFetchResponse, PostHogFetchOptions, PostHogPersistedProperty } from './types';
2
+ import { PostHogFlagsResponse, PostHogCoreOptions, PostHogEventProperties, PostHogCaptureOptions, JsonType, PostHogRemoteConfig, FeatureFlagValue, PostHogFeatureFlagDetails, FeatureFlagDetail, SurveyResponse, PostHogFetchResponse, PostHogFetchOptions, PostHogPersistedProperty, Logger } from './types';
3
3
  import { RetriableOptions } from './utils';
4
4
  export declare const maybeAdd: (key: string, value: JsonType | undefined) => Record<string, JsonType>;
5
5
  export declare function logFlushError(err: any): Promise<void>;
@@ -34,6 +34,7 @@ export declare abstract class PostHogCoreStateless {
34
34
  protected _initPromise: Promise<void>;
35
35
  protected _isInitialized: boolean;
36
36
  protected _remoteConfigResponsePromise?: Promise<PostHogRemoteConfig | undefined>;
37
+ protected _logger: Logger;
37
38
  abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
38
39
  abstract getLibraryId(): string;
39
40
  abstract getLibraryVersion(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAEzB,MAAM,SAAS,CAAA;AAChB,OAAO,EAOL,gBAAgB,EAGjB,MAAM,SAAS,CAAA;AAqChB,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAO,QAAQ,GAAG,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AAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD;;SAEK;IACL,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI;cAgCrE,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+C1G,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,eAAe;IAOvB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;YAazC,MAAM;YA0FN,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
@@ -32,6 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  const external_eventemitter_js_namespaceObject = require("./eventemitter.js");
33
33
  const external_featureFlagUtils_js_namespaceObject = require("./featureFlagUtils.js");
34
34
  const external_gzip_js_namespaceObject = require("./gzip.js");
35
+ const external_logger_js_namespaceObject = require("./logger.js");
35
36
  const external_types_js_namespaceObject = require("./types.js");
36
37
  const index_js_namespaceObject = require("./utils/index.js");
37
38
  const uuidv7_js_namespaceObject = require("./vendor/uuidv7.js");
@@ -81,7 +82,7 @@ var posthog_core_stateless_QuotaLimitedFeature = /*#__PURE__*/ function(QuotaLim
81
82
  return QuotaLimitedFeature;
82
83
  }({});
83
84
  class PostHogCoreStateless {
84
- constructor(apiKey, options){
85
+ constructor(apiKey, options = {}){
85
86
  this.flushPromise = null;
86
87
  this.shutdownPromise = null;
87
88
  this.promiseQueue = new index_js_namespaceObject.PromiseQueue();
@@ -89,34 +90,35 @@ class PostHogCoreStateless {
89
90
  this._isInitialized = false;
90
91
  (0, index_js_namespaceObject.assert)(apiKey, "You must pass your PostHog project's api key.");
91
92
  this.apiKey = apiKey;
92
- this.host = (0, index_js_namespaceObject.removeTrailingSlash)(options?.host || 'https://us.i.posthog.com');
93
- this.flushAt = options?.flushAt ? Math.max(options?.flushAt, 1) : 20;
94
- this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100);
95
- this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000);
96
- this.flushInterval = options?.flushInterval ?? 10000;
97
- this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true;
98
- this.defaultOptIn = options?.defaultOptIn ?? true;
99
- this.disableSurveys = options?.disableSurveys ?? false;
93
+ this.host = (0, index_js_namespaceObject.removeTrailingSlash)(options.host || 'https://us.i.posthog.com');
94
+ this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
95
+ this.maxBatchSize = Math.max(this.flushAt, options.maxBatchSize ?? 100);
96
+ this.maxQueueSize = Math.max(this.flushAt, options.maxQueueSize ?? 1000);
97
+ this.flushInterval = options.flushInterval ?? 10000;
98
+ this.preloadFeatureFlags = options.preloadFeatureFlags ?? true;
99
+ this.defaultOptIn = options.defaultOptIn ?? true;
100
+ this.disableSurveys = options.disableSurveys ?? false;
100
101
  this._retryOptions = {
101
- retryCount: options?.fetchRetryCount ?? 3,
102
- retryDelay: options?.fetchRetryDelay ?? 3000,
102
+ retryCount: options.fetchRetryCount ?? 3,
103
+ retryDelay: options.fetchRetryDelay ?? 3000,
103
104
  retryCheck: isPostHogFetchError
104
105
  };
105
- this.requestTimeout = options?.requestTimeout ?? 10000;
106
- this.featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 3000;
107
- this.remoteConfigRequestTimeoutMs = options?.remoteConfigRequestTimeoutMs ?? 3000;
108
- this.disableGeoip = options?.disableGeoip ?? true;
109
- this.disabled = options?.disabled ?? false;
106
+ this.requestTimeout = options.requestTimeout ?? 10000;
107
+ this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
108
+ this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
109
+ this.disableGeoip = options.disableGeoip ?? true;
110
+ this.disabled = options.disabled ?? false;
110
111
  this.historicalMigration = options?.historicalMigration ?? false;
111
112
  this._initPromise = Promise.resolve();
112
113
  this._isInitialized = true;
114
+ this._logger = (0, external_logger_js_namespaceObject.createLogger)('[PostHog]', this.logMsgIfDebug.bind(this));
113
115
  this.disableCompression = !(0, external_gzip_js_namespaceObject.isGzipSupported)() || (options?.disableCompression ?? false);
114
116
  }
115
117
  logMsgIfDebug(fn) {
116
118
  if (this.isDebug) fn();
117
119
  }
118
120
  wrap(fn) {
119
- if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
121
+ if (this.disabled) return void this._logger.warn('The client is disabled');
120
122
  if (this._isInitialized) return fn();
121
123
  this._initPromise.then(()=>fn());
122
124
  }
@@ -145,7 +147,7 @@ class PostHogCoreStateless {
145
147
  debug(enabled = true) {
146
148
  this.removeDebugCallback?.();
147
149
  if (enabled) {
148
- const removeDebugCallback = this.on('*', (event, payload)=>console.log('PostHog Debug', event, payload));
150
+ const removeDebugCallback = this.on('*', (event, payload)=>this._logger.info(event, payload));
149
151
  this.removeDebugCallback = ()=>{
150
152
  removeDebugCallback();
151
153
  this.removeDebugCallback = void 0;
@@ -268,7 +270,7 @@ class PostHogCoreStateless {
268
270
  return this.fetchWithRetry(url, fetchOptions, {
269
271
  retryCount: 0
270
272
  }, this.remoteConfigRequestTimeoutMs).then((response)=>response.json()).catch((error)=>{
271
- this.logMsgIfDebug(()=>console.error('Remote config could not be loaded', error));
273
+ this._logger.error('Remote config could not be loaded', error);
272
274
  this._events.emit('error', error);
273
275
  });
274
276
  }
@@ -290,7 +292,7 @@ class PostHogCoreStateless {
290
292
  ...extraPayload
291
293
  })
292
294
  };
293
- this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Flags URL', url));
295
+ this._logger.info('Flags URL', url);
294
296
  return this.fetchWithRetry(url, fetchOptions, {
295
297
  retryCount: 0
296
298
  }, this.featureFlagsRequestTimeoutMs).then((response)=>response.json()).then((response)=>(0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(response)).catch((error)=>{
@@ -379,7 +381,7 @@ class PostHogCoreStateless {
379
381
  async getSurveysStateless() {
380
382
  await this._initPromise;
381
383
  if (true === this.disableSurveys) {
382
- this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Loading surveys is disabled.'));
384
+ this._logger.info('Loading surveys is disabled.');
383
385
  return [];
384
386
  }
385
387
  const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
@@ -394,17 +396,17 @@ class PostHogCoreStateless {
394
396
  if (200 !== response.status || !response.json) {
395
397
  const msg = `Surveys API could not be loaded: ${response.status}`;
396
398
  const error = new Error(msg);
397
- this.logMsgIfDebug(()=>console.error(error));
399
+ this._logger.error(error);
398
400
  this._events.emit('error', new Error(msg));
399
401
  return;
400
402
  }
401
403
  return response.json();
402
404
  }).catch((error)=>{
403
- this.logMsgIfDebug(()=>console.error('Surveys API could not be loaded', error));
405
+ this._logger.error('Surveys API could not be loaded', error);
404
406
  this._events.emit('error', error);
405
407
  });
406
408
  const newSurveys = response?.surveys;
407
- if (newSurveys) this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Surveys fetched from API: ', JSON.stringify(newSurveys)));
409
+ if (newSurveys) this._logger.info('Surveys fetched from API: ', JSON.stringify(newSurveys));
408
410
  return newSurveys ?? [];
409
411
  }
410
412
  get props() {
@@ -436,7 +438,7 @@ class PostHogCoreStateless {
436
438
  const queue = this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.Queue) || [];
437
439
  if (queue.length >= this.maxQueueSize) {
438
440
  queue.shift();
439
- this.logMsgIfDebug(()=>console.info('Queue is full, the oldest event is dropped.'));
441
+ this._logger.info('Queue is full, the oldest event is dropped.');
440
442
  }
441
443
  queue.push({
442
444
  message
@@ -448,7 +450,7 @@ class PostHogCoreStateless {
448
450
  });
449
451
  }
450
452
  async sendImmediate(type, _message, options) {
451
- if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
453
+ if (this.disabled) return void this._logger.warn('The client is disabled');
452
454
  if (!this._isInitialized) await this._initPromise;
453
455
  if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
454
456
  const data = {
@@ -576,7 +578,7 @@ class PostHogCoreStateless {
576
578
  } catch (err) {
577
579
  if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
578
580
  this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
579
- this.logMsgIfDebug(()=>console.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`));
581
+ this._logger.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`);
580
582
  continue;
581
583
  }
582
584
  if (!(err instanceof PostHogFetchNetworkError)) persistQueueChange();
@@ -644,7 +646,7 @@ class PostHogCoreStateless {
644
646
  return Promise.race([
645
647
  new Promise((_, reject)=>{
646
648
  (0, index_js_namespaceObject.safeSetTimeout)(()=>{
647
- this.logMsgIfDebug(()=>console.error('Timed out while shutting down PostHog'));
649
+ this._logger.error('Timed out while shutting down PostHog');
648
650
  hasTimedOut = true;
649
651
  reject('Timeout while shutting down PostHog. Some events may not have been sent.');
650
652
  }, shutdownTimeoutMs);
@@ -653,7 +655,7 @@ class PostHogCoreStateless {
653
655
  ]);
654
656
  }
655
657
  async shutdown(shutdownTimeoutMs = 30000) {
656
- if (this.shutdownPromise) this.logMsgIfDebug(()=>console.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup'));
658
+ if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
657
659
  else this.shutdownPromise = this._shutdown(shutdownTimeoutMs).finally(()=>{
658
660
  this.shutdownPromise = null;
659
661
  });
@@ -1,6 +1,7 @@
1
1
  import { SimpleEventEmitter } from "./eventemitter.mjs";
2
2
  import { getFeatureFlagValue, normalizeFlagsResponse } from "./featureFlagUtils.mjs";
3
3
  import { gzipCompress, isGzipSupported } from "./gzip.mjs";
4
+ import { createLogger } from "./logger.mjs";
4
5
  import { PostHogPersistedProperty } from "./types.mjs";
5
6
  import { PromiseQueue, STRING_FORMAT, allSettled, assert, currentISOTime, removeTrailingSlash, retriable, safeSetTimeout } from "./utils/index.mjs";
6
7
  import { uuidv7 } from "./vendor/uuidv7.mjs";
@@ -50,7 +51,7 @@ var posthog_core_stateless_QuotaLimitedFeature = /*#__PURE__*/ function(QuotaLim
50
51
  return QuotaLimitedFeature;
51
52
  }({});
52
53
  class PostHogCoreStateless {
53
- constructor(apiKey, options){
54
+ constructor(apiKey, options = {}){
54
55
  this.flushPromise = null;
55
56
  this.shutdownPromise = null;
56
57
  this.promiseQueue = new PromiseQueue();
@@ -58,34 +59,35 @@ class PostHogCoreStateless {
58
59
  this._isInitialized = false;
59
60
  assert(apiKey, "You must pass your PostHog project's api key.");
60
61
  this.apiKey = apiKey;
61
- this.host = removeTrailingSlash(options?.host || 'https://us.i.posthog.com');
62
- this.flushAt = options?.flushAt ? Math.max(options?.flushAt, 1) : 20;
63
- this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100);
64
- this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000);
65
- this.flushInterval = options?.flushInterval ?? 10000;
66
- this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true;
67
- this.defaultOptIn = options?.defaultOptIn ?? true;
68
- this.disableSurveys = options?.disableSurveys ?? false;
62
+ this.host = removeTrailingSlash(options.host || 'https://us.i.posthog.com');
63
+ this.flushAt = options.flushAt ? Math.max(options.flushAt, 1) : 20;
64
+ this.maxBatchSize = Math.max(this.flushAt, options.maxBatchSize ?? 100);
65
+ this.maxQueueSize = Math.max(this.flushAt, options.maxQueueSize ?? 1000);
66
+ this.flushInterval = options.flushInterval ?? 10000;
67
+ this.preloadFeatureFlags = options.preloadFeatureFlags ?? true;
68
+ this.defaultOptIn = options.defaultOptIn ?? true;
69
+ this.disableSurveys = options.disableSurveys ?? false;
69
70
  this._retryOptions = {
70
- retryCount: options?.fetchRetryCount ?? 3,
71
- retryDelay: options?.fetchRetryDelay ?? 3000,
71
+ retryCount: options.fetchRetryCount ?? 3,
72
+ retryDelay: options.fetchRetryDelay ?? 3000,
72
73
  retryCheck: isPostHogFetchError
73
74
  };
74
- this.requestTimeout = options?.requestTimeout ?? 10000;
75
- this.featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 3000;
76
- this.remoteConfigRequestTimeoutMs = options?.remoteConfigRequestTimeoutMs ?? 3000;
77
- this.disableGeoip = options?.disableGeoip ?? true;
78
- this.disabled = options?.disabled ?? false;
75
+ this.requestTimeout = options.requestTimeout ?? 10000;
76
+ this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
77
+ this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
78
+ this.disableGeoip = options.disableGeoip ?? true;
79
+ this.disabled = options.disabled ?? false;
79
80
  this.historicalMigration = options?.historicalMigration ?? false;
80
81
  this._initPromise = Promise.resolve();
81
82
  this._isInitialized = true;
83
+ this._logger = createLogger('[PostHog]', this.logMsgIfDebug.bind(this));
82
84
  this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false);
83
85
  }
84
86
  logMsgIfDebug(fn) {
85
87
  if (this.isDebug) fn();
86
88
  }
87
89
  wrap(fn) {
88
- if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
90
+ if (this.disabled) return void this._logger.warn('The client is disabled');
89
91
  if (this._isInitialized) return fn();
90
92
  this._initPromise.then(()=>fn());
91
93
  }
@@ -114,7 +116,7 @@ class PostHogCoreStateless {
114
116
  debug(enabled = true) {
115
117
  this.removeDebugCallback?.();
116
118
  if (enabled) {
117
- const removeDebugCallback = this.on('*', (event, payload)=>console.log('PostHog Debug', event, payload));
119
+ const removeDebugCallback = this.on('*', (event, payload)=>this._logger.info(event, payload));
118
120
  this.removeDebugCallback = ()=>{
119
121
  removeDebugCallback();
120
122
  this.removeDebugCallback = void 0;
@@ -237,7 +239,7 @@ class PostHogCoreStateless {
237
239
  return this.fetchWithRetry(url, fetchOptions, {
238
240
  retryCount: 0
239
241
  }, this.remoteConfigRequestTimeoutMs).then((response)=>response.json()).catch((error)=>{
240
- this.logMsgIfDebug(()=>console.error('Remote config could not be loaded', error));
242
+ this._logger.error('Remote config could not be loaded', error);
241
243
  this._events.emit('error', error);
242
244
  });
243
245
  }
@@ -259,7 +261,7 @@ class PostHogCoreStateless {
259
261
  ...extraPayload
260
262
  })
261
263
  };
262
- this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Flags URL', url));
264
+ this._logger.info('Flags URL', url);
263
265
  return this.fetchWithRetry(url, fetchOptions, {
264
266
  retryCount: 0
265
267
  }, this.featureFlagsRequestTimeoutMs).then((response)=>response.json()).then((response)=>normalizeFlagsResponse(response)).catch((error)=>{
@@ -348,7 +350,7 @@ class PostHogCoreStateless {
348
350
  async getSurveysStateless() {
349
351
  await this._initPromise;
350
352
  if (true === this.disableSurveys) {
351
- this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Loading surveys is disabled.'));
353
+ this._logger.info('Loading surveys is disabled.');
352
354
  return [];
353
355
  }
354
356
  const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
@@ -363,17 +365,17 @@ class PostHogCoreStateless {
363
365
  if (200 !== response.status || !response.json) {
364
366
  const msg = `Surveys API could not be loaded: ${response.status}`;
365
367
  const error = new Error(msg);
366
- this.logMsgIfDebug(()=>console.error(error));
368
+ this._logger.error(error);
367
369
  this._events.emit('error', new Error(msg));
368
370
  return;
369
371
  }
370
372
  return response.json();
371
373
  }).catch((error)=>{
372
- this.logMsgIfDebug(()=>console.error('Surveys API could not be loaded', error));
374
+ this._logger.error('Surveys API could not be loaded', error);
373
375
  this._events.emit('error', error);
374
376
  });
375
377
  const newSurveys = response?.surveys;
376
- if (newSurveys) this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Surveys fetched from API: ', JSON.stringify(newSurveys)));
378
+ if (newSurveys) this._logger.info('Surveys fetched from API: ', JSON.stringify(newSurveys));
377
379
  return newSurveys ?? [];
378
380
  }
379
381
  get props() {
@@ -405,7 +407,7 @@ class PostHogCoreStateless {
405
407
  const queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
406
408
  if (queue.length >= this.maxQueueSize) {
407
409
  queue.shift();
408
- this.logMsgIfDebug(()=>console.info('Queue is full, the oldest event is dropped.'));
410
+ this._logger.info('Queue is full, the oldest event is dropped.');
409
411
  }
410
412
  queue.push({
411
413
  message
@@ -417,7 +419,7 @@ class PostHogCoreStateless {
417
419
  });
418
420
  }
419
421
  async sendImmediate(type, _message, options) {
420
- if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
422
+ if (this.disabled) return void this._logger.warn('The client is disabled');
421
423
  if (!this._isInitialized) await this._initPromise;
422
424
  if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
423
425
  const data = {
@@ -545,7 +547,7 @@ class PostHogCoreStateless {
545
547
  } catch (err) {
546
548
  if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
547
549
  this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
548
- this.logMsgIfDebug(()=>console.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`));
550
+ this._logger.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`);
549
551
  continue;
550
552
  }
551
553
  if (!(err instanceof PostHogFetchNetworkError)) persistQueueChange();
@@ -613,7 +615,7 @@ class PostHogCoreStateless {
613
615
  return Promise.race([
614
616
  new Promise((_, reject)=>{
615
617
  safeSetTimeout(()=>{
616
- this.logMsgIfDebug(()=>console.error('Timed out while shutting down PostHog'));
618
+ this._logger.error('Timed out while shutting down PostHog');
617
619
  hasTimedOut = true;
618
620
  reject('Timeout while shutting down PostHog. Some events may not have been sent.');
619
621
  }, shutdownTimeoutMs);
@@ -622,7 +624,7 @@ class PostHogCoreStateless {
622
624
  ]);
623
625
  }
624
626
  async shutdown(shutdownTimeoutMs = 30000) {
625
- if (this.shutdownPromise) this.logMsgIfDebug(()=>console.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup'));
627
+ if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
626
628
  else this.shutdownPromise = this._shutdown(shutdownTimeoutMs).finally(()=>{
627
629
  this.shutdownPromise = null;
628
630
  });