qarpeo 0.1.18 → 0.1.21

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 (237) hide show
  1. package/README.md +96 -96
  2. package/dist/chunks/auth-schema.mjs +3 -1
  3. package/dist/chunks/wrangler.mjs +22 -3
  4. package/dist/cli/index.mjs +448 -221
  5. package/dist/fate/index.d.ts +29 -22
  6. package/dist/fate/index.mjs +1 -3
  7. package/dist/module.d.ts +1 -1
  8. package/dist/module.mjs +103 -82
  9. package/dist/runtime/ai.d.ts +2 -2
  10. package/dist/runtime/app/components/BlobImage.vue +119 -107
  11. package/dist/runtime/app/components/CMSBlocks.vue +104 -93
  12. package/dist/runtime/app/components/CMSContent.vue +24 -23
  13. package/dist/runtime/app/components/CMSImage.vue +49 -49
  14. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
  15. package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
  16. package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
  17. package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
  18. package/dist/runtime/app/components/ContentRenderer.vue +83 -80
  19. package/dist/runtime/app/components/FileUpload.vue +200 -196
  20. package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
  21. package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
  22. package/dist/runtime/app/components/SignedIn.vue +13 -13
  23. package/dist/runtime/app/components/SignedOut.vue +13 -13
  24. package/dist/runtime/app/components/shiki.css +34 -34
  25. package/dist/runtime/app/composables/ai.d.ts +22 -22
  26. package/dist/runtime/app/composables/ai.mjs +3 -7
  27. package/dist/runtime/app/composables/analytics.mjs +1 -1
  28. package/dist/runtime/app/composables/api-tokens.mjs +1 -1
  29. package/dist/runtime/app/composables/auth.d.ts +6 -7
  30. package/dist/runtime/app/composables/auth.mjs +6 -3
  31. package/dist/runtime/app/composables/chat.mjs +3 -7
  32. package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
  33. package/dist/runtime/app/composables/cms-preview.mjs +1 -1
  34. package/dist/runtime/app/composables/cms.d.ts +3 -5
  35. package/dist/runtime/app/composables/cms.mjs +2 -2
  36. package/dist/runtime/app/composables/docs-version.d.ts +8 -7
  37. package/dist/runtime/app/composables/docs-version.mjs +3 -3
  38. package/dist/runtime/app/composables/impersonation.mjs +1 -1
  39. package/dist/runtime/app/composables/notifications.d.ts +5 -5
  40. package/dist/runtime/app/composables/notifications.mjs +4 -5
  41. package/dist/runtime/app/composables/organization.mjs +1 -1
  42. package/dist/runtime/app/composables/passkey.mjs +1 -1
  43. package/dist/runtime/app/composables/passwordless.mjs +1 -1
  44. package/dist/runtime/app/composables/payments.d.ts +2 -1
  45. package/dist/runtime/app/composables/payments.mjs +1 -1
  46. package/dist/runtime/app/composables/realtime.d.ts +13 -13
  47. package/dist/runtime/app/composables/realtime.mjs +2 -2
  48. package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
  49. package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
  50. package/dist/runtime/app/composables/site.mjs +1 -1
  51. package/dist/runtime/app/composables/storage.d.ts +151 -11
  52. package/dist/runtime/app/composables/storage.mjs +291 -33
  53. package/dist/runtime/app/composables/turnstile.mjs +1 -1
  54. package/dist/runtime/app/composables/two-factor.mjs +1 -1
  55. package/dist/runtime/app/pages/devtools/agents.vue +716 -716
  56. package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
  57. package/dist/runtime/app/pages/devtools/auth.vue +381 -350
  58. package/dist/runtime/app/pages/devtools/blob.vue +743 -744
  59. package/dist/runtime/app/pages/devtools/db.vue +545 -545
  60. package/dist/runtime/app/pages/devtools/domains.vue +771 -771
  61. package/dist/runtime/app/pages/devtools/kv.vue +827 -828
  62. package/dist/runtime/app/pages/devtools/logs.vue +649 -653
  63. package/dist/runtime/app/pages/devtools/mail.vue +388 -388
  64. package/dist/runtime/app/pages/devtools/overview.vue +391 -389
  65. package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
  66. package/dist/runtime/app/pages/devtools/security.vue +20 -5
  67. package/dist/runtime/app/pages/devtools/settings.vue +559 -559
  68. package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
  69. package/dist/runtime/app/pages/devtools.vue +176 -176
  70. package/dist/runtime/app/plugins/seo.mjs +1 -1
  71. package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
  72. package/dist/runtime/app/public/sw-notifications.mjs +47 -52
  73. package/dist/runtime/blob.mjs +11 -4
  74. package/dist/runtime/browser.d.ts +1 -1
  75. package/dist/runtime/browser.mjs +12 -2
  76. package/dist/runtime/cache.d.ts +2 -1
  77. package/dist/runtime/kv.mjs +4 -1
  78. package/dist/runtime/providers/qarpeo.d.ts +3 -3
  79. package/dist/runtime/server/durable-objects/agent.mjs +1 -1
  80. package/dist/runtime/server/durable-objects/room.d.ts +2 -2
  81. package/dist/runtime/server/durable-objects/room.mjs +5 -5
  82. package/dist/runtime/server/middleware/devtools.mjs +6 -2
  83. package/dist/runtime/server/plugins/cms.d.ts +4 -2
  84. package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
  85. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
  86. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
  87. package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
  88. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
  89. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
  90. package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
  91. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
  92. package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
  93. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
  94. package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
  95. package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
  96. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
  97. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
  98. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
  99. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
  100. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
  101. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
  102. package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
  103. package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
  104. package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
  105. package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
  106. package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
  107. package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
  108. package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
  109. package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
  110. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
  111. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
  112. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
  113. package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
  114. package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
  115. package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
  116. package/dist/runtime/server/routes/auth/handler.mjs +6 -1
  117. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
  118. package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
  119. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
  120. package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
  121. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
  122. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
  123. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  124. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
  125. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
  126. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
  127. package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
  128. package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
  129. package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
  131. package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
  132. package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
  133. package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
  134. package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
  136. package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
  137. package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
  138. package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
  139. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
  140. package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
  141. package/dist/runtime/server/routes/fate.mjs +5 -8
  142. package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
  143. package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
  144. package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
  145. package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
  146. package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
  147. package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
  148. package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
  149. package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
  150. package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
  151. package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
  152. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  153. package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
  154. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
  155. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
  156. package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
  157. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
  158. package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
  159. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
  160. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
  161. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
  162. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
  163. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
  164. package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
  165. package/dist/runtime/server/utils/ai.d.ts +9 -9
  166. package/dist/runtime/server/utils/ai.mjs +3 -3
  167. package/dist/runtime/server/utils/auth.d.ts +12 -16
  168. package/dist/runtime/server/utils/auth.mjs +15 -9
  169. package/dist/runtime/server/utils/bots.mjs +21 -7
  170. package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
  171. package/dist/runtime/server/utils/browser-utils.mjs +14 -4
  172. package/dist/runtime/server/utils/cache.d.ts +5 -5
  173. package/dist/runtime/server/utils/cms/common.d.ts +26 -0
  174. package/dist/runtime/server/utils/cms/common.mjs +68 -0
  175. package/dist/runtime/server/utils/cms/git.d.ts +24 -0
  176. package/dist/runtime/server/utils/cms/git.mjs +240 -0
  177. package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
  178. package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
  179. package/dist/runtime/server/utils/cms/path.d.ts +51 -0
  180. package/dist/runtime/server/utils/cms/path.mjs +127 -0
  181. package/dist/runtime/server/utils/cms/search.d.ts +22 -0
  182. package/dist/runtime/server/utils/cms/search.mjs +221 -0
  183. package/dist/runtime/server/utils/cms-events.d.ts +1 -1
  184. package/dist/runtime/server/utils/cms-events.mjs +2 -2
  185. package/dist/runtime/server/utils/cms-filter.mjs +2 -2
  186. package/dist/runtime/server/utils/cms.d.ts +17 -149
  187. package/dist/runtime/server/utils/cms.mjs +52 -761
  188. package/dist/runtime/server/utils/config.d.ts +5 -4
  189. package/dist/runtime/server/utils/domains.mjs +7 -4
  190. package/dist/runtime/server/utils/email-templates.d.ts +10 -7
  191. package/dist/runtime/server/utils/email-templates.mjs +20 -5
  192. package/dist/runtime/server/utils/feed.d.ts +2 -2
  193. package/dist/runtime/server/utils/feed.mjs +3 -1
  194. package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
  195. package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
  196. package/dist/runtime/server/utils/mail.d.ts +7 -8
  197. package/dist/runtime/server/utils/mail.mjs +17 -12
  198. package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
  199. package/dist/runtime/server/utils/notifications.d.ts +9 -23
  200. package/dist/runtime/server/utils/organization.mjs +4 -12
  201. package/dist/runtime/server/utils/passwordless.mjs +1 -1
  202. package/dist/runtime/server/utils/payments.d.ts +2 -6
  203. package/dist/runtime/server/utils/payments.mjs +1 -1
  204. package/dist/runtime/server/utils/queue.d.ts +21 -31
  205. package/dist/runtime/server/utils/rag.d.ts +4 -4
  206. package/dist/runtime/server/utils/rag.mjs +8 -8
  207. package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
  208. package/dist/runtime/server/utils/realtime.d.ts +26 -28
  209. package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
  210. package/dist/runtime/server/utils/security-store.d.ts +2 -2
  211. package/dist/runtime/server/utils/session.d.ts +9 -11
  212. package/dist/runtime/server/utils/sso.d.ts +9 -15
  213. package/dist/runtime/server/utils/sso.mjs +4 -8
  214. package/dist/runtime/server/utils/storage.d.ts +19 -2
  215. package/dist/runtime/server/utils/storage.mjs +36 -7
  216. package/dist/runtime/server/utils/tenant.mjs +3 -1
  217. package/dist/runtime/server/utils/turnstile.d.ts +3 -5
  218. package/dist/runtime/server/utils/vapid.d.ts +5 -8
  219. package/dist/runtime/server/utils/vapid.mjs +26 -13
  220. package/dist/runtime/service.d.ts +13 -13
  221. package/dist/runtime/service.mjs +4 -2
  222. package/dist/runtime/test-utils.d.ts +20 -30
  223. package/dist/runtime/test-utils.mjs +5 -4
  224. package/dist/runtime/types/auth-globals.d.ts +14 -14
  225. package/dist/runtime/types/imports.d.ts +82 -82
  226. package/dist/runtime/types/index.d.ts +2 -2
  227. package/dist/runtime/types/r2.d.ts +5 -0
  228. package/dist/runtime/types/service.d.ts +11 -18
  229. package/dist/types.d.ts +100 -107
  230. package/dist/utils/auth-schema.d.ts +2 -2
  231. package/dist/utils/cms-sources.d.ts +3 -3
  232. package/dist/utils/local-db.d.ts +3 -3
  233. package/dist/utils/notifications-schema.d.ts +1 -3
  234. package/dist/utils/pkg.d.ts +7 -0
  235. package/dist/utils/queue.d.ts +3 -3
  236. package/dist/utils/tasks.d.ts +3 -2
  237. package/package.json +11 -8
@@ -1,196 +1,200 @@
1
- <script lang="ts" setup>
2
- import { ref, computed } from "vue"
3
- import { useUpload, type UploadedFile } from "../composables/storage"
4
-
5
- /**
6
- * `<FileUpload>` — Drag-and-drop file upload dropzone with progress and v-model support.
7
- * Supports custom slot for full UI control or uses a built-in dropzone UI.
8
- */
9
- const props = withDefaults(defineProps<{
10
- /** File types accepted (e.g. "image/*", ".pdf,.docx"). */
11
- accept?: string
12
- /** Allow multiple file selection. */
13
- multiple?: boolean
14
- /** Maximum file size allowed in bytes. */
15
- maxSize?: number
16
- /** Whether the dropzone is disabled. */
17
- disabled?: boolean
18
- /** Automatically trigger upload immediately on file selection. */
19
- autoUpload?: boolean
20
- /** Target upload endpoint URL (e.g. '/api/avatars'). Defaults to '/api/upload'. */
21
- url?: string
22
- /** Uploaded file(s) v-model. */
23
- modelValue?: UploadedFile | UploadedFile[] | null
24
- /** Additional CSS class for the wrapper container. */
25
- dropzoneClass?: string
26
- }>(), {
27
- url: "/api/upload",
28
- multiple: false,
29
- disabled: false,
30
- autoUpload: true,
31
- modelValue: null,
32
- dropzoneClass: "",
33
- })
34
-
35
- const emit = defineEmits<{
36
- "update:modelValue": [value: UploadedFile | UploadedFile[] | null]
37
- change: [files: File | File[]]
38
- upload: [files: File[]]
39
- success: [result: UploadedFile | UploadedFile[]]
40
- error: [err: Error]
41
- progress: [percent: number]
42
- }>()
43
-
44
- const inputRef = ref<HTMLInputElement | null>(null)
45
- const isDragging = ref(false)
46
- const clientError = ref<string | null>(null)
47
-
48
- const { isUploading, progress, error, upload, uploadMultiple, reset } = useUpload(() => props.url)
49
-
50
- function open() {
51
- if (props.disabled || isUploading.value) return
52
- inputRef.value?.click()
53
- }
54
-
55
- function clear() {
56
- reset()
57
- clientError.value = null
58
- if (inputRef.value) inputRef.value.value = ""
59
- emit("update:modelValue", props.multiple ? [] : null)
60
- }
61
-
62
- async function processFiles(files: FileList | File[]) {
63
- clientError.value = null
64
- const fileList = Array.from(files)
65
- if (fileList.length === 0) return
66
-
67
- if (props.maxSize) {
68
- const oversized = fileList.find((f) => f.size > props.maxSize!)
69
- if (oversized) {
70
- const maxMb = (props.maxSize / (1024 * 1024)).toFixed(1)
71
- const msg = `File "${oversized.name}" exceeds maximum size of ${maxMb}MB`
72
- clientError.value = msg
73
- emit("error", new Error(msg))
74
- return
75
- }
76
- }
77
-
78
- emit("change", props.multiple ? fileList : fileList[0]!)
79
- if (!props.autoUpload) return
80
- emit("upload", fileList)
81
-
82
- try {
83
- if (props.multiple) {
84
- const results = await uploadMultiple(fileList)
85
- emit("update:modelValue", results)
86
- emit("success", results)
87
- } else {
88
- const result = await upload(fileList[0]!)
89
- emit("update:modelValue", result)
90
- emit("success", result)
91
- }
92
- } catch (err: any) {
93
- clientError.value = err?.message || "Upload failed"
94
- emit("error", err)
95
- }
96
- }
97
-
98
- function onDrop(event: DragEvent) {
99
- event.preventDefault()
100
- isDragging.value = false
101
- if (props.disabled || isUploading.value) return
102
- if (event.dataTransfer?.files) processFiles(event.dataTransfer.files)
103
- }
104
-
105
- function onDragOver(event: DragEvent) {
106
- event.preventDefault()
107
- if (!props.disabled && !isUploading.value) isDragging.value = true
108
- }
109
-
110
- function onDragLeave(event: DragEvent) {
111
- event.preventDefault()
112
- isDragging.value = false
113
- }
114
-
115
- function onInputChange(event: Event) {
116
- const target = event.target as HTMLInputElement
117
- if (target.files) processFiles(target.files)
118
- }
119
-
120
- const displayError = computed(() => clientError.value || error.value?.message || null)
121
- </script>
122
-
123
- <template>
124
- <!-- Custom slot: users take full UI control -->
125
- <div
126
- v-if="$slots.default"
127
- :class="['qarpeo-file-upload', dropzoneClass]"
128
- @drop="onDrop"
129
- @dragover="onDragOver"
130
- @dragleave="onDragLeave"
131
- >
132
- <input
133
- ref="inputRef"
134
- type="file"
135
- :accept="accept"
136
- :multiple="multiple"
137
- class="hidden"
138
- @change="onInputChange"
139
- />
140
- <slot
141
- :is-dragging="isDragging"
142
- :is-uploading="isUploading"
143
- :progress="progress"
144
- :error="displayError"
145
- :open="open"
146
- :clear="clear"
147
- />
148
- </div>
149
-
150
- <!-- Built-in dropzone UI -->
151
- <div
152
- v-else
153
- class="qarpeo-file-upload-wrapper"
154
- @drop="onDrop"
155
- @dragover="onDragOver"
156
- @dragleave="onDragLeave"
157
- >
158
- <input
159
- ref="inputRef"
160
- type="file"
161
- :accept="accept"
162
- :multiple="multiple"
163
- class="hidden"
164
- @change="onInputChange"
165
- />
166
- <div
167
- :class="[
168
- 'rounded-lg border-2 border-dashed p-6 text-center transition-colors duration-200',
169
- isDragging
170
- ? 'border-primary-500 bg-primary-50/50 dark:bg-primary-950/20'
171
- : 'border-gray-300 dark:border-gray-700',
172
- disabled ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
173
- dropzoneClass,
174
- ]"
175
- @click="open"
176
- >
177
- <!-- Uploading state -->
178
- <div v-if="isUploading" class="space-y-2">
179
- <p class="text-sm text-gray-500">Uploading... {{ progress }}%</p>
180
- <UProgress :value="progress" size="xs" />
181
- </div>
182
-
183
- <!-- Idle / drag state -->
184
- <div v-else class="space-y-1">
185
- <UIcon name="i-lucide-upload-cloud" class="size-8 mx-auto text-gray-400" />
186
- <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
187
- {{ isDragging ? "Drop files to upload" : "Click or drag files here to upload" }}
188
- </p>
189
- <p v-if="accept" class="text-xs text-gray-400">Accepted: {{ accept }}</p>
190
- </div>
191
-
192
- <!-- Error -->
193
- <p v-if="displayError" class="mt-2 text-xs text-red-500">{{ displayError }}</p>
194
- </div>
195
- </div>
196
- </template>
1
+ <script lang="ts" setup>
2
+ import { ref, computed } from "vue"
3
+
4
+ import { useUpload, type UploadedFile } from "../composables/storage"
5
+
6
+ /**
7
+ * `<FileUpload>` — Drag-and-drop file upload dropzone with progress and v-model support. Supports
8
+ * custom slot for full UI control or uses a built-in dropzone UI.
9
+ */
10
+ const props = withDefaults(
11
+ defineProps<{
12
+ /** File types accepted (e.g. "image/*", ".pdf,.docx"). */
13
+ accept?: string
14
+ /** Allow multiple file selection. */
15
+ multiple?: boolean
16
+ /** Maximum file size allowed in bytes. */
17
+ maxSize?: number
18
+ /** Whether the dropzone is disabled. */
19
+ disabled?: boolean
20
+ /** Automatically trigger upload immediately on file selection. */
21
+ autoUpload?: boolean
22
+ /** Target upload endpoint URL (e.g. '/api/avatars'). Defaults to '/api/upload'. */
23
+ url?: string
24
+ /** Uploaded file(s) v-model. */
25
+ modelValue?: UploadedFile | UploadedFile[] | null
26
+ /** Additional CSS class for the wrapper container. */
27
+ dropzoneClass?: string
28
+ }>(),
29
+ {
30
+ url: "/api/upload",
31
+ multiple: false,
32
+ disabled: false,
33
+ autoUpload: true,
34
+ modelValue: null,
35
+ dropzoneClass: "",
36
+ },
37
+ )
38
+
39
+ const emit = defineEmits<{
40
+ "update:modelValue": [value: UploadedFile | UploadedFile[] | null]
41
+ change: [files: File | File[]]
42
+ upload: [files: File[]]
43
+ success: [result: UploadedFile | UploadedFile[]]
44
+ error: [err: Error]
45
+ progress: [percent: number]
46
+ }>()
47
+
48
+ const inputRef = ref<HTMLInputElement | null>(null)
49
+ const isDragging = ref(false)
50
+ const clientError = ref<string | null>(null)
51
+
52
+ const { isUploading, progress, error, upload, uploadMultiple, reset } = useUpload(() => props.url)
53
+
54
+ function open() {
55
+ if (props.disabled || isUploading.value) return
56
+ inputRef.value?.click()
57
+ }
58
+
59
+ function clear() {
60
+ reset()
61
+ clientError.value = null
62
+ if (inputRef.value) inputRef.value.value = ""
63
+ emit("update:modelValue", props.multiple ? [] : null)
64
+ }
65
+
66
+ async function processFiles(files: FileList | File[]) {
67
+ clientError.value = null
68
+ const fileList = Array.from(files)
69
+ if (fileList.length === 0) return
70
+
71
+ if (props.maxSize) {
72
+ const oversized = fileList.find((f) => f.size > props.maxSize!)
73
+ if (oversized) {
74
+ const maxMb = (props.maxSize / (1024 * 1024)).toFixed(1)
75
+ const msg = `File "${oversized.name}" exceeds maximum size of ${maxMb}MB`
76
+ clientError.value = msg
77
+ emit("error", new Error(msg))
78
+ return
79
+ }
80
+ }
81
+
82
+ emit("change", props.multiple ? fileList : fileList[0]!)
83
+ if (!props.autoUpload) return
84
+ emit("upload", fileList)
85
+
86
+ try {
87
+ if (props.multiple) {
88
+ const results = await uploadMultiple(fileList)
89
+ emit("update:modelValue", results)
90
+ emit("success", results)
91
+ } else {
92
+ const result = await upload(fileList[0]!)
93
+ emit("update:modelValue", result)
94
+ emit("success", result)
95
+ }
96
+ } catch (err: any) {
97
+ clientError.value = err?.message || "Upload failed"
98
+ emit("error", err)
99
+ }
100
+ }
101
+
102
+ function onDrop(event: DragEvent) {
103
+ event.preventDefault()
104
+ isDragging.value = false
105
+ if (props.disabled || isUploading.value) return
106
+ if (event.dataTransfer?.files) processFiles(event.dataTransfer.files)
107
+ }
108
+
109
+ function onDragOver(event: DragEvent) {
110
+ event.preventDefault()
111
+ if (!props.disabled && !isUploading.value) isDragging.value = true
112
+ }
113
+
114
+ function onDragLeave(event: DragEvent) {
115
+ event.preventDefault()
116
+ isDragging.value = false
117
+ }
118
+
119
+ function onInputChange(event: Event) {
120
+ const target = event.target as HTMLInputElement
121
+ if (target.files) processFiles(target.files)
122
+ }
123
+
124
+ const displayError = computed(() => clientError.value || error.value?.message || null)
125
+ </script>
126
+
127
+ <template>
128
+ <!-- Custom slot: users take full UI control -->
129
+ <div
130
+ v-if="$slots.default"
131
+ :class="['qarpeo-file-upload', dropzoneClass]"
132
+ @drop="onDrop"
133
+ @dragover="onDragOver"
134
+ @dragleave="onDragLeave"
135
+ >
136
+ <input
137
+ ref="inputRef"
138
+ type="file"
139
+ :accept="accept"
140
+ :multiple="multiple"
141
+ class="hidden"
142
+ @change="onInputChange"
143
+ />
144
+ <slot
145
+ :is-dragging="isDragging"
146
+ :is-uploading="isUploading"
147
+ :progress="progress"
148
+ :error="displayError"
149
+ :open="open"
150
+ :clear="clear"
151
+ />
152
+ </div>
153
+
154
+ <!-- Built-in dropzone UI -->
155
+ <div
156
+ v-else
157
+ class="qarpeo-file-upload-wrapper"
158
+ @drop="onDrop"
159
+ @dragover="onDragOver"
160
+ @dragleave="onDragLeave"
161
+ >
162
+ <input
163
+ ref="inputRef"
164
+ type="file"
165
+ :accept="accept"
166
+ :multiple="multiple"
167
+ class="hidden"
168
+ @change="onInputChange"
169
+ />
170
+ <div
171
+ :class="[
172
+ 'rounded-lg border-2 border-dashed p-6 text-center transition-colors duration-200',
173
+ isDragging
174
+ ? 'border-primary-500 bg-primary-50/50 dark:bg-primary-950/20'
175
+ : 'border-gray-300 dark:border-gray-700',
176
+ disabled ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
177
+ dropzoneClass,
178
+ ]"
179
+ @click="open"
180
+ >
181
+ <!-- Uploading state -->
182
+ <div v-if="isUploading" class="space-y-2">
183
+ <p class="text-sm text-gray-500">Uploading... {{ progress }}%</p>
184
+ <UProgress :value="progress" size="xs" />
185
+ </div>
186
+
187
+ <!-- Idle / drag state -->
188
+ <div v-else class="space-y-1">
189
+ <UIcon name="i-lucide-upload-cloud" class="size-8 mx-auto text-gray-400" />
190
+ <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
191
+ {{ isDragging ? "Drop files to upload" : "Click or drag files here to upload" }}
192
+ </p>
193
+ <p v-if="accept" class="text-xs text-gray-400">Accepted: {{ accept }}</p>
194
+ </div>
195
+
196
+ <!-- Error -->
197
+ <p v-if="displayError" class="mt-2 text-xs text-red-500">{{ displayError }}</p>
198
+ </div>
199
+ </div>
200
+ </template>
@@ -1,57 +1,61 @@
1
- <script lang="ts" setup>
2
- import { computed } from "vue"
3
- import { useUserSession } from "../composables/auth"
4
- import type { QarpeoUser, QarpeoSession } from "../../types/auth"
5
-
6
- /**
7
- * `<ImpersonationBanner>` Renders a dismissible banner when an admin is actively impersonating a
8
- * user. Shows who is being impersonated and provides a "Stop Impersonating" button.
9
- * Auto-hides when not in an impersonation session.
10
- * @emits stopped — when impersonation is stopped successfully
11
- */
12
- const emit = defineEmits<{ stopped: [] }>()
13
-
14
- const { session, fetch: refreshSession } = useUserSession()
15
-
16
- const isImpersonating = computed(() => Boolean((session.value as QarpeoSession | null)?.impersonator))
17
- const impersonator = computed<QarpeoUser | null>(
18
- () => ((session.value as QarpeoSession | null)?.impersonator as QarpeoUser) || null,
19
- )
20
- const impersonated = computed<QarpeoUser | null>(() => {
21
- if (!isImpersonating.value) return null
22
- return ((session.value as QarpeoSession | null)?.user as QarpeoUser) || null
23
- })
24
-
25
- async function stopImpersonating() {
26
- try {
27
- await $fetch("/api/auth/impersonate/stop", { method: "POST", credentials: "include" })
28
- await refreshSession()
29
- emit("stopped")
30
- } catch {}
31
- }
32
- </script>
33
-
34
- <template>
35
- <Teleport to="body">
36
- <div
37
- v-if="isImpersonating"
38
- class="fixed top-0 left-0 right-0 z-[9999] flex items-center justify-between gap-4 bg-amber-700 text-white px-4 py-2 text-sm font-sans"
39
- >
40
- <span>
41
- ⚠ Admin
42
- <strong>{{ impersonator?.email || impersonator?.name || "Unknown" }}</strong>
43
- is impersonating
44
- <strong>{{ impersonated?.email || impersonated?.name || "Unknown" }}</strong>
45
- </span>
46
- <UButton
47
- color="neutral"
48
- variant="outline"
49
- size="xs"
50
- class="border-white/50 text-white hover:bg-white/20"
51
- @click="stopImpersonating"
52
- >
53
- Stop Impersonating
54
- </UButton>
55
- </div>
56
- </Teleport>
57
- </template>
1
+ <script lang="ts" setup>
2
+ import { computed } from "vue"
3
+
4
+ import type { QarpeoUser, QarpeoSession } from "../../types/auth"
5
+ import { useUserSession } from "../composables/auth"
6
+
7
+ /**
8
+ * `<ImpersonationBanner>` Renders a dismissible banner when an admin is actively impersonating a
9
+ * user. Shows who is being impersonated and provides a "Stop Impersonating" button. Auto-hides when
10
+ * not in an impersonation session.
11
+ *
12
+ * @fires stopped — when impersonation is stopped successfully
13
+ */
14
+ const emit = defineEmits<{ stopped: [] }>()
15
+
16
+ const { session, fetch: refreshSession } = useUserSession()
17
+
18
+ const isImpersonating = computed(() =>
19
+ Boolean((session.value as QarpeoSession | null)?.impersonator),
20
+ )
21
+ const impersonator = computed<QarpeoUser | null>(
22
+ () => ((session.value as QarpeoSession | null)?.impersonator as QarpeoUser) || null,
23
+ )
24
+ const impersonated = computed<QarpeoUser | null>(() => {
25
+ if (!isImpersonating.value) return null
26
+ return ((session.value as QarpeoSession | null)?.user as QarpeoUser) || null
27
+ })
28
+
29
+ async function stopImpersonating() {
30
+ try {
31
+ await $fetch("/api/auth/impersonate/stop", { method: "POST", credentials: "include" })
32
+ await refreshSession()
33
+ emit("stopped")
34
+ } catch {}
35
+ }
36
+ </script>
37
+
38
+ <template>
39
+ <Teleport to="body">
40
+ <div
41
+ v-if="isImpersonating"
42
+ class="fixed top-0 left-0 right-0 z-[9999] flex items-center justify-between gap-4 bg-amber-700 text-white px-4 py-2 text-sm font-sans"
43
+ >
44
+ <span>
45
+ ⚠ Admin
46
+ <strong>{{ impersonator?.email || impersonator?.name || "Unknown" }}</strong>
47
+ is impersonating
48
+ <strong>{{ impersonated?.email || impersonated?.name || "Unknown" }}</strong>
49
+ </span>
50
+ <UButton
51
+ color="neutral"
52
+ variant="outline"
53
+ size="xs"
54
+ class="border-white/50 text-white hover:bg-white/20"
55
+ @click="stopImpersonating"
56
+ >
57
+ Stop Impersonating
58
+ </UButton>
59
+ </div>
60
+ </Teleport>
61
+ </template>