strapi-plugin-comments 3.0.0-beta.1 → 3.0.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 (90) hide show
  1. package/README.md +81 -122
  2. package/dist/_chunks/{index-D3iNqWZT.mjs → index-BC5Odn17.mjs} +5 -5
  3. package/dist/_chunks/{index-BBcsmSTs.mjs → index-BIorFYba.mjs} +448 -256
  4. package/dist/_chunks/{index-Bcck91A8.js → index-COoWcAcA.js} +1290 -1144
  5. package/dist/_chunks/{index-CY_AVWS-.js → index-Ccb93U47.js} +445 -253
  6. package/dist/_chunks/{index-D9MOkoQ2.mjs → index-D1DAMkhj.mjs} +20 -26
  7. package/dist/_chunks/{index-BFPteXuP.js → index-R1krliyC.js} +5 -5
  8. package/dist/_chunks/{index-DJ32APz-.mjs → index-_exHAK6u.mjs} +1290 -1144
  9. package/dist/_chunks/{index-BXEk5PWx.js → index-k7z0V0lj.js} +20 -26
  10. package/dist/admin/index.js +1 -1
  11. package/dist/admin/index.mjs +1 -1
  12. package/dist/admin/src/api/client.d.ts +30 -50
  13. package/dist/admin/src/api/schemas.d.ts +432 -756
  14. package/dist/admin/src/components/UserAvatar/index.d.ts +1 -1
  15. package/dist/admin/src/hooks/useAPI.d.ts +30 -50
  16. package/dist/admin/src/hooks/useCommentsAll.d.ts +6 -10
  17. package/dist/admin/src/hooks/useReports.d.ts +6 -10
  18. package/dist/server/index.js +212 -157
  19. package/dist/server/index.mjs +212 -157
  20. package/dist/server/src/{@types-v5 → @types}/utils.d.ts +4 -0
  21. package/dist/server/src/bootstrap.d.ts +1 -1
  22. package/dist/server/src/config/index.d.ts +30 -0
  23. package/dist/server/src/content-types/index.d.ts +1 -1
  24. package/dist/server/src/controllers/admin.controller.d.ts +108 -29
  25. package/dist/server/src/controllers/client.controller.d.ts +121 -24
  26. package/dist/server/src/controllers/index.d.ts +300 -88
  27. package/dist/server/src/controllers/settings.controller.d.ts +33 -1
  28. package/dist/server/src/graphql/index.d.ts +1 -1
  29. package/dist/server/src/graphql/mutations/getCreateAbuseReport.d.ts +10 -4
  30. package/dist/server/src/graphql/mutations/getCreateComment.d.ts +10 -4
  31. package/dist/server/src/graphql/mutations/getRemoveComment.d.ts +10 -4
  32. package/dist/server/src/graphql/mutations/getUpdateComment.d.ts +10 -4
  33. package/dist/server/src/graphql/mutations/index.d.ts +2 -2
  34. package/dist/server/src/graphql/queries/findAllFlat.d.ts +18 -6
  35. package/dist/server/src/graphql/queries/findAllInHierarchy.d.ts +10 -4
  36. package/dist/server/src/graphql/queries/findAllPerAuthor.d.ts +18 -6
  37. package/dist/server/src/graphql/queries/index.d.ts +2 -2
  38. package/dist/server/src/graphql/types/getComment.d.ts +1 -1
  39. package/dist/server/src/graphql/types/getCommentAuthor.d.ts +1 -1
  40. package/dist/server/src/graphql/types/getCommentAuthorType.d.ts +1 -1
  41. package/dist/server/src/graphql/types/getCommentNested.d.ts +1 -1
  42. package/dist/server/src/graphql/types/getCreateComment.d.ts +1 -1
  43. package/dist/server/src/graphql/types/getCreateCommentAuthor.d.ts +1 -1
  44. package/dist/server/src/graphql/types/getCreateReport.d.ts +1 -1
  45. package/dist/server/src/graphql/types/getId.d.ts +1 -1
  46. package/dist/server/src/graphql/types/getIdentityAuthor.d.ts +1 -1
  47. package/dist/server/src/graphql/types/getRemoveComment.d.ts +1 -1
  48. package/dist/server/src/graphql/types/getReport.d.ts +1 -1
  49. package/dist/server/src/graphql/types/getReportReason.d.ts +1 -1
  50. package/dist/server/src/graphql/types/getResponseFindAll.d.ts +1 -1
  51. package/dist/server/src/graphql/types/getResponseFindAllPerAuthor.d.ts +1 -1
  52. package/dist/server/src/graphql/types/getResponseMeta.d.ts +1 -1
  53. package/dist/server/src/graphql/types/getResponsePagination.d.ts +1 -1
  54. package/dist/server/src/graphql/types/getUpdateComment.d.ts +1 -1
  55. package/dist/server/src/graphql/types/index.d.ts +1 -1
  56. package/dist/server/src/index.d.ts +931 -315
  57. package/dist/server/src/register/custom-fields/index.d.ts +1 -1
  58. package/dist/server/src/register/index.d.ts +1 -1
  59. package/dist/server/src/repositories/comment.repository.d.ts +10 -1
  60. package/dist/server/src/repositories/index.d.ts +0 -2
  61. package/dist/server/src/repositories/report.comment.repository.d.ts +38 -1
  62. package/dist/server/src/repositories/store.repository.d.ts +159 -3
  63. package/dist/server/src/repositories/utils.d.ts +1 -3
  64. package/dist/server/src/routes/admin.routes.d.ts +1 -1
  65. package/dist/server/src/routes/client.routes.d.ts +1 -1
  66. package/dist/server/src/routes/index.d.ts +2 -2
  67. package/dist/server/src/services/admin/admin.service.d.ts +232 -78
  68. package/dist/server/src/services/admin/utils.d.ts +1 -1
  69. package/dist/server/src/services/client.service.d.ts +178 -67
  70. package/dist/server/src/services/common.service.d.ts +60 -19
  71. package/dist/server/src/services/gql.service.d.ts +1 -1
  72. package/dist/server/src/services/index.d.ts +615 -223
  73. package/dist/server/src/services/settings.service.d.ts +25 -1
  74. package/dist/server/src/services/utils/functions.d.ts +1 -3
  75. package/dist/server/src/test/utils.d.ts +1 -0
  76. package/dist/server/src/utils/constants.d.ts +1 -1
  77. package/dist/server/src/utils/getConfig.d.ts +2 -2
  78. package/dist/server/src/utils/getPluginService.d.ts +2 -2
  79. package/dist/server/src/utils/throwError.d.ts +1 -1
  80. package/dist/server/src/validators/api/controllers/client.controller.validator.d.ts +16 -9
  81. package/dist/server/src/validators/api/controllers/settings.controller.validator.d.ts +4 -0
  82. package/dist/server/src/validators/repositories/comment.schema.d.ts +18 -3
  83. package/dist/server/src/validators/repositories/comment.validator.d.ts +384 -72
  84. package/dist/server/src/validators/repositories/reports.validator.d.ts +60 -18
  85. package/dist/server/src/validators/utils.d.ts +1 -1
  86. package/package.json +18 -12
  87. /package/dist/server/src/{@types-v5 → @types}/controllers.d.ts +0 -0
  88. /package/dist/server/src/{@types-v5 → @types}/index.d.ts +0 -0
  89. /package/dist/server/src/{@types-v5 → @types}/repositories.d.ts +0 -0
  90. /package/dist/server/src/{@types-v5 → @types}/routes.d.ts +0 -0
@@ -205,7 +205,7 @@ const getModelUid = (strapi2, name) => {
205
205
  const getDefaultAuthorPopulate = (strapi2) => {
206
206
  const strapiUserTypeUid = "plugin::users-permissions.user";
207
207
  const allowedTypes = ["media", "relation"];
208
- const { attributes } = strapi2.contentTypes[strapiUserTypeUid] || {};
208
+ const { attributes } = strapi2.contentType(strapiUserTypeUid) ?? { attributes: {} };
209
209
  const relationTypes = Object.keys(attributes)?.filter(
210
210
  (key) => allowedTypes.includes(attributes[key]?.type)
211
211
  );
@@ -1038,7 +1038,7 @@ lodash.exports;
1038
1038
  }
1039
1039
  var runInContext = function runInContext2(context) {
1040
1040
  context = context == null ? root : _2.defaults(root.Object(), context, _2.pick(root, contextProps));
1041
- var Array2 = context.Array, Date2 = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
1041
+ var Array2 = context.Array, Date = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
1042
1042
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
1043
1043
  var coreJsData = context["__core-js_shared__"];
1044
1044
  var funcToString = funcProto.toString;
@@ -1063,8 +1063,8 @@ lodash.exports;
1063
1063
  } catch (e) {
1064
1064
  }
1065
1065
  }();
1066
- var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1067
- var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
1066
+ var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1067
+ var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
1068
1068
  var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
1069
1069
  var metaMap = WeakMap && new WeakMap();
1070
1070
  var realNames = {};
@@ -2236,7 +2236,7 @@ lodash.exports;
2236
2236
  return symbolToString ? symbolToString.call(value) : "";
2237
2237
  }
2238
2238
  var result2 = value + "";
2239
- return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
2239
+ return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
2240
2240
  }
2241
2241
  function baseUniq(array, iteratee2, comparator) {
2242
2242
  var index2 = -1, includes2 = arrayIncludes, length = array.length, isCommon = true, result2 = [], seen = result2;
@@ -2788,7 +2788,7 @@ lodash.exports;
2788
2788
  bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
2789
2789
  bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
2790
2790
  if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
2791
- bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
2791
+ bitmask &= -4;
2792
2792
  }
2793
2793
  var newData = [
2794
2794
  func,
@@ -2844,7 +2844,7 @@ lodash.exports;
2844
2844
  }
2845
2845
  var length = partials ? partials.length : 0;
2846
2846
  if (!length) {
2847
- bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
2847
+ bitmask &= -97;
2848
2848
  partials = holders = undefined$1;
2849
2849
  }
2850
2850
  ary2 = ary2 === undefined$1 ? ary2 : nativeMax(toInteger(ary2), 0);
@@ -2877,7 +2877,7 @@ lodash.exports;
2877
2877
  holders = newData[4];
2878
2878
  arity = newData[9] = newData[9] === undefined$1 ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0);
2879
2879
  if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
2880
- bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
2880
+ bitmask &= -25;
2881
2881
  }
2882
2882
  if (!bitmask || bitmask == WRAP_BIND_FLAG) {
2883
2883
  var result2 = createBind(func, bitmask, thisArg);
@@ -3443,7 +3443,7 @@ lodash.exports;
3443
3443
  return value;
3444
3444
  }
3445
3445
  var result2 = value + "";
3446
- return result2 == "0" && 1 / value == -INFINITY ? "-0" : result2;
3446
+ return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
3447
3447
  }
3448
3448
  function toSource(func) {
3449
3449
  if (func != null) {
@@ -4507,7 +4507,7 @@ lodash.exports;
4507
4507
  }
4508
4508
  var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
4509
4509
  function isSafeInteger(value) {
4510
- return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
4510
+ return isInteger(value) && value >= -9007199254740991 && value <= MAX_SAFE_INTEGER;
4511
4511
  }
4512
4512
  var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
4513
4513
  function isString(value) {
@@ -4548,7 +4548,7 @@ lodash.exports;
4548
4548
  return value === 0 ? value : 0;
4549
4549
  }
4550
4550
  value = toNumber(value);
4551
- if (value === INFINITY || value === -INFINITY) {
4551
+ if (value === INFINITY || value === -Infinity) {
4552
4552
  var sign = value < 0 ? -1 : 1;
4553
4553
  return sign * MAX_INTEGER;
4554
4554
  }
@@ -4583,7 +4583,7 @@ lodash.exports;
4583
4583
  return copyObject(value, keysIn(value));
4584
4584
  }
4585
4585
  function toSafeInteger(value) {
4586
- return value ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
4586
+ return value ? baseClamp(toInteger(value), -9007199254740991, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
4587
4587
  }
4588
4588
  function toString(value) {
4589
4589
  return value == null ? "" : baseToString(value);
@@ -5821,29 +5821,6 @@ lodash.exports;
5821
5821
  }).call(commonjsGlobal);
5822
5822
  })(lodash, lodash.exports);
5823
5823
  var lodashExports = lodash.exports;
5824
- let PluginError$1 = class PluginError extends Error {
5825
- constructor(status, message, payload = void 0) {
5826
- super();
5827
- this.name = "Strapi:Plugin:Comments";
5828
- this.status = status || 500;
5829
- this.message = message || "Internal error";
5830
- this.payload = payload;
5831
- Object.setPrototypeOf(this, PluginError.prototype);
5832
- }
5833
- toString(e = this) {
5834
- return `${e.name} - ${e.message}`;
5835
- }
5836
- toJSON() {
5837
- if (this.payload) {
5838
- return {
5839
- ...this.payload,
5840
- name: this.name,
5841
- message: this.message
5842
- };
5843
- }
5844
- return this;
5845
- }
5846
- };
5847
5824
  const flatInput = (payload) => {
5848
5825
  const {
5849
5826
  sort,
@@ -5883,7 +5860,6 @@ const flatInput = (payload) => {
5883
5860
  }
5884
5861
  };
5885
5862
  }
5886
- ({ ...filters });
5887
5863
  return {
5888
5864
  ...payload,
5889
5865
  filters: {
@@ -6024,6 +6000,7 @@ const getComment = (nexus) => {
6024
6000
  name: "CommentSingle",
6025
6001
  definition(t) {
6026
6002
  t.id("id");
6003
+ t.string("documentId");
6027
6004
  t.nonNull.string("content");
6028
6005
  t.boolean("blocked");
6029
6006
  t.boolean("blockedThread");
@@ -6059,6 +6036,7 @@ const getCommentNested = (nexus) => {
6059
6036
  name: "CommentNested",
6060
6037
  definition(t) {
6061
6038
  t.id("id");
6039
+ t.string("documentId");
6062
6040
  t.nonNull.string("content");
6063
6041
  t.boolean("blocked");
6064
6042
  t.boolean("blockedThread");
@@ -8110,8 +8088,19 @@ const typesFactories = [
8110
8088
  getReport
8111
8089
  ];
8112
8090
  const getTypes = (config2, nexus) => typesFactories.map((factory) => factory(nexus, config2));
8091
+ const getExtensionService = (strapi2) => strapi2.plugin("graphql").service("extension");
8092
+ const disableDefaultGQL = (strapi2) => {
8093
+ const extensionService = getExtensionService(strapi2);
8094
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
8095
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
8096
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
8097
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
8098
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
8099
+ extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
8100
+ };
8113
8101
  const setupGQL = async ({ strapi: strapi2 }) => {
8114
8102
  if (strapi2.plugin("graphql")) {
8103
+ disableDefaultGQL(strapi2);
8115
8104
  const enableCollections = await getPluginService(strapi2, "common").getConfig(CONFIG_PARAMS$1.ENABLED_COLLECTIONS, []);
8116
8105
  if (enableCollections.length) {
8117
8106
  await handleConfig(strapi2);
@@ -8119,13 +8108,7 @@ const setupGQL = async ({ strapi: strapi2 }) => {
8119
8108
  }
8120
8109
  };
8121
8110
  const handleConfig = async (strapi2) => {
8122
- const extensionService = strapi2.plugin("graphql").service("extension");
8123
- extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
8124
- extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
8125
- extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
8126
- extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
8127
- extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
8128
- extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
8111
+ const extensionService = getExtensionService(strapi2);
8129
8112
  const config2 = await getPluginService(strapi2, "common").getConfig();
8130
8113
  extensionService.use(({ strapi: strapi22, nexus }) => {
8131
8114
  const types = getTypes(config2, nexus);
@@ -8234,7 +8217,11 @@ const schemaConfig = z.object({
8234
8217
  [CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS]: z.array(z.string()),
8235
8218
  gql: z.object({
8236
8219
  auth: z.boolean().optional()
8237
- }).optional()
8220
+ }).optional(),
8221
+ client: z.object({
8222
+ url: z.string().nullable(),
8223
+ contactEmail: z.string().nullable()
8224
+ }).default({ url: null, contactEmail: null })
8238
8225
  });
8239
8226
  const config = {
8240
8227
  default: schemaConfig.parse(defaultPluginConfig),
@@ -8271,14 +8258,14 @@ const isRight = (e) => {
8271
8258
  };
8272
8259
  const makeLeft = (value) => ({ left: value });
8273
8260
  const makeRight = (value) => ({ right: value });
8274
- class PluginError2 extends Error {
8261
+ let PluginError$1 = class PluginError extends Error {
8275
8262
  constructor(status, message, payload = void 0) {
8276
8263
  super();
8277
8264
  this.name = "Strapi:Plugin:Comments";
8278
8265
  this.status = status || 500;
8279
8266
  this.message = message || "Internal error";
8280
8267
  this.payload = payload;
8281
- Object.setPrototypeOf(this, PluginError2.prototype);
8268
+ Object.setPrototypeOf(this, PluginError.prototype);
8282
8269
  }
8283
8270
  toString(e = this) {
8284
8271
  return `${e.name} - ${e.message}`;
@@ -8293,9 +8280,9 @@ class PluginError2 extends Error {
8293
8280
  }
8294
8281
  return this;
8295
8282
  }
8296
- }
8283
+ };
8297
8284
  const throwError = (ctx, e) => {
8298
- if (e instanceof PluginError2) {
8285
+ if (e instanceof PluginError$1) {
8299
8286
  return ctx.throw(e.status, JSON.stringify(e));
8300
8287
  }
8301
8288
  return e;
@@ -8382,7 +8369,7 @@ const queryPaginationSchema = z.object({ pageSize: stringToNumberValidator.defau
8382
8369
  const validate = (result) => {
8383
8370
  if (!result.success) {
8384
8371
  const message = result.error.issues.map((i) => `Path: ${i.path.join(".")} Code: ${i.code} Message: ${i.message}`).join("\n");
8385
- return makeLeft(new PluginError2(400, message));
8372
+ return makeLeft(new PluginError$1(400, message));
8386
8373
  }
8387
8374
  return makeRight(result.data);
8388
8375
  };
@@ -8450,7 +8437,7 @@ const getCommentSchema = (enabledCollections) => {
8450
8437
  relation: getRelationValidator(enabledCollections),
8451
8438
  content: z.string().min(1),
8452
8439
  author: externalAuthorSchema.optional(),
8453
- threadOf: z.number().optional(),
8440
+ threadOf: z.string().optional(),
8454
8441
  approvalStatus: z.nativeEnum(APPROVAL_STATUS).optional(),
8455
8442
  locale: z.string().optional()
8456
8443
  });
@@ -8463,7 +8450,7 @@ const newCommentValidator = (enabledCollections, relation, payload) => {
8463
8450
  };
8464
8451
  const updateCommentValidator = (enabledCollections, payload) => {
8465
8452
  return validate(
8466
- getCommentSchema(enabledCollections).pick({ content: true, relation: true }).merge(getStringToNumberValidator({ commentId: AVAILABLE_OPERATORS.single })).safeParse(payload)
8453
+ getCommentSchema(enabledCollections).pick({ content: true, relation: true, author: true }).merge(getStringToNumberValidator({ commentId: AVAILABLE_OPERATORS.single })).safeParse(payload)
8467
8454
  );
8468
8455
  };
8469
8456
  const getRelationSchema = (enabledCollections) => z.object({
@@ -8537,16 +8524,16 @@ const findAllPerAuthorValidator = (params, payload) => {
8537
8524
  ...params
8538
8525
  }));
8539
8526
  };
8540
- const getReportAbuseSchema = (enabledCollections) => {
8527
+ const getReportAbuseSchema = (config2) => {
8541
8528
  return z.object({
8542
- relation: getRelationValidator(enabledCollections),
8543
- commentId: z.number(),
8529
+ relation: getRelationValidator(config2[CONFIG_PARAMS.ENABLED_COLLECTIONS]),
8530
+ commentId: stringToNumberValidator,
8544
8531
  content: z.string().min(1),
8545
- reason: z.string().min(1)
8532
+ reason: z.nativeEnum(config2.reportReasons)
8546
8533
  });
8547
8534
  };
8548
- const reportAbuseValidator = (enabledCollections, payload) => {
8549
- return validate(getReportAbuseSchema(enabledCollections).safeParse(payload));
8535
+ const reportAbuseValidator = (config2, payload) => {
8536
+ return validate(getReportAbuseSchema(config2).safeParse(payload));
8550
8537
  };
8551
8538
  const getRemoveCommentSchema = (enabledCollections) => {
8552
8539
  return z.object({
@@ -8713,7 +8700,7 @@ const dbBaseCommentSchema = z.object({
8713
8700
  authorName: z.string().nullable(),
8714
8701
  authorEmail: z.string().email().nullable(),
8715
8702
  authorAvatar: z.string().nullable(),
8716
- authorUser: z.string().optional().nullable(),
8703
+ authorUser: z.union([z.string(), z.object({ id: z.number(), email: z.string().email() })]).optional().nullable(),
8717
8704
  locale: z.string().nullable()
8718
8705
  });
8719
8706
  const paginationSchema = z.object({
@@ -8803,7 +8790,7 @@ const reportSchema = z.object({
8803
8790
  updatedAt: z.string(),
8804
8791
  publishedAt: z.string().nullable(),
8805
8792
  locale: z.string().nullable(),
8806
- related: relatedSchema.nullable()
8793
+ related: relatedSchema.nullable().optional()
8807
8794
  });
8808
8795
  const findPageSchema = z.object({
8809
8796
  results: z.array(reportSchema),
@@ -8838,7 +8825,7 @@ const reportResultValidator = {
8838
8825
  update: updateResultSchema,
8839
8826
  create: reportSchema
8840
8827
  };
8841
- const getReportCommentRepository = lodashExports.once((strapi2) => {
8828
+ const getReportCommentRepositorySource = (strapi2) => {
8842
8829
  const modelUid = getModelUid(strapi2, "comment-report");
8843
8830
  const repository = strapi2.query(modelUid);
8844
8831
  return {
@@ -8862,8 +8849,9 @@ const getReportCommentRepository = lodashExports.once((strapi2) => {
8862
8849
  return repository.create(params).then(shouldValidateObject(isValidationEnabled, reportResultValidator.create));
8863
8850
  }
8864
8851
  };
8865
- });
8866
- const getCommentRepository = lodashExports.once((strapi2) => {
8852
+ };
8853
+ const getReportCommentRepository = lodashExports.once(getReportCommentRepositorySource);
8854
+ const getCommentRepositorySource = (strapi2) => {
8867
8855
  const modelUid = getModelUid(strapi2, "comment");
8868
8856
  return {
8869
8857
  async findMany(params) {
@@ -8894,8 +8882,9 @@ const getCommentRepository = lodashExports.once((strapi2) => {
8894
8882
  return strapi2.query(modelUid).create(params).then(shouldValidateObject(isValidationEnabled, commentResultValidator.create));
8895
8883
  }
8896
8884
  };
8897
- });
8898
- const getStoreRepository = lodashExports.once((strapi2) => {
8885
+ };
8886
+ const getCommentRepository = lodashExports.once(getCommentRepositorySource);
8887
+ const getStoreRepositorySource = (strapi2) => {
8899
8888
  return {
8900
8889
  getLocalConfig(prop, defaultValue) {
8901
8890
  return strapi2.config.get([PLUGIN_SELECTOR, prop].filter(Boolean).join("."), defaultValue);
@@ -8972,7 +8961,8 @@ const getStoreRepository = lodashExports.once((strapi2) => {
8972
8961
  return this.get();
8973
8962
  }
8974
8963
  };
8975
- });
8964
+ };
8965
+ const getStoreRepository = lodashExports.once(getStoreRepositorySource);
8976
8966
  const controllers$1 = ({ strapi: strapi2 }) => ({
8977
8967
  getService(name) {
8978
8968
  return getPluginService(strapi2, name);
@@ -8984,7 +8974,6 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
8984
8974
  const configResult = await this.getStoreRepository().get(true);
8985
8975
  if (isRight(configResult)) {
8986
8976
  const config2 = unwrapEither(configResult);
8987
- console.log("config.enabledCollections", config2.enabledCollections);
8988
8977
  const result = newCommentValidator(config2.enabledCollections, ctx.params.relation, ctx.request.body);
8989
8978
  if (isRight(result)) {
8990
8979
  return this.getService("client").create(result.right, ctx.state.user);
@@ -9037,8 +9026,9 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
9037
9026
  if (isRight(configResult)) {
9038
9027
  const config2 = unwrapEither(configResult);
9039
9028
  const result = updateCommentValidator(config2.enabledCollections, {
9040
- ...ctx.query,
9041
- ...ctx.params
9029
+ ...ctx.params,
9030
+ content: ctx.request.body.content,
9031
+ author: ctx.request.body.author
9042
9032
  });
9043
9033
  if (isRight(result)) {
9044
9034
  return await this.getService("client").update(
@@ -9056,7 +9046,7 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
9056
9046
  const configResult = await this.getStoreRepository().get(true);
9057
9047
  if (isRight(configResult)) {
9058
9048
  const config2 = unwrapEither(configResult);
9059
- const result = reportAbuseValidator(config2.enabledCollections, {
9049
+ const result = reportAbuseValidator(config2, {
9060
9050
  ...ctx.request.body,
9061
9051
  ...ctx.params
9062
9052
  });
@@ -9327,7 +9317,6 @@ const routes$1 = [
9327
9317
  path: "/:relation",
9328
9318
  handler: "client.findAllInHierarchy",
9329
9319
  config: {
9330
- auth: false,
9331
9320
  policies: [],
9332
9321
  description: "Find all comments related to configured Collection / Single Type and return them in a nested structure",
9333
9322
  tag: {
@@ -9342,7 +9331,6 @@ const routes$1 = [
9342
9331
  path: "/:relation",
9343
9332
  handler: "client.post",
9344
9333
  config: {
9345
- auth: false,
9346
9334
  policies: [],
9347
9335
  description: "Post a comment against configured Collection / Single Type",
9348
9336
  tag: {
@@ -9357,7 +9345,6 @@ const routes$1 = [
9357
9345
  path: "/:relation/flat",
9358
9346
  handler: "client.findAllFlat",
9359
9347
  config: {
9360
- auth: false,
9361
9348
  policies: [],
9362
9349
  description: "Find all comments related to configured Collection / Single Type and return them in a flat structure for further processing",
9363
9350
  tag: {
@@ -9372,7 +9359,6 @@ const routes$1 = [
9372
9359
  path: "/:relation/comment/:commentId",
9373
9360
  handler: "client.put",
9374
9361
  config: {
9375
- auth: false,
9376
9362
  policies: [],
9377
9363
  description: "Update comment related to configured Collection / Single Type if user is the author",
9378
9364
  tag: {
@@ -9387,7 +9373,6 @@ const routes$1 = [
9387
9373
  path: "/:relation/comment/:commentId/report-abuse",
9388
9374
  handler: "client.reportAbuse",
9389
9375
  config: {
9390
- auth: false,
9391
9376
  policies: [],
9392
9377
  description: "Report an abuse against comment for configured Collection / Single Type",
9393
9378
  tag: {
@@ -9402,7 +9387,6 @@ const routes$1 = [
9402
9387
  path: "/:relation/comment/:commentId",
9403
9388
  handler: "client.removeComment",
9404
9389
  config: {
9405
- auth: false,
9406
9390
  policies: [],
9407
9391
  description: "Remove comment related to configured Collection / Single Type if user is the author",
9408
9392
  tag: {
@@ -9417,7 +9401,6 @@ const routes$1 = [
9417
9401
  path: "/author/:authorId",
9418
9402
  handler: "client.findAllPerAuthor",
9419
9403
  config: {
9420
- auth: false,
9421
9404
  policies: [],
9422
9405
  description: "Find all comments created by Strapi user",
9423
9406
  tag: {
@@ -9432,7 +9415,6 @@ const routes$1 = [
9432
9415
  path: "/author/:authorId/:type",
9433
9416
  handler: "client.findAllPerAuthor",
9434
9417
  config: {
9435
- auth: false,
9436
9418
  policies: [],
9437
9419
  description: "Find all comments created by specified type of user",
9438
9420
  tag: {
@@ -9453,6 +9435,29 @@ const routes = {
9453
9435
  routes: adminRoutes$1
9454
9436
  }
9455
9437
  };
9438
+ class PluginError2 extends Error {
9439
+ constructor(status, message, payload = void 0) {
9440
+ super();
9441
+ this.name = "Strapi:Plugin:Comments";
9442
+ this.status = status || 500;
9443
+ this.message = message || "Internal error";
9444
+ this.payload = payload;
9445
+ Object.setPrototypeOf(this, PluginError2.prototype);
9446
+ }
9447
+ toString(e = this) {
9448
+ return `${e.name} - ${e.message}`;
9449
+ }
9450
+ toJSON() {
9451
+ if (this.payload) {
9452
+ return {
9453
+ ...this.payload,
9454
+ name: this.name,
9455
+ message: this.message
9456
+ };
9457
+ }
9458
+ return this;
9459
+ }
9460
+ }
9456
9461
  const buildNestedStructure = (entities, id = null, field = "threadOf", dropBlockedThreads = false, blockNestedThreads = false) => entities.filter((entity) => {
9457
9462
  const entityField = lodashExports.get(entity, field);
9458
9463
  if (entityField === null && id === null) {
@@ -9518,14 +9523,14 @@ const buildAuthorModel = (item, blockedAuthorProps, fieldsToPopulate = []) => {
9518
9523
  );
9519
9524
  return {
9520
9525
  ...rest,
9521
- author
9526
+ author: lodashExports.isEmpty(author) ? item.author || {} : author
9522
9527
  };
9523
9528
  };
9524
9529
  const resolveUserContextError = (user) => {
9525
9530
  if (user) {
9526
- throw new PluginError$1(401, "Not authenticated");
9531
+ throw new PluginError2(401, "Not authenticated");
9527
9532
  } else {
9528
- throw new PluginError$1(403, "Not authorized");
9533
+ throw new PluginError2(403, "Not authorized");
9529
9534
  }
9530
9535
  };
9531
9536
  const getAuthorName = (author) => {
@@ -9716,16 +9721,16 @@ const adminServices = ({ strapi: strapi2 }) => {
9716
9721
  where: { id }
9717
9722
  });
9718
9723
  if (!entity) {
9719
- throw new PluginError2(404, "Not found");
9724
+ throw new PluginError$1(404, "Not found");
9720
9725
  }
9721
9726
  const { relatedId, uid } = this.getCommonService().parseRelationString(entity.related);
9722
- const relatedEntity = await strapi2.entityService.findOne(uid, relatedId).then((_2) => {
9727
+ const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId }).then((_2) => {
9723
9728
  if (!_2) {
9724
- throw new PluginError2(404, "Relation not found");
9729
+ throw new PluginError$1(404, "Relation not found");
9725
9730
  }
9726
9731
  return { ..._2, uid };
9727
9732
  });
9728
- const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.id : null;
9733
+ const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.documentId : null;
9729
9734
  const entitiesOnSameLevel = await this.getCommonService().findAllInHierarchy(
9730
9735
  {
9731
9736
  query: {
@@ -9782,7 +9787,7 @@ const adminServices = ({ strapi: strapi2 }) => {
9782
9787
  data: { approvalStatus: APPROVAL_STATUS.APPROVED }
9783
9788
  });
9784
9789
  if (!entity) {
9785
- throw new PluginError2(404, "Not found");
9790
+ throw new PluginError$1(404, "Not found");
9786
9791
  }
9787
9792
  return this.getCommonService().sanitizeCommentEntity(entity, []);
9788
9793
  },
@@ -9792,7 +9797,7 @@ const adminServices = ({ strapi: strapi2 }) => {
9792
9797
  data: { approvalStatus: APPROVAL_STATUS.REJECTED }
9793
9798
  });
9794
9799
  if (!entity) {
9795
- throw new PluginError2(404, "Not found");
9800
+ throw new PluginError$1(404, "Not found");
9796
9801
  }
9797
9802
  return this.getCommonService().sanitizeCommentEntity(entity, []);
9798
9803
  },
@@ -9838,14 +9843,14 @@ const adminServices = ({ strapi: strapi2 }) => {
9838
9843
  }
9839
9844
  });
9840
9845
  }
9841
- throw new PluginError2(
9846
+ throw new PluginError$1(
9842
9847
  400,
9843
9848
  "At least one of selected reports got invalid comment entity relation. Try again."
9844
9849
  );
9845
9850
  },
9846
9851
  async resolveAllAbuseReportsForComment(id) {
9847
9852
  if (!id) {
9848
- throw new PluginError2(
9853
+ throw new PluginError$1(
9849
9854
  400,
9850
9855
  "There is something wrong with comment Id. Try again."
9851
9856
  );
@@ -9862,7 +9867,7 @@ const adminServices = ({ strapi: strapi2 }) => {
9862
9867
  },
9863
9868
  async resolveAllAbuseReportsForThread(commentId) {
9864
9869
  if (!commentId) {
9865
- throw new PluginError2(
9870
+ throw new PluginError$1(
9866
9871
  400,
9867
9872
  "There is something wrong with comment Id. Try again."
9868
9873
  );
@@ -9900,7 +9905,7 @@ const adminServices = ({ strapi: strapi2 }) => {
9900
9905
  where: { id }
9901
9906
  });
9902
9907
  if (!entity) {
9903
- throw new PluginError2(404, "Not found");
9908
+ throw new PluginError$1(404, "Not found");
9904
9909
  }
9905
9910
  return getCommentRepository(strapi2).create({
9906
9911
  data: {
@@ -9920,7 +9925,7 @@ const adminServices = ({ strapi: strapi2 }) => {
9920
9925
  data: { content }
9921
9926
  });
9922
9927
  if (!entity) {
9923
- throw new PluginError2(404, "Not found");
9928
+ throw new PluginError$1(404, "Not found");
9924
9929
  }
9925
9930
  return this.getCommonService().sanitizeCommentEntity(entity, []);
9926
9931
  }
@@ -9934,8 +9939,8 @@ const tryCatch = async (callback, throwError2) => {
9934
9939
  }
9935
9940
  };
9936
9941
  const clientService = ({ strapi: strapi2 }) => {
9937
- const createAuthor = (isValidContent, author, user) => {
9938
- if (isValidContent && user) {
9942
+ const createAuthor = (author, user) => {
9943
+ if (user) {
9939
9944
  return {
9940
9945
  authorUser: user.id
9941
9946
  };
@@ -9957,7 +9962,7 @@ const clientService = ({ strapi: strapi2 }) => {
9957
9962
  const { uid, relatedId } = this.getCommonService().parseRelationString(relation);
9958
9963
  const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId, locale });
9959
9964
  if (!relatedEntity) {
9960
- throw new PluginError$1(
9965
+ throw new PluginError2(
9961
9966
  400,
9962
9967
  `Relation for field "related" does not exist. Check your payload please.`
9963
9968
  );
@@ -9972,21 +9977,23 @@ const clientService = ({ strapi: strapi2 }) => {
9972
9977
  async () => {
9973
9978
  return threadOf ? await this.getCommonService().findOne({ id: threadOf, related: relation, locale }) : null;
9974
9979
  },
9975
- new PluginError$1(400, "Thread does not exist")
9980
+ new PluginError2(400, "Thread does not exist")
9976
9981
  );
9977
9982
  if (isLeft(threadData)) {
9978
9983
  throw unwrapEither(threadData);
9979
9984
  }
9980
9985
  const linkToThread = unwrapEither(threadData);
9981
- this.getCommonService().isValidUserContext(user);
9986
+ if (!author && !this.getCommonService().isValidUserContext(user)) {
9987
+ throw resolveUserContextError(user);
9988
+ }
9982
9989
  const clearContent = await this.getCommonService().checkBadWords(content);
9983
- const authorData = createAuthor(isApprovalFlowEnabled, author, user);
9990
+ const authorData = createAuthor(author, user);
9984
9991
  const authorNotProperlyProvided = !lodashExports.isEmpty(authorData) && !(authorData.authorId || authorData.authorUser);
9985
9992
  if (lodashExports.isEmpty(authorData) || authorNotProperlyProvided) {
9986
- throw new PluginError$1(400, `Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
9993
+ throw new PluginError2(400, `Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
9987
9994
  }
9988
9995
  if (isApprovalFlowEnabled && approvalStatus && approvalStatus !== APPROVAL_STATUS.PENDING) {
9989
- throw new PluginError$1(400, "Invalid approval status");
9996
+ throw new PluginError2(400, "Invalid approval status");
9990
9997
  }
9991
9998
  const comment2 = await getCommentRepository(strapi2).create({
9992
9999
  data: {
@@ -10013,19 +10020,22 @@ const clientService = ({ strapi: strapi2 }) => {
10013
10020
  return sanitizedEntity;
10014
10021
  },
10015
10022
  // Update a comment
10016
- async update({ commentId, content }, user) {
10017
- const validContext = this.getCommonService().isValidUserContext(user);
10018
- if (!validContext) {
10023
+ async update({ commentId, content, author, relation }, user) {
10024
+ if (!author && !this.getCommonService().isValidUserContext(user)) {
10019
10025
  throw resolveUserContextError(user);
10020
10026
  }
10027
+ const authorId = user?.id || author?.id;
10021
10028
  if (await this.getCommonService().checkBadWords(content)) {
10022
10029
  const blockedAuthorProps = await this.getCommonService().getConfig(CONFIG_PARAMS$1.AUTHOR_BLOCKED_PROPS, []);
10023
- const entity = await getCommentRepository(strapi2).update({
10024
- where: { id: commentId },
10025
- data: { content },
10026
- populate: { threadOf: true, authorUser: true }
10027
- });
10028
- return this.getCommonService().sanitizeCommentEntity(entity, blockedAuthorProps);
10030
+ const existingComment = await this.getCommonService().findOne({ id: commentId, related: relation });
10031
+ if (existingComment && existingComment.author?.id?.toString() === authorId?.toString()) {
10032
+ const entity = await getCommentRepository(strapi2).update({
10033
+ where: { id: commentId },
10034
+ data: { content },
10035
+ populate: { threadOf: true, authorUser: true }
10036
+ });
10037
+ return this.getCommonService().sanitizeCommentEntity(entity, blockedAuthorProps);
10038
+ }
10029
10039
  }
10030
10040
  },
10031
10041
  // Report abuse in comment
@@ -10039,7 +10049,7 @@ const clientService = ({ strapi: strapi2 }) => {
10039
10049
  related: relation
10040
10050
  });
10041
10051
  if (reportAgainstEntity.isAdminComment) {
10042
- throw new PluginError$1(
10052
+ throw new PluginError2(
10043
10053
  403,
10044
10054
  `You're not allowed to take an action on that entity. This in a admin comment.`
10045
10055
  );
@@ -10064,10 +10074,10 @@ const clientService = ({ strapi: strapi2 }) => {
10064
10074
  return response;
10065
10075
  }
10066
10076
  } else {
10067
- throw new PluginError$1(500, "Report cannot be created");
10077
+ throw new PluginError2(500, "Report cannot be created");
10068
10078
  }
10069
10079
  }
10070
- throw new PluginError$1(
10080
+ throw new PluginError2(
10071
10081
  403,
10072
10082
  `You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.`
10073
10083
  );
@@ -10076,12 +10086,12 @@ const clientService = ({ strapi: strapi2 }) => {
10076
10086
  }
10077
10087
  },
10078
10088
  async markAsRemoved({ commentId, relation, authorId }, user) {
10079
- if (!this.getCommonService().isValidUserContext(user)) {
10089
+ if (!authorId && !this.getCommonService().isValidUserContext(user)) {
10080
10090
  throw resolveUserContextError(user);
10081
10091
  }
10082
10092
  const author = user?.id || authorId;
10083
10093
  if (!author) {
10084
- throw new PluginError$1(
10094
+ throw new PluginError2(
10085
10095
  403,
10086
10096
  `You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`
10087
10097
  );
@@ -10110,23 +10120,88 @@ const clientService = ({ strapi: strapi2 }) => {
10110
10120
  const doNotPopulateAuthor = await this.getCommonService().getConfig(CONFIG_PARAMS$1.AUTHOR_BLOCKED_PROPS, []);
10111
10121
  return this.getCommonService().sanitizeCommentEntity(removedEntity, doNotPopulateAuthor);
10112
10122
  } else {
10113
- throw new PluginError$1(
10123
+ throw new PluginError2(
10114
10124
  404,
10115
10125
  `Entity does not exist or you're not allowed to take an action on it`
10116
10126
  );
10117
10127
  }
10118
10128
  } catch (e) {
10119
- throw new PluginError$1(
10129
+ throw new PluginError2(
10120
10130
  404,
10121
10131
  `Entity does not exist or you're not allowed to take an action on it`
10122
10132
  );
10123
10133
  }
10124
10134
  },
10125
10135
  async sendAbuseReportEmail(reason, content) {
10136
+ const SUPER_ADMIN_ROLE = "strapi-super-admin";
10137
+ const rolesToNotify = await this.getCommonService().getConfig(CONFIG_PARAMS$1.MODERATOR_ROLES, [SUPER_ADMIN_ROLE]);
10138
+ if (rolesToNotify.length > 0) {
10139
+ const emails = await strapi2.query("admin::user").findMany({ where: { roles: { code: rolesToNotify } } }).then((users) => users.map((user) => user.email));
10140
+ if (emails.length > 0) {
10141
+ const from = await strapi2.query("admin::user").findOne({ where: { roles: { code: SUPER_ADMIN_ROLE } } });
10142
+ if (strapi2.plugin("email")) {
10143
+ await strapi2.plugin("email").service("email").send({
10144
+ to: emails,
10145
+ from: from.email,
10146
+ subject: "New abuse report on comment",
10147
+ text: `
10148
+ There was a new abuse report on your app.
10149
+ Reason: ${reason}
10150
+ Message: ${content}
10151
+ `
10152
+ });
10153
+ }
10154
+ }
10155
+ }
10126
10156
  },
10127
10157
  async markAsRemovedNested(commentId, status) {
10158
+ return this.getCommonService().modifiedNestedNestedComments(
10159
+ commentId,
10160
+ "removed",
10161
+ status
10162
+ );
10128
10163
  },
10129
- async sendResponseNotification(_entry) {
10164
+ async sendResponseNotification(entity) {
10165
+ if (entity.threadOf) {
10166
+ const thread = typeof entity.threadOf === "object" ? entity.threadOf : await this.getCommonService().findOne({ id: entity.threadOf });
10167
+ let emailRecipient = thread?.author?.email;
10168
+ if (thread.authorUser && !emailRecipient) {
10169
+ const strapiUser = typeof thread.authorUser === "object" ? thread.authorUser : await strapi2.query("plugin::users-permissions.user").findOne({
10170
+ where: { id: thread.authorUser }
10171
+ });
10172
+ emailRecipient = strapiUser?.email;
10173
+ }
10174
+ if (emailRecipient) {
10175
+ const superAdmin = await strapi2.query("admin::user").findOne({
10176
+ where: {
10177
+ roles: { code: "strapi-super-admin" }
10178
+ }
10179
+ });
10180
+ const emailSender = await this.getCommonService().getConfig("client.contactEmail", superAdmin.email);
10181
+ const clientAppUrl = await this.getCommonService().getConfig("client.url", "our site");
10182
+ try {
10183
+ await strapi2.plugin("email").service("email").send({
10184
+ to: [emailRecipient],
10185
+ from: emailSender,
10186
+ subject: "You've got a new response to your comment",
10187
+ text: `Hello ${thread?.author?.name || emailRecipient}!
10188
+ You've got a new response to your comment by ${entity?.author?.name || entity?.author?.email}.
10189
+
10190
+ ------
10191
+
10192
+ "${entity.content}"
10193
+
10194
+ ------
10195
+
10196
+ Visit ${clientAppUrl} and continue the discussion.
10197
+ `
10198
+ });
10199
+ } catch (err) {
10200
+ strapi2.log.error(err);
10201
+ throw err;
10202
+ }
10203
+ }
10204
+ }
10130
10205
  }
10131
10206
  };
10132
10207
  };
@@ -10136,7 +10211,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10136
10211
  async getConfig(prop, defaultValue, useLocal = false) {
10137
10212
  const storeRepository = getStoreRepository(strapi2);
10138
10213
  const config2 = await storeRepository.getConfig();
10139
- if (prop && config2 && !useLocal) {
10214
+ if (prop && !useLocal) {
10140
10215
  return lodashExports.get(config2, prop, defaultValue);
10141
10216
  }
10142
10217
  if (useLocal) {
@@ -10187,7 +10262,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10187
10262
  const [operator, direction] = getOrderBy(sort);
10188
10263
  const fieldsQuery = {
10189
10264
  sort: { [operator]: direction },
10190
- select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect]) : fields
10265
+ select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect].flat()) : fields
10191
10266
  };
10192
10267
  const entries = await getCommentRepository(strapi2).findMany({
10193
10268
  where: {
@@ -10275,7 +10350,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10275
10350
  }
10276
10351
  });
10277
10352
  if (!entity) {
10278
- throw new PluginError2(400, "Comment does not exist. Check your payload please.");
10353
+ throw new PluginError$1(400, "Comment does not exist. Check your payload please.");
10279
10354
  }
10280
10355
  const doNotPopulateAuthor = await this.getConfig(CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
10281
10356
  const item = this.sanitizeCommentEntity(entity, doNotPopulateAuthor);
@@ -10379,7 +10454,11 @@ const commonService = ({ strapi: strapi2 }) => ({
10379
10454
  )
10380
10455
  };
10381
10456
  },
10382
- async modifiedNestedNestedComments(id, fieldName, value) {
10457
+ // TODO: we need to add deepLimit to the function to prevent infinite loops
10458
+ async modifiedNestedNestedComments(id, fieldName, value, deepLimit = 10) {
10459
+ if (deepLimit === 0) {
10460
+ return true;
10461
+ }
10383
10462
  try {
10384
10463
  const entities = await this.findMany({ where: { threadOf: id } });
10385
10464
  const changedEntries = await getCommentRepository(strapi2).updateMany({
@@ -10388,7 +10467,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10388
10467
  });
10389
10468
  if (entities.length === changedEntries.count && changedEntries.count > 0) {
10390
10469
  const nestedTransactions = await Promise.all(
10391
- entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value))
10470
+ entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value, deepLimit - 1))
10392
10471
  );
10393
10472
  return nestedTransactions.length === changedEntries.count;
10394
10473
  }
@@ -10401,7 +10480,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10401
10480
  const config2 = await this.getConfig(CONFIG_PARAMS.BAD_WORDS, true);
10402
10481
  if (config2) {
10403
10482
  if (content && isProfane({ testString: content })) {
10404
- throw new PluginError2(
10483
+ throw new PluginError$1(
10405
10484
  400,
10406
10485
  "Bad language used! Please polite your comment...",
10407
10486
  {
@@ -11501,7 +11580,7 @@ lodash_min.exports;
11501
11580
  if (bh(n2)) return c(n2, vu) + "";
11502
11581
  if (bc(n2)) return vs ? vs.call(n2) : "";
11503
11582
  var t2 = n2 + "";
11504
- return "0" == t2 && 1 / n2 == -Sn ? "-0" : t2;
11583
+ return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
11505
11584
  }
11506
11585
  function gu(n2, t2, r2) {
11507
11586
  var e2 = -1, u2 = o, i2 = n2.length, c2 = true, a2 = [], l2 = a2;
@@ -11820,7 +11899,7 @@ lodash_min.exports;
11820
11899
  }
11821
11900
  function oi(n2, t2, r2, e2, u2, i2, o2, f2, c2, a2) {
11822
11901
  var l2 = t2 & yn, s2 = l2 ? o2 : X, h2 = l2 ? X : o2, p3 = l2 ? i2 : X, _3 = l2 ? X : i2;
11823
- t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &= ~(_n | vn));
11902
+ t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &= -4);
11824
11903
  var v2 = [n2, t2, u2, p3, s2, _3, h2, f2, c2, a2], g2 = r2.apply(X, v2);
11825
11904
  return $i(n2) && Ss(g2, v2), g2.placeholder = e2, Yi(g2, n2, t2);
11826
11905
  }
@@ -11844,12 +11923,12 @@ lodash_min.exports;
11844
11923
  var c2 = t2 & vn;
11845
11924
  if (!c2 && "function" != typeof n2) throw new pl(en);
11846
11925
  var a2 = e2 ? e2.length : 0;
11847
- if (a2 || (t2 &= ~(bn | wn), e2 = u2 = X), o2 = o2 === X ? o2 : Gl(kc(o2), 0), f2 = f2 === X ? f2 : kc(f2), a2 -= u2 ? u2.length : 0, t2 & wn) {
11926
+ if (a2 || (t2 &= -97, e2 = u2 = X), o2 = o2 === X ? o2 : Gl(kc(o2), 0), f2 = f2 === X ? f2 : kc(f2), a2 -= u2 ? u2.length : 0, t2 & wn) {
11848
11927
  var l2 = e2, s2 = u2;
11849
11928
  e2 = u2 = X;
11850
11929
  }
11851
11930
  var h2 = c2 ? X : Os(n2), p3 = [n2, t2, r2, e2, u2, l2, s2, i2, o2, f2];
11852
- if (h2 && qi(p3, h2), n2 = p3[0], t2 = p3[1], r2 = p3[2], e2 = p3[3], u2 = p3[4], f2 = p3[9] = p3[9] === X ? c2 ? 0 : n2.length : Gl(p3[9] - a2, 0), !f2 && t2 & (yn | dn) && (t2 &= ~(yn | dn)), t2 && t2 != _n) _3 = t2 == yn || t2 == dn ? Hu(n2, t2, f2) : t2 != bn && t2 != (_n | bn) || u2.length ? Qu.apply(X, p3) : ei(n2, t2, r2, e2);
11931
+ if (h2 && qi(p3, h2), n2 = p3[0], t2 = p3[1], r2 = p3[2], e2 = p3[3], u2 = p3[4], f2 = p3[9] = p3[9] === X ? c2 ? 0 : n2.length : Gl(p3[9] - a2, 0), !f2 && t2 & (yn | dn) && (t2 &= -25), t2 && t2 != _n) _3 = t2 == yn || t2 == dn ? Hu(n2, t2, f2) : t2 != bn && t2 != (_n | bn) || u2.length ? Qu.apply(X, p3) : ei(n2, t2, r2, e2);
11853
11932
  else var _3 = Zu(n2, t2, r2);
11854
11933
  return Yi((h2 ? ms : Ss)(_3, p3), n2, t2);
11855
11934
  }
@@ -12188,7 +12267,7 @@ lodash_min.exports;
12188
12267
  function no(n2) {
12189
12268
  if ("string" == typeof n2 || bc(n2)) return n2;
12190
12269
  var t2 = n2 + "";
12191
- return "0" == t2 && 1 / n2 == -Sn ? "-0" : t2;
12270
+ return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
12192
12271
  }
12193
12272
  function to(n2) {
12194
12273
  if (null != n2) {
@@ -12752,7 +12831,7 @@ lodash_min.exports;
12752
12831
  return "function" == typeof r2 && r2 instanceof r2 && dl.call(r2) == jl;
12753
12832
  }
12754
12833
  function yc(n2) {
12755
- return ic(n2) && n2 >= -Wn && n2 <= Wn;
12834
+ return ic(n2) && n2 >= -9007199254740991 && n2 <= Wn;
12756
12835
  }
12757
12836
  function dc(n2) {
12758
12837
  return "string" == typeof n2 || !bh(n2) && cc(n2) && we(n2) == rt;
@@ -12778,7 +12857,7 @@ lodash_min.exports;
12778
12857
  }
12779
12858
  function Ac(n2) {
12780
12859
  if (!n2) return 0 === n2 ? n2 : 0;
12781
- if (n2 = Ic(n2), n2 === Sn || n2 === -Sn) {
12860
+ if (n2 = Ic(n2), n2 === Sn || n2 === -Infinity) {
12782
12861
  return (n2 < 0 ? -1 : 1) * Ln;
12783
12862
  }
12784
12863
  return n2 === n2 ? n2 : 0;
@@ -12806,7 +12885,7 @@ lodash_min.exports;
12806
12885
  return $u(n2, qc(n2));
12807
12886
  }
12808
12887
  function zc(n2) {
12809
- return n2 ? Mr2(kc(n2), -Wn, Wn) : 0 === n2 ? n2 : 0;
12888
+ return n2 ? Mr2(kc(n2), -9007199254740991, Wn) : 0 === n2 ? n2 : 0;
12810
12889
  }
12811
12890
  function Ec(n2) {
12812
12891
  return null == n2 ? "" : vu(n2);
@@ -14719,7 +14798,6 @@ class DynamicOutputPropertyDef {
14719
14798
  }
14720
14799
  withNexusSymbol(DynamicOutputPropertyDef, NexusTypes.DynamicOutputProperty);
14721
14800
  const virtualScalarAttributes = ["id"];
14722
- const customFields = ["filterBy", "filterByValue"];
14723
14801
  const addScalarAttribute = (builder, attributeName, attribute) => {
14724
14802
  const { naming, mappers } = strapi.plugin("graphql").service("utils");
14725
14803
  const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
@@ -14768,19 +14846,16 @@ const gqlService = ({ strapi: strapi2 }) => {
14768
14846
  }
14769
14847
  if (Array.isArray(queryFilters)) {
14770
14848
  return queryFilters.reduce((acc, filtersItem) => {
14771
- if (!customFields.includes(filtersItem)) {
14772
- acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
14773
- }
14849
+ acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
14774
14850
  return acc;
14775
- });
14851
+ }, []);
14776
14852
  }
14777
14853
  const resultMap = {};
14778
- const { filterBy, filterByValue, ...filters } = queryFilters;
14779
14854
  const { attributes } = contentType;
14780
14855
  const isAttribute = (attributeName) => {
14781
14856
  return virtualScalarAttributes.includes(attributeName) || fp.has(attributeName, attributes);
14782
14857
  };
14783
- for (const [key, value] of Object.entries(filters)) {
14858
+ for (const [key, value] of Object.entries(queryFilters)) {
14784
14859
  if (isAttribute(key)) {
14785
14860
  const attribute = attributes[key];
14786
14861
  if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
@@ -14802,23 +14877,6 @@ const gqlService = ({ strapi: strapi2 }) => {
14802
14877
  }
14803
14878
  }
14804
14879
  }
14805
- if (filterBy === "DATE_CREATED") {
14806
- const date = new Date(filterByValue);
14807
- if (!filterByValue || Number.isNaN(+date)) {
14808
- throw new Error('Invalid date specified in "filterByValue"');
14809
- }
14810
- const start = date.setHours(0, 0, 0, 0);
14811
- const end = date.setHours(23, 59, 59, 999);
14812
- resultMap.createdAt = {
14813
- $between: [start, end]
14814
- };
14815
- }
14816
- if (filterBy === "APPROVAL_STATUS") {
14817
- if (!filterByValue) {
14818
- throw new Error('Empty "filterByValue" parameter');
14819
- }
14820
- resultMap.approvalStatus = filterByValue;
14821
- }
14822
14880
  return resultMap;
14823
14881
  };
14824
14882
  return {
@@ -14850,9 +14908,6 @@ const gqlService = ({ strapi: strapi2 }) => {
14850
14908
  for (const operator of rootLevelOperators()) {
14851
14909
  operator.add(t, filtersTypeName);
14852
14910
  }
14853
- customFields.forEach((field) => {
14854
- t.field(field, { type: "String" });
14855
- });
14856
14911
  }
14857
14912
  });
14858
14913
  }