-
Notifications
You must be signed in to change notification settings - Fork 0
/
sns-listener.js
104 lines (79 loc) · 1.53 KB
/
sns-listener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const { struct } = require('@janiscommerce/superstruct');
class SNSListener {
constructor(event) {
this._event = event;
}
get notificationType() {
return this._event.notificationType;
}
/**
* Return the recipients of the email
*
* @type {Array}
*/
get destinationRecipients() {
const destination = [];
if(this._event.mail.destination)
return this._event.mail.destination;
return destination;
}
get rejectedRecipients() {
const rejectedRecipients = [];
if(this._event.bounce)
return this._event.bounce.bouncedRecipients;
if(this._event.complaint)
return this._event.complaint.complainedRecipients;
return rejectedRecipients;
}
/**
* The type
*
* @type {string|null}
*/
get type() {
if(this._event.bounce)
return this._event.bounce.bounceType;
if(this._event.complaint)
return this._event.complaint.complaintFeedbackType;
return null;
}
/**
* The subType
*
* @type {string|null}
*/
get subType() {
if(this._event.bounce)
return this._event.bounce.bounceSubType;
return null;
}
/**
* Return the full mail sent
*
* @type {object}
*/
get mail() {
return this._event.mail;
}
/**
* Return the messageId of the mail sended
*
* @type {string}
*/
get messageId() {
return this._event.mail.messageId;
}
get sendingAccountId() {
return this._event.mail.sendingAccountId;
}
/**
* Validate the event
*
* @memberof SNSListener
*/
validate() {
struct(this.struct, this.event);
}
}
module.exports = SNSListener;