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