strapi-plugin-comments 3.0.2 → 3.0.4

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 (27) hide show
  1. package/dist/_chunks/{index-BoLOt7pX.js → index-BMAhFLKR.js} +2 -2
  2. package/dist/_chunks/{index-ChxSaqbf.mjs → index-CK1XCSqz.mjs} +2 -2
  3. package/dist/_chunks/{index-Czdnz9Ci.js → index-DCKroyap.js} +6 -6
  4. package/dist/_chunks/{index-7Geqfcar.js → index-DHhRVslt.js} +2 -2
  5. package/dist/_chunks/{index-Ct7A5TFY.mjs → index-DUWJDJLu.mjs} +2 -2
  6. package/dist/_chunks/{index-CIBI9Is6.mjs → index-PCqyAKE7.mjs} +10 -4
  7. package/dist/_chunks/{index-CiJKS9C3.js → index-_4jTpBrc.js} +10 -4
  8. package/dist/_chunks/{index-JWxk4wBa.mjs → index-yhf78avJ.mjs} +6 -6
  9. package/dist/admin/index.js +1 -1
  10. package/dist/admin/index.mjs +1 -1
  11. package/dist/admin/src/api/client.d.ts +10 -10
  12. package/dist/admin/src/api/schemas.d.ts +126 -126
  13. package/dist/admin/src/components/UserAvatar/index.d.ts +1 -1
  14. package/dist/admin/src/hooks/useAPI.d.ts +10 -10
  15. package/dist/admin/src/hooks/useCommentsAll.d.ts +2 -2
  16. package/dist/admin/src/hooks/useReports.d.ts +2 -2
  17. package/dist/server/index.js +34 -19
  18. package/dist/server/index.mjs +34 -19
  19. package/dist/server/src/controllers/index.d.ts +526 -1
  20. package/dist/server/src/index.d.ts +2281 -181
  21. package/dist/server/src/services/admin/admin.service.d.ts +526 -1
  22. package/dist/server/src/services/admin/utils.d.ts +9 -1
  23. package/dist/server/src/services/client.service.d.ts +526 -1
  24. package/dist/server/src/services/common.service.d.ts +1 -1
  25. package/dist/server/src/services/index.d.ts +1800 -225
  26. package/dist/server/src/validators/api/controllers/client.controller.validator.d.ts +527 -2
  27. package/package.json +1 -2
@@ -1,7 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { Author } from '../../api/schemas';
3
3
  type Props = Readonly<Pick<Author, 'avatar'> & {
4
- readonly name?: string;
4
+ readonly name?: string | null;
5
5
  readonly isAdminComment: boolean | null;
6
6
  }>;
7
7
  export declare const UserAvatar: FC<Props>;
@@ -149,8 +149,8 @@ export declare const useAPI: () => {
149
149
  author: {
150
150
  email: string;
151
151
  id: string | number;
152
- name?: string | undefined;
153
- avatar?: {
152
+ name?: string | null | undefined;
153
+ avatar?: string | {
154
154
  url: string;
155
155
  } | {
156
156
  url: string;
@@ -187,8 +187,8 @@ export declare const useAPI: () => {
187
187
  author: {
188
188
  email: string;
189
189
  id: string | number;
190
- name?: string | undefined;
191
- avatar?: {
190
+ name?: string | null | undefined;
191
+ avatar?: string | {
192
192
  url: string;
193
193
  } | {
194
194
  url: string;
@@ -224,8 +224,8 @@ export declare const useAPI: () => {
224
224
  author: {
225
225
  email: string;
226
226
  id: string | number;
227
- name?: string | undefined;
228
- avatar?: {
227
+ name?: string | null | undefined;
228
+ avatar?: string | {
229
229
  url: string;
230
230
  } | {
231
231
  url: string;
@@ -267,8 +267,8 @@ export declare const useAPI: () => {
267
267
  author: {
268
268
  email: string;
269
269
  id: string | number;
270
- name?: string | undefined;
271
- avatar?: {
270
+ name?: string | null | undefined;
271
+ avatar?: string | {
272
272
  url: string;
273
273
  } | {
274
274
  url: string;
@@ -360,8 +360,8 @@ export declare const useAPI: () => {
360
360
  author: {
361
361
  email: string;
362
362
  id: string | number;
363
- name?: string | undefined;
364
- avatar?: {
363
+ name?: string | null | undefined;
364
+ avatar?: string | {
365
365
  url: string;
366
366
  } | {
367
367
  url: string;
@@ -21,8 +21,8 @@ export declare const useCommentsAll: (queryParams: Record<string, string>) => im
21
21
  author: {
22
22
  email: string;
23
23
  id: string | number;
24
- name?: string | undefined;
25
- avatar?: {
24
+ name?: string | null | undefined;
25
+ avatar?: string | {
26
26
  url: string;
27
27
  } | {
28
28
  url: string;
@@ -26,8 +26,8 @@ export declare const useReports: (queryParams?: Record<string, string>) => impor
26
26
  author: {
27
27
  email: string;
28
28
  id: string | number;
29
- name?: string | undefined;
30
- avatar?: {
29
+ name?: string | null | undefined;
30
+ avatar?: string | {
31
31
  url: string;
32
32
  } | {
33
33
  url: string;
@@ -8438,7 +8438,7 @@ const getCommentSchema = (enabledCollections) => {
8438
8438
  relation: getRelationValidator(enabledCollections),
8439
8439
  content: zod.z.string().min(1),
8440
8440
  author: externalAuthorSchema.optional(),
8441
- threadOf: zod.z.string().optional(),
8441
+ threadOf: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
8442
8442
  approvalStatus: zod.z.nativeEnum(APPROVAL_STATUS).optional(),
8443
8443
  locale: zod.z.string().optional()
8444
8444
  });
@@ -8469,7 +8469,18 @@ const getBaseFindSchema = (enabledCollections) => {
8469
8469
  sort: orderByValidator.optional().nullable().default("createdAt:desc"),
8470
8470
  fields: zod.z.string().array().optional(),
8471
8471
  omit: zod.z.string().array().optional(),
8472
- filters: getFiltersOperators({ content: true, authorName: true, createdAt: true, updatedAt: true, id: true }).optional(),
8472
+ filters: getFiltersOperators({
8473
+ id: true,
8474
+ content: true,
8475
+ authorId: true,
8476
+ authorName: true,
8477
+ authorEmail: true,
8478
+ createdAt: true,
8479
+ updatedAt: true,
8480
+ removed: true,
8481
+ blocked: true,
8482
+ blockedThread: true
8483
+ }).optional(),
8473
8484
  isAdmin: zod.z.boolean().optional().default(false),
8474
8485
  populate: zod.z.record(zod.z.union([zod.z.boolean(), zod.z.object({ populate: zod.z.boolean() })])).optional(),
8475
8486
  limit: stringToNumberValidator.optional(),
@@ -8539,7 +8550,7 @@ const reportAbuseValidator = (config2, payload) => {
8539
8550
  const getRemoveCommentSchema = (enabledCollections) => {
8540
8551
  return zod.z.object({
8541
8552
  relation: getRelationValidator(enabledCollections),
8542
- commentId: zod.z.number(),
8553
+ commentId: zod.z.union([zod.z.string(), zod.z.number()]),
8543
8554
  authorId: zod.z.union([zod.z.string(), zod.z.number()])
8544
8555
  });
8545
8556
  };
@@ -9565,7 +9576,11 @@ const getAdminServiceUtils = lodashExports.once((strapi2) => {
9565
9576
  getPopulate() {
9566
9577
  return {
9567
9578
  authorUser: getDefaultAuthorPopulate(strapi2),
9568
- threadOf: true,
9579
+ threadOf: {
9580
+ populate: {
9581
+ authorUser: getDefaultAuthorPopulate(strapi2)
9582
+ }
9583
+ },
9569
9584
  reports: {
9570
9585
  where: {
9571
9586
  resolved: false
@@ -9742,7 +9757,8 @@ const adminServices = ({ strapi: strapi2 }) => {
9742
9757
  },
9743
9758
  ...defaultPopulate,
9744
9759
  startingFromId: levelThreadId,
9745
- isAdmin: true
9760
+ isAdmin: true,
9761
+ limit: Number.MAX_SAFE_INTEGER
9746
9762
  },
9747
9763
  false
9748
9764
  );
@@ -9999,10 +10015,11 @@ const clientService = ({ strapi: strapi2 }) => {
9999
10015
  const comment2 = await getCommentRepository(strapi2).create({
10000
10016
  data: {
10001
10017
  ...authorData,
10018
+ threadOf,
10019
+ locale,
10002
10020
  content: clearContent,
10003
10021
  related: relation,
10004
- approvalStatus: isApprovalFlowEnabled ? APPROVAL_STATUS.PENDING : null,
10005
- locale
10022
+ approvalStatus: isApprovalFlowEnabled ? APPROVAL_STATUS.PENDING : null
10006
10023
  },
10007
10024
  populate: {
10008
10025
  authorUser: true
@@ -10225,7 +10242,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10225
10242
  return { uid, relatedId: relatedStringId };
10226
10243
  },
10227
10244
  isValidUserContext(user) {
10228
- return !!user?.id;
10245
+ return user ? user.id != void 0 : true;
10229
10246
  },
10230
10247
  sanitizeCommentEntity(entity, blockedAuthors, omitProps = [], populate = {}) {
10231
10248
  const fieldsToPopulate = Array.isArray(populate) ? populate : Object.keys(populate || {});
@@ -10265,20 +10282,17 @@ const commonService = ({ strapi: strapi2 }) => ({
10265
10282
  sort: { [operator]: direction },
10266
10283
  select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect].flat()) : fields
10267
10284
  };
10268
- const entries = await getCommentRepository(strapi2).findMany({
10285
+ const params = {
10269
10286
  where: {
10270
10287
  ...filters,
10271
10288
  ...locale ? { locale } : {}
10272
10289
  },
10273
10290
  populate: populateClause,
10274
10291
  ...fieldsQuery,
10275
- limit: limit || PAGE_SIZE,
10276
- offset: skip || 0
10277
- });
10278
- let paginationData = void 0;
10279
- if (pagination?.withCount) {
10280
- paginationData = await getCommentRepository(strapi2).findWithCount({ where: { ...filters, ...locale ? { locale } : {} } }).then((result2) => result2.pagination);
10281
- }
10292
+ pageSize: pagination?.pageSize || limit || PAGE_SIZE,
10293
+ page: pagination?.page || (skip ? Math.floor(skip / limit) : 1) || 1
10294
+ };
10295
+ const { results: entries, pagination: resultPaginationData } = await getCommentRepository(strapi2).findWithCount(params);
10282
10296
  const entriesWithThreads = await Promise.all(
10283
10297
  entries.map(async (_2) => {
10284
10298
  const { results, pagination: { total } } = await getCommentRepository(strapi2).findWithCount({
@@ -10317,7 +10331,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10317
10331
  });
10318
10332
  return {
10319
10333
  data: hasRelatedEntitiesToMap ? result.map((_2) => this.mergeRelatedEntityTo(_2, relatedEntities)) : result,
10320
- pagination: paginationData
10334
+ pagination: resultPaginationData
10321
10335
  };
10322
10336
  },
10323
10337
  // Find comments and create relations tree structure
@@ -10330,9 +10344,10 @@ const commonService = ({ strapi: strapi2 }) => ({
10330
10344
  dropBlockedThreads,
10331
10345
  isAdmin = false,
10332
10346
  omit = [],
10333
- locale
10347
+ locale,
10348
+ limit
10334
10349
  }, relatedEntity) {
10335
- const entities = await this.findAllFlat({ filters, populate, sort, fields, isAdmin, omit, locale }, relatedEntity);
10350
+ const entities = await this.findAllFlat({ filters, populate, sort, fields, isAdmin, omit, locale, limit }, relatedEntity);
10336
10351
  return buildNestedStructure(
10337
10352
  entities?.data,
10338
10353
  startingFromId,
@@ -8437,7 +8437,7 @@ const getCommentSchema = (enabledCollections) => {
8437
8437
  relation: getRelationValidator(enabledCollections),
8438
8438
  content: z.string().min(1),
8439
8439
  author: externalAuthorSchema.optional(),
8440
- threadOf: z.string().optional(),
8440
+ threadOf: z.union([z.string(), z.number()]).optional(),
8441
8441
  approvalStatus: z.nativeEnum(APPROVAL_STATUS).optional(),
8442
8442
  locale: z.string().optional()
8443
8443
  });
@@ -8468,7 +8468,18 @@ const getBaseFindSchema = (enabledCollections) => {
8468
8468
  sort: orderByValidator.optional().nullable().default("createdAt:desc"),
8469
8469
  fields: z.string().array().optional(),
8470
8470
  omit: z.string().array().optional(),
8471
- filters: getFiltersOperators({ content: true, authorName: true, createdAt: true, updatedAt: true, id: true }).optional(),
8471
+ filters: getFiltersOperators({
8472
+ id: true,
8473
+ content: true,
8474
+ authorId: true,
8475
+ authorName: true,
8476
+ authorEmail: true,
8477
+ createdAt: true,
8478
+ updatedAt: true,
8479
+ removed: true,
8480
+ blocked: true,
8481
+ blockedThread: true
8482
+ }).optional(),
8472
8483
  isAdmin: z.boolean().optional().default(false),
8473
8484
  populate: z.record(z.union([z.boolean(), z.object({ populate: z.boolean() })])).optional(),
8474
8485
  limit: stringToNumberValidator.optional(),
@@ -8538,7 +8549,7 @@ const reportAbuseValidator = (config2, payload) => {
8538
8549
  const getRemoveCommentSchema = (enabledCollections) => {
8539
8550
  return z.object({
8540
8551
  relation: getRelationValidator(enabledCollections),
8541
- commentId: z.number(),
8552
+ commentId: z.union([z.string(), z.number()]),
8542
8553
  authorId: z.union([z.string(), z.number()])
8543
8554
  });
8544
8555
  };
@@ -9564,7 +9575,11 @@ const getAdminServiceUtils = lodashExports.once((strapi2) => {
9564
9575
  getPopulate() {
9565
9576
  return {
9566
9577
  authorUser: getDefaultAuthorPopulate(strapi2),
9567
- threadOf: true,
9578
+ threadOf: {
9579
+ populate: {
9580
+ authorUser: getDefaultAuthorPopulate(strapi2)
9581
+ }
9582
+ },
9568
9583
  reports: {
9569
9584
  where: {
9570
9585
  resolved: false
@@ -9741,7 +9756,8 @@ const adminServices = ({ strapi: strapi2 }) => {
9741
9756
  },
9742
9757
  ...defaultPopulate,
9743
9758
  startingFromId: levelThreadId,
9744
- isAdmin: true
9759
+ isAdmin: true,
9760
+ limit: Number.MAX_SAFE_INTEGER
9745
9761
  },
9746
9762
  false
9747
9763
  );
@@ -9998,10 +10014,11 @@ const clientService = ({ strapi: strapi2 }) => {
9998
10014
  const comment2 = await getCommentRepository(strapi2).create({
9999
10015
  data: {
10000
10016
  ...authorData,
10017
+ threadOf,
10018
+ locale,
10001
10019
  content: clearContent,
10002
10020
  related: relation,
10003
- approvalStatus: isApprovalFlowEnabled ? APPROVAL_STATUS.PENDING : null,
10004
- locale
10021
+ approvalStatus: isApprovalFlowEnabled ? APPROVAL_STATUS.PENDING : null
10005
10022
  },
10006
10023
  populate: {
10007
10024
  authorUser: true
@@ -10224,7 +10241,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10224
10241
  return { uid, relatedId: relatedStringId };
10225
10242
  },
10226
10243
  isValidUserContext(user) {
10227
- return !!user?.id;
10244
+ return user ? user.id != void 0 : true;
10228
10245
  },
10229
10246
  sanitizeCommentEntity(entity, blockedAuthors, omitProps = [], populate = {}) {
10230
10247
  const fieldsToPopulate = Array.isArray(populate) ? populate : Object.keys(populate || {});
@@ -10264,20 +10281,17 @@ const commonService = ({ strapi: strapi2 }) => ({
10264
10281
  sort: { [operator]: direction },
10265
10282
  select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect].flat()) : fields
10266
10283
  };
10267
- const entries = await getCommentRepository(strapi2).findMany({
10284
+ const params = {
10268
10285
  where: {
10269
10286
  ...filters,
10270
10287
  ...locale ? { locale } : {}
10271
10288
  },
10272
10289
  populate: populateClause,
10273
10290
  ...fieldsQuery,
10274
- limit: limit || PAGE_SIZE,
10275
- offset: skip || 0
10276
- });
10277
- let paginationData = void 0;
10278
- if (pagination?.withCount) {
10279
- paginationData = await getCommentRepository(strapi2).findWithCount({ where: { ...filters, ...locale ? { locale } : {} } }).then((result2) => result2.pagination);
10280
- }
10291
+ pageSize: pagination?.pageSize || limit || PAGE_SIZE,
10292
+ page: pagination?.page || (skip ? Math.floor(skip / limit) : 1) || 1
10293
+ };
10294
+ const { results: entries, pagination: resultPaginationData } = await getCommentRepository(strapi2).findWithCount(params);
10281
10295
  const entriesWithThreads = await Promise.all(
10282
10296
  entries.map(async (_2) => {
10283
10297
  const { results, pagination: { total } } = await getCommentRepository(strapi2).findWithCount({
@@ -10316,7 +10330,7 @@ const commonService = ({ strapi: strapi2 }) => ({
10316
10330
  });
10317
10331
  return {
10318
10332
  data: hasRelatedEntitiesToMap ? result.map((_2) => this.mergeRelatedEntityTo(_2, relatedEntities)) : result,
10319
- pagination: paginationData
10333
+ pagination: resultPaginationData
10320
10334
  };
10321
10335
  },
10322
10336
  // Find comments and create relations tree structure
@@ -10329,9 +10343,10 @@ const commonService = ({ strapi: strapi2 }) => ({
10329
10343
  dropBlockedThreads,
10330
10344
  isAdmin = false,
10331
10345
  omit = [],
10332
- locale
10346
+ locale,
10347
+ limit
10333
10348
  }, relatedEntity) {
10334
- const entities = await this.findAllFlat({ filters, populate, sort, fields, isAdmin, omit, locale }, relatedEntity);
10349
+ const entities = await this.findAllFlat({ filters, populate, sort, fields, isAdmin, omit, locale, limit }, relatedEntity);
10335
10350
  return buildNestedStructure(
10336
10351
  entities?.data,
10337
10352
  startingFromId,