@strapi/strapi 4.0.0-beta.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.
Files changed (143) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +144 -0
  3. package/bin/strapi.js +186 -0
  4. package/lib/Strapi.js +470 -0
  5. package/lib/commands/admin-reset.js +51 -0
  6. package/lib/commands/build.js +56 -0
  7. package/lib/commands/configurationDump.js +50 -0
  8. package/lib/commands/configurationRestore.js +169 -0
  9. package/lib/commands/console.js +26 -0
  10. package/lib/commands/develop.js +157 -0
  11. package/lib/commands/generate-template.js +97 -0
  12. package/lib/commands/install.js +48 -0
  13. package/lib/commands/new.js +11 -0
  14. package/lib/commands/start.js +8 -0
  15. package/lib/commands/uninstall.js +68 -0
  16. package/lib/commands/watchAdmin.js +45 -0
  17. package/lib/container.js +45 -0
  18. package/lib/core/app-configuration/config-loader.js +20 -0
  19. package/lib/core/app-configuration/index.js +75 -0
  20. package/lib/core/app-configuration/load-config-file.js +43 -0
  21. package/lib/core/app-configuration/load-functions.js +28 -0
  22. package/lib/core/bootstrap.js +60 -0
  23. package/lib/core/domain/component/index.js +24 -0
  24. package/lib/core/domain/component/validator.js +29 -0
  25. package/lib/core/domain/content-type/index.js +140 -0
  26. package/lib/core/domain/content-type/validator.js +64 -0
  27. package/lib/core/domain/module/index.js +106 -0
  28. package/lib/core/domain/module/validation.js +36 -0
  29. package/lib/core/loaders/admin.js +16 -0
  30. package/lib/core/loaders/apis.js +157 -0
  31. package/lib/core/loaders/components.js +41 -0
  32. package/lib/core/loaders/index.js +11 -0
  33. package/lib/core/loaders/middlewares.js +86 -0
  34. package/lib/core/loaders/plugins/get-enabled-plugins.js +100 -0
  35. package/lib/core/loaders/plugins/index.js +109 -0
  36. package/lib/core/loaders/policies.js +28 -0
  37. package/lib/core/loaders/src-index.js +38 -0
  38. package/lib/core/registries/apis.js +43 -0
  39. package/lib/core/registries/config.js +21 -0
  40. package/lib/core/registries/content-types.js +53 -0
  41. package/lib/core/registries/controllers.js +43 -0
  42. package/lib/core/registries/hooks.js +37 -0
  43. package/lib/core/registries/middlewares.js +30 -0
  44. package/lib/core/registries/modules.js +44 -0
  45. package/lib/core/registries/plugins.js +28 -0
  46. package/lib/core/registries/policies.js +38 -0
  47. package/lib/core/registries/services.js +58 -0
  48. package/lib/core/utils.js +35 -0
  49. package/lib/core-api/controller/collection-type.js +84 -0
  50. package/lib/core-api/controller/index.js +26 -0
  51. package/lib/core-api/controller/single-type.js +44 -0
  52. package/lib/core-api/controller/transform.js +97 -0
  53. package/lib/core-api/index.js +39 -0
  54. package/lib/core-api/service/collection-type.js +84 -0
  55. package/lib/core-api/service/index.js +55 -0
  56. package/lib/core-api/service/pagination.js +125 -0
  57. package/lib/core-api/service/single-type.js +58 -0
  58. package/lib/index.d.ts +26 -0
  59. package/lib/index.js +3 -0
  60. package/lib/load/filepath-to-prop-path.js +22 -0
  61. package/lib/load/glob.js +15 -0
  62. package/lib/load/index.js +9 -0
  63. package/lib/load/load-files.js +56 -0
  64. package/lib/load/package-path.js +9 -0
  65. package/lib/middlewares/cors/index.js +66 -0
  66. package/lib/middlewares/error/defaults.json +5 -0
  67. package/lib/middlewares/error/index.js +147 -0
  68. package/lib/middlewares/favicon/defaults.json +7 -0
  69. package/lib/middlewares/favicon/index.js +31 -0
  70. package/lib/middlewares/gzip/defaults.json +6 -0
  71. package/lib/middlewares/gzip/index.js +19 -0
  72. package/lib/middlewares/helmet/defaults.json +18 -0
  73. package/lib/middlewares/helmet/index.js +9 -0
  74. package/lib/middlewares/index.js +120 -0
  75. package/lib/middlewares/ip/defaults.json +7 -0
  76. package/lib/middlewares/ip/index.js +25 -0
  77. package/lib/middlewares/logger/defaults.json +5 -0
  78. package/lib/middlewares/logger/index.js +37 -0
  79. package/lib/middlewares/parser/defaults.json +11 -0
  80. package/lib/middlewares/parser/index.js +75 -0
  81. package/lib/middlewares/poweredBy/defaults.json +5 -0
  82. package/lib/middlewares/poweredBy/index.js +16 -0
  83. package/lib/middlewares/public/assets/images/group_people_1.png +0 -0
  84. package/lib/middlewares/public/assets/images/group_people_2.png +0 -0
  85. package/lib/middlewares/public/assets/images/group_people_3.png +0 -0
  86. package/lib/middlewares/public/assets/images/logo_login.png +0 -0
  87. package/lib/middlewares/public/defaults.json +8 -0
  88. package/lib/middlewares/public/index.html +66 -0
  89. package/lib/middlewares/public/index.js +130 -0
  90. package/lib/middlewares/public/serve-static.js +23 -0
  91. package/lib/middlewares/responseTime/defaults.json +5 -0
  92. package/lib/middlewares/responseTime/index.js +25 -0
  93. package/lib/middlewares/responses/defaults.json +5 -0
  94. package/lib/middlewares/responses/index.js +19 -0
  95. package/lib/middlewares/router/defaults.json +7 -0
  96. package/lib/middlewares/router/index.js +97 -0
  97. package/lib/middlewares/session/defaults.json +18 -0
  98. package/lib/middlewares/session/index.js +140 -0
  99. package/lib/migrations/draft-publish.js +57 -0
  100. package/lib/services/auth/index.js +92 -0
  101. package/lib/services/core-store.js +145 -0
  102. package/lib/services/cron.js +54 -0
  103. package/lib/services/entity-service/components.js +365 -0
  104. package/lib/services/entity-service/index.d.ts +91 -0
  105. package/lib/services/entity-service/index.js +244 -0
  106. package/lib/services/entity-service/params.js +145 -0
  107. package/lib/services/entity-validator/index.js +187 -0
  108. package/lib/services/entity-validator/validators.js +123 -0
  109. package/lib/services/event-hub.js +15 -0
  110. package/lib/services/fs.js +58 -0
  111. package/lib/services/metrics/index.js +104 -0
  112. package/lib/services/metrics/is-truthy.js +9 -0
  113. package/lib/services/metrics/middleware.js +33 -0
  114. package/lib/services/metrics/rate-limiter.js +27 -0
  115. package/lib/services/metrics/sender.js +76 -0
  116. package/lib/services/metrics/stringify-deep.js +22 -0
  117. package/lib/services/server/admin-api.js +14 -0
  118. package/lib/services/server/api.js +32 -0
  119. package/lib/services/server/compose-endpoint.js +112 -0
  120. package/lib/services/server/content-api.js +16 -0
  121. package/lib/services/server/http-server.js +64 -0
  122. package/lib/services/server/index.js +108 -0
  123. package/lib/services/server/middleware.js +28 -0
  124. package/lib/services/server/policy.js +34 -0
  125. package/lib/services/server/routing.js +107 -0
  126. package/lib/services/utils/upload-files.js +79 -0
  127. package/lib/services/webhook-runner.js +155 -0
  128. package/lib/services/webhook-store.js +91 -0
  129. package/lib/services/worker-queue.js +58 -0
  130. package/lib/utils/addSlash.js +10 -0
  131. package/lib/utils/ee.js +123 -0
  132. package/lib/utils/get-dirs.js +15 -0
  133. package/lib/utils/get-prefixed-dependencies.js +7 -0
  134. package/lib/utils/index.js +11 -0
  135. package/lib/utils/is-initialized.js +23 -0
  136. package/lib/utils/open-browser.js +12 -0
  137. package/lib/utils/resources/key.pub +9 -0
  138. package/lib/utils/run-checks.js +22 -0
  139. package/lib/utils/startup-logger.js +90 -0
  140. package/lib/utils/success.js +31 -0
  141. package/lib/utils/update-notifier/index.js +97 -0
  142. package/lib/utils/url-from-segments.js +12 -0
  143. package/package.json +133 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015-present Strapi Solutions SAS
2
+
3
+ Portions of the Strapi software are licensed as follows:
4
+
5
+ * All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
6
+
7
+ * All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
8
+
9
+ MIT Expat License
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ <p align="center">
2
+ <a href="https://strapi.io">
3
+ <img src="https://strapi.io/assets/strapi-logo-dark.svg" width="318px" alt="Strapi logo" />
4
+ </a>
5
+ </p>
6
+ <h3 align="center">API creation made simple, secure and fast.</h3>
7
+ <p align="center">The most advanced open-source headless CMS to build powerful APIs with no effort.</p>
8
+ <p align="center"><a href="https://strapi.io/demo">Try live demo</a></p>
9
+ <br />
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.org/package/strapi">
13
+ <img src="https://img.shields.io/npm/v/strapi/latest.svg" alt="NPM Version" />
14
+ </a>
15
+ <a href="https://www.npmjs.org/package/strapi">
16
+ <img src="https://img.shields.io/npm/dm/strapi.svg" alt="Monthly download on NPM" />
17
+ </a>
18
+ <a href="https://discord.strapi.io">
19
+ <img src="https://img.shields.io/discord/811989166782021633?label=Discord" alt="Strapi on Discord" />
20
+ </a>
21
+ </p>
22
+
23
+ <br>
24
+
25
+ <p align="center">
26
+ <a href="https://strapi.io">
27
+ <img src="https://raw.githubusercontent.com/strapi/strapi/master/public/assets/administration_panel.png" alt="Administration panel" />
28
+ </a>
29
+ </p>
30
+
31
+ <br>
32
+
33
+ Strapi is a free and open-source headless CMS delivering your content anywhere you need.
34
+
35
+ - **Keep control over your data**. With Strapi, you know where your data is stored, and you keep full control at all times.
36
+ - **Self-hosted**. You can host and scale Strapi projects the way you want. You can choose any hosting platform you want: AWS, Render, Netlify, Heroku, a VPS, or a dedicated server. You can scale as you grow, 100% independent.
37
+ - **Database agnostic**. Strapi works with SQL databases. You can choose the database you prefer: PostgreSQL, MySQL, MariaDB, and SQLite.
38
+ - **Customizable**. You can quickly build your logic by fully customizing APIs, routes, or plugins to fit your needs perfectly.
39
+
40
+ ## Getting Started
41
+
42
+ <a href="https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html" target="_blank">Read the Getting Started tutorial</a> or follow the steps below:
43
+
44
+ ### ⏳ Installation
45
+
46
+ Install Strapi with this **Quickstart** command to create a Strapi project instantly:
47
+
48
+ - (Use **yarn** to install the Strapi project (recommended). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/).)
49
+
50
+ ```bash
51
+ yarn create strapi-app my-project --quickstart
52
+ ```
53
+
54
+ **or**
55
+
56
+ - (Use npm/npx to install the Strapi project.)
57
+
58
+ ```bash
59
+ npx create-strapi-app my-project --quickstart
60
+ ```
61
+
62
+ This command generates a brand new project with the default features (authentication, permissions, content management, content type builder & file upload). The **Quickstart** command installs Strapi using a **SQLite** database which is used for prototyping in development.
63
+
64
+ Enjoy 🎉
65
+
66
+ ### 🖐 Requirements
67
+
68
+ Complete installation requirements can be found in the documentation under <a href="https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/deployment.html#recommended-requirements">Installation Requirements</a>.
69
+
70
+ **Supported operating systems**:
71
+
72
+ - Ubuntu LTS/Debian 9.x
73
+ - CentOS/RHEL 8
74
+ - macOS Mojave
75
+ - Windows 10
76
+ - Docker - [Docker-Repo](https://github.com/strapi/strapi-docker)
77
+
78
+ (Please note that Strapi may work on other operating systems, but these are not tested nor officially supported at this time.)
79
+
80
+ **Node:**
81
+
82
+ - NodeJS >= 10.16 <=14
83
+ - NPM >= 6.x
84
+
85
+ **Database:**
86
+
87
+ - MySQL >= 5.6
88
+ - MariaDB >= 10.1
89
+ - PostgreSQL >= 10
90
+ - SQLite >= 3
91
+
92
+ **We recommend always using the latest version of Strapi to start your new projects**.
93
+
94
+ ## Features
95
+
96
+ - **Modern Admin Panel:** Elegant, entirely customizable and a fully extensible admin panel.
97
+ - **Secure by default:** Reusable policies, CORS, CSP, P3P, Xframe, XSS, and more.
98
+ - **Plugins Oriented:** Install the auth system, content management, custom plugins, and more, in seconds.
99
+ - **Blazing Fast:** Built on top of Node.js, Strapi delivers amazing performance.
100
+ - **Front-end Agnostic:** Use any front-end framework (React, Vue, Angular, etc.), mobile apps or even IoT.
101
+ - **Powerful CLI:** Scaffold projects and APIs on the fly.
102
+ - **SQL databases:** Works with PostgreSQL, MySQL, MariaDB, and SQLite.
103
+
104
+ **[See more on our website](https://strapi.io/overview)**.
105
+
106
+ ## Contributing
107
+
108
+ Please read our [Contributing Guide](./CONTRIBUTING.md) before submitting a Pull Request to the project.
109
+
110
+ ## Community support
111
+
112
+ For general help using Strapi, please refer to [the official Strapi documentation](https://strapi.io/documentation/). For additional help, you can use one of these channels to ask a question:
113
+
114
+ - [Discord](https://discord.strapi.io) (For live discussion with the Community and Strapi team)
115
+ - [GitHub](https://github.com/strapi/strapi) (Bug reports, Contributions)
116
+ - [Community Forum](https://forum.strapi.io) (Questions and Discussions)
117
+ - [Academy](https://academy.strapi.io) (Learn the fundamentals of Strapi)
118
+ - [ProductBoard](https://portal.productboard.com/strapi/tabs/2-under-consideration) (Roadmap, Feature requests)
119
+ - [Twitter](https://twitter.com/strapijs) (Get the news fast)
120
+ - [Facebook](https://www.facebook.com/Strapi-616063331867161)
121
+ - [YouTube Channel](https://www.youtube.com/strapi) (Learn from Video Tutorials)
122
+
123
+ ## Migration
124
+
125
+ Follow our [migration guides](https://strapi.io/documentation/developer-docs/latest/update-migration-guides/migration-guides.html) on the documentation to keep your projects up-to-date.
126
+
127
+ ## Roadmap
128
+
129
+ Check out our [roadmap](https://portal.productboard.com/strapi) to get informed of the latest features released and the upcoming ones. You may also give us insights and vote for a specific feature.
130
+
131
+ ## Documentation
132
+
133
+ See our dedicated [repository](https://github.com/strapi/documentation) for the Strapi documentation, or view our documentation live:
134
+
135
+ - [Developer docs](https://strapi.io/documentation/developer-docs/latest/getting-started/introduction.html)
136
+ - [User docs](https://strapi.io/documentation/user-docs/latest/getting-started/introduction.html)
137
+
138
+ ## Try live demo
139
+
140
+ See for yourself what's under the hood by getting access to a [hosted Strapi project](https://strapi.io/demo) with sample data.
141
+
142
+ ## License
143
+
144
+ See the [LICENSE](./LICENSE) file for licensing information.
package/bin/strapi.js ADDED
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // FIXME
5
+ /* eslint-disable import/extensions */
6
+ const _ = require('lodash');
7
+ const resolveCwd = require('resolve-cwd');
8
+ const { yellow } = require('chalk');
9
+ const { Command } = require('commander');
10
+
11
+ const program = new Command();
12
+
13
+ const packageJSON = require('../package.json');
14
+
15
+ const checkCwdIsStrapiApp = name => {
16
+ let logErrorAndExit = () => {
17
+ console.log(
18
+ `You need to run ${yellow(
19
+ `strapi ${name}`
20
+ )} in a Strapi project. Make sure you are in the right directory`
21
+ );
22
+ process.exit(1);
23
+ };
24
+
25
+ try {
26
+ const pkgJSON = require(process.cwd() + '/package.json');
27
+ if (!_.has(pkgJSON, 'dependencies.@strapi/strapi')) {
28
+ logErrorAndExit(name);
29
+ }
30
+ } catch (err) {
31
+ logErrorAndExit(name);
32
+ }
33
+ };
34
+
35
+ const getLocalScript = name => (...args) => {
36
+ checkCwdIsStrapiApp(name);
37
+
38
+ const cmdPath = resolveCwd.silent(`@strapi/strapi/lib/commands/${name}`);
39
+ if (!cmdPath) {
40
+ console.log(
41
+ `Error loading the local ${yellow(
42
+ name
43
+ )} command. Strapi might not be installed in your "node_modules". You may need to run "npm install"`
44
+ );
45
+ process.exit(1);
46
+ }
47
+
48
+ const script = require(cmdPath);
49
+
50
+ Promise.resolve()
51
+ .then(() => {
52
+ return script(...args);
53
+ })
54
+ .catch(error => {
55
+ console.error(error);
56
+ process.exit(1);
57
+ });
58
+ };
59
+
60
+ // Initial program setup
61
+ program.storeOptionsAsProperties(false).allowUnknownOption(true);
62
+
63
+ program.helpOption('-h, --help', 'Display help for command');
64
+ program.addHelpCommand('help [command]', 'Display help for command');
65
+
66
+ // `$ strapi version` (--version synonym)
67
+ program.version(packageJSON.version, '-v, --version', 'Output the version number');
68
+ program
69
+ .command('version')
70
+ .description('Output your version of Strapi')
71
+ .action(() => {
72
+ process.stdout.write(packageJSON.version + '\n');
73
+ process.exit(0);
74
+ });
75
+
76
+ // `$ strapi console`
77
+ program
78
+ .command('console')
79
+ .description('Open the Strapi framework console')
80
+ .action(getLocalScript('console'));
81
+
82
+ // `$ strapi new`
83
+ program
84
+ .command('new <directory>')
85
+ .option('--no-run', 'Do not start the application after it is created')
86
+ .option('--use-npm', 'Force usage of npm instead of yarn to create the project')
87
+ .option('--debug', 'Display database connection error')
88
+ .option('--quickstart', 'Quickstart app creation')
89
+ .option('--dbclient <dbclient>', 'Database client')
90
+ .option('--dbhost <dbhost>', 'Database host')
91
+ .option('--dbport <dbport>', 'Database port')
92
+ .option('--dbname <dbname>', 'Database name')
93
+ .option('--dbusername <dbusername>', 'Database username')
94
+ .option('--dbpassword <dbpassword>', 'Database password')
95
+ .option('--dbssl <dbssl>', 'Database SSL')
96
+ .option('--dbfile <dbfile>', 'Database file path for sqlite')
97
+ .option('--dbforce', 'Overwrite database content if any')
98
+ .description('Create a new application')
99
+ .action(require('../lib/commands/new'));
100
+
101
+ // `$ strapi start`
102
+ program
103
+ .command('start')
104
+ .description('Start your Strapi application')
105
+ .action(getLocalScript('start'));
106
+
107
+ // `$ strapi develop`
108
+ program
109
+ .command('develop')
110
+ .alias('dev')
111
+ .option('--no-build', 'Disable build')
112
+ .option('--watch-admin', 'Enable watch', false)
113
+ .option('--polling', 'Watching file changes in network directories', false)
114
+ .option('--browser <name>', 'Open the browser', true)
115
+ .description('Start your Strapi application in development mode')
116
+ .action(getLocalScript('develop'));
117
+
118
+ // $ strapi generate
119
+ program
120
+ .command('generate')
121
+ .description('Launch interactive API generator')
122
+ .action(() => {
123
+ checkCwdIsStrapiApp('generate');
124
+ process.argv.splice(2, 1);
125
+ require('@strapi/generators').runCLI();
126
+ });
127
+
128
+ // `$ strapi generate:template <directory>`
129
+ program
130
+ .command('generate:template <directory>')
131
+ .description('Generate template from Strapi project')
132
+ .action(getLocalScript('generate-template'));
133
+
134
+ program
135
+ .command('build')
136
+ .option('--clean', 'Remove the build and .cache folders', false)
137
+ .option('--no-optimization', 'Build the Administration without assets optimization')
138
+ .description('Builds the strapi admin app')
139
+ .action(getLocalScript('build'));
140
+
141
+ // `$ strapi install`
142
+ program
143
+ .command('install [plugins...]')
144
+ .description('Install a Strapi plugin')
145
+ .action(getLocalScript('install'));
146
+
147
+ // `$ strapi uninstall`
148
+ program
149
+ .command('uninstall [plugins...]')
150
+ .description('Uninstall a Strapi plugin')
151
+ .option('-d, --delete-files', 'Delete files', false)
152
+ .action(getLocalScript('uninstall'));
153
+
154
+ // `$ strapi watch-admin`
155
+ program
156
+ .command('watch-admin')
157
+ .option('--browser <name>', 'Open the browser', true)
158
+ .description('Starts the admin dev server')
159
+ .action(getLocalScript('watchAdmin'));
160
+
161
+ program
162
+ .command('configuration:dump')
163
+ .alias('config:dump')
164
+ .description('Dump configurations of your application')
165
+ .option('-f, --file <file>', 'Output file, default output is stdout')
166
+ .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)
167
+ .action(getLocalScript('configurationDump'));
168
+
169
+ program
170
+ .command('configuration:restore')
171
+ .alias('config:restore')
172
+ .description('Restore configurations of your application')
173
+ .option('-f, --file <file>', 'Input file, default input is stdin')
174
+ .option('-s, --strategy <strategy>', 'Strategy name, one of: "replace", "merge", "keep"')
175
+ .action(getLocalScript('configurationRestore'));
176
+
177
+ // Admin
178
+ program
179
+ .command('admin:reset-user-password')
180
+ .alias('admin:reset-password')
181
+ .description("Reset an admin user's password")
182
+ .option('-e, --email <email>', 'The user email')
183
+ .option('-p, --password <password>', 'New password for the user')
184
+ .action(getLocalScript('admin-reset'));
185
+
186
+ program.parseAsync(process.argv);