backend-manager 3.2.122 → 3.2.124

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": "3.2.122",
3
+ "version": "3.2.124",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
package/src/cli/cli.js CHANGED
@@ -1317,39 +1317,59 @@ async function cmd_configSet(self, newPath, newValue) {
1317
1317
  name: 'path',
1318
1318
  default: 'service.key'
1319
1319
  }
1320
- ]).then(answers => answers.path)
1320
+ ]).then(answers => answers.path);
1321
+
1322
+ let object = null;
1321
1323
 
1322
1324
  try {
1323
- const object = JSON5.parse(newPath)
1324
- try {
1325
- if (typeof object === 'object') {
1326
- const keyify = (obj, prefix = '') =>
1327
- Object.keys(obj).reduce((res, el) => {
1328
- if( Array.isArray(obj[el]) ) {
1329
- return res;
1330
- } else if( typeof obj[el] === 'object' && obj[el] !== null ) {
1331
- return [...res, ...keyify(obj[el], prefix + el + '.')];
1332
- }
1333
- return [...res, prefix + el];
1334
- }, []);
1335
- const pathArray = keyify(object);
1336
- for (var i = 0; i < pathArray.length; i++) {
1337
- const pathName = pathArray[i];
1338
- const pathValue = _.get(object, pathName);
1339
- // console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)} = ${chalk.bold(pathValue)}`));
1340
- console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)}`));
1341
- await cmd_configSet(self, pathName, pathValue)
1342
- .catch(e => {
1343
- log(chalk.red(`Failed to save object path: ${e}`));
1344
- })
1345
- }
1346
- return resolve();
1325
+ object = JSON5.parse(newPath);
1326
+ } catch (e) {
1327
+ }
1328
+
1329
+ const isObject = typeof object === 'object';
1330
+
1331
+ // If it's a string, ensure some things
1332
+ if (!isObject) {
1333
+ // Validate path
1334
+ if (!newPath.includes('.')) {
1335
+ console.log(chalk.red(`Path needs 2 parts (one.two): ${newPath}`));
1336
+ return reject();
1337
+ }
1338
+
1339
+ // Make sure it doesnt include space or special characters
1340
+ if (newPath.match(/[^a-zA-Z0-9.]/)) {
1341
+ console.log(chalk.red(`Path contains invalid characters: ${newPath}`));
1342
+ return reject();
1343
+ }
1344
+ }
1345
+
1346
+ try {
1347
+ if (isObject) {
1348
+ const keyify = (obj, prefix = '') =>
1349
+ Object.keys(obj).reduce((res, el) => {
1350
+ if( Array.isArray(obj[el]) ) {
1351
+ return res;
1352
+ } else if( typeof obj[el] === 'object' && obj[el] !== null ) {
1353
+ return [...res, ...keyify(obj[el], prefix + el + '.')];
1354
+ }
1355
+ return [...res, prefix + el];
1356
+ }, []);
1357
+ const pathArray = keyify(object);
1358
+ for (var i = 0; i < pathArray.length; i++) {
1359
+ const pathName = pathArray[i];
1360
+ const pathValue = _.get(object, pathName);
1361
+ // console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)} = ${chalk.bold(pathValue)}`));
1362
+ console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)}`));
1363
+ await cmd_configSet(self, pathName, pathValue)
1364
+ .catch(e => {
1365
+ log(chalk.red(`Failed to save object path: ${e}`));
1366
+ })
1347
1367
  }
1348
- } catch (e) {
1349
- log(chalk.red(`Failed to save object: ${e}`));
1350
- return reject(e)
1368
+ return resolve();
1351
1369
  }
1352
1370
  } catch (e) {
1371
+ log(chalk.red(`Failed to save object: ${e}`));
1372
+ return reject(e)
1353
1373
  }
1354
1374
 
1355
1375
  newValue = newValue || await inquirer.prompt([
@@ -52,6 +52,8 @@ Middleware.prototype.run = function (libPath, options) {
52
52
 
53
53
  // Wakeup trigger (quit immediately if wakeup is true to avoid cold start on a future request)
54
54
  if (data.wakeup) {
55
+ assistant.log(`Middleware.process(): Wakeup activated at ${new Date().toISOString()}`);
56
+
55
57
  return assistant.respond({wakeup: true});
56
58
  }
57
59
 
@@ -99,9 +99,9 @@ Manager.prototype.init = function (exporter, options) {
99
99
  // Load config
100
100
  self.config = merge(
101
101
  // Load basic config
102
- requireJSON5(self.project.backendManagerConfigPath),
102
+ requireJSON5(self.project.backendManagerConfigPath, true),
103
103
  // Load ENV config as a fallback
104
- requireJSON5(path.resolve(self.cwd, '.runtimeconfig.json'), true),
104
+ requireJSON5(path.resolve(self.cwd, '.runtimeconfig.json'), options.projectType === 'firebase'),
105
105
  // Finally, load the functions config
106
106
  self.libraries.functions
107
107
  ? self.libraries.functions.config()
@@ -984,17 +984,21 @@ function resolveProjectPackage() {
984
984
  } catch (e) {}
985
985
  }
986
986
 
987
- function requireJSON5(file, log) {
988
- // Set log
989
- log = typeof log === 'undefined' ? true : log;
987
+ function requireJSON5(file, throwError) {
988
+ // Set throwError
989
+ throwError = typeof throwError === 'undefined' ? true : throwError;
990
990
 
991
991
  // Load JSON5
992
992
  try {
993
993
  return JSON5.parse(jetpack.read(file))
994
994
  } catch (e) {
995
- if (log) {
996
- console.error(`Failed to load JSON at ${file}:`, e);
995
+ // If we're not throwing an error, just return
996
+ if (!throwError) {
997
+ return {};
997
998
  }
999
+
1000
+ // Otherwise, throw the error
1001
+ console.error(`Failed to load JSON at ${file}:`, e);
998
1002
  throw e;
999
1003
  }
1000
1004
  }