backend-manager 5.0.95 → 5.0.97
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 +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-completed.js +4 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/send-email.js +10 -0
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/cancellation-requested.js +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/new-subscription.js +3 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-failed.js +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-recovered.js +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/plan-changed.js +1 -1
- package/src/manager/events/firestore/payments-webhooks/transitions/subscription/subscription-cancelled.js +1 -1
- package/src/manager/libraries/email.js +11 -16
package/package.json
CHANGED
package/src/manager/events/firestore/payments-webhooks/transitions/one-time/purchase-completed.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
const { sendOrderEmail, formatDate } = require('../send-email.js');
|
|
6
6
|
|
|
7
7
|
module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
|
|
8
|
+
const brandName = assistant.Manager.config.brand?.name || '';
|
|
9
|
+
const productName = after.product?.name || '';
|
|
10
|
+
|
|
8
11
|
assistant.log(`Transition [one-time/purchase-completed]: uid=${uid}, resourceId=${after.payment?.resourceId}`);
|
|
9
12
|
|
|
10
13
|
sendOrderEmail({
|
|
11
14
|
template: 'main/order/confirmation',
|
|
12
|
-
subject:
|
|
15
|
+
subject: `Your ${brandName} ${productName} order #${order?.id || ''}`,
|
|
13
16
|
categories: ['order/confirmation'],
|
|
14
17
|
userDoc,
|
|
15
18
|
assistant,
|
|
@@ -27,12 +27,22 @@ function sendOrderEmail({ template, subject, categories, data, userDoc, assistan
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// Strip sensitive fields before passing to email template
|
|
31
|
+
const safeUser = { ...userDoc };
|
|
32
|
+
delete safeUser.api;
|
|
33
|
+
delete safeUser.oauth2;
|
|
34
|
+
delete safeUser.activity;
|
|
35
|
+
delete safeUser.affiliate;
|
|
36
|
+
delete safeUser.attribution;
|
|
37
|
+
delete safeUser.flags;
|
|
38
|
+
|
|
30
39
|
const settings = {
|
|
31
40
|
to: { email: userEmail, ...(userName && { name: userName }) },
|
|
32
41
|
subject,
|
|
33
42
|
template,
|
|
34
43
|
categories,
|
|
35
44
|
copy: true,
|
|
45
|
+
user: safeUser,
|
|
36
46
|
data,
|
|
37
47
|
};
|
|
38
48
|
|
|
@@ -9,7 +9,7 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
|
|
|
9
9
|
|
|
10
10
|
sendOrderEmail({
|
|
11
11
|
template: 'main/order/cancellation-requested',
|
|
12
|
-
subject:
|
|
12
|
+
subject: `Your cancellation is confirmed #${order?.id || ''}`,
|
|
13
13
|
categories: ['order/cancellation-requested'],
|
|
14
14
|
userDoc,
|
|
15
15
|
assistant,
|
package/src/manager/events/firestore/payments-webhooks/transitions/subscription/new-subscription.js
CHANGED
|
@@ -7,12 +7,14 @@ const { sendOrderEmail, formatDate } = require('../send-email.js');
|
|
|
7
7
|
|
|
8
8
|
module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
|
|
9
9
|
const isTrial = after.trial?.claimed === true;
|
|
10
|
+
const brandName = assistant.Manager.config.brand?.name || '';
|
|
11
|
+
const planName = after.product?.name || '';
|
|
10
12
|
|
|
11
13
|
assistant.log(`Transition [subscription/new-subscription]: uid=${uid}, product=${after.product?.id}, frequency=${after.payment?.frequency}, trial=${isTrial}`);
|
|
12
14
|
|
|
13
15
|
sendOrderEmail({
|
|
14
16
|
template: 'main/order/confirmation',
|
|
15
|
-
subject:
|
|
17
|
+
subject: `Your ${brandName} ${planName} order #${order?.id || ''}`,
|
|
16
18
|
categories: ['order/confirmation'],
|
|
17
19
|
userDoc,
|
|
18
20
|
assistant,
|
package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-failed.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
|
|
|
9
9
|
|
|
10
10
|
sendOrderEmail({
|
|
11
11
|
template: 'main/order/payment-failed',
|
|
12
|
-
subject:
|
|
12
|
+
subject: `Payment failed for order #${order?.id || ''}`,
|
|
13
13
|
categories: ['order/payment-failed'],
|
|
14
14
|
userDoc,
|
|
15
15
|
assistant,
|
package/src/manager/events/firestore/payments-webhooks/transitions/subscription/payment-recovered.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
|
|
|
9
9
|
|
|
10
10
|
sendOrderEmail({
|
|
11
11
|
template: 'main/order/payment-recovered',
|
|
12
|
-
subject:
|
|
12
|
+
subject: `Payment received for order #${order?.id || ''}`,
|
|
13
13
|
categories: ['order/payment-recovered'],
|
|
14
14
|
userDoc,
|
|
15
15
|
assistant,
|
package/src/manager/events/firestore/payments-webhooks/transitions/subscription/plan-changed.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
|
|
|
10
10
|
|
|
11
11
|
sendOrderEmail({
|
|
12
12
|
template: 'main/order/plan-changed',
|
|
13
|
-
subject:
|
|
13
|
+
subject: `Your plan has been updated #${order?.id || ''}`,
|
|
14
14
|
categories: ['order/plan-changed'],
|
|
15
15
|
userDoc,
|
|
16
16
|
assistant,
|
|
@@ -12,7 +12,7 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
|
|
|
12
12
|
|
|
13
13
|
sendOrderEmail({
|
|
14
14
|
template: 'main/order/cancelled',
|
|
15
|
-
subject:
|
|
15
|
+
subject: `Your subscription has been cancelled #${order?.id || ''}`,
|
|
16
16
|
categories: ['order/cancelled'],
|
|
17
17
|
userDoc,
|
|
18
18
|
assistant,
|
|
@@ -91,15 +91,10 @@ Email.prototype.build = async function (settings) {
|
|
|
91
91
|
throw errorWithCode('Missing brand configuration in backend-manager-config.json', 400);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
name: brand.name,
|
|
97
|
-
url: brand.url,
|
|
98
|
-
email: brand.contact?.email,
|
|
99
|
-
images: sanitizeImagesForEmail(brand.images || {}),
|
|
100
|
-
};
|
|
94
|
+
const brandData = _.cloneDeep(brand);
|
|
95
|
+
brandData.images = sanitizeImagesForEmail(brandData.images || {});
|
|
101
96
|
|
|
102
|
-
if (!
|
|
97
|
+
if (!brandData.contact?.email) {
|
|
103
98
|
throw errorWithCode('Missing brand.contact.email in backend-manager-config.json', 400);
|
|
104
99
|
}
|
|
105
100
|
|
|
@@ -108,8 +103,8 @@ Email.prototype.build = async function (settings) {
|
|
|
108
103
|
// Add carbon copy recipients
|
|
109
104
|
if (copy) {
|
|
110
105
|
cc.push({
|
|
111
|
-
email:
|
|
112
|
-
name:
|
|
106
|
+
email: brandData.contact.email,
|
|
107
|
+
name: brandData.name,
|
|
113
108
|
});
|
|
114
109
|
bcc.push(
|
|
115
110
|
{
|
|
@@ -152,7 +147,7 @@ Email.prototype.build = async function (settings) {
|
|
|
152
147
|
// Build categories
|
|
153
148
|
const categories = _.uniq([
|
|
154
149
|
'transactional',
|
|
155
|
-
|
|
150
|
+
brandData.id,
|
|
156
151
|
...powertools.arrayify(settings.categories),
|
|
157
152
|
]);
|
|
158
153
|
|
|
@@ -160,7 +155,7 @@ Email.prototype.build = async function (settings) {
|
|
|
160
155
|
const sendAt = normalizeSendAt(settings.sendAt);
|
|
161
156
|
|
|
162
157
|
// Build unsubscribe URL
|
|
163
|
-
const unsubscribeUrl = `${Manager.project.websiteUrl}/portal/account/email-preferences?email=${encode(to[0].email)}&asmId=${encode(groupId)}&templateId=${encode(templateId)}&appName=${
|
|
158
|
+
const unsubscribeUrl = `${Manager.project.websiteUrl}/portal/account/email-preferences?email=${encode(to[0].email)}&asmId=${encode(groupId)}&templateId=${encode(templateId)}&appName=${brandData.name}&appUrl=${brandData.url}`;
|
|
164
159
|
|
|
165
160
|
// Build signoff
|
|
166
161
|
const signoff = settings?.data?.signoff || {};
|
|
@@ -194,7 +189,7 @@ Email.prototype.build = async function (settings) {
|
|
|
194
189
|
...settings?.data?.personalization,
|
|
195
190
|
},
|
|
196
191
|
signoff,
|
|
197
|
-
|
|
192
|
+
brand: brandData,
|
|
198
193
|
user: userProperties,
|
|
199
194
|
data: settings.data || {},
|
|
200
195
|
};
|
|
@@ -204,8 +199,8 @@ Email.prototype.build = async function (settings) {
|
|
|
204
199
|
to,
|
|
205
200
|
cc,
|
|
206
201
|
bcc,
|
|
207
|
-
from: settings.from || { email:
|
|
208
|
-
replyTo: settings.replyTo ||
|
|
202
|
+
from: settings.from || { email: brandData.contact.email, name: brandData.name },
|
|
203
|
+
replyTo: settings.replyTo || brandData.contact.email,
|
|
209
204
|
subject,
|
|
210
205
|
templateId,
|
|
211
206
|
asm: { groupId },
|
|
@@ -230,7 +225,7 @@ Email.prototype.build = async function (settings) {
|
|
|
230
225
|
|
|
231
226
|
// Build stringified version for template rendering
|
|
232
227
|
const clonedData = _.cloneDeep(dynamicTemplateData);
|
|
233
|
-
clonedData.
|
|
228
|
+
clonedData.brand.sponsorships = {};
|
|
234
229
|
email.dynamicTemplateData._stringified = JSON.stringify(clonedData, null, 2);
|
|
235
230
|
|
|
236
231
|
return email;
|