@koolbase/js 10.0.0 → 10.1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,55 @@ is based on [Keep a Changelog][kac], and this project adheres to
7
7
  [kac]: https://keepachangelog.com/en/1.1.0/
8
8
  [semver]: https://semver.org/
9
9
 
10
+ ## 10.1.0
11
+
12
+ ### Fixed
13
+
14
+ - **Uploads could not work from a browser.** `upload()` required
15
+ `{ uri, name, type }` — a React Native shape — and fetched that URI to get
16
+ the bytes. A browser `File` has no `uri`, so every upload from the web
17
+ failed before it reached the network, while the README showed a file input
18
+ as if it worked. `file` now accepts a `Blob` or `File` directly and the
19
+ React Native form is unchanged. Round-tripped in a browser: upload,
20
+ download, byte-for-byte comparison.
21
+
22
+ ### Added
23
+
24
+ - **`storageTier()`** on the browser adapter — `'indexeddb'`,
25
+ `'localstorage'` or `'memory'`. Storage is now chosen by *trying* each
26
+ store rather than checking whether the API exists: Safari in private
27
+ browsing exposes `indexedDB` and may refuse to open it, and a browser with
28
+ site data blocked exposes `localStorage` and throws on write. A failure at
29
+ any tier falls to the next, ending in memory with one console warning. An
30
+ app can read the tier and tell the user their session will not survive a
31
+ reload.
32
+
33
+ ## 10.0.2
34
+
35
+ ### Fixed
36
+
37
+ - **A Node process that initialized the SDK never exited.** The analytics
38
+ flush interval, and a pending realtime reconnect, counted as work on Node's
39
+ event loop, so a CLI, a test runner or an SSR build step hung after its last
40
+ line. Both timers are now unref'd where the runtime supports it. A browser
41
+ is unaffected: the page keeps itself alive regardless.
42
+
43
+ ## 10.0.1
44
+
45
+ ### Fixed
46
+
47
+ - **`restoreSession()` threw in Node.** With no `indexedDB`, the adapter fell
48
+ through to `localStorage`, which does not exist on a server either — so a
49
+ Next.js server render, or any tooling that imports the SDK, crashed with
50
+ `ReferenceError: localStorage is not defined`. Storage now falls back to an
51
+ in-memory store when neither is present, and a server render reports
52
+ `NoSession` rather than failing.
53
+
54
+ Note what this is not: server-side authentication. This package holds one
55
+ session per process, which is correct for a browser tab and wrong for a
56
+ server handling many users. It renders without crashing; it is not a way to
57
+ sign users in on a server.
58
+
10
59
  ## 10.0.0
11
60
 
12
61
  The first release. Numbered to match `@koolbase/react-native` and
package/README.md CHANGED
@@ -11,7 +11,8 @@ feature flags, remote config, and an offline write queue with conflict
11
11
  resolution — one package, one `initialize()` call, TypeScript throughout.
12
12
 
13
13
  Same core as [`@koolbase/react-native`](https://www.npmjs.com/package/@koolbase/react-native).
14
- Same behaviour, proven by the same test suite on both hosts.
14
+ Same behaviour, proven by the same test suite on both hosts. The whole SDK
15
+ is about 16 kB gzipped.
15
16
 
16
17
  ---
17
18
 
@@ -261,7 +262,10 @@ Stated here so nothing is discovered as a method that fails:
261
262
  - **Code push** — a native-bundle concept. The web already ships on deploy.
262
263
  - **Push messaging** — FCM device tokens come from a native module. Use Web
263
264
  Push through your own service worker and your backend.
264
- - **Native Google / Apple sign-in** — use the web OAuth flows, above.
265
+ - **The native sign-in libraries** — `signInWithGoogle` and
266
+ `signInWithApple` themselves are here and work; what a browser cannot do
267
+ is fetch the credential from a native module. Run the provider's web
268
+ OAuth flow and pass the ID token, as above.
265
269
 
266
270
  ---
267
271
 
@@ -1,2 +1,25 @@
1
1
  import type { PlatformAdapter } from '@koolbase/core';
2
- export declare function browserPlatform(): PlatformAdapter;
2
+ /**
3
+ * What a browser is actually willing to persist, decided by trying.
4
+ *
5
+ * Feature detection is not capability detection. Safari in private browsing
6
+ * exposes `indexedDB` and then refuses to open a database; a browser with
7
+ * site data blocked exposes `localStorage` and throws on write; a storage
8
+ * quota can be exhausted at any point afterwards. A selector that checks
9
+ * `typeof` commits to a store that may never work.
10
+ *
11
+ * So the store is resolved on first use, by using it, and the result is
12
+ * cached. A failure at any tier falls to the next, ending in memory — which
13
+ * always works and persists nothing.
14
+ */
15
+ type Tier = 'indexeddb' | 'localstorage' | 'memory';
16
+ /**
17
+ * The browser adapter, plus what only a browser needs: which storage tier it
18
+ * settled on. Not on PlatformAdapter, because no other host has tiers — React
19
+ * Native's keychain either works or its package is absent.
20
+ */
21
+ export interface BrowserPlatformAdapter extends PlatformAdapter {
22
+ storageTier(): Promise<Tier>;
23
+ }
24
+ export declare function browserPlatform(): BrowserPlatformAdapter;
25
+ export {};
@@ -94,10 +94,76 @@ function browserVersion() {
94
94
  const m = /(Chrome|Firefox|Safari|Edg)\/([\d.]+)/.exec(ua);
95
95
  return m ? `${m[1]} ${m[2]}` : '';
96
96
  }
97
+ // Neither store exists during server-side rendering, in a Node tool, or in
98
+ // a worker without storage access. Persisting nothing is the correct answer
99
+ // there: a server render has no session to restore, and the client hydrates
100
+ // with the real one. Throwing instead — which it did — crashes the render.
101
+ function memoryStorage() {
102
+ const m = new Map();
103
+ return {
104
+ getItem: async (k) => m.get(k) ?? null,
105
+ setItem: async (k, v) => { m.set(k, v); },
106
+ removeItem: async (k) => { m.delete(k); },
107
+ getAllKeys: async () => Array.from(m.keys()),
108
+ };
109
+ }
110
+ async function probe(store) {
111
+ const k = '__koolbase_probe__';
112
+ try {
113
+ await store.setItem(k, '1');
114
+ const v = await store.getItem(k);
115
+ await store.removeItem(k);
116
+ return v === '1';
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ function makeResolver() {
123
+ // Per adapter, not per module: two adapters must not share a store, or a
124
+ // server that built one client per request would hand one request's
125
+ // session to the next.
126
+ let resolved = null;
127
+ let resolving = null;
128
+ return () => {
129
+ if (resolved)
130
+ return Promise.resolve(resolved);
131
+ resolving ?? (resolving = (async () => {
132
+ if (typeof indexedDB !== 'undefined') {
133
+ const s = indexedDBStorage();
134
+ if (await probe(s))
135
+ return { tier: 'indexeddb', store: s };
136
+ }
137
+ if (typeof localStorage !== 'undefined') {
138
+ const s = localStorageStorage();
139
+ if (await probe(s))
140
+ return { tier: 'localstorage', store: s };
141
+ }
142
+ // eslint-disable-next-line no-console
143
+ console.warn('[Koolbase] No persistent storage available in this browser ' +
144
+ '(private browsing, blocked site data, or an exhausted quota). ' +
145
+ 'The session and the offline queue will not survive a reload.');
146
+ return { tier: 'memory', store: memoryStorage() };
147
+ })());
148
+ return resolving.then((r) => { resolved = r; return r; });
149
+ };
150
+ }
97
151
  function browserPlatform() {
98
- const hasIDB = typeof indexedDB !== 'undefined';
152
+ const resolve = makeResolver();
153
+ // Every call resolves first, so a browser that only reveals its refusal on
154
+ // use is handled here rather than by the caller.
155
+ const storage = {
156
+ getItem: async (k) => (await resolve()).store.getItem(k),
157
+ setItem: async (k, v) => { await (await resolve()).store.setItem(k, v); },
158
+ removeItem: async (k) => { await (await resolve()).store.removeItem(k); },
159
+ getAllKeys: async () => (await resolve()).store.getAllKeys(),
160
+ };
161
+ // Which tier this adapter settled on: 'indexeddb', 'localstorage' or
162
+ // 'memory'. An app that cares can warn the user before they lose a session.
163
+ const storageTier = async () => (await resolve()).tier;
99
164
  return {
100
- storage: hasIDB ? indexedDBStorage() : localStorageStorage(),
165
+ storageTier,
166
+ storage,
101
167
  network: {
102
168
  onChange: (cb) => {
103
169
  // navigator.onLine is a hint that the interface is up, not that
@@ -1,2 +1,25 @@
1
1
  import type { PlatformAdapter } from '@koolbase/core';
2
- export declare function browserPlatform(): PlatformAdapter;
2
+ /**
3
+ * What a browser is actually willing to persist, decided by trying.
4
+ *
5
+ * Feature detection is not capability detection. Safari in private browsing
6
+ * exposes `indexedDB` and then refuses to open a database; a browser with
7
+ * site data blocked exposes `localStorage` and throws on write; a storage
8
+ * quota can be exhausted at any point afterwards. A selector that checks
9
+ * `typeof` commits to a store that may never work.
10
+ *
11
+ * So the store is resolved on first use, by using it, and the result is
12
+ * cached. A failure at any tier falls to the next, ending in memory — which
13
+ * always works and persists nothing.
14
+ */
15
+ type Tier = 'indexeddb' | 'localstorage' | 'memory';
16
+ /**
17
+ * The browser adapter, plus what only a browser needs: which storage tier it
18
+ * settled on. Not on PlatformAdapter, because no other host has tiers — React
19
+ * Native's keychain either works or its package is absent.
20
+ */
21
+ export interface BrowserPlatformAdapter extends PlatformAdapter {
22
+ storageTier(): Promise<Tier>;
23
+ }
24
+ export declare function browserPlatform(): BrowserPlatformAdapter;
25
+ export {};
@@ -91,10 +91,76 @@ function browserVersion() {
91
91
  const m = /(Chrome|Firefox|Safari|Edg)\/([\d.]+)/.exec(ua);
92
92
  return m ? `${m[1]} ${m[2]}` : '';
93
93
  }
94
+ // Neither store exists during server-side rendering, in a Node tool, or in
95
+ // a worker without storage access. Persisting nothing is the correct answer
96
+ // there: a server render has no session to restore, and the client hydrates
97
+ // with the real one. Throwing instead — which it did — crashes the render.
98
+ function memoryStorage() {
99
+ const m = new Map();
100
+ return {
101
+ getItem: async (k) => m.get(k) ?? null,
102
+ setItem: async (k, v) => { m.set(k, v); },
103
+ removeItem: async (k) => { m.delete(k); },
104
+ getAllKeys: async () => Array.from(m.keys()),
105
+ };
106
+ }
107
+ async function probe(store) {
108
+ const k = '__koolbase_probe__';
109
+ try {
110
+ await store.setItem(k, '1');
111
+ const v = await store.getItem(k);
112
+ await store.removeItem(k);
113
+ return v === '1';
114
+ }
115
+ catch {
116
+ return false;
117
+ }
118
+ }
119
+ function makeResolver() {
120
+ // Per adapter, not per module: two adapters must not share a store, or a
121
+ // server that built one client per request would hand one request's
122
+ // session to the next.
123
+ let resolved = null;
124
+ let resolving = null;
125
+ return () => {
126
+ if (resolved)
127
+ return Promise.resolve(resolved);
128
+ resolving ?? (resolving = (async () => {
129
+ if (typeof indexedDB !== 'undefined') {
130
+ const s = indexedDBStorage();
131
+ if (await probe(s))
132
+ return { tier: 'indexeddb', store: s };
133
+ }
134
+ if (typeof localStorage !== 'undefined') {
135
+ const s = localStorageStorage();
136
+ if (await probe(s))
137
+ return { tier: 'localstorage', store: s };
138
+ }
139
+ // eslint-disable-next-line no-console
140
+ console.warn('[Koolbase] No persistent storage available in this browser ' +
141
+ '(private browsing, blocked site data, or an exhausted quota). ' +
142
+ 'The session and the offline queue will not survive a reload.');
143
+ return { tier: 'memory', store: memoryStorage() };
144
+ })());
145
+ return resolving.then((r) => { resolved = r; return r; });
146
+ };
147
+ }
94
148
  export function browserPlatform() {
95
- const hasIDB = typeof indexedDB !== 'undefined';
149
+ const resolve = makeResolver();
150
+ // Every call resolves first, so a browser that only reveals its refusal on
151
+ // use is handled here rather than by the caller.
152
+ const storage = {
153
+ getItem: async (k) => (await resolve()).store.getItem(k),
154
+ setItem: async (k, v) => { await (await resolve()).store.setItem(k, v); },
155
+ removeItem: async (k) => { await (await resolve()).store.removeItem(k); },
156
+ getAllKeys: async () => (await resolve()).store.getAllKeys(),
157
+ };
158
+ // Which tier this adapter settled on: 'indexeddb', 'localstorage' or
159
+ // 'memory'. An app that cares can warn the user before they lose a session.
160
+ const storageTier = async () => (await resolve()).tier;
96
161
  return {
97
- storage: hasIDB ? indexedDBStorage() : localStorageStorage(),
162
+ storageTier,
163
+ storage,
98
164
  network: {
99
165
  onChange: (cb) => {
100
166
  // navigator.onLine is a hint that the interface is up, not that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/js",
3
- "version": "10.0.0",
3
+ "version": "10.1.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": "10.0.0"
28
+ "@koolbase/core": "10.1.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"