UNPKG

longcelot-sheet-db

Version:

Google Sheets-backed staging database adapter for Node.js with schema-first design

39 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveActorClient = resolveActorClient; exports.resolveRoleFolder = resolveRoleFolder; const sheetClient_1 = require("./sheetClient"); /** * Resolves which `SheetClient` a per-actor Drive operation should use: explicit `actorTokens` > * `tokenStore.get(userId)` > the shared admin client. Mirrors `createUserSheet()`'s original * actor-vs-admin client choice (Phase 8.1/8.4) exactly, so sheets and file uploads for the same * actor land in the same Drive. */ async function resolveActorClient(userId, adminClient, credentials, cacheConfig, tokenStore, actorTokens) { let tokens = actorTokens; if (!tokens && tokenStore) { tokens = (await tokenStore.get(userId)) ?? undefined; } if (tokens) { return { client: new sheetClient_1.SheetClient(credentials, tokens, cacheConfig), actorOwned: true }; } return { client: adminClient, actorOwned: false }; } /** * Resolves (creating if missing) the `driveFolder.root/subfolders[role]` folder on `client`, scoped * to `sharedDriveId` if configured. `cacheKey` lets callers namespace the cache per client/scope * (e.g. `admin:seller` vs `actor:user_123:seller`) so an actor-owned client's folder ID is never * confused with the shared admin client's folder of the same role name. */ async function resolveRoleFolder(client, driveFolder, role, sharedDriveId, cache, cacheKey) { if (!driveFolder) return undefined; if (cache.has(cacheKey)) return cache.get(cacheKey); const rootId = await client.findOrCreateFolder(driveFolder.root, undefined, sharedDriveId); const subfolderName = driveFolder.subfolders?.[role] ?? role; const folderId = await client.findOrCreateFolder(subfolderName, rootId, sharedDriveId); cache.set(cacheKey, folderId); return folderId; } //# sourceMappingURL=driveTenancy.js.map