@strapi/strapi 4.3.2 → 4.3.5

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 (112) hide show
  1. package/README.md +1 -1
  2. package/bin/strapi.js +29 -26
  3. package/lib/Strapi.js +9 -9
  4. package/lib/commands/admin-create.js +2 -5
  5. package/lib/commands/admin-reset.js +1 -1
  6. package/lib/commands/build.js +1 -1
  7. package/lib/commands/builders/admin.js +1 -1
  8. package/lib/commands/builders/typescript.js +2 -2
  9. package/lib/commands/configurationDump.js +3 -3
  10. package/lib/commands/configurationRestore.js +5 -4
  11. package/lib/commands/console.js +1 -1
  12. package/lib/commands/content-types/list.js +2 -2
  13. package/lib/commands/controllers/list.js +2 -2
  14. package/lib/commands/develop.js +16 -10
  15. package/lib/commands/hooks/list.js +2 -2
  16. package/lib/commands/install.js +4 -4
  17. package/lib/commands/middlewares/list.js +2 -2
  18. package/lib/commands/new.js +1 -1
  19. package/lib/commands/opt-in-telemetry.js +12 -13
  20. package/lib/commands/opt-out-telemetry.js +3 -3
  21. package/lib/commands/policies/list.js +2 -2
  22. package/lib/commands/routes/list.js +3 -3
  23. package/lib/commands/services/list.js +2 -2
  24. package/lib/commands/start.js +1 -0
  25. package/lib/commands/ts/generate-types.js +1 -1
  26. package/lib/commands/uninstall.js +4 -4
  27. package/lib/commands/watchAdmin.js +1 -1
  28. package/lib/compile.js +1 -1
  29. package/lib/container.js +1 -1
  30. package/lib/core/app-configuration/config-loader.js +2 -2
  31. package/lib/core/app-configuration/load-config-file.js +3 -3
  32. package/lib/core/bootstrap.js +1 -1
  33. package/lib/core/domain/component/validator.js +3 -9
  34. package/lib/core/domain/content-type/index.js +2 -2
  35. package/lib/core/domain/content-type/validator.js +9 -23
  36. package/lib/core/domain/module/index.js +1 -1
  37. package/lib/core/domain/module/validation.js +3 -4
  38. package/lib/core/loaders/admin.js +1 -1
  39. package/lib/core/loaders/apis.js +22 -30
  40. package/lib/core/loaders/components.js +2 -2
  41. package/lib/core/loaders/middlewares.js +1 -1
  42. package/lib/core/loaders/plugins/get-enabled-plugins.js +7 -7
  43. package/lib/core/loaders/plugins/index.js +7 -8
  44. package/lib/core/loaders/sanitizers.js +1 -1
  45. package/lib/core/loaders/src-index.js +2 -2
  46. package/lib/core/registries/apis.js +1 -1
  47. package/lib/core/registries/config.js +1 -1
  48. package/lib/core/registries/content-types.js +1 -1
  49. package/lib/core/registries/modules.js +1 -1
  50. package/lib/core/registries/plugins.js +1 -1
  51. package/lib/core/registries/services.js +1 -1
  52. package/lib/core/utils.js +3 -6
  53. package/lib/core-api/controller/transform.js +4 -4
  54. package/lib/core-api/service/collection-type.js +1 -1
  55. package/lib/core-api/service/index.d.ts +6 -3
  56. package/lib/core-api/service/pagination.js +5 -5
  57. package/lib/factories.js +5 -5
  58. package/lib/load/filepath-to-prop-path.js +2 -2
  59. package/lib/load/load-files.js +1 -1
  60. package/lib/load/package-path.js +1 -1
  61. package/lib/middlewares/body.js +7 -3
  62. package/lib/middlewares/compression.js +1 -1
  63. package/lib/middlewares/cors.js +4 -11
  64. package/lib/middlewares/ip.js +1 -1
  65. package/lib/middlewares/logger.js +4 -1
  66. package/lib/middlewares/powered-by.js +1 -1
  67. package/lib/middlewares/query.js +8 -2
  68. package/lib/middlewares/response-time.js +1 -1
  69. package/lib/middlewares/responses.js +1 -1
  70. package/lib/middlewares/security.js +21 -16
  71. package/lib/middlewares/session.js +2 -2
  72. package/lib/migrations/draft-publish.js +1 -5
  73. package/lib/services/auth/index.js +1 -3
  74. package/lib/services/core-store.js +4 -4
  75. package/lib/services/entity-service/components.js +12 -18
  76. package/lib/services/entity-service/index.js +65 -51
  77. package/lib/services/entity-validator/index.js +134 -127
  78. package/lib/services/entity-validator/validators.js +18 -15
  79. package/lib/services/errors.js +6 -10
  80. package/lib/services/event-hub.js +1 -0
  81. package/lib/services/fs.js +1 -1
  82. package/lib/services/metrics/index.js +6 -9
  83. package/lib/services/metrics/is-truthy.js +1 -1
  84. package/lib/services/metrics/sender.js +4 -4
  85. package/lib/services/metrics/stringify-deep.js +1 -1
  86. package/lib/services/server/admin-api.js +1 -1
  87. package/lib/services/server/compose-endpoint.js +7 -7
  88. package/lib/services/server/content-api.js +1 -1
  89. package/lib/services/server/http-server.js +9 -9
  90. package/lib/services/server/index.js +4 -4
  91. package/lib/services/server/koa.js +9 -12
  92. package/lib/services/server/middleware.js +1 -1
  93. package/lib/services/server/policy.js +1 -1
  94. package/lib/services/server/register-middlewares.js +6 -8
  95. package/lib/services/server/register-routes.js +11 -11
  96. package/lib/services/server/routing.js +11 -26
  97. package/lib/services/utils/upload-files.js +3 -3
  98. package/lib/services/webhook-runner.js +8 -7
  99. package/lib/services/webhook-store.js +3 -2
  100. package/lib/services/worker-queue.js +1 -0
  101. package/lib/types/core/strapi/index.d.ts +4 -3
  102. package/lib/types/factories.d.ts +3 -3
  103. package/lib/utils/addSlash.js +3 -3
  104. package/lib/utils/ee.js +1 -1
  105. package/lib/utils/import-default.js +1 -1
  106. package/lib/utils/open-browser.js +1 -1
  107. package/lib/utils/run-checks.js +4 -4
  108. package/lib/utils/signals.js +2 -2
  109. package/lib/utils/startup-logger.js +2 -2
  110. package/lib/utils/success.js +1 -1
  111. package/lib/utils/update-notifier/index.js +4 -4
  112. package/package.json +15 -15
@@ -2,6 +2,7 @@
2
2
  * Entity validator
3
3
  * Module that will validate input data for entity creation or edition
4
4
  */
5
+
5
6
  'use strict';
6
7
 
7
8
  const { has, assoc, prop, isObject } = require('lodash/fp');
@@ -25,110 +26,117 @@ const addMinMax = (validator, { attr, updatedAttribute }) => {
25
26
  return validator;
26
27
  };
27
28
 
28
- const addRequiredValidation = createOrUpdate => (validator, { attr: { required } }) => {
29
- if (required) {
30
- if (createOrUpdate === 'creation') {
31
- validator = validator.notNil();
32
- } else if (createOrUpdate === 'update') {
33
- validator = validator.notNull();
29
+ const addRequiredValidation =
30
+ (createOrUpdate) =>
31
+ (validator, { attr: { required } }) => {
32
+ if (required) {
33
+ if (createOrUpdate === 'creation') {
34
+ validator = validator.notNil();
35
+ } else if (createOrUpdate === 'update') {
36
+ validator = validator.notNull();
37
+ }
38
+ } else {
39
+ validator = validator.nullable();
34
40
  }
35
- } else {
36
- validator = validator.nullable();
37
- }
38
- return validator;
39
- };
41
+ return validator;
42
+ };
40
43
 
41
- const addDefault = createOrUpdate => (validator, { attr }) => {
42
- if (createOrUpdate === 'creation') {
43
- if (
44
- ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&
45
- !attr.required
46
- ) {
47
- validator = validator.default([]);
44
+ const addDefault =
45
+ (createOrUpdate) =>
46
+ (validator, { attr }) => {
47
+ if (createOrUpdate === 'creation') {
48
+ if (
49
+ ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&
50
+ !attr.required
51
+ ) {
52
+ validator = validator.default([]);
53
+ } else {
54
+ validator = validator.default(attr.default);
55
+ }
48
56
  } else {
49
- validator = validator.default(attr.default);
57
+ validator = validator.default(undefined);
50
58
  }
51
- } else {
52
- validator = validator.default(undefined);
53
- }
54
59
 
55
- return validator;
56
- };
60
+ return validator;
61
+ };
57
62
 
58
- const preventCast = validator => validator.transform((val, originalVal) => originalVal);
63
+ const preventCast = (validator) => validator.transform((val, originalVal) => originalVal);
59
64
 
60
- const createComponentValidator = createOrUpdate => ({ attr, updatedAttribute }, { isDraft }) => {
61
- let validator;
65
+ const createComponentValidator =
66
+ (createOrUpdate) =>
67
+ ({ attr, updatedAttribute }, { isDraft }) => {
68
+ let validator;
62
69
 
63
- const model = strapi.getModel(attr.component);
64
- if (!model) {
65
- throw new Error('Validation failed: Model not found');
66
- }
70
+ const model = strapi.getModel(attr.component);
71
+ if (!model) {
72
+ throw new Error('Validation failed: Model not found');
73
+ }
67
74
 
68
- if (prop('repeatable', attr) === true) {
69
- validator = yup
70
- .array()
71
- .of(
72
- yup.lazy(item =>
73
- createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }).notNull()
74
- )
75
- );
75
+ if (prop('repeatable', attr) === true) {
76
+ validator = yup
77
+ .array()
78
+ .of(
79
+ yup.lazy((item) =>
80
+ createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }).notNull()
81
+ )
82
+ );
83
+ validator = addRequiredValidation(createOrUpdate)(validator, { attr: { required: true } });
84
+ validator = addMinMax(validator, { attr, updatedAttribute });
85
+ } else {
86
+ validator = createModelValidator(createOrUpdate)({ model, updatedAttribute }, { isDraft });
87
+ validator = addRequiredValidation(createOrUpdate)(validator, {
88
+ attr: { required: !isDraft && attr.required },
89
+ });
90
+ }
91
+
92
+ return validator;
93
+ };
94
+
95
+ const createDzValidator =
96
+ (createOrUpdate) =>
97
+ ({ attr, updatedAttribute }, { isDraft }) => {
98
+ let validator;
99
+
100
+ validator = yup.array().of(
101
+ yup.lazy((item) => {
102
+ const model = strapi.getModel(prop('__component', item));
103
+ const schema = yup
104
+ .object()
105
+ .shape({
106
+ __component: yup.string().required().oneOf(Object.keys(strapi.components)),
107
+ })
108
+ .notNull();
109
+
110
+ return model
111
+ ? schema.concat(createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }))
112
+ : schema;
113
+ })
114
+ );
76
115
  validator = addRequiredValidation(createOrUpdate)(validator, { attr: { required: true } });
77
116
  validator = addMinMax(validator, { attr, updatedAttribute });
78
- } else {
79
- validator = createModelValidator(createOrUpdate)({ model, updatedAttribute }, { isDraft });
80
- validator = addRequiredValidation(createOrUpdate)(validator, {
81
- attr: { required: !isDraft && attr.required },
82
- });
83
- }
84
-
85
- return validator;
86
- };
87
-
88
- const createDzValidator = createOrUpdate => ({ attr, updatedAttribute }, { isDraft }) => {
89
- let validator;
90
-
91
- validator = yup.array().of(
92
- yup.lazy(item => {
93
- const model = strapi.getModel(prop('__component', item));
94
- const schema = yup
95
- .object()
96
- .shape({
97
- __component: yup
98
- .string()
99
- .required()
100
- .oneOf(Object.keys(strapi.components)),
101
- })
102
- .notNull();
103
-
104
- return model
105
- ? schema.concat(createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }))
106
- : schema;
107
- })
108
- );
109
- validator = addRequiredValidation(createOrUpdate)(validator, { attr: { required: true } });
110
- validator = addMinMax(validator, { attr, updatedAttribute });
111
117
 
112
- return validator;
113
- };
118
+ return validator;
119
+ };
114
120
 
115
- const createRelationValidator = createOrUpdate => ({ attr, updatedAttribute }, { isDraft }) => {
116
- let validator;
121
+ const createRelationValidator =
122
+ (createOrUpdate) =>
123
+ ({ attr, updatedAttribute }, { isDraft }) => {
124
+ let validator;
117
125
 
118
- if (Array.isArray(updatedAttribute.value)) {
119
- validator = yup.array().of(yup.mixed());
120
- } else {
121
- validator = yup.mixed();
122
- }
126
+ if (Array.isArray(updatedAttribute.value)) {
127
+ validator = yup.array().of(yup.mixed());
128
+ } else {
129
+ validator = yup.mixed();
130
+ }
123
131
 
124
- validator = addRequiredValidation(createOrUpdate)(validator, {
125
- attr: { required: !isDraft && attr.required },
126
- });
132
+ validator = addRequiredValidation(createOrUpdate)(validator, {
133
+ attr: { required: !isDraft && attr.required },
134
+ });
127
135
 
128
- return validator;
129
- };
136
+ return validator;
137
+ };
130
138
 
131
- const createScalarAttributeValidator = createOrUpdate => (metas, options) => {
139
+ const createScalarAttributeValidator = (createOrUpdate) => (metas, options) => {
132
140
  let validator;
133
141
 
134
142
  if (has(metas.attr.type, validators)) {
@@ -145,7 +153,7 @@ const createScalarAttributeValidator = createOrUpdate => (metas, options) => {
145
153
  return validator;
146
154
  };
147
155
 
148
- const createAttributeValidator = createOrUpdate => (metas, options) => {
156
+ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
149
157
  let validator;
150
158
 
151
159
  if (isMediaAttribute(metas.attr)) {
@@ -169,50 +177,49 @@ const createAttributeValidator = createOrUpdate => (metas, options) => {
169
177
  return validator;
170
178
  };
171
179
 
172
- const createModelValidator = createOrUpdate => ({ model, data, entity }, options) => {
173
- const writableAttributes = model ? getWritableAttributes(model) : [];
180
+ const createModelValidator =
181
+ (createOrUpdate) =>
182
+ ({ model, data, entity }, options) => {
183
+ const writableAttributes = model ? getWritableAttributes(model) : [];
184
+
185
+ const schema = writableAttributes.reduce((validators, attributeName) => {
186
+ const validator = createAttributeValidator(createOrUpdate)(
187
+ {
188
+ attr: model.attributes[attributeName],
189
+ updatedAttribute: { name: attributeName, value: prop(attributeName, data) },
190
+ model,
191
+ entity,
192
+ },
193
+ options
194
+ );
174
195
 
175
- const schema = writableAttributes.reduce((validators, attributeName) => {
176
- const validator = createAttributeValidator(createOrUpdate)(
177
- {
178
- attr: model.attributes[attributeName],
179
- updatedAttribute: { name: attributeName, value: prop(attributeName, data) },
180
- model,
181
- entity,
182
- },
183
- options
184
- );
196
+ return assoc(attributeName, validator)(validators);
197
+ }, {});
185
198
 
186
- return assoc(attributeName, validator)(validators);
187
- }, {});
199
+ return yup.object().shape(schema);
200
+ };
188
201
 
189
- return yup.object().shape(schema);
190
- };
202
+ const createValidateEntity =
203
+ (createOrUpdate) =>
204
+ async (model, data, { isDraft = false } = {}, entity = null) => {
205
+ if (!isObject(data)) {
206
+ const { displayName } = model.info;
191
207
 
192
- const createValidateEntity = createOrUpdate => async (
193
- model,
194
- data,
195
- { isDraft = false } = {},
196
- entity = null
197
- ) => {
198
- if (!isObject(data)) {
199
- const { displayName } = model.info;
200
-
201
- throw new ValidationError(
202
- `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`
203
- );
204
- }
208
+ throw new ValidationError(
209
+ `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`
210
+ );
211
+ }
205
212
 
206
- const validator = createModelValidator(createOrUpdate)(
207
- {
208
- model,
209
- data,
210
- entity,
211
- },
212
- { isDraft }
213
- ).required();
214
- return validateYupSchema(validator, { strict: false, abortEarly: false })(data);
215
- };
213
+ const validator = createModelValidator(createOrUpdate)(
214
+ {
215
+ model,
216
+ data,
217
+ entity,
218
+ },
219
+ { isDraft }
220
+ ).required();
221
+ return validateYupSchema(validator, { strict: false, abortEarly: false })(data);
222
+ };
216
223
 
217
224
  module.exports = {
218
225
  validateEntityCreation: createValidateEntity('creation'),
@@ -13,17 +13,20 @@ const { yup } = require('@strapi/utils');
13
13
  /**
14
14
  * Utility function to compose validators
15
15
  */
16
- const composeValidators = (...fns) => (...args) => {
17
- let validator = yup.mixed();
18
-
19
- // if we receive a schema then use it as base schema for nested composition
20
- if (yup.isSchema(args[0])) {
21
- validator = args[0];
22
- args = args.slice(1);
23
- }
16
+ const composeValidators =
17
+ (...fns) =>
18
+ (...args) => {
19
+ let nextArgs = args;
20
+ let validator = yup.mixed();
21
+
22
+ // if we receive a schema then use it as base schema for nested composition
23
+ if (yup.isSchema(args[0])) {
24
+ validator = args[0];
25
+ nextArgs = args.slice(1);
26
+ }
24
27
 
25
- return fns.reduce((validator, fn) => fn(validator, ...args), validator);
26
- };
28
+ return fns.reduce((validator, fn) => fn(validator, ...nextArgs), validator);
29
+ };
27
30
 
28
31
  /* Validator utils */
29
32
 
@@ -124,7 +127,7 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
124
127
  return validator;
125
128
  }
126
129
 
127
- return validator.test('unique', 'This attribute must be unique', async value => {
130
+ return validator.test('unique', 'This attribute must be unique', async (value) => {
128
131
  /**
129
132
  * If the attribute value is `null` we want to skip the unique validation.
130
133
  * Otherwise it'll only accept a single `null` entry in the database.
@@ -143,7 +146,7 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
143
146
  return true;
144
147
  }
145
148
 
146
- let whereParams = entity
149
+ const whereParams = entity
147
150
  ? { $and: [{ [updatedAttribute.name]: value }, { $not: { id: entity.id } }] }
148
151
  : { [updatedAttribute.name]: value };
149
152
 
@@ -166,12 +169,12 @@ const stringValidator = composeValidators(
166
169
  addUniqueValidator
167
170
  );
168
171
 
169
- const emailValidator = composeValidators(stringValidator, validator =>
172
+ const emailValidator = composeValidators(stringValidator, (validator) =>
170
173
  validator.email().min(1, '${path} cannot be empty')
171
174
  );
172
175
 
173
- const uidValidator = composeValidators(stringValidator, validator =>
174
- validator.matches(new RegExp('^[A-Za-z0-9-_.~]*$'))
176
+ const uidValidator = composeValidators(stringValidator, (validator) =>
177
+ validator.matches(/^[A-Za-z0-9-_.~]*$/)
175
178
  );
176
179
 
177
180
  const enumerationValidator = ({ attr }) => {
@@ -1,12 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const createError = require('http-errors');
4
- const {
5
- NotFoundError,
6
- UnauthorizedError,
7
- ForbiddenError,
8
- PayloadTooLargeError,
9
- } = require('@strapi/utils').errors;
4
+ const { NotFoundError, UnauthorizedError, ForbiddenError, PayloadTooLargeError } =
5
+ require('@strapi/utils').errors;
10
6
 
11
7
  const mapErrorsAndStatus = [
12
8
  {
@@ -27,8 +23,8 @@ const mapErrorsAndStatus = [
27
23
  },
28
24
  ];
29
25
 
30
- const formatApplicationError = error => {
31
- const errorAndStatus = mapErrorsAndStatus.find(pair => error instanceof pair.classError);
26
+ const formatApplicationError = (error) => {
27
+ const errorAndStatus = mapErrorsAndStatus.find((pair) => error instanceof pair.classError);
32
28
  const status = errorAndStatus ? errorAndStatus.status : 400;
33
29
 
34
30
  return {
@@ -45,7 +41,7 @@ const formatApplicationError = error => {
45
41
  };
46
42
  };
47
43
 
48
- const formatHttpError = error => {
44
+ const formatHttpError = (error) => {
49
45
  return {
50
46
  status: error.status,
51
47
  body: {
@@ -60,7 +56,7 @@ const formatHttpError = error => {
60
56
  };
61
57
  };
62
58
 
63
- const formatInternalError = error => {
59
+ const formatInternalError = (error) => {
64
60
  const httpError = createError(error);
65
61
 
66
62
  if (httpError.expose) {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The event hub is Strapi's event control center.
3
3
  */
4
+
4
5
  'use strict';
5
6
 
6
7
  const EventEmitter = require('events');
@@ -6,7 +6,7 @@ const fse = require('fs-extra');
6
6
  /**
7
7
  * create strapi fs layer
8
8
  */
9
- module.exports = strapi => {
9
+ module.exports = (strapi) => {
10
10
  function normalizePath(optPath) {
11
11
  const filePath = Array.isArray(optPath) ? optPath.join('/') : optPath;
12
12
 
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+
2
3
  /**
3
4
  * Strapi telemetry package.
4
5
  * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html
@@ -22,7 +23,7 @@ const LIMITED_EVENTS = [
22
23
  'didEnableResponsiveDimensions',
23
24
  ];
24
25
 
25
- const createTelemetryInstance = strapi => {
26
+ const createTelemetryInstance = (strapi) => {
26
27
  const uuid = strapi.config.get('uuid');
27
28
  const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');
28
29
  const isDisabled =
@@ -76,7 +77,7 @@ const createTelemetryInstance = strapi => {
76
77
  },
77
78
  destroy() {
78
79
  // clear open handles
79
- crons.forEach(cron => cron.cancel());
80
+ crons.forEach((cron) => cron.cancel());
80
81
  },
81
82
  async send(event, payload) {
82
83
  if (isDisabled) return true;
@@ -85,16 +86,12 @@ const createTelemetryInstance = strapi => {
85
86
  };
86
87
  };
87
88
 
88
- const hash = str =>
89
- crypto
90
- .createHash('sha256')
91
- .update(str)
92
- .digest('hex');
89
+ const hash = (str) => crypto.createHash('sha256').update(str).digest('hex');
93
90
 
94
- const hashProject = strapi =>
91
+ const hashProject = (strapi) =>
95
92
  hash(`${strapi.config.get('info.name')}${strapi.config.get('info.description')}`);
96
93
 
97
- const hashDep = strapi => {
94
+ const hashDep = (strapi) => {
98
95
  const depStr = JSON.stringify(strapi.config.info.dependencies);
99
96
  const readmePath = path.join(strapi.dirs.app.root, 'README.md');
100
97
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
- const isTruthy = val => {
5
+ const isTruthy = (val) => {
6
6
  return [1, true].includes(val) || ['true', '1'].includes(_.toLower(val));
7
7
  };
8
8
 
@@ -33,7 +33,7 @@ const addPackageJsonStrapiMetadata = (metadata, strapi) => {
33
33
  * @param {Object} strapi strapi app
34
34
  * @returns {Function} (event, payload) -> Promise{boolean}
35
35
  */
36
- module.exports = strapi => {
36
+ module.exports = (strapi) => {
37
37
  const { uuid } = strapi.config;
38
38
  const deviceId = machineID();
39
39
  const isEE = strapi.EE === true && ee.isEE === true;
@@ -41,7 +41,7 @@ module.exports = strapi => {
41
41
  const serverRootPath = strapi.dirs.app.root;
42
42
  const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
43
43
 
44
- const anonymous_metadata = {
44
+ const anonymousMetadata = {
45
45
  environment: strapi.config.environment,
46
46
  os: os.type(),
47
47
  osPlatform: os.platform(),
@@ -56,7 +56,7 @@ module.exports = strapi => {
56
56
  useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
57
57
  };
58
58
 
59
- addPackageJsonStrapiMetadata(anonymous_metadata, strapi);
59
+ addPackageJsonStrapiMetadata(anonymousMetadata, strapi);
60
60
 
61
61
  return async (event, payload = {}, opts = {}) => {
62
62
  const reqParams = {
@@ -67,7 +67,7 @@ module.exports = strapi => {
67
67
  deviceId,
68
68
  properties: stringifyDeep({
69
69
  ...payload,
70
- ...anonymous_metadata,
70
+ ...anonymousMetadata,
71
71
  }),
72
72
  }),
73
73
  ..._.merge({}, defaultQueryOpts, opts),
@@ -7,7 +7,7 @@ const { map, mapValues, isObject, isArray, toString } = require('lodash/fp');
7
7
  * @param {object} obj
8
8
  * @returns {object}
9
9
  */
10
- const stringifyDeep = value => {
10
+ const stringifyDeep = (value) => {
11
11
  if (isArray(value)) {
12
12
  return map(stringifyDeep, value);
13
13
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { createAPI } = require('./api');
4
4
 
5
- const createAdminAPI = strapi => {
5
+ const createAdminAPI = (strapi) => {
6
6
  const opts = {
7
7
  prefix: '', // '/admin';
8
8
  type: 'admin',
@@ -7,10 +7,10 @@ const compose = require('koa-compose');
7
7
  const { resolveRouteMiddlewares } = require('./middleware');
8
8
  const { resolvePolicies } = require('./policy');
9
9
 
10
- const getMethod = route => trim(toLower(route.method));
11
- const getPath = route => trim(route.path);
10
+ const getMethod = (route) => trim(toLower(route.method));
11
+ const getPath = (route) => trim(route.path);
12
12
 
13
- const createRouteInfoMiddleware = routeInfo => (ctx, next) => {
13
+ const createRouteInfoMiddleware = (routeInfo) => (ctx, next) => {
14
14
  const route = {
15
15
  ...routeInfo,
16
16
  config: routeInfo.config || {},
@@ -22,7 +22,7 @@ const createRouteInfoMiddleware = routeInfo => (ctx, next) => {
22
22
 
23
23
  const getAuthConfig = prop('config.auth');
24
24
 
25
- const createAuthorizeMiddleware = strapi => async (ctx, next) => {
25
+ const createAuthorizeMiddleware = (strapi) => async (ctx, next) => {
26
26
  const { auth, route } = ctx.state;
27
27
 
28
28
  const authService = strapi.container.get('auth');
@@ -44,7 +44,7 @@ const createAuthorizeMiddleware = strapi => async (ctx, next) => {
44
44
  }
45
45
  };
46
46
 
47
- const createAuthenticateMiddleware = strapi => async (ctx, next) => {
47
+ const createAuthenticateMiddleware = (strapi) => async (ctx, next) => {
48
48
  return strapi.container.get('auth').authenticate(ctx, next);
49
49
  };
50
50
 
@@ -56,7 +56,7 @@ const returnBodyMiddleware = async (ctx, next) => {
56
56
  }
57
57
  };
58
58
 
59
- module.exports = strapi => {
59
+ module.exports = (strapi) => {
60
60
  const authenticate = createAuthenticateMiddleware(strapi);
61
61
  const authorize = createAuthorizeMiddleware(strapi);
62
62
 
@@ -108,7 +108,7 @@ const getController = (name, { pluginName, apiName }, strapi) => {
108
108
  return ctrl;
109
109
  };
110
110
 
111
- const extractHandlerParts = name => {
111
+ const extractHandlerParts = (name) => {
112
112
  const controllerName = name.slice(0, name.lastIndexOf('.'));
113
113
  const actionName = name.slice(name.lastIndexOf('.') + 1);
114
114
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { createAPI } = require('./api');
4
4
 
5
- const createContentAPI = strapi => {
5
+ const createContentAPI = (strapi) => {
6
6
  const opts = {
7
7
  prefix: strapi.config.get('api.rest.prefix', '/api'),
8
8
  type: 'content-api',
@@ -17,7 +17,7 @@ const createHTTPServer = (strapi, koaApp) => {
17
17
 
18
18
  const server = http.createServer(listener);
19
19
 
20
- server.on('connection', connection => {
20
+ server.on('connection', (connection) => {
21
21
  connections.add(connection);
22
22
 
23
23
  connection.on('close', () => {
@@ -26,7 +26,7 @@ const createHTTPServer = (strapi, koaApp) => {
26
26
  });
27
27
 
28
28
  // handle port in use cleanly
29
- server.on('error', err => {
29
+ server.on('error', (err) => {
30
30
  if (err.code === 'EADDRINUSE') {
31
31
  return strapi.stopWithError(`The port ${err.port} is already used by another application.`);
32
32
  }
@@ -45,15 +45,15 @@ const createHTTPServer = (strapi, koaApp) => {
45
45
  return;
46
46
  }
47
47
 
48
- return new Promise((resolve, reject) =>
49
- server.close(error => {
48
+ return new Promise((resolve, reject) => {
49
+ server.close((error) => {
50
50
  if (error) {
51
- return reject(error);
51
+ reject(error);
52
+ } else {
53
+ resolve();
52
54
  }
53
-
54
- resolve();
55
- })
56
- );
55
+ });
56
+ });
57
57
  };
58
58
 
59
59
  return server;