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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "5.0.95",
3
+ "version": "5.0.97",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -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: 'Your order is confirmed!',
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: 'Your subscription cancellation is confirmed',
12
+ subject: `Your cancellation is confirmed #${order?.id || ''}`,
13
13
  categories: ['order/cancellation-requested'],
14
14
  userDoc,
15
15
  assistant,
@@ -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: isTrial ? 'Your free trial has started!' : 'Your subscription is confirmed!',
17
+ subject: `Your ${brandName} ${planName} order #${order?.id || ''}`,
16
18
  categories: ['order/confirmation'],
17
19
  userDoc,
18
20
  assistant,
@@ -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: 'Your payment failed',
12
+ subject: `Payment failed for order #${order?.id || ''}`,
13
13
  categories: ['order/payment-failed'],
14
14
  userDoc,
15
15
  assistant,
@@ -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: 'Your payment was successful',
12
+ subject: `Payment received for order #${order?.id || ''}`,
13
13
  categories: ['order/payment-recovered'],
14
14
  userDoc,
15
15
  assistant,
@@ -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: 'Your subscription plan has been updated',
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: 'Your subscription has been cancelled',
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 app = {
95
- id: brand.id,
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 (!app.email) {
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: app.email,
112
- name: app.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
- app.id,
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=${app.name}&appUrl=${app.url}`;
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
- app,
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: app.email, name: app.name },
208
- replyTo: settings.replyTo || app.email,
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.app.sponsorships = {};
228
+ clonedData.brand.sponsorships = {};
234
229
  email.dynamicTemplateData._stringified = JSON.stringify(clonedData, null, 2);
235
230
 
236
231
  return email;