Skip to content

Commit 4dddcea

Browse files
authored
refactor: remove commodo (#4436)
1 parent 76ed2a8 commit 4dddcea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+730
-659
lines changed

packages/api-admin-users/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
],
1313
"license": "MIT",
1414
"dependencies": {
15-
"@commodo/fields": "1.1.2-beta.20",
1615
"@webiny/api": "0.0.0",
1716
"@webiny/api-security": "0.0.0",
1817
"@webiny/api-tenancy": "0.0.0",
1918
"@webiny/error": "0.0.0",
2019
"@webiny/handler-graphql": "0.0.0",
2120
"@webiny/pubsub": "0.0.0",
2221
"@webiny/utils": "0.0.0",
23-
"@webiny/validation": "0.0.0",
24-
"commodo-fields-object": "^1.0.6",
2522
"dataloader": "^2.2.2",
2623
"lodash": "^4.17.21",
27-
"md5": "^2.3.0"
24+
"md5": "^2.3.0",
25+
"zod": "^3.23.8"
2826
},
2927
"devDependencies": {
3028
"@types/jsonwebtoken": "^9.0.2",
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
1-
// @ts-expect-error Package @commodo/fields does not have types.
2-
import { string, withFields } from "@commodo/fields";
3-
// @ts-expect-error Package commodo-fields-object does not have types.
4-
import { object } from "commodo-fields-object";
5-
import { validation } from "@webiny/validation";
1+
import zod from "zod";
62
import { AdminUsers } from "~/types";
3+
import { createZodError } from "@webiny/utils";
74

8-
const CreateUserDataModel = withFields({
9-
id: string({ validation: validation.create("minLength:1") }),
10-
displayName: string({ validation: validation.create("minLength:1") }),
11-
5+
const createUserDataValidation = zod.object({
6+
id: zod.string().min(1).optional(),
7+
displayName: zod.string().min(1).optional(),
128
// We did not use an e-mail validator here, just because external
139
// IdPs (Okta, Auth0) do not require e-mail to be present. When creating
1410
// admin users, they're actually passing the user's ID as the e-mail.
1511
// For example: packages/api-security-okta/src/createAdminUsersHooks.ts:13
1612
// In the future, we might want to rename this field to `idpId` or similar.
17-
email: string({ validation: validation.create("required") }),
18-
19-
firstName: string({ validation: validation.create("minLength:1") }),
20-
lastName: string({ validation: validation.create("minLength:1") }),
21-
avatar: object()
22-
})();
13+
email: zod.string(),
14+
firstName: zod.string().min(1).optional(),
15+
lastName: zod.string().min(1).optional(),
16+
avatar: zod.object({}).passthrough()
17+
});
2318

24-
const UpdateUserDataModel = withFields({
25-
displayName: string({ validation: validation.create("minLength:1") }),
26-
avatar: object(),
27-
firstName: string({ validation: validation.create("minLength:1") }),
28-
lastName: string({ validation: validation.create("minLength:1") }),
29-
group: string(),
30-
team: string()
31-
})();
19+
const updateUserDataValidation = zod.object({
20+
displayName: zod.string().min(1).optional(),
21+
avatar: zod.object({}).passthrough().optional(),
22+
firstName: zod.string().min(1).optional(),
23+
lastName: zod.string().min(1).optional(),
24+
group: zod.string().optional(),
25+
team: zod.string().optional()
26+
});
3227

3328
export const attachUserValidation = (
3429
params: Pick<AdminUsers, "onUserBeforeCreate" | "onUserBeforeUpdate">
3530
) => {
3631
const { onUserBeforeCreate, onUserBeforeUpdate } = params;
3732
onUserBeforeCreate.subscribe(async ({ inputData }) => {
38-
const model = await new CreateUserDataModel().populate(inputData);
39-
await model.validate();
33+
const validation = createUserDataValidation.safeParse(inputData);
34+
if (validation.success) {
35+
return;
36+
}
37+
throw createZodError(validation.error);
4038
});
4139

4240
onUserBeforeUpdate.subscribe(async ({ inputData }) => {
43-
const model = await new UpdateUserDataModel().populate(inputData);
44-
await model.validate();
41+
const validation = updateUserDataValidation.safeParse(inputData);
42+
if (validation.success) {
43+
return;
44+
}
45+
throw createZodError(validation.error);
4546
});
4647
};

packages/api-admin-users/tsconfig.build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
{ "path": "../handler-graphql/tsconfig.build.json" },
1010
{ "path": "../pubsub/tsconfig.build.json" },
1111
{ "path": "../utils/tsconfig.build.json" },
12-
{ "path": "../validation/tsconfig.build.json" },
1312
{ "path": "../api-i18n/tsconfig.build.json" },
1413
{ "path": "../api-wcp/tsconfig.build.json" }
1514
],

packages/api-admin-users/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
{ "path": "../handler-graphql" },
1010
{ "path": "../pubsub" },
1111
{ "path": "../utils" },
12-
{ "path": "../validation" },
1312
{ "path": "../api-i18n" },
1413
{ "path": "../api-wcp" }
1514
],
@@ -34,8 +33,6 @@
3433
"@webiny/pubsub": ["../pubsub/src"],
3534
"@webiny/utils/*": ["../utils/src/*"],
3635
"@webiny/utils": ["../utils/src"],
37-
"@webiny/validation/*": ["../validation/src/*"],
38-
"@webiny/validation": ["../validation/src"],
3936
"@webiny/api-i18n/*": ["../api-i18n/src/*"],
4037
"@webiny/api-i18n": ["../api-i18n/src"],
4138
"@webiny/api-wcp/*": ["../api-wcp/src/*"],

packages/api-apw/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"author": "Webiny Ltd",
1515
"license": "MIT",
1616
"dependencies": {
17-
"@commodo/fields": "1.1.2-beta.20",
1817
"@webiny/api": "0.0.0",
1918
"@webiny/api-admin-settings": "0.0.0",
2019
"@webiny/api-headless-cms": "0.0.0",
@@ -35,9 +34,9 @@
3534
"@webiny/plugins": "0.0.0",
3635
"@webiny/pubsub": "0.0.0",
3736
"@webiny/utils": "0.0.0",
38-
"@webiny/validation": "0.0.0",
3937
"dayjs": "^1.11.13",
40-
"lodash": "^4.17.21"
38+
"lodash": "^4.17.21",
39+
"zod": "^3.23.8"
4140
},
4241
"devDependencies": {
4342
"@webiny/cli": "0.0.0",

packages/api-apw/src/crud/createContentReviewMethods.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import get from "lodash/get";
21
import { createTopic } from "@webiny/pubsub";
32
import Error from "@webiny/error";
43
import {
@@ -524,7 +523,7 @@ export function createContentReviewMethods(
524523
},
525524
async deleteScheduledAction(id) {
526525
const contentReview = await this.get(id);
527-
const scheduledActionId = get(contentReview, "content.scheduledActionId");
526+
const scheduledActionId = contentReview.content?.scheduledActionId;
528527

529528
/**
530529
* Check if there is any action scheduled for this "content review".

packages/api-apw/src/plugins/cms/linkWorkflowToEntry.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import {
99
} from "~/plugins/cms/utils";
1010
import { HeadlessCms } from "@webiny/api-headless-cms/types";
1111

12-
interface Value {
13-
id: string;
14-
modelId: string;
15-
}
16-
1712
interface LinkWorkflowToEntryParams {
1813
apw: AdvancedPublishingWorkflow;
1914
cms: HeadlessCms;
@@ -107,8 +102,8 @@ export const linkWorkflowToEntry = (params: LinkWorkflowToEntryParams) => {
107102

108103
const models = await cms.listModels();
109104

110-
const values: Value[] | undefined = scope.data?.entries;
111-
if (!values || Array.isArray(values) === false || values.length === 0) {
105+
const values = scope.data?.entries;
106+
if (!values?.length) {
112107
return;
113108
}
114109

packages/api-apw/src/plugins/pageBuilder/linkWorkflowToPage.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import get from "lodash/get";
21
import set from "lodash/set";
32
import {
4-
ApwWorkflowApplications,
5-
ApwOnPageBeforeCreateTopicParams,
3+
AdvancedPublishingWorkflow,
64
ApwOnPageBeforeCreateFromTopicParams,
5+
ApwOnPageBeforeCreateTopicParams,
76
ApwOnPageBeforeUpdateTopicParams,
8-
AdvancedPublishingWorkflow
7+
ApwWorkflowApplications
98
} from "~/types";
109
import {
10+
assignWorkflowToPage,
1111
getPagesDiff,
1212
hasPages,
13-
updatePageSettings,
1413
shouldUpdatePages,
15-
assignWorkflowToPage
14+
updatePageSettings
1615
} from "./utils";
1716
import { PageBuilderContextObject } from "@webiny/api-page-builder/graphql/types";
1817

@@ -34,7 +33,7 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
3433
* If the previous revision(original) already had the "contentReviewId",
3534
* we need to unlink it so that new "contentReview" can be request for the new revision.
3635
*/
37-
const previousContentReviewId = get(original, "settings.apw.contentReviewId");
36+
const previousContentReviewId = original.settings.apw?.contentReviewId;
3837
if (previousContentReviewId) {
3938
page.settings.apw.contentReviewId = null;
4039
}
@@ -43,7 +42,7 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
4342
* If the previous revision(original) already had the "workflowId",
4443
* we don't need to do anything we'll just let it be copied over.
4544
*/
46-
const previousWorkflowId = get(original, "settings.apw.workflowId");
45+
const previousWorkflowId = original.settings.apw?.workflowId;
4746
if (previousWorkflowId) {
4847
return;
4948
}
@@ -55,8 +54,8 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
5554
);
5655
pageBuilder.onPageBeforeUpdate.subscribe<ApwOnPageBeforeUpdateTopicParams>(async params => {
5756
const { page, original } = params;
58-
const prevApwWorkflowId = get(original, "settings.apw");
59-
const currentApwWorkflowId = get(page, "settings.apw");
57+
const prevApwWorkflowId = original.settings?.apw;
58+
const currentApwWorkflowId = page.settings?.apw;
6059
/**
6160
* Make sure the apw property doesn't get lost between updates.
6261
* It can happen because we run modal validation in "onBeforePageUpdate" event,
@@ -69,9 +68,9 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
6968
* If there is a linked "contentReview" for this page and the page "title" has changed.
7069
* Let's update the "title" field in "contentReview".
7170
*/
72-
const linkedContentReviewId = get(page, "settings.apw.contentReviewId");
73-
const prevTitle = get(original, "title");
74-
const newTitle = get(page, "title");
71+
const linkedContentReviewId = page.settings.apw?.contentReviewId;
72+
const prevTitle = original.title;
73+
const newTitle = page.title;
7574

7675
if (linkedContentReviewId && prevTitle !== newTitle) {
7776
await apw.contentReview.update(linkedContentReviewId, { title: newTitle });
@@ -91,7 +90,7 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
9190
if (hasPages(workflow) === false) {
9291
return;
9392
}
94-
const pages = get(scope, "data.pages") as unknown as string[];
93+
const pages = scope.data?.pages || [];
9594

9695
for (const pid of pages) {
9796
await updatePageSettings({
@@ -121,8 +120,8 @@ export const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {
121120
return;
122121
}
123122

124-
const previousPages = get(prevScope, "data.pages", []);
125-
const currentPages = get(scope, "data.pages", []);
123+
const previousPages = prevScope.data?.pages || [];
124+
const currentPages = scope.data?.pages || [];
126125

127126
const { removedPages, addedPages } = getPagesDiff(currentPages, previousPages);
128127
for (const pid of addedPages) {

packages/api-apw/src/plugins/pageBuilder/triggerContentReview.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import get from "lodash/get";
21
import Error from "@webiny/error";
32
import {
43
AdvancedPublishingWorkflow,
@@ -17,7 +16,7 @@ export const triggerContentReview = (params: TriggerContentReviewParams) => {
1716

1817
pageBuilder.onPageBeforePublish.subscribe<ApwOnPageBeforePublishTopicParams>(
1918
async ({ page }) => {
20-
const contentReviewId = get(page, "settings.apw.contentReviewId");
19+
const contentReviewId = page.settings.apw?.contentReviewId;
2120
if (contentReviewId) {
2221
const contentReview = await apw.contentReview.get(contentReviewId);
2322

@@ -34,7 +33,7 @@ export const triggerContentReview = (params: TriggerContentReviewParams) => {
3433
return;
3534
}
3635

37-
const workflowId = get(page, "settings.apw.workflowId");
36+
const workflowId = page.settings.apw?.workflowId;
3837

3938
if (workflowId) {
4039
throw new Error(

packages/api-apw/src/plugins/pageBuilder/updateContentReviewStatus.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import get from "lodash/get";
21
import {
32
AdvancedPublishingWorkflow,
43
ApwContentReviewStatus,
@@ -19,7 +18,7 @@ export const updateContentReviewStatus = (params: UpdateContentReviewStatusParam
1918

2019
pageBuilder.onPageAfterPublish.subscribe<ApwOnPageBeforePublishTopicParams>(
2120
async ({ page }) => {
22-
const contentReviewId = get(page, "settings.apw.contentReviewId");
21+
const contentReviewId = page.settings.apw?.contentReviewId;
2322
/**
2423
* Bail out if there is no "content review" linked.
2524
*/
@@ -46,7 +45,7 @@ export const updateContentReviewStatus = (params: UpdateContentReviewStatusParam
4645
);
4746
pageBuilder.onPageAfterUnpublish.subscribe<ApwOnPageBeforePublishTopicParams>(
4847
async ({ page }) => {
49-
const contentReviewId = get(page, "settings.apw.contentReviewId");
48+
const contentReviewId = page.settings.apw?.contentReviewId;
5049
/**
5150
* Bail out if there is no "content review" linked.
5251
*/

packages/api-apw/src/plugins/pageBuilder/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import get from "lodash/get";
21
import WebinyError from "@webiny/error";
32
import {
43
ApwWorkflow,
@@ -22,13 +21,13 @@ const isWorkflowApplicable = (page: PageWithWorkflow, workflow: ApwWorkflow) =>
2221
if (scopeType === WorkflowScopeTypes.DEFAULT) {
2322
return true;
2423
} else if (scopeType === WorkflowScopeTypes.CUSTOM) {
25-
const categories = get(workflow, "scope.data.categories");
24+
const categories = workflow.scope.data?.categories;
2625

2726
if (Array.isArray(categories) && categories.includes(page.category)) {
2827
return true;
2928
}
3029

31-
const pages = get(workflow, "scope.data.pages");
30+
const pages = workflow.scope.data?.pages;
3231
if (Array.isArray(pages) && pages.includes(page.pid)) {
3332
return true;
3433
}
@@ -105,8 +104,8 @@ export const shouldUpdatePages = (
105104
if (prevScope.type !== WorkflowScopeTypes.CUSTOM) {
106105
return true;
107106
}
108-
const prevScopePages: string[] = get(prevScope, "data.pages") as unknown as string[];
109-
const currentScopePages: string[] = get(scope, "data.pages") as unknown as string[];
107+
const prevScopePages = prevScope.data.pages || [];
108+
const currentScopePages = scope.data.pages || [];
110109
/**
111110
* Bail out early if there were no pages assigned previously.
112111
*/

packages/api-apw/src/plugins/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import get from "lodash/get";
21
import { CmsModelField } from "@webiny/api-headless-cms/types";
32
import { SecurityIdentity } from "@webiny/api-security/types";
43
import {
@@ -41,7 +40,10 @@ export const hasReviewer = async (params: HasReviewersParams): Promise<boolean>
4140
};
4241

4342
export const getValue = (object: Record<string, any>, key: string) => {
44-
return get(object, `values.${key}`);
43+
if (!object.values) {
44+
return undefined;
45+
}
46+
return object.values[key];
4547
};
4648

4749
export const getContentReviewStepInitialStatus = (
@@ -189,8 +191,8 @@ export const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {
189191
};
190192

191193
export const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {
192-
const createdOnA = get(a, "createdOn");
193-
const createdOnB = get(b, "createdOn");
194+
const createdOnA = a.createdOn;
195+
const createdOnB = b.createdOn;
194196
/**
195197
* In descending order of workflow createdOn i.e. the most recent one first.
196198
*/

0 commit comments

Comments
 (0)