@akemona-org/strapi 3.7.0 → 3.7.2

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 (59) hide show
  1. package/bin/strapi.js +30 -28
  2. package/lib/commands/admin-reset.js +1 -1
  3. package/lib/commands/configurationDump.js +3 -3
  4. package/lib/commands/configurationRestore.js +4 -4
  5. package/lib/commands/console.js +1 -1
  6. package/lib/commands/generate.js +1 -0
  7. package/lib/commands/install.js +3 -3
  8. package/lib/commands/uninstall.js +2 -2
  9. package/lib/core/fs.js +2 -4
  10. package/lib/core/load-admin.js +2 -2
  11. package/lib/core/load-apis.js +1 -3
  12. package/lib/core/load-components.js +2 -2
  13. package/lib/core/load-extensions.js +4 -4
  14. package/lib/core/load-functions.js +2 -2
  15. package/lib/core/load-hooks.js +6 -6
  16. package/lib/core/load-middlewares.js +11 -8
  17. package/lib/core/load-modules.js +1 -1
  18. package/lib/core/load-plugins.js +2 -2
  19. package/lib/core/load-policies.js +3 -3
  20. package/lib/hooks/index.js +10 -16
  21. package/lib/load/check-reserved-filename.js +1 -1
  22. package/lib/load/filepath-to-prop-path.js +1 -1
  23. package/lib/load/package-path.js +1 -1
  24. package/lib/middlewares/boom/index.js +8 -11
  25. package/lib/middlewares/cors/index.js +4 -11
  26. package/lib/middlewares/cron/index.js +2 -2
  27. package/lib/middlewares/csp/index.js +2 -5
  28. package/lib/middlewares/favicon/index.js +2 -5
  29. package/lib/middlewares/gzip/index.js +1 -1
  30. package/lib/middlewares/hsts/index.js +2 -5
  31. package/lib/middlewares/index.js +7 -7
  32. package/lib/middlewares/ip/index.js +1 -1
  33. package/lib/middlewares/language/index.js +1 -1
  34. package/lib/middlewares/logger/index.js +2 -2
  35. package/lib/middlewares/p3p/index.js +2 -5
  36. package/lib/middlewares/parser/index.js +1 -1
  37. package/lib/middlewares/poweredBy/index.js +1 -1
  38. package/lib/middlewares/public/index.js +2 -2
  39. package/lib/middlewares/responseTime/index.js +1 -1
  40. package/lib/middlewares/responses/index.js +1 -1
  41. package/lib/middlewares/router/index.js +4 -4
  42. package/lib/middlewares/router/utils/composeEndpoint.js +1 -1
  43. package/lib/middlewares/session/index.js +3 -3
  44. package/lib/middlewares/xframe/index.js +2 -1
  45. package/lib/middlewares/xss/index.js +2 -1
  46. package/lib/services/core-store.js +23 -16
  47. package/lib/services/metrics/index.js +5 -9
  48. package/lib/services/metrics/is-truthy.js +1 -1
  49. package/lib/services/metrics/sender.js +1 -1
  50. package/lib/services/metrics/stringify-deep.js +1 -1
  51. package/lib/services/utils/upload-files.js +2 -2
  52. package/lib/services/webhook-runner.js +7 -11
  53. package/lib/services/webhook-store.js +3 -3
  54. package/lib/utils/addSlash.js +1 -1
  55. package/lib/utils/ee.js +1 -1
  56. package/lib/utils/get-prefixed-dependencies.js +2 -2
  57. package/lib/utils/run-checks.js +3 -3
  58. package/lib/utils/url-from-segments.js +1 -2
  59. package/package.json +12 -12
package/bin/strapi.js CHANGED
@@ -8,9 +8,12 @@ const { Command } = require('commander');
8
8
 
9
9
  const program = new Command();
10
10
 
11
+ // eslint-disable-next-line import/extensions
11
12
  const packageJSON = require('../package.json');
12
13
 
13
- const checkCwdIsStrapiApp = name => {
14
+ const strapiPackageName = '@akemona-org/strapi';
15
+
16
+ const checkCwdIsStrapiApp = (name) => {
14
17
  let logErrorAndExit = () => {
15
18
  console.log(
16
19
  `You need to run ${yellow(
@@ -22,7 +25,7 @@ const checkCwdIsStrapiApp = name => {
22
25
 
23
26
  try {
24
27
  const pkgJSON = require(process.cwd() + '/package.json');
25
- if (!_.has(pkgJSON, 'dependencies.strapi')) {
28
+ if (!_.has(pkgJSON, `dependencies.${strapiPackageName}`)) {
26
29
  logErrorAndExit(name);
27
30
  }
28
31
  } catch (err) {
@@ -30,36 +33,35 @@ const checkCwdIsStrapiApp = name => {
30
33
  }
31
34
  };
32
35
 
33
- const getLocalScript = name => (...args) => {
34
- checkCwdIsStrapiApp(name);
35
-
36
- const cmdPath = resolveCwd.silent(`strapi/lib/commands/${name}`);
37
- if (!cmdPath) {
38
- console.log(
39
- `Error loading the local ${yellow(
40
- name
41
- )} command. Strapi might not be installed in your "node_modules". You may need to run "npm install"`
42
- );
43
- process.exit(1);
44
- }
36
+ const getLocalScript =
37
+ (name) =>
38
+ (...args) => {
39
+ checkCwdIsStrapiApp(name);
40
+
41
+ const cmdPath = resolveCwd.silent(`${strapiPackageName}/lib/commands/${name}`);
42
+ if (!cmdPath) {
43
+ console.log(
44
+ `Error loading the local ${yellow(
45
+ name
46
+ )} command. Strapi might not be installed in your "node_modules". You may need to run "npm install"`
47
+ );
48
+ process.exit(1);
49
+ }
45
50
 
46
- const script = require(cmdPath);
51
+ const script = require(cmdPath);
47
52
 
48
- Promise.resolve()
49
- .then(() => {
50
- return script(...args);
51
- })
52
- .catch(error => {
53
- console.error(`Error while running command ${name}: ${error.message || error}`);
54
- process.exit(1);
55
- });
56
- };
53
+ Promise.resolve()
54
+ .then(() => {
55
+ return script(...args);
56
+ })
57
+ .catch((error) => {
58
+ console.error(`Error while running command ${name}: ${error.message || error}`);
59
+ process.exit(1);
60
+ });
61
+ };
57
62
 
58
63
  // Initial program setup
59
- program
60
- .storeOptionsAsProperties(false)
61
- .passCommandToAction(false)
62
- .allowUnknownOption(true);
64
+ program.storeOptionsAsProperties(false).passCommandToAction(false).allowUnknownOption(true);
63
65
 
64
66
  program.helpOption('-h, --help', 'Display help for command');
65
67
  program.addHelpCommand('help [command]', 'Display help for command');
@@ -20,7 +20,7 @@ const promptQuestions = [
20
20
  * @param {string} cmdOptions.email - user's email
21
21
  * @param {string} cmdOptions.password - user's new password
22
22
  */
23
- module.exports = async function(cmdOptions = {}) {
23
+ module.exports = async function (cmdOptions = {}) {
24
24
  const { email, password } = cmdOptions;
25
25
 
26
26
  if (_.isEmpty(email) && _.isEmpty(password) && process.stdin.isTTY) {
@@ -9,7 +9,7 @@ const CHUNK_SIZE = 100;
9
9
  * Will dump configurations to a file or stdout
10
10
  * @param {string} file filepath to use as output
11
11
  */
12
- module.exports = async function({ file: filePath, pretty }) {
12
+ module.exports = async function ({ file: filePath, pretty }) {
13
13
  const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
14
14
 
15
15
  const app = await strapi().load();
@@ -26,8 +26,8 @@ module.exports = async function({ file: filePath, pretty }) {
26
26
  .find({ _limit: CHUNK_SIZE, _start: page * CHUNK_SIZE, _sort: 'key' });
27
27
 
28
28
  results
29
- .filter(result => result.key.startsWith('plugin_'))
30
- .forEach(result => {
29
+ .filter((result) => result.key.startsWith('plugin_'))
30
+ .forEach((result) => {
31
31
  exportData.push({
32
32
  key: result.key,
33
33
  value: result.value,
@@ -9,7 +9,7 @@ const strapi = require('../index');
9
9
  * @param {string} file filepath to use as input
10
10
  * @param {string} strategy import strategy. one of (replace, merge, keep, default: replace)
11
11
  */
12
- module.exports = async function({ file: filePath, strategy = 'replace' }) {
12
+ module.exports = async function ({ file: filePath, strategy = 'replace' }) {
13
13
  const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
14
14
 
15
15
  const app = await strapi().load();
@@ -78,7 +78,7 @@ const createImporter = (db, strategy) => {
78
78
  * Replace importer. Will replace the keys that already exist and create the new ones
79
79
  * @param {Object} db - DatabaseManager instance
80
80
  */
81
- const createReplaceImporter = db => {
81
+ const createReplaceImporter = (db) => {
82
82
  const stats = {
83
83
  created: 0,
84
84
  replaced: 0,
@@ -106,7 +106,7 @@ const createReplaceImporter = db => {
106
106
  * Merge importer. Will merge the keys that already exist with their new value and create the new ones
107
107
  * @param {Object} db - DatabaseManager instance
108
108
  */
109
- const createMergeImporter = db => {
109
+ const createMergeImporter = (db) => {
110
110
  const stats = {
111
111
  created: 0,
112
112
  merged: 0,
@@ -134,7 +134,7 @@ const createMergeImporter = db => {
134
134
  * Merge importer. Will keep the keys that already exist without changing them and create the new ones
135
135
  * @param {Object} db - DatabaseManager instance
136
136
  */
137
- const createKeepImporter = db => {
137
+ const createKeepImporter = (db) => {
138
138
  const stats = {
139
139
  created: 0,
140
140
  untouched: 0,
@@ -13,7 +13,7 @@ module.exports = () => {
13
13
  app.start(() => {
14
14
  const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
15
15
 
16
- repl.on('exit', function(err) {
16
+ repl.on('exit', function (err) {
17
17
  if (err) {
18
18
  app.log.error(err);
19
19
  process.exit(1);
@@ -14,6 +14,7 @@ const generate = require('@akemona-org/strapi-generate');
14
14
  const { logger } = require('@akemona-org/strapi-utils');
15
15
 
16
16
  // Local Strapi dependencies.
17
+ // eslint-disable-next-line import/extensions
17
18
  const packageJSON = require('../../package.json');
18
19
 
19
20
  /**
@@ -6,13 +6,13 @@ const ora = require('ora');
6
6
  const execa = require('execa');
7
7
  const findPackagePath = require('../load/package-path');
8
8
 
9
- module.exports = async plugins => {
9
+ module.exports = async (plugins) => {
10
10
  const loader = ora();
11
11
  const dir = process.cwd();
12
12
 
13
13
  const version = require(join(dir, 'package.json')).dependencies.strapi;
14
14
 
15
- const pluginArgs = plugins.map(name => `strapi-plugin-${name}@${version}`);
15
+ const pluginArgs = plugins.map((name) => `strapi-plugin-${name}@${version}`);
16
16
 
17
17
  try {
18
18
  loader.start(`Installing dependencies`);
@@ -29,7 +29,7 @@ module.exports = async plugins => {
29
29
  // check if rebuild is necessary
30
30
  let shouldRebuild = false;
31
31
  for (let name of plugins) {
32
- let pkgPath = findPackagePath(`strapi-plugin-${name}`);
32
+ let pkgPath = findPackagePath(`@akemona-org/strapi-plugin-${name}`);
33
33
  if (existsSync(join(pkgPath, 'admin', 'src', 'index.js'))) {
34
34
  shouldRebuild = true;
35
35
  }
@@ -21,13 +21,13 @@ module.exports = async (plugins, { deleteFiles }) => {
21
21
  const loader = ora();
22
22
  const dir = process.cwd();
23
23
 
24
- const pluginArgs = plugins.map(name => `strapi-plugin-${name}`);
24
+ const pluginArgs = plugins.map((name) => `strapi-plugin-${name}`);
25
25
 
26
26
  try {
27
27
  // verify should rebuild before removing the pacakge
28
28
  let shouldRebuild = false;
29
29
  for (let name of plugins) {
30
- let pkgPath = findPackagePath(`strapi-plugin-${name}`);
30
+ let pkgPath = findPackagePath(`@akemona-org/strapi-plugin-${name}`);
31
31
  if (existsSync(join(pkgPath, 'admin', 'src', 'index.js'))) {
32
32
  shouldRebuild = true;
33
33
  }
package/lib/core/fs.js CHANGED
@@ -6,7 +6,7 @@ const fse = require('fs-extra');
6
6
  /**
7
7
  * create strapi fs layer
8
8
  */
9
- module.exports = strapi => {
9
+ module.exports = (strapi) => {
10
10
  function normalizePath(optPath) {
11
11
  const filePath = Array.isArray(optPath) ? optPath.join('/') : optPath;
12
12
 
@@ -23,9 +23,7 @@ module.exports = strapi => {
23
23
  */
24
24
  writeAppFile(optPath, data) {
25
25
  const writePath = normalizePath(optPath);
26
- return fse
27
- .ensureFile(writePath)
28
- .then(() => fse.writeFile(writePath, data));
26
+ return fse.ensureFile(writePath).then(() => fse.writeFile(writePath, data));
29
27
  },
30
28
 
31
29
  /**
@@ -9,8 +9,8 @@ const loadConfig = require('../load/load-config-files');
9
9
  const mergeRoutes = (a, b, key) =>
10
10
  _.isArray(a) && _.isArray(b) && key === 'routes' ? a.concat(b) : undefined;
11
11
 
12
- module.exports = async strapi => {
13
- const adminPath = findPackagePath('strapi-admin');
12
+ module.exports = async (strapi) => {
13
+ const adminPath = findPackagePath('@akemona-org/strapi-admin');
14
14
  const [files, config] = await Promise.all([
15
15
  loadFiles(adminPath, '!(config|node_modules|tests|ee|scripts)/*.*(js|json)'),
16
16
  loadConfig(adminPath),
@@ -10,9 +10,7 @@ module.exports = async ({ dir }) => {
10
10
  const apiDir = join(dir, 'api');
11
11
 
12
12
  if (!existsSync(apiDir)) {
13
- throw new Error(
14
- `Missing api folder. Please create one in your app root directory`
15
- );
13
+ throw new Error(`Missing api folder. Please create one in your app root directory`);
16
14
  }
17
15
 
18
16
  const apis = await loadFiles(apiDir, '*/!(config)/**/*.*(js|json)');
@@ -5,7 +5,7 @@ const _ = require('lodash');
5
5
  const { exists } = require('fs-extra');
6
6
  const loadFiles = require('../load/load-files');
7
7
 
8
- module.exports = async strapi => {
8
+ module.exports = async (strapi) => {
9
9
  const componentsDir = join(strapi.dir, 'components');
10
10
 
11
11
  if (!(await exists(componentsDir))) {
@@ -15,7 +15,7 @@ module.exports = async strapi => {
15
15
  const map = await loadFiles(componentsDir, '*/*.*(js|json)');
16
16
 
17
17
  return Object.keys(map).reduce((acc, category) => {
18
- Object.keys(map[category]).forEach(key => {
18
+ Object.keys(map[category]).forEach((key) => {
19
19
  const schema = map[category][key];
20
20
 
21
21
  const filePath = join(componentsDir, category, schema.__filename__);
@@ -12,7 +12,7 @@ const filePathToPath = require('../load/filepath-to-prop-path');
12
12
  /**
13
13
  * Loads the extensions folder
14
14
  */
15
- module.exports = async function({ appPath }) {
15
+ module.exports = async function ({ appPath }) {
16
16
  const extensionsDir = path.resolve(appPath, 'extensions');
17
17
 
18
18
  if (!existsSync(extensionsDir)) {
@@ -35,13 +35,13 @@ module.exports = async function({ appPath }) {
35
35
 
36
36
  const OVERWRITABLE_FOLDERS_GLOB = 'models';
37
37
  // returns a list of path and module to overwrite
38
- const loadOverwrites = async extensionsDir => {
38
+ const loadOverwrites = async (extensionsDir) => {
39
39
  const files = await glob(`*/${OVERWRITABLE_FOLDERS_GLOB}/*.*(js|json)`, {
40
40
  cwd: extensionsDir,
41
41
  });
42
42
 
43
43
  const overwrites = {};
44
- files.forEach(file => {
44
+ files.forEach((file) => {
45
45
  const absolutePath = path.resolve(extensionsDir, file);
46
46
 
47
47
  // load module
@@ -64,7 +64,7 @@ const loadOverwrites = async extensionsDir => {
64
64
  }
65
65
  });
66
66
 
67
- return Object.keys(overwrites).map(strPath => ({
67
+ return Object.keys(overwrites).map((strPath) => ({
68
68
  path: strPath.split('.'),
69
69
  mod: overwrites[strPath],
70
70
  }));
@@ -4,13 +4,13 @@ const fse = require('fs-extra');
4
4
 
5
5
  const walk = require('./walk');
6
6
 
7
- const loadFunctions = dir => {
7
+ const loadFunctions = (dir) => {
8
8
  if (!fse.existsSync(dir)) return {};
9
9
 
10
10
  return walk(dir, { loader: loadFunction });
11
11
  };
12
12
 
13
- const loadFunction = file => {
13
+ const loadFunction = (file) => {
14
14
  try {
15
15
  return require(file);
16
16
  } catch (error) {
@@ -10,7 +10,7 @@ const findPackagePath = require('../load/package-path');
10
10
  /**
11
11
  * Load hooks
12
12
  */
13
- module.exports = async function({ installedHooks, installedPlugins, appPath }) {
13
+ module.exports = async function ({ installedHooks, installedPlugins, appPath }) {
14
14
  let hooks = {};
15
15
 
16
16
  await Promise.all([
@@ -33,7 +33,7 @@ const loadHooksInDir = async (dir, hooks) => {
33
33
  cwd: dir,
34
34
  });
35
35
 
36
- files.forEach(f => {
36
+ files.forEach((f) => {
37
37
  const name = f.split('/')[0];
38
38
  mountHooks(name, [path.resolve(dir, f)], hooks);
39
39
  });
@@ -43,14 +43,14 @@ const loadLocalHooks = (appPath, hooks) => loadHooksInDir(path.resolve(appPath,
43
43
 
44
44
  const loadPluginsHooks = async (plugins, hooks) => {
45
45
  for (let pluginName of plugins) {
46
- const dir = path.resolve(findPackagePath(`strapi-plugin-${pluginName}`), 'hooks');
46
+ const dir = path.resolve(findPackagePath(`@akemona-org/strapi-plugin-${pluginName}`), 'hooks');
47
47
  await loadHooksInDir(dir, hooks);
48
48
  }
49
49
  };
50
50
 
51
- const loadAdminHooks = async hooks => {
51
+ const loadAdminHooks = async (hooks) => {
52
52
  const hooksDir = 'hooks';
53
- const dir = path.resolve(findPackagePath('strapi-admin'), hooksDir);
53
+ const dir = path.resolve(findPackagePath('@akemona-org/strapi-admin'), hooksDir);
54
54
  await loadHooksInDir(dir, hooks);
55
55
 
56
56
  // load ee admin hooks if they exist
@@ -89,7 +89,7 @@ const loadHookDependencies = async (installedHooks, hooks) => {
89
89
  };
90
90
 
91
91
  const mountHooks = (name, files, hooks) => {
92
- files.forEach(file => {
92
+ files.forEach((file) => {
93
93
  hooks[name] = hooks[name] || { loaded: false };
94
94
 
95
95
  let dependencies = [];
@@ -10,7 +10,7 @@ const findPackagePath = require('../load/package-path');
10
10
  /**
11
11
  * Load middlewares
12
12
  */
13
- module.exports = async function(strapi) {
13
+ module.exports = async function (strapi) {
14
14
  const { installedMiddlewares, installedPlugins, appPath } = strapi.config;
15
15
 
16
16
  let middlewares = {};
@@ -36,19 +36,19 @@ module.exports = async function(strapi) {
36
36
  * Build loader functions
37
37
  * @param {*} strapi - strapi instance
38
38
  */
39
- const createLoaders = strapi => {
39
+ const createLoaders = (strapi) => {
40
40
  const loadMiddlewaresInDir = async (dir, middlewares) => {
41
41
  const files = await glob('*/*(index|defaults).*(js|json)', {
42
42
  cwd: dir,
43
43
  });
44
44
 
45
- files.forEach(f => {
45
+ files.forEach((f) => {
46
46
  const name = f.split('/')[0];
47
47
  mountMiddleware(name, [path.resolve(dir, f)], middlewares);
48
48
  });
49
49
  };
50
50
 
51
- const loadInternalMiddlewares = middlewares =>
51
+ const loadInternalMiddlewares = (middlewares) =>
52
52
  loadMiddlewaresInDir(path.resolve(__dirname, '..', 'middlewares'), middlewares);
53
53
 
54
54
  const loadLocalMiddlewares = (appPath, middlewares) =>
@@ -56,7 +56,10 @@ const createLoaders = strapi => {
56
56
 
57
57
  const loadPluginsMiddlewares = async (plugins, middlewares) => {
58
58
  for (let pluginName of plugins) {
59
- const dir = path.resolve(findPackagePath(`strapi-plugin-${pluginName}`), 'middlewares');
59
+ const dir = path.resolve(
60
+ findPackagePath(`@akemona-org/strapi-plugin-${pluginName}`),
61
+ 'middlewares'
62
+ );
60
63
  await loadMiddlewaresInDir(dir, middlewares);
61
64
  }
62
65
  };
@@ -77,9 +80,9 @@ const createLoaders = strapi => {
77
80
  }
78
81
  };
79
82
 
80
- const loadAdminMiddlewares = async middlewares => {
83
+ const loadAdminMiddlewares = async (middlewares) => {
81
84
  const middlewaresDir = 'middlewares';
82
- const dir = path.resolve(findPackagePath(`strapi-admin`), middlewaresDir);
85
+ const dir = path.resolve(findPackagePath(`@akemona-org/strapi-admin`), middlewaresDir);
83
86
  await loadMiddlewaresInDir(dir, middlewares);
84
87
 
85
88
  // load ee admin middlewares if they exist
@@ -101,7 +104,7 @@ const createLoaders = strapi => {
101
104
  };
102
105
 
103
106
  const mountMiddleware = (name, files, middlewares) => {
104
- files.forEach(file => {
107
+ files.forEach((file) => {
105
108
  middlewares[name] = middlewares[name] || { loaded: false };
106
109
 
107
110
  if (_.endsWith(file, 'index.js') && !middlewares[name].load) {
@@ -20,7 +20,7 @@ const loadExtensions = require('./load-extensions');
20
20
  const loadHooks = require('./load-hooks');
21
21
  const loadComponents = require('./load-components');
22
22
 
23
- module.exports = async strapi => {
23
+ module.exports = async (strapi) => {
24
24
  const [api, admin, plugins, middlewares, hook, extensions, components] = await Promise.all([
25
25
  loadApis(strapi),
26
26
  loadAdmin(strapi),
@@ -19,7 +19,7 @@ module.exports = async ({ dir, config }) => {
19
19
  if (pluginsIntersection.length > 0) {
20
20
  throw new Error(
21
21
  `You have some local plugins with the same name as npm installed plugins:\n${pluginsIntersection
22
- .map(p => `- ${p}`)
22
+ .map((p) => `- ${p}`)
23
23
  .join('\n')}`
24
24
  );
25
25
  }
@@ -48,7 +48,7 @@ const loadPlugins = async ({ installedPlugins, config }) => {
48
48
  let plugins = {};
49
49
 
50
50
  for (let plugin of installedPlugins) {
51
- const pluginPath = findPackagePath(`strapi-plugin-${plugin}`);
51
+ const pluginPath = findPackagePath(`@akemona-org/strapi-plugin-${plugin}`);
52
52
 
53
53
  const files = await loadFiles(
54
54
  pluginPath,
@@ -5,11 +5,11 @@ const path = require('path');
5
5
  const _ = require('lodash');
6
6
  const fse = require('fs-extra');
7
7
 
8
- module.exports = dir => {
8
+ module.exports = (dir) => {
9
9
  if (!fse.existsSync(dir)) return {};
10
10
 
11
11
  const root = {};
12
- const paths = fse.readdirSync(dir, { withFileTypes: true }).filter(fd => fd.isFile());
12
+ const paths = fse.readdirSync(dir, { withFileTypes: true }).filter((fd) => fd.isFile());
13
13
 
14
14
  for (let fd of paths) {
15
15
  const { name } = fd;
@@ -23,7 +23,7 @@ module.exports = dir => {
23
23
  return root;
24
24
  };
25
25
 
26
- const loadPolicy = file => {
26
+ const loadPolicy = (file) => {
27
27
  try {
28
28
  const policy = require(file);
29
29
 
@@ -2,24 +2,24 @@
2
2
 
3
3
  const { uniq, difference, get, isUndefined, merge } = require('lodash');
4
4
 
5
- module.exports = async function() {
5
+ module.exports = async function () {
6
6
  /** Utils */
7
7
 
8
8
  const hookConfig = this.config.hook;
9
9
 
10
10
  // check if a hook exists
11
- const hookExists = key => {
11
+ const hookExists = (key) => {
12
12
  return !isUndefined(this.hook[key]);
13
13
  };
14
14
 
15
15
  // check if a hook is enabled
16
- const hookEnabled = key => get(hookConfig, ['settings', key, 'enabled'], false) === true;
16
+ const hookEnabled = (key) => get(hookConfig, ['settings', key, 'enabled'], false) === true;
17
17
 
18
18
  // list of enabled hooks
19
19
  const enableddHook = Object.keys(this.hook).filter(hookEnabled);
20
20
 
21
21
  // Method to initialize hooks and emit an event.
22
- const initialize = hookKey => {
22
+ const initialize = (hookKey) => {
23
23
  if (this.hook[hookKey].loaded === true) return;
24
24
 
25
25
  const module = this.hook[hookKey].load;
@@ -40,7 +40,7 @@ module.exports = async function() {
40
40
  this.hook[hookKey].loaded = true;
41
41
  resolve();
42
42
  })
43
- .catch(err => {
43
+ .catch((err) => {
44
44
  clearTimeout(timeout);
45
45
 
46
46
  if (err) {
@@ -56,7 +56,7 @@ module.exports = async function() {
56
56
 
57
57
  // Run beforeInitialize of every hook
58
58
  await Promise.all(
59
- enableddHook.map(key => {
59
+ enableddHook.map((key) => {
60
60
  const { beforeInitialize } = this.hook[key].load;
61
61
  if (typeof beforeInitialize === 'function') {
62
62
  return beforeInitialize();
@@ -65,23 +65,17 @@ module.exports = async function() {
65
65
  );
66
66
 
67
67
  // run the initialization of an array of hooks sequentially
68
- const initdHookSeq = async hookArr => {
68
+ const initdHookSeq = async (hookArr) => {
69
69
  for (let key of uniq(hookArr)) {
70
70
  await initialize(key);
71
71
  }
72
72
  };
73
73
 
74
- const hooksBefore = get(hookConfig, 'load.before', [])
75
- .filter(hookExists)
76
- .filter(hookEnabled);
74
+ const hooksBefore = get(hookConfig, 'load.before', []).filter(hookExists).filter(hookEnabled);
77
75
 
78
- const hooksAfter = get(hookConfig, 'load.after', [])
79
- .filter(hookExists)
80
- .filter(hookEnabled);
76
+ const hooksAfter = get(hookConfig, 'load.after', []).filter(hookExists).filter(hookEnabled);
81
77
 
82
- const hooksOrder = get(hookConfig, 'load.order', [])
83
- .filter(hookExists)
84
- .filter(hookEnabled);
78
+ const hooksOrder = get(hookConfig, 'load.order', []).filter(hookExists).filter(hookEnabled);
85
79
 
86
80
  const unspecifieddHook = difference(enableddHook, hooksBefore, hooksOrder, hooksAfter);
87
81
 
@@ -14,5 +14,5 @@ const prefixedPaths = [
14
14
  ];
15
15
 
16
16
  module.exports = function checkReservedFilenames(file) {
17
- return _.some(prefixedPaths, e => file.indexOf(`config/${e}`) >= 0) ? true : false;
17
+ return _.some(prefixedPaths, (e) => file.indexOf(`config/${e}`) >= 0) ? true : false;
18
18
  };
@@ -14,7 +14,7 @@ module.exports = (filePath, useFileNameAsKey = true) => {
14
14
  .replace(/(\.settings|\.json|\.js)/g, '')
15
15
  .toLowerCase()
16
16
  .split('/')
17
- .map(p => _.trimStart(p, '.'))
17
+ .map((p) => _.trimStart(p, '.'))
18
18
  .join('.')
19
19
  .split('.');
20
20
 
@@ -6,4 +6,4 @@ const path = require('path');
6
6
  * Returns the path to a node modules root directory (not the main file path)
7
7
  * @param {string} moduleName - name of a node module
8
8
  */
9
- module.exports = moduleName => path.dirname(require.resolve(`${moduleName}/package.json`));
9
+ module.exports = (moduleName) => path.dirname(require.resolve(`${moduleName}/package.json`));
@@ -42,7 +42,7 @@ const boomMethods = [
42
42
  'gatewayTimeout',
43
43
  ];
44
44
 
45
- const formatBoomPayload = boomError => {
45
+ const formatBoomPayload = (boomError) => {
46
46
  if (!Boom.isBoom(boomError)) {
47
47
  boomError = Boom.boomify(boomError, {
48
48
  statusCode: boomError.status || 500,
@@ -58,7 +58,7 @@ const formatBoomPayload = boomError => {
58
58
  return { status: output.statusCode, body: output.payload };
59
59
  };
60
60
 
61
- module.exports = strapi => {
61
+ module.exports = (strapi) => {
62
62
  return {
63
63
  /**
64
64
  * Initialize the hook
@@ -103,8 +103,8 @@ module.exports = strapi => {
103
103
 
104
104
  // Custom function to avoid ctx.body repeat
105
105
  createResponses() {
106
- boomMethods.forEach(method => {
107
- strapi.app.response[method] = function(msg, ...rest) {
106
+ boomMethods.forEach((method) => {
107
+ strapi.app.response[method] = function (msg, ...rest) {
108
108
  const boomError = Boom[method](msg, ...rest) || {};
109
109
 
110
110
  const { status, body } = formatBoomPayload(boomError);
@@ -119,17 +119,17 @@ module.exports = strapi => {
119
119
  this.delegator.method(method);
120
120
  });
121
121
 
122
- strapi.app.response.send = function(data, status = 200) {
122
+ strapi.app.response.send = function (data, status = 200) {
123
123
  this.status = status;
124
124
  this.body = data;
125
125
  };
126
126
 
127
- strapi.app.response.created = function(data) {
127
+ strapi.app.response.created = function (data) {
128
128
  this.status = 201;
129
129
  this.body = data;
130
130
  };
131
131
 
132
- strapi.app.response.deleted = function(data) {
132
+ strapi.app.response.deleted = function (data) {
133
133
  if (_.isNil(data)) {
134
134
  this.status = 204;
135
135
  } else {
@@ -138,10 +138,7 @@ module.exports = strapi => {
138
138
  }
139
139
  };
140
140
 
141
- this.delegator
142
- .method('send')
143
- .method('created')
144
- .method('deleted');
141
+ this.delegator.method('send').method('created').method('deleted');
145
142
  },
146
143
  };
147
144
  };