@hartl-services/medusa-base 1.0.0 → 2.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 (79) hide show
  1. package/.medusa/server/src/admin/index.js +117 -1
  2. package/.medusa/server/src/admin/index.mjs +118 -2
  3. package/.medusa/server/src/documents/plugin-features.js +15 -1
  4. package/.medusa/server/src/documents/templates/financial-document.js +69 -51
  5. package/.medusa/server/src/documents/templates/format.js +44 -2
  6. package/.medusa/server/src/documents/templates/html-factory.js +7 -5
  7. package/.medusa/server/src/documents/templates/html-utils.js +12 -2
  8. package/.medusa/server/src/documents/templates/layout.js +115 -70
  9. package/.medusa/server/src/documents/templates/packing-list.js +10 -8
  10. package/.medusa/server/src/documents/utils/document-merchant.js +5 -5
  11. package/.medusa/server/src/documents/utils/document-render-settings.js +59 -0
  12. package/.medusa/server/src/email/application/handle-invite-event.js +8 -2
  13. package/.medusa/server/src/email/application/handle-password-reset-event.js +16 -4
  14. package/.medusa/server/src/email/domain/order-summary.js +103 -0
  15. package/.medusa/server/src/email/domain/refund-summary.js +43 -0
  16. package/.medusa/server/src/email/domain/return-summary.js +118 -0
  17. package/.medusa/server/src/email/domain/shipment-summary.js +74 -0
  18. package/.medusa/server/src/email/plugin-features.js +9 -1
  19. package/.medusa/server/src/email/rendering/default-templates.js +693 -65
  20. package/.medusa/server/src/email/rendering/load-email-shop-details.js +36 -0
  21. package/.medusa/server/src/email/rendering/render-email.js +16 -3
  22. package/.medusa/server/src/email/rendering/resolve-shop-configuration.js +20 -1
  23. package/.medusa/server/src/email/types/template-data.js +155 -2
  24. package/.medusa/server/src/modules/documents/domain/merchant.js +2 -33
  25. package/.medusa/server/src/modules/documents/domain/options.js +1 -7
  26. package/.medusa/server/src/modules/plugin-features/domain/plugin-settings.js +4 -3
  27. package/.medusa/server/src/public/descriptor.js +3 -1
  28. package/.medusa/server/src/public/shop-master-data.js +7 -7
  29. package/.medusa/server/src/shop-config/build-food-shop-config.js +6 -6
  30. package/.medusa/server/src/shop-config/options.js +5 -15
  31. package/.medusa/server/src/workflows/documents/issue-cancellation-after-refund.js +2 -3
  32. package/.medusa/server/src/workflows/documents/issue-document.js +6 -5
  33. package/.medusa/server/src/workflows/documents/issue-packing-list.js +9 -3
  34. package/.medusa/server/src/workflows/email/dispatch-email-message.js +4 -2
  35. package/.medusa/server/src/workflows/email/prepare-order-canceled-email.js +42 -4
  36. package/.medusa/server/src/workflows/email/prepare-order-received-email.js +31 -5
  37. package/.medusa/server/src/workflows/email/prepare-refund-email.js +25 -1
  38. package/.medusa/server/src/workflows/email/prepare-return-email.js +64 -3
  39. package/.medusa/server/src/workflows/email/prepare-shipment-email.js +36 -3
  40. package/README.md +180 -43
  41. package/dist/admin-components/features/plugin-features/components/ImageSettingInput.d.ts +15 -0
  42. package/dist/admin-components/features/plugin-features/components/ImageSettingInput.js +42 -0
  43. package/dist/admin-components/features/plugin-features/components/PluginSettingsForm.js +4 -2
  44. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatureEnabled.d.ts +1 -1
  45. package/dist/admin-components/features/plugin-features/hooks/usePluginFeatures.d.ts +4 -4
  46. package/dist/admin-components/features/plugin-features/hooks/usePluginSettingsForm.d.ts +1 -1
  47. package/dist/admin-components/features/plugin-features/lib/image-upload.d.ts +6 -0
  48. package/dist/admin-components/features/plugin-features/lib/image-upload.js +17 -0
  49. package/dist/admin-components/features/plugin-features/lib/plugin-features-admin-client.d.ts +4 -4
  50. package/dist/admin-components/i18n/texts.d.ts +6 -0
  51. package/dist/admin-components/i18n/texts.js +6 -0
  52. package/dist/documents/templates/financial-document.d.ts +3 -3
  53. package/dist/documents/templates/financial-document.js +68 -50
  54. package/dist/documents/templates/format.d.ts +14 -0
  55. package/dist/documents/templates/format.js +43 -1
  56. package/dist/documents/templates/html-factory.d.ts +6 -2
  57. package/dist/documents/templates/html-factory.js +6 -4
  58. package/dist/documents/templates/html-utils.d.ts +6 -0
  59. package/dist/documents/templates/html-utils.js +11 -1
  60. package/dist/documents/templates/layout.d.ts +21 -3
  61. package/dist/documents/templates/layout.js +114 -69
  62. package/dist/documents/templates/packing-list.js +9 -7
  63. package/dist/documents/types/documents.d.ts +11 -16
  64. package/dist/documents/types/html-factory.d.ts +1 -0
  65. package/dist/email/types/shop-configuration.d.ts +25 -0
  66. package/dist/email/types/template-data.d.ts +509 -0
  67. package/dist/email/types/template-data.js +154 -1
  68. package/dist/modules/documents/domain/options.d.ts +1 -9
  69. package/dist/modules/documents/domain/options.js +0 -6
  70. package/dist/public/descriptor.js +2 -0
  71. package/dist/public/shop-master-data.d.ts +5 -6
  72. package/dist/public/shop-master-data.js +6 -6
  73. package/dist/public/types.d.ts +2 -1
  74. package/dist/shop-config/build-food-shop-config.js +5 -5
  75. package/dist/shop-config/options.d.ts +13 -8
  76. package/dist/shop-config/options.js +4 -14
  77. package/package.json +2 -2
  78. package/dist/modules/documents/domain/merchant.d.ts +0 -22
  79. package/dist/modules/documents/domain/merchant.js +0 -85
@@ -10,15 +10,15 @@ const renderBatchAllocations = (line, timeZone) => {
10
10
  return line.batch_allocations
11
11
  .map((allocation) => `<div class="packing-batch">
12
12
  <strong>${(0, html_utils_1.escapeHtml)(allocation.lot_number)}</strong>
13
- <span>MHD: ${(0, format_1.formatDate)(allocation.expiry_date, { timeZone })}</span>
13
+ <span>MHD: ${(0, html_utils_1.escapeHtml)((0, format_1.formatDocumentDate)(allocation.expiry_date, timeZone))}</span>
14
14
  <span>Menge: ${(0, html_utils_1.escapeHtml)(allocation.quantity)}</span>
15
15
  </div>`)
16
16
  .join("");
17
17
  };
18
18
  const renderLines = (input, timeZone) => input.lines
19
19
  .map((line) => `<tr>
20
- <td>
21
- <strong>${(0, html_utils_1.escapeHtml)(line.title)}</strong>
20
+ <td class="item">
21
+ <div class="item-title">${(0, html_utils_1.escapeHtml)(line.title)}</div>
22
22
  ${line.sku ? `<div class="sku">SKU: ${(0, html_utils_1.escapeHtml)(line.sku)}</div>` : ""}
23
23
  </td>
24
24
  <td>${renderBatchAllocations(line, timeZone)}</td>
@@ -26,12 +26,13 @@ const renderLines = (input, timeZone) => input.lines
26
26
  </tr>`)
27
27
  .join("");
28
28
  const renderPackingList = (input, layout, timeZone) => layout({
29
- body: `<table>
30
- <thead><tr><th>Bezeichnung</th><th>Charge</th><th class="number">Benötigte Menge</th></tr></thead>
31
- <tbody>${renderLines(input, timeZone)}</tbody>
29
+ body: `<table class="items packing-items">
30
+ <thead><tr><th class="item">Bezeichnung</th><th>Charge</th><th class="number">Benötigte Menge</th></tr></thead>
31
+ <tbody class="lines">${renderLines(input, timeZone)}</tbody>
32
32
  </table>`,
33
33
  documentTitle: "Packliste",
34
34
  metadata: [
35
+ { label: "Packlistennummer", value: input.document.number },
35
36
  {
36
37
  label: "Bestellung",
37
38
  value: (0, html_utils_1.formatOrderReference)(input.order.display_id),
@@ -39,11 +40,12 @@ const renderPackingList = (input, layout, timeZone) => layout({
39
40
  { label: "Fulfillment", value: input.fulfillment.id },
40
41
  {
41
42
  label: "Erstellungsdatum",
42
- value: (0, format_1.formatDate)(input.document.generated_at, { timeZone }),
43
+ value: (0, format_1.formatDocumentDate)(input.document.generated_at, timeZone),
43
44
  },
44
45
  { label: "Lagerplatz", value: input.fulfillment.location_name },
45
46
  ],
46
47
  number: input.document.number,
47
48
  pageTitle: "Packliste",
49
+ recipient: null,
48
50
  });
49
51
  exports.renderPackingList = renderPackingList;
@@ -144,28 +144,23 @@ export type DocumentMerchant = {
144
144
  company_register_number: string | null;
145
145
  company_register_court: string | null;
146
146
  };
147
- /**
148
- * Optional `merchant` plugin option: used per field only where the shop
149
- * master data in the base plugin has no value (same shape as the demo shop's
150
- * `merchant` constant in medusa-config).
151
- */
152
- export type DocumentMerchantOption = {
153
- countryCode: string;
154
- legalName: string;
155
- registeredAddress: {
156
- address1: string;
157
- address2?: string;
158
- city: string;
159
- countryCode: string;
160
- postalCode: string;
161
- };
162
- vatNumber?: string;
147
+ export type DocumentRenderSettings = {
148
+ /**
149
+ * The uploaded logo as a `data:` URL, ready for `<img src>`; `null` when no
150
+ * logo is set or it could not be loaded (the document then shows the
151
+ * merchant's legal name instead).
152
+ */
153
+ logo_src: string | null;
154
+ /** Payment terms printed below the totals of an invoice; `null` = none. */
155
+ payment_terms: string | null;
163
156
  };
164
157
  export type FinancialDocumentRenderInput = DocumentTemplateInput & {
165
158
  merchant: DocumentMerchant;
159
+ settings: DocumentRenderSettings;
166
160
  };
167
161
  export type PackingListRenderInput = PackingListTemplateInput & {
168
162
  merchant: DocumentMerchant;
163
+ settings: DocumentRenderSettings;
169
164
  };
170
165
  export type DocumentRenderInput = FinancialDocumentRenderInput | PackingListRenderInput;
171
166
  export type DocumentPdfOptions = {
@@ -5,3 +5,4 @@ import type { DocumentRenderInput } from "./documents";
5
5
  */
6
6
  export type DocumentHtmlFactory = (input: DocumentRenderInput) => string | Promise<string>;
7
7
  export declare const defineDocumentHtmlFactory: (factory: DocumentHtmlFactory) => DocumentHtmlFactory;
8
+ export type { DocumentTheme } from "../templates/layout";
@@ -1,3 +1,4 @@
1
+ import type { ShopMasterData } from "../../public";
1
2
  import type { EmailKind } from "./email-kinds";
2
3
  import type { EmailRenderDataMap } from "./template-data";
3
4
  export type EmailTemplateContent = Readonly<{
@@ -5,10 +6,22 @@ export type EmailTemplateContent = Readonly<{
5
6
  subject: string;
6
7
  text: string;
7
8
  }>;
9
+ /**
10
+ * The shop's master data ("Shop-Stammdaten") plus the `logo` URL of the
11
+ * E-Mail settings, read when the mail is sent. Every field may be missing; a
12
+ * layout shows what is there instead of failing.
13
+ */
14
+ export type EmailShopDetails = Readonly<ShopMasterData & {
15
+ logo?: string;
16
+ }>;
17
+ /** Who reads a mail: a customer or the shop's own team. */
18
+ export type EmailAudience = "customer" | "shop";
8
19
  export type EmailLayout = (input: Readonly<{
20
+ audience: EmailAudience;
9
21
  bodyHtml: string;
10
22
  preheader: string;
11
23
  subject: string;
24
+ shop: EmailShopDetails;
12
25
  }>) => string;
13
26
  export type EmailRendererMap = {
14
27
  readonly [Kind in EmailKind]: (data: EmailRenderDataMap[Kind]) => EmailTemplateContent;
@@ -19,6 +32,13 @@ export type EmailRendererMap = {
19
32
  * partial `renderers` map replaces only the listed kinds.
20
33
  */
21
34
  export type ShopEmailConfiguration = Readonly<{
35
+ /**
36
+ * Link to an order in the Medusa Admin; the shop's order notification shows
37
+ * an "Im Admin öffnen" button only when it is set.
38
+ */
39
+ adminOrderUrl?: (input: Readonly<{
40
+ orderId: string;
41
+ }>) => string;
22
42
  affiliatePortalUrl: string;
23
43
  displayName: string;
24
44
  inviteUrl: (input: Readonly<{
@@ -30,6 +50,11 @@ export type ShopEmailConfiguration = Readonly<{
30
50
  locale: string | null;
31
51
  }>) => string;
32
52
  renderers?: Partial<EmailRendererMap>;
53
+ /**
54
+ * IANA time zone of dates in the default templates (e.g. the order time in
55
+ * the shop's order notification); without it they are left out.
56
+ */
57
+ timeZone?: string;
33
58
  }>;
34
59
  /** A `ShopEmailConfiguration` with the defaults merged in; used internally. */
35
60
  export type ResolvedShopEmailConfiguration = Readonly<Omit<ShopEmailConfiguration, "layout" | "renderers"> & {