@webiny/api-headless-cms 5.20.0-beta.0 → 5.20.0-beta.1

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.
@@ -1,3 +1,4 @@
1
1
  export declare const CreateContentModelModel: any;
2
+ export declare const CreateContentModelModelFrom: any;
2
3
  export declare const ContentModelFieldModel: any;
3
4
  export declare const UpdateContentModelModel: any;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.UpdateContentModelModel = exports.CreateContentModelModel = exports.ContentModelFieldModel = void 0;
8
+ exports.UpdateContentModelModel = exports.CreateContentModelModelFrom = exports.CreateContentModelModel = exports.ContentModelFieldModel = void 0;
9
9
 
10
10
  var _validation = require("@webiny/validation");
11
11
 
@@ -36,6 +36,24 @@ const CreateContentModelModel = (0, _fields.withFields)({
36
36
  })
37
37
  })();
38
38
  exports.CreateContentModelModel = CreateContentModelModel;
39
+ const CreateContentModelModelFrom = (0, _fields.withFields)({
40
+ name: (0, _fields.string)({
41
+ validation: requiredShortString
42
+ }),
43
+ modelId: (0, _fields.string)({
44
+ validation: shortString
45
+ }),
46
+ description: (0, _fields.string)({
47
+ validation: shortString
48
+ }),
49
+ group: (0, _fields.string)({
50
+ validation: requiredShortString
51
+ }),
52
+ locale: (0, _fields.string)({
53
+ validation: shortString
54
+ })
55
+ })();
56
+ exports.CreateContentModelModelFrom = CreateContentModelModelFrom;
39
57
  const RendererModel = (0, _fields.withFields)({
40
58
  name: (0, _fields.string)({
41
59
  validation: requiredShortString
@@ -264,8 +264,10 @@ const createModelsCrud = params => {
264
264
  }
265
265
 
266
266
  const identity = getIdentity();
267
-
268
- const model = _objectSpread(_objectSpread({}, input), {}, {
267
+ const model = {
268
+ name: input.name,
269
+ description: input.description,
270
+ modelId: input.modelId,
269
271
  titleFieldId: "id",
270
272
  locale: getLocale().code,
271
273
  tenant: getTenant().id,
@@ -284,8 +286,7 @@ const createModelsCrud = params => {
284
286
  lockedFields: [],
285
287
  layout: [],
286
288
  webinyVersion: context.WEBINY_VERSION
287
- });
288
-
289
+ };
289
290
  await onBeforeCreate.publish({
290
291
  model,
291
292
  input
@@ -346,17 +347,30 @@ const createModelsCrud = params => {
346
347
  */
347
348
 
348
349
  const original = await get(modelId);
349
- const createdData = new _models.CreateContentModelModel().populate({
350
+ const createdData = new _models.CreateContentModelModelFrom().populate({
350
351
  name: data.name,
351
352
  modelId: data.modelId,
352
353
  description: data.description || original.description,
353
- group: data.group
354
+ group: data.group,
355
+ locale: data.locale
354
356
  });
355
357
  await createdData.validate();
356
358
  const input = await createdData.toJSON();
357
- context.security.disableAuthorization();
358
- const group = await context.cms.getGroup(input.group);
359
- context.security.enableAuthorization();
359
+ const locale = await context.i18n.getLocale(input.locale || original.locale);
360
+
361
+ if (!locale) {
362
+ throw new _handlerGraphql.NotFoundError(`There is no locale "${input.locale}".`);
363
+ }
364
+ /**
365
+ * Use storage operations directly because we cannot get group from different locale via context methods.
366
+ */
367
+
368
+
369
+ const group = await context.cms.storageOperations.groups.get({
370
+ id: input.group,
371
+ tenant: original.tenant,
372
+ locale: locale.code
373
+ });
360
374
 
361
375
  if (!group) {
362
376
  throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
@@ -365,6 +379,7 @@ const createModelsCrud = params => {
365
379
  const identity = getIdentity();
366
380
 
367
381
  const model = _objectSpread(_objectSpread({}, original), {}, {
382
+ locale: locale.code,
368
383
  group: {
369
384
  id: group.id,
370
385
  name: group.name
@@ -416,25 +431,30 @@ const createModelsCrud = params => {
416
431
  return {};
417
432
  }
418
433
 
434
+ let group = {
435
+ id: original.group.id,
436
+ name: original.group.name
437
+ };
438
+
419
439
  if (input.group) {
420
440
  context.security.disableAuthorization();
421
- const group = await context.cms.getGroup(input.group);
441
+ const groupData = await context.cms.getGroup(input.group);
422
442
  context.security.enableAuthorization();
423
443
 
424
- if (!group) {
444
+ if (!groupData) {
425
445
  throw new _handlerGraphql.NotFoundError(`There is no group "${input.group}".`);
426
446
  }
427
447
 
428
- input.group = {
429
- id: group.id,
430
- name: group.name
448
+ group = {
449
+ id: groupData.id,
450
+ name: groupData.name
431
451
  };
432
452
  }
433
453
 
434
454
  const modelFields = await (0, _createFieldModels.createFieldModels)(original, inputData);
435
- (0, _validateLayout.validateLayout)(input, modelFields);
436
455
 
437
456
  const model = _objectSpread(_objectSpread(_objectSpread({}, original), input), {}, {
457
+ group,
438
458
  tenant: original.tenant || getTenant().id,
439
459
  locale: original.locale || getLocale().code,
440
460
  webinyVersion: context.WEBINY_VERSION,
@@ -442,6 +462,7 @@ const createModelsCrud = params => {
442
462
  savedOn: new Date().toISOString()
443
463
  });
444
464
 
465
+ (0, _validateLayout.validateLayout)(model, modelFields);
445
466
  await onBeforeUpdate.publish({
446
467
  input,
447
468
  original,
@@ -133,6 +133,7 @@ const plugin = context => {
133
133
  modelId: String
134
134
  group: RefInput!
135
135
  description: String
136
+ locale: String
136
137
  }
137
138
 
138
139
  input CmsContentModelUpdateInput {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.20.0-beta.0",
3
+ "version": "5.20.0-beta.1",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "cms:base"
@@ -21,23 +21,23 @@
21
21
  "@babel/runtime": "7.16.3",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
23
  "@graphql-tools/schema": "7.1.5",
24
- "@webiny/api-file-manager": "5.20.0-beta.0",
25
- "@webiny/api-i18n": "5.20.0-beta.0",
26
- "@webiny/api-i18n-content": "5.20.0-beta.0",
27
- "@webiny/api-i18n-ddb": "5.20.0-beta.0",
28
- "@webiny/api-security": "5.20.0-beta.0",
29
- "@webiny/api-tenancy": "5.20.0-beta.0",
30
- "@webiny/api-upgrade": "5.20.0-beta.0",
31
- "@webiny/error": "5.20.0-beta.0",
32
- "@webiny/handler": "5.20.0-beta.0",
33
- "@webiny/handler-aws": "5.20.0-beta.0",
34
- "@webiny/handler-db": "5.20.0-beta.0",
35
- "@webiny/handler-graphql": "5.20.0-beta.0",
36
- "@webiny/handler-http": "5.20.0-beta.0",
37
- "@webiny/plugins": "5.20.0-beta.0",
38
- "@webiny/pubsub": "5.20.0-beta.0",
39
- "@webiny/utils": "5.20.0-beta.0",
40
- "@webiny/validation": "5.20.0-beta.0",
24
+ "@webiny/api-file-manager": "5.20.0-beta.1",
25
+ "@webiny/api-i18n": "5.20.0-beta.1",
26
+ "@webiny/api-i18n-content": "5.20.0-beta.1",
27
+ "@webiny/api-i18n-ddb": "5.20.0-beta.1",
28
+ "@webiny/api-security": "5.20.0-beta.1",
29
+ "@webiny/api-tenancy": "5.20.0-beta.1",
30
+ "@webiny/api-upgrade": "5.20.0-beta.1",
31
+ "@webiny/error": "5.20.0-beta.1",
32
+ "@webiny/handler": "5.20.0-beta.1",
33
+ "@webiny/handler-aws": "5.20.0-beta.1",
34
+ "@webiny/handler-db": "5.20.0-beta.1",
35
+ "@webiny/handler-graphql": "5.20.0-beta.1",
36
+ "@webiny/handler-http": "5.20.0-beta.1",
37
+ "@webiny/plugins": "5.20.0-beta.1",
38
+ "@webiny/pubsub": "5.20.0-beta.1",
39
+ "@webiny/utils": "5.20.0-beta.1",
40
+ "@webiny/validation": "5.20.0-beta.1",
41
41
  "boolean": "3.1.4",
42
42
  "commodo-fields-object": "1.0.6",
43
43
  "dataloader": "2.0.0",
@@ -54,10 +54,10 @@
54
54
  "@babel/core": "^7.5.5",
55
55
  "@babel/preset-env": "^7.5.5",
56
56
  "@babel/preset-flow": "^7.0.0",
57
- "@webiny/api-security-so-ddb": "^5.20.0-beta.0",
58
- "@webiny/api-tenancy-so-ddb": "^5.20.0-beta.0",
59
- "@webiny/cli": "^5.20.0-beta.0",
60
- "@webiny/project-utils": "^5.20.0-beta.0",
57
+ "@webiny/api-security-so-ddb": "^5.20.0-beta.1",
58
+ "@webiny/api-tenancy-so-ddb": "^5.20.0-beta.1",
59
+ "@webiny/cli": "^5.20.0-beta.1",
60
+ "@webiny/project-utils": "^5.20.0-beta.1",
61
61
  "apollo-graphql": "^0.4.1",
62
62
  "get-yarn-workspaces": "^1.0.2",
63
63
  "graphql": "^14.6.0",
@@ -77,5 +77,5 @@
77
77
  "build": "yarn webiny run build",
78
78
  "watch": "yarn webiny run watch"
79
79
  },
80
- "gitHead": "2de02bc113e15e3ffa8e1d82deb9d27417787188"
80
+ "gitHead": "40e30fb4c778d0bcc773b3b8231ce8e0861b6d52"
81
81
  }
package/types.d.ts CHANGED
@@ -910,6 +910,18 @@ export interface CmsModelCreateInput {
910
910
  */
911
911
  group: string;
912
912
  }
913
+ /**
914
+ * A GraphQL params.data parameter received when creating content model from existing model.
915
+ *
916
+ * @category GraphQL params
917
+ * @category CmsModel
918
+ */
919
+ export interface CmsModelCreateFromInput extends CmsModelCreateInput {
920
+ /**
921
+ * Locale into which we want to clone the model into.
922
+ */
923
+ locale?: string;
924
+ }
913
925
  /**
914
926
  * A definition for content model field received from the user.
915
927
  *
@@ -981,6 +993,10 @@ export interface CmsModelUpdateInput {
981
993
  * A new content model name.
982
994
  */
983
995
  name?: string;
996
+ /**
997
+ * A group we want to move the model to.
998
+ */
999
+ group?: string;
984
1000
  /**
985
1001
  * A new description of the content model.
986
1002
  */
@@ -1156,30 +1172,30 @@ export interface CmsModelManager {
1156
1172
  delete: (id: string) => Promise<void>;
1157
1173
  }
1158
1174
  export interface BeforeModelCreateTopicParams {
1159
- input: Partial<CmsModel>;
1175
+ input: CmsModelCreateInput;
1160
1176
  model: CmsModel;
1161
1177
  }
1162
1178
  export interface AfterModelCreateTopicParams {
1163
- input: Partial<CmsModel>;
1179
+ input: CmsModelCreateInput;
1164
1180
  model: CmsModel;
1165
1181
  }
1166
1182
  export interface BeforeModelCreateFromTopicParams {
1167
- input: Partial<CmsModel>;
1183
+ input: CmsModelCreateFromInput;
1168
1184
  original: CmsModel;
1169
1185
  model: CmsModel;
1170
1186
  }
1171
1187
  export interface AfterModelCreateFromTopicParams {
1172
- input: Partial<CmsModel>;
1188
+ input: CmsModelCreateFromInput;
1173
1189
  original: CmsModel;
1174
1190
  model: CmsModel;
1175
1191
  }
1176
1192
  export interface BeforeModelUpdateTopicParams {
1177
- input: Partial<CmsModel>;
1193
+ input: CmsModelUpdateInput;
1178
1194
  original: CmsModel;
1179
1195
  model: CmsModel;
1180
1196
  }
1181
1197
  export interface AfterModelUpdateTopicParams {
1182
- input: Partial<CmsModel>;
1198
+ input: CmsModelUpdateInput;
1183
1199
  original: CmsModel;
1184
1200
  model: CmsModel;
1185
1201
  }
@@ -1224,7 +1240,7 @@ export interface CmsModelContext {
1224
1240
  /**
1225
1241
  * Create a content model from the given model - clone.
1226
1242
  */
1227
- createModelFrom: (modelId: string, data: CmsModelCreateInput) => Promise<CmsModel>;
1243
+ createModelFrom: (modelId: string, data: CmsModelCreateFromInput) => Promise<CmsModel>;
1228
1244
  /**
1229
1245
  * Update content model without data validation. Used internally.
1230
1246
  * @hidden
package/types.js CHANGED
@@ -191,6 +191,13 @@ exports.CONTENT_ENTRY_STATUS = void 0;
191
191
  * @category CmsModel
192
192
  */
193
193
 
194
+ /**
195
+ * A GraphQL params.data parameter received when creating content model from existing model.
196
+ *
197
+ * @category GraphQL params
198
+ * @category CmsModel
199
+ */
200
+
194
201
  /**
195
202
  * A definition for content model field received from the user.
196
203
  *