backend-manager 2.0.21 → 2.0.24

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.
Files changed (24) hide show
  1. package/package.json +3 -2
  2. package/src/cli/cli.js +2 -2
  3. package/src/manager/functions/core/actions/api/admin/create-post.js +1 -11
  4. package/src/manager/functions/core/actions/api/admin/firestore-query.js +1 -11
  5. package/src/manager/functions/core/actions/api/admin/firestore-read.js +1 -11
  6. package/src/manager/functions/core/actions/api/admin/firestore-write.js +1 -11
  7. package/src/manager/functions/core/actions/api/admin/get-stats.js +1 -11
  8. package/src/manager/functions/core/actions/api/admin/payment-processor.js +1 -11
  9. package/src/manager/functions/core/actions/api/admin/send-notification.js +1 -11
  10. package/src/manager/functions/core/actions/api/general/generate-uuid.js +2 -13
  11. package/src/manager/functions/core/actions/api/handler/create-post.js +1 -11
  12. package/src/manager/functions/core/actions/api/special/setup-electron-manager-client.js +71 -0
  13. package/src/manager/functions/core/actions/api/template.js +1 -11
  14. package/src/manager/functions/core/actions/api/test/authenticate.js +1 -11
  15. package/src/manager/functions/core/actions/api/test/create-test-accounts.js +1 -11
  16. package/src/manager/functions/core/actions/api/test/webhook.js +1 -11
  17. package/src/manager/functions/core/actions/api/user/create-custom-token.js +1 -11
  18. package/src/manager/functions/core/actions/api/user/delete.js +1 -11
  19. package/src/manager/functions/core/actions/api/user/get-subscription-info.js +1 -11
  20. package/src/manager/functions/core/actions/api/user/sign-out-all-sessions.js +1 -11
  21. package/src/manager/functions/core/actions/api/user/sign-up.js +1 -11
  22. package/src/manager/functions/core/actions/api.js +59 -16
  23. package/src/manager/index.js +4 -3
  24. package/templates/backend-manager-config.json +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.0.21",
3
+ "version": "2.0.24",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -57,6 +57,7 @@
57
57
  "ultimate-jekyll-poster": "^0.0.10",
58
58
  "universal-analytics": "^0.5.3",
59
59
  "uuid": "^8.3.2",
60
+ "wonderful-fetch": "^0.0.4",
60
61
  "yargs": "^17.4.1"
61
62
  },
62
63
  "files": [
@@ -64,4 +65,4 @@
64
65
  "src/",
65
66
  "templates/"
66
67
  ]
67
- }
68
+ }
package/src/cli/cli.js CHANGED
@@ -208,7 +208,7 @@ Main.prototype.getRulesFile = function () {
208
208
  Main.prototype.setup = async function () {
209
209
  let self = this;
210
210
  let cwd = fs.cwd();
211
- log(chalk.green(`\n---- RUNNING SETUP ----`));
211
+ log(chalk.green(`\n---- RUNNING v${this.default.version} SETUP ----`));
212
212
  this.package = fs.read(`${this.firebaseProjectPath}/functions/package.json`) || '{}';
213
213
  this.firebaseJSON = fs.read(`${this.firebaseProjectPath}/firebase.json`) || '{}';
214
214
  this.firebaseRC = fs.read(`${this.firebaseProjectPath}/.firebaserc`) || '{}';
@@ -385,7 +385,7 @@ Main.prototype.setup = async function () {
385
385
  let item = ogPaths[i];
386
386
  if (!item) {continue}
387
387
  pass = (_.get(bemConfig, item, undefined));
388
- if (typeof pass === 'undefined') {
388
+ if (typeof pass === 'undefined' || typeof pass === '') {
389
389
  break;
390
390
  }
391
391
  }
@@ -7,20 +7,10 @@ function Module() {
7
7
 
8
8
  }
9
9
 
10
- Module.prototype.init = async function (s, payload) {
11
- const self = this;
12
- self.Api = s;
13
- self.Manager = s.Manager;
14
- self.libraries = s.Manager.libraries;
15
- self.assistant = s.assistant;
16
- self.payload = payload;
17
-
18
- return self;
19
- };
20
-
21
10
  Module.prototype.main = function () {
22
11
  const self = this;
23
12
  const Manager = self.Manager;
13
+ const Api = self.Api;
24
14
  const assistant = self.assistant;
25
15
  const payload = self.payload;
26
16
 
@@ -5,20 +5,10 @@ function Module() {
5
5
 
6
6
  }
7
7
 
8
- Module.prototype.init = async function (s, payload) {
9
- const self = this;
10
- self.Api = s;
11
- self.Manager = s.Manager;
12
- self.libraries = s.Manager.libraries;
13
- self.assistant = s.Manager.assistant;
14
- self.payload = payload;
15
-
16
- return self;
17
- };
18
-
19
8
  Module.prototype.main = function () {
20
9
  const self = this;
21
10
  const Manager = self.Manager;
11
+ const Api = self.Api;
22
12
  const assistant = self.assistant;
23
13
  const payload = self.payload;
24
14
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -6,20 +6,10 @@ function Module() {
6
6
 
7
7
  }
8
8
 
9
- Module.prototype.init = async function (s, payload) {
10
- const self = this;
11
- self.Api = s;
12
- self.Manager = s.Manager;
13
- self.libraries = s.Manager.libraries;
14
- self.assistant = s.assistant;
15
- self.payload = payload;
16
-
17
- return self;
18
- };
19
-
20
9
  Module.prototype.main = function () {
21
10
  const self = this;
22
11
  const Manager = self.Manager;
12
+ const Api = self.Api;
23
13
  const assistant = self.assistant;
24
14
  const payload = self.payload;
25
15
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -42,8 +32,7 @@ Module.prototype.main = function () {
42
32
 
43
33
  assistant.log('UUID Generated', payload.data.payload, result, {environment: 'production'});
44
34
 
45
- // Return the timestamp so electron-manager can save an http request >:)
46
- return resolve({data: {uuid: result, timestamp: new Date().toISOString()}});
35
+ return resolve({data: {uuid: result}});
47
36
 
48
37
  });
49
38
 
@@ -5,20 +5,10 @@ function Module() {
5
5
 
6
6
  }
7
7
 
8
- Module.prototype.init = async function (s, payload) {
9
- const self = this;
10
- self.Api = s;
11
- self.Manager = s.Manager;
12
- self.libraries = s.Manager.libraries;
13
- self.assistant = s.Manager.assistant;
14
- self.payload = payload;
15
-
16
- return self;
17
- };
18
-
19
8
  Module.prototype.main = function () {
20
9
  const self = this;
21
10
  const Manager = self.Manager;
11
+ const Api = self.Api;
22
12
  const assistant = self.assistant;
23
13
  const payload = self.payload;
24
14
 
@@ -0,0 +1,71 @@
1
+ function Module() {
2
+
3
+ }
4
+
5
+ Module.prototype.main = function () {
6
+ const self = this;
7
+ const Manager = self.Manager;
8
+ const Api = self.Api;
9
+ const assistant = self.assistant;
10
+ const payload = self.payload;
11
+
12
+ return new Promise(async function(resolve, reject) {
13
+
14
+ const fetch = Manager.require('wonderful-fetch');
15
+
16
+ const uid = payload.data.payload.uid;
17
+ const app = payload.data.payload.appId || payload.data.payload.app || Manager.config.app.id;
18
+
19
+ let uuid = null;
20
+ let error;
21
+
22
+ // Generate uuid
23
+ if (uid) {
24
+ await Api.import('general:generate-uuid', {version: 5, name: uid})
25
+ .then(library => {
26
+
27
+ library.main()
28
+ .then(result => {
29
+ uuid = result.data.uuid;
30
+ })
31
+ .catch(e => {
32
+ error = e;
33
+ })
34
+ })
35
+ }
36
+
37
+ if (error) {
38
+ return reject(error)
39
+ }
40
+
41
+ // Fetch app details
42
+ await fetch('https://us-central1-itw-creative-works.cloudfunctions.net/getApp', {
43
+ method: 'post',
44
+ timeout: 30000,
45
+ tries: 3,
46
+ json: true,
47
+ body: {
48
+ id: app,
49
+ },
50
+ })
51
+ .then(result => {
52
+ return resolve({
53
+ data: {
54
+ uuid: uuid,
55
+ timestamp: new Date().toISOString(),
56
+ ip: assistant.request.ip,
57
+ country: assistant.request.country,
58
+ app: result,
59
+ }
60
+ });
61
+ })
62
+ .catch(e => {
63
+ return reject(new Error(`Error fetching app details: ${e}`))
64
+ })
65
+
66
+ });
67
+
68
+ };
69
+
70
+
71
+ module.exports = Module;
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -2,20 +2,10 @@ function Module() {
2
2
 
3
3
  }
4
4
 
5
- Module.prototype.init = async function (s, payload) {
6
- const self = this;
7
- self.Api = s;
8
- self.Manager = s.Manager;
9
- self.libraries = s.Manager.libraries;
10
- self.assistant = s.Manager.assistant;
11
- self.payload = payload;
12
-
13
- return self;
14
- };
15
-
16
5
  Module.prototype.main = function () {
17
6
  const self = this;
18
7
  const Manager = self.Manager;
8
+ const Api = self.Api;
19
9
  const assistant = self.assistant;
20
10
  const payload = self.payload;
21
11
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -4,20 +4,10 @@ function Module() {
4
4
 
5
5
  }
6
6
 
7
- Module.prototype.init = async function (s, payload) {
8
- const self = this;
9
- self.Api = s;
10
- self.Manager = s.Manager;
11
- self.libraries = s.Manager.libraries;
12
- self.assistant = s.Manager.assistant;
13
- self.payload = payload;
14
-
15
- return self;
16
- };
17
-
18
7
  Module.prototype.main = function () {
19
8
  const self = this;
20
9
  const Manager = self.Manager;
10
+ const Api = self.Api;
21
11
  const assistant = self.assistant;
22
12
  const payload = self.payload;
23
13
 
@@ -5,20 +5,10 @@ function Module() {
5
5
 
6
6
  }
7
7
 
8
- Module.prototype.init = async function (s, payload) {
9
- const self = this;
10
- self.Api = s;
11
- self.Manager = s.Manager;
12
- self.libraries = s.Manager.libraries;
13
- self.assistant = s.Manager.assistant;
14
- self.payload = payload;
15
-
16
- return self;
17
- };
18
-
19
8
  Module.prototype.main = function () {
20
9
  const self = this;
21
10
  const Manager = self.Manager;
11
+ const Api = self.Api;
22
12
  const assistant = self.assistant;
23
13
  const payload = self.payload;
24
14
 
@@ -36,19 +36,18 @@ Module.prototype.main = function() {
36
36
  self.payload.data = assistant.request.data;
37
37
  self.payload.user = await assistant.authenticate();
38
38
 
39
- const command = self.resolveCommand(self.payload.data.command);
40
- const commandPath = './' + path.join('./api/', `${command.replace(/\.\.\//g, '').replace(/\:/, '/')}.js`);
39
+ const resolved = self.resolveCommand(self.payload.data.command);
41
40
 
42
- self.assistant.log(`Executing: ${command}`, self.payload, JSON.stringify(self.payload), {environment: 'production'})
41
+ self.assistant.log(`Executing: ${resolved.command}`, self.payload, JSON.stringify(self.payload), {environment: 'production'})
43
42
 
44
- try {
45
- const lib = new (require(commandPath))();
43
+ await self.import(resolved.command)
44
+ .then(async lib => {
46
45
  try {
47
- await lib.init(self, self.payload);
46
+ // Call main function
48
47
  await lib.main()
49
- .then(r => {
50
- self.payload.response.status = r.status || 200;
51
- self.payload.response.data = r.data || {};
48
+ .then(result => {
49
+ self.payload.response.status = result.status || 200;
50
+ self.payload.response.data = result.data || {};
52
51
  })
53
52
  .catch(e => {
54
53
  self.payload.response.status = e.code || 500;
@@ -58,22 +57,59 @@ Module.prototype.main = function() {
58
57
  self.payload.response.status = 500;
59
58
  self.payload.response.error = e || new Error('Unknown error occured');
60
59
  }
61
- } catch (e) {
60
+ })
61
+ .catch(e => {
62
62
  self.payload.response.status = 400;
63
- self.payload.response.error = new Error(`Improper command supplied: ${command}`);
64
- assistant.log('Dev error log', e)
65
- }
63
+ self.payload.response.error = new Error(`Failed to import: ${e}`);
64
+ })
66
65
 
67
66
  if (self.payload.response.status === 200) {
68
67
  return res.status(self.payload.response.status).json(self.payload.response.data);
69
68
  } else {
70
- console.error(`Error executing ${command} @ ${commandPath}`, self.payload.response.error)
69
+ console.error(`Error executing ${self.payload.data.command} => ${resolved.command} @ ${resolved.path}`, self.payload.response.error)
71
70
  // return res.status(self.payload.response.status).send(self.payload.response.error.message);
72
71
  return res.status(self.payload.response.status).send(`${self.payload.response.error}`);
73
72
  }
74
73
  });
75
74
  }
76
75
 
76
+ Module.prototype.import = function (command, payload, user, response) {
77
+ const self = this;
78
+
79
+ return new Promise(function(resolve, reject) {
80
+ const resolved = self.resolveCommand(command);
81
+
82
+ try {
83
+ const lib = new (require(resolved.path))();
84
+
85
+ // Initialize
86
+ lib.Api = self;
87
+ lib.Manager = self.Manager;
88
+ lib.libraries = self.Manager.libraries;
89
+ lib.assistant = self.assistant;
90
+ lib.payload = _.cloneDeep({
91
+ data: {
92
+ payload: payload ? payload : self.payload.data.payload,
93
+ },
94
+ user: user ? user : self.payload.user,
95
+ response: response ? response : self.payload.response,
96
+ });
97
+
98
+ // lib.payload = {};
99
+ //
100
+ // // Set payload and user if it's provided
101
+ // lib.payload.data.payload = payload ? _.cloneDeep(payload) : lib.payload.data.payload;
102
+ // lib.payload.user = user ? _.cloneDeep(user) : lib.payload.user;
103
+ // lib.payload.response = response ? _.cloneDeep(response) : lib.payload.response;
104
+
105
+ return resolve(lib);
106
+ } catch (e) {
107
+ return reject(e);
108
+ }
109
+
110
+ });
111
+ }
112
+
77
113
  Module.prototype.resolveCommand = function (command) {
78
114
  const self = this;
79
115
 
@@ -116,6 +152,10 @@ Module.prototype.resolveCommand = function (command) {
116
152
  } else if (command === 'admin:payment-processor' || command === 'payment-processor') { // rename: admin:payment-processor
117
153
  command = 'admin:payment-processor';
118
154
 
155
+ // Special
156
+ } else if (command === 'special:setup-electron-manager-client' || command === 'setup-electron-manager-client') {
157
+ command = 'special:setup-electron-manager-client';
158
+
119
159
  // Test
120
160
  } else if (command === 'test:authenticate' || command === 'authenticate') {
121
161
  command = 'test:authenticate';
@@ -126,10 +166,13 @@ Module.prototype.resolveCommand = function (command) {
126
166
 
127
167
  // End
128
168
  } else {
129
- command = '';
169
+ command = 'error:error';
130
170
  }
131
171
 
132
- return command;
172
+ return {
173
+ command: command,
174
+ path: './' + path.join('./api/', `${command.replace(/\.\.\//g, '').replace(/\:/, '/')}.js`),
175
+ };
133
176
  }
134
177
 
135
178
  Module.prototype.resolveUser = function (options) {
@@ -90,13 +90,14 @@ Manager.prototype.init = function (exporter, options) {
90
90
  }
91
91
 
92
92
  if (self.options.sentry) {
93
- // console.log('Setting up sentry:', `${self.project.projectId}@${self.package.version}`);
94
- // console.log('self.config.sentry.dsn', self.config.sentry.dsn);
93
+ const sentryRelease = `${self.config.app.id || self.project.projectId}@${self.package.version}`;
95
94
  const sentryDSN = get(self.config, 'sentry.dsn', '');
95
+ // console.log('Sentry', sentryRelease, sentryDSN);
96
+
96
97
  self.libraries.sentry = require('@sentry/node');
97
98
  self.libraries.sentry.init({
98
99
  dsn: sentryDSN,
99
- release: `${self.project.projectId}@${self.package.version}`,
100
+ release: sentryRelease,
100
101
  beforeSend(event, hint) {
101
102
  if (self.assistant.meta.environment === 'development' && !self.options.reportErrorsInDev) {
102
103
  self.assistant.error('Skipping Sentry because DEV')
@@ -1,4 +1,7 @@
1
1
  {
2
+ "app": {
3
+ "id": "my-app"
4
+ },
2
5
  "brand": {
3
6
  "name": "My Brand",
4
7
  "url": "https://example.com",