@koolbase/react-native 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 +20 -5
- package/dist/cjs/platform.js +6 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +21 -6
- package/dist/esm/platform.js +6 -0
- package/package.json +2 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@koolbase/core';
|
|
2
2
|
export { reactNativePlatform } from './platform.js';
|
|
3
|
-
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
3
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
4
4
|
export declare const Koolbase: {
|
|
5
5
|
initialize(config: KoolbaseConfig): Promise<void>;
|
|
6
6
|
readonly auth: KoolbaseAuth;
|
|
@@ -8,6 +8,7 @@ export declare const Koolbase: {
|
|
|
8
8
|
readonly storage: KoolbaseStorage;
|
|
9
9
|
readonly fiscal: KoolbaseFiscal;
|
|
10
10
|
readonly realtime: KoolbaseRealtime;
|
|
11
|
+
readonly connectivity: KoolbaseConnectivity;
|
|
11
12
|
readonly functions: KoolbaseFunctions;
|
|
12
13
|
isEnabled(key: string): boolean;
|
|
13
14
|
configString(key: string, fallback?: string): string;
|
package/dist/cjs/index.js
CHANGED
|
@@ -33,6 +33,7 @@ let _db = null;
|
|
|
33
33
|
let _storage = null;
|
|
34
34
|
let _fiscal = null;
|
|
35
35
|
let _realtime = null;
|
|
36
|
+
let _connectivity = null;
|
|
36
37
|
let _functions = null;
|
|
37
38
|
let _flags = null;
|
|
38
39
|
let _analytics = null;
|
|
@@ -65,21 +66,31 @@ exports.Koolbase = {
|
|
|
65
66
|
// the network. Tests leave this unset and run on the in-memory default.
|
|
66
67
|
(0, core_1.setPlatform)(config.platform ?? (0, platform_js_2.reactNativePlatform)());
|
|
67
68
|
_auth = new core_1.KoolbaseAuth(config);
|
|
69
|
+
// A data request refused with the signed-in person's token renews the
|
|
70
|
+
// session once and goes again (#96); only a refused renewal ends it.
|
|
71
|
+
(0, core_1.setSessionRenewal)((refused) => (_auth ? _auth.renewRejected(refused) : Promise.resolve(null)));
|
|
68
72
|
_db = new core_1.KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null),
|
|
69
73
|
// A session the server refuses is not a session. Clearing it here means an
|
|
70
74
|
// app catching KoolbaseUnauthenticatedError is already signed out and can
|
|
71
75
|
// route to login, rather than looping on a dead token.
|
|
72
|
-
async () => { await _auth?.
|
|
73
|
-
_storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
76
|
+
async () => { await _auth?.sessionRejected(); });
|
|
77
|
+
_storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); },
|
|
74
78
|
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
75
79
|
// missing one nudges a refresh (as Flutter's storage client).
|
|
76
80
|
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
77
|
-
_fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
81
|
+
_fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
78
82
|
_realtime = new core_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
79
83
|
// Signed in, signed out, another user: the realtime connection is
|
|
80
84
|
// replaced to match (signed out, collections anyone can read only).
|
|
81
|
-
_auth?.onAuthStateChange(() =>
|
|
82
|
-
|
|
85
|
+
_auth?.onAuthStateChange(() => {
|
|
86
|
+
_realtime?.sessionChanged();
|
|
87
|
+
// Pending writes and conflicts are per-user: watchers read again.
|
|
88
|
+
_db?.sessionChanged();
|
|
89
|
+
});
|
|
90
|
+
// Whether the device reports a connection: unknown until it first answers.
|
|
91
|
+
_connectivity = new core_1.KoolbaseConnectivity();
|
|
92
|
+
_connectivity.start();
|
|
93
|
+
_functions = new core_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
83
94
|
// One anonymous device id for the whole SDK — bucketing (flags), targeting
|
|
84
95
|
// (code push), and registration keying (messaging) must all agree on it.
|
|
85
96
|
const deviceId = await (0, core_1.getOrCreateDeviceId)();
|
|
@@ -129,6 +140,10 @@ exports.Koolbase = {
|
|
|
129
140
|
ensureInitialized();
|
|
130
141
|
return _realtime;
|
|
131
142
|
},
|
|
143
|
+
get connectivity() {
|
|
144
|
+
ensureInitialized();
|
|
145
|
+
return _connectivity;
|
|
146
|
+
},
|
|
132
147
|
get functions() {
|
|
133
148
|
ensureInitialized();
|
|
134
149
|
return _functions;
|
package/dist/cjs/platform.js
CHANGED
|
@@ -21,6 +21,12 @@ function reactNativePlatform() {
|
|
|
21
21
|
getAllKeys: async () => Array.from(await async_storage_1.default.getAllKeys()),
|
|
22
22
|
},
|
|
23
23
|
network: {
|
|
24
|
+
current: async () => {
|
|
25
|
+
const state = await netinfo_1.default.fetch();
|
|
26
|
+
if (state.isConnected === null || state.isConnected === undefined)
|
|
27
|
+
return null;
|
|
28
|
+
return Boolean(state.isConnected) && state.isInternetReachable !== false;
|
|
29
|
+
},
|
|
24
30
|
onChange: (cb) => netinfo_1.default.addEventListener(state => {
|
|
25
31
|
cb(Boolean(state.isConnected) && state.isInternetReachable !== false);
|
|
26
32
|
}),
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@koolbase/core';
|
|
2
2
|
export { reactNativePlatform } from './platform.js';
|
|
3
|
-
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
3
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult } from '@koolbase/core';
|
|
4
4
|
export declare const Koolbase: {
|
|
5
5
|
initialize(config: KoolbaseConfig): Promise<void>;
|
|
6
6
|
readonly auth: KoolbaseAuth;
|
|
@@ -8,6 +8,7 @@ export declare const Koolbase: {
|
|
|
8
8
|
readonly storage: KoolbaseStorage;
|
|
9
9
|
readonly fiscal: KoolbaseFiscal;
|
|
10
10
|
readonly realtime: KoolbaseRealtime;
|
|
11
|
+
readonly connectivity: KoolbaseConnectivity;
|
|
11
12
|
readonly functions: KoolbaseFunctions;
|
|
12
13
|
isEnabled(key: string): boolean;
|
|
13
14
|
configString(key: string, fallback?: string): string;
|
package/dist/esm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Platform } from 'react-native';
|
|
|
7
7
|
// React Native platform adapter and keychain-backed session storage.
|
|
8
8
|
export * from '@koolbase/core';
|
|
9
9
|
export { reactNativePlatform } from './platform.js';
|
|
10
|
-
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, KoolbaseMessaging, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
|
|
10
|
+
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, KoolbaseMessaging, getOrCreateDeviceId, setPlatform, setSessionRenewal } from '@koolbase/core';
|
|
11
11
|
import { reactNativePlatform } from './platform.js';
|
|
12
12
|
import { createUseCollection, createUseRecord } from '@koolbase/core/react';
|
|
13
13
|
let _auth = null;
|
|
@@ -15,6 +15,7 @@ let _db = null;
|
|
|
15
15
|
let _storage = null;
|
|
16
16
|
let _fiscal = null;
|
|
17
17
|
let _realtime = null;
|
|
18
|
+
let _connectivity = null;
|
|
18
19
|
let _functions = null;
|
|
19
20
|
let _flags = null;
|
|
20
21
|
let _analytics = null;
|
|
@@ -47,21 +48,31 @@ export const Koolbase = {
|
|
|
47
48
|
// the network. Tests leave this unset and run on the in-memory default.
|
|
48
49
|
setPlatform(config.platform ?? reactNativePlatform());
|
|
49
50
|
_auth = new KoolbaseAuth(config);
|
|
51
|
+
// A data request refused with the signed-in person's token renews the
|
|
52
|
+
// session once and goes again (#96); only a refused renewal ends it.
|
|
53
|
+
setSessionRenewal((refused) => (_auth ? _auth.renewRejected(refused) : Promise.resolve(null)));
|
|
50
54
|
_db = new KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null),
|
|
51
55
|
// A session the server refuses is not a session. Clearing it here means an
|
|
52
56
|
// app catching KoolbaseUnauthenticatedError is already signed out and can
|
|
53
57
|
// route to login, rather than looping on a dead token.
|
|
54
|
-
async () => { await _auth?.
|
|
55
|
-
_storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
58
|
+
async () => { await _auth?.sessionRejected(); });
|
|
59
|
+
_storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); },
|
|
56
60
|
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
57
61
|
// missing one nudges a refresh (as Flutter's storage client).
|
|
58
62
|
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
59
|
-
_fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.
|
|
63
|
+
_fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
60
64
|
_realtime = new KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
61
65
|
// Signed in, signed out, another user: the realtime connection is
|
|
62
66
|
// replaced to match (signed out, collections anyone can read only).
|
|
63
|
-
_auth?.onAuthStateChange(() =>
|
|
64
|
-
|
|
67
|
+
_auth?.onAuthStateChange(() => {
|
|
68
|
+
_realtime?.sessionChanged();
|
|
69
|
+
// Pending writes and conflicts are per-user: watchers read again.
|
|
70
|
+
_db?.sessionChanged();
|
|
71
|
+
});
|
|
72
|
+
// Whether the device reports a connection: unknown until it first answers.
|
|
73
|
+
_connectivity = new KoolbaseConnectivity();
|
|
74
|
+
_connectivity.start();
|
|
75
|
+
_functions = new KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.sessionRejected(); });
|
|
65
76
|
// One anonymous device id for the whole SDK — bucketing (flags), targeting
|
|
66
77
|
// (code push), and registration keying (messaging) must all agree on it.
|
|
67
78
|
const deviceId = await getOrCreateDeviceId();
|
|
@@ -111,6 +122,10 @@ export const Koolbase = {
|
|
|
111
122
|
ensureInitialized();
|
|
112
123
|
return _realtime;
|
|
113
124
|
},
|
|
125
|
+
get connectivity() {
|
|
126
|
+
ensureInitialized();
|
|
127
|
+
return _connectivity;
|
|
128
|
+
},
|
|
114
129
|
get functions() {
|
|
115
130
|
ensureInitialized();
|
|
116
131
|
return _functions;
|
package/dist/esm/platform.js
CHANGED
|
@@ -15,6 +15,12 @@ export function reactNativePlatform() {
|
|
|
15
15
|
getAllKeys: async () => Array.from(await AsyncStorage.getAllKeys()),
|
|
16
16
|
},
|
|
17
17
|
network: {
|
|
18
|
+
current: async () => {
|
|
19
|
+
const state = await NetInfo.fetch();
|
|
20
|
+
if (state.isConnected === null || state.isConnected === undefined)
|
|
21
|
+
return null;
|
|
22
|
+
return Boolean(state.isConnected) && state.isInternetReachable !== false;
|
|
23
|
+
},
|
|
18
24
|
onChange: (cb) => NetInfo.addEventListener(state => {
|
|
19
25
|
cb(Boolean(state.isConnected) && state.isInternetReachable !== false);
|
|
20
26
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/react-native",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.15.0",
|
|
4
4
|
"description": "React Native SDK for Koolbase \u2014 auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/koolbase/koolbase-react-native"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@koolbase/core": "12.
|
|
27
|
+
"@koolbase/core": "12.15.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@react-native-async-storage/async-storage": "^2.2.0 || ^3.0.2",
|