@leanbase-giangnd/js 0.0.4 → 0.0.7
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/index.cjs +261 -2875
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +95 -685
- package/dist/index.mjs +262 -2876
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +236 -8815
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +5 -6
- package/src/extensions/replay/external/README.md +5 -0
- package/src/extensions/replay/external/config.ts +25 -33
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +71 -67
- package/src/extensions/replay/external/mutation-throttler.ts +1 -4
- package/src/extensions/replay/external/network-plugin.ts +3 -10
- package/src/extensions/replay/external/triggerMatching.ts +13 -13
- package/src/extensions/replay/rrweb-plugins/patch.ts +7 -0
- package/src/extensions/replay/session-recording.ts +61 -50
- package/src/extensions/utils/stylesheet-loader.ts +27 -0
- package/src/leanbase.ts +51 -154
- package/src/posthog-core.ts +12 -0
- package/src/types.ts +119 -123
- package/src/utils/globals.ts +239 -0
- package/src/utils/logger.ts +51 -13
- package/src/utils/request-router.ts +77 -0
- package/src/utils/type-utils.ts +139 -0
- package/src/version.ts +1 -1
- package/src/types/fflate.d.ts +0 -6
- package/src/types/rrweb-record.d.ts +0 -8
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PostHog } from '../posthog-core'
|
|
2
|
+
|
|
3
|
+
export enum RequestRouterRegion {
|
|
4
|
+
US = 'us',
|
|
5
|
+
EU = 'eu',
|
|
6
|
+
CUSTOM = 'custom',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RequestRouterTarget = 'api' | 'ui' | 'assets'
|
|
10
|
+
|
|
11
|
+
const ingestionDomain = 'i.posthog.com'
|
|
12
|
+
|
|
13
|
+
export class RequestRouter {
|
|
14
|
+
instance: PostHog
|
|
15
|
+
private _regionCache: Record<string, RequestRouterRegion> = {}
|
|
16
|
+
|
|
17
|
+
constructor(instance: PostHog) {
|
|
18
|
+
this.instance = instance
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get apiHost(): string {
|
|
22
|
+
const host = this.instance.config.api_host.trim().replace(/\/$/, '')
|
|
23
|
+
if (host === 'https://app.posthog.com') {
|
|
24
|
+
return 'https://us.i.posthog.com'
|
|
25
|
+
}
|
|
26
|
+
return host
|
|
27
|
+
}
|
|
28
|
+
get uiHost(): string | undefined {
|
|
29
|
+
let host = this.instance.config.ui_host?.replace(/\/$/, '')
|
|
30
|
+
|
|
31
|
+
if (!host) {
|
|
32
|
+
host = this.apiHost.replace(`.${ingestionDomain}`, '.posthog.com')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (host === 'https://app.posthog.com') {
|
|
36
|
+
return 'https://us.posthog.com'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return host
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get region(): RequestRouterRegion {
|
|
43
|
+
if (!this._regionCache[this.apiHost]) {
|
|
44
|
+
if (/https:\/\/(app|us|us-assets)(\\.i)?\\.posthog\\.com/i.test(this.apiHost)) {
|
|
45
|
+
this._regionCache[this.apiHost] = RequestRouterRegion.US
|
|
46
|
+
} else if (/https:\/\/(eu|eu-assets)(\\.i)?\\.posthog\\.com/i.test(this.apiHost)) {
|
|
47
|
+
this._regionCache[this.apiHost] = RequestRouterRegion.EU
|
|
48
|
+
} else {
|
|
49
|
+
this._regionCache[this.apiHost] = RequestRouterRegion.CUSTOM
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return this._regionCache[this.apiHost]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
endpointFor(target: RequestRouterTarget, path: string = ''): string {
|
|
56
|
+
if (path) {
|
|
57
|
+
path = path[0] === '/' ? path : `/${path}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (target === 'ui') {
|
|
61
|
+
return this.uiHost + path
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.region === RequestRouterRegion.CUSTOM) {
|
|
65
|
+
return this.apiHost + path
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const suffix = ingestionDomain + path
|
|
69
|
+
|
|
70
|
+
switch (target) {
|
|
71
|
+
case 'assets':
|
|
72
|
+
return `https://${this.region}-assets.${suffix}`
|
|
73
|
+
case 'api':
|
|
74
|
+
return `https://${this.region}.${suffix}`
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { knownUnsafeEditableEvent, KnownUnsafeEditableEvent } from '@posthog/core'
|
|
2
|
+
import { includes } from '@posthog/core'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line posthog-js/no-direct-array-check
|
|
5
|
+
const nativeIsArray = Array.isArray
|
|
6
|
+
const ObjProto = Object.prototype
|
|
7
|
+
export const hasOwnProperty = ObjProto.hasOwnProperty
|
|
8
|
+
const toString = ObjProto.toString
|
|
9
|
+
|
|
10
|
+
export const isArray =
|
|
11
|
+
nativeIsArray ||
|
|
12
|
+
function (obj: any): obj is any[] {
|
|
13
|
+
return toString.call(obj) === '[object Array]'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// from a comment on http://dbj.org/dbj/?p=286
|
|
17
|
+
// fails on only one very rare and deliberate custom object:
|
|
18
|
+
// let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
19
|
+
export const isFunction = (x: unknown): x is (...args: any[]) => any => {
|
|
20
|
+
// eslint-disable-next-line posthog-js/no-direct-function-check
|
|
21
|
+
return typeof x === 'function'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const isNativeFunction = (x: unknown): x is (...args: any[]) => any =>
|
|
25
|
+
isFunction(x) && x.toString().indexOf('[native code]') !== -1
|
|
26
|
+
|
|
27
|
+
// Underscore Addons
|
|
28
|
+
export const isObject = (x: unknown): x is Record<string, any> => {
|
|
29
|
+
// eslint-disable-next-line posthog-js/no-direct-object-check
|
|
30
|
+
return x === Object(x) && !isArray(x)
|
|
31
|
+
}
|
|
32
|
+
export const isEmptyObject = (x: unknown) => {
|
|
33
|
+
if (isObject(x)) {
|
|
34
|
+
for (const key in x) {
|
|
35
|
+
if (hasOwnProperty.call(x, key)) {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
export const isUndefined = (x: unknown): x is undefined => x === void 0
|
|
44
|
+
|
|
45
|
+
export const isString = (x: unknown): x is string => {
|
|
46
|
+
// eslint-disable-next-line posthog-js/no-direct-string-check
|
|
47
|
+
return toString.call(x) == '[object String]'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const isEmptyString = (x: unknown): boolean => isString(x) && x.trim().length === 0
|
|
51
|
+
|
|
52
|
+
export const isNull = (x: unknown): x is null => {
|
|
53
|
+
// eslint-disable-next-line posthog-js/no-direct-null-check
|
|
54
|
+
return x === null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
sometimes you want to check if something is null or undefined
|
|
59
|
+
that's what this is for
|
|
60
|
+
*/
|
|
61
|
+
export const isNullish = (x: unknown): x is null | undefined => isUndefined(x) || isNull(x)
|
|
62
|
+
|
|
63
|
+
export const isNumber = (x: unknown): x is number => {
|
|
64
|
+
// eslint-disable-next-line posthog-js/no-direct-number-check
|
|
65
|
+
return toString.call(x) == '[object Number]'
|
|
66
|
+
}
|
|
67
|
+
export const isBoolean = (x: unknown): x is boolean => {
|
|
68
|
+
// eslint-disable-next-line posthog-js/no-direct-boolean-check
|
|
69
|
+
return toString.call(x) === '[object Boolean]'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const isFormData = (x: unknown): x is FormData => {
|
|
73
|
+
// eslint-disable-next-line posthog-js/no-direct-form-data-check
|
|
74
|
+
return x instanceof FormData
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const isFile = (x: unknown): x is File => {
|
|
78
|
+
// eslint-disable-next-line posthog-js/no-direct-file-check
|
|
79
|
+
return x instanceof File
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const isPlainError = (x: unknown): x is Error => {
|
|
83
|
+
return x instanceof Error
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const isKnownUnsafeEditableEvent = (x: unknown): x is KnownUnsafeEditableEvent => {
|
|
87
|
+
return includes(knownUnsafeEditableEvent as unknown as string[], x)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function isInstanceOf(candidate: unknown, base: any): boolean {
|
|
91
|
+
try {
|
|
92
|
+
return candidate instanceof base
|
|
93
|
+
} catch {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function isPrimitive(value: unknown): boolean {
|
|
99
|
+
return isNull(value) || typeof value !== 'object'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isBuiltin(candidate: unknown, className: string): boolean {
|
|
103
|
+
return Object.prototype.toString.call(candidate) === `[object ${className}]`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function isError(candidate: unknown): candidate is Error {
|
|
107
|
+
switch (Object.prototype.toString.call(candidate)) {
|
|
108
|
+
case '[object Error]':
|
|
109
|
+
case '[object Exception]':
|
|
110
|
+
case '[object DOMException]':
|
|
111
|
+
case '[object DOMError]':
|
|
112
|
+
case '[object WebAssembly.Exception]':
|
|
113
|
+
return true
|
|
114
|
+
default:
|
|
115
|
+
return isInstanceOf(candidate, Error)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function isErrorEvent(event: unknown): boolean {
|
|
120
|
+
return isBuiltin(event, 'ErrorEvent')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function isEvent(candidate: unknown): candidate is Event {
|
|
124
|
+
return !isUndefined(Event) && isInstanceOf(candidate, Event)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const isDocument = (x: unknown): x is Document => {
|
|
128
|
+
// eslint-disable-next-line posthog-js/no-direct-document-check
|
|
129
|
+
return typeof Document !== 'undefined' && isInstanceOf(x, Document)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function isPlainObject(candidate: unknown): candidate is Record<string, unknown> {
|
|
133
|
+
return isBuiltin(candidate, 'Object')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const yesLikeValues = [true, 'true', 1, '1', 'yes']
|
|
137
|
+
export const isYesLike = (val: string | boolean | number): boolean => includes(yesLikeValues, val)
|
|
138
|
+
export const noLikeValues = [false, 'false', 0, '0', 'no']
|
|
139
|
+
export const isNoLike = (val: string | boolean | number): boolean => includes(noLikeValues, val)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.0.
|
|
1
|
+
export const version = '0.0.7'
|
package/src/types/fflate.d.ts
DELETED