@koolbase/js 12.38.1 → 12.39.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,20 @@ 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
+ ## 12.39.0
11
+
12
+ A device registers as its signed-in person's (R138). Same contract as koolbase_flutter 12.53.0.
13
+
14
+ - **`Koolbase.messaging`** is here: a browser's FCM token registers as `web`.
15
+ - **`registerToken`** sends the signed-in person's session, so the API ties the device to them -- before, every registration was ownerless and sends to a user never reached their devices. The platform is `android`, `ios` or `web`; anything else is refused before sending. Signing in or out registers the last token again by itself. `userId` is kept but ignored (the API takes the owner from the session).
16
+ - **`initializeForTesting`** keeps messaging on, so the test's server sees a device register.
17
+
18
+ ## 12.38.2
19
+
20
+ Discarding a refused change shows the server's version (R125). Same contract as koolbase_flutter 12.52.8.
21
+
22
+ - **`resolveWithServer` and `abandon`** put the server's version in the device's saved copy and tell what shows the collection, so a shown record or list stops showing the discarded change -- offline too.
23
+
10
24
  ## 12.38.1
11
25
 
12
26
  A shown record follows the app's own writes (R125). Same contract as koolbase_flutter 12.52.7.
@@ -1,14 +1,15 @@
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, KoolbaseConnectivity, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult, type FetchLike } from '@koolbase/core';
4
+ import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult, type FetchLike } from '@koolbase/core';
5
5
  export declare const Koolbase: {
6
6
  initialize(config: KoolbaseConfig): Promise<void>;
7
7
  /**
8
8
  * For tests (R49): the real initialize, against a server you give as
9
9
  * `fetch` -- the SDK's own auth and data code runs; only the server is
10
- * yours -- with storage and the session in memory, and no analytics or
11
- * messaging. Call resetForTesting after each test.
10
+ * yours -- with storage and the session in memory, and no analytics.
11
+ * Messaging registers on that server too (R138). Call resetForTesting
12
+ * after each test.
12
13
  *
13
14
  * ```ts
14
15
  * await Koolbase.initializeForTesting({ fetch: myFakeServer });
@@ -29,6 +30,7 @@ export declare const Koolbase: {
29
30
  readonly realtime: KoolbaseRealtime;
30
31
  readonly connectivity: KoolbaseConnectivity;
31
32
  readonly functions: KoolbaseFunctions;
33
+ readonly messaging: KoolbaseMessaging;
32
34
  readonly analytics: KoolbaseAnalytics;
33
35
  isEnabled(key: string): boolean;
34
36
  configString(key: string, fallback?: string): string;
package/dist/cjs/index.js CHANGED
@@ -4,9 +4,9 @@
4
4
  // The same surface as @koolbase/react-native where the browser can honour it.
5
5
  // What is deliberately absent, so it is not discovered as a method that
6
6
  // fails: code push (a native-bundle concept; the web already has one), the
7
- // logic engine (its flows arrived only through code-push bundles), push
8
- // messaging (FCM tokens come from a native module), and Apple/Google native
9
- // sign-in (use the web OAuth flows against the same auth endpoints).
7
+ // logic engine (its flows arrived only through code-push bundles), and
8
+ // Apple/Google native sign-in (use the web OAuth flows against the same auth
9
+ // endpoints). Messaging registers a browser's FCM token as `web` (R138).
10
10
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
11
  if (k2 === undefined) k2 = k;
12
12
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -39,6 +39,7 @@ let _connectivity = null;
39
39
  let _functions = null;
40
40
  let _flags = null;
41
41
  let _analytics = null;
42
+ let _messaging = null;
42
43
  // While analytics is off, calls are harmless no-ops rather than a crash.
43
44
  const analyticsOff = (0, core_1.disabledAnalytics)();
44
45
  let _initialized = false;
@@ -79,10 +80,17 @@ exports.Koolbase = {
79
80
  _realtime = new core_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
80
81
  // Signed in, signed out, another user: the realtime connection is
81
82
  // replaced to match (signed out, collections anyone can read only).
83
+ let lastUser = _auth?.currentUser?.id ?? null;
82
84
  _auth?.onAuthStateChange(() => {
83
85
  _realtime?.sessionChanged();
84
86
  // Pending writes and conflicts are per-user: watchers read again.
85
87
  _db?.sessionChanged();
88
+ // R138: a registered device follows who is signed in.
89
+ const user = _auth?.currentUser?.id ?? null;
90
+ if (user !== lastUser) {
91
+ lastUser = user;
92
+ void _messaging?.sessionChanged();
93
+ }
86
94
  });
87
95
  // Whether the device reports a connection: unknown until it first answers.
88
96
  _connectivity = new core_1.KoolbaseConnectivity();
@@ -98,6 +106,11 @@ exports.Koolbase = {
98
106
  _analytics = new core_1.KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
99
107
  await _analytics.init(config.appVersion);
100
108
  }
109
+ // A browser's FCM token registers as web (R138).
110
+ if (config.messagingEnabled !== false) {
111
+ _messaging = new core_1.KoolbaseMessaging(config, () => _auth?.validAccessToken() ?? Promise.resolve(null));
112
+ _messaging.setDeviceId(deviceId);
113
+ }
101
114
  _initialized = true;
102
115
  })();
103
116
  try {
@@ -112,8 +125,9 @@ exports.Koolbase = {
112
125
  /**
113
126
  * For tests (R49): the real initialize, against a server you give as
114
127
  * `fetch` -- the SDK's own auth and data code runs; only the server is
115
- * yours -- with storage and the session in memory, and no analytics or
116
- * messaging. Call resetForTesting after each test.
128
+ * yours -- with storage and the session in memory, and no analytics.
129
+ * Messaging registers on that server too (R138). Call resetForTesting
130
+ * after each test.
117
131
  *
118
132
  * ```ts
119
133
  * await Koolbase.initializeForTesting({ fetch: myFakeServer });
@@ -128,7 +142,6 @@ exports.Koolbase = {
128
142
  authStorage: new core_1.MemoryAuthStorage(),
129
143
  fetch: options.fetch,
130
144
  analyticsEnabled: false,
131
- messagingEnabled: false,
132
145
  });
133
146
  },
134
147
  /** After a test (R49): everything initialize made is dropped, so the next one starts from nothing. */
@@ -145,6 +158,7 @@ exports.Koolbase = {
145
158
  _functions = null;
146
159
  _flags = null;
147
160
  _analytics = null;
161
+ _messaging = null;
148
162
  _initialized = false;
149
163
  _initializing = null;
150
164
  },
@@ -155,6 +169,7 @@ exports.Koolbase = {
155
169
  get realtime() { ensureInitialized(); return _realtime; },
156
170
  get connectivity() { ensureInitialized(); return _connectivity; },
157
171
  get functions() { ensureInitialized(); return _functions; },
172
+ get messaging() { ensureInitialized(); return _messaging; },
158
173
  get analytics() {
159
174
  ensureInitialized();
160
175
  return _analytics ?? analyticsOff;
@@ -1,14 +1,15 @@
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, KoolbaseConnectivity, KoolbaseAnalytics, type KoolbaseConfig, type VersionCheckResult, type FetchLike } from '@koolbase/core';
4
+ import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseAnalytics, KoolbaseMessaging, type KoolbaseConfig, type VersionCheckResult, type FetchLike } from '@koolbase/core';
5
5
  export declare const Koolbase: {
6
6
  initialize(config: KoolbaseConfig): Promise<void>;
7
7
  /**
8
8
  * For tests (R49): the real initialize, against a server you give as
9
9
  * `fetch` -- the SDK's own auth and data code runs; only the server is
10
- * yours -- with storage and the session in memory, and no analytics or
11
- * messaging. Call resetForTesting after each test.
10
+ * yours -- with storage and the session in memory, and no analytics.
11
+ * Messaging registers on that server too (R138). Call resetForTesting
12
+ * after each test.
12
13
  *
13
14
  * ```ts
14
15
  * await Koolbase.initializeForTesting({ fetch: myFakeServer });
@@ -29,6 +30,7 @@ export declare const Koolbase: {
29
30
  readonly realtime: KoolbaseRealtime;
30
31
  readonly connectivity: KoolbaseConnectivity;
31
32
  readonly functions: KoolbaseFunctions;
33
+ readonly messaging: KoolbaseMessaging;
32
34
  readonly analytics: KoolbaseAnalytics;
33
35
  isEnabled(key: string): boolean;
34
36
  configString(key: string, fallback?: string): string;
package/dist/esm/index.js CHANGED
@@ -3,13 +3,13 @@
3
3
  // The same surface as @koolbase/react-native where the browser can honour it.
4
4
  // What is deliberately absent, so it is not discovered as a method that
5
5
  // fails: code push (a native-bundle concept; the web already has one), the
6
- // logic engine (its flows arrived only through code-push bundles), push
7
- // messaging (FCM tokens come from a native module), and Apple/Google native
8
- // sign-in (use the web OAuth flows against the same auth endpoints).
6
+ // logic engine (its flows arrived only through code-push bundles), and
7
+ // Apple/Google native sign-in (use the web OAuth flows against the same auth
8
+ // endpoints). Messaging registers a browser's FCM token as `web` (R138).
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, KoolbaseConnectivity, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, getOrCreateDeviceId, setPlatform, setSessionRenewal, setFetch, memoryPlatform, MemoryAuthStorage } from '@koolbase/core';
12
+ import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseConnectivity, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, KoolbaseMessaging, getOrCreateDeviceId, setPlatform, setSessionRenewal, setFetch, memoryPlatform, MemoryAuthStorage } from '@koolbase/core';
13
13
  import { browserPlatform } from './platform.js';
14
14
  let _auth = null;
15
15
  let _db = null;
@@ -20,6 +20,7 @@ let _connectivity = null;
20
20
  let _functions = null;
21
21
  let _flags = null;
22
22
  let _analytics = null;
23
+ let _messaging = null;
23
24
  // While analytics is off, calls are harmless no-ops rather than a crash.
24
25
  const analyticsOff = disabledAnalytics();
25
26
  let _initialized = false;
@@ -60,10 +61,17 @@ export const Koolbase = {
60
61
  _realtime = new KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
61
62
  // Signed in, signed out, another user: the realtime connection is
62
63
  // replaced to match (signed out, collections anyone can read only).
64
+ let lastUser = _auth?.currentUser?.id ?? null;
63
65
  _auth?.onAuthStateChange(() => {
64
66
  _realtime?.sessionChanged();
65
67
  // Pending writes and conflicts are per-user: watchers read again.
66
68
  _db?.sessionChanged();
69
+ // R138: a registered device follows who is signed in.
70
+ const user = _auth?.currentUser?.id ?? null;
71
+ if (user !== lastUser) {
72
+ lastUser = user;
73
+ void _messaging?.sessionChanged();
74
+ }
67
75
  });
68
76
  // Whether the device reports a connection: unknown until it first answers.
69
77
  _connectivity = new KoolbaseConnectivity();
@@ -79,6 +87,11 @@ export const Koolbase = {
79
87
  _analytics = new KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
80
88
  await _analytics.init(config.appVersion);
81
89
  }
90
+ // A browser's FCM token registers as web (R138).
91
+ if (config.messagingEnabled !== false) {
92
+ _messaging = new KoolbaseMessaging(config, () => _auth?.validAccessToken() ?? Promise.resolve(null));
93
+ _messaging.setDeviceId(deviceId);
94
+ }
82
95
  _initialized = true;
83
96
  })();
84
97
  try {
@@ -93,8 +106,9 @@ export const Koolbase = {
93
106
  /**
94
107
  * For tests (R49): the real initialize, against a server you give as
95
108
  * `fetch` -- the SDK's own auth and data code runs; only the server is
96
- * yours -- with storage and the session in memory, and no analytics or
97
- * messaging. Call resetForTesting after each test.
109
+ * yours -- with storage and the session in memory, and no analytics.
110
+ * Messaging registers on that server too (R138). Call resetForTesting
111
+ * after each test.
98
112
  *
99
113
  * ```ts
100
114
  * await Koolbase.initializeForTesting({ fetch: myFakeServer });
@@ -109,7 +123,6 @@ export const Koolbase = {
109
123
  authStorage: new MemoryAuthStorage(),
110
124
  fetch: options.fetch,
111
125
  analyticsEnabled: false,
112
- messagingEnabled: false,
113
126
  });
114
127
  },
115
128
  /** After a test (R49): everything initialize made is dropped, so the next one starts from nothing. */
@@ -126,6 +139,7 @@ export const Koolbase = {
126
139
  _functions = null;
127
140
  _flags = null;
128
141
  _analytics = null;
142
+ _messaging = null;
129
143
  _initialized = false;
130
144
  _initializing = null;
131
145
  },
@@ -136,6 +150,7 @@ export const Koolbase = {
136
150
  get realtime() { ensureInitialized(); return _realtime; },
137
151
  get connectivity() { ensureInitialized(); return _connectivity; },
138
152
  get functions() { ensureInitialized(); return _functions; },
153
+ get messaging() { ensureInitialized(); return _messaging; },
139
154
  get analytics() {
140
155
  ensureInitialized();
141
156
  return _analytics ?? analyticsOff;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/js",
3
- "version": "12.38.1",
3
+ "version": "12.39.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.38.1"
29
+ "@koolbase/core": "^12.39.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"