@vue-skuilder/db 0.2.25 → 0.2.27

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 (40) 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 +55 -13
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/core/index.mjs +55 -13
  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 +71 -13
  16. package/dist/impl/couch/index.js.map +1 -1
  17. package/dist/impl/couch/index.mjs +71 -13
  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 +55 -13
  22. package/dist/impl/static/index.js.map +1 -1
  23. package/dist/impl/static/index.mjs +55 -13
  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 +72 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +72 -14
  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/core/navigators/generators/prescribed.ts +43 -14
  34. package/src/impl/common/BaseUserDB.ts +40 -0
  35. package/src/impl/common/SyncStrategy.ts +11 -1
  36. package/src/impl/common/index.ts +1 -0
  37. package/src/impl/common/types.ts +5 -0
  38. package/src/impl/couch/CouchDBSyncStrategy.ts +25 -1
  39. package/src/study/SessionController.ts +6 -2
  40. package/tests/core/navigators/prescribedIntroExposure.test.ts +29 -0
@@ -1,4 +1,4 @@
1
- import { U as UserDBInterface, a as UserDBReader, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface } from './contentSource-CrRnbjBx.cjs';
1
+ import { U as UserDBInterface, a as UserDBReader, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface } from './contentSource-D3c1fMAk.cjs';
2
2
 
3
3
  /**
4
4
  * Main factory interface for data access
@@ -1,4 +1,4 @@
1
- import { U as UserDBInterface, a as UserDBReader, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface } from './contentSource-kD35o65m.js';
1
+ import { U as UserDBInterface, a as UserDBReader, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface } from './contentSource-LPf044hY.js';
2
2
 
3
3
  /**
4
4
  * Main factory interface for data access
@@ -1,10 +1,10 @@
1
1
  import { T as TagStub, a as Tag, S as SkuilderCourseData, Q as QualifiedCardID } from '../../types-legacy-CrwyZIvI.cjs';
2
2
  import { Moment } from 'moment';
3
- import { A as AdminDBInterface, g as AssignedContent, h as StudyContentSource, i as StudentClassroomDBInterface, U as UserDBInterface, G as GeneratorResult, T as TeacherClassroomDBInterface, b as CoursesDBInterface, C as CourseDBInterface, d as CourseInfo, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, S as StudySessionItem, j as ScheduledCard } from '../../contentSource-CrRnbjBx.cjs';
4
- export { q as ContentSourceID, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, r as getStudySource, p as isReview } from '../../contentSource-CrRnbjBx.cjs';
3
+ import { A as AdminDBInterface, g as AssignedContent, h as StudyContentSource, i as StudentClassroomDBInterface, U as UserDBInterface, G as GeneratorResult, T as TeacherClassroomDBInterface, b as CoursesDBInterface, C as CourseDBInterface, d as CourseInfo, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, S as StudySessionItem, j as ScheduledCard } from '../../contentSource-D3c1fMAk.cjs';
4
+ export { q as ContentSourceID, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, r as getStudySource, p as isReview } from '../../contentSource-D3c1fMAk.cjs';
5
5
  import * as _vue_skuilder_common from '@vue-skuilder/common';
6
6
  import { ClassroomConfig, DataShape, CourseElo, CourseConfig as CourseConfig$1 } from '@vue-skuilder/common';
7
- import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-CCU1H81I.cjs';
7
+ import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult, b as AdoptSessionResult } from '../../SyncStrategy-BXliog1m.cjs';
8
8
 
9
9
  type NamespacedDatashape = string;
10
10
  interface DataShape55 {
@@ -534,6 +534,7 @@ declare class CouchDBSyncStrategy implements SyncStrategy {
534
534
  canAuthenticate(): boolean;
535
535
  createAccount(username: string, password: string): Promise<AccountCreationResult>;
536
536
  authenticate(username: string, password: string): Promise<AuthenticationResult>;
537
+ adoptSession(migrateFromGuest?: string): Promise<AdoptSessionResult>;
537
538
  logout(): Promise<AuthenticationResult>;
538
539
  getCurrentUsername(): Promise<string>;
539
540
  /**
@@ -1,10 +1,10 @@
1
1
  import { T as TagStub, a as Tag, S as SkuilderCourseData, Q as QualifiedCardID } from '../../types-legacy-CrwyZIvI.js';
2
2
  import { Moment } from 'moment';
3
- import { A as AdminDBInterface, g as AssignedContent, h as StudyContentSource, i as StudentClassroomDBInterface, U as UserDBInterface, G as GeneratorResult, T as TeacherClassroomDBInterface, b as CoursesDBInterface, C as CourseDBInterface, d as CourseInfo, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, S as StudySessionItem, j as ScheduledCard } from '../../contentSource-kD35o65m.js';
4
- export { q as ContentSourceID, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, r as getStudySource, p as isReview } from '../../contentSource-kD35o65m.js';
3
+ import { A as AdminDBInterface, g as AssignedContent, h as StudyContentSource, i as StudentClassroomDBInterface, U as UserDBInterface, G as GeneratorResult, T as TeacherClassroomDBInterface, b as CoursesDBInterface, C as CourseDBInterface, d as CourseInfo, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, S as StudySessionItem, j as ScheduledCard } from '../../contentSource-LPf044hY.js';
4
+ export { q as ContentSourceID, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, r as getStudySource, p as isReview } from '../../contentSource-LPf044hY.js';
5
5
  import * as _vue_skuilder_common from '@vue-skuilder/common';
6
6
  import { ClassroomConfig, DataShape, CourseElo, CourseConfig as CourseConfig$1 } from '@vue-skuilder/common';
7
- import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-CCU1H81I.js';
7
+ import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult, b as AdoptSessionResult } from '../../SyncStrategy-BXliog1m.js';
8
8
 
9
9
  type NamespacedDatashape = string;
10
10
  interface DataShape55 {
@@ -534,6 +534,7 @@ declare class CouchDBSyncStrategy implements SyncStrategy {
534
534
  canAuthenticate(): boolean;
535
535
  createAccount(username: string, password: string): Promise<AccountCreationResult>;
536
536
  authenticate(username: string, password: string): Promise<AuthenticationResult>;
537
+ adoptSession(migrateFromGuest?: string): Promise<AdoptSessionResult>;
537
538
  logout(): Promise<AuthenticationResult>;
538
539
  getCurrentUsername(): Promise<string>;
539
540
  /**
@@ -1964,7 +1964,8 @@ var init_generators = __esm({
1964
1964
  // src/core/navigators/generators/prescribed.ts
1965
1965
  var prescribed_exports = {};
1966
1966
  __export(prescribed_exports, {
1967
- default: () => PrescribedCardsGenerator
1967
+ default: () => PrescribedCardsGenerator,
1968
+ unmetIntroExposeTags: () => unmetIntroExposeTags
1968
1969
  });
1969
1970
  function dedupe(arr) {
1970
1971
  return [...new Set(arr)];
@@ -2004,6 +2005,19 @@ function formatAge(ms) {
2004
2005
  if (hours < 24) return `${hours}h`;
2005
2006
  return `${Math.round(hours / 24)}d`;
2006
2007
  }
2008
+ function unmetIntroExposeTags(tags, userTagElo, minCount) {
2009
+ if (minCount <= 0) return [];
2010
+ const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
2011
+ for (const tag of tags) {
2012
+ if (!tag.startsWith("gpc:intro:")) continue;
2013
+ const suffix = tag.slice("gpc:intro:".length);
2014
+ if (suffix) exposeTags.add(`gpc:expose:${suffix}`);
2015
+ }
2016
+ return [...exposeTags].filter((tag) => {
2017
+ const tagElo = userTagElo[tag];
2018
+ return !tagElo || tagElo.count < minCount;
2019
+ });
2020
+ }
2007
2021
  function pickTopByScore(cards, limit) {
2008
2022
  return [...cards].sort((a, b) => b.score - a.score || a.cardId.localeCompare(b.cardId)).slice(0, limit);
2009
2023
  }
@@ -2302,6 +2316,7 @@ var init_prescribed = __esm({
2302
2316
  freshnessWindowSessions: typeof raw.freshnessWindowSessions === "number" ? raw.freshnessWindowSessions : DEFAULT_FRESHNESS_WINDOW,
2303
2317
  maxDirectTargetsPerRun: typeof raw.maxDirectTargetsPerRun === "number" ? raw.maxDirectTargetsPerRun : DEFAULT_MAX_DIRECT_PER_RUN,
2304
2318
  maxSupportCardsPerRun: typeof raw.maxSupportCardsPerRun === "number" ? raw.maxSupportCardsPerRun : DEFAULT_MAX_SUPPORT_PER_RUN,
2319
+ introExposeMinCount: typeof raw.introExposeMinCount === "number" ? raw.introExposeMinCount : DEFAULT_MIN_COUNT,
2305
2320
  hierarchyWalk: {
2306
2321
  enabled: raw.hierarchyWalk?.enabled !== false,
2307
2322
  maxDepth: typeof raw.hierarchyWalk?.maxDepth === "number" ? raw.hierarchyWalk.maxDepth : DEFAULT_HIERARCHY_DEPTH
@@ -2377,18 +2392,11 @@ var init_prescribed = __esm({
2377
2392
  group.hierarchyWalk?.enabled !== false,
2378
2393
  group.hierarchyWalk?.maxDepth ?? DEFAULT_HIERARCHY_DEPTH
2379
2394
  );
2380
- const introTags = tags.filter((tag) => tag.startsWith("gpc:intro:"));
2381
- const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
2382
- for (const introTag of introTags) {
2383
- const suffix = introTag.slice("gpc:intro:".length);
2384
- if (suffix) {
2385
- exposeTags.add(`gpc:expose:${suffix}`);
2386
- }
2387
- }
2388
- const unmetExposeTags = [...exposeTags].filter((tag) => {
2389
- const tagElo = userTagElo[tag];
2390
- return !tagElo || tagElo.count < DEFAULT_MIN_COUNT;
2391
- });
2395
+ const unmetExposeTags = unmetIntroExposeTags(
2396
+ tags,
2397
+ userTagElo,
2398
+ group.introExposeMinCount ?? DEFAULT_MIN_COUNT
2399
+ );
2392
2400
  if (unmetExposeTags.length > 0) {
2393
2401
  unmetExposeTags.forEach((tag) => supportTags.add(tag));
2394
2402
  }
@@ -9688,6 +9696,40 @@ Currently logged-in as ${this._username}.`
9688
9696
  }
9689
9697
  return loginResult;
9690
9698
  }
9699
+ /**
9700
+ * Adopt a remote session that was established outside this client — e.g. a
9701
+ * backend verified a third-party sign-in (Google) and set the session cookie
9702
+ * on its response. Afterwards the user is logged in exactly as after
9703
+ * login(): username switched, guest pointer cleared, init() re-run.
9704
+ *
9705
+ * @param opts.migrateGuestData Carry the current guest account's local data
9706
+ * into the adopted account. Pass true for a freshly created account (as
9707
+ * createAccount() does), false for an existing one (as login() does).
9708
+ */
9709
+ async adoptSession(opts) {
9710
+ if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
9711
+ throw new Error("Session adoption not supported by current sync strategy");
9712
+ }
9713
+ const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
9714
+ if (!guestUsername) {
9715
+ throw new Error(`Cannot adopt a session while logged in.
9716
+ Log out of account ${this.getUsername()} first.`);
9717
+ }
9718
+ const result = await this.syncStrategy.adoptSession(
9719
+ opts.migrateGuestData ? guestUsername : void 0
9720
+ );
9721
+ if (result.ok && result.username) {
9722
+ log3(`Adopted session for ${result.username}`);
9723
+ this._username = result.username;
9724
+ try {
9725
+ localStorage.removeItem("sk-guest-uuid");
9726
+ } catch (e) {
9727
+ logger.warn("localStorage not available (Node.js environment):", e);
9728
+ }
9729
+ await this.init();
9730
+ }
9731
+ return result;
9732
+ }
9691
9733
  async resetUserData() {
9692
9734
  if (this.syncStrategy.canAuthenticate()) {
9693
9735
  return {
@@ -11259,6 +11301,22 @@ var init_CouchDBSyncStrategy = __esm({
11259
11301
  };
11260
11302
  }
11261
11303
  }
11304
+ async adoptSession(migrateFromGuest) {
11305
+ let username;
11306
+ try {
11307
+ username = await getLoggedInUsername();
11308
+ } catch {
11309
+ return { ok: false, error: "No session to adopt" };
11310
+ }
11311
+ if (migrateFromGuest?.startsWith(GuestUsername)) {
11312
+ logger.info(`Migrating data from funnel account ${migrateFromGuest} to ${username}`);
11313
+ const migrationResult = await this.migrateFunnelData(migrateFromGuest, username);
11314
+ if (!migrationResult.success) {
11315
+ logger.warn(`Migration failed: ${migrationResult.error}`);
11316
+ }
11317
+ }
11318
+ return { ok: true, username };
11319
+ }
11262
11320
  async logout() {
11263
11321
  try {
11264
11322
  const result = await this.getRemoteCouchRootDB().logOut();