@posthog/browser-common 0.8.1 → 0.8.3

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/dist/config.js CHANGED
@@ -27,7 +27,7 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- const packageVersion = "0.8.1";
30
+ const packageVersion = "0.8.3";
31
31
  const Config = {
32
32
  DEBUG: false,
33
33
  LIB_VERSION: packageVersion,
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const packageVersion = "0.8.1";
1
+ const packageVersion = "0.8.3";
2
2
  const Config = {
3
3
  DEBUG: false,
4
4
  LIB_VERSION: packageVersion,
@@ -1,4 +1,5 @@
1
1
  import type { PostHogConfig, Properties } from '@posthog/types';
2
+ export { trySafe } from '@posthog/core';
2
3
  export declare function find<T>(value: T[], predicate: (value: T) => boolean): T | undefined;
3
4
  export declare function eachArray<E = any>(obj: E[] | null | undefined, iterator: (value: E, key: number) => void): void;
4
5
  export declare function each(obj: any, iterator: (value: any, key: any) => void): void;
@@ -8,10 +9,13 @@ export declare const extend: (obj: Record<string, any>, ...args: Record<string,
8
9
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
9
10
  */
10
11
  export declare function entries<T = any>(obj: Record<string, T>): [string, T][];
11
- export declare const trySafe: <T>(fn: () => T) => T | undefined;
12
12
  export declare const safewrap: <F extends (...args: any[]) => any = (...args: any[]) => any>(f: F) => F;
13
13
  export declare const safewrapClass: (klass: Function, functions: string[]) => void;
14
14
  export declare const stripEmptyProperties: (p: Properties) => Properties;
15
+ export declare function errorToProperties(error: Error & {
16
+ cause?: unknown;
17
+ errors?: unknown;
18
+ }): Record<string, unknown>;
15
19
  export declare function _copyAndTruncateStrings<T extends Record<string, any> = Record<string, any>>(object: T, maxStringLength: number): T;
16
20
  export declare function isCrossDomainCookie(documentLocation: Location | undefined): boolean;
17
21
  export declare function addEventListener(element: Window | Document | Element | undefined, event: string, callback: EventListener, options?: AddEventListenerOptions): void;
@@ -33,6 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  each: ()=>each,
34
34
  eachArray: ()=>eachArray,
35
35
  entries: ()=>entries,
36
+ errorToProperties: ()=>errorToProperties,
36
37
  extend: ()=>extend,
37
38
  find: ()=>find,
38
39
  isCrossDomainCookie: ()=>isCrossDomainCookie,
@@ -41,7 +42,7 @@ __webpack_require__.d(__webpack_exports__, {
41
42
  safewrap: ()=>safewrap,
42
43
  safewrapClass: ()=>safewrapClass,
43
44
  stripEmptyProperties: ()=>stripEmptyProperties,
44
- trySafe: ()=>trySafe
45
+ trySafe: ()=>core_namespaceObject.trySafe
45
46
  });
46
47
  const core_namespaceObject = require("@posthog/core");
47
48
  const external_logger_js_namespaceObject = require("./logger.js");
@@ -71,13 +72,6 @@ function entries(obj) {
71
72
  ];
72
73
  return resArray;
73
74
  }
74
- const trySafe = function(fn) {
75
- try {
76
- return fn();
77
- } catch {
78
- return;
79
- }
80
- };
81
75
  const safewrap = function(f) {
82
76
  return function(...args) {
83
77
  try {
@@ -98,6 +92,21 @@ const stripEmptyProperties = function(p) {
98
92
  });
99
93
  return ret;
100
94
  };
95
+ function errorToProperties(error) {
96
+ const copy = {
97
+ ...error
98
+ };
99
+ for (const detail of [
100
+ 'name',
101
+ 'message',
102
+ 'stack',
103
+ 'cause',
104
+ 'errors'
105
+ ])try {
106
+ if (detail in error) copy[detail] = error[detail];
107
+ } catch {}
108
+ return copy;
109
+ }
101
110
  function deepCircularCopy(value, customizer) {
102
111
  const COPY_IN_PROGRESS_SET = new Set();
103
112
  function internalDeepCircularCopy(value, key) {
@@ -112,7 +121,7 @@ function deepCircularCopy(value, customizer) {
112
121
  });
113
122
  } else {
114
123
  const copy = {};
115
- each(value, (val, key)=>{
124
+ each((0, core_namespaceObject.isError)(value) ? errorToProperties(value) : value, (val, key)=>{
116
125
  if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
117
126
  });
118
127
  result = copy;
@@ -165,6 +174,7 @@ exports.addEventListener = __webpack_exports__.addEventListener;
165
174
  exports.each = __webpack_exports__.each;
166
175
  exports.eachArray = __webpack_exports__.eachArray;
167
176
  exports.entries = __webpack_exports__.entries;
177
+ exports.errorToProperties = __webpack_exports__.errorToProperties;
168
178
  exports.extend = __webpack_exports__.extend;
169
179
  exports.find = __webpack_exports__.find;
170
180
  exports.isCrossDomainCookie = __webpack_exports__.isCrossDomainCookie;
@@ -180,6 +190,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
180
190
  "each",
181
191
  "eachArray",
182
192
  "entries",
193
+ "errorToProperties",
183
194
  "extend",
184
195
  "find",
185
196
  "isCrossDomainCookie",
@@ -1,4 +1,4 @@
1
- import { hasOwnProperty as core_hasOwnProperty, isArray, isFormData, isNullish, isNumber, isString } from "@posthog/core";
1
+ import { hasOwnProperty as core_hasOwnProperty, isArray, isError, isFormData, isNullish, isNumber, isString, trySafe } from "@posthog/core";
2
2
  import { logger } from "./logger.mjs";
3
3
  function find(value, predicate) {
4
4
  for(let i = 0; i < value.length; i++)if (predicate(value[i])) return value[i];
@@ -26,13 +26,6 @@ function entries(obj) {
26
26
  ];
27
27
  return resArray;
28
28
  }
29
- const trySafe = function(fn) {
30
- try {
31
- return fn();
32
- } catch {
33
- return;
34
- }
35
- };
36
29
  const safewrap = function(f) {
37
30
  return function(...args) {
38
31
  try {
@@ -53,6 +46,21 @@ const stripEmptyProperties = function(p) {
53
46
  });
54
47
  return ret;
55
48
  };
49
+ function errorToProperties(error) {
50
+ const copy = {
51
+ ...error
52
+ };
53
+ for (const detail of [
54
+ 'name',
55
+ 'message',
56
+ 'stack',
57
+ 'cause',
58
+ 'errors'
59
+ ])try {
60
+ if (detail in error) copy[detail] = error[detail];
61
+ } catch {}
62
+ return copy;
63
+ }
56
64
  function deepCircularCopy(value, customizer) {
57
65
  const COPY_IN_PROGRESS_SET = new Set();
58
66
  function internalDeepCircularCopy(value, key) {
@@ -67,7 +75,7 @@ function deepCircularCopy(value, customizer) {
67
75
  });
68
76
  } else {
69
77
  const copy = {};
70
- each(value, (val, key)=>{
78
+ each(isError(value) ? errorToProperties(value) : value, (val, key)=>{
71
79
  if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
72
80
  });
73
81
  result = copy;
@@ -115,4 +123,4 @@ const TOOLBAR_INTERNAL_INSTANCE_NAME = 'ph_toolbar_internal';
115
123
  function isToolbarInstance(config) {
116
124
  return config.name === TOOLBAR_INTERNAL_INSTANCE_NAME;
117
125
  }
118
- export { _copyAndTruncateStrings, addEventListener, each, eachArray, entries, extend, find, isCrossDomainCookie, isToolbarInstance, migrateConfigField, safewrap, safewrapClass, stripEmptyProperties, trySafe };
126
+ export { _copyAndTruncateStrings, addEventListener, each, eachArray, entries, errorToProperties, extend, find, isCrossDomainCookie, isToolbarInstance, migrateConfigField, safewrap, safewrapClass, stripEmptyProperties, trySafe };
@@ -48,7 +48,15 @@ const localDomains = [
48
48
  ];
49
49
  const jsonStringify = (data, space)=>{
50
50
  try {
51
- return JSON.stringify(data, (_, value)=>'bigint' == typeof value ? value.toString() : value, space);
51
+ let errors;
52
+ return JSON.stringify(data, (_, value)=>{
53
+ if ((0, core_namespaceObject.isError)(value)) {
54
+ errors ??= new WeakMap();
55
+ if (!errors.has(value)) errors.set(value, (0, external_general_utils_js_namespaceObject.errorToProperties)(value));
56
+ return errors.get(value);
57
+ }
58
+ return 'bigint' == typeof value ? value.toString() : value;
59
+ }, space);
52
60
  } catch {
53
61
  return (0, core_namespaceObject.safeJsonStringify)(data);
54
62
  }
@@ -1,5 +1,5 @@
1
- import { isArray, isFile, isUndefined, safeJsonStringify } from "@posthog/core";
2
- import { each } from "./general-utils.mjs";
1
+ import { isArray, isError, isFile, isUndefined, safeJsonStringify } from "@posthog/core";
2
+ import { each, errorToProperties } from "./general-utils.mjs";
3
3
  import { document as external_globals_mjs_document, isBrowserOnline, location as external_globals_mjs_location } from "./globals.mjs";
4
4
  import { logger } from "./logger.mjs";
5
5
  const localDomains = [
@@ -8,7 +8,15 @@ const localDomains = [
8
8
  ];
9
9
  const jsonStringify = (data, space)=>{
10
10
  try {
11
- return JSON.stringify(data, (_, value)=>'bigint' == typeof value ? value.toString() : value, space);
11
+ let errors;
12
+ return JSON.stringify(data, (_, value)=>{
13
+ if (isError(value)) {
14
+ errors ??= new WeakMap();
15
+ if (!errors.has(value)) errors.set(value, errorToProperties(value));
16
+ return errors.get(value);
17
+ }
18
+ return 'bigint' == typeof value ? value.toString() : value;
19
+ }, space);
12
20
  } catch {
13
21
  return safeJsonStringify(data);
14
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -73,8 +73,8 @@
73
73
  }
74
74
  },
75
75
  "dependencies": {
76
- "@posthog/core": "^1.51.0",
77
- "@posthog/types": "^1.409.1"
76
+ "@posthog/types": "^1.411.1",
77
+ "@posthog/core": "^1.53.2"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@rslib/core": "0.23.2",
@@ -90,7 +90,7 @@
90
90
  "build": "rslib build",
91
91
  "dev": "rslib build -w",
92
92
  "test:unit": "vitest run",
93
- "check-types": "pnpm build",
93
+ "check-types": "tsc --noEmit --project tsconfig.build.json",
94
94
  "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
95
95
  }
96
96
  }