aeremmiddleware 1.0.25 → 1.0.27

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.
Files changed (54) hide show
  1. package/README.md +28 -28
  2. package/dist/Finance/Ingenico.types.d.ts +1 -0
  3. package/dist/Finance/auFinance.d.ts +33 -2
  4. package/dist/Finance/auFinance.js +8 -3
  5. package/dist/Finance/auFinance.js.map +1 -1
  6. package/dist/Finance/index.d.ts +2 -0
  7. package/dist/Finance/index.js +2 -0
  8. package/dist/Finance/index.js.map +1 -1
  9. package/dist/Finance/ingenico.js +3 -6
  10. package/dist/Finance/ingenico.js.map +1 -1
  11. package/dist/Finance/ingenicoHtml.js +114 -114
  12. package/dist/Finance/ingenicoHtml.js.map +1 -1
  13. package/dist/Finance/novel.d.ts +2 -1
  14. package/dist/Finance/novel.js +8 -8
  15. package/dist/Finance/novel.js.map +1 -1
  16. package/dist/Finance/novel.types.js +1 -1
  17. package/dist/Finance/novel.types.js.map +1 -1
  18. package/dist/Finance/setu.d.ts +107 -0
  19. package/dist/Finance/setu.js +499 -0
  20. package/dist/Finance/setu.js.map +1 -0
  21. package/dist/Finance/setu.types.d.ts +39 -0
  22. package/dist/Finance/setu.types.js +3 -0
  23. package/dist/Finance/setu.types.js.map +1 -0
  24. package/dist/Socials/Sms.types.js +1 -1
  25. package/dist/Socials/Sms.types.js.map +1 -1
  26. package/dist/Socials/Whatsapp.types.js +1 -1
  27. package/dist/Socials/Whatsapp.types.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/package.json +21 -21
  30. package/src/Finance/Ingenico.types.ts +22 -21
  31. package/src/Finance/auEncrypt.ts +32 -32
  32. package/src/Finance/auFinance.ts +115 -75
  33. package/src/Finance/crimeCheck.ts +212 -212
  34. package/src/Finance/crimecheck.types.ts +31 -31
  35. package/src/Finance/encrypt.ts +18 -18
  36. package/src/Finance/idfy.ts +542 -542
  37. package/src/Finance/index.ts +16 -15
  38. package/src/Finance/ingenico.ts +104 -110
  39. package/src/Finance/ingenicoHtml.ts +119 -119
  40. package/src/Finance/novel.ts +233 -231
  41. package/src/Finance/novel.types.ts +30 -30
  42. package/src/Finance/qbrik.ts +828 -828
  43. package/src/Finance/qbrik.types.ts +131 -131
  44. package/src/Finance/setu.ts +560 -0
  45. package/src/Finance/setu.types.ts +44 -0
  46. package/src/PushNotification/index.ts +5 -5
  47. package/src/PushNotification/pushNotificationFCM.ts +37 -37
  48. package/src/Socials/Sms.types.ts +9 -9
  49. package/src/Socials/SmsSender.ts +78 -78
  50. package/src/Socials/Whatsapp.types.ts +95 -95
  51. package/src/Socials/index.ts +6 -6
  52. package/src/Socials/whatsApp.ts +188 -188
  53. package/src/index.ts +9 -9
  54. package/tsconfig.json +111 -111
@@ -1,188 +1,188 @@
1
- import axios from "axios";
2
- import { DemoBody, EmiReminderAug2023, Provider, WhatsAppTemplateDemoBody } from "./Whatsapp.types";
3
-
4
- class WhatsappMessageSender {
5
- private exotelSid: string;
6
- private exotelToken: string;
7
- private exotelApiKey: string;
8
- private whatsappApiUrl!: string;
9
- private provider: string;
10
-
11
- constructor(payload: {
12
- exotelSid: string;
13
- exotelToken: string;
14
- exotelApiKey: string;
15
- provider: string;
16
- }) {
17
- const { exotelSid, exotelToken, exotelApiKey, provider } = payload;
18
- this.exotelSid = exotelSid;
19
- this.exotelToken = exotelToken;
20
- this.exotelApiKey = exotelApiKey;
21
- this.provider = provider;
22
-
23
- if (this.provider === Provider.EXOTEL) {
24
- this.whatsappApiUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v2/accounts/${exotelSid}/messages`;
25
- } else if (this.provider === Provider.GUPSHUP) {
26
- // Define the URL for Gupshup API
27
- // this.gupshupApiUrl = ...;
28
- }
29
- }
30
-
31
- async getTemplates() {
32
- const request = await axios.get(
33
- `https://${this.exotelApiKey}:${this.exotelToken}@api.exotel.com/v2/accounts/${this.exotelSid}/templates?waba_id=114033855070320`
34
- );
35
-
36
- return request.data.response.whatsapp.templates;
37
- }
38
- getUniquePlaceholderCount(str: string) {
39
- const arr:Array<string> = [];
40
- str.split("{{").map((s) => arr.push(...s.split("}}")));
41
- const placeholders: Array<string> = arr.filter(
42
- (i) => i.match(/[0-9]+/) && !isNaN(Number(i))
43
- );
44
- return [...new Set(placeholders)].length;
45
- }
46
-
47
- validateTemplatePayload(template:EmiReminderAug2023, payload:any) {
48
- const templateComponents = template.data.components;
49
- if (templateComponents.length != 2) {
50
- return;
51
- }
52
-
53
- const [headerTemplate, bodyTemplate] = templateComponents;
54
- //this checks if placeholder is correct or not
55
- for (let index = 0; index < payload.whatsapp.messages.length; index++) {
56
- const message = payload.whatsapp.messages[index];
57
- const payloadComponents = message.content.template.components;
58
- for (let index2 = 0; index2 < payloadComponents.length; index2++) {
59
- const payloadComponent = payloadComponents[index2];
60
- // validate template header
61
- if (payloadComponent.type === headerTemplate.type.toLowerCase()) {
62
- const headerPlaceholdersCount = this.getUniquePlaceholderCount(
63
- headerTemplate.text
64
- );
65
- if (payloadComponent.parameters.length != headerPlaceholdersCount) {
66
- console.log("invalid header");
67
- throw new Error("header count mismatch");
68
- } else {
69
- // header validated
70
- // TODO: add more validations if required
71
- }
72
- } else if (payloadComponent.type === bodyTemplate.type.toLowerCase()) {
73
- const bodyPlaceholdersCount = this.getUniquePlaceholderCount(
74
- bodyTemplate.text
75
- );
76
- if (payloadComponent.parameters.length != bodyPlaceholdersCount) {
77
- console.log("invalid body");
78
- throw new Error("body count mismatch");
79
- } else {
80
- // validate template body
81
- // body validated
82
- // TODO: add more validations if required
83
- }
84
- }
85
- else
86
- throw new Error("type mismatch or incorrect")
87
-
88
- }
89
- return true;
90
- }
91
- }
92
- testType(obj: DemoBody) {
93
- let returnValue = true;
94
- obj.whatsapp.messages.every((message) => {
95
- returnValue =
96
- Boolean(message?.content?.type === "text" && message.content.text) ||
97
- Boolean(
98
- message?.content?.type === "document" && message.content.document
99
- ) ||
100
- Boolean(message?.content?.type === "image" && message.content.image) ||
101
- Boolean(message?.content?.type === "video" && message.content.video) ||
102
- Boolean(
103
- message?.content?.type === "template" && message.content.template
104
- );
105
- return returnValue;
106
- });
107
- return returnValue;
108
- }
109
-
110
- private async sendMessage(messageData: DemoBody): Promise<boolean> {
111
- try {
112
- let config = {
113
- method: "post",
114
- maxBodyLength: Infinity,
115
- url: this.whatsappApiUrl,
116
- headers: {
117
- "Content-Type": "application/json",
118
- },
119
-
120
- data: JSON.stringify(messageData),
121
- };
122
-
123
- const response = await axios.request(config);
124
- if (response.data.metadata && response.data.metadata.success != 0) {
125
- console.log("WhatsApp message sent successfully:", response.data);
126
- return true;
127
- } else {
128
- console.error("Error sending WhatsApp message:", response.data);
129
- return false;
130
- }
131
- } catch (error) {
132
- console.error("Error sending WhatsApp message:", error);
133
- return false;
134
- }
135
- }
136
-
137
- private async sendTemplateMessage(
138
- messageData: WhatsAppTemplateDemoBody
139
- ): Promise<boolean> {
140
- try {
141
- const config = {
142
- method: "post",
143
- maxBodyLength: Infinity,
144
- url: this.whatsappApiUrl,
145
- headers: {
146
- "Content-Type": "application/json",
147
- },
148
- data: JSON.stringify(messageData),
149
- };
150
-
151
- const response = await axios.request(config);
152
- if (response.data.metadata && response.data.metadata.success !== 0) {
153
- console.log(
154
- "WhatsApp template message sent successfully:",
155
- response.data
156
- );
157
- return true;
158
- } else {
159
- console.error(
160
- "Error sending WhatsApp template message:",
161
- response.data
162
- );
163
- return false;
164
- }
165
- } catch (error) {
166
- console.error("Error sending WhatsApp template message:", error);
167
- return false;
168
- }
169
- }
170
-
171
- async sendWhatsAppMessage(obj: DemoBody): Promise<boolean> {
172
- if (this.testType(obj)) return this.sendMessage(obj);
173
- else return false;
174
- }
175
-
176
- async sendWhatsappTemplateMessage(
177
- obj: WhatsAppTemplateDemoBody
178
- ): Promise<boolean> {
179
- let templatevalue=await this.getTemplates();
180
- let tempVariable=obj.whatsapp.messages[0].content.template.name;
181
- let template = templatevalue.find((e:any)=>e.data.name==tempVariable)
182
- if(this.validateTemplatePayload(template,obj)){
183
- return this.sendTemplateMessage(obj)
184
- }
185
- else return false;
186
- }
187
- }
188
- export default WhatsappMessageSender;
1
+ import axios from "axios";
2
+ import { DemoBody, EmiReminderAug2023, Provider, WhatsAppTemplateDemoBody } from "./Whatsapp.types";
3
+
4
+ class WhatsappMessageSender {
5
+ private exotelSid: string;
6
+ private exotelToken: string;
7
+ private exotelApiKey: string;
8
+ private whatsappApiUrl!: string;
9
+ private provider: string;
10
+
11
+ constructor(payload: {
12
+ exotelSid: string;
13
+ exotelToken: string;
14
+ exotelApiKey: string;
15
+ provider: string;
16
+ }) {
17
+ const { exotelSid, exotelToken, exotelApiKey, provider } = payload;
18
+ this.exotelSid = exotelSid;
19
+ this.exotelToken = exotelToken;
20
+ this.exotelApiKey = exotelApiKey;
21
+ this.provider = provider;
22
+
23
+ if (this.provider === Provider.EXOTEL) {
24
+ this.whatsappApiUrl = `https://${exotelApiKey}:${exotelToken}@api.exotel.com/v2/accounts/${exotelSid}/messages`;
25
+ } else if (this.provider === Provider.GUPSHUP) {
26
+ // Define the URL for Gupshup API
27
+ // this.gupshupApiUrl = ...;
28
+ }
29
+ }
30
+
31
+ async getTemplates() {
32
+ const request = await axios.get(
33
+ `https://${this.exotelApiKey}:${this.exotelToken}@api.exotel.com/v2/accounts/${this.exotelSid}/templates?waba_id=114033855070320`
34
+ );
35
+
36
+ return request.data.response.whatsapp.templates;
37
+ }
38
+ getUniquePlaceholderCount(str: string) {
39
+ const arr:Array<string> = [];
40
+ str.split("{{").map((s) => arr.push(...s.split("}}")));
41
+ const placeholders: Array<string> = arr.filter(
42
+ (i) => i.match(/[0-9]+/) && !isNaN(Number(i))
43
+ );
44
+ return [...new Set(placeholders)].length;
45
+ }
46
+
47
+ validateTemplatePayload(template:EmiReminderAug2023, payload:any) {
48
+ const templateComponents = template.data.components;
49
+ if (templateComponents.length != 2) {
50
+ return;
51
+ }
52
+
53
+ const [headerTemplate, bodyTemplate] = templateComponents;
54
+ //this checks if placeholder is correct or not
55
+ for (let index = 0; index < payload.whatsapp.messages.length; index++) {
56
+ const message = payload.whatsapp.messages[index];
57
+ const payloadComponents = message.content.template.components;
58
+ for (let index2 = 0; index2 < payloadComponents.length; index2++) {
59
+ const payloadComponent = payloadComponents[index2];
60
+ // validate template header
61
+ if (payloadComponent.type === headerTemplate.type.toLowerCase()) {
62
+ const headerPlaceholdersCount = this.getUniquePlaceholderCount(
63
+ headerTemplate.text
64
+ );
65
+ if (payloadComponent.parameters.length != headerPlaceholdersCount) {
66
+ console.log("invalid header");
67
+ throw new Error("header count mismatch");
68
+ } else {
69
+ // header validated
70
+ // TODO: add more validations if required
71
+ }
72
+ } else if (payloadComponent.type === bodyTemplate.type.toLowerCase()) {
73
+ const bodyPlaceholdersCount = this.getUniquePlaceholderCount(
74
+ bodyTemplate.text
75
+ );
76
+ if (payloadComponent.parameters.length != bodyPlaceholdersCount) {
77
+ console.log("invalid body");
78
+ throw new Error("body count mismatch");
79
+ } else {
80
+ // validate template body
81
+ // body validated
82
+ // TODO: add more validations if required
83
+ }
84
+ }
85
+ else
86
+ throw new Error("type mismatch or incorrect")
87
+
88
+ }
89
+ return true;
90
+ }
91
+ }
92
+ testType(obj: DemoBody) {
93
+ let returnValue = true;
94
+ obj.whatsapp.messages.every((message) => {
95
+ returnValue =
96
+ Boolean(message?.content?.type === "text" && message.content.text) ||
97
+ Boolean(
98
+ message?.content?.type === "document" && message.content.document
99
+ ) ||
100
+ Boolean(message?.content?.type === "image" && message.content.image) ||
101
+ Boolean(message?.content?.type === "video" && message.content.video) ||
102
+ Boolean(
103
+ message?.content?.type === "template" && message.content.template
104
+ );
105
+ return returnValue;
106
+ });
107
+ return returnValue;
108
+ }
109
+
110
+ private async sendMessage(messageData: DemoBody): Promise<boolean> {
111
+ try {
112
+ let config = {
113
+ method: "post",
114
+ maxBodyLength: Infinity,
115
+ url: this.whatsappApiUrl,
116
+ headers: {
117
+ "Content-Type": "application/json",
118
+ },
119
+
120
+ data: JSON.stringify(messageData),
121
+ };
122
+
123
+ const response = await axios.request(config);
124
+ if (response.data.metadata && response.data.metadata.success != 0) {
125
+ console.log("WhatsApp message sent successfully:", response.data);
126
+ return true;
127
+ } else {
128
+ console.error("Error sending WhatsApp message:", response.data);
129
+ return false;
130
+ }
131
+ } catch (error) {
132
+ console.error("Error sending WhatsApp message:", error);
133
+ return false;
134
+ }
135
+ }
136
+
137
+ private async sendTemplateMessage(
138
+ messageData: WhatsAppTemplateDemoBody
139
+ ): Promise<boolean> {
140
+ try {
141
+ const config = {
142
+ method: "post",
143
+ maxBodyLength: Infinity,
144
+ url: this.whatsappApiUrl,
145
+ headers: {
146
+ "Content-Type": "application/json",
147
+ },
148
+ data: JSON.stringify(messageData),
149
+ };
150
+
151
+ const response = await axios.request(config);
152
+ if (response.data.metadata && response.data.metadata.success !== 0) {
153
+ console.log(
154
+ "WhatsApp template message sent successfully:",
155
+ response.data
156
+ );
157
+ return true;
158
+ } else {
159
+ console.error(
160
+ "Error sending WhatsApp template message:",
161
+ response.data
162
+ );
163
+ return false;
164
+ }
165
+ } catch (error) {
166
+ console.error("Error sending WhatsApp template message:", error);
167
+ return false;
168
+ }
169
+ }
170
+
171
+ async sendWhatsAppMessage(obj: DemoBody): Promise<boolean> {
172
+ if (this.testType(obj)) return this.sendMessage(obj);
173
+ else return false;
174
+ }
175
+
176
+ async sendWhatsappTemplateMessage(
177
+ obj: WhatsAppTemplateDemoBody
178
+ ): Promise<boolean> {
179
+ let templatevalue=await this.getTemplates();
180
+ let tempVariable=obj.whatsapp.messages[0].content.template.name;
181
+ let template = templatevalue.find((e:any)=>e.data.name==tempVariable)
182
+ if(this.validateTemplatePayload(template,obj)){
183
+ return this.sendTemplateMessage(obj)
184
+ }
185
+ else return false;
186
+ }
187
+ }
188
+ export default WhatsappMessageSender;
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { finance } from "./Finance";
2
- import { socials } from "./Socials";
3
- import {pushNotification } from "./PushNotification";
4
-
5
-
6
- export const AeremMiddleware = {
7
- finance,socials, pushNotification
8
-
9
- }
1
+ import { finance } from "./Finance";
2
+ import { socials } from "./Socials";
3
+ import {pushNotification } from "./PushNotification";
4
+
5
+
6
+ export const AeremMiddleware = {
7
+ finance,socials, pushNotification
8
+
9
+ }