UNPKG

@nestjs-mod/two-factor

Version:

Two factor module with an error filter, guard, controller, database migrations and rest-sdk for work with module from other nodejs appliaction

42 lines 1.68 kB
"use strict"; var TwoFactorEventsService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.TwoFactorEventsService = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const node_crypto_1 = require("node:crypto"); const rxjs_1 = require("rxjs"); let TwoFactorEventsService = TwoFactorEventsService_1 = class TwoFactorEventsService { constructor() { this.logger = new common_1.Logger(TwoFactorEventsService_1.name); this.twoFactorEventStream$ = new rxjs_1.ReplaySubject(); this.twoFactorEventCallbacks = []; this.id = (0, node_crypto_1.randomUUID)(); } async send(event) { if (event.serviceId !== this.id) { event.serviceId = this.id; this.logger.debug(`send: ${JSON.stringify(event)}`); this.twoFactorEventStream$.next(event); for (const twoFactorEventCallback of this.twoFactorEventCallbacks) { await twoFactorEventCallback(event); } } } listen(twoFactorEventCallback) { if (twoFactorEventCallback) { this.logger.debug(`append new callback...`); this.twoFactorEventCallbacks.push(twoFactorEventCallback); return null; } else { this.logger.debug(`listen...`); return this.twoFactorEventStream$; } } }; exports.TwoFactorEventsService = TwoFactorEventsService; exports.TwoFactorEventsService = TwoFactorEventsService = TwoFactorEventsService_1 = tslib_1.__decorate([ (0, common_1.Injectable)() ], TwoFactorEventsService); //# sourceMappingURL=two-factor-events.service.js.map