forked from Mailtrain-org/mailtrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaigns.js
102 lines (78 loc) · 1.82 KB
/
campaigns.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
'use strict';
const CampaignSource = {
MIN: 1,
TEMPLATE: 1,
CUSTOM: 2,
CUSTOM_FROM_TEMPLATE: 3,
CUSTOM_FROM_CAMPAIGN: 4,
URL: 5,
MAX: 5
};
const CampaignType = {
MIN: 1,
REGULAR: 1,
RSS: 2,
RSS_ENTRY: 3,
TRIGGERED: 4,
MAX: 4
};
const CampaignStatus = {
MIN: 1,
// For campaign types: NORMAL, RSS_ENTRY
IDLE: 1,
SCHEDULED: 2,
FINISHED: 3,
PAUSED: 4,
// For campaign types: RSS, TRIGGERED
INACTIVE: 5,
ACTIVE: 6,
// For campaign types: NORMAL, RSS_ENTRY
SENDING: 7,
PAUSING: 8,
MAX: 9
};
const CampaignMessageStatus = {
MIN: 0,
SENT: 1,
UNSUBSCRIBED: 2,
BOUNCED: 3,
COMPLAINED: 4,
SCHEDULED: 5,
FAILED: 6,
MAX: 6
};
const CampaignMessageErrorType = {
TRANSIENT: 0,
PERMANENT: 1
};
const campaignOverridables = ['from_name', 'from_email', 'reply_to'];
function getSendConfigurationPermissionRequiredForSend(campaign, sendConfiguration) {
let allowedOverride = false;
let disallowedOverride = false;
for (const overridable of campaignOverridables) {
if (campaign[overridable + '_override'] !== null) {
if (sendConfiguration[overridable + '_overridable']) {
allowedOverride = true;
} else {
disallowedOverride = true;
}
}
}
let requiredPermission = 'sendWithoutOverrides';
if (allowedOverride) {
requiredPermission = 'sendWithAllowedOverrides';
}
if (disallowedOverride) {
requiredPermission = 'sendWithAnyOverrides';
}
return requiredPermission;
}
module.exports = {
CampaignSource,
CampaignType,
CampaignStatus,
campaignOverridables,
CampaignMessageStatus,
CampaignMessageErrorType,
getSendConfigurationPermissionRequiredForSend
};