@koolbase/js 12.13.1 → 12.15.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.d.ts +2 -1
- package/dist/cjs/index.js +17 -5
- package/dist/cjs/platform.js +27 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +18 -6
- package/dist/esm/platform.js +27 -0
- package/package.json +2 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from '@koolbase/core';
|
|
2
2
|
export { BrowserAuthStorage } from './auth-storage.js';
|
|
3
3
|
export { browserPlatform } from './platform.js';
|
|
4
|
-
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
4
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
5
5
|
export declare const Koolbase: {
|
|
6
6
|
initialize(config: KoolbaseConfig): Promise<void>;
|
|
7
7
|
readonly auth: KoolbaseAuth;
|
|
@@ -9,6 +9,7 @@ export declare const Koolbase: {
|
|
|
9
9
|
readonly storage: KoolbaseStorage;
|
|
10
10
|
readonly fiscal: KoolbaseFiscal;
|
|
11
11
|
readonly realtime: KoolbaseRealtime;
|
|
12
|
+
readonly connectivity: KoolbaseConnectivity;
|
|
12
13
|
readonly functions: KoolbaseFunctions;
|
|
13
14
|
readonly analytics: KoolbaseAnalytics;
|
|
14
15
|
isEnabled(key: string): boolean;
|
package/dist/cjs/index.js
CHANGED
|
@@ -35,6 +35,7 @@ let _db = null;
|
|
|
35
35
|
let _storage = null;
|
|
36
36
|
let _fiscal = null;
|
|
37
37
|
let _realtime = null;
|
|
38
|
+
let _connectivity = null;
|
|
38
39
|
let _functions = null;
|
|
39
40
|
let _flags = null;
|
|
40
41
|
let _analytics = null;
|
|
@@ -64,17 +65,27 @@ exports.Koolbase = {
|
|
|
64
65
|
_initializing = (async () => {
|
|
65
66
|
(0, core_1.setPlatform)(config.platform ?? (0, platform_js_2.browserPlatform)());
|
|
66
67
|
_auth = new core_1.KoolbaseAuth(config);
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
// A data request refused with the signed-in person's token renews the
|
|
69
|
+
// session once and goes again (#96); only a refused renewal ends it.
|
|
70
|
+
(0, core_1.setSessionRenewal)((refused) => (_auth ? _auth.renewRejected(refused) : Promise.resolve(null)));
|
|
71
|
+
_db = new core_1.KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
72
|
+
_storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); },
|
|
69
73
|
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
70
74
|
// missing one nudges a refresh (as Flutter's storage client).
|
|
71
75
|
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
72
|
-
_fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
76
|
+
_fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
73
77
|
_realtime = new core_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
74
78
|
// Signed in, signed out, another user: the realtime connection is
|
|
75
79
|
// replaced to match (signed out, collections anyone can read only).
|
|
76
|
-
_auth?.onAuthStateChange(() =>
|
|
77
|
-
|
|
80
|
+
_auth?.onAuthStateChange(() => {
|
|
81
|
+
_realtime?.sessionChanged();
|
|
82
|
+
// Pending writes and conflicts are per-user: watchers read again.
|
|
83
|
+
_db?.sessionChanged();
|
|
84
|
+
});
|
|
85
|
+
// Whether the device reports a connection: unknown until it first answers.
|
|
86
|
+
_connectivity = new core_1.KoolbaseConnectivity();
|
|
87
|
+
_connectivity.start();
|
|
88
|
+
_functions = new core_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
78
89
|
const deviceId = await (0, core_1.getOrCreateDeviceId)();
|
|
79
90
|
_flags = new core_1.KoolbaseFlags(config, deviceId);
|
|
80
91
|
// The bootstrap payload (flags, config, version policy, project identity),
|
|
@@ -101,6 +112,7 @@ exports.Koolbase = {
|
|
|
101
112
|
get storage() { ensureInitialized(); return _storage; },
|
|
102
113
|
get fiscal() { ensureInitialized(); return _fiscal; },
|
|
103
114
|
get realtime() { ensureInitialized(); return _realtime; },
|
|
115
|
+
get connectivity() { ensureInitialized(); return _connectivity; },
|
|
104
116
|
get functions() { ensureInitialized(); return _functions; },
|
|
105
117
|
get analytics() {
|
|
106
118
|
ensureInitialized();
|
package/dist/cjs/platform.js
CHANGED
|
@@ -232,7 +232,13 @@ function browserPlatform() {
|
|
|
232
232
|
return {
|
|
233
233
|
storageTier,
|
|
234
234
|
storage,
|
|
235
|
+
broadcast: browserBroadcast(),
|
|
235
236
|
network: {
|
|
237
|
+
// navigator.onLine: false is reliable; true means an interface is up.
|
|
238
|
+
// A hint either way, like the events below. No window: cannot tell.
|
|
239
|
+
current: async () => typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean'
|
|
240
|
+
? navigator.onLine
|
|
241
|
+
: null,
|
|
236
242
|
onChange: (cb) => {
|
|
237
243
|
// navigator.onLine is a hint that the interface is up, not that
|
|
238
244
|
// Koolbase is reachable. The sync engine treats a false positive as
|
|
@@ -278,3 +284,24 @@ function browserPlatform() {
|
|
|
278
284
|
authStorage: () => new auth_storage_js_1.BrowserAuthStorage(),
|
|
279
285
|
};
|
|
280
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Other tabs of this origin, told when offline state changes, so a sync badge
|
|
289
|
+
* in one tab moves when another tab's sync drains the queue. Absent outside a
|
|
290
|
+
* browser or where BroadcastChannel is not supported.
|
|
291
|
+
*/
|
|
292
|
+
function browserBroadcast() {
|
|
293
|
+
if (typeof window === 'undefined' || typeof BroadcastChannel === 'undefined')
|
|
294
|
+
return undefined;
|
|
295
|
+
const channel = new BroadcastChannel('koolbase');
|
|
296
|
+
return {
|
|
297
|
+
post: (message) => channel.postMessage(message),
|
|
298
|
+
on: (callback) => {
|
|
299
|
+
const handler = (event) => {
|
|
300
|
+
if (typeof event.data === 'string')
|
|
301
|
+
callback(event.data);
|
|
302
|
+
};
|
|
303
|
+
channel.addEventListener('message', handler);
|
|
304
|
+
return () => channel.removeEventListener('message', handler);
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from '@koolbase/core';
|
|
2
2
|
export { BrowserAuthStorage } from './auth-storage.js';
|
|
3
3
|
export { browserPlatform } from './platform.js';
|
|
4
|
-
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
4
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
5
5
|
export declare const Koolbase: {
|
|
6
6
|
initialize(config: KoolbaseConfig): Promise<void>;
|
|
7
7
|
readonly auth: KoolbaseAuth;
|
|
@@ -9,6 +9,7 @@ export declare const Koolbase: {
|
|
|
9
9
|
readonly storage: KoolbaseStorage;
|
|
10
10
|
readonly fiscal: KoolbaseFiscal;
|
|
11
11
|
readonly realtime: KoolbaseRealtime;
|
|
12
|
+
readonly connectivity: KoolbaseConnectivity;
|
|
12
13
|
readonly functions: KoolbaseFunctions;
|
|
13
14
|
readonly analytics: KoolbaseAnalytics;
|
|
14
15
|
isEnabled(key: string): boolean;
|
package/dist/esm/index.js
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
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, disabledAnalytics, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
|
|
12
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, getOrCreateDeviceId, setPlatform, setSessionRenewal } from '@koolbase/core';
|
|
13
13
|
import { browserPlatform } from './platform.js';
|
|
14
14
|
let _auth = null;
|
|
15
15
|
let _db = null;
|
|
16
16
|
let _storage = null;
|
|
17
17
|
let _fiscal = null;
|
|
18
18
|
let _realtime = null;
|
|
19
|
+
let _connectivity = null;
|
|
19
20
|
let _functions = null;
|
|
20
21
|
let _flags = null;
|
|
21
22
|
let _analytics = null;
|
|
@@ -45,17 +46,27 @@ export const Koolbase = {
|
|
|
45
46
|
_initializing = (async () => {
|
|
46
47
|
setPlatform(config.platform ?? browserPlatform());
|
|
47
48
|
_auth = new KoolbaseAuth(config);
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
// A data request refused with the signed-in person's token renews the
|
|
50
|
+
// session once and goes again (#96); only a refused renewal ends it.
|
|
51
|
+
setSessionRenewal((refused) => (_auth ? _auth.renewRejected(refused) : Promise.resolve(null)));
|
|
52
|
+
_db = new KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
53
|
+
_storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); },
|
|
50
54
|
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
51
55
|
// missing one nudges a refresh (as Flutter's storage client).
|
|
52
56
|
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
53
|
-
_fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
57
|
+
_fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
54
58
|
_realtime = new KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
55
59
|
// Signed in, signed out, another user: the realtime connection is
|
|
56
60
|
// replaced to match (signed out, collections anyone can read only).
|
|
57
|
-
_auth?.onAuthStateChange(() =>
|
|
58
|
-
|
|
61
|
+
_auth?.onAuthStateChange(() => {
|
|
62
|
+
_realtime?.sessionChanged();
|
|
63
|
+
// Pending writes and conflicts are per-user: watchers read again.
|
|
64
|
+
_db?.sessionChanged();
|
|
65
|
+
});
|
|
66
|
+
// Whether the device reports a connection: unknown until it first answers.
|
|
67
|
+
_connectivity = new KoolbaseConnectivity();
|
|
68
|
+
_connectivity.start();
|
|
69
|
+
_functions = new KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
59
70
|
const deviceId = await getOrCreateDeviceId();
|
|
60
71
|
_flags = new KoolbaseFlags(config, deviceId);
|
|
61
72
|
// The bootstrap payload (flags, config, version policy, project identity),
|
|
@@ -82,6 +93,7 @@ export const Koolbase = {
|
|
|
82
93
|
get storage() { ensureInitialized(); return _storage; },
|
|
83
94
|
get fiscal() { ensureInitialized(); return _fiscal; },
|
|
84
95
|
get realtime() { ensureInitialized(); return _realtime; },
|
|
96
|
+
get connectivity() { ensureInitialized(); return _connectivity; },
|
|
85
97
|
get functions() { ensureInitialized(); return _functions; },
|
|
86
98
|
get analytics() {
|
|
87
99
|
ensureInitialized();
|
package/dist/esm/platform.js
CHANGED
|
@@ -229,7 +229,13 @@ export function browserPlatform() {
|
|
|
229
229
|
return {
|
|
230
230
|
storageTier,
|
|
231
231
|
storage,
|
|
232
|
+
broadcast: browserBroadcast(),
|
|
232
233
|
network: {
|
|
234
|
+
// navigator.onLine: false is reliable; true means an interface is up.
|
|
235
|
+
// A hint either way, like the events below. No window: cannot tell.
|
|
236
|
+
current: async () => typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean'
|
|
237
|
+
? navigator.onLine
|
|
238
|
+
: null,
|
|
233
239
|
onChange: (cb) => {
|
|
234
240
|
// navigator.onLine is a hint that the interface is up, not that
|
|
235
241
|
// Koolbase is reachable. The sync engine treats a false positive as
|
|
@@ -275,3 +281,24 @@ export function browserPlatform() {
|
|
|
275
281
|
authStorage: () => new BrowserAuthStorage(),
|
|
276
282
|
};
|
|
277
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Other tabs of this origin, told when offline state changes, so a sync badge
|
|
286
|
+
* in one tab moves when another tab's sync drains the queue. Absent outside a
|
|
287
|
+
* browser or where BroadcastChannel is not supported.
|
|
288
|
+
*/
|
|
289
|
+
function browserBroadcast() {
|
|
290
|
+
if (typeof window === 'undefined' || typeof BroadcastChannel === 'undefined')
|
|
291
|
+
return undefined;
|
|
292
|
+
const channel = new BroadcastChannel('koolbase');
|
|
293
|
+
return {
|
|
294
|
+
post: (message) => channel.postMessage(message),
|
|
295
|
+
on: (callback) => {
|
|
296
|
+
const handler = (event) => {
|
|
297
|
+
if (typeof event.data === 'string')
|
|
298
|
+
callback(event.data);
|
|
299
|
+
};
|
|
300
|
+
channel.addEventListener('message', handler);
|
|
301
|
+
return () => channel.removeEventListener('message', handler);
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/js",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.15.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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"url": "https://github.com/koolbase/koolbase-react-native"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@koolbase/core": "12.
|
|
29
|
+
"@koolbase/core": "12.15.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|