@strapi/strapi 4.0.2 → 4.0.6

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/bin/strapi.js CHANGED
@@ -133,7 +133,6 @@ program
133
133
 
134
134
  program
135
135
  .command('build')
136
- .option('--clean', 'Remove the build and .cache folders', false)
137
136
  .option('--no-optimization', 'Build the Administration without assets optimization')
138
137
  .description('Builds the strapi admin app')
139
138
  .action(getLocalScript('build'));
package/lib/Strapi.js CHANGED
@@ -189,15 +189,13 @@ class Strapi {
189
189
  }
190
190
 
191
191
  sendStartupTelemetry() {
192
- // Get database clients
193
- const databaseClients = _.map(this.config.get('connections'), _.property('settings.client'));
194
-
195
192
  // Emit started event.
196
193
  // do not await to avoid slower startup
197
194
  this.telemetry.send('didStartServer', {
198
- database: databaseClients,
199
- plugins: this.config.installedPlugins,
200
- providers: this.config.installedProviders,
195
+ database: strapi.config.get('database.connection.client'),
196
+ plugins: Object.keys(strapi.plugins),
197
+ // TODO: to add back
198
+ // providers: this.config.installedProviders,
201
199
  });
202
200
  }
203
201
 
@@ -12,7 +12,7 @@ const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins')
12
12
  /**
13
13
  * `$ strapi build`
14
14
  */
15
- module.exports = async ({ clean, optimization, forceBuild = true }) => {
15
+ module.exports = async ({ optimization, forceBuild = true }) => {
16
16
  const dir = process.cwd();
17
17
 
18
18
  const strapiInstance = strapi({
@@ -28,9 +28,8 @@ module.exports = async ({ clean, optimization, forceBuild = true }) => {
28
28
 
29
29
  console.log(`Building your admin UI with ${green(env)} configuration ...`);
30
30
 
31
- if (clean) {
32
- await strapiAdmin.clean({ dir });
33
- }
31
+ // Always remove the .cache and build folders
32
+ await strapiAdmin.clean({ dir });
34
33
 
35
34
  ee({ dir });
36
35
 
@@ -22,14 +22,14 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
22
22
  const logger = createLogger(config.logger, {});
23
23
 
24
24
  try {
25
- if (cluster.isMaster) {
25
+ if (cluster.isMaster || cluster.isPrimary) {
26
26
  const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
27
27
 
28
28
  const buildExists = fs.existsSync(path.join(dir, 'build'));
29
29
  // Don't run the build process if the admin is in watch mode
30
30
  if (build && !watchAdmin && serveAdminPanel && !buildExists) {
31
31
  try {
32
- await buildAdmin({ clean: false, optimization: false, forceBuild: false });
32
+ await buildAdmin({ optimization: false, forceBuild: false });
33
33
  } catch (err) {
34
34
  process.exit(1);
35
35
  }
@@ -126,6 +126,8 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
126
126
  '**/node_modules',
127
127
  '**/node_modules/**',
128
128
  '**/plugins.json',
129
+ '**/build',
130
+ '**/build/**',
129
131
  '**/index.html',
130
132
  '**/public',
131
133
  '**/public/**',
@@ -55,17 +55,6 @@ const applyUserExtension = async plugins => {
55
55
  }
56
56
  };
57
57
 
58
- const formatContentTypes = plugins => {
59
- for (const pluginName in plugins) {
60
- const plugin = plugins[pluginName];
61
- for (const contentTypeName in plugin.contentTypes) {
62
- const ctSchema = plugin.contentTypes[contentTypeName].schema;
63
- ctSchema.plugin = pluginName;
64
- ctSchema.uid = `plugin::${pluginName}.${ctSchema.singularName}`;
65
- }
66
- }
67
- };
68
-
69
58
  const applyUserConfig = async plugins => {
70
59
  const userPluginsConfig = await getUserPluginsConfig();
71
60
 
@@ -111,7 +100,6 @@ const loadPlugins = async strapi => {
111
100
  // TODO: validate plugin format
112
101
  await applyUserConfig(plugins);
113
102
  await applyUserExtension(plugins);
114
- formatContentTypes(plugins);
115
103
 
116
104
  for (const pluginName in plugins) {
117
105
  strapi.container.get('plugins').add(pluginName, plugins[pluginName]);
@@ -12,8 +12,7 @@ const query = require('./query');
12
12
  const responseTime = require('./response-time');
13
13
  const responses = require('./responses');
14
14
  const security = require('./security');
15
- // TODO: add back ?
16
- // session: require('./session'),
15
+ const session = require('./session');
17
16
  const publicStatic = require('./public');
18
17
 
19
18
  module.exports = {
@@ -23,6 +22,7 @@ module.exports = {
23
22
  cors,
24
23
  responseTime,
25
24
  poweredBy,
25
+ session,
26
26
  logger,
27
27
  compression,
28
28
  responses,
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const { defaultsDeep, isEmpty, isArray } = require('lodash/fp');
4
+ const session = require('koa-session');
5
+
6
+ const defaultConfig = {
7
+ key: 'koa.sess',
8
+ maxAge: 86400000,
9
+ autoCommit: true,
10
+ overwrite: true,
11
+ httpOnly: true,
12
+ signed: true,
13
+ rolling: false,
14
+ renew: false,
15
+ secure: process.env.NODE_ENV === 'production' ? true : false,
16
+ sameSite: null,
17
+ };
18
+
19
+ module.exports = (userConfig, { strapi }) => {
20
+ const keys = strapi.server.app.keys;
21
+ if (!isArray(keys) || isEmpty(keys) || keys.some(isEmpty)) {
22
+ throw new Error(`App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`);
23
+ }
24
+
25
+ const config = defaultsDeep(defaultConfig, userConfig);
26
+
27
+ strapi.server.use(session(config, strapi.server.app));
28
+ };
@@ -12,7 +12,7 @@ module.exports = strapi => {
12
12
 
13
13
  const normalizedPath = path.normalize(filePath).replace(/^\/?(\.\/|\.\.\/)+/, '');
14
14
 
15
- return path.join(strapi.dirs.root, normalizedPath);
15
+ return path.resolve(strapi.dirs.root, normalizedPath);
16
16
  }
17
17
 
18
18
  const strapiFS = {
@@ -3,10 +3,10 @@
3
3
  const os = require('os');
4
4
  const _ = require('lodash');
5
5
  const isDocker = require('is-docker');
6
- const { machineIdSync } = require('node-machine-id');
7
6
  const fetch = require('node-fetch');
8
7
  const ciEnv = require('ci-info');
9
8
  const ee = require('../../utils/ee');
9
+ const machineID = require('../../utils/machine-id');
10
10
  const stringifyDeep = require('./stringify-deep');
11
11
 
12
12
  const defaultQueryOpts = {
@@ -33,7 +33,7 @@ const addPackageJsonStrapiMetadata = (metadata, strapi) => {
33
33
  */
34
34
  module.exports = strapi => {
35
35
  const { uuid } = strapi.config;
36
- const deviceId = machineIdSync();
36
+ const deviceId = machineID();
37
37
  const isEE = strapi.EE === true && ee.isEE === true;
38
38
 
39
39
  const anonymous_metadata = {
@@ -28,7 +28,10 @@ const healthCheck = async ctx => {
28
28
  * @returns {Server}
29
29
  */
30
30
  const createServer = strapi => {
31
- const app = createKoaApp({ proxy: strapi.config.get('server.proxy') });
31
+ const app = createKoaApp({
32
+ proxy: strapi.config.get('server.proxy'),
33
+ keys: strapi.config.get('server.app.keys'),
34
+ });
32
35
 
33
36
  const router = new Router();
34
37
 
@@ -53,8 +53,9 @@ const addCustomMethods = app => {
53
53
  return app;
54
54
  };
55
55
 
56
- const createKoaApp = ({ proxy }) => {
56
+ const createKoaApp = ({ proxy, keys }) => {
57
57
  const app = new Koa({ proxy });
58
+ app.keys = keys;
58
59
 
59
60
  addCustomMethods(app);
60
61
 
@@ -5,6 +5,14 @@ const { propOr, isArray, isNil } = require('lodash/fp');
5
5
 
6
6
  const getMiddlewareConfig = propOr([], 'config.middlewares');
7
7
 
8
+ const instantiateMiddleware = (middlewareFactory, name, config, strapi) => {
9
+ try {
10
+ return middlewareFactory(config, { strapi });
11
+ } catch (e) {
12
+ throw new Error(`Middleware "${name}": ${e.message}`);
13
+ }
14
+ };
15
+
8
16
  const resolveRouteMiddlewares = (route, strapi) => {
9
17
  const middlewaresConfig = getMiddlewareConfig(route);
10
18
 
@@ -45,7 +53,7 @@ const resolveMiddlewares = (config, strapi) => {
45
53
 
46
54
  middlewares.push({
47
55
  name: item,
48
- handler: middlewareFactory({}, { strapi }),
56
+ handler: instantiateMiddleware(middlewareFactory, item, {}, strapi),
49
57
  });
50
58
 
51
59
  continue;
@@ -58,16 +66,17 @@ const resolveMiddlewares = (config, strapi) => {
58
66
  const middlewareFactory = strapi.middleware(name);
59
67
  middlewares.push({
60
68
  name,
61
- handler: middlewareFactory(config, { strapi }),
69
+ handler: instantiateMiddleware(middlewareFactory, name, config, strapi),
62
70
  });
63
71
 
64
72
  continue;
65
73
  }
66
74
 
67
75
  if (resolve) {
76
+ const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);
68
77
  middlewares.push({
69
78
  name: resolve,
70
- handler: resolveCustomMiddleware(resolve, strapi)(config, { strapi }),
79
+ handler: instantiateMiddleware(resolvedMiddlewareFactory, item, config, strapi),
71
80
  });
72
81
 
73
82
  continue;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { propOr } = require('lodash/fp');
4
- const { ForbiddenError } = require('@strapi/utils').errors;
4
+ const { PolicyError } = require('@strapi/utils').errors;
5
5
  const { policy: policyUtils } = require('@strapi/utils');
6
6
 
7
7
  const getPoliciesConfig = propOr([], 'config.policies');
@@ -17,7 +17,7 @@ const resolvePolicies = route => {
17
17
  const result = await handler(context, config, { strapi });
18
18
 
19
19
  if (![true, undefined].includes(result)) {
20
- throw new ForbiddenError('Policies failed.');
20
+ throw new PolicyError();
21
21
  }
22
22
  }
23
23
 
@@ -15,6 +15,7 @@ const defaultConfig = [
15
15
  'strapi::security',
16
16
  'strapi::cors',
17
17
  'strapi::poweredBy',
18
+ 'strapi::session',
18
19
  'strapi::logger',
19
20
  'strapi::query',
20
21
  'strapi::body',
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { machineIdSync } = require('node-machine-id');
4
+ const uuid = require('uuid');
5
+
6
+ module.exports = () => {
7
+ try {
8
+ const deviceId = machineIdSync();
9
+ return deviceId;
10
+ } catch (error) {
11
+ const deviceId = uuid();
12
+ return deviceId;
13
+ }
14
+ };
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  const fetch = require('node-fetch');
8
- const { machineIdSync } = require('node-machine-id');
8
+ const machineID = require('./machine-id');
9
9
 
10
10
  /*
11
11
  * No need to worry about this file, we only retrieve anonymous data here.
@@ -21,7 +21,7 @@ try {
21
21
  method: 'POST',
22
22
  body: JSON.stringify({
23
23
  event: 'didInstallStrapi',
24
- deviceId: machineIdSync(),
24
+ deviceId: machineID(),
25
25
  }),
26
26
  headers: { 'Content-Type': 'application/json' },
27
27
  }).catch(() => {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.0.2",
3
+ "version": "4.0.6",
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,22 +80,22 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.0.2",
84
- "@strapi/database": "4.0.2",
85
- "@strapi/generate-new": "4.0.2",
86
- "@strapi/generators": "4.0.2",
87
- "@strapi/logger": "4.0.2",
88
- "@strapi/plugin-content-manager": "4.0.2",
89
- "@strapi/plugin-content-type-builder": "4.0.2",
90
- "@strapi/plugin-email": "4.0.2",
91
- "@strapi/plugin-upload": "4.0.2",
92
- "@strapi/utils": "4.0.2",
83
+ "@strapi/admin": "4.0.6",
84
+ "@strapi/database": "4.0.6",
85
+ "@strapi/generate-new": "4.0.6",
86
+ "@strapi/generators": "4.0.6",
87
+ "@strapi/logger": "4.0.6",
88
+ "@strapi/plugin-content-manager": "4.0.6",
89
+ "@strapi/plugin-content-type-builder": "4.0.6",
90
+ "@strapi/plugin-email": "4.0.6",
91
+ "@strapi/plugin-upload": "4.0.6",
92
+ "@strapi/utils": "4.0.6",
93
93
  "bcryptjs": "2.4.3",
94
94
  "boxen": "5.1.2",
95
95
  "chalk": "4.1.2",
96
96
  "chokidar": "3.5.2",
97
97
  "ci-info": "3.2.0",
98
- "cli-table3": "0.6.0",
98
+ "cli-table3": "0.6.1",
99
99
  "commander": "8.2.0",
100
100
  "configstore": "5.0.1",
101
101
  "debug": "4.3.2",
@@ -117,7 +117,7 @@
117
117
  "koa-session": "6.2.0",
118
118
  "koa-static": "5.0.0",
119
119
  "lodash": "4.17.21",
120
- "node-fetch": "2.6.5",
120
+ "node-fetch": "2.6.7",
121
121
  "node-machine-id": "1.1.12",
122
122
  "node-schedule": "2.0.0",
123
123
  "open": "8.2.1",
@@ -126,14 +126,15 @@
126
126
  "qs": "6.10.1",
127
127
  "resolve-cwd": "3.0.0",
128
128
  "semver": "7.3.5",
129
- "statuses": "2.0.1"
129
+ "statuses": "2.0.1",
130
+ "uuid": "^3.3.2"
130
131
  },
131
132
  "devDependencies": {
132
133
  "supertest": "^6.1.6"
133
134
  },
134
135
  "engines": {
135
- "node": ">=12.x.x <=16.x.x",
136
+ "node": ">=12.22.0 <=16.x.x",
136
137
  "npm": ">=6.0.0"
137
138
  },
138
- "gitHead": "fd656a47698e0a33aae42abd4330410c8cba1d08"
139
+ "gitHead": "5b48053946aacfb564ff423342fe70d79cd6d66d"
139
140
  }
@@ -1,18 +0,0 @@
1
- {
2
- "session": {
3
- "enabled": true,
4
- "client": "cookie",
5
- "key": "strapi.sid",
6
- "prefix": "strapi:sess:",
7
- "ttl": 864000000,
8
- "rolling": false,
9
- "secretKeys": ["mySecretKey1", "mySecretKey2"],
10
- "cookie": {
11
- "path": "/",
12
- "httpOnly": true,
13
- "maxAge": 864000000,
14
- "rewrite": true,
15
- "signed": false
16
- }
17
- }
18
- }
@@ -1,140 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const _ = require('lodash');
5
- const session = require('koa-session');
6
-
7
- /**
8
- * Session middleware
9
- */
10
- module.exports = strapi => {
11
- const requireStore = store => {
12
- return require(path.resolve(strapi.dirs.root, 'node_modules', 'koa-' + store));
13
- };
14
-
15
- const defineStore = session => {
16
- if (_.isEmpty(_.get(session, 'client'))) {
17
- return strapi.log.error(
18
- '(middleware:session) please provide a valid client to store session'
19
- );
20
- } else if (_.isEmpty(_.get(session, 'connection'))) {
21
- return strapi.log.error(
22
- '(middleware:session) please provide connection for the session store'
23
- );
24
- } else if (!strapi.config.get(`database.connections.${session.connection}`)) {
25
- return strapi.log.error(
26
- '(middleware:session) please provide a valid connection for the session store'
27
- );
28
- }
29
-
30
- session.settings = strapi.config.get(`database.connections.${session.connection}`);
31
-
32
- // Define correct store name to avoid require to failed.
33
- switch (session.client.toLowerCase()) {
34
- case 'redis': {
35
- const store = requireStore('redis');
36
-
37
- session.settings.db = session.settings.database;
38
-
39
- return store(session.settings);
40
- }
41
- case 'mysql': {
42
- const Store = requireStore('mysql-session');
43
-
44
- return new Store(session.settings);
45
- }
46
- case 'mongo': {
47
- const Store = requireStore('generic-session-mongo');
48
-
49
- session.settings.db = session.settings.database;
50
-
51
- return new Store(session.settings);
52
- }
53
- case 'postgresql': {
54
- const Store = requireStore('pg-session');
55
-
56
- return new Store(session.settings, session.options);
57
- }
58
- case 'rethink': {
59
- const Store = requireStore('generic-session-rethinkdb');
60
-
61
- session.settings.dbName = session.settings.database;
62
- session.settings.tableName = session.settings.table;
63
-
64
- const sessionStore = new Store({
65
- connection: session.settings,
66
- });
67
-
68
- // Create the DB, tables and indexes to store sessions.
69
- sessionStore.setup();
70
-
71
- return sessionStore;
72
- }
73
- case 'sqlite': {
74
- const Store = requireStore('sqlite3-session');
75
-
76
- return new Store(session.fileName, session.options);
77
- }
78
- case 'sequelize': {
79
- const Store = requireStore('generic-session-sequelize');
80
-
81
- // Sequelize needs to be instantiated.
82
- if (!_.isObject(strapi.sequelize)) {
83
- return null;
84
- }
85
-
86
- return new Store(strapi.sequelize, session.options);
87
- }
88
- default: {
89
- return null;
90
- }
91
- }
92
- };
93
-
94
- return {
95
- initialize() {
96
- strapi.server.app.keys = strapi.config.get('middleware.settings.session.secretKeys');
97
-
98
- if (
99
- _.has(strapi.config.middleware.settings.session, 'client') &&
100
- _.isString(strapi.config.middleware.settings.session.client) &&
101
- strapi.config.middleware.settings.session.client !== 'cookie'
102
- ) {
103
- const store = defineStore(strapi.config.middleware.settings.session);
104
-
105
- if (!_.isEmpty(store)) {
106
- // Options object contains the defined store, the custom middlewares configurations
107
- // and also the function which are located to `./config/functions/session.js`
108
- const options = _.assign(
109
- {
110
- store,
111
- },
112
- strapi.config.middleware.settings.session
113
- );
114
-
115
- strapi.server.use(session(options, strapi.server.app));
116
- strapi.server.use((ctx, next) => {
117
- ctx.state = ctx.state || {};
118
- ctx.state.session = ctx.session || {};
119
-
120
- return next();
121
- });
122
- }
123
- } else if (
124
- _.has(strapi.config.middleware.settings.session, 'client') &&
125
- _.isString(strapi.config.middleware.settings.session.client) &&
126
- strapi.config.middleware.settings.session.client === 'cookie'
127
- ) {
128
- const options = _.assign(strapi.config.middleware.settings.session);
129
-
130
- strapi.server.use(session(options, strapi.server.app));
131
- strapi.server.use((ctx, next) => {
132
- ctx.state = ctx.state || {};
133
- ctx.state.session = ctx.session || {};
134
-
135
- return next();
136
- });
137
- }
138
- },
139
- };
140
- };