@webbio/strapi-plugin-page-builder 0.0.30 → 0.1.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.
Files changed (59) hide show
  1. package/README.md +95 -0
  2. package/admin/src/api/template.ts +4 -2
  3. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +6 -0
  4. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +5 -3
  5. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +14 -3
  6. package/admin/src/components/EditView/PageSettings/index.tsx +13 -6
  7. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +7 -2
  8. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +11 -3
  9. package/admin/src/components/EditView/index.tsx +3 -1
  10. package/admin/src/components/EditView/page-type-select.tsx +3 -1
  11. package/admin/src/constants.ts +2 -0
  12. package/admin/src/index.tsx +1 -1
  13. package/dist/package.json +10 -10
  14. package/dist/server/bootstrap.js +86 -17
  15. package/dist/server/controllers/collection-types.js +0 -2
  16. package/dist/server/controllers/index.js +3 -1
  17. package/dist/server/controllers/page-type.js +0 -1
  18. package/dist/server/controllers/page.js +0 -8
  19. package/dist/server/controllers/platform.js +20 -0
  20. package/dist/server/controllers/template.js +15 -0
  21. package/dist/server/graphql/index.js +2 -0
  22. package/dist/server/graphql/page-by-slug.js +4 -4
  23. package/dist/server/graphql/page-type.js +4 -1
  24. package/dist/server/graphql/pages-by-uid.js +105 -0
  25. package/dist/server/register.js +2 -0
  26. package/dist/server/routes/index.js +16 -0
  27. package/dist/server/schema/platform-start.json +31 -0
  28. package/dist/server/services/builder.js +6 -3
  29. package/dist/server/services/index.js +3 -1
  30. package/dist/server/services/page-type.js +7 -4
  31. package/dist/server/services/platform.js +36 -0
  32. package/dist/server/services/template.js +14 -0
  33. package/dist/server/utils/graphql.js +4 -1
  34. package/dist/server/utils/paginationValidation.js +31 -0
  35. package/dist/server/utils/strapi.js +42 -0
  36. package/dist/tsconfig.server.tsbuildinfo +1 -1
  37. package/package.json +10 -10
  38. package/server/bootstrap.ts +94 -17
  39. package/server/controllers/collection-types.ts +4 -4
  40. package/server/controllers/index.ts +3 -1
  41. package/server/controllers/page-type.ts +3 -2
  42. package/server/controllers/page.ts +0 -11
  43. package/server/controllers/template.ts +16 -0
  44. package/server/graphql/index.ts +2 -0
  45. package/server/graphql/page-by-slug.ts +1 -1
  46. package/server/graphql/page-type.ts +13 -4
  47. package/server/graphql/pages-by-uid.ts +127 -0
  48. package/server/register.ts +2 -0
  49. package/server/routes/index.ts +16 -0
  50. package/server/services/builder.ts +13 -12
  51. package/server/services/collection-types.ts +6 -6
  52. package/server/services/index.ts +3 -1
  53. package/server/services/page-type.ts +7 -3
  54. package/server/services/template.ts +14 -0
  55. package/server/utils/graphql.ts +4 -1
  56. package/server/utils/paginationValidation.ts +39 -0
  57. package/server/utils/strapi.ts +49 -0
  58. package/tsconfig.tsbuildinfo +1 -1
  59. package/.prettierignore +0 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.0.30",
3
+ "version": "0.1.0",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -20,17 +20,17 @@
20
20
  "url": "https://github.com/webbio/strapi-plugin-page-builder.git"
21
21
  },
22
22
  "dependencies": {
23
- "@strapi/design-system": "^1.8.2",
24
- "@strapi/helper-plugin": "^4.12.0",
25
- "@strapi/icons": "^1.8.2",
26
- "@strapi/typescript-utils": "^4.12.0",
27
- "@strapi/utils": "^4.12.0",
23
+ "@strapi/design-system": "^1.11.0",
24
+ "@strapi/helper-plugin": "^4.13.6",
25
+ "@strapi/icons": "^1.11.0",
26
+ "@strapi/typescript-utils": "^4.13.6",
27
+ "@strapi/utils": "^4.13.6",
28
28
  "react-select": "^5.7.4"
29
29
  },
30
30
  "devDependencies": {
31
- "@strapi/typescript-utils": "^4.12.0",
32
- "@types/react": "^17.0.53",
33
- "@types/react-dom": "^18.0.28",
31
+ "@strapi/typescript-utils": "^4.13.6",
32
+ "@types/react": "^18.2.21",
33
+ "@types/react-dom": "^18.2.7",
34
34
  "@types/react-router-dom": "^5.3.3",
35
35
  "@types/styled-components": "^5.1.26",
36
36
  "react": "^18.2.0",
@@ -40,7 +40,7 @@
40
40
  "typescript": "5.1.6"
41
41
  },
42
42
  "peerDependencies": {
43
- "@strapi/strapi": "^4.12.0",
43
+ "@strapi/strapi": "^4.13.6",
44
44
  "@webbio/strapi-plugin-slug": "^0.1.0",
45
45
  "react": "^17.0.0 || ^18.0.0",
46
46
  "react-dom": "^17.0.0 || ^18.0.0",
@@ -1,14 +1,14 @@
1
1
  import { Strapi } from '@strapi/strapi';
2
2
  import { errors } from '@strapi/utils';
3
-
4
- import { PAGE_UID } from '../shared/utils/constants';
3
+ import { PAGE_TYPE_UID, PAGE_UID } from '../shared/utils/constants';
5
4
 
6
5
  export default async ({ strapi }: { strapi: Strapi }) => {
7
6
  // TODO: refactor to own function
8
7
  try {
9
- const pageTypes = await strapi.entityService.findMany('api::page-type.page-type', {
8
+ const pageTypes = (await strapi.entityService?.findMany(PAGE_TYPE_UID, {
10
9
  limit: -1
11
- });
10
+ })) as Record<string, any>[];
11
+
12
12
  const pagePermissions = pageTypes.map((pageType) => {
13
13
  const name = `page-type-is-${pageType.uid}`;
14
14
  const displayName = pageType.title;
@@ -54,7 +54,7 @@ export default async ({ strapi }: { strapi: Strapi }) => {
54
54
  return data;
55
55
  };
56
56
 
57
- strapi.db.lifecycles.subscribe({
57
+ strapi.db?.lifecycles.subscribe({
58
58
  // @ts-ignore
59
59
  models: [PAGE_UID],
60
60
  async beforeCreate(event) {
@@ -63,20 +63,26 @@ export default async ({ strapi }: { strapi: Strapi }) => {
63
63
  const pageTypeId = data?.pageType.connect?.[0]?.id || data.initialPageType;
64
64
 
65
65
  if (collectionTypeId && pageTypeId) {
66
- const { uid } = await strapi.entityService.findOne('api::page-type.page-type', pageTypeId);
67
- const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
66
+ const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
67
+ PAGE_TYPE_UID,
68
+ pageTypeId
69
+ );
70
+ const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
68
71
  populate: { page: true }
69
72
  });
70
73
 
71
- if (collectionToConnect.page && collectionToConnect.page.length > 0) {
74
+ const page: Record<string, any>[] = collectionToConnect?.page as any;
75
+
76
+ if (page && page.length > 0) {
72
77
  throw new errors.ValidationError('You can only link one CollectionType to one page');
73
78
  }
74
79
 
75
- data = updateCollectionTypeData(data, collectionTypeId, uid);
80
+ data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
76
81
  }
77
82
  },
78
83
  async beforeUpdate(event) {
79
84
  let data = event?.params?.data;
85
+
80
86
  const collectionTypeId = data?.collectionTypeId;
81
87
  const pageTypeId = data?.pageType?.connect?.[0]?.id || data?.initialPageType;
82
88
  const removedPageType = data?.pageType?.disconnect?.[0]?.id;
@@ -86,20 +92,91 @@ export default async ({ strapi }: { strapi: Strapi }) => {
86
92
  }
87
93
 
88
94
  if (collectionTypeId && pageTypeId && !removedPageType) {
89
- const { uid } = await strapi.entityService.findOne('api::page-type.page-type', pageTypeId);
90
- const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
95
+ const pageType: Record<string, any> | undefined | null = await strapi.entityService?.findOne(
96
+ PAGE_TYPE_UID,
97
+ pageTypeId
98
+ );
99
+ const collectionToConnect = await strapi.entityService?.findOne(pageType?.uid, collectionTypeId, {
91
100
  populate: { page: true }
92
101
  });
93
102
 
94
- if (
95
- collectionToConnect.page &&
96
- collectionToConnect.page.length > 0 &&
97
- !collectionToConnect?.page.some((p) => p.id === data.id)
98
- ) {
103
+ const page: Record<string, any>[] = collectionToConnect?.page as any;
104
+
105
+ if (page && page?.length > 0 && !page.some((p) => p.id === data.id)) {
99
106
  throw new errors.ValidationError('You can only link one CollectionType to one page');
100
107
  }
101
108
 
102
- data = updateCollectionTypeData(data, collectionTypeId, uid);
109
+ data = updateCollectionTypeData(data, collectionTypeId, pageType?.uid);
110
+ }
111
+
112
+ // needs to check if the collectionTypeData is already connected to another page
113
+ // if so, remove the hasPage for filtering
114
+ // const foundPage = await strapi.entityService?.findOne(PAGE_UID, data.id, { populate: '*' });
115
+ // if (
116
+ // data.collectionTypeData &&
117
+ // foundPage &&
118
+ // foundPage.collectionTypeData &&
119
+ // +data.collectionTypeData.id !== foundPage.collectionTypeData[0].id
120
+ // ) {
121
+ // await strapi.entityService?.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
122
+ // data: {
123
+ // id: foundPage.collectionTypeData[0].id,
124
+ // hasPage: false
125
+ // }
126
+ // });
127
+ // }
128
+ },
129
+ async afterUpdate(event) {
130
+ const data = event?.params?.data;
131
+ console.log(data);
132
+ if (data.collectionTypeData) {
133
+ await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
134
+ data: {
135
+ id: data.collectionTypeData.id,
136
+ hasPage: true
137
+ }
138
+ });
139
+ }
140
+ },
141
+ async afterCreate(event) {
142
+ const data = event?.params?.data;
143
+ if (data.collectionTypeData) {
144
+ await strapi.entityService?.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
145
+ data: {
146
+ id: data.collectionTypeData.id,
147
+ hasPage: true
148
+ }
149
+ });
150
+ }
151
+ },
152
+ async beforeDelete(event) {
153
+ const foundPage = await strapi.entityService?.findOne(PAGE_UID, event.params.where.id, { populate: '*' });
154
+ if (foundPage && foundPage.collectionTypeData) {
155
+ await strapi.entityService?.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
156
+ data: {
157
+ id: foundPage.collectionTypeData[0].id,
158
+ hasPage: false
159
+ }
160
+ });
161
+ }
162
+ },
163
+ async beforeDeleteMany(event) {
164
+ const pagesToUnConnect = event.params.where['$and'][0].id['$in'];
165
+
166
+ for (const pageId of pagesToUnConnect) {
167
+ const foundPage = await strapi.entityService?.findOne(PAGE_UID, pageId, { populate: '*' });
168
+ if (foundPage && foundPage.collectionTypeData) {
169
+ await strapi.entityService?.update(
170
+ foundPage.collectionTypeData[0].__type,
171
+ foundPage.collectionTypeData[0].id,
172
+ {
173
+ data: {
174
+ id: foundPage.collectionTypeData[0].id,
175
+ hasPage: false
176
+ }
177
+ }
178
+ );
179
+ }
103
180
  }
104
181
  }
105
182
  });
@@ -1,9 +1,10 @@
1
+ import { Strapi } from '@strapi/strapi';
2
+
1
3
  export default {
2
4
  async hasPageRelation(ctx: any) {
3
5
  const uid = ctx.params?.uid;
4
6
 
5
- // @ts-ignore
6
- return strapi.service('plugin::page-builder.collection-types').hasPageRelation(uid);
7
+ return (strapi as Strapi).service('plugin::page-builder.collection-types').hasPageRelation(uid);
7
8
  },
8
9
  async getTranslationPageLinks(ctx: any): Promise<IGetTranslationPageLinks[] | undefined> {
9
10
  const { uid, ids } = ctx.params || {};
@@ -16,8 +17,7 @@ export default {
16
17
  return undefined;
17
18
  }
18
19
 
19
- // @ts-ignore
20
- return strapi.service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
20
+ return (strapi as Strapi).service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
21
21
  }
22
22
  };
23
23
 
@@ -1,9 +1,11 @@
1
1
  import page from './page';
2
2
  import pageType from './page-type';
3
3
  import collectionTypes from './collection-types';
4
+ import template from './template';
4
5
 
5
6
  export default {
6
7
  page,
7
8
  'page-type': pageType,
8
- 'collection-types': collectionTypes
9
+ 'collection-types': collectionTypes,
10
+ template
9
11
  };
@@ -1,3 +1,5 @@
1
+ import { Strapi } from '@strapi/strapi';
2
+
1
3
  export default {
2
4
  async findOneByUid(ctx: any) {
3
5
  const uid = ctx?.params?.uid;
@@ -6,7 +8,6 @@ export default {
6
8
  return ctx.badRequest('uid is missing.');
7
9
  }
8
10
 
9
- // @ts-ignore strapi typings
10
- return await strapi.service('plugin::page-builder.page-type').findOneByUid(uid);
11
+ return await (strapi as Strapi).service('plugin::page-builder.page-type').findOneByUid(uid);
11
12
  }
12
13
  };
@@ -1,20 +1,9 @@
1
1
  import { Strapi } from '@strapi/strapi';
2
2
 
3
- import { PAGE_UID } from '../../shared/utils/constants';
4
-
5
3
  export default {
6
4
  async getPage(ctx) {
7
5
  const id = ctx.params?.id;
8
6
 
9
7
  return (strapi as Strapi).service('plugin::page-builder.page')?.getPage(id);
10
- },
11
-
12
- async findOneBySlug(ctx) {
13
- const { slug = '' } = ctx.params;
14
-
15
- const entity = await (strapi as Strapi).service(PAGE_UID)?.find({ filters: { slug } });
16
- const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
17
-
18
- return this.transformResponse(sanitizedEntity);
19
8
  }
20
9
  };
@@ -0,0 +1,16 @@
1
+ import { Strapi } from '@strapi/strapi';
2
+
3
+ export default {
4
+ async findOneById(ctx: any) {
5
+ const id = ctx?.params?.id;
6
+
7
+ if (!id) {
8
+ return ctx.badRequest('id is missing.');
9
+ }
10
+
11
+ return await (strapi as Strapi).service('plugin::page-builder.template').findOne(id);
12
+ },
13
+ async findAll() {
14
+ return await (strapi as Strapi).service('plugin::page-builder.template').findAll();
15
+ }
16
+ };
@@ -1,7 +1,9 @@
1
1
  import pageType from './page-type';
2
2
  import pageBySlug from './page-by-slug';
3
+ import getPageInfoFromUID from './pages-by-uid';
3
4
 
4
5
  export default {
6
+ getPageInfoFromUID,
5
7
  pageType,
6
8
  pageBySlug
7
9
  };
@@ -36,7 +36,7 @@ const getPageBySlug = (strapi: Strapi) => {
36
36
  usePagination: false
37
37
  });
38
38
 
39
- const results = await strapi.entityService.findMany(PAGE_UID, {
39
+ const results = await strapi.entityService?.findMany(PAGE_UID, {
40
40
  filters: transformedArgs,
41
41
  locale: args._locale,
42
42
  publicationState: args._publicationState,
@@ -1,3 +1,4 @@
1
+ import { Common } from '@strapi/strapi';
1
2
  import { ICollectionTypeGL } from '../services/collection-types';
2
3
 
3
4
  const pageType = ({ nexus }) => {
@@ -15,11 +16,19 @@ const pageType = ({ nexus }) => {
15
16
  type: 'Page',
16
17
  resolve: async (root) => {
17
18
  try {
18
- const results = await strapi.entityService.findOne(collectionType.uid, root?.id, {
19
- populate: '*'
20
- });
19
+ const results = await strapi.entityService.findOne(
20
+ collectionType.uid as Common.UID.ContentType,
21
+ root?.id,
22
+ {
23
+ populate: '*'
24
+ }
25
+ );
21
26
 
22
- return results.page?.[0] || null;
27
+ if (!results) {
28
+ return null;
29
+ }
30
+
31
+ return results.page?.[0];
23
32
  } catch {
24
33
  return null;
25
34
  }
@@ -0,0 +1,127 @@
1
+ import { Strapi } from '@strapi/strapi';
2
+
3
+ import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
4
+ import { PAGE_UID } from '../../shared/utils/constants';
5
+ import { Pagination } from '../utils/paginationValidation';
6
+
7
+ const getPageInfoFromUID = (strapi: Strapi) => {
8
+ // @ts-ignore service does exist
9
+ const collectionTypes: ICollectionTypeGL[] = strapi.service('plugin::page-builder.collection-types').withPageMorph();
10
+
11
+ const typeDefs = () => {
12
+ const metaInfo = `type MetaInfo {
13
+ total: Int
14
+ page: Int
15
+ pageCount: Int
16
+ pageSize: Int
17
+ }`;
18
+ const entityInfo = collectionTypes.map((collectionType) => {
19
+ return `
20
+ extend type ${collectionType.type}EntityResponseCollection {
21
+ metaInfo: MetaInfo
22
+ }
23
+
24
+ type Query {
25
+ get${collectionType.type}Pages(filters: ${collectionType.type}FiltersInput,pagination: PaginationArg, sort:[String], pageFilters: PageFiltersInput): ${collectionType.type}EntityResponseCollection
26
+ }
27
+
28
+ `;
29
+ });
30
+
31
+ return `${metaInfo} ${entityInfo}`;
32
+ };
33
+ const resolvers = (strapi: Strapi) => {
34
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
35
+ const pageQuery = collectionTypes.map((collectionType) => {
36
+ return {
37
+ [`get${collectionType.type}Pages`]: {
38
+ resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
39
+ if (!args.pagination || !args.pagination.page || !args.pagination.pageSize) {
40
+ throw new Error('page and pageSize is required');
41
+ }
42
+
43
+ const { start, limit } = Pagination.checkPagination(args.pagination.page, args.pagination.pageSize);
44
+
45
+ const filteredArgs = {
46
+ ...filterUnderscoreArguments(args)
47
+ };
48
+ const pageFilters = { filters: args.pageFilters };
49
+
50
+ const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
51
+
52
+ const getPage = async () => {
53
+ const transformedArgs = transformArgs(filteredArgs, {
54
+ contentType: strapi.contentTypes[collectionType.uid],
55
+ usePagination: true
56
+ });
57
+
58
+ const transformedpageArgs = transformArgs(pageFilters, {
59
+ contentType: strapi.contentTypes[PAGE_UID],
60
+ usePagination: true
61
+ });
62
+
63
+ const results = await (strapi as Strapi)?.entityService?.findMany(collectionType.uid, {
64
+ populate: '*',
65
+ filters: {
66
+ ...transformedArgs.filters,
67
+ hasPage: { $eq: true },
68
+ page: { ...transformedpageArgs.filters }
69
+ },
70
+ sort: transformedArgs.sort,
71
+ start: start,
72
+ limit: limit
73
+ });
74
+
75
+ const entityResponse = toEntityResponseCollection(results || [], {
76
+ args: transformedArgs,
77
+ resourceUID: collectionType.uid
78
+ });
79
+
80
+ const entityResponsePaginated = Pagination.getPaginationInfo(
81
+ transformedpageArgs,
82
+ transformedArgs,
83
+ start,
84
+ args.pagination.pageSize,
85
+ entityResponse,
86
+ collectionType.uid
87
+ );
88
+
89
+ return entityResponsePaginated;
90
+ };
91
+
92
+ const results: Record<string, any> = await getPage();
93
+
94
+ if (Object.values(results)?.filter(Boolean).length > 0) {
95
+ return results;
96
+ } else {
97
+ throw new Error(ctx.koaContext.response.message);
98
+ }
99
+ }
100
+ }
101
+ };
102
+ });
103
+
104
+ return {
105
+ Query: Object.assign({}, ...pageQuery)
106
+ };
107
+ };
108
+
109
+ const resolversConfig = () => {
110
+ const configQuery = collectionTypes.map((collectionType) => {
111
+ return {
112
+ [`Query.get${collectionType.type}Pages`]: {
113
+ auth: false
114
+ }
115
+ };
116
+ });
117
+ return Object.assign({}, ...configQuery);
118
+ };
119
+
120
+ return {
121
+ typeDefs: typeDefs(),
122
+ resolvers: resolvers(strapi),
123
+ resolversConfig: resolversConfig()
124
+ };
125
+ };
126
+
127
+ export default getPageInfoFromUID;
@@ -2,12 +2,14 @@ import { Strapi } from '@strapi/strapi';
2
2
 
3
3
  import getPageBySlug from './graphql/page-by-slug';
4
4
  import pageType from './graphql/page-type';
5
+ import getPageInfoFromUID from './graphql/pages-by-uid';
5
6
 
6
7
  export default async ({ strapi }: { strapi: Strapi }) => {
7
8
  const extensionService = strapi.plugin('graphql').service('extension');
8
9
 
9
10
  extensionService.use(pageType);
10
11
  extensionService.use(getPageBySlug(strapi));
12
+ extensionService.use(getPageInfoFromUID(strapi));
11
13
 
12
14
  await strapi.services?.['plugin::page-builder.builder']?.buildContentTypes();
13
15
  };
@@ -36,6 +36,22 @@ const routes = {
36
36
  handler: 'collection-types.getTranslationPageLinks'
37
37
  }
38
38
  ]
39
+ },
40
+ template: {
41
+ type: 'admin',
42
+ prefix: undefined,
43
+ routes: [
44
+ {
45
+ method: 'GET',
46
+ path: '/template',
47
+ handler: 'template.findAll'
48
+ },
49
+ {
50
+ method: 'GET',
51
+ path: '/template/:id',
52
+ handler: 'template.findOneById'
53
+ }
54
+ ]
39
55
  }
40
56
  };
41
57
 
@@ -1,6 +1,5 @@
1
1
  import partition from 'lodash/partition';
2
-
3
- import { Service } from '@strapi/strapi/lib/types/core/common';
2
+ import { Common } from '@strapi/strapi';
4
3
 
5
4
  import pageStart from '../schema/page-start.json';
6
5
  import pageEnd from '../schema/page-end.json';
@@ -11,7 +10,7 @@ import pageTypeStart from '../schema/page-type-start.json';
11
10
  import pageTypeEnd from '../schema/page-type-end.json';
12
11
  import templateStart from '../schema/template-start.json';
13
12
 
14
- const UIDS = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
13
+ const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
15
14
 
16
15
  export default {
17
16
  async buildContentTypes() {
@@ -43,8 +42,8 @@ export default {
43
42
 
44
43
  await this.synchronizeContentTypes(updateContentTypes);
45
44
  },
46
- async synchronizeContentTypes(contentTypes: { uid: string; contentType: Record<string, any> }[]) {
47
- const ctb = strapi.service('plugin::content-type-builder.content-types') as Service;
45
+ async synchronizeContentTypes(contentTypes: { uid: Common.UID.ContentType; contentType: Record<string, any> }[]) {
46
+ const ctb = strapi.service('plugin::content-type-builder.content-types');
48
47
 
49
48
  const [updateTypes, newTypes] = partition(contentTypes, (c) => Boolean(strapi.contentType(c.uid)));
50
49
 
@@ -68,7 +67,10 @@ export default {
68
67
 
69
68
  if ((updateTypes || []).length > 0) {
70
69
  for await (const updateType of updateTypes) {
71
- await ctb.editContentType(updateType.uid, { contentType: updateType.contentType, components: [] });
70
+ await ctb.editContentType(updateType.uid, {
71
+ contentType: updateType.contentType,
72
+ components: []
73
+ });
72
74
  }
73
75
  }
74
76
  },
@@ -103,14 +105,13 @@ export default {
103
105
  return { uid: PAGE_TYPE_UID, contentType };
104
106
  },
105
107
  getTemplateContentType() {
106
- const pageType = templateStart;
107
- const contentType = this.mergeCollectionTypeWithModules(pageType, TEMPLATE_UID);
108
+ const template = templateStart;
109
+ const contentType = this.mergeCollectionTypeWithModules(template, TEMPLATE_UID);
108
110
 
109
111
  return { uid: TEMPLATE_UID, contentType };
110
112
  },
111
- mergeCollectionTypeWithModules(collectionType: Record<string, any>, uid: string) {
112
- const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = strapi.contentType(uid) || {};
113
-
113
+ mergeCollectionTypeWithModules(collectionType: Record<string, any>, uid: Common.UID.ContentType) {
114
+ const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = (strapi.contentType(uid) as any) || {};
114
115
  const components = this.getConfigModuleComponents();
115
116
 
116
117
  return {
@@ -127,6 +128,6 @@ export default {
127
128
  };
128
129
  },
129
130
  getConfigModuleComponents() {
130
- return (strapi.config.get(`plugin.${pluginId}`)?.modules || []).filter(Boolean);
131
+ return ((strapi.config.get(`plugin.${pluginId}`) as Record<string, any>)?.modules || []).filter(Boolean);
131
132
  }
132
133
  };
@@ -1,5 +1,5 @@
1
- import { Strapi } from '@strapi/strapi';
2
1
  import uniqBy from 'lodash/uniqBy';
2
+ import { Common } from '@strapi/strapi';
3
3
 
4
4
  import { IGetTranslationPageLinks } from '../controllers/collection-types';
5
5
  import { PAGE_TYPE_UID } from '../../shared/utils/constants';
@@ -13,7 +13,7 @@ export interface ICollectionTypeGL {
13
13
  export default {
14
14
  async hasPageRelation(uid: string): Promise<{ hasPageRelation: boolean }> {
15
15
  const contentType = strapi.contentTypes?.[uid];
16
- const pageTypesWithUid: any[] =
16
+ const pageTypesWithUid =
17
17
  (await strapi.entityService.findMany(PAGE_TYPE_UID, {
18
18
  filters: {
19
19
  uid: {
@@ -26,7 +26,7 @@ export default {
26
26
  hasPageRelation: Boolean(
27
27
  contentType?.attributes?.page &&
28
28
  contentType?.attributes?.page?.morphBy === 'collectionTypeData' &&
29
- pageTypesWithUid.length > 0
29
+ (pageTypesWithUid as Record<string, any>[]).length > 0
30
30
  )
31
31
  };
32
32
  },
@@ -52,9 +52,9 @@ export default {
52
52
 
53
53
  return collectionTypes;
54
54
  },
55
- async getTranslationPageLinks(uid: string, ids: string[]) {
55
+ async getTranslationPageLinks(uid: Common.UID.ContentType, ids: string[]) {
56
56
  try {
57
- const entities = await (strapi as Strapi).entityService.findMany(uid, {
57
+ const entities = await strapi.entityService.findMany(uid, {
58
58
  filters: {
59
59
  id: { $in: ids }
60
60
  },
@@ -65,7 +65,7 @@ export default {
65
65
  }
66
66
  }
67
67
  }
68
- });
68
+ } as any);
69
69
 
70
70
  let pages: IGetTranslationPageLinks[] = [];
71
71
 
@@ -2,10 +2,12 @@ import page from './page';
2
2
  import builder from './builder';
3
3
  import pageType from './page-type';
4
4
  import collectionTypes from './collection-types';
5
+ import template from './template';
5
6
 
6
7
  export default {
7
8
  page,
8
9
  builder,
9
10
  'page-type': pageType,
10
- 'collection-types': collectionTypes
11
+ 'collection-types': collectionTypes,
12
+ template
11
13
  };
@@ -1,6 +1,8 @@
1
+ import { PAGE_TYPE_UID } from '../../shared/utils/constants';
2
+
1
3
  export default {
2
4
  async findOneByUid(uid: string) {
3
- const result = await strapi.entityService.findMany('api::page-type.page-type', {
5
+ const results = await strapi.entityService?.findMany(PAGE_TYPE_UID, {
4
6
  populate: {
5
7
  template: {
6
8
  populate: {
@@ -13,8 +15,10 @@ export default {
13
15
  }
14
16
  });
15
17
 
16
- if (result.length > 0) {
17
- return result[0];
18
+ const result = (results as any[]).length > 0 ? results?.[0] : undefined;
19
+
20
+ if (result) {
21
+ return result;
18
22
  } else {
19
23
  return null;
20
24
  }
@@ -0,0 +1,14 @@
1
+ import { getPopulatedEntity } from '../utils/strapi';
2
+ import { TEMPLATE_UID } from '../../shared/utils/constants';
3
+
4
+ export default {
5
+ async findAll() {
6
+ const foundTemplates = await strapi.entityService.findMany(TEMPLATE_UID);
7
+
8
+ return foundTemplates;
9
+ },
10
+ async findOne(id: number) {
11
+ const getpopulatedTemplate = getPopulatedEntity(TEMPLATE_UID, id);
12
+ return getpopulatedTemplate;
13
+ }
14
+ };