backend-manager 2.5.62 → 2.5.64

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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.5.62",
3
+ "version": "2.5.64",
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.0",
34
+ "backend-assistant": "^1.0.1",
35
35
  "busboy": "^1.6.0",
36
36
  "chalk": "^4.1.2",
37
37
  "cors": "^2.8.5",
@@ -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
  };
@@ -1,4 +1,5 @@
1
1
  const _ = require('lodash')
2
+ const powertools = require('node-powertools')
2
3
 
3
4
  function Module() {
4
5
 
@@ -12,11 +13,25 @@ Module.prototype.main = function () {
12
13
  const payload = self.payload;
13
14
 
14
15
  return new Promise(async function(resolve, reject) {
16
+ const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
17
+ const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});
18
+
15
19
  self.Api.resolveUser({adminRequired: false})
16
20
  .then(async (user) => {
17
21
  const result = {
18
22
  plan: {
19
23
  id: _.get(user, 'plan.id', 'unknown'),
24
+ expires: {
25
+ timestamp: _.get(user, 'plan.expires.timestamp', oldDate),
26
+ timestampUNIX: _.get(user, 'plan.expires.timestampUNIX', oldDateUNIX),
27
+ },
28
+ trial: {
29
+ activated: _.get(user, 'plan.trial.activated', false),
30
+ date: {
31
+ timestamp: _.get(user, 'plan.trial.date.timestamp', oldDate),
32
+ timestampUNIX: _.get(user, 'plan.trial.date.timestampUNIX', oldDateUNIX),
33
+ }
34
+ },
20
35
  payment: {
21
36
  active: _.get(user, 'plan.payment.active', false),
22
37
  },
@@ -50,9 +50,10 @@ Module.prototype.signOutOfSession = function (uid, session) {
50
50
  const payload = self.payload;
51
51
 
52
52
  return new Promise(async function(resolve, reject) {
53
- assistant.log(`Signing out of all active sessions for ${uid} @ ${session}`, {environment: 'production'})
54
53
  let count = 0;
55
54
 
55
+ assistant.log(`Signing out of all active sessions for ${uid} @ ${session}`, {environment: 'production'})
56
+
56
57
  await self.libraries.admin.database().ref(session)
57
58
  .orderByChild('uid')
58
59
  .equalTo(uid)
@@ -220,18 +220,18 @@ Module.prototype.resolveCommand = function (command) {
220
220
 
221
221
  command = command || '';
222
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 (!pathExists) {
228
- self.assistant.log(`This command does not exist: ${originalCommand} => ${command} @ ${pathExists}`, {environment: 'production'})
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: !!pathExists,
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;
@@ -6,13 +6,15 @@ const UIDGenerator = require('uid-generator');
6
6
  const uidgen = new UIDGenerator(256);
7
7
 
8
8
  function User(settings, options) {
9
- let self = this;
9
+ const self = this;
10
+
10
11
  settings = settings || {};
11
12
  options = options || {};
12
- let now = powertools.timestamp(new Date(), {output: 'string'});
13
- let nowUNIX = powertools.timestamp(now, {output: 'unix'});
14
- let oldDate = powertools.timestamp(new Date(0), {output: 'string'})
15
- let oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});
13
+
14
+ const now = powertools.timestamp(new Date(), {output: 'string'});
15
+ const nowUNIX = powertools.timestamp(now, {output: 'unix'});
16
+ const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
17
+ const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});
16
18
 
17
19
  const useDefaults = typeof options.defaults === 'undefined' ? true : options.defaults;
18
20
 
@@ -33,6 +35,13 @@ function User(settings, options) {
33
35
  timestamp: _.get(settings, 'plan.expires.timestamp', useDefaults ? oldDate : null),
34
36
  timestampUNIX: _.get(settings, 'plan.expires.timestampUNIX', useDefaults ? oldDateUNIX : null),
35
37
  },
38
+ trial: {
39
+ activated: _.get(settings, 'plan.trial.activated', useDefaults ? false : null),
40
+ date: {
41
+ timestamp: _.get(settings, 'plan.trial.date.timestamp', useDefaults ? oldDate : null),
42
+ timestampUNIX: _.get(settings, 'plan.trial.date.timestampUNIX', useDefaults ? oldDateUNIX : null),
43
+ }
44
+ },
36
45
  limits: {
37
46
  // devices: _.get(settings, 'plan.limits.devices', null),
38
47
  },
@@ -77,6 +86,25 @@ function User(settings, options) {
77
86
  clientId: _.get(settings, 'api.clientId', useDefaults ? `${uuid4()}` : null),
78
87
  privateKey: _.get(settings, 'api.privateKey', useDefaults ? `${uidgen.generateSync()}` : null),
79
88
  },
89
+ personal: {
90
+ birthday: {
91
+ timestamp: _.get(settings, 'personal.birthday.timestamp', useDefaults ? oldDate : null),
92
+ timestampUNIX: _.get(settings, 'personal.birthday.timestampUNIX', useDefaults ? oldDateUNIX : null),
93
+ },
94
+ gender: _.get(settings, 'personal.gender', useDefaults ? 'undisclosed' : null),
95
+ location: {
96
+ city: _.get(settings, 'personal.location.city', useDefaults ? 'undisclosed' : null),
97
+ country: _.get(settings, 'personal.location.country', useDefaults ? 'ZZ' : null),
98
+ },
99
+ name: {
100
+ first: _.get(settings, 'personal.name.first', useDefaults ? 'undisclosed' : null),
101
+ last: _.get(settings, 'personal.name.last', useDefaults ? 'undisclosed' : null),
102
+ },
103
+ telephone: {
104
+ countryCode: _.get(settings, 'personal.telephone.countryCode', useDefaults ? 0 : null),
105
+ national: _.get(settings, 'personal.telephone.national', useDefaults ? 0 : null),
106
+ },
107
+ },
80
108
  }
81
109
 
82
110
  if (options.prune) {