@strapi/strapi 4.3.4 → 4.3.7

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 +18 -9
  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 +10 -3
  62. package/lib/middlewares/compression.js +1 -1
  63. package/lib/middlewares/cors.js +3 -10
  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 +22 -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 +34 -20
  76. package/lib/services/entity-service/index.js +73 -52
  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 +6 -6
  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,11 +2,8 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const delegate = require('delegates');
5
- const {
6
- InvalidTimeError,
7
- InvalidDateError,
8
- InvalidDateTimeError,
9
- } = require('@strapi/database').errors;
5
+ const { InvalidTimeError, InvalidDateError, InvalidDateTimeError } =
6
+ require('@strapi/database').errors;
10
7
  const {
11
8
  webhook: webhookUtils,
12
9
  contentTypes: contentTypesUtils,
@@ -17,6 +14,7 @@ const uploadFiles = require('../utils/upload-files');
17
14
 
18
15
  const {
19
16
  omitComponentData,
17
+ getComponents,
20
18
  createComponents,
21
19
  updateComponents,
22
20
  deleteComponents,
@@ -37,51 +35,6 @@ const updatePipeline = (data, context) => {
37
35
  return applyTransforms(data, context);
38
36
  };
39
37
 
40
- module.exports = ctx => {
41
- const implementation = createDefaultImplementation(ctx);
42
-
43
- const service = {
44
- implementation,
45
- decorate(decorator) {
46
- if (typeof decorator !== 'function') {
47
- throw new Error(`Decorator must be a function, received ${typeof decorator}`);
48
- }
49
-
50
- this.implementation = Object.assign({}, this.implementation, decorator(this.implementation));
51
- return this;
52
- },
53
- };
54
-
55
- const delegator = delegate(service, 'implementation');
56
-
57
- // delegate every method in implementation
58
- Object.keys(service.implementation).forEach(key => delegator.method(key));
59
-
60
- // wrap methods to handle Database Errors
61
- service.decorate(oldService => {
62
- const newService = _.mapValues(
63
- oldService,
64
- (method, methodName) =>
65
- async function(...args) {
66
- try {
67
- return await oldService[methodName].call(this, ...args);
68
- } catch (error) {
69
- if (
70
- databaseErrorsToTransform.some(errorToTransform => error instanceof errorToTransform)
71
- ) {
72
- throw new ValidationError(error.message);
73
- }
74
- throw error;
75
- }
76
- }
77
- );
78
-
79
- return newService;
80
- });
81
-
82
- return service;
83
- };
84
-
85
38
  /**
86
39
  * @type {import('.').default}
87
40
  */
@@ -261,8 +214,10 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
261
214
  return null;
262
215
  }
263
216
 
217
+ const componentsToDelete = await getComponents(uid, entityToDelete);
218
+
264
219
  await db.query(uid).delete({ where: { id: entityToDelete.id } });
265
- await deleteComponents(uid, entityToDelete);
220
+ await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete });
266
221
 
267
222
  await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
268
223
 
@@ -276,7 +231,23 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
276
231
  // select / populate
277
232
  const query = transformParamsToQuery(uid, wrappedParams);
278
233
 
279
- return db.query(uid).deleteMany(query);
234
+ const entitiesToDelete = await db.query(uid).findMany(query);
235
+
236
+ if (!entitiesToDelete.length) {
237
+ return null;
238
+ }
239
+
240
+ const componentsToDelete = await Promise.all(
241
+ entitiesToDelete.map((entityToDelete) => getComponents(uid, entityToDelete))
242
+ );
243
+
244
+ const deletedEntities = await db.query(uid).deleteMany(query);
245
+ await Promise.all(componentsToDelete.map((compos) => deleteComponents(uid, compos)));
246
+
247
+ // Trigger webhooks. One for each entity
248
+ await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
249
+
250
+ return deletedEntities;
280
251
  },
281
252
 
282
253
  load(uid, entity, field, params = {}) {
@@ -303,8 +274,58 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
303
274
  Object.assign(loadParams, transformParamsToQuery('plugin::upload.file', params));
304
275
  break;
305
276
  }
277
+ default: {
278
+ break;
279
+ }
306
280
  }
307
281
 
308
282
  return db.query(uid).load(entity, field, loadParams);
309
283
  },
310
284
  });
285
+
286
+ module.exports = (ctx) => {
287
+ const implementation = createDefaultImplementation(ctx);
288
+
289
+ const service = {
290
+ implementation,
291
+ decorate(decorator) {
292
+ if (typeof decorator !== 'function') {
293
+ throw new Error(`Decorator must be a function, received ${typeof decorator}`);
294
+ }
295
+
296
+ this.implementation = { ...this.implementation, ...decorator(this.implementation) };
297
+ return this;
298
+ },
299
+ };
300
+
301
+ const delegator = delegate(service, 'implementation');
302
+
303
+ // delegate every method in implementation
304
+ Object.keys(service.implementation).forEach((key) => delegator.method(key));
305
+
306
+ // wrap methods to handle Database Errors
307
+ service.decorate((oldService) => {
308
+ const newService = _.mapValues(
309
+ oldService,
310
+ (method, methodName) =>
311
+ async function (...args) {
312
+ try {
313
+ return await oldService[methodName].call(this, ...args);
314
+ } catch (error) {
315
+ if (
316
+ databaseErrorsToTransform.some(
317
+ (errorToTransform) => error instanceof errorToTransform
318
+ )
319
+ ) {
320
+ throw new ValidationError(error.message);
321
+ }
322
+ throw error;
323
+ }
324
+ }
325
+ );
326
+
327
+ return newService;
328
+ });
329
+
330
+ return service;
331
+ };
@@ -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