dt-common-device 13.4.7 → 13.4.9
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/dist/Integrations/twilio/twilio.service.d.ts +1 -2
- package/dist/Integrations/twilio/twilio.service.js +16 -20
- package/dist/entities/notification/INotification.d.ts +9 -0
- package/dist/entities/notification/Notification.repository.d.ts +2 -1
- package/dist/entities/notification/Notification.repository.js +13 -1
- package/dist/entities/notification/Notification.service.d.ts +2 -1
- package/dist/entities/notification/Notification.service.js +3 -0
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ISendSMSRequest } from "./interface/twilioInterface";
|
|
2
2
|
export declare class TwilioService {
|
|
3
|
-
private readonly
|
|
4
|
-
private readonly propertyRepository;
|
|
3
|
+
private readonly notificationService;
|
|
5
4
|
constructor();
|
|
6
5
|
sendSMS(data: ISendSMSRequest): Promise<any>;
|
|
7
6
|
}
|
|
@@ -76,10 +76,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
76
76
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
77
|
exports.TwilioService = void 0;
|
|
78
78
|
const typedi_1 = __importStar(require("typedi"));
|
|
79
|
-
const
|
|
80
|
-
const IConnection_1 = require("../../entities/connection/IConnection");
|
|
79
|
+
const Notification_service_1 = require("../../entities/notification/Notification.service");
|
|
81
80
|
const twilio_1 = __importDefault(require("twilio"));
|
|
82
|
-
const Property_repository_1 = require("../../entities/property/Property.repository");
|
|
83
81
|
let TwilioService = (() => {
|
|
84
82
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
85
83
|
let _classDescriptor;
|
|
@@ -87,36 +85,34 @@ let TwilioService = (() => {
|
|
|
87
85
|
let _classThis;
|
|
88
86
|
var TwilioService = _classThis = class {
|
|
89
87
|
constructor() {
|
|
90
|
-
this.
|
|
91
|
-
this.propertyRepository = typedi_1.default.get(Property_repository_1.PropertyRepository);
|
|
88
|
+
this.notificationService = typedi_1.default.get(Notification_service_1.NotificationService);
|
|
92
89
|
}
|
|
93
90
|
// -----------------------------
|
|
94
91
|
// Send SMS
|
|
95
92
|
// -----------------------------
|
|
96
93
|
async sendSMS(data) {
|
|
97
94
|
const { propertyId, message, toNumber } = data;
|
|
95
|
+
if (!propertyId) {
|
|
96
|
+
throw new Error("Property ID is required for sending SMS");
|
|
97
|
+
}
|
|
98
98
|
if (!toNumber) {
|
|
99
99
|
throw new Error("To number is required for sending SMS");
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
const response = await this.connectionRepository.queryConnections({
|
|
101
|
+
const connection = await this.notificationService.queryConnections({
|
|
103
102
|
propertyId,
|
|
104
|
-
connectionProvider:
|
|
103
|
+
connectionProvider: "twilio",
|
|
104
|
+
isEnable: true,
|
|
105
105
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const fromNumber = metaData?.fromNumber;
|
|
109
|
-
if (!fromNumber) {
|
|
110
|
-
throw new Error("From number not found");
|
|
106
|
+
if (!connection) {
|
|
107
|
+
throw new Error("Twilio connection not found for this property");
|
|
111
108
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
throw new Error("Property settings not found");
|
|
109
|
+
const { clientId, clientSecret, metaData } = connection;
|
|
110
|
+
if (!clientId || !clientSecret) {
|
|
111
|
+
throw new Error("Twilio credentials (clientId, clientSecret) not found");
|
|
116
112
|
}
|
|
117
|
-
const
|
|
118
|
-
if (!
|
|
119
|
-
throw new Error("
|
|
113
|
+
const fromNumber = metaData?.fromNumber;
|
|
114
|
+
if (!fromNumber || typeof fromNumber !== "string") {
|
|
115
|
+
throw new Error("From number not found");
|
|
120
116
|
}
|
|
121
117
|
//TODO: Need to do single tone pattern for the client
|
|
122
118
|
const client = (0, twilio_1.default)(clientId, clientSecret);
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export type NotificationChannel = "email" | "sms";
|
|
2
2
|
export type NotificationScope = "platform" | "organization" | "property";
|
|
3
|
+
export interface INotificationQuery {
|
|
4
|
+
id?: string;
|
|
5
|
+
clientId?: string;
|
|
6
|
+
clientSecret?: string;
|
|
7
|
+
metaData?: Record<string, unknown>;
|
|
8
|
+
propertyId?: string;
|
|
9
|
+
connectionProvider?: string;
|
|
10
|
+
isEnable?: boolean;
|
|
11
|
+
}
|
|
3
12
|
export interface INotificationTemplateResolve {
|
|
4
13
|
propertyId?: string;
|
|
5
14
|
organizationId?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { INotificationTemplate, INotificationTemplateResolve } from "./INotification";
|
|
1
|
+
import { INotificationQuery, INotificationTemplate, INotificationTemplateResolve } from "./INotification";
|
|
2
2
|
export declare class NotificationRepository {
|
|
3
|
+
queryConnections(payload: INotificationQuery): Promise<any>;
|
|
3
4
|
getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
|
|
4
5
|
}
|
|
@@ -47,6 +47,17 @@ let NotificationRepository = (() => {
|
|
|
47
47
|
let _classExtraInitializers = [];
|
|
48
48
|
let _classThis;
|
|
49
49
|
var NotificationRepository = _classThis = class {
|
|
50
|
+
async queryConnections(payload) {
|
|
51
|
+
if (!payload || Object.keys(payload).length === 0) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const normalizedPayload = { ...payload };
|
|
55
|
+
const response = await (0, http_utils_1.getNotificationServiceAxiosInstance)().post(`/connections/query`, normalizedPayload);
|
|
56
|
+
if (!response.data?.success || !response.data?.data?.length) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return response.data.data;
|
|
60
|
+
}
|
|
50
61
|
async getNotificationTemplate(payload) {
|
|
51
62
|
if (!payload.propertyId ||
|
|
52
63
|
!payload.organizationId ||
|
|
@@ -55,7 +66,8 @@ let NotificationRepository = (() => {
|
|
|
55
66
|
throw new Error("Property ID, Organization ID, Event Name, and Channel are required in payload");
|
|
56
67
|
}
|
|
57
68
|
const response = await (0, http_utils_1.getNotificationServiceAxiosInstance)().post(`/notification-templates/resolve`, payload);
|
|
58
|
-
|
|
69
|
+
console.log("NotificationTemplate response:", response.data);
|
|
70
|
+
return response.data;
|
|
59
71
|
}
|
|
60
72
|
};
|
|
61
73
|
__setFunctionName(_classThis, "NotificationRepository");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { INotificationTemplate, INotificationTemplateResolve } from "./INotification";
|
|
1
|
+
import { INotificationQuery, INotificationTemplate, INotificationTemplateResolve } from "./INotification";
|
|
2
2
|
export declare class NotificationService {
|
|
3
3
|
private readonly notificationRepository;
|
|
4
4
|
constructor();
|
|
5
|
+
queryConnections(payload: INotificationQuery): Promise<any>;
|
|
5
6
|
getNotificationTemplate(payload: INotificationTemplateResolve): Promise<INotificationTemplate | null>;
|
|
6
7
|
}
|
|
@@ -83,6 +83,9 @@ let NotificationService = (() => {
|
|
|
83
83
|
constructor() {
|
|
84
84
|
this.notificationRepository = typedi_1.default.get(Notification_repository_1.NotificationRepository);
|
|
85
85
|
}
|
|
86
|
+
async queryConnections(payload) {
|
|
87
|
+
return await this.notificationRepository.queryConnections(payload);
|
|
88
|
+
}
|
|
86
89
|
async getNotificationTemplate(payload) {
|
|
87
90
|
if (!payload.propertyId ||
|
|
88
91
|
!payload.organizationId ||
|