@strapi/strapi 4.2.0 → 4.3.0-beta.1

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 (57) hide show
  1. package/bin/strapi.js +1 -0
  2. package/lib/Strapi.js +37 -8
  3. package/lib/commands/admin-create.js +2 -1
  4. package/lib/commands/admin-reset.js +2 -1
  5. package/lib/commands/build.js +8 -46
  6. package/lib/commands/builders/admin.js +56 -0
  7. package/lib/commands/builders/index.js +9 -0
  8. package/lib/commands/builders/typescript.js +32 -0
  9. package/lib/commands/configurationDump.js +2 -1
  10. package/lib/commands/configurationRestore.js +3 -1
  11. package/lib/commands/console.js +4 -3
  12. package/lib/commands/content-types/list.js +2 -1
  13. package/lib/commands/controllers/list.js +2 -1
  14. package/lib/commands/develop.js +111 -74
  15. package/lib/commands/hooks/list.js +2 -1
  16. package/lib/commands/middlewares/list.js +2 -1
  17. package/lib/commands/policies/list.js +2 -1
  18. package/lib/commands/routes/list.js +2 -1
  19. package/lib/commands/services/list.js +2 -1
  20. package/lib/commands/start.js +18 -2
  21. package/lib/commands/watchAdmin.js +5 -10
  22. package/lib/compile.js +20 -0
  23. package/lib/core/app-configuration/index.js +4 -3
  24. package/lib/core/app-configuration/load-config-file.js +3 -1
  25. package/lib/core/bootstrap.js +2 -2
  26. package/lib/core/loaders/apis.js +6 -5
  27. package/lib/core/loaders/components.js +5 -4
  28. package/lib/core/loaders/middlewares.js +4 -2
  29. package/lib/core/loaders/plugins/get-enabled-plugins.js +2 -1
  30. package/lib/core/loaders/plugins/get-user-plugins-config.js +2 -2
  31. package/lib/core/loaders/plugins/index.js +1 -1
  32. package/lib/core/loaders/policies.js +4 -2
  33. package/lib/core/loaders/src-index.js +6 -4
  34. package/lib/core/registries/policies.d.ts +1 -1
  35. package/lib/core-api/controller/index.d.ts +16 -14
  36. package/lib/core-api/service/index.d.ts +10 -9
  37. package/lib/factories.d.ts +22 -18
  38. package/lib/index.d.ts +7 -6
  39. package/lib/index.js +1 -0
  40. package/lib/load/load-files.js +3 -1
  41. package/lib/middlewares/favicon.js +1 -1
  42. package/lib/middlewares/public/index.js +1 -1
  43. package/lib/services/entity-service/index.d.ts +7 -1
  44. package/lib/services/entity-service/index.js +11 -1
  45. package/lib/services/fs.js +1 -1
  46. package/lib/services/metrics/index.js +5 -1
  47. package/lib/services/metrics/sender.js +7 -0
  48. package/lib/services/server/middleware.js +1 -1
  49. package/lib/services/utils/upload-files.js +1 -1
  50. package/lib/types/strapi.d.ts +370 -0
  51. package/lib/types/utils.d.ts +1 -0
  52. package/lib/utils/get-dirs.js +24 -10
  53. package/lib/utils/import-default.js +10 -0
  54. package/lib/utils/index.js +2 -0
  55. package/lib/utils/lifecycles.js +15 -0
  56. package/lib/utils/update-notifier/index.js +1 -1
  57. package/package.json +15 -13
@@ -112,7 +112,7 @@ const resolveCustomMiddleware = (resolve, strapi) => {
112
112
  modulePath = require.resolve(resolve);
113
113
  } catch (error) {
114
114
  if (error.code === 'MODULE_NOT_FOUND') {
115
- modulePath = path.resolve(strapi.dirs.root, resolve);
115
+ modulePath = path.resolve(strapi.dirs.dist.root, resolve);
116
116
  } else {
117
117
  throw error;
118
118
  }
@@ -3,7 +3,7 @@
3
3
  const _ = require('lodash');
4
4
 
5
5
  /**
6
- * Upload files and like them to an entity
6
+ * Upload files and link them to an entity
7
7
  * @param {string} uid model uid
8
8
  * @param {object} entity entity created
9
9
  * @param {object} files files to upload
@@ -0,0 +1,370 @@
1
+ import type Koa from 'koa';
2
+
3
+ import type { StringMap } from './utils';
4
+ import type { GenericController } from '../core-api/controller'
5
+
6
+ /**
7
+ * The Strapi interface implemented by the main Strapi class.
8
+ */
9
+ export interface Strapi {
10
+ /**
11
+ * Getter for the Strapi enterprise edition configuration
12
+ */
13
+ readonly EE: any;
14
+
15
+ /**
16
+ * Getter for the Strapi configuration container
17
+ */
18
+ readonly config: any;
19
+
20
+ /**
21
+ * Getter for the Strapi auth container
22
+ */
23
+ readonly auth: any;
24
+
25
+ /**
26
+ * Getter for the Strapi sanitizers container
27
+ */
28
+ readonly sanitizers: any;
29
+
30
+ /**
31
+ * Getter for the Strapi services container
32
+ *
33
+ * It returns all the registered services
34
+ */
35
+ readonly services: StringMap<Service>;
36
+
37
+ /**
38
+ * Find a service using its unique identifier
39
+ */
40
+ service<T extends Service = unknown>(uid: string): T | undefined;
41
+
42
+ /**
43
+ * Getter for the Strapi controllers container
44
+ *
45
+ * It returns all the registered controllers
46
+ */
47
+ readonly controllers: StringMap<GenericController>;
48
+
49
+ /**
50
+ * Find a controller using its unique identifier
51
+ */
52
+ controller(uid: string): GenericController | undefined;
53
+
54
+ /**
55
+ * Getter for the Strapi content types container
56
+ *
57
+ * It returns all the registered content types
58
+ */
59
+ readonly contentTypes: any;
60
+
61
+ /**
62
+ * Find a content type using its unique identifier
63
+ */
64
+ contentType(uid: string): any;
65
+
66
+ /**
67
+ * Getter for the Strapi policies container
68
+ *
69
+ * It returns all the registered policies
70
+ */
71
+ readonly policies: any;
72
+
73
+ /**
74
+ * Find a policy using its name
75
+ */
76
+ policy(name: string): any;
77
+
78
+ /**
79
+ * Getter for the Strapi middlewares container
80
+ *
81
+ * It returns all the registered middlewares
82
+ */
83
+ readonly middlewares: any;
84
+
85
+ /**
86
+ * Find a middleware using its name
87
+ */
88
+ middleware(): any;
89
+
90
+ /**
91
+ * Getter for the Strapi plugins container
92
+ *
93
+ * It returns all the registered plugins
94
+ */
95
+ readonly plugins: any;
96
+
97
+ /**
98
+ * Find a plugin using its name
99
+ */
100
+ plugin(name: string): any;
101
+
102
+ /**
103
+ * Getter for the Strapi hooks container
104
+ *
105
+ * It returns all the registered hooks
106
+ */
107
+ readonly hooks: any;
108
+
109
+ /**
110
+ * Find a hook using its name
111
+ */
112
+ hook(): any;
113
+
114
+ /**
115
+ * Getter for the Strapi APIs container
116
+ *
117
+ * It returns all the registered APIs
118
+ */
119
+ readonly api: any;
120
+
121
+ /**
122
+ * Strapi Register Lifecycle.
123
+ *
124
+ * - Load
125
+ * - The user application
126
+ * - The plugins
127
+ * - The admin
128
+ * - The APIs
129
+ * - The components
130
+ * - The middlewares
131
+ * - The policies
132
+ * - Trigger Strapi internal bootstrap
133
+ * - Create the webhooks runner
134
+ * - Create the internal hooks registry.
135
+ * - Init the telemetry cron job and middleware
136
+ * - Run all the `register` lifecycle methods loaded by the user application or the enabled plugins
137
+ */
138
+ register(): Promise<Strapi>;
139
+
140
+ /**
141
+ * Bootstraping phase.
142
+ *
143
+ * - Load all the content types
144
+ * - Initialize the database layer
145
+ * - Initialize the entity service
146
+ * - Run the schemas/database synchronization
147
+ * - Start the webhooks and initializing middlewares and routes
148
+ * - Run all the `bootstrap` lifecycle methods loaded by the
149
+ * user application or the enabled plugins
150
+ */
151
+ bootstrap(): Promise<Strapi>;
152
+
153
+ /**
154
+ * Destroy phase
155
+ *
156
+ * - Destroy Strapi server
157
+ * - Run all the `destroy` lifecycle methods loaded by the
158
+ * user application or the enabled plugins
159
+ * - Cleanup the event hub
160
+ * - Gracefully stop the database
161
+ * - Stop the telemetry and cron instance
162
+ * - Cleanup the global scope by removing global.strapi
163
+ */
164
+ destroy(): Promise<void>;
165
+
166
+ /**
167
+ * Run all functions registered for a given lifecycle. (Strapi core, user app, plugins)
168
+ */
169
+ runLifecyclesFunctions<T extends Lifecycles[keyof Lifecycles]>(lifecycleName: T): Promise<void>;
170
+
171
+ /**
172
+ * Load the application if needed and start the server
173
+ */
174
+ start(): Promise<void>;
175
+
176
+ /**
177
+ * Stop the server and provide a custom error and message
178
+ */
179
+ stopWithError<TError = unknown>(error: TError, customMessage?: string): void;
180
+
181
+ /**
182
+ * Gracefully stop the server
183
+ * Call the destroy method.
184
+ */
185
+ stop(code?: number): void;
186
+
187
+ /**
188
+ * Load the server and the user application.
189
+ * It basically triggers the register and bootstrap phases
190
+ */
191
+ load(): Promise<Strapi>;
192
+
193
+ /**
194
+ * Restart the server and reload all the configuration.
195
+ * It re-runs all the lifecycles phases.
196
+ *
197
+ * @example
198
+ * ``` ts
199
+ * setImmediate(() => strapi.reload());
200
+ * ```
201
+ */
202
+ reload(): () => void;
203
+
204
+ /**
205
+ * Initialize and start all the webhooks registered in the webhook store
206
+ */
207
+ startWebhooks(): Promise<void>;
208
+
209
+ /**
210
+ * Method called when the server is fully initialized and listen to incomming requests.
211
+ * It handles tasks such as logging the startup message
212
+ * or automatically opening the administration panel.
213
+ */
214
+ postListen(): Promise<void>;
215
+
216
+ /**
217
+ * Start listening for incomming requests
218
+ */
219
+ listen(): Promise<void | Error>;
220
+
221
+ /**
222
+ * Opent he administration panel in a browser if the option is enabled.
223
+ * You can disable it using the admin.autoOpen configuration variable.
224
+ *
225
+ * Note: It only works in development envs.
226
+ */
227
+ openAdmin(options: { isInitialized: boolean }): Promise<void>;
228
+
229
+ /**
230
+ * Load the admin panel server logic into the server code and initialize its configuration.
231
+ */
232
+ loadAdmin(): Promise<void>;
233
+
234
+ /**
235
+ * Resolve every enabled plugin and load them into the application.
236
+ */
237
+ loadPlugins(): Promise<void>;
238
+
239
+ /**
240
+ * Load every global policies in the policies container by
241
+ * reading from the `strapi.dirs.dist.policies` directory.
242
+ */
243
+ loadPolicies(): Promise<void>;
244
+
245
+ /**
246
+ * Load every APIs and their components (config, routes, controllers, services,
247
+ * policies, middlewares, content-types) in the API container.
248
+ */
249
+ loadAPIs(): Promise<void>;
250
+
251
+ /**
252
+ * Resolve every components in the user application and store them in `strapi.components`
253
+ */
254
+ loadComponents(): Promise<void>;
255
+
256
+ /**
257
+ * Load every global and core middlewares in the middlewares container by
258
+ * reading from the `strapi.dirs.dist.middlewares` and internal middlewares directory.
259
+ */
260
+ loadMiddlewares(): Promise<void>;
261
+
262
+ /**
263
+ * Load the user application in the server by reading the `src/index.js` file.
264
+ */
265
+ loadApp(): Promise<void>;
266
+
267
+ /**
268
+ * Add internal hooks to the hooks container.
269
+ * Those hooks are meant for internal usage and might break in future releases.
270
+ */
271
+ registerInternalHooks(): void;
272
+
273
+ /**
274
+ * Find a model (content-type, component) based on its unique identifier.
275
+ */
276
+ getModel(uid: string): any;
277
+
278
+ /**
279
+ * Binds database queries for a specific model based on its unique identifier.
280
+ */
281
+ query(uid: string): any;
282
+
283
+ /**
284
+ * Main Strapi container holding all the registries and providers (config, content-types, services, policies, etc...)
285
+ */
286
+ container: any;
287
+
288
+ /**
289
+ * References to all the directories handled by Strapi
290
+ */
291
+ dirs: StrapiDirectories;
292
+
293
+ /**
294
+ * Internal flag used to check if the application has been loaded
295
+ */
296
+ isLoaded: boolean;
297
+
298
+ /**
299
+ * Fully reload the application
300
+ */
301
+ reload(): void;
302
+
303
+ /**
304
+ * Holds a reference to the Koa application and the http server used by Strapi
305
+ */
306
+ server: any;
307
+
308
+ /**
309
+ * Strapi util used to manage application files
310
+ */
311
+ fs: any;
312
+
313
+ /**
314
+ * Event hub used to send and receive events from anywhere in the application
315
+ */
316
+ eventHub: any;
317
+
318
+ /**
319
+ * Internal util used to log stats and messages on application Startup
320
+ */
321
+ startupLogger: any;
322
+
323
+ /**
324
+ * Strapi logger used to send errors, warning or information messages
325
+ */
326
+ log: any;
327
+
328
+
329
+ /**
330
+ * Used to manage cron within Strapi
331
+ */
332
+ cron: any;
333
+
334
+ /**
335
+ * Telemetry util used to collect anonymous data on the application usage
336
+ */
337
+ telemetry: any;
338
+ }
339
+
340
+ export interface Lifecycles {
341
+ REGISTER: 'register';
342
+ BOOTSTRAP: 'bootstrap';
343
+ DESTROY: 'destroy';
344
+ }
345
+
346
+ export interface StrapiDirectories {
347
+ static: {
348
+ public: string;
349
+ };
350
+ app: {
351
+ root: string;
352
+ src: string;
353
+ api: string;
354
+ components: string;
355
+ extensions: string;
356
+ policies: string;
357
+ middlewares: string;
358
+ config: string;
359
+ };
360
+ dist: {
361
+ root: string;
362
+ src: string;
363
+ api: string;
364
+ components: string;
365
+ extensions: string;
366
+ policies: string;
367
+ middlewares: string;
368
+ config: string;
369
+ };
370
+ }
@@ -0,0 +1 @@
1
+ export type StringMap<T> = { [key: string]: T };
@@ -2,16 +2,30 @@
2
2
 
3
3
  const { join, resolve } = require('path');
4
4
 
5
- const getDirs = (root, { strapi }) => ({
6
- root,
7
- src: join(root, 'src'),
8
- api: join(root, 'src', 'api'),
9
- components: join(root, 'src', 'components'),
10
- extensions: join(root, 'src', 'extensions'),
11
- policies: join(root, 'src', 'policies'),
12
- middlewares: join(root, 'src', 'middlewares'),
13
- config: join(root, 'config'),
14
- public: resolve(root, strapi.config.get('server.dirs.public')),
5
+ const getDirs = ({ app: appDir, dist: distDir }, { strapi }) => ({
6
+ dist: {
7
+ root: distDir,
8
+ src: join(distDir, 'src'),
9
+ api: join(distDir, 'src', 'api'),
10
+ components: join(distDir, 'src', 'components'),
11
+ extensions: join(distDir, 'src', 'extensions'),
12
+ policies: join(distDir, 'src', 'policies'),
13
+ middlewares: join(distDir, 'src', 'middlewares'),
14
+ config: join(distDir, 'config'),
15
+ },
16
+ app: {
17
+ root: appDir,
18
+ src: join(appDir, 'src'),
19
+ api: join(appDir, 'src', 'api'),
20
+ components: join(appDir, 'src', 'components'),
21
+ extensions: join(appDir, 'src', 'extensions'),
22
+ policies: join(appDir, 'src', 'policies'),
23
+ middlewares: join(appDir, 'src', 'middlewares'),
24
+ config: join(appDir, 'config'),
25
+ },
26
+ static: {
27
+ public: resolve(appDir, strapi.config.get('server.dirs.public')),
28
+ },
15
29
  });
16
30
 
17
31
  module.exports = getDirs;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const importDefault =
4
+ (this && this.importDefault) ||
5
+ function(modName) {
6
+ const mod = require(modName);
7
+ return mod && mod.__esModule ? mod.default : mod;
8
+ };
9
+
10
+ module.exports = importDefault;
@@ -3,9 +3,11 @@
3
3
  const openBrowser = require('./open-browser');
4
4
  const isInitialized = require('./is-initialized');
5
5
  const getDirs = require('./get-dirs');
6
+ const importDefault = require('./import-default');
6
7
 
7
8
  module.exports = {
8
9
  isInitialized,
9
10
  openBrowser,
10
11
  getDirs,
12
+ importDefault,
11
13
  };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * A map of all the available Strapi lifecycles
5
+ * @type {import('@strapi/strapi').Core.Lifecycles}
6
+ */
7
+ const LIFECYCLES = {
8
+ REGISTER: 'register',
9
+ BOOTSTRAP: 'bootstrap',
10
+ DESTROY: 'destroy',
11
+ };
12
+
13
+ module.exports = {
14
+ LIFECYCLES,
15
+ };
@@ -38,7 +38,7 @@ const createUpdateNotifier = strapi => {
38
38
  config = new Configstore(
39
39
  pkg.name,
40
40
  {},
41
- { configPath: path.join(strapi.dirs.root, '.strapi-updater.json') }
41
+ { configPath: path.join(strapi.dirs.app.root, '.strapi-updater.json') }
42
42
  );
43
43
  } catch {
44
44
  // we don't have write access to the file system
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.2.0",
3
+ "version": "4.3.0-beta.1",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,16 +80,17 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.2.0",
84
- "@strapi/database": "4.2.0",
85
- "@strapi/generate-new": "4.2.0",
86
- "@strapi/generators": "4.2.0",
87
- "@strapi/logger": "4.2.0",
88
- "@strapi/plugin-content-manager": "4.2.0",
89
- "@strapi/plugin-content-type-builder": "4.2.0",
90
- "@strapi/plugin-email": "4.2.0",
91
- "@strapi/plugin-upload": "4.2.0",
92
- "@strapi/utils": "4.2.0",
83
+ "@strapi/admin": "4.3.0-beta.1",
84
+ "@strapi/database": "4.3.0-beta.1",
85
+ "@strapi/generate-new": "4.3.0-beta.1",
86
+ "@strapi/generators": "4.3.0-beta.1",
87
+ "@strapi/logger": "4.3.0-beta.1",
88
+ "@strapi/plugin-content-manager": "4.3.0-beta.1",
89
+ "@strapi/plugin-content-type-builder": "4.3.0-beta.1",
90
+ "@strapi/plugin-email": "4.3.0-beta.1",
91
+ "@strapi/plugin-upload": "4.3.0-beta.1",
92
+ "@strapi/typescript-utils": "4.3.0-beta.1",
93
+ "@strapi/utils": "4.3.0-beta.1",
93
94
  "bcryptjs": "2.4.3",
94
95
  "boxen": "5.1.2",
95
96
  "chalk": "4.1.2",
@@ -131,11 +132,12 @@
131
132
  "uuid": "^3.3.2"
132
133
  },
133
134
  "devDependencies": {
134
- "supertest": "^6.1.6"
135
+ "supertest": "^6.1.6",
136
+ "typescript": "4.6.2"
135
137
  },
136
138
  "engines": {
137
139
  "node": ">=14.19.1 <=16.x.x",
138
140
  "npm": ">=6.0.0"
139
141
  },
140
- "gitHead": "12c8ee3b2d95fe417de4d939db0311a0513bd8da"
142
+ "gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
141
143
  }