@webbio/strapi-plugin-page-builder 0.14.1-platform → 0.15.0-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.
@@ -1,10 +1,10 @@
1
1
  import { useQuery, UseQueryOptions } from 'react-query';
2
- import orderBy from 'lodash/orderBy';
3
2
  import objGet from 'lodash/get';
4
3
 
5
4
  import { useFetchClient } from '@strapi/helper-plugin';
6
5
  import qs from 'qs';
7
- import { getConditionalFilters } from '../components/PlatformFilteredSelectField/utils/get-condition-filters';
6
+
7
+ import Fuse from 'fuse.js';
8
8
 
9
9
  export type SearchFilteredEntitiesResult = {
10
10
  pagination: {
@@ -81,32 +81,44 @@ export const getSearchFilteredEntities = async ({
81
81
  });
82
82
 
83
83
  const { data } = await get(`/content-manager/collection-types/${uid}?${filters}`);
84
- const mapResults = data.results.map(
85
- (result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
86
- const getPublicationState = () => {
87
- if (result?.publishedAt !== undefined) {
88
- return result?.publishedAt ? 'published' : 'draft';
89
- }
90
-
91
- return false;
92
- };
93
-
94
- const subTitle = subTitlePath ? objGet(result, subTitlePath) : undefined;
95
-
96
- return {
97
- id: result.id,
98
- title: result?.[mainFieldName],
99
- publicationState: getPublicationState(),
100
- publishedAt: result?.publishedAt,
101
- href: `/content-manager/collectionType/${uid}/${result.id}`,
102
- subTitle: typeof subTitle === 'string' || typeof subTitle === 'number' ? String(subTitle) : ''
103
- };
84
+ let results = data.results;
85
+
86
+ if (searchQuery) {
87
+ const fuse = new Fuse(data.results, {
88
+ keys: searchableFields
89
+ });
90
+
91
+ const fuseSearch = fuse.search(searchQuery);
92
+
93
+ if (fuseSearch && fuseSearch.length > 0) {
94
+ results = fuseSearch.map((r) => r.item);
104
95
  }
105
- );
96
+ }
97
+
98
+ const mapResults = results.map((result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
99
+ const getPublicationState = () => {
100
+ if (result?.publishedAt !== undefined) {
101
+ return result?.publishedAt ? 'published' : 'draft';
102
+ }
103
+
104
+ return false;
105
+ };
106
+
107
+ const subTitle = subTitlePath ? objGet(result, subTitlePath) : undefined;
108
+
109
+ return {
110
+ id: result.id,
111
+ title: result?.[mainFieldName],
112
+ publicationState: getPublicationState(),
113
+ publishedAt: result?.publishedAt,
114
+ href: `/content-manager/collectionType/${uid}/${result.id}`,
115
+ subTitle: typeof subTitle === 'string' || typeof subTitle === 'number' ? String(subTitle) : ''
116
+ };
117
+ });
106
118
 
107
119
  return {
108
120
  pagination: data.pagination,
109
- results: orderBy(mapResults, ['title'], ['asc'])
121
+ results: mapResults
110
122
  };
111
123
  } catch (e) {
112
124
  return {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.14.1-platform",
3
+ "version": "0.15.0-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -31,6 +31,7 @@
31
31
  "@strapi/utils": "^4.15.0",
32
32
  "add": "^2.0.6",
33
33
  "aws-sdk": "^2.1528.0",
34
+ "fuse.js": "^7.0.0",
34
35
  "handlebars": "^4.7.8",
35
36
  "react-select": "^5.7.4",
36
37
  "sitemap": "^7.1.1"
@@ -28,23 +28,21 @@ exports.default = async ({ strapi }) => {
28
28
  (_a = strapi.db) === null || _a === void 0 ? void 0 : _a.lifecycles.subscribe({
29
29
  models: [constants_1.USER_PERMISSION_USER_PLUGIN],
30
30
  async beforeUpdate(event) {
31
- var _a;
31
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
32
32
  if (event.params.data.id) {
33
- const originalUserObject = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
33
+ const originalUserObject = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
34
34
  populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
35
- }));
35
+ })));
36
36
  if (originalUserObject &&
37
37
  event.params.data.activateUser &&
38
38
  event.params.data.confirmed &&
39
39
  !originalUserObject.confirmMailSend) {
40
40
  await strapi.service(constants_1.PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
41
- // @ts-ignore strapi typings
42
- from: originalUserObject.platform.platformEmails.accountAcceptedMail.fromEmail,
41
+ from: (_d = (_c = (_b = originalUserObject.platform) === null || _b === void 0 ? void 0 : _b.platformEmails) === null || _c === void 0 ? void 0 : _c.accountAcceptedMail) === null || _d === void 0 ? void 0 : _d.fromEmail,
43
42
  to: event.params.data.email,
44
- // @ts-ignore
45
- subject: originalUserObject.platform.platformEmails.accountAcceptedMail.subject,
46
- // @ts-ignore
47
- text: originalUserObject.platform.platformEmails.accountAcceptedMail.message,
43
+ nameSender: (_g = (_f = (_e = originalUserObject.platform) === null || _e === void 0 ? void 0 : _e.platformEmails) === null || _f === void 0 ? void 0 : _f.accountAcceptedMail) === null || _g === void 0 ? void 0 : _g.nameSender,
44
+ subject: (_k = (_j = (_h = originalUserObject.platform) === null || _h === void 0 ? void 0 : _h.platformEmails) === null || _j === void 0 ? void 0 : _j.accountAcceptedMail) === null || _k === void 0 ? void 0 : _k.subject,
45
+ text: (_o = (_m = (_l = originalUserObject.platform) === null || _l === void 0 ? void 0 : _l.platformEmails) === null || _m === void 0 ? void 0 : _m.accountAcceptedMail) === null || _o === void 0 ? void 0 : _o.message,
48
46
  firstName: event.params.data.firstName,
49
47
  lastName: event.params.data.lastName
50
48
  });
@@ -29,12 +29,13 @@ const constants_1 = require("../../shared/utils/constants");
29
29
  const utils_1 = require("@strapi/utils");
30
30
  exports.default = {
31
31
  async sendMail(options) {
32
- const { from, to, subject, text, variables } = options;
32
+ const { from, to, subject, text, variables, nameSender } = options;
33
33
  const emailData = (0, txtMail_email_template_text_1.txtEmail)(text, variables);
34
+ const Source = nameSender ? `${nameSender} <${from}>` : from;
34
35
  try {
35
36
  const client = new AWS.SES();
36
37
  await client.sendEmail({
37
- Source: from,
38
+ Source,
38
39
  Destination: {
39
40
  ToAddresses: [to]
40
41
  },
@@ -52,17 +53,16 @@ exports.default = {
52
53
  }
53
54
  },
54
55
  async sendAdminMail(user) {
55
- const foundUser = await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
56
+ var _a, _b, _c;
57
+ const foundUser = (await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
56
58
  populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
57
- });
59
+ }));
60
+ console.log('HI', (_c = (_b = (_a = foundUser === null || foundUser === void 0 ? void 0 : foundUser.platform) === null || _a === void 0 ? void 0 : _a.platformEmails) === null || _b === void 0 ? void 0 : _b.adminEmail) === null || _c === void 0 ? void 0 : _c.fromEmail);
58
61
  await this.sendMail({
59
- // @ts-ignore we all love strapi typings
60
62
  from: foundUser.platform.platformEmails.adminEmail.fromEmail,
61
- // @ts-ignore
62
63
  to: foundUser.platform.platformEmails.adminEmail.toEmail,
63
- // @ts-ignore
64
+ nameSender: user.platform.platformEmails.adminEmail.nameSender,
64
65
  subject: foundUser.platform.platformEmails.adminEmail.subject,
65
- // @ts-ignore
66
66
  text: foundUser.platform.platformEmails.adminEmail.message,
67
67
  variables: {
68
68
  firstName: user.firstName,
@@ -71,33 +71,24 @@ exports.default = {
71
71
  });
72
72
  },
73
73
  async sendConfirmationEmail(user) {
74
- const foundUser = await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
74
+ const foundUser = (await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
75
75
  populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
76
- });
76
+ }));
77
77
  if (foundUser && foundUser.platform) {
78
78
  const jwtService = strapi.plugin('users-permissions').service('jwt');
79
- const confirmationToken = await jwtService.issue(
80
- // @ts-ignore
81
- { userId: user.id, platformId: foundUser.platform.id }, { expiresIn: '1d' });
79
+ const confirmationToken = await jwtService.issue({ userId: user.id, platformId: foundUser.platform.id }, { expiresIn: '1d' });
82
80
  await strapi.entityService.update(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
83
- // @ts-ignore
84
81
  data: { confirmationToken: confirmationToken }
85
82
  });
86
- // @ts-ignore
87
83
  const confirmEmailUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
88
84
  await this.sendMail({
89
- // @ts-ignore
90
85
  from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
91
- // @ts-ignore
92
86
  to: foundUser.email,
93
- // @ts-ignore
87
+ nameSender: user.platform.platformEmails.accountCreatedMail.nameSender,
94
88
  subject: foundUser.platform.platformEmails.accountCreatedMail.subject,
95
- // @ts-ignore
96
89
  text: foundUser.platform.platformEmails.accountCreatedMail.message,
97
90
  variables: {
98
- // @ts-ignore
99
91
  firstName: foundUser.firstName,
100
- // @ts-ignore
101
92
  lastName: foundUser.lastName,
102
93
  confirmEmailUrl
103
94
  }
@@ -109,18 +100,14 @@ exports.default = {
109
100
  const jwtService = strapi.plugin('users-permissions').service('jwt');
110
101
  const resetPasswordToken = await jwtService.issue({ userId: user.id, platformId: user.platform.id }, { expiresIn: '1d' });
111
102
  await strapi.entityService.update(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
112
- // @ts-ignore
113
103
  data: { resetPasswordToken }
114
104
  });
115
- // @ts-ignore
116
- const resetPasswordUrl = `${user.platform.domain}/wachtwoord-resetten/${resetPasswordToken}`;
105
+ const resetPasswordUrl = getResetPasswordUrl(user, resetPasswordToken);
117
106
  await this.sendMail({
118
- // @ts-ignore
119
107
  from: user.platform.platformEmails.resetPasswordMail.fromEmail,
120
108
  to: user.email,
121
- // @ts-ignore
109
+ nameSender: user.platform.platformEmails.resetPasswordMail.nameSender,
122
110
  subject: user.platform.platformEmails.resetPasswordMail.subject,
123
- // @ts-ignore
124
111
  text: user.platform.platformEmails.resetPasswordMail.message,
125
112
  variables: {
126
113
  firstName: user === null || user === void 0 ? void 0 : user.firstName,
@@ -131,3 +118,16 @@ exports.default = {
131
118
  }
132
119
  }
133
120
  };
121
+ const getResetPasswordUrl = (user, resetPasswordToken) => {
122
+ if (!user || !(user === null || user === void 0 ? void 0 : user.platform)) {
123
+ return '';
124
+ }
125
+ if (user.platform.platformEmails.resetPasswordUrl &&
126
+ user.platform.platformEmails.resetPasswordUrl.includes('{{resetPasswordToken}}')) {
127
+ const replacedTokens = user.platform.platformEmails.resetPasswordUrl
128
+ .replace('{{domain}}', user.platform.domain)
129
+ .replace('{{resetPasswordToken}}', resetPasswordToken);
130
+ return replacedTokens;
131
+ }
132
+ return `${user.platform.domain}/wachtwoord-resetten/${resetPasswordToken}`;
133
+ };
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.platformForgotPassword = void 0;
4
- const utils_1 = require("@strapi/utils");
5
4
  const constants_1 = require("../../constants");
6
5
  const schemas_1 = require("../../schemas");
7
- const { UnauthorizedError } = utils_1.errors;
8
6
  exports.platformForgotPassword = {
9
7
  async resolve(parent, args, context) {
10
8
  await (0, schemas_1.validateForgotPasswordSchema)(args.input);