@webiny/api-headless-cms 0.0.0-mt-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.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/content/contextSetup.d.ts +4 -0
- package/content/contextSetup.js +65 -0
- package/content/graphQLHandlerFactory.d.ts +5 -0
- package/content/graphQLHandlerFactory.js +173 -0
- package/content/plugins/CmsGroupPlugin.d.ts +11 -0
- package/content/plugins/CmsGroupPlugin.js +24 -0
- package/content/plugins/CmsModelPlugin.d.ts +11 -0
- package/content/plugins/CmsModelPlugin.js +24 -0
- package/content/plugins/buildSchemaPlugins.d.ts +7 -0
- package/content/plugins/buildSchemaPlugins.js +29 -0
- package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
- package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
- package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
- package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
- package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
- package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
- package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +4 -0
- package/content/plugins/crud/contentEntry/entryDataValidation.js +188 -0
- package/content/plugins/crud/contentEntry/markLockedFields.d.ts +12 -0
- package/content/plugins/crud/contentEntry/markLockedFields.js +117 -0
- package/content/plugins/crud/contentEntry.crud.d.ts +17 -0
- package/content/plugins/crud/contentEntry.crud.js +931 -0
- package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterCreate.js +18 -0
- package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterDelete.js +18 -0
- package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
- package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
- package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
- package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
- package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
- package/content/plugins/crud/contentModel/contentModelManagerFactory.js +29 -0
- package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -0
- package/content/plugins/crud/contentModel/createFieldModels.js +22 -0
- package/content/plugins/crud/contentModel/idValidation.d.ts +2 -0
- package/content/plugins/crud/contentModel/idValidation.js +22 -0
- package/content/plugins/crud/contentModel/models.d.ts +3 -0
- package/content/plugins/crud/contentModel/models.js +141 -0
- package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -0
- package/content/plugins/crud/contentModel/validateLayout.js +38 -0
- package/content/plugins/crud/contentModel.crud.d.ts +12 -0
- package/content/plugins/crud/contentModel.crud.js +425 -0
- package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
- package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
- package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
- package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
- package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
- package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
- package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -0
- package/content/plugins/crud/contentModelGroup.crud.js +351 -0
- package/content/plugins/crud/index.d.ts +6 -0
- package/content/plugins/crud/index.js +100 -0
- package/content/plugins/graphqlFields/boolean.d.ts +3 -0
- package/content/plugins/graphqlFields/boolean.js +69 -0
- package/content/plugins/graphqlFields/datetime.d.ts +3 -0
- package/content/plugins/graphqlFields/datetime.js +83 -0
- package/content/plugins/graphqlFields/file.d.ts +3 -0
- package/content/plugins/graphqlFields/file.js +49 -0
- package/content/plugins/graphqlFields/index.d.ts +2 -0
- package/content/plugins/graphqlFields/index.js +30 -0
- package/content/plugins/graphqlFields/longText.d.ts +3 -0
- package/content/plugins/graphqlFields/longText.js +62 -0
- package/content/plugins/graphqlFields/number.d.ts +3 -0
- package/content/plugins/graphqlFields/number.js +75 -0
- package/content/plugins/graphqlFields/object.d.ts +3 -0
- package/content/plugins/graphqlFields/object.js +180 -0
- package/content/plugins/graphqlFields/ref.d.ts +3 -0
- package/content/plugins/graphqlFields/ref.js +205 -0
- package/content/plugins/graphqlFields/richText.d.ts +3 -0
- package/content/plugins/graphqlFields/richText.js +55 -0
- package/content/plugins/graphqlFields/text.d.ts +3 -0
- package/content/plugins/graphqlFields/text.js +72 -0
- package/content/plugins/internalSecurity/InternalAuthenticationPlugin.d.ts +8 -0
- package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +54 -0
- package/content/plugins/internalSecurity/InternalAuthorizationPlugin.d.ts +7 -0
- package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +35 -0
- package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
- package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
- package/content/plugins/modelManager/index.d.ts +3 -0
- package/content/plugins/modelManager/index.js +20 -0
- package/content/plugins/schema/baseSchema.d.ts +4 -0
- package/content/plugins/schema/baseSchema.js +98 -0
- package/content/plugins/schema/contentEntries.d.ts +4 -0
- package/content/plugins/schema/contentEntries.js +166 -0
- package/content/plugins/schema/contentModelGroups.d.ts +4 -0
- package/content/plugins/schema/contentModelGroups.js +153 -0
- package/content/plugins/schema/contentModels.d.ts +4 -0
- package/content/plugins/schema/contentModels.js +225 -0
- package/content/plugins/schema/createFieldResolvers.d.ts +19 -0
- package/content/plugins/schema/createFieldResolvers.js +92 -0
- package/content/plugins/schema/createManageResolvers.d.ts +11 -0
- package/content/plugins/schema/createManageResolvers.js +135 -0
- package/content/plugins/schema/createManageSDL.d.ts +9 -0
- package/content/plugins/schema/createManageSDL.js +153 -0
- package/content/plugins/schema/createPreviewResolvers.d.ts +10 -0
- package/content/plugins/schema/createPreviewResolvers.js +55 -0
- package/content/plugins/schema/createReadResolvers.d.ts +10 -0
- package/content/plugins/schema/createReadResolvers.js +55 -0
- package/content/plugins/schema/createReadSDL.d.ts +9 -0
- package/content/plugins/schema/createReadSDL.js +96 -0
- package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +6 -0
- package/content/plugins/schema/resolvers/commonFieldResolvers.js +14 -0
- package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveCreate.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +7 -0
- package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveDelete.js +30 -0
- package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGet.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveList.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolvePublish.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +7 -0
- package/content/plugins/schema/resolvers/manage/resolveUpdate.js +23 -0
- package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/preview/resolveGet.js +38 -0
- package/content/plugins/schema/resolvers/preview/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/preview/resolveList.js +23 -0
- package/content/plugins/schema/resolvers/read/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/read/resolveGet.js +38 -0
- package/content/plugins/schema/resolvers/read/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/read/resolveList.js +23 -0
- package/content/plugins/schema/schemaPlugins.d.ts +3 -0
- package/content/plugins/schema/schemaPlugins.js +92 -0
- package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
- package/content/plugins/storage/StorageTransformPlugin.js +36 -0
- package/content/plugins/storage/default.d.ts +3 -0
- package/content/plugins/storage/default.js +28 -0
- package/content/plugins/storage/object.d.ts +3 -0
- package/content/plugins/storage/object.js +119 -0
- package/content/plugins/utils/createTypeName.d.ts +3 -0
- package/content/plugins/utils/createTypeName.js +28 -0
- package/content/plugins/utils/entryStorage.d.ts +17 -0
- package/content/plugins/utils/entryStorage.js +125 -0
- package/content/plugins/utils/getEntryTitle.d.ts +2 -0
- package/content/plugins/utils/getEntryTitle.js +42 -0
- package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +11 -0
- package/content/plugins/utils/getSchemaFromFieldPlugins.js +30 -0
- package/content/plugins/utils/pluralizedTypeName.d.ts +1 -0
- package/content/plugins/utils/pluralizedTypeName.js +26 -0
- package/content/plugins/utils/renderFields.d.ts +16 -0
- package/content/plugins/utils/renderFields.js +51 -0
- package/content/plugins/utils/renderGetFilterFields.d.ts +9 -0
- package/content/plugins/utils/renderGetFilterFields.js +41 -0
- package/content/plugins/utils/renderInputFields.d.ts +14 -0
- package/content/plugins/utils/renderInputFields.js +53 -0
- package/content/plugins/utils/renderListFilterFields.d.ts +10 -0
- package/content/plugins/utils/renderListFilterFields.js +39 -0
- package/content/plugins/utils/renderSortEnum.d.ts +9 -0
- package/content/plugins/utils/renderSortEnum.js +32 -0
- package/content/plugins/validators/dateGte.d.ts +3 -0
- package/content/plugins/validators/dateGte.js +37 -0
- package/content/plugins/validators/dateLte.d.ts +3 -0
- package/content/plugins/validators/dateLte.js +37 -0
- package/content/plugins/validators/gte.d.ts +3 -0
- package/content/plugins/validators/gte.js +32 -0
- package/content/plugins/validators/in.d.ts +3 -0
- package/content/plugins/validators/in.js +32 -0
- package/content/plugins/validators/index.d.ts +2 -0
- package/content/plugins/validators/index.js +36 -0
- package/content/plugins/validators/lte.d.ts +3 -0
- package/content/plugins/validators/lte.js +32 -0
- package/content/plugins/validators/maxLength.d.ts +3 -0
- package/content/plugins/validators/maxLength.js +32 -0
- package/content/plugins/validators/minLength.d.ts +3 -0
- package/content/plugins/validators/minLength.js +32 -0
- package/content/plugins/validators/pattern.d.ts +3 -0
- package/content/plugins/validators/pattern.js +47 -0
- package/content/plugins/validators/patternPlugins/email.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/email.js +17 -0
- package/content/plugins/validators/patternPlugins/index.d.ts +2 -0
- package/content/plugins/validators/patternPlugins/index.js +19 -0
- package/content/plugins/validators/patternPlugins/lowerCase.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/lowerCase.js +17 -0
- package/content/plugins/validators/patternPlugins/upperCase.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/upperCase.js +17 -0
- package/content/plugins/validators/patternPlugins/url.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/url.js +17 -0
- package/content/plugins/validators/required.d.ts +3 -0
- package/content/plugins/validators/required.js +25 -0
- package/content/plugins/validators/timeGte.d.ts +3 -0
- package/content/plugins/validators/timeGte.js +32 -0
- package/content/plugins/validators/timeLte.d.ts +3 -0
- package/content/plugins/validators/timeLte.js +32 -0
- package/index.d.ts +12 -0
- package/index.js +66 -0
- package/migrateCMSPermissions.d.ts +17 -0
- package/migrateCMSPermissions.js +193 -0
- package/package.json +80 -0
- package/plugins/context.d.ts +4 -0
- package/plugins/context.js +34 -0
- package/plugins/crud/index.d.ts +6 -0
- package/plugins/crud/index.js +100 -0
- package/plugins/crud/settings.crud.d.ts +10 -0
- package/plugins/crud/settings.crud.js +93 -0
- package/plugins/crud/system.crud.d.ts +10 -0
- package/plugins/crud/system.crud.js +182 -0
- package/plugins/graphql/system.d.ts +17 -0
- package/plugins/graphql/system.js +72 -0
- package/plugins/graphql.d.ts +2 -0
- package/plugins/graphql.js +79 -0
- package/plugins/upgrades/index.d.ts +2 -0
- package/plugins/upgrades/index.js +14 -0
- package/plugins/upgrades/v5.5.0/helpers.d.ts +6 -0
- package/plugins/upgrades/v5.5.0/helpers.js +10 -0
- package/plugins/upgrades/v5.5.0/index.d.ts +4 -0
- package/plugins/upgrades/v5.5.0/index.js +129 -0
- package/transformers.d.ts +2 -0
- package/transformers.js +25 -0
- package/types.d.ts +2149 -0
- package/types.js +366 -0
- package/utils.d.ts +25 -0
- package/utils.js +251 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @webiny/api-headless-cms
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/api-headless-cms)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/api-headless-cms)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install --save @webiny/api-headless-cms
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or if you prefer yarn:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
yarn add @webiny/api-headless-cms
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Testing
|
|
21
|
+
Due to possibility of multiple storage operations, the tests are completely decoupled from those storage operations.
|
|
22
|
+
|
|
23
|
+
The [jest.setup.js](./jest.setup.js) is using [@webiny/project-utils/testing/presets.js](../project-utils/testing/presets/index.js) to find and load all the packages containing `@webiny/api-headless-cms` and `storage-operations` keywords in their `package.json` file.
|
|
24
|
+
Those packages are then used to build the test run - one for each of the packages. So depending on how many storage operations there are in the repository, that much of `api-headless-cms` tests will run.
|
|
25
|
+
|
|
26
|
+
### Defining test environment
|
|
27
|
+
To make it possible for api-headless-cms tests to run with a storage operations package you MUST create `presets.js` file in `storage-operations-package-path/__tests__/__api__/` directory. That file is loaded when setting up the api-headless-cms tests.
|
|
28
|
+
|
|
29
|
+
It MUST contain the `testEnvironment` variable which contains path to the environment definition file.
|
|
30
|
+
|
|
31
|
+
That environment file MUST define the test environment which extends `NodeEnvironment` class.
|
|
32
|
+
|
|
33
|
+
Test environment MUST expose `__getStorageOperationsPlugins` method, via `this.global` property of the class, which will load the required plugins in the `api-headless-cms` tests.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Examples of preset and test environment files
|
|
37
|
+
|
|
38
|
+
The first implementation of the decoupled storage operations is DynamoDB/Elasticsearch, which you can find in [@webiny/api-headless-cms-ddb-es](../api-headless-cms-ddb-es).
|
|
39
|
+
Files which you can check to help you define your own presets and test environment are:
|
|
40
|
+
* [presets.js](../api-headless-cms-ddb-es/__tests__/__api__/presets.js) - an array of presets of which last one defines the environment to be loaded
|
|
41
|
+
* [environment.js](../api-headless-cms-ddb-es/__tests__/__api__/environment.js) - a class which extends NodeEnvironment and exposes `__getStorageOperationsPlugins` to the tests
|
|
42
|
+
|
|
43
|
+
### Debugging when testing
|
|
44
|
+
For the WebStorm (PhpStorm,...) when starting a test you must have some values defined in the run/debug configurations screen:
|
|
45
|
+
#### Node options
|
|
46
|
+
`````
|
|
47
|
+
--inspect=9229
|
|
48
|
+
`````
|
|
49
|
+
#### Working directory
|
|
50
|
+
`````
|
|
51
|
+
PATH_TO_YOUR_PROJECT_ROOT
|
|
52
|
+
`````
|
|
53
|
+
example:
|
|
54
|
+
````
|
|
55
|
+
~/webiny/webiny-js/
|
|
56
|
+
````
|
|
57
|
+
#### Jest options
|
|
58
|
+
For DynamoDB + Elasticsearch storage operations tests:
|
|
59
|
+
`````
|
|
60
|
+
--keyword=cms:base --keyword=cms:ddb-es
|
|
61
|
+
`````
|
|
62
|
+
For the DynamoDB storage operations tests:
|
|
63
|
+
`````
|
|
64
|
+
--keyword=cms:base --keyword=cms:ddb
|
|
65
|
+
`````
|
|
66
|
+
Note that base keyword is the `cms:base`. It tells Jest setup to load the `api-headless-cms` tests with the api-headless-cms-ddb-es tests.
|
|
67
|
+
|
|
68
|
+
#### Environment variables
|
|
69
|
+
If you want to use local Elasticsearch:
|
|
70
|
+
`````
|
|
71
|
+
ELASTICSEARCH_PORT=9200;LOCAL_ELASTICSEARCH=true
|
|
72
|
+
`````
|
|
73
|
+
Nothing if you do not want to use the local Elasticsearch.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
|
|
13
|
+
|
|
14
|
+
const extractHandlerHttpParameters = context => {
|
|
15
|
+
var _context$http, _context$http$request, _context$http$request2;
|
|
16
|
+
|
|
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("/");
|
|
21
|
+
|
|
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".`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
type,
|
|
30
|
+
locale
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var _default = () => {
|
|
35
|
+
return new _ContextPlugin.ContextPlugin(async context => {
|
|
36
|
+
var _context$http2, _context$http2$reques;
|
|
37
|
+
|
|
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") {
|
|
39
|
+
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
|
+
}
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
type,
|
|
46
|
+
locale
|
|
47
|
+
} = extractHandlerHttpParameters(context);
|
|
48
|
+
const systemLocale = context.i18n.getLocale(locale);
|
|
49
|
+
|
|
50
|
+
if (!systemLocale) {
|
|
51
|
+
throw new _error.default(`There is no locale "${locale}" in the system.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
context.cms = {
|
|
55
|
+
type,
|
|
56
|
+
locale,
|
|
57
|
+
getLocale: () => systemLocale,
|
|
58
|
+
READ: type === "read",
|
|
59
|
+
PREVIEW: type === "preview",
|
|
60
|
+
MANAGE: type === "manage"
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.default = _default;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.graphQLHandlerFactory = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _boolean = require("boolean");
|
|
13
|
+
|
|
14
|
+
var _schema = require("@graphql-tools/schema");
|
|
15
|
+
|
|
16
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
17
|
+
|
|
18
|
+
var _debugPlugins = _interopRequireDefault(require("@webiny/handler-graphql/debugPlugins"));
|
|
19
|
+
|
|
20
|
+
var _processRequestBody = _interopRequireDefault(require("@webiny/handler-graphql/processRequestBody"));
|
|
21
|
+
|
|
22
|
+
var _buildSchemaPlugins = _interopRequireDefault(require("./plugins/buildSchemaPlugins"));
|
|
23
|
+
|
|
24
|
+
var _plugins = require("@webiny/handler-graphql/plugins");
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
29
|
+
|
|
30
|
+
const DEFAULT_HEADERS = {
|
|
31
|
+
"Access-Control-Allow-Origin": "*",
|
|
32
|
+
"Access-Control-Allow-Headers": "*",
|
|
33
|
+
"Access-Control-Allow-Methods": "OPTIONS,POST",
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
};
|
|
36
|
+
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
37
|
+
|
|
38
|
+
const respond = (http, result) => {
|
|
39
|
+
return http.response({
|
|
40
|
+
body: JSON.stringify(result),
|
|
41
|
+
statusCode: 200,
|
|
42
|
+
headers: DEFAULT_HEADERS
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const schemaList = new Map();
|
|
47
|
+
|
|
48
|
+
const generateCacheKey = async args => {
|
|
49
|
+
const {
|
|
50
|
+
context,
|
|
51
|
+
locale,
|
|
52
|
+
type
|
|
53
|
+
} = args;
|
|
54
|
+
const lastModelChange = await context.cms.getModelLastChange();
|
|
55
|
+
return [locale.code, type, lastModelChange.toISOString()].join("#");
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const generateSchema = async args => {
|
|
59
|
+
const {
|
|
60
|
+
context
|
|
61
|
+
} = args;
|
|
62
|
+
context.plugins.register(await (0, _buildSchemaPlugins.default)(context));
|
|
63
|
+
const typeDefs = [];
|
|
64
|
+
const resolvers = []; // Get schema definitions from plugins
|
|
65
|
+
|
|
66
|
+
const schemaPlugins = context.plugins.byType(_plugins.GraphQLSchemaPlugin.type);
|
|
67
|
+
|
|
68
|
+
for (const pl of schemaPlugins) {
|
|
69
|
+
typeDefs.push(pl.schema.typeDefs);
|
|
70
|
+
resolvers.push(pl.schema.resolvers);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (0, _schema.makeExecutableSchema)({
|
|
74
|
+
typeDefs,
|
|
75
|
+
resolvers
|
|
76
|
+
});
|
|
77
|
+
}; // gets an existing schema or rewrites existing one or creates a completely new one
|
|
78
|
+
// depending on the schemaId created from type and locale parameters
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const getSchema = async args => {
|
|
82
|
+
const {
|
|
83
|
+
context,
|
|
84
|
+
type,
|
|
85
|
+
locale
|
|
86
|
+
} = args;
|
|
87
|
+
const tenantId = context.tenancy.getCurrentTenant().id;
|
|
88
|
+
const id = `${tenantId}#${type}#${locale.code}`;
|
|
89
|
+
const cacheKey = await generateCacheKey(args);
|
|
90
|
+
|
|
91
|
+
if (!schemaList.has(id)) {
|
|
92
|
+
const schema = await generateSchema(args);
|
|
93
|
+
schemaList.set(id, {
|
|
94
|
+
key: cacheKey,
|
|
95
|
+
schema
|
|
96
|
+
});
|
|
97
|
+
return schema;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const cache = schemaList.get(id);
|
|
101
|
+
|
|
102
|
+
if (cache.key === cacheKey) {
|
|
103
|
+
return cache.schema;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const schema = await generateSchema(args);
|
|
107
|
+
schemaList.set(id, {
|
|
108
|
+
key: cacheKey,
|
|
109
|
+
schema
|
|
110
|
+
});
|
|
111
|
+
return schema;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const checkEndpointAccess = async context => {
|
|
115
|
+
const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
|
|
116
|
+
|
|
117
|
+
if (!permission) {
|
|
118
|
+
throw new _apiSecurity.NotAuthorizedError({
|
|
119
|
+
data: {
|
|
120
|
+
reason: `Not allowed to access "${context.cms.type}" endpoint.`
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const graphQLHandlerFactory = (options = {}) => {
|
|
127
|
+
const debug = (0, _boolean.boolean)(options.debug);
|
|
128
|
+
return [...(debug ? (0, _debugPlugins.default)() : []), {
|
|
129
|
+
type: "handler",
|
|
130
|
+
name: "handler-graphql-content-model",
|
|
131
|
+
|
|
132
|
+
async handle(context, next) {
|
|
133
|
+
const {
|
|
134
|
+
http
|
|
135
|
+
} = context;
|
|
136
|
+
|
|
137
|
+
if (!http || !http.request || !http.request.path || !http.request.path.parameters) {
|
|
138
|
+
return next();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (http.request.method === "OPTIONS") {
|
|
142
|
+
return http.response({
|
|
143
|
+
statusCode: 204,
|
|
144
|
+
headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
|
|
145
|
+
"Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (http.request.method !== "POST") {
|
|
151
|
+
return next();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
await checkEndpointAccess(context);
|
|
156
|
+
} catch (ex) {
|
|
157
|
+
return respond(http, new _apiSecurity.NotAuthorizedResponse(ex));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const schema = await getSchema({
|
|
161
|
+
context,
|
|
162
|
+
locale: context.cms.getLocale(),
|
|
163
|
+
type: context.cms.type
|
|
164
|
+
});
|
|
165
|
+
const body = JSON.parse(http.request.body);
|
|
166
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
167
|
+
return respond(http, result);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}];
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
exports.graphQLHandlerFactory = graphQLHandlerFactory;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { CmsGroup as BaseCmsGroup } from "../../types";
|
|
3
|
+
export interface CmsGroup extends Omit<BaseCmsGroup, "locale" | "tenant" | "webinyVersion"> {
|
|
4
|
+
tenant?: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class CmsGroupPlugin extends Plugin {
|
|
8
|
+
static readonly type: string;
|
|
9
|
+
contentModelGroup: CmsGroup;
|
|
10
|
+
constructor(contentModelGroup: CmsGroup);
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CmsGroupPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class CmsGroupPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(contentModelGroup) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "contentModelGroup", void 0);
|
|
18
|
+
this.contentModelGroup = contentModelGroup;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.CmsGroupPlugin = CmsGroupPlugin;
|
|
24
|
+
(0, _defineProperty2.default)(CmsGroupPlugin, "type", "cms-content-model-group");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { CmsModel as CmsModelBase } from "../../types";
|
|
3
|
+
export interface CmsModel extends Omit<CmsModelBase, "locale" | "tenant" | "webinyVersion"> {
|
|
4
|
+
locale?: string;
|
|
5
|
+
tenant?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class CmsModelPlugin extends Plugin {
|
|
8
|
+
static readonly type: string;
|
|
9
|
+
contentModel: CmsModel;
|
|
10
|
+
constructor(contentModel: CmsModel);
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CmsModelPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class CmsModelPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(contentModel) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "contentModel", void 0);
|
|
18
|
+
this.contentModel = contentModel;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.CmsModelPlugin = CmsModelPlugin;
|
|
24
|
+
(0, _defineProperty2.default)(CmsModelPlugin, "type", "cms-content-model");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/plugins/GraphQLSchemaPlugin";
|
|
2
|
+
import { CmsContext } from "../../types";
|
|
3
|
+
declare const _default: (context: CmsContext) => Promise<GraphQLSchemaPlugin<CmsContext>[]>;
|
|
4
|
+
/**
|
|
5
|
+
* This factory is called whenever we need to generate graphql-schema plugins using the current context.
|
|
6
|
+
*/
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _contentModels = _interopRequireDefault(require("./schema/contentModels"));
|
|
11
|
+
|
|
12
|
+
var _contentEntries = _interopRequireDefault(require("./schema/contentEntries"));
|
|
13
|
+
|
|
14
|
+
var _contentModelGroups = _interopRequireDefault(require("./schema/contentModelGroups"));
|
|
15
|
+
|
|
16
|
+
var _baseSchema = _interopRequireDefault(require("./schema/baseSchema"));
|
|
17
|
+
|
|
18
|
+
var _schemaPlugins = require("./schema/schemaPlugins");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This factory is called whenever we need to generate graphql-schema plugins using the current context.
|
|
22
|
+
*/
|
|
23
|
+
var _default = async context => {
|
|
24
|
+
return [// Base GQL types and scalars
|
|
25
|
+
(0, _baseSchema.default)(context), (0, _contentModels.default)(context), (0, _contentEntries.default)(context), (0, _contentModelGroups.default)(context), // Dynamic schema
|
|
26
|
+
...(await (0, _schemaPlugins.generateSchemaPlugins)(context))].filter(Boolean);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.default = _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Topic } from "@webiny/pubsub/types";
|
|
2
|
+
import { AfterEntryDeleteTopicParams, CmsContext } from "../../../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
context: CmsContext;
|
|
5
|
+
onAfterDelete: Topic<AfterEntryDeleteTopicParams>;
|
|
6
|
+
}
|
|
7
|
+
export declare const assignAfterEntryDelete: (params: Params) => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assignAfterEntryDelete = void 0;
|
|
7
|
+
|
|
8
|
+
var _markLockedFields = require("./markLockedFields");
|
|
9
|
+
|
|
10
|
+
const assignAfterEntryDelete = params => {
|
|
11
|
+
const {
|
|
12
|
+
context,
|
|
13
|
+
onAfterDelete
|
|
14
|
+
} = params;
|
|
15
|
+
onAfterDelete.subscribe(async params => {
|
|
16
|
+
const {
|
|
17
|
+
entry,
|
|
18
|
+
model
|
|
19
|
+
} = params;
|
|
20
|
+
const {
|
|
21
|
+
items
|
|
22
|
+
} = await context.cms.storageOperations.entries.list(model, {
|
|
23
|
+
where: {
|
|
24
|
+
entryId_not: entry.entryId,
|
|
25
|
+
latest: true
|
|
26
|
+
},
|
|
27
|
+
limit: 1
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (items.length > 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await (0, _markLockedFields.markUnlockedFields)({
|
|
35
|
+
context,
|
|
36
|
+
model
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.assignAfterEntryDelete = assignAfterEntryDelete;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Topic } from "@webiny/pubsub/types";
|
|
2
|
+
import { BeforeEntryCreateTopicParams, CmsContext } from "../../../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
context: CmsContext;
|
|
5
|
+
onBeforeCreate: Topic<BeforeEntryCreateTopicParams>;
|
|
6
|
+
}
|
|
7
|
+
export declare const assignBeforeEntryCreate: (params: Params) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assignBeforeEntryCreate = void 0;
|
|
7
|
+
|
|
8
|
+
var _markLockedFields = require("./markLockedFields");
|
|
9
|
+
|
|
10
|
+
const assignBeforeEntryCreate = params => {
|
|
11
|
+
const {
|
|
12
|
+
context,
|
|
13
|
+
onBeforeCreate
|
|
14
|
+
} = params;
|
|
15
|
+
onBeforeCreate.subscribe(async params => {
|
|
16
|
+
const {
|
|
17
|
+
entry,
|
|
18
|
+
model
|
|
19
|
+
} = params;
|
|
20
|
+
await (0, _markLockedFields.markLockedFields)({
|
|
21
|
+
model,
|
|
22
|
+
entry,
|
|
23
|
+
context
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.assignBeforeEntryCreate = assignBeforeEntryCreate;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Topic } from "@webiny/pubsub/types";
|
|
2
|
+
import { BeforeEntryUpdateTopicParams, CmsContext } from "../../../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
context: CmsContext;
|
|
5
|
+
onBeforeUpdate: Topic<BeforeEntryUpdateTopicParams>;
|
|
6
|
+
}
|
|
7
|
+
export declare const assignBeforeEntryUpdate: (params: Params) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assignBeforeEntryUpdate = void 0;
|
|
7
|
+
|
|
8
|
+
var _markLockedFields = require("./markLockedFields");
|
|
9
|
+
|
|
10
|
+
const assignBeforeEntryUpdate = params => {
|
|
11
|
+
const {
|
|
12
|
+
context,
|
|
13
|
+
onBeforeUpdate
|
|
14
|
+
} = params;
|
|
15
|
+
onBeforeUpdate.subscribe(async params => {
|
|
16
|
+
const {
|
|
17
|
+
entry,
|
|
18
|
+
model
|
|
19
|
+
} = params;
|
|
20
|
+
await (0, _markLockedFields.markLockedFields)({
|
|
21
|
+
model,
|
|
22
|
+
entry,
|
|
23
|
+
context
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.assignBeforeEntryUpdate = assignBeforeEntryUpdate;
|