backend-manager 2.5.64 → 2.5.65

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.64",
3
+ "version": "2.5.65",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -162,6 +162,8 @@ Module.prototype.resolveCommand = function (command) {
162
162
  const self = this;
163
163
  const originalCommand = command;
164
164
 
165
+ command = command || '';
166
+
165
167
  // Start
166
168
  if (false) {
167
169
 
@@ -218,8 +220,6 @@ Module.prototype.resolveCommand = function (command) {
218
220
  // command = 'error:error';
219
221
  }
220
222
 
221
- command = command || '';
222
-
223
223
  // Check local path
224
224
  const resolvedPath = resolveApiPath(command);
225
225
 
@@ -27,6 +27,9 @@ SubscriptionResolver.prototype.resolve = function (options) {
27
27
  timestamp: moment(0),
28
28
  timestampUNIX: moment(0),
29
29
  },
30
+ trial: {
31
+ active: false,
32
+ }
30
33
  }
31
34
 
32
35
  const profile = self.profile;
@@ -42,10 +45,22 @@ SubscriptionResolver.prototype.resolve = function (options) {
42
45
  // Process differently based on each provider
43
46
  if (profile.processor === 'paypal') {
44
47
  // Set status
45
- // subscription: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
46
- // APPROVAL_PENDING. The subscription is created but not yet approved by the buyer. APPROVED. The buyer has approved the subscription. ACTIVE. The subscription is active. SUSPENDED. The subscription is suspended. CANCELLED. The subscription is cancelled. EXPIRED. The subscription is expired.
47
- // order: https://developer.paypal.com/docs/api/orders/v2/#orders_get
48
- // CREATED. The order was created with the specified context. SAVED. The order was saved and persisted. The order status continues to be in progress until a capture is made with final_capture = true for all purchase units within the order. APPROVED. The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment. For example, a card, bank account, or so on. VOIDED. All purchase units in the order are voided. COMPLETED. The payment was authorized or the authorized payment was captured for the order. PAYER_ACTION_REQUIRED. The order requires an action from the payer (e.g. 3DS authentication). Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing the order.
48
+ /*
49
+ subscription: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
50
+ APPROVAL_PENDING. The subscription is created but not yet approved by the buyer.
51
+ APPROVED. The buyer has approved the subscription.
52
+ ACTIVE. The subscription is active.
53
+ SUSPENDED. The subscription is suspended.
54
+ CANCELLED. The subscription is cancelled.
55
+ EXPIRED. The subscription is expired.
56
+
57
+ order: https://developer.paypal.com/docs/api/orders/v2/#orders_get
58
+ CREATED. The order was created with the specified context.
59
+ SAVED. The order was saved and persisted. The order status continues to be in progress until a capture is made with final_capture = true for all purchase units within the order.
60
+ APPROVED. The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment. For example, a card, bank account, or so on.
61
+ VOIDED. All purchase units in the order are voided. COMPLETED. The payment was authorized or the authorized payment was captured for the order.
62
+ PAYER_ACTION_REQUIRED. The order requires an action from the payer (e.g. 3DS authentication). Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing the order.
63
+ */
49
64
  if (['ACTIVE'].includes(resource.status)) {
50
65
  resolved.status = 'active';
51
66
  } else if (['SUSPENDED'].includes(resource.status)) {
@@ -57,10 +72,26 @@ SubscriptionResolver.prototype.resolve = function (options) {
57
72
  // Set resource ID
58
73
  resolved.resource.id = resource.id;
59
74
 
60
- // Set expiration and start
61
- resolved.expires.timestamp = moment(
62
- get(resource, 'billing_info.last_payment.time', 0)
63
- )
75
+ // Get trial
76
+ const trialTenure = get(resource, 'billing_info.cycle_executions', []).find((cycle) => cycle.tenure_type === 'TRIAL');
77
+ const regularTenure = get(resource, 'billing_info.cycle_executions', []).find((cycle) => cycle.tenure_type === 'REGULAR');
78
+
79
+ // Resolve trial
80
+ if (trialTenure && regularTenure && regularTenure.cycles_completed === 0) {
81
+ resolved.trial.active = true;
82
+
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();
88
+ } else {
89
+ // Set expiration and start
90
+ resolved.expires.timestamp = moment(
91
+ get(resource, 'billing_info.last_payment.time', 0)
92
+ )
93
+ }
94
+
64
95
  resolved.start.timestamp = moment(
65
96
  get(resource, 'start_time', 0)
66
97
  )
@@ -86,10 +117,28 @@ SubscriptionResolver.prototype.resolve = function (options) {
86
117
  // Set resource ID
87
118
  resolved.resource.id = resource.id;
88
119
 
89
- // Set expiration and start
90
- resolved.expires.timestamp = moment(
91
- get(resource, 'current_term_start', 0) * 1000
92
- )
120
+ // Get trial
121
+ if (resource.status === 'in_trial') {
122
+ resolved.trial.active = true;
123
+
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
+ // )
133
+ } else {
134
+ // Set expiration and start
135
+ resolved.expires.timestamp = moment(
136
+ (
137
+ get(resource, 'current_term_start', 0)
138
+ ) * 1000
139
+ )
140
+ }
141
+
93
142
  resolved.start.timestamp = moment(
94
143
  get(resource, 'created_at', 0) * 1000
95
144
  )
@@ -116,10 +165,19 @@ SubscriptionResolver.prototype.resolve = function (options) {
116
165
  // Set resource ID
117
166
  resolved.resource.id = resource.id;
118
167
 
119
- // Set expiration and start
120
- resolved.expires.timestamp = moment(
121
- get(resource, 'current_period_start', 0) * 1000
122
- );
168
+ // Get trial
169
+ if (resource.status === 'trialing') {
170
+ resolved.trial.active = true;
171
+
172
+ // Set expiration and start
173
+ resolved.expires.timestamp = moment();
174
+ } else {
175
+ // Set expiration and start
176
+ resolved.expires.timestamp = moment(
177
+ get(resource, 'current_period_start', 0) * 1000
178
+ );
179
+ }
180
+
123
181
  resolved.start.timestamp = moment(
124
182
  get(resource, 'start_date', 0) * 1000
125
183
  );
@@ -137,6 +195,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
137
195
  // Set resource ID
138
196
  resolved.resource.id = resource.id;
139
197
 
198
+ // Get trial
199
+ if (true) {
200
+ resolved.trial.active = false;
201
+ }
202
+
140
203
  // Set expiration and start
141
204
  resolved.expires.timestamp = moment(
142
205
  get(resource, 'created_at', 0)
@@ -170,6 +233,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
170
233
  }
171
234
  }
172
235
 
236
+ // If trial, set to a max of 1 month
237
+ if (resolved.trial.active) {
238
+ resolved.expires.timestamp = moment().add(1, 'month');
239
+ }
240
+
173
241
  // Fix timestamps
174
242
  resolved.expires.timestampUNIX = resolved.expires.timestamp.unix()
175
243
  resolved.expires.timestamp = resolved.expires.timestamp.toISOString()
@@ -7,9 +7,11 @@ const JSON5 = require('json5');
7
7
  // const { debug, log, error, warn } = require('firebase-functions/lib/logger');
8
8
  // let User;
9
9
  // let Analytics;
10
+ // Paths
11
+ const core = './functions/core';
12
+ const wrappers = './functions/wrappers';
10
13
 
11
-
12
- function Manager(exporter, options) {
14
+ function Manager(exporter, options) {
13
15
  const self = this;
14
16
  // Constants
15
17
  self.SERVER_UUID = '11111111-1111-1111-1111-111111111111';
@@ -30,10 +32,6 @@ const JSON5 = require('json5');
30
32
  Manager.prototype.init = function (exporter, options) {
31
33
  const self = this;
32
34
 
33
- // Paths
34
- const core = './functions/core';
35
- const wrappers = './functions/wrappers';
36
-
37
35
  // Set options defaults
38
36
  options = options || {};
39
37
  options.initialize = typeof options.initialize === 'undefined' ? true : options.initialize;
@@ -583,6 +581,18 @@ Manager.prototype.SubscriptionResolver = function () {
583
581
  return new self.libraries.SubscriptionResolver(...arguments);
584
582
  };
585
583
 
584
+ // For importing API libraries
585
+ Manager.prototype.Api = function () {
586
+ const self = this;
587
+ // self.libraries.Api = self.libraries.Api || require('./helpers/subscription-resolver.js');
588
+ // return new self.libraries.Api(...arguments);
589
+ // return self._process((new (require(`${core}/actions/api.js`))()).init(self, { req: req, res: res, }))
590
+
591
+ const Api = (new (require(`${core}/actions/api.js`))()).init(self, { req: {}, res: {}, });
592
+
593
+ return Api;
594
+ };
595
+
586
596
  // Manager.prototype.Utilities = function () {
587
597
  // const self = this;
588
598
  // self.libraries.Utilities = self.libraries.Utilities || require('./helpers/utilities.js');