@posthog/core 1.39.1 → 1.39.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/error-tracking/exception-steps.d.ts.map +1 -1
- package/dist/error-tracking/exception-steps.js +6 -24
- package/dist/error-tracking/exception-steps.mjs +7 -25
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +2 -2
- package/dist/posthog-core-stateless.mjs +3 -3
- package/dist/utils/string-utils.d.ts +1 -0
- package/dist/utils/string-utils.d.ts.map +1 -1
- package/dist/utils/string-utils.js +21 -0
- package/dist/utils/string-utils.mjs +19 -1
- package/package.json +1 -1
- package/src/error-tracking/exception-steps.ts +5 -42
- package/src/posthog-core-stateless.ts +3 -2
- package/src/utils/string-utils.spec.ts +38 -1
- package/src/utils/string-utils.ts +42 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-steps.d.ts","sourceRoot":"","sources":["../../src/error-tracking/exception-steps.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B;;;CAGjC,CAAA;AAOV,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,8BAA8B,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChD,CAAC,8BAA8B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,kGAAkG;AAClG,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,4BAG5C,CAAA;AAED,wBAAgB,2BAA2B,CAAC,MAAM,CAAC,EAAE,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,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,4BAG5C,CAAA;AAED,wBAAgB,2BAA2B,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,4BAA4B,CAS9G;AAED,wBAAgB,gCAAgC,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG;IAC7F,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5C,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB,CAmBA;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,WAAW,CAAY;IAC/B,OAAO,CAAC,OAAO,CAA8B;gBAEjC,MAAM,CAAC,EAAE,oBAAoB,GAAG,IAAI;IAIzC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,IAAI;IAKrD,GAAG,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;IAgB9B,aAAa,IAAI,aAAa,EAAE;IAIhC,KAAK,IAAI,IAAI;IAKb,IAAI,IAAI,MAAM;IAIrB,OAAO,CAAC,eAAe;CAQxB;AAkDD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBvD"}
|
|
@@ -118,8 +118,12 @@ function normalizePositiveInteger(input, fallback) {
|
|
|
118
118
|
return normalized;
|
|
119
119
|
}
|
|
120
120
|
function normalizeAndSerializeStep(step) {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
let json;
|
|
122
|
+
try {
|
|
123
|
+
json = (0, index_js_namespaceObject.safeJsonStringify)(step);
|
|
124
|
+
} catch {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
123
127
|
try {
|
|
124
128
|
const parsed = JSON.parse(json);
|
|
125
129
|
if (!(0, index_js_namespaceObject.isObject)(parsed)) return;
|
|
@@ -136,28 +140,6 @@ function normalizeAndSerializeStep(step) {
|
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
|
-
function safeStringify(value) {
|
|
140
|
-
const seen = new WeakSet();
|
|
141
|
-
try {
|
|
142
|
-
return JSON.stringify(value, (_key, replacementValue)=>{
|
|
143
|
-
if ('bigint' == typeof replacementValue) return replacementValue.toString();
|
|
144
|
-
if ('function' == typeof replacementValue || 'symbol' == typeof replacementValue) return;
|
|
145
|
-
if (replacementValue instanceof Date) return replacementValue.toISOString();
|
|
146
|
-
if (replacementValue instanceof Error) return {
|
|
147
|
-
name: replacementValue.name,
|
|
148
|
-
message: replacementValue.message,
|
|
149
|
-
stack: replacementValue.stack
|
|
150
|
-
};
|
|
151
|
-
if (replacementValue && 'object' == typeof replacementValue) {
|
|
152
|
-
if (seen.has(replacementValue)) return '[Circular]';
|
|
153
|
-
seen.add(replacementValue);
|
|
154
|
-
}
|
|
155
|
-
return replacementValue;
|
|
156
|
-
});
|
|
157
|
-
} catch {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
143
|
function getUtf8ByteLength(value) {
|
|
162
144
|
if ('undefined' != typeof TextEncoder) return new TextEncoder().encode(value).length;
|
|
163
145
|
const encoded = encodeURIComponent(value);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNumber, isObject, isString } from "../utils/index.mjs";
|
|
1
|
+
import { isNumber, isObject, isString, safeJsonStringify } from "../utils/index.mjs";
|
|
2
2
|
const EXCEPTION_STEP_INTERNAL_FIELDS = {
|
|
3
3
|
MESSAGE: '$message',
|
|
4
4
|
TIMESTAMP: '$timestamp'
|
|
@@ -85,8 +85,12 @@ function normalizePositiveInteger(input, fallback) {
|
|
|
85
85
|
return normalized;
|
|
86
86
|
}
|
|
87
87
|
function normalizeAndSerializeStep(step) {
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
let json;
|
|
89
|
+
try {
|
|
90
|
+
json = safeJsonStringify(step);
|
|
91
|
+
} catch {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
90
94
|
try {
|
|
91
95
|
const parsed = JSON.parse(json);
|
|
92
96
|
if (!isObject(parsed)) return;
|
|
@@ -103,28 +107,6 @@ function normalizeAndSerializeStep(step) {
|
|
|
103
107
|
return;
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
|
-
function safeStringify(value) {
|
|
107
|
-
const seen = new WeakSet();
|
|
108
|
-
try {
|
|
109
|
-
return JSON.stringify(value, (_key, replacementValue)=>{
|
|
110
|
-
if ('bigint' == typeof replacementValue) return replacementValue.toString();
|
|
111
|
-
if ('function' == typeof replacementValue || 'symbol' == typeof replacementValue) return;
|
|
112
|
-
if (replacementValue instanceof Date) return replacementValue.toISOString();
|
|
113
|
-
if (replacementValue instanceof Error) return {
|
|
114
|
-
name: replacementValue.name,
|
|
115
|
-
message: replacementValue.message,
|
|
116
|
-
stack: replacementValue.stack
|
|
117
|
-
};
|
|
118
|
-
if (replacementValue && 'object' == typeof replacementValue) {
|
|
119
|
-
if (seen.has(replacementValue)) return '[Circular]';
|
|
120
|
-
seen.add(replacementValue);
|
|
121
|
-
}
|
|
122
|
-
return replacementValue;
|
|
123
|
-
});
|
|
124
|
-
} catch {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
110
|
function getUtf8ByteLength(value) {
|
|
129
111
|
if ('undefined' != typeof TextEncoder) return new TextEncoder().encode(value).length;
|
|
130
112
|
const encoded = encodeURIComponent(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EA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Ae;IAMvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B5B,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;YAazC,MAAM;IAkGpB;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAwC/D,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -555,7 +555,7 @@ class PostHogCoreStateless {
|
|
|
555
555
|
sent_at: (0, index_js_namespaceObject.currentISOTime)()
|
|
556
556
|
};
|
|
557
557
|
if (this.historicalMigration) data.historical_migration = true;
|
|
558
|
-
const payload =
|
|
558
|
+
const payload = (0, index_js_namespaceObject.safeJsonStringify)(data);
|
|
559
559
|
const url = `${this.host}/batch/`;
|
|
560
560
|
const gzippedPayload = this.disableCompression ? null : await (0, external_gzip_js_namespaceObject.gzipCompress)(payload, this.isDebug);
|
|
561
561
|
const fetchOptions = {
|
|
@@ -662,7 +662,7 @@ class PostHogCoreStateless {
|
|
|
662
662
|
sent_at: (0, index_js_namespaceObject.currentISOTime)()
|
|
663
663
|
};
|
|
664
664
|
if (this.historicalMigration) data.historical_migration = true;
|
|
665
|
-
const payload =
|
|
665
|
+
const payload = (0, index_js_namespaceObject.safeJsonStringify)(data);
|
|
666
666
|
const url = `${this.host}/batch/`;
|
|
667
667
|
const gzippedPayload = this.disableCompression ? null : await (0, external_gzip_js_namespaceObject.gzipCompress)(payload, this.isDebug);
|
|
668
668
|
const fetchOptions = {
|
|
@@ -2,7 +2,7 @@ import { SimpleEventEmitter } from "./eventemitter.mjs";
|
|
|
2
2
|
import { getFeatureFlagValue, normalizeFlagsResponse } from "./featureFlagUtils.mjs";
|
|
3
3
|
import { gzipCompress, isGzipSupported } from "./gzip.mjs";
|
|
4
4
|
import { PostHogPersistedProperty } from "./types.mjs";
|
|
5
|
-
import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime, getEventUuid, removeTrailingSlash, retriable, safeSetTimeout } from "./utils/index.mjs";
|
|
5
|
+
import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime, getEventUuid, removeTrailingSlash, retriable, safeJsonStringify, safeSetTimeout } from "./utils/index.mjs";
|
|
6
6
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
7
7
|
import { ErrorCoercer, ErrorPropertiesBuilder, ObjectCoercer, PrimitiveCoercer, StringCoercer, createDefaultStackParser } from "./error-tracking/index.mjs";
|
|
8
8
|
class PostHogFetchHttpError extends Error {
|
|
@@ -523,7 +523,7 @@ class PostHogCoreStateless {
|
|
|
523
523
|
sent_at: currentISOTime()
|
|
524
524
|
};
|
|
525
525
|
if (this.historicalMigration) data.historical_migration = true;
|
|
526
|
-
const payload =
|
|
526
|
+
const payload = safeJsonStringify(data);
|
|
527
527
|
const url = `${this.host}/batch/`;
|
|
528
528
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
529
529
|
const fetchOptions = {
|
|
@@ -630,7 +630,7 @@ class PostHogCoreStateless {
|
|
|
630
630
|
sent_at: currentISOTime()
|
|
631
631
|
};
|
|
632
632
|
if (this.historicalMigration) data.historical_migration = true;
|
|
633
|
-
const payload =
|
|
633
|
+
const payload = safeJsonStringify(data);
|
|
634
634
|
const url = `${this.host}/batch/`;
|
|
635
635
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
636
636
|
const fetchOptions = {
|
|
@@ -4,6 +4,7 @@ export declare function includes<T>(arr: T[], needle: T): boolean;
|
|
|
4
4
|
export declare const trim: (str: string) => string;
|
|
5
5
|
export declare const stripLeadingDollar: (s: string) => string;
|
|
6
6
|
export declare function isDistinctIdStringLike(value: string): boolean;
|
|
7
|
+
export declare function safeJsonStringify(value: unknown): string;
|
|
7
8
|
/**
|
|
8
9
|
* Creates a hash string from distinct_id and person properties.
|
|
9
10
|
* Used to detect if person properties have changed to avoid duplicate $set events.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;AAC9D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAA;AAKzD,eAAO,MAAM,IAAI,GAAa,KAAK,MAAM,KAAG,MAM3C,CAAA;AAID,eAAO,MAAM,kBAAkB,GAAa,GAAG,MAAM,KAAG,MAEvD,CAAA;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAuBD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,mBAAmB,CAAC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,EACjD,uBAAuB,CAAC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,GACpD,MAAM,CAMR"}
|
|
1
|
+
{"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;AAC9D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAA;AAKzD,eAAO,MAAM,IAAI,GAAa,KAAK,MAAM,KAAG,MAM3C,CAAA;AAID,eAAO,MAAM,kBAAkB,GAAa,GAAG,MAAM,KAAG,MAEvD,CAAA;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAwCxD;AAuBD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,mBAAmB,CAAC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,EACjD,uBAAuB,CAAC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,GACpD,MAAM,CAMR"}
|
|
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
getPersonPropertiesHash: ()=>getPersonPropertiesHash,
|
|
28
28
|
includes: ()=>includes,
|
|
29
29
|
isDistinctIdStringLike: ()=>isDistinctIdStringLike,
|
|
30
|
+
safeJsonStringify: ()=>safeJsonStringify,
|
|
30
31
|
stripLeadingDollar: ()=>stripLeadingDollar,
|
|
31
32
|
trim: ()=>trim
|
|
32
33
|
});
|
|
@@ -45,6 +46,24 @@ function isDistinctIdStringLike(value) {
|
|
|
45
46
|
'distinctid'
|
|
46
47
|
].includes(value.toLowerCase());
|
|
47
48
|
}
|
|
49
|
+
function safeJsonStringify(value) {
|
|
50
|
+
const ancestors = [];
|
|
51
|
+
return JSON.stringify(value, function(_key, replacementValue) {
|
|
52
|
+
if ('bigint' == typeof replacementValue) return replacementValue.toString();
|
|
53
|
+
if ('function' == typeof replacementValue || 'symbol' == typeof replacementValue) return;
|
|
54
|
+
if (replacementValue instanceof Error) return {
|
|
55
|
+
name: replacementValue.name,
|
|
56
|
+
message: replacementValue.message,
|
|
57
|
+
stack: replacementValue.stack
|
|
58
|
+
};
|
|
59
|
+
if (replacementValue && 'object' == typeof replacementValue) {
|
|
60
|
+
while(ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)ancestors.pop();
|
|
61
|
+
if (ancestors.includes(replacementValue)) return '[Circular]';
|
|
62
|
+
ancestors.push(replacementValue);
|
|
63
|
+
}
|
|
64
|
+
return replacementValue;
|
|
65
|
+
}) ?? 'null';
|
|
66
|
+
}
|
|
48
67
|
function deepSortKeys(value) {
|
|
49
68
|
if (null === value || 'object' != typeof value) return value;
|
|
50
69
|
if (Array.isArray(value)) return value.map(deepSortKeys);
|
|
@@ -63,12 +82,14 @@ function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertie
|
|
|
63
82
|
exports.getPersonPropertiesHash = __webpack_exports__.getPersonPropertiesHash;
|
|
64
83
|
exports.includes = __webpack_exports__.includes;
|
|
65
84
|
exports.isDistinctIdStringLike = __webpack_exports__.isDistinctIdStringLike;
|
|
85
|
+
exports.safeJsonStringify = __webpack_exports__.safeJsonStringify;
|
|
66
86
|
exports.stripLeadingDollar = __webpack_exports__.stripLeadingDollar;
|
|
67
87
|
exports.trim = __webpack_exports__.trim;
|
|
68
88
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
69
89
|
"getPersonPropertiesHash",
|
|
70
90
|
"includes",
|
|
71
91
|
"isDistinctIdStringLike",
|
|
92
|
+
"safeJsonStringify",
|
|
72
93
|
"stripLeadingDollar",
|
|
73
94
|
"trim"
|
|
74
95
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
@@ -13,6 +13,24 @@ function isDistinctIdStringLike(value) {
|
|
|
13
13
|
'distinctid'
|
|
14
14
|
].includes(value.toLowerCase());
|
|
15
15
|
}
|
|
16
|
+
function safeJsonStringify(value) {
|
|
17
|
+
const ancestors = [];
|
|
18
|
+
return JSON.stringify(value, function(_key, replacementValue) {
|
|
19
|
+
if ('bigint' == typeof replacementValue) return replacementValue.toString();
|
|
20
|
+
if ('function' == typeof replacementValue || 'symbol' == typeof replacementValue) return;
|
|
21
|
+
if (replacementValue instanceof Error) return {
|
|
22
|
+
name: replacementValue.name,
|
|
23
|
+
message: replacementValue.message,
|
|
24
|
+
stack: replacementValue.stack
|
|
25
|
+
};
|
|
26
|
+
if (replacementValue && 'object' == typeof replacementValue) {
|
|
27
|
+
while(ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)ancestors.pop();
|
|
28
|
+
if (ancestors.includes(replacementValue)) return '[Circular]';
|
|
29
|
+
ancestors.push(replacementValue);
|
|
30
|
+
}
|
|
31
|
+
return replacementValue;
|
|
32
|
+
}) ?? 'null';
|
|
33
|
+
}
|
|
16
34
|
function deepSortKeys(value) {
|
|
17
35
|
if (null === value || 'object' != typeof value) return value;
|
|
18
36
|
if (Array.isArray(value)) return value.map(deepSortKeys);
|
|
@@ -28,4 +46,4 @@ function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertie
|
|
|
28
46
|
userPropertiesToSetOnce: userPropertiesToSetOnce ? deepSortKeys(userPropertiesToSetOnce) : void 0
|
|
29
47
|
});
|
|
30
48
|
}
|
|
31
|
-
export { getPersonPropertiesHash, includes, isDistinctIdStringLike, stripLeadingDollar, trim };
|
|
49
|
+
export { getPersonPropertiesHash, includes, isDistinctIdStringLike, safeJsonStringify, stripLeadingDollar, trim };
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isNumber, isObject, isString } from '@/utils'
|
|
1
|
+
import { isArray, isNumber, isObject, isString, safeJsonStringify } from '@/utils'
|
|
2
2
|
|
|
3
3
|
export const EXCEPTION_STEP_INTERNAL_FIELDS = {
|
|
4
4
|
MESSAGE: '$message',
|
|
@@ -134,8 +134,10 @@ function normalizePositiveInteger(input: number | undefined, fallback: number):
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
function normalizeAndSerializeStep(step: ExceptionStep): { step: ExceptionStep; json: string } | undefined {
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
let json: string
|
|
138
|
+
try {
|
|
139
|
+
json = safeJsonStringify(step)
|
|
140
|
+
} catch {
|
|
139
141
|
return undefined
|
|
140
142
|
}
|
|
141
143
|
|
|
@@ -166,45 +168,6 @@ function normalizeAndSerializeStep(step: ExceptionStep): { step: ExceptionStep;
|
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
170
|
|
|
169
|
-
function safeStringify(value: unknown): string | undefined {
|
|
170
|
-
const seen = new WeakSet<object>()
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
return JSON.stringify(value, (_key, replacementValue: unknown) => {
|
|
174
|
-
if (typeof replacementValue === 'bigint') {
|
|
175
|
-
return replacementValue.toString()
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (typeof replacementValue === 'function' || typeof replacementValue === 'symbol') {
|
|
179
|
-
return undefined
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (replacementValue instanceof Date) {
|
|
183
|
-
return replacementValue.toISOString()
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (replacementValue instanceof Error) {
|
|
187
|
-
return {
|
|
188
|
-
name: replacementValue.name,
|
|
189
|
-
message: replacementValue.message,
|
|
190
|
-
stack: replacementValue.stack,
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (replacementValue && typeof replacementValue === 'object') {
|
|
195
|
-
if (seen.has(replacementValue)) {
|
|
196
|
-
return '[Circular]'
|
|
197
|
-
}
|
|
198
|
-
seen.add(replacementValue)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return replacementValue
|
|
202
|
-
})
|
|
203
|
-
} catch {
|
|
204
|
-
return undefined
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
171
|
export function getUtf8ByteLength(value: string): number {
|
|
209
172
|
if (typeof TextEncoder !== 'undefined') {
|
|
210
173
|
return new TextEncoder().encode(value).length
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
STRING_FORMAT,
|
|
35
35
|
createLogger,
|
|
36
36
|
getEventUuid,
|
|
37
|
+
safeJsonStringify,
|
|
37
38
|
} from './utils'
|
|
38
39
|
import { uuidv7 } from './vendor/uuidv7'
|
|
39
40
|
import {
|
|
@@ -1082,7 +1083,7 @@ export abstract class PostHogCoreStateless {
|
|
|
1082
1083
|
data.historical_migration = true
|
|
1083
1084
|
}
|
|
1084
1085
|
|
|
1085
|
-
const payload =
|
|
1086
|
+
const payload = safeJsonStringify(data)
|
|
1086
1087
|
|
|
1087
1088
|
const url = `${this.host}/batch/`
|
|
1088
1089
|
|
|
@@ -1278,7 +1279,7 @@ export abstract class PostHogCoreStateless {
|
|
|
1278
1279
|
data.historical_migration = true
|
|
1279
1280
|
}
|
|
1280
1281
|
|
|
1281
|
-
const payload =
|
|
1282
|
+
const payload = safeJsonStringify(data)
|
|
1282
1283
|
|
|
1283
1284
|
const url = `${this.host}/batch/`
|
|
1284
1285
|
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
import { getPersonPropertiesHash } from './string-utils'
|
|
1
|
+
import { getPersonPropertiesHash, safeJsonStringify } from './string-utils'
|
|
2
2
|
|
|
3
3
|
describe('string-utils', () => {
|
|
4
|
+
describe('safeJsonStringify', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
[
|
|
7
|
+
'replaces circular references',
|
|
8
|
+
() => {
|
|
9
|
+
const circular: Record<string, any> = { foo: 'bar' }
|
|
10
|
+
circular.self = circular
|
|
11
|
+
return {
|
|
12
|
+
value: circular,
|
|
13
|
+
expected: { foo: 'bar', self: '[Circular]' },
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
'preserves shared non-circular references',
|
|
19
|
+
() => {
|
|
20
|
+
const shared = { id: 1 }
|
|
21
|
+
return {
|
|
22
|
+
value: { a: shared, b: shared },
|
|
23
|
+
expected: { a: { id: 1 }, b: { id: 1 } },
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
'serializes bigint values as strings',
|
|
29
|
+
() => ({
|
|
30
|
+
value: { count: BigInt(123) },
|
|
31
|
+
expected: { count: '123' },
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
])('%s', (_description, buildCase) => {
|
|
35
|
+
const { value, expected } = buildCase()
|
|
36
|
+
|
|
37
|
+
expect(JSON.parse(safeJsonStringify(value))).toEqual(expected)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
4
41
|
describe('getPersonPropertiesHash', () => {
|
|
5
42
|
it('should return consistent hash regardless of top-level key order', () => {
|
|
6
43
|
const hash1 = getPersonPropertiesHash('user-1', { b: 'value-b', a: 'value-a' })
|
|
@@ -24,6 +24,48 @@ export function isDistinctIdStringLike(value: string): boolean {
|
|
|
24
24
|
return ['distinct_id', 'distinctid'].includes(value.toLowerCase())
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export function safeJsonStringify(value: unknown): string {
|
|
28
|
+
// Browser replay has `circularReferenceReplacer`, which uses this same
|
|
29
|
+
// ancestor-chain approach to replace only true cycles. Keep this core helper
|
|
30
|
+
// separate so Node/RN/core payload serialization does not depend on browser
|
|
31
|
+
// replay internals, and so we can also handle BigInt and Error values here.
|
|
32
|
+
const ancestors: object[] = []
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
JSON.stringify(value, function (this: unknown, _key: string, replacementValue: unknown) {
|
|
36
|
+
if (typeof replacementValue === 'bigint') {
|
|
37
|
+
return replacementValue.toString()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof replacementValue === 'function' || typeof replacementValue === 'symbol') {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (replacementValue instanceof Error) {
|
|
45
|
+
return {
|
|
46
|
+
name: replacementValue.name,
|
|
47
|
+
message: replacementValue.message,
|
|
48
|
+
stack: replacementValue.stack,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (replacementValue && typeof replacementValue === 'object') {
|
|
53
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
54
|
+
ancestors.pop()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (ancestors.includes(replacementValue)) {
|
|
58
|
+
return '[Circular]'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ancestors.push(replacementValue)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return replacementValue
|
|
65
|
+
}) ?? 'null'
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
27
69
|
/**
|
|
28
70
|
* Recursively sorts all keys in an object and its nested objects/arrays.
|
|
29
71
|
* Used to ensure deterministic JSON serialization regardless of object construction order.
|