@strapi/strapi 4.4.0-beta.1 → 4.4.0-beta.4

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/lib/Strapi.js CHANGED
@@ -23,6 +23,7 @@ const entityValidator = require('./services/entity-validator');
23
23
  const createTelemetry = require('./services/metrics');
24
24
  const createAuth = require('./services/auth');
25
25
  const createContentAPI = require('./services/content-api');
26
+ const createCustomFields = require('./services/custom-fields');
26
27
  const createUpdateNotifier = require('./utils/update-notifier');
27
28
  const createStartupLogger = require('./utils/startup-logger');
28
29
  const { LIFECYCLES } = require('./utils/lifecycles');
@@ -35,12 +36,14 @@ const hooksRegistry = require('./core/registries/hooks');
35
36
  const controllersRegistry = require('./core/registries/controllers');
36
37
  const modulesRegistry = require('./core/registries/modules');
37
38
  const pluginsRegistry = require('./core/registries/plugins');
39
+ const customFieldsRegistry = require('./core/registries/custom-fields');
38
40
  const createConfigProvider = require('./core/registries/config');
39
41
  const apisRegistry = require('./core/registries/apis');
40
42
  const bootstrap = require('./core/bootstrap');
41
43
  const loaders = require('./core/loaders');
42
44
  const { destroyOnSignal } = require('./utils/signals');
43
45
  const sanitizersRegistry = require('./core/registries/sanitizers');
46
+ const convertCustomFieldType = require('./utils/convert-custom-field-type');
44
47
 
45
48
  // TODO: move somewhere else
46
49
  const draftAndPublishSync = require('./migrations/draft-publish');
@@ -88,6 +91,7 @@ class Strapi {
88
91
  this.container.register('controllers', controllersRegistry(this));
89
92
  this.container.register('modules', modulesRegistry(this));
90
93
  this.container.register('plugins', pluginsRegistry(this));
94
+ this.container.register('custom-fields', customFieldsRegistry(this));
91
95
  this.container.register('apis', apisRegistry(this));
92
96
  this.container.register('auth', createAuth(this));
93
97
  this.container.register('content-api', createContentAPI(this));
@@ -111,6 +115,8 @@ class Strapi {
111
115
  this.cron = createCronService();
112
116
  this.telemetry = createTelemetry(this);
113
117
 
118
+ this.customFields = createCustomFields(this);
119
+
114
120
  createUpdateNotifier(this).notify();
115
121
  }
116
122
 
@@ -383,6 +389,8 @@ class Strapi {
383
389
  this.telemetry.register();
384
390
 
385
391
  await this.runLifecyclesFunctions(LIFECYCLES.REGISTER);
392
+ // NOTE: Swap type customField for underlying data type
393
+ convertCustomFieldType(this);
386
394
 
387
395
  return this;
388
396
  }
@@ -17,7 +17,7 @@ const passwordValidator = yup
17
17
  const adminCreateSchema = yup.object().shape({
18
18
  email: emailValidator,
19
19
  password: passwordValidator,
20
- firstname: yup.string().required('First name is required'),
20
+ firstname: yup.string().trim().required('First name is required'),
21
21
  lastname: yup.string(),
22
22
  });
23
23
 
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ const { has } = require('lodash/fp');
4
+ const validators = require('../../services/entity-validator/validators');
5
+
6
+ const customFieldsRegistry = (strapi) => {
7
+ const customFields = {};
8
+
9
+ return {
10
+ getAll() {
11
+ return customFields;
12
+ },
13
+ get(customField) {
14
+ const registeredCustomField = customFields[customField];
15
+ if (!registeredCustomField) {
16
+ throw new Error(`Could not find Custom Field: ${customField}`);
17
+ }
18
+
19
+ return registeredCustomField;
20
+ },
21
+ add(customField) {
22
+ const customFieldList = Array.isArray(customField) ? customField : [customField];
23
+
24
+ for (const cf of customFieldList) {
25
+ if (!has('name', cf) || !has('type', cf)) {
26
+ throw new Error(`Custom fields require a 'name' and 'type' key`);
27
+ }
28
+
29
+ const { name, plugin, type } = cf;
30
+ if (!has(type, validators)) {
31
+ throw new Error(
32
+ `Custom field type: '${type}' is not a valid Strapi type or it can't be used with a Custom Field`
33
+ );
34
+ }
35
+
36
+ const isValidObjectKey = /^(?![0-9])[a-zA-Z0-9$_-]+$/g;
37
+ if (!isValidObjectKey.test(name)) {
38
+ throw new Error(`Custom field name: '${name}' is not a valid object key`);
39
+ }
40
+
41
+ // When no plugin is specified, or it isn't found in Strapi, default to global
42
+ const uid = strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;
43
+
44
+ if (has(uid, customFields)) {
45
+ throw new Error(`Custom field: '${uid}' has already been registered`);
46
+ }
47
+
48
+ customFields[uid] = cf;
49
+ }
50
+ },
51
+ };
52
+ };
53
+
54
+ module.exports = customFieldsRegistry;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const createCustomFields = (strapi) => {
4
+ return {
5
+ register(customField) {
6
+ strapi.container.get('custom-fields').add(customField);
7
+ },
8
+ };
9
+ };
10
+
11
+ module.exports = createCustomFields;
@@ -5,6 +5,28 @@ import type { StringMap } from './utils';
5
5
  import type { GenericController } from '../../../core-api/controller'
6
6
  import type { GenericService } from '../../../core-api/service'
7
7
 
8
+ // TODO move custom fields types to a separate file
9
+ interface CustomFieldServerOptions {
10
+ /**
11
+ * The name of the custom field
12
+ */
13
+ name: string;
14
+
15
+ /**
16
+ * The name of the plugin creating the custom field
17
+ */
18
+ plugin?: string;
19
+
20
+ /**
21
+ * The existing Strapi data type the custom field uses
22
+ */
23
+ type: string;
24
+ }
25
+
26
+ interface CustomFields {
27
+ register: (customFields: CustomFieldServerOptions[] | CustomFieldServerOptions) => void;
28
+ }
29
+
8
30
  /**
9
31
  * The Strapi interface implemented by the main Strapi class.
10
32
  */
@@ -70,6 +92,13 @@ export interface Strapi {
70
92
  */
71
93
  contentType(uid: string): any;
72
94
 
95
+ /**
96
+ * The custom fields registry
97
+ *
98
+ * It returns the custom fields interface
99
+ */
100
+ readonly customFields: CustomFields;
101
+
73
102
  /**
74
103
  * Getter for the Strapi policies container
75
104
  *
@@ -200,7 +229,7 @@ export interface Strapi {
200
229
  /**
201
230
  * Restart the server and reload all the configuration.
202
231
  * It re-runs all the lifecycles phases.
203
- *
232
+ *
204
233
  * @example
205
234
  * ``` ts
206
235
  * setImmediate(() => strapi.reload());
@@ -228,13 +257,13 @@ export interface Strapi {
228
257
  /**
229
258
  * Opent he administration panel in a browser if the option is enabled.
230
259
  * You can disable it using the admin.autoOpen configuration variable.
231
- *
260
+ *
232
261
  * Note: It only works in development envs.
233
262
  */
234
263
  openAdmin(options: { isInitialized: boolean }): Promise<void>;
235
264
 
236
265
  /**
237
- * Load the admin panel server logic into the server code and initialize its configuration.
266
+ * Load the admin panel server logic into the server code and initialize its configuration.
238
267
  */
239
268
  loadAdmin(): Promise<void>;
240
269
 
@@ -293,7 +322,7 @@ export interface Strapi {
293
322
  container: any;
294
323
 
295
324
  /**
296
- * References to all the directories handled by Strapi
325
+ * References to all the directories handled by Strapi
297
326
  */
298
327
  dirs: StrapiDirectories;
299
328
 
@@ -328,7 +357,7 @@ export interface Strapi {
328
357
  startupLogger: any;
329
358
 
330
359
  /**
331
- * Strapi logger used to send errors, warning or information messages
360
+ * Strapi logger used to send errors, warning or information messages
332
361
  */
333
362
  log: any;
334
363
 
@@ -361,7 +390,7 @@ export interface Strapi {
361
390
  /**
362
391
  * Entity Service instance
363
392
  */
364
- entityService: any;
393
+ entityService: any;
365
394
  }
366
395
 
367
396
  export interface Lifecycles {
@@ -394,4 +423,4 @@ export interface StrapiDirectories {
394
423
  middlewares: string;
395
424
  config: string;
396
425
  };
397
- }
426
+ }
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const convertCustomFieldType = (strapi) => {
4
+ const allContentTypeSchemaAttributes = Object.values(strapi.contentTypes).map(
5
+ (schema) => schema.attributes
6
+ );
7
+ const allComponentSchemaAttributes = Object.values(strapi.components).map(
8
+ (schema) => schema.attributes
9
+ );
10
+ const allSchemasAttributes = [...allContentTypeSchemaAttributes, ...allComponentSchemaAttributes];
11
+
12
+ for (const schemaAttrbutes of allSchemasAttributes) {
13
+ for (const attribute of Object.values(schemaAttrbutes)) {
14
+ if (attribute.type === 'customField') {
15
+ const customField = strapi.container.get('custom-fields').get(attribute.customField);
16
+ attribute.type = customField.type;
17
+ }
18
+ }
19
+ }
20
+ };
21
+
22
+ module.exports = convertCustomFieldType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.4.0-beta.1",
3
+ "version": "4.4.0-beta.4",
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,18 +80,18 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.4.1",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.4.0-beta.1",
84
- "@strapi/database": "4.4.0-beta.1",
85
- "@strapi/generate-new": "4.4.0-beta.1",
86
- "@strapi/generators": "4.4.0-beta.1",
87
- "@strapi/logger": "4.4.0-beta.1",
88
- "@strapi/permissions": "4.4.0-beta.1",
89
- "@strapi/plugin-content-manager": "4.4.0-beta.1",
90
- "@strapi/plugin-content-type-builder": "4.4.0-beta.1",
91
- "@strapi/plugin-email": "4.4.0-beta.1",
92
- "@strapi/plugin-upload": "4.4.0-beta.1",
93
- "@strapi/typescript-utils": "4.4.0-beta.1",
94
- "@strapi/utils": "4.4.0-beta.1",
83
+ "@strapi/admin": "4.4.0-beta.4",
84
+ "@strapi/database": "4.4.0-beta.4",
85
+ "@strapi/generate-new": "4.4.0-beta.4",
86
+ "@strapi/generators": "4.4.0-beta.4",
87
+ "@strapi/logger": "4.4.0-beta.4",
88
+ "@strapi/permissions": "4.4.0-beta.4",
89
+ "@strapi/plugin-content-manager": "4.4.0-beta.4",
90
+ "@strapi/plugin-content-type-builder": "4.4.0-beta.4",
91
+ "@strapi/plugin-email": "4.4.0-beta.4",
92
+ "@strapi/plugin-upload": "4.4.0-beta.4",
93
+ "@strapi/typescript-utils": "4.4.0-beta.4",
94
+ "@strapi/utils": "4.4.0-beta.4",
95
95
  "bcryptjs": "2.4.3",
96
96
  "boxen": "5.1.2",
97
97
  "chalk": "4.1.2",
@@ -140,5 +140,5 @@
140
140
  "node": ">=14.19.1 <=18.x.x",
141
141
  "npm": ">=6.0.0"
142
142
  },
143
- "gitHead": "cae16f7f259fa4473a55e8fea57839cda98f34ae"
143
+ "gitHead": "8ad31453be3eda4e01eae027995e7e584892e688"
144
144
  }