@leanbase-giangnd/js 0.3.0 → 0.3.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.
@@ -0,0 +1,39 @@
1
+ import type { Leanbase } from '../leanbase'
2
+
3
+ export type RequestRouterTarget = 'api' | 'ui' | 'assets'
4
+
5
+ /**
6
+ * Leanbase-local version of PostHog's RequestRouter.
7
+ *
8
+ * Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
9
+ * features like Session Replay can construct ingestion URLs.
10
+ */
11
+ export class RequestRouter {
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ constructor(private readonly instance: Leanbase) {}
14
+
15
+ get apiHost(): string {
16
+ const configured = (this.instance.config.api_host || this.instance.config.host || '').trim()
17
+ return configured.replace(/\/$/, '')
18
+ }
19
+
20
+ get uiHost(): string | undefined {
21
+ const configured = this.instance.config.ui_host?.trim().replace(/\/$/, '')
22
+ return configured || undefined
23
+ }
24
+
25
+ endpointFor(target: RequestRouterTarget, path: string = ''): string {
26
+ if (path) {
27
+ path = path[0] === '/' ? path : `/${path}`
28
+ }
29
+
30
+ if (target === 'ui') {
31
+ const host = this.uiHost || this.apiHost
32
+ return host + path
33
+ }
34
+
35
+ // Leanbase doesn't currently do region-based routing; default to apiHost.
36
+ // Browser's router has special handling for assets; we keep parity in interface, not domains.
37
+ return this.apiHost + path
38
+ }
39
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '0.3.0'
1
+ export const version = '0.3.2'