@leanbase-giangnd/js 0.0.0 → 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/package.json CHANGED
@@ -1,48 +1,47 @@
1
1
  {
2
- "name": "@leanbase-giangnd/js",
3
- "version": "0.0.0",
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
- "scripts": {
17
- "clean": "rimraf dist coverage",
18
- "test:unit": "jest -c jest.config.js",
19
- "lint": "eslint src test",
20
- "lint:fix": "eslint src test --fix",
21
- "prebuild": "node -p \"'export const version = \\'' + require('./package.json').version + '\\''\" > src/version.ts",
22
- "build": "rollup -c",
23
- "dev": "rollup -c -w",
24
- "prepublishOnly": "pnpm lint && pnpm test:unit && pnpm build",
25
- "package": "mkdir -p ../../target && pnpm pack --pack-destination ../../target"
26
- },
27
- "files": [
28
- "dist",
29
- "src",
30
- "README.md"
31
- ],
32
- "publishConfig": {
33
- "access": "public"
34
- },
35
- "dependencies": {
36
- "@posthog/core": "workspace:*",
37
- "@rrweb/record": "2.0.0-alpha.17",
38
- "fflate": "^0.4.8"
39
- },
40
- "devDependencies": {
41
- "@posthog-tooling/tsconfig-base": "workspace:*",
42
- "@posthog-tooling/rollup-utils": "workspace:*",
43
- "jest": "catalog:",
44
- "jest-environment-jsdom": "catalog:",
45
- "rollup": "catalog:",
46
- "rimraf": "^6.0.1"
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
+ }
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.0'
1
+ export const version = '0.0.2'