@viardex/viardex-libs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cache/cache.interface.d.ts +2 -0
- package/dist/cache/cache.interface.js +2 -0
- package/dist/cache/cache.module.d.ts +5 -0
- package/dist/cache/cache.module.js +27 -0
- package/dist/cache/cache.service.d.ts +25 -0
- package/dist/cache/cache.service.js +94 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +18 -0
- package/dist/common/config/index.d.ts +1 -0
- package/dist/common/config/index.js +2 -0
- package/dist/common/config/nats.config.d.ts +9 -0
- package/dist/common/config/nats.config.js +12 -0
- package/dist/common/constants/index.d.ts +2 -0
- package/dist/common/constants/index.js +18 -0
- package/dist/common/constants/otp.constants.d.ts +15 -0
- package/dist/common/constants/otp.constants.js +18 -0
- package/dist/common/constants/queues.constants.d.ts +17 -0
- package/dist/common/constants/queues.constants.js +20 -0
- package/dist/common/enums/index.d.ts +2 -0
- package/dist/common/enums/index.js +18 -0
- package/dist/common/enums/support-action.enum.d.ts +7 -0
- package/dist/common/enums/support-action.enum.js +11 -0
- package/dist/common/enums/ticket.enum.d.ts +19 -0
- package/dist/common/enums/ticket.enum.js +25 -0
- package/dist/common/health/health.controller.d.ts +9 -0
- package/dist/common/health/health.controller.js +49 -0
- package/dist/common/health/health.module.d.ts +2 -0
- package/dist/common/health/health.module.js +22 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +19 -0
- package/dist/common/utils/index.d.ts +3 -0
- package/dist/common/utils/index.js +19 -0
- package/dist/common/utils/random.utils.d.ts +10 -0
- package/dist/common/utils/random.utils.js +27 -0
- package/dist/common/utils/reference.utils.d.ts +1 -0
- package/dist/common/utils/reference.utils.js +17 -0
- package/dist/common/utils/string.utils.d.ts +10 -0
- package/dist/common/utils/string.utils.js +34 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/nats/constants/nats.constants.d.ts +11 -0
- package/dist/nats/constants/nats.constants.js +15 -0
- package/dist/nats/decorators/nats-event-pattern.decorator.d.ts +2 -0
- package/dist/nats/decorators/nats-event-pattern.decorator.js +11 -0
- package/dist/nats/dto/nats-message.dto.d.ts +5 -0
- package/dist/nats/dto/nats-message.dto.js +27 -0
- package/dist/nats/index.d.ts +5 -0
- package/dist/nats/index.js +21 -0
- package/dist/nats/interceptors/nats-logging.interceptor.d.ts +6 -0
- package/dist/nats/interceptors/nats-logging.interceptor.js +33 -0
- package/dist/nats/interfaces/nats-options.interface.d.ts +23 -0
- package/dist/nats/interfaces/nats-options.interface.js +2 -0
- package/dist/notification/index.d.ts +4 -0
- package/dist/notification/index.js +20 -0
- package/dist/notification/notification.client.d.ts +31 -0
- package/dist/notification/notification.client.js +104 -0
- package/dist/notification/notification.enum.d.ts +10 -0
- package/dist/notification/notification.enum.js +14 -0
- package/dist/notification/notification.interface.d.ts +31 -0
- package/dist/notification/notification.interface.js +2 -0
- package/dist/notification/notification.module.d.ts +2 -0
- package/dist/notification/notification.module.js +20 -0
- package/dist/rpc/index.d.ts +54 -0
- package/dist/rpc/index.js +135 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskPhoneNumber = exports.formatPhoneNumber = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Formats phone number for display
|
|
6
|
+
* 2348012345678 → +234 801 234 5678
|
|
7
|
+
*/
|
|
8
|
+
const formatPhoneNumber = (phone) => {
|
|
9
|
+
const cleaned = phone.replace(/[\s\-\(\)]/g, '');
|
|
10
|
+
// Ensure it starts with 234
|
|
11
|
+
let formatted = cleaned;
|
|
12
|
+
if (formatted.startsWith('0')) {
|
|
13
|
+
formatted = '234' + formatted.substring(1);
|
|
14
|
+
}
|
|
15
|
+
// Format as +234 801 234 5678
|
|
16
|
+
if (formatted.startsWith('234')) {
|
|
17
|
+
return `+234 ${formatted.substring(3, 6)} ${formatted.substring(6, 9)} ${formatted.substring(9)}`;
|
|
18
|
+
}
|
|
19
|
+
return phone;
|
|
20
|
+
};
|
|
21
|
+
exports.formatPhoneNumber = formatPhoneNumber;
|
|
22
|
+
/**
|
|
23
|
+
* Masks phone number for security
|
|
24
|
+
* +2348012345678 → +234****5678
|
|
25
|
+
*/
|
|
26
|
+
const maskPhoneNumber = (phone) => {
|
|
27
|
+
const cleaned = phone.replace(/[\s\-\(\)]/g, '');
|
|
28
|
+
if (cleaned.length < 8)
|
|
29
|
+
return phone;
|
|
30
|
+
const prefix = cleaned.substring(0, 4);
|
|
31
|
+
const suffix = cleaned.slice(-4);
|
|
32
|
+
return `${prefix}****${suffix}`;
|
|
33
|
+
};
|
|
34
|
+
exports.maskPhoneNumber = maskPhoneNumber;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nats"), exports);
|
|
18
|
+
__exportStar(require("./common"), exports);
|
|
19
|
+
__exportStar(require("./cache"), exports);
|
|
20
|
+
__exportStar(require("./rpc"), exports);
|
|
21
|
+
__exportStar(require("./notification"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const NATS_OPTIONS = "NATS_OPTIONS";
|
|
2
|
+
export declare const NATS_CLIENT = "NATS_CLIENT";
|
|
3
|
+
export declare const DEFAULT_NATS_CONFIG: {
|
|
4
|
+
url: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
reconnect: boolean;
|
|
7
|
+
reconnectTimeWait: number;
|
|
8
|
+
maxReconnectAttempts: number;
|
|
9
|
+
};
|
|
10
|
+
export declare enum NatsSubjects {
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsSubjects = exports.DEFAULT_NATS_CONFIG = exports.NATS_CLIENT = exports.NATS_OPTIONS = void 0;
|
|
4
|
+
exports.NATS_OPTIONS = 'NATS_OPTIONS';
|
|
5
|
+
exports.NATS_CLIENT = 'NATS_CLIENT';
|
|
6
|
+
exports.DEFAULT_NATS_CONFIG = {
|
|
7
|
+
url: 'nats://localhost:4222',
|
|
8
|
+
timeout: 5000,
|
|
9
|
+
reconnect: true,
|
|
10
|
+
reconnectTimeWait: 2000,
|
|
11
|
+
maxReconnectAttempts: 10,
|
|
12
|
+
};
|
|
13
|
+
var NatsSubjects;
|
|
14
|
+
(function (NatsSubjects) {
|
|
15
|
+
})(NatsSubjects || (exports.NatsSubjects = NatsSubjects = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NATS_EVENT_METADATA = void 0;
|
|
4
|
+
exports.NatsEventPattern = NatsEventPattern;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
7
|
+
const nats_logging_interceptor_1 = require("../interceptors/nats-logging.interceptor");
|
|
8
|
+
exports.NATS_EVENT_METADATA = 'nats_event_metadata';
|
|
9
|
+
function NatsEventPattern(pattern) {
|
|
10
|
+
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.NATS_EVENT_METADATA, { pattern }), (0, microservices_1.EventPattern)(pattern), (0, common_1.UseInterceptors)(nats_logging_interceptor_1.NatsLoggingInterceptor));
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NatsMessageDto = void 0;
|
|
10
|
+
const class_validator_1 = require("class-validator");
|
|
11
|
+
class NatsMessageDto {
|
|
12
|
+
pattern;
|
|
13
|
+
data;
|
|
14
|
+
replyTo;
|
|
15
|
+
}
|
|
16
|
+
exports.NatsMessageDto = NatsMessageDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_validator_1.IsString)(),
|
|
19
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
20
|
+
], NatsMessageDto.prototype, "pattern", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, class_validator_1.IsNotEmpty)()
|
|
23
|
+
], NatsMessageDto.prototype, "data", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_validator_1.IsString)(),
|
|
26
|
+
(0, class_validator_1.IsOptional)()
|
|
27
|
+
], NatsMessageDto.prototype, "replyTo", void 0);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants/nats.constants"), exports);
|
|
18
|
+
__exportStar(require("./interfaces/nats-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./dto/nats-message.dto"), exports);
|
|
20
|
+
__exportStar(require("./decorators/nats-event-pattern.decorator"), exports);
|
|
21
|
+
__exportStar(require("./interceptors/nats-logging.interceptor"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class NatsLoggingInterceptor implements NestInterceptor {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var NatsLoggingInterceptor_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.NatsLoggingInterceptor = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
let NatsLoggingInterceptor = NatsLoggingInterceptor_1 = class NatsLoggingInterceptor {
|
|
14
|
+
logger = new common_1.Logger(NatsLoggingInterceptor_1.name);
|
|
15
|
+
intercept(context, next) {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
const rpcContext = context.switchToRpc();
|
|
18
|
+
const natsContext = rpcContext.getContext();
|
|
19
|
+
const pattern = natsContext.getSubject();
|
|
20
|
+
return next.handle().pipe((0, rxjs_1.tap)({
|
|
21
|
+
next: (data) => {
|
|
22
|
+
this.logger.log(`Pattern: ${pattern} | Response time: ${Date.now() - now}ms | Response: ${JSON.stringify(data)}`);
|
|
23
|
+
},
|
|
24
|
+
error: (error) => {
|
|
25
|
+
this.logger.error(`Pattern: ${pattern} | Error: ${error.message}`, error.stack);
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.NatsLoggingInterceptor = NatsLoggingInterceptor;
|
|
31
|
+
exports.NatsLoggingInterceptor = NatsLoggingInterceptor = NatsLoggingInterceptor_1 = __decorate([
|
|
32
|
+
(0, common_1.Injectable)()
|
|
33
|
+
], NatsLoggingInterceptor);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { Transport } from '@nestjs/microservices';
|
|
3
|
+
export interface NatsOptions {
|
|
4
|
+
transport: Transport.NATS;
|
|
5
|
+
options: {
|
|
6
|
+
servers: string[];
|
|
7
|
+
queue?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
reconnect?: boolean;
|
|
11
|
+
reconnectTimeWait?: number;
|
|
12
|
+
maxReconnectAttempts?: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface NatsOptionsFactory {
|
|
16
|
+
createNatsOptions(): Promise<NatsOptions> | NatsOptions;
|
|
17
|
+
}
|
|
18
|
+
export interface NatsAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
19
|
+
useExisting?: Type<NatsOptionsFactory>;
|
|
20
|
+
useClass?: Type<NatsOptionsFactory>;
|
|
21
|
+
useFactory?: (...args: any[]) => Promise<NatsOptions> | NatsOptions;
|
|
22
|
+
inject?: any[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./notification.client"), exports);
|
|
18
|
+
__exportStar(require("./notification.interface"), exports);
|
|
19
|
+
__exportStar(require("./notification.enum"), exports);
|
|
20
|
+
__exportStar(require("./notification.module"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ClientProxy } from '@nestjs/microservices';
|
|
2
|
+
import { OTPMail, ResetTransactionPinEmail, PasswordResetMail, EmailVerificationMail, DeviceVerificationMail, BulkEmail, BaseEmail } from './notification.interface';
|
|
3
|
+
export declare class Notification {
|
|
4
|
+
private readonly natsClient;
|
|
5
|
+
constructor(natsClient: ClientProxy);
|
|
6
|
+
private validatePhoneNumber;
|
|
7
|
+
private validateEmailAddress;
|
|
8
|
+
sendBulkEmail(data: BulkEmail): Promise<void>;
|
|
9
|
+
sendForgetPinOTPMail(to: string, data: ResetTransactionPinEmail): Promise<void>;
|
|
10
|
+
sendPasswordResetMail(to: string, data: PasswordResetMail): Promise<void>;
|
|
11
|
+
sendEmailVerificationMail(to: string, data: EmailVerificationMail): Promise<void>;
|
|
12
|
+
sendDeviceVerificationEmail(to: string, data: Omit<DeviceVerificationMail, keyof BaseEmail>): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Sends generated OTP via email
|
|
15
|
+
* @param to - recipient email address
|
|
16
|
+
* @param data - OTP data
|
|
17
|
+
*/
|
|
18
|
+
sendOTPByMail(to: string, data: OTPMail): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Sends generated OTP via SMS
|
|
21
|
+
* @param to - recipient phone number
|
|
22
|
+
* @param data - OTP data
|
|
23
|
+
*/
|
|
24
|
+
sendOTPBySms(to: string, data: OTPMail): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Sends generated OTP via voice call
|
|
27
|
+
* @param to - recipient phone number
|
|
28
|
+
* @param data - OTP data
|
|
29
|
+
*/
|
|
30
|
+
sendOTPByVoice(to: string, data: OTPMail): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Notification = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const notification_enum_1 = require("./notification.enum");
|
|
15
|
+
const nats_1 = require("../nats");
|
|
16
|
+
const class_validator_1 = require("class-validator");
|
|
17
|
+
let Notification = class Notification {
|
|
18
|
+
natsClient;
|
|
19
|
+
constructor(natsClient) {
|
|
20
|
+
this.natsClient = natsClient;
|
|
21
|
+
}
|
|
22
|
+
validatePhoneNumber(phone) {
|
|
23
|
+
if (!(0, class_validator_1.isPhoneNumber)(phone)) {
|
|
24
|
+
throw new common_1.BadRequestException('Invalid phone number');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
validateEmailAddress(email) {
|
|
28
|
+
if (!(0, class_validator_1.isEmail)(email)) {
|
|
29
|
+
throw new common_1.BadRequestException('Invalid email address');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async sendBulkEmail(data) {
|
|
33
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.NOTIFICATION_EMAIL_BULK, data);
|
|
34
|
+
}
|
|
35
|
+
async sendForgetPinOTPMail(to, data) {
|
|
36
|
+
this.validateEmailAddress(to);
|
|
37
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.FORGET_PIN_OTP_MAIL, {
|
|
38
|
+
to,
|
|
39
|
+
data,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async sendPasswordResetMail(to, data) {
|
|
43
|
+
this.validateEmailAddress(to);
|
|
44
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.PASSWORD_RESET_MAIL, {
|
|
45
|
+
to,
|
|
46
|
+
data,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async sendEmailVerificationMail(to, data) {
|
|
50
|
+
this.validateEmailAddress(to);
|
|
51
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.EMAIL_VERIFICATION_EMAIL, {
|
|
52
|
+
to,
|
|
53
|
+
data,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async sendDeviceVerificationEmail(to, data) {
|
|
57
|
+
this.validateEmailAddress(to);
|
|
58
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.DEVICE_VERIFICATION_MAIL, {
|
|
59
|
+
to,
|
|
60
|
+
data,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sends generated OTP via email
|
|
65
|
+
* @param to - recipient email address
|
|
66
|
+
* @param data - OTP data
|
|
67
|
+
*/
|
|
68
|
+
async sendOTPByMail(to, data) {
|
|
69
|
+
this.validateEmailAddress(to);
|
|
70
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.OTP_MAIL, {
|
|
71
|
+
to,
|
|
72
|
+
...data,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sends generated OTP via SMS
|
|
77
|
+
* @param to - recipient phone number
|
|
78
|
+
* @param data - OTP data
|
|
79
|
+
*/
|
|
80
|
+
async sendOTPBySms(to, data) {
|
|
81
|
+
this.validatePhoneNumber(to);
|
|
82
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.NOTIFICATION_OTP_TEXT, {
|
|
83
|
+
to,
|
|
84
|
+
...data,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sends generated OTP via voice call
|
|
89
|
+
* @param to - recipient phone number
|
|
90
|
+
* @param data - OTP data
|
|
91
|
+
*/
|
|
92
|
+
async sendOTPByVoice(to, data) {
|
|
93
|
+
this.validatePhoneNumber(to);
|
|
94
|
+
this.natsClient.emit(notification_enum_1.NotificationSubject.NOTIFICATION_OTP_VOICE, {
|
|
95
|
+
to,
|
|
96
|
+
...data,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
exports.Notification = Notification;
|
|
101
|
+
exports.Notification = Notification = __decorate([
|
|
102
|
+
(0, common_1.Injectable)(),
|
|
103
|
+
__param(0, (0, common_1.Inject)(nats_1.NATS_CLIENT))
|
|
104
|
+
], Notification);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum NotificationSubject {
|
|
2
|
+
NOTIFICATION_EMAIL_BULK = "notification.email.bulk",
|
|
3
|
+
OTP_MAIL = "notification.mail.otp",
|
|
4
|
+
EMAIL_VERIFICATION_EMAIL = "notification.mail.email.verification",
|
|
5
|
+
PASSWORD_RESET_MAIL = "notification.mail.passwordreset",
|
|
6
|
+
FORGET_PIN_OTP_MAIL = "notification.mail.forgetpin.otp",
|
|
7
|
+
DEVICE_VERIFICATION_MAIL = "notification.mail.device.verification",
|
|
8
|
+
NOTIFICATION_OTP_TEXT = "notification.text.otp",
|
|
9
|
+
NOTIFICATION_OTP_VOICE = "notification.voice.otp"
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationSubject = void 0;
|
|
4
|
+
var NotificationSubject;
|
|
5
|
+
(function (NotificationSubject) {
|
|
6
|
+
NotificationSubject["NOTIFICATION_EMAIL_BULK"] = "notification.email.bulk";
|
|
7
|
+
NotificationSubject["OTP_MAIL"] = "notification.mail.otp";
|
|
8
|
+
NotificationSubject["EMAIL_VERIFICATION_EMAIL"] = "notification.mail.email.verification";
|
|
9
|
+
NotificationSubject["PASSWORD_RESET_MAIL"] = "notification.mail.passwordreset";
|
|
10
|
+
NotificationSubject["FORGET_PIN_OTP_MAIL"] = "notification.mail.forgetpin.otp";
|
|
11
|
+
NotificationSubject["DEVICE_VERIFICATION_MAIL"] = "notification.mail.device.verification";
|
|
12
|
+
NotificationSubject["NOTIFICATION_OTP_TEXT"] = "notification.text.otp";
|
|
13
|
+
NotificationSubject["NOTIFICATION_OTP_VOICE"] = "notification.voice.otp";
|
|
14
|
+
})(NotificationSubject || (exports.NotificationSubject = NotificationSubject = {}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface BulkEmail {
|
|
2
|
+
to: string[];
|
|
3
|
+
subject: string;
|
|
4
|
+
template: string;
|
|
5
|
+
user_id?: string;
|
|
6
|
+
bypassPreferenceCheck?: boolean;
|
|
7
|
+
context: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
export interface BaseEmail {
|
|
10
|
+
firstName: string;
|
|
11
|
+
currentYear: number;
|
|
12
|
+
}
|
|
13
|
+
export interface OTPMail extends BaseEmail {
|
|
14
|
+
otp: number;
|
|
15
|
+
expiration: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ResetTransactionPinEmail extends OTPMail {
|
|
18
|
+
}
|
|
19
|
+
export interface PasswordResetMail extends OTPMail {
|
|
20
|
+
}
|
|
21
|
+
export interface EmailVerificationMail extends OTPMail {
|
|
22
|
+
}
|
|
23
|
+
export interface DeviceVerificationMail extends BaseEmail {
|
|
24
|
+
to: string;
|
|
25
|
+
subject: string;
|
|
26
|
+
otp: string;
|
|
27
|
+
deviceId: string;
|
|
28
|
+
deviceName?: string;
|
|
29
|
+
time?: string;
|
|
30
|
+
expiration?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NotificationModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const notification_client_1 = require("./notification.client");
|
|
12
|
+
let NotificationModule = class NotificationModule {
|
|
13
|
+
};
|
|
14
|
+
exports.NotificationModule = NotificationModule;
|
|
15
|
+
exports.NotificationModule = NotificationModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
providers: [notification_client_1.Notification],
|
|
18
|
+
exports: [notification_client_1.Notification],
|
|
19
|
+
})
|
|
20
|
+
], NotificationModule);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NatsContext, RpcException } from '@nestjs/microservices';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export interface ViardexRPCError {
|
|
4
|
+
success: boolean;
|
|
5
|
+
subject: string | null;
|
|
6
|
+
message: string;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface ViardexRPCSuccess<T> {
|
|
11
|
+
data?: T;
|
|
12
|
+
}
|
|
13
|
+
export declare class ViardexRpc {
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a promise returned by an RPC request handler.
|
|
16
|
+
* @param promise - A Promise resolving to the response value.
|
|
17
|
+
* @param ctx - Optional NatsContext object.
|
|
18
|
+
* @param successMessage - Optional success message
|
|
19
|
+
*/
|
|
20
|
+
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext): Promise<ViardexRPCSuccess<V> | RpcException>;
|
|
21
|
+
/**
|
|
22
|
+
* Handles errors from an RPC request handler and returns a ViardexRPCError wrapped in RpcException.
|
|
23
|
+
* @param err - Error to be handled.
|
|
24
|
+
* @param ctx - A NATS Context.
|
|
25
|
+
*/
|
|
26
|
+
static handleRequestError(err: unknown, ctx: NatsContext): RpcException;
|
|
27
|
+
private static catch;
|
|
28
|
+
/**
|
|
29
|
+
* Handles NATS request response.
|
|
30
|
+
* @param obs - An instance of an Observable.
|
|
31
|
+
* @param successMessage - Optional success message
|
|
32
|
+
*/
|
|
33
|
+
static withReply<V>(obs: Observable<V>, successMessage?: string): Promise<ViardexRPCSuccess<V>>;
|
|
34
|
+
}
|
|
35
|
+
export declare class ViardexRpcV2 {
|
|
36
|
+
/**
|
|
37
|
+
* Wraps a promise returned by an RPC request handler.
|
|
38
|
+
* @param promise - A Promise resolving to the response value.
|
|
39
|
+
* @param ctx - Optional NatsContext object.
|
|
40
|
+
*/
|
|
41
|
+
static handleRequest<V>(promise: Promise<V>, ctx?: NatsContext): Promise<ViardexRPCSuccess<V> | ViardexRPCError>;
|
|
42
|
+
/**
|
|
43
|
+
* Handles errors from an RPC request handler and returns a ViardexRPCError.
|
|
44
|
+
* @param err - Error to be handled.
|
|
45
|
+
* @param ctx - A NATS Context.
|
|
46
|
+
*/
|
|
47
|
+
static handleRequestError(err: unknown, ctx: NatsContext): ViardexRPCError;
|
|
48
|
+
private static catch;
|
|
49
|
+
/**
|
|
50
|
+
* Handles NATS request response.
|
|
51
|
+
* @param obs - An instance of an Observable.
|
|
52
|
+
*/
|
|
53
|
+
static withReply<V>(obs: Observable<V>): Promise<ViardexRPCSuccess<V>>;
|
|
54
|
+
}
|