@hintergrund/worker 0.3.4 → 0.3.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"setup.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/setup.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAWpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAyB9C,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAQtG;AAQD,uFAAuF;AACvF,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAIzE;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsMzE;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7E"}
1
+ {"version":3,"file":"setup.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/setup.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAWpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAyB9C,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAQtG;AAQD,uFAAuF;AACvF,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAIzE;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoMzE;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7E"}
@@ -188,10 +188,8 @@ export async function setupProject(c) {
188
188
  const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_CONFIG_PATH, {});
189
189
  await stageConfig(client, WEBSITE_CONFIG_PATH, {
190
190
  ...setupState,
191
- version: 1,
192
191
  complete: true,
193
192
  features,
194
- updatedAt: Date.now(),
195
193
  }, 'Record project features [skip ci]', setupCommitSha);
196
194
  const { data: shopSettings, commitSha: shopCommitSha } = await readJsonConfig(client, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS);
197
195
  await stageConfig(client, SHOP_SETTINGS_PATH, {
@@ -1 +1 @@
1
- {"version":3,"file":"campaigns.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/campaigns.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsB/B,qCAAqC;AACrC,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWhE;AAED,yCAAyC;AACzC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW/D;AAED,sCAAsC;AACtC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBlE;AAED,2CAA2C;AAC3C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2BlE;AAED,4CAA4C;AAC5C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYlE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6DhE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8BhE"}
1
+ {"version":3,"file":"campaigns.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/campaigns.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsB/B,qCAAqC;AACrC,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWhE;AAED,yCAAyC;AACzC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW/D;AAED,sCAAsC;AACtC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBlE;AAED,2CAA2C;AAC3C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2BlE;AAED,4CAA4C;AAC5C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYlE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyDhE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6BhE"}
@@ -139,9 +139,6 @@ export async function sendCampaign(c) {
139
139
  }
140
140
  const now = Date.now();
141
141
  const { settings, logoDataUrl } = await readEmailTemplateData(c.env);
142
- if (settings.automation?.newsletterEnabled === false) {
143
- return c.json({ success: false, message: 'Newsletters are disabled.' }, 403);
144
- }
145
142
  let sentCount = 0;
146
143
  let lastError;
147
144
  const origin = new URL(c.req.url).origin;
@@ -155,8 +152,7 @@ export async function sendCampaign(c) {
155
152
  subject: row.subject,
156
153
  html: renderEmailTemplate({
157
154
  bodyHtml: row.body_html,
158
- template: settings.emailTemplate,
159
- logoDataUrl,
155
+ template: settings.emailTemplate, logoDataUrl,
160
156
  unsubscribeUrl,
161
157
  }),
162
158
  });
@@ -197,8 +193,7 @@ export async function testCampaign(c) {
197
193
  subject: `[TEST] ${row.subject}`,
198
194
  html: renderEmailTemplate({
199
195
  bodyHtml: row.body_html,
200
- template: settings.emailTemplate,
201
- logoDataUrl,
196
+ template: settings.emailTemplate, logoDataUrl,
202
197
  }),
203
198
  });
204
199
  return c.json({ success: true, message: `Test email sent to ${body.email}` });
@@ -1,9 +1,9 @@
1
- import { type Brand, type InvoiceDesign, type InvoiceConfig, type InvoiceData } from '@hintergrund/runtime-contracts';
1
+ import { type Design, type InvoiceDesign, type InvoiceConfig, type InvoiceData } from '@hintergrund/runtime-contracts';
2
2
  export interface InvoiceAssets {
3
3
  logo?: Uint8Array;
4
4
  bodyFont?: Uint8Array;
5
5
  displayFont?: Uint8Array;
6
6
  }
7
7
  /** Same deterministic renderer for preview, downloads and email attachments. */
8
- export declare function generateInvoicePdf(config: InvoiceConfig, data: InvoiceData, brand: Brand, design: InvoiceDesign, assets?: InvoiceAssets): Promise<Uint8Array>;
8
+ export declare function generateInvoicePdf(config: InvoiceConfig, data: InvoiceData, design: Design, invoiceDesign: InvoiceDesign, assets?: InvoiceAssets): Promise<Uint8Array>;
9
9
  //# sourceMappingURL=invoice.handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/invoice.handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwC,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE5J,MAAM,WAAW,aAAa;IAAG,IAAI,CAAC,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,UAAU,CAAA;CAAE;AAErG,gFAAgF;AAChF,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4GvK"}
1
+ {"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/invoice.handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyC,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE9J,MAAM,WAAW,aAAa;IAAG,IAAI,CAAC,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,UAAU,CAAA;CAAE;AAErG,gFAAgF;AAChF,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CA6GhL"}
@@ -1,21 +1,22 @@
1
1
  import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
2
2
  import fontkit from '@pdf-lib/fontkit';
3
- import { validateBrand, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
3
+ import { validateDesign, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
4
4
  /** Same deterministic renderer for preview, downloads and email attachments. */
5
- export async function generateInvoicePdf(config, data, brand, design, assets = {}) {
6
- validateBrand(brand);
7
- validateInvoiceDesign(design);
5
+ export async function generateInvoicePdf(config, data, design, invoiceDesign, assets = {}) {
6
+ validateDesign(design);
7
+ validateInvoiceDesign(invoiceDesign);
8
8
  const pdf = await PDFDocument.create();
9
9
  pdf.registerFontkit(fontkit);
10
10
  const standard = (name) => name === 'Georgia' ? StandardFonts.TimesRoman : name === 'Courier New' ? StandardFonts.Courier : StandardFonts.Helvetica;
11
- if ((brand.bodyFontPath && !assets.bodyFont) || (brand.displayFontPath && !assets.displayFont))
12
- throw new Error('Missing brand font asset.');
13
- const font = await pdf.embedFont(assets.bodyFont ?? standard(brand.bodyFont), { subset: true });
14
- const heading = await pdf.embedFont(assets.displayFont ?? standard(brand.displayFont), { subset: true });
11
+ // PDFs embed the TTF/OTF `embed` file, never the woff2 the site downloads.
12
+ if ((design.fonts.body.embed && !assets.bodyFont) || (design.fonts.headings.embed && !assets.displayFont))
13
+ throw new Error('Missing design font asset.');
14
+ const font = await pdf.embedFont(assets.bodyFont ?? standard(design.fonts.body.family), { subset: true });
15
+ const heading = await pdf.embedFont(assets.displayFont ?? standard(design.fonts.headings.family), { subset: true });
15
16
  const color = (hex) => rgb(...[1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16) / 255));
16
- const ink = color(brand.colors.text), primary = color(brand.colors.primary), muted = color(brand.colors.muted);
17
- const [width, height] = design.pageSize === 'A4' ? [595.28, 841.89] : [612, 792];
18
- const margin = design.margin, size = design.fontSize, line = size * design.lineHeight;
17
+ const ink = color(design.colors.text), primary = color(design.colors.primary), muted = color(design.colors.muted);
18
+ const [width, height] = invoiceDesign.pageSize === 'A4' ? [595.28, 841.89] : [612, 792];
19
+ const margin = invoiceDesign.margin, size = invoiceDesign.fontSize, line = size * invoiceDesign.lineHeight;
19
20
  const contentWidth = width - 2 * margin;
20
21
  let page, y;
21
22
  const wrap = (text, maxWidth, face = font, fontSize = size) => {
@@ -45,30 +46,29 @@ export async function generateInvoicePdf(config, data, brand, design, assets = {
45
46
  }
46
47
  return lines;
47
48
  };
48
- const footerLines = wrap(design.footerText, contentWidth, font, 8);
49
+ const footerLines = wrap(invoiceDesign.footerText, contentWidth, font, 8);
49
50
  const bottom = margin + footerLines.length * 11 + 22;
50
51
  function newPage() {
51
52
  page = pdf.addPage([width, height]);
52
- page.drawRectangle({ x: 0, y: 0, width, height, color: color(brand.colors.surface) });
53
+ page.drawRectangle({ x: 0, y: 0, width, height, color: color(design.colors.surface) });
53
54
  y = height - margin;
54
55
  }
55
56
  function ensure(space) { if (y - space < bottom)
56
57
  newPage(); }
57
58
  function text(value, face = font, fontSize = size, tone = ink) {
58
59
  for (const row of wrap(value, contentWidth, face, fontSize)) {
59
- ensure(fontSize * design.lineHeight);
60
+ ensure(fontSize * invoiceDesign.lineHeight);
60
61
  page.drawText(row, { x: margin, y: y - fontSize, size: fontSize, font: face, color: tone });
61
- y -= fontSize * design.lineHeight;
62
+ y -= fontSize * invoiceDesign.lineHeight;
62
63
  }
63
64
  }
64
65
  newPage();
65
- if (design.showLogo && brand.logoPath) {
66
- if (!assets.logo)
67
- throw new Error('Missing brand logo asset.');
68
- const image = /\.png$/i.test(brand.logoPath) ? await pdf.embedPng(assets.logo) : await pdf.embedJpg(assets.logo);
69
- const scale = Math.min(design.logoWidth / image.width, 64 / image.height);
66
+ // The letterhead is chosen in invoice design, independent of the website.
67
+ if (invoiceDesign.logoPath && assets.logo) {
68
+ const image = /\.png$/i.test(invoiceDesign.logoPath) ? await pdf.embedPng(assets.logo) : await pdf.embedJpg(assets.logo);
69
+ const scale = Math.min(invoiceDesign.logoWidth / image.width, 64 / image.height);
70
70
  const w = image.width * scale, h = image.height * scale;
71
- const x = design.logoPosition === 'right' ? width - margin - w : design.logoPosition === 'center' ? (width - w) / 2 : margin;
71
+ const x = invoiceDesign.logoPosition === 'right' ? width - margin - w : invoiceDesign.logoPosition === 'center' ? (width - w) / 2 : margin;
72
72
  page.drawImage(image, { x, y: y - h, width: w, height: h });
73
73
  y -= h + line;
74
74
  }
@@ -76,7 +76,7 @@ export async function generateInvoicePdf(config, data, brand, design, assets = {
76
76
  if (value)
77
77
  text(value);
78
78
  y -= line;
79
- text('INVOICE', heading, design.titleSize, primary);
79
+ text('INVOICE', heading, invoiceDesign.titleSize, primary);
80
80
  text(`Invoice: ${data.invoiceNumber}`);
81
81
  text(`Date: ${data.invoiceDate}`);
82
82
  if (data.dueDate)
@@ -95,7 +95,7 @@ export async function generateInvoicePdf(config, data, brand, design, assets = {
95
95
  function tableHeader() {
96
96
  ensure(line * 3);
97
97
  page.drawRectangle({ x: margin, y: y - line - 10, width: contentWidth, height: line + 10, color: primary });
98
- const headerColor = (() => { const c = brand.colors.primary; const brightness = .299 * parseInt(c.slice(1, 3), 16) + .587 * parseInt(c.slice(3, 5), 16) + .114 * parseInt(c.slice(5, 7), 16); return brightness > 155 ? rgb(0, 0, 0) : rgb(1, 1, 1); })();
98
+ const headerColor = (() => { const c = design.colors.primary; const brightness = .299 * parseInt(c.slice(1, 3), 16) + .587 * parseInt(c.slice(3, 5), 16) + .114 * parseInt(c.slice(5, 7), 16); return brightness > 155 ? rgb(0, 0, 0) : rgb(1, 1, 1); })();
99
99
  for (const [label, x] of [['Description', margin + 6], ['Qty', qtyX - 20], ['Price', priceX - 30], ['Total', totalX - 30]])
100
100
  page.drawText(label, { x, y: y - size - 5, size, font, color: headerColor });
101
101
  y -= line + 16;
@@ -114,7 +114,7 @@ export async function generateInvoicePdf(config, data, brand, design, assets = {
114
114
  newPage();
115
115
  tableHeader();
116
116
  }
117
- if (design.tableStyle === 'striped' && index % 2 === 0)
117
+ if (invoiceDesign.tableStyle === 'striped' && index % 2 === 0)
118
118
  page.drawRectangle({ x: margin, y: y - line, width: contentWidth, height: line, color: primary, opacity: .06 });
119
119
  page.drawText(lines[i], { x: margin + 6, y: y - size, size, font, color: ink });
120
120
  if (i === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/public.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAS/B,gCAAgC;AAChC,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqD7D;AAsBD,6BAA6B;AAC7B,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0C3D;AAED,kCAAkC;AAClC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoC/D;AAED,yDAAyD;AACzD,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2DvE"}
1
+ {"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/public.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAS/B,gCAAgC;AAChC,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkD7D;AAqBD,6BAA6B;AAC7B,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0C3D;AAED,kCAAkC;AAClC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoC/D;AAED,yDAAyD;AACzD,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2DvE"}
@@ -11,9 +11,6 @@ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
11
11
  export async function subscribe(c) {
12
12
  try {
13
13
  const { settings } = await readEmailSettings(c.env);
14
- if (settings.automation?.newsletterEnabled === false) {
15
- return c.json({ success: false, message: 'Newsletter signup is disabled.' }, 403);
16
- }
17
14
  const body = await c.req.json();
18
15
  if (!body.email)
19
16
  return c.json({ success: false, message: 'Email is required' }, 400);
@@ -64,8 +61,7 @@ async function sendConfirmation(c, email, token) {
64
61
  const bodyHtml = (automation?.confirmation?.bodyHtml || DEFAULT_SUBSCRIPTION_TEMPLATES.confirmation.bodyHtml).replaceAll('{{confirm_url}}', confirmUrl);
65
62
  const html = renderEmailTemplate({
66
63
  bodyHtml,
67
- template: settings.emailTemplate,
68
- logoDataUrl,
64
+ template: settings.emailTemplate, logoDataUrl,
69
65
  });
70
66
  await sendEmail(c.env, { to: email, subject: automation?.confirmation?.subject || DEFAULT_SUBSCRIPTION_TEMPLATES.confirmation.subject, html });
71
67
  }
@@ -93,7 +89,7 @@ export async function confirm(c) {
93
89
  const result = await db.prepare(`UPDATE subscribers SET status = 'subscribed', confirmed_at = ?, subscribed_at = ?, confirmation_token = NULL, updated_at = ? WHERE id = ? AND status = 'pending' AND confirmation_token = ?`).bind(now, now, now, subscriber.id, token).run();
94
90
  // Only the request that consumes the token sends a welcome. Confirmation stays
95
91
  // successful if the provider fails; never undo consent or send it twice on refresh.
96
- if (result.meta.changes > 0 && settings.automation?.newsletterEnabled !== false) {
92
+ if (result.meta.changes > 0) {
97
93
  const welcome = settings.automation?.welcome ?? DEFAULT_SUBSCRIPTION_TEMPLATES.welcome;
98
94
  try {
99
95
  await sendEmail(c.env, {
@@ -1 +1 @@
1
- {"version":3,"file":"send.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/send.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAQ/B,8DAA8D;AAC9D,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsCrE;AAED,wEAAwE;AACxE,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiDjE"}
1
+ {"version":3,"file":"send.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/send.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAQ/B,8DAA8D;AAC9D,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqCrE;AAED,wEAAwE;AACxE,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6CjE"}
@@ -23,8 +23,7 @@ export async function sendTransactional(c) {
23
23
  subject: body.subject,
24
24
  html: renderEmailTemplate({
25
25
  bodyHtml: body.bodyHtml,
26
- template: settings.emailTemplate,
27
- logoDataUrl,
26
+ template: settings.emailTemplate, logoDataUrl,
28
27
  }),
29
28
  from: body.from,
30
29
  replyTo: body.replyTo,
@@ -45,9 +44,6 @@ export async function sendBulkEmail(c) {
45
44
  }
46
45
  const db = getProjectDb(c.env);
47
46
  const { settings, logoDataUrl } = await readEmailTemplateData(c.env);
48
- if (settings.automation?.newsletterEnabled === false) {
49
- return c.json({ success: false, message: 'Newsletters are disabled.' }, 403);
50
- }
51
47
  const { results: subscribers } = await db
52
48
  .prepare("SELECT email, name FROM subscribers WHERE status = 'subscribed'")
53
49
  .all();
@@ -65,8 +61,7 @@ export async function sendBulkEmail(c) {
65
61
  subject: body.subject,
66
62
  html: renderEmailTemplate({
67
63
  bodyHtml: body.bodyHtml,
68
- template: settings.emailTemplate,
69
- logoDataUrl,
64
+ template: settings.emailTemplate, logoDataUrl,
70
65
  unsubscribeUrl,
71
66
  }),
72
67
  });
@@ -5,22 +5,19 @@ import { EMAIL_SETTINGS_PATH, type EmailSettings, type InvoiceConfig } from '@hi
5
5
  export { EMAIL_SETTINGS_PATH };
6
6
  export declare const DEFAULT_INVOICE: InvoiceConfig;
7
7
  export declare const DEFAULT_EMAIL_SETTINGS: EmailSettings;
8
+ /** Reads the letterhead chosen in email settings and inlines it, as mail clients need a data URL. */
8
9
  export declare function resolveLogoDataUrl(github: GitHubClient, logoPath: string | undefined): Promise<string | undefined>;
9
10
  export declare function readEmailSettings(env: Bindings): Promise<{
10
11
  settings: {
11
12
  invoice: {
12
- companyName: string;
13
- companyAddress: string;
14
- companyEmail: string;
15
- companyPhone: string;
16
- dueDays: number;
13
+ companyName?: string;
14
+ companyAddress?: string;
15
+ companyEmail?: string;
16
+ companyPhone?: string;
17
+ dueDays?: number;
17
18
  };
18
- logoPath: string | undefined;
19
19
  emailTemplate: import("@hintergrund/runtime-contracts").EmailTemplateConfig;
20
- emailBrand?: import("@hintergrund/runtime-contracts").Brand;
21
20
  automation?: {
22
- newsletterEnabled?: boolean;
23
- doubleOptIn?: boolean;
24
21
  confirmation?: {
25
22
  subject: string;
26
23
  bodyHtml: string;
@@ -31,28 +28,24 @@ export declare function readEmailSettings(env: Bindings): Promise<{
31
28
  };
32
29
  };
33
30
  footerHtml?: string;
31
+ logoPath?: string;
34
32
  fromEmail?: string;
35
33
  fromName?: string;
36
34
  replyTo?: string;
37
- updatedAt: number;
38
35
  };
39
36
  commitSha: string;
40
37
  }>;
41
38
  export declare function readEmailTemplateData(env: Bindings): Promise<{
42
39
  settings: {
43
40
  invoice: {
44
- companyName: string;
45
- companyAddress: string;
46
- companyEmail: string;
47
- companyPhone: string;
48
- dueDays: number;
41
+ companyName?: string;
42
+ companyAddress?: string;
43
+ companyEmail?: string;
44
+ companyPhone?: string;
45
+ dueDays?: number;
49
46
  };
50
- logoPath: string | undefined;
51
47
  emailTemplate: import("@hintergrund/runtime-contracts").EmailTemplateConfig;
52
- emailBrand?: import("@hintergrund/runtime-contracts").Brand;
53
48
  automation?: {
54
- newsletterEnabled?: boolean;
55
- doubleOptIn?: boolean;
56
49
  confirmation?: {
57
50
  subject: string;
58
51
  bodyHtml: string;
@@ -63,10 +56,10 @@ export declare function readEmailTemplateData(env: Bindings): Promise<{
63
56
  };
64
57
  };
65
58
  footerHtml?: string;
59
+ logoPath?: string;
66
60
  fromEmail?: string;
67
61
  fromName?: string;
68
62
  replyTo?: string;
69
- updatedAt: number;
70
63
  };
71
64
  logoDataUrl: string | undefined;
72
65
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/settings.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAAyC,KAAK,aAAa,EAAE,KAAK,aAAa,EAAiC,MAAM,gCAAgC,CAAC;AAGnL,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,eAAO,MAAM,eAAe,EAAE,aAAwG,CAAC;AACvI,eAAO,MAAM,sBAAsB,EAAE,aAA0D,CAAC;AAEhG,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKxH;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ;;;;;;;;;;;;;6BAElC,CAAC;uBAA8B,CAAC;wBAA+B,CAAC;;;;mBAEnE,CAAC;;;;;;;;;;;;GAEhB;AACD,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,QAAQ;;;;;;;;;;;;;6BALtC,CAAC;uBAA8B,CAAC;wBAA+B,CAAC;;;;mBAEnE,CAAC;;;;;;;;;;;;GAOhB;AACD,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMvF;AACD,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkBxF"}
1
+ {"version":3,"file":"settings.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/settings.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAA2B,KAAK,aAAa,EAAE,KAAK,aAAa,EAAiC,MAAM,gCAAgC,CAAC;AAGrK,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,eAAO,MAAM,eAAe,EAAE,aAAwG,CAAC;AACvI,eAAO,MAAM,sBAAsB,EAAE,aAA4C,CAAC;AAElF,qGAAqG;AACrG,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKxH;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ;;;;;;;;;;;wBAAxC,CAAC;;;;mBACgC,CAAC;;;;;;;;;;;;GAK9C;AACD,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,QAAQ;;;;;;;;;;;wBAP5C,CAAC;;;;mBACgC,CAAC;;;;;;;;;;;;GAU9C;AACD,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMvF;AACD,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkBxF"}
@@ -1,25 +1,26 @@
1
1
  import { getGitHubConfig } from '../../../lib/config';
2
2
  import { createGitHubClient } from '../../../lib/github';
3
3
  import { readJsonConfig, writeJsonConfig, ConfigConflictError } from '../../../lib/github-config';
4
- import { EMAIL_SETTINGS_PATH, emailTemplateFromBrand, validateBrand } from '@hintergrund/runtime-contracts';
5
- import { readBrand } from '../../../lib/brand';
4
+ import { EMAIL_SETTINGS_PATH, emailTemplateFromDesign } from '@hintergrund/runtime-contracts';
5
+ import { readDesign } from '../../../lib/design';
6
6
  export { EMAIL_SETTINGS_PATH };
7
7
  export const DEFAULT_INVOICE = { companyName: '', companyAddress: '', companyEmail: '', companyPhone: '', dueDays: 14 };
8
- export const DEFAULT_EMAIL_SETTINGS = { invoice: DEFAULT_INVOICE, updatedAt: 0 };
8
+ export const DEFAULT_EMAIL_SETTINGS = { invoice: DEFAULT_INVOICE };
9
+ /** Reads the letterhead chosen in email settings and inlines it, as mail clients need a data URL. */
9
10
  export async function resolveLogoDataUrl(github, logoPath) {
10
11
  if (!logoPath)
11
12
  return undefined;
12
13
  const file = await github.readFileBinary(logoPath);
13
14
  if (!file)
14
- throw new Error('Brand logo not found.');
15
+ return undefined;
15
16
  return `data:${/\.png$/i.test(logoPath) ? 'image/png' : 'image/jpeg'};base64,${file.content}`;
16
17
  }
17
18
  export async function readEmailSettings(env) {
18
19
  const github = createGitHubClient(getGitHubConfig(env));
19
20
  const { data, commitSha } = await readJsonConfig(github, EMAIL_SETTINGS_PATH, DEFAULT_EMAIL_SETTINGS);
20
- const brand = await readBrand(env);
21
- return { settings: { ...data, invoice: { ...DEFAULT_INVOICE, ...data.invoice }, logoPath: brand.logoPath ?? undefined,
22
- emailTemplate: emailTemplateFromBrand(data.emailBrand ? validateBrand(data.emailBrand) : brand, data.footerHtml) }, commitSha };
21
+ const design = await readDesign(env);
22
+ return { settings: { ...data, invoice: { ...DEFAULT_INVOICE, ...data.invoice },
23
+ emailTemplate: emailTemplateFromDesign(design, data.footerHtml) }, commitSha };
23
24
  }
24
25
  export async function readEmailTemplateData(env) {
25
26
  const { settings } = await readEmailSettings(env);
@@ -42,7 +43,7 @@ export async function saveSettings(c) {
42
43
  try {
43
44
  const body = await c.req.json();
44
45
  const { data: current } = await readJsonConfig(github, EMAIL_SETTINGS_PATH, DEFAULT_EMAIL_SETTINGS);
45
- const next = { ...current, invoice: { ...DEFAULT_INVOICE, ...current.invoice, ...body.invoice }, updatedAt: Date.now() };
46
+ const next = { ...current, invoice: { ...DEFAULT_INVOICE, ...current.invoice, ...body.invoice } };
46
47
  for (const key of ['fromEmail', 'fromName', 'replyTo', 'footerHtml']) {
47
48
  if (body[key] !== undefined) {
48
49
  if (typeof body[key] !== 'string')
@@ -1,7 +1,7 @@
1
1
  import { getEmailsConfig } from '../../../lib/config';
2
2
  import Stripe from 'stripe';
3
3
  import { renderInvoice } from '../../../lib/invoice';
4
- import { base64 } from '../../../lib/brand';
4
+ import { base64 } from '../../../lib/design';
5
5
  import { sendEmail } from '../../../lib/email';
6
6
  import { DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
7
7
  import { renderEmailTemplate } from '../../../lib/email-template';
@@ -1,6 +1,6 @@
1
1
  import type { Bindings } from '../index';
2
- export declare function readBrand(env: Bindings): Promise<import("@hintergrund/runtime-contracts").Brand>;
2
+ export declare function readDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").Design>;
3
3
  export declare function readInvoiceDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").InvoiceDesign>;
4
- export declare function readBrandAsset(env: Bindings, path: string): Promise<Uint8Array>;
4
+ export declare function readDesignAsset(env: Bindings, path: string): Promise<Uint8Array>;
5
5
  export declare function base64(bytes: Uint8Array): string;
6
6
  //# sourceMappingURL=brand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,SAAS,CAAC,GAAG,EAAE,QAAQ,2DAK5C;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,mEAIpD;AACD,wBAAsB,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMrF;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIhD"}
1
+ {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,UAAU,CAAC,GAAG,EAAE,QAAQ,4DAK7C;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,mEAIpD;AACD,wBAAsB,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMtF;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIhD"}
package/dist/lib/brand.js CHANGED
@@ -1,26 +1,26 @@
1
- import { BRAND_PATH, validateBrand, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN, validateInvoiceDesign, publicAssetPath } from '@hintergrund/runtime-contracts';
1
+ import { DESIGN_PATH, validateDesign, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN, validateInvoiceDesign, publicAssetPath } from '@hintergrund/runtime-contracts';
2
2
  import { createGitHubClient } from './github';
3
3
  import { getGitHubConfig } from './config';
4
4
  import { readJsonConfig } from './github-config';
5
- export async function readBrand(env) {
5
+ export async function readDesign(env) {
6
6
  const github = createGitHubClient(getGitHubConfig(env));
7
- const file = await github.readJsonFileIfExists(BRAND_PATH);
7
+ const file = await github.readJsonFileIfExists(DESIGN_PATH);
8
8
  if (!file)
9
- throw new Error(`Missing ${BRAND_PATH}. Every website template ships one.`);
10
- return validateBrand(file.data);
9
+ throw new Error(`Missing ${DESIGN_PATH}. Every website template ships one.`);
10
+ return validateDesign(file.data);
11
11
  }
12
12
  export async function readInvoiceDesign(env) {
13
13
  const github = createGitHubClient(getGitHubConfig(env));
14
14
  const { data } = await readJsonConfig(github, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN);
15
15
  return validateInvoiceDesign(data);
16
16
  }
17
- export async function readBrandAsset(env, path) {
17
+ export async function readDesignAsset(env, path) {
18
18
  publicAssetPath(path);
19
19
  const file = await createGitHubClient(getGitHubConfig(env)).readFileBinary(path);
20
20
  if (!file)
21
- throw new Error(`Brand asset not found: ${path}`);
21
+ throw new Error(`Design asset not found: ${path}`);
22
22
  if (file.content.length > 8 * 1024 * 1024)
23
- throw new Error('Brand asset exceeds 6 MB.');
23
+ throw new Error('Design asset exceeds 6 MB.');
24
24
  return Uint8Array.from(atob(file.content), char => char.charCodeAt(0));
25
25
  }
26
26
  export function base64(bytes) {
@@ -0,0 +1,6 @@
1
+ import type { Bindings } from '../index';
2
+ export declare function readDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").Design>;
3
+ export declare function readInvoiceDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").InvoiceDesign>;
4
+ export declare function readDesignAsset(env: Bindings, path: string): Promise<Uint8Array>;
5
+ export declare function base64(bytes: Uint8Array): string;
6
+ //# sourceMappingURL=design.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"design.d.ts","sourceRoot":"","sources":["../../src/lib/design.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,UAAU,CAAC,GAAG,EAAE,QAAQ,4DAK7C;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,mEAIpD;AACD,wBAAsB,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMtF;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIhD"}
@@ -0,0 +1,31 @@
1
+ import { DESIGN_PATH, validateDesign, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN, validateInvoiceDesign, publicAssetPath } from '@hintergrund/runtime-contracts';
2
+ import { createGitHubClient } from './github';
3
+ import { getGitHubConfig } from './config';
4
+ import { readJsonConfig } from './github-config';
5
+ export async function readDesign(env) {
6
+ const github = createGitHubClient(getGitHubConfig(env));
7
+ const file = await github.readJsonFileIfExists(DESIGN_PATH);
8
+ if (!file)
9
+ throw new Error(`Missing ${DESIGN_PATH}. Every website template ships one.`);
10
+ return validateDesign(file.data);
11
+ }
12
+ export async function readInvoiceDesign(env) {
13
+ const github = createGitHubClient(getGitHubConfig(env));
14
+ const { data } = await readJsonConfig(github, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN);
15
+ return validateInvoiceDesign(data);
16
+ }
17
+ export async function readDesignAsset(env, path) {
18
+ publicAssetPath(path);
19
+ const file = await createGitHubClient(getGitHubConfig(env)).readFileBinary(path);
20
+ if (!file)
21
+ throw new Error(`Design asset not found: ${path}`);
22
+ if (file.content.length > 8 * 1024 * 1024)
23
+ throw new Error('Design asset exceeds 6 MB.');
24
+ return Uint8Array.from(atob(file.content), char => char.charCodeAt(0));
25
+ }
26
+ export function base64(bytes) {
27
+ let result = '';
28
+ for (let i = 0; i < bytes.length; i += 8192)
29
+ result += String.fromCharCode(...bytes.subarray(i, i + 8192));
30
+ return btoa(result);
31
+ }
@@ -1,8 +1,9 @@
1
1
  import type { EmailTemplateConfig } from '@hintergrund/runtime-contracts';
2
2
  export interface RenderEmailTemplateOptions {
3
3
  bodyHtml: string;
4
- /** Always derived from the project's brand via emailTemplateFromBrand. */
4
+ /** Always derived from the project's design via emailTemplateFromDesign. */
5
5
  template: EmailTemplateConfig;
6
+ /** Data URL of the letterhead chosen in email settings, if any. */
6
7
  logoDataUrl?: string;
7
8
  unsubscribeUrl?: string;
8
9
  footerHtml?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"email-template.d.ts","sourceRoot":"","sources":["../../src/lib/email-template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAqB1E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAkB/E"}
1
+ {"version":3,"file":"email-template.d.ts","sourceRoot":"","sources":["../../src/lib/email-template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAqB1E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAkB/E"}
@@ -1,4 +1,4 @@
1
- /** Brand colors are validated as #rrggbb; refuse anything else rather than interpolate it into style="". */
1
+ /** Design colors are validated as #rrggbb; refuse anything else rather than interpolate it into style="". */
2
2
  function safeColor(value) {
3
3
  return value && /^#[\da-f]{6}$/i.test(value) ? value : 'inherit';
4
4
  }
@@ -20,16 +20,16 @@ export function renderEmailTemplate(options) {
20
20
  const template = options.template;
21
21
  const primaryColor = safeColor(template.primaryColor);
22
22
  const bodyHtml = styleEmailBody(options.bodyHtml, primaryColor, template.headingFont);
23
+ const footerHtml = options.footerHtml ?? template.footerHtml ?? '';
23
24
  const logoHtml = options.logoDataUrl
24
- ? `<div style="text-align:center;margin:0 0 20px 0;"><img src="${options.logoDataUrl}" alt="Logo" style="max-width:120px;max-height:80px;height:auto;"></div>`
25
+ ? `<div style="text-align:center;margin:0 0 20px 0;"><img src="${options.logoDataUrl}" alt="" style="max-width:120px;max-height:80px;height:auto;"></div>`
25
26
  : '';
26
- const footerHtml = options.footerHtml ?? template.footerHtml ?? '';
27
27
  const unsubscribeHtml = options.unsubscribeUrl
28
28
  ? `<p style="margin:10px 0 0 0;"><a href="${options.unsubscribeUrl}" style="color:inherit;text-decoration:underline;">Unsubscribe</a></p>`
29
29
  : '';
30
30
  return template.html
31
- .replaceAll('{{content}}', bodyHtml)
32
31
  .replaceAll('{{logo}}', logoHtml)
32
+ .replaceAll('{{content}}', bodyHtml)
33
33
  .replaceAll('{{footer}}', footerHtml)
34
34
  .replaceAll('{{unsubscribe}}', unsubscribeHtml)
35
35
  .replaceAll('{{unsubscribe_url}}', options.unsubscribeUrl ?? '');
@@ -1,9 +1,9 @@
1
1
  import type { Context } from 'hono';
2
- import { type Brand, type InvoiceDesign, type InvoiceData } from '@hintergrund/runtime-contracts';
2
+ import { type Design, type InvoiceDesign, type InvoiceData } from '@hintergrund/runtime-contracts';
3
3
  import type { Bindings } from '../index';
4
4
  export declare function renderInvoice(env: Bindings, data: InvoiceData, draft?: {
5
- brand: Brand;
6
- design: InvoiceDesign;
5
+ design: Design;
6
+ invoiceDesign: InvoiceDesign;
7
7
  assets?: Partial<Record<'logo' | 'bodyFont' | 'displayFont', Uint8Array>>;
8
8
  }): Promise<Uint8Array<ArrayBufferLike>>;
9
9
  /** Authenticated, side-effect-free preview. Only presentation can be supplied. */
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../src/lib/invoice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAwC,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACxI,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,aAAa,EAAE,UAAU,CAAC,CAAC,CAAA;CAAE,wCAU/L;AAED,kFAAkF;AAClF,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqB1F"}
1
+ {"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../src/lib/invoice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAyC,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC1I,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,UAAU,GAAG,aAAa,EAAE,UAAU,CAAC,CAAC,CAAA;CAAE,wCAUxM;AAED,kFAAkF;AAClF,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqB1F"}
@@ -1,23 +1,23 @@
1
- import { validateBrand, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
2
- import { readBrand, readInvoiceDesign, readBrandAsset } from './brand';
1
+ import { validateDesign, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
2
+ import { readDesign, readInvoiceDesign, readDesignAsset } from './design';
3
3
  import { readEmailSettings } from '../api/emails/handlers/settings.handler';
4
4
  import { generateInvoicePdf } from '../api/emails/handlers/invoice.handler';
5
5
  export async function renderInvoice(env, data, draft) {
6
- const brand = draft?.brand ?? await readBrand(env);
7
- const design = draft?.design ?? await readInvoiceDesign(env);
6
+ const design = draft?.design ?? await readDesign(env);
7
+ const invoiceDesign = draft?.invoiceDesign ?? await readInvoiceDesign(env);
8
8
  const { settings } = await readEmailSettings(env);
9
9
  const [logo, bodyFont, displayFont] = await Promise.all([
10
- design.showLogo && brand.logoPath ? draft?.assets?.logo ?? readBrandAsset(env, brand.logoPath) : undefined,
11
- brand.bodyFontPath ? draft?.assets?.bodyFont ?? readBrandAsset(env, brand.bodyFontPath) : undefined,
12
- brand.displayFontPath ? draft?.assets?.displayFont ?? readBrandAsset(env, brand.displayFontPath) : undefined,
10
+ invoiceDesign.logoPath ? draft?.assets?.logo ?? readDesignAsset(env, invoiceDesign.logoPath) : undefined,
11
+ design.fonts.body.embed ? draft?.assets?.bodyFont ?? readDesignAsset(env, design.fonts.body.embed) : undefined,
12
+ design.fonts.headings.embed ? draft?.assets?.displayFont ?? readDesignAsset(env, design.fonts.headings.embed) : undefined,
13
13
  ]);
14
- return generateInvoicePdf(settings.invoice, data, brand, design, { logo, bodyFont, displayFont });
14
+ return generateInvoicePdf(settings.invoice, data, design, invoiceDesign, { logo, bodyFont, displayFont });
15
15
  }
16
16
  /** Authenticated, side-effect-free preview. Only presentation can be supplied. */
17
17
  export async function previewInvoice(c) {
18
18
  try {
19
19
  const input = await c.req.json();
20
- const brand = validateBrand(input.brand), design = validateInvoiceDesign(input.design);
20
+ const design = validateDesign(input.design), invoiceDesign = validateInvoiceDesign(input.invoiceDesign);
21
21
  const assets = {};
22
22
  for (const key of ['logo', 'bodyFont', 'displayFont']) {
23
23
  const content = input.assets?.[key];
@@ -32,7 +32,7 @@ export async function previewInvoice(c) {
32
32
  customerName: 'Sample Customer', customerEmail: 'sample@example.com', customerAddress: 'Example Street 12\n12345 Example City',
33
33
  items: [{ description: 'Sample product', quantity: 2, unitPrice: 25, total: 50 }, { description: 'A longer service description to demonstrate wrapping in the invoice table', quantity: 1, unitPrice: 100, total: 100 }],
34
34
  subtotal: 150, tax: 28.5, total: 178.5, currency: 'EUR', notes: 'PREVIEW ONLY — not a financial document.',
35
- }, { brand, design, assets });
35
+ }, { design, invoiceDesign, assets });
36
36
  return new Response(pdf, { headers: { 'Content-Type': 'application/pdf', 'Cache-Control': 'no-store', 'Content-Disposition': 'inline; filename="invoice-preview.pdf"' } });
37
37
  }
38
38
  catch (error) {
@@ -9,7 +9,7 @@ export function getTemplate(element, uiBaseUrl, params = '') {
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1">
10
10
  <title>Login</title>
11
11
  <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
12
- <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; height: 100vh; }</style>
12
+ <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; min-height: 100dvh; }</style>
13
13
  <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
14
14
  </head>
15
15
  <body>
@@ -52,7 +52,7 @@ export function getTemplate(element, uiBaseUrl, params = '') {
52
52
  <link rel="preconnect" href="https://fonts.googleapis.com">
53
53
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
54
54
  <link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
55
- <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; height: 100vh; }</style>
55
+ <style>* { box-sizing: border-box; margin: 0; padding: 0; } html, body { margin: 0; height: 100dvh; overflow: hidden; }</style>
56
56
  <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
57
57
  </head>
58
58
  <body>
@@ -74,7 +74,7 @@ export function getTemplate(element, uiBaseUrl, params = '') {
74
74
  <link rel="preconnect" href="https://fonts.googleapis.com">
75
75
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
76
76
  <link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
77
- <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; height: 100vh; }</style>
77
+ <style>* { box-sizing: border-box; margin: 0; padding: 0; } html, body { margin: 0; height: 100dvh; overflow: hidden; }</style>
78
78
  <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
79
79
  </head>
80
80
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hintergrund/worker",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dist"
15
15
  ],
16
16
  "devDependencies": {
17
- "@cloudflare/workers-types": "^4.20250111.0",
17
+ "@cloudflare/workers-types": "^5.20260915.1",
18
18
  "concurrently": "^9.2.1",
19
19
  "typescript": "^5.5.2"
20
20
  },
@@ -24,12 +24,12 @@
24
24
  "@pdf-lib/fontkit": "^1.1.1",
25
25
  "blakejs": "^1.2.1",
26
26
  "cookie": "^1.0.2",
27
- "hono": "^4.10.2",
27
+ "hono": "^4.13.8",
28
28
  "pdf-lib": "^1.17.1",
29
29
  "postal-mime": "^3.0.0",
30
30
  "stripe": "^17.5.0",
31
31
  "tweetnacl": "^1.0.3",
32
- "@hintergrund/runtime-contracts": "0.3.4"
32
+ "@hintergrund/runtime-contracts": "0.3.6"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc",