@webbio/strapi-plugin-page-builder 0.3.3 → 0.3.4-legacy

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 (81) hide show
  1. package/README.md +21 -6
  2. package/admin/src/api/collection-type.ts +1 -7
  3. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +12 -15
  4. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +28 -10
  5. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +32 -61
  6. package/admin/src/components/EditView/Details/index.tsx +1 -1
  7. package/admin/src/components/EditView/PageSettings/index.tsx +6 -74
  8. package/admin/src/components/PageTypeFilter/index.tsx +17 -0
  9. package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -0
  10. package/admin/src/index.tsx +2 -2
  11. package/admin/src/utils/sanitizeModules.ts +92 -9
  12. package/dist/package.json +12 -10
  13. package/dist/server/bootstrap/permissions.js +10 -68
  14. package/dist/server/bootstrap.js +24 -40
  15. package/dist/server/content-types/user-categories/schema.json +18 -0
  16. package/dist/server/content-types/user-category/schema.json +23 -0
  17. package/dist/server/controllers/index.js +1 -3
  18. package/dist/server/controllers/platform.js +5 -5
  19. package/dist/server/controllers/private-content.js +18 -0
  20. package/dist/server/controllers/sitemap.js +29 -0
  21. package/dist/server/controllers/user-category.js +4 -0
  22. package/dist/server/graphql/page-by-path.js +113 -0
  23. package/dist/server/graphql/page-by-slug.js +37 -44
  24. package/dist/server/graphql/pages-by-uid.js +7 -9
  25. package/dist/server/policies/isAuthorizedPage.js +11 -0
  26. package/dist/server/routes/index.js +0 -21
  27. package/dist/server/routes/user-category.js +4 -0
  28. package/dist/server/schema/page-end.json +0 -5
  29. package/dist/server/schema/platform-start.json +0 -10
  30. package/dist/server/schema/template-end.json +40 -0
  31. package/dist/server/services/builder.js +5 -15
  32. package/dist/server/services/email.js +160 -0
  33. package/dist/server/services/index.js +1 -3
  34. package/dist/server/services/platform.js +6 -11
  35. package/dist/server/services/private-content/components/admin-email.json +22 -0
  36. package/dist/server/services/private-content/components/email.json +22 -0
  37. package/dist/server/services/private-content/components/platform-email.json +33 -0
  38. package/dist/server/services/private-content/constants/index.js +16 -0
  39. package/dist/server/services/private-content/graphql/index.js +77 -0
  40. package/dist/server/services/private-content/graphql/resolvers/findOnePage.js +40 -0
  41. package/dist/server/services/private-content/graphql/resolvers/findPage.js +44 -0
  42. package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +29 -0
  43. package/dist/server/services/private-content/graphql/resolvers/login.js +49 -0
  44. package/dist/server/services/private-content/graphql/resolvers/register.js +68 -0
  45. package/dist/server/services/private-content/graphql/resolvers/reset-password.js +41 -0
  46. package/dist/server/services/private-content/graphql/types/index.js +89 -0
  47. package/dist/server/services/private-content/index.js +94 -0
  48. package/dist/server/services/private-content/mail-template/txtMail.email.template.text.js +12 -0
  49. package/dist/server/services/private-content/page.js +22 -0
  50. package/dist/server/services/private-content/platform.js +22 -0
  51. package/dist/server/services/private-content/schemas/index.js +30 -0
  52. package/dist/server/services/private-content/user.js +170 -0
  53. package/dist/server/services/sitemap.js +78 -0
  54. package/dist/server/services/template.js +1 -2
  55. package/dist/server/services/user-category.js +4 -0
  56. package/dist/server/utils/strapi.js +1 -4
  57. package/dist/shared/utils/constants.js +1 -3
  58. package/dist/tsconfig.server.tsbuildinfo +1 -1
  59. package/package.json +12 -10
  60. package/server/bootstrap/collection-type-lifecycles.ts +1 -1
  61. package/server/bootstrap/permissions.ts +10 -75
  62. package/server/bootstrap.ts +24 -43
  63. package/server/controllers/index.ts +1 -3
  64. package/server/graphql/page-by-slug.ts +43 -50
  65. package/server/graphql/pages-by-uid.ts +7 -9
  66. package/server/routes/index.ts +0 -21
  67. package/server/schema/page-end.json +0 -5
  68. package/server/services/builder.ts +6 -18
  69. package/server/services/index.ts +1 -3
  70. package/server/services/template.ts +1 -2
  71. package/server/utils/strapi.ts +1 -5
  72. package/shared/utils/constants.ts +0 -2
  73. package/admin/src/api/platform.ts +0 -34
  74. package/admin/src/components/EditView/Platform/platform-select.tsx +0 -30
  75. package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +0 -39
  76. package/admin/src/components/PageFilters/PlatformFilter/index.tsx +0 -28
  77. package/admin/src/components/PageFilters/filters.tsx +0 -180
  78. package/admin/src/components/PageFilters/index.tsx +0 -30
  79. package/server/controllers/platform.ts +0 -21
  80. package/server/schema/platform-start.json +0 -31
  81. package/server/services/platform.ts +0 -36
@@ -1,10 +1,93 @@
1
- export const sanitizeModules = (modules: Record<string, any>[]) => {
2
- return modules?.map((module, idx) => {
3
- delete module.id;
4
-
5
- return {
6
- ...module,
7
- __temp_key__: idx
8
- };
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
+ }
9
32
  });
10
- };
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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.3.3",
3
+ "version": "0.3.4-legacy",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -20,14 +20,16 @@
20
20
  "url": "https://github.com/webbio/strapi-plugin-page-builder.git"
21
21
  },
22
22
  "dependencies": {
23
- "@strapi/design-system": "^1.11.0",
24
- "@strapi/helper-plugin": "^4.15.0",
25
- "@strapi/icons": "^1.11.0",
26
- "@strapi/typescript-utils": "^4.15.0",
27
- "@strapi/utils": "^4.15.0",
28
- "react-select": "^5.7.4"
23
+ "@strapi/design-system": "^1.19.0",
24
+ "@strapi/helper-plugin": "^4.25.22",
25
+ "@strapi/icons": "^1.19.0",
26
+ "@strapi/typescript-utils": "4.25.22",
27
+ "@strapi/utils": "4.25.22",
28
+ "react-select": "^5.7.4",
29
+ "slugify": "^1.6.6"
29
30
  },
30
31
  "devDependencies": {
32
+ "@strapi/typescript-utils": "4.25.22",
31
33
  "@types/react": "^18.2.21",
32
34
  "@types/react-dom": "^18.2.7",
33
35
  "@types/react-router-dom": "^5.3.3",
@@ -39,8 +41,8 @@
39
41
  "typescript": "5.1.6"
40
42
  },
41
43
  "peerDependencies": {
42
- "@strapi/strapi": "^4.15.0",
43
- "@webbio/strapi-plugin-slug": "^2.0.2",
44
+ "@strapi/strapi": "4.25.22",
45
+ "@webbio/strapi-plugin-slug": "^4.0.10",
44
46
  "react": "^17.0.0 || ^18.0.0",
45
47
  "react-dom": "^17.0.0 || ^18.0.0",
46
48
  "react-router-dom": "^5.3.4",
@@ -59,7 +61,7 @@
59
61
  }
60
62
  ],
61
63
  "engines": {
62
- "node": ">=14.19.1 <=18.x.x",
64
+ "node": ">=14.19.1 <=20.x.x",
63
65
  "npm": ">=6.0.0"
64
66
  },
65
67
  "license": "MIT",
@@ -2,83 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const constants_1 = require("../../shared/utils/constants");
4
4
  exports.default = async ({ strapi }) => {
5
- var _a, _b;
5
+ var _a;
6
6
  try {
7
7
  const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
8
8
  limit: -1
9
9
  })));
10
- const platforms = (await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.findMany(constants_1.PLATFORM_UID, {
11
- limit: -1
12
- })));
13
- const platformPagePermissions = platforms.map((platform) => {
14
- return pageTypes.map((pageType) => {
15
- const name = `platform-is-${platform.title}-${pageType.uid}`;
16
- const displayName = `${platform.title}-${pageType.title}`;
17
- return {
18
- plugin: 'page-builder',
19
- name,
20
- displayName,
21
- category: `${platform.title} Page roles`,
22
- handler: async () => {
23
- return {
24
- $and: [
25
- {
26
- 'platform.id': {
27
- $eq: platform.id
28
- }
29
- },
30
- {
31
- 'pageType.uid': {
32
- $eq: pageType.uid
33
- }
34
- },
35
- {
36
- uid: {
37
- $eq: pageType.uid
38
- }
39
- }
40
- ]
41
- };
42
- }
43
- };
44
- });
45
- });
46
- const pageTypePermissions = pageTypes.map((pageType) => {
47
- const name = `pageType-permission-${pageType.uid}`;
48
- const displayName = `pageType ${pageType.title}`;
49
- return {
50
- plugin: 'page-builder',
51
- name,
52
- displayName,
53
- category: `Platform pageType roles`,
54
- handler: async () => {
55
- return {
56
- uid: {
57
- $eq: pageType.uid
58
- }
59
- };
60
- }
61
- };
62
- });
63
- const platformCollectiontypePermissions = platforms.map((platform) => {
64
- const name = `platform-is-${platform.title}`;
65
- const displayName = platform.title;
10
+ const pagePermissions = pageTypes.map((pageType) => {
11
+ const name = `page-type-is-${pageType.uid}`;
12
+ const displayName = pageType.title;
66
13
  return {
67
14
  plugin: 'page-builder',
68
15
  name,
69
16
  displayName,
70
- category: 'Platform CollectionType roles',
17
+ category: 'Page type',
71
18
  handler: async () => {
72
19
  return {
73
20
  $or: [
74
21
  {
75
- 'platform.id': {
76
- $eq: platform.id
22
+ 'pageType.uid': {
23
+ $eq: pageType.uid
77
24
  }
78
25
  },
79
26
  {
80
- id: {
81
- $eq: platform.id
27
+ uid: {
28
+ $eq: pageType.uid
82
29
  }
83
30
  }
84
31
  ]
@@ -86,13 +33,8 @@ exports.default = async ({ strapi }) => {
86
33
  }
87
34
  };
88
35
  });
89
- const allPermissions = [
90
- ...platformPagePermissions.flat(),
91
- ...pageTypePermissions.flat(),
92
- ...platformCollectiontypePermissions
93
- ];
94
36
  // @ts-ignore shitty types
95
- await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
37
+ await strapi.admin.services.permission.conditionProvider.registerMany(pagePermissions);
96
38
  }
97
39
  catch {
98
40
  console.log('Cannot set page permissions');
@@ -25,31 +25,19 @@ exports.default = async ({ strapi }) => {
25
25
  // @ts-ignore
26
26
  models: [constants_1.PAGE_UID],
27
27
  async beforeCreate(event) {
28
- var _a, _b, _c, _d, _e, _f, _g;
28
+ var _a, _b, _c, _d;
29
29
  let { data } = event.params;
30
30
  const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
31
31
  const pageTypeId = ((_b = (_a = data === null || data === void 0 ? void 0 : data.pageType.connect) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) || data.initialPageType;
32
- const platformId = (_d = (_c = data === null || data === void 0 ? void 0 : data.platform.connect) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.id;
33
32
  if (collectionTypeId && pageTypeId) {
34
- const pageType = await ((_e = strapi.entityService) === null || _e === void 0 ? void 0 : _e.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
35
- const collectionToConnect = await ((_f = strapi.entityService) === null || _f === void 0 ? void 0 : _f.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
33
+ const pageType = await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
34
+ const collectionToConnect = await ((_d = strapi.entityService) === null || _d === void 0 ? void 0 : _d.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
36
35
  populate: { page: true }
37
36
  }));
38
37
  const page = collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page;
39
- const foundPlatforms = await ((_g = strapi.entityService) === null || _g === void 0 ? void 0 : _g.findMany(constants_1.PLATFORM_UID, {
40
- populate: '*',
41
- filters: {
42
- pagetype: {
43
- uid: pageType === null || pageType === void 0 ? void 0 : pageType.uid
44
- }
45
- }
46
- }));
47
38
  if (page && page.length > 0) {
48
39
  throw new utils_1.errors.ValidationError('You can only link one CollectionType to one page');
49
40
  }
50
- if (platformId && !(foundPlatforms === null || foundPlatforms === void 0 ? void 0 : foundPlatforms.some((platform) => platform.id === platformId))) {
51
- throw new utils_1.errors.ValidationError('Platform not found');
52
- }
53
41
  data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
54
42
  }
55
43
  },
@@ -86,6 +74,8 @@ exports.default = async ({ strapi }) => {
86
74
  }
87
75
  data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
88
76
  }
77
+ // needs to check if the collectionTypeData is already connected to another page
78
+ // if so, remove the hasPage for filtering
89
79
  if (data.collectionTypeData &&
90
80
  ((_r = (_q = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.__type) &&
91
81
  ((_t = (_s = originalEntity === null || originalEntity === void 0 ? void 0 : originalEntity.collectionTypeData) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.id) &&
@@ -102,33 +92,27 @@ exports.default = async ({ strapi }) => {
102
92
  }
103
93
  },
104
94
  async afterUpdate(event) {
105
- var _a, _b, _c;
106
- const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
107
- if (((_b = data.collectionTypeData) === null || _b === void 0 ? void 0 : _b.__type) && data.collectionTypeData.id) {
108
- await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
109
- data: {
110
- id: data.collectionTypeData.id,
111
- hasPage: true,
112
- lifecycleState: {
113
- exit: true
95
+ var _a, _b;
96
+ try {
97
+ // Result not correctly typed within Strapi
98
+ const data = event === null || event === void 0 ? void 0 : event['result'];
99
+ const hasCollectionTypeRelation = data && ((_a = data === null || data === void 0 ? void 0 : data.collectionTypeData) === null || _a === void 0 ? void 0 : _a[0]) && (data === null || data === void 0 ? void 0 : data.collectionTypeData[0].__type) && (data === null || data === void 0 ? void 0 : data.collectionTypeData[0].id);
100
+ if (hasCollectionTypeRelation) {
101
+ const isPublished = data.publishedAt !== undefined;
102
+ const pageData = isPublished ? { hasPage: !!data.publishedAt } : {};
103
+ await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData[0].__type, data.collectionTypeData[0].id, {
104
+ data: {
105
+ ...pageData,
106
+ id: data.collectionTypeData[0].id,
107
+ lifecycleState: {
108
+ exit: true
109
+ }
114
110
  }
115
- }
116
- }));
111
+ }));
112
+ }
117
113
  }
118
- },
119
- async afterCreate(event) {
120
- var _a, _b, _c;
121
- const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
122
- if (((_b = data.collectionTypeData) === null || _b === void 0 ? void 0 : _b.__type) && data.collectionTypeData.id) {
123
- await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
124
- data: {
125
- id: data.collectionTypeData.id,
126
- hasPage: true,
127
- lifecycleState: {
128
- exit: true
129
- }
130
- }
131
- }));
114
+ catch (error) {
115
+ console.error('Failed to save hasPage data', error);
132
116
  }
133
117
  },
134
118
  async beforeDelete(event) {
@@ -0,0 +1,18 @@
1
+ {
2
+ "kind": "collectionType",
3
+ "collectionName": "user-categories",
4
+ "info": {
5
+ "singularName": "user-category",
6
+ "pluralName": "user-categories",
7
+ "displayName": "User Categories"
8
+ },
9
+ "options": {
10
+ "draftAndPublish": false,
11
+ "comment": ""
12
+ },
13
+ "attributes": {
14
+ "title": {
15
+ "type": "string"
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "kind": "collectionType",
3
+ "collectionName": "user-categories",
4
+ "info": {
5
+ "singularName": "user-category",
6
+ "pluralName": "user-categories",
7
+ "displayName": "User Categories"
8
+ },
9
+ "options": {
10
+ "draftAndPublish": false,
11
+ "comment": ""
12
+ },
13
+ "attributes": {
14
+ "title": {
15
+ "type": "string"
16
+ },
17
+ "platform": {
18
+ "type": "relation",
19
+ "relation": "oneToOne",
20
+ "target": "api::platform.platform"
21
+ }
22
+ }
23
+ }
@@ -7,11 +7,9 @@ const page_1 = __importDefault(require("./page"));
7
7
  const page_type_1 = __importDefault(require("./page-type"));
8
8
  const collection_types_1 = __importDefault(require("./collection-types"));
9
9
  const template_1 = __importDefault(require("./template"));
10
- const platform_1 = __importDefault(require("./platform"));
11
10
  exports.default = {
12
11
  page: page_1.default,
13
12
  'page-type': page_type_1.default,
14
13
  'collection-types': collection_types_1.default,
15
- template: template_1.default,
16
- platform: platform_1.default
14
+ template: template_1.default
17
15
  };
@@ -4,13 +4,13 @@ exports.default = {
4
4
  async findAll() {
5
5
  return await strapi.service('plugin::page-builder.platform').findAll();
6
6
  },
7
- async findOneByUid(ctx) {
7
+ async findOneById(ctx) {
8
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.');
9
+ const id = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.id;
10
+ if (!id) {
11
+ return ctx.badRequest('id is missing.');
12
12
  }
13
- return await strapi.service('plugin::page-builder.platform').findOneByUid(uid);
13
+ return await strapi.service('plugin::page-builder.platform').findOneById(id);
14
14
  },
15
15
  async findPageTypesByPlatform(ctx) {
16
16
  var _a;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ async activateUser(ctx) {
5
+ try {
6
+ const user = await strapi.service('plugin::page-builder.private-content').activateUser(ctx.params.token);
7
+ const callbackUrl = `${user.platform.domain}/inloggen`;
8
+ return ctx.redirect(callbackUrl);
9
+ }
10
+ catch (error) {
11
+ console.log('Activate User Error', error, ctx);
12
+ return ctx.unauthorized('User is already confirmed or token is invalid');
13
+ }
14
+ },
15
+ removeInactiveUsers(ctx) {
16
+ return strapi.service('plugin::page-builder.private-content').removeInactiveUsers();
17
+ }
18
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@strapi/utils");
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ exports.default = {
6
+ async generate(ctx) {
7
+ var _a;
8
+ try {
9
+ ctx.set('Content-Type', 'text/xml');
10
+ const domain = (_a = ctx.query) === null || _a === void 0 ? void 0 : _a.domain;
11
+ if (domain == null) {
12
+ return ctx.badRequest('Domain is required.');
13
+ }
14
+ const platform = await strapi.query(constants_1.PLATFORM_UID).findOne({
15
+ select: ['domain'],
16
+ where: {
17
+ domain
18
+ }
19
+ });
20
+ if (platform == null) {
21
+ return ctx.notFound('No platform found for specified domain.');
22
+ }
23
+ return strapi.service('plugin::page-builder.sitemap').generateSitemap(domain);
24
+ }
25
+ catch (error) {
26
+ throw new utils_1.errors.ApplicationError('Unknown error while generating the sitemap.');
27
+ }
28
+ }
29
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const strapi_1 = require("@strapi/strapi");
4
+ exports.default = strapi_1.factories.createCoreController('plugin::page-builder.user-category');
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../../shared/utils/constants");
4
+ const apollo_server_koa_1 = require("apollo-server-koa");
5
+ const strapi_1 = require("../utils/strapi");
6
+ const getPageByPath = (strapi) => {
7
+ const typeDefs = () => {
8
+ return `
9
+ extend type Page {
10
+ collectionType: GenericMorph
11
+ }
12
+
13
+ type Query {
14
+ getPageByPath(path: String, domain: String, publicationState: PublicationState): PageEntity
15
+ }
16
+
17
+ `;
18
+ };
19
+ const resolvers = (strapi) => {
20
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
21
+ return {
22
+ Query: {
23
+ getPageByPath: {
24
+ resolve: async (_parent, args, ctx) => {
25
+ var _a, _b, _c, _d, _e;
26
+ try {
27
+ const filteredArgs = {
28
+ filters: {
29
+ path: args.path,
30
+ platform: args.domain ? { domain: args.domain } : null
31
+ },
32
+ publicationState: args.publicationState,
33
+ locale: args.locale
34
+ };
35
+ const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
36
+ const getPage = async () => {
37
+ var _a, _b, _c;
38
+ const transformedArgs = transformArgs(filteredArgs, {
39
+ contentType: strapi.contentTypes[constants_1.PAGE_UID],
40
+ usePagination: false
41
+ });
42
+ const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
43
+ ...filteredArgs,
44
+ populate: '*'
45
+ }));
46
+ const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
47
+ args: transformedArgs,
48
+ resourceUID: constants_1.PAGE_UID
49
+ });
50
+ if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
51
+ throw new Error(ctx.koaContext.response.message);
52
+ }
53
+ 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);
54
+ const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
55
+ const addedAttributes = {
56
+ collectionType: collectionType
57
+ };
58
+ const result = {
59
+ ...entityResponse.value,
60
+ ...addedAttributes
61
+ };
62
+ return result;
63
+ };
64
+ const result = await getPage();
65
+ if (((_a = Object.values(result)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
66
+ if ((result === null || result === void 0 ? void 0 : result.path) === '404' || result.path === '500') {
67
+ return result;
68
+ }
69
+ if (!((_b = result === null || result === void 0 ? void 0 : result.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) && !(result === null || result === void 0 ? void 0 : result.isPrivate)) {
70
+ return result;
71
+ }
72
+ if ((((_c = result === null || result === void 0 ? void 0 : result.platform) === null || _c === void 0 ? void 0 : _c.isPrivate) === true && ctx.koaContext.req.headers.authorization) ||
73
+ ((result === null || result === void 0 ? void 0 : result.isPrivate) === true && ctx.koaContext.req.headers.authorization)) {
74
+ const auth = ctx.koaContext.req.headers.authorization;
75
+ const token = auth.split(' ');
76
+ const jwtService = strapi.plugin('users-permissions').service('jwt');
77
+ const decodedToken = await jwtService.verify(token[1]);
78
+ if (decodedToken) {
79
+ const user = ctx.state.user;
80
+ if (((_d = user === null || user === void 0 ? void 0 : user.platform) === null || _d === void 0 ? void 0 : _d.id) === ((_e = result === null || result === void 0 ? void 0 : result.platform) === null || _e === void 0 ? void 0 : _e.id)) {
81
+ return result;
82
+ }
83
+ }
84
+ }
85
+ return new apollo_server_koa_1.ForbiddenError('Forbidden access');
86
+ }
87
+ else {
88
+ throw new Error(ctx.koaContext.response.message);
89
+ }
90
+ }
91
+ catch (error) {
92
+ console.log('Error in [getPageByPath], args:', args, 'ERROR:', error);
93
+ throw new Error(ctx.koaContext.response.message);
94
+ }
95
+ }
96
+ }
97
+ }
98
+ };
99
+ };
100
+ const pageBuilderConfig = (0, strapi_1.getConfig)();
101
+ const resolversConfig = {
102
+ 'Query.getPageByPath': {
103
+ policies: (pageBuilderConfig === null || pageBuilderConfig === void 0 ? void 0 : pageBuilderConfig.privateContent) === true ? ['plugin::page-builder.isAuthorizedForPage'] : [],
104
+ auth: false
105
+ }
106
+ };
107
+ return {
108
+ typeDefs: typeDefs(),
109
+ resolvers: resolvers(strapi),
110
+ resolversConfig
111
+ };
112
+ };
113
+ exports.default = getPageByPath;