@hartl-services/medusa-base 0.3.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 (323) hide show
  1. package/.medusa/server/src/admin/index.js +2164 -29
  2. package/.medusa/server/src/admin/index.mjs +2166 -31
  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/admin/plugin-features/[plugin_key]/actions/[action_key]/route.js +31 -0
  16. package/.medusa/server/src/api/admin/plugin-features/[plugin_key]/actions/[action_key]/runs/route.js +16 -0
  17. package/.medusa/server/src/api/admin/plugin-features/[plugin_key]/route.js +14 -0
  18. package/.medusa/server/src/api/admin/plugin-features/[plugin_key]/settings/route.js +22 -0
  19. package/.medusa/server/src/api/admin/plugin-features/route.js +6 -4
  20. package/.medusa/server/src/api/document-download-response.js +16 -0
  21. package/.medusa/server/src/api/document-response.js +23 -0
  22. package/.medusa/server/src/api/files/[asset]/route.js +24 -0
  23. package/.medusa/server/src/api/files/file-response.js +43 -0
  24. package/.medusa/server/src/api/files/gateway-options.js +31 -0
  25. package/.medusa/server/src/api/files/private/[token]/route.js +29 -0
  26. package/.medusa/server/src/api/files/upload/[token]/route.js +66 -0
  27. package/.medusa/server/src/api/middlewares.js +186 -5
  28. package/.medusa/server/src/api/packing-list-response.js +22 -0
  29. package/.medusa/server/src/api/plugin-actions.js +221 -0
  30. package/.medusa/server/src/api/plugin-features-http.js +67 -8
  31. package/.medusa/server/src/api/route.js +27 -0
  32. package/.medusa/server/src/api/store/documents/[id]/download/route.js +21 -0
  33. package/.medusa/server/src/api/store/documents/[id]/route.js +15 -0
  34. package/.medusa/server/src/api/store/documents/route.js +11 -0
  35. package/.medusa/server/src/api/terms-download-response.js +12 -0
  36. package/.medusa/server/src/documents/config/index.js +18 -0
  37. package/.medusa/server/src/documents/paths/documents.js +6 -0
  38. package/.medusa/server/src/documents/paths/index.js +18 -0
  39. package/.medusa/server/src/documents/plugin-features.js +24 -0
  40. package/.medusa/server/src/documents/schemas/documents.js +18 -0
  41. package/.medusa/server/src/documents/schemas/index.js +18 -0
  42. package/.medusa/server/src/documents/scripts/verify-documents-file-storage.js +55 -0
  43. package/.medusa/server/src/documents/templates/financial-document.js +142 -0
  44. package/.medusa/server/src/documents/templates/format.js +31 -0
  45. package/.medusa/server/src/documents/templates/html-factory.js +40 -0
  46. package/.medusa/server/src/documents/templates/html-utils.js +13 -0
  47. package/.medusa/server/src/documents/templates/layout.js +97 -0
  48. package/.medusa/server/src/documents/templates/packing-list.js +50 -0
  49. package/.medusa/server/src/documents/types/admin-api.js +3 -0
  50. package/.medusa/server/src/documents/types/document-summary.js +3 -0
  51. package/.medusa/server/src/documents/types/documents.js +3 -0
  52. package/.medusa/server/src/documents/types/html-factory.js +6 -0
  53. package/.medusa/server/src/documents/types/index.js +22 -0
  54. package/.medusa/server/src/documents/types/store-api.js +3 -0
  55. package/.medusa/server/src/documents/utils/document-merchant.js +22 -0
  56. package/.medusa/server/src/documents/utils/html-to-pdf.js +61 -0
  57. package/.medusa/server/src/documents/utils/private-file-storage.js +64 -0
  58. package/.medusa/server/src/documents/utils/resolve-services.js +7 -0
  59. package/.medusa/server/src/email/application/handle-invite-event.js +312 -0
  60. package/.medusa/server/src/email/application/handle-password-reset-event.js +354 -0
  61. package/.medusa/server/src/email/config/index.js +84 -0
  62. package/.medusa/server/src/email/config/notification-module.js +20 -0
  63. package/.medusa/server/src/email/domain/business-keys.js +50 -0
  64. package/.medusa/server/src/email/domain/documents-fact-fingerprint.js +7 -0
  65. package/.medusa/server/src/email/domain/event-schemas.js +36 -0
  66. package/.medusa/server/src/email/domain/failure-classification.js +53 -0
  67. package/.medusa/server/src/email/plugin-features.js +31 -0
  68. package/.medusa/server/src/email/rendering/default-templates.js +91 -0
  69. package/.medusa/server/src/email/rendering/render-email.js +37 -0
  70. package/.medusa/server/src/email/rendering/resolve-shop-configuration.js +48 -0
  71. package/.medusa/server/src/email/types/email-kinds.js +18 -0
  72. package/.medusa/server/src/email/types/index.js +21 -0
  73. package/.medusa/server/src/email/types/shop-configuration.js +3 -0
  74. package/.medusa/server/src/email/types/smtp-configuration.js +3 -0
  75. package/.medusa/server/src/email/types/template-data.js +79 -0
  76. package/.medusa/server/src/files/config/index.js +256 -0
  77. package/.medusa/server/src/files/gateway/index.js +115 -0
  78. package/.medusa/server/src/files/types/index.js +6 -0
  79. package/.medusa/server/src/files/types/public.js +6 -0
  80. package/.medusa/server/src/jobs/document-fact-publication-reconciliation.js +18 -0
  81. package/.medusa/server/src/jobs/document-resolution-reconciliation.js +20 -0
  82. package/.medusa/server/src/jobs/packing-list-reconciliation.js +49 -0
  83. package/.medusa/server/src/jobs/reconcile-email-attempts.js +63 -0
  84. package/.medusa/server/src/jobs/reconcile-pending-email-messages.js +41 -0
  85. package/.medusa/server/src/jobs/retry-email-messages.js +27 -0
  86. package/.medusa/server/src/migration-scripts/dismiss-orphaned-cart-promotion-links.js +26 -0
  87. package/.medusa/server/src/modules/documents/domain/cancellation-snapshot.js +97 -0
  88. package/.medusa/server/src/modules/documents/domain/document-number.js +36 -0
  89. package/.medusa/server/src/modules/documents/domain/document-resolution.js +24 -0
  90. package/.medusa/server/src/modules/documents/domain/issuance-rules.js +37 -0
  91. package/.medusa/server/src/modules/documents/domain/merchant.js +86 -0
  92. package/.medusa/server/src/modules/documents/domain/options.js +40 -0
  93. package/.medusa/server/src/modules/documents/domain/packing-list.js +90 -0
  94. package/.medusa/server/src/modules/documents/domain/snapshot-normalization.js +17 -0
  95. package/.medusa/server/src/modules/documents/domain/tax-breakdown.js +66 -0
  96. package/.medusa/server/src/modules/documents/index.js +15 -0
  97. package/.medusa/server/src/modules/documents/loaders/assert-private-file-storage.js +20 -0
  98. package/.medusa/server/src/modules/documents/migrations/Migration20260827061749.js +75 -0
  99. package/.medusa/server/src/modules/documents/migrations/Migration20260830111207.js +28 -0
  100. package/.medusa/server/src/modules/documents/models/document-artifact.js +25 -0
  101. package/.medusa/server/src/modules/documents/models/document-number-sequence.js +29 -0
  102. package/.medusa/server/src/modules/documents/models/document.js +82 -0
  103. package/.medusa/server/src/modules/documents/models/order-cancellation-resolution.js +51 -0
  104. package/.medusa/server/src/modules/documents/models/packing-list-revision.js +36 -0
  105. package/.medusa/server/src/modules/documents/models/packing-list.js +27 -0
  106. package/.medusa/server/src/modules/documents/models/refund-document-resolution.js +66 -0
  107. package/.medusa/server/src/modules/documents/models/shipment-invoice-assignment.js +51 -0
  108. package/.medusa/server/src/modules/documents/models/shipment-invoice-coordinator.js +44 -0
  109. package/.medusa/server/src/modules/documents/service.js +1701 -0
  110. package/.medusa/server/src/modules/email/domain/attachment.js +25 -0
  111. package/.medusa/server/src/modules/email/domain/message-state.js +69 -0
  112. package/.medusa/server/src/modules/email/index.js +13 -0
  113. package/.medusa/server/src/modules/email/migrations/Migration20260826173422.js +32 -0
  114. package/.medusa/server/src/modules/email/migrations/Migration20260827172945.js +16 -0
  115. package/.medusa/server/src/modules/email/migrations/Migration20260827194804.js +22 -0
  116. package/.medusa/server/src/modules/email/migrations/Migration20260906195205.js +16 -0
  117. package/.medusa/server/src/modules/email/models/email-attempt.js +56 -0
  118. package/.medusa/server/src/modules/email/models/email-message.js +71 -0
  119. package/.medusa/server/src/modules/email/models/email-terms-version.js +37 -0
  120. package/.medusa/server/src/modules/email/service.js +1285 -0
  121. package/.medusa/server/src/modules/plugin-features/domain/plugin-action-runs.js +92 -0
  122. package/.medusa/server/src/modules/plugin-features/domain/plugin-settings.js +213 -0
  123. package/.medusa/server/src/modules/plugin-features/domain/secret-box.js +56 -0
  124. package/.medusa/server/src/modules/plugin-features/migrations/Migration20260928205031.js +16 -0
  125. package/.medusa/server/src/modules/plugin-features/migrations/Migration20260928215428.js +17 -0
  126. package/.medusa/server/src/modules/plugin-features/models/plugin-action-run.js +43 -0
  127. package/.medusa/server/src/modules/plugin-features/models/plugin-setting-state.js +32 -0
  128. package/.medusa/server/src/modules/plugin-features/service.js +419 -17
  129. package/.medusa/server/src/providers/s3-cache/cache/atomic-write.js +25 -0
  130. package/.medusa/server/src/providers/s3-cache/cache/cache-manager.js +115 -0
  131. package/.medusa/server/src/providers/s3-cache/cache/keyed-lock.js +28 -0
  132. package/.medusa/server/src/providers/s3-cache/index.js +8 -0
  133. package/.medusa/server/src/providers/s3-cache/object-key.js +53 -0
  134. package/.medusa/server/src/providers/s3-cache/s3-cache-file.js +229 -0
  135. package/.medusa/server/src/providers/s3-cache/s3-object-store.js +86 -0
  136. package/.medusa/server/src/providers/smtp/index.js +8 -0
  137. package/.medusa/server/src/providers/smtp/service.js +236 -0
  138. package/.medusa/server/src/providers/smtp/types.js +11 -0
  139. package/.medusa/server/src/public/action-progress.js +67 -0
  140. package/.medusa/server/src/public/config.js +186 -0
  141. package/.medusa/server/src/public/descriptor.js +199 -2
  142. package/.medusa/server/src/public/effective-features.js +9 -5
  143. package/.medusa/server/src/public/enforcement.js +18 -8
  144. package/.medusa/server/src/public/gateway.js +19 -0
  145. package/.medusa/server/src/public/index.js +10 -2
  146. package/.medusa/server/src/public/instrumentation.js +56 -0
  147. package/.medusa/server/src/public/module-access.js +14 -0
  148. package/.medusa/server/src/public/settings.js +17 -0
  149. package/.medusa/server/src/public/shop-config.js +12 -0
  150. package/.medusa/server/src/public/shop-master-data.js +95 -0
  151. package/.medusa/server/src/public/shop-types.js +24 -0
  152. package/.medusa/server/src/shop-config/build-food-shop-config.js +248 -0
  153. package/.medusa/server/src/shop-config/options.js +71 -0
  154. package/.medusa/server/src/subscribers/affiliate-consignment-reminder-due.js +26 -0
  155. package/.medusa/server/src/subscribers/documents-order-canceled.js +24 -0
  156. package/.medusa/server/src/subscribers/documents-order-cancellation-ready.js +26 -0
  157. package/.medusa/server/src/subscribers/documents-refund-ready.js +24 -0
  158. package/.medusa/server/src/subscribers/documents-shipment-created.js +36 -0
  159. package/.medusa/server/src/subscribers/documents-shipment-invoice-assignment-decided.js +26 -0
  160. package/.medusa/server/src/subscribers/email-order-canceled.js +28 -0
  161. package/.medusa/server/src/subscribers/email-shipment-created.js +32 -0
  162. package/.medusa/server/src/subscribers/order-placed.js +27 -0
  163. package/.medusa/server/src/subscribers/packing-list-allocation-revised.js +32 -0
  164. package/.medusa/server/src/subscribers/packing-list-fulfillment-canceled.js +54 -0
  165. package/.medusa/server/src/subscribers/packing-list-fulfillment-created.js +31 -0
  166. package/.medusa/server/src/subscribers/password-reset.js +23 -0
  167. package/.medusa/server/src/subscribers/payment-refunded.js +38 -0
  168. package/.medusa/server/src/subscribers/return-received.js +27 -0
  169. package/.medusa/server/src/subscribers/return-requested.js +27 -0
  170. package/.medusa/server/src/subscribers/user-invite.js +23 -0
  171. package/.medusa/server/src/utils/cart-promotion-links.js +101 -0
  172. package/.medusa/server/src/utils/discover-complete-cart-participants.js +9 -2
  173. package/.medusa/server/src/utils/discover-plugin-features.js +47 -9
  174. package/.medusa/server/src/workflows/documents/issue-cancellation-after-refund.js +246 -0
  175. package/.medusa/server/src/workflows/documents/issue-document.js +163 -0
  176. package/.medusa/server/src/workflows/documents/issue-invoice-after-shipment.js +521 -0
  177. package/.medusa/server/src/workflows/documents/issue-packing-list.js +384 -0
  178. package/.medusa/server/src/workflows/documents/publish-document-facts.js +53 -0
  179. package/.medusa/server/src/workflows/documents/reconcile-document-resolutions.js +48 -0
  180. package/.medusa/server/src/workflows/documents/reconcile-order-cancellation.js +92 -0
  181. package/.medusa/server/src/workflows/documents/regenerate-issued-document.js +61 -0
  182. package/.medusa/server/src/workflows/email/dispatch-email-message.js +299 -0
  183. package/.medusa/server/src/workflows/email/documents-required-facts.js +30 -0
  184. package/.medusa/server/src/workflows/email/prepare-affiliate-reminder-email.js +58 -0
  185. package/.medusa/server/src/workflows/email/prepare-order-canceled-email.js +64 -0
  186. package/.medusa/server/src/workflows/email/prepare-order-received-email.js +56 -0
  187. package/.medusa/server/src/workflows/email/prepare-refund-email.js +47 -0
  188. package/.medusa/server/src/workflows/email/prepare-return-email.js +75 -0
  189. package/.medusa/server/src/workflows/email/prepare-shipment-email.js +82 -0
  190. package/.medusa/server/src/workflows/email/retry-email-messages.js +31 -0
  191. package/.medusa/server/src/workflows/hooks/complete-cart-participants.js +28 -16
  192. package/.medusa/server/src/workflows/hooks/dismiss-deleted-promotion-cart-links.js +23 -0
  193. package/README.md +2004 -11
  194. package/dist/admin-components/features/plugin-features/components/PluginActionsSection.d.ts +6 -0
  195. package/dist/admin-components/features/plugin-features/components/PluginActionsSection.js +66 -0
  196. package/dist/admin-components/features/plugin-features/components/PluginDetailPage.d.ts +2 -0
  197. package/dist/admin-components/features/plugin-features/components/PluginDetailPage.js +9 -0
  198. package/dist/admin-components/features/plugin-features/components/PluginFeatureGate.d.ts +22 -0
  199. package/dist/admin-components/features/plugin-features/components/PluginFeatureGate.js +18 -0
  200. package/dist/admin-components/features/plugin-features/components/PluginFeatureSections.d.ts +11 -0
  201. package/dist/admin-components/features/plugin-features/components/PluginFeatureSections.js +19 -0
  202. package/dist/admin-components/features/plugin-features/components/PluginFeaturesCard.d.ts +12 -0
  203. package/dist/admin-components/features/plugin-features/components/PluginFeaturesCard.js +34 -0
  204. package/dist/admin-components/features/plugin-features/components/PluginFeaturesSettingsPage.d.ts +5 -0
  205. package/dist/admin-components/features/plugin-features/components/PluginFeaturesSettingsPage.js +16 -0
  206. package/dist/admin-components/features/plugin-features/components/PluginHubCard.d.ts +7 -0
  207. package/dist/admin-components/features/plugin-features/components/PluginHubCard.js +21 -0
  208. package/dist/admin-components/features/plugin-features/components/PluginPageShell.d.ts +13 -0
  209. package/dist/admin-components/features/plugin-features/components/PluginPageShell.js +20 -0
  210. package/dist/admin-components/features/plugin-features/components/PluginSettingsForm.d.ts +7 -0
  211. package/dist/admin-components/features/plugin-features/components/PluginSettingsForm.js +39 -0
  212. package/dist/admin-components/features/plugin-features/components/PluginStatusChips.d.ts +5 -0
  213. package/dist/admin-components/features/plugin-features/components/PluginStatusChips.js +8 -0
  214. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatureEnabled.d.ts +114 -0
  215. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatureEnabled.js +40 -0
  216. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatures.d.ts +392 -0
  217. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatures.js +128 -0
  218. package/dist/admin-components/features/plugin-features/hooks/usePluginSettingsForm.d.ts +93 -0
  219. package/dist/admin-components/features/plugin-features/hooks/usePluginSettingsForm.js +44 -0
  220. package/dist/admin-components/features/plugin-features/lib/action-runs.d.ts +19 -0
  221. package/dist/admin-components/features/plugin-features/lib/action-runs.js +74 -0
  222. package/dist/admin-components/features/plugin-features/lib/plugin-features-admin-client.d.ts +363 -0
  223. package/dist/admin-components/features/plugin-features/lib/plugin-features-admin-client.js +9 -0
  224. package/dist/admin-components/features/plugin-features/lib/plugin-paths.d.ts +4 -0
  225. package/dist/admin-components/features/plugin-features/lib/plugin-paths.js +4 -0
  226. package/dist/admin-components/features/plugin-features/lib/settings-draft.d.ts +28 -0
  227. package/dist/admin-components/features/plugin-features/lib/settings-draft.js +86 -0
  228. package/dist/admin-components/features/plugin-features/queries/pluginFeatureKeys.d.ts +7 -0
  229. package/dist/admin-components/features/plugin-features/queries/pluginFeatureKeys.js +7 -0
  230. package/dist/admin-components/i18n/texts.d.ts +90 -0
  231. package/dist/admin-components/i18n/texts.js +90 -0
  232. package/dist/admin-components/index.d.ts +14 -0
  233. package/dist/admin-components/index.js +14 -0
  234. package/dist/admin-components/lib/errors.d.ts +6 -0
  235. package/dist/admin-components/lib/errors.js +27 -0
  236. package/dist/admin-components/lib/sdk.d.ts +2 -0
  237. package/dist/admin-components/lib/sdk.js +13 -0
  238. package/dist/documents/config/index.d.ts +11 -0
  239. package/dist/documents/config/index.js +17 -0
  240. package/dist/documents/templates/financial-document.d.ts +3 -0
  241. package/dist/documents/templates/financial-document.js +141 -0
  242. package/dist/documents/templates/format.d.ts +16 -0
  243. package/dist/documents/templates/format.js +30 -0
  244. package/dist/documents/templates/html-factory.d.ts +11 -0
  245. package/dist/documents/templates/html-factory.js +39 -0
  246. package/dist/documents/templates/html-utils.d.ts +2 -0
  247. package/dist/documents/templates/html-utils.js +12 -0
  248. package/dist/documents/templates/layout.d.ts +17 -0
  249. package/dist/documents/templates/layout.js +96 -0
  250. package/dist/documents/templates/packing-list.d.ts +3 -0
  251. package/dist/documents/templates/packing-list.js +49 -0
  252. package/dist/documents/types/admin-api.d.ts +1 -0
  253. package/dist/documents/types/admin-api.js +2 -0
  254. package/dist/documents/types/document-summary.d.ts +1 -0
  255. package/dist/documents/types/document-summary.js +2 -0
  256. package/dist/documents/types/documents.d.ts +174 -0
  257. package/dist/documents/types/documents.js +2 -0
  258. package/dist/documents/types/html-factory.d.ts +7 -0
  259. package/dist/documents/types/html-factory.js +5 -0
  260. package/dist/documents/types/index.d.ts +5 -0
  261. package/dist/documents/types/index.js +21 -0
  262. package/dist/documents/types/store-api.d.ts +1 -0
  263. package/dist/documents/types/store-api.js +2 -0
  264. package/dist/email/config/index.d.ts +17 -0
  265. package/dist/email/config/index.js +83 -0
  266. package/dist/email/config/notification-module.d.ts +22 -0
  267. package/dist/email/config/notification-module.js +19 -0
  268. package/dist/email/types/email-kinds.d.ts +15 -0
  269. package/dist/email/types/email-kinds.js +17 -0
  270. package/dist/email/types/index.d.ts +4 -0
  271. package/dist/email/types/index.js +20 -0
  272. package/dist/email/types/shop-configuration.d.ts +43 -0
  273. package/dist/email/types/shop-configuration.js +2 -0
  274. package/dist/email/types/smtp-configuration.d.ts +9 -0
  275. package/dist/email/types/smtp-configuration.js +2 -0
  276. package/dist/email/types/template-data.d.ts +100 -0
  277. package/dist/email/types/template-data.js +78 -0
  278. package/dist/files/config/index.d.ts +32 -0
  279. package/dist/files/config/index.js +255 -0
  280. package/dist/files/gateway/index.d.ts +30 -0
  281. package/dist/files/gateway/index.js +114 -0
  282. package/dist/files/types/index.d.ts +2 -0
  283. package/dist/files/types/index.js +5 -0
  284. package/dist/files/types/public.d.ts +90 -0
  285. package/dist/files/types/public.js +5 -0
  286. package/dist/modules/documents/domain/merchant.d.ts +22 -0
  287. package/dist/modules/documents/domain/merchant.js +85 -0
  288. package/dist/modules/documents/domain/options.d.ts +34 -0
  289. package/dist/modules/documents/domain/options.js +39 -0
  290. package/dist/public/action-progress.d.ts +25 -0
  291. package/dist/public/action-progress.js +66 -0
  292. package/dist/public/config.d.ts +59 -0
  293. package/dist/public/config.js +185 -0
  294. package/dist/public/descriptor.d.ts +3 -2
  295. package/dist/public/descriptor.js +198 -1
  296. package/dist/public/effective-features.d.ts +2 -1
  297. package/dist/public/effective-features.js +8 -4
  298. package/dist/public/enforcement.d.ts +7 -0
  299. package/dist/public/enforcement.js +17 -7
  300. package/dist/public/gateway.d.ts +2 -0
  301. package/dist/public/gateway.js +18 -0
  302. package/dist/public/index.d.ts +5 -2
  303. package/dist/public/index.js +9 -1
  304. package/dist/public/instrumentation.d.ts +12 -0
  305. package/dist/public/instrumentation.js +55 -0
  306. package/dist/public/module-access.d.ts +3 -0
  307. package/dist/public/module-access.js +13 -0
  308. package/dist/public/settings.d.ts +11 -0
  309. package/dist/public/settings.js +16 -0
  310. package/dist/public/shop-config.d.ts +8 -0
  311. package/dist/public/shop-config.js +11 -0
  312. package/dist/public/shop-master-data.d.ts +25 -0
  313. package/dist/public/shop-master-data.js +94 -0
  314. package/dist/public/shop-types.d.ts +7 -0
  315. package/dist/public/shop-types.js +23 -0
  316. package/dist/public/types.d.ts +113 -1
  317. package/dist/shop-config/build-food-shop-config.d.ts +44 -0
  318. package/dist/shop-config/build-food-shop-config.js +247 -0
  319. package/dist/shop-config/options.d.ts +41 -0
  320. package/dist/shop-config/options.js +70 -0
  321. package/dist/utils/discover-plugin-features.d.ts +28 -0
  322. package/dist/utils/discover-plugin-features.js +96 -0
  323. package/package.json +53 -6
@@ -1,10 +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");
9
+ const reactRouterDom = require("react-router-dom");
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");
8
13
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
9
14
  const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
10
15
  const texts = {
@@ -13,26 +18,85 @@ const texts = {
13
18
  },
14
19
  page: {
15
20
  title: "Hartl Services Plugins",
16
- description: "Plugins und einzelne Funktionen ein- oder ausschalten. Änderungen gelten sofort; abgeschaltete Funktionen sind im Shop nicht erreichbar."
21
+ description: "Plugins ein- oder ausschalten und öffnen, um Funktionen, Einstellungen und Aktionen zu verwalten. Änderungen gelten sofort; abgeschaltete Funktionen sind im Shop nicht erreichbar."
17
22
  },
18
23
  states: {
19
- loading: "Funktionsschalter werden geladen…",
20
- error: "Funktionsschalter konnten nicht geladen werden.",
24
+ loading: "Plugins werden geladen…",
25
+ error: "Plugins konnten nicht geladen werden.",
21
26
  empty: "Keine Plugins mit Funktionsschaltern installiert.",
22
- retry: "Erneut laden"
27
+ retry: "Erneut laden",
28
+ notFound: "Dieses Plugin ist nicht installiert."
23
29
  },
24
30
  plugin: {
25
- switchLabel: (label) => `${label} aktiv`
31
+ switchLabel: (label) => `${label} aktiv`,
32
+ open: "Öffnen",
33
+ openLabel: (label) => `${label} öffnen`
34
+ },
35
+ chips: {
36
+ enabled: "aktiv",
37
+ disabled: "aus",
38
+ configured: "konfiguriert",
39
+ notConfigured: (labels) => `nicht konfiguriert: ${labels}`
40
+ },
41
+ detail: {
42
+ back: "Zurück zu Hartl Services Plugins"
43
+ },
44
+ sections: {
45
+ features: "Funktionen",
46
+ settings: "Einstellungen",
47
+ actions: "Aktionen"
26
48
  },
27
49
  hints: {
28
50
  pluginDisabled: "Das Plugin ist ausgeschaltet. Alle Funktionen sind inaktiv, ihre Einstellungen bleiben erhalten.",
29
51
  parentDisabled: (parentLabel) => `Inaktiv, solange „${parentLabel}“ ausgeschaltet ist.`,
30
52
  saving: "Wird gespeichert…"
31
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
+ },
59
+ settings: {
60
+ missing: (labels) => `Nicht konfiguriert: ${labels}`,
61
+ save: "Einstellungen speichern",
62
+ secretPlaceholder: "gesetzt",
63
+ secretClear: "Löschen",
64
+ secretClearPending: "Wird beim Speichern gelöscht; danach gilt der Wert aus der Konfiguration, falls vorhanden.",
65
+ secretClearUndo: "Nicht löschen",
66
+ secretClearLabel: (label) => `${label} löschen`,
67
+ secretClearUndoLabel: (label) => `${label} nicht löschen`,
68
+ invalidates: (labels) => `Beim Ändern muss ${labels} neu eingegeben werden.`,
69
+ required: "Pflichtfeld",
70
+ invalidNumber: "Bitte eine gültige Zahl eingeben.",
71
+ outOfRange: "Der Wert liegt außerhalb des erlaubten Bereichs.",
72
+ numberMin: (min) => `Mindestens ${min}.`,
73
+ numberMax: (max) => `Höchstens ${max}.`,
74
+ numberRange: (min, max) => `Zwischen ${min} und ${max}.`,
75
+ selectPlaceholder: "Bitte auswählen",
76
+ clearHint: "Ein leeres Feld speichern entfernt den gespeicherten Wert (dann gilt Konfiguration oder Standard).",
77
+ source: {
78
+ stored: "gespeichert",
79
+ config: "aus Konfiguration",
80
+ default: "Standard",
81
+ none: "nicht gesetzt"
82
+ }
83
+ },
84
+ actions: {
85
+ confirmTitle: (label) => `${label}?`,
86
+ confirm: "Ausführen",
87
+ cancel: "Abbrechen",
88
+ runningSince: (time) => `läuft seit ${time}`,
89
+ lastCompleted: (time) => `Zuletzt erfolgreich: ${time}`,
90
+ lastFailed: (time) => `Zuletzt fehlgeschlagen: ${time}`
91
+ },
32
92
  toasts: {
33
93
  saved: "Einstellung wurde gespeichert.",
34
94
  saveFailed: "Einstellung konnte nicht gespeichert werden.",
35
- conflict: "Die Einstellungen wurden zwischenzeitlich geändert und neu geladen."
95
+ conflict: "Die Einstellungen wurden zwischenzeitlich geändert und neu geladen.",
96
+ actionCompleted: (label) => `„${label}“ wurde ausgeführt.`,
97
+ actionStarted: (label) => `„${label}“ wurde gestartet und läuft im Hintergrund.`,
98
+ actionFailed: (label) => `„${label}“ ist fehlgeschlagen.`,
99
+ actionAlreadyRunning: (label) => `„${label}“ läuft bereits; der Fortschritt wird angezeigt.`
36
100
  },
37
101
  errors: {
38
102
  unknown: "Unbekannter Fehler"
@@ -61,62 +125,641 @@ const getErrorMessage = (error) => {
61
125
  return void 0;
62
126
  };
63
127
  const sdk = new Medusa__default.default({
64
- baseUrl: __BACKEND_URL__ ?? "/",
128
+ baseUrl: (typeof __BACKEND_URL__ === "undefined" ? void 0 : __BACKEND_URL__) ?? "/",
65
129
  auth: {
66
- type: __AUTH_TYPE__ ?? "session",
67
- jwtTokenStorageKey: __JWT_TOKEN_STORAGE_KEY__ || void 0
130
+ type: (typeof __AUTH_TYPE__ === "undefined" ? void 0 : __AUTH_TYPE__) ?? "session",
131
+ jwtTokenStorageKey: (typeof __JWT_TOKEN_STORAGE_KEY__ === "undefined" ? void 0 : __JWT_TOKEN_STORAGE_KEY__) || void 0
68
132
  }
69
133
  });
70
134
  const listPluginFeatures = () => sdk.client.fetch(
71
135
  pluginFeatures.pluginFeaturesAdminPaths.get.list,
72
136
  { method: "GET" }
73
137
  );
138
+ const retrievePluginFeatures = (pluginKey) => sdk.client.fetch(
139
+ pluginFeatures.pluginFeaturesAdminPaths.get.retrieve(pluginKey),
140
+ { method: "GET" }
141
+ );
74
142
  const updatePluginFeatures = (payload) => sdk.client.fetch(
75
143
  pluginFeatures.pluginFeaturesAdminPaths.post.update,
76
144
  { method: "POST", body: payload }
77
145
  );
146
+ const updatePluginSettings = (pluginKey, payload) => sdk.client.fetch(
147
+ pluginFeatures.pluginFeaturesAdminPaths.post.updateSettings(pluginKey),
148
+ { method: "POST", body: payload }
149
+ );
150
+ const runPluginAction = (pluginKey, actionKey) => sdk.client.fetch(
151
+ pluginFeatures.pluginFeaturesAdminPaths.post.runAction(pluginKey, actionKey),
152
+ { method: "POST", body: {} }
153
+ );
154
+ const listPluginActionRuns = (pluginKey, actionKey, limit = 1) => sdk.client.fetch(
155
+ pluginFeatures.pluginFeaturesAdminPaths.get.actionRuns(pluginKey, actionKey),
156
+ { method: "GET", query: { limit } }
157
+ );
78
158
  const pluginFeatureKeys = {
79
159
  all: ["plugin-features"],
80
- list: () => [...pluginFeatureKeys.all, "list"]
160
+ list: () => [...pluginFeatureKeys.all, "list"],
161
+ details: () => [...pluginFeatureKeys.all, "detail"],
162
+ detail: (pluginKey) => [...pluginFeatureKeys.details(), pluginKey],
163
+ actionRuns: (pluginKey, actionKey) => [...pluginFeatureKeys.all, "action-runs", pluginKey, actionKey]
81
164
  };
82
165
  const isConflict = (error) => typeof error === "object" && error !== null && "status" in error && error.status === 409;
166
+ const storePlugin = (queryClient, plugin2) => {
167
+ queryClient.setQueryData(
168
+ pluginFeatureKeys.list(),
169
+ (current) => current && {
170
+ plugins: current.plugins.map(
171
+ (entry) => entry.plugin_key === plugin2.plugin_key ? plugin2 : entry
172
+ )
173
+ }
174
+ );
175
+ queryClient.setQueryData(
176
+ pluginFeatureKeys.detail(plugin2.plugin_key),
177
+ { plugin: plugin2 }
178
+ );
179
+ };
180
+ const onSaveError = async (queryClient, error) => {
181
+ if (isConflict(error)) {
182
+ ui.toast.error(texts.toasts.conflict);
183
+ } else {
184
+ ui.toast.error(texts.toasts.saveFailed, {
185
+ description: getErrorMessage(error) ?? texts.errors.unknown
186
+ });
187
+ }
188
+ await queryClient.invalidateQueries({ queryKey: pluginFeatureKeys.all });
189
+ };
83
190
  function usePluginFeatures() {
84
191
  return reactQuery.useQuery({
85
192
  queryKey: pluginFeatureKeys.list(),
86
193
  queryFn: listPluginFeatures
87
194
  });
88
195
  }
196
+ function usePluginFeature(pluginKey) {
197
+ const queryClient = reactQuery.useQueryClient();
198
+ return reactQuery.useQuery({
199
+ queryKey: pluginFeatureKeys.detail(pluginKey ?? ""),
200
+ queryFn: () => retrievePluginFeatures(pluginKey),
201
+ enabled: Boolean(pluginKey),
202
+ placeholderData: () => {
203
+ const plugin2 = queryClient.getQueryData(pluginFeatureKeys.list())?.plugins.find((entry) => entry.plugin_key === pluginKey);
204
+ return plugin2 ? { plugin: plugin2 } : void 0;
205
+ }
206
+ });
207
+ }
89
208
  function useUpdatePluginFeatures() {
90
209
  const queryClient = reactQuery.useQueryClient();
91
210
  return reactQuery.useMutation({
92
211
  mutationFn: updatePluginFeatures,
93
212
  onSuccess: ({ plugin: plugin2 }) => {
213
+ storePlugin(queryClient, plugin2);
214
+ ui.toast.success(texts.toasts.saved);
215
+ },
216
+ onError: (error) => onSaveError(queryClient, error)
217
+ });
218
+ }
219
+ function useUpdatePluginSettings(pluginKey) {
220
+ const queryClient = reactQuery.useQueryClient();
221
+ return reactQuery.useMutation({
222
+ mutationFn: (payload) => updatePluginSettings(pluginKey, payload),
223
+ onSuccess: ({ plugin: plugin2 }) => {
224
+ storePlugin(queryClient, plugin2);
225
+ ui.toast.success(texts.toasts.saved);
226
+ },
227
+ onError: (error) => onSaveError(queryClient, error)
228
+ });
229
+ }
230
+ const PLUGIN_ACTION_RUN_POLL_MS = 2e3;
231
+ function useLatestPluginActionRun(pluginKey, actionKey) {
232
+ return reactQuery.useQuery({
233
+ queryKey: pluginFeatureKeys.actionRuns(pluginKey, actionKey),
234
+ queryFn: () => listPluginActionRuns(pluginKey, actionKey, 1),
235
+ select: (data) => data.runs[0],
236
+ refetchInterval: (query) => query.state.data?.runs[0]?.status === "running" ? PLUGIN_ACTION_RUN_POLL_MS : false
237
+ });
238
+ }
239
+ function useRunPluginAction(pluginKey) {
240
+ const queryClient = reactQuery.useQueryClient();
241
+ return reactQuery.useMutation({
242
+ mutationFn: (action) => runPluginAction(pluginKey, action.key),
243
+ onSuccess: ({ action: run }, action) => {
94
244
  queryClient.setQueryData(
95
- pluginFeatureKeys.list(),
96
- (current) => current && {
97
- plugins: current.plugins.map(
98
- (entry) => entry.plugin_key === plugin2.plugin_key ? plugin2 : entry
99
- )
100
- }
245
+ pluginFeatureKeys.actionRuns(pluginKey, action.key),
246
+ { runs: [run.run] }
101
247
  );
102
- ui.toast.success(texts.toasts.saved);
248
+ if (run.status === "started") {
249
+ ui.toast.info(texts.toasts.actionStarted(action.label));
250
+ } else {
251
+ ui.toast.success(texts.toasts.actionCompleted(action.label));
252
+ }
103
253
  },
104
- onError: async (error) => {
254
+ onError: async (error, action) => {
105
255
  if (isConflict(error)) {
106
- ui.toast.error(texts.toasts.conflict);
256
+ ui.toast.info(texts.toasts.actionAlreadyRunning(action.label));
107
257
  } else {
108
- ui.toast.error(texts.toasts.saveFailed, {
258
+ ui.toast.error(texts.toasts.actionFailed(action.label), {
109
259
  description: getErrorMessage(error) ?? texts.errors.unknown
110
260
  });
111
261
  }
112
- await queryClient.invalidateQueries({ queryKey: pluginFeatureKeys.list() });
262
+ await queryClient.invalidateQueries({
263
+ queryKey: pluginFeatureKeys.actionRuns(pluginKey, action.key)
264
+ });
113
265
  }
114
266
  });
115
267
  }
268
+ const PLUGIN_HUB_PATH = "/settings/hartl-services";
269
+ const pluginDetailPath = (pluginKey) => `${PLUGIN_HUB_PATH}/plugin/${encodeURIComponent(pluginKey)}`;
270
+ const initialEntry = (setting) => {
271
+ if (setting.type === "secret") {
272
+ return "";
273
+ }
274
+ if (setting.type === "boolean") {
275
+ return setting.value === true;
276
+ }
277
+ return setting.value === null ? "" : String(setting.value);
278
+ };
279
+ const initialSettingsDraft = (settings) => Object.fromEntries(
280
+ settings.map((setting) => [setting.key, initialEntry(setting)])
281
+ );
282
+ const outsideBounds = (setting, value) => setting.min !== null && value < setting.min || setting.max !== null && value > setting.max;
283
+ const numberEntryValue = (entry) => {
284
+ const value = Number(entry.trim());
285
+ return Number.isFinite(value) ? value : null;
286
+ };
287
+ const invalidDraftKeys = (settings, draft, unparsable = []) => settings.filter((setting) => {
288
+ if (setting.type !== "number") {
289
+ return false;
290
+ }
291
+ if (unparsable.includes(setting.key)) {
292
+ return true;
293
+ }
294
+ const entry = draft[setting.key];
295
+ if (typeof entry !== "string" || entry.trim() === "") {
296
+ return false;
297
+ }
298
+ const value = numberEntryValue(entry);
299
+ return value === null || outsideBounds(setting, value);
300
+ }).map((setting) => setting.key);
301
+ const changedSettingValues = (settings, draft, unparsable = []) => {
302
+ const initial = initialSettingsDraft(settings);
303
+ const values = {};
304
+ for (const setting of settings) {
305
+ const entry = draft[setting.key];
306
+ if (entry === void 0 || entry === initial[setting.key]) {
307
+ continue;
308
+ }
309
+ if (setting.type === "secret") {
310
+ if (entry === null) {
311
+ if (setting.source === "stored") {
312
+ values[setting.key] = null;
313
+ }
314
+ } else if (typeof entry === "string" && entry !== "") {
315
+ values[setting.key] = entry;
316
+ }
317
+ continue;
318
+ }
319
+ if (setting.type === "boolean") {
320
+ values[setting.key] = entry === true;
321
+ continue;
322
+ }
323
+ if (unparsable.includes(setting.key)) {
324
+ continue;
325
+ }
326
+ const text = typeof entry === "string" ? entry.trim() : "";
327
+ if (text === "") {
328
+ if (setting.source === "stored") {
329
+ values[setting.key] = null;
330
+ }
331
+ } else if (setting.type === "number") {
332
+ const value = numberEntryValue(text);
333
+ if (value !== null) {
334
+ values[setting.key] = value;
335
+ }
336
+ } else {
337
+ values[setting.key] = text;
338
+ }
339
+ }
340
+ return values;
341
+ };
342
+ function usePluginSettingsForm(plugin2) {
343
+ const mutation = useUpdatePluginSettings(plugin2.plugin_key);
344
+ const [draft, setDraft] = react.useState(
345
+ () => initialSettingsDraft(plugin2.settings)
346
+ );
347
+ const [unparsable, setUnparsable] = react.useState([]);
348
+ react.useEffect(() => {
349
+ setDraft(initialSettingsDraft(plugin2.settings));
350
+ setUnparsable([]);
351
+ }, [plugin2.settings, plugin2.settings_version]);
352
+ const changes = react.useMemo(
353
+ () => changedSettingValues(plugin2.settings, draft, unparsable),
354
+ [plugin2.settings, draft, unparsable]
355
+ );
356
+ const invalid = react.useMemo(
357
+ () => invalidDraftKeys(plugin2.settings, draft, unparsable),
358
+ [plugin2.settings, draft, unparsable]
359
+ );
360
+ const dirty = Object.keys(changes).length > 0;
361
+ const setValue = (key, value, badInput = false) => {
362
+ setDraft((current) => ({ ...current, [key]: value }));
363
+ setUnparsable(
364
+ (current) => badInput ? current.includes(key) ? current : [...current, key] : current.filter((entry) => entry !== key)
365
+ );
366
+ };
367
+ const submit = (event) => {
368
+ event.preventDefault();
369
+ if (!dirty || invalid.length > 0 || mutation.isPending) {
370
+ return;
371
+ }
372
+ mutation.mutate({
373
+ expected_version: plugin2.settings_version,
374
+ values: changes
375
+ });
376
+ };
377
+ return {
378
+ draft,
379
+ setValue,
380
+ dirty,
381
+ invalid,
382
+ submit,
383
+ mutation
384
+ };
385
+ }
386
+ const fieldId = (pluginKey, key) => `plugin-setting-${pluginKey}-${key}`;
387
+ const missingLabels = (plugin2) => plugin2.missing.map(
388
+ (key) => plugin2.settings.find((setting) => setting.key === key)?.label ?? key
389
+ ).join(", ");
390
+ const invalidatesLabels = (plugin2, setting) => setting.invalidates.map(
391
+ (key) => plugin2.settings.find((candidate) => candidate.key === key)?.label ?? key
392
+ ).join(", ");
393
+ const boundsText = (setting) => setting.min !== null && setting.max !== null ? texts.settings.numberRange(setting.min, setting.max) : setting.min !== null ? texts.settings.numberMin(setting.min) : setting.max !== null ? texts.settings.numberMax(setting.max) : void 0;
394
+ const SettingField = ({
395
+ pluginKey,
396
+ setting,
397
+ invalidatesLabels: invalidatesLabels2,
398
+ value,
399
+ invalid,
400
+ disabled,
401
+ onChange
402
+ }) => {
403
+ const id = fieldId(pluginKey, setting.key);
404
+ const hintId = `${id}-hint`;
405
+ const clearPending = setting.type === "secret" && value === null;
406
+ const bounds = setting.type === "number" ? boundsText(setting) : void 0;
407
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2", children: [
408
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
409
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Label, { htmlFor: id, size: "small", weight: "plus", children: [
410
+ setting.label,
411
+ setting.required && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-ui-fg-muted", children: [
412
+ " (",
413
+ texts.settings.required,
414
+ ")"
415
+ ] })
416
+ ] }),
417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-muted shrink-0", children: texts.settings.source[setting.source] })
418
+ ] }),
419
+ setting.type === "boolean" ? /* @__PURE__ */ jsxRuntime.jsx(
420
+ ui.Switch,
421
+ {
422
+ id,
423
+ "aria-describedby": hintId,
424
+ checked: value === true,
425
+ disabled,
426
+ onCheckedChange: (checked) => onChange(checked === true)
427
+ }
428
+ ) : setting.type === "secret" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
429
+ /* @__PURE__ */ jsxRuntime.jsx(
430
+ ui.Input,
431
+ {
432
+ id,
433
+ "aria-describedby": hintId,
434
+ className: "flex-1",
435
+ type: "password",
436
+ autoComplete: "new-password",
437
+ placeholder: setting.is_set ? texts.settings.secretPlaceholder : "",
438
+ value: typeof value === "string" ? value : "",
439
+ disabled: disabled || clearPending,
440
+ onChange: (event) => onChange(event.target.value)
441
+ }
442
+ ),
443
+ setting.source === "stored" && /* @__PURE__ */ jsxRuntime.jsx(
444
+ ui.Button,
445
+ {
446
+ type: "button",
447
+ size: "small",
448
+ variant: "secondary",
449
+ disabled,
450
+ "aria-label": clearPending ? texts.settings.secretClearUndoLabel(setting.label) : texts.settings.secretClearLabel(setting.label),
451
+ onClick: () => onChange(clearPending ? "" : null),
452
+ children: clearPending ? texts.settings.secretClearUndo : texts.settings.secretClear
453
+ }
454
+ )
455
+ ] }) : setting.type === "select" ? /* @__PURE__ */ jsxRuntime.jsxs(
456
+ ui.Select,
457
+ {
458
+ value: typeof value === "string" ? value : "",
459
+ disabled,
460
+ onValueChange: (next) => onChange(next),
461
+ children: [
462
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id, "aria-describedby": hintId, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: texts.settings.selectPlaceholder }) }),
463
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: setting.options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: option.value, children: option.label }, option.value)) })
464
+ ]
465
+ }
466
+ ) : setting.type === "number" ? /* @__PURE__ */ jsxRuntime.jsx(
467
+ ui.Input,
468
+ {
469
+ id,
470
+ "aria-describedby": hintId,
471
+ "aria-invalid": invalid,
472
+ type: "number",
473
+ step: "any",
474
+ min: setting.min ?? void 0,
475
+ max: setting.max ?? void 0,
476
+ value: typeof value === "string" ? value : "",
477
+ disabled,
478
+ onChange: (event) => onChange(event.target.value, event.target.validity.badInput)
479
+ }
480
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
481
+ ui.Input,
482
+ {
483
+ id,
484
+ "aria-describedby": hintId,
485
+ "aria-invalid": invalid,
486
+ type: setting.type === "url" ? "url" : "text",
487
+ value: typeof value === "string" ? value : "",
488
+ disabled,
489
+ onChange: (event) => onChange(event.target.value)
490
+ }
491
+ ),
492
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { id: hintId, className: "grid gap-1", children: [
493
+ setting.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: setting.description }),
494
+ clearPending && /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { variant: "info", children: texts.settings.secretClearPending }),
495
+ invalidatesLabels2 && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: texts.settings.invalidates(invalidatesLabels2) }),
496
+ bounds && !invalid && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: bounds }),
497
+ invalid && /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { variant: "error", children: bounds ?? texts.settings.invalidNumber })
498
+ ] })
499
+ ] });
500
+ };
501
+ const PluginSettingsForm = ({ plugin: plugin2 }) => {
502
+ const form = usePluginSettingsForm(plugin2);
503
+ const pending = form.mutation.isPending;
504
+ const hasTextFields = plugin2.settings.some(
505
+ (setting) => setting.type !== "boolean" && setting.type !== "secret" && setting.type !== "select"
506
+ );
507
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", "aria-busy": pending, children: [
508
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4", children: [
509
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: texts.sections.settings }),
510
+ hasTextFields && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: texts.settings.clearHint })
511
+ ] }),
512
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: form.submit, className: "grid gap-5 px-6 py-5", children: [
513
+ !plugin2.configured && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "warning", children: texts.settings.missing(missingLabels(plugin2)) }),
514
+ plugin2.settings.map((setting) => /* @__PURE__ */ jsxRuntime.jsx(
515
+ SettingField,
516
+ {
517
+ pluginKey: plugin2.plugin_key,
518
+ setting,
519
+ invalidatesLabels: invalidatesLabels(plugin2, setting),
520
+ value: form.draft[setting.key],
521
+ invalid: form.invalid.includes(setting.key),
522
+ disabled: pending,
523
+ onChange: (value, badInput) => form.setValue(setting.key, value, badInput)
524
+ },
525
+ setting.key
526
+ )),
527
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
528
+ ui.Button,
529
+ {
530
+ type: "submit",
531
+ size: "small",
532
+ isLoading: pending,
533
+ disabled: !form.dirty || form.invalid.length > 0 || pending,
534
+ children: texts.settings.save
535
+ }
536
+ ) })
537
+ ] })
538
+ ] });
539
+ };
540
+ const PluginStatusChips = ({ plugin: plugin2 }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex flex-wrap gap-2", children: [
541
+ plugin2.switchable && /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: plugin2.enabled ? "green" : "grey", children: plugin2.enabled ? texts.chips.enabled : texts.chips.disabled }),
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)) })
543
+ ] });
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;
548
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-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: [
568
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: texts.states.error }),
569
+ /* @__PURE__ */ jsxRuntime.jsx(
570
+ ui.Button,
571
+ {
572
+ size: "small",
573
+ variant: "secondary",
574
+ isLoading: query.isFetching,
575
+ onClick: () => void query.refetch(),
576
+ children: texts.states.retry
577
+ }
578
+ )
579
+ ] })
580
+ ] });
581
+ };
582
+ const SUMMARY_MAX_LENGTH = 200;
583
+ const cut = (text) => text.length > SUMMARY_MAX_LENGTH ? `${text.slice(0, SUMMARY_MAX_LENGTH - 1)}…` : text;
584
+ const isPrimitive = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
585
+ const summarizeActionResult = (result) => {
586
+ if (result === null || result === void 0) {
587
+ return null;
588
+ }
589
+ if (isPrimitive(result)) {
590
+ return cut(String(result));
591
+ }
592
+ if (typeof result !== "object" || Array.isArray(result)) {
593
+ return null;
594
+ }
595
+ const record = result;
596
+ for (const key of ["summary", "message"]) {
597
+ const value = record[key];
598
+ if (typeof value === "string" && value.trim()) {
599
+ return cut(value.trim());
600
+ }
601
+ }
602
+ const parts = Object.entries(record).filter(
603
+ (entry) => isPrimitive(entry[1])
604
+ ).map(([key, value]) => `${key}: ${String(value)}`);
605
+ return parts.length > 0 ? cut(parts.join(", ")) : null;
606
+ };
607
+ const progressPercent = (progress) => {
608
+ if (!progress || progress.total === null || progress.total <= 0) {
609
+ return null;
610
+ }
611
+ return Math.max(
612
+ 0,
613
+ Math.min(100, Math.round(progress.current / progress.total * 100))
614
+ );
615
+ };
616
+ const progressCount = (progress) => {
617
+ if (!progress) {
618
+ return null;
619
+ }
620
+ return progress.total === null ? String(progress.current) : `${progress.current} / ${progress.total}`;
621
+ };
622
+ const formatRunTime = (iso) => {
623
+ if (!iso) {
624
+ return "";
625
+ }
626
+ const date = new Date(iso);
627
+ return Number.isNaN(date.getTime()) ? iso : date.toLocaleString("de-AT", { dateStyle: "short", timeStyle: "short" });
628
+ };
629
+ const runTransition = (previous, current) => {
630
+ if (!previous || !current || previous.id !== current.id || previous.status !== "running" || current.status === "running") {
631
+ return null;
632
+ }
633
+ return current.status;
634
+ };
635
+ const RunProgress = ({ run }) => {
636
+ const percent = progressPercent(run.progress);
637
+ const count = progressCount(run.progress);
638
+ const label = run.progress?.label;
639
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 flex flex-col gap-y-1", role: "status", children: [
640
+ (label || count) && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: [label, count].filter(Boolean).join(" · ") }),
641
+ percent !== null && /* @__PURE__ */ jsxRuntime.jsx(
642
+ "div",
643
+ {
644
+ className: "bg-ui-border-base w-full overflow-hidden rounded-full",
645
+ style: { height: 6 },
646
+ role: "progressbar",
647
+ "aria-valuemin": 0,
648
+ "aria-valuemax": 100,
649
+ "aria-valuenow": percent,
650
+ children: /* @__PURE__ */ jsxRuntime.jsx(
651
+ "div",
652
+ {
653
+ className: "bg-ui-fg-interactive h-full rounded-full",
654
+ style: { width: `${percent}%`, height: "100%" }
655
+ }
656
+ )
657
+ }
658
+ ),
659
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: texts.actions.runningSince(formatRunTime(run.started_at)) })
660
+ ] });
661
+ };
662
+ const RunStatusLine = ({ run }) => {
663
+ if (run.status === "completed") {
664
+ const summary = summarizeActionResult(run.result);
665
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1", children: [
666
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: texts.actions.lastCompleted(
667
+ formatRunTime(run.finished_at ?? run.started_at)
668
+ ) }),
669
+ summary && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: summary })
670
+ ] });
671
+ }
672
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1", children: [
673
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-error", children: texts.actions.lastFailed(
674
+ formatRunTime(run.finished_at ?? run.started_at)
675
+ ) }),
676
+ run.message && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-error", children: run.message })
677
+ ] });
678
+ };
679
+ const PluginActionRow = ({
680
+ pluginKey,
681
+ action,
682
+ starting,
683
+ blocked,
684
+ onRun
685
+ }) => {
686
+ const { data: run } = useLatestPluginActionRun(pluginKey, action.key);
687
+ const previous = react.useRef(void 0);
688
+ const running = run?.status === "running";
689
+ react.useEffect(() => {
690
+ const transition = runTransition(previous.current, run);
691
+ previous.current = run;
692
+ if (transition === "completed") {
693
+ ui.toast.success(texts.toasts.actionCompleted(action.label), {
694
+ description: summarizeActionResult(run?.result) ?? void 0
695
+ });
696
+ } else if (transition === "failed") {
697
+ ui.toast.error(texts.toasts.actionFailed(action.label), {
698
+ description: run?.message ?? texts.errors.unknown
699
+ });
700
+ }
701
+ }, [run, action.label]);
702
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4 px-6 py-4", children: [
703
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
704
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: action.label }),
705
+ action.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: action.description }),
706
+ run && (running ? /* @__PURE__ */ jsxRuntime.jsx(RunProgress, { run }) : /* @__PURE__ */ jsxRuntime.jsx(RunStatusLine, { run }))
707
+ ] }),
708
+ /* @__PURE__ */ jsxRuntime.jsx(
709
+ ui.Button,
710
+ {
711
+ size: "small",
712
+ variant: "secondary",
713
+ className: "shrink-0",
714
+ isLoading: starting || running,
715
+ disabled: blocked || starting || running,
716
+ onClick: () => onRun(action),
717
+ children: action.label
718
+ }
719
+ )
720
+ ] });
721
+ };
722
+ const PluginActionsSection = ({ plugin: plugin2 }) => {
723
+ const mutation = useRunPluginAction(plugin2.plugin_key);
724
+ const prompt = ui.usePrompt();
725
+ const startingKey = mutation.isPending ? mutation.variables?.key : void 0;
726
+ const run = async (action) => {
727
+ if (mutation.isPending) {
728
+ return;
729
+ }
730
+ if (action.confirm) {
731
+ const confirmed = await prompt({
732
+ title: texts.actions.confirmTitle(action.label),
733
+ description: action.confirm,
734
+ confirmText: texts.actions.confirm,
735
+ cancelText: texts.actions.cancel,
736
+ variant: "confirmation"
737
+ });
738
+ if (!confirmed) {
739
+ return;
740
+ }
741
+ }
742
+ mutation.mutate(action);
743
+ };
744
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
745
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: texts.sections.actions }) }),
746
+ plugin2.actions.map((action) => /* @__PURE__ */ jsxRuntime.jsx(
747
+ PluginActionRow,
748
+ {
749
+ pluginKey: plugin2.plugin_key,
750
+ action,
751
+ starting: startingKey === action.key,
752
+ blocked: mutation.isPending && startingKey !== action.key,
753
+ onRun: (entry) => void run(entry)
754
+ },
755
+ action.key
756
+ ))
757
+ ] });
758
+ };
116
759
  const configuredFeatures = (plugin2) => Object.fromEntries(
117
760
  plugin2.features.map((feature) => [feature.key, feature.enabled])
118
761
  );
119
- const PluginFeaturesCard = ({ plugin: plugin2 }) => {
762
+ const PluginFeaturesCard = ({ plugin: plugin2, title }) => {
120
763
  const mutation = useUpdatePluginFeatures();
121
764
  const pending = mutation.isPending;
122
765
  const labels = new Map(
@@ -135,12 +778,12 @@ const PluginFeaturesCard = ({ plugin: plugin2 }) => {
135
778
  return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", "aria-busy": pending, children: [
136
779
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4 px-6 py-4", children: [
137
780
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
138
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: plugin2.label }),
139
- plugin2.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: plugin2.description }),
781
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: title ?? plugin2.label }),
782
+ title === void 0 && plugin2.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: plugin2.description }),
140
783
  !plugin2.enabled && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted mt-1", children: texts.hints.pluginDisabled }),
141
784
  pending && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted mt-1", children: texts.hints.saving })
142
785
  ] }),
143
- /* @__PURE__ */ jsxRuntime.jsx(
786
+ plugin2.switchable && /* @__PURE__ */ jsxRuntime.jsx(
144
787
  ui.Switch,
145
788
  {
146
789
  id: pluginSwitchId,
@@ -200,6 +843,632 @@ const PluginFeaturesCard = ({ plugin: plugin2 }) => {
200
843
  })
201
844
  ] });
202
845
  };
846
+ const PluginFeatureSections = ({ pluginKey }) => {
847
+ const plugin2 = usePluginFeature(pluginKey).data?.plugin;
848
+ if (!plugin2) {
849
+ return null;
850
+ }
851
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
852
+ (plugin2.switchable || plugin2.features.length > 0) && /* @__PURE__ */ jsxRuntime.jsx(PluginFeaturesCard, { plugin: plugin2, title: texts.sections.features }),
853
+ plugin2.settings.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(PluginSettingsForm, { plugin: plugin2 }),
854
+ plugin2.actions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(PluginActionsSection, { plugin: plugin2 })
855
+ ] });
856
+ };
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,
1119
+ {
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
+ ] })
1138
+ }
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." })
1272
+ ] }),
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
+ };
203
1472
  const PluginFeaturesSettingsPage = () => {
204
1473
  const query = usePluginFeatures();
205
1474
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-3", children: [
@@ -219,19 +1488,885 @@ const PluginFeaturesSettingsPage = () => {
219
1488
  children: texts.states.retry
220
1489
  }
221
1490
  )
222
- ] }) : 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 }) }) : query.data.plugins.map((plugin2) => /* @__PURE__ */ jsxRuntime.jsx(PluginFeaturesCard, { plugin: plugin2 }, plugin2.plugin_key))
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))
223
1495
  ] });
224
1496
  };
225
1497
  const config = adminSdk.defineRouteConfig({
226
1498
  label: texts.menu.label
227
1499
  });
228
- const widgetModule = { widgets: [] };
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
2323
+ ] })
2324
+ ] });
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
+ ] });
2340
+ const PluginDetailPage = () => {
2341
+ const { plugin_key: pluginKey = "" } = reactRouterDom.useParams();
2342
+ return /* @__PURE__ */ jsxRuntime.jsx(PluginPageShell, { pluginKey, children: /* @__PURE__ */ jsxRuntime.jsx(PluginFeatureSections, { pluginKey }) });
2343
+ };
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
+ ] };
229
2356
  const routeModule = {
230
2357
  routes: [
231
2358
  {
232
2359
  Component: PluginFeaturesSettingsPage,
233
2360
  path: "/settings/hartl-services",
234
2361
  handle: { label: config.label, translationNs: config.translationNs }
2362
+ },
2363
+ {
2364
+ Component: EmailPluginRoute,
2365
+ path: "/settings/hartl-services/email"
2366
+ },
2367
+ {
2368
+ Component: PluginDetailPage,
2369
+ path: "/settings/hartl-services/plugin/:plugin_key"
235
2370
  }
236
2371
  ]
237
2372
  };