backend-manager 2.4.17 → 2.4.18

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.4.17",
3
+ "version": "2.4.18",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -35,9 +35,9 @@
35
35
  "busboy": "^1.6.0",
36
36
  "chalk": "^4.1.2",
37
37
  "cors": "^2.8.5",
38
- "dotenv": "^16.0.1",
38
+ "dotenv": "^16.0.2",
39
39
  "firebase-admin": "^9.12.0",
40
- "firebase-functions": "^3.22.0",
40
+ "firebase-functions": "^3.23.0",
41
41
  "fs-jetpack": "^4.3.1",
42
42
  "hcaptcha": "^0.1.1",
43
43
  "inquirer": "^8.2.4",
@@ -46,7 +46,6 @@
46
46
  "lodash": "^4.17.21",
47
47
  "lowdb": "^1.0.0",
48
48
  "mailchimp-api-v3": "^1.15.0",
49
- "mocha": "^9.2.2",
50
49
  "moment": "^2.29.4",
51
50
  "node-fetch": "^2.6.7",
52
51
  "node-powertools": "^0.0.21",
@@ -67,4 +66,4 @@
67
66
  "src/",
68
67
  "templates/"
69
68
  ]
70
- }
69
+ }
@@ -0,0 +1,40 @@
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
+ 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 {
32
+ return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
33
+ }
34
+
35
+ });
36
+
37
+ };
38
+
39
+
40
+ module.exports = Module;
@@ -0,0 +1,44 @@
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
+ 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
+ return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
37
+ }
38
+
39
+ });
40
+
41
+ };
42
+
43
+
44
+ module.exports = Module;
@@ -14,8 +14,7 @@ Module.prototype.main = function () {
14
14
  if (payload.user.roles.admin) {
15
15
 
16
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 || { merge: true };
17
+ payload.data.payload.options = payload.data.payload.options || {};
19
18
 
20
19
  if (!payload.data.payload.path) {
21
20
  return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
@@ -1,12 +1,13 @@
1
1
  // Libraries
2
2
  const path = require('path');
3
3
  const { get, merge } = require('lodash');
4
+ const jetpack = require('fs-jetpack');
4
5
  // const { debug, log, error, warn } = require('firebase-functions/lib/logger');
5
6
  // let User;
6
7
  // let Analytics;
7
8
 
8
9
 
9
- function Manager(exporter, options) {
10
+ function Manager(exporter, options) {
10
11
  const self = this;
11
12
  // Constants
12
13
  self.SERVER_UUID = '11111111-1111-1111-1111-111111111111';
@@ -92,6 +93,30 @@ Manager.prototype.init = function (exporter, options) {
92
93
  require('firebase-functions/lib/logger/compat');
93
94
  }
94
95
 
96
+ // Handle dev environments
97
+ if (self.assistant.meta.environment === 'development') {
98
+ const semverMajor = require('semver/functions/major')
99
+ const semverCoerce = require('semver/functions/coerce')
100
+ const semverUsing = semverMajor(semverCoerce(process.versions.node));
101
+ const semverRequired = semverMajor(semverCoerce(get(self.package, 'engines.node', '0.0.0')));
102
+
103
+ // Fix firebase-tools overwriting console.log
104
+ // https://stackoverflow.com/questions/56026747/firebase-console-log-on-localhost
105
+ if (process.env.GCLOUD_PROJECT) {
106
+ function logFix() {
107
+ console.error(...arguments);
108
+ }
109
+ console.log = logFix;
110
+ console.info = logFix;
111
+ }
112
+
113
+ // Reject if package.json does not exist
114
+ if (semverUsing !== semverRequired) {
115
+ console.error(new Error(`Node.js version mismatch: using ${semverUsing} but asked for ${semverRequired}`));
116
+ return process.exit(1);
117
+ }
118
+ }
119
+
95
120
  if (options.log) {
96
121
  self.assistant.log('process.env', process.env, {environment: 'production'})
97
122
  }
@@ -517,7 +542,6 @@ Manager.prototype.storage = function (options) {
517
542
  const FileSync = require('lowdb/adapters/FileSync');
518
543
  const dbPath = `./.data/${options.name}.json`;
519
544
  const adapter = new FileSync(dbPath);
520
- const jetpack = require('fs-jetpack');
521
545
 
522
546
  options.clearInvalid = typeof options.clearInvalid === 'undefined'
523
547
  ? true