@vue-skuilder/db 0.2.25 → 0.2.26
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/{SyncStrategy-CCU1H81I.d.cts → SyncStrategy-BXliog1m.d.cts} +14 -1
- package/dist/{SyncStrategy-CCU1H81I.d.ts → SyncStrategy-BXliog1m.d.ts} +14 -1
- package/dist/{contentSource-CrRnbjBx.d.cts → contentSource-D3c1fMAk.d.cts} +11 -0
- package/dist/{contentSource-kD35o65m.d.ts → contentSource-LPf044hY.d.ts} +11 -0
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +34 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +34 -0
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-IecbidDO.d.cts → dataLayerProvider-CeLiFbHv.d.cts} +1 -1
- package/dist/{dataLayerProvider-CtzddVdy.d.ts → dataLayerProvider-DaAootVV.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +4 -3
- package/dist/impl/couch/index.d.ts +4 -3
- package/dist/impl/couch/index.js +50 -0
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +50 -0
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +3 -3
- package/dist/impl/static/index.d.ts +3 -3
- package/dist/impl/static/index.js +34 -0
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +34 -0
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/core/interfaces/userDB.ts +10 -0
- package/src/impl/common/BaseUserDB.ts +40 -0
- package/src/impl/common/SyncStrategy.ts +11 -1
- package/src/impl/common/index.ts +1 -0
- package/src/impl/common/types.ts +5 -0
- package/src/impl/couch/CouchDBSyncStrategy.ts +25 -1
- package/src/study/SessionController.ts +6 -2
|
@@ -9673,6 +9673,40 @@ Currently logged-in as ${this._username}.`
|
|
|
9673
9673
|
}
|
|
9674
9674
|
return loginResult;
|
|
9675
9675
|
}
|
|
9676
|
+
/**
|
|
9677
|
+
* Adopt a remote session that was established outside this client — e.g. a
|
|
9678
|
+
* backend verified a third-party sign-in (Google) and set the session cookie
|
|
9679
|
+
* on its response. Afterwards the user is logged in exactly as after
|
|
9680
|
+
* login(): username switched, guest pointer cleared, init() re-run.
|
|
9681
|
+
*
|
|
9682
|
+
* @param opts.migrateGuestData Carry the current guest account's local data
|
|
9683
|
+
* into the adopted account. Pass true for a freshly created account (as
|
|
9684
|
+
* createAccount() does), false for an existing one (as login() does).
|
|
9685
|
+
*/
|
|
9686
|
+
async adoptSession(opts) {
|
|
9687
|
+
if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
|
|
9688
|
+
throw new Error("Session adoption not supported by current sync strategy");
|
|
9689
|
+
}
|
|
9690
|
+
const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
|
|
9691
|
+
if (!guestUsername) {
|
|
9692
|
+
throw new Error(`Cannot adopt a session while logged in.
|
|
9693
|
+
Log out of account ${this.getUsername()} first.`);
|
|
9694
|
+
}
|
|
9695
|
+
const result = await this.syncStrategy.adoptSession(
|
|
9696
|
+
opts.migrateGuestData ? guestUsername : void 0
|
|
9697
|
+
);
|
|
9698
|
+
if (result.ok && result.username) {
|
|
9699
|
+
log3(`Adopted session for ${result.username}`);
|
|
9700
|
+
this._username = result.username;
|
|
9701
|
+
try {
|
|
9702
|
+
localStorage.removeItem("sk-guest-uuid");
|
|
9703
|
+
} catch (e) {
|
|
9704
|
+
logger.warn("localStorage not available (Node.js environment):", e);
|
|
9705
|
+
}
|
|
9706
|
+
await this.init();
|
|
9707
|
+
}
|
|
9708
|
+
return result;
|
|
9709
|
+
}
|
|
9676
9710
|
async resetUserData() {
|
|
9677
9711
|
if (this.syncStrategy.canAuthenticate()) {
|
|
9678
9712
|
return {
|
|
@@ -11243,6 +11277,22 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
11243
11277
|
};
|
|
11244
11278
|
}
|
|
11245
11279
|
}
|
|
11280
|
+
async adoptSession(migrateFromGuest) {
|
|
11281
|
+
let username;
|
|
11282
|
+
try {
|
|
11283
|
+
username = await getLoggedInUsername();
|
|
11284
|
+
} catch {
|
|
11285
|
+
return { ok: false, error: "No session to adopt" };
|
|
11286
|
+
}
|
|
11287
|
+
if (migrateFromGuest?.startsWith(GuestUsername)) {
|
|
11288
|
+
logger.info(`Migrating data from funnel account ${migrateFromGuest} to ${username}`);
|
|
11289
|
+
const migrationResult = await this.migrateFunnelData(migrateFromGuest, username);
|
|
11290
|
+
if (!migrationResult.success) {
|
|
11291
|
+
logger.warn(`Migration failed: ${migrationResult.error}`);
|
|
11292
|
+
}
|
|
11293
|
+
}
|
|
11294
|
+
return { ok: true, username };
|
|
11295
|
+
}
|
|
11246
11296
|
async logout() {
|
|
11247
11297
|
try {
|
|
11248
11298
|
const result = await this.getRemoteCouchRootDB().logOut();
|