qarpeo 0.1.32 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +5 -7
  2. package/dist/chunks/auth-schema.mjs +12 -10
  3. package/dist/chunks/wrangler.mjs +1 -1
  4. package/dist/module.d.ts +1 -0
  5. package/dist/module.mjs +284 -100
  6. package/dist/runtime/app/components/Comments.vue +411 -0
  7. package/dist/runtime/app/composables/cms.d.ts +11 -7
  8. package/dist/runtime/app/composables/cms.mjs +36 -68
  9. package/dist/runtime/app/composables/comments.d.ts +45 -0
  10. package/dist/runtime/app/composables/comments.mjs +150 -0
  11. package/dist/runtime/app/composables/organization.d.ts +3 -3
  12. package/dist/runtime/server/db/cms-schema.d.ts +1 -1
  13. package/dist/runtime/server/db/cms-schema.mjs +1 -2
  14. package/dist/runtime/server/routes/cms/[collection]/index.get.mjs +2 -0
  15. package/dist/runtime/server/routes/cms/publish-scheduled.post.mjs +7 -4
  16. package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +9 -2
  17. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +41 -28
  18. package/dist/runtime/server/routes/comments/[id]/react.post.d.ts +6 -0
  19. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +35 -0
  20. package/dist/runtime/server/routes/{cms/comments/[id].patch.d.ts → comments/[id]/report.post.d.ts} +1 -2
  21. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +50 -0
  22. package/dist/runtime/server/routes/{cms/comments → comments}/[id].delete.d.ts +0 -1
  23. package/dist/runtime/server/routes/comments/[id].delete.mjs +27 -0
  24. package/dist/runtime/server/routes/{cms/comments → comments}/[id].get.d.ts +1 -1
  25. package/dist/runtime/server/routes/comments/[id].get.mjs +14 -0
  26. package/dist/runtime/server/routes/comments/[id].patch.d.ts +4 -0
  27. package/dist/runtime/server/routes/comments/[id].patch.mjs +37 -0
  28. package/dist/runtime/server/routes/{cms/comments.get.d.ts → comments/index.get.d.ts} +1 -1
  29. package/dist/runtime/server/routes/comments/index.get.mjs +34 -0
  30. package/dist/runtime/server/routes/comments/index.post.d.ts +4 -0
  31. package/dist/runtime/server/routes/comments/index.post.mjs +36 -0
  32. package/dist/runtime/server/utils/audit.d.ts +3 -3
  33. package/dist/runtime/server/utils/audit.mjs +43 -17
  34. package/dist/runtime/server/utils/auth.d.ts +55 -0
  35. package/dist/runtime/server/utils/auth.mjs +92 -10
  36. package/dist/runtime/server/utils/cms/git.mjs +2 -6
  37. package/dist/runtime/server/utils/cms.d.ts +17 -22
  38. package/dist/runtime/server/utils/cms.mjs +144 -309
  39. package/dist/runtime/server/utils/comments.d.ts +112 -0
  40. package/dist/runtime/server/utils/comments.mjs +450 -0
  41. package/dist/runtime/server/utils/config.d.ts +2 -1
  42. package/dist/runtime/server/utils/config.mjs +1 -0
  43. package/dist/runtime/server/utils/urn.d.ts +15 -0
  44. package/dist/runtime/server/utils/urn.mjs +20 -0
  45. package/dist/runtime/server.d.ts +4 -0
  46. package/dist/runtime/server.mjs +5 -0
  47. package/dist/runtime/types/auth.d.ts +12 -1
  48. package/dist/types.d.ts +67 -27
  49. package/dist/utils/comments-schema.d.ts +13 -0
  50. package/package.json +4 -4
  51. package/dist/runtime/app/components/CMSComments.vue +0 -202
  52. package/dist/runtime/server/routes/cms/comments/[id].delete.mjs +0 -12
  53. package/dist/runtime/server/routes/cms/comments/[id].get.mjs +0 -13
  54. package/dist/runtime/server/routes/cms/comments/[id].patch.mjs +0 -17
  55. package/dist/runtime/server/routes/cms/comments.get.mjs +0 -43
  56. package/dist/runtime/server/routes/cms/comments.post.d.ts +0 -17
  57. package/dist/runtime/server/routes/cms/comments.post.mjs +0 -46
@@ -0,0 +1,411 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from "vue"
3
+
4
+ import { useComments, type CommentItem } from "../composables/comments"
5
+
6
+ const props = withDefaults(
7
+ defineProps<{
8
+ /** Universal Resource Name of target (e.g. "urn:cms:blog:my-post" or "urn:product:123") */
9
+ targetUrn?: string
10
+ /** Optional CMS entry identifier alias (resolves to urn:cms:entry:<id>) */
11
+ entryId?: string
12
+ title?: string
13
+ allowReplies?: boolean
14
+ allowReactions?: boolean
15
+ reactions?: string[]
16
+ allowReports?: boolean
17
+ placeholder?: string
18
+ }>(),
19
+ {
20
+ title: "Discussion",
21
+ allowReplies: true,
22
+ allowReactions: true,
23
+ reactions: () => ["like", "heart", "fire"],
24
+ allowReports: true,
25
+ placeholder: "Share your thoughts or ask a question...",
26
+ },
27
+ )
28
+
29
+ const resolvedUrn = computed(() => {
30
+ if (props.targetUrn) return props.targetUrn
31
+ if (props.entryId) {
32
+ return props.entryId.startsWith("urn:") ? props.entryId : `urn:cms:entry:${props.entryId}`
33
+ }
34
+ return ""
35
+ })
36
+
37
+ const { comments, loading, error, postComment, deleteComment, reportComment, react } =
38
+ useComments(() => resolvedUrn.value)
39
+
40
+ const authorName = ref("")
41
+ const authorEmail = ref("")
42
+ const newContent = ref("")
43
+ const replyToId = ref<string | null>(null)
44
+ const replyContent = ref("")
45
+ const replyAuthorName = ref("")
46
+ const submitting = ref(false)
47
+ const reportingId = ref<string | null>(null)
48
+ const reportReason = ref<"spam" | "harassment" | "off-topic" | "misinformation" | "other">("spam")
49
+ const reportNote = ref("")
50
+
51
+ const reactionIcons: Record<string, string> = {
52
+ like: "👍",
53
+ heart: "❤️",
54
+ fire: "🔥",
55
+ unicorn: "🦄",
56
+ }
57
+
58
+ async function handleRootSubmit() {
59
+ if (!newContent.value.trim() || !authorName.value.trim()) return
60
+ submitting.value = true
61
+ try {
62
+ await postComment({
63
+ content: newContent.value.trim(),
64
+ authorName: authorName.value.trim(),
65
+ authorEmail: authorEmail.value.trim() || undefined,
66
+ })
67
+ newContent.value = ""
68
+ } finally {
69
+ submitting.value = false
70
+ }
71
+ }
72
+
73
+ async function handleReplySubmit(parentId: string) {
74
+ if (!replyContent.value.trim() || !replyAuthorName.value.trim()) return
75
+ submitting.value = true
76
+ try {
77
+ await postComment({
78
+ parentId,
79
+ content: replyContent.value.trim(),
80
+ authorName: replyAuthorName.value.trim(),
81
+ })
82
+ replyContent.value = ""
83
+ replyToId.value = null
84
+ } finally {
85
+ submitting.value = false
86
+ }
87
+ }
88
+
89
+ async function submitReport(commentId: string) {
90
+ await reportComment(commentId, reportReason.value, reportNote.value || undefined)
91
+ reportingId.value = null
92
+ reportNote.value = ""
93
+ }
94
+
95
+ function formatDate(ms: number): string {
96
+ if (!ms) return ""
97
+ return new Date(ms).toLocaleDateString(undefined, {
98
+ year: "numeric",
99
+ month: "short",
100
+ day: "numeric",
101
+ })
102
+ }
103
+ </script>
104
+
105
+ <template>
106
+ <section class="qarpeo-comments space-y-6">
107
+ <div class="flex items-center justify-between border-b pb-3 dark:border-neutral-800">
108
+ <h3 class="text-lg font-bold text-neutral-900 dark:text-neutral-100">
109
+ {{ title }}
110
+ <span class="ml-1 text-sm font-normal text-neutral-500">({{ comments.length }})</span>
111
+ </h3>
112
+ </div>
113
+
114
+ <!-- Main Comment Form -->
115
+ <form
116
+ class="space-y-3 rounded-xl border border-neutral-200 bg-neutral-50/50 p-4 dark:border-neutral-800 dark:bg-neutral-900/50"
117
+ @submit.prevent="handleRootSubmit"
118
+ >
119
+ <div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
120
+ <input
121
+ v-model="authorName"
122
+ type="text"
123
+ placeholder="Your name *"
124
+ required
125
+ class="w-full rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm outline-none focus:border-neutral-900 focus:ring-1 focus:ring-neutral-900 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
126
+ />
127
+ <input
128
+ v-model="authorEmail"
129
+ type="email"
130
+ placeholder="Your email (optional)"
131
+ class="w-full rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm outline-none focus:border-neutral-900 focus:ring-1 focus:ring-neutral-900 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
132
+ />
133
+ </div>
134
+
135
+ <textarea
136
+ v-model="newContent"
137
+ rows="3"
138
+ :placeholder="placeholder"
139
+ required
140
+ class="w-full rounded-lg border border-neutral-300 bg-white p-3 text-sm outline-none focus:border-neutral-900 focus:ring-1 focus:ring-neutral-900 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
141
+ />
142
+
143
+ <div class="flex items-center justify-between">
144
+ <span v-if="error" class="text-xs text-red-500">
145
+ {{ error.message || "Failed to post comment" }}
146
+ </span>
147
+ <span v-else />
148
+
149
+ <button
150
+ type="submit"
151
+ :disabled="submitting || !newContent.trim() || !authorName.trim()"
152
+ class="rounded-lg bg-neutral-900 px-4 py-2 text-xs font-semibold text-white transition hover:bg-neutral-800 disabled:opacity-50 dark:bg-white dark:text-neutral-900 dark:hover:bg-neutral-200"
153
+ >
154
+ {{ submitting ? "Posting..." : "Post Comment" }}
155
+ </button>
156
+ </div>
157
+ </form>
158
+
159
+ <!-- Comments List -->
160
+ <div v-if="loading && comments.length === 0" class="py-6 text-center text-sm text-neutral-500">
161
+ Loading comments...
162
+ </div>
163
+
164
+ <div v-else-if="comments.length === 0" class="py-6 text-center text-sm text-neutral-500">
165
+ No comments yet. Be the first to start the conversation!
166
+ </div>
167
+
168
+ <div v-else class="space-y-4">
169
+ <!-- Recursive or flattened tree renderer -->
170
+ <template v-for="comment in comments" :key="comment.id">
171
+ <div
172
+ class="space-y-3 rounded-xl border border-neutral-200 bg-white p-4 dark:border-neutral-800 dark:bg-neutral-900"
173
+ >
174
+ <!-- Comment Header -->
175
+ <div class="flex items-center justify-between">
176
+ <div class="flex items-center gap-2.5">
177
+ <img
178
+ v-if="comment.authorAvatar"
179
+ :src="comment.authorAvatar"
180
+ alt="Avatar"
181
+ class="h-8 w-8 rounded-full"
182
+ />
183
+ <div
184
+ v-else
185
+ class="flex h-8 w-8 items-center justify-center rounded-full bg-neutral-200 text-xs font-bold text-neutral-700 dark:bg-neutral-700 dark:text-neutral-200"
186
+ >
187
+ {{ (comment.authorName || "A")[0]?.toUpperCase() }}
188
+ </div>
189
+ <div>
190
+ <p class="text-sm font-semibold text-neutral-900 dark:text-neutral-100">
191
+ {{ comment.authorName }}
192
+ </p>
193
+ <p class="text-xs text-neutral-500">
194
+ {{ formatDate(comment.createdAt) }}
195
+ </p>
196
+ </div>
197
+ </div>
198
+
199
+ <!-- Actions Menu -->
200
+ <div class="flex items-center gap-2">
201
+ <button
202
+ v-if="allowReports && comment.status !== 'deleted'"
203
+ type="button"
204
+ class="text-xs text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300"
205
+ @click="reportingId = reportingId === comment.id ? null : comment.id"
206
+ >
207
+ Report
208
+ </button>
209
+ <button
210
+ type="button"
211
+ class="text-xs text-neutral-400 hover:text-red-600"
212
+ @click="deleteComment(comment.id)"
213
+ >
214
+ Delete
215
+ </button>
216
+ </div>
217
+ </div>
218
+
219
+ <!-- Report Dropdown/Modal inline -->
220
+ <div
221
+ v-if="reportingId === comment.id"
222
+ class="space-y-2 rounded-lg border border-red-200 bg-red-50 p-3 dark:border-red-900/50 dark:bg-red-950/30"
223
+ >
224
+ <p class="text-xs font-semibold text-red-800 dark:text-red-300">
225
+ Report this comment
226
+ </p>
227
+ <div class="flex flex-wrap gap-2">
228
+ <label
229
+ v-for="r in ['spam', 'harassment', 'off-topic', 'misinformation', 'other'] as const"
230
+ :key="r"
231
+ class="flex items-center gap-1 text-xs"
232
+ >
233
+ <input v-model="reportReason" type="radio" :value="r" />
234
+ <span class="capitalize">{{ r }}</span>
235
+ </label>
236
+ </div>
237
+ <input
238
+ v-model="reportNote"
239
+ type="text"
240
+ placeholder="Additional details (optional)"
241
+ class="w-full rounded border border-red-300 bg-white px-2 py-1 text-xs outline-none dark:border-red-800 dark:bg-neutral-900"
242
+ />
243
+ <div class="flex justify-end gap-2">
244
+ <button
245
+ type="button"
246
+ class="text-xs text-neutral-600 dark:text-neutral-400"
247
+ @click="reportingId = null"
248
+ >
249
+ Cancel
250
+ </button>
251
+ <button
252
+ type="button"
253
+ class="rounded bg-red-600 px-2.5 py-1 text-xs font-semibold text-white"
254
+ @click="submitReport(comment.id)"
255
+ >
256
+ Submit Report
257
+ </button>
258
+ </div>
259
+ </div>
260
+
261
+ <!-- Comment Body -->
262
+ <p
263
+ class="text-sm leading-relaxed"
264
+ :class="
265
+ comment.status === 'deleted'
266
+ ? 'italic text-neutral-400'
267
+ : 'text-neutral-800 dark:text-neutral-200'
268
+ "
269
+ >
270
+ {{ comment.content }}
271
+ </p>
272
+
273
+ <!-- Reactions & Reply Button -->
274
+ <div class="flex flex-wrap items-center justify-between gap-2 pt-1">
275
+ <!-- Reactions -->
276
+ <div v-if="allowReactions && comment.status !== 'deleted'" class="flex flex-wrap items-center gap-1.5">
277
+ <button
278
+ v-for="rx in reactions"
279
+ :key="rx"
280
+ type="button"
281
+ class="flex items-center gap-1 rounded-full border border-neutral-200 bg-neutral-50 px-2.5 py-1 text-xs transition hover:bg-neutral-100 dark:border-neutral-700 dark:bg-neutral-800 dark:hover:bg-neutral-700"
282
+ @click="react(comment.id, rx)"
283
+ >
284
+ <span>{{ reactionIcons[rx] || rx }}</span>
285
+ <span v-if="comment.reactionCounts?.[rx]" class="font-medium text-neutral-700 dark:text-neutral-300">
286
+ {{ comment.reactionCounts[rx] }}
287
+ </span>
288
+ </button>
289
+ </div>
290
+ <div v-else />
291
+
292
+ <!-- Reply Button -->
293
+ <button
294
+ v-if="allowReplies && comment.status !== 'deleted'"
295
+ type="button"
296
+ class="text-xs font-medium text-neutral-600 hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-100"
297
+ @click="replyToId = replyToId === comment.id ? null : comment.id"
298
+ >
299
+ {{ replyToId === comment.id ? "Cancel Reply" : "Reply" }}
300
+ </button>
301
+ </div>
302
+
303
+ <!-- Inline Reply Box -->
304
+ <div
305
+ v-if="replyToId === comment.id"
306
+ class="mt-3 space-y-2 rounded-lg border border-neutral-200 bg-neutral-50 p-3 dark:border-neutral-800 dark:bg-neutral-900"
307
+ >
308
+ <input
309
+ v-model="replyAuthorName"
310
+ type="text"
311
+ placeholder="Your name *"
312
+ required
313
+ class="w-full rounded border border-neutral-300 bg-white px-2 py-1 text-xs outline-none focus:border-neutral-900 dark:border-neutral-700 dark:bg-neutral-800"
314
+ />
315
+ <textarea
316
+ v-model="replyContent"
317
+ rows="2"
318
+ placeholder="Write your reply..."
319
+ class="w-full rounded border border-neutral-300 bg-white p-2 text-xs outline-none focus:border-neutral-900 dark:border-neutral-700 dark:bg-neutral-800"
320
+ />
321
+ <div class="flex justify-end">
322
+ <button
323
+ type="button"
324
+ :disabled="submitting || !replyContent.trim() || !replyAuthorName.trim()"
325
+ class="rounded bg-neutral-900 px-3 py-1.5 text-xs font-semibold text-white disabled:opacity-50 dark:bg-white dark:text-neutral-900"
326
+ @click="handleReplySubmit(comment.id)"
327
+ >
328
+ {{ submitting ? "Posting..." : "Post Reply" }}
329
+ </button>
330
+ </div>
331
+ </div>
332
+
333
+ <!-- Nested Replies (Level 1+) -->
334
+ <div
335
+ v-if="comment.replies && comment.replies.length > 0"
336
+ class="mt-3 space-y-3 border-l-2 border-neutral-200 pl-4 dark:border-neutral-800"
337
+ >
338
+ <div
339
+ v-for="reply in comment.replies"
340
+ :key="reply.id"
341
+ class="space-y-2 rounded-lg border border-neutral-100 bg-neutral-50/50 p-3 dark:border-neutral-800/60 dark:bg-neutral-900/30"
342
+ >
343
+ <div class="flex items-center justify-between">
344
+ <div class="flex items-center gap-2">
345
+ <img
346
+ v-if="reply.authorAvatar"
347
+ :src="reply.authorAvatar"
348
+ alt="Avatar"
349
+ class="h-6 w-6 rounded-full"
350
+ />
351
+ <div
352
+ v-else
353
+ class="flex h-6 w-6 items-center justify-center rounded-full bg-neutral-200 text-[10px] font-bold text-neutral-700 dark:bg-neutral-700 dark:text-neutral-200"
354
+ >
355
+ {{ (reply.authorName || "A")[0]?.toUpperCase() }}
356
+ </div>
357
+ <div>
358
+ <p class="text-xs font-semibold text-neutral-900 dark:text-neutral-100">
359
+ {{ reply.authorName }}
360
+ </p>
361
+ <p class="text-[10px] text-neutral-500">
362
+ {{ formatDate(reply.createdAt) }}
363
+ </p>
364
+ </div>
365
+ </div>
366
+
367
+ <button
368
+ type="button"
369
+ class="text-[11px] text-neutral-400 hover:text-red-600"
370
+ @click="deleteComment(reply.id)"
371
+ >
372
+ Delete
373
+ </button>
374
+ </div>
375
+
376
+ <p
377
+ class="text-xs leading-relaxed"
378
+ :class="
379
+ reply.status === 'deleted'
380
+ ? 'italic text-neutral-400'
381
+ : 'text-neutral-700 dark:text-neutral-300'
382
+ "
383
+ >
384
+ {{ reply.content }}
385
+ </p>
386
+
387
+ <!-- Reply Reactions -->
388
+ <div
389
+ v-if="allowReactions && reply.status !== 'deleted'"
390
+ class="flex flex-wrap items-center gap-1 pt-1"
391
+ >
392
+ <button
393
+ v-for="rx in reactions"
394
+ :key="rx"
395
+ type="button"
396
+ class="flex items-center gap-1 rounded-full border border-neutral-200 bg-white px-2 py-0.5 text-[11px] transition hover:bg-neutral-100 dark:border-neutral-700 dark:bg-neutral-800"
397
+ @click="react(reply.id, rx)"
398
+ >
399
+ <span>{{ reactionIcons[rx] || rx }}</span>
400
+ <span v-if="reply.reactionCounts?.[rx]" class="font-medium text-neutral-700 dark:text-neutral-300">
401
+ {{ reply.reactionCounts[rx] }}
402
+ </span>
403
+ </button>
404
+ </div>
405
+ </div>
406
+ </div>
407
+ </div>
408
+ </template>
409
+ </div>
410
+ </section>
411
+ </template>
@@ -330,22 +330,26 @@ export declare function useDocsSearch(options?: {
330
330
  search: (q: string) => Promise<void>;
331
331
  searchDebounced: (q: string, delay?: number) => void;
332
332
  };
333
- /** Reactive composable for fetching and posting threaded comments on a CMS entry. */
333
+ /**
334
+ * @deprecated Use `useComments("urn:cms:entry:" + entryId)` instead.
335
+ * Preserved for backwards compatibility with legacy CMS templates.
336
+ */
334
337
  export declare function useCMSComments(entryId: string | (() => string) | any): {
335
- comments: Ref<any[], any[]>;
338
+ comments: Ref<import("./comments").CommentItem[], import("./comments").CommentItem[]>;
336
339
  loading: Ref<boolean, boolean>;
337
340
  error: Ref<Error | null, Error | null>;
338
- fetchComments: () => Promise<any[]>;
339
- fetchComment: (commentId: string) => Promise<any>;
341
+ total: Ref<number, number>;
342
+ fetchComments: () => Promise<void>;
340
343
  postComment: (data: {
341
344
  authorName: string;
342
345
  content: string;
343
346
  authorEmail?: string;
344
347
  authorAvatar?: string;
345
348
  parentId?: string;
346
- }) => Promise<any>;
347
- updateCommentStatus: (commentId: string, status: "approved" | "pending" | "spam") => Promise<any>;
348
- deleteComment: (commentId: string) => Promise<any>;
349
+ }) => Promise<import("./comments").CommentItem | null>;
350
+ deleteComment: (id: string) => Promise<boolean>;
351
+ reportComment: (id: string, reason: string, note?: string) => Promise<boolean>;
352
+ react: (id: string, reaction: string) => Promise<boolean>;
349
353
  };
350
354
  export interface UseCMSCategoriesReturn {
351
355
  categories: ComputedRef<any[]>;
@@ -1,5 +1,6 @@
1
1
  import { useRuntimeConfig, useFetch } from "nuxt/app";
2
2
  import { ref, computed } from "vue";
3
+ import { useComments } from "./comments.mjs";
3
4
  import { useCMSPreview } from "./cms-preview.mjs";
4
5
  export function useCMS(collectionId) {
5
6
  const runtimeConfig = useRuntimeConfig();
@@ -243,6 +244,17 @@ export function queryCollection(collection) {
243
244
  if (_orderField) params.set("sort", `${_orderField}:${_orderDirection.toLowerCase()}`);
244
245
  if (_locale) params.set("locale", _locale);
245
246
  if (_fields.length) params.set("fields", _fields.join(","));
247
+ if (_wheres.length) {
248
+ const serverWhere = {};
249
+ for (const w of _wheres) {
250
+ if (w.op === "=" && /^[a-zA-Z0-9_]+$/.test(w.field)) {
251
+ serverWhere[w.field] = w.value;
252
+ }
253
+ }
254
+ if (Object.keys(serverWhere).length > 0) {
255
+ params.set("where", JSON.stringify(serverWhere));
256
+ }
257
+ }
246
258
  const qs = params.toString() ? `?${params.toString()}` : "";
247
259
  let res;
248
260
  try {
@@ -401,83 +413,37 @@ export function useDocsSearch(options) {
401
413
  };
402
414
  }
403
415
  export function useCMSComments(entryId) {
404
- const runtimeConfig = useRuntimeConfig();
405
- const publicCms = runtimeConfig.public?.qarpeo?.cms || {};
406
- const apiPath = publicCms.apiPath || "/api/cms";
407
416
  const targetId = computed(() => {
408
417
  if (typeof entryId === "function") return entryId();
409
418
  if (entryId && typeof entryId === "object" && "value" in entryId) return entryId.value;
410
419
  return String(entryId || "");
411
420
  });
412
- const comments = ref([]);
413
- const loading = ref(false);
414
- const error = ref(null);
415
- async function fetchComments() {
416
- if (!targetId.value) return [];
417
- loading.value = true;
418
- error.value = null;
419
- try {
420
- const res = await $fetch(
421
- `${apiPath}/comments?entryId=${encodeURIComponent(targetId.value)}`
422
- );
423
- comments.value = res?.comments || [];
424
- return comments.value;
425
- } catch (err) {
426
- error.value = err;
427
- return [];
428
- } finally {
429
- loading.value = false;
430
- }
431
- }
432
- async function postComment(data) {
433
- if (!targetId.value) throw new Error("Entry ID is required");
434
- const res = await $fetch(`${apiPath}/comments`, {
435
- method: "POST",
436
- body: {
437
- entryId: targetId.value,
438
- ...data
439
- }
440
- });
441
- await fetchComments();
442
- return res?.comment;
443
- }
444
- async function updateCommentStatus(commentId, status) {
445
- const res = await $fetch(`${apiPath}/comments/${encodeURIComponent(commentId)}`, {
446
- method: "PATCH",
447
- body: { status }
448
- });
449
- await fetchComments();
450
- return res;
451
- }
452
- async function fetchComment(commentId) {
453
- loading.value = true;
454
- error.value = null;
455
- try {
456
- const res = await $fetch(`${apiPath}/comments/${encodeURIComponent(commentId)}`);
457
- return res?.comment || null;
458
- } catch (err) {
459
- error.value = err;
460
- return null;
461
- } finally {
462
- loading.value = false;
463
- }
464
- }
465
- async function deleteComment(commentId) {
466
- const res = await $fetch(`${apiPath}/comments/${encodeURIComponent(commentId)}`, {
467
- method: "DELETE"
468
- });
469
- await fetchComments();
470
- return res;
471
- }
472
- return {
421
+ const urn = computed(() => {
422
+ const id = targetId.value;
423
+ if (!id) return "";
424
+ return id.startsWith("urn:") ? id : `urn:cms:entry:${id}`;
425
+ });
426
+ const {
473
427
  comments,
474
428
  loading,
475
429
  error,
430
+ total,
476
431
  fetchComments,
477
- fetchComment,
478
432
  postComment,
479
- updateCommentStatus,
480
- deleteComment
433
+ deleteComment,
434
+ reportComment,
435
+ react
436
+ } = useComments(urn);
437
+ return {
438
+ comments,
439
+ loading,
440
+ error,
441
+ total,
442
+ fetchComments,
443
+ postComment: (data) => postComment(data),
444
+ deleteComment,
445
+ reportComment,
446
+ react
481
447
  };
482
448
  }
483
449
  export function useCMSCategories() {
@@ -618,7 +584,9 @@ export function useCMSNewsletter() {
618
584
  const success = ref(false);
619
585
  const error = ref(null);
620
586
  async function subscribe(email, source = "website") {
621
- if (!email || !email.includes("@")) {
587
+ const rawEmail = typeof email === "string" ? email.trim() : "";
588
+ const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
589
+ if (!rawEmail || rawEmail.length > 255 || !emailRegex.test(rawEmail)) {
622
590
  error.value = "Valid email is required";
623
591
  return false;
624
592
  }
@@ -0,0 +1,45 @@
1
+ import { type MaybeRefOrGetter, type Ref } from "vue";
2
+ export interface CommentItem {
3
+ id: string;
4
+ targetUrn: string;
5
+ tenantId?: string;
6
+ parentId?: string;
7
+ path: string;
8
+ depth: number;
9
+ authorName: string;
10
+ authorEmail?: string;
11
+ authorAvatar?: string;
12
+ content: string;
13
+ status: "pending" | "approved" | "spam" | "deleted";
14
+ deletedAt?: number;
15
+ reportCount: number;
16
+ reactionCounts: Record<string, number>;
17
+ metadata: Record<string, unknown>;
18
+ createdAt: number;
19
+ updatedAt: number;
20
+ replies?: CommentItem[];
21
+ }
22
+ export interface PostCommentOptions {
23
+ content: string;
24
+ authorName?: string;
25
+ authorEmail?: string;
26
+ parentId?: string;
27
+ turnstileToken?: string;
28
+ metadata?: Record<string, unknown>;
29
+ }
30
+ export interface UseCommentsReturn {
31
+ comments: Ref<CommentItem[]>;
32
+ loading: Ref<boolean>;
33
+ error: Ref<Error | null>;
34
+ total: Ref<number>;
35
+ fetchComments: () => Promise<void>;
36
+ postComment: (input: PostCommentOptions) => Promise<CommentItem | null>;
37
+ deleteComment: (id: string) => Promise<boolean>;
38
+ reportComment: (id: string, reason: string, note?: string) => Promise<boolean>;
39
+ react: (id: string, reaction: string) => Promise<boolean>;
40
+ }
41
+ export declare function useComments(targetUrn: MaybeRefOrGetter<string>, options?: {
42
+ threaded?: boolean;
43
+ autoFetch?: boolean;
44
+ status?: string;
45
+ }): UseCommentsReturn;