@posthog/core 1.67.0 → 1.67.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/coercers/utils.d.ts.map +1 -1
- package/dist/error-tracking/coercers/utils.js +6 -7
- package/dist/error-tracking/coercers/utils.mjs +6 -7
- package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.js +17 -2
- package/dist/featureFlagLocalEvaluation.mjs +17 -2
- package/package.json +2 -2
- package/src/error-tracking/coercers/utils.ts +7 -10
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +18 -3
- package/src/featureFlagLocalEvaluation.ts +23 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,GAAG,MAAM,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,GAAG,MAAM,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,CAiBlF"}
|
|
@@ -35,14 +35,13 @@ function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
|
35
35
|
const keys = Object.keys(err);
|
|
36
36
|
keys.sort();
|
|
37
37
|
if (!keys.length) return '[object has no keys]';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
38
|
+
let serialized = '';
|
|
39
|
+
for (const key of keys){
|
|
40
|
+
const next = serialized ? `${serialized}, ${key}` : key;
|
|
41
|
+
if (next.length > maxLength) break;
|
|
42
|
+
serialized = next;
|
|
44
43
|
}
|
|
45
|
-
return
|
|
44
|
+
return serialized;
|
|
46
45
|
}
|
|
47
46
|
__webpack_require__.d(__webpack_exports__, {
|
|
48
47
|
extractExceptionKeysForMessage: ()=>extractExceptionKeysForMessage,
|
|
@@ -6,13 +6,12 @@ function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
|
6
6
|
const keys = Object.keys(err);
|
|
7
7
|
keys.sort();
|
|
8
8
|
if (!keys.length) return '[object has no keys]';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
9
|
+
let serialized = '';
|
|
10
|
+
for (const key of keys){
|
|
11
|
+
const next = serialized ? `${serialized}, ${key}` : key;
|
|
12
|
+
if (next.length > maxLength) break;
|
|
13
|
+
serialized = next;
|
|
15
14
|
}
|
|
16
|
-
return
|
|
15
|
+
return serialized;
|
|
17
16
|
}
|
|
18
17
|
export { extractExceptionKeysForMessage, truncate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureFlagLocalEvaluation.d.ts","sourceRoot":"","sources":["../src/featureFlagLocalEvaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAA;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,wBAAwB,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG,QAAQ,GAAG,mBAAmB,CAAA;AAE3E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,YAAY,CAAC,EAAE,CAAC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C7B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAUT;AAkJD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ5D;AAED,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EACtB,IAAI,GAAE,MAAW,EACjB,SAAS,GAAE,MAAY,GACtB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EACxE,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA0B7B;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,6BAA6B,EAAE,CASjC;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK7B;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3E,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC7C,QAAQ,GAAG,IAAI,CAMjB"}
|
|
@@ -417,13 +417,28 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
417
417
|
if ('h' === interval) parsedDt.setUTCHours(parsedDt.getUTCHours() - number);
|
|
418
418
|
else if ('d' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - number);
|
|
419
419
|
else if ('w' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - 7 * number);
|
|
420
|
-
else if ('m' === interval)
|
|
420
|
+
else if ('m' === interval) subtractUTCMonths(parsedDt, number);
|
|
421
421
|
else {
|
|
422
422
|
if ('y' !== interval) return null;
|
|
423
|
-
|
|
423
|
+
subtractUTCYears(parsedDt, number);
|
|
424
424
|
}
|
|
425
425
|
return parsedDt;
|
|
426
426
|
}
|
|
427
|
+
function subtractUTCMonths(date, months) {
|
|
428
|
+
const year = date.getUTCFullYear();
|
|
429
|
+
const month = date.getUTCMonth();
|
|
430
|
+
let day = date.getUTCDate();
|
|
431
|
+
for(let step = 1; step <= months && day > 28; step++){
|
|
432
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate();
|
|
433
|
+
day = Math.min(day, lastDayOfMonth);
|
|
434
|
+
}
|
|
435
|
+
date.setUTCFullYear(year, month - months, day);
|
|
436
|
+
}
|
|
437
|
+
function subtractUTCYears(date, years) {
|
|
438
|
+
const month = date.getUTCMonth();
|
|
439
|
+
const day = years > 0 && 1 === month && 29 === date.getUTCDate() ? 28 : date.getUTCDate();
|
|
440
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day);
|
|
441
|
+
}
|
|
427
442
|
function parseDateFilter(value) {
|
|
428
443
|
if ('boolean' == typeof value) throw new InconclusiveMatchError('Date operations cannot be performed on boolean values');
|
|
429
444
|
return relativeDateParseForFeatureFlagMatching(String(value)) ?? convertToDateTime(value);
|
|
@@ -375,13 +375,28 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
375
375
|
if ('h' === interval) parsedDt.setUTCHours(parsedDt.getUTCHours() - number);
|
|
376
376
|
else if ('d' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - number);
|
|
377
377
|
else if ('w' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - 7 * number);
|
|
378
|
-
else if ('m' === interval)
|
|
378
|
+
else if ('m' === interval) subtractUTCMonths(parsedDt, number);
|
|
379
379
|
else {
|
|
380
380
|
if ('y' !== interval) return null;
|
|
381
|
-
|
|
381
|
+
subtractUTCYears(parsedDt, number);
|
|
382
382
|
}
|
|
383
383
|
return parsedDt;
|
|
384
384
|
}
|
|
385
|
+
function subtractUTCMonths(date, months) {
|
|
386
|
+
const year = date.getUTCFullYear();
|
|
387
|
+
const month = date.getUTCMonth();
|
|
388
|
+
let day = date.getUTCDate();
|
|
389
|
+
for(let step = 1; step <= months && day > 28; step++){
|
|
390
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate();
|
|
391
|
+
day = Math.min(day, lastDayOfMonth);
|
|
392
|
+
}
|
|
393
|
+
date.setUTCFullYear(year, month - months, day);
|
|
394
|
+
}
|
|
395
|
+
function subtractUTCYears(date, years) {
|
|
396
|
+
const month = date.getUTCMonth();
|
|
397
|
+
const day = years > 0 && 1 === month && 29 === date.getUTCDate() ? 28 : date.getUTCDate();
|
|
398
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day);
|
|
399
|
+
}
|
|
385
400
|
function parseDateFilter(value) {
|
|
386
401
|
if ('boolean' == typeof value) throw new InconclusiveMatchError('Date operations cannot be performed on boolean values');
|
|
387
402
|
return relativeDateParseForFeatureFlagMatching(String(value)) ?? convertToDateTime(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.67.
|
|
3
|
+
"version": "1.67.2",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@posthog/types": "^1.
|
|
75
|
+
"@posthog/types": "^1.424.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@rslib/core": "0.23.2",
|
|
@@ -22,16 +22,13 @@ export function extractExceptionKeysForMessage(err: object, maxLength = 40): str
|
|
|
22
22
|
return '[object has no keys]'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
let serialized = ''
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
const next = serialized ? `${serialized}, ${key}` : key
|
|
28
|
+
if (next.length > maxLength) {
|
|
29
|
+
break
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
return serialized
|
|
32
|
-
}
|
|
33
|
-
return serialized.length <= maxLength ? serialized : `${serialized.slice(0, maxLength)}...`
|
|
31
|
+
serialized = next
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
return ''
|
|
33
|
+
return serialized
|
|
37
34
|
}
|
|
@@ -79,17 +79,32 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
79
79
|
})
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
it(
|
|
82
|
+
it.each([
|
|
83
|
+
['all keys when they fit', { foo: 'Foo value', bar: 'Bar value' }, 'bar, foo'],
|
|
84
|
+
[
|
|
85
|
+
'the longest key prefix that fits',
|
|
86
|
+
Object.fromEntries(['golf', 'alpha', 'echo', 'bravo', 'foxtrot', 'delta', 'charlie'].map((k) => [k, 1])),
|
|
87
|
+
'alpha, bravo, charlie, delta, echo',
|
|
88
|
+
],
|
|
89
|
+
['nothing when the first key is too long', { ['x'.repeat(41)]: 1 }, ''],
|
|
90
|
+
])('should use %s in objects', (_case, errorObject, keys) => {
|
|
83
91
|
const syntheticError = new Error()
|
|
84
|
-
const errorObject = { foo: 'Foo value', bar: 'Bar value' }
|
|
85
92
|
const exception = coerceInput(errorObject, syntheticError)
|
|
86
93
|
expect(exception).toMatchObject({
|
|
87
94
|
type: 'Error',
|
|
88
|
-
value:
|
|
95
|
+
value: `Object captured as exception with keys: ${keys}`,
|
|
89
96
|
stack: syntheticError.stack,
|
|
90
97
|
})
|
|
91
98
|
})
|
|
92
99
|
|
|
100
|
+
it('should summarize the keys of a very wide object quickly', () => {
|
|
101
|
+
const errorObject = Object.fromEntries(Array.from({ length: 30_000 }, (_, i) => [`k${i}`, i]))
|
|
102
|
+
const start = process.hrtime.bigint()
|
|
103
|
+
const exception = coerceInput(errorObject, new Error())
|
|
104
|
+
expect(Number(process.hrtime.bigint() - start) / 1e6).toBeLessThan(1000)
|
|
105
|
+
expect(exception.value).toBe('Object captured as exception with keys: k0, k1, k10, k100, k1000, k10000, k10001')
|
|
106
|
+
})
|
|
107
|
+
|
|
93
108
|
it('should handle object with an error property', () => {
|
|
94
109
|
const nestedError = new CustomTestError('My special error')
|
|
95
110
|
const errorObject = { error: nestedError }
|
|
@@ -478,13 +478,34 @@ export function relativeDateParseForFeatureFlagMatching(value: string): Date | n
|
|
|
478
478
|
if (interval === 'h') parsedDt.setUTCHours(parsedDt.getUTCHours() - number)
|
|
479
479
|
else if (interval === 'd') parsedDt.setUTCDate(parsedDt.getUTCDate() - number)
|
|
480
480
|
else if (interval === 'w') parsedDt.setUTCDate(parsedDt.getUTCDate() - number * 7)
|
|
481
|
-
else if (interval === 'm')
|
|
482
|
-
else if (interval === 'y')
|
|
481
|
+
else if (interval === 'm') subtractUTCMonths(parsedDt, number)
|
|
482
|
+
else if (interval === 'y') subtractUTCYears(parsedDt, number)
|
|
483
483
|
else return null
|
|
484
484
|
|
|
485
485
|
return parsedDt
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
+
// The SDK spec subtracts months one at a time and clamps the day after every step, so
|
|
489
|
+
// March 31 minus one month is February 28 and minus two months is January 28.
|
|
490
|
+
function subtractUTCMonths(date: Date, months: number): void {
|
|
491
|
+
const year = date.getUTCFullYear()
|
|
492
|
+
const month = date.getUTCMonth()
|
|
493
|
+
let day = date.getUTCDate()
|
|
494
|
+
// Every month has at least 28 days, so nothing can clamp further after that.
|
|
495
|
+
for (let step = 1; step <= months && day > 28; step++) {
|
|
496
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate()
|
|
497
|
+
day = Math.min(day, lastDayOfMonth)
|
|
498
|
+
}
|
|
499
|
+
date.setUTCFullYear(year, month - months, day)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function subtractUTCYears(date: Date, years: number): void {
|
|
503
|
+
const month = date.getUTCMonth()
|
|
504
|
+
// The year before a leap year is never a leap year, so February 29 clamps on the first step.
|
|
505
|
+
const day = years > 0 && month === 1 && date.getUTCDate() === 29 ? 28 : date.getUTCDate()
|
|
506
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day)
|
|
507
|
+
}
|
|
508
|
+
|
|
488
509
|
function parseDateFilter(value: FeatureFlagPropertyValue): Date {
|
|
489
510
|
if (typeof value === 'boolean') {
|
|
490
511
|
throw new InconclusiveMatchError('Date operations cannot be performed on boolean values')
|