@webiny/api-apw 5.23.0-beta.0
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 +33 -0
- package/createApw/createChangeRequestMethods.d.ts +2 -0
- package/createApw/createChangeRequestMethods.js +95 -0
- package/createApw/createCommentMethods.d.ts +2 -0
- package/createApw/createCommentMethods.js +96 -0
- package/createApw/createContentReviewMethods.d.ts +6 -0
- package/createApw/createContentReviewMethods.js +301 -0
- package/createApw/createReviewerMethods.d.ts +2 -0
- package/createApw/createReviewerMethods.js +96 -0
- package/createApw/createWorkflowMethods.d.ts +2 -0
- package/createApw/createWorkflowMethods.js +96 -0
- package/createApw/index.d.ts +2 -0
- package/createApw/index.js +54 -0
- package/index.d.ts +2 -0
- package/index.js +28 -0
- package/package.json +67 -0
- package/plugins/context.d.ts +4 -0
- package/plugins/context.js +89 -0
- package/plugins/createManageCMSPlugin.d.ts +2 -0
- package/plugins/createManageCMSPlugin.js +31 -0
- package/plugins/graphql/changeRequest.gql.d.ts +4 -0
- package/plugins/graphql/changeRequest.gql.js +152 -0
- package/plugins/graphql/comment.gql.d.ts +4 -0
- package/plugins/graphql/comment.gql.js +166 -0
- package/plugins/graphql/contentReview.gql.d.ts +4 -0
- package/plugins/graphql/contentReview.gql.js +224 -0
- package/plugins/graphql/reviewer.gql.d.ts +4 -0
- package/plugins/graphql/reviewer.gql.js +111 -0
- package/plugins/graphql/workflow.gql.d.ts +4 -0
- package/plugins/graphql/workflow.gql.js +199 -0
- package/plugins/graphql.d.ts +3 -0
- package/plugins/graphql.js +84 -0
- package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
- package/plugins/hooks/createReviewerFromIdentity.js +44 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +66 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +58 -0
- package/plugins/hooks/extendPbPageSchema.d.ts +4 -0
- package/plugins/hooks/extendPbPageSchema.js +24 -0
- package/plugins/hooks/index.d.ts +4 -0
- package/plugins/hooks/index.js +68 -0
- package/plugins/hooks/initializeContentReviewSteps.d.ts +7 -0
- package/plugins/hooks/initializeContentReviewSteps.js +70 -0
- package/plugins/hooks/linkWorkflowToPage.d.ts +9 -0
- package/plugins/hooks/linkWorkflowToPage.js +154 -0
- package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
- package/plugins/hooks/updatePendingChangeRequests.js +107 -0
- package/plugins/utils.d.ts +15 -0
- package/plugins/utils.js +69 -0
- package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
- package/storageOperations/changeRequestStorageOperations.js +96 -0
- package/storageOperations/commentStorageOperations.d.ts +3 -0
- package/storageOperations/commentStorageOperations.js +101 -0
- package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
- package/storageOperations/contentReviewStorageOperations.js +72 -0
- package/storageOperations/index.d.ts +9 -0
- package/storageOperations/index.js +63 -0
- package/storageOperations/models/changeRequest.model.d.ts +7 -0
- package/storageOperations/models/changeRequest.model.js +52 -0
- package/storageOperations/models/comment.model.d.ts +9 -0
- package/storageOperations/models/comment.model.js +37 -0
- package/storageOperations/models/contentModelPluginFactory.d.ts +17 -0
- package/storageOperations/models/contentModelPluginFactory.js +33 -0
- package/storageOperations/models/contentReview.model.d.ts +25 -0
- package/storageOperations/models/contentReview.model.js +181 -0
- package/storageOperations/models/index.d.ts +1 -0
- package/storageOperations/models/index.js +87 -0
- package/storageOperations/models/reviewer.model.d.ts +7 -0
- package/storageOperations/models/reviewer.model.js +48 -0
- package/storageOperations/models/utils.d.ts +3 -0
- package/storageOperations/models/utils.js +35 -0
- package/storageOperations/models/workflow.model.d.ts +17 -0
- package/storageOperations/models/workflow.model.js +204 -0
- package/storageOperations/reviewerStorageOperations.d.ts +3 -0
- package/storageOperations/reviewerStorageOperations.js +72 -0
- package/storageOperations/types.d.ts +34 -0
- package/storageOperations/types.js +5 -0
- package/storageOperations/workflowStorageOperations.d.ts +3 -0
- package/storageOperations/workflowStorageOperations.js +72 -0
- package/types.d.ts +646 -0
- package/types.js +63 -0
- package/utils/errors.d.ts +16 -0
- package/utils/errors.js +75 -0
- package/utils/fieldResolver.d.ts +15 -0
- package/utils/fieldResolver.js +58 -0
- package/utils/resolve.d.ts +3 -0
- package/utils/resolve.js +18 -0
@@ -0,0 +1,84 @@
|
|
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 _plugins = require("@webiny/handler-graphql/plugins");
|
11
|
+
|
12
|
+
var _workflow = _interopRequireDefault(require("./graphql/workflow.gql"));
|
13
|
+
|
14
|
+
var _contentReview = _interopRequireDefault(require("./graphql/contentReview.gql"));
|
15
|
+
|
16
|
+
var _reviewer = _interopRequireDefault(require("./graphql/reviewer.gql"));
|
17
|
+
|
18
|
+
var _comment = _interopRequireDefault(require("./graphql/comment.gql"));
|
19
|
+
|
20
|
+
var _changeRequest = _interopRequireDefault(require("./graphql/changeRequest.gql"));
|
21
|
+
|
22
|
+
const emptyResolver = () => ({});
|
23
|
+
|
24
|
+
const baseSchema = new _plugins.GraphQLSchemaPlugin({
|
25
|
+
typeDefs:
|
26
|
+
/* GraphQL */
|
27
|
+
`
|
28
|
+
input ApwRefFieldInput {
|
29
|
+
id: ID!
|
30
|
+
modelId: String
|
31
|
+
}
|
32
|
+
|
33
|
+
input ApwRefFieldWhereInput {
|
34
|
+
id: String
|
35
|
+
id_not: String
|
36
|
+
id_in: [String!]
|
37
|
+
id_not_in: [String]
|
38
|
+
entryId: String
|
39
|
+
entryId_not: String
|
40
|
+
entryId_in: [String!]
|
41
|
+
entryId_not_in: [String!]
|
42
|
+
}
|
43
|
+
|
44
|
+
type ApwRefField {
|
45
|
+
modelId: String!
|
46
|
+
entryId: ID!
|
47
|
+
id: ID!
|
48
|
+
}
|
49
|
+
|
50
|
+
type ApwMeta {
|
51
|
+
hasMoreItems: Boolean
|
52
|
+
totalCount: Int
|
53
|
+
cursor: String
|
54
|
+
}
|
55
|
+
type ApwCreatedBy {
|
56
|
+
id: ID
|
57
|
+
displayName: String
|
58
|
+
type: String
|
59
|
+
}
|
60
|
+
type ApwError {
|
61
|
+
code: String
|
62
|
+
message: String
|
63
|
+
data: JSON
|
64
|
+
}
|
65
|
+
extend type Query {
|
66
|
+
apw: ApwQuery
|
67
|
+
}
|
68
|
+
extend type Mutation {
|
69
|
+
apw: ApwMutation
|
70
|
+
}
|
71
|
+
`,
|
72
|
+
resolvers: {
|
73
|
+
Query: {
|
74
|
+
apw: emptyResolver
|
75
|
+
},
|
76
|
+
Mutation: {
|
77
|
+
apw: emptyResolver
|
78
|
+
}
|
79
|
+
}
|
80
|
+
});
|
81
|
+
|
82
|
+
var _default = () => [baseSchema, _workflow.default, _contentReview.default, _reviewer.default, _comment.default, _changeRequest.default];
|
83
|
+
|
84
|
+
exports.default = _default;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createReviewerFromIdentity = void 0;
|
7
|
+
|
8
|
+
const createReviewerFromIdentity = ({
|
9
|
+
security,
|
10
|
+
apw
|
11
|
+
}) => {
|
12
|
+
/**
|
13
|
+
* Replicate identity in "AdvancedPublishingWorkflow" system after login.
|
14
|
+
*/
|
15
|
+
security.onAfterLogin.subscribe(async ({
|
16
|
+
identity
|
17
|
+
}) => {
|
18
|
+
let reviewer;
|
19
|
+
|
20
|
+
try {
|
21
|
+
[[reviewer]] = await apw.reviewer.list({
|
22
|
+
where: {
|
23
|
+
identityId: identity.id
|
24
|
+
},
|
25
|
+
limit: 1
|
26
|
+
});
|
27
|
+
} catch (e) {
|
28
|
+
if (e.message === "index_not_found_exception") {// Do nothing
|
29
|
+
} else {
|
30
|
+
throw e;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
if (!reviewer) {
|
35
|
+
await apw.reviewer.create({
|
36
|
+
identityId: identity.id,
|
37
|
+
displayName: identity.displayName,
|
38
|
+
type: identity.type
|
39
|
+
});
|
40
|
+
}
|
41
|
+
});
|
42
|
+
};
|
43
|
+
|
44
|
+
exports.createReviewerFromIdentity = createReviewerFromIdentity;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.deleteChangeRequestsWithContentReview = void 0;
|
7
|
+
|
8
|
+
const deleteChangeRequestsWithContentReview = ({
|
9
|
+
apw
|
10
|
+
}) => {
|
11
|
+
apw.contentReview.onAfterContentReviewDelete.subscribe(async ({
|
12
|
+
contentReview
|
13
|
+
}) => {
|
14
|
+
/**
|
15
|
+
* Also delete all associated "changeRequest" when a "contentReview" is deleted.
|
16
|
+
*/
|
17
|
+
const steps = contentReview.steps;
|
18
|
+
/**
|
19
|
+
* For each step get associated change requests and delete them.
|
20
|
+
*/
|
21
|
+
|
22
|
+
for (let i = 0; i < steps.length; i++) {
|
23
|
+
const {
|
24
|
+
slug
|
25
|
+
} = steps[i];
|
26
|
+
let meta = {
|
27
|
+
hasMoreItems: true,
|
28
|
+
cursor: null
|
29
|
+
};
|
30
|
+
let changeRequests = [];
|
31
|
+
/**
|
32
|
+
* Paginate through change requests.
|
33
|
+
*/
|
34
|
+
|
35
|
+
while (meta.hasMoreItems) {
|
36
|
+
/**
|
37
|
+
* Get all change requests.
|
38
|
+
*/
|
39
|
+
try {
|
40
|
+
[changeRequests, meta] = await apw.changeRequest.list({
|
41
|
+
where: {
|
42
|
+
step: `${contentReview.id}#${slug}`
|
43
|
+
},
|
44
|
+
after: meta.cursor
|
45
|
+
});
|
46
|
+
} catch (e) {
|
47
|
+
meta.hasMoreItems = false;
|
48
|
+
|
49
|
+
if (e.message !== "index_not_found_exception") {
|
50
|
+
throw e;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
/**
|
54
|
+
* Delete change requests one by one.
|
55
|
+
*/
|
56
|
+
|
57
|
+
|
58
|
+
for (const changeRequest of changeRequests) {
|
59
|
+
await apw.changeRequest.delete(changeRequest.id);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
});
|
64
|
+
};
|
65
|
+
|
66
|
+
exports.deleteChangeRequestsWithContentReview = deleteChangeRequestsWithContentReview;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.deleteCommentsAfterChangeRequest = void 0;
|
7
|
+
|
8
|
+
const deleteCommentsAfterChangeRequest = ({
|
9
|
+
apw
|
10
|
+
}) => {
|
11
|
+
apw.changeRequest.onAfterChangeRequestDelete.subscribe(async ({
|
12
|
+
changeRequest
|
13
|
+
}) => {
|
14
|
+
/**
|
15
|
+
* Also delete all associated comments with "changeRequest".
|
16
|
+
*/
|
17
|
+
let meta = {
|
18
|
+
hasMoreItems: true,
|
19
|
+
cursor: null
|
20
|
+
};
|
21
|
+
let comments = [];
|
22
|
+
/**
|
23
|
+
* Paginate through comments.
|
24
|
+
*/
|
25
|
+
|
26
|
+
while (meta.hasMoreItems) {
|
27
|
+
/**
|
28
|
+
* Get all comments.
|
29
|
+
*/
|
30
|
+
try {
|
31
|
+
[comments, meta] = await apw.comment.list({
|
32
|
+
where: {
|
33
|
+
changeRequest: {
|
34
|
+
id: changeRequest.id
|
35
|
+
}
|
36
|
+
},
|
37
|
+
after: meta.cursor
|
38
|
+
});
|
39
|
+
} catch (e) {
|
40
|
+
meta.hasMoreItems = false;
|
41
|
+
|
42
|
+
if (e.message !== "index_not_found_exception") {
|
43
|
+
throw e;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* Delete comments one by one.
|
48
|
+
*/
|
49
|
+
|
50
|
+
|
51
|
+
for (const comment of comments) {
|
52
|
+
await apw.comment.delete(comment.id);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
};
|
57
|
+
|
58
|
+
exports.deleteCommentsAfterChangeRequest = deleteCommentsAfterChangeRequest;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _plugins = require("@webiny/handler-graphql/plugins");
|
9
|
+
|
10
|
+
var _default = () => new _plugins.GraphQLSchemaPlugin({
|
11
|
+
typeDefs:
|
12
|
+
/* GraphQL */
|
13
|
+
`
|
14
|
+
type PbApwPageSettings {
|
15
|
+
workflowId: ID
|
16
|
+
}
|
17
|
+
|
18
|
+
extend type PbPageSettings {
|
19
|
+
apw: PbApwPageSettings
|
20
|
+
}
|
21
|
+
`
|
22
|
+
});
|
23
|
+
|
24
|
+
exports.default = _default;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
|
2
|
+
import { ApwContext } from "../../types";
|
3
|
+
declare const _default: () => (import("@webiny/handler-graphql/plugins").GraphQLSchemaPlugin<ApwContext> | ContextPlugin<ApwContext>)[];
|
4
|
+
export default _default;
|
@@ -0,0 +1,68 @@
|
|
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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
|
13
|
+
|
14
|
+
var _extendPbPageSchema = _interopRequireDefault(require("./extendPbPageSchema"));
|
15
|
+
|
16
|
+
var _linkWorkflowToPage = require("./linkWorkflowToPage");
|
17
|
+
|
18
|
+
var _deleteCommentsAfterChangeRequest = require("./deleteCommentsAfterChangeRequest");
|
19
|
+
|
20
|
+
var _deleteChangeRequestsAfterContentReview = require("./deleteChangeRequestsAfterContentReview");
|
21
|
+
|
22
|
+
var _createReviewerFromIdentity = require("./createReviewerFromIdentity");
|
23
|
+
|
24
|
+
var _initializeContentReviewSteps = require("./initializeContentReviewSteps");
|
25
|
+
|
26
|
+
var _updatePendingChangeRequests = require("./updatePendingChangeRequests");
|
27
|
+
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
29
|
+
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
31
|
+
|
32
|
+
var _default = () => [(0, _extendPbPageSchema.default)(),
|
33
|
+
/**
|
34
|
+
* Hook into CMS events and execute business logic.
|
35
|
+
*/
|
36
|
+
new _ContextPlugin.ContextPlugin(async context => {
|
37
|
+
const {
|
38
|
+
security,
|
39
|
+
apw,
|
40
|
+
pageBuilder
|
41
|
+
} = context;
|
42
|
+
const pageMethods = {
|
43
|
+
onBeforePageCreate: pageBuilder.onBeforePageCreate,
|
44
|
+
getPage: pageBuilder.getPage,
|
45
|
+
updatePage: pageBuilder.updatePage
|
46
|
+
};
|
47
|
+
(0, _createReviewerFromIdentity.createReviewerFromIdentity)({
|
48
|
+
security,
|
49
|
+
apw
|
50
|
+
});
|
51
|
+
(0, _linkWorkflowToPage.linkWorkflowToPage)(_objectSpread({
|
52
|
+
apw
|
53
|
+
}, pageMethods));
|
54
|
+
(0, _initializeContentReviewSteps.initializeContentReviewSteps)({
|
55
|
+
apw
|
56
|
+
});
|
57
|
+
(0, _updatePendingChangeRequests.updatePendingChangeRequestsCount)({
|
58
|
+
apw
|
59
|
+
});
|
60
|
+
(0, _deleteCommentsAfterChangeRequest.deleteCommentsAfterChangeRequest)({
|
61
|
+
apw
|
62
|
+
});
|
63
|
+
(0, _deleteChangeRequestsAfterContentReview.deleteChangeRequestsWithContentReview)({
|
64
|
+
apw
|
65
|
+
});
|
66
|
+
})];
|
67
|
+
|
68
|
+
exports.default = _default;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { AdvancedPublishingWorkflow, ApwContentTypes, LifeCycleHookCallbackParams } from "../../types";
|
2
|
+
export declare const getWorkflowIdFromContent: (apw: AdvancedPublishingWorkflow, params: {
|
3
|
+
type: ApwContentTypes;
|
4
|
+
id: string;
|
5
|
+
settings: Record<string, any>;
|
6
|
+
}) => Promise<string>;
|
7
|
+
export declare const initializeContentReviewSteps: ({ apw }: LifeCycleHookCallbackParams) => void;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.initializeContentReviewSteps = exports.getWorkflowIdFromContent = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _set = _interopRequireDefault(require("lodash/set"));
|
13
|
+
|
14
|
+
var _types = require("../../types");
|
15
|
+
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
19
|
+
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
21
|
+
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
23
|
+
|
24
|
+
const getWorkflowIdFromContent = async (apw, params) => {
|
25
|
+
switch (params.type) {
|
26
|
+
case _types.ApwContentTypes.PAGE:
|
27
|
+
const getWorkflowFromPage = apw.getWorkflowGetter(_types.ApwContentTypes.PAGE);
|
28
|
+
return getWorkflowFromPage(params.id, {});
|
29
|
+
|
30
|
+
case _types.ApwContentTypes.CMS_ENTRY:
|
31
|
+
const getWorkflowFromCmsEntry = apw.getWorkflowGetter(_types.ApwContentTypes.CMS_ENTRY);
|
32
|
+
return getWorkflowFromCmsEntry(params.id, params.settings);
|
33
|
+
}
|
34
|
+
|
35
|
+
return null;
|
36
|
+
};
|
37
|
+
|
38
|
+
exports.getWorkflowIdFromContent = getWorkflowIdFromContent;
|
39
|
+
|
40
|
+
const initializeContentReviewSteps = ({
|
41
|
+
apw
|
42
|
+
}) => {
|
43
|
+
apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({
|
44
|
+
input
|
45
|
+
}) => {
|
46
|
+
/**
|
47
|
+
* Let's initialize the "ContentReview" steps.
|
48
|
+
*/
|
49
|
+
const workflowId = await getWorkflowIdFromContent(apw, input.content);
|
50
|
+
|
51
|
+
if (!workflowId) {
|
52
|
+
throw new _handlerGraphql.NotFoundError(`Unable to initiate a "Content review". No workflow found!`);
|
53
|
+
}
|
54
|
+
|
55
|
+
const workflow = await apw.workflow.get(workflowId);
|
56
|
+
const workflowSteps = workflow.steps;
|
57
|
+
let previousStepStatus;
|
58
|
+
const updatedSteps = workflow.steps.map((step, index) => {
|
59
|
+
const status = (0, _utils.getContentReviewStepInitialStatus)(workflowSteps, index, previousStepStatus);
|
60
|
+
previousStepStatus = status;
|
61
|
+
return _objectSpread(_objectSpread({}, step), {}, {
|
62
|
+
status,
|
63
|
+
pendingChangeRequests: 0
|
64
|
+
});
|
65
|
+
});
|
66
|
+
input = (0, _set.default)(input, "steps", updatedSteps);
|
67
|
+
});
|
68
|
+
};
|
69
|
+
|
70
|
+
exports.initializeContentReviewSteps = initializeContentReviewSteps;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { LifeCycleHookCallbackParams } from "../../types";
|
2
|
+
import { PageBuilderContextObject } from "@webiny/api-page-builder/graphql/types";
|
3
|
+
interface PageMethods {
|
4
|
+
getPage: PageBuilderContextObject["getPage"];
|
5
|
+
updatePage: PageBuilderContextObject["updatePage"];
|
6
|
+
onBeforePageCreate: PageBuilderContextObject["onBeforePageCreate"];
|
7
|
+
}
|
8
|
+
export declare const linkWorkflowToPage: ({ apw, getPage, updatePage, onBeforePageCreate }: LifeCycleHookCallbackParams & PageMethods) => void;
|
9
|
+
export {};
|
@@ -0,0 +1,154 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.linkWorkflowToPage = void 0;
|
9
|
+
|
10
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
11
|
+
|
12
|
+
var _set = _interopRequireDefault(require("lodash/set"));
|
13
|
+
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
15
|
+
|
16
|
+
var _types = require("../../types");
|
17
|
+
|
18
|
+
const WORKFLOW_PRECEDENCE = {
|
19
|
+
[_types.WorkflowScopeTypes.DEFAULT]: 0,
|
20
|
+
[_types.WorkflowScopeTypes.PB]: 1,
|
21
|
+
[_types.WorkflowScopeTypes.CMS]: 1
|
22
|
+
};
|
23
|
+
|
24
|
+
const workflowByPrecedenceDesc = (a, b) => {
|
25
|
+
const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
|
26
|
+
const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
|
27
|
+
/**
|
28
|
+
* In descending order of workflow precedence.
|
29
|
+
*/
|
30
|
+
|
31
|
+
return scoreB - scoreA;
|
32
|
+
};
|
33
|
+
|
34
|
+
const workflowByCreatedOnDesc = (a, b) => {
|
35
|
+
const createdOnA = (0, _get.default)(a, "createdOn");
|
36
|
+
const createdOnB = (0, _get.default)(b, "createdOn");
|
37
|
+
/**
|
38
|
+
* In descending order of workflow createdOn i.e. the most recent one first.
|
39
|
+
*/
|
40
|
+
|
41
|
+
return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
|
42
|
+
};
|
43
|
+
|
44
|
+
const isWorkflowApplicable = (page, workflow) => {
|
45
|
+
const application = workflow.app;
|
46
|
+
|
47
|
+
if (application !== _types.ApwWorkflowApplications.PB) {
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
|
51
|
+
const scopeType = workflow.scope.type;
|
52
|
+
|
53
|
+
if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
|
54
|
+
return true;
|
55
|
+
}
|
56
|
+
|
57
|
+
if (scopeType === _types.WorkflowScopeTypes.PB) {
|
58
|
+
const categories = (0, _get.default)(workflow, "scope.data.categories");
|
59
|
+
|
60
|
+
if (Array.isArray(categories) && categories.includes(page.category)) {
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
|
64
|
+
const pages = (0, _get.default)(workflow, "scope.data.pages");
|
65
|
+
|
66
|
+
if (Array.isArray(pages) && pages.includes(page.pid)) {
|
67
|
+
return true;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
return false;
|
72
|
+
};
|
73
|
+
|
74
|
+
const linkWorkflowToPage = ({
|
75
|
+
apw,
|
76
|
+
getPage,
|
77
|
+
updatePage,
|
78
|
+
onBeforePageCreate
|
79
|
+
}) => {
|
80
|
+
onBeforePageCreate.subscribe(async ({
|
81
|
+
page
|
82
|
+
}) => {
|
83
|
+
try {
|
84
|
+
/*
|
85
|
+
* List all workflows for app pageBuilder
|
86
|
+
*/
|
87
|
+
const [entries] = await apw.workflow.list({
|
88
|
+
where: {
|
89
|
+
app: _types.ApwWorkflowApplications.PB
|
90
|
+
}
|
91
|
+
});
|
92
|
+
/*
|
93
|
+
* Re-order them based on workflow scope and pre-defined rule i.e.
|
94
|
+
* "specific" entry -> entry for a "category" -> "default".
|
95
|
+
* There can be more than one workflow with same "scope" and "app".
|
96
|
+
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
97
|
+
*/
|
98
|
+
|
99
|
+
const sortedWorkflows = entries.sort(workflowByPrecedenceDesc).sort(workflowByCreatedOnDesc);
|
100
|
+
|
101
|
+
for (const workflow of sortedWorkflows) {
|
102
|
+
/**
|
103
|
+
* We workflow if applicable to this page, we're done here.
|
104
|
+
* Assign the workflow to the page and exit.
|
105
|
+
*/
|
106
|
+
if (isWorkflowApplicable(page, workflow)) {
|
107
|
+
page.settings.apw = {
|
108
|
+
workflowId: workflow.id
|
109
|
+
};
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
} catch (e) {
|
114
|
+
throw new _error.default(`Failed to assign workflow to page "${page.pid}".`, e.code, e.data);
|
115
|
+
}
|
116
|
+
});
|
117
|
+
apw.workflow.onAfterWorkflowCreate.subscribe(async ({
|
118
|
+
workflow
|
119
|
+
}) => {
|
120
|
+
const {
|
121
|
+
app,
|
122
|
+
scope
|
123
|
+
} = workflow;
|
124
|
+
/**
|
125
|
+
* If the workflow is applicable PB application and pages are provided,
|
126
|
+
* we'll assign workflow for each of those provided page.
|
127
|
+
*/
|
128
|
+
|
129
|
+
if (app === _types.ApwWorkflowApplications.PB && scope.type === _types.WorkflowScopeTypes.PB && scope.data && Array.isArray(scope.data.pages)) {
|
130
|
+
for (const pid of scope.data.pages) {
|
131
|
+
try {
|
132
|
+
/**
|
133
|
+
* Currently, we only assign "workflow" to latest page.
|
134
|
+
*/
|
135
|
+
const page = await getPage(pid);
|
136
|
+
/**
|
137
|
+
* There can be more than one workflow with same `scope` for same `app`. That is why;
|
138
|
+
* We'll update the workflow reference even though it already had one assign.
|
139
|
+
*/
|
140
|
+
|
141
|
+
await updatePage(page.id, {
|
142
|
+
settings: (0, _set.default)(page.settings, "apw.workflowId", workflow.id)
|
143
|
+
});
|
144
|
+
} catch (e) {
|
145
|
+
if (e.code !== "NOT_FOUND") {
|
146
|
+
throw e;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
});
|
152
|
+
};
|
153
|
+
|
154
|
+
exports.linkWorkflowToPage = linkWorkflowToPage;
|