strapi-plugin-comments 3.2.2 → 3.2.3-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import * as Fr from "react";
2
2
  import { useMemo as ql, createContext as u_, useState as ll } from "react";
3
- import { p as a_, a as Rr } from "./index-BFK8nlhm.mjs";
3
+ import { p as a_, a as Rr } from "./index-BOiPKIfk.mjs";
4
4
  import { jsx as Ye, jsxs as ti } from "react/jsx-runtime";
5
5
  import { useQuery as f_, QueryClientProvider as l_, QueryClient as s_ } from "@tanstack/react-query";
6
6
  import { getFetchClient as c_, useRBAC as p_ } from "@strapi/strapi/admin";
@@ -5427,9 +5427,9 @@ const ws = Eu(), g1 = v.object({
5427
5427
  name: v.string(),
5428
5428
  code: v.string(),
5429
5429
  description: v.string(),
5430
- createdAt: v.string(),
5431
- updatedAt: v.string(),
5432
- publishedAt: v.string(),
5430
+ createdAt: v.string().nullable(),
5431
+ updatedAt: v.string().nullable(),
5432
+ publishedAt: v.string().nullable(),
5433
5433
  locale: v.string().nullable(),
5434
5434
  usersCount: v.number()
5435
5435
  }), w1 = v.object({
@@ -5445,11 +5445,11 @@ const ws = Eu(), g1 = v.object({
5445
5445
  username: v.string().nullable(),
5446
5446
  email: v.string(),
5447
5447
  isActive: v.boolean(),
5448
- blocked: v.boolean(),
5448
+ blocked: v.boolean().nullable(),
5449
5449
  preferedLanguage: v.string().nullable(),
5450
- createdAt: v.string(),
5451
- updatedAt: v.string(),
5452
- publishedAt: v.string(),
5450
+ createdAt: v.string().nullable(),
5451
+ updatedAt: v.string().nullable(),
5452
+ publishedAt: v.string().nullable(),
5453
5453
  locale: v.null(),
5454
5454
  roles: v.array(
5455
5455
  v.object({
@@ -1 +1 @@
1
- "use strict";const e=require("../_chunks/index-BIcDaXS9.js");require("react");require("@strapi/design-system");require("@strapi/icons");module.exports=e.index;
1
+ "use strict";const e=require("../_chunks/index-DMbK1qUe.js");require("react");require("@strapi/design-system");require("@strapi/icons");module.exports=e.index;
@@ -1,4 +1,4 @@
1
- import { i as p } from "../_chunks/index-BFK8nlhm.mjs";
1
+ import { i as p } from "../_chunks/index-BOiPKIfk.mjs";
2
2
  import "react";
3
3
  import "@strapi/design-system";
4
4
  import "@strapi/icons";
@@ -76,9 +76,9 @@ export declare const getApiClient: (fetch: ReturnType<typeof getFetchClient>) =>
76
76
  code: string;
77
77
  id: number;
78
78
  documentId: string;
79
- createdAt: string;
80
- updatedAt: string;
81
- publishedAt: string;
79
+ createdAt: string | null;
80
+ updatedAt: string | null;
81
+ publishedAt: string | null;
82
82
  locale: string | null;
83
83
  name: string;
84
84
  description: string;
@@ -91,11 +91,11 @@ export declare const getApiClient: (fetch: ReturnType<typeof getFetchClient>) =>
91
91
  email: string;
92
92
  id: number;
93
93
  documentId: string;
94
- createdAt: string;
95
- updatedAt: string;
96
- publishedAt: string;
94
+ createdAt: string | null;
95
+ updatedAt: string | null;
96
+ publishedAt: string | null;
97
97
  locale: null;
98
- blocked: boolean;
98
+ blocked: boolean | null;
99
99
  firstname: string;
100
100
  lastname: string | null;
101
101
  username: string | null;
@@ -2957,18 +2957,18 @@ export declare const rolesListSchema: z.ZodObject<{
2957
2957
  name: z.ZodString;
2958
2958
  code: z.ZodString;
2959
2959
  description: z.ZodString;
2960
- createdAt: z.ZodString;
2961
- updatedAt: z.ZodString;
2962
- publishedAt: z.ZodString;
2960
+ createdAt: z.ZodNullable<z.ZodString>;
2961
+ updatedAt: z.ZodNullable<z.ZodString>;
2962
+ publishedAt: z.ZodNullable<z.ZodString>;
2963
2963
  locale: z.ZodNullable<z.ZodString>;
2964
2964
  usersCount: z.ZodNumber;
2965
2965
  }, "strip", z.ZodTypeAny, {
2966
2966
  code: string;
2967
2967
  id: number;
2968
2968
  documentId: string;
2969
- createdAt: string;
2970
- updatedAt: string;
2971
- publishedAt: string;
2969
+ createdAt: string | null;
2970
+ updatedAt: string | null;
2971
+ publishedAt: string | null;
2972
2972
  locale: string | null;
2973
2973
  name: string;
2974
2974
  description: string;
@@ -2977,9 +2977,9 @@ export declare const rolesListSchema: z.ZodObject<{
2977
2977
  code: string;
2978
2978
  id: number;
2979
2979
  documentId: string;
2980
- createdAt: string;
2981
- updatedAt: string;
2982
- publishedAt: string;
2980
+ createdAt: string | null;
2981
+ updatedAt: string | null;
2982
+ publishedAt: string | null;
2983
2983
  locale: string | null;
2984
2984
  name: string;
2985
2985
  description: string;
@@ -2990,9 +2990,9 @@ export declare const rolesListSchema: z.ZodObject<{
2990
2990
  code: string;
2991
2991
  id: number;
2992
2992
  documentId: string;
2993
- createdAt: string;
2994
- updatedAt: string;
2995
- publishedAt: string;
2993
+ createdAt: string | null;
2994
+ updatedAt: string | null;
2995
+ publishedAt: string | null;
2996
2996
  locale: string | null;
2997
2997
  name: string;
2998
2998
  description: string;
@@ -3003,9 +3003,9 @@ export declare const rolesListSchema: z.ZodObject<{
3003
3003
  code: string;
3004
3004
  id: number;
3005
3005
  documentId: string;
3006
- createdAt: string;
3007
- updatedAt: string;
3008
- publishedAt: string;
3006
+ createdAt: string | null;
3007
+ updatedAt: string | null;
3008
+ publishedAt: string | null;
3009
3009
  locale: string | null;
3010
3010
  name: string;
3011
3011
  description: string;
@@ -3021,11 +3021,11 @@ export declare const userSchema: z.ZodObject<{
3021
3021
  username: z.ZodNullable<z.ZodString>;
3022
3022
  email: z.ZodString;
3023
3023
  isActive: z.ZodBoolean;
3024
- blocked: z.ZodBoolean;
3024
+ blocked: z.ZodNullable<z.ZodBoolean>;
3025
3025
  preferedLanguage: z.ZodNullable<z.ZodString>;
3026
- createdAt: z.ZodString;
3027
- updatedAt: z.ZodString;
3028
- publishedAt: z.ZodString;
3026
+ createdAt: z.ZodNullable<z.ZodString>;
3027
+ updatedAt: z.ZodNullable<z.ZodString>;
3028
+ publishedAt: z.ZodNullable<z.ZodString>;
3029
3029
  locale: z.ZodNull;
3030
3030
  roles: z.ZodArray<z.ZodObject<{
3031
3031
  id: z.ZodNumber;
@@ -3047,11 +3047,11 @@ export declare const userSchema: z.ZodObject<{
3047
3047
  email: string;
3048
3048
  id: number;
3049
3049
  documentId: string;
3050
- createdAt: string;
3051
- updatedAt: string;
3052
- publishedAt: string;
3050
+ createdAt: string | null;
3051
+ updatedAt: string | null;
3052
+ publishedAt: string | null;
3053
3053
  locale: null;
3054
- blocked: boolean;
3054
+ blocked: boolean | null;
3055
3055
  firstname: string;
3056
3056
  lastname: string | null;
3057
3057
  username: string | null;
@@ -3067,11 +3067,11 @@ export declare const userSchema: z.ZodObject<{
3067
3067
  email: string;
3068
3068
  id: number;
3069
3069
  documentId: string;
3070
- createdAt: string;
3071
- updatedAt: string;
3072
- publishedAt: string;
3070
+ createdAt: string | null;
3071
+ updatedAt: string | null;
3072
+ publishedAt: string | null;
3073
3073
  locale: null;
3074
- blocked: boolean;
3074
+ blocked: boolean | null;
3075
3075
  firstname: string;
3076
3076
  lastname: string | null;
3077
3077
  username: string | null;
@@ -3089,11 +3089,11 @@ export declare const userSchema: z.ZodObject<{
3089
3089
  email: string;
3090
3090
  id: number;
3091
3091
  documentId: string;
3092
- createdAt: string;
3093
- updatedAt: string;
3094
- publishedAt: string;
3092
+ createdAt: string | null;
3093
+ updatedAt: string | null;
3094
+ publishedAt: string | null;
3095
3095
  locale: null;
3096
- blocked: boolean;
3096
+ blocked: boolean | null;
3097
3097
  firstname: string;
3098
3098
  lastname: string | null;
3099
3099
  username: string | null;
@@ -3111,11 +3111,11 @@ export declare const userSchema: z.ZodObject<{
3111
3111
  email: string;
3112
3112
  id: number;
3113
3113
  documentId: string;
3114
- createdAt: string;
3115
- updatedAt: string;
3116
- publishedAt: string;
3114
+ createdAt: string | null;
3115
+ updatedAt: string | null;
3116
+ publishedAt: string | null;
3117
3117
  locale: null;
3118
- blocked: boolean;
3118
+ blocked: boolean | null;
3119
3119
  firstname: string;
3120
3120
  lastname: string | null;
3121
3121
  username: string | null;
@@ -3,11 +3,11 @@ export declare const UserContext: import("react").Context<{
3
3
  email: string;
4
4
  id: number;
5
5
  documentId: string;
6
- createdAt: string;
7
- updatedAt: string;
8
- publishedAt: string;
6
+ createdAt: string | null;
7
+ updatedAt: string | null;
8
+ publishedAt: string | null;
9
9
  locale: null;
10
- blocked: boolean;
10
+ blocked: boolean | null;
11
11
  firstname: string;
12
12
  lastname: string | null;
13
13
  username: string | null;
@@ -73,9 +73,9 @@ export declare const useAPI: () => {
73
73
  code: string;
74
74
  id: number;
75
75
  documentId: string;
76
- createdAt: string;
77
- updatedAt: string;
78
- publishedAt: string;
76
+ createdAt: string | null;
77
+ updatedAt: string | null;
78
+ publishedAt: string | null;
79
79
  locale: string | null;
80
80
  name: string;
81
81
  description: string;
@@ -88,11 +88,11 @@ export declare const useAPI: () => {
88
88
  email: string;
89
89
  id: number;
90
90
  documentId: string;
91
- createdAt: string;
92
- updatedAt: string;
93
- publishedAt: string;
91
+ createdAt: string | null;
92
+ updatedAt: string | null;
93
+ publishedAt: string | null;
94
94
  locale: null;
95
- blocked: boolean;
95
+ blocked: boolean | null;
96
96
  firstname: string;
97
97
  lastname: string | null;
98
98
  username: string | null;
@@ -302,11 +302,11 @@ export declare const useAPI: () => {
302
302
  email: string;
303
303
  id: number;
304
304
  documentId: string;
305
- createdAt: string;
306
- updatedAt: string;
307
- publishedAt: string;
305
+ createdAt: string | null;
306
+ updatedAt: string | null;
307
+ publishedAt: string | null;
308
308
  locale: null;
309
- blocked: boolean;
309
+ blocked: boolean | null;
310
310
  firstname: string;
311
311
  lastname: string | null;
312
312
  username: string | null;
@@ -34,11 +34,11 @@ export declare const useCommentMutations: (callbacksMutation?: CallbacksMutation
34
34
  email: string;
35
35
  id: number;
36
36
  documentId: string;
37
- createdAt: string;
38
- updatedAt: string;
39
- publishedAt: string;
37
+ createdAt: string | null;
38
+ updatedAt: string | null;
39
+ publishedAt: string | null;
40
40
  locale: null;
41
- blocked: boolean;
41
+ blocked: boolean | null;
42
42
  firstname: string;
43
43
  lastname: string | null;
44
44
  username: string | null;
@@ -2,11 +2,11 @@ export declare const useUserContext: () => {
2
2
  email: string;
3
3
  id: number;
4
4
  documentId: string;
5
- createdAt: string;
6
- updatedAt: string;
7
- publishedAt: string;
5
+ createdAt: string | null;
6
+ updatedAt: string | null;
7
+ publishedAt: string | null;
8
8
  locale: null;
9
- blocked: boolean;
9
+ blocked: boolean | null;
10
10
  firstname: string;
11
11
  lastname: string | null;
12
12
  username: string | null;
@@ -51,9 +51,9 @@ export declare const useSettingsAPI: (callbacksMutation?: CallbacksMutation) =>
51
51
  code: string;
52
52
  id: number;
53
53
  documentId: string;
54
- createdAt: string;
55
- updatedAt: string;
56
- publishedAt: string;
54
+ createdAt: string | null;
55
+ updatedAt: string | null;
56
+ publishedAt: string | null;
57
57
  locale: string | null;
58
58
  name: string;
59
59
  description: string;
@@ -79,7 +79,7 @@ spurious results.`)}}return!1},b0=5;function w0(i,u){const[o,h]=u?[i,u]:[void 0,
79
79
  `)))!==null&&u!==void 0?u:!1}function wm(i,u){switch(i.kind){case Xt.NULL:return null;case Xt.INT:return parseInt(i.value,10);case Xt.FLOAT:return parseFloat(i.value);case Xt.STRING:case Xt.ENUM:case Xt.BOOLEAN:return i.value;case Xt.LIST:return i.values.map(o=>wm(o,u));case Xt.OBJECT:return Im(i.fields,o=>o.name.value,o=>wm(o.value,u));case Xt.VARIABLE:return u?.[i.name.value]}}function cr(i){if(i!=null||He(!1,"Must provide name."),typeof i=="string"||He(!1,"Expected name to be a string."),i.length===0)throw new Bn("Expected name to be a non-empty string.");for(let u=1;u<i.length;++u)if(!f0(i.charCodeAt(u)))throw new Bn(`Names must only contain [_a-zA-Z0-9] but "${i}" does not.`);if(!c0(i.charCodeAt(0)))throw new Bn(`Names must start with [_a-zA-Z] but "${i}" does not.`);return i}function F0(i){if(i==="true"||i==="false"||i==="null")throw new Bn(`Enum values cannot be named: ${i}`);return cr(i)}function ll(i){return U0(i)||M0(i)||W0(i)||B0(i)||j0(i)||$0(i)||k0(i)||Rm(i)}function U0(i){return Ui(i,nv)}function M0(i){return Ui(i,H0)}function W0(i){return Ui(i,J0)}function B0(i){return Ui(i,X0)}function j0(i){return Ui(i,K0)}function $0(i){return Ui(i,ey)}function k0(i){return Ui(i,V0)}function Rm(i){return Ui(i,G0)}class V0{constructor(u){ll(u)||He(!1,`Expected ${jn(u)} to be a GraphQL type.`),this.ofType=u}get[Symbol.toStringTag](){return"GraphQLList"}toString(){return"["+String(this.ofType)+"]"}toJSON(){return this.toString()}}class G0{constructor(u){q0(u)||He(!1,`Expected ${jn(u)} to be a GraphQL nullable type.`),this.ofType=u}get[Symbol.toStringTag](){return"GraphQLNonNull"}toString(){return String(this.ofType)+"!"}toJSON(){return this.toString()}}function q0(i){return ll(i)&&!Rm(i)}function ev(i){return typeof i=="function"?i():i}function tv(i){return typeof i=="function"?i():i}class nv{constructor(u){var o,h,m,A;const S=(o=u.parseValue)!==null&&o!==void 0?o:Mm;this.name=cr(u.name),this.description=u.description,this.specifiedByURL=u.specifiedByURL,this.serialize=(h=u.serialize)!==null&&h!==void 0?h:Mm,this.parseValue=S,this.parseLiteral=(m=u.parseLiteral)!==null&&m!==void 0?m:(C,R)=>S(wm(C,R)),this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(A=u.extensionASTNodes)!==null&&A!==void 0?A:[],u.specifiedByURL==null||typeof u.specifiedByURL=="string"||He(!1,`${this.name} must provide "specifiedByURL" as a string, but got: ${jn(u.specifiedByURL)}.`),u.serialize==null||typeof u.serialize=="function"||He(!1,`${this.name} must provide "serialize" function. If this custom Scalar is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.`),u.parseLiteral&&(typeof u.parseValue=="function"&&typeof u.parseLiteral=="function"||He(!1,`${this.name} must provide both "parseValue" and "parseLiteral" functions.`))}get[Symbol.toStringTag](){return"GraphQLScalarType"}toConfig(){return{name:this.name,description:this.description,specifiedByURL:this.specifiedByURL,serialize:this.serialize,parseValue:this.parseValue,parseLiteral:this.parseLiteral,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}}class H0{constructor(u){var o;this.name=cr(u.name),this.description=u.description,this.isTypeOf=u.isTypeOf,this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(o=u.extensionASTNodes)!==null&&o!==void 0?o:[],this._fields=()=>iv(u),this._interfaces=()=>rv(u),u.isTypeOf==null||typeof u.isTypeOf=="function"||He(!1,`${this.name} must provide "isTypeOf" as a function, but got: ${jn(u.isTypeOf)}.`)}get[Symbol.toStringTag](){return"GraphQLObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return{name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:ov(this.getFields()),isTypeOf:this.isTypeOf,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}}function rv(i){var u;const o=ev((u=i.interfaces)!==null&&u!==void 0?u:[]);return Array.isArray(o)||He(!1,`${i.name} interfaces must be an Array or a function which returns an Array.`),o}function iv(i){const u=tv(i.fields);return aa(u)||He(!1,`${i.name} fields must be an object with field names as keys or a function which returns such an object.`),Pf(u,(o,h)=>{var m;aa(o)||He(!1,`${i.name}.${h} field config must be an object.`),o.resolve==null||typeof o.resolve=="function"||He(!1,`${i.name}.${h} field resolver must be a function if provided, but got: ${jn(o.resolve)}.`);const A=(m=o.args)!==null&&m!==void 0?m:{};return aa(A)||He(!1,`${i.name}.${h} args must be an object with argument names as keys.`),{name:cr(h),description:o.description,type:o.type,args:Y0(A),resolve:o.resolve,subscribe:o.subscribe,deprecationReason:o.deprecationReason,extensions:xr(o.extensions),astNode:o.astNode}})}function Y0(i){return Object.entries(i).map(([u,o])=>({name:cr(u),description:o.description,type:o.type,defaultValue:o.defaultValue,deprecationReason:o.deprecationReason,extensions:xr(o.extensions),astNode:o.astNode}))}function aa(i){return Qm(i)&&!Array.isArray(i)}function ov(i){return Pf(i,u=>({description:u.description,type:u.type,args:Q0(u.args),resolve:u.resolve,subscribe:u.subscribe,deprecationReason:u.deprecationReason,extensions:u.extensions,astNode:u.astNode}))}function Q0(i){return Im(i,u=>u.name,u=>({description:u.description,type:u.type,defaultValue:u.defaultValue,deprecationReason:u.deprecationReason,extensions:u.extensions,astNode:u.astNode}))}class J0{constructor(u){var o;this.name=cr(u.name),this.description=u.description,this.resolveType=u.resolveType,this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(o=u.extensionASTNodes)!==null&&o!==void 0?o:[],this._fields=iv.bind(void 0,u),this._interfaces=rv.bind(void 0,u),u.resolveType==null||typeof u.resolveType=="function"||He(!1,`${this.name} must provide "resolveType" as a function, but got: ${jn(u.resolveType)}.`)}get[Symbol.toStringTag](){return"GraphQLInterfaceType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}getInterfaces(){return typeof this._interfaces=="function"&&(this._interfaces=this._interfaces()),this._interfaces}toConfig(){return{name:this.name,description:this.description,interfaces:this.getInterfaces(),fields:ov(this.getFields()),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}}class X0{constructor(u){var o;this.name=cr(u.name),this.description=u.description,this.resolveType=u.resolveType,this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(o=u.extensionASTNodes)!==null&&o!==void 0?o:[],this._types=Z0.bind(void 0,u),u.resolveType==null||typeof u.resolveType=="function"||He(!1,`${this.name} must provide "resolveType" as a function, but got: ${jn(u.resolveType)}.`)}get[Symbol.toStringTag](){return"GraphQLUnionType"}getTypes(){return typeof this._types=="function"&&(this._types=this._types()),this._types}toConfig(){return{name:this.name,description:this.description,types:this.getTypes(),resolveType:this.resolveType,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}}function Z0(i){const u=ev(i.types);return Array.isArray(u)||He(!1,`Must provide Array of types or a function which returns such an array for Union ${i.name}.`),u}class K0{constructor(u){var o;this.name=cr(u.name),this.description=u.description,this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(o=u.extensionASTNodes)!==null&&o!==void 0?o:[],this._values=typeof u.values=="function"?u.values:jm(this.name,u.values),this._valueLookup=null,this._nameLookup=null}get[Symbol.toStringTag](){return"GraphQLEnumType"}getValues(){return typeof this._values=="function"&&(this._values=jm(this.name,this._values())),this._values}getValue(u){return this._nameLookup===null&&(this._nameLookup=A0(this.getValues(),o=>o.name)),this._nameLookup[u]}serialize(u){this._valueLookup===null&&(this._valueLookup=new Map(this.getValues().map(h=>[h.value,h])));const o=this._valueLookup.get(u);if(o===void 0)throw new Bn(`Enum "${this.name}" cannot represent value: ${jn(u)}`);return o.name}parseValue(u){if(typeof u!="string"){const h=jn(u);throw new Bn(`Enum "${this.name}" cannot represent non-string value: ${h}.`+Tf(this,h))}const o=this.getValue(u);if(o==null)throw new Bn(`Value "${u}" does not exist in "${this.name}" enum.`+Tf(this,u));return o.value}parseLiteral(u,o){if(u.kind!==Xt.ENUM){const m=Bm(u);throw new Bn(`Enum "${this.name}" cannot represent non-enum value: ${m}.`+Tf(this,m),{nodes:u})}const h=this.getValue(u.value);if(h==null){const m=Bm(u);throw new Bn(`Value "${m}" does not exist in "${this.name}" enum.`+Tf(this,m),{nodes:u})}return h.value}toConfig(){const u=Im(this.getValues(),o=>o.name,o=>({description:o.description,value:o.value,deprecationReason:o.deprecationReason,extensions:o.extensions,astNode:o.astNode}));return{name:this.name,description:this.description,values:u,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes}}toString(){return this.name}toJSON(){return this.toString()}}function Tf(i,u){const o=i.getValues().map(m=>m.name),h=T0(u,o);return w0("the enum value",h)}function jm(i,u){return aa(u)||He(!1,`${i} values must be an object with value names as keys.`),Object.entries(u).map(([o,h])=>(aa(h)||He(!1,`${i}.${o} must refer to an object with a "value" key representing an internal value but got: ${jn(h)}.`),{name:F0(o),description:h.description,value:h.value!==void 0?h.value:o,deprecationReason:h.deprecationReason,extensions:xr(h.extensions),astNode:h.astNode}))}class ey{constructor(u){var o,h;this.name=cr(u.name),this.description=u.description,this.extensions=xr(u.extensions),this.astNode=u.astNode,this.extensionASTNodes=(o=u.extensionASTNodes)!==null&&o!==void 0?o:[],this.isOneOf=(h=u.isOneOf)!==null&&h!==void 0?h:!1,this._fields=ty.bind(void 0,u)}get[Symbol.toStringTag](){return"GraphQLInputObjectType"}getFields(){return typeof this._fields=="function"&&(this._fields=this._fields()),this._fields}toConfig(){const u=Pf(this.getFields(),o=>({description:o.description,type:o.type,defaultValue:o.defaultValue,deprecationReason:o.deprecationReason,extensions:o.extensions,astNode:o.astNode}));return{name:this.name,description:this.description,fields:u,extensions:this.extensions,astNode:this.astNode,extensionASTNodes:this.extensionASTNodes,isOneOf:this.isOneOf}}toString(){return this.name}toJSON(){return this.toString()}}function ty(i){const u=tv(i.fields);return aa(u)||He(!1,`${i.name} fields must be an object with field names as keys or a function which returns such an object.`),Pf(u,(o,h)=>(!("resolve"in o)||He(!1,`${i.name}.${h} field has a resolve property, but Input Types cannot define resolvers.`),{name:cr(h),description:o.description,type:o.type,defaultValue:o.defaultValue,deprecationReason:o.deprecationReason,extensions:xr(o.extensions),astNode:o.astNode}))}function Mi(i){const u=ny(i);if(u)throw u;return i}function ny(i){if(typeof i=="string"||He(!1,"Expected name to be a string."),i.startsWith("__"))return new Bn(`Name "${i}" must not begin with "__", which is reserved by GraphQL introspection.`);try{cr(i)}catch(u){return u}}const ry=i=>i.scalarType({name:"ID",asNexusMethod:"id",description:"id as string or integer",serialize:u=>u,parseValue(u){const o=parseInt(u);return ze.isNumber(o)?o:u},parseLiteral(u){return u.kind===Xt.INT||u.kind===Xt.STRING?u.value:null}}),iy=i=>i.inputObjectType({name:"IdentifyCommentAuthor",definition(u){u.nonNull.id("id")}}),oy=i=>i.inputObjectType({name:"RemoveComment",definition(u){u.id("id"),u.nonNull.string("relation"),u.field("author",{type:"IdentifyCommentAuthor"})}}),uy=i=>i.objectType({name:"Report",definition(u){u.id("id"),u.nonNull.string("content"),u.field("reason",{type:"ReportReason"}),u.field("related",{type:"CommentSingle"}),u.string("createdAt"),u.string("updatedAt")}}),ay=(i,{reportReasons:u})=>i.enumType({name:"ReportReason",description:"Reason of abuse report",members:Object.values(u)}),sy=i=>i.objectType({name:"ResponseFindAll",definition(u){u.nonNull.list.field("data",{type:"CommentSingle"}),u.field("meta",{type:"ResponseMeta"})}}),ly=i=>i.objectType({name:"ResponseFindAllPerAuthor",definition(u){u.nonNull.list.field("data",{type:"CommentSingle"}),u.field("meta",{type:"ResponseMeta"})}}),cy=i=>i.objectType({name:"ResponseMeta",definition(u){u.field("pagination",{type:"ResponsePagination"})}}),fy=i=>i.objectType({name:"ResponsePagination",definition(u){u.int("page"),u.int("pageSize"),u.int("pageCount"),u.int("total"),u.int("start"),u.int("limit")}}),hy=i=>i.inputObjectType({name:"UpdateComment",definition(u){u.id("id"),u.nonNull.string("content"),u.nonNull.string("relation"),u.field("author",{type:"IdentifyCommentAuthor"})}}),py=[Xv,Zv,Kv,e0,t0,n0,r0,ry,iy,oy,ay,sy,ly,cy,fy,hy,uy],dy=(i,u)=>py.map(o=>o(u,i)),uv=i=>i.plugin("graphql").service("extension"),gy=i=>{const u=uv(i);u.shadowCRUD(lr(i,"comment")).disable(),u.shadowCRUD(lr(i,"comment")).disableQueries(),u.shadowCRUD(lr(i,"comment")).disableMutations(),u.shadowCRUD(lr(i,"comment-report")).disable(),u.shadowCRUD(lr(i,"comment-report")).disableQueries(),u.shadowCRUD(lr(i,"comment-report")).disableMutations()},my=async({strapi:i})=>{i.plugin("graphql")&&(gy(i),(await ft(i,"common").getConfig(oa.ENABLED_COLLECTIONS,[])).length&&await vy(i))},vy=async i=>{const u=uv(i),o=await ft(i,"common").getConfig();u.use(({strapi:h,nexus:m})=>{const A=dy(o,m),S=Jv(h,m),C=Gv(h,m),R=Bv(o);return{types:[A,S,C],resolversConfig:R}})},ra={comments:{read:"comments-read",moderate:"comments-moderate"},reports:{read:"reports-read",review:"reports-review"},settings:{read:"settings-read",change:"settings-change"}},yy=async({strapi:i})=>{if(i.plugin("graphql")&&await my({strapi:i}),Object.keys(i.plugins).indexOf("users-permissions")===-1)throw new Error("In order to make the comments plugin work the users-permissions plugin is required");const u=[{section:"plugins",displayName:"Comments: Read",uid:ra.comments.read,pluginName:"comments"},{section:"plugins",displayName:"Comments: Moderate",uid:ra.comments.moderate,pluginName:"comments"},{section:"plugins",displayName:"Reports: Read",uid:ra.reports.read,pluginName:"comments"},{section:"plugins",displayName:"Reports: Moderate",uid:ra.reports.review,pluginName:"comments"},{section:"plugins",displayName:"Settings: Read",uid:ra.settings.read,pluginName:"comments"},{section:"plugins",displayName:"Settings: Change",uid:ra.settings.change,pluginName:"comments"}];await i.admin.services.permission.actionProvider.registerMany(u)},_y={isValidationEnabled:!0,enabledCollections:[],moderatorRoles:[],approvalFlow:[],entryLabel:{"*":["Title","title","Name","name","Subject","subject"]},reportReasons:{BAD_LANGUAGE:Zt.BAD_LANGUAGE,DISCRIMINATION:Zt.DISCRIMINATION,OTHER:Zt.OTHER},blockedAuthorProps:[]},by=v.z.object({[Zt.BAD_LANGUAGE]:v.z.literal(Zt.BAD_LANGUAGE),[Zt.OTHER]:v.z.literal(Zt.OTHER),[Zt.DISCRIMINATION]:v.z.literal(Zt.DISCRIMINATION)}),Am=v.z.object({isValidationEnabled:v.z.boolean().optional(),reportReasons:by.optional(),isGQLPluginEnabled:v.z.boolean().optional(),[Cr.ENABLED_COLLECTIONS]:v.z.array(v.z.string()),[Cr.MODERATOR_ROLES]:v.z.array(v.z.string()),[Cr.APPROVAL_FLOW]:v.z.array(v.z.string()),[Cr.ENTRY_LABEL]:v.z.record(v.z.array(v.z.string())),[Cr.BAD_WORDS]:v.z.boolean().optional(),[Cr.AUTHOR_BLOCKED_PROPS]:v.z.array(v.z.string()),gql:v.z.object({auth:v.z.boolean().optional()}).optional(),client:v.z.object({url:v.z.string().nullable(),contactEmail:v.z.string().nullable()}).default({url:null,contactEmail:null})}),wy={default:Am.parse(_y),validate:i=>Am.safeParse(i)},Y=({left:i,right:u})=>{if(u!==void 0&&i!==void 0)throw new Error(`Received both left and right values at runtime when opening an Either
80
80
  Left: ${JSON.stringify(i)}
81
81
  Right: ${JSON.stringify(u)}`);if(i!==void 0)return i;if(u!==void 0)return u;throw new Error("Received no left or right values at runtime when opening Either")},Ay=i=>i.left!==void 0,pe=i=>i.right!==void 0,av=i=>({left:i}),ol=i=>({right:i});let An=class sv extends Error{constructor(u,o,h=void 0){super(),this.name="Strapi:Plugin:Comments",this.status=u||500,this.message=o||"Internal error",this.payload=h,Object.setPrototypeOf(this,sv.prototype)}toString(u=this){return`${u.name} - ${u.message}`}toJSON(){return this.payload?{...this.payload,name:this.name,message:this.message}:this}};const ce=(i,u)=>u instanceof An?i.throw(u.status,JSON.stringify(u)):u,Ey=v.z.union([v.z.object({$eq:v.z.string().min(1)}),v.z.object({$eqi:v.z.string().min(1)})]),Sy=v.z.union([v.z.object({$ne:v.z.string().min(1)}),v.z.object({$nei:v.z.string().min(1)})]),Ty=v.z.union([v.z.object({$gt:v.z.string().min(1)}),v.z.object({$gte:v.z.string().min(1)})]),Oy=v.z.union([v.z.object({$lt:v.z.string().min(1)}),v.z.object({$lte:v.z.string().min(1)})]),Cy=v.z.union([v.z.object({$startsWith:v.z.string().min(1)}),v.z.object({$startsWithi:v.z.string().min(1)})]),Iy=v.z.union([v.z.object({$endsWith:v.z.string().min(1)}),v.z.object({$endsWithi:v.z.string().min(1)})]),Ry=v.z.union([v.z.object({$contains:v.z.string().min(1)}),v.z.object({$containsi:v.z.string().min(1)})]),xy=v.z.union([v.z.object({$notContains:v.z.string().min(1)}),v.z.object({$notContainsi:v.z.string().min(1)})]),Xr=v.z.union([v.z.string(),v.z.number()]).transform(i=>Number(i)).pipe(v.z.number()),Em=v.z.union([v.z.string(),v.z.boolean()]).transform(i=>typeof i=="string"?["t","true"].includes(i):i).pipe(v.z.boolean()),Ny=v.z.object({_q:v.z.string().optional()}),lv=v.z.string().regex(/^(content|createdAt|updatedAt|id):(desc|asc|ASC|DESC)$/,"Invalid orderBy options"),zy=v.z.union([v.z.string(),v.z.number(),Ey,Sy,Ty,Oy,Cy,Iy,Ry,xy,v.z.object({$null:Em}),v.z.object({$notNull:Em})]),Sm=i=>v.z.object(Object.keys(i).reduce((u,o)=>({...u,[o]:zy.optional()}),{})),Zr={single:"single",array:"array"},sa=i=>{const u=Object.entries(i).reduce((o,[h,m])=>({...o,[h]:m===Zr.single?Xr:v.z.array(Xr)}),{});return v.z.object(u)},Ly=v.z.object({pageSize:Xr.default(10),page:Xr.default(1)}).merge(Ny).merge(v.z.object({orderBy:lv.optional().nullable()})).merge(v.z.object({filters:Sm({removed:!0,approvalStatus:!0}).merge(v.z.object({$or:v.z.array(Sm({blocked:!0,blockedThread:!0})).optional()})).optional()})),Nt=i=>{if(!i.success){const u=i.error.issues.map(o=>`Path: ${o.path.join(".")} Code: ${o.code} Message: ${o.message}`).join(`
82
- `);return av(new An(400,u))}return ol(i.data)},Ff=i=>v.z.string().regex(vm.relatedUid,{message:'Field "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<document id>"'}).refine(u=>i.some(o=>u.startsWith(o)),"Invalid relation or not enabled collections"),Dy=v.z.object({id:v.z.union([v.z.number(),v.z.string()]),name:v.z.string().min(1).max(100).optional(),email:v.z.string().email(),avatar:v.z.string().url().optional()});v.z.union([v.z.string(),v.z.number(),v.z.boolean()]);const cv=Ly.merge(v.z.object({_q:v.z.string().optional()})),Jr=i=>Nt(sa({id:Zr.single}).safeParse(i)),Py=i=>Nt(cv.safeParse(i)),Fy=i=>Nt(cv.safeParse(i)),Uy=(i,u)=>{const o=sa({id:Zr.single}).merge(v.z.object({removed:v.z.string().optional().transform(h=>h==="true")})).safeParse({...u,id:i});return Nt(o)},My=i=>Nt(sa({id:Zr.single,reportId:Zr.single}).safeParse(i)),Wy=i=>{const u=sa({id:Zr.single,reportIds:Zr.array}).safeParse(i);return Nt(u)},By=i=>{const u=sa({reportIds:Zr.array}).safeParse(i);return Nt(u)},jy=v.z.object({id:v.z.union([v.z.string(),v.z.number()]),email:v.z.string().email(),lastname:v.z.string().nullable().optional(),username:v.z.string().nullable().optional(),firstname:v.z.string().nullable().optional()}),fv=v.z.object({id:v.z.union([v.z.string(),v.z.number()]),content:v.z.string(),author:jy}),$y=i=>Nt(fv.safeParse(i)),ky=i=>Nt(fv.pick({content:!0,id:!0}).safeParse(i)),Vy=i=>Nt(Am.safeParse(i)),hv=i=>v.z.object({relation:Ff(i),content:v.z.string().min(1),author:Dy.optional(),threadOf:v.z.union([v.z.string(),v.z.number()]).optional(),approvalStatus:v.z.nativeEnum(Fi).optional(),locale:v.z.string().optional()}),Gy=(i,u,o)=>Nt(hv(i).safeParse({...o,relation:u})),qy=(i,u)=>Nt(hv(i).pick({content:!0,relation:!0,author:!0}).merge(sa({commentId:Zr.single})).safeParse(u)),Hy=i=>v.z.object({relation:Ff(i)}),Yy=v.z.object({pagination:v.z.object({pageSize:Xr.default(10),page:Xr.default(1),withCount:Em.optional().default(!1)}).optional()}),Qy=v.z.record(v.z.union([v.z.union([v.z.boolean(),v.z.literal("true").transform(()=>!0),v.z.literal("false").transform(()=>!1),v.z.literal("*")]),v.z.record(v.z.any())])).optional(),xm=i=>{const u=Sm({id:!0,content:!0,authorId:!0,authorName:!0,authorEmail:!0,createdAt:!0,updatedAt:!0,removed:!0,blocked:!0,blockedThread:!0,approvalStatus:!0,isAdminComment:!0,threadOf:!0});return v.z.object({sort:lv.optional().nullable().default("createdAt:desc"),fields:v.z.string().array().optional(),omit:v.z.string().array().optional(),filters:u.merge(v.z.object({$and:u.array().min(1).optional(),$or:u.array().min(1).optional()})).optional(),isAdmin:v.z.boolean().optional().default(!1),populate:Qy,limit:Xr.optional(),skip:Xr.optional(),locale:v.z.string().optional()}).merge(Hy(i)).merge(Yy)},Jy=(i,u,o)=>Nt(xm(i).safeParse({...o,relation:u})),Xy=(i,u,o)=>{const h=xm(i).pick({sort:!0,fields:!0,omit:!0,filters:!0,isAdmin:!0,populate:!0,limit:!0,skip:!0,relation:!0,locale:!0,pagination:!0}).merge(v.z.object({startingFromId:v.z.number().optional(),dropBlockedThreads:v.z.boolean().optional().default(!1)}));return Nt(h.safeParse({...o,relation:u}))},Zy=(i,u)=>{const o=xm([]).pick({sort:!0,fields:!0,omit:!0,isAdmin:!0,populate:!0,limit:!0,skip:!0,pagination:!0,filters:!0,locale:!0}).merge(v.z.object({type:v.z.union([v.z.literal(ul.GENERIC),v.z.literal("generic")]).optional(),authorId:v.z.union([v.z.string(),v.z.number()])}));return Nt(o.safeParse({...u,...i}))},Ky=i=>v.z.object({relation:Ff(i[Cr.ENABLED_COLLECTIONS]),commentId:Xr,content:v.z.string().min(1),reason:v.z.nativeEnum(i.reportReasons)}),e_=(i,u)=>Nt(Ky(i).safeParse(u)),t_=i=>v.z.object({relation:Ff(i),commentId:v.z.union([v.z.string(),v.z.number()]),authorId:v.z.union([v.z.string(),v.z.number()])}),n_=(i,u)=>Nt(t_(i).safeParse(u)),r_=({strapi:i})=>({getService(u){return ft(i,u)},async findAll(u){const o=Py(u.query);if(pe(o))return this.getService("admin").findAll(Y(o));throw ce(u,Y(o))},async findReports(u){const o=Fy(u.query);if(pe(o))return this.getService("admin").findReports(Y(o));throw ce(u,Y(o))},async findOne(u){const o=Uy(u.params.id,u.query);if(pe(o))return this.getService("admin").findOneAndThread(Y(o));throw ce(u,Y(o))},async blockComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").changeBlockedComment(Y(o).id,!0);throw ce(u,Y(o))},async unblockComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").changeBlockedComment(Y(o).id,!1);throw ce(u,Y(o))},async deleteComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").deleteComment(Y(o).id);throw ce(u,Y(o))},async blockCommentThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").blockCommentThread(Y(o).id,!0);throw ce(u,Y(o))},async unblockCommentThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").blockCommentThread(Y(o).id,!1);throw ce(u,Y(o))},async resolveAbuseReport(u){const o=My(u.params);if(pe(o))return this.getService("admin").resolveAbuseReport(Y(o));throw ce(u,Y(o))},async resolveCommentMultipleAbuseReports(u){const o=Wy({...u.request.body,id:u.params.id});if(pe(o))return this.getService("admin").resolveCommentMultipleAbuseReports(Y(o));throw ce(u,Y(o))},async resolveAllAbuseReportsForComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").resolveAllAbuseReportsForComment(Y(o).id);throw ce(u,Y(o))},async resolveAllAbuseReportsForThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").resolveAllAbuseReportsForThread(Y(o).id);throw ce(u,Y(o))},async resolveMultipleAbuseReports(u){const o=By(u.request.body);if(pe(o))return this.getService("admin").resolveMultipleAbuseReports(Y(o));throw ce(u,Y(o))},async postComment(u){const o=$y({id:u.params.id,content:u.request.body.content,author:u.request.body.author});if(pe(o))return this.getService("admin").postComment(Y(o));throw ce(u,Y(o))},async updateComment(u){const o=ky({id:u.params.id,content:u.request.body.content});if(pe(o))return this.getService("admin").updateComment(Y(o));throw ce(u,Y(o))},async approveComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").approveComment(Y(o).id);throw ce(u,Y(o))},async rejectComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").rejectComment(Y(o).id);throw ce(u,Y(o))}}),Ir=async(i,u,o)=>Uf(i).getLocalConfig(u,o),nl=v.z.object({url:v.z.string(),name:v.z.string(),hash:v.z.string()}),pv=v.z.object({id:v.z.number(),...nl.shape,formats:v.z.object({thumbnail:nl.optional(),small:nl.optional(),medium:nl.optional(),large:nl.optional()}).optional()}).nullable().optional(),dv=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),blocked:v.z.boolean().nullable(),blockedThread:v.z.boolean().nullable(),blockReason:v.z.string().nullable(),isAdminComment:v.z.boolean().nullable(),removed:v.z.boolean().nullable(),approvalStatus:v.z.string().nullable(),related:v.z.string(),createdAt:v.z.string(),updatedAt:v.z.string().nullable(),publishedAt:v.z.string().nullable(),authorId:v.z.string().nullable(),authorName:v.z.string().nullable(),authorEmail:v.z.string().email().nullable(),authorAvatar:v.z.string().nullable(),authorUser:v.z.union([v.z.string(),v.z.object({id:v.z.number(),username:v.z.string(),email:v.z.string().email(),avatar:pv})]).optional().nullable(),locale:v.z.string().nullable()}),gv=v.z.object({page:v.z.number(),pageSize:v.z.number(),pageCount:v.z.number(),total:v.z.number()}),Pi=(i,u)=>o=>i?u.parseAsync(o):Promise.resolve(o),mv=(i,u)=>o=>i?u.parseAsync(o):Promise.resolve(o),i_=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable()}),$m=dv.merge(v.z.object({gotThread:v.z.boolean().nullable().optional(),threadFirstItemId:v.z.number().nullable().optional(),reports:v.z.array(i_).default([]),author:v.z.any().nullable().optional()})),al=$m.extend({threadOf:v.z.lazy(()=>v.z.union([v.z.number(),$m])).nullable().optional()}),o_=v.z.object({id:v.z.number(),uid:v.z.string(),documentId:v.z.string(),requireCommentsApproval:v.z.boolean().nullable().optional(),locale:v.z.string().nullable().optional()});al.omit({related:!0}).extend({related:o_.nullable().optional()});const u_=v.z.array(al),a_=v.z.object({pagination:gv,results:v.z.array(al)}),ia={findMany:u_,findWithCount:a_,findOne:al,create:al},s_=v.z.object({id:v.z.number(),documentId:v.z.string(),content:v.z.string(),blocked:v.z.boolean(),blockedThread:v.z.boolean(),blockReason:v.z.string().nullable(),authorId:v.z.string().nullable(),authorName:v.z.string().nullable(),authorEmail:v.z.string().nullable(),authorAvatar:v.z.string().nullable(),authorUser:v.z.union([v.z.string(),v.z.object({id:v.z.number(),username:v.z.string(),email:v.z.string().email(),avatar:pv})]).optional().nullable(),isAdminComment:v.z.boolean().nullable(),removed:v.z.boolean().nullable(),approvalStatus:v.z.string().nullable(),related:v.z.string(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string(),locale:v.z.string().nullable()}),vv=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable(),related:s_.nullable().optional()}),l_=v.z.object({results:v.z.array(vv),pagination:gv}),c_=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable()}),f_=v.z.array(v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable(),related:dv.nullable()})),Of={findMany:f_,findPage:l_,update:c_,create:vv},h_=i=>{const u=lr(i,"comment-report"),o=i.query(u);return{async findPage(h){const m=await Ir(i,"isValidationEnabled",!1);return o.findPage(h).then(Pi(m,Of.findPage))},async findMany(h){const m=await Ir(i,"isValidationEnabled",!1);return o.findMany(h).then(mv(m,Of.findMany))},async update(h){const m=await Ir(i,"isValidationEnabled",!1);return o.update(h).then(Pi(m,Of.update))},async updateMany(h){return o.updateMany(h)},async create(h){const m=await Ir(i,"isValidationEnabled",!1);return o.create(h).then(Pi(m,Of.create))}}},Di=ze.once(h_),p_=i=>{const u=lr(i,"comment");return{async findMany(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findMany(o).then(mv(h,ia.findMany))},async findWithCount(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findPage(o).then(Pi(h,ia.findWithCount))},async findOne(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findOne(o).then(m=>m?Pi(h,ia.findOne)(m):null)},async update(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).update(o).then(Pi(h,ia.findOne))},async delete(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).delete(o).then(m=>m?Pi(h,ia.findOne)(m):null)},async deleteMany(o){return i.query(u).deleteMany(o)},updateMany(o){return i.query(u).updateMany(o)},async create(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).create(o).then(Pi(h,ia.create))}}},it=ze.once(p_),d_=i=>({getLocalConfig(u,o){return i.config.get([xv,u].filter(Boolean).join("."),o)},async getStore(){return await i.store({type:"plugin",name:"comments"})},async getConfig(){return await(await this.getStore()).get({key:"config"})},async get(u){const o=await this.getConfig(),h={regex:Object.keys(vm).reduce((O,F)=>({...O,[F]:vm[F].toString()}),{})},m=!!i.plugin("graphql"),A=this.getLocalConfig("reportReasons");if(o)return ol({...o,...h,reportReasons:A,isGQLPluginEnabled:u?m:void 0});const S=this.getLocalConfig("entryLabel"),C=this.getLocalConfig("approvalFlow"),R=this.getLocalConfig("blockedAuthorProps"),N={entryLabel:S,approvalFlow:C,blockedAuthorProps:R,reportReasons:A,...h};if(u){const O=this.getLocalConfig("enabledCollections"),F=this.getLocalConfig("moderatorRoles");return ol({...N,enabledCollections:O,moderatorRoles:F,isGQLPluginEnabled:m})}return ol(N)},async update(u){return await(await this.getStore()).set({key:"config",value:{...u,reportReasons:{BAD_LANGUAGE:Zt.BAD_LANGUAGE,DISCRIMINATION:Zt.DISCRIMINATION,OTHER:Zt.OTHER}}}),this.get()},async restore(){return await(await this.getStore()).delete({key:"config"}),this.get()}}),Uf=ze.once(d_),g_=({strapi:i})=>({getService(u){return ft(i,u)},getStoreRepository(){return Uf(i)},async post(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Gy(h.enabledCollections,u.params.relation,u.request.body);if(pe(m))return this.getService("client").create(m.right,u.state.user);throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllFlat(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Jy(h.enabledCollections,u.params.relation,u.query);if(pe(m))return this.getService("common").findAllFlat(ua(m.right));throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllInHierarchy(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Xy(h.enabledCollections,u.params.relation,u.query);if(pe(m))return this.getService("common").findAllInHierarchy(ua(m.right));throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllPerAuthor(u){const o=Zy(u.params,u.query);if(pe(o))return this.getService("common").findAllPerAuthor(ua(o.right),u.params.type?![ul.GENERIC.toLowerCase(),ul.GENERIC].includes(u.params.type):!1);throw ce(u,Y(o))},async put(u){const{user:o}=u.state,h=await this.getStoreRepository().get(!0);if(pe(h)){const m=Y(h),A=qy(m.enabledCollections,{...u.params,content:u.request.body.content,author:u.request.body.author});if(pe(A))return await this.getService("client").update(A.right,o);throw ce(u,Y(A))}throw ce(u,Y(h))},async reportAbuse(u){const{state:o}=u,{user:h}=o,m=await this.getStoreRepository().get(!0);if(pe(m)){const A=Y(m),S=e_(A,{...u.request.body,...u.params});if(pe(S))return await this.getService("client").reportAbuse(S.right,h);throw ce(u,Y(S))}throw ce(u,Y(m))},async removeComment(u){const{state:o}=u,{user:h}=o,m=await this.getStoreRepository().get(!0);if(pe(m)){const A=Y(m),S=n_(A.enabledCollections,{...u.query,...u.params});if(pe(S))return await this.getService("client").markAsRemoved(S.right,h);throw ce(u,Y(S))}throw ce(u,Y(m))}}),m_=({strapi:i})=>{const u=ft(i,"settings");return{async get(o){try{return await u.getConfig()}catch(h){throw ce(o,h)}},async getForSettingsPage(o){try{return await u.getConfig(!0)}catch(h){throw ce(o,h)}},async update(o){const h=Vy(o.request.body);if(pe(h))return await u.update(Y(h));throw ce(o,Y(h))},async restore(o){try{return await u.restore()}catch(h){throw ce(o,h)}},async restart(o){try{return u.restart(),o.send({message:"Restarted",status:200})}catch(h){throw ce(o,h)}}}},v_={admin:r_,client:g_,settings:m_},y_=[{method:"GET",path:"/moderate/all",handler:"admin.findAll",config:{policies:[]}},{method:"GET",path:"/moderate/reports",handler:"admin.findReports",config:{policies:[]}},{method:"GET",path:"/moderate/single/:id",handler:"admin.findOne",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/approve",handler:"admin.approveComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/reject",handler:"admin.rejectComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/block",handler:"admin.blockComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/unblock",handler:"admin.unblockComment",config:{policies:[]}},{method:"DELETE",path:"/moderate/single/:id/delete",handler:"admin.deleteComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/report/:reportId/resolve",handler:"admin.resolveAbuseReport",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/report/resolve",handler:"admin.resolveCommentMultipleAbuseReports",config:{policies:[]}},{method:"PUT",path:"/moderate/all/:id/report/resolve",handler:"admin.resolveAllAbuseReportsForComment",config:{policies:[]}},{method:"PUT",path:"/moderate/all/:id/report/resolve-thread",handler:"admin.resolveAllAbuseReportsForThread",config:{policies:[]}},{method:"PUT",path:"/moderate/multiple/report/resolve",handler:"admin.resolveMultipleAbuseReports",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/update",handler:"admin.updateComment",config:{policies:[]}},{method:"PUT",path:"/moderate/thread/:id/block",handler:"admin.blockCommentThread",config:{policies:[]}},{method:"PUT",path:"/moderate/thread/:id/unblock",handler:"admin.unblockCommentThread",config:{policies:[]}},{method:"POST",path:"/moderate/thread/:id/postComment",handler:"admin.postComment",config:{policies:[]}}],__=[{method:"PUT",path:"/settings/config",handler:"settings.update",config:{policies:[]}},{method:"DELETE",path:"/settings/config",handler:"settings.restore",config:{policies:[]}},{method:"POST",path:"/settings/restart",handler:"settings.restart",config:{policies:[]}},{method:"GET",path:"/settings/config",handler:"settings.getForSettingsPage",config:{policies:[]}},{method:"GET",path:"/moderate/config",handler:"settings.get",config:{policies:[]}}],b_=[...y_,...__],w_=[{method:"GET",path:"/:relation",handler:"client.findAllInHierarchy",config:{policies:[],description:"Find all comments related to configured Collection / Single Type and return them in a nested structure",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"POST",path:"/:relation",handler:"client.post",config:{policies:[],description:"Post a comment against configured Collection / Single Type",tag:{plugin:"comments",name:"Comments",actionType:"create"}}},{method:"GET",path:"/:relation/flat",handler:"client.findAllFlat",config:{policies:[],description:"Find all comments related to configured Collection / Single Type and return them in a flat structure for further processing",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"PUT",path:"/:relation/comment/:commentId",handler:"client.put",config:{policies:[],description:"Update comment related to configured Collection / Single Type if user is the author",tag:{plugin:"comments",name:"Comments",actionType:"update"}}},{method:"POST",path:"/:relation/comment/:commentId/report-abuse",handler:"client.reportAbuse",config:{policies:[],description:"Report an abuse against comment for configured Collection / Single Type",tag:{plugin:"comments",name:"Comments",actionType:"create"}}},{method:"DELETE",path:"/:relation/comment/:commentId",handler:"client.removeComment",config:{policies:[],description:"Remove comment related to configured Collection / Single Type if user is the author",tag:{plugin:"comments",name:"Comments",actionType:"delete"}}},{method:"GET",path:"/author/:authorId",handler:"client.findAllPerAuthor",config:{policies:[],description:"Find all comments created by Strapi user",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"GET",path:"/author/:authorId/:type",handler:"client.findAllPerAuthor",config:{policies:[],description:"Find all comments created by specified type of user",tag:{plugin:"comments",name:"Comments",actionType:"find"}}}],A_={"content-api":{type:"content-api",routes:w_},admin:{type:"admin",routes:b_}};class fn extends Error{constructor(u,o,h=void 0){super(),this.name="Strapi:Plugin:Comments",this.status=u||500,this.message=o||"Internal error",this.payload=h,Object.setPrototypeOf(this,fn.prototype)}toString(u=this){return`${u.name} - ${u.message}`}toJSON(){return this.payload?{...this.payload,name:this.name,message:this.message}:this}}const km=i=>i.split(Yv.relatedUid).filter(u=>u&&u.length>0),yv=i=>i&&{...i,reports:(i.reports||[]).filter(u=>!u.resolved)},Vm=(i,u,o=[])=>{const{authorUser:h,authorId:m,authorName:A,authorEmail:S,authorAvatar:C,...R}=i;let N={};if(h&&typeof h!="string"){const O=h;N=o.reduce((F,U)=>({...F,[U]:O[U]}),{id:O.id,name:O.username,email:O.email,avatar:O.avatar?.formats?.thumbnail.url||O.avatar?.url})}else m&&(N={id:m,name:A,email:S,avatar:C});return N=ze.isEmpty(N)?N:Object.fromEntries(Object.entries(N).filter(([O])=>!u.includes(O))),{...R,author:ze.isEmpty(N)?i.author||{}:N}},Cf=i=>{throw i?new fn(401,"Not authenticated"):new fn(403,"Not authorized")},E_=i=>{const{lastname:u,username:o,firstname:h}=i;return u&&h?`${h} ${u}`:o||h||""},S_=ze.once(i=>({findAll:{createParams(u,o,h,m,A){const[S,C]=ym(u),R={orderBy:u?{[S]:C}:void 0,where:A,page:o,pageSize:h};return m&&ze.set(R,"where.content.$contains",m),R},getPopulate(){return{authorUser:il(i),threadOf:{populate:{authorUser:il(i)}},reports:{where:{resolved:!1}}}}},findReports:{getDefaultWhere(){return{resolved:{$notNull:!0}}},createParams(u,o,h,m){const[A,S]=ym(u),C={orderBy:u?{[A]:S}:void 0,where:this.getDefaultWhere(),page:o,pageSize:h};return m&&ze.set(C,"where.content.$contains",m),C}},findOneAndThread:{getDefaultWhere(u){return u?{$or:[{removed:!1},{removed:{$notNull:!1}}]}:{}},getPopulate(){const u=il(i),o={reports:{where:{resolved:!1}}},h={populate:{threadOf:{populate:{...o}},...o}};return{populate:{...h.populate,authorUser:u,threadOf:{populate:{...h.populate.threadOf.populate,authorUser:u}}}}}}})),T_=({strapi:i})=>{const u=S_(i);return{getCommonService(){return ft(i,"common")},async findAll({_q:o,orderBy:h,page:m,pageSize:A,filters:S}){const C=u.findAll.createParams(h,m,A,o,S),R=u.findAll.getPopulate(),N=it(i),{pagination:O,results:F}=await N.findWithCount({...C,count:!0,populate:R}),U=await this.getCommonService().findRelatedEntitiesFor(F);return{pagination:O,result:F.map(Q=>this.getCommonService().sanitizeCommentEntity(Q,[],[])).map(Q=>this.getCommonService().mergeRelatedEntityTo(Q,U))}},async findReports({_q:o,orderBy:h,page:m,pageSize:A}){const S=u.findReports.createParams(h,m,A,o),C=il(i),{pagination:R,results:N}=await Di(i).findPage({...S,populate:{related:{populate:{authorUser:C}}}}),O=N.map(j=>typeof j.related=="object"?j.related.id:null).filter(Boolean),F=await it(i).findMany({where:{threadOf:O},populate:["threadOf"],limit:Number.MAX_SAFE_INTEGER}),U=Array.from(new Set(F.map(({threadOf:j})=>typeof j=="object"?j.id:null).filter(Boolean)));return{result:N.map(j=>{const J=U.includes(j.related.id),te=this.getCommonService(),X={...j,related:te.sanitizeCommentEntity({...j.related,gotThread:J},[])},ye=typeof C!="boolean"?C?.populate:{};return yv(te.sanitizeCommentEntity(X,[],[],ye))}),pagination:R}},async findOneAndThread({id:o,removed:h,...m}){const A=il(i),S=u.findOneAndThread.getDefaultWhere(h),C=u.findOneAndThread.getPopulate(),R=await it(i).findOne({...C,where:{id:o}});if(!R)throw new An(404,"Not found");const{relatedId:N,uid:O}=this.getCommonService().parseRelationString(R.related),F=await i.documents(O).findOne({documentId:N}).then(te=>{if(!te)throw new An(404,"Relation not found");return{...te,uid:O}}),U=R.threadOf&&typeof R.threadOf=="object"?R.threadOf.id:null,Q=await this.getCommonService().findAllInHierarchy({filters:{...S,...m,threadOf:U,related:R.related},...C,startingFromId:U,isAdmin:!0,limit:Number.MAX_SAFE_INTEGER},!1),j=typeof A!="boolean"?A?.populate:{},J=this.getCommonService().sanitizeCommentEntity({...R,threadOf:R.threadOf||null},[],[],j);return{entity:F,selected:J,level:Q}},async changeBlockedComment(o,h){const m=await this.getCommonService().findOne({id:o});return this.getCommonService().updateComment({id:o},{blocked:ze.isNil(h)?!m.blocked:h})},async deleteComment(o){return it(i).update({where:{id:o},data:{removed:!0}})},async blockCommentThread(o,h){const m=await this.getCommonService().findOne({id:o}),A=h||!m.blocked,S=await this.getCommonService().updateComment({id:o},{blocked:A,blockedThread:A});return await this.blockNestedThreads(o,A),this.getCommonService().sanitizeCommentEntity(S,[])},async approveComment(o){const h=await it(i).update({where:{id:o},data:{approvalStatus:Fi.APPROVED}});if(!h)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(h,[])},async rejectComment(o){const h=await it(i).update({where:{id:o},data:{approvalStatus:Fi.REJECTED}});if(!h)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(h,[])},async blockNestedThreads(o,h){return this.getCommonService().modifiedNestedNestedComments(o,"blockedThread",h)},async resolveAbuseReport({id:o,reportId:h}){return Di(i).update({where:{id:h,related:o},data:{resolved:!0}})},async resolveCommentMultipleAbuseReports({id:o,reportIds:h}){if((await Di(i).findMany({where:{id:h,related:o},populate:["related"]})).length===h.length)return Di(i).updateMany({where:{id:h},data:{resolved:!0}});throw new An(400,"At least one of selected reports got invalid comment entity relation. Try again.")},async resolveAllAbuseReportsForComment(o){if(!o)throw new An(400,"There is something wrong with comment Id. Try again.");return Di(i).updateMany({where:{related:o,resolved:!1},data:{resolved:!0}})},async resolveAllAbuseReportsForThread(o){if(!o)throw new An(400,"There is something wrong with comment Id. Try again.");const h=await it(i).findMany({where:{threadOf:o},select:["id"]});return Di(i).updateMany({where:{related:h.map(({id:m})=>m).concat([o]),resolved:!1},data:{resolved:!0}})},async resolveMultipleAbuseReports({reportIds:o}){return Di(i).updateMany({where:{id:{$in:o}},data:{resolved:!0}})},async postComment({id:o,author:h,content:m}){const A=await it(i).findOne({where:{id:o}});if(!A)throw new An(404,"Not found");return it(i).create({data:{content:this.getCommonService().sanitizeCommentContent(m),threadOf:o,authorId:h.id,authorName:E_(h),authorEmail:h.email,related:A.related,isAdminComment:!0}})},async updateComment({id:o,content:h}){const m=await it(i).update({where:{id:o},data:{content:this.getCommonService().sanitizeCommentContent(h)}});if(!m)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(m,[])}}},O_=async(i,u)=>{try{return ol(await i())}catch{return av(u)}},C_=({strapi:i})=>{const u=async(o,h)=>{if(h)return{authorUser:h.id};if(o)return{authorId:o.id,authorName:o.name,authorEmail:o.email,authorAvatar:o.avatar}};return{getCommonService(){return ft(i,"common")},async create({relation:o,content:h,threadOf:m,author:A,approvalStatus:S,locale:C},R){const{uid:N,relatedId:O}=this.getCommonService().parseRelationString(o),F=await i.documents(N).findOne({documentId:O,locale:C});if(!F)throw new fn(400,'Relation for field "related" does not exist. Check your payload please.');const Q=(await this.getCommonService().getConfig(oa.APPROVAL_FLOW,[])).includes(N)||F.requireCommentsApproval,j=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]),J=await O_(async()=>m?await this.getCommonService().findOne({id:m,related:o,locale:C||null}):null,new fn(400,"Thread does not exist"));if(Ay(J))throw Y(J);const te=Y(J);if(!A&&!this.getCommonService().isValidUserContext(R))throw Cf(R);const[X,ye]=await Promise.all([this.getCommonService().checkBadWords(h),u(A,R)]),_e=!ze.isEmpty(ye)&&!(ye.authorId||ye.authorUser);if(ze.isEmpty(ye)||_e)throw new fn(400,`Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);if(Q&&S&&S!==Fi.PENDING)throw new fn(400,"Invalid approval status");const Ve={...await it(i).create({data:{...ye,threadOf:m,locale:C,content:this.getCommonService().sanitizeCommentContent(X),related:o,approvalStatus:Q?Fi.PENDING:Fi.APPROVED},populate:{authorUser:{populate:["avatar"]}}}),threadOf:te},Ye=this.getCommonService().sanitizeCommentEntity(Ve,j);try{await this.sendResponseNotification(Ye)}catch(Me){console.error(Me)}return Ye},async update({commentId:o,content:h,author:m,relation:A},S){if(!m&&!this.getCommonService().isValidUserContext(S))throw Cf(S);const C=S?.id||m?.id;if(await this.getCommonService().checkBadWords(h)){const R=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]),N=await this.getCommonService().findOne({id:o,related:A});if(N&&N.author?.id?.toString()===C?.toString()){const O=await it(i).update({where:{id:o},data:{content:this.getCommonService().sanitizeCommentContent(h)},populate:{threadOf:!0,authorUser:{populate:["avatar"]}}});return this.getCommonService().sanitizeCommentEntity(O,R)}}},async reportAbuse({commentId:o,relation:h,...m},A){if(!this.getCommonService().isValidUserContext(A))throw Cf(A);try{const S=await this.getCommonService().findOne({id:o,related:h});if(S.isAdminComment)throw new fn(403,"You're not allowed to take an action on that entity. This in a admin comment.");if(S){const C=await Di(i).create({data:{...m,resolved:!1,related:o}});if(C){const R={...C,related:S};try{return await this.sendAbuseReportEmail(C.reason,C.content),R}catch{return R}}else throw new fn(500,"Report cannot be created")}throw new fn(403,"You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.")}catch(S){throw S}},async markAsRemoved({commentId:o,relation:h,authorId:m},A){if(!m&&!this.getCommonService().isValidUserContext(A))throw Cf(A);const S=A?.id||m;if(!S)throw new fn(403,`You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`);try{const C=A?.id?{authorUser:S}:{authorId:S};if(await this.getCommonService().findOne({id:o,related:h,...C})){const N=await it(i).update({where:{id:o,related:h},data:{removed:!0},populate:{threadOf:!0,authorUser:{populate:["avatar"]}}});await this.markAsRemovedNested(o,!0);const O=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]);return this.getCommonService().sanitizeCommentEntity(N,O)}else throw new fn(404,"Entity does not exist or you're not allowed to take an action on it")}catch{throw new fn(404,"Entity does not exist or you're not allowed to take an action on it")}},async sendAbuseReportEmail(o,h){const m="strapi-super-admin",A=await this.getCommonService().getConfig(oa.MODERATOR_ROLES,[m]);if(A.length>0){const S=await i.query("admin::user").findMany({where:{roles:{code:A}}}).then(C=>C.map(R=>R.email));if(S.length>0){const C=await i.query("admin::user").findOne({where:{roles:{code:m}}});i.plugin("email")&&await i.plugin("email").service("email").send({to:S,from:C.email,subject:"New abuse report on comment",text:`
82
+ `);return av(new An(400,u))}return ol(i.data)},Ff=i=>v.z.string().regex(vm.relatedUid,{message:'Field "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<document id>"'}).refine(u=>i.some(o=>u.startsWith(o)),"Invalid relation or not enabled collections"),Dy=v.z.object({id:v.z.union([v.z.number(),v.z.string()]),name:v.z.string().min(1).max(100).optional(),email:v.z.string().email(),avatar:v.z.string().url().optional()});v.z.union([v.z.string(),v.z.number(),v.z.boolean()]);const cv=Ly.merge(v.z.object({_q:v.z.string().optional()})),Jr=i=>Nt(sa({id:Zr.single}).safeParse(i)),Py=i=>Nt(cv.safeParse(i)),Fy=i=>Nt(cv.safeParse(i)),Uy=(i,u)=>{const o=sa({id:Zr.single}).merge(v.z.object({removed:v.z.string().optional().transform(h=>h==="true")})).safeParse({...u,id:i});return Nt(o)},My=i=>Nt(sa({id:Zr.single,reportId:Zr.single}).safeParse(i)),Wy=i=>{const u=sa({id:Zr.single,reportIds:Zr.array}).safeParse(i);return Nt(u)},By=i=>{const u=sa({reportIds:Zr.array}).safeParse(i);return Nt(u)},jy=v.z.object({id:v.z.union([v.z.string(),v.z.number()]),email:v.z.string().email(),lastname:v.z.string().nullable().optional(),username:v.z.string().nullable().optional(),firstname:v.z.string().nullable().optional()}),fv=v.z.object({id:v.z.union([v.z.string(),v.z.number()]),content:v.z.string(),author:jy}),$y=i=>Nt(fv.safeParse(i)),ky=i=>Nt(fv.pick({content:!0,id:!0}).safeParse(i)),Vy=i=>Nt(Am.safeParse(i)),hv=i=>v.z.object({relation:Ff(i),content:v.z.string().min(1),author:Dy.optional(),threadOf:v.z.union([v.z.string(),v.z.number()]).optional(),approvalStatus:v.z.nativeEnum(Fi).optional(),locale:v.z.string().optional()}),Gy=(i,u,o)=>Nt(hv(i).safeParse({...o,relation:u})),qy=(i,u)=>Nt(hv(i).pick({content:!0,relation:!0,author:!0}).merge(sa({commentId:Zr.single})).safeParse(u)),Hy=i=>v.z.object({relation:Ff(i)}),Yy=v.z.object({pagination:v.z.object({pageSize:Xr.default(10),page:Xr.default(1),withCount:Em.optional().default(!1)}).optional()}),Qy=v.z.record(v.z.union([v.z.union([v.z.boolean(),v.z.literal("true").transform(()=>!0),v.z.literal("false").transform(()=>!1),v.z.literal("*")]),v.z.record(v.z.any())])).optional(),xm=i=>{const u=Sm({id:!0,content:!0,authorId:!0,authorName:!0,authorEmail:!0,createdAt:!0,updatedAt:!0,removed:!0,blocked:!0,blockedThread:!0,approvalStatus:!0,isAdminComment:!0,threadOf:!0});return v.z.object({sort:lv.optional().nullable().default("createdAt:desc"),fields:v.z.string().array().optional(),omit:v.z.string().array().optional(),filters:u.merge(v.z.object({$and:u.array().min(1).optional(),$or:u.array().min(1).optional()})).optional(),isAdmin:v.z.boolean().optional().default(!1),populate:Qy,limit:Xr.optional(),skip:Xr.optional(),locale:v.z.string().optional()}).merge(Hy(i)).merge(Yy)},Jy=(i,u,o)=>Nt(xm(i).safeParse({...o,relation:u})),Xy=(i,u,o)=>{const h=xm(i).pick({sort:!0,fields:!0,omit:!0,filters:!0,isAdmin:!0,populate:!0,limit:!0,skip:!0,relation:!0,locale:!0,pagination:!0}).merge(v.z.object({startingFromId:v.z.number().optional(),dropBlockedThreads:v.z.boolean().optional().default(!1)}));return Nt(h.safeParse({...o,relation:u}))},Zy=(i,u)=>{const o=xm([]).pick({sort:!0,fields:!0,omit:!0,isAdmin:!0,populate:!0,limit:!0,skip:!0,pagination:!0,filters:!0,locale:!0}).merge(v.z.object({type:v.z.union([v.z.literal(ul.GENERIC),v.z.literal("generic")]).optional(),authorId:v.z.union([v.z.string(),v.z.number()])}));return Nt(o.safeParse({...u,...i}))},Ky=i=>v.z.object({relation:Ff(i[Cr.ENABLED_COLLECTIONS]),commentId:Xr,content:v.z.string().min(1),reason:v.z.nativeEnum(i.reportReasons)}),e_=(i,u)=>Nt(Ky(i).safeParse(u)),t_=i=>v.z.object({relation:Ff(i),commentId:v.z.union([v.z.string(),v.z.number()]),authorId:v.z.union([v.z.string(),v.z.number()])}),n_=(i,u)=>Nt(t_(i).safeParse(u)),r_=({strapi:i})=>({getService(u){return ft(i,u)},async findAll(u){const o=Py(u.query);if(pe(o))return this.getService("admin").findAll(Y(o));throw ce(u,Y(o))},async findReports(u){const o=Fy(u.query);if(pe(o))return this.getService("admin").findReports(Y(o));throw ce(u,Y(o))},async findOne(u){const o=Uy(u.params.id,u.query);if(pe(o))return this.getService("admin").findOneAndThread(Y(o));throw ce(u,Y(o))},async blockComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").changeBlockedComment(Y(o).id,!0);throw ce(u,Y(o))},async unblockComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").changeBlockedComment(Y(o).id,!1);throw ce(u,Y(o))},async deleteComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").deleteComment(Y(o).id);throw ce(u,Y(o))},async blockCommentThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").blockCommentThread(Y(o).id,!0);throw ce(u,Y(o))},async unblockCommentThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").blockCommentThread(Y(o).id,!1);throw ce(u,Y(o))},async resolveAbuseReport(u){const o=My(u.params);if(pe(o))return this.getService("admin").resolveAbuseReport(Y(o));throw ce(u,Y(o))},async resolveCommentMultipleAbuseReports(u){const o=Wy({...u.request.body,id:u.params.id});if(pe(o))return this.getService("admin").resolveCommentMultipleAbuseReports(Y(o));throw ce(u,Y(o))},async resolveAllAbuseReportsForComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").resolveAllAbuseReportsForComment(Y(o).id);throw ce(u,Y(o))},async resolveAllAbuseReportsForThread(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").resolveAllAbuseReportsForThread(Y(o).id);throw ce(u,Y(o))},async resolveMultipleAbuseReports(u){const o=By(u.request.body);if(pe(o))return this.getService("admin").resolveMultipleAbuseReports(Y(o));throw ce(u,Y(o))},async postComment(u){const o=$y({id:u.params.id,content:u.request.body.content,author:u.request.body.author});if(pe(o))return this.getService("admin").postComment(Y(o));throw ce(u,Y(o))},async updateComment(u){const o=ky({id:u.params.id,content:u.request.body.content});if(pe(o))return this.getService("admin").updateComment(Y(o));throw ce(u,Y(o))},async approveComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").approveComment(Y(o).id);throw ce(u,Y(o))},async rejectComment(u){const o=Jr(u.params);if(pe(o))return this.getService("admin").rejectComment(Y(o).id);throw ce(u,Y(o))}}),Ir=async(i,u,o)=>Uf(i).getLocalConfig(u,o),nl=v.z.object({url:v.z.string(),name:v.z.string(),hash:v.z.string()}),pv=v.z.object({id:v.z.number(),...nl.shape,formats:v.z.object({thumbnail:nl.optional(),small:nl.optional(),medium:nl.optional(),large:nl.optional()}).optional()}).nullable().optional(),dv=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),blocked:v.z.boolean().nullable(),blockedThread:v.z.boolean().nullable(),blockReason:v.z.string().nullable(),isAdminComment:v.z.boolean().nullable(),removed:v.z.boolean().nullable(),approvalStatus:v.z.string().nullable(),related:v.z.string(),createdAt:v.z.string(),updatedAt:v.z.string().nullable(),publishedAt:v.z.string().nullable(),authorId:v.z.string().nullable(),authorName:v.z.string().nullable(),authorEmail:v.z.string().email().nullable(),authorAvatar:v.z.string().nullable(),authorUser:v.z.union([v.z.string(),v.z.object({id:v.z.number(),username:v.z.string(),email:v.z.string().email(),avatar:pv})]).optional().nullable(),locale:v.z.string().nullable()}),gv=v.z.object({page:v.z.number(),pageSize:v.z.number(),pageCount:v.z.number(),total:v.z.number()}),Pi=(i,u)=>o=>i?u.parseAsync(o):Promise.resolve(o),mv=(i,u)=>o=>i?u.parseAsync(o):Promise.resolve(o),i_=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable()}),$m=dv.merge(v.z.object({gotThread:v.z.boolean().nullable().optional(),threadFirstItemId:v.z.number().nullable().optional(),reports:v.z.array(i_).default([]),author:v.z.any().nullable().optional()})),al=$m.extend({threadOf:v.z.lazy(()=>v.z.union([v.z.number(),$m])).nullable().optional()}),o_=v.z.object({id:v.z.number(),uid:v.z.string(),documentId:v.z.string(),requireCommentsApproval:v.z.boolean().nullable().optional(),locale:v.z.string().nullable().optional()});al.omit({related:!0}).extend({related:o_.nullable().optional()});const u_=v.z.array(al),a_=v.z.object({pagination:gv,results:v.z.array(al)}),ia={findMany:u_,findWithCount:a_,findOne:al,create:al},s_=v.z.object({id:v.z.number(),documentId:v.z.string(),content:v.z.string(),blocked:v.z.boolean(),blockedThread:v.z.boolean(),blockReason:v.z.string().nullable(),authorId:v.z.string().nullable(),authorName:v.z.string().nullable(),authorEmail:v.z.string().nullable(),authorAvatar:v.z.string().nullable(),authorUser:v.z.union([v.z.string(),v.z.object({id:v.z.number(),username:v.z.string(),email:v.z.string().email(),avatar:pv})]).optional().nullable(),isAdminComment:v.z.boolean().nullable(),removed:v.z.boolean().nullable(),approvalStatus:v.z.string().nullable(),related:v.z.string(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string(),locale:v.z.string().nullable()}),vv=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable(),related:s_.nullable().optional()}),l_=v.z.object({results:v.z.array(vv),pagination:gv}),c_=v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable()}),f_=v.z.array(v.z.object({id:v.z.number(),documentId:v.z.string().nullable(),content:v.z.string(),reason:v.z.string(),resolved:v.z.boolean(),createdAt:v.z.string(),updatedAt:v.z.string(),publishedAt:v.z.string().nullable(),locale:v.z.string().nullable(),related:dv.nullable()})),Of={findMany:f_,findPage:l_,update:c_,create:vv},h_=i=>{const u=lr(i,"comment-report"),o=i.query(u);return{async findPage(h){const m=await Ir(i,"isValidationEnabled",!1);return o.findPage(h).then(Pi(m,Of.findPage))},async findMany(h){const m=await Ir(i,"isValidationEnabled",!1);return o.findMany(h).then(mv(m,Of.findMany))},async update(h){const m=await Ir(i,"isValidationEnabled",!1);return o.update(h).then(Pi(m,Of.update))},async updateMany(h){return o.updateMany(h)},async create(h){const m=await Ir(i,"isValidationEnabled",!1);return o.create(h).then(Pi(m,Of.create))}}},Di=ze.once(h_),p_=i=>{const u=lr(i,"comment");return{async findMany(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findMany(o).then(mv(h,ia.findMany))},async findWithCount(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findPage(o).then(Pi(h,ia.findWithCount))},async findOne(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).findOne(o).then(m=>m?Pi(h,ia.findOne)(m):null)},async update(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).update(o).then(Pi(h,ia.findOne))},async delete(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).delete(o).then(m=>m?Pi(h,ia.findOne)(m):null)},async deleteMany(o){return i.query(u).deleteMany(o)},updateMany(o){return i.query(u).updateMany(o)},async create(o){const h=await Ir(i,"isValidationEnabled",!1);return i.query(u).create(o).then(Pi(h,ia.create))}}},it=ze.once(p_),d_=i=>({getLocalConfig(u,o){return i.config.get([xv,u].filter(Boolean).join("."),o)},async getStore(){return await i.store({type:"plugin",name:"comments"})},async getConfig(){return await(await this.getStore()).get({key:"config"})},async get(u){const o=await this.getConfig(),h={regex:Object.keys(vm).reduce((O,F)=>({...O,[F]:vm[F].toString()}),{})},m=!!i.plugin("graphql"),A=this.getLocalConfig("reportReasons");if(o)return ol({...o,...h,reportReasons:A,isGQLPluginEnabled:u?m:void 0});const S=this.getLocalConfig("entryLabel"),C=this.getLocalConfig("approvalFlow"),R=this.getLocalConfig("blockedAuthorProps"),N={entryLabel:S,approvalFlow:C,blockedAuthorProps:R,reportReasons:A,...h};if(u){const O=this.getLocalConfig("enabledCollections"),F=this.getLocalConfig("moderatorRoles");return ol({...N,enabledCollections:O,moderatorRoles:F,isGQLPluginEnabled:m})}return ol(N)},async update(u){return await(await this.getStore()).set({key:"config",value:{...u,reportReasons:{BAD_LANGUAGE:Zt.BAD_LANGUAGE,DISCRIMINATION:Zt.DISCRIMINATION,OTHER:Zt.OTHER}}}),this.get()},async restore(){return await(await this.getStore()).delete({key:"config"}),this.get()}}),Uf=ze.once(d_),g_=({strapi:i})=>({getService(u){return ft(i,u)},getStoreRepository(){return Uf(i)},async post(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Gy(h.enabledCollections,u.params.relation,u.request.body);if(pe(m))return this.getService("client").create(m.right,u.state.user);throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllFlat(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Jy(h.enabledCollections,u.params.relation,u.query);if(pe(m))return this.getService("common").findAllFlat(ua(m.right));throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllInHierarchy(u){const o=await this.getStoreRepository().get(!0);if(pe(o)){const h=Y(o),m=Xy(h.enabledCollections,u.params.relation,u.query);if(pe(m))return this.getService("common").findAllInHierarchy(ua(m.right));throw ce(u,Y(m))}throw ce(u,Y(o))},async findAllPerAuthor(u){const o=Zy(u.params,u.query);if(pe(o))return this.getService("common").findAllPerAuthor(ua(o.right),u.params.type?![ul.GENERIC.toLowerCase(),ul.GENERIC].includes(u.params.type):!1);throw ce(u,Y(o))},async put(u){const{user:o}=u.state,h=await this.getStoreRepository().get(!0);if(pe(h)){const m=Y(h),A=qy(m.enabledCollections,{...u.params,content:u.request.body.content,author:u.request.body.author});if(pe(A))return await this.getService("client").update(A.right,o);throw ce(u,Y(A))}throw ce(u,Y(h))},async reportAbuse(u){const{state:o}=u,{user:h}=o,m=await this.getStoreRepository().get(!0);if(pe(m)){const A=Y(m),S=e_(A,{...u.request.body,...u.params});if(pe(S))return await this.getService("client").reportAbuse(S.right,h);throw ce(u,Y(S))}throw ce(u,Y(m))},async removeComment(u){const{state:o}=u,{user:h}=o,m=await this.getStoreRepository().get(!0);if(pe(m)){const A=Y(m),S=n_(A.enabledCollections,{...u.query,...u.params});if(pe(S))return await this.getService("client").markAsRemoved(S.right,h);throw ce(u,Y(S))}throw ce(u,Y(m))}}),m_=({strapi:i})=>{const u=ft(i,"settings");return{async get(o){try{return await u.getConfig()}catch(h){throw ce(o,h)}},async getForSettingsPage(o){try{return await u.getConfig(!0)}catch(h){throw ce(o,h)}},async update(o){const h=Vy(o.request.body);if(pe(h))return await u.update(Y(h));throw ce(o,Y(h))},async restore(o){try{return await u.restore()}catch(h){throw ce(o,h)}},async restart(o){try{return u.restart(),o.send({message:"Restarted",status:200})}catch(h){throw ce(o,h)}}}},v_={admin:r_,client:g_,settings:m_},y_=[{method:"GET",path:"/moderate/all",handler:"admin.findAll",config:{policies:[]}},{method:"GET",path:"/moderate/reports",handler:"admin.findReports",config:{policies:[]}},{method:"GET",path:"/moderate/single/:id",handler:"admin.findOne",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/approve",handler:"admin.approveComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/reject",handler:"admin.rejectComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/block",handler:"admin.blockComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/unblock",handler:"admin.unblockComment",config:{policies:[]}},{method:"DELETE",path:"/moderate/single/:id/delete",handler:"admin.deleteComment",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/report/:reportId/resolve",handler:"admin.resolveAbuseReport",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/report/resolve",handler:"admin.resolveCommentMultipleAbuseReports",config:{policies:[]}},{method:"PUT",path:"/moderate/all/:id/report/resolve",handler:"admin.resolveAllAbuseReportsForComment",config:{policies:[]}},{method:"PUT",path:"/moderate/all/:id/report/resolve-thread",handler:"admin.resolveAllAbuseReportsForThread",config:{policies:[]}},{method:"PUT",path:"/moderate/multiple/report/resolve",handler:"admin.resolveMultipleAbuseReports",config:{policies:[]}},{method:"PUT",path:"/moderate/single/:id/update",handler:"admin.updateComment",config:{policies:[]}},{method:"PUT",path:"/moderate/thread/:id/block",handler:"admin.blockCommentThread",config:{policies:[]}},{method:"PUT",path:"/moderate/thread/:id/unblock",handler:"admin.unblockCommentThread",config:{policies:[]}},{method:"POST",path:"/moderate/thread/:id/postComment",handler:"admin.postComment",config:{policies:[]}}],__=[{method:"PUT",path:"/settings/config",handler:"settings.update",config:{policies:[]}},{method:"DELETE",path:"/settings/config",handler:"settings.restore",config:{policies:[]}},{method:"POST",path:"/settings/restart",handler:"settings.restart",config:{policies:[]}},{method:"GET",path:"/settings/config",handler:"settings.getForSettingsPage",config:{policies:[]}},{method:"GET",path:"/moderate/config",handler:"settings.get",config:{policies:[]}}],b_=[...y_,...__],w_=[{method:"GET",path:"/:relation",handler:"client.findAllInHierarchy",config:{policies:[],description:"Find all comments related to configured Collection / Single Type and return them in a nested structure",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"POST",path:"/:relation",handler:"client.post",config:{policies:[],description:"Post a comment against configured Collection / Single Type",tag:{plugin:"comments",name:"Comments",actionType:"create"}}},{method:"GET",path:"/:relation/flat",handler:"client.findAllFlat",config:{policies:[],description:"Find all comments related to configured Collection / Single Type and return them in a flat structure for further processing",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"PUT",path:"/:relation/comment/:commentId",handler:"client.put",config:{policies:[],description:"Update comment related to configured Collection / Single Type if user is the author",tag:{plugin:"comments",name:"Comments",actionType:"update"}}},{method:"POST",path:"/:relation/comment/:commentId/report-abuse",handler:"client.reportAbuse",config:{policies:[],description:"Report an abuse against comment for configured Collection / Single Type",tag:{plugin:"comments",name:"Comments",actionType:"create"}}},{method:"DELETE",path:"/:relation/comment/:commentId",handler:"client.removeComment",config:{policies:[],description:"Remove comment related to configured Collection / Single Type if user is the author",tag:{plugin:"comments",name:"Comments",actionType:"delete"}}},{method:"GET",path:"/author/:authorId",handler:"client.findAllPerAuthor",config:{policies:[],description:"Find all comments created by Strapi user",tag:{plugin:"comments",name:"Comments",actionType:"find"}}},{method:"GET",path:"/author/:authorId/:type",handler:"client.findAllPerAuthor",config:{policies:[],description:"Find all comments created by specified type of user",tag:{plugin:"comments",name:"Comments",actionType:"find"}}}],A_={"content-api":{type:"content-api",routes:w_},admin:{type:"admin",routes:b_}};class fn extends Error{constructor(u,o,h=void 0){super(),this.name="Strapi:Plugin:Comments",this.status=u||500,this.message=o||"Internal error",this.payload=h,Object.setPrototypeOf(this,fn.prototype)}toString(u=this){return`${u.name} - ${u.message}`}toJSON(){return this.payload?{...this.payload,name:this.name,message:this.message}:this}}const km=i=>i.split(Yv.relatedUid).filter(u=>u&&u.length>0),yv=i=>i&&{...i,reports:(i.reports||[]).filter(u=>!u.resolved)},Vm=(i,u,o=[])=>{const{authorUser:h,authorId:m,authorName:A,authorEmail:S,authorAvatar:C,...R}=i;let N={};if(h&&typeof h!="string"){const O=h;N=o.reduce((F,U)=>({...F,[U]:O[U]}),{id:O.id,name:O.username,email:O.email,avatar:O.avatar?.formats?.thumbnail.url||O.avatar?.url})}else m&&(N={id:m,name:A,email:S,avatar:C});return N=ze.isEmpty(N)?N:Object.fromEntries(Object.entries(N).filter(([O])=>!u.includes(O))),{...R,author:ze.isEmpty(N)?i.author||{}:N}},Cf=i=>{throw i?new fn(401,"Not authenticated"):new fn(403,"Not authorized")},E_=i=>{const{lastname:u,username:o,firstname:h}=i;return u&&h?`${h} ${u}`:o||h||""},S_=ze.once(i=>({findAll:{createParams(u,o,h,m,A){const[S,C]=ym(u),R={orderBy:u?{[S]:C}:void 0,where:A,page:o,pageSize:h};return m&&ze.set(R,"where.content.$contains",m),R},getPopulate(){return{authorUser:il(i),threadOf:{populate:{authorUser:il(i)}},reports:{where:{resolved:!1}}}}},findReports:{getDefaultWhere(){return{resolved:{$notNull:!0}}},createParams(u,o,h,m){const[A,S]=ym(u),C={orderBy:u?{[A]:S}:void 0,where:this.getDefaultWhere(),page:o,pageSize:h};return m&&ze.set(C,"where.content.$contains",m),C}},findOneAndThread:{getDefaultWhere(u){return u?{$or:[{removed:!1},{removed:{$notNull:!1}}]}:{}},getPopulate(){const u=il(i),o={reports:{where:{resolved:!1}}},h={populate:{threadOf:{populate:{...o}},...o}};return{populate:{...h.populate,authorUser:u,threadOf:{populate:{...h.populate.threadOf.populate,authorUser:u}}}}}}})),T_=({strapi:i})=>{const u=S_(i);return{getCommonService(){return ft(i,"common")},async findAll({_q:o,orderBy:h,page:m,pageSize:A,filters:S}){const C=u.findAll.createParams(h,m,A,o,S),R=u.findAll.getPopulate(),N=it(i),{pagination:O,results:F}=await N.findWithCount({...C,count:!0,populate:R}),U=await this.getCommonService().findRelatedEntitiesFor(F);return{pagination:O,result:F.map(Q=>this.getCommonService().sanitizeCommentEntity(Q,[],[])).map(Q=>this.getCommonService().mergeRelatedEntityTo(Q,U))}},async findReports({_q:o,orderBy:h,page:m,pageSize:A}){const S=u.findReports.createParams(h,m,A,o),C=il(i),{pagination:R,results:N}=await Di(i).findPage({...S,populate:{related:{populate:{authorUser:C}}}}),O=N.map(j=>typeof j.related=="object"?j.related?.id:null).filter(Boolean),F=await it(i).findMany({where:{threadOf:O},populate:["threadOf"],limit:Number.MAX_SAFE_INTEGER}),U=Array.from(new Set(F.map(({threadOf:j})=>typeof j=="object"?j?.id:null).filter(Boolean)));return{result:N.map(j=>{const J=U.includes(j.related?.id),te=this.getCommonService(),X={...j,related:te.sanitizeCommentEntity({...j.related,gotThread:J},[])},ye=typeof C!="boolean"?C?.populate:{};return yv(te.sanitizeCommentEntity(X,[],[],ye))}),pagination:R}},async findOneAndThread({id:o,removed:h,...m}){const A=il(i),S=u.findOneAndThread.getDefaultWhere(h),C=u.findOneAndThread.getPopulate(),R=await it(i).findOne({...C,where:{id:o}});if(!R)throw new An(404,"Not found");const{relatedId:N,uid:O}=this.getCommonService().parseRelationString(R.related),F=await i.documents(O).findOne({documentId:N}).then(te=>{if(!te)throw new An(404,"Relation not found");return{...te,uid:O}}),U=R.threadOf&&typeof R.threadOf=="object"?R.threadOf.id:null,Q=await this.getCommonService().findAllInHierarchy({filters:{...S,...m,threadOf:U,related:R.related},...C,startingFromId:U,isAdmin:!0,limit:Number.MAX_SAFE_INTEGER},!1),j=typeof A!="boolean"?A?.populate:{},J=this.getCommonService().sanitizeCommentEntity({...R,threadOf:R.threadOf||null},[],[],j);return{entity:F,selected:J,level:Q}},async changeBlockedComment(o,h){const m=await this.getCommonService().findOne({id:o});return this.getCommonService().updateComment({id:o},{blocked:ze.isNil(h)?!m.blocked:h})},async deleteComment(o){return it(i).update({where:{id:o},data:{removed:!0}})},async blockCommentThread(o,h){const m=await this.getCommonService().findOne({id:o}),A=h||!m.blocked,S=await this.getCommonService().updateComment({id:o},{blocked:A,blockedThread:A});return await this.blockNestedThreads(o,A),this.getCommonService().sanitizeCommentEntity(S,[])},async approveComment(o){const h=await it(i).update({where:{id:o},data:{approvalStatus:Fi.APPROVED}});if(!h)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(h,[])},async rejectComment(o){const h=await it(i).update({where:{id:o},data:{approvalStatus:Fi.REJECTED}});if(!h)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(h,[])},async blockNestedThreads(o,h){return this.getCommonService().modifiedNestedNestedComments(o,"blockedThread",h)},async resolveAbuseReport({id:o,reportId:h}){return Di(i).update({where:{id:h,related:o},data:{resolved:!0}})},async resolveCommentMultipleAbuseReports({id:o,reportIds:h}){if((await Di(i).findMany({where:{id:h,related:o},populate:["related"]})).length===h.length)return Di(i).updateMany({where:{id:h},data:{resolved:!0}});throw new An(400,"At least one of selected reports got invalid comment entity relation. Try again.")},async resolveAllAbuseReportsForComment(o){if(!o)throw new An(400,"There is something wrong with comment Id. Try again.");return Di(i).updateMany({where:{related:o,resolved:!1},data:{resolved:!0}})},async resolveAllAbuseReportsForThread(o){if(!o)throw new An(400,"There is something wrong with comment Id. Try again.");const h=await it(i).findMany({where:{threadOf:o},select:["id"]});return Di(i).updateMany({where:{related:h.map(({id:m})=>m).concat([o]),resolved:!1},data:{resolved:!0}})},async resolveMultipleAbuseReports({reportIds:o}){return Di(i).updateMany({where:{id:{$in:o}},data:{resolved:!0}})},async postComment({id:o,author:h,content:m}){const A=await it(i).findOne({where:{id:o}});if(!A)throw new An(404,"Not found");return it(i).create({data:{content:this.getCommonService().sanitizeCommentContent(m),threadOf:o,authorId:h.id,authorName:E_(h),authorEmail:h.email,related:A.related,isAdminComment:!0}})},async updateComment({id:o,content:h}){const m=await it(i).update({where:{id:o},data:{content:this.getCommonService().sanitizeCommentContent(h)}});if(!m)throw new An(404,"Not found");return this.getCommonService().sanitizeCommentEntity(m,[])}}},O_=async(i,u)=>{try{return ol(await i())}catch{return av(u)}},C_=({strapi:i})=>{const u=async(o,h)=>{if(h)return{authorUser:h.id};if(o)return{authorId:o.id,authorName:o.name,authorEmail:o.email,authorAvatar:o.avatar}};return{getCommonService(){return ft(i,"common")},async create({relation:o,content:h,threadOf:m,author:A,approvalStatus:S,locale:C},R){const{uid:N,relatedId:O}=this.getCommonService().parseRelationString(o),F=await i.documents(N).findOne({documentId:O,locale:C});if(!F)throw new fn(400,'Relation for field "related" does not exist. Check your payload please.');const Q=(await this.getCommonService().getConfig(oa.APPROVAL_FLOW,[])).includes(N)||F.requireCommentsApproval,j=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]),J=await O_(async()=>m?await this.getCommonService().findOne({id:m,related:o,locale:C||null}):null,new fn(400,"Thread does not exist"));if(Ay(J))throw Y(J);const te=Y(J);if(!A&&!this.getCommonService().isValidUserContext(R))throw Cf(R);const[X,ye]=await Promise.all([this.getCommonService().checkBadWords(h),u(A,R)]),_e=!ze.isEmpty(ye)&&!(ye.authorId||ye.authorUser);if(ze.isEmpty(ye)||_e)throw new fn(400,`Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);if(Q&&S&&S!==Fi.PENDING)throw new fn(400,"Invalid approval status");const Ve={...await it(i).create({data:{...ye,threadOf:m,locale:C,content:this.getCommonService().sanitizeCommentContent(X),related:o,approvalStatus:Q?Fi.PENDING:Fi.APPROVED},populate:{authorUser:{populate:["avatar"]}}}),threadOf:te},Ye=this.getCommonService().sanitizeCommentEntity(Ve,j);try{await this.sendResponseNotification(Ye)}catch(Me){console.error(Me)}return Ye},async update({commentId:o,content:h,author:m,relation:A},S){if(!m&&!this.getCommonService().isValidUserContext(S))throw Cf(S);const C=S?.id||m?.id;if(await this.getCommonService().checkBadWords(h)){const R=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]),N=await this.getCommonService().findOne({id:o,related:A});if(N&&N.author?.id?.toString()===C?.toString()){const O=await it(i).update({where:{id:o},data:{content:this.getCommonService().sanitizeCommentContent(h)},populate:{threadOf:!0,authorUser:{populate:["avatar"]}}});return this.getCommonService().sanitizeCommentEntity(O,R)}}},async reportAbuse({commentId:o,relation:h,...m},A){if(!this.getCommonService().isValidUserContext(A))throw Cf(A);try{const S=await this.getCommonService().findOne({id:o,related:h});if(S.isAdminComment)throw new fn(403,"You're not allowed to take an action on that entity. This in a admin comment.");if(S){const C=await Di(i).create({data:{...m,resolved:!1,related:o}});if(C){const R={...C,related:S};try{return await this.sendAbuseReportEmail(C.reason,C.content),R}catch{return R}}else throw new fn(500,"Report cannot be created")}throw new fn(403,"You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.")}catch(S){throw S}},async markAsRemoved({commentId:o,relation:h,authorId:m},A){if(!m&&!this.getCommonService().isValidUserContext(A))throw Cf(A);const S=A?.id||m;if(!S)throw new fn(403,`You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`);try{const C=A?.id?{authorUser:S}:{authorId:S};if(await this.getCommonService().findOne({id:o,related:h,...C})){const N=await it(i).update({where:{id:o,related:h},data:{removed:!0},populate:{threadOf:!0,authorUser:{populate:["avatar"]}}});await this.markAsRemovedNested(o,!0);const O=await this.getCommonService().getConfig(oa.AUTHOR_BLOCKED_PROPS,[]);return this.getCommonService().sanitizeCommentEntity(N,O)}else throw new fn(404,"Entity does not exist or you're not allowed to take an action on it")}catch{throw new fn(404,"Entity does not exist or you're not allowed to take an action on it")}},async sendAbuseReportEmail(o,h){const m="strapi-super-admin",A=await this.getCommonService().getConfig(oa.MODERATOR_ROLES,[m]);if(A.length>0){const S=await i.query("admin::user").findMany({where:{roles:{code:A}}}).then(C=>C.map(R=>R.email));if(S.length>0){const C=await i.query("admin::user").findOne({where:{roles:{code:m}}});i.plugin("email")&&await i.plugin("email").service("email").send({to:S,from:C.email,subject:"New abuse report on comment",text:`
83
83
  There was a new abuse report on your app.
84
84
  Reason: ${o}
85
85
  Message: ${h}
@@ -7275,18 +7275,18 @@ const km = (i) => i.split(Hv.relatedUid).filter((u) => u && u.length > 0), vv =
7275
7275
  }
7276
7276
  }
7277
7277
  }
7278
- }), O = N.map(($) => typeof $.related == "object" ? $.related.id : null).filter(Boolean), U = await it(i).findMany({
7278
+ }), O = N.map(($) => typeof $.related == "object" ? $.related?.id : null).filter(Boolean), U = await it(i).findMany({
7279
7279
  where: {
7280
7280
  threadOf: O
7281
7281
  },
7282
7282
  populate: ["threadOf"],
7283
7283
  limit: Number.MAX_SAFE_INTEGER
7284
7284
  }), M = Array.from(
7285
- new Set(U.map(({ threadOf: $ }) => typeof $ == "object" ? $.id : null).filter(Boolean))
7285
+ new Set(U.map(({ threadOf: $ }) => typeof $ == "object" ? $?.id : null).filter(Boolean))
7286
7286
  );
7287
7287
  return {
7288
7288
  result: N.map(($) => {
7289
- const J = M.includes($.related.id), te = this.getCommonService(), X = {
7289
+ const J = M.includes($.related?.id), te = this.getCommonService(), X = {
7290
7290
  ...$,
7291
7291
  related: te.sanitizeCommentEntity(
7292
7292
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-comments",
3
- "version": "3.2.2",
3
+ "version": "3.2.3-beta.2",
4
4
  "description": "Strapi - Comments plugin",
5
5
  "strapi": {
6
6
  "name": "comments",
@@ -87,8 +87,8 @@
87
87
  "typescript": "^5.6.2"
88
88
  },
89
89
  "peerDependencies": {
90
- "@strapi/design-system": "^2.0.0",
91
- "@strapi/icons": "^2.0.0",
90
+ "@strapi/design-system": ">=2.0.0-rc.0 <3.0.0",
91
+ "@strapi/icons": ">=2.0.0-rc.0 <3.0.0",
92
92
  "@strapi/sdk-plugin": "^5.0.0",
93
93
  "@strapi/strapi": "^5.0.0",
94
94
  "react": "^17.0.0 || ^18.0.0",