@webbio/strapi-plugin-page-builder 0.12.3-platform → 0.12.4-platform

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.12.3-platform",
3
+ "version": "0.12.4-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -9,7 +9,7 @@ exports.default = async ({ strapi }) => {
9
9
  const models = collectionTypesWithPageMorph.map((ct) => ct.uid);
10
10
  (_a = strapi.db) === null || _a === void 0 ? void 0 : _a.lifecycles.subscribe({
11
11
  models,
12
- async beforeUpdate(event) {
12
+ async afterUpdate(event) {
13
13
  var _a, _b, _c, _d, _e, _f;
14
14
  try {
15
15
  let { data, where } = event === null || event === void 0 ? void 0 : event.params;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ const getPageBySlug = (strapi) => {
6
+ const typeDefs = () => {
7
+ return `
8
+ extend type Page {
9
+ collectionType: GenericMorph
10
+ }
11
+
12
+ type Query {
13
+ getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
14
+ }
15
+
16
+ `;
17
+ };
18
+ const resolvers = (strapi) => {
19
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
20
+ return {
21
+ Query: {
22
+ getPageBySlug: {
23
+ resolve: async (_parent, args, ctx) => {
24
+ var _a;
25
+ try {
26
+ const filteredArgs = {
27
+ ...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
28
+ platform: { domain: args._domain }
29
+ };
30
+ const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
31
+ const getPage = async () => {
32
+ var _a, _b, _c;
33
+ const transformedArgs = transformArgs(filteredArgs, {
34
+ contentType: strapi.contentTypes[constants_1.PAGE_UID],
35
+ usePagination: false
36
+ });
37
+ const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
38
+ filters: filteredArgs,
39
+ locale: args._locale,
40
+ publicationState: args._publicationState,
41
+ populate: '*'
42
+ }));
43
+ const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
44
+ args: transformedArgs,
45
+ resourceUID: constants_1.PAGE_UID
46
+ });
47
+ if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
48
+ throw new Error(ctx.koaContext.response.message);
49
+ }
50
+ 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);
51
+ const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
52
+ const addedAttributes = {
53
+ collectionType: collectionType
54
+ };
55
+ const result = {
56
+ ...entityResponse.value,
57
+ ...addedAttributes
58
+ };
59
+ return result;
60
+ };
61
+ const results = await getPage();
62
+ if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
63
+ return results;
64
+ }
65
+ else {
66
+ throw new Error(ctx.koaContext.response.message);
67
+ }
68
+ }
69
+ catch (error) {
70
+ console.log('Error in getPageBySlug:', error);
71
+ throw new Error(ctx.koaContext.response.message);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ };
77
+ };
78
+ const resolversConfig = {
79
+ 'Query.getPageBySlug': {
80
+ auth: false
81
+ }
82
+ };
83
+ return {
84
+ typeDefs: typeDefs(),
85
+ resolvers: resolvers(strapi),
86
+ resolversConfig
87
+ };
88
+ };
89
+ exports.default = getPageBySlug;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerGraphQLResolvers = void 0;
4
+ const constants_1 = require("../../shared/utils/constants");
5
+ const findPageByPath = (strapi) => {
6
+ const typeDefs = `
7
+ type Query {
8
+ findPageByPath(path: String, locale: I18NLocaleCode): PageEntityResponse
9
+ }
10
+ `;
11
+ const resolvers = (strapi) => {
12
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
13
+ const { toEntityResponse, toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
14
+ return {
15
+ Query: {
16
+ findPageByPath: {
17
+ resolve: async (parent, args, ctx) => {
18
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
19
+ const transformedArgs = transformArgs(args, { contentType });
20
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
21
+ filters: {
22
+ path: {
23
+ $eq: transformedArgs.path
24
+ }
25
+ },
26
+ locale: transformedArgs.locale
27
+ });
28
+ const result = queryResult === null || queryResult === void 0 ? void 0 : queryResult[0];
29
+ return toEntityResponse(result, {
30
+ args: transformedArgs,
31
+ resourceUID: contentType.uid
32
+ });
33
+ }
34
+ }
35
+ }
36
+ };
37
+ };
38
+ const resolversConfig = {
39
+ 'Query.findPageByPath': {
40
+ auth: false
41
+ }
42
+ };
43
+ return {
44
+ typeDefs,
45
+ resolvers: resolvers(strapi),
46
+ resolversConfig
47
+ };
48
+ };
49
+ const findPagePaths = (strapi) => {
50
+ const typeDefs = `
51
+ type PageByPath {
52
+ id: Int!
53
+ path: String!
54
+ title: String!
55
+ locale: String!
56
+ pageType: ENUM_PAGE_PAGETYPE
57
+ updatedAt: DateTime!
58
+ publishedAt: DateTime!
59
+ }
60
+
61
+ type Query {
62
+ findPagePaths(locale: String, pageType: String = "all"): [PageByPath]
63
+ }
64
+ `;
65
+ const resolvers = (strapi) => {
66
+ const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
67
+ return {
68
+ Query: {
69
+ findPagePaths: {
70
+ resolve: async (parent, args, ctx) => {
71
+ const contentType = strapi.getModel(constants_1.PAGE_UID);
72
+ const transformedArgs = transformArgs(args, { contentType });
73
+ const queryResult = await strapi.entityService.findMany(contentType.uid, {
74
+ populate: '*',
75
+ locale: transformedArgs.locale
76
+ });
77
+ const result = queryResult.filter((page) => page === null || page === void 0 ? void 0 : page.path);
78
+ return result;
79
+ }
80
+ }
81
+ }
82
+ };
83
+ };
84
+ const resolversConfig = {
85
+ 'Query.findPagePaths': {
86
+ auth: false
87
+ }
88
+ };
89
+ return {
90
+ typeDefs,
91
+ resolvers: resolvers(strapi),
92
+ resolversConfig
93
+ };
94
+ };
95
+ const registerGraphQLResolvers = (strapi) => {
96
+ const extensionService = strapi.plugin('graphql').service('extension');
97
+ extensionService.use(findPageByPath(strapi));
98
+ extensionService.use(findPagePaths(strapi));
99
+ };
100
+ exports.registerGraphQLResolvers = registerGraphQLResolvers;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pagination = void 0;
4
+ class Pagination {
5
+ static checkPagination(page, pageSize) {
6
+ const startPage = page === 1 ? 0 : page - 1;
7
+ const start = startPage * pageSize;
8
+ const limit = (startPage + 1) * pageSize;
9
+ return { start, limit };
10
+ }
11
+ static async getPaginationInfo(transformedpageArgs, transformArgs, start, pageSize, entityResponse, uid) {
12
+ var _a;
13
+ const total = await ((_a = strapi === null || strapi === void 0 ? void 0 : strapi.entityService) === null || _a === void 0 ? void 0 : _a.count(uid, {
14
+ filters: {
15
+ ...transformArgs.filters,
16
+ hasPage: { $eq: true },
17
+ page: { ...transformedpageArgs.filters }
18
+ }
19
+ }));
20
+ const pageCount = Math.ceil(total / pageSize);
21
+ const page = Math.floor(start / pageSize) + 1;
22
+ entityResponse.metaInfo = {
23
+ total,
24
+ pageCount,
25
+ page,
26
+ pageSize
27
+ };
28
+ return entityResponse;
29
+ }
30
+ }
31
+ exports.Pagination = Pagination;