@hartl-services/medusa-base 0.4.0 → 1.1.0

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 (258) hide show
  1. package/.medusa/server/src/admin/index.js +1657 -111
  2. package/.medusa/server/src/admin/index.mjs +1647 -101
  3. package/.medusa/server/src/api/admin/email/messages/[id]/resends/route.js +24 -0
  4. package/.medusa/server/src/api/admin/email/messages/[id]/route.js +12 -0
  5. package/.medusa/server/src/api/admin/email/messages/route.js +12 -0
  6. package/.medusa/server/src/api/admin/email/terms-versions/[id]/download/route.js +16 -0
  7. package/.medusa/server/src/api/admin/email/terms-versions/route.js +47 -0
  8. package/.medusa/server/src/api/admin/orders/[id]/documents/[document_id]/download/route.js +21 -0
  9. package/.medusa/server/src/api/admin/orders/[id]/documents/[document_id]/regenerate/route.js +38 -0
  10. package/.medusa/server/src/api/admin/orders/[id]/documents/regenerate/route.js +32 -0
  11. package/.medusa/server/src/api/admin/orders/[id]/documents/route.js +36 -0
  12. package/.medusa/server/src/api/admin/orders/[id]/packing-lists/[fulfillment_id]/download/route.js +24 -0
  13. package/.medusa/server/src/api/admin/orders/[id]/packing-lists/[fulfillment_id]/retry/route.js +44 -0
  14. package/.medusa/server/src/api/admin/orders/[id]/packing-lists/route.js +82 -0
  15. package/.medusa/server/src/api/document-download-response.js +16 -0
  16. package/.medusa/server/src/api/document-response.js +23 -0
  17. package/.medusa/server/src/api/files/[asset]/route.js +24 -0
  18. package/.medusa/server/src/api/files/file-response.js +43 -0
  19. package/.medusa/server/src/api/files/gateway-options.js +31 -0
  20. package/.medusa/server/src/api/files/private/[token]/route.js +29 -0
  21. package/.medusa/server/src/api/files/upload/[token]/route.js +66 -0
  22. package/.medusa/server/src/api/middlewares.js +168 -1
  23. package/.medusa/server/src/api/packing-list-response.js +22 -0
  24. package/.medusa/server/src/api/route.js +27 -0
  25. package/.medusa/server/src/api/store/documents/[id]/download/route.js +21 -0
  26. package/.medusa/server/src/api/store/documents/[id]/route.js +15 -0
  27. package/.medusa/server/src/api/store/documents/route.js +11 -0
  28. package/.medusa/server/src/api/terms-download-response.js +12 -0
  29. package/.medusa/server/src/documents/config/index.js +18 -0
  30. package/.medusa/server/src/documents/paths/documents.js +6 -0
  31. package/.medusa/server/src/documents/paths/index.js +18 -0
  32. package/.medusa/server/src/documents/plugin-features.js +38 -0
  33. package/.medusa/server/src/documents/schemas/documents.js +18 -0
  34. package/.medusa/server/src/documents/schemas/index.js +18 -0
  35. package/.medusa/server/src/documents/scripts/verify-documents-file-storage.js +55 -0
  36. package/.medusa/server/src/documents/templates/financial-document.js +160 -0
  37. package/.medusa/server/src/documents/templates/format.js +73 -0
  38. package/.medusa/server/src/documents/templates/html-factory.js +42 -0
  39. package/.medusa/server/src/documents/templates/html-utils.js +23 -0
  40. package/.medusa/server/src/documents/templates/layout.js +142 -0
  41. package/.medusa/server/src/documents/templates/packing-list.js +52 -0
  42. package/.medusa/server/src/documents/types/admin-api.js +3 -0
  43. package/.medusa/server/src/documents/types/document-summary.js +3 -0
  44. package/.medusa/server/src/documents/types/documents.js +3 -0
  45. package/.medusa/server/src/documents/types/html-factory.js +6 -0
  46. package/.medusa/server/src/documents/types/index.js +22 -0
  47. package/.medusa/server/src/documents/types/store-api.js +3 -0
  48. package/.medusa/server/src/documents/utils/document-merchant.js +22 -0
  49. package/.medusa/server/src/documents/utils/document-render-settings.js +59 -0
  50. package/.medusa/server/src/documents/utils/html-to-pdf.js +61 -0
  51. package/.medusa/server/src/documents/utils/private-file-storage.js +64 -0
  52. package/.medusa/server/src/documents/utils/resolve-services.js +7 -0
  53. package/.medusa/server/src/email/application/handle-invite-event.js +318 -0
  54. package/.medusa/server/src/email/application/handle-password-reset-event.js +366 -0
  55. package/.medusa/server/src/email/config/index.js +84 -0
  56. package/.medusa/server/src/email/config/notification-module.js +20 -0
  57. package/.medusa/server/src/email/domain/business-keys.js +50 -0
  58. package/.medusa/server/src/email/domain/documents-fact-fingerprint.js +7 -0
  59. package/.medusa/server/src/email/domain/event-schemas.js +36 -0
  60. package/.medusa/server/src/email/domain/failure-classification.js +53 -0
  61. package/.medusa/server/src/email/domain/order-summary.js +103 -0
  62. package/.medusa/server/src/email/domain/refund-summary.js +43 -0
  63. package/.medusa/server/src/email/domain/return-summary.js +118 -0
  64. package/.medusa/server/src/email/domain/shipment-summary.js +74 -0
  65. package/.medusa/server/src/email/plugin-features.js +39 -0
  66. package/.medusa/server/src/email/rendering/default-templates.js +719 -0
  67. package/.medusa/server/src/email/rendering/load-email-shop-details.js +36 -0
  68. package/.medusa/server/src/email/rendering/render-email.js +50 -0
  69. package/.medusa/server/src/email/rendering/resolve-shop-configuration.js +67 -0
  70. package/.medusa/server/src/email/types/email-kinds.js +18 -0
  71. package/.medusa/server/src/email/types/index.js +21 -0
  72. package/.medusa/server/src/email/types/shop-configuration.js +3 -0
  73. package/.medusa/server/src/email/types/smtp-configuration.js +3 -0
  74. package/.medusa/server/src/email/types/template-data.js +232 -0
  75. package/.medusa/server/src/files/config/index.js +256 -0
  76. package/.medusa/server/src/files/gateway/index.js +115 -0
  77. package/.medusa/server/src/files/types/index.js +6 -0
  78. package/.medusa/server/src/files/types/public.js +6 -0
  79. package/.medusa/server/src/jobs/document-fact-publication-reconciliation.js +18 -0
  80. package/.medusa/server/src/jobs/document-resolution-reconciliation.js +20 -0
  81. package/.medusa/server/src/jobs/packing-list-reconciliation.js +49 -0
  82. package/.medusa/server/src/jobs/reconcile-email-attempts.js +63 -0
  83. package/.medusa/server/src/jobs/reconcile-pending-email-messages.js +41 -0
  84. package/.medusa/server/src/jobs/retry-email-messages.js +27 -0
  85. package/.medusa/server/src/migration-scripts/dismiss-orphaned-cart-promotion-links.js +26 -0
  86. package/.medusa/server/src/modules/documents/domain/cancellation-snapshot.js +97 -0
  87. package/.medusa/server/src/modules/documents/domain/document-number.js +36 -0
  88. package/.medusa/server/src/modules/documents/domain/document-resolution.js +24 -0
  89. package/.medusa/server/src/modules/documents/domain/issuance-rules.js +37 -0
  90. package/.medusa/server/src/modules/documents/domain/merchant.js +86 -0
  91. package/.medusa/server/src/modules/documents/domain/options.js +40 -0
  92. package/.medusa/server/src/modules/documents/domain/packing-list.js +90 -0
  93. package/.medusa/server/src/modules/documents/domain/snapshot-normalization.js +17 -0
  94. package/.medusa/server/src/modules/documents/domain/tax-breakdown.js +66 -0
  95. package/.medusa/server/src/modules/documents/index.js +15 -0
  96. package/.medusa/server/src/modules/documents/loaders/assert-private-file-storage.js +20 -0
  97. package/.medusa/server/src/modules/documents/migrations/Migration20260827061749.js +75 -0
  98. package/.medusa/server/src/modules/documents/migrations/Migration20260830111207.js +28 -0
  99. package/.medusa/server/src/modules/documents/models/document-artifact.js +25 -0
  100. package/.medusa/server/src/modules/documents/models/document-number-sequence.js +29 -0
  101. package/.medusa/server/src/modules/documents/models/document.js +82 -0
  102. package/.medusa/server/src/modules/documents/models/order-cancellation-resolution.js +51 -0
  103. package/.medusa/server/src/modules/documents/models/packing-list-revision.js +36 -0
  104. package/.medusa/server/src/modules/documents/models/packing-list.js +27 -0
  105. package/.medusa/server/src/modules/documents/models/refund-document-resolution.js +66 -0
  106. package/.medusa/server/src/modules/documents/models/shipment-invoice-assignment.js +51 -0
  107. package/.medusa/server/src/modules/documents/models/shipment-invoice-coordinator.js +44 -0
  108. package/.medusa/server/src/modules/documents/service.js +1701 -0
  109. package/.medusa/server/src/modules/email/domain/attachment.js +25 -0
  110. package/.medusa/server/src/modules/email/domain/message-state.js +69 -0
  111. package/.medusa/server/src/modules/email/index.js +13 -0
  112. package/.medusa/server/src/modules/email/migrations/Migration20260826173422.js +32 -0
  113. package/.medusa/server/src/modules/email/migrations/Migration20260827172945.js +16 -0
  114. package/.medusa/server/src/modules/email/migrations/Migration20260827194804.js +22 -0
  115. package/.medusa/server/src/modules/email/migrations/Migration20260906195205.js +16 -0
  116. package/.medusa/server/src/modules/email/models/email-attempt.js +56 -0
  117. package/.medusa/server/src/modules/email/models/email-message.js +71 -0
  118. package/.medusa/server/src/modules/email/models/email-terms-version.js +37 -0
  119. package/.medusa/server/src/modules/email/service.js +1285 -0
  120. package/.medusa/server/src/modules/plugin-features/domain/plugin-settings.js +4 -3
  121. package/.medusa/server/src/providers/s3-cache/cache/atomic-write.js +25 -0
  122. package/.medusa/server/src/providers/s3-cache/cache/cache-manager.js +115 -0
  123. package/.medusa/server/src/providers/s3-cache/cache/keyed-lock.js +28 -0
  124. package/.medusa/server/src/providers/s3-cache/index.js +8 -0
  125. package/.medusa/server/src/providers/s3-cache/object-key.js +53 -0
  126. package/.medusa/server/src/providers/s3-cache/s3-cache-file.js +229 -0
  127. package/.medusa/server/src/providers/s3-cache/s3-object-store.js +86 -0
  128. package/.medusa/server/src/providers/smtp/index.js +8 -0
  129. package/.medusa/server/src/providers/smtp/service.js +236 -0
  130. package/.medusa/server/src/providers/smtp/types.js +11 -0
  131. package/.medusa/server/src/public/config.js +186 -0
  132. package/.medusa/server/src/public/descriptor.js +3 -1
  133. package/.medusa/server/src/public/gateway.js +19 -0
  134. package/.medusa/server/src/public/instrumentation.js +56 -0
  135. package/.medusa/server/src/public/shop-config.js +12 -0
  136. package/.medusa/server/src/public/shop-master-data.js +2 -2
  137. package/.medusa/server/src/public/shop-types.js +24 -0
  138. package/.medusa/server/src/shop-config/build-food-shop-config.js +252 -0
  139. package/.medusa/server/src/shop-config/options.js +75 -0
  140. package/.medusa/server/src/subscribers/affiliate-consignment-reminder-due.js +26 -0
  141. package/.medusa/server/src/subscribers/documents-order-canceled.js +24 -0
  142. package/.medusa/server/src/subscribers/documents-order-cancellation-ready.js +26 -0
  143. package/.medusa/server/src/subscribers/documents-refund-ready.js +24 -0
  144. package/.medusa/server/src/subscribers/documents-shipment-created.js +36 -0
  145. package/.medusa/server/src/subscribers/documents-shipment-invoice-assignment-decided.js +26 -0
  146. package/.medusa/server/src/subscribers/email-order-canceled.js +28 -0
  147. package/.medusa/server/src/subscribers/email-shipment-created.js +32 -0
  148. package/.medusa/server/src/subscribers/order-placed.js +27 -0
  149. package/.medusa/server/src/subscribers/packing-list-allocation-revised.js +32 -0
  150. package/.medusa/server/src/subscribers/packing-list-fulfillment-canceled.js +54 -0
  151. package/.medusa/server/src/subscribers/packing-list-fulfillment-created.js +31 -0
  152. package/.medusa/server/src/subscribers/password-reset.js +23 -0
  153. package/.medusa/server/src/subscribers/payment-refunded.js +38 -0
  154. package/.medusa/server/src/subscribers/return-received.js +27 -0
  155. package/.medusa/server/src/subscribers/return-requested.js +27 -0
  156. package/.medusa/server/src/subscribers/user-invite.js +23 -0
  157. package/.medusa/server/src/utils/cart-promotion-links.js +101 -0
  158. package/.medusa/server/src/workflows/documents/issue-cancellation-after-refund.js +246 -0
  159. package/.medusa/server/src/workflows/documents/issue-document.js +165 -0
  160. package/.medusa/server/src/workflows/documents/issue-invoice-after-shipment.js +521 -0
  161. package/.medusa/server/src/workflows/documents/issue-packing-list.js +390 -0
  162. package/.medusa/server/src/workflows/documents/publish-document-facts.js +53 -0
  163. package/.medusa/server/src/workflows/documents/reconcile-document-resolutions.js +48 -0
  164. package/.medusa/server/src/workflows/documents/reconcile-order-cancellation.js +92 -0
  165. package/.medusa/server/src/workflows/documents/regenerate-issued-document.js +61 -0
  166. package/.medusa/server/src/workflows/email/dispatch-email-message.js +301 -0
  167. package/.medusa/server/src/workflows/email/documents-required-facts.js +30 -0
  168. package/.medusa/server/src/workflows/email/prepare-affiliate-reminder-email.js +58 -0
  169. package/.medusa/server/src/workflows/email/prepare-order-canceled-email.js +102 -0
  170. package/.medusa/server/src/workflows/email/prepare-order-received-email.js +82 -0
  171. package/.medusa/server/src/workflows/email/prepare-refund-email.js +71 -0
  172. package/.medusa/server/src/workflows/email/prepare-return-email.js +136 -0
  173. package/.medusa/server/src/workflows/email/prepare-shipment-email.js +115 -0
  174. package/.medusa/server/src/workflows/email/retry-email-messages.js +31 -0
  175. package/.medusa/server/src/workflows/hooks/dismiss-deleted-promotion-cart-links.js +23 -0
  176. package/README.md +1777 -8
  177. package/dist/admin-components/features/plugin-features/components/ImageSettingInput.d.ts +15 -0
  178. package/dist/admin-components/features/plugin-features/components/ImageSettingInput.js +42 -0
  179. package/dist/admin-components/features/plugin-features/components/PluginSettingsForm.js +4 -2
  180. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatureEnabled.d.ts +1 -1
  181. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatures.d.ts +4 -4
  182. package/dist/admin-components/features/plugin-features/hooks/usePluginSettingsForm.d.ts +1 -1
  183. package/dist/admin-components/features/plugin-features/lib/image-upload.d.ts +6 -0
  184. package/dist/admin-components/features/plugin-features/lib/image-upload.js +17 -0
  185. package/dist/admin-components/features/plugin-features/lib/plugin-features-admin-client.d.ts +4 -4
  186. package/dist/admin-components/i18n/texts.d.ts +6 -0
  187. package/dist/admin-components/i18n/texts.js +6 -0
  188. package/dist/documents/config/index.d.ts +11 -0
  189. package/dist/documents/config/index.js +17 -0
  190. package/dist/documents/templates/financial-document.d.ts +3 -0
  191. package/dist/documents/templates/financial-document.js +159 -0
  192. package/dist/documents/templates/format.d.ts +30 -0
  193. package/dist/documents/templates/format.js +72 -0
  194. package/dist/documents/templates/html-factory.d.ts +15 -0
  195. package/dist/documents/templates/html-factory.js +41 -0
  196. package/dist/documents/templates/html-utils.d.ts +8 -0
  197. package/dist/documents/templates/html-utils.js +22 -0
  198. package/dist/documents/templates/layout.d.ts +35 -0
  199. package/dist/documents/templates/layout.js +141 -0
  200. package/dist/documents/templates/packing-list.d.ts +3 -0
  201. package/dist/documents/templates/packing-list.js +51 -0
  202. package/dist/documents/types/admin-api.d.ts +1 -0
  203. package/dist/documents/types/admin-api.js +2 -0
  204. package/dist/documents/types/document-summary.d.ts +1 -0
  205. package/dist/documents/types/document-summary.js +2 -0
  206. package/dist/documents/types/documents.d.ts +191 -0
  207. package/dist/documents/types/documents.js +2 -0
  208. package/dist/documents/types/html-factory.d.ts +8 -0
  209. package/dist/documents/types/html-factory.js +5 -0
  210. package/dist/documents/types/index.d.ts +5 -0
  211. package/dist/documents/types/index.js +21 -0
  212. package/dist/documents/types/store-api.d.ts +1 -0
  213. package/dist/documents/types/store-api.js +2 -0
  214. package/dist/email/config/index.d.ts +17 -0
  215. package/dist/email/config/index.js +83 -0
  216. package/dist/email/config/notification-module.d.ts +22 -0
  217. package/dist/email/config/notification-module.js +19 -0
  218. package/dist/email/types/email-kinds.d.ts +15 -0
  219. package/dist/email/types/email-kinds.js +17 -0
  220. package/dist/email/types/index.d.ts +4 -0
  221. package/dist/email/types/index.js +20 -0
  222. package/dist/email/types/shop-configuration.d.ts +68 -0
  223. package/dist/email/types/shop-configuration.js +2 -0
  224. package/dist/email/types/smtp-configuration.d.ts +9 -0
  225. package/dist/email/types/smtp-configuration.js +2 -0
  226. package/dist/email/types/template-data.d.ts +609 -0
  227. package/dist/email/types/template-data.js +231 -0
  228. package/dist/files/config/index.d.ts +32 -0
  229. package/dist/files/config/index.js +255 -0
  230. package/dist/files/gateway/index.d.ts +30 -0
  231. package/dist/files/gateway/index.js +114 -0
  232. package/dist/files/types/index.d.ts +2 -0
  233. package/dist/files/types/index.js +5 -0
  234. package/dist/files/types/public.d.ts +90 -0
  235. package/dist/files/types/public.js +5 -0
  236. package/dist/modules/documents/domain/merchant.d.ts +22 -0
  237. package/dist/modules/documents/domain/merchant.js +85 -0
  238. package/dist/modules/documents/domain/options.d.ts +34 -0
  239. package/dist/modules/documents/domain/options.js +39 -0
  240. package/dist/public/config.d.ts +59 -0
  241. package/dist/public/config.js +185 -0
  242. package/dist/public/descriptor.js +2 -0
  243. package/dist/public/gateway.d.ts +2 -0
  244. package/dist/public/gateway.js +18 -0
  245. package/dist/public/instrumentation.d.ts +12 -0
  246. package/dist/public/instrumentation.js +55 -0
  247. package/dist/public/shop-config.d.ts +8 -0
  248. package/dist/public/shop-config.js +11 -0
  249. package/dist/public/shop-master-data.d.ts +1 -1
  250. package/dist/public/shop-master-data.js +1 -1
  251. package/dist/public/shop-types.d.ts +7 -0
  252. package/dist/public/shop-types.js +23 -0
  253. package/dist/public/types.d.ts +19 -2
  254. package/dist/shop-config/build-food-shop-config.d.ts +44 -0
  255. package/dist/shop-config/build-food-shop-config.js +251 -0
  256. package/dist/shop-config/options.d.ts +48 -0
  257. package/dist/shop-config/options.js +74 -0
  258. package/package.json +48 -5
@@ -1,11 +1,14 @@
1
- import { defineRouteConfig } from "@medusajs/admin-sdk";
2
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
3
- import { toast, Container, Heading, Text, Alert, Button, Label, Switch, Input, Select, Hint, StatusBadge, usePrompt } from "@medusajs/ui";
2
+ import { useState, useEffect, useMemo, useRef } from "react";
3
+ import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
4
+ import { toast, Button, Text, Hint, Container, Heading, Alert, Label, Switch, Input, Select, StatusBadge, usePrompt, FocusModal, Prompt } from "@medusajs/ui";
4
5
  import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
5
- import { pluginFeaturesAdminPaths } from "@hartl-services/medusa-food-supplements-contracts/paths/plugin-features";
6
+ import { documentsPaths, packingListsPaths } from "@hartl-services/medusa-food-supplements-contracts/paths/documents";
6
7
  import Medusa from "@medusajs/js-sdk";
7
8
  import { Link, useParams } from "react-router-dom";
8
- import { useState, useEffect, useMemo, useRef } from "react";
9
+ import { pluginFeaturesAdminPaths } from "@hartl-services/medusa-food-supplements-contracts/paths/plugin-features";
10
+ import { emailAdminPaths } from "@hartl-services/medusa-food-supplements-contracts/paths/email";
11
+ import { EMAIL_TERMS_MAX_PDF_BYTES } from "@hartl-services/medusa-food-supplements-contracts/schemas/email";
9
12
  const texts = {
10
13
  menu: {
11
14
  label: "Hartl Services Plugins"
@@ -45,6 +48,11 @@ const texts = {
45
48
  parentDisabled: (parentLabel) => `Inaktiv, solange „${parentLabel}“ ausgeschaltet ist.`,
46
49
  saving: "Wird gespeichert…"
47
50
  },
51
+ gate: {
52
+ disabled: "Diese Funktion ist unter Einstellungen → Hartl Services Plugins ausgeschaltet.",
53
+ disabledNamed: (label) => `„${label}“ ist unter Einstellungen → Hartl Services Plugins ausgeschaltet.`,
54
+ openHub: "Zu Hartl Services Plugins"
55
+ },
48
56
  settings: {
49
57
  missing: (labels) => `Nicht konfiguriert: ${labels}`,
50
58
  save: "Einstellungen speichern",
@@ -62,6 +70,12 @@ const texts = {
62
70
  numberMax: (max) => `Höchstens ${max}.`,
63
71
  numberRange: (min, max) => `Zwischen ${min} und ${max}.`,
64
72
  selectPlaceholder: "Bitte auswählen",
73
+ imageUpload: "Bild hochladen",
74
+ imageReplace: "Anderes Bild hochladen",
75
+ imageRemove: "Entfernen",
76
+ imageNone: "Kein Bild hinterlegt",
77
+ imageUploadFailed: "Das Bild konnte nicht hochgeladen werden.",
78
+ imagePreviewAlt: (label) => `Vorschau ${label}`,
65
79
  clearHint: "Ein leeres Feld speichern entfernt den gespeicherten Wert (dann gilt Konfiguration oder Standard).",
66
80
  source: {
67
81
  stored: "gespeichert",
@@ -372,6 +386,106 @@ function usePluginSettingsForm(plugin2) {
372
386
  mutation
373
387
  };
374
388
  }
389
+ const SETTING_IMAGE_MAX_BYTES = 2 * 1024 * 1024;
390
+ const IMAGE_TYPES = /* @__PURE__ */ new Set(["image/png", "image/jpeg"]);
391
+ const validateSettingImage = (file) => {
392
+ if (!IMAGE_TYPES.has(file.type)) {
393
+ return "Bitte eine PNG- oder JPG-Datei auswählen.";
394
+ }
395
+ if (file.size === 0) {
396
+ return "Die Bilddatei ist leer.";
397
+ }
398
+ if (file.size > SETTING_IMAGE_MAX_BYTES) {
399
+ return "Die Bilddatei darf maximal 2 MiB groß sein.";
400
+ }
401
+ return null;
402
+ };
403
+ const ImageSettingInput = ({
404
+ id,
405
+ hintId,
406
+ label,
407
+ value,
408
+ disabled,
409
+ onChange
410
+ }) => {
411
+ const fileInput = useRef(null);
412
+ const [error, setError] = useState(null);
413
+ const upload = useMutation({
414
+ mutationFn: async (file) => {
415
+ const { files } = await sdk.admin.upload.create({ files: [file] });
416
+ const url = files[0]?.url;
417
+ if (!url) {
418
+ throw new Error("upload returned no file");
419
+ }
420
+ return url;
421
+ },
422
+ onSuccess: (url) => onChange(url),
423
+ onError: () => setError(texts.settings.imageUploadFailed)
424
+ });
425
+ const busy = disabled || upload.isPending;
426
+ const selectFile = (file) => {
427
+ if (!file) {
428
+ return;
429
+ }
430
+ const invalid = validateSettingImage(file);
431
+ setError(invalid);
432
+ if (!invalid) {
433
+ upload.mutate(file);
434
+ }
435
+ };
436
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
437
+ value && /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-subtle flex items-center justify-center rounded-md border p-4", children: /* @__PURE__ */ jsx(
438
+ "img",
439
+ {
440
+ src: value,
441
+ alt: texts.settings.imagePreviewAlt(label),
442
+ className: "max-h-24 max-w-full object-contain"
443
+ }
444
+ ) }),
445
+ /* @__PURE__ */ jsx(
446
+ "input",
447
+ {
448
+ ref: fileInput,
449
+ id,
450
+ "aria-describedby": hintId,
451
+ type: "file",
452
+ accept: "image/png,image/jpeg",
453
+ className: "hidden",
454
+ onChange: (event) => {
455
+ selectFile(event.target.files?.[0]);
456
+ event.target.value = "";
457
+ }
458
+ }
459
+ ),
460
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
461
+ /* @__PURE__ */ jsx(
462
+ Button,
463
+ {
464
+ type: "button",
465
+ size: "small",
466
+ variant: "secondary",
467
+ isLoading: upload.isPending,
468
+ disabled: busy,
469
+ onClick: () => fileInput.current?.click(),
470
+ children: value ? texts.settings.imageReplace : texts.settings.imageUpload
471
+ }
472
+ ),
473
+ value && /* @__PURE__ */ jsx(
474
+ Button,
475
+ {
476
+ type: "button",
477
+ size: "small",
478
+ variant: "transparent",
479
+ disabled: busy,
480
+ onClick: () => onChange(""),
481
+ children: texts.settings.imageRemove
482
+ }
483
+ ),
484
+ !value && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: texts.settings.imageNone })
485
+ ] }),
486
+ error && /* @__PURE__ */ jsx(Hint, { variant: "error", children: error })
487
+ ] });
488
+ };
375
489
  const fieldId = (pluginKey, key) => `plugin-setting-${pluginKey}-${key}`;
376
490
  const missingLabels = (plugin2) => plugin2.missing.map(
377
491
  (key) => plugin2.settings.find((setting) => setting.key === key)?.label ?? key
@@ -452,6 +566,16 @@ const SettingField = ({
452
566
  /* @__PURE__ */ jsx(Select.Content, { children: setting.options.map((option) => /* @__PURE__ */ jsx(Select.Item, { value: option.value, children: option.label }, option.value)) })
453
567
  ]
454
568
  }
569
+ ) : setting.type === "image" ? /* @__PURE__ */ jsx(
570
+ ImageSettingInput,
571
+ {
572
+ id,
573
+ hintId,
574
+ label: setting.label,
575
+ value: typeof value === "string" ? value : "",
576
+ disabled,
577
+ onChange: (url) => onChange(url)
578
+ }
455
579
  ) : setting.type === "number" ? /* @__PURE__ */ jsx(
456
580
  Input,
457
581
  {
@@ -491,7 +615,7 @@ const PluginSettingsForm = ({ plugin: plugin2 }) => {
491
615
  const form = usePluginSettingsForm(plugin2);
492
616
  const pending = form.mutation.isPending;
493
617
  const hasTextFields = plugin2.settings.some(
494
- (setting) => setting.type !== "boolean" && setting.type !== "secret" && setting.type !== "select"
618
+ (setting) => setting.type !== "boolean" && setting.type !== "secret" && setting.type !== "select" && setting.type !== "image"
495
619
  );
496
620
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", "aria-busy": pending, children: [
497
621
  /* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
@@ -530,62 +654,30 @@ const PluginStatusChips = ({ plugin: plugin2 }) => /* @__PURE__ */ jsxs("div", {
530
654
  plugin2.switchable && /* @__PURE__ */ jsx(StatusBadge, { color: plugin2.enabled ? "green" : "grey", children: plugin2.enabled ? texts.chips.enabled : texts.chips.disabled }),
531
655
  plugin2.settings.length > 0 && /* @__PURE__ */ jsx(StatusBadge, { color: plugin2.configured ? "green" : "orange", children: plugin2.configured ? texts.chips.configured : texts.chips.notConfigured(missingLabels(plugin2)) })
532
656
  ] });
533
- const PluginHubCard = ({ plugin: plugin2 }) => {
534
- const mutation = useUpdatePluginFeatures();
535
- const pending = mutation.isPending;
536
- const toggle = (enabled) => {
537
- mutation.mutate({
538
- plugin_key: plugin2.plugin_key,
539
- expected_version: plugin2.version,
540
- enabled,
541
- features: Object.fromEntries(
542
- plugin2.features.map((feature) => [feature.key, feature.enabled])
543
- )
544
- });
545
- };
546
- return /* @__PURE__ */ jsxs(
547
- Container,
548
- {
549
- className: "flex flex-wrap items-start justify-between gap-4 px-6 py-4",
550
- "aria-busy": pending,
551
- children: [
552
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
553
- /* @__PURE__ */ jsx(Heading, { level: "h2", children: plugin2.label }),
554
- plugin2.description && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: plugin2.description }),
555
- /* @__PURE__ */ jsx(PluginStatusChips, { plugin: plugin2 }),
556
- pending && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted mt-1", children: texts.hints.saving })
557
- ] }),
558
- /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-3", children: [
559
- plugin2.switchable && /* @__PURE__ */ jsx(
560
- Switch,
561
- {
562
- "aria-label": texts.plugin.switchLabel(plugin2.label),
563
- checked: plugin2.enabled,
564
- disabled: pending,
565
- onCheckedChange: (checked) => toggle(checked === true)
566
- }
567
- ),
568
- /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx(
569
- Link,
570
- {
571
- to: plugin2.admin_page ?? pluginDetailPath(plugin2.plugin_key),
572
- "aria-label": texts.plugin.openLabel(plugin2.label),
573
- children: texts.plugin.open
574
- }
575
- ) })
576
- ] })
577
- ]
578
- }
579
- );
580
- };
581
- const PluginFeaturesSettingsPage = () => {
582
- const query = usePluginFeatures();
657
+ const isNotFound = (error) => typeof error === "object" && error !== null && error.status === 404;
658
+ const PluginPageShell = ({ pluginKey, children }) => {
659
+ const query = usePluginFeature(pluginKey);
660
+ const plugin2 = query.data?.plugin;
583
661
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3", children: [
584
- /* @__PURE__ */ jsxs(Container, { className: "px-6 py-4", children: [
585
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: texts.page.title }),
586
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.page.description })
587
- ] }),
588
- query.isPending ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.loading }) }) : query.isError ? /* @__PURE__ */ jsxs(Container, { className: "flex flex-wrap items-center justify-between gap-3", children: [
662
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
663
+ Link,
664
+ {
665
+ to: PLUGIN_HUB_PATH,
666
+ className: "text-ui-fg-subtle hover:text-ui-fg-base txt-compact-small-plus",
667
+ children: [
668
+ "← ",
669
+ texts.detail.back
670
+ ]
671
+ }
672
+ ) }),
673
+ plugin2 ? /* @__PURE__ */ jsxs(Fragment, { children: [
674
+ /* @__PURE__ */ jsxs(Container, { className: "px-6 py-4", children: [
675
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: plugin2.label }),
676
+ plugin2.description && /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: plugin2.description }),
677
+ /* @__PURE__ */ jsx(PluginStatusChips, { plugin: plugin2 })
678
+ ] }),
679
+ children
680
+ ] }) : query.isPending ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.loading }) }) : isNotFound(query.error) ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.notFound }) }) : /* @__PURE__ */ jsxs(Container, { className: "flex flex-wrap items-center justify-between gap-3", children: [
589
681
  /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", children: texts.states.error }),
590
682
  /* @__PURE__ */ jsx(
591
683
  Button,
@@ -597,15 +689,9 @@ const PluginFeaturesSettingsPage = () => {
597
689
  children: texts.states.retry
598
690
  }
599
691
  )
600
- ] }) : query.data.plugins.length === 0 ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.empty }) }) : [
601
- ...query.data.plugins.filter((plugin2) => !plugin2.switchable),
602
- ...query.data.plugins.filter((plugin2) => plugin2.switchable)
603
- ].map((plugin2) => /* @__PURE__ */ jsx(PluginHubCard, { plugin: plugin2 }, plugin2.plugin_key))
692
+ ] })
604
693
  ] });
605
694
  };
606
- const config = defineRouteConfig({
607
- label: texts.menu.label
608
- });
609
695
  const SUMMARY_MAX_LENGTH = 200;
610
696
  const cut = (text) => text.length > SUMMARY_MAX_LENGTH ? `${text.slice(0, SUMMARY_MAX_LENGTH - 1)}…` : text;
611
697
  const isPrimitive = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
@@ -881,49 +967,1505 @@ const PluginFeatureSections = ({ pluginKey }) => {
881
967
  plugin2.actions.length > 0 && /* @__PURE__ */ jsx(PluginActionsSection, { plugin: plugin2 })
882
968
  ] });
883
969
  };
884
- const isNotFound = (error) => typeof error === "object" && error !== null && error.status === 404;
885
- const PluginPageShell = ({ pluginKey, children }) => {
886
- const query = usePluginFeature(pluginKey);
887
- const plugin2 = query.data?.plugin;
888
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3", children: [
889
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
890
- Link,
891
- {
892
- to: PLUGIN_HUB_PATH,
893
- className: "text-ui-fg-subtle hover:text-ui-fg-base txt-compact-small-plus",
894
- children: [
895
- "← ",
896
- texts.detail.back
897
- ]
970
+ const PLUGIN_FEATURE_ENABLED_STALE_TIME = 3e4;
971
+ const isPluginFeatureEnabledIn = (data, pluginKey, featureKeys) => {
972
+ const plugin2 = data.plugins.find((entry) => entry.plugin_key === pluginKey);
973
+ if (!plugin2?.enabled) {
974
+ return false;
975
+ }
976
+ return featureKeys.every(
977
+ (key) => plugin2.features.find((feature) => feature.key === key)?.effective_enabled === true
978
+ );
979
+ };
980
+ const pluginFeatureEnabledQueryOptions = (pluginKey, featureKeys) => ({
981
+ queryKey: pluginFeatureKeys.list(),
982
+ queryFn: listPluginFeatures,
983
+ staleTime: PLUGIN_FEATURE_ENABLED_STALE_TIME,
984
+ select: (data) => isPluginFeatureEnabledIn(data, pluginKey, featureKeys)
985
+ });
986
+ const toPluginFeatureEnabledState = (result) => ({
987
+ enabled: !result.isPending && !result.isError && result.data === true,
988
+ isPending: result.isPending,
989
+ isError: result.isError
990
+ });
991
+ function usePluginFeatureEnabled(pluginKey, ...featureKeys) {
992
+ return toPluginFeatureEnabledState(
993
+ useQuery(pluginFeatureEnabledQueryOptions(pluginKey, featureKeys))
994
+ );
995
+ }
996
+ const PluginFeatureGate = ({
997
+ pluginKey,
998
+ featureKeys = [],
999
+ fallback = null,
1000
+ children
1001
+ }) => {
1002
+ const { enabled } = usePluginFeatureEnabled(pluginKey, ...featureKeys);
1003
+ return /* @__PURE__ */ jsx(Fragment, { children: enabled ? children : fallback });
1004
+ };
1005
+ const PluginFeatureDisabledNotice = ({
1006
+ pluginKey,
1007
+ featureLabel
1008
+ }) => /* @__PURE__ */ jsxs(
1009
+ Container,
1010
+ {
1011
+ className: "flex flex-col gap-2 px-6 py-4",
1012
+ "data-plugin-key": pluginKey,
1013
+ children: [
1014
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: featureLabel ? texts.gate.disabledNamed(featureLabel) : texts.gate.disabled }),
1015
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1016
+ Link,
1017
+ {
1018
+ to: PLUGIN_HUB_PATH,
1019
+ className: "text-ui-fg-interactive hover:text-ui-fg-interactive-hover txt-compact-small-plus",
1020
+ children: texts.gate.openHub
1021
+ }
1022
+ ) })
1023
+ ]
1024
+ }
1025
+ );
1026
+ const listOrderDocuments = (orderId) => sdk.client.fetch(
1027
+ documentsPaths.admin.get.listForOrder(orderId)
1028
+ );
1029
+ const issueOrderInvoice = (orderId) => sdk.client.fetch(
1030
+ documentsPaths.admin.post.issueInvoice(orderId),
1031
+ { method: "POST" }
1032
+ );
1033
+ const regenerateOrderDocument = (orderId, documentId) => sdk.client.fetch(
1034
+ documentsPaths.admin.post.regenerateDocument(orderId, documentId),
1035
+ { method: "POST", body: {} }
1036
+ );
1037
+ const listOrderPackingLists = (orderId) => sdk.client.fetch(
1038
+ packingListsPaths.admin.get.listForOrder(orderId)
1039
+ );
1040
+ const retryOrderPackingList = (orderId, fulfillmentId) => sdk.client.fetch(
1041
+ packingListsPaths.admin.post.retry(orderId, fulfillmentId),
1042
+ { method: "POST", body: {} }
1043
+ );
1044
+ const retrieveOrderDocumentPreview = async (orderId, documentId) => {
1045
+ const response = await sdk.client.fetch(
1046
+ documentsPaths.admin.get.download(orderId, documentId),
1047
+ { headers: { accept: "application/pdf" } }
1048
+ );
1049
+ const pdf = await response.blob();
1050
+ return URL.createObjectURL(pdf);
1051
+ };
1052
+ const retrieveOrderPackingListPreview = async (orderId, fulfillmentId) => {
1053
+ const response = await sdk.client.fetch(
1054
+ packingListsPaths.admin.get.download(orderId, fulfillmentId),
1055
+ { headers: { accept: "application/pdf" } }
1056
+ );
1057
+ const pdf = await response.blob();
1058
+ return URL.createObjectURL(pdf);
1059
+ };
1060
+ const formatDocumentKind = (kind) => {
1061
+ switch (kind) {
1062
+ case "invoice":
1063
+ return "Rechnung";
1064
+ case "cancellation":
1065
+ return "Stornorechnung";
1066
+ case "credit_note":
1067
+ return "Gutschrift";
1068
+ }
1069
+ };
1070
+ const formatAmount = (document2) => {
1071
+ const amount = Number(document2.total.amount);
1072
+ if (!Number.isFinite(amount)) {
1073
+ return `${document2.total.amount} ${document2.total.currency_code.toUpperCase()}`;
1074
+ }
1075
+ return new Intl.NumberFormat("de-AT", {
1076
+ style: "currency",
1077
+ currency: document2.total.currency_code.toUpperCase()
1078
+ }).format(amount);
1079
+ };
1080
+ const formatIssuedAt = (issuedAt) => new Intl.DateTimeFormat("de-AT", { dateStyle: "medium" }).format(
1081
+ new Date(issuedAt)
1082
+ );
1083
+ const OrderDocumentsWidgetContent = ({
1084
+ data
1085
+ }) => {
1086
+ const queryClient = useQueryClient();
1087
+ const [preview, setPreview] = useState(null);
1088
+ const previewRequest = useRef(0);
1089
+ const documentsQueryKey = ["documents", "order", data.id];
1090
+ const documentsQuery = useQuery({
1091
+ queryKey: documentsQueryKey,
1092
+ queryFn: () => listOrderDocuments(data.id)
1093
+ });
1094
+ const documents = documentsQuery.data?.documents ?? [];
1095
+ const invoice = documents.find((document2) => document2.kind === "invoice");
1096
+ const issueInvoice = useMutation({
1097
+ mutationFn: () => issueOrderInvoice(data.id),
1098
+ onSuccess: async ({ created }) => {
1099
+ toast.success(
1100
+ created ? "Die Rechnung wurde ausgestellt." : "Für diese Bestellung existiert bereits eine Rechnung."
1101
+ );
1102
+ await queryClient.invalidateQueries({ queryKey: documentsQueryKey });
1103
+ },
1104
+ onError: (error) => {
1105
+ const message = error instanceof Error ? error.message : null;
1106
+ toast.error("Die Rechnung konnte nicht ausgestellt werden.", {
1107
+ description: message ?? "Die Bestellung muss vollständig versendet und darf nicht storniert sein."
1108
+ });
1109
+ }
1110
+ });
1111
+ const regenerateDocument = useMutation({
1112
+ mutationFn: (document2) => regenerateOrderDocument(data.id, document2.id),
1113
+ onSuccess: async () => {
1114
+ toast.success("Das Dokument wurde neu ausgestellt.");
1115
+ await queryClient.invalidateQueries({ queryKey: documentsQueryKey });
1116
+ },
1117
+ onError: (error) => {
1118
+ const message = error instanceof Error ? error.message : null;
1119
+ toast.error("Das Dokument konnte nicht regeneriert werden.", {
1120
+ description: message ?? "Das ausgestellte Dokument ist nicht verfügbar."
1121
+ });
1122
+ }
1123
+ });
1124
+ const closePreview = () => {
1125
+ previewRequest.current += 1;
1126
+ if (preview?.url) {
1127
+ URL.revokeObjectURL(preview.url);
1128
+ }
1129
+ setPreview(null);
1130
+ };
1131
+ const previewDocument = async (document2) => {
1132
+ if (preview?.url) {
1133
+ URL.revokeObjectURL(preview.url);
1134
+ }
1135
+ const requestId = previewRequest.current + 1;
1136
+ previewRequest.current = requestId;
1137
+ setPreview({ document: document2, url: null, error: null });
1138
+ try {
1139
+ const url = await retrieveOrderDocumentPreview(data.id, document2.id);
1140
+ if (previewRequest.current !== requestId) {
1141
+ URL.revokeObjectURL(url);
1142
+ return;
898
1143
  }
899
- ) }),
900
- plugin2 ? /* @__PURE__ */ jsxs(Fragment, { children: [
901
- /* @__PURE__ */ jsxs(Container, { className: "px-6 py-4", children: [
902
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: plugin2.label }),
903
- plugin2.description && /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: plugin2.description }),
904
- /* @__PURE__ */ jsx(PluginStatusChips, { plugin: plugin2 })
1144
+ setPreview({ document: document2, url, error: null });
1145
+ } catch {
1146
+ if (previewRequest.current !== requestId) {
1147
+ return;
1148
+ }
1149
+ setPreview({
1150
+ document: document2,
1151
+ url: null,
1152
+ error: "Das Dokument konnte nicht geladen werden."
1153
+ });
1154
+ }
1155
+ };
1156
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1157
+ /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
1158
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 px-6 py-4", children: [
1159
+ /* @__PURE__ */ jsxs("div", { children: [
1160
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Dokumente" }),
1161
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Ausgestellte Belege zu dieser Bestellung." })
1162
+ ] }),
1163
+ !invoice ? /* @__PURE__ */ jsx(
1164
+ Button,
1165
+ {
1166
+ disabled: issueInvoice.isPending,
1167
+ isLoading: issueInvoice.isPending,
1168
+ onClick: () => issueInvoice.mutate(),
1169
+ size: "small",
1170
+ variant: "secondary",
1171
+ children: "Rechnung ausstellen"
1172
+ }
1173
+ ) : /* @__PURE__ */ jsx(
1174
+ Button,
1175
+ {
1176
+ disabled: regenerateDocument.isPending,
1177
+ isLoading: regenerateDocument.isPending,
1178
+ onClick: () => regenerateDocument.mutate(invoice),
1179
+ size: "small",
1180
+ variant: "secondary",
1181
+ children: "Rechnung regenerieren"
1182
+ }
1183
+ )
905
1184
  ] }),
906
- children
907
- ] }) : query.isPending ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.loading }) }) : isNotFound(query.error) ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.notFound }) }) : /* @__PURE__ */ jsxs(Container, { className: "flex flex-wrap items-center justify-between gap-3", children: [
908
- /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", children: texts.states.error }),
909
- /* @__PURE__ */ jsx(
910
- Button,
1185
+ /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: documentsQuery.isPending ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Dokumente werden geladen." }) : documentsQuery.isError ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", children: "Dokumente konnten nicht geladen werden." }) : documents.length ? /* @__PURE__ */ jsx("div", { className: "space-y-3", children: documents.map((document2) => /* @__PURE__ */ jsxs(
1186
+ "div",
911
1187
  {
912
- size: "small",
913
- variant: "secondary",
914
- isLoading: query.isFetching,
915
- onClick: () => void query.refetch(),
916
- children: texts.states.retry
917
- }
918
- )
919
- ] })
1188
+ className: "flex items-center justify-between gap-4",
1189
+ children: [
1190
+ /* @__PURE__ */ jsxs("div", { children: [
1191
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
1192
+ formatDocumentKind(document2.kind),
1193
+ " ",
1194
+ document2.number
1195
+ ] }),
1196
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle", children: [
1197
+ formatIssuedAt(document2.issued_at),
1198
+ " ·",
1199
+ " ",
1200
+ formatAmount(document2)
1201
+ ] })
1202
+ ] }),
1203
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1204
+ /* @__PURE__ */ jsx(
1205
+ Button,
1206
+ {
1207
+ onClick: () => previewDocument(document2),
1208
+ size: "small",
1209
+ variant: "secondary",
1210
+ children: "Ansehen"
1211
+ }
1212
+ ),
1213
+ document2.kind !== "invoice" ? /* @__PURE__ */ jsx(
1214
+ Button,
1215
+ {
1216
+ disabled: regenerateDocument.isPending,
1217
+ isLoading: regenerateDocument.isPending,
1218
+ onClick: () => regenerateDocument.mutate(document2),
1219
+ size: "small",
1220
+ variant: "secondary",
1221
+ children: "Regenerieren"
1222
+ }
1223
+ ) : null
1224
+ ] })
1225
+ ]
1226
+ },
1227
+ document2.id
1228
+ )) }) : /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Für diese Bestellung wurden noch keine Dokumente ausgestellt." }) })
1229
+ ] }),
1230
+ /* @__PURE__ */ jsx(
1231
+ FocusModal,
1232
+ {
1233
+ onOpenChange: (open) => {
1234
+ if (!open) {
1235
+ closePreview();
1236
+ }
1237
+ },
1238
+ open: preview !== null,
1239
+ children: /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1240
+ /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsx(FocusModal.Title, { children: preview ? `${formatDocumentKind(preview.document.kind)} ${preview.document.number}` : "Dokument" }) }),
1241
+ /* @__PURE__ */ jsx(FocusModal.Body, { className: "h-[75vh] p-0", children: preview?.url ? /* @__PURE__ */ jsx(
1242
+ "iframe",
1243
+ {
1244
+ className: "h-full w-full border-0",
1245
+ src: preview.url,
1246
+ title: `Vorschau ${preview.document.number}`
1247
+ }
1248
+ ) : preview?.error ? /* @__PURE__ */ jsx(Text, { className: "p-6 text-ui-fg-error", children: preview.error }) : /* @__PURE__ */ jsx(Text, { className: "p-6 text-ui-fg-subtle", children: "Dokument wird geladen." }) }),
1249
+ /* @__PURE__ */ jsx(FocusModal.Footer, { children: /* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { onClick: closePreview, variant: "secondary", children: "Schließen" }) }) })
1250
+ ] })
1251
+ }
1252
+ )
920
1253
  ] });
921
1254
  };
1255
+ const OrderDocumentsWidget = (props) => /* @__PURE__ */ jsx(PluginFeatureGate, { pluginKey: "documents", featureKeys: ["invoices"], children: /* @__PURE__ */ jsx(OrderDocumentsWidgetContent, { ...props }) });
1256
+ defineWidgetConfig({
1257
+ zone: "order.details.side.after"
1258
+ });
1259
+ const formatStatus = (status) => {
1260
+ switch (status) {
1261
+ case "missing":
1262
+ return "Nicht erstellt";
1263
+ case "pending":
1264
+ return "Ausstehend";
1265
+ case "processing":
1266
+ return "Wird erstellt";
1267
+ case "ready":
1268
+ return "Bereit";
1269
+ case "failed":
1270
+ return "Fehlgeschlagen";
1271
+ case "canceled":
1272
+ return "Storniert";
1273
+ }
1274
+ };
1275
+ const formatGeneratedAt = (generatedAt) => new Intl.DateTimeFormat("de-AT", {
1276
+ dateStyle: "medium",
1277
+ timeStyle: "short"
1278
+ }).format(new Date(generatedAt));
1279
+ const formatDetails = (packingList) => [
1280
+ packingList.number ? `Nummer: ${packingList.number}` : null,
1281
+ packingList.source_revision !== null ? `Revision: ${packingList.source_revision}` : null,
1282
+ packingList.generated_at ? `Datum: ${formatGeneratedAt(packingList.generated_at)}` : null
1283
+ ].filter((detail) => detail !== null).join(" · ");
1284
+ const formatFailureReason = (failureReason) => {
1285
+ const description = failureReason?.replace(/\s+/g, " ").trim();
1286
+ if (!description) {
1287
+ return null;
1288
+ }
1289
+ return description.length > 140 ? `${description.slice(0, 137)}...` : description;
1290
+ };
1291
+ const retryLabel = (status) => {
1292
+ if (status === "missing") {
1293
+ return "Erstellen";
1294
+ }
1295
+ if (status === "pending" || status === "failed") {
1296
+ return "Erneut versuchen";
1297
+ }
1298
+ return null;
1299
+ };
1300
+ const OrderPackingListsWidgetContent = ({
1301
+ data
1302
+ }) => {
1303
+ const queryClient = useQueryClient();
1304
+ const [preview, setPreview] = useState(null);
1305
+ const previewRequest = useRef(0);
1306
+ const previewUrl = useRef(null);
1307
+ const packingListsQueryKey = ["packing-lists", "order", data.id];
1308
+ const packingListsQuery = useQuery({
1309
+ queryKey: packingListsQueryKey,
1310
+ queryFn: () => listOrderPackingLists(data.id),
1311
+ refetchInterval: (query) => {
1312
+ const packingLists2 = query.state.data?.packing_lists;
1313
+ return packingLists2?.some(
1314
+ ({ status }) => status === "missing" || status === "pending" || status === "processing"
1315
+ ) ? 2e3 : false;
1316
+ }
1317
+ });
1318
+ const packingLists = packingListsQuery.data?.packing_lists ?? [];
1319
+ const retryPackingList = useMutation({
1320
+ mutationFn: (packingList) => retryOrderPackingList(data.id, packingList.fulfillment_id),
1321
+ onSuccess: async () => {
1322
+ toast.success("Die Packliste wird erstellt.");
1323
+ await queryClient.invalidateQueries({ queryKey: packingListsQueryKey });
1324
+ },
1325
+ onError: (error) => {
1326
+ toast.error("Die Packliste konnte nicht erstellt werden.", {
1327
+ description: error instanceof Error ? error.message : "Bitte versuchen Sie es erneut."
1328
+ });
1329
+ }
1330
+ });
1331
+ useEffect(
1332
+ () => () => {
1333
+ previewRequest.current += 1;
1334
+ if (previewUrl.current) {
1335
+ URL.revokeObjectURL(previewUrl.current);
1336
+ previewUrl.current = null;
1337
+ }
1338
+ },
1339
+ []
1340
+ );
1341
+ const revokePreviewUrl = () => {
1342
+ if (previewUrl.current) {
1343
+ URL.revokeObjectURL(previewUrl.current);
1344
+ previewUrl.current = null;
1345
+ }
1346
+ };
1347
+ const closePreview = () => {
1348
+ previewRequest.current += 1;
1349
+ revokePreviewUrl();
1350
+ setPreview(null);
1351
+ };
1352
+ const previewPackingList = async (packingList, position) => {
1353
+ revokePreviewUrl();
1354
+ const requestId = previewRequest.current + 1;
1355
+ previewRequest.current = requestId;
1356
+ setPreview({ packingList, position, url: null, error: null });
1357
+ try {
1358
+ const url = await retrieveOrderPackingListPreview(
1359
+ data.id,
1360
+ packingList.fulfillment_id
1361
+ );
1362
+ if (previewRequest.current !== requestId) {
1363
+ URL.revokeObjectURL(url);
1364
+ return;
1365
+ }
1366
+ previewUrl.current = url;
1367
+ setPreview({ packingList, position, url, error: null });
1368
+ } catch {
1369
+ if (previewRequest.current !== requestId) {
1370
+ return;
1371
+ }
1372
+ setPreview({
1373
+ packingList,
1374
+ position,
1375
+ url: null,
1376
+ error: "Die Packliste konnte nicht geladen werden."
1377
+ });
1378
+ }
1379
+ };
1380
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1381
+ /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
1382
+ /* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
1383
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Packlisten" }),
1384
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Packlisten zu den Versandvorgängen dieser Bestellung." })
1385
+ ] }),
1386
+ /* @__PURE__ */ jsx("div", { className: "grid gap-3 px-6 py-4", children: packingListsQuery.isPending ? /* @__PURE__ */ jsx(
1387
+ Text,
1388
+ {
1389
+ "aria-atomic": "true",
1390
+ "aria-live": "polite",
1391
+ className: "text-ui-fg-subtle",
1392
+ role: "status",
1393
+ children: "Packlisten werden geladen."
1394
+ }
1395
+ ) : packingListsQuery.isError ? /* @__PURE__ */ jsx(
1396
+ Text,
1397
+ {
1398
+ "aria-atomic": "true",
1399
+ "aria-live": "assertive",
1400
+ className: "text-ui-fg-error",
1401
+ role: "alert",
1402
+ children: "Packlisten konnten nicht geladen werden."
1403
+ }
1404
+ ) : packingLists.length ? packingLists.map((packingList, index) => {
1405
+ const actionLabel = retryLabel(packingList.status);
1406
+ const details = formatDetails(packingList);
1407
+ const failureReason = formatFailureReason(
1408
+ packingList.failure_reason
1409
+ );
1410
+ const canPreview = packingList.generated_at !== null && (packingList.status === "ready" || packingList.status === "canceled");
1411
+ const isRetrying = retryPackingList.isPending && retryPackingList.variables?.fulfillment_id === packingList.fulfillment_id;
1412
+ const accessiblePackingListName = packingList.number ? `Packliste ${packingList.number} für Fulfillment ${packingList.fulfillment_id}` : `Packliste ${index + 1} für Fulfillment ${packingList.fulfillment_id}`;
1413
+ return /* @__PURE__ */ jsxs(
1414
+ "div",
1415
+ {
1416
+ className: "border-ui-border-base rounded-md border p-3",
1417
+ children: [
1418
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
1419
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
1420
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
1421
+ "Packliste ",
1422
+ index + 1
1423
+ ] }),
1424
+ /* @__PURE__ */ jsxs(
1425
+ Text,
1426
+ {
1427
+ "aria-atomic": "true",
1428
+ "aria-live": "polite",
1429
+ className: packingList.status === "failed" ? "text-ui-fg-error text-xs" : "text-ui-fg-subtle text-xs",
1430
+ role: "status",
1431
+ children: [
1432
+ "Status: ",
1433
+ formatStatus(packingList.status)
1434
+ ]
1435
+ }
1436
+ )
1437
+ ] }),
1438
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 gap-2", children: [
1439
+ canPreview ? /* @__PURE__ */ jsx(
1440
+ Button,
1441
+ {
1442
+ "aria-label": `Ansehen: ${accessiblePackingListName}`,
1443
+ onClick: () => previewPackingList(packingList, index + 1),
1444
+ size: "small",
1445
+ variant: "secondary",
1446
+ children: "Ansehen"
1447
+ }
1448
+ ) : null,
1449
+ actionLabel ? /* @__PURE__ */ jsx(
1450
+ Button,
1451
+ {
1452
+ "aria-label": `${actionLabel}: ${accessiblePackingListName}`,
1453
+ disabled: retryPackingList.isPending,
1454
+ isLoading: isRetrying,
1455
+ onClick: () => retryPackingList.mutate(packingList),
1456
+ size: "small",
1457
+ variant: "secondary",
1458
+ children: actionLabel
1459
+ }
1460
+ ) : null
1461
+ ] })
1462
+ ] }),
1463
+ /* @__PURE__ */ jsxs("div", { className: "mt-2 grid gap-1", children: [
1464
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle text-xs", children: [
1465
+ "Lagerstandort:",
1466
+ " ",
1467
+ packingList.location_name ?? "Nicht verfügbar"
1468
+ ] }),
1469
+ details ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: details }) : null,
1470
+ failureReason ? /* @__PURE__ */ jsxs(
1471
+ Text,
1472
+ {
1473
+ "aria-atomic": "true",
1474
+ "aria-live": "assertive",
1475
+ className: "text-ui-fg-error text-xs",
1476
+ role: "alert",
1477
+ children: [
1478
+ "Fehler: ",
1479
+ failureReason
1480
+ ]
1481
+ }
1482
+ ) : null
1483
+ ] })
1484
+ ]
1485
+ },
1486
+ packingList.fulfillment_id
1487
+ );
1488
+ }) : /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Für diese Bestellung sind keine Packlisten vorhanden." }) })
1489
+ ] }),
1490
+ /* @__PURE__ */ jsx(
1491
+ FocusModal,
1492
+ {
1493
+ onOpenChange: (open) => {
1494
+ if (!open) {
1495
+ closePreview();
1496
+ }
1497
+ },
1498
+ open: preview !== null,
1499
+ children: /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1500
+ /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsx(FocusModal.Title, { children: preview ? `Packliste ${preview.position}${preview.packingList.number ? ` · ${preview.packingList.number}` : ""}` : "Packliste" }) }),
1501
+ /* @__PURE__ */ jsx(FocusModal.Body, { className: "h-[75vh] p-0", children: preview?.url ? /* @__PURE__ */ jsx(
1502
+ "iframe",
1503
+ {
1504
+ className: "h-full w-full border-0",
1505
+ src: preview.url,
1506
+ title: `Vorschau Packliste ${preview.position}`
1507
+ }
1508
+ ) : preview?.error ? /* @__PURE__ */ jsx(
1509
+ Text,
1510
+ {
1511
+ "aria-atomic": "true",
1512
+ "aria-live": "assertive",
1513
+ className: "p-6 text-ui-fg-error",
1514
+ role: "alert",
1515
+ children: preview.error
1516
+ }
1517
+ ) : /* @__PURE__ */ jsx(
1518
+ Text,
1519
+ {
1520
+ "aria-atomic": "true",
1521
+ "aria-live": "polite",
1522
+ className: "p-6 text-ui-fg-subtle",
1523
+ role: "status",
1524
+ children: "Packliste wird geladen."
1525
+ }
1526
+ ) }),
1527
+ /* @__PURE__ */ jsx(FocusModal.Footer, { children: /* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { onClick: closePreview, variant: "secondary", children: "Schließen" }) }) })
1528
+ ] })
1529
+ }
1530
+ )
1531
+ ] });
1532
+ };
1533
+ const OrderPackingListsWidget = (props) => /* @__PURE__ */ jsx(PluginFeatureGate, { pluginKey: "documents", featureKeys: ["packing_lists"], children: /* @__PURE__ */ jsx(OrderPackingListsWidgetContent, { ...props }) });
1534
+ defineWidgetConfig({
1535
+ zone: "order.details.side.after"
1536
+ });
1537
+ const PluginHubCard = ({ plugin: plugin2 }) => {
1538
+ const mutation = useUpdatePluginFeatures();
1539
+ const pending = mutation.isPending;
1540
+ const toggle = (enabled) => {
1541
+ mutation.mutate({
1542
+ plugin_key: plugin2.plugin_key,
1543
+ expected_version: plugin2.version,
1544
+ enabled,
1545
+ features: Object.fromEntries(
1546
+ plugin2.features.map((feature) => [feature.key, feature.enabled])
1547
+ )
1548
+ });
1549
+ };
1550
+ return /* @__PURE__ */ jsxs(
1551
+ Container,
1552
+ {
1553
+ className: "flex flex-wrap items-start justify-between gap-4 px-6 py-4",
1554
+ "aria-busy": pending,
1555
+ children: [
1556
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
1557
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: plugin2.label }),
1558
+ plugin2.description && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: plugin2.description }),
1559
+ /* @__PURE__ */ jsx(PluginStatusChips, { plugin: plugin2 }),
1560
+ pending && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted mt-1", children: texts.hints.saving })
1561
+ ] }),
1562
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-3", children: [
1563
+ plugin2.switchable && /* @__PURE__ */ jsx(
1564
+ Switch,
1565
+ {
1566
+ "aria-label": texts.plugin.switchLabel(plugin2.label),
1567
+ checked: plugin2.enabled,
1568
+ disabled: pending,
1569
+ onCheckedChange: (checked) => toggle(checked === true)
1570
+ }
1571
+ ),
1572
+ /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx(
1573
+ Link,
1574
+ {
1575
+ to: plugin2.admin_page ?? pluginDetailPath(plugin2.plugin_key),
1576
+ "aria-label": texts.plugin.openLabel(plugin2.label),
1577
+ children: texts.plugin.open
1578
+ }
1579
+ ) })
1580
+ ] })
1581
+ ]
1582
+ }
1583
+ );
1584
+ };
1585
+ const PluginFeaturesSettingsPage = () => {
1586
+ const query = usePluginFeatures();
1587
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3", children: [
1588
+ /* @__PURE__ */ jsxs(Container, { className: "px-6 py-4", children: [
1589
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: texts.page.title }),
1590
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.page.description })
1591
+ ] }),
1592
+ query.isPending ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.loading }) }) : query.isError ? /* @__PURE__ */ jsxs(Container, { className: "flex flex-wrap items-center justify-between gap-3", children: [
1593
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", children: texts.states.error }),
1594
+ /* @__PURE__ */ jsx(
1595
+ Button,
1596
+ {
1597
+ size: "small",
1598
+ variant: "secondary",
1599
+ isLoading: query.isFetching,
1600
+ onClick: () => void query.refetch(),
1601
+ children: texts.states.retry
1602
+ }
1603
+ )
1604
+ ] }) : query.data.plugins.length === 0 ? /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: texts.states.empty }) }) : [
1605
+ ...query.data.plugins.filter((plugin2) => !plugin2.switchable),
1606
+ ...query.data.plugins.filter((plugin2) => plugin2.switchable)
1607
+ ].map((plugin2) => /* @__PURE__ */ jsx(PluginHubCard, { plugin: plugin2 }, plugin2.plugin_key))
1608
+ ] });
1609
+ };
1610
+ const config = defineRouteConfig({
1611
+ label: texts.menu.label
1612
+ });
1613
+ const withPagination = (params) => new URLSearchParams({
1614
+ limit: String(params.limit),
1615
+ offset: String(params.offset)
1616
+ });
1617
+ const withMessageQuery = (path, params) => {
1618
+ const query = withPagination(params);
1619
+ if (params.kind) {
1620
+ query.set("kind", params.kind);
1621
+ }
1622
+ if (params.status) {
1623
+ query.set("status", params.status);
1624
+ }
1625
+ return `${path}?${query.toString()}`;
1626
+ };
1627
+ const listEmailMessages = (params) => sdk.client.fetch(
1628
+ withMessageQuery(emailAdminPaths.get.list, params)
1629
+ );
1630
+ const retrieveEmailMessage = (messageId) => sdk.client.fetch(
1631
+ emailAdminPaths.get.detail(messageId)
1632
+ );
1633
+ const resendEmailMessage = (messageId, body) => sdk.client.fetch(
1634
+ emailAdminPaths.post.resend(messageId),
1635
+ { method: "POST", body }
1636
+ );
1637
+ const listEmailTermsVersions = (params) => {
1638
+ const query = withPagination(params);
1639
+ return sdk.client.fetch(
1640
+ `${emailAdminPaths.get.termsVersions}?${query.toString()}`
1641
+ );
1642
+ };
1643
+ const createEmailTermsVersion = (body) => sdk.client.fetch(
1644
+ emailAdminPaths.post.createTermsVersion,
1645
+ { method: "POST", body }
1646
+ );
1647
+ const downloadEmailTermsVersion = async (termsVersionId) => {
1648
+ const response = await sdk.client.fetch(
1649
+ emailAdminPaths.get.downloadTermsVersion(termsVersionId),
1650
+ { headers: { accept: "application/pdf" } }
1651
+ );
1652
+ return response.blob();
1653
+ };
1654
+ const PAGE_SIZE$1 = 20;
1655
+ const MAX_PAGE_OFFSET$1 = 1e4;
1656
+ const KINDS = [
1657
+ "order.received",
1658
+ "order.received.admin",
1659
+ "order.shipped",
1660
+ "order.canceled",
1661
+ "order.return_requested",
1662
+ "order.return_received",
1663
+ "order.refunded",
1664
+ "auth.password_reset",
1665
+ "affiliate.consignment_report_due"
1666
+ ];
1667
+ const STATUSES = [
1668
+ "pending",
1669
+ "ready",
1670
+ "sending",
1671
+ "retry_pending",
1672
+ "sent",
1673
+ "failed",
1674
+ "unknown",
1675
+ "suppressed"
1676
+ ];
1677
+ const KIND_LABELS = {
1678
+ "order.received": "Bestellbestätigung (Kunde)",
1679
+ "order.received.admin": "Neue Bestellung (Shop)",
1680
+ "order.shipped": "Versandbestätigung",
1681
+ "order.canceled": "Stornierung",
1682
+ "order.return_requested": "Retourenanfrage",
1683
+ "order.return_received": "Retoureneingang",
1684
+ "order.refunded": "Rückerstattung",
1685
+ "auth.password_reset": "Passwort zurücksetzen",
1686
+ "affiliate.consignment_report_due": "Affiliate-Meldung"
1687
+ };
1688
+ const STATUS_LABELS = {
1689
+ pending: "Wartet auf Fakten",
1690
+ ready: "Bereit",
1691
+ sending: "Wird versendet",
1692
+ retry_pending: "Erneuter Versuch geplant",
1693
+ sent: "Versendet",
1694
+ failed: "Fehlgeschlagen",
1695
+ unknown: "Ausgang unbekannt",
1696
+ suppressed: "Unterdrückt"
1697
+ };
1698
+ const ATTEMPT_STATUS_LABELS = {
1699
+ processing: "In Bearbeitung",
1700
+ sent: "Versendet",
1701
+ failed: "Fehlgeschlagen",
1702
+ unknown: "Ausgang unbekannt"
1703
+ };
1704
+ const isKindFilter = (value) => value === "all" || KINDS.includes(value);
1705
+ const isStatusFilter = (value) => value === "all" || STATUSES.includes(value);
1706
+ const canResend = (message) => message.kind !== "auth.password_reset" && (message.status === "sent" || message.status === "unknown" || message.status === "failed");
1707
+ const formatDateTime$1 = (value) => {
1708
+ if (!value) {
1709
+ return "-";
1710
+ }
1711
+ const date = new Date(value);
1712
+ if (Number.isNaN(date.getTime())) {
1713
+ return "-";
1714
+ }
1715
+ return new Intl.DateTimeFormat("de-AT", {
1716
+ dateStyle: "medium",
1717
+ timeStyle: "short"
1718
+ }).format(date);
1719
+ };
1720
+ const formatResource = (message) => message.resource_id ? `${message.resource_type} · ${message.resource_id}` : message.resource_type;
1721
+ const Status = ({ message }) => /* @__PURE__ */ jsx(
1722
+ "span",
1723
+ {
1724
+ className: message.status === "sent" ? "text-ui-fg-base" : message.status === "failed" || message.status === "unknown" ? "text-ui-fg-error" : "text-ui-fg-subtle",
1725
+ children: STATUS_LABELS[message.status]
1726
+ }
1727
+ );
1728
+ const MessageCards = ({
1729
+ messages,
1730
+ selectedId,
1731
+ onSelect
1732
+ }) => /* @__PURE__ */ jsx("div", { className: "grid gap-3 px-4 py-4 md:hidden", children: messages.map((message) => /* @__PURE__ */ jsxs(
1733
+ "div",
1734
+ {
1735
+ className: `border-ui-border-base rounded-md border p-4 ${selectedId === message.id ? "bg-ui-bg-base-hover" : ""}`,
1736
+ children: [
1737
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
1738
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
1739
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: KIND_LABELS[message.kind] }),
1740
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle break-all text-xs", children: formatResource(message) })
1741
+ ] }),
1742
+ /* @__PURE__ */ jsx(
1743
+ Button,
1744
+ {
1745
+ "aria-pressed": selectedId === message.id,
1746
+ onClick: () => onSelect(message.id),
1747
+ size: "small",
1748
+ variant: "secondary",
1749
+ children: "Details"
1750
+ }
1751
+ )
1752
+ ] }),
1753
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 flex items-center justify-between gap-3 text-sm", children: [
1754
+ /* @__PURE__ */ jsx(Status, { message }),
1755
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: formatDateTime$1(message.created_at) })
1756
+ ] })
1757
+ ]
1758
+ },
1759
+ message.id
1760
+ )) });
1761
+ const MessageTable = ({
1762
+ messages,
1763
+ selectedId,
1764
+ onSelect
1765
+ }) => /* @__PURE__ */ jsx("div", { className: "hidden overflow-x-auto md:block", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-left text-sm", children: [
1766
+ /* @__PURE__ */ jsx("thead", { className: "border-ui-border-base border-b", children: /* @__PURE__ */ jsxs("tr", { className: "text-ui-fg-subtle", children: [
1767
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Art" }),
1768
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Status" }),
1769
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Ressource" }),
1770
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Versuche" }),
1771
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Erstellt" }),
1772
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 text-right font-medium", children: "Aktion" })
1773
+ ] }) }),
1774
+ /* @__PURE__ */ jsx("tbody", { children: messages.map((message) => /* @__PURE__ */ jsxs(
1775
+ "tr",
1776
+ {
1777
+ className: `border-ui-border-base border-b ${selectedId === message.id ? "bg-ui-bg-base-hover" : ""}`,
1778
+ children: [
1779
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-3 font-medium", children: KIND_LABELS[message.kind] }),
1780
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-3", children: /* @__PURE__ */ jsx(Status, { message }) }),
1781
+ /* @__PURE__ */ jsx("td", { className: "max-w-64 truncate px-6 py-3 font-mono text-xs", children: formatResource(message) }),
1782
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-3 tabular-nums", children: message.attempt_count }),
1783
+ /* @__PURE__ */ jsx("td", { className: "whitespace-nowrap px-6 py-3", children: formatDateTime$1(message.created_at) }),
1784
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-3 text-right", children: /* @__PURE__ */ jsx(
1785
+ Button,
1786
+ {
1787
+ "aria-pressed": selectedId === message.id,
1788
+ onClick: () => onSelect(message.id),
1789
+ size: "small",
1790
+ variant: "secondary",
1791
+ children: "Details"
1792
+ }
1793
+ ) })
1794
+ ]
1795
+ },
1796
+ message.id
1797
+ )) })
1798
+ ] }) });
1799
+ const DetailTimestamp = ({
1800
+ label,
1801
+ value
1802
+ }) => /* @__PURE__ */ jsxs("div", { children: [
1803
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: label }),
1804
+ /* @__PURE__ */ jsx(Text, { className: "text-sm", children: formatDateTime$1(value) })
1805
+ ] });
1806
+ const EmailStatusPage = () => {
1807
+ const queryClient = useQueryClient();
1808
+ const [kind, setKind] = useState("all");
1809
+ const [status, setStatus] = useState("all");
1810
+ const [offset, setOffset] = useState(0);
1811
+ const [selectedId, setSelectedId] = useState(null);
1812
+ const [confirmationOpen, setConfirmationOpen] = useState(false);
1813
+ const [retryDecisions, setRetryDecisions] = useState({});
1814
+ const listQueryKey = [
1815
+ "email",
1816
+ "message-list",
1817
+ { kind, status, offset, limit: PAGE_SIZE$1 }
1818
+ ];
1819
+ const messagesQuery = useQuery({
1820
+ queryKey: listQueryKey,
1821
+ queryFn: () => listEmailMessages({
1822
+ kind: kind === "all" ? void 0 : kind,
1823
+ status: status === "all" ? void 0 : status,
1824
+ limit: PAGE_SIZE$1,
1825
+ offset
1826
+ })
1827
+ });
1828
+ const detailQueryKey = ["email", "message-detail", selectedId];
1829
+ const detailQuery = useQuery({
1830
+ queryKey: detailQueryKey,
1831
+ queryFn: () => retrieveEmailMessage(selectedId),
1832
+ enabled: selectedId !== null
1833
+ });
1834
+ const resend = useMutation({
1835
+ mutationFn: (decision) => resendEmailMessage(decision.messageId, {
1836
+ request_id: decision.requestId
1837
+ }),
1838
+ onSuccess: async (_, decision) => {
1839
+ setRetryDecisions((current) => {
1840
+ const next = { ...current };
1841
+ delete next[decision.messageId];
1842
+ return next;
1843
+ });
1844
+ toast.success("Der erneute Versand wurde angenommen.");
1845
+ await Promise.all([
1846
+ queryClient.invalidateQueries({ queryKey: ["email", "message-list"] }),
1847
+ queryClient.invalidateQueries({
1848
+ queryKey: ["email", "message-detail", decision.messageId]
1849
+ })
1850
+ ]);
1851
+ },
1852
+ onError: (_, decision) => {
1853
+ setRetryDecisions((current) => ({
1854
+ ...current,
1855
+ [decision.messageId]: decision
1856
+ }));
1857
+ toast.error("Die Anfrage zum erneuten Versand ist fehlgeschlagen.", {
1858
+ description: "Dieselbe Anfrage kann mit unveränderter UUID sicher wiederholt werden."
1859
+ });
1860
+ }
1861
+ });
1862
+ const messages = messagesQuery.data?.messages ?? [];
1863
+ const count = messagesQuery.data?.count ?? 0;
1864
+ const detail = detailQuery.data?.message;
1865
+ const attempts = detailQuery.data?.attempts ?? [];
1866
+ const retryDecision = selectedId ? retryDecisions[selectedId] : void 0;
1867
+ const selectMessage = (messageId) => {
1868
+ setSelectedId(messageId);
1869
+ };
1870
+ const changePage = (nextOffset) => {
1871
+ setSelectedId(null);
1872
+ setOffset(nextOffset);
1873
+ };
1874
+ const confirmResend = () => {
1875
+ if (!detail || !canResend(detail)) {
1876
+ setConfirmationOpen(false);
1877
+ return;
1878
+ }
1879
+ setConfirmationOpen(false);
1880
+ resend.mutate({ messageId: detail.id, requestId: crypto.randomUUID() });
1881
+ };
1882
+ const renderMessages = () => {
1883
+ if (messagesQuery.isPending) {
1884
+ return /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", role: "status", children: "E-Mails werden geladen." }) });
1885
+ }
1886
+ if (messagesQuery.isError) {
1887
+ return /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", role: "alert", children: "E-Mails konnten nicht geladen werden." }) });
1888
+ }
1889
+ if (!messages.length) {
1890
+ return /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Für diese Filter wurden keine E-Mails gefunden." }) });
1891
+ }
1892
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1893
+ /* @__PURE__ */ jsx(
1894
+ MessageTable,
1895
+ {
1896
+ messages,
1897
+ onSelect: selectMessage,
1898
+ selectedId
1899
+ }
1900
+ ),
1901
+ /* @__PURE__ */ jsx(
1902
+ MessageCards,
1903
+ {
1904
+ messages,
1905
+ onSelect: selectMessage,
1906
+ selectedId
1907
+ }
1908
+ )
1909
+ ] });
1910
+ };
1911
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3", children: [
1912
+ /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
1913
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 px-6 py-4 lg:flex-row lg:items-center lg:justify-between", children: [
1914
+ /* @__PURE__ */ jsxs("div", { children: [
1915
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: "E-Mail-Protokoll" }),
1916
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Sicherer Status und Zustellversuche ohne Empfänger- oder Inhaltsdaten." })
1917
+ ] }),
1918
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [
1919
+ /* @__PURE__ */ jsxs(
1920
+ Select,
1921
+ {
1922
+ value: kind,
1923
+ onValueChange: (value) => {
1924
+ if (isKindFilter(value)) {
1925
+ setKind(value);
1926
+ setOffset(0);
1927
+ setSelectedId(null);
1928
+ }
1929
+ },
1930
+ children: [
1931
+ /* @__PURE__ */ jsx(Select.Trigger, { "aria-label": "E-Mail-Art", className: "sm:w-56", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
1932
+ /* @__PURE__ */ jsxs(Select.Content, { children: [
1933
+ /* @__PURE__ */ jsx(Select.Item, { value: "all", children: "Alle Arten" }),
1934
+ KINDS.map((value) => /* @__PURE__ */ jsx(Select.Item, { value, children: KIND_LABELS[value] }, value))
1935
+ ] })
1936
+ ]
1937
+ }
1938
+ ),
1939
+ /* @__PURE__ */ jsxs(
1940
+ Select,
1941
+ {
1942
+ value: status,
1943
+ onValueChange: (value) => {
1944
+ if (isStatusFilter(value)) {
1945
+ setStatus(value);
1946
+ setOffset(0);
1947
+ setSelectedId(null);
1948
+ }
1949
+ },
1950
+ children: [
1951
+ /* @__PURE__ */ jsx(Select.Trigger, { "aria-label": "E-Mail-Status", className: "sm:w-52", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
1952
+ /* @__PURE__ */ jsxs(Select.Content, { children: [
1953
+ /* @__PURE__ */ jsx(Select.Item, { value: "all", children: "Alle Status" }),
1954
+ STATUSES.map((value) => /* @__PURE__ */ jsx(Select.Item, { value, children: STATUS_LABELS[value] }, value))
1955
+ ] })
1956
+ ]
1957
+ }
1958
+ )
1959
+ ] })
1960
+ ] }),
1961
+ renderMessages(),
1962
+ !messagesQuery.isPending && !messagesQuery.isError && count > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 px-6 py-4 sm:flex-row sm:items-center sm:justify-between", children: [
1963
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle text-sm", children: [
1964
+ offset + 1,
1965
+ "-",
1966
+ offset + messages.length,
1967
+ " von ",
1968
+ count
1969
+ ] }),
1970
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1971
+ /* @__PURE__ */ jsx(
1972
+ Button,
1973
+ {
1974
+ disabled: offset === 0,
1975
+ onClick: () => changePage(Math.max(0, offset - PAGE_SIZE$1)),
1976
+ size: "small",
1977
+ variant: "secondary",
1978
+ children: "Zurück"
1979
+ }
1980
+ ),
1981
+ /* @__PURE__ */ jsx(
1982
+ Button,
1983
+ {
1984
+ disabled: offset >= MAX_PAGE_OFFSET$1 || offset + messages.length >= count,
1985
+ onClick: () => changePage(Math.min(MAX_PAGE_OFFSET$1, offset + PAGE_SIZE$1)),
1986
+ size: "small",
1987
+ variant: "secondary",
1988
+ children: "Weiter"
1989
+ }
1990
+ )
1991
+ ] })
1992
+ ] }) : null
1993
+ ] }),
1994
+ selectedId ? /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
1995
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 px-6 py-4 sm:flex-row sm:items-start sm:justify-between", children: [
1996
+ /* @__PURE__ */ jsxs("div", { children: [
1997
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Zustellstatus" }),
1998
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Autoritativer Status und sichere Versuchsdaten." })
1999
+ ] }),
2000
+ detail && canResend(detail) ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 sm:items-end", children: [
2001
+ /* @__PURE__ */ jsx(
2002
+ Button,
2003
+ {
2004
+ disabled: resend.isPending,
2005
+ onClick: () => setConfirmationOpen(true),
2006
+ size: "small",
2007
+ variant: "secondary",
2008
+ children: "Erneut senden"
2009
+ }
2010
+ ),
2011
+ retryDecision ? /* @__PURE__ */ jsx(
2012
+ Button,
2013
+ {
2014
+ disabled: resend.isPending,
2015
+ onClick: () => resend.mutate(retryDecision),
2016
+ size: "small",
2017
+ variant: "transparent",
2018
+ children: "Gleiche Anfrage wiederholen"
2019
+ }
2020
+ ) : null
2021
+ ] }) : null
2022
+ ] }),
2023
+ detailQuery.isPending ? /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", role: "status", children: "Zustellversuche werden geladen." }) }) : detailQuery.isError ? /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", role: "alert", children: "Details konnten nicht geladen werden." }) }) : detail ? /* @__PURE__ */ jsxs(Fragment, { children: [
2024
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-4 px-6 py-5 sm:grid-cols-2 lg:grid-cols-4", children: [
2025
+ /* @__PURE__ */ jsxs("div", { children: [
2026
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: "Art" }),
2027
+ /* @__PURE__ */ jsx(Text, { className: "text-sm", children: KIND_LABELS[detail.kind] })
2028
+ ] }),
2029
+ /* @__PURE__ */ jsxs("div", { children: [
2030
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: "Status" }),
2031
+ /* @__PURE__ */ jsx(Text, { className: "text-sm", children: /* @__PURE__ */ jsx(Status, { message: detail }) })
2032
+ ] }),
2033
+ /* @__PURE__ */ jsxs("div", { className: "sm:col-span-2", children: [
2034
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: "Ressource" }),
2035
+ /* @__PURE__ */ jsx(Text, { className: "break-all font-mono text-xs", children: formatResource(detail) })
2036
+ ] }),
2037
+ /* @__PURE__ */ jsx(DetailTimestamp, { label: "Erstellt", value: detail.created_at }),
2038
+ /* @__PURE__ */ jsx(
2039
+ DetailTimestamp,
2040
+ {
2041
+ label: "Aktualisiert",
2042
+ value: detail.updated_at
2043
+ }
2044
+ ),
2045
+ /* @__PURE__ */ jsx(DetailTimestamp, { label: "Versendet", value: detail.sent_at }),
2046
+ /* @__PURE__ */ jsx(
2047
+ DetailTimestamp,
2048
+ {
2049
+ label: "Fehlgeschlagen",
2050
+ value: detail.failed_at
2051
+ }
2052
+ ),
2053
+ /* @__PURE__ */ jsx(
2054
+ DetailTimestamp,
2055
+ {
2056
+ label: "Nächster Versuch",
2057
+ value: detail.next_attempt_at
2058
+ }
2059
+ ),
2060
+ detail.terminal_code ? /* @__PURE__ */ jsxs("div", { children: [
2061
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle text-xs", children: "Statuscode" }),
2062
+ /* @__PURE__ */ jsx(Text, { className: "font-mono text-xs", children: detail.terminal_code })
2063
+ ] }) : null
2064
+ ] }),
2065
+ /* @__PURE__ */ jsxs("div", { className: "px-6 py-5", children: [
2066
+ /* @__PURE__ */ jsx(Heading, { level: "h3", children: "Zustellversuche" }),
2067
+ attempts.length ? /* @__PURE__ */ jsx("div", { className: "mt-3 grid gap-3", children: attempts.map((attempt) => /* @__PURE__ */ jsxs(
2068
+ "div",
2069
+ {
2070
+ className: "border-ui-border-base grid gap-3 rounded-md border p-4 sm:grid-cols-[auto_1fr_auto] sm:items-center",
2071
+ children: [
2072
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2073
+ "Versuch ",
2074
+ attempt.attempt_number
2075
+ ] }),
2076
+ /* @__PURE__ */ jsxs("div", { children: [
2077
+ /* @__PURE__ */ jsx(Text, { className: "text-sm", children: ATTEMPT_STATUS_LABELS[attempt.status] }),
2078
+ attempt.failure_code ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle font-mono text-xs", children: attempt.failure_code }) : null
2079
+ ] }),
2080
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle text-xs sm:text-right", children: [
2081
+ formatDateTime$1(attempt.started_at),
2082
+ attempt.finished_at ? ` · ${formatDateTime$1(attempt.finished_at)}` : ""
2083
+ ] })
2084
+ ]
2085
+ },
2086
+ attempt.id
2087
+ )) }) : /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle mt-3", children: "Es gibt noch keinen Zustellversuch." })
2088
+ ] })
2089
+ ] }) : null
2090
+ ] }) : null,
2091
+ /* @__PURE__ */ jsx(Prompt, { open: confirmationOpen, onOpenChange: setConfirmationOpen, children: /* @__PURE__ */ jsxs(Prompt.Content, { children: [
2092
+ /* @__PURE__ */ jsxs(Prompt.Header, { children: [
2093
+ /* @__PURE__ */ jsx(Prompt.Title, { children: "E-Mail erneut senden?" }),
2094
+ /* @__PURE__ */ jsx(Prompt.Description, { children: "Diese bewusste Entscheidung erzeugt einen neuen Versand mit einer neuen Request-UUID. Der Server prüft Status und E-Mail-Art erneut." })
2095
+ ] }),
2096
+ /* @__PURE__ */ jsxs(Prompt.Footer, { children: [
2097
+ /* @__PURE__ */ jsx(Prompt.Cancel, { children: "Abbrechen" }),
2098
+ /* @__PURE__ */ jsx(Prompt.Action, { onClick: confirmResend, children: "Erneut senden" })
2099
+ ] })
2100
+ ] }) })
2101
+ ] });
2102
+ };
2103
+ const validateTermsPdf = (file) => {
2104
+ if (!file.name.toLowerCase().endsWith(".pdf") || file.type !== "" && file.type !== "application/pdf") {
2105
+ return "Bitte eine PDF-Datei auswählen.";
2106
+ }
2107
+ if (file.size === 0) {
2108
+ return "Die PDF-Datei darf nicht leer sein.";
2109
+ }
2110
+ if (file.size > EMAIL_TERMS_MAX_PDF_BYTES) {
2111
+ return "Die PDF-Datei darf maximal 5 MiB groß sein.";
2112
+ }
2113
+ return null;
2114
+ };
2115
+ const encodeCanonicalBase64 = (buffer) => {
2116
+ const bytes = new Uint8Array(buffer);
2117
+ const chunkSize = 32768;
2118
+ let binary = "";
2119
+ for (let offset = 0; offset < bytes.length; offset += chunkSize) {
2120
+ binary += String.fromCharCode(
2121
+ ...bytes.subarray(offset, offset + chunkSize)
2122
+ );
2123
+ }
2124
+ return btoa(binary);
2125
+ };
2126
+ const readPdfAsCanonicalBase64 = async (file) => encodeCanonicalBase64(await file.arrayBuffer());
2127
+ const PAGE_SIZE = 20;
2128
+ const MAX_PAGE_OFFSET = 1e4;
2129
+ const formatDateTime = (value) => {
2130
+ const date = new Date(value);
2131
+ if (Number.isNaN(date.getTime())) {
2132
+ return "-";
2133
+ }
2134
+ return new Intl.DateTimeFormat("de-AT", {
2135
+ dateStyle: "medium",
2136
+ timeStyle: "short"
2137
+ }).format(date);
2138
+ };
2139
+ const formatFileSize = (bytes) => {
2140
+ if (bytes < 1024) {
2141
+ return `${bytes} B`;
2142
+ }
2143
+ const divisor = bytes < 1024 * 1024 ? 1024 : 1024 * 1024;
2144
+ const unit = bytes < 1024 * 1024 ? "KiB" : "MiB";
2145
+ return `${new Intl.NumberFormat("de-AT", {
2146
+ maximumFractionDigits: 1
2147
+ }).format(bytes / divisor)} ${unit}`;
2148
+ };
2149
+ const newestFirst = (versions) => [...versions].sort(
2150
+ (left, right) => right.effective_at.localeCompare(left.effective_at) || right.created_at.localeCompare(left.created_at)
2151
+ );
2152
+ const EmailTermsVersionsSection = () => {
2153
+ const queryClient = useQueryClient();
2154
+ const fileInputRef = useRef(null);
2155
+ const [effectiveAt, setEffectiveAt] = useState("");
2156
+ const [file, setFile] = useState(null);
2157
+ const [formError, setFormError] = useState(null);
2158
+ const [offset, setOffset] = useState(0);
2159
+ const termsQueryKey = [
2160
+ "email",
2161
+ "terms-versions",
2162
+ { limit: PAGE_SIZE, offset }
2163
+ ];
2164
+ const termsQuery = useQuery({
2165
+ queryKey: termsQueryKey,
2166
+ queryFn: () => listEmailTermsVersions({ limit: PAGE_SIZE, offset })
2167
+ });
2168
+ const createTermsVersion = useMutation({
2169
+ mutationFn: async ({
2170
+ effectiveAt: effectiveAtValue,
2171
+ file: selectedFile,
2172
+ requestId
2173
+ }) => {
2174
+ const body = {
2175
+ request_id: requestId,
2176
+ filename: selectedFile.name,
2177
+ effective_at: effectiveAtValue,
2178
+ content_base64: await readPdfAsCanonicalBase64(selectedFile)
2179
+ };
2180
+ return createEmailTermsVersion(body);
2181
+ },
2182
+ onSuccess: async ({ created }) => {
2183
+ setFile(null);
2184
+ setEffectiveAt("");
2185
+ setFormError(null);
2186
+ setOffset(0);
2187
+ if (fileInputRef.current) {
2188
+ fileInputRef.current.value = "";
2189
+ }
2190
+ toast.success(
2191
+ created ? "Die AGB-Version wurde hochgeladen." : "Diese AGB-Version war bereits vorhanden."
2192
+ );
2193
+ await queryClient.invalidateQueries({
2194
+ queryKey: ["email", "terms-versions"]
2195
+ });
2196
+ },
2197
+ onError: () => {
2198
+ toast.error("Die AGB-Version konnte nicht hochgeladen werden.");
2199
+ }
2200
+ });
2201
+ const downloadTermsVersion = useMutation({
2202
+ mutationFn: async (version) => ({
2203
+ blob: await downloadEmailTermsVersion(version.id),
2204
+ version
2205
+ }),
2206
+ onSuccess: ({ blob, version }) => {
2207
+ const url = URL.createObjectURL(blob);
2208
+ const link = document.createElement("a");
2209
+ link.href = url;
2210
+ link.download = version.filename;
2211
+ document.body.appendChild(link);
2212
+ link.click();
2213
+ link.remove();
2214
+ window.setTimeout(() => URL.revokeObjectURL(url), 0);
2215
+ },
2216
+ onError: () => {
2217
+ toast.error("Die AGB-PDF konnte nicht heruntergeladen werden.");
2218
+ }
2219
+ });
2220
+ const versions = newestFirst(termsQuery.data?.terms_versions ?? []);
2221
+ const count = termsQuery.data?.count ?? 0;
2222
+ const submit = (event) => {
2223
+ event.preventDefault();
2224
+ if (!file) {
2225
+ setFormError("Bitte eine PDF-Datei auswählen.");
2226
+ return;
2227
+ }
2228
+ const fileError = validateTermsPdf(file);
2229
+ if (fileError) {
2230
+ setFormError(fileError);
2231
+ return;
2232
+ }
2233
+ const date = new Date(effectiveAt);
2234
+ if (!effectiveAt || Number.isNaN(date.getTime())) {
2235
+ setFormError("Bitte einen gültigen Wirksamkeitszeitpunkt angeben.");
2236
+ return;
2237
+ }
2238
+ setFormError(null);
2239
+ createTermsVersion.mutate({
2240
+ effectiveAt: date.toISOString(),
2241
+ file,
2242
+ requestId: crypto.randomUUID()
2243
+ });
2244
+ };
2245
+ return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
2246
+ /* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
2247
+ /* @__PURE__ */ jsx(Heading, { level: "h2", children: "AGB/PDF-Versionen" }),
2248
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Globale, unveränderliche AGB-Versionen für den E-Mail-Versand verwalten." })
2249
+ ] }),
2250
+ /* @__PURE__ */ jsxs("form", { className: "grid gap-4 px-6 py-5", onSubmit: submit, children: [
2251
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-4 md:grid-cols-[minmax(0,1fr)_minmax(15rem,0.6fr)_auto] md:items-end", children: [
2252
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
2253
+ /* @__PURE__ */ jsx(Label, { htmlFor: "email-terms-pdf", children: "AGB als PDF" }),
2254
+ /* @__PURE__ */ jsx(
2255
+ Input,
2256
+ {
2257
+ accept: "application/pdf,.pdf",
2258
+ "aria-describedby": `email-terms-pdf-help${formError ? " email-terms-form-error" : ""}`,
2259
+ disabled: createTermsVersion.isPending,
2260
+ id: "email-terms-pdf",
2261
+ onChange: (event) => {
2262
+ const selectedFile = event.target.files?.[0] ?? null;
2263
+ setFile(selectedFile);
2264
+ setFormError(
2265
+ selectedFile ? validateTermsPdf(selectedFile) : null
2266
+ );
2267
+ },
2268
+ ref: fileInputRef,
2269
+ type: "file"
2270
+ }
2271
+ )
2272
+ ] }),
2273
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-2", children: [
2274
+ /* @__PURE__ */ jsx(Label, { htmlFor: "email-terms-effective-at", children: "Wirksam ab" }),
2275
+ /* @__PURE__ */ jsx(
2276
+ Input,
2277
+ {
2278
+ "aria-describedby": `email-terms-effective-at-help${formError ? " email-terms-form-error" : ""}`,
2279
+ disabled: createTermsVersion.isPending,
2280
+ id: "email-terms-effective-at",
2281
+ onChange: (event) => setEffectiveAt(event.target.value),
2282
+ type: "datetime-local",
2283
+ value: effectiveAt
2284
+ }
2285
+ )
2286
+ ] }),
2287
+ /* @__PURE__ */ jsx(
2288
+ Button,
2289
+ {
2290
+ disabled: createTermsVersion.isPending,
2291
+ isLoading: createTermsVersion.isPending,
2292
+ type: "submit",
2293
+ children: "Version hochladen"
2294
+ }
2295
+ )
2296
+ ] }),
2297
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-1", children: [
2298
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle text-xs", id: "email-terms-pdf-help", children: [
2299
+ "Nur PDF, maximal ",
2300
+ formatFileSize(EMAIL_TERMS_MAX_PDF_BYTES),
2301
+ "."
2302
+ ] }),
2303
+ /* @__PURE__ */ jsx(
2304
+ Text,
2305
+ {
2306
+ className: "text-ui-fg-subtle text-xs",
2307
+ id: "email-terms-effective-at-help",
2308
+ children: "Der Zeitpunkt wird aus der lokalen Zeitzone in UTC übernommen."
2309
+ }
2310
+ ),
2311
+ formError ? /* @__PURE__ */ jsx(
2312
+ Text,
2313
+ {
2314
+ className: "text-ui-fg-error text-sm",
2315
+ id: "email-terms-form-error",
2316
+ role: "alert",
2317
+ children: formError
2318
+ }
2319
+ ) : null
2320
+ ] })
2321
+ ] }),
2322
+ /* @__PURE__ */ jsxs("div", { children: [
2323
+ /* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
2324
+ /* @__PURE__ */ jsx(Heading, { level: "h3", children: "Hinterlegte Versionen" }),
2325
+ /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Neueste Wirksamkeit zuerst. Downloads erfolgen authentifiziert." })
2326
+ ] }),
2327
+ termsQuery.isPending ? /* @__PURE__ */ jsx("div", { className: "px-6 pb-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", role: "status", children: "AGB-Versionen werden geladen." }) }) : termsQuery.isError ? /* @__PURE__ */ jsx("div", { className: "px-6 pb-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", role: "alert", children: "AGB-Versionen konnten nicht geladen werden." }) }) : versions.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
2328
+ /* @__PURE__ */ jsx("div", { className: "hidden overflow-x-auto md:block", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-left text-sm", children: [
2329
+ /* @__PURE__ */ jsx("thead", { className: "border-ui-border-base border-y", children: /* @__PURE__ */ jsxs("tr", { className: "text-ui-fg-subtle", children: [
2330
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Dateiname" }),
2331
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Wirksam ab" }),
2332
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Größe" }),
2333
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 font-medium", children: "Erstellt" }),
2334
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-3 text-right font-medium", children: "Aktion" })
2335
+ ] }) }),
2336
+ /* @__PURE__ */ jsx("tbody", { children: versions.map((version) => {
2337
+ const isDownloading = downloadTermsVersion.isPending && downloadTermsVersion.variables?.id === version.id;
2338
+ return /* @__PURE__ */ jsxs(
2339
+ "tr",
2340
+ {
2341
+ className: "border-ui-border-base border-b",
2342
+ children: [
2343
+ /* @__PURE__ */ jsx("td", { className: "max-w-80 break-all px-6 py-3 font-medium", children: version.filename }),
2344
+ /* @__PURE__ */ jsx("td", { className: "whitespace-nowrap px-6 py-3", children: formatDateTime(version.effective_at) }),
2345
+ /* @__PURE__ */ jsx("td", { className: "whitespace-nowrap px-6 py-3 tabular-nums", children: formatFileSize(version.byte_size) }),
2346
+ /* @__PURE__ */ jsx("td", { className: "whitespace-nowrap px-6 py-3", children: formatDateTime(version.created_at) }),
2347
+ /* @__PURE__ */ jsx("td", { className: "px-6 py-3 text-right", children: /* @__PURE__ */ jsx(
2348
+ Button,
2349
+ {
2350
+ "aria-label": `${version.filename} herunterladen`,
2351
+ disabled: downloadTermsVersion.isPending,
2352
+ isLoading: isDownloading,
2353
+ onClick: () => downloadTermsVersion.mutate(version),
2354
+ size: "small",
2355
+ variant: "secondary",
2356
+ children: "Herunterladen"
2357
+ }
2358
+ ) })
2359
+ ]
2360
+ },
2361
+ version.id
2362
+ );
2363
+ }) })
2364
+ ] }) }),
2365
+ /* @__PURE__ */ jsx("div", { className: "grid gap-3 px-4 py-4 md:hidden", children: versions.map((version) => {
2366
+ const isDownloading = downloadTermsVersion.isPending && downloadTermsVersion.variables?.id === version.id;
2367
+ return /* @__PURE__ */ jsxs(
2368
+ "div",
2369
+ {
2370
+ className: "border-ui-border-base grid gap-3 rounded-md border p-4",
2371
+ children: [
2372
+ /* @__PURE__ */ jsx(Text, { className: "break-all font-medium", children: version.filename }),
2373
+ /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-2 gap-3 text-sm", children: [
2374
+ /* @__PURE__ */ jsxs("div", { children: [
2375
+ /* @__PURE__ */ jsx("dt", { className: "text-ui-fg-subtle text-xs", children: "Wirksam ab" }),
2376
+ /* @__PURE__ */ jsx("dd", { children: formatDateTime(version.effective_at) })
2377
+ ] }),
2378
+ /* @__PURE__ */ jsxs("div", { children: [
2379
+ /* @__PURE__ */ jsx("dt", { className: "text-ui-fg-subtle text-xs", children: "Größe" }),
2380
+ /* @__PURE__ */ jsx("dd", { children: formatFileSize(version.byte_size) })
2381
+ ] }),
2382
+ /* @__PURE__ */ jsxs("div", { className: "col-span-2", children: [
2383
+ /* @__PURE__ */ jsx("dt", { className: "text-ui-fg-subtle text-xs", children: "Erstellt" }),
2384
+ /* @__PURE__ */ jsx("dd", { children: formatDateTime(version.created_at) })
2385
+ ] })
2386
+ ] }),
2387
+ /* @__PURE__ */ jsx(
2388
+ Button,
2389
+ {
2390
+ "aria-label": `${version.filename} herunterladen`,
2391
+ disabled: downloadTermsVersion.isPending,
2392
+ isLoading: isDownloading,
2393
+ onClick: () => downloadTermsVersion.mutate(version),
2394
+ size: "small",
2395
+ variant: "secondary",
2396
+ children: "Herunterladen"
2397
+ }
2398
+ )
2399
+ ]
2400
+ },
2401
+ version.id
2402
+ );
2403
+ }) })
2404
+ ] }) : /* @__PURE__ */ jsx("div", { className: "px-6 pb-6", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Es wurde noch keine AGB-Version hinterlegt." }) }),
2405
+ !termsQuery.isPending && !termsQuery.isError && count > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 px-6 py-4 sm:flex-row sm:items-center sm:justify-between", children: [
2406
+ /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-subtle text-sm", children: [
2407
+ offset + 1,
2408
+ "-",
2409
+ offset + versions.length,
2410
+ " von ",
2411
+ count
2412
+ ] }),
2413
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2414
+ /* @__PURE__ */ jsx(
2415
+ Button,
2416
+ {
2417
+ disabled: offset === 0,
2418
+ onClick: () => setOffset(Math.max(0, offset - PAGE_SIZE)),
2419
+ size: "small",
2420
+ variant: "secondary",
2421
+ children: "Neuere"
2422
+ }
2423
+ ),
2424
+ /* @__PURE__ */ jsx(
2425
+ Button,
2426
+ {
2427
+ disabled: offset >= MAX_PAGE_OFFSET || offset + versions.length >= count,
2428
+ onClick: () => setOffset(Math.min(MAX_PAGE_OFFSET, offset + PAGE_SIZE)),
2429
+ size: "small",
2430
+ variant: "secondary",
2431
+ children: "Ältere"
2432
+ }
2433
+ )
2434
+ ] })
2435
+ ] }) : null
2436
+ ] })
2437
+ ] });
2438
+ };
2439
+ const EmailPluginContent = () => {
2440
+ const { enabled, isPending, isError } = usePluginFeatureEnabled("email");
2441
+ if (isPending || isError) {
2442
+ return null;
2443
+ }
2444
+ return enabled ? /* @__PURE__ */ jsxs(Fragment, { children: [
2445
+ /* @__PURE__ */ jsx(EmailTermsVersionsSection, {}),
2446
+ /* @__PURE__ */ jsx(EmailStatusPage, {})
2447
+ ] }) : /* @__PURE__ */ jsx(PluginFeatureDisabledNotice, { pluginKey: "email" });
2448
+ };
2449
+ const EmailPluginRoute = () => /* @__PURE__ */ jsxs(PluginPageShell, { pluginKey: "email", children: [
2450
+ /* @__PURE__ */ jsx(PluginFeatureSections, { pluginKey: "email" }),
2451
+ /* @__PURE__ */ jsx(EmailPluginContent, {})
2452
+ ] });
922
2453
  const PluginDetailPage = () => {
923
2454
  const { plugin_key: pluginKey = "" } = useParams();
924
2455
  return /* @__PURE__ */ jsx(PluginPageShell, { pluginKey, children: /* @__PURE__ */ jsx(PluginFeatureSections, { pluginKey }) });
925
2456
  };
926
- const widgetModule = { widgets: [] };
2457
+ const widgetModule = { widgets: [
2458
+ {
2459
+ Component: OrderDocumentsWidget,
2460
+ zone: ["order.details.side.after"],
2461
+ widgetId: "Widget-93c9"
2462
+ },
2463
+ {
2464
+ Component: OrderPackingListsWidget,
2465
+ zone: ["order.details.side.after"],
2466
+ widgetId: "Widget-381c"
2467
+ }
2468
+ ] };
927
2469
  const routeModule = {
928
2470
  routes: [
929
2471
  {
@@ -931,6 +2473,10 @@ const routeModule = {
931
2473
  path: "/settings/hartl-services",
932
2474
  handle: { label: config.label, translationNs: config.translationNs }
933
2475
  },
2476
+ {
2477
+ Component: EmailPluginRoute,
2478
+ path: "/settings/hartl-services/email"
2479
+ },
934
2480
  {
935
2481
  Component: PluginDetailPage,
936
2482
  path: "/settings/hartl-services/plugin/:plugin_key"