@koolbase/js 12.3.0 → 12.4.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.
package/dist/cjs/index.js CHANGED
@@ -38,6 +38,8 @@ let _realtime = null;
38
38
  let _functions = null;
39
39
  let _flags = null;
40
40
  let _analytics = null;
41
+ // While analytics is off, calls are harmless no-ops rather than a crash.
42
+ const analyticsOff = (0, core_1.disabledAnalytics)();
41
43
  let _initialized = false;
42
44
  // The in-flight initialize, so overlapping callers await the same one.
43
45
  //
@@ -69,7 +71,8 @@ exports.Koolbase = {
69
71
  _functions = new core_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
70
72
  const deviceId = await (0, core_1.getOrCreateDeviceId)();
71
73
  _flags = new core_1.KoolbaseFlags(config, deviceId);
72
- if (config.analyticsEnabled !== false) {
74
+ // Opt-in: nothing is sent unless the app asks for it.
75
+ if (config.analyticsEnabled === true) {
73
76
  _analytics = new core_1.KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
74
77
  await _analytics.init(config.appVersion);
75
78
  }
@@ -92,9 +95,7 @@ exports.Koolbase = {
92
95
  get functions() { ensureInitialized(); return _functions; },
93
96
  get analytics() {
94
97
  ensureInitialized();
95
- if (!_analytics)
96
- throw new Error('Analytics is disabled (analyticsEnabled: false).');
97
- return _analytics;
98
+ return _analytics ?? analyticsOff;
98
99
  },
99
100
  isEnabled(key) { ensureInitialized(); return _flags.isEnabled(key); },
100
101
  configString(key, fallback = '') { ensureInitialized(); return _flags.getString(key, fallback); },
package/dist/esm/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  export * from '@koolbase/core';
10
10
  export { BrowserAuthStorage } from './auth-storage.js';
11
11
  export { browserPlatform } from './platform.js';
12
- import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseFlags, KoolbaseAnalytics, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
12
+ import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
13
13
  import { browserPlatform } from './platform.js';
14
14
  let _auth = null;
15
15
  let _db = null;
@@ -19,6 +19,8 @@ let _realtime = null;
19
19
  let _functions = null;
20
20
  let _flags = null;
21
21
  let _analytics = null;
22
+ // While analytics is off, calls are harmless no-ops rather than a crash.
23
+ const analyticsOff = disabledAnalytics();
22
24
  let _initialized = false;
23
25
  // The in-flight initialize, so overlapping callers await the same one.
24
26
  //
@@ -50,7 +52,8 @@ export const Koolbase = {
50
52
  _functions = new KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
51
53
  const deviceId = await getOrCreateDeviceId();
52
54
  _flags = new KoolbaseFlags(config, deviceId);
53
- if (config.analyticsEnabled !== false) {
55
+ // Opt-in: nothing is sent unless the app asks for it.
56
+ if (config.analyticsEnabled === true) {
54
57
  _analytics = new KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
55
58
  await _analytics.init(config.appVersion);
56
59
  }
@@ -73,9 +76,7 @@ export const Koolbase = {
73
76
  get functions() { ensureInitialized(); return _functions; },
74
77
  get analytics() {
75
78
  ensureInitialized();
76
- if (!_analytics)
77
- throw new Error('Analytics is disabled (analyticsEnabled: false).');
78
- return _analytics;
79
+ return _analytics ?? analyticsOff;
79
80
  },
80
81
  isEnabled(key) { ensureInitialized(); return _flags.isEnabled(key); },
81
82
  configString(key, fallback = '') { ensureInitialized(); return _flags.getString(key, fallback); },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koolbase/js",
3
- "version": "12.3.0",
4
- "description": "Koolbase SDK for the browser — auth, database, storage, realtime, functions, flags and offline sync in one package.",
3
+ "version": "12.4.0",
4
+ "description": "Koolbase SDK for the browser \u2014 auth, database, storage, realtime, functions, flags and offline sync in one package.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
7
7
  "files": [
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/koolbase/koolbase-react-native"
26
26
  },
27
27
  "dependencies": {
28
- "@koolbase/core": "12.3.0"
28
+ "@koolbase/core": "12.4.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"