feat(cms): white-label email templates and API doc config (#2)
All checks were successful
Build and publish / build (push) Successful in 7m11s
All checks were successful
Build and publish / build (push) Successful in 7m11s
## Summary - Replace all hardcoded muellerprints brand identity in email templates with template variables sourced from env vars - Inject shop context into both `sendInvoice` and `sendDeliveryNote` template calls in `order.ts` - Make API documentation title/description env-var driven ## New env vars (all optional with safe defaults) | Var | Default | Used in | |-----|---------|---------| | `SHOP_NAME` | `"Shop"` | Email subject, body, footer | | `SHOP_CONTACT_NAME` | `""` | Email footer | | `SHOP_ADDRESS` | `""` | Email footer | | `SHOP_PHONE` | `""` | Email footer | | `SHOP_EMAIL` | `ADMIN_EMAIL_ADDRESS` | Email footer | | `SHOP_LOGO_URL` | `""` | Email header logo | | `SHOP_SECONDARY_LOGO_URL` | `""` | Email footer logo | | `API_TITLE` | `"Paperwork API"` | Swagger/OpenAPI title | | `API_DESCRIPTION` | `"Paperwork API"` | Swagger/OpenAPI description | ## Test plan - [ ] Set `SHOP_NAME=TestShop` and trigger invoice send → confirm subject and body use `TestShop` - [ ] Leave `SHOP_NAME` unset → confirm default `"Shop"` appears - [ ] Set `SHOP_LOGO_URL` → confirm logo renders in email header; unset → confirm no broken `<img>` tag - [ ] Check Strapi admin `/documentation` with `API_TITLE=MyAPI` env var Closes #1 Reviewed-on: #2 Co-authored-by: Michael Czechowski <mail@dailysh.it> Co-committed-by: Michael Czechowski <mail@dailysh.it>
This commit is contained in:
@@ -3,7 +3,7 @@ import fs from "fs";
|
||||
import { factories } from "@strapi/strapi";
|
||||
import { sanitize } from "@strapi/utils";
|
||||
import { ID } from "@strapi/database/dist/types";
|
||||
import { vatDecimal, vatIncludedDecimal, baseUrl, adminEmail } from "../../../../config/constants";
|
||||
import { vatDecimal, vatIncludedDecimal, baseUrl, adminEmail, shopName, shopContactName, shopAddress, shopPhone, shopEmail, shopLogoUrl, shopSecondaryLogoUrl } from "../../../../config/constants";
|
||||
import { calculateTotalProductPrice, productDefaultParams } from "../../product/services/product";
|
||||
import { CartProduct, Order, PdfBody } from "../../../../types";
|
||||
import { pdfApi } from "../../../services/PdfApi";
|
||||
@@ -81,12 +81,13 @@ export default factories.createCoreService("api::order.order", ({ strapi }) => (
|
||||
strapi.log.info(`app:i:order-service: - Sending invoice for order ${uuid}`);
|
||||
const oderUnsafe = (await strapi.service("api::order.order").findOneByUuid(uuid)) as Partial<Order>;
|
||||
|
||||
const shopContext = { shopName, shopContactName, shopAddress, shopPhone, shopEmail, shopLogoUrl, shopSecondaryLogoUrl };
|
||||
try {
|
||||
const emailConfig: MessageBody = {
|
||||
to_email: oderUnsafe.email,
|
||||
subject: template(invoiceEmailTemplate.subject)(oderUnsafe),
|
||||
message: template(invoiceEmailTemplate.text)({ baseUrl, ...oderUnsafe }),
|
||||
html: template(invoiceEmailTemplate.html)({ baseUrl, ...oderUnsafe })
|
||||
subject: template(invoiceEmailTemplate.subject)({ ...shopContext, ...oderUnsafe }),
|
||||
message: template(invoiceEmailTemplate.text)({ baseUrl, ...shopContext, ...oderUnsafe }),
|
||||
html: template(invoiceEmailTemplate.html)({ baseUrl, ...shopContext, ...oderUnsafe })
|
||||
};
|
||||
|
||||
strapi.log.debug(`app:d:order-service: - Email config ${emailConfig.html}`);
|
||||
@@ -118,12 +119,13 @@ export default factories.createCoreService("api::order.order", ({ strapi }) => (
|
||||
sendDeliveryNote: async (uuid: string, blob?: ArrayBuffer) => {
|
||||
strapi.log.info(`app:i:order-service: - Sending delivery note for order ${uuid}`);
|
||||
const oderUnsafe = (await strapi.service("api::order.order").findOneByUuid(uuid)) as Partial<Order>;
|
||||
const shopContext = { shopName, shopContactName, shopAddress, shopPhone, shopEmail, shopLogoUrl, shopSecondaryLogoUrl };
|
||||
try {
|
||||
const emailConfig: MessageBody = {
|
||||
to_email: oderUnsafe.email,
|
||||
subject: template(deliveryNoteEmailTemplate.subject)(oderUnsafe),
|
||||
message: template(deliveryNoteEmailTemplate.text)(oderUnsafe),
|
||||
html: template(deliveryNoteEmailTemplate.html)({ ...oderUnsafe, baseUrl })
|
||||
subject: template(deliveryNoteEmailTemplate.subject)({ ...shopContext, ...oderUnsafe }),
|
||||
message: template(deliveryNoteEmailTemplate.text)({ ...shopContext, ...oderUnsafe }),
|
||||
html: template(deliveryNoteEmailTemplate.html)({ baseUrl, ...shopContext, ...oderUnsafe })
|
||||
};
|
||||
await mailApi.sendTextMessage(emailConfig);
|
||||
strapi.log.info(`app:i:order-service: ✔ Sending delivery note for order ${uuid}`);
|
||||
|
||||
Reference in New Issue
Block a user