UNPKG

@infomaker/service-authorization-lib

Version:

IMID Service Authorization Library

47 lines (38 loc) 1.05 kB
class Plugin { constructor(plugin, options) { this.plugin = plugin this.options = options this.onPreHandlerHandler = null this.onPreResponseHandler = null this.implementation = null this.scheme = null return new Promise((resolve, reject) => { this.init().then(() => { resolve(this) }).catch(err => { reject(err) }) }) } async init() { await this.extractImplementation() } mockScheme(hapiVersion) { return { ext: (lifecycleMethodName, handler) => { if (lifecycleMethodName === 'onPreHandler') { this.onPreHandlerHandler = handler } if (lifecycleMethodName === 'onPreResponse') { this.onPreResponseHandler = handler } }, version: hapiVersion } } async extractImplementation() { const nextFunc = this.options.hapiVersion === '16.0.0' ? () => {} : null await this.plugin.register(this.mockScheme(this.options.hapiVersion), this.options, nextFunc) } } module.exports = Plugin