@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
@@ -18,6 +18,10 @@ interface AuthenticationResult {
18
18
  ok: boolean;
19
19
  error?: string;
20
20
  }
21
+ interface AdoptSessionResult extends AuthenticationResult {
22
+ /** The adopted session's user, when ok. */
23
+ username?: string;
24
+ }
21
25
 
22
26
  /**
23
27
  * Strategy interface for handling user data synchronization
@@ -93,6 +97,15 @@ interface SyncStrategy {
93
97
  * Log out the current user (if supported)
94
98
  */
95
99
  logout?(): Promise<AuthenticationResult>;
100
+ /**
101
+ * Adopt a remote session established outside this client (e.g. a server that
102
+ * verified a third-party sign-in and set the session cookie), optionally
103
+ * migrating a guest account's local data into it (if supported).
104
+ * @param migrateFromGuest Guest username whose local data should be carried
105
+ * over. The caller must capture it BEFORE the session switched, since the
106
+ * remote now reports the adopted user.
107
+ */
108
+ adoptSession?(migrateFromGuest?: string): Promise<AdoptSessionResult>;
96
109
  /**
97
110
  * Get the current logged-in username
98
111
  * Returns the username if logged in, or a default guest username
@@ -100,4 +113,4 @@ interface SyncStrategy {
100
113
  getCurrentUsername(): Promise<string>;
101
114
  }
102
115
 
103
- export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a };
116
+ export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a, AdoptSessionResult as b };
@@ -18,6 +18,10 @@ interface AuthenticationResult {
18
18
  ok: boolean;
19
19
  error?: string;
20
20
  }
21
+ interface AdoptSessionResult extends AuthenticationResult {
22
+ /** The adopted session's user, when ok. */
23
+ username?: string;
24
+ }
21
25
 
22
26
  /**
23
27
  * Strategy interface for handling user data synchronization
@@ -93,6 +97,15 @@ interface SyncStrategy {
93
97
  * Log out the current user (if supported)
94
98
  */
95
99
  logout?(): Promise<AuthenticationResult>;
100
+ /**
101
+ * Adopt a remote session established outside this client (e.g. a server that
102
+ * verified a third-party sign-in and set the session cookie), optionally
103
+ * migrating a guest account's local data into it (if supported).
104
+ * @param migrateFromGuest Guest username whose local data should be carried
105
+ * over. The caller must capture it BEFORE the session switched, since the
106
+ * remote now reports the adopted user.
107
+ */
108
+ adoptSession?(migrateFromGuest?: string): Promise<AdoptSessionResult>;
96
109
  /**
97
110
  * Get the current logged-in username
98
111
  * Returns the username if logged in, or a default guest username
@@ -100,4 +113,4 @@ interface SyncStrategy {
100
113
  getCurrentUsername(): Promise<string>;
101
114
  }
102
115
 
103
- export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a };
116
+ export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a, AdoptSessionResult as b };
@@ -1213,6 +1213,17 @@ interface UserDBAuthenticator {
1213
1213
  logout(): Promise<{
1214
1214
  ok: boolean;
1215
1215
  }>;
1216
+ /**
1217
+ * Adopt a session established outside this client (e.g. third-party
1218
+ * sign-in completed server-side), optionally migrating guest data.
1219
+ */
1220
+ adoptSession(opts: {
1221
+ migrateGuestData: boolean;
1222
+ }): Promise<{
1223
+ ok: boolean;
1224
+ error?: string;
1225
+ username?: string;
1226
+ }>;
1216
1227
  }
1217
1228
  /**
1218
1229
  * Complete user database interface - combines all user operations
@@ -1213,6 +1213,17 @@ interface UserDBAuthenticator {
1213
1213
  logout(): Promise<{
1214
1214
  ok: boolean;
1215
1215
  }>;
1216
+ /**
1217
+ * Adopt a session established outside this client (e.g. third-party
1218
+ * sign-in completed server-side), optionally migrating guest data.
1219
+ */
1220
+ adoptSession(opts: {
1221
+ migrateGuestData: boolean;
1222
+ }): Promise<{
1223
+ ok: boolean;
1224
+ error?: string;
1225
+ username?: string;
1226
+ }>;
1216
1227
  }
1217
1228
  /**
1218
1229
  * Complete user database interface - combines all user operations
@@ -1,6 +1,6 @@
1
- import { as as LearnableWeight, O as UserOutcomeRecord, at as OrchestrationContext, W as WeightedCard, U as UserDBInterface, C as CourseDBInterface } from '../contentSource-CrRnbjBx.cjs';
2
- export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, s as CourseRegistrationDoc, b as CoursesDBInterface, aq as FilterImpact, ag as GeneratorContext, G as GeneratorResult, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, ar as PipelineForecaster, ao as PipelineRunReport, R as ReplanHints, j as ScheduledCard, t as SessionEloEvent, V as SessionStateSnapshot, u as SessionStateSnapshotProvider, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, h as StudyContentSource, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, S as StudySessionItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from '../contentSource-CrRnbjBx.cjs';
3
- export { D as DataLayerProvider } from '../dataLayerProvider-IecbidDO.cjs';
1
+ import { as as LearnableWeight, O as UserOutcomeRecord, at as OrchestrationContext, W as WeightedCard, U as UserDBInterface, C as CourseDBInterface } from '../contentSource-D3c1fMAk.cjs';
2
+ export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, s as CourseRegistrationDoc, b as CoursesDBInterface, aq as FilterImpact, ag as GeneratorContext, G as GeneratorResult, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, ar as PipelineForecaster, ao as PipelineRunReport, R as ReplanHints, j as ScheduledCard, t as SessionEloEvent, V as SessionStateSnapshot, u as SessionStateSnapshotProvider, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, h as StudyContentSource, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, S as StudySessionItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from '../contentSource-D3c1fMAk.cjs';
3
+ export { D as DataLayerProvider } from '../dataLayerProvider-CeLiFbHv.cjs';
4
4
  import { D as DocType, c as QuestionRecord, i as DocTypePrefixes, C as CardHistory, b as CardRecord } from '../types-legacy-CrwyZIvI.cjs';
5
5
  export { d as CardData, e as CourseListData, g as DataShapeData, f as DisplayableData, F as Field, G as GuestUsername, Q as QualifiedCardID, h as QuestionData, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from '../types-legacy-CrwyZIvI.cjs';
6
6
  import { DataShape, ParsedCard } from '@vue-skuilder/common';
@@ -1,6 +1,6 @@
1
- import { as as LearnableWeight, O as UserOutcomeRecord, at as OrchestrationContext, W as WeightedCard, U as UserDBInterface, C as CourseDBInterface } from '../contentSource-kD35o65m.js';
2
- export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, s as CourseRegistrationDoc, b as CoursesDBInterface, aq as FilterImpact, ag as GeneratorContext, G as GeneratorResult, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, ar as PipelineForecaster, ao as PipelineRunReport, R as ReplanHints, j as ScheduledCard, t as SessionEloEvent, V as SessionStateSnapshot, u as SessionStateSnapshotProvider, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, h as StudyContentSource, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, S as StudySessionItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from '../contentSource-kD35o65m.js';
3
- export { D as DataLayerProvider } from '../dataLayerProvider-CtzddVdy.js';
1
+ import { as as LearnableWeight, O as UserOutcomeRecord, at as OrchestrationContext, W as WeightedCard, U as UserDBInterface, C as CourseDBInterface } from '../contentSource-LPf044hY.js';
2
+ export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, s as CourseRegistrationDoc, b as CoursesDBInterface, aq as FilterImpact, ag as GeneratorContext, G as GeneratorResult, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, ar as PipelineForecaster, ao as PipelineRunReport, R as ReplanHints, j as ScheduledCard, t as SessionEloEvent, V as SessionStateSnapshot, u as SessionStateSnapshotProvider, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, h as StudyContentSource, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, S as StudySessionItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from '../contentSource-LPf044hY.js';
3
+ export { D as DataLayerProvider } from '../dataLayerProvider-DaAootVV.js';
4
4
  import { D as DocType, c as QuestionRecord, i as DocTypePrefixes, C as CardHistory, b as CardRecord } from '../types-legacy-CrwyZIvI.js';
5
5
  export { d as CardData, e as CourseListData, g as DataShapeData, f as DisplayableData, F as Field, G as GuestUsername, Q as QualifiedCardID, h as QuestionData, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from '../types-legacy-CrwyZIvI.js';
6
6
  import { DataShape, ParsedCard } from '@vue-skuilder/common';
@@ -9215,6 +9215,40 @@ Currently logged-in as ${this._username}.`
9215
9215
  }
9216
9216
  return loginResult;
9217
9217
  }
9218
+ /**
9219
+ * Adopt a remote session that was established outside this client — e.g. a
9220
+ * backend verified a third-party sign-in (Google) and set the session cookie
9221
+ * on its response. Afterwards the user is logged in exactly as after
9222
+ * login(): username switched, guest pointer cleared, init() re-run.
9223
+ *
9224
+ * @param opts.migrateGuestData Carry the current guest account's local data
9225
+ * into the adopted account. Pass true for a freshly created account (as
9226
+ * createAccount() does), false for an existing one (as login() does).
9227
+ */
9228
+ async adoptSession(opts) {
9229
+ if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
9230
+ throw new Error("Session adoption not supported by current sync strategy");
9231
+ }
9232
+ const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
9233
+ if (!guestUsername) {
9234
+ throw new Error(`Cannot adopt a session while logged in.
9235
+ Log out of account ${this.getUsername()} first.`);
9236
+ }
9237
+ const result = await this.syncStrategy.adoptSession(
9238
+ opts.migrateGuestData ? guestUsername : void 0
9239
+ );
9240
+ if (result.ok && result.username) {
9241
+ log3(`Adopted session for ${result.username}`);
9242
+ this._username = result.username;
9243
+ try {
9244
+ localStorage.removeItem("sk-guest-uuid");
9245
+ } catch (e) {
9246
+ logger.warn("localStorage not available (Node.js environment):", e);
9247
+ }
9248
+ await this.init();
9249
+ }
9250
+ return result;
9251
+ }
9218
9252
  async resetUserData() {
9219
9253
  if (this.syncStrategy.canAuthenticate()) {
9220
9254
  return {