@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.
Files changed (38) hide show
  1. package/dist/{SyncStrategy-CCU1H81I.d.cts → SyncStrategy-BXliog1m.d.cts} +14 -1
  2. package/dist/{SyncStrategy-CCU1H81I.d.ts → SyncStrategy-BXliog1m.d.ts} +14 -1
  3. package/dist/{contentSource-CrRnbjBx.d.cts → contentSource-D3c1fMAk.d.cts} +11 -0
  4. package/dist/{contentSource-kD35o65m.d.ts → contentSource-LPf044hY.d.ts} +11 -0
  5. package/dist/core/index.d.cts +3 -3
  6. package/dist/core/index.d.ts +3 -3
  7. package/dist/core/index.js +34 -0
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/core/index.mjs +34 -0
  10. package/dist/core/index.mjs.map +1 -1
  11. package/dist/{dataLayerProvider-IecbidDO.d.cts → dataLayerProvider-CeLiFbHv.d.cts} +1 -1
  12. package/dist/{dataLayerProvider-CtzddVdy.d.ts → dataLayerProvider-DaAootVV.d.ts} +1 -1
  13. package/dist/impl/couch/index.d.cts +4 -3
  14. package/dist/impl/couch/index.d.ts +4 -3
  15. package/dist/impl/couch/index.js +50 -0
  16. package/dist/impl/couch/index.js.map +1 -1
  17. package/dist/impl/couch/index.mjs +50 -0
  18. package/dist/impl/couch/index.mjs.map +1 -1
  19. package/dist/impl/static/index.d.cts +3 -3
  20. package/dist/impl/static/index.d.ts +3 -3
  21. package/dist/impl/static/index.js +34 -0
  22. package/dist/impl/static/index.js.map +1 -1
  23. package/dist/impl/static/index.mjs +34 -0
  24. package/dist/impl/static/index.mjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +51 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +51 -1
  30. package/dist/index.mjs.map +1 -1
  31. package/package.json +3 -3
  32. package/src/core/interfaces/userDB.ts +10 -0
  33. package/src/impl/common/BaseUserDB.ts +40 -0
  34. package/src/impl/common/SyncStrategy.ts +11 -1
  35. package/src/impl/common/index.ts +1 -0
  36. package/src/impl/common/types.ts +5 -0
  37. package/src/impl/couch/CouchDBSyncStrategy.ts +25 -1
  38. package/src/study/SessionController.ts +6 -2
package/dist/index.mjs CHANGED
@@ -7350,6 +7350,22 @@ var init_CouchDBSyncStrategy = __esm({
7350
7350
  };
7351
7351
  }
7352
7352
  }
7353
+ async adoptSession(migrateFromGuest) {
7354
+ let username;
7355
+ try {
7356
+ username = await getLoggedInUsername();
7357
+ } catch {
7358
+ return { ok: false, error: "No session to adopt" };
7359
+ }
7360
+ if (migrateFromGuest?.startsWith(GuestUsername)) {
7361
+ logger.info(`Migrating data from funnel account ${migrateFromGuest} to ${username}`);
7362
+ const migrationResult = await this.migrateFunnelData(migrateFromGuest, username);
7363
+ if (!migrationResult.success) {
7364
+ logger.warn(`Migration failed: ${migrationResult.error}`);
7365
+ }
7366
+ }
7367
+ return { ok: true, username };
7368
+ }
7353
7369
  async logout() {
7354
7370
  try {
7355
7371
  const result = await this.getRemoteCouchRootDB().logOut();
@@ -11948,7 +11964,7 @@ var init_SessionController = __esm({
11948
11964
  });
11949
11965
  } catch (error) {
11950
11966
  this.error(`Failed to get content from source ${i}:`, error);
11951
- if (this.sources.length === 1) {
11967
+ if (this.sources.length === 1 && !replan) {
11952
11968
  throw new Error(`Cannot start session: failed to load content from source ${i}`);
11953
11969
  }
11954
11970
  }
@@ -13084,6 +13100,40 @@ Currently logged-in as ${this._username}.`
13084
13100
  }
13085
13101
  return loginResult;
13086
13102
  }
13103
+ /**
13104
+ * Adopt a remote session that was established outside this client — e.g. a
13105
+ * backend verified a third-party sign-in (Google) and set the session cookie
13106
+ * on its response. Afterwards the user is logged in exactly as after
13107
+ * login(): username switched, guest pointer cleared, init() re-run.
13108
+ *
13109
+ * @param opts.migrateGuestData Carry the current guest account's local data
13110
+ * into the adopted account. Pass true for a freshly created account (as
13111
+ * createAccount() does), false for an existing one (as login() does).
13112
+ */
13113
+ async adoptSession(opts) {
13114
+ if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
13115
+ throw new Error("Session adoption not supported by current sync strategy");
13116
+ }
13117
+ const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
13118
+ if (!guestUsername) {
13119
+ throw new Error(`Cannot adopt a session while logged in.
13120
+ Log out of account ${this.getUsername()} first.`);
13121
+ }
13122
+ const result = await this.syncStrategy.adoptSession(
13123
+ opts.migrateGuestData ? guestUsername : void 0
13124
+ );
13125
+ if (result.ok && result.username) {
13126
+ log4(`Adopted session for ${result.username}`);
13127
+ this._username = result.username;
13128
+ try {
13129
+ localStorage.removeItem("sk-guest-uuid");
13130
+ } catch (e) {
13131
+ logger.warn("localStorage not available (Node.js environment):", e);
13132
+ }
13133
+ await this.init();
13134
+ }
13135
+ return result;
13136
+ }
13087
13137
  async resetUserData() {
13088
13138
  if (this.syncStrategy.canAuthenticate()) {
13089
13139
  return {