backend-manager 5.0.93 → 5.0.95

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.93",
3
+ "version": "5.0.95",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -5,13 +5,12 @@
5
5
  const { sendOrderEmail, formatDate } = require('../send-email.js');
6
6
 
7
7
  module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
8
- assistant.log(`Transition [one-time/purchase-completed]: uid=${uid}, resourceId=${after.payment.resourceId}`);
8
+ assistant.log(`Transition [one-time/purchase-completed]: uid=${uid}, resourceId=${after.payment?.resourceId}`);
9
9
 
10
10
  sendOrderEmail({
11
11
  template: 'main/order/confirmation',
12
12
  subject: 'Your order is confirmed!',
13
13
  categories: ['order/confirmation'],
14
- uid,
15
14
  userDoc,
16
15
  assistant,
17
16
  data: {
@@ -12,16 +12,15 @@ const moment = require('moment');
12
12
  * @param {string} options.subject - Email subject line
13
13
  * @param {string[]} options.categories - SendGrid categories for filtering
14
14
  * @param {object} options.data - Template data (passed as-is to the email)
15
- * @param {string} options.uid - User UID
16
- * @param {object} options.userDoc - User document data (used to get email directly, avoids race conditions)
15
+ * @param {object} options.userDoc - User document data (already fetched by on-write.js)
17
16
  * @param {object} options.assistant - Assistant instance
18
17
  */
19
- function sendOrderEmail({ template, subject, categories, data, uid, userDoc, assistant }) {
18
+ function sendOrderEmail({ template, subject, categories, data, userDoc, assistant }) {
20
19
  const email = assistant.Manager.Email(assistant);
21
20
 
22
- // Use email directly from userDoc (already fetched by on-write.js, avoids redundant Firestore lookup)
23
21
  const userEmail = userDoc?.auth?.email;
24
22
  const userName = userDoc?.personal?.name?.first;
23
+ const uid = userDoc?.auth?.uid;
25
24
 
26
25
  if (!userEmail) {
27
26
  assistant.error(`sendOrderEmail(): No email found for uid=${uid}, skipping`);
@@ -33,7 +32,7 @@ function sendOrderEmail({ template, subject, categories, data, uid, userDoc, ass
33
32
  subject,
34
33
  template,
35
34
  categories,
36
- copy: false,
35
+ copy: true,
37
36
  data,
38
37
  };
39
38
 
@@ -5,13 +5,12 @@
5
5
  const { sendOrderEmail, formatDate } = require('../send-email.js');
6
6
 
7
7
  module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
8
- assistant.log(`Transition [subscription/cancellation-requested]: uid=${uid}, product=${after.product.id}, cancelDate=${after.cancellation.date?.timestamp}`);
8
+ assistant.log(`Transition [subscription/cancellation-requested]: uid=${uid}, product=${after.product?.id}, cancelDate=${after.cancellation?.date?.timestamp}`);
9
9
 
10
10
  sendOrderEmail({
11
11
  template: 'main/order/cancellation-requested',
12
12
  subject: 'Your subscription cancellation is confirmed',
13
13
  categories: ['order/cancellation-requested'],
14
- uid,
15
14
  userDoc,
16
15
  assistant,
17
16
  data: {
@@ -8,13 +8,12 @@ const { sendOrderEmail, formatDate } = require('../send-email.js');
8
8
  module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
9
9
  const isTrial = after.trial?.claimed === true;
10
10
 
11
- assistant.log(`Transition [subscription/new-subscription]: uid=${uid}, product=${after.product.id}, frequency=${after.payment.frequency}, trial=${isTrial}`);
11
+ assistant.log(`Transition [subscription/new-subscription]: uid=${uid}, product=${after.product?.id}, frequency=${after.payment?.frequency}, trial=${isTrial}`);
12
12
 
13
13
  sendOrderEmail({
14
14
  template: 'main/order/confirmation',
15
15
  subject: isTrial ? 'Your free trial has started!' : 'Your subscription is confirmed!',
16
16
  categories: ['order/confirmation'],
17
- uid,
18
17
  userDoc,
19
18
  assistant,
20
19
  data: {
@@ -5,13 +5,12 @@
5
5
  const { sendOrderEmail, formatDate } = require('../send-email.js');
6
6
 
7
7
  module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
8
- assistant.log(`Transition [subscription/payment-failed]: uid=${uid}, product=${after.product.id}, previousStatus=${before?.status}`);
8
+ assistant.log(`Transition [subscription/payment-failed]: uid=${uid}, product=${after.product?.id}, previousStatus=${before?.status}`);
9
9
 
10
10
  sendOrderEmail({
11
11
  template: 'main/order/payment-failed',
12
12
  subject: 'Your payment failed',
13
13
  categories: ['order/payment-failed'],
14
- uid,
15
14
  userDoc,
16
15
  assistant,
17
16
  data: {
@@ -5,13 +5,12 @@
5
5
  const { sendOrderEmail, formatDate } = require('../send-email.js');
6
6
 
7
7
  module.exports = async function ({ before, after, order, uid, userDoc, assistant }) {
8
- assistant.log(`Transition [subscription/payment-recovered]: uid=${uid}, product=${after.product.id}`);
8
+ assistant.log(`Transition [subscription/payment-recovered]: uid=${uid}, product=${after.product?.id}`);
9
9
 
10
10
  sendOrderEmail({
11
11
  template: 'main/order/payment-recovered',
12
12
  subject: 'Your payment was successful',
13
13
  categories: ['order/payment-recovered'],
14
- uid,
15
14
  userDoc,
16
15
  assistant,
17
16
  data: {
@@ -5,14 +5,13 @@
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 direction = after.product.id > before.product.id ? 'upgrade' : 'downgrade';
9
- assistant.log(`Transition [subscription/plan-changed]: uid=${uid}, ${before.product.id} → ${after.product.id} (${direction})`);
8
+ const direction = (after.product?.id || '') > (before.product?.id || '') ? 'upgrade' : 'downgrade';
9
+ assistant.log(`Transition [subscription/plan-changed]: uid=${uid}, ${before.product?.id} → ${after.product?.id} (${direction})`);
10
10
 
11
11
  sendOrderEmail({
12
12
  template: 'main/order/plan-changed',
13
13
  subject: 'Your subscription plan has been updated',
14
14
  categories: ['order/plan-changed'],
15
- uid,
16
15
  userDoc,
17
16
  assistant,
18
17
  data: {
@@ -14,7 +14,6 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
14
14
  template: 'main/order/cancelled',
15
15
  subject: 'Your subscription has been cancelled',
16
16
  categories: ['order/cancelled'],
17
- uid,
18
17
  userDoc,
19
18
  assistant,
20
19
  data: {
@@ -103,6 +103,8 @@ Email.prototype.build = async function (settings) {
103
103
  throw errorWithCode('Missing brand.contact.email in backend-manager-config.json', 400);
104
104
  }
105
105
 
106
+ const copy = settings.copy ?? true;
107
+
106
108
  // Add carbon copy recipients
107
109
  if (copy) {
108
110
  cc.push({
@@ -146,7 +148,6 @@ Email.prototype.build = async function (settings) {
146
148
 
147
149
  const templateId = TEMPLATES[settings.template] || settings.template || TEMPLATES['default'];
148
150
  const groupId = GROUPS[settings.group] || settings.group || GROUPS['default'];
149
- const copy = settings.copy ?? true;
150
151
 
151
152
  // Build categories
152
153
  const categories = _.uniq([
@@ -70,10 +70,7 @@ module.exports = async ({ assistant, user, settings, libraries }) => {
70
70
  assistant.log(`signup(): Writing user record for ${uid}`, userRecord);
71
71
 
72
72
  await admin.firestore().doc(`users/${uid}`)
73
- .set(userRecord, { merge: true })
74
- .catch((e) => {
75
- assistant.error(`signup(): Failed to update user record:`, e);
76
- });
73
+ .set(userRecord, { merge: true });
77
74
 
78
75
  // 5. Process affiliate referral (writes to referrer's doc, not this user's)
79
76
  await processAffiliate(assistant, uid, settings);