backend-manager 2.5.63 → 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/firebase-debug.log +10 -0
- package/package.json +1 -1
- package/src/manager/functions/core/actions/api/admin/database-read.js +10 -18
- package/src/manager/functions/core/actions/api/admin/database-write.js +13 -21
- package/src/manager/functions/core/actions/api.js +30 -7
- package/src/manager/helpers/subscription-resolver.js +84 -16
- package/src/manager/index.js +16 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[debug] [2023-03-24T23:10:48.343Z] ----------------------------------------------------------------------
|
|
2
|
+
[debug] [2023-03-24T23:10:48.344Z] Command: /Users/ian/.nvm/versions/node/v16.17.0/bin/node /Users/ian/.nvm/versions/node/v16.17.0/bin/firebase deploy
|
|
3
|
+
[debug] [2023-03-24T23:10:48.344Z] CLI Version: 11.8.0
|
|
4
|
+
[debug] [2023-03-24T23:10:48.344Z] Platform: darwin
|
|
5
|
+
[debug] [2023-03-24T23:10:48.345Z] Node Version: v16.17.0
|
|
6
|
+
[debug] [2023-03-24T23:10:48.346Z] Time: Fri Mar 24 2023 16:10:48 GMT-0700 (Pacific Daylight Time)
|
|
7
|
+
[debug] [2023-03-24T23:10:48.347Z] ----------------------------------------------------------------------
|
|
8
|
+
[debug]
|
|
9
|
+
[error]
|
|
10
|
+
[error] Error: Not in a Firebase app directory (could not locate firebase.json)
|
package/package.json
CHANGED
|
@@ -10,28 +10,20 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
+
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
14
|
+
payload.data.payload.options = payload.data.payload.options || {};
|
|
13
15
|
|
|
14
|
-
if (payload.user.roles.admin) {
|
|
15
|
-
|
|
16
|
-
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
17
|
-
payload.data.payload.options = payload.data.payload.options || {};
|
|
18
|
-
|
|
19
|
-
if (!payload.data.payload.path) {
|
|
20
|
-
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
21
|
-
} else {
|
|
22
|
-
|
|
23
|
-
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
24
|
-
.on('value', (snapshot) => {
|
|
25
|
-
const data = snapshot.val();
|
|
26
|
-
return resolve({data: data});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
} else {
|
|
16
|
+
if (!payload.user.roles.admin) {
|
|
32
17
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
18
|
+
} else if (!payload.data.payload.path) {
|
|
19
|
+
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
33
20
|
}
|
|
34
21
|
|
|
22
|
+
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
23
|
+
.on('value', (snapshot) => {
|
|
24
|
+
const data = snapshot.val();
|
|
25
|
+
return resolve({data: data});
|
|
26
|
+
});
|
|
35
27
|
});
|
|
36
28
|
|
|
37
29
|
};
|
|
@@ -10,32 +10,24 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
+
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
14
|
+
payload.data.payload.document = payload.data.payload.document || {};
|
|
15
|
+
payload.data.payload.options = payload.data.payload.options || {};
|
|
13
16
|
|
|
14
17
|
if (payload.user.roles.admin) {
|
|
15
|
-
|
|
16
|
-
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
17
|
-
payload.data.payload.document = payload.data.payload.document || {};
|
|
18
|
-
payload.data.payload.options = payload.data.payload.options || {};
|
|
19
|
-
|
|
20
|
-
if (!payload.data.payload.path) {
|
|
21
|
-
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
22
|
-
} else {
|
|
23
|
-
|
|
24
|
-
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
25
|
-
.set(payload.data.payload.document)
|
|
26
|
-
.then(() => {
|
|
27
|
-
return resolve({data: payload.data.payload.document});
|
|
28
|
-
})
|
|
29
|
-
.catch((e) => {
|
|
30
|
-
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
} else {
|
|
36
18
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
19
|
+
} else if (!payload.data.payload.path) {
|
|
20
|
+
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error);
|
|
37
21
|
}
|
|
38
22
|
|
|
23
|
+
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
24
|
+
.set(payload.data.payload.document)
|
|
25
|
+
.then(() => {
|
|
26
|
+
return resolve({data: payload.data.payload.document});
|
|
27
|
+
})
|
|
28
|
+
.catch((e) => {
|
|
29
|
+
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
30
|
+
});
|
|
39
31
|
});
|
|
40
32
|
|
|
41
33
|
};
|
|
@@ -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,20 +220,18 @@ Module.prototype.resolveCommand = function (command) {
|
|
|
218
220
|
// command = 'error:error';
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const resolvedPath = './' + path.join('./api/', `${command.replace(/\.\.\//g, '').replace(/\:/, '/')}.js`);
|
|
224
|
-
const pathExists = jetpack.exists(path.join(__dirname, resolvedPath));
|
|
223
|
+
// Check local path
|
|
224
|
+
const resolvedPath = resolveApiPath(command);
|
|
225
225
|
|
|
226
226
|
// if (!command || command === 'error:error') {
|
|
227
|
-
if (!
|
|
228
|
-
self.assistant.log(`This command does not exist: ${originalCommand} => ${command} @ ${
|
|
227
|
+
if (!resolvedPath) {
|
|
228
|
+
self.assistant.log(`This command does not exist: ${originalCommand} => ${command} @ ${resolvedPath}`, {environment: 'production'})
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
return {
|
|
232
232
|
command: command,
|
|
233
233
|
path: resolvedPath,
|
|
234
|
-
exists: !!
|
|
234
|
+
exists: !!resolvedPath,
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
|
|
@@ -290,4 +290,27 @@ function _fixStatus(status) {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
function resolveBasePath(basePath, command) {
|
|
294
|
+
const sanitizedCommand = command.replace(/\.\.\//g, '').replace(/\:/, '/');
|
|
295
|
+
const resolvedPath = path.join(basePath, `${sanitizedCommand}.js`);
|
|
296
|
+
|
|
297
|
+
return resolvedPath;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
function resolveApiPath(command) {
|
|
301
|
+
const projectBasePath = path.join(process.cwd(), 'methods/api');
|
|
302
|
+
const localBasePath = './api/';
|
|
303
|
+
|
|
304
|
+
const projectPath = resolveBasePath(projectBasePath, command);
|
|
305
|
+
const localPath = path.join(__dirname, resolveBasePath(localBasePath, command));
|
|
306
|
+
|
|
307
|
+
if (jetpack.exists(projectPath)) {
|
|
308
|
+
return projectPath;
|
|
309
|
+
} else if (jetpack.exists(localPath)) {
|
|
310
|
+
return localPath;
|
|
311
|
+
} else {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
293
316
|
module.exports = Module;
|
|
@@ -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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
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()
|
package/src/manager/index.js
CHANGED
|
@@ -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');
|