@koolbase/js 12.2.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); },
@@ -137,10 +137,14 @@ function makeResolver() {
137
137
  if (await probe(s))
138
138
  return { tier: 'localstorage', store: s };
139
139
  }
140
+ // Outside a browser (Node, a server rendering pages) memory is the
141
+ // expected store, not a symptom, so there is nothing to warn about.
142
+ const inBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
140
143
  // eslint-disable-next-line no-console
141
- console.warn('[Koolbase] No persistent storage available in this browser ' +
142
- '(private browsing, blocked site data, or an exhausted quota). ' +
143
- 'The session and the offline queue will not survive a reload.');
144
+ if (inBrowser)
145
+ console.warn('[Koolbase] No persistent storage available in this browser ' +
146
+ '(private browsing, blocked site data, or an exhausted quota). ' +
147
+ 'The session and the offline queue will not survive a reload.');
144
148
  return { tier: 'memory', store: memoryStorage() };
145
149
  })());
146
150
  return resolving.then((r) => { resolved = r; return r; });
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); },
@@ -134,10 +134,14 @@ function makeResolver() {
134
134
  if (await probe(s))
135
135
  return { tier: 'localstorage', store: s };
136
136
  }
137
+ // Outside a browser (Node, a server rendering pages) memory is the
138
+ // expected store, not a symptom, so there is nothing to warn about.
139
+ const inBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
137
140
  // eslint-disable-next-line no-console
138
- console.warn('[Koolbase] No persistent storage available in this browser ' +
139
- '(private browsing, blocked site data, or an exhausted quota). ' +
140
- 'The session and the offline queue will not survive a reload.');
141
+ if (inBrowser)
142
+ console.warn('[Koolbase] No persistent storage available in this browser ' +
143
+ '(private browsing, blocked site data, or an exhausted quota). ' +
144
+ 'The session and the offline queue will not survive a reload.');
141
145
  return { tier: 'memory', store: memoryStorage() };
142
146
  })());
143
147
  return resolving.then((r) => { resolved = r; return r; });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/js",
3
- "version": "12.2.0",
3
+ "version": "12.4.0",
4
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",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/koolbase/koolbase-react-native"
26
26
  },
27
27
  "dependencies": {
28
- "@koolbase/core": "12.2.0"
28
+ "@koolbase/core": "12.4.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"