ltijs
Version:
Easily turn your web application into a LTI 1.3 Learning Tool.
149 lines • 7.81 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextTokenModel = exports.LegacyIdTokenModel = exports.NonceModel = exports.LegacyAccessTokenModel = exports.PrivateKeyModel = exports.PublicKeyModel = exports.PlatformStatusModel = exports.LegacyPlatformModel = void 0;
const mongoose_1 = __importStar(require("mongoose"));
// Mongoose schema/model definitions mirroring the real, existing legacy collection structure
// `src/utils/Database.js` used -- fully independent of `../mongo/database-schemas.ts` by design (`mongo/`
// and `mongo-legacy/` are isolated implementations, each extractable on its own). Collection names
// (platforms/idTokens/accesstokens) match `mongo/`'s exactly, since both must coexist against one real
// database during a migration; registered under distinct model names (3-arg `mongoose.model()`) so both
// can be loaded in the same process (e.g. this repo's test suite) without a naming conflict.
const PLATFORM_COLLECTION = 'platforms';
const PLATFORMSTATUS_COLLECTION = 'platformstatuses';
const PUBLICKEY_COLLECTION = 'publickeys';
const PRIVATEKEY_COLLECTION = 'privatekeys';
const IDTOKEN_COLLECTION = 'idTokens';
const CONTEXTTOKEN_COLLECTION = 'contexttokens';
const ACCESSTOKEN_COLLECTION = 'accesstokens';
const NONCE_COLLECTION = 'nonces';
const legacyPlatformSchema = new mongoose_1.Schema({
platformUrl: String,
platformName: String,
clientId: String,
authEndpoint: String,
accesstokenEndpoint: String,
authorizationServer: String,
kid: String,
authConfig: { method: String, key: String },
});
legacyPlatformSchema.index({ platformUrl: 1 });
// Partial, not plain, unique indexes: `platforms` is a real collection
// `../mongo/database-schemas.ts`'s own `PlatformModel` also targets (by
// design, both implementations must be able to coexist against one real
// deployed database during a migration), but that model's own docs never set
// `kid`/`platformUrl` (it uses `id`/`url` instead) -- a plain unique index
// would treat every one of its docs as colliding on `kid: null`. Genuine
// legacy data always has `kid`/`platformUrl` set, so this is a no-op for real
// legacy's own documents.
legacyPlatformSchema.index({ kid: 1 }, { unique: true, partialFilterExpression: { kid: { $type: 'string' } } });
legacyPlatformSchema.index({ platformUrl: 1, clientId: 1 }, { unique: true, partialFilterExpression: { platformUrl: { $type: 'string' }, clientId: { $type: 'string' } } });
const platformStatusSchema = new mongoose_1.Schema({
id: String,
active: { type: Boolean, default: false },
});
platformStatusSchema.index({ id: 1 }, { unique: true });
const keySchema = new mongoose_1.Schema({
kid: String,
platformUrl: String,
clientId: String,
iv: String,
data: String,
});
keySchema.index({ kid: 1 }, { unique: true });
const legacyAccessTokenSchema = new mongoose_1.Schema({
platformUrl: String,
clientId: String,
scopes: String,
iv: String,
data: String,
createdAt: { type: Date, expires: 3600, default: Date.now },
});
legacyAccessTokenSchema.index({ platformUrl: 1, clientId: 1, scopes: 1 }, { unique: true });
// TTL/save-at-issuance behavior matches `../mongo/database-schemas.ts`'s
// own `NonceModel` exactly (both implementations' nonce handling was
// redesigned uniformly in an earlier round) -- only the file-level sharing
// is what's being removed here.
const nonceSchema = new mongoose_1.Schema({
nonce: String,
createdAt: { type: Date, expires: 600, default: Date.now },
});
nonceSchema.index({ nonce: 1 });
const legacyIdTokenSchema = new mongoose_1.Schema({
launchId: String,
iss: String,
user: String,
clientId: String,
deploymentId: String,
userInfo: mongoose_1.Schema.Types.Mixed,
platformInfo: mongoose_1.Schema.Types.Mixed,
platformId: String,
createdAt: { type: Date, expires: 3600 * 24, default: Date.now },
});
// Partial, not plain, unique index: `idTokens` is a real collection
// `../mongo/database-schemas.ts`'s own `IdTokenDoc` also targets (same
// cross-implementation coexistence design as `legacyPlatformSchema`'s own
// indexes above), but that model's own docs never set `launchId` at all -- a
// plain unique index would treat every one of its docs as colliding on
// `launchId: null`. Genuine legacy data always sets `launchId`, so this is a
// no-op for real legacy's own documents.
legacyIdTokenSchema.index({ launchId: 1 }, { unique: true, partialFilterExpression: { launchId: { $type: 'string' } } });
const contextTokenSchema = new mongoose_1.Schema({
launchId: String,
contextId: String,
user: String,
createdAt: { type: Date, expires: 3600 * 24, default: Date.now },
}, { strict: false });
contextTokenSchema.index({ launchId: 1 }, { unique: true });
// Re-requiring this module (e.g. once per test file) must not re-register the
// same model twice on the shared `mongoose` instance.
function model(name, schema, collection) {
return mongoose_1.default.models[name] ?? mongoose_1.default.model(name, schema, collection);
}
// Every model uses a `Legacy`-prefixed name, distinct from both `../mongo/database-schemas.ts`'s names
// and the real `src/utils/Database.js`'s own literal registrations -- this matters because the interop
// dbtest suite constructs that real class directly in-process, and its constructor registers all nine
// of its models in one try/catch that silently aborts on the first name collision, breaking the rest of
// *its* models too. Each model still targets the same real collection (explicit 3rd arg), just under a
// distinct registration name.
exports.LegacyPlatformModel = model('LegacyPlatform', legacyPlatformSchema, PLATFORM_COLLECTION);
exports.PlatformStatusModel = model('LegacyPlatformStatus', platformStatusSchema, PLATFORMSTATUS_COLLECTION);
exports.PublicKeyModel = model('LegacyPublicKey', keySchema, PUBLICKEY_COLLECTION);
exports.PrivateKeyModel = model('LegacyPrivateKey', keySchema, PRIVATEKEY_COLLECTION);
exports.LegacyAccessTokenModel = model('LegacyAccessToken', legacyAccessTokenSchema, ACCESSTOKEN_COLLECTION);
exports.NonceModel = model('LegacyNonce', nonceSchema, NONCE_COLLECTION);
exports.LegacyIdTokenModel = model('LegacyIdToken', legacyIdTokenSchema, IDTOKEN_COLLECTION);
exports.ContextTokenModel = model('LegacyContextToken', contextTokenSchema, CONTEXTTOKEN_COLLECTION);
//# sourceMappingURL=database-schemas.js.map