@konplit-services/common 1.0.71 → 1.0.74
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/build/events/accounts-events/interfaces/permission-created.interface.d.ts +1 -1
- package/build/events/accounts-events/interfaces/permission-removed.interface.d.ts +1 -1
- package/build/events/publisher/email.publisher.d.ts +8 -0
- package/build/events/publisher/email.publisher.js +14 -0
- package/build/events/publisher/sms.publisher.d.ts +8 -0
- package/build/events/publisher/sms.publisher.js +14 -0
- package/build/services/base.service.d.ts +5 -0
- package/build/services/base.service.js +70 -0
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Publisher } from "../base-events";
|
|
2
|
+
import { MailersendEmailCreatedEvent } from "../notification-events/interfaces";
|
|
3
|
+
import { StreamEvent, StreamName, Subjects } from "../subjects";
|
|
4
|
+
export declare class EmailCreatedPublisher extends Publisher<MailersendEmailCreatedEvent> {
|
|
5
|
+
streamEvents: StreamEvent.Event;
|
|
6
|
+
stream: StreamName.name;
|
|
7
|
+
readonly subject = Subjects.NotificationEmailCreated;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailCreatedPublisher = void 0;
|
|
4
|
+
const base_events_1 = require("../base-events");
|
|
5
|
+
const subjects_1 = require("../subjects");
|
|
6
|
+
class EmailCreatedPublisher extends base_events_1.Publisher {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.streamEvents = subjects_1.StreamEvent.Event;
|
|
10
|
+
this.stream = subjects_1.StreamName.name;
|
|
11
|
+
this.subject = subjects_1.Subjects.NotificationEmailCreated;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.EmailCreatedPublisher = EmailCreatedPublisher;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Publisher } from "../base-events";
|
|
2
|
+
import { TermiiSmsCreatedEvent } from "../notification-events/interfaces";
|
|
3
|
+
import { StreamEvent, StreamName, Subjects } from "../subjects";
|
|
4
|
+
export declare class SMSCreatedPublisher extends Publisher<TermiiSmsCreatedEvent> {
|
|
5
|
+
streamEvents: StreamEvent.Event;
|
|
6
|
+
stream: StreamName.name;
|
|
7
|
+
readonly subject = Subjects.NotificationSmsCreated;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SMSCreatedPublisher = void 0;
|
|
4
|
+
const base_events_1 = require("../base-events");
|
|
5
|
+
const subjects_1 = require("../subjects");
|
|
6
|
+
class SMSCreatedPublisher extends base_events_1.Publisher {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.streamEvents = subjects_1.StreamEvent.Event;
|
|
10
|
+
this.stream = subjects_1.StreamName.name;
|
|
11
|
+
this.subject = subjects_1.Subjects.NotificationSmsCreated;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SMSCreatedPublisher = SMSCreatedPublisher;
|
|
@@ -7,6 +7,7 @@ import { AxiosRequestError } from "../errors/axios-request-error";
|
|
|
7
7
|
import { JetStreamClient } from "nats";
|
|
8
8
|
import { LOGACTIONS } from "../log-activities/actions";
|
|
9
9
|
import { JWT_Data } from "./Jwt";
|
|
10
|
+
import { EmailValidationTypes, SMSTYPE } from "../notification";
|
|
10
11
|
interface User {
|
|
11
12
|
id?: string;
|
|
12
13
|
email?: string;
|
|
@@ -23,5 +24,9 @@ export declare class Service {
|
|
|
23
24
|
protected AxiosRequestError: typeof AxiosRequestError;
|
|
24
25
|
activityLog(client: JetStreamClient, user: Partial<User> | Partial<JWT_Data>, action: LOGACTIONS, data: any): void;
|
|
25
26
|
merchantOnlyLogs(client: JetStreamClient, user: Partial<User> | Partial<JWT_Data>, action: LOGACTIONS, data: any): void;
|
|
27
|
+
sendSMS(token: string, type: SMSTYPE, data: any, client: JetStreamClient): void;
|
|
28
|
+
sendEmail(emailtype: EmailValidationTypes, data: any, to: string, subject: string, client: JetStreamClient): void;
|
|
29
|
+
private sysType;
|
|
30
|
+
private emailType;
|
|
26
31
|
}
|
|
27
32
|
export {};
|
|
@@ -10,6 +10,11 @@ const axios_request_error_1 = require("../errors/axios-request-error");
|
|
|
10
10
|
const merchant_log_publisher_1 = require("../events/publisher/merchant-log.publisher");
|
|
11
11
|
const admin_log_publisher_1 = require("../events/publisher/admin-log.publisher");
|
|
12
12
|
const helper_1 = require("../helper");
|
|
13
|
+
const notification_1 = require("../notification");
|
|
14
|
+
const app_configs_1 = require("../app.configs");
|
|
15
|
+
const util_1 = require("../util");
|
|
16
|
+
const email_publisher_1 = require("../events/publisher/email.publisher");
|
|
17
|
+
const sms_publisher_1 = require("../events/publisher/sms.publisher");
|
|
13
18
|
class Service {
|
|
14
19
|
constructor() {
|
|
15
20
|
this.NotFoundError = not_found_1.NotFoundError;
|
|
@@ -48,5 +53,70 @@ class Service {
|
|
|
48
53
|
data,
|
|
49
54
|
});
|
|
50
55
|
}
|
|
56
|
+
sendSMS(token, type, data, client) {
|
|
57
|
+
const sms = this.sysType(type, token);
|
|
58
|
+
new sms_publisher_1.SMSCreatedPublisher(client).publish({
|
|
59
|
+
to: (0, util_1.formatToNigerianNumber)(data.phone),
|
|
60
|
+
sms,
|
|
61
|
+
channel: "unknown",
|
|
62
|
+
type: "unknown",
|
|
63
|
+
from: "unknown",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
sendEmail(emailtype, data, to, subject, client) {
|
|
67
|
+
const templateId = this.emailType(emailtype);
|
|
68
|
+
new email_publisher_1.EmailCreatedPublisher(client).publish({
|
|
69
|
+
to: to,
|
|
70
|
+
subject: subject,
|
|
71
|
+
templateId: templateId,
|
|
72
|
+
data: data,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
sysType(type, token) {
|
|
76
|
+
let message;
|
|
77
|
+
switch (type) {
|
|
78
|
+
case notification_1.SMSTYPE.PHONE_VALIDATION:
|
|
79
|
+
message = (0, notification_1.phoneValidation)(token);
|
|
80
|
+
break;
|
|
81
|
+
case notification_1.SMSTYPE.TWO_FACTOR_VALIDATION:
|
|
82
|
+
message = (0, notification_1.twoFactor)(token);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
throw new Error("Invalid sms type");
|
|
86
|
+
}
|
|
87
|
+
return message;
|
|
88
|
+
}
|
|
89
|
+
emailType(type) {
|
|
90
|
+
let templateId;
|
|
91
|
+
switch (type) {
|
|
92
|
+
case notification_1.EmailValidationTypes.EMAILVALIDATION:
|
|
93
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().verify_account;
|
|
94
|
+
break;
|
|
95
|
+
case notification_1.EmailValidationTypes.TWO_FACTOR_VALIDATION:
|
|
96
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().token;
|
|
97
|
+
break;
|
|
98
|
+
case notification_1.EmailValidationTypes.ACCOUNTVERIFIED:
|
|
99
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().account_verified;
|
|
100
|
+
break;
|
|
101
|
+
case notification_1.EmailValidationTypes.FORGETPASSWORD:
|
|
102
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().forgot_password;
|
|
103
|
+
break;
|
|
104
|
+
case notification_1.EmailValidationTypes.RESETPASSORD:
|
|
105
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().reset_password;
|
|
106
|
+
break;
|
|
107
|
+
case notification_1.EmailValidationTypes.TWO_FACTOR_AUTHS_CHANGE:
|
|
108
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().two_factor_auth_change;
|
|
109
|
+
break;
|
|
110
|
+
case notification_1.EmailValidationTypes.USER_ACCOUNT_CREATED:
|
|
111
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().user_account_created;
|
|
112
|
+
break;
|
|
113
|
+
case notification_1.EmailValidationTypes.USER_INVITED:
|
|
114
|
+
templateId = app_configs_1.appConfigs.getEmailTemplates().user_invited;
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
throw new Error("Invalid email type");
|
|
118
|
+
}
|
|
119
|
+
return templateId;
|
|
120
|
+
}
|
|
51
121
|
}
|
|
52
122
|
exports.Service = Service;
|