@vasrefil/api-toolkit 1.0.69 → 1.1.1
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.
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { ServiceRespI } from '../interfaces';
|
|
1
|
+
import { ServiceRespI, TransactionI, UserI } from '../interfaces';
|
|
2
2
|
declare class GoMailerUtil_ {
|
|
3
3
|
send_event: (dto: {
|
|
4
4
|
serviceResponse: ServiceRespI;
|
|
5
5
|
}) => Promise<void>;
|
|
6
|
+
send_user_event: (payload: {
|
|
7
|
+
actionType: string;
|
|
8
|
+
user: UserI;
|
|
9
|
+
transaction: TransactionI;
|
|
10
|
+
}) => Promise<any>;
|
|
11
|
+
trigger_event: (payload: {
|
|
12
|
+
event_code: string;
|
|
13
|
+
contact_email: string;
|
|
14
|
+
context: any;
|
|
15
|
+
}) => Promise<any>;
|
|
6
16
|
}
|
|
7
17
|
declare const GoMailerUtil: GoMailerUtil_;
|
|
8
18
|
export { GoMailerUtil };
|
|
@@ -13,11 +13,23 @@ class GoMailerUtil_ {
|
|
|
13
13
|
this.send_event = async (dto) => {
|
|
14
14
|
try {
|
|
15
15
|
const { req, actionType } = dto.serviceResponse;
|
|
16
|
-
const url = 'https://automata.go-mailer.com/api/v1/events/trigger';
|
|
17
16
|
const user = req.user;
|
|
18
17
|
const transaction = req.transaction;
|
|
19
18
|
if (!user?.email)
|
|
20
19
|
return;
|
|
20
|
+
await this.send_user_event({
|
|
21
|
+
actionType,
|
|
22
|
+
user,
|
|
23
|
+
transaction,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.log('GoMailerUtil_send_event:error', error);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.send_user_event = async (payload) => {
|
|
31
|
+
try {
|
|
32
|
+
const { actionType, user, transaction } = payload;
|
|
21
33
|
const body = {
|
|
22
34
|
event_code: actionType,
|
|
23
35
|
contact_email: user.email,
|
|
@@ -31,9 +43,20 @@ class GoMailerUtil_ {
|
|
|
31
43
|
transaction_status: transaction?.status || ''
|
|
32
44
|
}
|
|
33
45
|
};
|
|
46
|
+
const resp = await this.trigger_event(body);
|
|
47
|
+
return resp;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.trigger_event = async (payload) => {
|
|
54
|
+
try {
|
|
34
55
|
const headers = { Authorization: `Bearer ${env_1.default.GO_MAILER.API_KEY}` };
|
|
35
|
-
const
|
|
36
|
-
|
|
56
|
+
const url = 'https://automata.go-mailer.com/api/v1/events/trigger';
|
|
57
|
+
const { data } = await axios_1.default.post(url, payload, { headers });
|
|
58
|
+
console.log('GoMailerUtil_trigger_event:success', data);
|
|
59
|
+
return data;
|
|
37
60
|
}
|
|
38
61
|
catch (error) {
|
|
39
62
|
const err = helpers_1.RequestHelper.get_error(error);
|
|
@@ -45,7 +68,8 @@ class GoMailerUtil_ {
|
|
|
45
68
|
category: "SEND_EVENT",
|
|
46
69
|
subcategory: "GO_MAILER_SEND_EVENT",
|
|
47
70
|
});
|
|
48
|
-
console.log('
|
|
71
|
+
console.log('GoMailerUtil_trigger_event:error', error);
|
|
72
|
+
throw err;
|
|
49
73
|
}
|
|
50
74
|
};
|
|
51
75
|
}
|
package/dist/utilities/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vasrefil/api-toolkit",
|
|
3
3
|
"description": "This is Vasrefil API toolkit",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"author": "Sodiq Alabi",
|
|
6
6
|
"main": "dist/public-api.js",
|
|
7
7
|
"types": "dist/public-api.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@airbrake/node": "^2.1.8",
|
|
22
22
|
"@types/jsonwebtoken": "^8.5.0",
|
|
23
|
+
"@vasrefil/api-toolkit": "^1.0.69",
|
|
23
24
|
"axios": "^1.7.8",
|
|
24
25
|
"chalk": "^4.1.0",
|
|
25
26
|
"cors": "^2.8.5",
|