@strapi/strapi 4.0.0-next.8 → 4.0.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.
- package/README.md +14 -14
- package/bin/strapi.js +46 -60
- package/lib/Strapi.js +152 -74
- package/lib/commands/build.js +19 -8
- package/lib/commands/console.js +1 -1
- package/lib/commands/content-types/list.js +22 -0
- package/lib/commands/controllers/list.js +22 -0
- package/lib/commands/develop.js +22 -27
- 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 -9
- package/lib/core/app-configuration/index.js +3 -19
- package/lib/core/bootstrap.js +3 -95
- package/lib/core/domain/content-type/index.js +5 -11
- package/lib/core/domain/module/index.js +42 -11
- package/lib/core/domain/module/validation.js +16 -19
- package/lib/core/loaders/admin.js +2 -2
- package/lib/core/loaders/apis.js +148 -9
- package/lib/core/loaders/components.js +4 -6
- package/lib/core/loaders/index.js +1 -0
- package/lib/core/loaders/middlewares.js +23 -123
- package/lib/core/loaders/plugins/get-enabled-plugins.js +55 -19
- package/lib/core/loaders/plugins/get-user-plugins-config.js +37 -0
- package/lib/core/loaders/plugins/index.js +30 -16
- package/lib/core/loaders/policies.js +1 -1
- package/lib/core/loaders/src-index.js +39 -0
- package/lib/core/registries/apis.js +29 -0
- package/lib/core/registries/content-types.js +61 -12
- package/lib/core/registries/controllers.d.ts +7 -0
- package/lib/core/registries/controllers.js +91 -7
- 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 +64 -5
- package/lib/core/registries/modules.js +3 -3
- package/lib/core/registries/plugins.js +2 -2
- package/lib/core/registries/policies.d.ts +9 -0
- package/lib/core/registries/policies.js +64 -5
- package/lib/core/registries/services.d.ts +7 -0
- package/lib/core/registries/services.js +86 -17
- package/lib/core/utils.js +22 -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 +125 -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 -116
- 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 +72 -77
- 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 -49
- 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 +118 -60
- 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 +131 -43
- package/lib/services/errors.js +77 -0
- package/lib/services/fs.js +1 -1
- package/lib/services/metrics/index.js +38 -36
- 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/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/signals.js +24 -0
- package/lib/utils/update-notifier/index.js +2 -1
- package/package.json +94 -97
- package/lib/commands/generate.js +0 -76
- package/lib/core/app-configuration/load-functions.js +0 -28
- 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 -58
- package/lib/middlewares/router/utils/composeEndpoint.js +0 -177
- package/lib/utils/get-prefixed-dependencies.js +0 -7
|
@@ -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,58 +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
|
-
module.exports = strapi => {
|
|
13
|
-
const composeEndpoint = createEndpointComposer(strapi);
|
|
14
|
-
|
|
15
|
-
const registerAdminRoutes = () => {
|
|
16
|
-
const router = new Router({ prefix: '/admin' });
|
|
17
|
-
|
|
18
|
-
for (const route of strapi.admin.routes) {
|
|
19
|
-
composeEndpoint(route, { plugin: 'admin', router });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
strapi.app.use(router.routes()).use(router.allowedMethods());
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const registerPluginRoutes = () => {
|
|
26
|
-
for (const pluginName in strapi.plugins) {
|
|
27
|
-
const plugin = strapi.plugins[pluginName];
|
|
28
|
-
|
|
29
|
-
const router = new Router({ prefix: `/${pluginName}` });
|
|
30
|
-
|
|
31
|
-
for (const route of plugin.routes || []) {
|
|
32
|
-
const hasPrefix = _.has(route.config, 'prefix');
|
|
33
|
-
composeEndpoint(route, {
|
|
34
|
-
plugin: pluginName,
|
|
35
|
-
router: hasPrefix ? strapi.router : router,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
strapi.app.use(router.routes()).use(router.allowedMethods());
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const registerAPIRoutes = () => {
|
|
44
|
-
strapi.router.prefix(strapi.config.get('middleware.settings.router.prefix', ''));
|
|
45
|
-
|
|
46
|
-
for (const route of strapi.config.routes) {
|
|
47
|
-
composeEndpoint(route, { router: strapi.router });
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
initialize() {
|
|
53
|
-
registerAPIRoutes();
|
|
54
|
-
registerAdminRoutes();
|
|
55
|
-
registerPluginRoutes();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
};
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const compose = require('koa-compose');
|
|
5
|
-
const { yup } = require('@strapi/utils');
|
|
6
|
-
|
|
7
|
-
const policyOrMiddlewareSchema = yup.lazy(value => {
|
|
8
|
-
if (typeof value === 'string') {
|
|
9
|
-
return yup.string().required();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof value === 'function') {
|
|
13
|
-
return yup.mixed().isFunction();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return yup.object({
|
|
17
|
-
name: yup.string().required(),
|
|
18
|
-
options: yup.object().notRequired(), // any options
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const routeSchema = yup.object({
|
|
23
|
-
method: yup
|
|
24
|
-
.string()
|
|
25
|
-
.oneOf(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ALL'])
|
|
26
|
-
.required(),
|
|
27
|
-
path: yup.string().required(),
|
|
28
|
-
handler: yup.lazy(value => {
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
return yup.string().required();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return yup
|
|
34
|
-
.mixed()
|
|
35
|
-
.isFunction()
|
|
36
|
-
.required();
|
|
37
|
-
}),
|
|
38
|
-
config: yup
|
|
39
|
-
.object({
|
|
40
|
-
policies: yup
|
|
41
|
-
.array()
|
|
42
|
-
.of(policyOrMiddlewareSchema)
|
|
43
|
-
.notRequired(),
|
|
44
|
-
middlwares: yup
|
|
45
|
-
.array()
|
|
46
|
-
.of(policyOrMiddlewareSchema)
|
|
47
|
-
.notRequired(),
|
|
48
|
-
})
|
|
49
|
-
.notRequired(),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const validateRouteConfig = routeConfig => {
|
|
53
|
-
try {
|
|
54
|
-
return routeSchema.validateSync(routeConfig, {
|
|
55
|
-
strict: true,
|
|
56
|
-
abortEarly: false,
|
|
57
|
-
stripUnknown: true,
|
|
58
|
-
});
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error(error);
|
|
61
|
-
throw new Error('Invalid route config');
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Strapi utilities.
|
|
66
|
-
const { finder, policy: policyUtils } = require('@strapi/utils');
|
|
67
|
-
|
|
68
|
-
module.exports = strapi => {
|
|
69
|
-
const routerChecker = createRouteChecker(strapi);
|
|
70
|
-
|
|
71
|
-
return (routeConfig, { plugin, router }) => {
|
|
72
|
-
validateRouteConfig(routeConfig);
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const middlewares = resolveMiddlewares(routeConfig);
|
|
76
|
-
|
|
77
|
-
const { method, endpoint, policies, action } = routerChecker(routeConfig, plugin);
|
|
78
|
-
|
|
79
|
-
if (_.isUndefined(action) || !_.isFunction(action)) {
|
|
80
|
-
return strapi.log.warn(
|
|
81
|
-
`Ignored attempt to bind route '${routeConfig.method} ${routeConfig.path}' to unknown controller/action.`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
router[method](endpoint, compose([...policies, ...middlewares, action]));
|
|
86
|
-
} catch (error) {
|
|
87
|
-
throw new Error(
|
|
88
|
-
`Error creating endpoint ${routeConfig.method} ${routeConfig.path}: ${error.message}`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const resolveMiddlewares = route => {
|
|
95
|
-
const middlewaresConfig = _.get(route, 'config.middlewares', []);
|
|
96
|
-
|
|
97
|
-
return middlewaresConfig.map(middlewareConfig => {
|
|
98
|
-
if (typeof middlewareConfig === 'function') {
|
|
99
|
-
return middlewareConfig;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const middleware = strapi.middleware(middlewareConfig);
|
|
103
|
-
|
|
104
|
-
if (!middleware) {
|
|
105
|
-
throw new Error(`Middleware ${middlewareConfig} not found.`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return middleware;
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const getMethod = route => _.trim(_.toLower(route.method));
|
|
113
|
-
const getEndpoint = route => _.trim(route.path);
|
|
114
|
-
|
|
115
|
-
const createRouteChecker = strapi => {
|
|
116
|
-
return (value, plugin) => {
|
|
117
|
-
const method = getMethod(value);
|
|
118
|
-
const endpoint = getEndpoint(value);
|
|
119
|
-
|
|
120
|
-
// Define controller and action names.
|
|
121
|
-
const [controllerName, actionName] = _.trim(value.handler).split('.');
|
|
122
|
-
const controllerKey = _.toLower(controllerName);
|
|
123
|
-
|
|
124
|
-
let controller;
|
|
125
|
-
|
|
126
|
-
if (plugin) {
|
|
127
|
-
if (plugin === 'admin') {
|
|
128
|
-
controller = strapi.admin.controllers[controllerKey];
|
|
129
|
-
} else {
|
|
130
|
-
controller = strapi.plugin(plugin).controller(controllerKey);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
controller = strapi.controllers[controllerKey];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!_.isFunction(controller[actionName])) {
|
|
137
|
-
strapi.stopWithError(
|
|
138
|
-
`Error creating endpoint ${method} ${endpoint}: handler not found "${controllerKey}.${actionName}"`
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const action = controller[actionName].bind(controller);
|
|
143
|
-
|
|
144
|
-
// Retrieve the API's name where the controller is located
|
|
145
|
-
// to access to the right validators
|
|
146
|
-
const currentApiName = finder(
|
|
147
|
-
strapi.plugin(plugin) || strapi.api || strapi.admin,
|
|
148
|
-
controllerKey
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
const { bodyPolicy } = policyUtils;
|
|
152
|
-
|
|
153
|
-
const globalPolicy = policyUtils.globalPolicy({
|
|
154
|
-
controller: controllerKey,
|
|
155
|
-
action: actionName,
|
|
156
|
-
method,
|
|
157
|
-
endpoint,
|
|
158
|
-
plugin,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const policyOption = _.get(value, 'config.policies', []);
|
|
162
|
-
|
|
163
|
-
const routePolicies = policyOption.map(policyConfig => {
|
|
164
|
-
return policyUtils.get(policyConfig, plugin, currentApiName);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Init policies array.
|
|
168
|
-
const policies = [globalPolicy, ...routePolicies, bodyPolicy];
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
method,
|
|
172
|
-
endpoint,
|
|
173
|
-
policies,
|
|
174
|
-
action,
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
};
|