@posthog/core 1.40.1 → 1.41.0

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,9 +1,38 @@
1
+ import type { ExceptionRateLimiterConfig } from '@posthog/types'
1
2
  import { Logger } from '../types'
2
3
  import { clampToRange } from './number-utils'
3
4
 
4
5
  type Bucket = { tokens: number; lastAccess: number }
5
6
  const ONE_DAY_IN_MS = 86400000
6
7
 
8
+ export const DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE = 1
9
+ export const DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE = 10
10
+
11
+ /**
12
+ * Resolves the error tracking rate limiter's `refillRate` and `bucketSize` from SDK config,
13
+ * applying the shared defaults. The deprecated double-underscore options are honoured as a
14
+ * fallback so existing browser SDK configs keep working after the rename.
15
+ */
16
+ export function resolveExceptionRateLimiterConfig(
17
+ config: ExceptionRateLimiterConfig & {
18
+ /** @deprecated use exceptionRateLimiterRefillRate */
19
+ __exceptionRateLimiterRefillRate?: number
20
+ /** @deprecated use exceptionRateLimiterBucketSize */
21
+ __exceptionRateLimiterBucketSize?: number
22
+ } = {}
23
+ ): { refillRate: number; bucketSize: number } {
24
+ return {
25
+ refillRate:
26
+ config.exceptionRateLimiterRefillRate ??
27
+ config.__exceptionRateLimiterRefillRate ??
28
+ DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE,
29
+ bucketSize:
30
+ config.exceptionRateLimiterBucketSize ??
31
+ config.__exceptionRateLimiterBucketSize ??
32
+ DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE,
33
+ }
34
+ }
35
+
7
36
  export class BucketedRateLimiter<T extends string | number> {
8
37
  private _bucketSize: number
9
38
  private _refillRate: number
@@ -6,7 +6,6 @@ import {
6
6
  } from '../types'
7
7
  import { includes } from './string-utils'
8
8
 
9
- // eslint-disable-next-line posthog-js/no-direct-array-check
10
9
  const nativeIsArray = Array.isArray
11
10
  const ObjProto = Object.prototype
12
11
  export const hasOwnProperty = ObjProto.hasOwnProperty
@@ -22,7 +21,6 @@ export const isArray =
22
21
  // fails on only one very rare and deliberate custom object:
23
22
  // let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
24
23
  export const isFunction = (x: unknown): x is (...args: any[]) => any => {
25
- // eslint-disable-next-line posthog-js/no-direct-function-check
26
24
  return typeof x === 'function'
27
25
  }
28
26
 
@@ -53,9 +51,7 @@ export const isString = (x: unknown): x is string => {
53
51
  }
54
52
 
55
53
  export const isEmptyString = (x: unknown): boolean => isString(x) && x.trim().length === 0
56
-
57
54
  export const isNull = (x: unknown): x is null => {
58
- // eslint-disable-next-line posthog-js/no-direct-null-check
59
55
  return x === null
60
56
  }
61
57
 
@@ -66,7 +62,6 @@ export const isNull = (x: unknown): x is null => {
66
62
  export const isNullish = (x: unknown): x is null | undefined => isUndefined(x) || isNull(x)
67
63
 
68
64
  export const isNumber = (x: unknown): x is number => {
69
- // eslint-disable-next-line posthog-js/no-direct-number-check
70
65
  // x !== x is true only for NaN (ES5-compatible NaN check)
71
66
  return toString.call(x) == '[object Number]' && x === x
72
67
  }
@@ -76,7 +71,6 @@ export const isPositiveNumber = (value: unknown): value is number => {
76
71
  }
77
72
 
78
73
  export const isBoolean = (x: unknown): x is boolean => {
79
- // eslint-disable-next-line posthog-js/no-direct-boolean-check
80
74
  return toString.call(x) === '[object Boolean]'
81
75
  }
82
76