@webiny/api-headless-cms 5.22.0 → 5.23.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.
@@ -7,58 +7,58 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
10
12
  var _error = _interopRequireDefault(require("@webiny/error"));
11
13
 
12
14
  var _handler = require("@webiny/handler");
13
15
 
14
- const extractHandlerHttpParameters = context => {
15
- var _context$http, _context$http$request, _context$http$request2;
16
+ var _CmsParametersPlugin = require("./plugins/CmsParametersPlugin");
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
21
 
17
- const {
18
- key = ""
19
- } = ((_context$http = context.http) === null || _context$http === void 0 ? void 0 : (_context$http$request = _context$http.request) === null || _context$http$request === void 0 ? void 0 : (_context$http$request2 = _context$http$request.path) === null || _context$http$request2 === void 0 ? void 0 : _context$http$request2.parameters) || {};
20
- const [type, locale] = key.split("/");
22
+ const getParameters = async context => {
23
+ const plugins = context.plugins.byType(_CmsParametersPlugin.CmsParametersPlugin.type);
21
24
 
22
- if (!type) {
23
- throw new _error.default(`Missing context.http.request.path parameter "type".`);
24
- } else if (!locale) {
25
- throw new _error.default(`Missing context.http.request.path parameter "locale".`);
25
+ for (const plugin of plugins) {
26
+ const result = await plugin.getParameters(context);
27
+
28
+ if (result !== null) {
29
+ return result;
30
+ }
26
31
  }
27
32
 
28
- return {
29
- type,
30
- locale
31
- };
33
+ throw new _error.default("Could not determine locale and/or type of the CMS.", "CMS_LOCALE_AND_TYPE_ERROR");
32
34
  };
33
35
 
34
36
  var _default = () => {
35
37
  return new _handler.ContextPlugin(async context => {
36
- var _context$http2, _context$http2$reques;
38
+ var _context$http, _context$http$request;
37
39
 
38
- if (((_context$http2 = context.http) === null || _context$http2 === void 0 ? void 0 : (_context$http2$reques = _context$http2.request) === null || _context$http2$reques === void 0 ? void 0 : _context$http2$reques.method) === "OPTIONS") {
40
+ if (((_context$http = context.http) === null || _context$http === void 0 ? void 0 : (_context$http$request = _context$http.request) === null || _context$http$request === void 0 ? void 0 : _context$http$request.method) === "OPTIONS") {
39
41
  return;
40
- } else if (context.cms) {
41
- throw new _error.default("Context setup plugin must be first to be registered. Cannot have anything before it.", "CMS_CONTEXT_INITIALIZED_ERROR");
42
42
  }
43
43
 
44
44
  const {
45
45
  type,
46
46
  locale
47
- } = extractHandlerHttpParameters(context);
47
+ } = await getParameters(context);
48
48
  const systemLocale = context.i18n.getLocale(locale);
49
49
 
50
50
  if (!systemLocale) {
51
51
  throw new _error.default(`There is no locale "${locale}" in the system.`);
52
52
  }
53
53
 
54
- context.cms = {
54
+ context.cms = _objectSpread(_objectSpread({}, context.cms || {}), {}, {
55
55
  type,
56
56
  locale,
57
57
  getLocale: () => systemLocale,
58
58
  READ: type === "read",
59
59
  PREVIEW: type === "preview",
60
60
  MANAGE: type === "manage"
61
- };
61
+ });
62
62
  });
63
63
  };
64
64
 
@@ -142,7 +142,7 @@ const graphQLHandlerFactory = (options = {}) => {
142
142
  http
143
143
  } = context;
144
144
 
145
- if (!http || !http.request || !http.request.path || !http.request.path.parameters) {
145
+ if (!http || !http.request) {
146
146
  return next();
147
147
  }
148
148
 
@@ -0,0 +1,6 @@
1
+ import { CmsParametersPlugin, CmsParametersPluginResponse } from "./plugins/CmsParametersPlugin";
2
+ export interface CreateParametersPluginsParams {
3
+ endpointType?: CmsParametersPluginResponse["type"];
4
+ locale?: CmsParametersPluginResponse["locale"];
5
+ }
6
+ export declare const createParametersPlugins: (params: CreateParametersPluginsParams) => CmsParametersPlugin[];
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createParametersPlugins = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _CmsParametersPlugin = require("./plugins/CmsParametersPlugin");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+
20
+ const createRequestPlugin = () => {
21
+ return new _CmsParametersPlugin.CmsParametersPlugin(async context => {
22
+ /**
23
+ * If any of the properties is not defined, just ignore this plugin
24
+ */
25
+ if (!context.http || !context.http.request || !context.http.request.path || !context.http.request.path.parameters) {
26
+ return null;
27
+ }
28
+
29
+ const {
30
+ key
31
+ } = context.http.request.path.parameters;
32
+
33
+ if (typeof key !== "string") {
34
+ throw new _error.default("The key property in context.http.request.path.parameters is not a string.", "MALFORMED_KEY", {
35
+ key
36
+ });
37
+ }
38
+
39
+ const [type, locale] = key.split("/");
40
+
41
+ if (!type) {
42
+ throw new _error.default(`Missing context.http.request.path.parameters.key parameter "type".`);
43
+ } else if (!locale) {
44
+ throw new _error.default(`Missing context.http.request.path.parameters.key "locale".`);
45
+ }
46
+
47
+ return {
48
+ type,
49
+ locale
50
+ };
51
+ });
52
+ };
53
+
54
+ const createManualPlugin = params => {
55
+ return new _CmsParametersPlugin.CmsParametersPlugin(async () => {
56
+ /**
57
+ * if both of parameters are not existing, just skip this plugin.
58
+ */
59
+ if (!params.endpointType && !params.locale) {
60
+ return null;
61
+ } else if (!params.endpointType) {
62
+ throw new _error.default(`There is defined locale CMS parameter but no endpointType.`, "MALFORMED_ENDPOINT_TYPE", _objectSpread({}, params));
63
+ } else if (!params.locale) {
64
+ throw new _error.default(`There is defined endpointType CMS parameter but no locale.`, "MALFORMED_LOCALE_TYPE", _objectSpread({}, params));
65
+ }
66
+
67
+ return {
68
+ type: params.endpointType,
69
+ locale: params.locale
70
+ };
71
+ });
72
+ };
73
+
74
+ const createParametersPlugins = params => {
75
+ return [createManualPlugin(params), createRequestPlugin()];
76
+ };
77
+
78
+ exports.createParametersPlugins = createParametersPlugins;
@@ -0,0 +1,15 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { CmsContext } from "../../types";
3
+ export interface CmsParametersPluginResponse {
4
+ type: "read" | "manage" | "preview" | string;
5
+ locale: string;
6
+ }
7
+ export interface CmsParametersPluginCallable {
8
+ (context: CmsContext): Promise<CmsParametersPluginResponse>;
9
+ }
10
+ export declare class CmsParametersPlugin extends Plugin {
11
+ static readonly type: string;
12
+ private readonly callable;
13
+ constructor(callable: CmsParametersPluginCallable);
14
+ getParameters(context: CmsContext): Promise<CmsParametersPluginResponse | null>;
15
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.CmsParametersPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class CmsParametersPlugin extends _plugins.Plugin {
15
+ constructor(callable) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "callable", void 0);
18
+ this.callable = callable;
19
+ }
20
+
21
+ async getParameters(context) {
22
+ return this.callable(context);
23
+ }
24
+
25
+ }
26
+
27
+ exports.CmsParametersPlugin = CmsParametersPlugin;
28
+ (0, _defineProperty2.default)(CmsParametersPlugin, "type", "cms-parameters-plugin");
@@ -45,10 +45,7 @@ const typeFromField = ({
45
45
  const replace = new RegExp(`${mTypeName}_`, "g");
46
46
 
47
47
  for (const f of fields) {
48
- const {
49
- fields,
50
- typeDefs
51
- } = typeOfType === "type" ? (0, _renderFields.renderField)({
48
+ const result = typeOfType === "type" ? (0, _renderFields.renderField)({
52
49
  field: f,
53
50
  type,
54
51
  model,
@@ -58,6 +55,15 @@ const typeFromField = ({
58
55
  model,
59
56
  fieldTypePlugins
60
57
  });
58
+
59
+ if (!result) {
60
+ continue;
61
+ }
62
+
63
+ const {
64
+ fields,
65
+ typeDefs
66
+ } = result;
61
67
  typeFields.push(fields.replace(replace, `${fieldTypeName}_`));
62
68
 
63
69
  if (typeDefs) {
@@ -32,7 +32,7 @@ const renderInputField = ({
32
32
 
33
33
  if (!plugin) {
34
34
  // Let's not render the field if it does not exist in the field plugins.
35
- return;
35
+ return null;
36
36
  }
37
37
 
38
38
  const def = plugin.manage.createInputField({
package/index.d.ts CHANGED
@@ -2,11 +2,16 @@ import { Params as CreateAdminCrudsParams } from "./plugins/crud";
2
2
  import { Params as CreateContentCrudsParams } from "./content/plugins/crud";
3
3
  import { CreateGraphQLHandlerOptions } from "./content/graphQLHandlerFactory";
4
4
  import { StorageTransformPlugin } from "./content/plugins/storage/StorageTransformPlugin";
5
+ import { CreateParametersPluginsParams } from "./content/parameterPlugins";
6
+ import { CmsParametersPlugin } from "./content/plugins/CmsParametersPlugin";
7
+ import { CmsGroupPlugin } from "./content/plugins/CmsGroupPlugin";
8
+ import { CmsModelPlugin } from "./content/plugins/CmsModelPlugin";
5
9
  export declare type AdminContextParams = CreateAdminCrudsParams;
6
10
  export declare const createAdminHeadlessCmsContext: (params: AdminContextParams) => (import("@webiny/handler").ContextPlugin<import("./types").CmsContext> | import("@webiny/api-upgrade").UpgradePlugin<import("./types").CmsContext>[])[];
7
11
  export declare const createAdminHeadlessCmsGraphQL: () => import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("@webiny/handler/types").Context>;
8
- export declare type ContentContextParams = CreateContentCrudsParams;
9
- export declare const createContentHeadlessCmsContext: (params: ContentContextParams) => (import("./types").ModelManagerPlugin | import("./types").CmsModelFieldToGraphQLPlugin[] | StorageTransformPlugin<any, any> | import("@webiny/handler").ContextPlugin<import("./types").CmsContext> | (import("./types").CmsModelFieldValidatorPlugin | import("./types").CmsModelFieldPatternValidatorPlugin[])[])[];
12
+ export interface ContentContextParams extends CreateContentCrudsParams, CreateParametersPluginsParams {
13
+ }
14
+ export declare const createContentHeadlessCmsContext: (params: ContentContextParams) => (import("./types").ModelManagerPlugin | import("./types").CmsModelFieldToGraphQLPlugin[] | StorageTransformPlugin<any, any> | import("@webiny/handler").ContextPlugin<import("./types").CmsContext> | CmsParametersPlugin[] | (import("./types").CmsModelFieldValidatorPlugin | import("./types").CmsModelFieldPatternValidatorPlugin[])[])[];
10
15
  export declare type ContentGraphQLParams = CreateGraphQLHandlerOptions;
11
16
  export declare const createContentHeadlessCmsGraphQL: (params?: ContentGraphQLParams) => import("@webiny/plugins/types").PluginCollection;
12
- export { StorageTransformPlugin };
17
+ export { StorageTransformPlugin, CmsParametersPlugin, CmsGroupPlugin, CmsModelPlugin };
package/index.js CHANGED
@@ -5,6 +5,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ Object.defineProperty(exports, "CmsGroupPlugin", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _CmsGroupPlugin.CmsGroupPlugin;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "CmsModelPlugin", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _CmsModelPlugin.CmsModelPlugin;
18
+ }
19
+ });
20
+ Object.defineProperty(exports, "CmsParametersPlugin", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _CmsParametersPlugin.CmsParametersPlugin;
24
+ }
25
+ });
8
26
  Object.defineProperty(exports, "StorageTransformPlugin", {
9
27
  enumerable: true,
10
28
  get: function () {
@@ -39,6 +57,14 @@ var _graphQLHandlerFactory = require("./content/graphQLHandlerFactory");
39
57
 
40
58
  var _StorageTransformPlugin = require("./content/plugins/storage/StorageTransformPlugin");
41
59
 
60
+ var _parameterPlugins = require("./content/parameterPlugins");
61
+
62
+ var _CmsParametersPlugin = require("./content/plugins/CmsParametersPlugin");
63
+
64
+ var _CmsGroupPlugin = require("./content/plugins/CmsGroupPlugin");
65
+
66
+ var _CmsModelPlugin = require("./content/plugins/CmsModelPlugin");
67
+
42
68
  const createAdminHeadlessCmsContext = params => {
43
69
  return [(0, _context.default)(), (0, _crud.createAdminCruds)(params), (0, _upgrades.default)()];
44
70
  };
@@ -52,7 +78,7 @@ const createAdminHeadlessCmsGraphQL = () => {
52
78
  exports.createAdminHeadlessCmsGraphQL = createAdminHeadlessCmsGraphQL;
53
79
 
54
80
  const createContentHeadlessCmsContext = params => {
55
- return [(0, _contextSetup.default)(), (0, _modelManager.default)(), (0, _crud2.createContentCruds)(params), (0, _graphqlFields.default)(), (0, _validators.default)(), (0, _default.default)(), (0, _object.default)() // new InternalAuthenticationPlugin("read-api-key"),
81
+ return [(0, _parameterPlugins.createParametersPlugins)(params), (0, _contextSetup.default)(), (0, _modelManager.default)(), (0, _crud2.createContentCruds)(params), (0, _graphqlFields.default)(), (0, _validators.default)(), (0, _default.default)(), (0, _object.default)() // new InternalAuthenticationPlugin("read-api-key"),
56
82
  // new InternalAuthorizationPlugin("read-api-key")
57
83
  ];
58
84
  };
@@ -153,9 +153,11 @@ const migrateCMSPermissions = async (permissions, getModel) => {
153
153
  exports.migrateCMSPermissions = migrateCMSPermissions;
154
154
 
155
155
  const mergeCustomizer = (objValue, srcValue) => {
156
- if (Array.isArray(objValue)) {
157
- return objValue.concat(srcValue).filter(removeDuplicate);
156
+ if (Array.isArray(objValue) === false) {
157
+ return [];
158
158
  }
159
+
160
+ return objValue.concat(srcValue).filter(removeDuplicate);
159
161
  };
160
162
 
161
163
  const removeDuplicate = (item, index, arr) => arr.findIndex(el => el === item) === index;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.22.0",
3
+ "version": "5.23.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.7",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
23
  "@graphql-tools/schema": "7.1.5",
24
- "@webiny/api-file-manager": "5.22.0",
25
- "@webiny/api-i18n": "5.22.0",
26
- "@webiny/api-i18n-content": "5.22.0",
27
- "@webiny/api-i18n-ddb": "5.22.0",
28
- "@webiny/api-security": "5.22.0",
29
- "@webiny/api-tenancy": "5.22.0",
30
- "@webiny/api-upgrade": "5.22.0",
31
- "@webiny/error": "5.22.0",
32
- "@webiny/handler": "5.22.0",
33
- "@webiny/handler-aws": "5.22.0",
34
- "@webiny/handler-db": "5.22.0",
35
- "@webiny/handler-graphql": "5.22.0",
36
- "@webiny/handler-http": "5.22.0",
37
- "@webiny/plugins": "5.22.0",
38
- "@webiny/pubsub": "5.22.0",
39
- "@webiny/utils": "5.22.0",
40
- "@webiny/validation": "5.22.0",
24
+ "@webiny/api-file-manager": "5.23.0-beta.1",
25
+ "@webiny/api-i18n": "5.23.0-beta.1",
26
+ "@webiny/api-i18n-content": "5.23.0-beta.1",
27
+ "@webiny/api-i18n-ddb": "5.23.0-beta.1",
28
+ "@webiny/api-security": "5.23.0-beta.1",
29
+ "@webiny/api-tenancy": "5.23.0-beta.1",
30
+ "@webiny/api-upgrade": "5.23.0-beta.1",
31
+ "@webiny/error": "5.23.0-beta.1",
32
+ "@webiny/handler": "5.23.0-beta.1",
33
+ "@webiny/handler-aws": "5.23.0-beta.1",
34
+ "@webiny/handler-db": "5.23.0-beta.1",
35
+ "@webiny/handler-graphql": "5.23.0-beta.1",
36
+ "@webiny/handler-http": "5.23.0-beta.1",
37
+ "@webiny/plugins": "5.23.0-beta.1",
38
+ "@webiny/pubsub": "5.23.0-beta.1",
39
+ "@webiny/utils": "5.23.0-beta.1",
40
+ "@webiny/validation": "5.23.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.16.0",
55
55
  "@babel/preset-env": "^7.16.4",
56
56
  "@babel/preset-flow": "^7.16.0",
57
- "@webiny/api-security-so-ddb": "^5.22.0",
58
- "@webiny/api-tenancy-so-ddb": "^5.22.0",
59
- "@webiny/cli": "^5.22.0",
60
- "@webiny/project-utils": "^5.22.0",
57
+ "@webiny/api-security-so-ddb": "^5.23.0-beta.1",
58
+ "@webiny/api-tenancy-so-ddb": "^5.23.0-beta.1",
59
+ "@webiny/cli": "^5.23.0-beta.1",
60
+ "@webiny/project-utils": "^5.23.0-beta.1",
61
61
  "apollo-graphql": "^0.9.5",
62
62
  "get-yarn-workspaces": "^1.0.2",
63
63
  "graphql": "^15.7.2",
@@ -77,5 +77,5 @@
77
77
  "build": "yarn webiny run build",
78
78
  "watch": "yarn webiny run watch"
79
79
  },
80
- "gitHead": "ab2ca1af058fdec3aa1bed3f30afd51f4592dbb6"
80
+ "gitHead": "04f2d5e43684b9086251e2a6370b3c085e6d51cb"
81
81
  }
package/types.d.ts CHANGED
@@ -962,6 +962,7 @@ export interface CmsModelFieldInput {
962
962
  type: string;
963
963
  /**
964
964
  * A unique ID for the field. Values will be mapped via this value.
965
+ * This field MUST be in range of "a-zA-Z".
965
966
  */
966
967
  fieldId: string;
967
968
  /**