strapi-plugin-comments 2.0.10 → 2.0.11

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 (261) hide show
  1. package/README.md +39 -5
  2. package/admin/src/translations/fr.json +132 -1
  3. package/build/README.md +818 -0
  4. package/build/admin/src/components/ActionButton/styles.d.ts +2 -0
  5. package/build/admin/src/components/ActionButton/styles.js +17 -0
  6. package/build/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  7. package/build/admin/src/components/ConfirmationDialog/index.js +104 -0
  8. package/build/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  9. package/build/admin/src/components/DiscussionStatus/index.js +38 -0
  10. package/build/admin/src/components/DiscussionThread/index.d.ts +16 -0
  11. package/build/admin/src/components/DiscussionThread/index.js +99 -0
  12. package/build/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  13. package/build/admin/src/components/DiscussionThreadItem/index.js +72 -0
  14. package/build/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  15. package/build/admin/src/components/DiscussionThreadItem/styles.js +27 -0
  16. package/build/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  17. package/build/admin/src/components/DiscussionThreadItemActions/index.js +414 -0
  18. package/build/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  19. package/build/admin/src/components/DiscussionThreadItemActions/styles.js +17 -0
  20. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  21. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +103 -0
  22. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  23. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +15 -0
  24. package/build/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  25. package/build/admin/src/components/DiscussionThreadItemFooter/index.js +73 -0
  26. package/build/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  27. package/build/admin/src/components/DiscussionThreadItemFooter/styles.js +25 -0
  28. package/build/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  29. package/build/admin/src/components/DiscussionThreadItemReviewAction/index.js +233 -0
  30. package/build/admin/src/components/FormSwitch/index.d.ts +11 -0
  31. package/build/admin/src/components/FormSwitch/index.js +39 -0
  32. package/build/admin/src/components/FormSwitch/styles.d.ts +2 -0
  33. package/build/admin/src/components/FormSwitch/styles.js +16 -0
  34. package/build/admin/src/components/IconButton/styles.d.ts +2 -0
  35. package/build/admin/src/components/IconButton/styles.js +27 -0
  36. package/build/admin/src/components/Initializer/index.d.ts +3 -0
  37. package/build/admin/src/components/Initializer/index.js +14 -0
  38. package/build/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  39. package/build/admin/src/components/LoadingIndicatorOverlay/index.js +18 -0
  40. package/build/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  41. package/build/admin/src/components/LoadingIndicatorOverlay/styles.js +32 -0
  42. package/build/admin/src/components/Nav/index.d.ts +7 -0
  43. package/build/admin/src/components/Nav/index.js +72 -0
  44. package/build/admin/src/components/PluginIcon/index.d.ts +3 -0
  45. package/build/admin/src/components/PluginIcon/index.js +13 -0
  46. package/build/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  47. package/build/admin/src/components/ReportsReviewModal/index.js +72 -0
  48. package/build/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  49. package/build/admin/src/components/ReportsReviewTable/index.js +321 -0
  50. package/build/admin/src/components/StatusBadge/index.d.ts +11 -0
  51. package/build/admin/src/components/StatusBadge/index.js +22 -0
  52. package/build/admin/src/components/StatusBadge/styles.d.ts +2 -0
  53. package/build/admin/src/components/StatusBadge/styles.js +25 -0
  54. package/build/admin/src/components/TableFilters/index.d.ts +10 -0
  55. package/build/admin/src/components/TableFilters/index.js +109 -0
  56. package/build/admin/src/components/TablePagination/index.d.ts +15 -0
  57. package/build/admin/src/components/TablePagination/index.js +45 -0
  58. package/build/admin/src/components/icons/comments.d.ts +9 -0
  59. package/build/admin/src/components/icons/comments.js +23 -0
  60. package/build/admin/src/components/icons/index.d.ts +6 -0
  61. package/build/admin/src/components/icons/index.js +21 -0
  62. package/build/admin/src/components/icons/lock.d.ts +11 -0
  63. package/build/admin/src/components/icons/lock.js +29 -0
  64. package/build/admin/src/components/icons/review.d.ts +11 -0
  65. package/build/admin/src/components/icons/review.js +31 -0
  66. package/build/admin/src/components/icons/unlock.d.ts +11 -0
  67. package/build/admin/src/components/icons/unlock.js +29 -0
  68. package/build/admin/src/hooks/useConfig.d.ts +8 -0
  69. package/build/admin/src/hooks/useConfig.js +52 -0
  70. package/build/admin/src/index.d.ts +7 -0
  71. package/build/admin/src/index.js +137 -0
  72. package/build/admin/src/pages/App/index.d.ts +4 -0
  73. package/build/admin/src/pages/App/index.js +90 -0
  74. package/build/admin/src/pages/App/reducer/actions.d.ts +8 -0
  75. package/build/admin/src/pages/App/reducer/actions.js +12 -0
  76. package/build/admin/src/pages/App/reducer/constants.d.ts +4 -0
  77. package/build/admin/src/pages/App/reducer/constants.js +7 -0
  78. package/build/admin/src/pages/App/reducer/index.d.ts +14 -0
  79. package/build/admin/src/pages/App/reducer/index.js +31 -0
  80. package/build/admin/src/pages/App/reducer/init.d.ts +3 -0
  81. package/build/admin/src/pages/App/reducer/init.js +9 -0
  82. package/build/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  83. package/build/admin/src/pages/App/reducer/selectors.js +20 -0
  84. package/build/admin/src/pages/App/utils/api.d.ts +2 -0
  85. package/build/admin/src/pages/App/utils/api.js +16 -0
  86. package/build/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  87. package/build/admin/src/pages/ComingSoonPage/index.js +78 -0
  88. package/build/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  89. package/build/admin/src/pages/Details/components/DetailsEntity/index.js +132 -0
  90. package/build/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  91. package/build/admin/src/pages/Details/components/DetailsFilters/index.js +48 -0
  92. package/build/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  93. package/build/admin/src/pages/Details/components/DetailsFilters/styles.js +16 -0
  94. package/build/admin/src/pages/Details/index.d.ts +4 -0
  95. package/build/admin/src/pages/Details/index.js +216 -0
  96. package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  97. package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.js +344 -0
  98. package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  99. package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +16 -0
  100. package/build/admin/src/pages/Discover/index.d.ts +4 -0
  101. package/build/admin/src/pages/Discover/index.js +332 -0
  102. package/build/admin/src/pages/Discover/utils/api.d.ts +2 -0
  103. package/build/admin/src/pages/Discover/utils/api.js +23 -0
  104. package/build/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  105. package/build/admin/src/pages/Discover/utils/filtersSchema.js +11 -0
  106. package/build/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  107. package/build/admin/src/pages/Settings/components/RestartAlert/styles.js +16 -0
  108. package/build/admin/src/pages/Settings/index.d.ts +3 -0
  109. package/build/admin/src/pages/Settings/index.js +712 -0
  110. package/build/admin/src/pages/Settings/utils/api.d.ts +7 -0
  111. package/build/admin/src/pages/Settings/utils/api.js +80 -0
  112. package/build/admin/src/pages/utils/api.d.ts +12 -0
  113. package/build/admin/src/pages/utils/api.js +83 -0
  114. package/build/admin/src/permissions.d.ts +28 -0
  115. package/build/admin/src/permissions.js +65 -0
  116. package/build/admin/src/pluginId.d.ts +2 -0
  117. package/build/admin/src/pluginId.js +50 -0
  118. package/build/admin/src/reducers.d.ts +12 -0
  119. package/build/admin/src/reducers.js +14 -0
  120. package/build/admin/src/translations/en.json +132 -0
  121. package/build/admin/src/translations/fr.json +1 -0
  122. package/build/admin/src/translations/pt-BR.json +132 -0
  123. package/build/admin/src/utils/axiosInstance.d.ts +3 -0
  124. package/build/admin/src/utils/axiosInstance.js +37 -0
  125. package/build/admin/src/utils/constants.d.ts +25 -0
  126. package/build/admin/src/utils/constants.js +30 -0
  127. package/build/admin/src/utils/getApiUrl.d.ts +3 -0
  128. package/build/admin/src/utils/getApiUrl.js +6 -0
  129. package/build/admin/src/utils/getMessage.d.ts +4 -0
  130. package/build/admin/src/utils/getMessage.js +25 -0
  131. package/build/admin/src/utils/getRelatedGroups.d.ts +4 -0
  132. package/build/admin/src/utils/getRelatedGroups.js +6 -0
  133. package/build/admin/src/utils/getUrl.d.ts +3 -0
  134. package/build/admin/src/utils/getUrl.js +6 -0
  135. package/build/admin/src/utils/handleAPIError.d.ts +4 -0
  136. package/build/admin/src/utils/handleAPIError.js +20 -0
  137. package/build/admin/src/utils/index.d.ts +12 -0
  138. package/build/admin/src/utils/index.js +97 -0
  139. package/build/admin/src/utils/parseRegExp.d.ts +6 -0
  140. package/build/admin/src/utils/parseRegExp.js +11 -0
  141. package/build/admin/src/utils/renderEntryTitle.d.ts +4 -0
  142. package/build/admin/src/utils/renderEntryTitle.js +16 -0
  143. package/build/admin/src/utils/renderInitials.d.ts +3 -0
  144. package/build/admin/src/utils/renderInitials.js +11 -0
  145. package/build/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  146. package/build/admin/src/utils/resolveCommentStatus.js +32 -0
  147. package/build/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  148. package/build/admin/src/utils/resolveCommentStatusColor.js +22 -0
  149. package/build/content-types/comment.d.ts +91 -0
  150. package/build/content-types/comment.js +92 -0
  151. package/build/content-types/index.d.ts +143 -0
  152. package/build/content-types/index.js +18 -0
  153. package/build/content-types/report.d.ts +48 -0
  154. package/build/content-types/report.js +49 -0
  155. package/build/package.json +94 -0
  156. package/build/permissions.d.ts +18 -0
  157. package/build/permissions.js +18 -0
  158. package/build/server/bootstrap.d.ts +4 -0
  159. package/build/server/bootstrap.js +65 -0
  160. package/build/server/config/index.d.ts +4 -0
  161. package/build/server/config/index.js +19 -0
  162. package/build/server/controllers/admin.d.ts +4 -0
  163. package/build/server/controllers/admin.js +124 -0
  164. package/build/server/controllers/client.d.ts +4 -0
  165. package/build/server/controllers/client.js +111 -0
  166. package/build/server/controllers/index.d.ts +6 -0
  167. package/build/server/controllers/index.js +15 -0
  168. package/build/server/controllers/utils/functions.d.ts +7 -0
  169. package/build/server/controllers/utils/functions.js +24 -0
  170. package/build/server/controllers/utils/parsers.d.ts +15 -0
  171. package/build/server/controllers/utils/parsers.js +25 -0
  172. package/build/server/destroy.d.ts +3 -0
  173. package/build/server/destroy.js +3 -0
  174. package/build/server/graphql/index.d.ts +4 -0
  175. package/build/server/graphql/index.js +37 -0
  176. package/build/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  177. package/build/server/graphql/mutations/createAbuseReport.js +27 -0
  178. package/build/server/graphql/mutations/createComment.d.ts +14 -0
  179. package/build/server/graphql/mutations/createComment.js +26 -0
  180. package/build/server/graphql/mutations/index.d.ts +4 -0
  181. package/build/server/graphql/mutations/index.js +28 -0
  182. package/build/server/graphql/mutations/removeComment.d.ts +11 -0
  183. package/build/server/graphql/mutations/removeComment.js +27 -0
  184. package/build/server/graphql/mutations/updateComment.d.ts +11 -0
  185. package/build/server/graphql/mutations/updateComment.js +27 -0
  186. package/build/server/graphql/queries/findAllFlat.d.ts +19 -0
  187. package/build/server/graphql/queries/findAllFlat.js +47 -0
  188. package/build/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
  189. package/build/server/graphql/queries/findAllInHierarchy.js +38 -0
  190. package/build/server/graphql/queries/index.d.ts +4 -0
  191. package/build/server/graphql/queries/index.js +24 -0
  192. package/build/server/graphql/resolvers-config.d.ts +23 -0
  193. package/build/server/graphql/resolvers-config.js +13 -0
  194. package/build/server/graphql/types/comment-author.d.ts +4 -0
  195. package/build/server/graphql/types/comment-author.js +12 -0
  196. package/build/server/graphql/types/comment-nested.d.ts +4 -0
  197. package/build/server/graphql/types/comment-nested.js +19 -0
  198. package/build/server/graphql/types/comment.d.ts +4 -0
  199. package/build/server/graphql/types/comment.js +18 -0
  200. package/build/server/graphql/types/create-comment-author.d.ts +4 -0
  201. package/build/server/graphql/types/create-comment-author.js +12 -0
  202. package/build/server/graphql/types/create-comment.d.ts +4 -0
  203. package/build/server/graphql/types/create-comment.js +12 -0
  204. package/build/server/graphql/types/create-report.d.ts +4 -0
  205. package/build/server/graphql/types/create-report.js +12 -0
  206. package/build/server/graphql/types/id.d.ts +4 -0
  207. package/build/server/graphql/types/id.js +26 -0
  208. package/build/server/graphql/types/identify-comment-author.d.ts +4 -0
  209. package/build/server/graphql/types/identify-comment-author.js +9 -0
  210. package/build/server/graphql/types/index.d.ts +4 -0
  211. package/build/server/graphql/types/index.js +44 -0
  212. package/build/server/graphql/types/remove-comment.d.ts +4 -0
  213. package/build/server/graphql/types/remove-comment.js +11 -0
  214. package/build/server/graphql/types/report-reason.d.ts +4 -0
  215. package/build/server/graphql/types/report-reason.js +12 -0
  216. package/build/server/graphql/types/report.d.ts +4 -0
  217. package/build/server/graphql/types/report.js +14 -0
  218. package/build/server/graphql/types/response-find-all.d.ts +4 -0
  219. package/build/server/graphql/types/response-find-all.js +10 -0
  220. package/build/server/graphql/types/response-meta.d.ts +4 -0
  221. package/build/server/graphql/types/response-meta.js +9 -0
  222. package/build/server/graphql/types/response-pagination.d.ts +4 -0
  223. package/build/server/graphql/types/response-pagination.js +14 -0
  224. package/build/server/graphql/types/update-comment.d.ts +4 -0
  225. package/build/server/graphql/types/update-comment.js +12 -0
  226. package/build/server/index.d.ts +26 -0
  227. package/build/server/index.js +25 -0
  228. package/build/server/register.d.ts +3 -0
  229. package/build/server/register.js +3 -0
  230. package/build/server/routes/admin.d.ts +4 -0
  231. package/build/server/routes/admin.js +118 -0
  232. package/build/server/routes/client.d.ts +4 -0
  233. package/build/server/routes/client.js +54 -0
  234. package/build/server/routes/index.d.ts +11 -0
  235. package/build/server/routes/index.js +21 -0
  236. package/build/server/services/admin.d.ts +5 -0
  237. package/build/server/services/admin.js +296 -0
  238. package/build/server/services/client.d.ts +5 -0
  239. package/build/server/services/client.js +247 -0
  240. package/build/server/services/common.d.ts +5 -0
  241. package/build/server/services/common.js +266 -0
  242. package/build/server/services/graphql.d.ts +5 -0
  243. package/build/server/services/graphql.js +136 -0
  244. package/build/server/services/index.d.ts +8 -0
  245. package/build/server/services/index.js +16 -0
  246. package/build/server/services/utils/functions.d.ts +13 -0
  247. package/build/server/services/utils/functions.js +141 -0
  248. package/build/server/utils/constants.d.ts +9 -0
  249. package/build/server/utils/constants.js +23 -0
  250. package/build/server/utils/error.d.ts +23 -0
  251. package/build/server/utils/error.js +29 -0
  252. package/build/server/utils/functions.d.ts +14 -0
  253. package/build/server/utils/functions.js +50 -0
  254. package/build/strapi-admin.d.ts +3 -0
  255. package/build/strapi-admin.js +10 -0
  256. package/build/strapi-server.d.ts +177 -0
  257. package/build/strapi-server.js +46 -0
  258. package/build/tsconfig.tsbuildinfo +1 -0
  259. package/build/types/contentTypes.d.ts +46 -0
  260. package/build/types/contentTypes.js +3 -0
  261. package/package.json +3 -3
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const bad_words_1 = __importDefault(require("bad-words"));
6
+ const lodash_1 = require("lodash");
7
+ const constants_1 = require("../utils/constants");
8
+ const error_1 = __importDefault(require("./../utils/error"));
9
+ const functions_1 = require("./utils/functions");
10
+ const PAGE_SIZE = 10;
11
+ module.exports = ({ strapi }) => ({
12
+ async getConfig(prop, defaultValue, useLocal = false) {
13
+ const queryProp = (0, functions_1.buildConfigQueryProp)(prop);
14
+ const pluginStore = await this.getPluginStore();
15
+ const config = await pluginStore.get({
16
+ key: "config",
17
+ });
18
+ let result;
19
+ if (config && !useLocal) {
20
+ result = queryProp ? (0, lodash_1.get)(config, queryProp, defaultValue) : config;
21
+ }
22
+ else {
23
+ result = this.getLocalConfig(queryProp, defaultValue);
24
+ }
25
+ return (0, lodash_1.isNil)(result) ? defaultValue : result;
26
+ },
27
+ async getPluginStore() {
28
+ return strapi.store({ type: "plugin", name: "comments" });
29
+ },
30
+ getLocalConfig(prop, defaultValue) {
31
+ const queryProp = (0, functions_1.buildConfigQueryProp)(prop);
32
+ const result = strapi.config.get(`plugin.comments${queryProp ? "." + queryProp : ""}`);
33
+ return (0, lodash_1.isNil)(result) ? defaultValue : result;
34
+ },
35
+ async findAllFlat({ query = {}, populate = {}, sort, pagination }, relatedEntity = null) {
36
+ const defaultPopulate = {
37
+ authorUser: true,
38
+ };
39
+ let queryExtension = {};
40
+ if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
41
+ queryExtension = {
42
+ ...queryExtension,
43
+ orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
44
+ .map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
45
+ .reduce((prev, curr) => {
46
+ const [type = "asc", ...parts] = curr.split(":").reverse();
47
+ return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
48
+ }, {}),
49
+ };
50
+ }
51
+ let meta = {};
52
+ if (pagination && (0, lodash_1.isObject)(pagination)) {
53
+ const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
54
+ ...prev,
55
+ [curr]: (0, lodash_1.parseInt)((0, lodash_1.get)(pagination, curr)),
56
+ }), {});
57
+ const { page = 1, pageSize = PAGE_SIZE, start = 0, limit = PAGE_SIZE, } = parsedpagination;
58
+ const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
59
+ queryExtension = {
60
+ ...queryExtension,
61
+ offset: paginationByPage ? (page - 1) * pageSize : start,
62
+ limit: paginationByPage ? pageSize : limit,
63
+ };
64
+ const metapagination = paginationByPage
65
+ ? {
66
+ pagination: {
67
+ page,
68
+ pageSize,
69
+ },
70
+ }
71
+ : {
72
+ pagination: {
73
+ start,
74
+ limit,
75
+ },
76
+ };
77
+ meta = {
78
+ ...metapagination,
79
+ };
80
+ }
81
+ const entries = await strapi.db
82
+ .query((0, functions_1.getModelUid)("comment"))
83
+ .findMany({
84
+ where: {
85
+ ...query,
86
+ },
87
+ populate: {
88
+ ...defaultPopulate,
89
+ ...populate,
90
+ },
91
+ ...queryExtension,
92
+ });
93
+ if (pagination?.withCount &&
94
+ (pagination.withCount === "true" || pagination.withCount === true)) {
95
+ const total = await strapi.db
96
+ .query((0, functions_1.getModelUid)("comment"))
97
+ .count({
98
+ where: {
99
+ ...query,
100
+ },
101
+ });
102
+ const pageSize = meta.pagination.pageSize || PAGE_SIZE;
103
+ const pageCount = Math.floor(total / pageSize);
104
+ meta = {
105
+ ...meta,
106
+ pagination: {
107
+ ...meta.pagination,
108
+ pageCount: !(0, lodash_1.isNil)(meta.pagination.page)
109
+ ? total % pageSize === 0
110
+ ? pageCount
111
+ : pageCount + 1
112
+ : undefined,
113
+ total,
114
+ },
115
+ };
116
+ }
117
+ const entriesWithThreads = await Promise.all(entries.map(async (_) => {
118
+ const [nestedEntries, count] = await strapi.db
119
+ .query((0, functions_1.getModelUid)("comment"))
120
+ .findWithCount({
121
+ where: {
122
+ threadOf: _.id,
123
+ },
124
+ });
125
+ return {
126
+ id: _.id,
127
+ itemsInTread: count,
128
+ firstThreadItemId: (0, lodash_1.first)(nestedEntries)?.id,
129
+ };
130
+ }));
131
+ const relatedEntities = relatedEntity !== null
132
+ ? [relatedEntity]
133
+ : await this.findRelatedEntitiesFor([...entries]);
134
+ const hasRelatedEntitiesToMap = relatedEntities.filter((_) => _).length > 0;
135
+ const result = entries.map((_) => {
136
+ const threadedItem = entriesWithThreads.find((item) => item.id === _.id);
137
+ const parsedThreadOf = (0, lodash_1.isString)(query.threadOf)
138
+ ? (0, lodash_1.parseInt)(query.threadOf)
139
+ : query.threadOf;
140
+ return this.sanitizeCommentEntity({
141
+ ..._,
142
+ threadOf: parsedThreadOf || _.threadOf || null,
143
+ gotThread: (threadedItem?.itemsInTread || 0) > 0,
144
+ threadFirstItemId: threadedItem?.firstThreadItemId,
145
+ });
146
+ });
147
+ return {
148
+ data: hasRelatedEntitiesToMap
149
+ ? result.map((_) => this.mergeRelatedEntityTo(_, relatedEntities))
150
+ : result,
151
+ ...((0, lodash_1.isEmpty)(meta) ? {} : { meta }),
152
+ };
153
+ },
154
+ async findAllInHierarchy({ query, populate = {}, sort, startingFromId = null, dropBlockedThreads = false, }, relatedEntity) {
155
+ const entities = await this.findAllFlat({ query, populate, sort }, relatedEntity);
156
+ return (0, functions_1.buildNestedStructure)(entities?.data, startingFromId, "threadOf", dropBlockedThreads, false);
157
+ },
158
+ async findOne(criteria) {
159
+ const entity = await strapi.db
160
+ .query((0, functions_1.getModelUid)("comment"))
161
+ .findOne({
162
+ where: criteria,
163
+ populate: {
164
+ reports: true,
165
+ authorUser: true,
166
+ },
167
+ });
168
+ if (!entity) {
169
+ throw new error_1.default(404, "Comment does not exist. Check your payload please.");
170
+ }
171
+ return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity));
172
+ },
173
+ async findRelatedEntitiesFor(entities = []) {
174
+ const data = entities.reduce((acc, curr) => {
175
+ const [relatedUid, relatedStringId] = (0, functions_1.getRelatedGroups)(curr.related);
176
+ const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
177
+ const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
178
+ ? parsedRelatedId
179
+ : relatedStringId;
180
+ return {
181
+ ...acc,
182
+ [relatedUid]: [...(acc[relatedUid] || []), relatedId],
183
+ };
184
+ }, {});
185
+ return Promise.all(Object.entries(data).map(async ([relatedUid, relatedStringIds]) => strapi.db
186
+ .query(relatedUid)
187
+ .findMany({
188
+ where: { id: Array.from(new Set(relatedStringIds)) },
189
+ })
190
+ .then((relatedEntities) => relatedEntities.map((_) => ({
191
+ ..._,
192
+ uid: relatedUid,
193
+ }))))).then((result) => result.flat(2));
194
+ },
195
+ mergeRelatedEntityTo(entity, relatedEntities = []) {
196
+ return {
197
+ ...entity,
198
+ related: relatedEntities.find((relatedEntity) => entity.related === `${relatedEntity.uid}:${relatedEntity.id}`),
199
+ };
200
+ },
201
+ async modifiedNestedNestedComments(id, fieldName, value) {
202
+ try {
203
+ const entitiesToChange = await strapi.db
204
+ .query((0, functions_1.getModelUid)("comment"))
205
+ .findMany({
206
+ where: { threadOf: id },
207
+ });
208
+ const changedEntities = await strapi.db
209
+ .query((0, functions_1.getModelUid)("comment"))
210
+ .updateMany({
211
+ where: { id: entitiesToChange.map((_) => _.id) },
212
+ data: { [fieldName]: value },
213
+ });
214
+ if (entitiesToChange.length === changedEntities.length &&
215
+ changedEntities.length > 0) {
216
+ const nestedTransactions = await Promise.all(changedEntities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value)));
217
+ return nestedTransactions.length === changedEntities.length;
218
+ }
219
+ return true;
220
+ }
221
+ catch (e) {
222
+ return false;
223
+ }
224
+ },
225
+ sanitizeCommentEntity(entity) {
226
+ return {
227
+ ...(0, functions_1.buildAuthorModel)({
228
+ ...entity,
229
+ threadOf: (0, lodash_1.isObject)(entity.threadOf)
230
+ ? (0, functions_1.buildAuthorModel)(entity.threadOf)
231
+ : entity.threadOf,
232
+ }),
233
+ };
234
+ },
235
+ isValidUserContext(user) {
236
+ return user ? !(0, lodash_1.isNil)(user?.id) : true;
237
+ },
238
+ async parseRelationString(relation) {
239
+ const [uid, relatedStringId] = (0, functions_1.getRelatedGroups)(relation);
240
+ const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
241
+ const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
242
+ ? parsedRelatedId
243
+ : relatedStringId;
244
+ const enabledCollections = await this.getConfig(constants_1.CONFIG_PARAMS.ENABLED_COLLECTIONS, []);
245
+ if (!enabledCollections.includes(uid)) {
246
+ throw new error_1.default(403, `Action not allowed for collection '${uid}'. Use one of: ${enabledCollections.join(", ")}`);
247
+ }
248
+ return [uid, relatedId];
249
+ },
250
+ async checkBadWords(content) {
251
+ const config = await this.getConfig(constants_1.CONFIG_PARAMS.BAD_WORDS, true);
252
+ if (config) {
253
+ const filter = new bad_words_1.default((0, lodash_1.isObject)(config) ? config : undefined);
254
+ if (content && filter.isProfane(content)) {
255
+ throw new error_1.default(400, "Bad language used! Please polite your comment...", {
256
+ content: {
257
+ original: content,
258
+ filtered: content && filter.clean(content),
259
+ },
260
+ });
261
+ }
262
+ }
263
+ return content;
264
+ },
265
+ });
266
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { IServiceGraphQL } from "../../types";
3
+ declare const _default: ({ strapi }: StrapiContext) => IServiceGraphQL;
4
+ export = _default;
5
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ const fp_1 = require("lodash/fp");
3
+ const nexus_1 = require("nexus");
4
+ const virtualScalarAttributes = ["id"];
5
+ module.exports = ({ strapi }) => {
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 } =
15
+ utils.naming;
16
+ const { isStrapiScalar, isRelation } = utils.attributes;
17
+ const { attributes } = contentType;
18
+ const filtersTypeName = getFiltersInputTypeName(contentType);
19
+ return (0, nexus_1.inputObjectType)({
20
+ name: filtersTypeName,
21
+ definition(t) {
22
+ const validAttributes = Object.entries(attributes).filter(
23
+ ([attributeName]) =>
24
+ extension
25
+ .shadowCRUD(contentType.uid)
26
+ .field(attributeName)
27
+ .hasFiltersEnabeld()
28
+ );
29
+ const isIDFilterEnabled = extension
30
+ .shadowCRUD(contentType.uid)
31
+ .field("id")
32
+ .hasFiltersEnabeld();
33
+ if (contentType.kind === "collectionType" && isIDFilterEnabled) {
34
+ t.field("id", { type: getScalarFilterInputTypeName("ID") });
35
+ }
36
+ for (const [attributeName, attribute] of validAttributes) {
37
+ if (isStrapiScalar(attribute)) {
38
+ addScalarAttribute(t, attributeName, attribute);
39
+ } else if (isRelation(attribute)) {
40
+ addRelationalAttribute(t, attributeName, attribute);
41
+ }
42
+ }
43
+ for (const operator of rootLevelOperators()) {
44
+ operator.add(t, filtersTypeName);
45
+ }
46
+ },
47
+ });
48
+ };
49
+ const addScalarAttribute = (builder, attributeName, attribute) => {
50
+ const { naming, mappers } = strapi.plugin("graphql").service("utils");
51
+ const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
52
+ builder.field(attributeName, {
53
+ type: naming.getScalarFilterInputTypeName(gqlType),
54
+ });
55
+ };
56
+ const addRelationalAttribute = (builder, attributeName, attribute) => {
57
+ const utils = strapi.plugin("graphql").service("utils");
58
+ const extension = strapi.plugin("graphql").service("extension");
59
+ const { getFiltersInputTypeName } = utils.naming;
60
+ const { isMorphRelation } = utils.attributes;
61
+ const model = strapi.getModel(attribute.target);
62
+ if (!model || isMorphRelation(attribute)) return;
63
+ if (extension.shadowCRUD(model.uid).isDisabled()) return;
64
+ builder.field(attributeName, { type: getFiltersInputTypeName(model) });
65
+ };
66
+ const recursivelyReplaceScalarOperators = (data) => {
67
+ const { operators } = getService("builders").filters;
68
+ if (Array.isArray(data)) {
69
+ return data.map(recursivelyReplaceScalarOperators);
70
+ }
71
+ if ((0, fp_1.isDate)(data) || !(0, fp_1.isObject)(data)) {
72
+ return data;
73
+ }
74
+ const result = {};
75
+ for (const [key, value] of Object.entries(data)) {
76
+ const isOperator = !!operators[key];
77
+ const newKey = isOperator ? operators[key].strapiOperator : key;
78
+ result[newKey] = recursivelyReplaceScalarOperators(value);
79
+ }
80
+ return result;
81
+ };
82
+ const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
83
+ const { isStrapiScalar, isMedia, isRelation } =
84
+ getService("utils").attributes;
85
+ const { operators } = getService("builders").filters;
86
+ const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
87
+ if ((0, fp_1.isNil)(filters)) {
88
+ return {};
89
+ }
90
+ if (Array.isArray(filters)) {
91
+ return filters.map((filtersItem) =>
92
+ graphQLFiltersToStrapiQuery(filtersItem, contentType)
93
+ );
94
+ }
95
+ const resultMap = {};
96
+ const { attributes } = contentType;
97
+ const isAttribute = (attributeName) => {
98
+ return (
99
+ virtualScalarAttributes.includes(attributeName) ||
100
+ (0, fp_1.has)(attributeName, attributes)
101
+ );
102
+ };
103
+ for (const [key, value] of Object.entries(filters)) {
104
+ if (isAttribute(key)) {
105
+ const attribute = attributes[key];
106
+ if (
107
+ virtualScalarAttributes.includes(key) ||
108
+ isStrapiScalar(attribute)
109
+ ) {
110
+ resultMap[key] = recursivelyReplaceScalarOperators(value);
111
+ } else if (isRelation(attribute) || isMedia(attribute)) {
112
+ const relModel = strapi.getModel(attribute.target);
113
+ resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
114
+ }
115
+ } else {
116
+ const rootLevelOperator = ROOT_LEVEL_OPERATORS.find(
117
+ (0, fp_1.propEq)("fieldName", key)
118
+ );
119
+ if (rootLevelOperator) {
120
+ const { strapiOperator } = rootLevelOperator;
121
+ resultMap[strapiOperator] = graphQLFiltersToStrapiQuery(
122
+ value,
123
+ contentType
124
+ );
125
+ }
126
+ }
127
+ }
128
+ return resultMap;
129
+ };
130
+ const serviceMethods = {
131
+ buildContentTypeFilters,
132
+ graphQLFiltersToStrapiQuery,
133
+ };
134
+ return serviceMethods;
135
+ };
136
+ //# 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
@@ -0,0 +1,16 @@
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
+ 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
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.resolveUserContextError =
9
+ exports.buildConfigQueryProp =
10
+ exports.buildAuthorModel =
11
+ exports.convertContentTypeNameToSlug =
12
+ exports.filterOurResolvedReports =
13
+ exports.getModelUid =
14
+ exports.getRelatedGroups =
15
+ exports.isEqualEntity =
16
+ exports.buildNestedStructure =
17
+ void 0;
18
+ const error_1 = __importDefault(require("./../../utils/error"));
19
+ const constants_1 = require("./../../utils/constants");
20
+ const lodash_1 = require("lodash");
21
+ const buildNestedStructure = (
22
+ entities,
23
+ id = null,
24
+ field = "threadOf",
25
+ dropBlockedThreads = false,
26
+ blockNestedThreads = false
27
+ ) =>
28
+ entities
29
+ .filter((entity) => {
30
+ const entityField = (0, lodash_1.get)(entity, field);
31
+ if (entityField === null && id === null) {
32
+ return true;
33
+ }
34
+ let data = entityField;
35
+ if (data && typeof id === "string") {
36
+ data = data.toString();
37
+ }
38
+ return (
39
+ (data && data === id) ||
40
+ ((0, lodash_1.isObject)(entityField) && entityField.id === id)
41
+ );
42
+ })
43
+ .map((entity) => ({
44
+ ...entity,
45
+ [field]: undefined,
46
+ related: undefined,
47
+ blockedThread: blockNestedThreads || entity.blockedThread,
48
+ children:
49
+ entity.blockedThread && dropBlockedThreads
50
+ ? []
51
+ : (0, exports.buildNestedStructure)(
52
+ entities,
53
+ entity.id,
54
+ field,
55
+ dropBlockedThreads,
56
+ entity.blockedThread
57
+ ),
58
+ }));
59
+ exports.buildNestedStructure = buildNestedStructure;
60
+ const isEqualEntity = (existing, data, user) => {
61
+ const { author: existingAuthor = {} } = existing;
62
+ const { author } = data;
63
+ if (data.approvalStatus && existing.approvalStatus !== data.approvalStatus) {
64
+ return false;
65
+ }
66
+ if (user) {
67
+ const existingUserId = existingAuthor?.id || existingAuthor;
68
+ const receivedUserId = user?.id || author?.id;
69
+ return receivedUserId && existingUserId === receivedUserId;
70
+ }
71
+ return existingAuthor.id === author?.id;
72
+ };
73
+ exports.isEqualEntity = isEqualEntity;
74
+ const getRelatedGroups = (related) =>
75
+ related.split(constants_1.REGEX.relatedUid).filter((s) => s && s.length > 0);
76
+ exports.getRelatedGroups = getRelatedGroups;
77
+ const getModelUid = (name) => {
78
+ return strapi.plugin("comments").contentTypes[name]?.uid;
79
+ };
80
+ exports.getModelUid = getModelUid;
81
+ const filterOurResolvedReports = (item) =>
82
+ item
83
+ ? {
84
+ ...item,
85
+ reports: (item.reports || []).filter((report) => !report.resolved),
86
+ }
87
+ : item;
88
+ exports.filterOurResolvedReports = filterOurResolvedReports;
89
+ const convertContentTypeNameToSlug = (str) => {
90
+ const plainConversion = str.replace(
91
+ /[A-Z]/g,
92
+ (letter) => `-${letter.toLowerCase()}`
93
+ );
94
+ return (0, lodash_1.first)(plainConversion) === "-"
95
+ ? plainConversion.slice(1, plainConversion.length)
96
+ : plainConversion;
97
+ };
98
+ exports.convertContentTypeNameToSlug = convertContentTypeNameToSlug;
99
+ const buildAuthorModel = (item) => {
100
+ const {
101
+ authorUser,
102
+ authorId,
103
+ authorName,
104
+ authorEmail,
105
+ authorAvatar,
106
+ ...rest
107
+ } = item;
108
+ let author = {};
109
+ if (authorUser) {
110
+ author = {
111
+ id: authorUser.id,
112
+ name: authorUser.username,
113
+ email: authorUser.email,
114
+ avatar: authorUser.avatar,
115
+ };
116
+ } else if (authorId) {
117
+ author = {
118
+ id: authorId,
119
+ name: authorName,
120
+ email: authorEmail,
121
+ avatar: authorAvatar,
122
+ };
123
+ }
124
+ return {
125
+ ...rest,
126
+ author: (0, lodash_1.isEmpty)(author) ? undefined : author,
127
+ };
128
+ };
129
+ exports.buildAuthorModel = buildAuthorModel;
130
+ const buildConfigQueryProp = (prop = "") =>
131
+ (0, lodash_1.isArray)(prop) ? prop.join(".") : prop ?? "";
132
+ exports.buildConfigQueryProp = buildConfigQueryProp;
133
+ const resolveUserContextError = (user) => {
134
+ if (user) {
135
+ throw new error_1.default(401, "Not authenticated");
136
+ } else {
137
+ throw new error_1.default(403, "Not authorized");
138
+ }
139
+ };
140
+ exports.resolveUserContextError = resolveUserContextError;
141
+ //# 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
@@ -0,0 +1,23 @@
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",
10
+ };
11
+ exports.APPROVAL_STATUS = {
12
+ PENDING: "PENDING",
13
+ APPROVED: "APPROVED",
14
+ REJECTED: "REJECTED",
15
+ };
16
+ exports.REGEX = {
17
+ uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
18
+ relatedUid:
19
+ /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
20
+ email: /\S+@\S+\.\S+/,
21
+ sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i,
22
+ };
23
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,23 @@
1
+ declare type ErrorPayload =
2
+ | {
3
+ [key: string]: any;
4
+ }
5
+ | undefined;
6
+ interface IPluginError extends Error {
7
+ status: number;
8
+ payload: ErrorPayload;
9
+ }
10
+ export default class PluginError extends Error implements IPluginError {
11
+ status: number;
12
+ payload: ErrorPayload;
13
+ constructor(status: number, message: string, payload?: ErrorPayload);
14
+ toString(e?: PluginError): string;
15
+ toJSON():
16
+ | this
17
+ | {
18
+ name: string;
19
+ message: string;
20
+ };
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PluginError extends Error {
4
+ status;
5
+ payload;
6
+ constructor(status, message, payload = undefined) {
7
+ super();
8
+ this.name = "Strapi:Plugin:Comments";
9
+ this.status = status || 500;
10
+ this.message = message || "Internal error";
11
+ this.payload = payload;
12
+ Object.setPrototypeOf(this, PluginError.prototype);
13
+ }
14
+ toString(e = this) {
15
+ return `${e.name} - ${e.message}`;
16
+ }
17
+ toJSON() {
18
+ if (this.payload) {
19
+ return {
20
+ name: this.name,
21
+ message: this.message,
22
+ ...(this.payload || {}),
23
+ };
24
+ }
25
+ return this;
26
+ }
27
+ }
28
+ exports.default = PluginError;
29
+ //# sourceMappingURL=error.js.map