@posthog/core 1.61.2 → 1.62.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bot-detection.d.ts","sourceRoot":"","sources":["../../src/utils/bot-detection.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,UAmGnC,CAAA;AAeD,0DAA0D;AAC1D,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,OAAiB,MAAM,GAAG,SAAS,4BAA2B,MAAM,EAAE,KAAQ,OAsBrG,CAAA"}
1
+ {"version":3,"file":"bot-detection.d.ts","sourceRoot":"","sources":["../../src/utils/bot-detection.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,UAoGnC,CAAA;AAeD,0DAA0D;AAC1D,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,OAAiB,MAAM,GAAG,SAAS,4BAA2B,MAAM,EAAE,KAAQ,OAsBrG,CAAA"}
@@ -88,6 +88,7 @@ const DEFAULT_BLOCKED_UA_STRS = [
88
88
  'sentryuptimebot',
89
89
  'uptimerobot',
90
90
  'headlesschrome',
91
+ 'lightpanda',
91
92
  'cypress',
92
93
  'google-hoteladsverifier',
93
94
  'adsbot-google',
@@ -59,6 +59,7 @@ const DEFAULT_BLOCKED_UA_STRS = [
59
59
  'sentryuptimebot',
60
60
  'uptimerobot',
61
61
  'headlesschrome',
62
+ 'lightpanda',
62
63
  'cypress',
63
64
  'google-hoteladsverifier',
64
65
  'adsbot-google',
@@ -9,9 +9,9 @@ export declare const MAX_RETRY_AFTER_MS: number;
9
9
  * `Retry-After` as milliseconds from now. The header is either delta-seconds or
10
10
  * an HTTP-date; anything else, a date already in the past, or a non-positive
11
11
  * delta yields `undefined` so the caller keeps its own backoff. The result is
12
- * capped at `MAX_RETRY_AFTER_MS`.
12
+ * capped at `maxMs`, which defaults to `MAX_RETRY_AFTER_MS`.
13
13
  */
14
- export declare function parseRetryAfterMs(value: unknown, now?: number): number | undefined;
14
+ export declare function parseRetryAfterMs(value: unknown, now?: number, maxMs?: number): number | undefined;
15
15
  /** The part of an export outcome the window reads. */
16
16
  export type RetryAfterOutcome = {
17
17
  kind: 'ok' | 'retry-later' | 'too-large' | 'fatal';
@@ -1 +1 @@
1
- {"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/utils/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAS5C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,GAAE,MAAmB,GAAG,MAAM,GAAG,SAAS,CA4B9F;AAED,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,IAAI,GAAG,aAAa,GAAG,WAAW,GAAG,OAAO,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,YAAY,CAAI;IAExB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA4BvC;IAED;;;OAGG;IACH,WAAW,IAAI,MAAM,CAWpB;IAED,MAAM,IAAI,OAAO,CAEhB;IAED,KAAK,IAAI,IAAI,CAGZ;CACF"}
1
+ {"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/utils/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAS5C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,GAAG,GAAE,MAAmB,EACxB,KAAK,GAAE,MAA2B,GACjC,MAAM,GAAG,SAAS,CA4BpB;AAED,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,IAAI,GAAG,aAAa,GAAG,WAAW,GAAG,OAAO,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,YAAY,CAAI;IAExB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CA4BvC;IAED;;;OAGG;IACH,WAAW,IAAI,MAAM,CAWpB;IAED,MAAM,IAAI,OAAO,CAEhB;IAED,KAAK,IAAI,IAAI,CAGZ;CACF"}
@@ -29,19 +29,19 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  const MAX_RETRY_AFTER_MS = 300000;
31
31
  const CLOCK_STEP_TOLERANCE_MS = 5000;
32
- function parseRetryAfterMs(value, now = Date.now()) {
32
+ function parseRetryAfterMs(value, now = Date.now(), maxMs = MAX_RETRY_AFTER_MS) {
33
33
  if ('string' != typeof value || !value) return;
34
34
  const raw = value.trim();
35
35
  const trimmed = /^\d+\s*,/.test(raw) ? raw.slice(0, raw.indexOf(',')).trim() : raw;
36
36
  if (/^\d+$/.test(trimmed)) {
37
- const ms = 1000 * Math.min(Number(trimmed), MAX_RETRY_AFTER_MS / 1000);
37
+ const ms = 1000 * Math.min(Number(trimmed), maxMs / 1000);
38
38
  return ms > 0 ? ms : void 0;
39
39
  }
40
40
  if (!/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[a-z]*[ ,]/.test(trimmed)) return;
41
41
  const date = /^\w{3} \w{3} /.test(trimmed) ? trimmed + ' GMT' : trimmed;
42
42
  const ms = Date.parse(date) - now;
43
43
  if (!Number.isFinite(ms) || ms <= 0) return;
44
- return Math.min(ms, MAX_RETRY_AFTER_MS);
44
+ return Math.min(ms, maxMs);
45
45
  }
46
46
  class RetryAfterWindow {
47
47
  record(outcome) {
@@ -1,18 +1,18 @@
1
1
  const MAX_RETRY_AFTER_MS = 300000;
2
2
  const CLOCK_STEP_TOLERANCE_MS = 5000;
3
- function parseRetryAfterMs(value, now = Date.now()) {
3
+ function parseRetryAfterMs(value, now = Date.now(), maxMs = MAX_RETRY_AFTER_MS) {
4
4
  if ('string' != typeof value || !value) return;
5
5
  const raw = value.trim();
6
6
  const trimmed = /^\d+\s*,/.test(raw) ? raw.slice(0, raw.indexOf(',')).trim() : raw;
7
7
  if (/^\d+$/.test(trimmed)) {
8
- const ms = 1000 * Math.min(Number(trimmed), MAX_RETRY_AFTER_MS / 1000);
8
+ const ms = 1000 * Math.min(Number(trimmed), maxMs / 1000);
9
9
  return ms > 0 ? ms : void 0;
10
10
  }
11
11
  if (!/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[a-z]*[ ,]/.test(trimmed)) return;
12
12
  const date = /^\w{3} \w{3} /.test(trimmed) ? trimmed + ' GMT' : trimmed;
13
13
  const ms = Date.parse(date) - now;
14
14
  if (!Number.isFinite(ms) || ms <= 0) return;
15
- return Math.min(ms, MAX_RETRY_AFTER_MS);
15
+ return Math.min(ms, maxMs);
16
16
  }
17
17
  class RetryAfterWindow {
18
18
  record(outcome) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.61.2",
3
+ "version": "1.62.1",
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.418.0"
75
+ "@posthog/types": "^1.419.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@rslib/core": "0.23.2",
@@ -43,6 +43,13 @@ describe('isBlockedUA', () => {
43
43
  expect(isBlockedUA('headlessChrome/119.0')).toBe(true)
44
44
  })
45
45
 
46
+ it.each(['Lightpanda/1.0', 'lightpanda/2.3.4', 'LIGHTPANDA/10.0', 'Mozilla/5.0 (compatible; Lightpanda/1.0)'])(
47
+ 'blocks the self-declared headless browser %s',
48
+ (ua) => {
49
+ expect(isBlockedUA(ua)).toBe(true)
50
+ }
51
+ )
52
+
46
53
  it('is case-insensitive on the UA input', () => {
47
54
  const bot = 'Mozilla/5.0 (compatible; Googlebot/2.1)'
48
55
  expect(isBlockedUA(bot)).toBe(true)
@@ -78,6 +78,7 @@ export const DEFAULT_BLOCKED_UA_STRS = [
78
78
 
79
79
  // headless browsers
80
80
  'headlesschrome',
81
+ 'lightpanda',
81
82
  'cypress',
82
83
  // we don't block electron here, as many customers use posthog-js in electron apps
83
84
 
@@ -17,9 +17,13 @@ const CLOCK_STEP_TOLERANCE_MS = 5_000
17
17
  * `Retry-After` as milliseconds from now. The header is either delta-seconds or
18
18
  * an HTTP-date; anything else, a date already in the past, or a non-positive
19
19
  * delta yields `undefined` so the caller keeps its own backoff. The result is
20
- * capped at `MAX_RETRY_AFTER_MS`.
20
+ * capped at `maxMs`, which defaults to `MAX_RETRY_AFTER_MS`.
21
21
  */
22
- export function parseRetryAfterMs(value: unknown, now: number = Date.now()): number | undefined {
22
+ export function parseRetryAfterMs(
23
+ value: unknown,
24
+ now: number = Date.now(),
25
+ maxMs: number = MAX_RETRY_AFTER_MS
26
+ ): number | undefined {
23
27
  if (typeof value !== 'string' || !value) {
24
28
  return undefined
25
29
  }
@@ -32,7 +36,7 @@ export function parseRetryAfterMs(value: unknown, now: number = Date.now()): num
32
36
  // Integer seconds. Not parseFloat: "10 minutes" must not read as 10 seconds.
33
37
  if (/^\d+$/.test(trimmed)) {
34
38
  // Cap before multiplication: even a valid integer can overflow to Infinity.
35
- const ms = Math.min(Number(trimmed), MAX_RETRY_AFTER_MS / 1000) * 1000
39
+ const ms = Math.min(Number(trimmed), maxMs / 1000) * 1000
36
40
  return ms > 0 ? ms : undefined
37
41
  }
38
42
  // HTTP dates start with a weekday. Do not let Date.parse guess a date from
@@ -46,7 +50,7 @@ export function parseRetryAfterMs(value: unknown, now: number = Date.now()): num
46
50
  if (!Number.isFinite(ms) || ms <= 0) {
47
51
  return undefined
48
52
  }
49
- return Math.min(ms, MAX_RETRY_AFTER_MS)
53
+ return Math.min(ms, maxMs)
50
54
  }
51
55
 
52
56
  /** The part of an export outcome the window reads. */