@posthog/browser-common 0.8.1 → 0.8.2
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 +1 -1
- package/dist/config.mjs +1 -1
- package/dist/utils/general-utils.d.ts +4 -0
- package/dist/utils/general-utils.js +19 -1
- package/dist/utils/general-utils.mjs +18 -3
- package/dist/utils/request-utils.js +9 -1
- package/dist/utils/request-utils.mjs +11 -3
- package/package.json +1 -1
package/dist/config.js
CHANGED
package/dist/config.mjs
CHANGED
|
@@ -12,6 +12,10 @@ 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,
|
|
@@ -98,6 +99,21 @@ const stripEmptyProperties = function(p) {
|
|
|
98
99
|
});
|
|
99
100
|
return ret;
|
|
100
101
|
};
|
|
102
|
+
function errorToProperties(error) {
|
|
103
|
+
const copy = {
|
|
104
|
+
...error
|
|
105
|
+
};
|
|
106
|
+
for (const detail of [
|
|
107
|
+
'name',
|
|
108
|
+
'message',
|
|
109
|
+
'stack',
|
|
110
|
+
'cause',
|
|
111
|
+
'errors'
|
|
112
|
+
])try {
|
|
113
|
+
if (detail in error) copy[detail] = error[detail];
|
|
114
|
+
} catch {}
|
|
115
|
+
return copy;
|
|
116
|
+
}
|
|
101
117
|
function deepCircularCopy(value, customizer) {
|
|
102
118
|
const COPY_IN_PROGRESS_SET = new Set();
|
|
103
119
|
function internalDeepCircularCopy(value, key) {
|
|
@@ -112,7 +128,7 @@ function deepCircularCopy(value, customizer) {
|
|
|
112
128
|
});
|
|
113
129
|
} else {
|
|
114
130
|
const copy = {};
|
|
115
|
-
each(value, (val, key)=>{
|
|
131
|
+
each((0, core_namespaceObject.isError)(value) ? errorToProperties(value) : value, (val, key)=>{
|
|
116
132
|
if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
|
|
117
133
|
});
|
|
118
134
|
result = copy;
|
|
@@ -165,6 +181,7 @@ exports.addEventListener = __webpack_exports__.addEventListener;
|
|
|
165
181
|
exports.each = __webpack_exports__.each;
|
|
166
182
|
exports.eachArray = __webpack_exports__.eachArray;
|
|
167
183
|
exports.entries = __webpack_exports__.entries;
|
|
184
|
+
exports.errorToProperties = __webpack_exports__.errorToProperties;
|
|
168
185
|
exports.extend = __webpack_exports__.extend;
|
|
169
186
|
exports.find = __webpack_exports__.find;
|
|
170
187
|
exports.isCrossDomainCookie = __webpack_exports__.isCrossDomainCookie;
|
|
@@ -180,6 +197,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
180
197
|
"each",
|
|
181
198
|
"eachArray",
|
|
182
199
|
"entries",
|
|
200
|
+
"errorToProperties",
|
|
183
201
|
"extend",
|
|
184
202
|
"find",
|
|
185
203
|
"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 } 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];
|
|
@@ -53,6 +53,21 @@ const stripEmptyProperties = function(p) {
|
|
|
53
53
|
});
|
|
54
54
|
return ret;
|
|
55
55
|
};
|
|
56
|
+
function errorToProperties(error) {
|
|
57
|
+
const copy = {
|
|
58
|
+
...error
|
|
59
|
+
};
|
|
60
|
+
for (const detail of [
|
|
61
|
+
'name',
|
|
62
|
+
'message',
|
|
63
|
+
'stack',
|
|
64
|
+
'cause',
|
|
65
|
+
'errors'
|
|
66
|
+
])try {
|
|
67
|
+
if (detail in error) copy[detail] = error[detail];
|
|
68
|
+
} catch {}
|
|
69
|
+
return copy;
|
|
70
|
+
}
|
|
56
71
|
function deepCircularCopy(value, customizer) {
|
|
57
72
|
const COPY_IN_PROGRESS_SET = new Set();
|
|
58
73
|
function internalDeepCircularCopy(value, key) {
|
|
@@ -67,7 +82,7 @@ function deepCircularCopy(value, customizer) {
|
|
|
67
82
|
});
|
|
68
83
|
} else {
|
|
69
84
|
const copy = {};
|
|
70
|
-
each(value, (val, key)=>{
|
|
85
|
+
each(isError(value) ? errorToProperties(value) : value, (val, key)=>{
|
|
71
86
|
if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
|
|
72
87
|
});
|
|
73
88
|
result = copy;
|
|
@@ -115,4 +130,4 @@ const TOOLBAR_INTERNAL_INSTANCE_NAME = 'ph_toolbar_internal';
|
|
|
115
130
|
function isToolbarInstance(config) {
|
|
116
131
|
return config.name === TOOLBAR_INTERNAL_INSTANCE_NAME;
|
|
117
132
|
}
|
|
118
|
-
export { _copyAndTruncateStrings, addEventListener, each, eachArray, entries, extend, find, isCrossDomainCookie, isToolbarInstance, migrateConfigField, safewrap, safewrapClass, stripEmptyProperties, trySafe };
|
|
133
|
+
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
|
-
|
|
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
|
-
|
|
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
|
}
|