aeremmiddleware 1.0.1 → 1.0.2

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.
@@ -0,0 +1,35 @@
1
+ export default class IdfyAPIWrapper {
2
+ private bodyTaskIdGroupId;
3
+ private defaultHeaderIdfyApi;
4
+ private baseUrl;
5
+ private gstVerificationEndPoint;
6
+ private panIndividualVerificationEndPoint;
7
+ private cinCompanyVerificationEndPoint;
8
+ private taskUrl;
9
+ private syncIndividualAadharScanInfoEndpoint;
10
+ private syncIndividualPANScanInfoEndpoint;
11
+ private syncIndividualLiveFaceLivenessEndpoint;
12
+ constructor();
13
+ private makeRequest;
14
+ private getTask;
15
+ private pingTaskUntilSuccess;
16
+ getCompanyGstInfo({ gstNo }: {
17
+ gstNo: string;
18
+ }): Promise<any>;
19
+ getCompanyCINInfo({ cinNo }: {
20
+ cinNo: string;
21
+ }): Promise<any>;
22
+ getIndividualPANInfo({ panNo }: {
23
+ panNo: string;
24
+ }): Promise<any>;
25
+ getSyncIndividualAadharScanInfo({ frontScanBase64, backScanBase64 }: {
26
+ frontScanBase64: string;
27
+ backScanBase64: string;
28
+ }): Promise<any>;
29
+ getSyncIndividualPANScanInfo({ frontScanBase64 }: {
30
+ frontScanBase64: string;
31
+ }): Promise<any>;
32
+ getSyncIndividualLivenessSelfyScanInfo({ faceScanBase64 }: {
33
+ faceScanBase64: string;
34
+ }): Promise<any>;
35
+ }
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ class IdfyAPIWrapper {
17
+ constructor() {
18
+ this.bodyTaskIdGroupId = {
19
+ task_id: '74f4c926-250c-43ca-9c53-453e87ceacd1',
20
+ group_id: '8e16424a-58fc-4ba4-ab20-5bc8e7c3c41e',
21
+ };
22
+ this.defaultHeaderIdfyApi = {
23
+ "account-id": "e0d2add9d3c1/86e1d197-adb5-4f8f-af82-2728599a3615",
24
+ "api-key": "7fad350f-5519-4ec7-b977-d8c8b131b8e4"
25
+ };
26
+ this.baseUrl = "https://eve.idfy.com/";
27
+ this.gstVerificationEndPoint = 'v3/tasks/sync/verify_with_source/ind_gst_certificate';
28
+ this.panIndividualVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_pan';
29
+ this.cinCompanyVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_mca';
30
+ this.taskUrl = 'v3/tasks?request_id=';
31
+ this.syncIndividualAadharScanInfoEndpoint = 'v3/tasks/sync/extract/ind_aadhaar_plus';
32
+ this.syncIndividualPANScanInfoEndpoint = 'v3/tasks/sync/extract/ind_pan';
33
+ this.syncIndividualLiveFaceLivenessEndpoint = 'v3/tasks/sync/check_photo_liveness/face';
34
+ }
35
+ makeRequest(method, endpoint, data) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const requestConfig = {
38
+ method,
39
+ url: this.baseUrl + endpoint,
40
+ headers: this.defaultHeaderIdfyApi,
41
+ data,
42
+ };
43
+ try {
44
+ const response = yield (0, axios_1.default)(requestConfig);
45
+ return response.data;
46
+ }
47
+ catch (error) {
48
+ console.error("Error while making Idfy Axios API request:", error);
49
+ throw error;
50
+ }
51
+ });
52
+ }
53
+ getTask(requestId) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ try {
56
+ const urlEndPoint = this.taskUrl + requestId;
57
+ const response = yield this.makeRequest("get", urlEndPoint);
58
+ return response;
59
+ }
60
+ catch (error) {
61
+ console.error("Error while fetching Idfy getTask API data:", error);
62
+ throw error;
63
+ }
64
+ });
65
+ }
66
+ pingTaskUntilSuccess(requestId) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ try {
69
+ let res = null;
70
+ const checkTaskAfter1sec = (requestId) => {
71
+ return new Promise((resolve, reject) => {
72
+ try {
73
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
74
+ const data = yield this.getTask(requestId);
75
+ if ((res === null || res === void 0 ? void 0 : res[0].status) == 'failed') {
76
+ reject(res);
77
+ }
78
+ resolve(data);
79
+ }), 1000);
80
+ }
81
+ catch (e) {
82
+ reject(e);
83
+ }
84
+ });
85
+ };
86
+ do {
87
+ res = yield checkTaskAfter1sec(requestId);
88
+ console.log("### res ", res);
89
+ } while ((res === null || res === void 0 ? void 0 : res[0].status) !== 'completed');
90
+ return res;
91
+ }
92
+ catch (error) {
93
+ console.error("Error while fetching Idfy getTask API data:", error);
94
+ throw error;
95
+ }
96
+ });
97
+ }
98
+ getCompanyGstInfo({ gstNo }) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ try {
101
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
102
+ gstin: gstNo,
103
+ } });
104
+ const response = yield this.makeRequest("post", this.gstVerificationEndPoint, data);
105
+ return response;
106
+ }
107
+ catch (error) {
108
+ console.error("Error while fetching Idfy API data:", error);
109
+ throw error;
110
+ }
111
+ });
112
+ }
113
+ getCompanyCINInfo({ cinNo }) {
114
+ var _a, _b;
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ try {
117
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
118
+ "cin": cinNo,
119
+ } });
120
+ const response = yield this.makeRequest("post", this.cinCompanyVerificationEndPoint, data);
121
+ const successData = yield this.pingTaskUntilSuccess(response.request_id);
122
+ return (_b = (_a = successData === null || successData === void 0 ? void 0 : successData[0]) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.source_output;
123
+ }
124
+ catch (error) {
125
+ console.error("Error while fetching Idfy CIN API data:", error);
126
+ throw error;
127
+ }
128
+ });
129
+ }
130
+ getIndividualPANInfo({ panNo }) {
131
+ var _a, _b;
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ try {
134
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
135
+ "id_number": panNo,
136
+ } });
137
+ const response = yield this.makeRequest("post", this.panIndividualVerificationEndPoint, data);
138
+ const successData = yield this.pingTaskUntilSuccess(response.request_id);
139
+ return (_b = (_a = successData === null || successData === void 0 ? void 0 : successData[0]) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.source_output;
140
+ }
141
+ catch (error) {
142
+ console.error("Error while fetching Idfy PAN API data:", error);
143
+ throw error;
144
+ }
145
+ });
146
+ }
147
+ getSyncIndividualAadharScanInfo({ frontScanBase64, backScanBase64 }) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ try {
150
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
151
+ "document1": frontScanBase64,
152
+ "document2": backScanBase64,
153
+ "consent": "yes",
154
+ "advanced_details": {
155
+ "extract_qr_info": true,
156
+ "extract_last_4_digit": false
157
+ }
158
+ } });
159
+ const response = yield this.makeRequest("post", this.syncIndividualAadharScanInfoEndpoint, data);
160
+ return response === null || response === void 0 ? void 0 : response.result;
161
+ }
162
+ catch (error) {
163
+ console.error("Error while fetching Idfy PAN API data:", error);
164
+ throw error;
165
+ }
166
+ });
167
+ }
168
+ getSyncIndividualPANScanInfo({ frontScanBase64 }) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ try {
171
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
172
+ "document1": frontScanBase64,
173
+ "consent": "yes",
174
+ } });
175
+ const response = yield this.makeRequest("post", this.syncIndividualPANScanInfoEndpoint, data);
176
+ return response === null || response === void 0 ? void 0 : response.result;
177
+ }
178
+ catch (error) {
179
+ console.error("Error while fetching Idfy PAN API data:", error);
180
+ throw error;
181
+ }
182
+ });
183
+ }
184
+ getSyncIndividualLivenessSelfyScanInfo({ faceScanBase64 }) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ try {
187
+ const data = Object.assign(Object.assign({}, (this.bodyTaskIdGroupId)), { data: {
188
+ "document1": faceScanBase64,
189
+ "consent": "yes",
190
+ } });
191
+ const response = yield this.makeRequest("post", this.syncIndividualLiveFaceLivenessEndpoint, data);
192
+ return response === null || response === void 0 ? void 0 : response.result;
193
+ }
194
+ catch (error) {
195
+ console.error("Error while fetching Idfy PAN API data:", error);
196
+ throw error;
197
+ }
198
+ });
199
+ }
200
+ }
201
+ exports.default = IdfyAPIWrapper;
202
+ //# sourceMappingURL=idfy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idfy.js","sourceRoot":"","sources":["../../src/Finance/idfy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAAiE;AAGjE,MAAqB,cAAc;IAsB/B;QApBQ,sBAAiB,GAAG;YACxB,OAAO,EAAE,sCAAsC;YAC/C,QAAQ,EAAE,sCAAsC;SACnD,CAAA;QACO,yBAAoB,GAAG;YAC3B,YAAY,EAAE,mDAAmD;YACjE,SAAS,EAAE,sCAAsC;SACpD,CAAA;QACO,YAAO,GAAW,uBAAuB,CAAC;QAC1C,4BAAuB,GAAG,sDAAsD,CAAA;QAChF,sCAAiC,GAAG,2CAA2C,CAAA;QAC/E,mCAA8B,GAAG,2CAA2C,CAAA;QAC5E,YAAO,GAAG,sBAAsB,CAAA;QAChC,yCAAoC,GAAG,wCAAwC,CAAA;QAC/E,sCAAiC,GAAG,+BAA+B,CAAA;QACnE,2CAAsC,GAAG,yCAAyC,CAAA;IAK1E,CAAC;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AM,IAAI,CAAC,WAAW,CAAM,MAAM,EAAE,IAAI,CAAC,sCAAsC,EAAE,IAAI,CAAC,CAAC;gBAExG,OAAO,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC;aAC3B;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;gBAChE,MAAM,KAAK,CAAC;aACf;QACL,CAAC;KAAA;CAIJ;AAzMD,iCAyMC"}
@@ -0,0 +1,4 @@
1
+ import IdfyAPIWrapper from './idfy';
2
+ export declare const finance: {
3
+ idFy: typeof IdfyAPIWrapper;
4
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.finance = void 0;
7
+ const idfy_1 = __importDefault(require("./idfy"));
8
+ exports.finance = {
9
+ idFy: idfy_1.default
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Finance/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmC;AAEtB,QAAA,OAAO,GAAG;IACvB,IAAI,EAAG,cAAc;CACpB,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Maps/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,97 @@
1
+ interface WhatsAppMessageData {
2
+ from: string;
3
+ to: string;
4
+ body?: string;
5
+ content?: WhatsappContentType;
6
+ }
7
+ interface Templatetype {
8
+ name: string;
9
+ language: {
10
+ policy: string;
11
+ code: string;
12
+ };
13
+ components: Array<{
14
+ type: string;
15
+ parameters: Array<{
16
+ type: string;
17
+ text: string;
18
+ }>;
19
+ }>;
20
+ }
21
+ interface WhatsappContentType {
22
+ type: string;
23
+ text?: {
24
+ preview_url: string;
25
+ body: string;
26
+ };
27
+ document?: any;
28
+ image?: any;
29
+ video?: any;
30
+ recipient_type: any;
31
+ template?: Templatetype;
32
+ }
33
+ export interface DemoBody {
34
+ whatsapp: {
35
+ messages: Array<WhatsAppMessageData>;
36
+ };
37
+ }
38
+ interface WhatsAppTemplateMessage {
39
+ from: string;
40
+ to: string;
41
+ content: {
42
+ type: string;
43
+ template: {
44
+ name: string;
45
+ language: {
46
+ policy?: string;
47
+ code: string;
48
+ };
49
+ components: Array<{
50
+ type: string;
51
+ parameters: Array<{
52
+ type: string;
53
+ text: string;
54
+ }>;
55
+ }>;
56
+ };
57
+ };
58
+ }
59
+ export interface WhatsAppTemplateDemoBody {
60
+ whatsapp: {
61
+ messages: Array<WhatsAppTemplateMessage>;
62
+ };
63
+ }
64
+ export interface EmiReminderAug2023 {
65
+ code: number;
66
+ error_data: null;
67
+ status: string;
68
+ data: {
69
+ waba_id: string;
70
+ name: string;
71
+ components: Array<HeaderComponent | BodyComponent>;
72
+ };
73
+ }
74
+ interface HeaderComponent {
75
+ type: string;
76
+ format: string;
77
+ text: string;
78
+ example: {
79
+ header_text: Array<string>;
80
+ };
81
+ }
82
+ interface BodyComponent {
83
+ type: string;
84
+ text: string;
85
+ example: {
86
+ body_text: Array<Array<string>>;
87
+ };
88
+ }
89
+ export interface SmsDemoBody {
90
+ To: string;
91
+ Body: string;
92
+ }
93
+ export declare enum Provider {
94
+ EXOTEL = "EXOTEL",
95
+ GUPSHUP = "GUPSHUP"
96
+ }
97
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = void 0;
4
+ var Provider;
5
+ (function (Provider) {
6
+ Provider["EXOTEL"] = "EXOTEL";
7
+ Provider["GUPSHUP"] = "GUPSHUP";
8
+ })(Provider || (exports.Provider = Provider = {}));
9
+ //# sourceMappingURL=Whatsapp.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Whatsapp.types.js","sourceRoot":"","sources":["../../src/Socials/Whatsapp.types.ts"],"names":[],"mappings":";;;AA+FE,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;AACrB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB"}
@@ -0,0 +1,4 @@
1
+ import Socials from './message';
2
+ export declare const socials: {
3
+ message: typeof Socials;
4
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.socials = void 0;
7
+ const message_1 = __importDefault(require("./message"));
8
+ exports.socials = {
9
+ message: message_1.default,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Socials/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAElB,QAAA,OAAO,GAAG;IACvB,OAAO,EAAG,iBAAO;CAEhB,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { DemoBody, EmiReminderAug2023, SmsDemoBody, WhatsAppTemplateDemoBody } from "./Whatsapp.types";
2
+ declare class MessageSender {
3
+ private exotelSid;
4
+ private exotelToken;
5
+ private exotelApiKey;
6
+ private whatsappApiUrl;
7
+ private smsUrl;
8
+ private provider;
9
+ constructor(payload: {
10
+ exotelSid: string;
11
+ exotelToken: string;
12
+ exotelApiKey: string;
13
+ provider: string;
14
+ });
15
+ getTemplates(): Promise<any>;
16
+ getUniquePlaceholderCount(str: string): number;
17
+ validateTemplatePayload(template: EmiReminderAug2023, payload: any): true | undefined;
18
+ testType(obj: DemoBody): boolean;
19
+ private sendMessage;
20
+ private sendTemplateMessage;
21
+ private sendOtpMessage;
22
+ sendOtpSms(obj: SmsDemoBody): Promise<boolean>;
23
+ sendWhatsAppMessage(obj: DemoBody): Promise<boolean>;
24
+ sendWhatsappTemplateMessage(obj: WhatsAppTemplateDemoBody): Promise<boolean>;
25
+ }
26
+ export default MessageSender;
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const axios_1 = __importDefault(require("axios"));
16
+ const Whatsapp_types_1 = require("./Whatsapp.types");
17
+ class MessageSender {
18
+ constructor(payload) {
19
+ const { exotelSid, exotelToken, exotelApiKey, provider } = payload;
20
+ this.exotelSid = exotelSid;
21
+ this.exotelToken = exotelToken;
22
+ this.exotelApiKey = exotelApiKey;
23
+ this.provider = provider;
24
+ if (this.provider === Whatsapp_types_1.Provider.EXOTEL) {
25
+ this.whatsappApiUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v2/accounts/${exotelSid}/messages`;
26
+ this.smsUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v1/Accounts/${exotelSid}/Sms/send`;
27
+ }
28
+ else if (this.provider === Whatsapp_types_1.Provider.GUPSHUP) {
29
+ }
30
+ }
31
+ getTemplates() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const request = yield axios_1.default.get(`https://${this.exotelApiKey}:${this.exotelToken}@api.exotel.com/v2/accounts/${this.exotelSid}/templates?waba_id=114033855070320`);
34
+ return request.data.response.whatsapp.templates;
35
+ });
36
+ }
37
+ getUniquePlaceholderCount(str) {
38
+ const arr = [];
39
+ str.split("{{").map((s) => arr.push(...s.split("}}")));
40
+ const placeholders = arr.filter((i) => i.match(/[0-9]+/) && !isNaN(Number(i)));
41
+ return [...new Set(placeholders)].length;
42
+ }
43
+ validateTemplatePayload(template, payload) {
44
+ const templateComponents = template.data.components;
45
+ if (templateComponents.length != 2) {
46
+ return;
47
+ }
48
+ const [headerTemplate, bodyTemplate] = templateComponents;
49
+ for (let index = 0; index < payload.whatsapp.messages.length; index++) {
50
+ const message = payload.whatsapp.messages[index];
51
+ const payloadComponents = message.content.template.components;
52
+ for (let index2 = 0; index2 < payloadComponents.length; index2++) {
53
+ const payloadComponent = payloadComponents[index2];
54
+ if (payloadComponent.type === headerTemplate.type.toLowerCase()) {
55
+ const headerPlaceholdersCount = this.getUniquePlaceholderCount(headerTemplate.text);
56
+ if (payloadComponent.parameters.length != headerPlaceholdersCount) {
57
+ console.log("invalid header");
58
+ throw new Error("header count mismatch");
59
+ }
60
+ else {
61
+ }
62
+ }
63
+ else if (payloadComponent.type === bodyTemplate.type.toLowerCase()) {
64
+ const bodyPlaceholdersCount = this.getUniquePlaceholderCount(bodyTemplate.text);
65
+ if (payloadComponent.parameters.length != bodyPlaceholdersCount) {
66
+ console.log("invalid body");
67
+ throw new Error("body count mismatch");
68
+ }
69
+ else {
70
+ }
71
+ }
72
+ else
73
+ throw new Error("type mismatch or incorrect");
74
+ }
75
+ return true;
76
+ }
77
+ }
78
+ testType(obj) {
79
+ let returnValue = true;
80
+ obj.whatsapp.messages.every((message) => {
81
+ var _a, _b, _c, _d, _e;
82
+ returnValue =
83
+ Boolean(((_a = message === null || message === void 0 ? void 0 : message.content) === null || _a === void 0 ? void 0 : _a.type) === "text" && message.content.text) ||
84
+ Boolean(((_b = message === null || message === void 0 ? void 0 : message.content) === null || _b === void 0 ? void 0 : _b.type) === "document" && message.content.document) ||
85
+ Boolean(((_c = message === null || message === void 0 ? void 0 : message.content) === null || _c === void 0 ? void 0 : _c.type) === "image" && message.content.image) ||
86
+ Boolean(((_d = message === null || message === void 0 ? void 0 : message.content) === null || _d === void 0 ? void 0 : _d.type) === "video" && message.content.video) ||
87
+ Boolean(((_e = message === null || message === void 0 ? void 0 : message.content) === null || _e === void 0 ? void 0 : _e.type) === "template" && message.content.template);
88
+ return returnValue;
89
+ });
90
+ return returnValue;
91
+ }
92
+ sendMessage(messageData) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ try {
95
+ let config = {
96
+ method: "post",
97
+ maxBodyLength: Infinity,
98
+ url: this.whatsappApiUrl,
99
+ headers: {
100
+ "Content-Type": "application/json",
101
+ },
102
+ data: JSON.stringify(messageData),
103
+ };
104
+ const response = yield axios_1.default.request(config);
105
+ if (response.data.metadata && response.data.metadata.success != 0) {
106
+ console.log("WhatsApp message sent successfully:", response.data);
107
+ return true;
108
+ }
109
+ else {
110
+ console.error("Error sending WhatsApp message:", response.data);
111
+ return false;
112
+ }
113
+ }
114
+ catch (error) {
115
+ console.error("Error sending WhatsApp message:", error);
116
+ return false;
117
+ }
118
+ });
119
+ }
120
+ sendTemplateMessage(messageData) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ try {
123
+ const config = {
124
+ method: "post",
125
+ maxBodyLength: Infinity,
126
+ url: this.whatsappApiUrl,
127
+ headers: {
128
+ "Content-Type": "application/json",
129
+ },
130
+ data: JSON.stringify(messageData),
131
+ };
132
+ const response = yield axios_1.default.request(config);
133
+ if (response.data.metadata && response.data.metadata.success !== 0) {
134
+ console.log("WhatsApp template message sent successfully:", response.data);
135
+ return true;
136
+ }
137
+ else {
138
+ console.error("Error sending WhatsApp template message:", response.data);
139
+ return false;
140
+ }
141
+ }
142
+ catch (error) {
143
+ console.error("Error sending WhatsApp template message:", error);
144
+ return false;
145
+ }
146
+ });
147
+ }
148
+ sendOtpMessage(messageData) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ if (messageData.To && messageData.Body) {
151
+ if (messageData.Body.length != 6) {
152
+ throw new Error("Please enter 6 digit number");
153
+ }
154
+ }
155
+ else
156
+ throw new Error("All input data not found");
157
+ const bodyFormData = new FormData();
158
+ const smsTemplateMsg = "Your OTP for AEREMS login is %d. This %d will expire in 10 minutes.";
159
+ bodyFormData.append("To", messageData.To);
160
+ bodyFormData.append("From", "AEREM");
161
+ bodyFormData.append("Body", smsTemplateMsg.replace(/%d/g, messageData.Body));
162
+ bodyFormData.append("EncodingType", "plain");
163
+ bodyFormData.append("DltEntityId", "1301164059765333889");
164
+ bodyFormData.append("DltTemplateId", "1307164663997173809");
165
+ bodyFormData.append("SmsType", "transactional");
166
+ try {
167
+ let config = {
168
+ method: "post",
169
+ maxBodyLength: Infinity,
170
+ url: this.smsUrl,
171
+ headers: {
172
+ "Content-Type": "multipart/form-data",
173
+ },
174
+ data: bodyFormData,
175
+ };
176
+ yield axios_1.default.request(config);
177
+ return true;
178
+ }
179
+ catch (error) {
180
+ console.error("Error sending sms:", error);
181
+ return false;
182
+ }
183
+ });
184
+ }
185
+ sendOtpSms(obj) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ return this.sendOtpMessage(obj);
188
+ });
189
+ }
190
+ sendWhatsAppMessage(obj) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ if (this.testType(obj))
193
+ return this.sendMessage(obj);
194
+ else
195
+ return false;
196
+ });
197
+ }
198
+ sendWhatsappTemplateMessage(obj) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ let templatevalue = yield this.getTemplates();
201
+ let tempVariable = obj.whatsapp.messages[0].content.template.name;
202
+ let template = templatevalue.find((e) => e.data.name == tempVariable);
203
+ if (this.validateTemplatePayload(template, obj)) {
204
+ return this.sendTemplateMessage(obj);
205
+ }
206
+ else
207
+ return false;
208
+ });
209
+ }
210
+ }
211
+ exports.default = MessageSender;
212
+ //# sourceMappingURL=message.js.map
@@ -0,0 +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AAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAK,EAAC,EAAE,CAAA,CAAC,CAAC,IAAI,CAAC,IAAI,IAAE,YAAY,CAAC,CAAA;YACrE,IAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAC,GAAG,CAAC,EAAC;gBAC5C,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;aACrC;;gBACI,OAAO,KAAK,CAAC;QACpB,CAAC;KAAA;CACF;AACD,kBAAe,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const AeremMiddleware: {
2
+ finance: {
3
+ idFy: typeof import("./Finance/idfy").default;
4
+ };
5
+ socials: {
6
+ message: typeof import("./Socials/message").default;
7
+ };
8
+ };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AeremMiddleware = void 0;
4
+ const Finance_1 = require("./Finance");
5
+ const Socials_1 = require("./Socials");
6
+ exports.AeremMiddleware = {
7
+ finance: Finance_1.finance, socials: Socials_1.socials
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,uCAAoC;AAGtB,QAAA,eAAe,GAAG;IAC5B,OAAO,EAAP,iBAAO,EAAC,OAAO,EAAP,iBAAO;CAElB,CAAA"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "aeremmiddleware",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "type":"dist/index.d.ts",
6
+ "main": "dist/index.js",
6
7
  "scripts": {
7
- "build": "rm -rf build && tsc ",
8
+ "build": "tsc",
8
9
  "prod": "node ./build/src/index.js"
9
10
  },
10
11
  "keywords": [],
File without changes
@@ -89,6 +89,10 @@ interface Templatetype {
89
89
  body_text: Array<Array<string>>;
90
90
  };
91
91
  }
92
+ export interface SmsDemoBody{
93
+ To:string,
94
+ Body:string,
95
+ }
92
96
  export enum Provider {
93
97
  EXOTEL = "EXOTEL",
94
98
  GUPSHUP = "GUPSHUP",
@@ -1,5 +1,6 @@
1
1
  import Socials from './message'
2
2
 
3
3
  export const socials = {
4
- message : Socials
4
+ message : Socials,
5
+
5
6
  }
@@ -1,11 +1,12 @@
1
1
  import axios from "axios";
2
- import { DemoBody, EmiReminderAug2023, Provider, WhatsAppTemplateDemoBody } from "./Whatsapp.types";
2
+ import { DemoBody, EmiReminderAug2023,SmsDemoBody, Provider, WhatsAppTemplateDemoBody } from "./Whatsapp.types";
3
3
 
4
- class ExotelWhatsAppSender {
4
+ class MessageSender {
5
5
  private exotelSid: string;
6
6
  private exotelToken: string;
7
7
  private exotelApiKey: string;
8
8
  private whatsappApiUrl!: string;
9
+ private smsUrl!: string;
9
10
  private provider: string;
10
11
 
11
12
  constructor(payload: {
@@ -22,6 +23,7 @@ class ExotelWhatsAppSender {
22
23
 
23
24
  if (this.provider === Provider.EXOTEL) {
24
25
  this.whatsappApiUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v2/accounts/${exotelSid}/messages`;
26
+ this.smsUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v1/Accounts/${exotelSid}/Sms/send`;
25
27
  } else if (this.provider === Provider.GUPSHUP) {
26
28
  // Define the URL for Gupshup API
27
29
  // this.gupshupApiUrl = ...;
@@ -91,7 +93,7 @@ class ExotelWhatsAppSender {
91
93
  }
92
94
  testType(obj: DemoBody) {
93
95
  let returnValue = true;
94
- obj.whatsapp.messages.every((message, index) => {
96
+ obj.whatsapp.messages.every((message) => {
95
97
  returnValue =
96
98
  Boolean(message?.content?.type === "text" && message.content.text) ||
97
99
  Boolean(
@@ -168,6 +170,52 @@ class ExotelWhatsAppSender {
168
170
  }
169
171
  }
170
172
 
173
+ private async sendOtpMessage(messageData: SmsDemoBody): Promise<boolean> {
174
+
175
+ if(messageData.To && messageData.Body ){
176
+ if(messageData.Body.length != 6){
177
+ throw new Error("Please enter 6 digit number")
178
+ }
179
+ } else throw new Error("All input data not found")
180
+
181
+ const bodyFormData=new FormData();
182
+
183
+ const smsTemplateMsg="Your OTP for AEREMS login is %d. This %d will expire in 10 minutes."
184
+
185
+ bodyFormData.append("To",messageData.To)
186
+ bodyFormData.append("From","AEREM")
187
+ bodyFormData.append("Body",smsTemplateMsg.replace(/%d/g,messageData.Body))
188
+ bodyFormData.append("EncodingType","plain")
189
+ bodyFormData.append("DltEntityId","1301164059765333889")
190
+ bodyFormData.append("DltTemplateId","1307164663997173809")
191
+ bodyFormData.append("SmsType","transactional")
192
+
193
+ try {
194
+ let config = {
195
+ method: "post",
196
+ maxBodyLength: Infinity,
197
+ url: this.smsUrl,
198
+ headers: {
199
+ "Content-Type": "multipart/form-data",
200
+ },
201
+
202
+ data: bodyFormData,
203
+ };
204
+
205
+ await axios.request(config);
206
+ return true;
207
+
208
+ } catch (error) {
209
+ console.error("Error sending sms:", error);
210
+ return false;
211
+ }
212
+ }
213
+
214
+ async sendOtpSms(obj: SmsDemoBody): Promise<boolean> {
215
+ return this.sendOtpMessage(obj);
216
+
217
+ }
218
+
171
219
  async sendWhatsAppMessage(obj: DemoBody): Promise<boolean> {
172
220
  if (this.testType(obj)) return this.sendMessage(obj);
173
221
  else return false;
@@ -185,4 +233,4 @@ class ExotelWhatsAppSender {
185
233
  else return false;
186
234
  }
187
235
  }
188
- export default ExotelWhatsAppSender;
236
+ export default MessageSender;
package/tsconfig.json CHANGED
@@ -1,13 +1,111 @@
1
1
  {
2
2
  "compilerOptions": {
3
-
4
- "target": "ES2017",
5
- "module": "commonjs",
6
- "esModuleInterop": true,
7
- "forceConsistentCasingInFileNames": true,
8
- "strict": true,
9
- "skipLibCheck": true,
10
- "rootDir": "./",
11
- "outDir": "build"
12
- }
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "commonjs", /* Specify what module code is generated. */
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
+ // "resolveJsonModule": true, /* Enable importing .json files. */
43
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
46
+ /* JavaScript Support */
47
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
51
+ /* Emit */
52
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
+ "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
59
+ "removeComments": true, /* Disable emitting comments. */
60
+ // "noEmit": true, /* Disable emitting files from a compilation. */
61
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
+ "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
81
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83
+
84
+ /* Type Checking */
85
+ "strict": true, /* Enable all strict type-checking options. */
86
+ "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
+ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
+ "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90
+ "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91
+ "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104
+
105
+ /* Completeness */
106
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
+ },
109
+ "exclude":["node_module"],
110
+ "include":["./src/**/*.tsx","./src/**/*.ts"]
13
111
  }
File without changes
File without changes
File without changes
File without changes