backend-manager 3.0.5 → 3.0.8

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.5",
3
+ "version": "3.0.8",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -69,4 +69,4 @@
69
69
  "wonderful-log": "^1.0.5",
70
70
  "yargs": "^17.7.2"
71
71
  }
72
- }
72
+ }
@@ -154,7 +154,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
154
154
  // Resolve
155
155
  const processor = self[`resolve_${profile.processor}`];
156
156
  if (processor) {
157
- processor(profile, resource, resolved);
157
+ processor(profile, resource, resolved, options);
158
158
  } else {
159
159
  throw new Error('Unknown processor');
160
160
  }
@@ -241,7 +241,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
241
241
  return resolved;
242
242
  };
243
243
 
244
- SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, resolved) {
244
+ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, resolved, options) {
245
245
  const self = this;
246
246
 
247
247
  // Set status
@@ -362,6 +362,17 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
362
362
  resolved.expires.timestamp = moment(
363
363
  get(resource, 'billing_info.next_billing_time', 0)
364
364
  )
365
+
366
+ /*
367
+ Special condition for PayPal #2
368
+ I want to put the subscription in a suspended state if it's even one day past due
369
+ */
370
+ const trialLength = get(trialTenure, 'frequency.interval_count', 0);
371
+ const daysSinceStart = moment(resolved.start.timestamp).diff(moment(options.today), 'days');
372
+ if (daysSinceStart > trialLength) {
373
+ resolved.status = 'suspended';
374
+ resolved.trial.active = false;
375
+ }
365
376
  }
366
377
  resolved.trial.claimed = trialClaimed;
367
378
 
@@ -396,7 +407,7 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
396
407
  return resolved;
397
408
  }
398
409
 
399
- SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource, resolved) {
410
+ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource, resolved, options) {
400
411
  const self = this;
401
412
 
402
413
  // Set status
@@ -589,7 +600,7 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
589
600
  return resolved;
590
601
  }
591
602
 
592
- SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, resolved) {
603
+ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, resolved, options) {
593
604
  const self = this;
594
605
 
595
606
  // Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
@@ -724,7 +735,7 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
724
735
  return resolved;
725
736
  }
726
737
 
727
- SubscriptionResolver.prototype.resolve_coinbase = function (profile, resource, resolved) {
738
+ SubscriptionResolver.prototype.resolve_coinbase = function (profile, resource, resolved, options) {
728
739
  const self = this;
729
740
 
730
741
  // Setup preliminary variables
@@ -4,7 +4,7 @@ function Utilities(Manager) {
4
4
  const self = this;
5
5
 
6
6
  self.cache = null;
7
-
7
+
8
8
  self.Manager = Manager;
9
9
  }
10
10
 
@@ -56,7 +56,7 @@ Utilities.prototype.iterateCollection = function (callback, options) {
56
56
 
57
57
  if (options.log) {
58
58
  console.log('Processing batch:', batch);
59
- }
59
+ }
60
60
 
61
61
  callback({
62
62
  snap: snap, docs: snap.docs.map(x => x)
@@ -81,14 +81,14 @@ Utilities.prototype.iterateCollection = function (callback, options) {
81
81
  });
82
82
  }
83
83
 
84
- listAllDocuments();
84
+ listAllDocuments();
85
85
  });
86
86
  };
87
87
 
88
88
  Utilities.prototype.iterateUsers = function (callback, options) {
89
89
  const self = this;
90
90
  const Manager = self.Manager;
91
- const admin = Manager.libraries.admin;
91
+ const admin = Manager.libraries.admin;
92
92
 
93
93
  return new Promise(function(resolve, reject) {
94
94
  let batch = -1;
@@ -97,13 +97,13 @@ Utilities.prototype.iterateUsers = function (callback, options) {
97
97
  options.batchSize = options.batchSize || 1000;
98
98
  options.log = options.log;
99
99
  options.pageToken = options.pageToken;
100
-
100
+
101
101
  function listAllUsers(nextPageToken) {
102
102
  // List batch of users, 1000 at a time.
103
103
  admin.auth()
104
104
  .listUsers(options.batchSize, nextPageToken)
105
105
  .then(async (listUsersResult) => {
106
-
106
+
107
107
  batch++;
108
108
 
109
109
  if (options.log) {
@@ -111,8 +111,8 @@ Utilities.prototype.iterateUsers = function (callback, options) {
111
111
  }
112
112
 
113
113
  callback({
114
- snap: listUsersResult,
115
- users: listUsersResult.users,
114
+ snap: listUsersResult,
115
+ users: listUsersResult.users,
116
116
  pageToken: listUsersResult.pageToken,
117
117
  }, batch)
118
118
  .then(r => {
@@ -125,16 +125,16 @@ Utilities.prototype.iterateUsers = function (callback, options) {
125
125
  .catch((e) => {
126
126
  console.error('Callback failed', e);
127
127
  return reject(e)
128
- });
129
-
128
+ });
129
+
130
130
  })
131
131
  .catch((e) => {
132
132
  console.error('Query failed', e);
133
133
  return reject(e)
134
- });
134
+ });
135
135
  }
136
-
137
- listAllUsers(options.pageToken);
136
+
137
+ listAllUsers(options.pageToken);
138
138
  });
139
139
  };
140
140
 
@@ -148,7 +148,7 @@ Utilities.prototype.randomId = function (options) {
148
148
  nanoId = require('nanoid');
149
149
 
150
150
  nanoId = nanoId.customAlphabet(
151
- nanoId.urlAlphabet.replace(/_|-/g, ''),
151
+ nanoId.urlAlphabet.replace(/_|-/g, ''),
152
152
  options.size,
153
153
  )
154
154
  }
@@ -177,18 +177,17 @@ Utilities.prototype.get = function (docPath, options) {
177
177
  .then(async (doc) => {
178
178
  const data = doc.data();
179
179
 
180
- if (!data) {
181
- throw new Error(`Document with ID ${doc} not found`);
180
+ if (data) {
181
+ self.cache.set(docPath, {
182
+ doc: doc,
183
+ time: Date.now(),
184
+ })
185
+ .write();
182
186
  }
183
187
 
184
- self.cache.set(docPath, {
185
- doc: doc,
186
- time: Date.now(),
187
- })
188
- .write();
189
-
190
188
  return resolve(doc);
191
189
  })
190
+ .catch(e => reject(e));
192
191
  }
193
192
  });
194
193
  };