@webiny/api-apw 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.bca7b3e350
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/index.d.ts +0 -1
- package/index.js +1 -5
- package/index.js.map +1 -1
- package/package.json +34 -34
- package/plugins/context.d.ts +0 -1
- package/plugins/context.js +2 -16
- package/plugins/context.js.map +1 -1
- package/plugins/graphql.js +1 -1
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +8 -2
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/scheduler/handlers/executeAction/index.js +10 -1
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +14 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +7 -2
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +3 -59
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/utils.d.ts +0 -1
- package/scheduler/handlers/utils.js +0 -1
- package/scheduler/handlers/utils.js.map +1 -1
- package/storageOperations/models/contentModelPluginFactory.d.ts +0 -7
- package/storageOperations/models/contentModelPluginFactory.js +1 -5
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
- package/storageOperations/models/index.js +0 -2
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/workflowStorageOperations.js +3 -1
- package/storageOperations/workflowStorageOperations.js.map +1 -1
package/index.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
1
|
import { CreateApwContextParams } from "./scheduler/types";
|
2
|
-
export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => (import("@webiny/api").ContextPlugin<import("./types").ApwContext> | import("@webiny/plugins/types").Plugin<Record<string, any>> | import("@webiny/plugins/types").PluginCollection)[];
|
3
2
|
export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => (import("@webiny/api").ContextPlugin<import("./types").ApwContext> | import("@webiny/plugins/types").Plugin<Record<string, any>> | import("@webiny/plugins/types").PluginCollection | import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("@webiny/api-mailer/types").MailerContext>)[];
|
4
3
|
export declare const createApwGraphQL: () => import("@webiny/api").ContextPlugin<import("./types").ApwContext>[];
|
package/index.js
CHANGED
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
-
exports.createApwPageBuilderContext = exports.
|
7
|
+
exports.createApwPageBuilderContext = exports.createApwGraphQL = void 0;
|
8
8
|
var _graphql = _interopRequireDefault(require("./plugins/graphql"));
|
9
9
|
var _context = require("./plugins/context");
|
10
10
|
var _apiMailer = require("@webiny/api-mailer");
|
@@ -14,10 +14,6 @@ var _apiAdminSettings = require("@webiny/api-admin-settings");
|
|
14
14
|
* GraphQL will not work without context, but context will without GraphQL.
|
15
15
|
*/
|
16
16
|
|
17
|
-
const createApwHeadlessCmsContext = params => {
|
18
|
-
return [...(0, _apiAdminSettings.createAdminSettingsContext)(), ...(0, _apiMailer.createMailerContext)(), (0, _context.createApwHeadlessCmsContext)(params)];
|
19
|
-
};
|
20
|
-
exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
|
21
17
|
const createApwPageBuilderContext = params => {
|
22
18
|
return [...(0, _apiAdminSettings.createAdminSettingsContext)(), ...(0, _apiMailer.createMailerContext)(), ...(0, _apiMailer.createMailerGraphQL)(), (0, _context.createApwPageBuilderContext)(params)];
|
23
19
|
};
|
package/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["createApwPageBuilderContext","params","createAdminSettingsContext","createMailerContext","createMailerGraphQL","createPageBuilder","createApwGraphQL","graphql"],"sources":["index.ts"],"sourcesContent":["/**\n * We have separated context and GraphQL creation so user can initialize only context if required.\n * GraphQL will not work without context, but context will without GraphQL.\n */\nimport graphql from \"~/plugins/graphql\";\nimport { createApwPageBuilderContext as createPageBuilder } from \"./plugins/context\";\nimport { CreateApwContextParams } from \"./scheduler/types\";\nimport { createMailerContext, createMailerGraphQL } from \"@webiny/api-mailer\";\nimport { createAdminSettingsContext } from \"@webiny/api-admin-settings\";\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return [\n ...createAdminSettingsContext(),\n ...createMailerContext(),\n ...createMailerGraphQL(),\n createPageBuilder(params)\n ];\n};\n\nexport const createApwGraphQL = () => {\n return [graphql()];\n};\n"],"mappings":";;;;;;;AAIA;AACA;AAEA;AACA;AARA;AACA;AACA;AACA;;AAOO,MAAMA,2BAA2B,GAAIC,MAA8B,IAAK;EAC3E,OAAO,CACH,GAAG,IAAAC,4CAA0B,GAAE,EAC/B,GAAG,IAAAC,8BAAmB,GAAE,EACxB,GAAG,IAAAC,8BAAmB,GAAE,EACxB,IAAAC,oCAAiB,EAACJ,MAAM,CAAC,CAC5B;AACL,CAAC;AAAC;AAEK,MAAMK,gBAAgB,GAAG,MAAM;EAClC,OAAO,CAAC,IAAAC,gBAAO,GAAE,CAAC;AACtB,CAAC;AAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@webiny/api-apw",
|
3
|
-
"version": "0.0.0-unstable.
|
3
|
+
"version": "0.0.0-unstable.bca7b3e350",
|
4
4
|
"keywords": [
|
5
5
|
"apw:base"
|
6
6
|
],
|
@@ -14,31 +14,31 @@
|
|
14
14
|
"author": "Webiny Ltd",
|
15
15
|
"license": "MIT",
|
16
16
|
"dependencies": {
|
17
|
-
"@aws-sdk/client-cloudwatch-events": "3.
|
18
|
-
"@babel/runtime": "7.20.
|
17
|
+
"@aws-sdk/client-cloudwatch-events": "3.54.1",
|
18
|
+
"@babel/runtime": "7.20.13",
|
19
19
|
"@commodo/fields": "1.1.2-beta.20",
|
20
|
-
"@webiny/api": "0.0.0-unstable.
|
21
|
-
"@webiny/api-admin-settings": "0.0.0-unstable.
|
22
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
23
|
-
"@webiny/api-i18n": "0.0.0-unstable.
|
24
|
-
"@webiny/api-i18n-ddb": "0.0.0-unstable.
|
25
|
-
"@webiny/api-mailer": "0.0.0-unstable.
|
26
|
-
"@webiny/api-page-builder": "0.0.0-unstable.
|
27
|
-
"@webiny/api-security": "0.0.0-unstable.
|
28
|
-
"@webiny/api-tenancy": "0.0.0-unstable.
|
29
|
-
"@webiny/api-wcp": "0.0.0-unstable.
|
30
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
31
|
-
"@webiny/error": "0.0.0-unstable.
|
32
|
-
"@webiny/handler": "0.0.0-unstable.
|
33
|
-
"@webiny/handler-client": "0.0.0-unstable.
|
34
|
-
"@webiny/handler-db": "0.0.0-unstable.
|
35
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
36
|
-
"@webiny/handler-logs": "0.0.0-unstable.
|
37
|
-
"@webiny/plugins": "0.0.0-unstable.
|
38
|
-
"@webiny/pubsub": "0.0.0-unstable.
|
39
|
-
"@webiny/utils": "0.0.0-unstable.
|
40
|
-
"@webiny/validation": "0.0.0-unstable.
|
41
|
-
"dayjs": "1.11.
|
20
|
+
"@webiny/api": "0.0.0-unstable.bca7b3e350",
|
21
|
+
"@webiny/api-admin-settings": "0.0.0-unstable.bca7b3e350",
|
22
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.bca7b3e350",
|
23
|
+
"@webiny/api-i18n": "0.0.0-unstable.bca7b3e350",
|
24
|
+
"@webiny/api-i18n-ddb": "0.0.0-unstable.bca7b3e350",
|
25
|
+
"@webiny/api-mailer": "0.0.0-unstable.bca7b3e350",
|
26
|
+
"@webiny/api-page-builder": "0.0.0-unstable.bca7b3e350",
|
27
|
+
"@webiny/api-security": "0.0.0-unstable.bca7b3e350",
|
28
|
+
"@webiny/api-tenancy": "0.0.0-unstable.bca7b3e350",
|
29
|
+
"@webiny/api-wcp": "0.0.0-unstable.bca7b3e350",
|
30
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.bca7b3e350",
|
31
|
+
"@webiny/error": "0.0.0-unstable.bca7b3e350",
|
32
|
+
"@webiny/handler": "0.0.0-unstable.bca7b3e350",
|
33
|
+
"@webiny/handler-client": "0.0.0-unstable.bca7b3e350",
|
34
|
+
"@webiny/handler-db": "0.0.0-unstable.bca7b3e350",
|
35
|
+
"@webiny/handler-graphql": "0.0.0-unstable.bca7b3e350",
|
36
|
+
"@webiny/handler-logs": "0.0.0-unstable.bca7b3e350",
|
37
|
+
"@webiny/plugins": "0.0.0-unstable.bca7b3e350",
|
38
|
+
"@webiny/pubsub": "0.0.0-unstable.bca7b3e350",
|
39
|
+
"@webiny/utils": "0.0.0-unstable.bca7b3e350",
|
40
|
+
"@webiny/validation": "0.0.0-unstable.bca7b3e350",
|
41
|
+
"dayjs": "1.11.7",
|
42
42
|
"lodash": "4.17.21",
|
43
43
|
"mdbid": "1.0.0"
|
44
44
|
},
|
@@ -46,14 +46,14 @@
|
|
46
46
|
"@babel/cli": "^7.19.3",
|
47
47
|
"@babel/core": "^7.19.3",
|
48
48
|
"@babel/preset-env": "^7.19.4",
|
49
|
-
"@webiny/api-headless-cms-ddb": "^0.0.0-unstable.
|
50
|
-
"@webiny/api-page-builder-so-ddb": "^0.0.0-unstable.
|
51
|
-
"@webiny/api-security-so-ddb": "^0.0.0-unstable.
|
52
|
-
"@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.
|
53
|
-
"@webiny/cli": "^0.0.0-unstable.
|
54
|
-
"@webiny/handler-aws": "^0.0.0-unstable.
|
55
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
56
|
-
"@webiny/wcp": "^0.0.0-unstable.
|
49
|
+
"@webiny/api-headless-cms-ddb": "^0.0.0-unstable.bca7b3e350",
|
50
|
+
"@webiny/api-page-builder-so-ddb": "^0.0.0-unstable.bca7b3e350",
|
51
|
+
"@webiny/api-security-so-ddb": "^0.0.0-unstable.bca7b3e350",
|
52
|
+
"@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.bca7b3e350",
|
53
|
+
"@webiny/cli": "^0.0.0-unstable.bca7b3e350",
|
54
|
+
"@webiny/handler-aws": "^0.0.0-unstable.bca7b3e350",
|
55
|
+
"@webiny/project-utils": "^0.0.0-unstable.bca7b3e350",
|
56
|
+
"@webiny/wcp": "^0.0.0-unstable.bca7b3e350",
|
57
57
|
"get-yarn-workspaces": "^1.0.2",
|
58
58
|
"graphql": "^15.7.2",
|
59
59
|
"jest": "^28.1.0",
|
@@ -72,5 +72,5 @@
|
|
72
72
|
"build": "yarn webiny run build",
|
73
73
|
"watch": "yarn webiny run watch"
|
74
74
|
},
|
75
|
-
"gitHead": "
|
75
|
+
"gitHead": "bca7b3e35084d7012061bda0d3f08202fe611581"
|
76
76
|
}
|
package/plugins/context.d.ts
CHANGED
@@ -2,4 +2,3 @@ import { ContextPlugin } from "@webiny/api";
|
|
2
2
|
import { ApwContext } from "../types";
|
3
3
|
import { CreateApwContextParams } from "../scheduler/types";
|
4
4
|
export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
5
|
-
export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
package/plugins/context.js
CHANGED
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
-
exports.createApwPageBuilderContext =
|
7
|
+
exports.createApwPageBuilderContext = void 0;
|
8
8
|
var _hooks = require("./hooks");
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
10
10
|
var _api = require("@webiny/api");
|
@@ -98,18 +98,4 @@ const createApwPageBuilderContext = params => {
|
|
98
98
|
context.plugins.register((0, _extendPbPageSettingsSchema.extendPbPageSettingsSchema)());
|
99
99
|
});
|
100
100
|
};
|
101
|
-
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|
102
|
-
const createApwHeadlessCmsContext = params => {
|
103
|
-
return new _api.ContextPlugin(async context => {
|
104
|
-
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
105
|
-
return;
|
106
|
-
} else if ((0, _utils.isInstallationPending)(context)) {
|
107
|
-
return;
|
108
|
-
}
|
109
|
-
await setupApwContext(params).apply(context);
|
110
|
-
await setupApwHeadlessCms().apply(context);
|
111
|
-
await (0, _hooks.attachApwHooks)().apply(context);
|
112
|
-
await (0, _security.createCustomAuth)(params).apply(context);
|
113
|
-
});
|
114
|
-
};
|
115
|
-
exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
|
101
|
+
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|
package/plugins/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema"
|
1
|
+
{"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AAGA,MAAMA,eAAe,GAAIC,MAA8B,IACnD,IAAIC,kBAAa,CAAa,MAAMC,OAAO,IAAI;EAC3C,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC,IAAI;IAAEC;EAAc,CAAC,GAAGJ,OAAO;EAE1D,IAAI,IAAAK,4BAAqB,EAAC;IAAEJ,OAAO;IAAEE;EAAK,CAAC,CAAC,EAAE;IAC1C;EACJ;EAEA,MAAMG,SAAS,GAAG,MAAkB;IAChC,MAAMC,MAAM,GAAGJ,IAAI,CAACK,gBAAgB,EAAE;IACtC,IAAI,CAACD,MAAM,E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IAAK;EAC3E,OAAO,IAAIC,kBAAa,CAAa,MAAMC,OAAO,IAAI;IAClD,IAAI,CAACA,OAAO,CAAC6B,GAAG,CAACC,aAAa,CAAC,4BAA4B,CAAC,EAAE;MAC1D;IACJ,CAAC,MAAM,IAAI,IAAAzB,4BAAqB,EAACL,OAAO,CAAC,EAAE;MACvC;IACJ;IAEA,MAAMH,eAAe,CAACC,MAAM,CAAC,CAACiC,KAAK,CAAC/B,OAAO,CAAC;IAC5C,MAAMwB,mBAAmB,EAAE,CAACO,KAAK,CAAC/B,OAAO,CAAC;IAC1C,MAAM0B,mBAAmB,EAAE,CAACK,KAAK,CAAC/B,OAAO,CAAC;IAC1C,MAAM,IAAAgC,4CAAqB,GAAE,CAACD,KAAK,CAAC/B,OAAO,CAAC;IAC5C,MAAM,IAAAiC,qBAAc,GAAE,CAACF,KAAK,CAAC/B,OAAO,CAAC;IACrC,MAAM,IAAAkC,0BAAgB,EAACpC,MAAM,CAAC,CAACiC,KAAK,CAAC/B,OAAO,CAAC;IAE7CA,OAAO,CAACuB,OAAO,CAACY,QAAQ,CAAC,IAAAC,sDAA0B,GAAE,CAAC;EAC1D,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/plugins/graphql.js
CHANGED
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
|
-
var _plugins = require("@webiny/handler-graphql/plugins");
|
9
8
|
var _workflow = _interopRequireDefault(require("./graphql/workflow.gql"));
|
10
9
|
var _contentReview = _interopRequireDefault(require("./graphql/contentReview.gql"));
|
11
10
|
var _reviewer = _interopRequireDefault(require("./graphql/reviewer.gql"));
|
12
11
|
var _comment = _interopRequireDefault(require("./graphql/comment.gql"));
|
13
12
|
var _changeRequest = _interopRequireDefault(require("./graphql/changeRequest.gql"));
|
13
|
+
var _plugins = require("@webiny/handler-graphql/plugins");
|
14
14
|
var _api = require("@webiny/api");
|
15
15
|
const emptyResolver = () => ({});
|
16
16
|
const baseSchema = new _plugins.GraphQLSchemaPlugin({
|
package/plugins/graphql.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["emptyResolver","baseSchema","GraphQLSchemaPlugin","typeDefs","resolvers","Query","apw","Mutation","ContextPlugin","context","wcp","canUseFeature","plugins","register","workflowSchema","contentReviewSchema","reviewerSchema","commentSchema","changeRequestedSchema"],"sources":["graphql.ts"],"sourcesContent":["import
|
1
|
+
{"version":3,"names":["emptyResolver","baseSchema","GraphQLSchemaPlugin","typeDefs","resolvers","Query","apw","Mutation","ContextPlugin","context","wcp","canUseFeature","plugins","register","workflowSchema","contentReviewSchema","reviewerSchema","commentSchema","changeRequestedSchema"],"sources":["graphql.ts"],"sourcesContent":["import workflowSchema from \"./graphql/workflow.gql\";\nimport contentReviewSchema from \"./graphql/contentReview.gql\";\nimport reviewerSchema from \"./graphql/reviewer.gql\";\nimport commentSchema from \"./graphql/comment.gql\";\nimport changeRequestedSchema from \"./graphql/changeRequest.gql\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\nconst baseSchema = new GraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n input ApwRefFieldInput {\n id: ID!\n modelId: String\n }\n\n input ApwRefFieldWhereInput {\n id: String\n id_not: String\n id_in: [String!]\n id_not_in: [String]\n entryId: String\n entryId_not: String\n entryId_in: [String!]\n entryId_not_in: [String!]\n }\n\n type ApwRefField {\n modelId: String!\n entryId: ID!\n id: ID!\n }\n\n type ApwMeta {\n hasMoreItems: Boolean\n totalCount: Int\n cursor: String\n }\n type ApwCreatedBy {\n id: ID\n displayName: String\n type: String\n }\n type ApwError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n extend type Query {\n apw: ApwQuery\n }\n extend type Mutation {\n apw: ApwMutation\n }\n `,\n resolvers: {\n Query: {\n apw: emptyResolver\n },\n Mutation: {\n apw: emptyResolver\n }\n }\n});\n\nexport default () => {\n return new ContextPlugin<ApwContext>(context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n }\n\n context.plugins.register([\n baseSchema,\n workflowSchema,\n contentReviewSchema,\n reviewerSchema,\n commentSchema,\n changeRequestedSchema\n ]);\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,MAAMA,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;AAEhC,MAAMC,UAAU,GAAG,IAAIC,4BAAmB,CAAC;EACvCC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,KAAK,EAAE;MACHC,GAAG,EAAEN;IACT,CAAC;IACDO,QAAQ,EAAE;MACND,GAAG,EAAEN;IACT;EACJ;AACJ,CAAC,CAAC;AAAC,eAEY,MAAM;EACjB,OAAO,IAAIQ,kBAAa,CAAaC,OAAO,IAAI;IAC5C,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,aAAa,CAAC,4BAA4B,CAAC,EAAE;MAC1D;IACJ;IAEAF,OAAO,CAACG,OAAO,CAACC,QAAQ,CAAC,CACrBZ,UAAU,EACVa,iBAAc,EACdC,sBAAmB,EACnBC,iBAAc,EACdC,gBAAa,EACbC,sBAAqB,CACxB,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAA"}
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
exports.initializeContentReviewSteps = void 0;
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
9
|
var _set = _interopRequireDefault(require("lodash/set"));
|
10
|
+
var _types = require("../../types");
|
10
11
|
var _utils = require("../utils");
|
11
12
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
12
13
|
var _contentApwSettingsPlugin = require("../../utils/contentApwSettingsPlugin");
|
@@ -64,9 +65,14 @@ const initializeContentReviewSteps = ({
|
|
64
65
|
});
|
65
66
|
});
|
66
67
|
/**
|
67
|
-
*
|
68
|
-
* There is no steps property on CreateApwContentReviewParams
|
68
|
+
* If there are only steps which are not mandatory ones, put review status to ApwContentReviewStatus.READY_TO_BE_PUBLISHED.
|
69
69
|
*/
|
70
|
+
const isNonMandatory = updatedSteps.every(step => {
|
71
|
+
return step.type === _types.ApwWorkflowStepTypes.NON_MANDATORY;
|
72
|
+
});
|
73
|
+
if (isNonMandatory) {
|
74
|
+
input.reviewStatus = _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED;
|
75
|
+
}
|
70
76
|
input = (0, _set.default)(input, "steps", updatedSteps);
|
71
77
|
});
|
72
78
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport {
|
1
|
+
{"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments","isNonMandatory","every","ApwWorkflowStepTypes","NON_MANDATORY","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport {\n ApwContentReviewStatus,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwWorkflowStepTypes\n} from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n input.workflowId = workflowId;\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * If there are only steps which are not mandatory ones, put review status to ApwContentReviewStatus.READY_TO_BE_PUBLISHED.\n */\n const isNonMandatory = updatedSteps.every(step => {\n return step.type === ApwWorkflowStepTypes.NON_MANDATORY;\n });\n if (isNonMandatory) {\n input.reviewStatus = ApwContentReviewStatus.READY_TO_BE_PUBLISHED;\n }\n\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAMA;AACA;AACA;AAEO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,GAAG;EAAEC;AAAoB,CAAC,KAAK;EAC1ED,GAAG,CAACE,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC,IAAI;MAAEC,EAAE;MAAEC;IAAS,CAAC,GAAGH,KAAK,CAACI,OAAO;IAC5C;AACR;AACA;IACQ,MAAMC,UAAU,GAAGV,GAAG,CAACW,gBAAgB,CAACL,IAAI,CAAC;IAC7C,MAAMG,OAAO,GAAG,MAAMC,UAAU,CAACH,EAAE,EAAEC,QAAQ,CAAC;IAC9C,IAAI,CAACC,OAAO,EAAE;MACV,MAAM,IAAIG,6BAAa,CAAE,YAAWN,IAAK,aAAYC,EAAG,aAAY,CAAC;IACzE;IAEA,MAAM;MAAEM;IAAM,CAAC,GAAGJ,OAAO;IACzBJ,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEQ,KAAK,CAAC;;IAExC;AACR;AACA;IACQ,MAAME,wBAAwB,GAAG,IAAAC,qDAA2B,EAAC;MACzDf,OAAO;MACPK;IACJ,CAAC,CAAC;IAEF,MAAMW,UAAU,GAAGF,wBAAwB,CAACG,aAAa,CAACT,OAAO,CAAC;;IAElE;AACR;AACA;IACQ,IAAI,CAACQ,UAAU,EAAE;MACb,MAAM,IAAIL,6BAAa,CAAE,2DAA0D,CAAC;IACxF;IAEAP,KAAK,CAACY,UAAU,GAAGA,UAAU;IAE7B,MAAME,QAAQ,GAAG,MAAMnB,GAAG,CAACmB,QAAQ,CAACC,GAAG,CAACH,UAAU,CAAC;IACnD,MAAMI,aAAa,GAAGF,QAAQ,CAACG,KAAK;IAEpC,IAAIC,kBAA0D,GAAGC,SAAS;IAC1E,MAAMC,YAAY,GAAGN,QAAQ,CAACG,KAAK,CAACI,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAK;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAiC,EAC5CT,aAAa,EACbO,KAAK,EACLL,kBAAkB,CACrB;MACDA,kBAAkB,GAAGM,MAAM;MAC3B,mEACOF,IAAI;QACPE,MAAM;QACNE,qBAAqB,EAAE,CAAC;QACxBC,aAAa,EAAE;MAAC;IAExB,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAMC,cAAc,GAAGR,YAAY,CAACS,KAAK,CAACP,IAAI,IAAI;MAC9C,OAAOA,IAAI,CAACrB,IAAI,KAAK6B,2BAAoB,CAACC,aAAa;IAC3D,CAAC,CAAC;IACF,IAAIH,cAAc,EAAE;MAChB5B,KAAK,CAACgC,YAAY,GAAGC,6BAAsB,CAACC,qBAAqB;IACrE;IAEAlC,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEoB,YAAY,CAAC;EACnD,CAAC,CAAC;AACN,CAAC;AAAC"}
|
@@ -96,6 +96,15 @@ const createExecuteActionLambda = params => {
|
|
96
96
|
}));
|
97
97
|
continue;
|
98
98
|
}
|
99
|
+
const url = plugin.getUrl({
|
100
|
+
locale,
|
101
|
+
tenant
|
102
|
+
});
|
103
|
+
if (!url) {
|
104
|
+
console.error(`There is no url defined, in the Plugin, for type "${item.data.type}".`);
|
105
|
+
console.log(JSON.stringify(item));
|
106
|
+
continue;
|
107
|
+
}
|
99
108
|
const body = plugin.getGraphQLBody(item.data);
|
100
109
|
if (!body) {
|
101
110
|
console.error(`There is no GraphQL body defined, in the Plugin, for type "${item.data.type}".`);
|
@@ -108,7 +117,7 @@ const createExecuteActionLambda = params => {
|
|
108
117
|
name,
|
109
118
|
payload: {
|
110
119
|
httpMethod: "POST",
|
111
|
-
path:
|
120
|
+
path: url,
|
112
121
|
headers: {
|
113
122
|
["content-type"]: "application/json",
|
114
123
|
Authorization: (0, _utils.encodeToken)({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,oBAAW,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5D,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IAAI,CAC1B;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC;IAE5E,MAAMC,2BAA2B,GAC7BC,IAA2B,IACC;MAC5B,MAAM;QAAEL;MAAK,CAAC,GAAGK,IAAI;MACrB,IAAIF,6BAA6B,CAACH,IAAI,CAAC,EAAE;QACrC,OAAOG,6BAA6B,CAACH,IAAI,CAAC;MAC9C;MACA,KAAK,MAAMM,MAAM,IAAIV,yBAAyB,EAAE;Q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I;UAC7B,CAAC;UACDW,KAAK,EAAE;QACX,CAAC,CAAC;QACF,IAAIT,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEF,IAAI,EAAE;UAChBjC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;YAAEI,IAAI,EAAEE,QAAQ,CAACF;UAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;UAC7D;QACJ;QACAjC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;UAAEM;QAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;QAElD;MACJ;IACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;MACR9C,GAAG,CAAC,oCAAoC,EAAE8C,CAAC,CAAC;MAC5C;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAMC,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMlD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAAC+C,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACb3D,yBAAyB,CAACsD,MAAM,CAAC,CACpC;AAAC"}
|
1
|
+
{"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,oBAAW,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5D,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IAAI,CAC1B;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC;IAE5E,MAAMC,2BAA2B,GAC7BC,IAA2B,IACC;MAC5B,MAAM;QAAEL;MAAK,CAAC,GAAGK,IAAI;MACrB,IAAIF,6BAA6B,CAACH,IAAI,CAAC,EAAE;QACrC,OAAOG,6BAA6B,CAACH,IAAI,CAAC;MAC9C;MACA,KAAK,MAAMM,MAAM,IAAIV,yBAAyB,EAAE;QAC5C,IAAI,CAACU,MAAM,CAACC,MAAM,CAACF,IAAI,CAAC,EAAE;UACtB;QACJ;QACAF,6BAA6B,CAACH,IAAI,CAAC,GAAGM,MAAM;QAC5C,OAAOA,MAAM;MACjB;MACA,OAAO,IAAI;IACf,CAAC;IAED,IAAI;MACA,MAAME,WAAW,GAAG,MAAM,IAAAC,qBAAc,GAAE;MAE1C,MAAM;QAAEC,cAAc,EAAEC,QAAQ;QAAEC,MAAM;QAAEC;MAAO,CAAC,GAAGrB,OAAO;MAC5D;AACZ;AACA;MACY,IAAI,CAACmB,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ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BnC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;YAAEM,IAAI,EAAEE,QAAQ,CAACF;UAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;UAC7D;QACJ;QACAnC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;UAAEQ;QAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;QAElD;MACJ;IACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;MACRhD,GAAG,CAAC,oCAAoC,EAAEgD,CAAC,CAAC;MAC5C;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAMC,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMpD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAACiD,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACb7D,yBAAyB,CAACwD,MAAM,CAAC,CACpC;AAAC"}
|
@@ -1,12 +1,18 @@
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin";
|
2
2
|
import { ApwScheduleActionData } from "../../../types";
|
3
3
|
import { ApwSettings } from "../../utils";
|
4
|
+
export { ApwScheduleActionData, ApwSettings };
|
5
|
+
export interface ApplicationGraphQLGetUrlParams {
|
6
|
+
tenant: string;
|
7
|
+
locale: string;
|
8
|
+
}
|
4
9
|
export interface ApplicationGraphQLBody<T = Record<string, any>> {
|
5
10
|
query: string;
|
6
11
|
variables: T;
|
7
12
|
}
|
8
13
|
export declare abstract class ApplicationGraphQL extends Plugin {
|
9
14
|
static readonly type: string;
|
15
|
+
abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;
|
10
16
|
abstract canUse(data: ApwScheduleActionData): boolean;
|
11
17
|
abstract getArn(settings: ApwSettings): string;
|
12
18
|
abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
|
@@ -5,8 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
6
6
|
});
|
7
7
|
exports.ApplicationGraphQL = void 0;
|
8
|
+
Object.defineProperty(exports, "ApwScheduleActionData", {
|
9
|
+
enumerable: true,
|
10
|
+
get: function () {
|
11
|
+
return _types.ApwScheduleActionData;
|
12
|
+
}
|
13
|
+
});
|
14
|
+
Object.defineProperty(exports, "ApwSettings", {
|
15
|
+
enumerable: true,
|
16
|
+
get: function () {
|
17
|
+
return _utils.ApwSettings;
|
18
|
+
}
|
19
|
+
});
|
8
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
9
21
|
var _Plugin = require("@webiny/plugins/Plugin");
|
22
|
+
var _types = require("../../../types");
|
23
|
+
var _utils = require("../../utils");
|
10
24
|
class ApplicationGraphQL extends _Plugin.Plugin {}
|
11
25
|
exports.ApplicationGraphQL = ApplicationGraphQL;
|
12
26
|
(0, _defineProperty2.default)(ApplicationGraphQL, "type", "apw.scheduler.applicationGraphQL");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport { ApwScheduleActionData, ApwSettings };\n\nexport interface ApplicationGraphQLGetUrlParams {\n tenant: string;\n locale: string;\n}\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAaO,MAAeA,kBAAkB,SAASC,cAAM,CAAC;AAUvD;AAAA,8BAVqBD,kBAAkB,UACW,kCAAkC"}
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import { ApplicationGraphQL, ApplicationGraphQLBody } from "./ApplicationGraphQL";
|
2
|
-
import { ApwScheduleActionData } from "../../../types";
|
3
|
-
import { ApwSettings } from "../../utils";
|
1
|
+
import { ApplicationGraphQL, ApplicationGraphQLBody, ApwSettings, ApplicationGraphQLGetUrlParams, ApwScheduleActionData } from "./ApplicationGraphQL";
|
4
2
|
export declare class HeadlessCMSGraphQL extends ApplicationGraphQL {
|
5
3
|
name: string;
|
6
4
|
canUse(data: ApwScheduleActionData): boolean;
|
5
|
+
getUrl({ locale }: ApplicationGraphQLGetUrlParams): string;
|
7
6
|
getArn(settings: ApwSettings): string;
|
8
7
|
getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
|
9
8
|
private getPublishBody;
|
@@ -57,13 +57,18 @@ const createUnpublishMutation = modelId => {
|
|
57
57
|
class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
58
58
|
constructor(...args) {
|
59
59
|
super(...args);
|
60
|
-
(0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.
|
60
|
+
(0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.headlessCms");
|
61
61
|
}
|
62
62
|
canUse(data) {
|
63
63
|
return data.type === _types.ApwContentTypes.CMS_ENTRY;
|
64
64
|
}
|
65
|
+
getUrl({
|
66
|
+
locale
|
67
|
+
}) {
|
68
|
+
return `/cms/manage/${locale}`;
|
69
|
+
}
|
65
70
|
getArn(settings) {
|
66
|
-
return settings.
|
71
|
+
return settings.mainGraphqlFunctionArn;
|
67
72
|
}
|
68
73
|
getGraphQLBody(data) {
|
69
74
|
switch (data.action) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getArn","settings","
|
1
|
+
{"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getUrl","locale","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwSettings,\n ApplicationGraphQLGetUrlParams,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.headlessCms\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getUrl({ locale }: ApplicationGraphQLGetUrlParams): string {\n return `/cms/manage/${locale}`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAOA;AACA;AACA;AAEA,MAAMA,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,qBAAqB,GAAIC,OAAe,IAAa;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAAU;AACV,CAAC;AAED,MAAMK,uBAAuB,GAAIH,OAAe,IAAK;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,+BAA+BC,cAAe;AAC9C,gCAAgCA,cAAe;AAC/C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAAU;AACV,CAAC;AAMM,MAAMM,kBAAkB,SAASC,sCAAkB,CAAC;EAAA;IAAA;IAAA,4CAChC,8CAA8C;EAAA;EAErDC,MAAM,CAACC,IAA2B,EAAW;IACzD,OAAOA,IAAI,CAACC,IAAI,KAAKC,sBAAe,CAACC,SAAS;EAClD;EAEgBC,MAAM,CAAC;IAAEC;EAAuC,CAAC,EAAU;IACvE,OAAQ,eAAcA,MAAO,EAAC;EAClC;EAEgBC,MAAM,CAACC,QAAqB,EAAU;IAClD,OAAOA,QAAQ,CAACC,sBAAsB;EAC1C;EAEgBC,cAAc,CAACT,IAA2B,EAAiC;IACvF,QAAQA,IAAI,CAACU,MAAM;MACf,KAAKC,6BAAsB,CAACC,OAAO;QAC/B,OAAO,IAAI,CAACC,cAAc,CAACb,IAAI,CAAC;MACpC,KAAKW,6BAAsB,CAACG,SAAS;QACjC,OAAO,IAAI,CAACC,gBAAgB,CAACf,IAAI,CAAC;MACtC;QACI,OAAO,IAAI;IAAC;EAExB;EAEQa,cAAc,CAClBb,IAA2B,EAC4B;IACvD,IAAI,CAACA,IAAI,CAACP,OAAO,EAAE;MACf,MAAM,IAAIuB,cAAW,CACjB,+CAA+C,EAC/C,uBAAuB,EACvB;QACIhB;MACJ,CAAC,CACJ;IACL;IACA,OAAO;MACHiB,KAAK,EAAEzB,qBAAqB,CAACQ,IAAI,CAACP,OAAO,CAAC;MAC1CyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;EAEQL,gBAAgB,CACpBf,IAA2B,EAC4B;IACvD,IAAI,CAACA,IAAI,CAACP,OAAO,EAAE;MACf,MAAM,IAAIuB,cAAW,CACjB,+CAA+C,EAC/C,uBAAuB,EACvB;QACIhB;MACJ,CAAC,CACJ;IACL;IACA,OAAO;MACHiB,KAAK,EAAErB,uBAAuB,CAACI,IAAI,CAACP,OAAO,CAAC;MAC5CyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;AACJ;AAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { ApplicationGraphQL, ApplicationGraphQLBody } from "./ApplicationGraphQL";
|
2
|
-
import { ApwScheduleActionData } from "../../../types";
|
1
|
+
import { ApplicationGraphQL, ApplicationGraphQLBody, ApwScheduleActionData } from "./ApplicationGraphQL";
|
3
2
|
import { ApwSettings } from "../../utils";
|
4
3
|
export declare class PageBuilderGraphQL extends ApplicationGraphQL {
|
5
4
|
name: string;
|
6
5
|
canUse(data: ApwScheduleActionData): boolean;
|
6
|
+
getUrl(): string;
|
7
7
|
getArn(settings: ApwSettings): string;
|
8
8
|
getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
|
9
9
|
private getPublishBody;
|
@@ -11,65 +11,6 @@ var _types = require("../../../types");
|
|
11
11
|
const PB_PAGE_DATA_FIELD = /* GraphQL */`
|
12
12
|
{
|
13
13
|
id
|
14
|
-
pid
|
15
|
-
editor
|
16
|
-
category {
|
17
|
-
slug
|
18
|
-
}
|
19
|
-
version
|
20
|
-
title
|
21
|
-
path
|
22
|
-
url
|
23
|
-
content
|
24
|
-
savedOn
|
25
|
-
status
|
26
|
-
locked
|
27
|
-
publishedOn
|
28
|
-
locked
|
29
|
-
revisions {
|
30
|
-
id
|
31
|
-
status
|
32
|
-
locked
|
33
|
-
version
|
34
|
-
}
|
35
|
-
settings {
|
36
|
-
general {
|
37
|
-
snippet
|
38
|
-
tags
|
39
|
-
layout
|
40
|
-
image {
|
41
|
-
id
|
42
|
-
src
|
43
|
-
}
|
44
|
-
}
|
45
|
-
social {
|
46
|
-
meta {
|
47
|
-
property
|
48
|
-
content
|
49
|
-
}
|
50
|
-
title
|
51
|
-
description
|
52
|
-
image {
|
53
|
-
id
|
54
|
-
src
|
55
|
-
}
|
56
|
-
}
|
57
|
-
seo {
|
58
|
-
title
|
59
|
-
description
|
60
|
-
meta {
|
61
|
-
name
|
62
|
-
content
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
createdFrom
|
67
|
-
createdOn
|
68
|
-
createdBy {
|
69
|
-
id
|
70
|
-
displayName
|
71
|
-
type
|
72
|
-
}
|
73
14
|
}
|
74
15
|
`;
|
75
16
|
const ERROR_FIELD = /* GraphQL */`
|
@@ -107,6 +48,9 @@ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
|
107
48
|
canUse(data) {
|
108
49
|
return data.type === _types.ApwContentTypes.PAGE;
|
109
50
|
}
|
51
|
+
getUrl() {
|
52
|
+
return `/graphql`;
|
53
|
+
}
|
110
54
|
getArn(settings) {
|
111
55
|
return settings.mainGraphqlFunctionArn;
|
112
56
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","PAGE","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"names":["PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","PAGE","getUrl","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst PB_PAGE_DATA_FIELD = /* GraphQL */ `\n {\n id\n }\n`;\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n code\n data\n message\n }\n`;\n\nconst PUBLISH_MUTATION = /* GraphQL */ `\n mutation PublishPage($id: ID!) {\n pageBuilder {\n publishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\nconst UNPUBLISH_MUTATION = /* GraphQL */ `\n mutation UnpublishPage($id: ID!) {\n pageBuilder {\n unpublishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\ninterface ApplicationGraphQLBodyVariables {\n id: string;\n}\n\nexport class PageBuilderGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.PAGE;\n }\n\n public override getUrl(): string {\n return `/graphql`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: PUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: UNPUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAKA;AAGA,MAAMA,kBAAkB,GAAG,aAAe;AAC1C;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAG,aAAe;AACnC;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,gBAAgB,GAAG,aAAe;AACxC;AACA;AACA;AACA,uBAAuBF,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CAAC;AAED,MAAME,kBAAkB,GAAG,aAAe;AAC1C;AACA;AACA;AACA,uBAAuBH,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CAAC;AAMM,MAAMG,kBAAkB,SAASC,sCAAkB,CAAC;EAAA;IAAA;IAAA,4CAChC,8CAA8C;EAAA;EAErDC,MAAM,CAACC,IAA2B,EAAW;IACzD,OAAOA,IAAI,CAACC,IAAI,KAAKC,sBAAe,CAACC,IAAI;EAC7C;EAEgBC,MAAM,GAAW;IAC7B,OAAQ,UAAS;EACrB;EAEgBC,MAAM,CAACC,QAAqB,EAAU;IAClD,OAAOA,QAAQ,CAACC,sBAAsB;EAC1C;EAEgBC,cAAc,CAACR,IAA2B,EAAiC;IACvF,QAAQA,IAAI,CAACS,MAAM;MACf,KAAKC,6BAAsB,CAACC,OAAO;QAC/B,OAAO,IAAI,CAACC,cAAc,CAACZ,IAAI,CAAC;MACpC,KAAKU,6BAAsB,CAACG,SAAS;QACjC,OAAO,IAAI,CAACC,gBAAgB,CAACd,IAAI,CAAC;MACtC;QACI,OAAO,IAAI;IAAC;EAExB;EAEQY,cAAc,CAClBZ,IAA2B,EAC4B;IACvD,OAAO;MACHe,KAAK,EAAEpB,gBAAgB;MACvBqB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MACb;IACJ,CAAC;EACL;EAEQJ,gBAAgB,CACpBd,IAA2B,EAC4B;IACvD,OAAO;MACHe,KAAK,EAAEnB,kBAAkB;MACzBoB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MACb;IACJ,CAAC;EACL;AACJ;AAAC"}
|
@@ -123,7 +123,6 @@ const getApwSettings = async () => {
|
|
123
123
|
} = await documentClient.get(params).promise();
|
124
124
|
return {
|
125
125
|
mainGraphqlFunctionArn: Item ? Item["mainGraphqlFunctionArn"] : "mainGraphqlFunctionArn",
|
126
|
-
cmsGraphqlFunctionArn: Item ? Item["cmsGraphqlFunctionArn"] : "cmsGraphqlFunctionArn",
|
127
126
|
eventRuleName: Item ? Item["eventRuleName"] : "eventRuleName",
|
128
127
|
eventTargetId: Item ? Item["eventTargetId"] : "eventTargetId"
|
129
128
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","
|
1
|
+
{"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","eventRuleName","eventTargetId"],"sources":["utils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport dbPlugins from \"@webiny/handler-db\";\nimport { DynamoDbDriver } from \"@webiny/db-dynamodb\";\nimport dynamoDbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport logsPlugins from \"@webiny/handler-logs\";\nimport { InvocationTypes } from \"~/scheduler/types\";\n\n/**\n * https://day.js.org/docs/en/plugin/utc\n */\ndayjs.extend(utc);\n\nconst TIME_SEPARATOR = \":\";\nconst ELAPSED_CRON_EXPRESSION = \"* * * * ? 2000\";\n\nexport const getIsoStringTillMinutes = (datetime: string): string => {\n /**\n * Validate datetime.\n */\n if (isNaN(Date.parse(datetime))) {\n return datetime;\n }\n // input = \"2022-03-08T05:41:13.230Z\"\n // output = \"2022-03-08T05:41\"\n return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));\n};\n\nexport const dateTimeToCronExpression = (datetime: string): string => {\n if (!datetime) {\n return ELAPSED_CRON_EXPRESSION;\n }\n /**\n * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.\n * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.\n *\n * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html\n */\n const dayOfWeek = \"?\";\n\n return dayjs.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);\n};\n\nexport const moveDateTimeToNextCentury = (datetime: string): string => {\n return dayjs.utc(datetime).add(100, \"year\").toISOString();\n};\n\nexport const moveDateTimeToCurrentCentury = (datetime: string): string => {\n return dayjs.utc(datetime).subtract(100, \"year\").toISOString();\n};\n\nexport const isDateTimeInNextCentury = (datetime: string): boolean => {\n return dayjs.utc(datetime).isAfter(\"2100-01-01\", \"year\");\n};\n\ninterface ShouldRestoreDatetimeParams {\n invocationType?: InvocationTypes;\n datetime: string;\n}\n\nexport const shouldRestoreDatetime = ({\n invocationType,\n datetime\n}: ShouldRestoreDatetimeParams): boolean => {\n /**\n * \"invocationType\" will not be SCHEDULED when the lambda is called from Main GQL handler.\n *\n * Which means a new content is scheduled for \"publish\"/\"unpublish\" therefore, we need to restore the previously\n * scheduled action if it has not been executed already.\n */\n const selfInvoked = invocationType === InvocationTypes.SCHEDULED;\n\n const today = dayjs.utc();\n const isExecutionPending = dayjs.utc(datetime).isAfter(today);\n\n return !selfInvoked && isExecutionPending;\n};\n\ninterface EncodeTokenParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport const encodeToken = ({ id, tenant, locale }: EncodeTokenParams) => {\n return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;\n};\n\nexport const TOKEN_PREFIX = \"apw-\";\n\nexport const decodeToken = (token: string): Partial<EncodeTokenParams> => {\n const auth = token.slice(TOKEN_PREFIX.length);\n const [id, tenant, locale] = auth.split(\"__\");\n\n return {\n id,\n tenant,\n locale\n };\n};\n\nexport const documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: process.env.AWS_REGION\n});\n\nexport const basePlugins = () => [\n dynamoDbPlugins(),\n logsPlugins(),\n dbPlugins({\n table: process.env.DB_TABLE,\n driver: new DynamoDbDriver({\n documentClient\n })\n })\n];\n\n/**\n * Get APW settings record from DDB.\n */\nexport interface ApwSettings {\n mainGraphqlFunctionArn: string;\n eventRuleName: string;\n eventTargetId: string;\n}\n\nexport const getApwSettings = async (): Promise<ApwSettings> => {\n const variant = process.env.STAGED_ROLLOUTS_VARIANT;\n\n const params = {\n TableName: process.env.DB_TABLE as string,\n Key: {\n PK: `APW#SETTINGS`,\n SK: variant || \"default\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n return {\n mainGraphqlFunctionArn: Item ? Item[\"mainGraphqlFunctionArn\"] : \"mainGraphqlFunctionArn\",\n eventRuleName: Item ? Item[\"eventRuleName\"] : \"eventRuleName\",\n eventTargetId: Item ? Item[\"eventTargetId\"] : \"eventTargetId\"\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACAA,cAAK,CAACC,MAAM,CAACC,YAAG,CAAC;AAEjB,MAAMC,cAAc,GAAG,GAAG;AAC1B,MAAMC,uBAAuB,GAAG,gBAAgB;AAEzC,MAAMC,uBAAuB,GAAIC,QAAgB,IAAa;EACjE;AACJ;AACA;EACI,IAAIC,KAAK,CAACC,IAAI,CAACC,KAAK,CAACH,QAAQ,CAAC,CAAC,EAAE;IAC7B,OAAOA,QAAQ;EACnB;EACA;EACA;EACA,OAAOA,QAAQ,CAACI,KAAK,CAAC,CAAC,EAAE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ACO,OAAO,EAAE;EAE3D,OAAO;IACHC,sBAAsB,EAAEH,IAAI,GAAGA,IAAI,CAAC,wBAAwB,CAAC,GAAG,wBAAwB;IACxFI,aAAa,EAAEJ,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG,eAAe;IAC7DK,aAAa,EAAEL,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG;EAClD,CAAC;AACL,CAAC;AAAC"}
|
@@ -2,13 +2,6 @@ import { CmsModelPlugin } from "@webiny/api-headless-cms";
|
|
2
2
|
import { CmsModel, CmsGroup } from "@webiny/api-headless-cms/types";
|
3
3
|
interface Params {
|
4
4
|
group: Pick<CmsGroup, "id" | "name">;
|
5
|
-
/**
|
6
|
-
* Locale and tenant do not need to be defined.
|
7
|
-
* In that case model is not bound to any locale or tenant.
|
8
|
-
* You can bind it to locale, tenant, both or none.
|
9
|
-
*/
|
10
|
-
locale?: string;
|
11
|
-
tenant?: string;
|
12
5
|
modelDefinition: Omit<CmsModel, "locale" | "tenant" | "webinyVersion" | "group">;
|
13
6
|
}
|
14
7
|
export declare const contentModelPluginFactory: (params: Params) => CmsModelPlugin;
|
@@ -10,14 +10,10 @@ var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
10
10
|
const contentModelPluginFactory = params => {
|
11
11
|
const {
|
12
12
|
group,
|
13
|
-
locale,
|
14
|
-
tenant,
|
15
13
|
modelDefinition
|
16
14
|
} = params;
|
17
15
|
return (0, _apiHeadlessCms.createCmsModel)((0, _objectSpread2.default)({
|
18
|
-
group
|
19
|
-
locale,
|
20
|
-
tenant
|
16
|
+
group
|
21
17
|
}, modelDefinition));
|
22
18
|
};
|
23
19
|
exports.contentModelPluginFactory = contentModelPluginFactory;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["contentModelPluginFactory","params","group","
|
1
|
+
{"version":3,"names":["contentModelPluginFactory","params","group","modelDefinition","createCmsModel"],"sources":["contentModelPluginFactory.ts"],"sourcesContent":["import { CmsModelPlugin, createCmsModel } from \"@webiny/api-headless-cms\";\nimport { CmsModel, CmsGroup } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n group: Pick<CmsGroup, \"id\" | \"name\">;\n modelDefinition: Omit<CmsModel, \"locale\" | \"tenant\" | \"webinyVersion\" | \"group\">;\n}\n\nexport const contentModelPluginFactory = (params: Params): CmsModelPlugin => {\n const { group, modelDefinition } = params;\n\n return createCmsModel({\n group,\n ...modelDefinition\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,yBAAyB,GAAIC,MAAc,IAAqB;EACzE,MAAM;IAAEC,KAAK;IAAEC;EAAgB,CAAC,GAAGF,MAAM;EAEzC,OAAO,IAAAG,8BAAc;IACjBF;EAAK,GACFC,eAAe,EACpB;AACN,CAAC;AAAC"}
|
@@ -70,8 +70,6 @@ const createApwModels = context => {
|
|
70
70
|
for (const modelDefinition of modelDefinitions) {
|
71
71
|
const cmsModelPlugin = (0, _contentModelPluginFactory.contentModelPluginFactory)({
|
72
72
|
group: cmsGroupPlugin.contentModelGroup,
|
73
|
-
tenant: context.tenancy.getCurrentTenant().id,
|
74
|
-
locale: locale.code,
|
75
73
|
modelDefinition
|
76
74
|
});
|
77
75
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createApwModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","security","disableAuthorization","locale","getContentLocale","WebinyError","groupId","cmsGroupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","changeRequestModelDefinition","createChangeRequestModelDefinition","reviewerModelDefinition","createReviewerModelDefinition","workflowModelDefinition","createWorkflowModelDefinition","reviewerModelId","modelId","commentModelDefinition","createCommentModelDefinition","contentReviewModelDefinition","createContentReviewModelDefinition","modelDefinitions","cmsModelPlugins","modelDefinition","cmsModelPlugin","contentModelPluginFactory","group","contentModelGroup","
|
1
|
+
{"version":3,"names":["createApwModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","security","disableAuthorization","locale","getContentLocale","WebinyError","groupId","cmsGroupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","changeRequestModelDefinition","createChangeRequestModelDefinition","reviewerModelDefinition","createReviewerModelDefinition","workflowModelDefinition","createWorkflowModelDefinition","reviewerModelId","modelId","commentModelDefinition","createCommentModelDefinition","contentReviewModelDefinition","createContentReviewModelDefinition","modelDefinitions","cmsModelPlugins","modelDefinition","cmsModelPlugin","contentModelPluginFactory","group","contentModelGroup","contentModel","titleFieldId","push","plugins","register","enableAuthorization"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin } from \"@webiny/api-headless-cms\";\nimport { contentModelPluginFactory } from \"./contentModelPluginFactory\";\nimport { createWorkflowModelDefinition } from \"./workflow.model\";\nimport { createContentReviewModelDefinition } from \"./contentReview.model\";\nimport { createReviewerModelDefinition } from \"./reviewer.model\";\nimport { createCommentModelDefinition } from \"./comment.model\";\nimport { createChangeRequestModelDefinition } from \"./changeRequest.model\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { isInstallationPending } from \"~/plugins/utils\";\n\nexport const createApwModels = (context: CmsContext) => {\n /**\n * This should never happen in the actual project.\n * It is to make sure that we load setup context before the CRUD init in our internal code.\n */\n if (!context.cms) {\n console.warn(\"Creating model before cms init.\");\n return;\n }\n\n if (isInstallationPending({ tenancy: context.tenancy, i18n: context.i18n })) {\n return;\n }\n\n context.security.disableAuthorization();\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/storageOperations/index.ts\",\n \"LOCALE_ERROR\"\n );\n }\n /**\n * TODO:@ashutosh\n * We need to move these plugin in an installation plugin\n */\n const groupId = \"contentModelGroup_apw\";\n /**\n * Create a CmsGroup.\n */\n const cmsGroupPlugin = new CmsGroupPlugin({\n id: groupId,\n slug: \"apw\",\n name: \"APW\",\n description: \"Group for Advanced Publishing Workflow\",\n icon: \"fas/star\",\n isPrivate: true\n });\n\n /**\n * Create CmsModel plugins.\n */\n const changeRequestModelDefinition = createChangeRequestModelDefinition();\n const reviewerModelDefinition = createReviewerModelDefinition();\n const workflowModelDefinition = createWorkflowModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n const commentModelDefinition = createCommentModelDefinition({\n modelId: changeRequestModelDefinition.modelId\n });\n const contentReviewModelDefinition = createContentReviewModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n\n const modelDefinitions = [\n workflowModelDefinition,\n contentReviewModelDefinition,\n reviewerModelDefinition,\n changeRequestModelDefinition,\n commentModelDefinition\n ];\n\n const cmsModelPlugins = [];\n for (const modelDefinition of modelDefinitions) {\n const cmsModelPlugin = contentModelPluginFactory({\n group: cmsGroupPlugin.contentModelGroup,\n modelDefinition\n });\n /**\n * We want \"title\" field as the \"titleField\" for \"ContentReview\" model.\n * so that we can later search entries by title.\n */\n if (cmsModelPlugin.contentModel.modelId === \"apwContentReviewModelDefinition\") {\n cmsModelPlugin.contentModel.titleFieldId = \"title\";\n }\n cmsModelPlugins.push(cmsModelPlugin);\n }\n\n /**\n * Register them so that they are accessible in cms context\n */\n context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);\n\n context.security.enableAuthorization();\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEO,MAAMA,eAAe,GAAIC,OAAmB,IAAK;EACpD;AACJ;AACA;AACA;EACI,IAAI,CAACA,OAAO,CAACC,GAAG,EAAE;IACdC,OAAO,CAACC,IAAI,CAAC,iCAAiC,CAAC;IAC/C;EACJ;EAEA,IAAI,IAAAC,4BAAqB,EAAC;IAAEC,OAAO,EAAEL,OAAO,CAACK,OAAO;IAAEC,IAAI,EAAEN,OAAO,CAACM;EAAK,CAAC,CAAC,EAAE;IACzE;EACJ;EAEAN,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;EAEvC,MAAMC,MAAM,GAAGT,OAAO,CAACM,IAAI,CAACI,gBAAgB,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AACC,YAAY,GAAG,OAAO;IACtD;IACAP,eAAe,CAACQ,IAAI,CAACN,cAAc,CAAC;EACxC;;EAEA;AACJ;AACA;EACIpC,OAAO,CAAC2C,OAAO,CAACC,QAAQ,CAAC,CAAC/B,cAAc,EAAEqB,eAAe,CAAC,CAAC;EAE3DlC,OAAO,CAACO,QAAQ,CAACsC,mBAAmB,EAAE;AAC1C,CAAC;AAAC"}
|
@@ -48,7 +48,9 @@ const createWorkflowStorageOperations = params => {
|
|
48
48
|
async listWorkflows(params) {
|
49
49
|
const model = await getWorkflowModel();
|
50
50
|
security.disableAuthorization();
|
51
|
-
const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)({}, params)
|
51
|
+
const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
52
|
+
where: (0, _objectSpread2.default)({}, params.where || {})
|
53
|
+
}));
|
52
54
|
security.enableAuthorization();
|
53
55
|
return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
|
54
56
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["formatReviewersForRefInput","data","modelId","steps","map","step","reviewers","id","createWorkflowStorageOperations","params","cms","security","getWorkflowModel","disableAuthorization","model","getModel","WORKFLOW_MODEL_ID","enableAuthorization","WebinyError","getWorkflow","entry","getEntryById","getFieldValues","baseFields","listWorkflows","entries","meta","listLatestEntries","createWorkflow","reviewerModel","getReviewerModel","createEntry","updateWorkflow","existingEntry","input","updateEntry","deleteWorkflow","deleteEntry"],"sources":["workflowStorageOperations.ts"],"sourcesContent":["import { CreateApwWorkflowParams } from \"~/types\";\nimport { ApwStorageOperations, ApwWorkflowStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\ntype ReviewersRefInput = CreateApwWorkflowParams<{ modelId: string; id: string }>;\n\nconst formatReviewersForRefInput = (\n data: CreateApwWorkflowParams,\n modelId: string\n): ReviewersRefInput => {\n return {\n ...data,\n steps: data.steps.map(step => ({\n ...step,\n reviewers: step.reviewers.map(id => ({\n id,\n modelId\n }))\n }))\n };\n};\n\nexport const createWorkflowStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwWorkflowStorageOperations => {\n const { cms, security } = params;\n const getWorkflowModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(WORKFLOW_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${WORKFLOW_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getWorkflow: ApwWorkflowStorageOperations[\"getWorkflow\"] = async ({ id }) => {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n return {\n getWorkflowModel,\n getWorkflow,\n async listWorkflows(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params\n });\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n\n const data = formatReviewersForRefInput(params.data, reviewerModel.modelId);\n security.disableAuthorization();\n const entry = await cms.createEntry(model, data);\n security.enableAuthorization();\n\n return getFieldValues(entry, baseFields);\n },\n async updateWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getWorkflow({ id: params.id });\n const input = {\n ...existingEntry,\n ...params.data\n };\n const data = formatReviewersForRefInput(\n input as CreateApwWorkflowParams,\n reviewerModel.modelId\n );\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, data);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteWorkflow(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAEA;AAKA;AACA;AAIA,MAAMA,0BAA0B,GAAG,CAC/BC,IAA6B,EAC7BC,OAAe,KACK;EACpB,mEACOD,IAAI;IACPE,KAAK,EAAEF,IAAI,CAACE,KAAK,CAACC,GAAG,CAACC,IAAI,gEACnBA,IAAI;MACPC,SAAS,EAAED,IAAI,CAACC,SAAS,CAACF,GAAG,CAACG,EAAE,KAAK;QACjCA,EAAE;QACFL;MACJ,CAAC,CAAC;IAAC,EACL;EAAC;AAEX,CAAC;AAEM,MAAMM,+BAA+B,GACxCC,MAAwC,IACT;EAC/B,MAAM;IAAEC,GAAG;IAAEC;EAAS,CAAC,GAAGF,MAAM;EAChC,MAAMG,gBAAgB,GAAG,YAAY;IACjCD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAQ,CAACC,2BAAiB,CAAC;IACnDL,QAAQ,CAACM,mBAAmB,EAAE;IAC9B,IAAI,CAACH,KAAK,EAAE;MACR,MAAM,IAAII,cAAW,CAChB,mBAAkBF,2BAAkB,UAAS,EAC9C,uBAAuB,CAC1B;IACL;IACA,OAAOF,KAAK;EAChB,CAAC;EACD,MAAMK,WAAwD,GAAG,OAAO;IAAEZ;EAAG,CAAC,KAAK;IAC/E,MAAMO,KAAK,GAAG,MAAMF,gBAAgB,EAAE;IACtCD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMO,KAAK,GAAG,MAAMV,GAAG,CAACW,YAAY,CAACP,KAAK,EAAEP,EAAE,CAAC;IAC/CI,QAAQ,CAACM,mBAAmB,EAAE;IAC9B,OAAO,IAAAK,qBAAc,EAACF,KAAK,EAAEG,iBAAU,CAAC;EAC5C,CAAC;EACD,OAAO;IACHX,gBAAgB;IAChBO,WAAW;IACX,MAAMK,aAAa,CAACf,MAAM,EAAE;MACxB,MAAMK,KAAK,GAAG,MAAMF,gBAAgB,EAAE;MACtCD,QAAQ,CAACE,oBAAoB,EAAE;MAC/B,MAAM,CAACY,OAAO,EAAEC,IAAI,CAAC,GAAG,MAAMhB,GAAG,CAACiB,iBAAiB,CAACb,KAAK,
|
1
|
+
{"version":3,"names":["formatReviewersForRefInput","data","modelId","steps","map","step","reviewers","id","createWorkflowStorageOperations","params","cms","security","getWorkflowModel","disableAuthorization","model","getModel","WORKFLOW_MODEL_ID","enableAuthorization","WebinyError","getWorkflow","entry","getEntryById","getFieldValues","baseFields","listWorkflows","entries","meta","listLatestEntries","where","createWorkflow","reviewerModel","getReviewerModel","createEntry","updateWorkflow","existingEntry","input","updateEntry","deleteWorkflow","deleteEntry"],"sources":["workflowStorageOperations.ts"],"sourcesContent":["import { CreateApwWorkflowParams } from \"~/types\";\nimport { ApwStorageOperations, ApwWorkflowStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\ntype ReviewersRefInput = CreateApwWorkflowParams<{ modelId: string; id: string }>;\n\nconst formatReviewersForRefInput = (\n data: CreateApwWorkflowParams,\n modelId: string\n): ReviewersRefInput => {\n return {\n ...data,\n steps: data.steps.map(step => ({\n ...step,\n reviewers: step.reviewers.map(id => ({\n id,\n modelId\n }))\n }))\n };\n};\n\nexport const createWorkflowStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwWorkflowStorageOperations => {\n const { cms, security } = params;\n const getWorkflowModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(WORKFLOW_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${WORKFLOW_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getWorkflow: ApwWorkflowStorageOperations[\"getWorkflow\"] = async ({ id }) => {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n return {\n getWorkflowModel,\n getWorkflow,\n async listWorkflows(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...(params.where || {})\n }\n });\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n\n const data = formatReviewersForRefInput(params.data, reviewerModel.modelId);\n security.disableAuthorization();\n const entry = await cms.createEntry(model, data);\n security.enableAuthorization();\n\n return getFieldValues(entry, baseFields);\n },\n async updateWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getWorkflow({ id: params.id });\n const input = {\n ...existingEntry,\n ...params.data\n };\n const data = formatReviewersForRefInput(\n input as CreateApwWorkflowParams,\n reviewerModel.modelId\n );\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, data);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteWorkflow(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAEA;AAKA;AACA;AAIA,MAAMA,0BAA0B,GAAG,CAC/BC,IAA6B,EAC7BC,OAAe,KACK;EACpB,mEACOD,IAAI;IACPE,KAAK,EAAEF,IAAI,CA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