strapi-plugin-comments 2.0.10 → 2.1.0-beta.1

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 (266) hide show
  1. package/README.md +164 -120
  2. package/admin/src/components/ActionButton/styles.d.ts +2 -0
  3. package/admin/src/components/ActionButton/styles.js +13 -8
  4. package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  5. package/admin/src/components/ConfirmationDialog/index.js +36 -55
  6. package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  7. package/admin/src/components/DiscussionStatus/index.js +22 -31
  8. package/admin/src/components/DiscussionThread/index.d.ts +16 -0
  9. package/admin/src/components/DiscussionThread/index.js +39 -56
  10. package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  11. package/admin/src/components/DiscussionThreadItem/index.js +28 -52
  12. package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  13. package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
  14. package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  15. package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
  16. package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  17. package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
  18. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  19. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
  20. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  21. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
  22. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  23. package/admin/src/components/DiscussionThreadItemFooter/index.js +35 -42
  24. package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  25. package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
  26. package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  27. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
  28. package/admin/src/components/FormSwitch/index.d.ts +7 -0
  29. package/admin/src/components/FormSwitch/index.js +15 -18
  30. package/admin/src/components/FormSwitch/styles.d.ts +2 -0
  31. package/admin/src/components/FormSwitch/styles.js +14 -8
  32. package/admin/src/components/IconButton/styles.d.ts +2 -0
  33. package/admin/src/components/IconButton/styles.js +16 -9
  34. package/admin/src/components/Initializer/index.d.ts +5 -0
  35. package/admin/src/components/Initializer/index.js +12 -24
  36. package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  37. package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
  38. package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  39. package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
  40. package/admin/src/components/Nav/index.d.ts +7 -0
  41. package/admin/src/components/Nav/index.js +25 -48
  42. package/admin/src/components/PluginIcon/index.d.ts +3 -0
  43. package/admin/src/components/PluginIcon/index.js +10 -12
  44. package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  45. package/admin/src/components/ReportsReviewModal/index.js +31 -46
  46. package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  47. package/admin/src/components/ReportsReviewTable/index.js +120 -140
  48. package/admin/src/components/StatusBadge/index.d.ts +7 -0
  49. package/admin/src/components/StatusBadge/index.js +12 -17
  50. package/admin/src/components/StatusBadge/styles.d.ts +2 -0
  51. package/admin/src/components/StatusBadge/styles.js +19 -13
  52. package/admin/src/components/TableFilters/index.d.ts +10 -0
  53. package/admin/src/components/TableFilters/index.js +52 -49
  54. package/admin/src/components/TablePagination/index.d.ts +17 -0
  55. package/admin/src/components/TablePagination/index.js +27 -29
  56. package/admin/src/components/icons/comments.d.ts +6 -0
  57. package/admin/src/components/icons/comments.js +11 -8
  58. package/admin/src/components/icons/index.d.ts +6 -0
  59. package/admin/src/components/icons/index.js +15 -6
  60. package/admin/src/components/icons/lock.d.ts +7 -0
  61. package/admin/src/components/icons/lock.js +11 -21
  62. package/admin/src/components/icons/review.d.ts +7 -0
  63. package/admin/src/components/icons/review.js +11 -17
  64. package/admin/src/components/icons/unlock.d.ts +7 -0
  65. package/admin/src/components/icons/unlock.js +11 -19
  66. package/admin/src/hooks/useConfig.d.ts +8 -0
  67. package/admin/src/hooks/useConfig.js +40 -45
  68. package/admin/src/index.d.ts +7 -0
  69. package/admin/src/index.js +98 -92
  70. package/admin/src/pages/App/index.d.ts +4 -0
  71. package/admin/src/pages/App/index.js +43 -67
  72. package/admin/src/pages/App/reducer/actions.d.ts +8 -0
  73. package/admin/src/pages/App/reducer/actions.js +11 -7
  74. package/admin/src/pages/App/reducer/constants.d.ts +4 -0
  75. package/admin/src/pages/App/reducer/constants.js +7 -4
  76. package/admin/src/pages/App/reducer/index.d.ts +9 -0
  77. package/admin/src/pages/App/reducer/index.js +24 -22
  78. package/admin/src/pages/App/reducer/init.d.ts +3 -0
  79. package/admin/src/pages/App/reducer/init.js +6 -4
  80. package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  81. package/admin/src/pages/App/reducer/selectors.js +17 -34
  82. package/admin/src/pages/App/utils/api.d.ts +2 -0
  83. package/admin/src/pages/App/utils/api.js +14 -11
  84. package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  85. package/admin/src/pages/ComingSoonPage/index.js +42 -24
  86. package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  87. package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
  88. package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  89. package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
  90. package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  91. package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
  92. package/admin/src/pages/Details/index.d.ts +4 -0
  93. package/admin/src/pages/Details/index.js +94 -133
  94. package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  95. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
  96. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  97. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
  98. package/admin/src/pages/Discover/index.d.ts +4 -0
  99. package/admin/src/pages/Discover/index.js +129 -170
  100. package/admin/src/pages/Discover/utils/api.d.ts +2 -0
  101. package/admin/src/pages/Discover/utils/api.js +15 -13
  102. package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  103. package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
  104. package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  105. package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
  106. package/admin/src/pages/Settings/index.d.ts +3 -0
  107. package/admin/src/pages/Settings/index.js +225 -391
  108. package/admin/src/pages/Settings/utils/api.d.ts +7 -0
  109. package/admin/src/pages/Settings/utils/api.js +60 -55
  110. package/admin/src/pages/utils/api.d.ts +12 -0
  111. package/admin/src/pages/utils/api.js +58 -53
  112. package/admin/src/permissions.d.ts +28 -0
  113. package/admin/src/permissions.js +31 -17
  114. package/admin/src/pluginId.d.ts +2 -0
  115. package/admin/src/pluginId.js +29 -5
  116. package/admin/src/reducers.d.ts +7 -0
  117. package/admin/src/reducers.js +10 -6
  118. package/admin/src/translations/en.json +131 -131
  119. package/admin/src/translations/fr.json +1 -1
  120. package/admin/src/utils/axiosInstance.d.ts +3 -0
  121. package/admin/src/utils/axiosInstance.js +21 -27
  122. package/admin/src/utils/constants.d.ts +25 -0
  123. package/admin/src/utils/constants.js +23 -22
  124. package/admin/src/utils/getApiUrl.d.ts +3 -0
  125. package/admin/src/utils/getApiUrl.js +6 -5
  126. package/admin/src/utils/getMessage.d.ts +4 -0
  127. package/admin/src/utils/getMessage.js +15 -15
  128. package/admin/src/utils/getRelatedGroups.d.ts +4 -0
  129. package/admin/src/utils/getRelatedGroups.js +5 -3
  130. package/admin/src/utils/getUrl.d.ts +3 -0
  131. package/admin/src/utils/getUrl.js +6 -5
  132. package/admin/src/utils/handleAPIError.d.ts +4 -0
  133. package/admin/src/utils/handleAPIError.js +12 -11
  134. package/admin/src/utils/index.d.ts +12 -0
  135. package/admin/src/utils/index.js +29 -11
  136. package/admin/src/utils/parseRegExp.d.ts +6 -0
  137. package/admin/src/utils/parseRegExp.js +6 -5
  138. package/admin/src/utils/renderEntryTitle.d.ts +4 -0
  139. package/admin/src/utils/renderEntryTitle.js +11 -12
  140. package/admin/src/utils/renderInitials.d.ts +3 -0
  141. package/admin/src/utils/renderInitials.js +10 -5
  142. package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  143. package/admin/src/utils/resolveCommentStatus.js +17 -21
  144. package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  145. package/admin/src/utils/resolveCommentStatusColor.js +19 -19
  146. package/content-types/comment.d.ts +91 -0
  147. package/content-types/comment.js +87 -88
  148. package/content-types/index.d.ts +143 -0
  149. package/content-types/index.js +15 -10
  150. package/content-types/report.d.ts +48 -0
  151. package/content-types/report.js +44 -49
  152. package/package.json +24 -19
  153. package/permissions.d.ts +18 -0
  154. package/permissions.js +12 -13
  155. package/server/bootstrap.d.ts +4 -0
  156. package/server/bootstrap.js +56 -62
  157. package/server/config/index.d.ts +4 -0
  158. package/server/config/index.js +17 -15
  159. package/server/controllers/admin.d.ts +4 -0
  160. package/server/controllers/admin.js +134 -167
  161. package/server/controllers/client.d.ts +4 -0
  162. package/server/controllers/client.js +104 -112
  163. package/server/controllers/index.d.ts +6 -0
  164. package/server/controllers/index.js +12 -8
  165. package/server/controllers/utils/functions.d.ts +7 -0
  166. package/server/controllers/utils/functions.js +22 -17
  167. package/server/controllers/utils/parsers.d.ts +15 -0
  168. package/server/controllers/utils/parsers.js +17 -17
  169. package/server/destroy.d.ts +3 -0
  170. package/server/destroy.js +3 -4
  171. package/server/graphql/index.d.ts +4 -0
  172. package/server/graphql/index.js +27 -25
  173. package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  174. package/server/graphql/mutations/createAbuseReport.js +22 -24
  175. package/server/graphql/mutations/createComment.d.ts +14 -0
  176. package/server/graphql/mutations/createComment.js +22 -24
  177. package/server/graphql/mutations/index.d.ts +4 -0
  178. package/server/graphql/mutations/index.js +24 -19
  179. package/server/graphql/mutations/removeComment.d.ts +11 -0
  180. package/server/graphql/mutations/removeComment.js +22 -24
  181. package/server/graphql/mutations/updateComment.d.ts +11 -0
  182. package/server/graphql/mutations/updateComment.js +22 -24
  183. package/server/graphql/queries/findAllFlat.d.ts +19 -0
  184. package/server/graphql/queries/findAllFlat.js +31 -34
  185. package/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
  186. package/server/graphql/queries/findAllInHierarchy.js +26 -30
  187. package/server/graphql/queries/index.d.ts +4 -0
  188. package/server/graphql/queries/index.js +20 -17
  189. package/server/graphql/resolvers-config.d.ts +23 -0
  190. package/server/graphql/resolvers-config.js +11 -11
  191. package/server/graphql/types/comment-author.d.ts +4 -0
  192. package/server/graphql/types/comment-author.js +10 -8
  193. package/server/graphql/types/comment-nested.d.ts +4 -0
  194. package/server/graphql/types/comment-nested.js +17 -15
  195. package/server/graphql/types/comment.d.ts +4 -0
  196. package/server/graphql/types/comment.js +16 -14
  197. package/server/graphql/types/create-comment-author.d.ts +4 -0
  198. package/server/graphql/types/create-comment-author.js +10 -8
  199. package/server/graphql/types/create-comment.d.ts +4 -0
  200. package/server/graphql/types/create-comment.js +10 -8
  201. package/server/graphql/types/create-report.d.ts +4 -0
  202. package/server/graphql/types/create-report.js +10 -8
  203. package/server/graphql/types/id.d.ts +4 -0
  204. package/server/graphql/types/id.js +24 -23
  205. package/server/graphql/types/identify-comment-author.d.ts +4 -0
  206. package/server/graphql/types/identify-comment-author.js +7 -5
  207. package/server/graphql/types/index.d.ts +4 -0
  208. package/server/graphql/types/index.js +36 -17
  209. package/server/graphql/types/remove-comment.d.ts +4 -0
  210. package/server/graphql/types/remove-comment.js +9 -7
  211. package/server/graphql/types/report-reason.d.ts +4 -0
  212. package/server/graphql/types/report-reason.js +10 -8
  213. package/server/graphql/types/report.d.ts +4 -0
  214. package/server/graphql/types/report.js +12 -10
  215. package/server/graphql/types/response-find-all.d.ts +4 -0
  216. package/server/graphql/types/response-find-all.js +8 -6
  217. package/server/graphql/types/response-meta.d.ts +4 -0
  218. package/server/graphql/types/response-meta.js +7 -5
  219. package/server/graphql/types/response-pagination.d.ts +4 -0
  220. package/server/graphql/types/response-pagination.js +12 -10
  221. package/server/graphql/types/update-comment.d.ts +4 -0
  222. package/server/graphql/types/update-comment.js +10 -8
  223. package/server/index.d.ts +26 -0
  224. package/server/index.js +24 -21
  225. package/server/register.d.ts +3 -0
  226. package/server/register.js +3 -4
  227. package/server/routes/admin.d.ts +4 -0
  228. package/server/routes/admin.js +103 -109
  229. package/server/routes/client.d.ts +4 -0
  230. package/server/routes/client.js +48 -46
  231. package/server/routes/index.d.ts +11 -0
  232. package/server/routes/index.js +18 -14
  233. package/server/services/admin.d.ts +5 -0
  234. package/server/services/admin.js +126 -158
  235. package/server/services/client.d.ts +5 -0
  236. package/server/services/client.js +135 -151
  237. package/server/services/common.d.ts +5 -0
  238. package/server/services/common.js +165 -194
  239. package/server/services/graphql.d.ts +5 -0
  240. package/server/services/graphql.js +117 -182
  241. package/server/services/index.d.ts +8 -0
  242. package/server/services/index.js +15 -12
  243. package/server/services/utils/functions.d.ts +13 -0
  244. package/server/services/utils/functions.js +100 -109
  245. package/server/utils/constants.d.ts +9 -0
  246. package/server/utils/constants.js +19 -23
  247. package/server/utils/error.d.ts +19 -0
  248. package/server/utils/error.js +23 -18
  249. package/server/utils/functions.d.ts +6 -0
  250. package/server/utils/functions.js +35 -18
  251. package/strapi-admin.d.ts +3 -0
  252. package/strapi-admin.js +8 -3
  253. package/strapi-server.d.ts +177 -0
  254. package/strapi-server.js +43 -46
  255. package/tsconfig.tsbuildinfo +1 -0
  256. package/types/contentTypes.d.ts +44 -0
  257. package/types/contentTypes.js +3 -0
  258. package/.husky/pre-commit +0 -4
  259. package/LICENSE.md +0 -7
  260. package/__mocks__/initSetup.js +0 -108
  261. package/jest.config.js +0 -7
  262. package/server/controllers/utils/__tests__/functions.test.js +0 -43
  263. package/server/controllers/utils/__tests__/parsers.test.js +0 -94
  264. package/server/services/__tests__/common.test.js +0 -399
  265. package/server/services/utils/__tests__/functions.test.js +0 -53
  266. package/server/utils/__tests__/functions.test.js +0 -17
@@ -1,190 +1,125 @@
1
- 'use strict';
2
-
3
- const { has, propEq, isNil, isDate, isObject } = require('lodash/fp');
4
- const { inputObjectType } = require('nexus');
5
-
6
- const virtualScalarAttributes = ['id'];
7
-
1
+ "use strict";
2
+ const fp_1 = require("lodash/fp");
3
+ const nexus_1 = require("nexus");
4
+ const virtualScalarAttributes = ["id"];
8
5
  module.exports = ({ strapi }) => {
9
- const { service: getService } = strapi.plugin('graphql');
10
-
11
- const rootLevelOperators = () => {
12
- const { operators } = strapi.plugin('graphql').service('builders').filters;
13
-
14
- return [operators.and, operators.or, operators.not];
15
- };
16
-
17
- const buildContentTypeFilters = contentType => {
18
- const utils = strapi.plugin('graphql').service('utils');
19
- const extension = strapi.plugin('graphql').service('extension');
20
-
21
- const { getFiltersInputTypeName, getScalarFilterInputTypeName } = utils.naming;
22
- const { isStrapiScalar, isRelation } = utils.attributes;
23
-
24
- const { attributes } = contentType;
25
-
26
- const filtersTypeName = getFiltersInputTypeName(contentType);
27
-
28
- return inputObjectType({
29
- name: filtersTypeName,
30
-
31
- definition(t) {
32
- const validAttributes = Object.entries(attributes).filter(([attributeName]) =>
33
- extension
34
- .shadowCRUD(contentType.uid)
35
- .field(attributeName)
36
- .hasFiltersEnabeld()
37
- );
38
-
39
- const isIDFilterEnabled = extension
40
- .shadowCRUD(contentType.uid)
41
- .field('id')
42
- .hasFiltersEnabeld();
43
- // Add an ID filter to the collection types
44
- if (contentType.kind === 'collectionType' && isIDFilterEnabled) {
45
- t.field('id', { type: getScalarFilterInputTypeName('ID') });
6
+ const { service: getService } = strapi.plugin("graphql");
7
+ const rootLevelOperators = () => {
8
+ const { operators } = strapi.plugin("graphql").service("builders").filters;
9
+ return [operators.and, operators.or, operators.not];
10
+ };
11
+ const buildContentTypeFilters = (contentType) => {
12
+ const utils = strapi.plugin("graphql").service("utils");
13
+ const extension = strapi.plugin("graphql").service("extension");
14
+ const { getFiltersInputTypeName, getScalarFilterInputTypeName } = utils.naming;
15
+ const { isStrapiScalar, isRelation } = utils.attributes;
16
+ const { attributes } = contentType;
17
+ const filtersTypeName = getFiltersInputTypeName(contentType);
18
+ return (0, nexus_1.inputObjectType)({
19
+ name: filtersTypeName,
20
+ definition(t) {
21
+ const validAttributes = Object.entries(attributes).filter(([attributeName]) => extension
22
+ .shadowCRUD(contentType.uid)
23
+ .field(attributeName)
24
+ .hasFiltersEnabeld());
25
+ const isIDFilterEnabled = extension
26
+ .shadowCRUD(contentType.uid)
27
+ .field("id")
28
+ .hasFiltersEnabeld();
29
+ if (contentType.kind === "collectionType" && isIDFilterEnabled) {
30
+ t.field("id", { type: getScalarFilterInputTypeName("ID") });
31
+ }
32
+ for (const [attributeName, attribute] of validAttributes) {
33
+ if (isStrapiScalar(attribute)) {
34
+ addScalarAttribute(t, attributeName, attribute);
35
+ }
36
+ else if (isRelation(attribute)) {
37
+ addRelationalAttribute(t, attributeName, attribute);
38
+ }
39
+ }
40
+ for (const operator of rootLevelOperators()) {
41
+ operator.add(t, filtersTypeName);
42
+ }
43
+ },
44
+ });
45
+ };
46
+ const addScalarAttribute = (builder, attributeName, attribute) => {
47
+ const { naming, mappers } = strapi.plugin("graphql").service("utils");
48
+ const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
49
+ builder.field(attributeName, {
50
+ type: naming.getScalarFilterInputTypeName(gqlType),
51
+ });
52
+ };
53
+ const addRelationalAttribute = (builder, attributeName, attribute) => {
54
+ const utils = strapi.plugin("graphql").service("utils");
55
+ const extension = strapi.plugin("graphql").service("extension");
56
+ const { getFiltersInputTypeName } = utils.naming;
57
+ const { isMorphRelation } = utils.attributes;
58
+ const model = strapi.getModel(attribute.target);
59
+ if (!model || isMorphRelation(attribute))
60
+ return;
61
+ if (extension.shadowCRUD(model.uid).isDisabled())
62
+ return;
63
+ builder.field(attributeName, { type: getFiltersInputTypeName(model) });
64
+ };
65
+ const recursivelyReplaceScalarOperators = (data) => {
66
+ const { operators } = getService("builders").filters;
67
+ if (Array.isArray(data)) {
68
+ return data.map(recursivelyReplaceScalarOperators);
46
69
  }
47
-
48
- // Add every defined attribute
49
- for (const [attributeName, attribute] of validAttributes) {
50
- // Handle scalars
51
- if (isStrapiScalar(attribute)) {
52
- addScalarAttribute(t, attributeName, attribute);
53
- }
54
-
55
- // Handle relations
56
- else if (isRelation(attribute)) {
57
- addRelationalAttribute(t, attributeName, attribute);
58
- }
70
+ if ((0, fp_1.isDate)(data) || !(0, fp_1.isObject)(data)) {
71
+ return data;
59
72
  }
60
-
61
- // Conditional clauses
62
- for (const operator of rootLevelOperators()) {
63
- operator.add(t, filtersTypeName);
73
+ const result = {};
74
+ for (const [key, value] of Object.entries(data)) {
75
+ const isOperator = !!operators[key];
76
+ const newKey = isOperator ? operators[key].strapiOperator : key;
77
+ result[newKey] = recursivelyReplaceScalarOperators(value);
64
78
  }
65
- },
66
- });
67
- };
68
-
69
- const addScalarAttribute = (builder, attributeName, attribute) => {
70
- const { naming, mappers } = strapi.plugin('graphql').service('utils');
71
-
72
- const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
73
-
74
- builder.field(attributeName, { type: naming.getScalarFilterInputTypeName(gqlType) });
75
- };
76
-
77
- const addRelationalAttribute = (builder, attributeName, attribute) => {
78
- const utils = strapi.plugin('graphql').service('utils');
79
- const extension = strapi.plugin('graphql').service('extension');
80
- const { getFiltersInputTypeName } = utils.naming;
81
- const { isMorphRelation } = utils.attributes;
82
-
83
- const model = strapi.getModel(attribute.target);
84
-
85
- // If there is no model corresponding to the attribute configuration
86
- // or if the attribute is a polymorphic relation, then ignore it
87
- if (!model || isMorphRelation(attribute)) return;
88
-
89
- // If the target model is disabled, then ignore it too
90
- if (extension.shadowCRUD(model.uid).isDisabled()) return;
91
-
92
- builder.field(attributeName, { type: getFiltersInputTypeName(model) });
93
- };
94
-
95
- const recursivelyReplaceScalarOperators = data => {
96
- const { operators } = getService('builders').filters;
97
-
98
- if (Array.isArray(data)) {
99
- return data.map(recursivelyReplaceScalarOperators);
100
- }
101
-
102
- // Note: We need to make an exception for date since GraphQL
103
- // automatically cast date strings to date instances in args
104
- if (isDate(data) || !isObject(data)) {
105
- return data;
106
- }
107
-
108
- const result = {};
109
-
110
- for (const [key, value] of Object.entries(data)) {
111
- const isOperator = !!operators[key];
112
-
113
- const newKey = isOperator ? operators[key].strapiOperator : key;
114
-
115
- result[newKey] = recursivelyReplaceScalarOperators(value);
116
- }
117
-
118
- return result;
119
- };
120
-
121
- const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
122
- const { isStrapiScalar, isMedia, isRelation } = getService('utils').attributes;
123
- const { operators } = getService('builders').filters;
124
-
125
- const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
126
-
127
- // Handle unwanted scenario where there is no filters defined
128
- if (isNil(filters)) {
129
- return {};
130
- }
131
-
132
- // If filters is a collection, then apply the transformation to every item of the list
133
- if (Array.isArray(filters)) {
134
- return filters.map(filtersItem =>
135
- graphQLFiltersToStrapiQuery(filtersItem, contentType)
136
- );
137
- }
138
-
139
- const resultMap = {};
140
- const { attributes } = contentType;
141
-
142
- const isAttribute = attributeName => {
143
- return virtualScalarAttributes.includes(attributeName) || has(attributeName, attributes);
79
+ return result;
144
80
  };
145
-
146
- for (const [key, value] of Object.entries(filters)) {
147
- // If the key is an attribute, update the value
148
- if (isAttribute(key)) {
149
- const attribute = attributes[key];
150
-
151
- // If it's a scalar attribute
152
- if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
153
- // Replace (recursively) every GraphQL scalar operator with the associated Strapi operator
154
- resultMap[key] = recursivelyReplaceScalarOperators(value);
81
+ const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
82
+ const { isStrapiScalar, isMedia, isRelation } = getService("utils").attributes;
83
+ const { operators } = getService("builders").filters;
84
+ const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
85
+ if ((0, fp_1.isNil)(filters)) {
86
+ return {};
155
87
  }
156
-
157
- // If it's a deep filter on a relation
158
- else if (isRelation(attribute) || isMedia(attribute)) {
159
- // Fetch the model from the relation
160
- const relModel = strapi.getModel(attribute.target);
161
-
162
- // Recursively apply the mapping to the value using the fetched model,
163
- // and update the value within `resultMap`
164
- resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
88
+ if (Array.isArray(filters)) {
89
+ return filters.map((filtersItem) => graphQLFiltersToStrapiQuery(filtersItem, contentType));
165
90
  }
166
- }
167
-
168
- // Handle the case where the key is not an attribute (operator, ...)
169
- else {
170
- const rootLevelOperator = ROOT_LEVEL_OPERATORS.find(propEq('fieldName', key));
171
-
172
- // If it's a root level operator (AND, NOT, OR, ...)
173
- if (rootLevelOperator) {
174
- const { strapiOperator } = rootLevelOperator;
175
-
176
- // Transform the current value recursively and add it to the resultMap
177
- // object using the strapiOperator equivalent of the GraphQL key
178
- resultMap[strapiOperator] = graphQLFiltersToStrapiQuery(value, contentType);
91
+ const resultMap = {};
92
+ const { attributes } = contentType;
93
+ const isAttribute = (attributeName) => {
94
+ return (virtualScalarAttributes.includes(attributeName) ||
95
+ (0, fp_1.has)(attributeName, attributes));
96
+ };
97
+ for (const [key, value] of Object.entries(filters)) {
98
+ if (isAttribute(key)) {
99
+ const attribute = attributes[key];
100
+ if (virtualScalarAttributes.includes(key) ||
101
+ isStrapiScalar(attribute)) {
102
+ resultMap[key] = recursivelyReplaceScalarOperators(value);
103
+ }
104
+ else if (isRelation(attribute) || isMedia(attribute)) {
105
+ const relModel = strapi.getModel(attribute.target);
106
+ resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
107
+ }
108
+ }
109
+ else {
110
+ const rootLevelOperator = ROOT_LEVEL_OPERATORS.find((0, fp_1.propEq)("fieldName", key));
111
+ if (rootLevelOperator) {
112
+ const { strapiOperator } = rootLevelOperator;
113
+ resultMap[strapiOperator] = graphQLFiltersToStrapiQuery(value, contentType);
114
+ }
115
+ }
179
116
  }
180
- }
181
- }
182
-
183
- return resultMap;
184
- };
185
-
186
- return {
187
- buildContentTypeFilters,
188
- graphQLFiltersToStrapiQuery,
189
- };
190
- };
117
+ return resultMap;
118
+ };
119
+ const serviceMethods = {
120
+ buildContentTypeFilters,
121
+ graphQLFiltersToStrapiQuery,
122
+ };
123
+ return serviceMethods;
124
+ };
125
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ admin: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceAdmin;
3
+ client: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceClient;
4
+ common: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceCommon;
5
+ gql: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceGraphQL;
6
+ };
7
+ export default _default;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -1,13 +1,16 @@
1
- 'use strict';
2
-
3
- const adminServices = require('./admin');
4
- const clientServices = require('./client');
5
- const commonServices = require('./common');
6
- const graphQLService = require('./graphql');
7
-
8
- module.exports = {
9
- admin: adminServices,
10
- client: clientServices,
11
- common: commonServices,
12
- gql: graphQLService,
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const admin_1 = __importDefault(require("./admin"));
7
+ const client_1 = __importDefault(require("./client"));
8
+ const common_1 = __importDefault(require("./common"));
9
+ const graphql_1 = __importDefault(require("./graphql"));
10
+ exports.default = {
11
+ admin: admin_1.default,
12
+ client: client_1.default,
13
+ common: common_1.default,
14
+ gql: graphql_1.default,
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ import { Id, StrapiUser } from "strapi-typed";
2
+ import { Comment, ToBeFixed } from "../../../types";
3
+ import PluginError from "./../../utils/error";
4
+ export declare const buildNestedStructure: (entities: Array<Comment>, id?: Id | null, field?: string, dropBlockedThreads?: boolean, blockNestedThreads?: boolean) => Array<Comment>;
5
+ export declare const isEqualEntity: (existing: Comment, data: ToBeFixed, user: StrapiUser) => boolean;
6
+ export declare const getRelatedGroups: (related: string) => Array<string>;
7
+ export declare const getModelUid: (name: string) => string;
8
+ export declare const filterOurResolvedReports: (item: Comment) => Comment;
9
+ export declare const convertContentTypeNameToSlug: (str: string) => string;
10
+ export declare const buildAuthorModel: (item: Comment) => Comment;
11
+ export declare const buildConfigQueryProp: (prop?: undefined | string | Array<string>) => string;
12
+ export declare const resolveUserContextError: (user: StrapiUser) => PluginError;
13
+ //# sourceMappingURL=functions.d.ts.map
@@ -1,112 +1,103 @@
1
- const PluginError = require('./../../utils/error');
2
- const { REGEX } = require('./../../utils/constants')
3
- const { first, isObject, isArray, isEmpty } = require('lodash');
4
-
5
- const buildNestedStructure = (
6
- entities,
7
- id = null,
8
- field = 'threadOf',
9
- dropBlockedThreads = false,
10
- blockNestedThreads = false,
11
- ) =>
12
- entities
13
- .filter(entity => {
14
- // mongo by default not return `null` for empty data
15
- if (entity[field] === null && id === null) {
16
- return true;
17
- }
18
- let data = entity[field];
19
- if (data && typeof id === 'string') {
20
- data = data.toString();
21
- }
22
- return (data && data === id) || (isObject(entity[field]) && (entity[field].id === id));
23
- })
24
- .map(entity => ({
25
- ...entity,
26
- [field]: undefined,
27
- related: undefined,
28
- blockedThread: blockNestedThreads || entity.blockedThread,
29
- children: entity.blockedThread && dropBlockedThreads ? [] : buildNestedStructure(entities, entity.id, field,
30
- dropBlockedThreads, entity.blockedThread),
31
- }));
32
-
33
- module.exports = {
34
- isEqualEntity: (existing, data, user) => {
35
- const { author: existingAuthor } = existing;
36
- const { author } = data;
37
-
38
- // Disallow approval status change by Client
39
- if (data.approvalStatus && (existing.approvalStatus !== data.approvalStatus)) {
40
- return false;
41
- }
42
-
43
- // Make sure that author is exact the same
44
- if (user) {
45
- const existingUserId = existingAuthor?.id || existingAuthor;
46
- const receivedUserId = user?.id || author?.id;
47
- return receivedUserId && (existingUserId === receivedUserId);
48
- }
49
- return existingAuthor.id === author?.id;
50
- },
51
-
52
- getRelatedGroups: related => related.split(REGEX.relatedUid).filter(s => s && s.length > 0),
53
-
54
- getModelUid: name => {
55
- return strapi
56
- .plugin('comments')
57
- .contentTypes[name]?.uid;
58
- },
59
-
60
- filterOurResolvedReports: item => (item ? {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveUserContextError = exports.buildConfigQueryProp = exports.buildAuthorModel = exports.convertContentTypeNameToSlug = exports.filterOurResolvedReports = exports.getModelUid = exports.getRelatedGroups = exports.isEqualEntity = exports.buildNestedStructure = void 0;
7
+ const error_1 = __importDefault(require("./../../utils/error"));
8
+ const constants_1 = require("./../../utils/constants");
9
+ const lodash_1 = require("lodash");
10
+ const buildNestedStructure = (entities, id = null, field = "threadOf", dropBlockedThreads = false, blockNestedThreads = false) => entities
11
+ .filter((entity) => {
12
+ const entityField = (0, lodash_1.get)(entity, field);
13
+ if (entityField === null && id === null) {
14
+ return true;
15
+ }
16
+ let data = entityField;
17
+ if (data && typeof id === "string") {
18
+ data = data.toString();
19
+ }
20
+ return ((data && data === id) ||
21
+ ((0, lodash_1.isObject)(entityField) && entityField.id === id));
22
+ })
23
+ .map((entity) => ({
24
+ ...entity,
25
+ [field]: undefined,
26
+ related: undefined,
27
+ blockedThread: blockNestedThreads || entity.blockedThread,
28
+ children: entity.blockedThread && dropBlockedThreads
29
+ ? []
30
+ : (0, exports.buildNestedStructure)(entities, entity.id, field, dropBlockedThreads, entity.blockedThread),
31
+ }));
32
+ exports.buildNestedStructure = buildNestedStructure;
33
+ const isEqualEntity = (existing, data, user) => {
34
+ const { author: existingAuthor = {} } = existing;
35
+ const { author } = data;
36
+ if (data.approvalStatus && existing.approvalStatus !== data.approvalStatus) {
37
+ return false;
38
+ }
39
+ if (user) {
40
+ const existingUserId = existingAuthor?.id || existingAuthor;
41
+ const receivedUserId = user?.id || author?.id;
42
+ return receivedUserId && existingUserId === receivedUserId;
43
+ }
44
+ return existingAuthor.id === author?.id;
45
+ };
46
+ exports.isEqualEntity = isEqualEntity;
47
+ const getRelatedGroups = (related) => related.split(constants_1.REGEX.relatedUid).filter((s) => s && s.length > 0);
48
+ exports.getRelatedGroups = getRelatedGroups;
49
+ const getModelUid = (name) => {
50
+ return strapi.plugin("comments").contentTypes[name]?.uid;
51
+ };
52
+ exports.getModelUid = getModelUid;
53
+ const filterOurResolvedReports = (item) => item
54
+ ? {
61
55
  ...item,
62
- reports: (item.reports || []).filter(report => !report.resolved),
63
- } : item),
64
-
65
- convertContentTypeNameToSlug: str => {
66
- const plainConversion = str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
67
- return first(plainConversion) === '-' ? plainConversion.slice(1, plainConversion.length) : plainConversion;
68
- },
69
-
70
- buildNestedStructure,
71
-
72
- buildAuthorModel: (item) => {
73
- const { authorUser, authorId, authorName, authorEmail, authorAvatar, ...rest } = item;
74
- let author = {};
75
- if (authorUser) {
76
- author = {
77
- id: authorUser.id,
78
- name: authorUser.username,
79
- email: authorUser.email,
80
- avatar: authorUser.avatar,
81
- };
82
- } else if(authorId) {
83
- author = {
84
- id: authorId,
85
- name: authorName,
86
- email: authorEmail,
87
- avatar: authorAvatar,
88
- };
89
- }
90
- return {
91
- ...rest,
92
- author: isEmpty(author) ? undefined : author,
56
+ reports: (item.reports || []).filter((report) => !report.resolved),
57
+ }
58
+ : item;
59
+ exports.filterOurResolvedReports = filterOurResolvedReports;
60
+ const convertContentTypeNameToSlug = (str) => {
61
+ const plainConversion = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
62
+ return (0, lodash_1.first)(plainConversion) === "-"
63
+ ? plainConversion.slice(1, plainConversion.length)
64
+ : plainConversion;
65
+ };
66
+ exports.convertContentTypeNameToSlug = convertContentTypeNameToSlug;
67
+ const buildAuthorModel = (item) => {
68
+ const { authorUser, authorId, authorName, authorEmail, authorAvatar, ...rest } = item;
69
+ let author = {};
70
+ if (authorUser) {
71
+ author = {
72
+ id: authorUser.id,
73
+ name: authorUser.username,
74
+ email: authorUser.email,
75
+ avatar: authorUser.avatar,
76
+ };
77
+ }
78
+ else if (authorId) {
79
+ author = {
80
+ id: authorId,
81
+ name: authorName,
82
+ email: authorEmail,
83
+ avatar: authorAvatar,
93
84
  };
94
- },
95
-
96
- buildConfigQueryProp(prop) {
97
- let queryProp = prop;
98
- if (prop && isArray(prop)) {
99
- queryProp = prop.join('.');
100
- }
101
- return queryProp;
102
- },
103
-
104
- resolveUserContextError: user => {
105
- if (user) {
106
- throw new PluginError(401, 'Not authenticated');
107
- } else {
108
- throw new PluginError(403, 'Not authorized');
109
- }
110
- },
85
+ }
86
+ return {
87
+ ...rest,
88
+ author: (0, lodash_1.isEmpty)(author) ? undefined : author,
89
+ };
90
+ };
91
+ exports.buildAuthorModel = buildAuthorModel;
92
+ const buildConfigQueryProp = (prop = "") => ((0, lodash_1.isArray)(prop) ? prop.join(".") : prop ?? "");
93
+ exports.buildConfigQueryProp = buildConfigQueryProp;
94
+ const resolveUserContextError = (user) => {
95
+ if (user) {
96
+ throw new error_1.default(401, "Not authenticated");
97
+ }
98
+ else {
99
+ throw new error_1.default(403, "Not authorized");
100
+ }
111
101
  };
112
-
102
+ exports.resolveUserContextError = resolveUserContextError;
103
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1,9 @@
1
+ import { ConfigParamKeys, RegExpCollection } from "../../types";
2
+ export declare const CONFIG_PARAMS: ConfigParamKeys;
3
+ export declare const APPROVAL_STATUS: {
4
+ PENDING: string;
5
+ APPROVED: string;
6
+ REJECTED: string;
7
+ };
8
+ export declare const REGEX: RegExpCollection;
9
+ //# sourceMappingURL=constants.d.ts.map
@@ -1,26 +1,22 @@
1
- const CONFIG_PARAMS = {
2
- ENABLED_COLLECTIONS: 'enabledCollections',
3
- APPROVAL_FLOW: 'approvalFlow',
4
- ENTRY_LABEL: 'entryLabel',
5
- MODERATOR_ROLES: 'moderatorRoles',
6
- BAD_WORDS: 'badWords',
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REGEX = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
4
+ exports.CONFIG_PARAMS = {
5
+ ENABLED_COLLECTIONS: "enabledCollections",
6
+ APPROVAL_FLOW: "approvalFlow",
7
+ ENTRY_LABEL: "entryLabel",
8
+ MODERATOR_ROLES: "moderatorRoles",
9
+ BAD_WORDS: "badWords",
7
10
  };
8
-
9
- const APPROVAL_STATUS = {
10
- PENDING: "PENDING",
11
- APPROVED: "APPROVED",
12
- REJECTED: "REJECTED",
11
+ exports.APPROVAL_STATUS = {
12
+ PENDING: "PENDING",
13
+ APPROVED: "APPROVED",
14
+ REJECTED: "REJECTED",
13
15
  };
14
-
15
- const REGEX = {
16
- uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
17
- relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
18
- email: /\S+@\S+\.\S+/,
19
- sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i
20
- };
21
-
22
- module.exports = {
23
- CONFIG_PARAMS,
24
- APPROVAL_STATUS,
25
- REGEX,
16
+ exports.REGEX = {
17
+ uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
18
+ relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
19
+ email: /\S+@\S+\.\S+/,
20
+ sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i,
26
21
  };
22
+ //# sourceMappingURL=constants.js.map