@strapi/strapi 4.3.4 → 4.3.7

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 (112) hide show
  1. package/README.md +18 -9
  2. package/bin/strapi.js +29 -26
  3. package/lib/Strapi.js +9 -9
  4. package/lib/commands/admin-create.js +2 -5
  5. package/lib/commands/admin-reset.js +1 -1
  6. package/lib/commands/build.js +1 -1
  7. package/lib/commands/builders/admin.js +1 -1
  8. package/lib/commands/builders/typescript.js +2 -2
  9. package/lib/commands/configurationDump.js +3 -3
  10. package/lib/commands/configurationRestore.js +5 -4
  11. package/lib/commands/console.js +1 -1
  12. package/lib/commands/content-types/list.js +2 -2
  13. package/lib/commands/controllers/list.js +2 -2
  14. package/lib/commands/develop.js +16 -10
  15. package/lib/commands/hooks/list.js +2 -2
  16. package/lib/commands/install.js +4 -4
  17. package/lib/commands/middlewares/list.js +2 -2
  18. package/lib/commands/new.js +1 -1
  19. package/lib/commands/opt-in-telemetry.js +12 -13
  20. package/lib/commands/opt-out-telemetry.js +3 -3
  21. package/lib/commands/policies/list.js +2 -2
  22. package/lib/commands/routes/list.js +3 -3
  23. package/lib/commands/services/list.js +2 -2
  24. package/lib/commands/start.js +1 -0
  25. package/lib/commands/ts/generate-types.js +1 -1
  26. package/lib/commands/uninstall.js +4 -4
  27. package/lib/commands/watchAdmin.js +1 -1
  28. package/lib/compile.js +1 -1
  29. package/lib/container.js +1 -1
  30. package/lib/core/app-configuration/config-loader.js +2 -2
  31. package/lib/core/app-configuration/load-config-file.js +3 -3
  32. package/lib/core/bootstrap.js +1 -1
  33. package/lib/core/domain/component/validator.js +3 -9
  34. package/lib/core/domain/content-type/index.js +2 -2
  35. package/lib/core/domain/content-type/validator.js +9 -23
  36. package/lib/core/domain/module/index.js +1 -1
  37. package/lib/core/domain/module/validation.js +3 -4
  38. package/lib/core/loaders/admin.js +1 -1
  39. package/lib/core/loaders/apis.js +22 -30
  40. package/lib/core/loaders/components.js +2 -2
  41. package/lib/core/loaders/middlewares.js +1 -1
  42. package/lib/core/loaders/plugins/get-enabled-plugins.js +7 -7
  43. package/lib/core/loaders/plugins/index.js +7 -8
  44. package/lib/core/loaders/sanitizers.js +1 -1
  45. package/lib/core/loaders/src-index.js +2 -2
  46. package/lib/core/registries/apis.js +1 -1
  47. package/lib/core/registries/config.js +1 -1
  48. package/lib/core/registries/content-types.js +1 -1
  49. package/lib/core/registries/modules.js +1 -1
  50. package/lib/core/registries/plugins.js +1 -1
  51. package/lib/core/registries/services.js +1 -1
  52. package/lib/core/utils.js +3 -6
  53. package/lib/core-api/controller/transform.js +4 -4
  54. package/lib/core-api/service/collection-type.js +1 -1
  55. package/lib/core-api/service/index.d.ts +6 -3
  56. package/lib/core-api/service/pagination.js +5 -5
  57. package/lib/factories.js +5 -5
  58. package/lib/load/filepath-to-prop-path.js +2 -2
  59. package/lib/load/load-files.js +1 -1
  60. package/lib/load/package-path.js +1 -1
  61. package/lib/middlewares/body.js +10 -3
  62. package/lib/middlewares/compression.js +1 -1
  63. package/lib/middlewares/cors.js +3 -10
  64. package/lib/middlewares/ip.js +1 -1
  65. package/lib/middlewares/logger.js +4 -1
  66. package/lib/middlewares/powered-by.js +1 -1
  67. package/lib/middlewares/query.js +8 -2
  68. package/lib/middlewares/response-time.js +1 -1
  69. package/lib/middlewares/responses.js +1 -1
  70. package/lib/middlewares/security.js +22 -16
  71. package/lib/middlewares/session.js +2 -2
  72. package/lib/migrations/draft-publish.js +1 -5
  73. package/lib/services/auth/index.js +1 -3
  74. package/lib/services/core-store.js +4 -4
  75. package/lib/services/entity-service/components.js +34 -20
  76. package/lib/services/entity-service/index.js +73 -52
  77. package/lib/services/entity-validator/index.js +134 -127
  78. package/lib/services/entity-validator/validators.js +18 -15
  79. package/lib/services/errors.js +6 -10
  80. package/lib/services/event-hub.js +1 -0
  81. package/lib/services/fs.js +1 -1
  82. package/lib/services/metrics/index.js +6 -9
  83. package/lib/services/metrics/is-truthy.js +1 -1
  84. package/lib/services/metrics/sender.js +6 -6
  85. package/lib/services/metrics/stringify-deep.js +1 -1
  86. package/lib/services/server/admin-api.js +1 -1
  87. package/lib/services/server/compose-endpoint.js +7 -7
  88. package/lib/services/server/content-api.js +1 -1
  89. package/lib/services/server/http-server.js +9 -9
  90. package/lib/services/server/index.js +4 -4
  91. package/lib/services/server/koa.js +9 -12
  92. package/lib/services/server/middleware.js +1 -1
  93. package/lib/services/server/policy.js +1 -1
  94. package/lib/services/server/register-middlewares.js +6 -8
  95. package/lib/services/server/register-routes.js +11 -11
  96. package/lib/services/server/routing.js +11 -26
  97. package/lib/services/utils/upload-files.js +3 -3
  98. package/lib/services/webhook-runner.js +8 -7
  99. package/lib/services/webhook-store.js +3 -2
  100. package/lib/services/worker-queue.js +1 -0
  101. package/lib/types/core/strapi/index.d.ts +4 -3
  102. package/lib/types/factories.d.ts +3 -3
  103. package/lib/utils/addSlash.js +3 -3
  104. package/lib/utils/ee.js +1 -1
  105. package/lib/utils/import-default.js +1 -1
  106. package/lib/utils/open-browser.js +1 -1
  107. package/lib/utils/run-checks.js +4 -4
  108. package/lib/utils/signals.js +2 -2
  109. package/lib/utils/startup-logger.js +2 -2
  110. package/lib/utils/success.js +1 -1
  111. package/lib/utils/update-notifier/index.js +4 -4
  112. package/package.json +15 -15
@@ -33,7 +33,7 @@ const addPackageJsonStrapiMetadata = (metadata, strapi) => {
33
33
  * @param {Object} strapi strapi app
34
34
  * @returns {Function} (event, payload) -> Promise{boolean}
35
35
  */
36
- module.exports = strapi => {
36
+ module.exports = (strapi) => {
37
37
  const { uuid } = strapi.config;
38
38
  const deviceId = machineID();
39
39
  const isEE = strapi.EE === true && ee.isEE === true;
@@ -41,22 +41,22 @@ module.exports = strapi => {
41
41
  const serverRootPath = strapi.dirs.app.root;
42
42
  const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
43
43
 
44
- const anonymous_metadata = {
44
+ const anonymousMetadata = {
45
45
  environment: strapi.config.environment,
46
46
  os: os.type(),
47
47
  osPlatform: os.platform(),
48
+ osArch: os.arch(),
48
49
  osRelease: os.release(),
49
- nodeVersion: process.version,
50
+ nodeVersion: process.versions.node,
50
51
  docker: process.env.DOCKER || isDocker(),
51
52
  isCI: ciEnv.isCI,
52
53
  version: strapi.config.get('info.strapi'),
53
- strapiVersion: strapi.config.get('info.strapi'),
54
54
  projectType: isEE ? 'Enterprise' : 'Community',
55
55
  useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
56
56
  useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
57
57
  };
58
58
 
59
- addPackageJsonStrapiMetadata(anonymous_metadata, strapi);
59
+ addPackageJsonStrapiMetadata(anonymousMetadata, strapi);
60
60
 
61
61
  return async (event, payload = {}, opts = {}) => {
62
62
  const reqParams = {
@@ -67,7 +67,7 @@ module.exports = strapi => {
67
67
  deviceId,
68
68
  properties: stringifyDeep({
69
69
  ...payload,
70
- ...anonymous_metadata,
70
+ ...anonymousMetadata,
71
71
  }),
72
72
  }),
73
73
  ..._.merge({}, defaultQueryOpts, opts),
@@ -7,7 +7,7 @@ const { map, mapValues, isObject, isArray, toString } = require('lodash/fp');
7
7
  * @param {object} obj
8
8
  * @returns {object}
9
9
  */
10
- const stringifyDeep = value => {
10
+ const stringifyDeep = (value) => {
11
11
  if (isArray(value)) {
12
12
  return map(stringifyDeep, value);
13
13
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { createAPI } = require('./api');
4
4
 
5
- const createAdminAPI = strapi => {
5
+ const createAdminAPI = (strapi) => {
6
6
  const opts = {
7
7
  prefix: '', // '/admin';
8
8
  type: 'admin',
@@ -7,10 +7,10 @@ const compose = require('koa-compose');
7
7
  const { resolveRouteMiddlewares } = require('./middleware');
8
8
  const { resolvePolicies } = require('./policy');
9
9
 
10
- const getMethod = route => trim(toLower(route.method));
11
- const getPath = route => trim(route.path);
10
+ const getMethod = (route) => trim(toLower(route.method));
11
+ const getPath = (route) => trim(route.path);
12
12
 
13
- const createRouteInfoMiddleware = routeInfo => (ctx, next) => {
13
+ const createRouteInfoMiddleware = (routeInfo) => (ctx, next) => {
14
14
  const route = {
15
15
  ...routeInfo,
16
16
  config: routeInfo.config || {},
@@ -22,7 +22,7 @@ const createRouteInfoMiddleware = routeInfo => (ctx, next) => {
22
22
 
23
23
  const getAuthConfig = prop('config.auth');
24
24
 
25
- const createAuthorizeMiddleware = strapi => async (ctx, next) => {
25
+ const createAuthorizeMiddleware = (strapi) => async (ctx, next) => {
26
26
  const { auth, route } = ctx.state;
27
27
 
28
28
  const authService = strapi.container.get('auth');
@@ -44,7 +44,7 @@ const createAuthorizeMiddleware = strapi => async (ctx, next) => {
44
44
  }
45
45
  };
46
46
 
47
- const createAuthenticateMiddleware = strapi => async (ctx, next) => {
47
+ const createAuthenticateMiddleware = (strapi) => async (ctx, next) => {
48
48
  return strapi.container.get('auth').authenticate(ctx, next);
49
49
  };
50
50
 
@@ -56,7 +56,7 @@ const returnBodyMiddleware = async (ctx, next) => {
56
56
  }
57
57
  };
58
58
 
59
- module.exports = strapi => {
59
+ module.exports = (strapi) => {
60
60
  const authenticate = createAuthenticateMiddleware(strapi);
61
61
  const authorize = createAuthorizeMiddleware(strapi);
62
62
 
@@ -108,7 +108,7 @@ const getController = (name, { pluginName, apiName }, strapi) => {
108
108
  return ctrl;
109
109
  };
110
110
 
111
- const extractHandlerParts = name => {
111
+ const extractHandlerParts = (name) => {
112
112
  const controllerName = name.slice(0, name.lastIndexOf('.'));
113
113
  const actionName = name.slice(name.lastIndexOf('.') + 1);
114
114
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { createAPI } = require('./api');
4
4
 
5
- const createContentAPI = strapi => {
5
+ const createContentAPI = (strapi) => {
6
6
  const opts = {
7
7
  prefix: strapi.config.get('api.rest.prefix', '/api'),
8
8
  type: 'content-api',
@@ -17,7 +17,7 @@ const createHTTPServer = (strapi, koaApp) => {
17
17
 
18
18
  const server = http.createServer(listener);
19
19
 
20
- server.on('connection', connection => {
20
+ server.on('connection', (connection) => {
21
21
  connections.add(connection);
22
22
 
23
23
  connection.on('close', () => {
@@ -26,7 +26,7 @@ const createHTTPServer = (strapi, koaApp) => {
26
26
  });
27
27
 
28
28
  // handle port in use cleanly
29
- server.on('error', err => {
29
+ server.on('error', (err) => {
30
30
  if (err.code === 'EADDRINUSE') {
31
31
  return strapi.stopWithError(`The port ${err.port} is already used by another application.`);
32
32
  }
@@ -45,15 +45,15 @@ const createHTTPServer = (strapi, koaApp) => {
45
45
  return;
46
46
  }
47
47
 
48
- return new Promise((resolve, reject) =>
49
- server.close(error => {
48
+ return new Promise((resolve, reject) => {
49
+ server.close((error) => {
50
50
  if (error) {
51
- return reject(error);
51
+ reject(error);
52
+ } else {
53
+ resolve();
52
54
  }
53
-
54
- resolve();
55
- })
56
- );
55
+ });
56
+ });
57
57
  };
58
58
 
59
59
  return server;
@@ -10,7 +10,7 @@ const registerAllRoutes = require('./register-routes');
10
10
  const registerApplicationMiddlewares = require('./register-middlewares');
11
11
  const createKoaApp = require('./koa');
12
12
 
13
- const healthCheck = async ctx => {
13
+ const healthCheck = async (ctx) => {
14
14
  ctx.set('strapi', 'You are so French!');
15
15
  ctx.status = 204;
16
16
  };
@@ -27,7 +27,7 @@ const healthCheck = async ctx => {
27
27
  * @param {Strapi} strapi
28
28
  * @returns {Server}
29
29
  */
30
- const createServer = strapi => {
30
+ const createServer = (strapi) => {
31
31
  const app = createKoaApp({
32
32
  proxy: strapi.config.get('server.proxy'),
33
33
  keys: strapi.config.get('server.app.keys'),
@@ -83,7 +83,7 @@ const createServer = strapi => {
83
83
  mount() {
84
84
  state.mounted = true;
85
85
 
86
- Object.values(apis).forEach(api => api.mount(router));
86
+ Object.values(apis).forEach((api) => api.mount(router));
87
87
  app.use(router.routes()).use(router.allowedMethods());
88
88
 
89
89
  return this;
@@ -104,7 +104,7 @@ const createServer = strapi => {
104
104
  listRoutes() {
105
105
  const allRoutes = [...router.stack];
106
106
 
107
- Object.values(apis).forEach(api => {
107
+ Object.values(apis).forEach((api) => {
108
108
  allRoutes.push(...api.listRoutes());
109
109
  });
110
110
 
@@ -4,19 +4,19 @@ const { isNil, camelCase } = require('lodash/fp');
4
4
  const Koa = require('koa');
5
5
  const createError = require('http-errors');
6
6
  const delegate = require('delegates');
7
- var statuses = require('statuses');
7
+ const statuses = require('statuses');
8
8
  const { formatHttpError } = require('../errors');
9
9
 
10
- const addCustomMethods = app => {
10
+ const addCustomMethods = (app) => {
11
11
  const delegator = delegate(app.context, 'response');
12
12
 
13
13
  /* errors */
14
14
  statuses.codes
15
- .filter(code => code >= 400 && code < 600)
16
- .forEach(code => {
15
+ .filter((code) => code >= 400 && code < 600)
16
+ .forEach((code) => {
17
17
  const name = statuses(code);
18
18
  const camelCasedName = camelCase(name);
19
- app.response[camelCasedName] = function(message, details = {}) {
19
+ app.response[camelCasedName] = function responseCode(message, details = {}) {
20
20
  const httpError = createError(code, message, { details });
21
21
  const { status, body } = formatHttpError(httpError);
22
22
  this.status = status;
@@ -26,17 +26,17 @@ const addCustomMethods = app => {
26
26
  });
27
27
 
28
28
  /* send, created, deleted */
29
- app.response.send = function(data, status = 200) {
29
+ app.response.send = function send(data, status = 200) {
30
30
  this.status = status;
31
31
  this.body = data;
32
32
  };
33
33
 
34
- app.response.created = function(data) {
34
+ app.response.created = function created(data) {
35
35
  this.status = 201;
36
36
  this.body = data;
37
37
  };
38
38
 
39
- app.response.deleted = function(data) {
39
+ app.response.deleted = function deleted(data) {
40
40
  if (isNil(data)) {
41
41
  this.status = 204;
42
42
  } else {
@@ -45,10 +45,7 @@ const addCustomMethods = app => {
45
45
  }
46
46
  };
47
47
 
48
- delegator
49
- .method('send')
50
- .method('created')
51
- .method('deleted');
48
+ delegator.method('send').method('created').method('deleted');
52
49
 
53
50
  return app;
54
51
  };
@@ -90,7 +90,7 @@ const resolveMiddlewares = (config, strapi) => {
90
90
  );
91
91
  }
92
92
 
93
- middlewares.forEach(middleware => {
93
+ middlewares.forEach((middleware) => {
94
94
  // NOTE: we replace null middlewares by a dumb one to avoid having to filter later on
95
95
  if (isNil(middleware.handler)) {
96
96
  middleware.handler = (_, next) => next();
@@ -6,7 +6,7 @@ const { policy: policyUtils } = require('@strapi/utils');
6
6
 
7
7
  const getPoliciesConfig = propOr([], 'config.policies');
8
8
 
9
- const resolvePolicies = route => {
9
+ const resolvePolicies = (route) => {
10
10
  const policiesConfig = getPoliciesConfig(route);
11
11
  const resolvedPolicies = policyUtils.resolve(policiesConfig, route.info);
12
12
 
@@ -34,7 +34,7 @@ const requiredMiddlewares = [
34
34
  ];
35
35
 
36
36
  const middlewareConfigSchema = yup.array().of(
37
- yup.lazy(value => {
37
+ yup.lazy((value) => {
38
38
  if (typeof value === 'string') {
39
39
  return yup.string().required();
40
40
  }
@@ -58,7 +58,7 @@ const middlewareConfigSchema = yup.array().of(
58
58
  * Register middlewares in router
59
59
  * @param {Strapi} strapi
60
60
  */
61
- const registerApplicationMiddlewares = async strapi => {
61
+ const registerApplicationMiddlewares = async (strapi) => {
62
62
  const middlewareConfig = strapi.config.get('middlewares', defaultConfig);
63
63
 
64
64
  await validateMiddlewareConfig(middlewareConfig);
@@ -78,7 +78,7 @@ const registerApplicationMiddlewares = async strapi => {
78
78
  *
79
79
  * @param {MiddlewaresConfig} config
80
80
  */
81
- const validateMiddlewareConfig = async config => {
81
+ const validateMiddlewareConfig = async (config) => {
82
82
  try {
83
83
  await middlewareConfigSchema.validate(config, { strict: true, abortEarly: false });
84
84
  } catch (error) {
@@ -92,9 +92,9 @@ const validateMiddlewareConfig = async config => {
92
92
  * Check if some required middlewares are missing in configure middlewares
93
93
  * @param {Middlewares} middlewares
94
94
  */
95
- const checkRequiredMiddlewares = middlewares => {
96
- const missingMiddlewares = requiredMiddlewares.filter(name => {
97
- return middlewares.findIndex(mdl => mdl.name === name) === -1;
95
+ const checkRequiredMiddlewares = (middlewares) => {
96
+ const missingMiddlewares = requiredMiddlewares.filter((name) => {
97
+ return middlewares.findIndex((mdl) => mdl.name === name) === -1;
98
98
  });
99
99
 
100
100
  if (missingMiddlewares.length > 0) {
@@ -104,8 +104,6 @@ const checkRequiredMiddlewares = middlewares => {
104
104
  )}".`
105
105
  );
106
106
  }
107
-
108
- return;
109
107
  };
110
108
 
111
109
  module.exports = registerApplicationMiddlewares;
@@ -2,7 +2,7 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
- const createRouteScopeGenerator = namespace => route => {
5
+ const createRouteScopeGenerator = (namespace) => (route) => {
6
6
  const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;
7
7
 
8
8
  if (typeof route.handler === 'string') {
@@ -20,7 +20,7 @@ const createRouteScopeGenerator = namespace => route => {
20
20
  * Register all routes
21
21
  * @param {import('../../').Strapi} strapi
22
22
  */
23
- module.exports = strapi => {
23
+ module.exports = (strapi) => {
24
24
  registerAdminRoutes(strapi);
25
25
  registerAPIRoutes(strapi);
26
26
  registerPluginRoutes(strapi);
@@ -30,10 +30,10 @@ module.exports = strapi => {
30
30
  * Register admin routes
31
31
  * @param {import('../../').Strapi} strapi
32
32
  */
33
- const registerAdminRoutes = strapi => {
33
+ const registerAdminRoutes = (strapi) => {
34
34
  const generateRouteScope = createRouteScopeGenerator(`admin::`);
35
35
 
36
- strapi.admin.routes.forEach(route => {
36
+ strapi.admin.routes.forEach((route) => {
37
37
  generateRouteScope(route);
38
38
  route.info = { pluginName: 'admin' };
39
39
  });
@@ -49,14 +49,14 @@ const registerAdminRoutes = strapi => {
49
49
  * Register plugin routes
50
50
  * @param {import('../../').Strapi} strapi
51
51
  */
52
- const registerPluginRoutes = strapi => {
52
+ const registerPluginRoutes = (strapi) => {
53
53
  for (const pluginName in strapi.plugins) {
54
54
  const plugin = strapi.plugins[pluginName];
55
55
 
56
56
  const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);
57
57
 
58
58
  if (Array.isArray(plugin.routes)) {
59
- plugin.routes.forEach(route => {
59
+ plugin.routes.forEach((route) => {
60
60
  generateRouteScope(route);
61
61
  route.info = { pluginName };
62
62
  });
@@ -67,10 +67,10 @@ const registerPluginRoutes = strapi => {
67
67
  routes: plugin.routes,
68
68
  });
69
69
  } else {
70
- _.forEach(plugin.routes, router => {
70
+ _.forEach(plugin.routes, (router) => {
71
71
  router.type = router.type || 'admin';
72
72
  router.prefix = `/${pluginName}`;
73
- router.routes.forEach(route => {
73
+ router.routes.forEach((route) => {
74
74
  generateRouteScope(route);
75
75
  route.info = { pluginName };
76
76
  });
@@ -85,17 +85,17 @@ const registerPluginRoutes = strapi => {
85
85
  * Register api routes
86
86
  * @param {import('../../').Strapi} strapi
87
87
  */
88
- const registerAPIRoutes = strapi => {
88
+ const registerAPIRoutes = (strapi) => {
89
89
  for (const apiName in strapi.api) {
90
90
  const api = strapi.api[apiName];
91
91
 
92
92
  const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
93
93
 
94
- _.forEach(api.routes, router => {
94
+ _.forEach(api.routes, (router) => {
95
95
  // TODO: remove once auth setup
96
96
  // pass meta down to compose endpoint
97
97
  router.type = 'content-api';
98
- router.routes.forEach(route => {
98
+ router.routes.forEach((route) => {
99
99
  generateRouteScope(route);
100
100
  route.info = { apiName };
101
101
  });
@@ -7,7 +7,7 @@ const { yup } = require('@strapi/utils');
7
7
 
8
8
  const createEndpointComposer = require('./compose-endpoint');
9
9
 
10
- const policyOrMiddlewareSchema = yup.lazy(value => {
10
+ const policyOrMiddlewareSchema = yup.lazy((value) => {
11
11
  if (typeof value === 'string') {
12
12
  return yup.string().required();
13
13
  }
@@ -23,12 +23,9 @@ const policyOrMiddlewareSchema = yup.lazy(value => {
23
23
  });
24
24
 
25
25
  const routeSchema = yup.object({
26
- method: yup
27
- .string()
28
- .oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL'])
29
- .required(),
26
+ method: yup.string().oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL']).required(),
30
27
  path: yup.string().required(),
31
- handler: yup.lazy(value => {
28
+ handler: yup.lazy((value) => {
32
29
  if (typeof value === 'string') {
33
30
  return yup.string().required();
34
31
  }
@@ -37,38 +34,26 @@ const routeSchema = yup.object({
37
34
  return yup.array().required();
38
35
  }
39
36
 
40
- return yup
41
- .mixed()
42
- .isFunction()
43
- .required();
37
+ return yup.mixed().isFunction().required();
44
38
  }),
45
39
  config: yup
46
40
  .object({
47
- auth: yup.lazy(value => {
41
+ auth: yup.lazy((value) => {
48
42
  if (value === false) {
49
43
  return yup.boolean().required();
50
44
  }
51
45
 
52
46
  return yup.object({
53
- scope: yup
54
- .array()
55
- .of(yup.string())
56
- .required(),
47
+ scope: yup.array().of(yup.string()).required(),
57
48
  });
58
49
  }),
59
- policies: yup
60
- .array()
61
- .of(policyOrMiddlewareSchema)
62
- .notRequired(),
63
- middlewares: yup
64
- .array()
65
- .of(policyOrMiddlewareSchema)
66
- .notRequired(),
50
+ policies: yup.array().of(policyOrMiddlewareSchema).notRequired(),
51
+ middlewares: yup.array().of(policyOrMiddlewareSchema).notRequired(),
67
52
  })
68
53
  .notRequired(),
69
54
  });
70
55
 
71
- const validateRouteConfig = routeConfig => {
56
+ const validateRouteConfig = (routeConfig) => {
72
57
  try {
73
58
  return routeSchema.validateSync(routeConfig, {
74
59
  strict: true,
@@ -96,11 +81,11 @@ const createRouteManager = (strapi, opts = {}) => {
96
81
 
97
82
  const addRoutes = (routes, router) => {
98
83
  if (Array.isArray(routes)) {
99
- routes.forEach(route => createRoute(route, router));
84
+ routes.forEach((route) => createRoute(route, router));
100
85
  } else if (routes.routes) {
101
86
  const subRouter = new Router({ prefix: routes.prefix });
102
87
 
103
- routes.routes.forEach(route => {
88
+ routes.routes.forEach((route) => {
104
89
  const hasPrefix = has('prefix', route.config);
105
90
  createRoute(route, hasPrefix ? router : subRouter);
106
91
  });
@@ -18,12 +18,12 @@ module.exports = async (uid, entity, files) => {
18
18
 
19
19
  const uploadService = strapi.plugin('upload').service('upload');
20
20
 
21
- const findModelFromUploadPath = path => {
21
+ const findModelFromUploadPath = (path) => {
22
22
  if (path.length === 0) {
23
23
  return uid;
24
24
  }
25
25
 
26
- let currentPath = [];
26
+ const currentPath = [];
27
27
  let tmpModel = modelDef;
28
28
  let modelUID = uid;
29
29
 
@@ -75,5 +75,5 @@ module.exports = async (uid, entity, files) => {
75
75
  }
76
76
  };
77
77
 
78
- await Promise.all(Object.keys(files).map(key => doUpload(key, files[key])));
78
+ await Promise.all(Object.keys(files).map((key) => doUpload(key, files[key])));
79
79
  };
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The event hub is Strapi's event control center.
3
3
  */
4
+
4
5
  'use strict';
5
6
 
6
7
  const debug = require('debug')('strapi:webhook');
@@ -51,7 +52,7 @@ class WebhookRunner {
51
52
  );
52
53
  }
53
54
 
54
- const listen = info => {
55
+ const listen = (info) => {
55
56
  this.queue.enqueue({ event, info });
56
57
  };
57
58
 
@@ -62,10 +63,10 @@ class WebhookRunner {
62
63
  async executeListener({ event, info }) {
63
64
  debug(`Executing webhook for event '${event}'`);
64
65
  const webhooks = this.webhooksMap.get(event) || [];
65
- const activeWebhooks = webhooks.filter(webhook => webhook.isEnabled === true);
66
+ const activeWebhooks = webhooks.filter((webhook) => webhook.isEnabled === true);
66
67
 
67
68
  for (const webhook of activeWebhooks) {
68
- await this.run(webhook, event, info).catch(error => {
69
+ await this.run(webhook, event, info).catch((error) => {
69
70
  this.logger.error('Error running webhook');
70
71
  this.logger.error(error);
71
72
  });
@@ -90,7 +91,7 @@ class WebhookRunner {
90
91
  },
91
92
  timeout: 10000,
92
93
  })
93
- .then(async res => {
94
+ .then(async (res) => {
94
95
  if (res.ok) {
95
96
  return {
96
97
  statusCode: res.status,
@@ -102,7 +103,7 @@ class WebhookRunner {
102
103
  message: await res.text(),
103
104
  };
104
105
  })
105
- .catch(err => {
106
+ .catch((err) => {
106
107
  return {
107
108
  statusCode: 500,
108
109
  message: err.message,
@@ -114,7 +115,7 @@ class WebhookRunner {
114
115
  debug(`Registering webhook '${webhook.id}'`);
115
116
  const { events } = webhook;
116
117
 
117
- events.forEach(event => {
118
+ events.forEach((event) => {
118
119
  if (this.webhooksMap.has(event)) {
119
120
  this.webhooksMap.get(event).push(webhook);
120
121
  } else {
@@ -134,7 +135,7 @@ class WebhookRunner {
134
135
  debug(`Unregistering webhook '${webhook.id}'`);
135
136
 
136
137
  this.webhooksMap.forEach((webhooks, event) => {
137
- const filteredWebhooks = webhooks.filter(value => value.id !== webhook.id);
138
+ const filteredWebhooks = webhooks.filter((value) => value.id !== webhook.id);
138
139
 
139
140
  // Cleanup hanging listeners
140
141
  if (filteredWebhooks.length === 0) {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Webhook store is the implementation of webhook storage over the core_store
3
3
  */
4
+
4
5
  'use strict';
5
6
 
6
7
  const webhookModel = {
@@ -25,7 +26,7 @@ const webhookModel = {
25
26
  },
26
27
  };
27
28
 
28
- const toDBObject = data => {
29
+ const toDBObject = (data) => {
29
30
  return {
30
31
  name: data.name,
31
32
  url: data.url,
@@ -35,7 +36,7 @@ const toDBObject = data => {
35
36
  };
36
37
  };
37
38
 
38
- const fromDBObject = row => {
39
+ const fromDBObject = (row) => {
39
40
  return {
40
41
  id: row.id,
41
42
  name: row.name,
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Simple worker queue in memory
3
3
  */
4
+
4
5
  'use strict';
5
6
 
6
7
  const debug = require('debug')('strapi:worker-queue');
@@ -2,7 +2,8 @@ import type Koa from 'koa';
2
2
  import { Database } from '@strapi/database';
3
3
 
4
4
  import type { StringMap } from './utils';
5
- import type { GenericController } from '../core-api/controller'
5
+ import type { GenericController } from '../../../core-api/controller'
6
+ import type { GenericService } from '../../../core-api/service'
6
7
 
7
8
  /**
8
9
  * The Strapi interface implemented by the main Strapi class.
@@ -33,12 +34,12 @@ export interface Strapi {
33
34
  *
34
35
  * It returns all the registered services
35
36
  */
36
- readonly services: StringMap<Service>;
37
+ readonly services: StringMap<GenericService>;
37
38
 
38
39
  /**
39
40
  * Find a service using its unique identifier
40
41
  */
41
- service<T extends Service = unknown>(uid: string): T | undefined;
42
+ service<T extends GenericService = GenericService>(uid: string): T | undefined;
42
43
 
43
44
  /**
44
45
  * Getter for the Strapi controllers container
@@ -1,4 +1,4 @@
1
- import { Service } from '../core-api/service';
1
+ import { Service,GenericService } from '../core-api/service';
2
2
  import { Controller, GenericController } from '../core-api/controller';
3
3
  import { Middleware } from '../middlewares';
4
4
  import { Policy } from '../core/registries/policies';
@@ -47,14 +47,14 @@ interface Router {
47
47
  type ControllerCallback<T extends GenericController = GenericController> = (params: {
48
48
  strapi: Strapi;
49
49
  }) => T;
50
- type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
50
+ type ServiceCallback<T extends GenericService = GenericService> = (params: { strapi: Strapi }) => T;
51
51
 
52
52
  export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
53
53
  export function createCoreController<T extends GenericController = GenericController>(
54
54
  uid: string,
55
55
  cfg?: ControllerCallback<T> | T = {}
56
56
  ): () => T & Controller;
57
- export function createCoreService<T extends Service = Service>(
57
+ export function createCoreService<T extends GenericService = GenericService>(
58
58
  uid: string,
59
59
  cfg?: ServiceCallback<T> | T = {}
60
60
  ): () => T;