ltijs
Version:
Easily turn your web application into a LTI 1.3 Learning Tool.
64 lines (63 loc) • 3.52 kB
TypeScript
import type { AccessTokenRecord, DatabaseManager, IdTokenClaims, IdTokenRecord, PlatformAttributes, PlatformFilter, PlatformRecord } from '#services/database-manager/database-manager.types';
import type { MongoConnectionConfig } from '#services/database-manager/mongo-legacy/mongo-legacy-database-manager.types';
import type { Logger } from '#services/logger/logger.types';
/**
* A fully standalone `DatabaseManager` implementation reading/writing the
* real, existing legacy collection structure `src/utils/Database.js` always
* used: platform base fields, status, and keys live in four separate
* collections (`platform`/`platformStatus`/`publickey`/`privatekey`) and are
* merged into (or decomposed from) a single `PlatformRecord`; the raw
* id_token is split across `idToken` (identity claims) and `contexttoken`
* (context/resource claims) and merged into (or decomposed from) a single
* `IdTokenRecord`. `publickey`/`privatekey`/`accesstoken` stay encrypted via
* an `encryptionKey` constructor parameter, exactly as before.
*
* Deliberately independent of `../mongo/mongo-database-manager.service.ts`
* (no shared imports, no inheritance) -- `mongo/` and `mongo-legacy/` are
* treated as isolated implementations that could each be extracted into
* their own package, so this class duplicates the generic Mongoose
* connection-lifecycle logic rather than inheriting it.
*/
export declare class MongoLegacyDatabaseManager implements DatabaseManager {
private readonly LOG_COMPONENT;
private readonly CONNECTED_EVENT;
private readonly OPEN_EVENT;
private readonly ERROR_EVENT;
private readonly RECONNECTED_EVENT;
private readonly DISCONNECTED_EVENT;
private readonly url;
private readonly connectionOptions;
private readonly logger;
private readonly encryptionKey;
private deployed;
/**
* Note the extra `encryptionKey` parameter -- unlike the default `MongoDatabaseManager`'s two-arg
* constructor, this one requires the same key legacy's `Provider.setup('LTIKEY', ...)` used, so it can
* decrypt the existing `publickey`/`privatekey`/`accesstoken` documents it reads.
*/
constructor(logger: Logger, config: MongoConnectionConfig, encryptionKey: string);
listen(): Promise<void>;
close(): Promise<void>;
getPlatformByUrlAndClientId(url: string, clientId: string): Promise<PlatformRecord | undefined>;
getPlatforms(filter?: PlatformFilter): Promise<PlatformRecord[]>;
getPlatformById(id: string): Promise<PlatformRecord | undefined>;
savePlatform(platform: PlatformAttributes): Promise<string>;
updatePlatformById(id: string, fields: Partial<PlatformAttributes>): Promise<void>;
deletePlatformById(id: string): Promise<void>;
getAccessToken(platformUrl: string, clientId: string, scopes: string): Promise<AccessTokenRecord | undefined>;
saveAccessToken(platformUrl: string, clientId: string, scopes: string, token: AccessTokenRecord): Promise<string>;
getIdToken(id: string): Promise<IdTokenRecord | undefined>;
saveIdToken(token: IdTokenClaims): Promise<string>;
consumeNonce(nonce: string): Promise<boolean>;
saveNonce(nonce: string): Promise<string>;
private ensureDeployed;
private generateUniqueKid;
private buildLegacyPlatformQuery;
private toPlatformRecord;
private toIdTokenRecord;
private getEncryptedKey;
private saveEncryptedKey;
private encryptPayload;
private decryptPayload;
}
export default MongoLegacyDatabaseManager;