@webbio/strapi-plugin-page-builder 0.2.4 → 0.2.6

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 (91) hide show
  1. package/README.md +98 -98
  2. package/admin/src/api/collection-type.ts +110 -110
  3. package/admin/src/api/has-page-relation.ts +34 -34
  4. package/admin/src/api/page-type.ts +31 -31
  5. package/admin/src/api/template.ts +27 -27
  6. package/admin/src/components/Combobox/index.tsx +77 -77
  7. package/admin/src/components/Combobox/react-select-custom-styles.tsx +120 -120
  8. package/admin/src/components/Combobox/styles.ts +22 -22
  9. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  10. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +124 -124
  11. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +104 -104
  12. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  13. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +74 -74
  14. package/admin/src/components/EditView/Details/index.tsx +47 -47
  15. package/admin/src/components/EditView/Details/styles.ts +51 -51
  16. package/admin/src/components/EditView/PageSettings/index.tsx +104 -104
  17. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  18. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +69 -69
  19. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +38 -38
  20. package/admin/src/components/EditView/index.tsx +29 -29
  21. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  22. package/admin/src/components/EditView/wrapper.tsx +35 -35
  23. package/admin/src/components/Initializer/index.tsx +24 -24
  24. package/admin/src/components/PageTypeFilter/index.tsx +17 -17
  25. package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -130
  26. package/admin/src/components/PluginIcon/index.tsx +12 -12
  27. package/admin/src/constants.ts +3 -3
  28. package/admin/src/index.tsx +59 -59
  29. package/admin/src/middlewares/index.tsx +37 -37
  30. package/admin/src/pluginId.ts +5 -5
  31. package/admin/src/translations/en.json +6 -6
  32. package/admin/src/translations/nl.json +6 -6
  33. package/admin/src/utils/getRequestUrl.ts +11 -11
  34. package/admin/src/utils/getTrad.ts +5 -5
  35. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  36. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  37. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  38. package/admin/src/utils/sanitizeModules.ts +93 -43
  39. package/custom.d.ts +5 -5
  40. package/dist/package.json +1 -1
  41. package/dist/server/controllers/platform.js +20 -0
  42. package/dist/server/graphql/page-by-path.js +90 -0
  43. package/dist/server/graphql/page-by-slug.js +9 -9
  44. package/dist/server/graphql/pages-by-uid.js +14 -14
  45. package/dist/server/schema/platform-start.json +31 -0
  46. package/dist/server/services/platform.js +36 -0
  47. package/dist/server/utils/graphql.js +18 -18
  48. package/dist/tsconfig.server.tsbuildinfo +1 -1
  49. package/package.json +71 -71
  50. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  51. package/server/bootstrap/permissions.ts +42 -42
  52. package/server/bootstrap.ts +198 -198
  53. package/server/config/index.ts +4 -4
  54. package/server/content-types/index.ts +1 -1
  55. package/server/controllers/collection-types.ts +27 -27
  56. package/server/controllers/index.ts +11 -11
  57. package/server/controllers/page-type.ts +13 -13
  58. package/server/controllers/page.ts +9 -9
  59. package/server/controllers/template.ts +16 -16
  60. package/server/destroy.ts +5 -5
  61. package/server/graphql/index.ts +9 -9
  62. package/server/graphql/page-by-slug.ts +98 -98
  63. package/server/graphql/page-type.ts +67 -67
  64. package/server/graphql/pages-by-uid.ts +127 -127
  65. package/server/index.ts +23 -23
  66. package/server/middlewares/index.ts +1 -1
  67. package/server/policies/index.ts +1 -1
  68. package/server/register.ts +15 -15
  69. package/server/routes/index.ts +58 -58
  70. package/server/schema/page-end.json +91 -91
  71. package/server/schema/page-start.json +87 -87
  72. package/server/schema/page-type-end.json +43 -43
  73. package/server/schema/page-type-start.json +38 -38
  74. package/server/schema/template-start.json +35 -35
  75. package/server/services/builder.ts +137 -137
  76. package/server/services/collection-types.ts +88 -88
  77. package/server/services/index.ts +13 -13
  78. package/server/services/page-type.ts +26 -26
  79. package/server/services/page.ts +24 -24
  80. package/server/services/template.ts +13 -13
  81. package/server/utils/filter-underscore-arguments.ts +12 -12
  82. package/server/utils/graphql.ts +113 -113
  83. package/server/utils/paginationValidation.ts +39 -39
  84. package/server/utils/reload-strapi-on-load.ts +13 -13
  85. package/server/utils/strapi.ts +45 -45
  86. package/shared/utils/constants.ts +4 -4
  87. package/shared/utils/sleep.ts +1 -1
  88. package/strapi-admin.js +3 -3
  89. package/strapi-server.js +3 -3
  90. package/tsconfig.json +20 -20
  91. package/tsconfig.server.json +25 -25
@@ -1,59 +1,59 @@
1
- import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
-
3
- import pluginPkg from '../../package.json';
4
- import pluginId from './pluginId';
5
- import Initializer from './components/Initializer';
6
- import PageTypeFilter from './components/PageTypeFilter';
7
- import { EditView } from './components/EditView';
8
- import middlewares from './middlewares';
9
-
10
- const name = pluginPkg.strapi.name;
11
-
12
- export default {
13
- register(app: any) {
14
- app.addMiddlewares(middlewares);
15
- const plugin = {
16
- id: pluginId,
17
- initializer: Initializer,
18
- isReady: false,
19
- name
20
- };
21
-
22
- app.registerPlugin(plugin);
23
- },
24
-
25
- bootstrap(app: any) {
26
- app.injectContentManagerComponent('editView', 'right-links', {
27
- name: 'collection-type-picker',
28
- Component: EditView
29
- });
30
- app.injectContentManagerComponent('listView', 'actions', {
31
- name: 'page-filters',
32
- Component: PageTypeFilter
33
- });
34
- },
35
-
36
- async registerTrads(app: any) {
37
- const { locales } = app;
38
-
39
- const importedTrads = await Promise.all(
40
- (locales as string[]).map((locale) => {
41
- return import(`./translations/${locale}.json`)
42
- .then(({ default: data }) => {
43
- return {
44
- data: prefixPluginTranslations(data, pluginId),
45
- locale
46
- };
47
- })
48
- .catch(() => {
49
- return {
50
- data: {},
51
- locale
52
- };
53
- });
54
- })
55
- );
56
-
57
- return Promise.resolve(importedTrads);
58
- }
59
- };
1
+ import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
+
3
+ import pluginPkg from '../../package.json';
4
+ import pluginId from './pluginId';
5
+ import Initializer from './components/Initializer';
6
+ import PageTypeFilter from './components/PageTypeFilter';
7
+ import { EditView } from './components/EditView';
8
+ import middlewares from './middlewares';
9
+
10
+ const name = pluginPkg.strapi.name;
11
+
12
+ export default {
13
+ register(app: any) {
14
+ app.addMiddlewares(middlewares);
15
+ const plugin = {
16
+ id: pluginId,
17
+ initializer: Initializer,
18
+ isReady: false,
19
+ name
20
+ };
21
+
22
+ app.registerPlugin(plugin);
23
+ },
24
+
25
+ bootstrap(app: any) {
26
+ app.injectContentManagerComponent('editView', 'right-links', {
27
+ name: 'collection-type-picker',
28
+ Component: EditView
29
+ });
30
+ app.injectContentManagerComponent('listView', 'actions', {
31
+ name: 'page-filters',
32
+ Component: PageTypeFilter
33
+ });
34
+ },
35
+
36
+ async registerTrads(app: any) {
37
+ const { locales } = app;
38
+
39
+ const importedTrads = await Promise.all(
40
+ (locales as string[]).map((locale) => {
41
+ return import(`./translations/${locale}.json`)
42
+ .then(({ default: data }) => {
43
+ return {
44
+ data: prefixPluginTranslations(data, pluginId),
45
+ locale
46
+ };
47
+ })
48
+ .catch(() => {
49
+ return {
50
+ data: {},
51
+ locale
52
+ };
53
+ });
54
+ })
55
+ );
56
+
57
+ return Promise.resolve(importedTrads);
58
+ }
59
+ };
@@ -1,37 +1,37 @@
1
- import { getFetchClient } from '@strapi/helper-plugin';
2
-
3
- import { PAGE_UID } from '../../../shared/utils/constants';
4
- import getRequestUrl from '../utils/getRequestUrl';
5
-
6
- const middleware =
7
- () =>
8
- ({ getState }: any) =>
9
- (next: any) =>
10
- async (action: any) => {
11
- // If data is being fetched or after a save
12
- if (
13
- action.type === 'ContentManager/CrudReducer/GET_DATA_SUCCEEDED' ||
14
- action.type === 'ContentManager/CrudReducer/SUBMIT_SUCCEEDED'
15
- ) {
16
- const store = getState();
17
- const layoutSlice = store['content-manager_editViewLayoutManager'];
18
- const uid = layoutSlice.currentLayout.contentType.uid;
19
-
20
- if (uid !== PAGE_UID) {
21
- return next(action);
22
- }
23
-
24
- const { get } = await getFetchClient();
25
- const { data: pageData } = await get(`${getRequestUrl('page')}/${action.data.id}`);
26
-
27
- action.data.collectionTypeTitle = pageData?.collectionTypeData?.title;
28
- action.data.collectionTypeId = pageData?.collectionTypeData?.id;
29
- action.data.initialPageType = pageData?.pageType ? pageData.pageType : undefined;
30
-
31
- return next(action);
32
- }
33
- return next(action);
34
- };
35
-
36
- const middlewares = [middleware];
37
- export default middlewares;
1
+ import { getFetchClient } from '@strapi/helper-plugin';
2
+
3
+ import { PAGE_UID } from '../../../shared/utils/constants';
4
+ import getRequestUrl from '../utils/getRequestUrl';
5
+
6
+ const middleware =
7
+ () =>
8
+ ({ getState }: any) =>
9
+ (next: any) =>
10
+ async (action: any) => {
11
+ // If data is being fetched or after a save
12
+ if (
13
+ action.type === 'ContentManager/CrudReducer/GET_DATA_SUCCEEDED' ||
14
+ action.type === 'ContentManager/CrudReducer/SUBMIT_SUCCEEDED'
15
+ ) {
16
+ const store = getState();
17
+ const layoutSlice = store['content-manager_editViewLayoutManager'];
18
+ const uid = layoutSlice.currentLayout.contentType.uid;
19
+
20
+ if (uid !== PAGE_UID) {
21
+ return next(action);
22
+ }
23
+
24
+ const { get } = await getFetchClient();
25
+ const { data: pageData } = await get(`${getRequestUrl('page')}/${action.data.id}`);
26
+
27
+ action.data.collectionTypeTitle = pageData?.collectionTypeData?.title;
28
+ action.data.collectionTypeId = pageData?.collectionTypeData?.id;
29
+ action.data.initialPageType = pageData?.pageType ? pageData.pageType : undefined;
30
+
31
+ return next(action);
32
+ }
33
+ return next(action);
34
+ };
35
+
36
+ const middlewares = [middleware];
37
+ export default middlewares;
@@ -1,5 +1,5 @@
1
- import pluginPkg from '../../package.json';
2
-
3
- const pluginId = pluginPkg.strapi.name;
4
-
5
- export default pluginId;
1
+ import pluginPkg from '../../package.json';
2
+
3
+ const pluginId = pluginPkg.strapi.name;
4
+
5
+ export default pluginId;
@@ -1,6 +1,6 @@
1
- {
2
- "template.confirmModal.title": "Replace all page modules",
3
- "template.confirmModal.body": "You are about to replace all modules on this page. Are you sure you want to continue?",
4
- "template.confirmModal.buttons.cancel": "No, cancel",
5
- "template.confirmModal.buttons.submit": "Yes, replace all"
6
- }
1
+ {
2
+ "template.confirmModal.title": "Replace all page modules",
3
+ "template.confirmModal.body": "You are about to replace all modules on this page. Are you sure you want to continue?",
4
+ "template.confirmModal.buttons.cancel": "No, cancel",
5
+ "template.confirmModal.buttons.submit": "Yes, replace all"
6
+ }
@@ -1,6 +1,6 @@
1
- {
2
- "template.confirmModal.title": "Pagina modules vervangen",
3
- "template.confirmModal.body": "Weet je zeker dat je alle modules op deze pagina wilt vervangen?",
4
- "template.confirmModal.buttons.cancel": "Nee, annuleer",
5
- "template.confirmModal.buttons.submit": "Ja, vervang modules"
6
- }
1
+ {
2
+ "template.confirmModal.title": "Pagina modules vervangen",
3
+ "template.confirmModal.body": "Weet je zeker dat je alle modules op deze pagina wilt vervangen?",
4
+ "template.confirmModal.buttons.cancel": "Nee, annuleer",
5
+ "template.confirmModal.buttons.submit": "Ja, vervang modules"
6
+ }
@@ -1,11 +1,11 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getRequestUrl = (path: string) => {
4
- if (path.startsWith('/')) {
5
- return `/${pluginId}${path}`;
6
- }
7
-
8
- return `/${pluginId}/${path}`;
9
- };
10
-
11
- export default getRequestUrl;
1
+ import pluginId from '../pluginId';
2
+
3
+ const getRequestUrl = (path: string) => {
4
+ if (path.startsWith('/')) {
5
+ return `/${pluginId}${path}`;
6
+ }
7
+
8
+ return `/${pluginId}/${path}`;
9
+ };
10
+
11
+ export default getRequestUrl;
@@ -1,5 +1,5 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getTrad = (id: string) => `${pluginId}.${id}`;
4
-
5
- export default getTrad;
1
+ import pluginId from '../pluginId';
2
+
3
+ const getTrad = (id: string) => `${pluginId}.${id}`;
4
+
5
+ export default getTrad;
@@ -1,17 +1,17 @@
1
- import React from 'react';
2
-
3
- export function useDebounce<T>(value: T, delay: number): T {
4
- const [debouncedValue, setDebouncedValue] = React.useState(value);
5
-
6
- React.useEffect(() => {
7
- const handler = setTimeout(() => {
8
- setDebouncedValue(value);
9
- }, delay);
10
-
11
- return () => {
12
- clearTimeout(handler);
13
- };
14
- }, [value, delay]);
15
-
16
- return debouncedValue;
17
- }
1
+ import React from 'react';
2
+
3
+ export function useDebounce<T>(value: T, delay: number): T {
4
+ const [debouncedValue, setDebouncedValue] = React.useState(value);
5
+
6
+ React.useEffect(() => {
7
+ const handler = setTimeout(() => {
8
+ setDebouncedValue(value);
9
+ }, delay);
10
+
11
+ return () => {
12
+ clearTimeout(handler);
13
+ };
14
+ }, [value, delay]);
15
+
16
+ return debouncedValue;
17
+ }
@@ -1,9 +1,9 @@
1
- import { useQueryParams } from '@strapi/helper-plugin';
2
-
3
- const useGetLocaleFromUrl = () => {
4
- const [{ query }] = useQueryParams() as any;
5
-
6
- return query?.plugins?.i18n?.locale;
7
- };
8
-
9
- export { useGetLocaleFromUrl };
1
+ import { useQueryParams } from '@strapi/helper-plugin';
2
+
3
+ const useGetLocaleFromUrl = () => {
4
+ const [{ query }] = useQueryParams() as any;
5
+
6
+ return query?.plugins?.i18n?.locale;
7
+ };
8
+
9
+ export { useGetLocaleFromUrl };
@@ -1,12 +1,12 @@
1
- import { useRef, useEffect } from 'react';
2
-
3
- // Hook
4
- export const usePrevious = <T>(value: T): T | null => {
5
- const ref: React.MutableRefObject<T | null> = useRef(null);
6
-
7
- useEffect(() => {
8
- ref.current = value;
9
- }, [value]);
10
-
11
- return ref.current;
12
- };
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ // Hook
4
+ export const usePrevious = <T>(value: T): T | null => {
5
+ const ref: React.MutableRefObject<T | null> = useRef(null);
6
+
7
+ useEffect(() => {
8
+ ref.current = value;
9
+ }, [value]);
10
+
11
+ return ref.current;
12
+ };
@@ -1,43 +1,93 @@
1
- export const sanitizeModules = (modules: Record<string, any>[]) =>
2
- modules?.map((module, idx) => {
3
- try {
4
- const sanitizedModule = sanitizeObject(module, idx);
5
-
6
- const result = {
7
- ...sanitizedModule
8
- };
9
-
10
- return result;
11
- } catch (e) {
12
- console.log('ERROR IN SANITIZE MODULES', e);
13
- }
14
- });
15
-
16
- function sanitizeObject(obj: any, idx: number): any {
17
- for (let key in obj) {
18
- if (typeof obj[key] === 'object' && obj[key] !== null) {
19
- sanitizeObject(obj[key], idx);
20
- }
21
- }
22
-
23
- if (obj.hasOwnProperty('id') && !obj.hasOwnProperty('createdAt')) {
24
- obj['__temp_key__'] = idx;
25
- delete obj['id'];
26
- }
27
-
28
- if (obj.hasOwnProperty('defaultModuleOptions') && !obj.hasOwnProperty('createdAt')) {
29
- delete obj['defaultModuleOptions'].id;
30
- obj['defaultModuleOptions'] = {
31
- ...obj['defaultModuleOptions'],
32
- spacing: JSON.stringify(obj['defaultModuleOptions'].spacing),
33
- __temp_key__: idx
34
- };
35
- }
36
-
37
- if (obj.hasOwnProperty('name') && !obj.hasOwnProperty('mainField') && !obj.hasOwnProperty('label')) {
38
- obj['label'] = obj['name'];
39
- obj['mainField'] = obj['name'];
40
- }
41
-
42
- return obj;
43
- }
1
+ export const sanitizeModules = (modules: Record<string, any>[], convertToJSON = true) =>
2
+ modules?.map((module, idx) => {
3
+ try {
4
+ const sanitizedModule = sanitizeObject(module, idx, convertToJSON);
5
+
6
+ // go through top level properties in the module
7
+ for (let prop in sanitizedModule) {
8
+ // Strapi didn't give us the properties in an array when we used the Strapi API to get modules
9
+ // But it crashes when we try and have single relations not in an array, so we put them into an array.
10
+ if (
11
+ sanitizedModule[prop] &&
12
+ sanitizedModule[prop].hasOwnProperty('__is_array__') &&
13
+ !Array.isArray(sanitizedModule[prop])
14
+ ) {
15
+ sanitizedModule[prop] = [{ ...sanitizedModule[prop] }];
16
+ }
17
+
18
+ // If a property is null, Strapi decides it should crash completely so we remove those.
19
+ if (sanitizedModule[prop] === null) {
20
+ delete sanitizedModule[prop];
21
+ }
22
+ }
23
+
24
+ const result = {
25
+ ...sanitizedModule
26
+ };
27
+
28
+ return result;
29
+ } catch (error) {
30
+ console.error('ERROR IN SANITIZE MODULES', error);
31
+ }
32
+ });
33
+
34
+ function sanitizeObject(obj: any, idx: number, convertToJSON = true): any {
35
+ try {
36
+ for (let key in obj) {
37
+ try {
38
+ if (typeof obj[key] === 'object' && obj[key] !== null && obj[key] !== undefined) {
39
+ sanitizeObject(obj[key], idx);
40
+ }
41
+ } catch (error) {
42
+ console.error('ERROR in loop', error);
43
+ return undefined;
44
+ }
45
+ }
46
+
47
+ // We have to remove the id for components, but not for relations to other collection items
48
+ // We use createdAt to check, only collection items have this property (hopefully)
49
+ if (obj.hasOwnProperty('id') && !obj.hasOwnProperty('createdAt')) {
50
+ obj['__temp_key__'] = idx;
51
+ delete obj['id'];
52
+ } else if (obj.hasOwnProperty('id') && obj.hasOwnProperty('createdAt')) {
53
+ // if it's a relation to a collection item, it has to be in an array because it crashes otherwise.
54
+ // We use this property at the top of this file, only for top level properties.
55
+ obj['__is_array__'] = true;
56
+ }
57
+
58
+ try {
59
+ if (obj.hasOwnProperty('defaultModuleOptions')) {
60
+ delete obj['defaultModuleOptions'].id;
61
+
62
+ let spacing = obj['defaultModuleOptions']?.spacing;
63
+
64
+ if (convertToJSON && spacing) {
65
+ spacing = JSON.stringify(spacing);
66
+ }
67
+
68
+ obj['defaultModuleOptions'] = {
69
+ ...obj['defaultModuleOptions'],
70
+ spacing,
71
+ __temp_key__: idx
72
+ };
73
+ }
74
+ } catch (error) {
75
+ console.error('error in defaultmodule options', error);
76
+ }
77
+
78
+ // Strapi doesnt give us the mainfield and label properties when we get the data using the Strapi API
79
+ // So we add them here using other properties. This might be expanded with more if statements if required,
80
+ if (obj.hasOwnProperty('name') && !obj.hasOwnProperty('mainField') && !obj.hasOwnProperty('label')) {
81
+ obj['label'] = obj['name'];
82
+ obj['mainField'] = obj['name'];
83
+ }
84
+ if (obj.hasOwnProperty('title') && !obj.hasOwnProperty('mainField') && !obj.hasOwnProperty('label')) {
85
+ obj['label'] = obj['title'];
86
+ obj['mainField'] = obj['title'];
87
+ }
88
+
89
+ return obj;
90
+ } catch (error) {
91
+ console.error('error in root sanitize object', error);
92
+ }
93
+ }
package/custom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- declare module '@strapi/design-system/*';
2
- declare module '@strapi/design-system';
3
- declare module '@strapi/icons';
4
- declare module '@strapi/icons/*';
5
- declare module '@strapi/helper-plugin';
1
+ declare module '@strapi/design-system/*';
2
+ declare module '@strapi/design-system';
3
+ declare module '@strapi/icons';
4
+ declare module '@strapi/icons/*';
5
+ declare module '@strapi/helper-plugin';
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ async findAll() {
5
+ return await strapi.service('plugin::page-builder.platform').findAll();
6
+ },
7
+ async findOneByUid(ctx) {
8
+ var _a;
9
+ const uid = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
10
+ if (!uid) {
11
+ return ctx.badRequest('uid is missing.');
12
+ }
13
+ return await strapi.service('plugin::page-builder.platform').findOneByUid(uid);
14
+ },
15
+ async findPageTypesByPlatform(ctx) {
16
+ var _a;
17
+ const platform = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.platform;
18
+ return await strapi.services['plugin::page-builder.platform'].findPageTypesByPlatform(platform);
19
+ }
20
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../../shared/utils/constants");
4
+ const getPageByPath = (strapi) => {
5
+ const typeDefs = () => {
6
+ return `
7
+ extend type Page {
8
+ collectionType: GenericMorph
9
+ }
10
+
11
+ type Query {
12
+ getPageByPath(path: String, domain: String, publicationState: PublicationState): PageEntity
13
+ }
14
+
15
+ `;
16
+ };
17
+ const resolvers = (strapi) => {
18
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
19
+ return {
20
+ Query: {
21
+ getPageByPath: {
22
+ resolve: async (_parent, args, ctx) => {
23
+ var _a;
24
+ try {
25
+ const filteredArgs = {
26
+ filters: {
27
+ path: args.path,
28
+ platform: args.domain ? { domain: args.domain } : null
29
+ },
30
+ publicationState: args.publicationState,
31
+ locale: args.locale
32
+ };
33
+ const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
34
+ const getPage = async () => {
35
+ var _a, _b, _c;
36
+ const transformedArgs = transformArgs(filteredArgs, {
37
+ contentType: strapi.contentTypes[constants_1.PAGE_UID],
38
+ usePagination: false
39
+ });
40
+ const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
41
+ ...filteredArgs,
42
+ populate: '*'
43
+ }));
44
+ const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
45
+ args: transformedArgs,
46
+ resourceUID: constants_1.PAGE_UID
47
+ });
48
+ if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
49
+ throw new Error(ctx.koaContext.response.message);
50
+ }
51
+ const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
52
+ const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
53
+ const addedAttributes = {
54
+ collectionType: collectionType
55
+ };
56
+ const result = {
57
+ ...entityResponse.value,
58
+ ...addedAttributes
59
+ };
60
+ return result;
61
+ };
62
+ const results = await getPage();
63
+ if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
64
+ return results;
65
+ }
66
+ else {
67
+ throw new Error(ctx.koaContext.response.message);
68
+ }
69
+ }
70
+ catch (error) {
71
+ console.log('Error in [getPageByPath], args:', args, 'ERROR:', error);
72
+ throw new Error(ctx.koaContext.response.message);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ };
78
+ };
79
+ const resolversConfig = {
80
+ 'Query.getPageByPath': {
81
+ auth: false
82
+ }
83
+ };
84
+ return {
85
+ typeDefs: typeDefs(),
86
+ resolvers: resolvers(strapi),
87
+ resolversConfig
88
+ };
89
+ };
90
+ exports.default = getPageByPath;
@@ -4,15 +4,15 @@ const filter_underscore_arguments_1 = require("../utils/filter-underscore-argume
4
4
  const constants_1 = require("../../shared/utils/constants");
5
5
  const getPageBySlug = (strapi) => {
6
6
  const typeDefs = () => {
7
- return `
8
- extend type Page {
9
- collectionType: GenericMorph
10
- }
11
-
12
- type Query {
13
- getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
14
- }
15
-
7
+ return `
8
+ extend type Page {
9
+ collectionType: GenericMorph
10
+ }
11
+
12
+ type Query {
13
+ getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
14
+ }
15
+
16
16
  `;
17
17
  };
18
18
  const resolvers = (strapi) => {