@strapi/strapi 4.2.0-beta.0 → 4.2.0-beta.3
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 +2 -3
- package/bin/strapi.js +7 -0
- package/lib/Strapi.js +22 -4
- package/lib/commands/admin-create.js +15 -1
- package/lib/commands/admin-reset.js +15 -1
- package/lib/commands/build.js +4 -5
- package/lib/commands/builders/admin.js +4 -3
- package/lib/commands/builders/typescript.js +3 -6
- package/lib/commands/configurationDump.js +14 -1
- package/lib/commands/configurationRestore.js +16 -1
- package/lib/commands/console.js +16 -2
- package/lib/commands/develop.js +10 -4
- package/lib/commands/opt-out-telemetry.js +83 -0
- package/lib/commands/routes/list.js +15 -1
- package/lib/commands/start.js +12 -2
- package/lib/commands/watchAdmin.js +3 -4
- package/lib/core/app-configuration/index.js +5 -3
- package/lib/core/bootstrap.js +9 -1
- package/lib/core/loaders/apis.js +13 -9
- package/lib/core/loaders/index.js +1 -0
- package/lib/core/loaders/plugins/get-enabled-plugins.js +1 -6
- package/lib/core/loaders/sanitizers.js +5 -0
- package/lib/core/registries/policies.d.ts +1 -1
- package/lib/core/registries/sanitizers.js +26 -0
- package/lib/core-api/controller/index.d.ts +14 -9
- package/lib/core-api/service/index.d.ts +10 -9
- package/lib/factories.d.ts +21 -17
- package/lib/index.d.ts +7 -6
- package/lib/middlewares/body.js +38 -10
- package/lib/middlewares/public/index.js +1 -1
- package/lib/middlewares/session.js +3 -1
- package/lib/services/entity-validator/validators.js +3 -1
- package/lib/services/metrics/index.js +7 -1
- package/lib/services/metrics/sender.js +7 -0
- package/lib/services/server/index.js +1 -1
- package/lib/types/strapi.d.ts +291 -0
- package/lib/types/utils.d.ts +1 -0
- package/lib/utils/get-dirs.js +5 -4
- package/lib/utils/update-notifier/index.js +2 -2
- package/package.json +14 -13
|
@@ -29,15 +29,11 @@ const toDetailedDeclaration = declaration => {
|
|
|
29
29
|
let detailedDeclaration = pick(['enabled'], declaration);
|
|
30
30
|
if (has('resolve', declaration)) {
|
|
31
31
|
let pathToPlugin = '';
|
|
32
|
-
let appPathToPlugin = '';
|
|
33
32
|
|
|
34
33
|
try {
|
|
35
34
|
pathToPlugin = dirname(require.resolve(declaration.resolve));
|
|
36
|
-
appPathToPlugin = pathToPlugin;
|
|
37
35
|
} catch (e) {
|
|
38
|
-
|
|
39
|
-
pathToPlugin = resolve(strapi.dirs.dist.root, declaration.resolve);
|
|
40
|
-
appPathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);
|
|
36
|
+
pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);
|
|
41
37
|
|
|
42
38
|
if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {
|
|
43
39
|
throw new Error(`${declaration.resolve} couldn't be resolved`);
|
|
@@ -45,7 +41,6 @@ const toDetailedDeclaration = declaration => {
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
detailedDeclaration.pathToPlugin = pathToPlugin;
|
|
48
|
-
detailedDeclaration.appPathToPlugin = appPathToPlugin;
|
|
49
44
|
}
|
|
50
45
|
return detailedDeclaration;
|
|
51
46
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
const sanitizersRegistry = () => {
|
|
6
|
+
const sanitizers = {};
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
get(path) {
|
|
10
|
+
return _.get(sanitizers, path, []);
|
|
11
|
+
},
|
|
12
|
+
add(path, sanitizer) {
|
|
13
|
+
this.get(path).push(sanitizer);
|
|
14
|
+
return this;
|
|
15
|
+
},
|
|
16
|
+
set(path, value = []) {
|
|
17
|
+
_.set(sanitizers, path, value);
|
|
18
|
+
return this;
|
|
19
|
+
},
|
|
20
|
+
has(path) {
|
|
21
|
+
return _.has(sanitizers, path);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = sanitizersRegistry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from 'koa';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type ControllerResponse <T=unknown> = T | Promise<T>;
|
|
4
4
|
|
|
5
5
|
interface BaseController {
|
|
6
6
|
transformResponse(data: object, meta: object): object;
|
|
@@ -9,17 +9,22 @@ interface BaseController {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface SingleTypeController extends BaseController {
|
|
12
|
-
find(ctx: Context):
|
|
13
|
-
update(ctx: Context):
|
|
14
|
-
delete(ctx: Context):
|
|
12
|
+
find(ctx: Context): ControllerResponse;
|
|
13
|
+
update(ctx: Context): ControllerResponse;
|
|
14
|
+
delete(ctx: Context): ControllerResponse;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface CollectionTypeController extends BaseController {
|
|
18
|
-
find(ctx: Context):
|
|
19
|
-
findOne(ctx: Context):
|
|
20
|
-
create(ctx: Context):
|
|
21
|
-
update(ctx: Context):
|
|
22
|
-
delete(ctx: Context):
|
|
18
|
+
find(ctx: Context): ControllerResponse;
|
|
19
|
+
findOne(ctx: Context): ControllerResponse
|
|
20
|
+
create(ctx: Context): ControllerResponse;
|
|
21
|
+
update(ctx: Context): ControllerResponse;
|
|
22
|
+
delete(ctx: Context): ControllerResponse;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type Controller = SingleTypeController | CollectionTypeController;
|
|
26
|
+
|
|
27
|
+
export type GenericController = Partial<Controller> & {
|
|
28
|
+
[method: string | number | symbol]: (ctx: Context) => unknown
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
type Entity = object;
|
|
2
2
|
|
|
3
3
|
interface BaseService {
|
|
4
|
-
getFetchParams(params: object): object;
|
|
4
|
+
getFetchParams?(params: object): object;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface SingleTypeService extends BaseService {
|
|
8
|
-
find(params: object): Promise<Entity
|
|
9
|
-
createOrUpdate(params: object): Promise<Entity
|
|
10
|
-
delete(params: object): Promise<Entity
|
|
8
|
+
find?(params: object): Promise<Entity> | Entity;
|
|
9
|
+
createOrUpdate?(params: object): Promise<Entity> | Entity;
|
|
10
|
+
delete?(params: object): Promise<Entity> | Entity;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface CollectionTypeService extends BaseService {
|
|
14
|
-
find(params: object): Promise<Entity[]
|
|
15
|
-
findOne(params: object): Promise<Entity
|
|
16
|
-
create(params: object): Promise<Entity
|
|
17
|
-
update(params: object): Promise<Entity
|
|
18
|
-
delete(params: object): Promise<Entity
|
|
14
|
+
find?(params: object): Promise<Entity[]> | Entity;
|
|
15
|
+
findOne?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
16
|
+
create?(params: object): Promise<Entity> | Entity;
|
|
17
|
+
update?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
18
|
+
delete?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type Service = SingleTypeService | CollectionTypeService;
|
|
22
|
+
|
package/lib/factories.d.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import { Service } from './core-api/service';
|
|
2
|
-
import { Controller } from './core-api/controller';
|
|
2
|
+
import { Controller, GenericController } from './core-api/controller';
|
|
3
3
|
import { Middleware } from './middlewares';
|
|
4
4
|
import { Policy } from './core/registries/policies';
|
|
5
|
+
import { Strapi } from '@strapi/strapi'
|
|
5
6
|
|
|
6
|
-
type ControllerConfig = Controller;
|
|
7
|
+
type ControllerConfig<T extends Controller = Controller> = T;
|
|
7
8
|
|
|
8
9
|
type ServiceConfig = Service;
|
|
9
10
|
|
|
10
11
|
type HandlerConfig = {
|
|
11
|
-
auth
|
|
12
|
-
policies
|
|
13
|
-
middlewares
|
|
12
|
+
auth?: false | { scope: string[] };
|
|
13
|
+
policies?: Array<string | Policy>;
|
|
14
|
+
middlewares?: Array<string | Middleware>;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
type SingleTypeRouterConfig = {
|
|
17
|
-
find
|
|
18
|
-
update
|
|
19
|
-
delete
|
|
18
|
+
find?: HandlerConfig;
|
|
19
|
+
update?: HandlerConfig;
|
|
20
|
+
delete?: HandlerConfig;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
type CollectionTypeRouterConfig = {
|
|
23
|
-
find
|
|
24
|
-
findOne
|
|
25
|
-
create
|
|
26
|
-
update
|
|
27
|
-
delete
|
|
24
|
+
find?: HandlerConfig;
|
|
25
|
+
findOne?: HandlerConfig;
|
|
26
|
+
create?: HandlerConfig;
|
|
27
|
+
update?: HandlerConfig;
|
|
28
|
+
delete?: HandlerConfig;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
type RouterConfig = {
|
|
31
|
-
prefix
|
|
32
|
+
prefix?: string;
|
|
32
33
|
only: string[];
|
|
33
|
-
except
|
|
34
|
+
except?: string[];
|
|
34
35
|
config: SingleTypeRouterConfig | CollectionTypeRouterConfig;
|
|
35
36
|
};
|
|
36
37
|
|
|
@@ -43,6 +44,9 @@ interface Router {
|
|
|
43
44
|
routes: Route[];
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
type ControllerCallback <T extends GenericController = GenericController> = (params:{strapi:Strapi}) => T;
|
|
48
|
+
type ServiceCallback <T extends Service = Sevice> = (params:{strapi:Strapi}) => T
|
|
49
|
+
|
|
46
50
|
export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
|
|
47
|
-
export function createCoreController(uid: string, cfg?:
|
|
48
|
-
export function createCoreService(uid: string, cfg?:
|
|
51
|
+
export function createCoreController<T extends GenericController = GenericController>(uid: string, cfg?: ControllerCallback<T> | T = {}): () => T & Controller;
|
|
52
|
+
export function createCoreService<T extends Service = Service>(uid: string, cfg?: ServiceCallback<T> | T = {}): () => T ;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Database } from '@strapi/database';
|
|
2
2
|
import { EntityService } from './services/entity-service';
|
|
3
|
-
import { Strapi as StrapiClass } from './Strapi';
|
|
4
3
|
|
|
4
|
+
import * as Core from './types/strapi';
|
|
5
5
|
export * as factories from './factories';
|
|
6
|
-
interface StrapiInterface extends StrapiClass {
|
|
7
|
-
query: Database['query'];
|
|
8
|
-
entityService: EntityService;
|
|
9
|
-
}
|
|
10
6
|
|
|
11
|
-
export type
|
|
7
|
+
export type { Core };
|
|
8
|
+
|
|
9
|
+
// Alias to resolve the Strapi global type easily
|
|
10
|
+
export type Strapi = Core.Strapi;
|
|
11
|
+
|
|
12
|
+
export interface StrapiInterface extends Core.Strapi {};
|
|
12
13
|
|
|
13
14
|
declare global {
|
|
14
15
|
interface AllTypes {}
|
package/lib/middlewares/body.js
CHANGED
|
@@ -3,12 +3,23 @@
|
|
|
3
3
|
const fse = require('fs-extra');
|
|
4
4
|
const { defaultsDeep, get } = require('lodash/fp');
|
|
5
5
|
const body = require('koa-body');
|
|
6
|
+
const mime = require('mime-types');
|
|
6
7
|
|
|
7
8
|
const defaults = {
|
|
8
9
|
multipart: true,
|
|
9
10
|
patchKoa: true,
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
function ensureFileMimeType(file) {
|
|
14
|
+
if (!file.type) {
|
|
15
|
+
file.type = mime.lookup(file.name) || 'application/octet-stream';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getFiles(ctx) {
|
|
20
|
+
return get('request.files.files', ctx);
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
/**
|
|
13
24
|
* @type {import('./').MiddlewareFactory}
|
|
14
25
|
*/
|
|
@@ -18,21 +29,38 @@ module.exports = config => {
|
|
|
18
29
|
return async (ctx, next) => {
|
|
19
30
|
// TODO: find a better way later
|
|
20
31
|
if (ctx.url === '/graphql') {
|
|
21
|
-
|
|
22
|
-
}
|
|
32
|
+
await next();
|
|
33
|
+
} else {
|
|
34
|
+
try {
|
|
35
|
+
await body({ patchKoa: true, ...bodyConfig })(ctx, () => {});
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
await body({ patchKoa: true, ...bodyConfig })(ctx, next);
|
|
26
|
-
} catch (e) {
|
|
27
|
-
if ((e || {}).message && e.message.includes('maxFileSize exceeded')) {
|
|
28
|
-
return ctx.payloadTooLarge('FileTooBig');
|
|
29
|
-
}
|
|
37
|
+
const files = getFiles(ctx);
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
/**
|
|
40
|
+
* in case the mime-type wasn't sent, Strapi tries to guess it
|
|
41
|
+
* from the file extension, to avoid a corrupt database state
|
|
42
|
+
*/
|
|
43
|
+
if (files) {
|
|
44
|
+
if (Array.isArray(files)) {
|
|
45
|
+
files.forEach(ensureFileMimeType);
|
|
46
|
+
} else {
|
|
47
|
+
ensureFileMimeType(files);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await next();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if ((e || {}).message && e.message.includes('maxFileSize exceeded')) {
|
|
54
|
+
return ctx.payloadTooLarge('FileTooBig');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
32
59
|
}
|
|
33
60
|
|
|
61
|
+
const files = getFiles(ctx);
|
|
62
|
+
|
|
34
63
|
// clean any file that was uploaded
|
|
35
|
-
const files = get('request.files.files', ctx);
|
|
36
64
|
if (files) {
|
|
37
65
|
if (Array.isArray(files)) {
|
|
38
66
|
// not awaiting to not slow the request
|
|
@@ -19,7 +19,9 @@ const defaultConfig = {
|
|
|
19
19
|
module.exports = (userConfig, { strapi }) => {
|
|
20
20
|
const keys = strapi.server.app.keys;
|
|
21
21
|
if (!isArray(keys) || isEmpty(keys) || keys.some(isEmpty)) {
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error(
|
|
23
|
+
`App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`
|
|
24
|
+
);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const config = defaultsDeep(defaultConfig, userConfig);
|
|
@@ -166,7 +166,9 @@ const stringValidator = composeValidators(
|
|
|
166
166
|
addUniqueValidator
|
|
167
167
|
);
|
|
168
168
|
|
|
169
|
-
const emailValidator = composeValidators(stringValidator, validator =>
|
|
169
|
+
const emailValidator = composeValidators(stringValidator, validator =>
|
|
170
|
+
validator.email().min(1, '${path} cannot be empty')
|
|
171
|
+
);
|
|
170
172
|
|
|
171
173
|
const uidValidator = composeValidators(stringValidator, validator =>
|
|
172
174
|
validator.matches(new RegExp('^[A-Za-z0-9-_.~]*$'))
|
|
@@ -24,13 +24,19 @@ const LIMITED_EVENTS = [
|
|
|
24
24
|
|
|
25
25
|
const createTelemetryInstance = strapi => {
|
|
26
26
|
const uuid = strapi.config.get('uuid');
|
|
27
|
-
const
|
|
27
|
+
const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');
|
|
28
|
+
const isDisabled =
|
|
29
|
+
!uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);
|
|
28
30
|
|
|
29
31
|
const crons = [];
|
|
30
32
|
const sender = createSender(strapi);
|
|
31
33
|
const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });
|
|
32
34
|
|
|
33
35
|
return {
|
|
36
|
+
get isDisabled() {
|
|
37
|
+
return isDisabled;
|
|
38
|
+
},
|
|
39
|
+
|
|
34
40
|
register() {
|
|
35
41
|
if (!isDisabled) {
|
|
36
42
|
const pingCron = scheduleJob('0 0 12 * * *', () => sendEvent('ping'));
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
4
5
|
const _ = require('lodash');
|
|
5
6
|
const isDocker = require('is-docker');
|
|
6
7
|
const fetch = require('node-fetch');
|
|
7
8
|
const ciEnv = require('ci-info');
|
|
9
|
+
const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
|
|
8
10
|
const ee = require('../../utils/ee');
|
|
9
11
|
const machineID = require('../../utils/machine-id');
|
|
10
12
|
const stringifyDeep = require('./stringify-deep');
|
|
@@ -36,6 +38,9 @@ module.exports = strapi => {
|
|
|
36
38
|
const deviceId = machineID();
|
|
37
39
|
const isEE = strapi.EE === true && ee.isEE === true;
|
|
38
40
|
|
|
41
|
+
const serverRootPath = strapi.dirs.app.root;
|
|
42
|
+
const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
|
|
43
|
+
|
|
39
44
|
const anonymous_metadata = {
|
|
40
45
|
environment: strapi.config.environment,
|
|
41
46
|
os: os.type(),
|
|
@@ -47,6 +52,8 @@ module.exports = strapi => {
|
|
|
47
52
|
version: strapi.config.get('info.strapi'),
|
|
48
53
|
strapiVersion: strapi.config.get('info.strapi'),
|
|
49
54
|
projectType: isEE ? 'Enterprise' : 'Community',
|
|
55
|
+
useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
|
|
56
|
+
useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
|
|
50
57
|
};
|
|
51
58
|
|
|
52
59
|
addPackageJsonStrapiMetadata(anonymous_metadata, strapi);
|
|
@@ -30,7 +30,7 @@ const healthCheck = async ctx => {
|
|
|
30
30
|
const createServer = strapi => {
|
|
31
31
|
const app = createKoaApp({
|
|
32
32
|
proxy: strapi.config.get('server.proxy'),
|
|
33
|
-
keys:
|
|
33
|
+
keys: strapi.config.get('server.app.keys'),
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
const router = new Router();
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import type Koa from 'koa';
|
|
2
|
+
|
|
3
|
+
import type { StringMap } from './utils';
|
|
4
|
+
|
|
5
|
+
type Controller = {
|
|
6
|
+
[methodName: string | number | symbol]: (context: Koa.Context) => unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Strapi interface implemented by the main Strapi class.
|
|
11
|
+
*/
|
|
12
|
+
export interface Strapi {
|
|
13
|
+
/**
|
|
14
|
+
* Getter for the Strapi enterprise edition configuration
|
|
15
|
+
*/
|
|
16
|
+
readonly EE: any;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Getter for the Strapi configuration container
|
|
20
|
+
*/
|
|
21
|
+
readonly config: any;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Getter for the Strapi auth container
|
|
25
|
+
*/
|
|
26
|
+
readonly auth: any;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Getter for the Strapi sanitizers container
|
|
30
|
+
*/
|
|
31
|
+
readonly sanitizers: any;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Getter for the Strapi services container
|
|
35
|
+
*
|
|
36
|
+
* It returns all the registered services
|
|
37
|
+
*/
|
|
38
|
+
readonly services: StringMap<Service>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Find a service using its unique identifier
|
|
42
|
+
*/
|
|
43
|
+
service<T extends Service = unknown>(uid: string): T | undefined;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Getter for the Strapi controllers container
|
|
47
|
+
*
|
|
48
|
+
* It returns all the registered controllers
|
|
49
|
+
*/
|
|
50
|
+
readonly controllers: StringMap<Controller>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Find a controller using its unique identifier
|
|
54
|
+
*/
|
|
55
|
+
controller(uid: string): Controller | undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Getter for the Strapi content types container
|
|
59
|
+
*
|
|
60
|
+
* It returns all the registered content types
|
|
61
|
+
*/
|
|
62
|
+
readonly contentTypes: any;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Find a content type using its unique identifier
|
|
66
|
+
*/
|
|
67
|
+
contentType(uid: string): any;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Getter for the Strapi policies container
|
|
71
|
+
*
|
|
72
|
+
* It returns all the registered policies
|
|
73
|
+
*/
|
|
74
|
+
readonly policies: any;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Find a policy using its name
|
|
78
|
+
*/
|
|
79
|
+
policy(name: string): any;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Getter for the Strapi middlewares container
|
|
83
|
+
*
|
|
84
|
+
* It returns all the registered middlewares
|
|
85
|
+
*/
|
|
86
|
+
readonly middlewares: any;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Find a middleware using its name
|
|
90
|
+
*/
|
|
91
|
+
middleware(): any;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Getter for the Strapi plugins container
|
|
95
|
+
*
|
|
96
|
+
* It returns all the registered plugins
|
|
97
|
+
*/
|
|
98
|
+
readonly plugins: any;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Find a plugin using its name
|
|
102
|
+
*/
|
|
103
|
+
plugin(name: string): any;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Getter for the Strapi hooks container
|
|
107
|
+
*
|
|
108
|
+
* It returns all the registered hooks
|
|
109
|
+
*/
|
|
110
|
+
readonly hooks: any;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Find a hook using its name
|
|
114
|
+
*/
|
|
115
|
+
hook(): any;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Getter for the Strapi APIs container
|
|
119
|
+
*
|
|
120
|
+
* It returns all the registered APIs
|
|
121
|
+
*/
|
|
122
|
+
readonly api: any;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Strapi Register Lifecycle.
|
|
126
|
+
*
|
|
127
|
+
* - Load
|
|
128
|
+
* - The user application
|
|
129
|
+
* - The plugins
|
|
130
|
+
* - The admin
|
|
131
|
+
* - The APIs
|
|
132
|
+
* - The components
|
|
133
|
+
* - The middlewares
|
|
134
|
+
* - The policies
|
|
135
|
+
* - Trigger Strapi internal bootstrap
|
|
136
|
+
* - Create the webhooks runner
|
|
137
|
+
* - Create the internal hooks registry.
|
|
138
|
+
* - Init the telemetry cron job and middleware
|
|
139
|
+
* - Run all the `register` lifecycle methods loaded by the user application or the enabled plugins
|
|
140
|
+
*/
|
|
141
|
+
register(): Promise<Strapi>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Bootstraping phase.
|
|
145
|
+
*
|
|
146
|
+
* - Load all the content types
|
|
147
|
+
* - Initialize the database layer
|
|
148
|
+
* - Initialize the entity service
|
|
149
|
+
* - Run the schemas/database synchronization
|
|
150
|
+
* - Start the webhooks and initializing middlewares and routes
|
|
151
|
+
* - Run all the `bootstrap` lifecycle methods loaded by the
|
|
152
|
+
* user application or the enabled plugins
|
|
153
|
+
*/
|
|
154
|
+
bootstrap(): Promise<Strapi>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Destroy phase
|
|
158
|
+
*
|
|
159
|
+
* - Destroy Strapi server
|
|
160
|
+
* - Run all the `destroy` lifecycle methods loaded by the
|
|
161
|
+
* user application or the enabled plugins
|
|
162
|
+
* - Cleanup the event hub
|
|
163
|
+
* - Gracefully stop the database
|
|
164
|
+
* - Stop the telemetry and cron instance
|
|
165
|
+
* - Cleanup the global scope by removing global.strapi
|
|
166
|
+
*/
|
|
167
|
+
destroy(): Promise<void>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Run all functions registered for a given lifecycle. (Strapi core, user app, plugins)
|
|
171
|
+
*/
|
|
172
|
+
runLifecyclesFunctions<T extends Lifecycles[keyof Lifecycles]>(lifecycleName: T): Promise<void>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Load the application if needed and start the server
|
|
176
|
+
*/
|
|
177
|
+
start(): Promise<void>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Stop the server and provide a custom error and message
|
|
181
|
+
*/
|
|
182
|
+
stopWithError<TError = unknown>(error: TError, customMessage?: string): void;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Gracefully stop the server
|
|
186
|
+
* Call the destroy method.
|
|
187
|
+
*/
|
|
188
|
+
stop(code?: number): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Load the server and the user application.
|
|
192
|
+
* It basically triggers the register and bootstrap phases
|
|
193
|
+
*/
|
|
194
|
+
load(): Promise<Strapi>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Restart the server and reload all the configuration.
|
|
198
|
+
* It re-runs all the lifecycles phases.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ``` ts
|
|
202
|
+
* setImmediate(() => strapi.reload());
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
reload(): () => void;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Initialize and start all the webhooks registered in the webhook store
|
|
209
|
+
*/
|
|
210
|
+
startWebhooks(): Promise<void>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Method called when the server is fully initialized and listen to incomming requests.
|
|
214
|
+
* It handles tasks such as logging the startup message
|
|
215
|
+
* or automatically opening the administration panel.
|
|
216
|
+
*/
|
|
217
|
+
postListen(): Promise<void>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Start listening for incomming requests
|
|
221
|
+
*/
|
|
222
|
+
listen(): Promise<void | Error>;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Opent he administration panel in a browser if the option is enabled.
|
|
226
|
+
* You can disable it using the admin.autoOpen configuration variable.
|
|
227
|
+
*
|
|
228
|
+
* Note: It only works in development envs.
|
|
229
|
+
*/
|
|
230
|
+
openAdmin(options: { isInitialized: boolean }): Promise<void>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Load the admin panel server logic into the server code and initialize its configuration.
|
|
234
|
+
*/
|
|
235
|
+
loadAdmin(): Promise<void>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Resolve every enabled plugin and load them into the application.
|
|
239
|
+
*/
|
|
240
|
+
loadPlugins(): Promise<void>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Load every global policies in the policies container by
|
|
244
|
+
* reading from the `strapi.dirs.dist.policies` directory.
|
|
245
|
+
*/
|
|
246
|
+
loadPolicies(): Promise<void>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Load every APIs and their components (config, routes, controllers, services,
|
|
250
|
+
* policies, middlewares, content-types) in the API container.
|
|
251
|
+
*/
|
|
252
|
+
loadAPIs(): Promise<void>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Resolve every components in the user application and store them in `strapi.components`
|
|
256
|
+
*/
|
|
257
|
+
loadComponents(): Promise<void>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Load every global and core middlewares in the middlewares container by
|
|
261
|
+
* reading from the `strapi.dirs.dist.middlewares` and internal middlewares directory.
|
|
262
|
+
*/
|
|
263
|
+
loadMiddlewares(): Promise<void>;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Load the user application in the server by reading the `src/index.js` file.
|
|
267
|
+
*/
|
|
268
|
+
loadApp(): Promise<void>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Add internal hooks to the hooks container.
|
|
272
|
+
* Those hooks are meant for internal usage and might break in future releases.
|
|
273
|
+
*/
|
|
274
|
+
registerInternalHooks(): void;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Find a model (content-type, component) based on its unique identifier.
|
|
278
|
+
*/
|
|
279
|
+
getModel(uid: string): any;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Binds database queries for a specific model based on its unique identifier.
|
|
283
|
+
*/
|
|
284
|
+
query(uid: string): any;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface Lifecycles {
|
|
288
|
+
REGISTER: 'register';
|
|
289
|
+
BOOTSTRAP: 'bootstrap';
|
|
290
|
+
DESTROY: 'destroy';
|
|
291
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type StringMap<T> = { [key: string]: T };
|