@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
package/dist/esm/Reactor.d.ts
CHANGED
|
@@ -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,i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iBAAiB;mBAC7C,OAAO,kBAAkB,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/esm/Reactor.js
CHANGED
|
@@ -32,6 +32,8 @@ import { InstantStream } from "./Stream.js";
|
|
|
32
32
|
/** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
|
|
33
33
|
/** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
|
|
34
34
|
/** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
|
|
35
|
+
/** @typedef {import('./clientTypes.ts').User} User */
|
|
36
|
+
/** @typedef {import('./clientTypes.ts').AuthState} AuthState */
|
|
35
37
|
export const STATUS = {
|
|
36
38
|
CONNECTING: 'connecting',
|
|
37
39
|
OPENED: 'opened',
|
|
@@ -252,7 +254,9 @@ export default class Reactor {
|
|
|
252
254
|
this._broadcastChannel.addEventListener('message', async (e) => {
|
|
253
255
|
try {
|
|
254
256
|
if (e.data?.type === 'auth') {
|
|
255
|
-
const res = await this.getCurrentUser(
|
|
257
|
+
const res = await this.getCurrentUser({
|
|
258
|
+
forceReadFromStorage: true,
|
|
259
|
+
});
|
|
256
260
|
await this.updateUser(res.user).catch((error) => {
|
|
257
261
|
this._log.error('[error] update user', error);
|
|
258
262
|
});
|
|
@@ -1619,7 +1623,7 @@ export default class Reactor {
|
|
|
1619
1623
|
if (error) {
|
|
1620
1624
|
throw new InstantError('Could not get current user: ' + error.message);
|
|
1621
1625
|
}
|
|
1622
|
-
return user;
|
|
1626
|
+
return user ?? null;
|
|
1623
1627
|
}
|
|
1624
1628
|
subscribeConnectionStatus(cb) {
|
|
1625
1629
|
this.connectionStatusCbs.push(cb);
|
|
@@ -1660,25 +1664,36 @@ export default class Reactor {
|
|
|
1660
1664
|
getCurrentUserCached() {
|
|
1661
1665
|
return this._currentUserCached;
|
|
1662
1666
|
}
|
|
1663
|
-
|
|
1667
|
+
/**
|
|
1668
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
1669
|
+
* @returns {Promise<User | undefined>}
|
|
1670
|
+
*/
|
|
1671
|
+
async _getCurrentUser(opts) {
|
|
1672
|
+
if (opts?.forceReadFromStorage) {
|
|
1673
|
+
await this.kv.unloadKey(currentUserKey);
|
|
1674
|
+
}
|
|
1664
1675
|
const user = await this.kv.waitForKeyToLoad(currentUserKey);
|
|
1665
1676
|
return typeof user === 'string' ? JSON.parse(user) : user;
|
|
1666
1677
|
}
|
|
1667
|
-
|
|
1678
|
+
/**
|
|
1679
|
+
* @param {{ forceReadFromStorage?: boolean }} [opts]
|
|
1680
|
+
* @returns {Promise<AuthState>}
|
|
1681
|
+
*/
|
|
1682
|
+
async getCurrentUser(opts) {
|
|
1668
1683
|
const oauthResp = await this._waitForOAuthCallbackResponse();
|
|
1669
1684
|
if (oauthResp?.error) {
|
|
1670
1685
|
const errorV = { error: oauthResp.error, user: undefined };
|
|
1671
1686
|
this._currentUserCached = { isLoading: false, ...errorV };
|
|
1672
|
-
return
|
|
1687
|
+
return this._currentUserCached;
|
|
1673
1688
|
}
|
|
1674
1689
|
try {
|
|
1675
|
-
const user = await this._getCurrentUser();
|
|
1690
|
+
const user = await this._getCurrentUser(opts);
|
|
1676
1691
|
const userV = { user: user, error: undefined };
|
|
1677
1692
|
this._currentUserCached = {
|
|
1678
1693
|
isLoading: false,
|
|
1679
1694
|
...userV,
|
|
1680
1695
|
};
|
|
1681
|
-
return
|
|
1696
|
+
return this._currentUserCached;
|
|
1682
1697
|
}
|
|
1683
1698
|
catch (e) {
|
|
1684
1699
|
return {
|
|
@@ -1704,6 +1719,9 @@ export default class Reactor {
|
|
|
1704
1719
|
// as they are no longer valid for the new user
|
|
1705
1720
|
await this.updateUser(newUser);
|
|
1706
1721
|
try {
|
|
1722
|
+
// Make sure everything is written to storage before we tell the
|
|
1723
|
+
// other tab to refetch
|
|
1724
|
+
await this.kv.flush();
|
|
1707
1725
|
this._broadcastChannel?.postMessage({ type: 'auth' });
|
|
1708
1726
|
}
|
|
1709
1727
|
catch (error) {
|
|
@@ -1765,7 +1783,7 @@ export default class Reactor {
|
|
|
1765
1783
|
appId: this.config.appId,
|
|
1766
1784
|
email,
|
|
1767
1785
|
code,
|
|
1768
|
-
refreshToken: isGuest ? currentUser
|
|
1786
|
+
refreshToken: isGuest ? currentUser?.user?.refresh_token : undefined,
|
|
1769
1787
|
});
|
|
1770
1788
|
await this.changeCurrentUser(res.user);
|
|
1771
1789
|
return res;
|
|
@@ -1838,7 +1856,7 @@ export default class Reactor {
|
|
|
1838
1856
|
appId: this.config.appId,
|
|
1839
1857
|
code: code,
|
|
1840
1858
|
codeVerifier,
|
|
1841
|
-
refreshToken: isGuest ? currentUser
|
|
1859
|
+
refreshToken: isGuest ? currentUser?.user?.refresh_token : undefined,
|
|
1842
1860
|
});
|
|
1843
1861
|
await this.changeCurrentUser(res.user);
|
|
1844
1862
|
return res;
|