@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.
- 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 +55 -13
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +55 -13
- 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 +71 -13
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +71 -13
- 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 +55 -13
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +55 -13
- 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 +72 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/core/interfaces/userDB.ts +10 -0
- package/src/core/navigators/generators/prescribed.ts +43 -14
- 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
- package/tests/core/navigators/prescribedIntroExposure.test.ts +29 -0
package/dist/index.mjs
CHANGED
|
@@ -1978,7 +1978,8 @@ var init_generators = __esm({
|
|
|
1978
1978
|
// src/core/navigators/generators/prescribed.ts
|
|
1979
1979
|
var prescribed_exports = {};
|
|
1980
1980
|
__export(prescribed_exports, {
|
|
1981
|
-
default: () => PrescribedCardsGenerator
|
|
1981
|
+
default: () => PrescribedCardsGenerator,
|
|
1982
|
+
unmetIntroExposeTags: () => unmetIntroExposeTags
|
|
1982
1983
|
});
|
|
1983
1984
|
function dedupe(arr) {
|
|
1984
1985
|
return [...new Set(arr)];
|
|
@@ -2018,6 +2019,19 @@ function formatAge(ms) {
|
|
|
2018
2019
|
if (hours < 24) return `${hours}h`;
|
|
2019
2020
|
return `${Math.round(hours / 24)}d`;
|
|
2020
2021
|
}
|
|
2022
|
+
function unmetIntroExposeTags(tags, userTagElo, minCount) {
|
|
2023
|
+
if (minCount <= 0) return [];
|
|
2024
|
+
const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
|
|
2025
|
+
for (const tag of tags) {
|
|
2026
|
+
if (!tag.startsWith("gpc:intro:")) continue;
|
|
2027
|
+
const suffix = tag.slice("gpc:intro:".length);
|
|
2028
|
+
if (suffix) exposeTags.add(`gpc:expose:${suffix}`);
|
|
2029
|
+
}
|
|
2030
|
+
return [...exposeTags].filter((tag) => {
|
|
2031
|
+
const tagElo = userTagElo[tag];
|
|
2032
|
+
return !tagElo || tagElo.count < minCount;
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2021
2035
|
function pickTopByScore(cards, limit) {
|
|
2022
2036
|
return [...cards].sort((a, b) => b.score - a.score || a.cardId.localeCompare(b.cardId)).slice(0, limit);
|
|
2023
2037
|
}
|
|
@@ -2316,6 +2330,7 @@ var init_prescribed = __esm({
|
|
|
2316
2330
|
freshnessWindowSessions: typeof raw.freshnessWindowSessions === "number" ? raw.freshnessWindowSessions : DEFAULT_FRESHNESS_WINDOW,
|
|
2317
2331
|
maxDirectTargetsPerRun: typeof raw.maxDirectTargetsPerRun === "number" ? raw.maxDirectTargetsPerRun : DEFAULT_MAX_DIRECT_PER_RUN,
|
|
2318
2332
|
maxSupportCardsPerRun: typeof raw.maxSupportCardsPerRun === "number" ? raw.maxSupportCardsPerRun : DEFAULT_MAX_SUPPORT_PER_RUN,
|
|
2333
|
+
introExposeMinCount: typeof raw.introExposeMinCount === "number" ? raw.introExposeMinCount : DEFAULT_MIN_COUNT,
|
|
2319
2334
|
hierarchyWalk: {
|
|
2320
2335
|
enabled: raw.hierarchyWalk?.enabled !== false,
|
|
2321
2336
|
maxDepth: typeof raw.hierarchyWalk?.maxDepth === "number" ? raw.hierarchyWalk.maxDepth : DEFAULT_HIERARCHY_DEPTH
|
|
@@ -2391,18 +2406,11 @@ var init_prescribed = __esm({
|
|
|
2391
2406
|
group.hierarchyWalk?.enabled !== false,
|
|
2392
2407
|
group.hierarchyWalk?.maxDepth ?? DEFAULT_HIERARCHY_DEPTH
|
|
2393
2408
|
);
|
|
2394
|
-
const
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
exposeTags.add(`gpc:expose:${suffix}`);
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
const unmetExposeTags = [...exposeTags].filter((tag) => {
|
|
2403
|
-
const tagElo = userTagElo[tag];
|
|
2404
|
-
return !tagElo || tagElo.count < DEFAULT_MIN_COUNT;
|
|
2405
|
-
});
|
|
2409
|
+
const unmetExposeTags = unmetIntroExposeTags(
|
|
2410
|
+
tags,
|
|
2411
|
+
userTagElo,
|
|
2412
|
+
group.introExposeMinCount ?? DEFAULT_MIN_COUNT
|
|
2413
|
+
);
|
|
2406
2414
|
if (unmetExposeTags.length > 0) {
|
|
2407
2415
|
unmetExposeTags.forEach((tag) => supportTags.add(tag));
|
|
2408
2416
|
}
|
|
@@ -7350,6 +7358,22 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
7350
7358
|
};
|
|
7351
7359
|
}
|
|
7352
7360
|
}
|
|
7361
|
+
async adoptSession(migrateFromGuest) {
|
|
7362
|
+
let username;
|
|
7363
|
+
try {
|
|
7364
|
+
username = await getLoggedInUsername();
|
|
7365
|
+
} catch {
|
|
7366
|
+
return { ok: false, error: "No session to adopt" };
|
|
7367
|
+
}
|
|
7368
|
+
if (migrateFromGuest?.startsWith(GuestUsername)) {
|
|
7369
|
+
logger.info(`Migrating data from funnel account ${migrateFromGuest} to ${username}`);
|
|
7370
|
+
const migrationResult = await this.migrateFunnelData(migrateFromGuest, username);
|
|
7371
|
+
if (!migrationResult.success) {
|
|
7372
|
+
logger.warn(`Migration failed: ${migrationResult.error}`);
|
|
7373
|
+
}
|
|
7374
|
+
}
|
|
7375
|
+
return { ok: true, username };
|
|
7376
|
+
}
|
|
7353
7377
|
async logout() {
|
|
7354
7378
|
try {
|
|
7355
7379
|
const result = await this.getRemoteCouchRootDB().logOut();
|
|
@@ -11948,7 +11972,7 @@ var init_SessionController = __esm({
|
|
|
11948
11972
|
});
|
|
11949
11973
|
} catch (error) {
|
|
11950
11974
|
this.error(`Failed to get content from source ${i}:`, error);
|
|
11951
|
-
if (this.sources.length === 1) {
|
|
11975
|
+
if (this.sources.length === 1 && !replan) {
|
|
11952
11976
|
throw new Error(`Cannot start session: failed to load content from source ${i}`);
|
|
11953
11977
|
}
|
|
11954
11978
|
}
|
|
@@ -13084,6 +13108,40 @@ Currently logged-in as ${this._username}.`
|
|
|
13084
13108
|
}
|
|
13085
13109
|
return loginResult;
|
|
13086
13110
|
}
|
|
13111
|
+
/**
|
|
13112
|
+
* Adopt a remote session that was established outside this client — e.g. a
|
|
13113
|
+
* backend verified a third-party sign-in (Google) and set the session cookie
|
|
13114
|
+
* on its response. Afterwards the user is logged in exactly as after
|
|
13115
|
+
* login(): username switched, guest pointer cleared, init() re-run.
|
|
13116
|
+
*
|
|
13117
|
+
* @param opts.migrateGuestData Carry the current guest account's local data
|
|
13118
|
+
* into the adopted account. Pass true for a freshly created account (as
|
|
13119
|
+
* createAccount() does), false for an existing one (as login() does).
|
|
13120
|
+
*/
|
|
13121
|
+
async adoptSession(opts) {
|
|
13122
|
+
if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
|
|
13123
|
+
throw new Error("Session adoption not supported by current sync strategy");
|
|
13124
|
+
}
|
|
13125
|
+
const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
|
|
13126
|
+
if (!guestUsername) {
|
|
13127
|
+
throw new Error(`Cannot adopt a session while logged in.
|
|
13128
|
+
Log out of account ${this.getUsername()} first.`);
|
|
13129
|
+
}
|
|
13130
|
+
const result = await this.syncStrategy.adoptSession(
|
|
13131
|
+
opts.migrateGuestData ? guestUsername : void 0
|
|
13132
|
+
);
|
|
13133
|
+
if (result.ok && result.username) {
|
|
13134
|
+
log4(`Adopted session for ${result.username}`);
|
|
13135
|
+
this._username = result.username;
|
|
13136
|
+
try {
|
|
13137
|
+
localStorage.removeItem("sk-guest-uuid");
|
|
13138
|
+
} catch (e) {
|
|
13139
|
+
logger.warn("localStorage not available (Node.js environment):", e);
|
|
13140
|
+
}
|
|
13141
|
+
await this.init();
|
|
13142
|
+
}
|
|
13143
|
+
return result;
|
|
13144
|
+
}
|
|
13087
13145
|
async resetUserData() {
|
|
13088
13146
|
if (this.syncStrategy.canAuthenticate()) {
|
|
13089
13147
|
return {
|