@strapi/strapi 4.0.0-next.6 → 4.0.0
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/README.md +12 -12
- package/bin/strapi.js +41 -60
- package/lib/Strapi.js +234 -114
- package/lib/commands/build.js +16 -6
- package/lib/commands/console.js +1 -1
- package/lib/commands/content-types/list.js +22 -0
- package/lib/commands/develop.js +17 -18
- package/lib/commands/generate-template.js +4 -5
- package/lib/commands/hooks/list.js +22 -0
- package/lib/commands/middlewares/list.js +22 -0
- package/lib/commands/new.js +3 -1
- package/lib/commands/policies/list.js +22 -0
- package/lib/commands/routes/list.js +28 -0
- package/lib/commands/services/list.js +22 -0
- package/lib/commands/watchAdmin.js +18 -8
- package/lib/container.js +6 -6
- package/lib/core/app-configuration/config-loader.js +1 -37
- package/lib/core/app-configuration/index.js +6 -46
- package/lib/core/app-configuration/load-config-file.js +43 -0
- package/lib/core/bootstrap.js +5 -117
- package/lib/core/domain/component/index.js +24 -0
- package/lib/core/domain/component/validator.js +29 -0
- package/lib/core/domain/content-type/index.js +140 -0
- package/lib/core/domain/content-type/validator.js +64 -0
- package/lib/core/domain/module/index.js +108 -0
- package/lib/core/domain/module/validation.js +33 -0
- package/lib/core/loaders/admin.js +16 -0
- package/lib/core/loaders/apis.js +159 -0
- package/lib/core/{load-components.js → loaders/components.js} +5 -7
- package/lib/core/loaders/index.js +11 -0
- package/lib/core/loaders/middlewares.js +36 -0
- package/lib/core/loaders/plugins/get-enabled-plugins.js +116 -0
- package/lib/core/loaders/plugins/index.js +123 -0
- package/lib/core/loaders/policies.js +28 -0
- package/lib/core/loaders/src-index.js +39 -0
- package/lib/core/registries/apis.js +29 -0
- package/lib/core/{app-configuration/config-provider.js → registries/config.js} +4 -11
- package/lib/core/registries/content-types.js +97 -0
- package/lib/core/registries/controllers.d.ts +7 -0
- package/lib/core/registries/controllers.js +114 -0
- package/lib/core/registries/hooks.d.ts +20 -0
- package/lib/core/registries/hooks.js +87 -0
- package/lib/core/registries/middlewares.d.ts +5 -0
- package/lib/core/registries/middlewares.js +89 -0
- package/lib/core/registries/modules.js +44 -0
- package/lib/core/registries/plugins.js +28 -0
- package/lib/core/registries/policies.d.ts +9 -0
- package/lib/core/registries/policies.js +89 -0
- package/lib/core/registries/services.d.ts +7 -0
- package/lib/core/registries/services.js +114 -0
- package/lib/core/utils.js +35 -0
- package/lib/core-api/controller/collection-type.js +45 -26
- package/lib/core-api/controller/index.d.ts +25 -0
- package/lib/core-api/controller/index.js +33 -11
- package/lib/core-api/controller/single-type.js +29 -15
- package/lib/core-api/controller/transform.js +62 -6
- package/lib/core-api/routes/index.js +71 -0
- package/lib/core-api/service/collection-type.js +43 -21
- package/lib/core-api/service/index.d.ts +21 -0
- package/lib/core-api/service/index.js +8 -67
- package/lib/core-api/service/pagination.js +130 -0
- package/lib/core-api/service/single-type.js +17 -19
- package/lib/factories.d.ts +48 -0
- package/lib/factories.js +84 -0
- package/lib/index.d.ts +10 -31
- package/lib/index.js +5 -1
- package/lib/middlewares/body.js +33 -0
- package/lib/middlewares/compression.js +8 -0
- package/lib/middlewares/cors.js +58 -0
- package/lib/middlewares/errors.js +40 -0
- package/lib/middlewares/favicon.js +19 -0
- package/lib/middlewares/index.d.ts +5 -0
- package/lib/middlewares/index.js +30 -117
- package/lib/middlewares/ip.js +8 -0
- package/lib/middlewares/logger.js +27 -0
- package/lib/middlewares/powered-by.js +20 -0
- package/lib/middlewares/public/index.js +98 -73
- package/lib/middlewares/query.js +46 -0
- package/lib/middlewares/response-time.js +15 -0
- package/lib/middlewares/responses.js +19 -0
- package/lib/middlewares/security.js +51 -0
- package/lib/middlewares/session/index.js +6 -6
- package/lib/migrations/draft-publish.js +57 -0
- package/lib/services/auth/index.js +87 -0
- package/lib/services/core-store.js +64 -51
- package/lib/services/cron.js +54 -0
- package/lib/services/entity-service/attributes/index.js +31 -0
- package/lib/services/entity-service/attributes/transforms.js +20 -0
- package/lib/services/entity-service/components.js +39 -15
- package/lib/services/entity-service/index.d.ts +91 -0
- package/lib/services/entity-service/index.js +120 -59
- package/lib/services/entity-service/params.js +52 -94
- package/lib/services/entity-validator/index.js +76 -43
- package/lib/services/entity-validator/validators.js +129 -43
- package/lib/services/errors.js +77 -0
- package/lib/{core → services}/fs.js +10 -2
- package/lib/services/metrics/index.js +41 -38
- package/lib/services/metrics/sender.js +2 -2
- package/lib/services/server/admin-api.js +14 -0
- package/lib/services/server/api.js +36 -0
- package/lib/services/server/compose-endpoint.js +141 -0
- package/lib/services/server/content-api.js +16 -0
- package/lib/{server.js → services/server/http-server.js} +0 -0
- package/lib/services/server/index.js +127 -0
- package/lib/services/server/koa.js +64 -0
- package/lib/services/server/middleware.js +122 -0
- package/lib/services/server/policy.js +32 -0
- package/lib/services/server/register-middlewares.js +110 -0
- package/lib/services/server/register-routes.js +106 -0
- package/lib/services/server/routing.js +120 -0
- package/lib/services/utils/upload-files.js +1 -1
- package/lib/services/webhook-runner.js +1 -1
- package/lib/utils/ee.js +3 -3
- package/lib/utils/get-dirs.js +17 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/is-initialized.js +1 -1
- package/lib/utils/run-checks.js +0 -15
- package/lib/utils/signals.js +24 -0
- package/lib/utils/startup-logger.js +2 -2
- package/lib/utils/update-notifier/index.js +3 -2
- package/package.json +93 -96
- package/lib/commands/generate.js +0 -76
- package/lib/core/index.js +0 -17
- package/lib/core/load-apis.js +0 -20
- package/lib/core/load-extensions.js +0 -71
- package/lib/core/load-functions.js +0 -21
- package/lib/core/load-middlewares.js +0 -130
- package/lib/core/load-modules.js +0 -55
- package/lib/core/load-plugins.js +0 -68
- package/lib/core/load-policies.js +0 -36
- package/lib/core/walk.js +0 -27
- package/lib/core-api/index.js +0 -39
- package/lib/load/check-reserved-filename.js +0 -10
- package/lib/load/load-config-files.js +0 -22
- package/lib/load/require-file-parse.js +0 -15
- package/lib/middlewares/boom/defaults.json +0 -5
- package/lib/middlewares/boom/index.js +0 -147
- package/lib/middlewares/cors/index.js +0 -66
- package/lib/middlewares/cron/defaults.json +0 -5
- package/lib/middlewares/cron/index.js +0 -43
- package/lib/middlewares/favicon/defaults.json +0 -7
- package/lib/middlewares/favicon/index.js +0 -32
- package/lib/middlewares/gzip/defaults.json +0 -6
- package/lib/middlewares/gzip/index.js +0 -19
- package/lib/middlewares/helmet/defaults.json +0 -18
- package/lib/middlewares/helmet/index.js +0 -9
- package/lib/middlewares/ip/defaults.json +0 -7
- package/lib/middlewares/ip/index.js +0 -25
- package/lib/middlewares/language/defaults.json +0 -9
- package/lib/middlewares/language/index.js +0 -40
- package/lib/middlewares/logger/defaults.json +0 -5
- package/lib/middlewares/logger/index.js +0 -37
- package/lib/middlewares/parser/defaults.json +0 -11
- package/lib/middlewares/parser/index.js +0 -71
- package/lib/middlewares/poweredBy/defaults.json +0 -5
- package/lib/middlewares/poweredBy/index.js +0 -16
- package/lib/middlewares/public/defaults.json +0 -8
- package/lib/middlewares/responseTime/defaults.json +0 -5
- package/lib/middlewares/responseTime/index.js +0 -25
- package/lib/middlewares/responses/defaults.json +0 -5
- package/lib/middlewares/responses/index.js +0 -18
- package/lib/middlewares/router/defaults.json +0 -7
- package/lib/middlewares/router/index.js +0 -64
- package/lib/middlewares/router/utils/composeEndpoint.js +0 -25
- package/lib/middlewares/router/utils/routerChecker.js +0 -92
- package/lib/utils/get-prefixed-dependencies.js +0 -7
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const body = require('koa-body');
|
|
4
|
-
const qs = require('qs');
|
|
5
|
-
const { omit } = require('lodash');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Body parser hook
|
|
9
|
-
*/
|
|
10
|
-
const addQsParser = (app, settings) => {
|
|
11
|
-
Object.defineProperty(app.request, 'query', {
|
|
12
|
-
configurable: false,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
/*
|
|
15
|
-
* Get parsed query-string.
|
|
16
|
-
*/
|
|
17
|
-
get() {
|
|
18
|
-
const qstr = this.querystring;
|
|
19
|
-
const cache = (this._querycache = this._querycache || {});
|
|
20
|
-
return cache[qstr] || (cache[qstr] = qs.parse(qstr, settings));
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/*
|
|
24
|
-
* Set query-string as an object.
|
|
25
|
-
*/
|
|
26
|
-
set(obj) {
|
|
27
|
-
this.querystring = qs.stringify(obj);
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return app;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports = strapi => {
|
|
35
|
-
return {
|
|
36
|
-
/**
|
|
37
|
-
* Initialize the hook
|
|
38
|
-
*/
|
|
39
|
-
initialize() {
|
|
40
|
-
strapi.app.use(async (ctx, next) => {
|
|
41
|
-
// disable for graphql
|
|
42
|
-
// TODO: find a better way later
|
|
43
|
-
if (ctx.url === '/graphql') {
|
|
44
|
-
return next();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const res = await body({
|
|
49
|
-
patchKoa: true,
|
|
50
|
-
...omit(strapi.config.middleware.settings.parser, 'queryStringParser'),
|
|
51
|
-
})(ctx, next);
|
|
52
|
-
return res;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
if ((e || {}).message && e.message.includes('maxFileSize exceeded')) {
|
|
55
|
-
throw strapi.errors.entityTooLarge('FileTooBig', {
|
|
56
|
-
errors: [
|
|
57
|
-
{
|
|
58
|
-
id: 'Upload.status.sizeLimit',
|
|
59
|
-
message: `file is bigger than the limit size!`,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
throw e;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
addQsParser(strapi.app, strapi.config.get('middleware.settings.parser.queryStringParser'));
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = strapi => {
|
|
4
|
-
return {
|
|
5
|
-
initialize() {
|
|
6
|
-
strapi.app.use(async (ctx, next) => {
|
|
7
|
-
await next();
|
|
8
|
-
|
|
9
|
-
ctx.set(
|
|
10
|
-
'X-Powered-By',
|
|
11
|
-
strapi.config.get('middleware.settings.poweredBy.value', 'Strapi <strapi.io>')
|
|
12
|
-
);
|
|
13
|
-
});
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* X-Response-Time hook
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
module.exports = strapi => {
|
|
8
|
-
return {
|
|
9
|
-
/**
|
|
10
|
-
* Initialize the hook
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
initialize() {
|
|
14
|
-
strapi.app.use(async (ctx, next) => {
|
|
15
|
-
const start = Date.now();
|
|
16
|
-
|
|
17
|
-
await next();
|
|
18
|
-
|
|
19
|
-
const delta = Math.ceil(Date.now() - start);
|
|
20
|
-
|
|
21
|
-
ctx.set('X-Response-Time', delta + 'ms'); // eslint-disable-line prefer-template
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
module.exports = strapi => {
|
|
6
|
-
return {
|
|
7
|
-
initialize() {
|
|
8
|
-
strapi.app.use(async (ctx, next) => {
|
|
9
|
-
await next();
|
|
10
|
-
|
|
11
|
-
const responseFn = strapi.config.get(['functions', 'responses', ctx.status]);
|
|
12
|
-
if (_.isFunction(responseFn)) {
|
|
13
|
-
await responseFn(ctx);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Public node modules.
|
|
8
|
-
const _ = require('lodash');
|
|
9
|
-
const Router = require('koa-router');
|
|
10
|
-
const createEndpointComposer = require('./utils/composeEndpoint');
|
|
11
|
-
/**
|
|
12
|
-
* Router hook
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
module.exports = strapi => {
|
|
16
|
-
const composeEndpoint = createEndpointComposer(strapi);
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
/**
|
|
20
|
-
* Initialize the hook
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
initialize() {
|
|
24
|
-
_.forEach(strapi.config.routes, value => {
|
|
25
|
-
composeEndpoint(value, { router: strapi.router });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
strapi.router.prefix(strapi.config.get('middleware.settings.router.prefix', ''));
|
|
29
|
-
|
|
30
|
-
if (_.has(strapi.admin, 'config.routes')) {
|
|
31
|
-
const router = new Router({
|
|
32
|
-
prefix: '/admin',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
_.get(strapi.admin, 'config.routes', []).forEach(route => {
|
|
36
|
-
composeEndpoint(route, { plugin: 'admin', router });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Mount admin router on Strapi router
|
|
40
|
-
strapi.app.use(router.routes()).use(router.allowedMethods());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (strapi.plugins) {
|
|
44
|
-
// Parse each plugin's routes.
|
|
45
|
-
_.forEach(strapi.plugins, (plugin, pluginName) => {
|
|
46
|
-
const router = new Router({
|
|
47
|
-
prefix: `/${pluginName}`,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
(plugin.config.routes || []).forEach(route => {
|
|
51
|
-
const hasPrefix = _.has(route.config, 'prefix');
|
|
52
|
-
composeEndpoint(route, {
|
|
53
|
-
plugin: pluginName,
|
|
54
|
-
router: hasPrefix ? strapi.router : router,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Mount plugin router
|
|
59
|
-
strapi.app.use(router.routes()).use(router.allowedMethods());
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const compose = require('koa-compose');
|
|
5
|
-
const createRouteChecker = require('./routerChecker');
|
|
6
|
-
|
|
7
|
-
module.exports = strapi => {
|
|
8
|
-
const routerChecker = createRouteChecker(strapi);
|
|
9
|
-
|
|
10
|
-
return (value, { plugin, router }) => {
|
|
11
|
-
if (_.isEmpty(_.get(value, 'method')) || _.isEmpty(_.get(value, 'path'))) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const { method, endpoint, policies, action } = routerChecker(value, plugin);
|
|
16
|
-
|
|
17
|
-
if (_.isUndefined(action) || !_.isFunction(action)) {
|
|
18
|
-
return strapi.log.warn(
|
|
19
|
-
`Ignored attempt to bind route '${value.method} ${value.path}' to unknown controller/action.`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
router[method](endpoint, compose(policies), action);
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Public node modules.
|
|
8
|
-
const _ = require('lodash');
|
|
9
|
-
|
|
10
|
-
// Strapi utilities.
|
|
11
|
-
const { finder, policy: policyUtils } = require('@strapi/utils');
|
|
12
|
-
|
|
13
|
-
const getMethod = route => _.trim(_.toLower(route.method));
|
|
14
|
-
const getEndpoint = route => _.trim(route.path);
|
|
15
|
-
|
|
16
|
-
module.exports = strapi =>
|
|
17
|
-
function routerChecker(value, plugin) {
|
|
18
|
-
const method = getMethod(value);
|
|
19
|
-
const endpoint = getEndpoint(value);
|
|
20
|
-
|
|
21
|
-
// Define controller and action names.
|
|
22
|
-
const [controllerName, actionName] = _.trim(value.handler).split('.');
|
|
23
|
-
const controllerKey = _.toLower(controllerName);
|
|
24
|
-
|
|
25
|
-
let controller;
|
|
26
|
-
|
|
27
|
-
if (plugin) {
|
|
28
|
-
controller =
|
|
29
|
-
plugin === 'admin'
|
|
30
|
-
? strapi.admin.controllers[controllerKey]
|
|
31
|
-
: strapi.plugins[plugin].controllers[controllerKey];
|
|
32
|
-
} else {
|
|
33
|
-
controller = strapi.controllers[controllerKey];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!_.isFunction(controller[actionName])) {
|
|
37
|
-
strapi.stopWithError(
|
|
38
|
-
`Error creating endpoint ${method} ${endpoint}: handler not found "${controllerKey}.${actionName}"`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const action = controller[actionName].bind(controller);
|
|
43
|
-
|
|
44
|
-
// Retrieve the API's name where the controller is located
|
|
45
|
-
// to access to the right validators
|
|
46
|
-
const currentApiName = finder(strapi.plugins[plugin] || strapi.api || strapi.admin, controller);
|
|
47
|
-
|
|
48
|
-
// Add the `globalPolicy`.
|
|
49
|
-
const globalPolicy = policyUtils.globalPolicy({
|
|
50
|
-
controller: controllerKey,
|
|
51
|
-
action: actionName,
|
|
52
|
-
method,
|
|
53
|
-
endpoint,
|
|
54
|
-
plugin,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Init policies array.
|
|
58
|
-
const policies = [globalPolicy];
|
|
59
|
-
|
|
60
|
-
let policyOption = _.get(value, 'config.policies');
|
|
61
|
-
|
|
62
|
-
// Allow string instead of array of policies.
|
|
63
|
-
if (_.isString(policyOption) && !_.isEmpty(policyOption)) {
|
|
64
|
-
policyOption = [policyOption];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (_.isArray(policyOption)) {
|
|
68
|
-
policyOption.forEach(policyName => {
|
|
69
|
-
try {
|
|
70
|
-
policies.push(policyUtils.get(policyName, plugin, currentApiName));
|
|
71
|
-
} catch (error) {
|
|
72
|
-
strapi.stopWithError(`Error creating endpoint ${method} ${endpoint}: ${error.message}`);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
policies.push(async (ctx, next) => {
|
|
78
|
-
// Set body.
|
|
79
|
-
const values = await next();
|
|
80
|
-
|
|
81
|
-
if (_.isNil(ctx.body) && !_.isNil(values)) {
|
|
82
|
-
ctx.body = values;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
method,
|
|
88
|
-
endpoint,
|
|
89
|
-
policies,
|
|
90
|
-
action,
|
|
91
|
-
};
|
|
92
|
-
};
|