@leanbase-giangnd/js 0.0.1 → 0.0.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/LICENSE +37 -0
- package/dist/index.cjs +26 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +26 -5
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +31 -7
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +46 -47
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +2 -4
- package/src/leanbase.ts +26 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,48 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
2
|
+
"name": "@leanbase-giangnd/js",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Leanbase browser SDK - event tracking, autocapture, and session replay",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"directory": "packages/leanbase"
|
|
8
|
+
},
|
|
9
|
+
"author": "leanbase",
|
|
10
|
+
"license": "Copyrighted by Leanflag Limited",
|
|
11
|
+
"main": "dist/index.cjs",
|
|
12
|
+
"module": "dist/index.mjs",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"unpkg": "dist/leanbase.iife.js",
|
|
15
|
+
"jsdelivr": "dist/leanbase.iife.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@rrweb/record": "2.0.0-alpha.17",
|
|
26
|
+
"fflate": "^0.4.8",
|
|
27
|
+
"@posthog/core": "1.3.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"jest": "^29.7.0",
|
|
31
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
32
|
+
"rollup": "^4.44.1",
|
|
33
|
+
"rimraf": "^6.0.1",
|
|
34
|
+
"@posthog-tooling/rollup-utils": "1.0.0",
|
|
35
|
+
"@posthog-tooling/tsconfig-base": "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"clean": "rimraf dist coverage",
|
|
39
|
+
"test:unit": "jest -c jest.config.js",
|
|
40
|
+
"lint": "eslint src test",
|
|
41
|
+
"lint:fix": "eslint src test --fix",
|
|
42
|
+
"prebuild": "node -p \"'export const version = \\'' + require('./package.json').version + '\\''\" > src/version.ts",
|
|
43
|
+
"build": "rollup -c",
|
|
44
|
+
"dev": "rollup -c -w",
|
|
45
|
+
"package": "mkdir -p ../../target && pnpm pack --pack-destination ../../target"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1031,14 +1031,12 @@ export class LazyLoadedSessionRecording {
|
|
|
1031
1031
|
|
|
1032
1032
|
private _snapshotUrl(): string {
|
|
1033
1033
|
const host = this._instance.config.host || ''
|
|
1034
|
-
// Ensure endpoint is set; default to /s/ if not provided or malformed
|
|
1035
|
-
const endpoint = this._endpoint || '/s/'
|
|
1036
1034
|
try {
|
|
1037
1035
|
// eslint-disable-next-line compat/compat
|
|
1038
|
-
return new URL(
|
|
1036
|
+
return new URL(this._endpoint, host).href
|
|
1039
1037
|
} catch {
|
|
1040
1038
|
const normalizedHost = host.endsWith('/') ? host.slice(0, -1) : host
|
|
1041
|
-
const normalizedEndpoint =
|
|
1039
|
+
const normalizedEndpoint = this._endpoint.startsWith('/') ? this._endpoint.slice(1) : this._endpoint
|
|
1042
1040
|
return `${normalizedHost}/${normalizedEndpoint}`
|
|
1043
1041
|
}
|
|
1044
1042
|
}
|
package/src/leanbase.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PostHogCore,
|
|
3
3
|
getFetch,
|
|
4
|
+
isArray,
|
|
4
5
|
isEmptyObject,
|
|
5
6
|
isEmptyString,
|
|
6
7
|
isNumber,
|
|
@@ -213,6 +214,31 @@ export class Leanbase extends PostHogCore {
|
|
|
213
214
|
if (!fetchFn) {
|
|
214
215
|
return Promise.reject(new Error('Fetch API is not available in this environment.'))
|
|
215
216
|
}
|
|
217
|
+
try {
|
|
218
|
+
const isPost = !options.method || options.method.toUpperCase() === 'POST'
|
|
219
|
+
const isBatchEndpoint = typeof url === 'string' && url.endsWith('/batch/')
|
|
220
|
+
|
|
221
|
+
if (isPost && isBatchEndpoint && options && options.body) {
|
|
222
|
+
let parsed: any = null
|
|
223
|
+
try {
|
|
224
|
+
const bodyString = typeof options.body === 'string' ? options.body : String(options.body)
|
|
225
|
+
parsed = JSON.parse(bodyString)
|
|
226
|
+
} catch {
|
|
227
|
+
parsed = null
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (parsed && isArray(parsed.batch)) {
|
|
231
|
+
const hasSnapshot = parsed.batch.some((item: any) => item && item.event === '$snapshot')
|
|
232
|
+
if (hasSnapshot) {
|
|
233
|
+
const host = (this.config && this.config.host) || ''
|
|
234
|
+
const newUrl = host ? `${host.replace(/\/$/, '')}/s/` : url
|
|
235
|
+
return fetchFn(newUrl, options)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
return fetchFn(url, options)
|
|
241
|
+
}
|
|
216
242
|
|
|
217
243
|
return fetchFn(url, options)
|
|
218
244
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.0.
|
|
1
|
+
export const version = '0.0.2'
|