@posthog/core 1.39.0 → 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 +12 -7
- package/dist/posthog-core-stateless.mjs +13 -8
- 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 +16 -9
- 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"}
|
|
@@ -86,6 +86,10 @@ function isRetryableFlagsFetchError(err) {
|
|
|
86
86
|
function isPostHogFetchContentTooLargeError(err) {
|
|
87
87
|
return 'object' == typeof err && err instanceof PostHogFetchHttpError && 413 === err.status;
|
|
88
88
|
}
|
|
89
|
+
function isPostHogFetchRetryableError(err) {
|
|
90
|
+
if (err instanceof PostHogFetchHttpError) return 408 === err.status || 429 === err.status || err.status >= 500;
|
|
91
|
+
return isPostHogFetchNetworkError(err);
|
|
92
|
+
}
|
|
89
93
|
function isPostHogEventProperties(value) {
|
|
90
94
|
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
91
95
|
}
|
|
@@ -130,7 +134,7 @@ class PostHogCoreStateless {
|
|
|
130
134
|
this._retryOptions = {
|
|
131
135
|
retryCount: options.fetchRetryCount ?? 3,
|
|
132
136
|
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
133
|
-
retryCheck:
|
|
137
|
+
retryCheck: isPostHogFetchRetryableError
|
|
134
138
|
};
|
|
135
139
|
this.requestTimeout = options.requestTimeout ?? 10000;
|
|
136
140
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
@@ -436,8 +440,9 @@ class PostHogCoreStateless {
|
|
|
436
440
|
}
|
|
437
441
|
async getFeatureFlagDetailsStateless(distinctId, groups = {}, personProperties = {}, groupProperties = {}, disableGeoip, flagKeysToEvaluate) {
|
|
438
442
|
await this._initPromise;
|
|
439
|
-
const extraPayload = {
|
|
440
|
-
|
|
443
|
+
const extraPayload = {
|
|
444
|
+
geoip_disable: disableGeoip ?? this.disableGeoip
|
|
445
|
+
};
|
|
441
446
|
if (flagKeysToEvaluate) extraPayload['flag_keys_to_evaluate'] = flagKeysToEvaluate;
|
|
442
447
|
const result = await this.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
443
448
|
if (!result.success) return;
|
|
@@ -550,7 +555,7 @@ class PostHogCoreStateless {
|
|
|
550
555
|
sent_at: (0, index_js_namespaceObject.currentISOTime)()
|
|
551
556
|
};
|
|
552
557
|
if (this.historicalMigration) data.historical_migration = true;
|
|
553
|
-
const payload =
|
|
558
|
+
const payload = (0, index_js_namespaceObject.safeJsonStringify)(data);
|
|
554
559
|
const url = `${this.host}/batch/`;
|
|
555
560
|
const gzippedPayload = this.disableCompression ? null : await (0, external_gzip_js_namespaceObject.gzipCompress)(payload, this.isDebug);
|
|
556
561
|
const fetchOptions = {
|
|
@@ -657,7 +662,7 @@ class PostHogCoreStateless {
|
|
|
657
662
|
sent_at: (0, index_js_namespaceObject.currentISOTime)()
|
|
658
663
|
};
|
|
659
664
|
if (this.historicalMigration) data.historical_migration = true;
|
|
660
|
-
const payload =
|
|
665
|
+
const payload = (0, index_js_namespaceObject.safeJsonStringify)(data);
|
|
661
666
|
const url = `${this.host}/batch/`;
|
|
662
667
|
const gzippedPayload = this.disableCompression ? null : await (0, external_gzip_js_namespaceObject.gzipCompress)(payload, this.isDebug);
|
|
663
668
|
const fetchOptions = {
|
|
@@ -674,7 +679,7 @@ class PostHogCoreStateless {
|
|
|
674
679
|
const retryOptions = {
|
|
675
680
|
retryCheck: (err)=>{
|
|
676
681
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
677
|
-
return
|
|
682
|
+
return isPostHogFetchRetryableError(err);
|
|
678
683
|
}
|
|
679
684
|
};
|
|
680
685
|
try {
|
|
@@ -718,7 +723,7 @@ class PostHogCoreStateless {
|
|
|
718
723
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
719
724
|
retryCheck: (err)=>{
|
|
720
725
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
721
|
-
return
|
|
726
|
+
return isPostHogFetchRetryableError(err);
|
|
722
727
|
}
|
|
723
728
|
});
|
|
724
729
|
return {
|
|
@@ -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 {
|
|
@@ -54,6 +54,10 @@ function isRetryableFlagsFetchError(err) {
|
|
|
54
54
|
function isPostHogFetchContentTooLargeError(err) {
|
|
55
55
|
return 'object' == typeof err && err instanceof PostHogFetchHttpError && 413 === err.status;
|
|
56
56
|
}
|
|
57
|
+
function isPostHogFetchRetryableError(err) {
|
|
58
|
+
if (err instanceof PostHogFetchHttpError) return 408 === err.status || 429 === err.status || err.status >= 500;
|
|
59
|
+
return isPostHogFetchNetworkError(err);
|
|
60
|
+
}
|
|
57
61
|
function isPostHogEventProperties(value) {
|
|
58
62
|
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
59
63
|
}
|
|
@@ -98,7 +102,7 @@ class PostHogCoreStateless {
|
|
|
98
102
|
this._retryOptions = {
|
|
99
103
|
retryCount: options.fetchRetryCount ?? 3,
|
|
100
104
|
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
101
|
-
retryCheck:
|
|
105
|
+
retryCheck: isPostHogFetchRetryableError
|
|
102
106
|
};
|
|
103
107
|
this.requestTimeout = options.requestTimeout ?? 10000;
|
|
104
108
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
@@ -404,8 +408,9 @@ class PostHogCoreStateless {
|
|
|
404
408
|
}
|
|
405
409
|
async getFeatureFlagDetailsStateless(distinctId, groups = {}, personProperties = {}, groupProperties = {}, disableGeoip, flagKeysToEvaluate) {
|
|
406
410
|
await this._initPromise;
|
|
407
|
-
const extraPayload = {
|
|
408
|
-
|
|
411
|
+
const extraPayload = {
|
|
412
|
+
geoip_disable: disableGeoip ?? this.disableGeoip
|
|
413
|
+
};
|
|
409
414
|
if (flagKeysToEvaluate) extraPayload['flag_keys_to_evaluate'] = flagKeysToEvaluate;
|
|
410
415
|
const result = await this.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
411
416
|
if (!result.success) return;
|
|
@@ -518,7 +523,7 @@ class PostHogCoreStateless {
|
|
|
518
523
|
sent_at: currentISOTime()
|
|
519
524
|
};
|
|
520
525
|
if (this.historicalMigration) data.historical_migration = true;
|
|
521
|
-
const payload =
|
|
526
|
+
const payload = safeJsonStringify(data);
|
|
522
527
|
const url = `${this.host}/batch/`;
|
|
523
528
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
524
529
|
const fetchOptions = {
|
|
@@ -625,7 +630,7 @@ class PostHogCoreStateless {
|
|
|
625
630
|
sent_at: currentISOTime()
|
|
626
631
|
};
|
|
627
632
|
if (this.historicalMigration) data.historical_migration = true;
|
|
628
|
-
const payload =
|
|
633
|
+
const payload = safeJsonStringify(data);
|
|
629
634
|
const url = `${this.host}/batch/`;
|
|
630
635
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
631
636
|
const fetchOptions = {
|
|
@@ -642,7 +647,7 @@ class PostHogCoreStateless {
|
|
|
642
647
|
const retryOptions = {
|
|
643
648
|
retryCheck: (err)=>{
|
|
644
649
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
645
|
-
return
|
|
650
|
+
return isPostHogFetchRetryableError(err);
|
|
646
651
|
}
|
|
647
652
|
};
|
|
648
653
|
try {
|
|
@@ -686,7 +691,7 @@ class PostHogCoreStateless {
|
|
|
686
691
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
687
692
|
retryCheck: (err)=>{
|
|
688
693
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
689
|
-
return
|
|
694
|
+
return isPostHogFetchRetryableError(err);
|
|
690
695
|
}
|
|
691
696
|
});
|
|
692
697
|
return {
|
|
@@ -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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B,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 {
|
|
@@ -126,6 +127,13 @@ function isPostHogFetchContentTooLargeError(err: unknown): err is PostHogFetchHt
|
|
|
126
127
|
return typeof err === 'object' && err instanceof PostHogFetchHttpError && err.status === 413
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
function isPostHogFetchRetryableError(err: unknown): err is PostHogFetchHttpError | PostHogFetchNetworkError {
|
|
131
|
+
if (err instanceof PostHogFetchHttpError) {
|
|
132
|
+
return err.status === 408 || err.status === 429 || err.status >= 500
|
|
133
|
+
}
|
|
134
|
+
return isPostHogFetchNetworkError(err)
|
|
135
|
+
}
|
|
136
|
+
|
|
129
137
|
function isPostHogEventProperties(value: JsonType | undefined): value is PostHogEventProperties {
|
|
130
138
|
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
131
139
|
}
|
|
@@ -250,7 +258,7 @@ export abstract class PostHogCoreStateless {
|
|
|
250
258
|
this._retryOptions = {
|
|
251
259
|
retryCount: options.fetchRetryCount ?? 3,
|
|
252
260
|
retryDelay: options.fetchRetryDelay ?? 3000, // 3 seconds
|
|
253
|
-
retryCheck:
|
|
261
|
+
retryCheck: isPostHogFetchRetryableError,
|
|
254
262
|
}
|
|
255
263
|
this.requestTimeout = options.requestTimeout ?? 10000 // 10 seconds
|
|
256
264
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000 // 3 seconds
|
|
@@ -853,9 +861,8 @@ export abstract class PostHogCoreStateless {
|
|
|
853
861
|
): Promise<PostHogFeatureFlagDetails | undefined> {
|
|
854
862
|
await this._initPromise
|
|
855
863
|
|
|
856
|
-
const extraPayload: Record<string, any> = {
|
|
857
|
-
|
|
858
|
-
extraPayload['geoip_disable'] = true
|
|
864
|
+
const extraPayload: Record<string, any> = {
|
|
865
|
+
geoip_disable: disableGeoip ?? this.disableGeoip,
|
|
859
866
|
}
|
|
860
867
|
if (flagKeysToEvaluate) {
|
|
861
868
|
extraPayload['flag_keys_to_evaluate'] = flagKeysToEvaluate
|
|
@@ -1076,7 +1083,7 @@ export abstract class PostHogCoreStateless {
|
|
|
1076
1083
|
data.historical_migration = true
|
|
1077
1084
|
}
|
|
1078
1085
|
|
|
1079
|
-
const payload =
|
|
1086
|
+
const payload = safeJsonStringify(data)
|
|
1080
1087
|
|
|
1081
1088
|
const url = `${this.host}/batch/`
|
|
1082
1089
|
|
|
@@ -1272,7 +1279,7 @@ export abstract class PostHogCoreStateless {
|
|
|
1272
1279
|
data.historical_migration = true
|
|
1273
1280
|
}
|
|
1274
1281
|
|
|
1275
|
-
const payload =
|
|
1282
|
+
const payload = safeJsonStringify(data)
|
|
1276
1283
|
|
|
1277
1284
|
const url = `${this.host}/batch/`
|
|
1278
1285
|
|
|
@@ -1293,8 +1300,8 @@ export abstract class PostHogCoreStateless {
|
|
|
1293
1300
|
if (isPostHogFetchContentTooLargeError(err)) {
|
|
1294
1301
|
return false
|
|
1295
1302
|
}
|
|
1296
|
-
// otherwise, retry on network errors
|
|
1297
|
-
return
|
|
1303
|
+
// otherwise, retry on transient HTTP and network errors
|
|
1304
|
+
return isPostHogFetchRetryableError(err)
|
|
1298
1305
|
},
|
|
1299
1306
|
}
|
|
1300
1307
|
|
|
@@ -1367,7 +1374,7 @@ export abstract class PostHogCoreStateless {
|
|
|
1367
1374
|
if (isPostHogFetchContentTooLargeError(err)) {
|
|
1368
1375
|
return false
|
|
1369
1376
|
}
|
|
1370
|
-
return
|
|
1377
|
+
return isPostHogFetchRetryableError(err)
|
|
1371
1378
|
},
|
|
1372
1379
|
})
|
|
1373
1380
|
return { kind: 'ok' }
|
|
@@ -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.
|