backend-manager 2.5.65 → 2.5.67

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": "2.5.65",
3
+ "version": "2.5.67",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -31,7 +31,7 @@
31
31
  "@google-cloud/storage": "^5.20.5",
32
32
  "@sendgrid/mail": "^7.7.0",
33
33
  "@sentry/node": "^6.19.7",
34
- "backend-assistant": "^1.0.1",
34
+ "backend-assistant": "^1.0.2",
35
35
  "busboy": "^1.6.0",
36
36
  "chalk": "^4.1.2",
37
37
  "cors": "^2.8.5",
@@ -47,7 +47,7 @@
47
47
  "lowdb": "^1.0.0",
48
48
  "mailchimp-api-v3": "^1.15.0",
49
49
  "moment": "^2.29.4",
50
- "nanoid": "^3.3.4",
50
+ "nanoid": "^3.3.6",
51
51
  "node-fetch": "^2.6.9",
52
52
  "node-powertools": "^0.0.23",
53
53
  "npm-api": "^1.0.1",
@@ -1,4 +1,5 @@
1
1
  const _ = require('lodash');
2
+ const jetpack = require('fs-jetpack');
2
3
 
3
4
  function Module() {
4
5
 
@@ -24,11 +25,18 @@ Module.prototype.main = function () {
24
25
  const processorPath = `${process.cwd()}/payment-processors/${productId}.js`
25
26
  let processor;
26
27
  // console.log('---processorPath', processorPath);
28
+
27
29
  try {
30
+ if (!jetpack.exists(processorPath)) {
31
+ self.assistant.warn('Subprocessor does not exist:', processorPath, {environment: 'production'})
32
+
33
+ return resolve({data: {}})
34
+ }
28
35
  processor = new (require(processorPath));
29
36
  processor.Manager = self.Manager;
30
37
  } catch (e) {
31
- self.assistant.error('Error loading processor', processorPath, e, {environment: 'production'})
38
+ self.assistant.error('Subprocessor failed to load:', processorPath, e, {environment: 'production'})
39
+
32
40
  return resolve({data: {}})
33
41
  }
34
42
 
@@ -81,10 +81,9 @@ SubscriptionResolver.prototype.resolve = function (options) {
81
81
  resolved.trial.active = true;
82
82
 
83
83
  // Set expiration and start
84
- // resolved.expires.timestamp = moment(
85
- // get(resource, 'billing_info.next_billing_time', 0)
86
- // )
87
- resolved.expires.timestamp = moment();
84
+ resolved.expires.timestamp = moment(
85
+ get(resource, 'billing_info.next_billing_time', 0)
86
+ )
88
87
  } else {
89
88
  // Set expiration and start
90
89
  resolved.expires.timestamp = moment(
@@ -102,6 +101,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
102
101
  } else {
103
102
  resolved.payment.completed = !['CREATED', 'SAVED', 'APPROVED', 'VOIDED', 'PAYER_ACTION_REQUIRED'].includes(resource.status);
104
103
  }
104
+
105
105
  } else if (profile.processor === 'chargebee') {
106
106
  // Set status
107
107
  // subscription: https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=2#subscription_status
@@ -122,14 +122,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
122
122
  resolved.trial.active = true;
123
123
 
124
124
  // Set expiration and start
125
- resolved.expires.timestamp = moment();
126
-
127
- // resolved.expires.timestamp = moment(
128
- // (
129
- // get(resource, 'current_term_start', 0)
130
- // || get(resource, 'current_term_start', 0)
131
- // ) * 1000
132
- // )
125
+ resolved.expires.timestamp = moment(
126
+ (
127
+ get(resource, 'trial_end', 0)
128
+ ) * 1000
129
+ )
133
130
  } else {
134
131
  // Set expiration and start
135
132
  resolved.expires.timestamp = moment(
@@ -141,12 +138,13 @@ SubscriptionResolver.prototype.resolve = function (options) {
141
138
 
142
139
  resolved.start.timestamp = moment(
143
140
  get(resource, 'created_at', 0) * 1000
144
- )
141
+ )
145
142
 
146
143
  // Set completed
147
144
  if (true) {
148
145
  resolved.payment.completed = !['future'].includes(resource.status);
149
146
  }
147
+
150
148
  } else if (profile.processor === 'stripe') {
151
149
  // Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
152
150
  // incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid
@@ -170,13 +168,17 @@ SubscriptionResolver.prototype.resolve = function (options) {
170
168
  resolved.trial.active = true;
171
169
 
172
170
  // Set expiration and start
173
- resolved.expires.timestamp = moment();
171
+ resolved.expires.timestamp = moment(
172
+ (
173
+ get(resource, 'trial_end', 0)
174
+ ) * 1000
175
+ )
174
176
  } else {
175
177
  // Set expiration and start
176
178
  resolved.expires.timestamp = moment(
177
179
  get(resource, 'current_period_start', 0) * 1000
178
180
  );
179
- }
181
+ }
180
182
 
181
183
  resolved.start.timestamp = moment(
182
184
  get(resource, 'start_date', 0) * 1000
@@ -188,6 +190,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
188
190
  } else if (resource.object === 'payment_intent') {
189
191
  resolved.payment.completed = !['requires_payment_method', 'requires_confirmation', 'requires_action', 'processing', 'requires_capture', 'canceled'].includes(resource.status);
190
192
  }
193
+
191
194
  } else if (profile.processor === 'coinbase') {
192
195
  // Set status
193
196
  resolved.status = 'cancelled';
@@ -214,28 +217,26 @@ SubscriptionResolver.prototype.resolve = function (options) {
214
217
  }
215
218
  }
216
219
 
217
- // If there was NEVER any payment sent
218
- if (!resolved.payment.completed) {
219
- resolved.expires.timestamp = moment(0);
220
- }
221
-
222
- // Fix expires by adding time to the date of last payment
220
+ // Fix expiry by adding time to the date of last payment
223
221
  if (resolved.status === 'active') {
224
222
  resolved.expires.timestamp.add(1, 'year').add(30, 'days');
225
223
  } else {
226
- const freq = profile.details.planFrequency || 'monthly';
227
- if (freq === 'annually') {
228
- resolved.expires.timestamp.add(1, 'year');
229
- } else if (freq === 'monthly') {
230
- resolved.expires.timestamp.add(1, 'month');
231
- } else if (freq === 'daily') {
232
- resolved.expires.timestamp.add(1, 'day');
224
+ // If trial, it's already set to the trial end above
225
+ if (!resolved.trial.active) {
226
+ const freq = profile.details.planFrequency || 'monthly';
227
+ if (freq === 'annually') {
228
+ resolved.expires.timestamp.add(1, 'year');
229
+ } else if (freq === 'monthly') {
230
+ resolved.expires.timestamp.add(1, 'month');
231
+ } else if (freq === 'daily') {
232
+ resolved.expires.timestamp.add(1, 'day');
233
+ }
233
234
  }
234
235
  }
235
236
 
236
- // If trial, set to a max of 1 month
237
- if (resolved.trial.active) {
238
- resolved.expires.timestamp = moment().add(1, 'month');
237
+ // If there was NEVER any payment sent AND they are not trialing
238
+ if (!resolved.payment.completed && !resolved.trial.active) {
239
+ resolved.expires.timestamp = moment(0);
239
240
  }
240
241
 
241
242
  // Fix timestamps
@@ -245,8 +246,6 @@ SubscriptionResolver.prototype.resolve = function (options) {
245
246
  resolved.start.timestampUNIX = resolved.start.timestamp.unix()
246
247
  resolved.start.timestamp = resolved.start.timestamp.toISOString()
247
248
 
248
- // console.log('---resolved', resolved);
249
-
250
249
  if (options.log) {
251
250
  console.log('resolved', resolved);
252
251
  }