backend-manager 3.0.21 → 3.0.23
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.23",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"moment": "^2.29.4",
|
|
54
54
|
"nanoid": "^3.3.7",
|
|
55
55
|
"node-fetch": "^2.7.0",
|
|
56
|
-
"node-powertools": "^1.1.
|
|
56
|
+
"node-powertools": "^1.1.1",
|
|
57
57
|
"npm-api": "^1.0.1",
|
|
58
58
|
"paypal-server-api": "^1.0.3",
|
|
59
59
|
"pushid": "^1.0.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"ultimate-jekyll-poster": "^0.0.15",
|
|
66
66
|
"universal-analytics": "^0.5.3",
|
|
67
67
|
"uuid": "^9.0.1",
|
|
68
|
-
"wonderful-fetch": "^1.0.
|
|
68
|
+
"wonderful-fetch": "^1.0.1",
|
|
69
69
|
"wonderful-log": "^1.0.5",
|
|
70
70
|
"yargs": "^17.7.2"
|
|
71
71
|
}
|
|
@@ -1,57 +1,23 @@
|
|
|
1
1
|
module.exports = function (payload, config) {
|
|
2
|
-
const subject = `Free ${config.brand.name} download link for ${payload.name || 'you'}!`;
|
|
3
|
-
const templateId = 'd-1d730ac8cc544b7cbccc8fa4a4b3f9ce';
|
|
4
|
-
const groupId = 16223;
|
|
5
|
-
|
|
6
2
|
return {
|
|
7
3
|
// spamFilter: {
|
|
8
4
|
// ip: 3,
|
|
9
5
|
// email: 3,
|
|
10
6
|
// },
|
|
11
7
|
// delay: 1,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
name: payload.name,
|
|
18
|
-
email: payload.email,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
dynamic_template_data: {
|
|
22
|
-
subject: subject,
|
|
23
|
-
app: {
|
|
24
|
-
url: config.brand.url,
|
|
25
|
-
name: config.brand.name,
|
|
26
|
-
wordmark: config.brand.wordmark,
|
|
27
|
-
brandmark: config.brand.brandmark,
|
|
28
|
-
combomark: config.brand.combomark,
|
|
29
|
-
},
|
|
30
|
-
footer: {
|
|
31
|
-
name: 'ITW Creative Works',
|
|
32
|
-
address: '4001 Inglewood Ave 101-385',
|
|
33
|
-
city: 'Redondo Beach',
|
|
34
|
-
state: 'CA',
|
|
35
|
-
zip: '90278',
|
|
36
|
-
'unsubscribe-link': `https://itwcreativeworks.com/email-preferences/?email=${encodeURIComponent(payload.email)}&asmId=${encodeURIComponent(groupId)}&templateId=${encodeURIComponent(templateId)}&appName=${encodeURIComponent(config.brand.name)}`,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
from: {
|
|
42
|
-
name: config.brand.name,
|
|
43
|
-
email: config.brand.email,
|
|
44
|
-
},
|
|
45
|
-
reply_to: {
|
|
46
|
-
name: config.brand.name,
|
|
47
|
-
email: config.brand.email,
|
|
8
|
+
payload: {
|
|
9
|
+
to: {
|
|
10
|
+
email: payload.email,
|
|
11
|
+
name: payload.name,
|
|
48
12
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
13
|
+
categories: ['download'],
|
|
14
|
+
subject: `Free ${config.brand.name} download link for ${payload.name || 'you'}!`,
|
|
15
|
+
template: 'd-1d730ac8cc544b7cbccc8fa4a4b3f9ce',
|
|
16
|
+
group: 24077,
|
|
17
|
+
options: {
|
|
18
|
+
copy: false,
|
|
53
19
|
},
|
|
54
|
-
|
|
20
|
+
data: {},
|
|
55
21
|
}
|
|
56
22
|
}
|
|
57
23
|
}
|
|
@@ -19,12 +19,16 @@ Module.prototype.main = function () {
|
|
|
19
19
|
payload.data.payload.name = payload.data.payload.name;
|
|
20
20
|
|
|
21
21
|
const DEFAULT = {
|
|
22
|
+
|
|
22
23
|
spamFilter: {
|
|
23
24
|
ip: 3,
|
|
24
25
|
email: 3,
|
|
25
26
|
},
|
|
26
27
|
delay: 1,
|
|
27
|
-
|
|
28
|
+
payload: {
|
|
29
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
30
|
+
app: Manager.config.app.id,
|
|
31
|
+
},
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
if (!payload.data.payload.id) {
|
|
@@ -35,7 +39,12 @@ Module.prototype.main = function () {
|
|
|
35
39
|
|
|
36
40
|
let emailPayload
|
|
37
41
|
try {
|
|
38
|
-
|
|
42
|
+
const script = require(path.join(__dirname, 'emails', `${payload.data.payload.id}.js`))
|
|
43
|
+
emailPayload = merge(
|
|
44
|
+
{},
|
|
45
|
+
DEFAULT,
|
|
46
|
+
script(payload.data.payload, Manager.config),
|
|
47
|
+
);
|
|
39
48
|
} catch (e) {
|
|
40
49
|
return reject(assistant.errorManager(`${payload.data.payload.id} is not a valid email ID.`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
41
50
|
}
|
|
@@ -65,26 +74,22 @@ Module.prototype.main = function () {
|
|
|
65
74
|
return resolve({data: {success: true}});
|
|
66
75
|
}
|
|
67
76
|
|
|
77
|
+
// Log the email payload
|
|
68
78
|
assistant.log('Email payload:', emailPayload, {environment: 'production'});
|
|
69
79
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
service: 'sendgrid',
|
|
73
|
-
command: `v3/mail/send`,
|
|
74
|
-
method: 'post',
|
|
75
|
-
delay: emailPayload.delay,
|
|
76
|
-
body: emailPayload.body,
|
|
80
|
+
if (emailPayload.delay) {
|
|
81
|
+
emailPayload.body.sendAt = new Date(new Date().getTime() + (emailPayload.delay * 1000)).toISOString();
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
// Send the email
|
|
85
|
+
await fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
|
|
80
86
|
method: 'post',
|
|
81
|
-
timeout: 30000,
|
|
82
|
-
tries: 1,
|
|
83
87
|
response: 'json',
|
|
84
|
-
|
|
88
|
+
log: true,
|
|
89
|
+
body: emailPayload.body,
|
|
85
90
|
})
|
|
86
|
-
.then(
|
|
87
|
-
assistant.log('Response:',
|
|
91
|
+
.then(async (json) => {
|
|
92
|
+
assistant.log('Response:', json, {environment: 'production'});
|
|
88
93
|
|
|
89
94
|
return resolve({
|
|
90
95
|
data: {
|
|
@@ -94,7 +99,8 @@ Module.prototype.main = function () {
|
|
|
94
99
|
})
|
|
95
100
|
.catch(e => {
|
|
96
101
|
return reject(assistant.errorManager(`Error sending email: ${e}`, {code: 500, sentry: true, send: false, log: false}).error)
|
|
97
|
-
})
|
|
102
|
+
});
|
|
103
|
+
|
|
98
104
|
});
|
|
99
105
|
|
|
100
106
|
};
|
|
@@ -44,7 +44,7 @@ let Module = {
|
|
|
44
44
|
// label: '',
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
assistant.log('Creating campagin with data', assistant.request.data)
|
|
47
|
+
assistant.log('Creating campagin with data', assistant.request.data)
|
|
48
48
|
|
|
49
49
|
if (!user.roles.admin) {
|
|
50
50
|
response.status = 401;
|
|
@@ -102,7 +102,7 @@ let Module = {
|
|
|
102
102
|
})
|
|
103
103
|
.then(async (campaign) => {
|
|
104
104
|
assistant.log('Created campaign', campaign);
|
|
105
|
-
await fetch(`https://email.itwcreativeworks.com/general/mailchimp-blog-syndication
|
|
105
|
+
await fetch(`https://email.itwcreativeworks.com/general/mailchimp-blog-syndication?cb=${Math.random()}`)
|
|
106
106
|
.then(async (fetchResponse) => {
|
|
107
107
|
if (fetchResponse.status >= 200 && fetchResponse.status < 300) {
|
|
108
108
|
let html = await fetchResponse.text();
|