@hmcts/rpx-xui-node-lib
Version:
Common nodejs library components for XUI
78 lines • 3.18 kB
JavaScript
;
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionStore = void 0;
const events = __importStar(require("events"));
const express_session_1 = __importDefault(require("express-session"));
const session_constants_1 = require("../session.constants");
const common_1 = require("../../common");
// TODO : This is hard to mock and test as it doesn't have
// an exported default, and when one is added the compiler
// complains that its constructor needs storename, as it's used
// in the constructor.
// This needs to be refactored so that storeName is not passed
// in via const?
class SessionStore extends events.EventEmitter {
constructor(storeName, router, logger = (0, common_1.getLogger)('session:store')) {
super();
this.configure = (options) => {
const store = this.getClassStore(options);
const sessionOptions = this.mapSessionOptions(options, store);
this.router.use((0, express_session_1.default)(sessionOptions));
return this.router;
};
this.getClassStore = (options) => {
if (options) {
return this.getStore(options);
}
throw new Error('Store Options are missing');
};
this.mapSessionOptions = (options, store) => {
return {
cookie: options.cookie,
name: options.name,
resave: options.resave,
saveUninitialized: options.saveUninitialized,
secret: options.secret,
store,
};
};
/**
* Get all the events that this strategy emits
* @return string[]
*/
this.getEvents = () => {
return Object.values(session_constants_1.SESSION.EVENT);
};
this.storeName = storeName;
this.router = router;
this.logger = logger;
}
}
exports.SessionStore = SessionStore;
//# sourceMappingURL=sessionStore.class.js.map