@instantdb/core 0.22.144 → 0.22.145
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/commonjs/Reactor.d.ts +17 -17
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +27 -9
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/esm/Reactor.d.ts +17 -17
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +27 -9
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/standalone/index.js +84 -73
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +27 -9
|
@@ -252,7 +252,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
252
252
|
} | null>;
|
|
253
253
|
__subscribeMutationErrors(cb: any): () => void;
|
|
254
254
|
subscribeAuth(cb: any): () => void;
|
|
255
|
-
getAuth(): Promise<
|
|
255
|
+
getAuth(): Promise<import("./clientTypes.ts").User | null>;
|
|
256
256
|
subscribeConnectionStatus(cb: any): () => void;
|
|
257
257
|
subscribeAttrs(cb: any): () => void;
|
|
258
258
|
notifyAuthSubs(user: any): void;
|
|
@@ -265,22 +265,20 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
265
265
|
error: any | undefined;
|
|
266
266
|
user: any | undefined;
|
|
267
267
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
} |
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
};
|
|
283
|
-
}>;
|
|
268
|
+
/**
|
|
269
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
270
|
+
* @returns {Promise<User | undefined>}
|
|
271
|
+
*/
|
|
272
|
+
_getCurrentUser(opts?: {
|
|
273
|
+
forceReadFromStorage?: boolean;
|
|
274
|
+
}): Promise<User | undefined>;
|
|
275
|
+
/**
|
|
276
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
277
|
+
* @returns {Promise<AuthState>}
|
|
278
|
+
*/
|
|
279
|
+
getCurrentUser(opts?: {
|
|
280
|
+
forceReadFromStorage?: boolean;
|
|
281
|
+
}): Promise<AuthState>;
|
|
284
282
|
_hasCurrentUser(): Promise<boolean>;
|
|
285
283
|
changeCurrentUser(newUser: any): Promise<void>;
|
|
286
284
|
syncUserToEndpoint(user: any): Promise<void>;
|
|
@@ -379,6 +377,8 @@ export type TransportType = import("./Connection.ts").TransportType;
|
|
|
379
377
|
export type EventSourceConstructor = import("./Connection.ts").EventSourceConstructor;
|
|
380
378
|
export type QuerySub = import("./reactorTypes.ts").QuerySub;
|
|
381
379
|
export type QuerySubInStorage = import("./reactorTypes.ts").QuerySubInStorage;
|
|
380
|
+
export type User = import("./clientTypes.ts").User;
|
|
381
|
+
export type AuthState = import("./clientTypes.ts").AuthState;
|
|
382
382
|
import * as s from './store.ts';
|
|
383
383
|
import { PersistedObject } from './utils/PersistedObject.ts';
|
|
384
384
|
import { SyncTable } from './SyncTable.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":";;;;;;;AA6MA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAqEpD,8KAmIC;IArMD,uCAAuC;IACvC,OADW,CAAC,CAAC,UAAU,GAAG,SAAS,CAC7B;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,mEAAmE;IACnE,WADW,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CACrD;IAEV,8BA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B,EAAE,IAAI;wBAC/B,OAAO,kBAAkB,EAAE,SAAS;mBAtC/B,YAAY;gCASC,4BAA4B;0BAmBlC,gBAAgB;8BACZ,aAAa;yBArBlB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
|
package/dist/commonjs/Reactor.js
CHANGED
|
@@ -71,6 +71,8 @@ const Stream_ts_1 = require("./Stream.js");
|
|
|
71
71
|
/** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
|
|
72
72
|
/** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
|
|
73
73
|
/** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
|
|
74
|
+
/** @typedef {import('./clientTypes.ts').User} User */
|
|
75
|
+
/** @typedef {import('./clientTypes.ts').AuthState} AuthState */
|
|
74
76
|
exports.STATUS = {
|
|
75
77
|
CONNECTING: 'connecting',
|
|
76
78
|
OPENED: 'opened',
|
|
@@ -291,7 +293,9 @@ class Reactor {
|
|
|
291
293
|
this._broadcastChannel.addEventListener('message', async (e) => {
|
|
292
294
|
try {
|
|
293
295
|
if (e.data?.type === 'auth') {
|
|
294
|
-
const res = await this.getCurrentUser(
|
|
296
|
+
const res = await this.getCurrentUser({
|
|
297
|
+
forceReadFromStorage: true,
|
|
298
|
+
});
|
|
295
299
|
await this.updateUser(res.user).catch((error) => {
|
|
296
300
|
this._log.error('[error] update user', error);
|
|
297
301
|
});
|
|
@@ -1658,7 +1662,7 @@ class Reactor {
|
|
|
1658
1662
|
if (error) {
|
|
1659
1663
|
throw new InstantError_ts_1.InstantError('Could not get current user: ' + error.message);
|
|
1660
1664
|
}
|
|
1661
|
-
return user;
|
|
1665
|
+
return user ?? null;
|
|
1662
1666
|
}
|
|
1663
1667
|
subscribeConnectionStatus(cb) {
|
|
1664
1668
|
this.connectionStatusCbs.push(cb);
|
|
@@ -1699,25 +1703,36 @@ class Reactor {
|
|
|
1699
1703
|
getCurrentUserCached() {
|
|
1700
1704
|
return this._currentUserCached;
|
|
1701
1705
|
}
|
|
1702
|
-
|
|
1706
|
+
/**
|
|
1707
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
1708
|
+
* @returns {Promise<User | undefined>}
|
|
1709
|
+
*/
|
|
1710
|
+
async _getCurrentUser(opts) {
|
|
1711
|
+
if (opts?.forceReadFromStorage) {
|
|
1712
|
+
await this.kv.unloadKey(currentUserKey);
|
|
1713
|
+
}
|
|
1703
1714
|
const user = await this.kv.waitForKeyToLoad(currentUserKey);
|
|
1704
1715
|
return typeof user === 'string' ? JSON.parse(user) : user;
|
|
1705
1716
|
}
|
|
1706
|
-
|
|
1717
|
+
/**
|
|
1718
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
1719
|
+
* @returns {Promise<AuthState>}
|
|
1720
|
+
*/
|
|
1721
|
+
async getCurrentUser(opts) {
|
|
1707
1722
|
const oauthResp = await this._waitForOAuthCallbackResponse();
|
|
1708
1723
|
if (oauthResp?.error) {
|
|
1709
1724
|
const errorV = { error: oauthResp.error, user: undefined };
|
|
1710
1725
|
this._currentUserCached = { isLoading: false, ...errorV };
|
|
1711
|
-
return
|
|
1726
|
+
return this._currentUserCached;
|
|
1712
1727
|
}
|
|
1713
1728
|
try {
|
|
1714
|
-
const user = await this._getCurrentUser();
|
|
1729
|
+
const user = await this._getCurrentUser(opts);
|
|
1715
1730
|
const userV = { user: user, error: undefined };
|
|
1716
1731
|
this._currentUserCached = {
|
|
1717
1732
|
isLoading: false,
|
|
1718
1733
|
...userV,
|
|
1719
1734
|
};
|
|
1720
|
-
return
|
|
1735
|
+
return this._currentUserCached;
|
|
1721
1736
|
}
|
|
1722
1737
|
catch (e) {
|
|
1723
1738
|
return {
|
|
@@ -1743,6 +1758,9 @@ class Reactor {
|
|
|
1743
1758
|
// as they are no longer valid for the new user
|
|
1744
1759
|
await this.updateUser(newUser);
|
|
1745
1760
|
try {
|
|
1761
|
+
// Make sure everything is written to storage before we tell the
|
|
1762
|
+
// other tab to refetch
|
|
1763
|
+
await this.kv.flush();
|
|
1746
1764
|
this._broadcastChannel?.postMessage({ type: 'auth' });
|
|
1747
1765
|
}
|
|
1748
1766
|
catch (error) {
|
|
@@ -1804,7 +1822,7 @@ class Reactor {
|
|
|
1804
1822
|
appId: this.config.appId,
|
|
1805
1823
|
email,
|
|
1806
1824
|
code,
|
|
1807
|
-
refreshToken: isGuest ? currentUser
|
|
1825
|
+
refreshToken: isGuest ? currentUser?.user?.refresh_token : undefined,
|
|
1808
1826
|
});
|
|
1809
1827
|
await this.changeCurrentUser(res.user);
|
|
1810
1828
|
return res;
|
|
@@ -1877,7 +1895,7 @@ class Reactor {
|
|
|
1877
1895
|
appId: this.config.appId,
|
|
1878
1896
|
code: code,
|
|
1879
1897
|
codeVerifier,
|
|
1880
|
-
refreshToken: isGuest ? currentUser
|
|
1898
|
+
refreshToken: isGuest ? currentUser?.user?.refresh_token : undefined,
|
|
1881
1899
|
});
|
|
1882
1900
|
await this.changeCurrentUser(res.user);
|
|
1883
1901
|
return res;
|