@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,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.updatePendingChangeRequestsCount = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
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; }
|
13
|
+
|
14
|
+
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; }
|
15
|
+
|
16
|
+
const updatePendingChangeRequests = async ({
|
17
|
+
contentReviewMethods,
|
18
|
+
changeRequest,
|
19
|
+
delta
|
20
|
+
}) => {
|
21
|
+
const {
|
22
|
+
step: stepSlug
|
23
|
+
} = changeRequest;
|
24
|
+
/*
|
25
|
+
* Get associated content review entry.
|
26
|
+
*/
|
27
|
+
|
28
|
+
const [entryId, version, slug] = stepSlug.split("#");
|
29
|
+
const revisionId = `${entryId}#${version}`;
|
30
|
+
let contentReviewEntry;
|
31
|
+
|
32
|
+
try {
|
33
|
+
contentReviewEntry = await contentReviewMethods.get(revisionId);
|
34
|
+
} catch (e) {
|
35
|
+
if (e.message !== "index_not_found_exception" && e.code !== "NOT_FOUND") {
|
36
|
+
throw e;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
if (contentReviewEntry) {
|
41
|
+
/**
|
42
|
+
* Update "pendingChangeRequests" count of corresponding step in content review entry.
|
43
|
+
*/
|
44
|
+
await contentReviewMethods.update(contentReviewEntry.id, {
|
45
|
+
steps: contentReviewEntry.steps.map(step => {
|
46
|
+
if (step.slug === slug) {
|
47
|
+
return _objectSpread(_objectSpread({}, step), {}, {
|
48
|
+
pendingChangeRequests: step.pendingChangeRequests + delta
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
return step;
|
53
|
+
})
|
54
|
+
});
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
const updatePendingChangeRequestsCount = ({
|
59
|
+
apw
|
60
|
+
}) => {
|
61
|
+
apw.changeRequest.onAfterChangeRequestDelete.subscribe(async ({
|
62
|
+
changeRequest
|
63
|
+
}) => {
|
64
|
+
/**
|
65
|
+
* After a "changeRequest" is deleted, decrement the "pendingChangeRequests" count
|
66
|
+
* in the corresponding step of the content review entry.
|
67
|
+
*/
|
68
|
+
await updatePendingChangeRequests({
|
69
|
+
contentReviewMethods: apw.contentReview,
|
70
|
+
changeRequest: changeRequest,
|
71
|
+
delta: -1
|
72
|
+
});
|
73
|
+
});
|
74
|
+
apw.changeRequest.onAfterChangeRequestCreate.subscribe(async ({
|
75
|
+
changeRequest
|
76
|
+
}) => {
|
77
|
+
/**
|
78
|
+
* After a "changeRequest" is created, increment the "pendingChangeRequests" count
|
79
|
+
* of the corresponding step in the content review entry.
|
80
|
+
*/
|
81
|
+
await updatePendingChangeRequests({
|
82
|
+
contentReviewMethods: apw.contentReview,
|
83
|
+
changeRequest,
|
84
|
+
delta: 1
|
85
|
+
});
|
86
|
+
});
|
87
|
+
apw.changeRequest.onAfterChangeRequestUpdate.subscribe(async ({
|
88
|
+
changeRequest,
|
89
|
+
original
|
90
|
+
}) => {
|
91
|
+
/**
|
92
|
+
* After a "changeRequest" is created, and the value of "resolved" field has changed;
|
93
|
+
* then we also need to update the "pendingChangeRequests" count of the corresponding step in the content review entry.
|
94
|
+
*/
|
95
|
+
if (original.resolved !== changeRequest.resolved) {
|
96
|
+
const resolved = changeRequest.resolved;
|
97
|
+
const delta = resolved === true ? -1 : 1;
|
98
|
+
await updatePendingChangeRequests({
|
99
|
+
contentReviewMethods: apw.contentReview,
|
100
|
+
changeRequest,
|
101
|
+
delta
|
102
|
+
});
|
103
|
+
}
|
104
|
+
});
|
105
|
+
};
|
106
|
+
|
107
|
+
exports.updatePendingChangeRequestsCount = updatePendingChangeRequestsCount;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
2
|
+
import { ApwContentReviewStep, ApwContentReviewStepStatus, ApwReviewerCrud, ApwWorkflowStep, ApwWorkflowStepTypes } from "../types";
|
3
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
4
|
+
export interface CreateModelFieldParams extends Omit<CmsModelField, "id" | "fieldId"> {
|
5
|
+
parent: string;
|
6
|
+
}
|
7
|
+
export interface HasReviewersParams {
|
8
|
+
identity: SecurityIdentity;
|
9
|
+
step: ApwContentReviewStep;
|
10
|
+
getReviewer: ApwReviewerCrud["get"];
|
11
|
+
}
|
12
|
+
export declare const hasReviewer: ({ getReviewer, identity, step }: HasReviewersParams) => Promise<Boolean>;
|
13
|
+
export declare const getValue: (object: Record<string, any>, key: string) => any;
|
14
|
+
export declare const getContentReviewStepInitialStatus: (workflowSteps: ApwWorkflowStep[], index: number, previousStepStatus: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
15
|
+
export declare const getNextStepStatus: (previousStepType: ApwWorkflowStepTypes, previousStepStatus: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
package/plugins/utils.js
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getContentReviewStepInitialStatus = void 0;
|
9
|
+
|
10
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
11
|
+
|
12
|
+
var _types = require("../types");
|
13
|
+
|
14
|
+
const hasReviewer = async ({
|
15
|
+
getReviewer,
|
16
|
+
identity,
|
17
|
+
step
|
18
|
+
}) => {
|
19
|
+
for (const stepReviewer of step.reviewers) {
|
20
|
+
const entry = await getReviewer(stepReviewer.id);
|
21
|
+
|
22
|
+
if (entry.identityId === identity.id) {
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
return false;
|
28
|
+
};
|
29
|
+
|
30
|
+
exports.hasReviewer = hasReviewer;
|
31
|
+
|
32
|
+
const getValue = (object, key) => {
|
33
|
+
return (0, _get.default)(object, `values.${key}`);
|
34
|
+
};
|
35
|
+
|
36
|
+
exports.getValue = getValue;
|
37
|
+
|
38
|
+
const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
|
39
|
+
/**
|
40
|
+
* Always set first step 'active' by default.
|
41
|
+
*/
|
42
|
+
if (index === 0) {
|
43
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
44
|
+
}
|
45
|
+
|
46
|
+
const previousStep = workflowSteps[index - 1];
|
47
|
+
|
48
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
49
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
50
|
+
}
|
51
|
+
|
52
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
53
|
+
};
|
54
|
+
|
55
|
+
exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
|
56
|
+
|
57
|
+
const getNextStepStatus = (previousStepType, previousStepStatus) => {
|
58
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
|
59
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
63
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
64
|
+
}
|
65
|
+
|
66
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.getNextStepStatus = getNextStepStatus;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { ApwChangeRequestStorageOperations } from "./types";
|
2
|
+
import { CreateApwStorageOperationsParams } from "./index";
|
3
|
+
export declare const createChangeRequestStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwChangeRequestStorageOperations;
|
@@ -0,0 +1,96 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createChangeRequestStorageOperations = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _index = require("./index");
|
13
|
+
|
14
|
+
var _fieldResolver = require("../utils/fieldResolver");
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
19
|
+
|
20
|
+
const createChangeRequestStorageOperations = ({
|
21
|
+
cms,
|
22
|
+
getCmsContext
|
23
|
+
}) => {
|
24
|
+
const getChangeRequestModel = () => {
|
25
|
+
return cms.getModel("apwChangeRequestModelDefinition");
|
26
|
+
};
|
27
|
+
|
28
|
+
const getChangeRequest = async ({
|
29
|
+
id
|
30
|
+
}) => {
|
31
|
+
const model = await getChangeRequestModel();
|
32
|
+
const entry = await cms.getEntryById(model, id);
|
33
|
+
return (0, _fieldResolver.getFieldValues)({
|
34
|
+
entry,
|
35
|
+
fields: _index.baseFields,
|
36
|
+
context: getCmsContext(),
|
37
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
return {
|
42
|
+
getChangeRequestModel,
|
43
|
+
getChangeRequest,
|
44
|
+
|
45
|
+
async listChangeRequests(params) {
|
46
|
+
const model = await getChangeRequestModel();
|
47
|
+
const [entries, meta] = await cms.listLatestEntries(model, params);
|
48
|
+
const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
|
49
|
+
entry,
|
50
|
+
fields: _index.baseFields,
|
51
|
+
context: getCmsContext(),
|
52
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
53
|
+
})));
|
54
|
+
return [all, meta];
|
55
|
+
},
|
56
|
+
|
57
|
+
async createChangeRequest(params) {
|
58
|
+
const model = await getChangeRequestModel();
|
59
|
+
const entry = await cms.createEntry(model, params.data);
|
60
|
+
return (0, _fieldResolver.getFieldValues)({
|
61
|
+
entry,
|
62
|
+
fields: _index.baseFields,
|
63
|
+
context: getCmsContext(),
|
64
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
65
|
+
});
|
66
|
+
},
|
67
|
+
|
68
|
+
async updateChangeRequest(params) {
|
69
|
+
const model = await getChangeRequestModel();
|
70
|
+
/**
|
71
|
+
* We're fetching the existing entry here because we're not accepting "app" field as input,
|
72
|
+
* but, we still need to retain its value after the "update" operation.
|
73
|
+
*/
|
74
|
+
|
75
|
+
const existingEntry = await getChangeRequest({
|
76
|
+
id: params.id
|
77
|
+
});
|
78
|
+
const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
|
79
|
+
return (0, _fieldResolver.getFieldValues)({
|
80
|
+
entry,
|
81
|
+
fields: _index.baseFields,
|
82
|
+
context: getCmsContext(),
|
83
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
84
|
+
});
|
85
|
+
},
|
86
|
+
|
87
|
+
async deleteChangeRequest(params) {
|
88
|
+
const model = await getChangeRequestModel();
|
89
|
+
await cms.deleteEntry(model, params.id);
|
90
|
+
return true;
|
91
|
+
}
|
92
|
+
|
93
|
+
};
|
94
|
+
};
|
95
|
+
|
96
|
+
exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createCommentStorageOperations = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _index = require("./index");
|
13
|
+
|
14
|
+
var _fieldResolver = require("../utils/fieldResolver");
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
19
|
+
|
20
|
+
const createCommentStorageOperations = ({
|
21
|
+
cms,
|
22
|
+
getCmsContext
|
23
|
+
}) => {
|
24
|
+
const getCommentModel = () => {
|
25
|
+
return cms.getModel("apwCommentModelDefinition");
|
26
|
+
};
|
27
|
+
|
28
|
+
const getComment = async ({
|
29
|
+
id
|
30
|
+
}) => {
|
31
|
+
const model = await getCommentModel();
|
32
|
+
const entry = await cms.getEntryById(model, id);
|
33
|
+
return (0, _fieldResolver.getFieldValues)({
|
34
|
+
entry,
|
35
|
+
fields: _index.baseFields,
|
36
|
+
context: getCmsContext(),
|
37
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
return {
|
42
|
+
getCommentModel,
|
43
|
+
getComment,
|
44
|
+
|
45
|
+
async listComments(params) {
|
46
|
+
const model = await getCommentModel();
|
47
|
+
const [entries, meta] = await cms.listLatestEntries(model, params);
|
48
|
+
const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
|
49
|
+
entry,
|
50
|
+
fields: _index.baseFields,
|
51
|
+
context: getCmsContext(),
|
52
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
53
|
+
})));
|
54
|
+
return [all, meta];
|
55
|
+
},
|
56
|
+
|
57
|
+
async createComment(params) {
|
58
|
+
const model = await getCommentModel();
|
59
|
+
const refModel = await this.getChangeRequestModel();
|
60
|
+
const entry = await cms.createEntry(model, _objectSpread(_objectSpread({}, params.data), {}, {
|
61
|
+
changeRequest: _objectSpread(_objectSpread({}, params.data.changeRequest), {}, {
|
62
|
+
modelId: refModel.modelId
|
63
|
+
})
|
64
|
+
}));
|
65
|
+
return (0, _fieldResolver.getFieldValues)({
|
66
|
+
entry,
|
67
|
+
fields: _index.baseFields,
|
68
|
+
context: getCmsContext(),
|
69
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
70
|
+
});
|
71
|
+
},
|
72
|
+
|
73
|
+
async updateComment(params) {
|
74
|
+
const model = await getCommentModel();
|
75
|
+
/**
|
76
|
+
* We're fetching the existing entry here because we're not accepting "app" field as input,
|
77
|
+
* but, we still need to retain its value after the "update" operation.
|
78
|
+
*/
|
79
|
+
|
80
|
+
const existingEntry = await getComment({
|
81
|
+
id: params.id
|
82
|
+
});
|
83
|
+
const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
|
84
|
+
return (0, _fieldResolver.getFieldValues)({
|
85
|
+
entry,
|
86
|
+
fields: _index.baseFields,
|
87
|
+
context: getCmsContext(),
|
88
|
+
transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
|
89
|
+
});
|
90
|
+
},
|
91
|
+
|
92
|
+
async deleteComment(params) {
|
93
|
+
const model = await getCommentModel();
|
94
|
+
await cms.deleteEntry(model, params.id);
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
|
98
|
+
};
|
99
|
+
};
|
100
|
+
|
101
|
+
exports.createCommentStorageOperations = createCommentStorageOperations;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { ApwContentReviewStorageOperations } from "./types";
|
2
|
+
import { CreateApwStorageOperationsParams } from "./index";
|
3
|
+
export declare const createContentReviewStorageOperations: ({ cms }: Pick<CreateApwStorageOperationsParams, "cms">) => ApwContentReviewStorageOperations;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createContentReviewStorageOperations = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _index = require("./index");
|
13
|
+
|
14
|
+
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; }
|
15
|
+
|
16
|
+
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; }
|
17
|
+
|
18
|
+
const createContentReviewStorageOperations = ({
|
19
|
+
cms
|
20
|
+
}) => {
|
21
|
+
const getContentReviewModel = () => {
|
22
|
+
return cms.getModel("apwContentReviewModelDefinition");
|
23
|
+
};
|
24
|
+
|
25
|
+
const getContentReview = async ({
|
26
|
+
id
|
27
|
+
}) => {
|
28
|
+
const model = await getContentReviewModel();
|
29
|
+
const entry = await cms.getEntryById(model, id);
|
30
|
+
return (0, _index.getFieldValues)(entry, _index.baseFields);
|
31
|
+
};
|
32
|
+
|
33
|
+
return {
|
34
|
+
getContentReviewModel,
|
35
|
+
getContentReview,
|
36
|
+
|
37
|
+
async listContentReviews(params) {
|
38
|
+
const model = await getContentReviewModel();
|
39
|
+
const [entries, meta] = await cms.listLatestEntries(model, params);
|
40
|
+
return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
|
41
|
+
},
|
42
|
+
|
43
|
+
async createContentReview(params) {
|
44
|
+
const model = await getContentReviewModel();
|
45
|
+
const entry = await cms.createEntry(model, params.data);
|
46
|
+
return (0, _index.getFieldValues)(entry, _index.baseFields);
|
47
|
+
},
|
48
|
+
|
49
|
+
async updateContentReview(params) {
|
50
|
+
const model = await getContentReviewModel();
|
51
|
+
/**
|
52
|
+
* We're fetching the existing entry here because we're not accepting "app" field as input,
|
53
|
+
* but, we still need to retain its value after the "update" operation.
|
54
|
+
*/
|
55
|
+
|
56
|
+
const existingEntry = await getContentReview({
|
57
|
+
id: params.id
|
58
|
+
});
|
59
|
+
const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
|
60
|
+
return (0, _index.getFieldValues)(entry, _index.baseFields);
|
61
|
+
},
|
62
|
+
|
63
|
+
async deleteContentReview(params) {
|
64
|
+
const model = await getContentReviewModel();
|
65
|
+
await cms.deleteEntry(model, params.id);
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
|
69
|
+
};
|
70
|
+
};
|
71
|
+
|
72
|
+
exports.createContentReviewStorageOperations = createContentReviewStorageOperations;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { CmsContext, HeadlessCms } from "@webiny/api-headless-cms/types";
|
2
|
+
import { ApwStorageOperations } from "../types";
|
3
|
+
export interface CreateApwStorageOperationsParams {
|
4
|
+
cms: HeadlessCms;
|
5
|
+
getCmsContext: () => CmsContext;
|
6
|
+
}
|
7
|
+
export declare function getFieldValues(object: any, fields: any): any;
|
8
|
+
export declare const baseFields: string[];
|
9
|
+
export declare const createStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwStorageOperations;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createStorageOperations = exports.baseFields = void 0;
|
9
|
+
exports.getFieldValues = getFieldValues;
|
10
|
+
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
12
|
+
|
13
|
+
var _pick = _interopRequireDefault(require("lodash/pick"));
|
14
|
+
|
15
|
+
var _reviewerStorageOperations = require("./reviewerStorageOperations");
|
16
|
+
|
17
|
+
var _workflowStorageOperations = require("./workflowStorageOperations");
|
18
|
+
|
19
|
+
var _contentReviewStorageOperations = require("./contentReviewStorageOperations");
|
20
|
+
|
21
|
+
var _changeRequestStorageOperations = require("./changeRequestStorageOperations");
|
22
|
+
|
23
|
+
var _commentStorageOperations = require("./commentStorageOperations");
|
24
|
+
|
25
|
+
var _models = require("./models");
|
26
|
+
|
27
|
+
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; }
|
28
|
+
|
29
|
+
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; }
|
30
|
+
|
31
|
+
function getFieldValues(object, fields) {
|
32
|
+
return _objectSpread(_objectSpread({}, (0, _pick.default)(object, fields)), object.values);
|
33
|
+
}
|
34
|
+
|
35
|
+
const baseFields = ["id", "createdBy", "createdOn", "savedOn"];
|
36
|
+
exports.baseFields = baseFields;
|
37
|
+
|
38
|
+
const createStorageOperations = ({
|
39
|
+
cms,
|
40
|
+
getCmsContext
|
41
|
+
}) => {
|
42
|
+
const context = getCmsContext();
|
43
|
+
/**
|
44
|
+
* Register Apw models.
|
45
|
+
*/
|
46
|
+
|
47
|
+
(0, _models.createApwModels)(context);
|
48
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, (0, _reviewerStorageOperations.createReviewerStorageOperations)({
|
49
|
+
cms
|
50
|
+
})), (0, _workflowStorageOperations.createWorkflowStorageOperations)({
|
51
|
+
cms
|
52
|
+
})), (0, _contentReviewStorageOperations.createContentReviewStorageOperations)({
|
53
|
+
cms
|
54
|
+
})), (0, _changeRequestStorageOperations.createChangeRequestStorageOperations)({
|
55
|
+
cms,
|
56
|
+
getCmsContext
|
57
|
+
})), (0, _commentStorageOperations.createCommentStorageOperations)({
|
58
|
+
cms,
|
59
|
+
getCmsContext
|
60
|
+
}));
|
61
|
+
};
|
62
|
+
|
63
|
+
exports.createStorageOperations = createStorageOperations;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createChangeRequestModelDefinition = void 0;
|
7
|
+
|
8
|
+
var _utils = require("./utils");
|
9
|
+
|
10
|
+
const bodyField = () => (0, _utils.createModelField)({
|
11
|
+
label: "Body",
|
12
|
+
type: "rich-text",
|
13
|
+
parent: "changeRequest"
|
14
|
+
});
|
15
|
+
|
16
|
+
const titleField = () => (0, _utils.createModelField)({
|
17
|
+
label: "Title",
|
18
|
+
type: "text",
|
19
|
+
parent: "changeRequest"
|
20
|
+
});
|
21
|
+
|
22
|
+
const resolvedField = () => (0, _utils.createModelField)({
|
23
|
+
label: "Resolved",
|
24
|
+
type: "boolean",
|
25
|
+
parent: "changeRequest"
|
26
|
+
});
|
27
|
+
|
28
|
+
const mediaField = () => (0, _utils.createModelField)({
|
29
|
+
label: "Media",
|
30
|
+
type: "file",
|
31
|
+
parent: "changeRequest"
|
32
|
+
});
|
33
|
+
|
34
|
+
const stepField = () => (0, _utils.createModelField)({
|
35
|
+
label: "Step",
|
36
|
+
type: "text",
|
37
|
+
parent: "changeRequest",
|
38
|
+
validation: [{
|
39
|
+
name: "required",
|
40
|
+
message: "Value is required"
|
41
|
+
}]
|
42
|
+
});
|
43
|
+
|
44
|
+
const createChangeRequestModelDefinition = () => ({
|
45
|
+
name: "APW - Change Request",
|
46
|
+
modelId: "apwChangeRequestModelDefinition",
|
47
|
+
titleFieldId: "changeRequest_title",
|
48
|
+
layout: [["changeRequest_body"], ["changeRequest_title"]],
|
49
|
+
fields: [bodyField(), titleField(), resolvedField(), mediaField(), stepField()]
|
50
|
+
});
|
51
|
+
|
52
|
+
exports.createChangeRequestModelDefinition = createChangeRequestModelDefinition;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createCommentModelDefinition = void 0;
|
7
|
+
|
8
|
+
var _utils = require("./utils");
|
9
|
+
|
10
|
+
const commentBody = () => (0, _utils.createModelField)({
|
11
|
+
label: "Body",
|
12
|
+
type: "rich-text",
|
13
|
+
parent: "comment"
|
14
|
+
});
|
15
|
+
|
16
|
+
const changeRequestRef = modelId => (0, _utils.createModelField)({
|
17
|
+
label: "Change Request",
|
18
|
+
type: "ref",
|
19
|
+
parent: "comment",
|
20
|
+
settings: {
|
21
|
+
models: [{
|
22
|
+
modelId
|
23
|
+
}]
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
27
|
+
const createCommentModelDefinition = ({
|
28
|
+
modelId
|
29
|
+
}) => ({
|
30
|
+
name: "APW - Comment",
|
31
|
+
modelId: "apwCommentModelDefinition",
|
32
|
+
titleFieldId: "displayName",
|
33
|
+
layout: [["comment_body"], ["comment_displayName"]],
|
34
|
+
fields: [commentBody(), changeRequestRef(modelId)]
|
35
|
+
});
|
36
|
+
|
37
|
+
exports.createCommentModelDefinition = createCommentModelDefinition;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { CmsGroup } from "@webiny/api-headless-cms/content/plugins/CmsGroupPlugin";
|
2
|
+
import { CmsModelPlugin } from "@webiny/api-headless-cms/content/plugins/CmsModelPlugin";
|
3
|
+
import { CmsModel } from "@webiny/api-headless-cms/types";
|
4
|
+
declare type ModelDefinition = Omit<CmsModel, "locale" | "tenant" | "webinyVersion" | "group">;
|
5
|
+
interface Params {
|
6
|
+
group: CmsGroup;
|
7
|
+
/**
|
8
|
+
* Locale and tenant do not need to be defined.
|
9
|
+
* In that case model is not bound to any locale or tenant.
|
10
|
+
* You can bind it to locale, tenant, both or none.
|
11
|
+
*/
|
12
|
+
locale?: string;
|
13
|
+
tenant?: string;
|
14
|
+
modelDefinition: ModelDefinition;
|
15
|
+
}
|
16
|
+
declare const contentModelPluginFactory: (params: Params) => CmsModelPlugin;
|
17
|
+
export default contentModelPluginFactory;
|