@vasrefil/api-toolkit 1.1.1 → 1.2.0
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.
|
@@ -7,12 +7,13 @@ declare class GoMailerUtil_ {
|
|
|
7
7
|
actionType: string;
|
|
8
8
|
user: UserI;
|
|
9
9
|
transaction: TransactionI;
|
|
10
|
-
}) => Promise<
|
|
10
|
+
}) => Promise<void>;
|
|
11
11
|
trigger_event: (payload: {
|
|
12
12
|
event_code: string;
|
|
13
13
|
contact_email: string;
|
|
14
14
|
context: any;
|
|
15
15
|
}) => Promise<any>;
|
|
16
|
+
send_transactional_email: (payload: any) => Promise<any>;
|
|
16
17
|
}
|
|
17
18
|
declare const GoMailerUtil: GoMailerUtil_;
|
|
18
19
|
export { GoMailerUtil };
|
|
@@ -24,13 +24,14 @@ class GoMailerUtil_ {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
catch (error) {
|
|
27
|
-
console.log('GoMailerUtil_send_event:error', error);
|
|
27
|
+
// console.log('GoMailerUtil_send_event:error', error);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
this.send_user_event = async (payload) => {
|
|
31
|
+
let body;
|
|
31
32
|
try {
|
|
32
33
|
const { actionType, user, transaction } = payload;
|
|
33
|
-
|
|
34
|
+
body = {
|
|
34
35
|
event_code: actionType,
|
|
35
36
|
contact_email: user.email,
|
|
36
37
|
context: {
|
|
@@ -43,11 +44,17 @@ class GoMailerUtil_ {
|
|
|
43
44
|
transaction_status: transaction?.status || ''
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
-
return resp;
|
|
47
|
+
await this.trigger_event(body);
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
|
-
|
|
50
|
+
log_util_1.LogUtil.app_log({
|
|
51
|
+
distinct_id: 'admin',
|
|
52
|
+
response: error,
|
|
53
|
+
request: { body },
|
|
54
|
+
function_name: "GoMailerUtil_send_event",
|
|
55
|
+
category: "SEND_EVENT",
|
|
56
|
+
subcategory: "GO_MAILER_SEND_EVENT",
|
|
57
|
+
});
|
|
51
58
|
}
|
|
52
59
|
};
|
|
53
60
|
this.trigger_event = async (payload) => {
|
|
@@ -55,20 +62,22 @@ class GoMailerUtil_ {
|
|
|
55
62
|
const headers = { Authorization: `Bearer ${env_1.default.GO_MAILER.API_KEY}` };
|
|
56
63
|
const url = 'https://automata.go-mailer.com/api/v1/events/trigger';
|
|
57
64
|
const { data } = await axios_1.default.post(url, payload, { headers });
|
|
58
|
-
console.log('GoMailerUtil_trigger_event:success', data);
|
|
59
65
|
return data;
|
|
60
66
|
}
|
|
61
67
|
catch (error) {
|
|
62
68
|
const err = helpers_1.RequestHelper.get_error(error);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
this.send_transactional_email = async (payload) => {
|
|
73
|
+
try {
|
|
74
|
+
const headers = { Authorization: `Bearer ${env_1.default.GO_MAILER.API_KEY}` };
|
|
75
|
+
const url = 'https://mailing.go-mailer.com/api/v1/transactionals/dispatch';
|
|
76
|
+
const { data } = await axios_1.default.post(url, payload, { headers });
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const err = helpers_1.RequestHelper.get_error(error);
|
|
72
81
|
throw err;
|
|
73
82
|
}
|
|
74
83
|
};
|