@hintergrund/worker 0.1.6 → 0.1.7

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 (186) hide show
  1. package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
  2. package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
  3. package/dist/api/cms/handlers/admin-users.handler.js +121 -0
  4. package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
  5. package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
  6. package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
  7. package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
  8. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/auth.handler.js +74 -153
  10. package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  12. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  13. package/dist/api/cms/routes/index.d.ts.map +1 -1
  14. package/dist/api/cms/routes/index.js +16 -4
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  17. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  18. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  19. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  20. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  21. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  22. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  23. package/dist/api/emails/handlers/public.handler.js +150 -312
  24. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  25. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  26. package/dist/api/emails/handlers/send.handler.js +107 -92
  27. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  28. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  29. package/dist/api/emails/handlers/settings.handler.js +96 -287
  30. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  32. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  33. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  34. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  35. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  36. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  37. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  38. package/dist/api/emails/routes/admin.routes.js +19 -49
  39. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  40. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  41. package/dist/api/emails/routes/public.routes.js +2 -9
  42. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  43. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  44. package/dist/api/shop/handlers/prices.handler.js +2 -83
  45. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  46. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  47. package/dist/api/shop/handlers/products.handler.js +195 -162
  48. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  49. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  50. package/dist/api/shop/handlers/public.handler.js +525 -78
  51. package/dist/api/shop/routes.d.ts.map +1 -1
  52. package/dist/api/shop/routes.js +14 -9
  53. package/dist/hintergrund-assets.d.ts +3 -2
  54. package/dist/hintergrund-assets.d.ts.map +1 -1
  55. package/dist/hintergrund-assets.js +4 -2
  56. package/dist/index.d.ts +14 -7
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +44 -4
  59. package/dist/lib/auth/crypto.d.ts +2 -15
  60. package/dist/lib/auth/crypto.d.ts.map +1 -1
  61. package/dist/lib/auth/crypto.js +8 -95
  62. package/dist/lib/auth/jwt.d.ts +0 -4
  63. package/dist/lib/auth/jwt.d.ts.map +1 -1
  64. package/dist/lib/auth/jwt.js +0 -6
  65. package/dist/lib/config.d.ts +1 -1
  66. package/dist/lib/config.d.ts.map +1 -1
  67. package/dist/lib/config.js +42 -86
  68. package/dist/lib/email-template.d.ts +15 -0
  69. package/dist/lib/email-template.d.ts.map +1 -0
  70. package/dist/lib/email-template.js +58 -0
  71. package/dist/lib/email.d.ts +18 -8
  72. package/dist/lib/email.d.ts.map +1 -1
  73. package/dist/lib/email.js +59 -70
  74. package/dist/lib/github-config.d.ts +19 -0
  75. package/dist/lib/github-config.d.ts.map +1 -0
  76. package/dist/lib/github-config.js +23 -0
  77. package/dist/lib/github.d.ts +10 -0
  78. package/dist/lib/github.d.ts.map +1 -1
  79. package/dist/lib/github.js +20 -2
  80. package/dist/lib/project-db.d.ts +24 -0
  81. package/dist/lib/project-db.d.ts.map +1 -0
  82. package/dist/lib/project-db.js +172 -0
  83. package/dist/lib/template.js +4 -4
  84. package/dist/middleware/auth.d.ts +0 -2
  85. package/dist/middleware/auth.d.ts.map +1 -1
  86. package/dist/middleware/auth.js +21 -50
  87. package/package.json +3 -2
  88. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  89. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  90. package/dist/api/builder/handlers/generate.handler.js +0 -203
  91. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  92. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  93. package/dist/api/builder/handlers/template.handler.js +0 -208
  94. package/dist/api/builder/routes.d.ts +0 -7
  95. package/dist/api/builder/routes.d.ts.map +0 -1
  96. package/dist/api/builder/routes.js +0 -15
  97. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  98. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  99. package/dist/api/cms/handlers/assets.handler.js +0 -200
  100. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  101. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  102. package/dist/api/cms/handlers/config.handler.js +0 -37
  103. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  104. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  105. package/dist/api/cms/handlers/content.handler.js +0 -117
  106. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  107. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  108. package/dist/api/cms/routes/assets.routes.js +0 -13
  109. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  110. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  111. package/dist/api/cms/routes/content.routes.js +0 -11
  112. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  113. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  114. package/dist/api/emails/handlers/branding.handler.js +0 -120
  115. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  116. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  117. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  118. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  119. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  120. package/dist/api/emails/handlers/templates.handler.js +0 -132
  121. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  122. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  123. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  124. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  125. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  126. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  127. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  128. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  129. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  130. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  131. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  132. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  133. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  134. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  135. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  136. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  137. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  138. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  139. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  140. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  141. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  142. package/dist/api/newsletter/routes/index.d.ts +0 -4
  143. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  144. package/dist/api/newsletter/routes/index.js +0 -9
  145. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  146. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  147. package/dist/api/newsletter/routes/public.routes.js +0 -9
  148. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  149. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  150. package/dist/api/shop/handlers/assets.handler.js +0 -62
  151. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  152. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  153. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  154. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  155. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  156. package/dist/api/shop/handlers/customers.handler.js +0 -89
  157. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  158. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  159. package/dist/api/shop/handlers/orders.handler.js +0 -84
  160. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  161. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  162. package/dist/api/shop/handlers/stats.handler.js +0 -71
  163. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  164. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  165. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  166. package/dist/cms-assets.d.ts +0 -4
  167. package/dist/cms-assets.d.ts.map +0 -1
  168. package/dist/cms-assets.js +0 -5
  169. package/dist/cms-bundle.d.ts +0 -3
  170. package/dist/cms-bundle.d.ts.map +0 -1
  171. package/dist/cms-bundle.js +0 -4
  172. package/dist/config-loader.d.ts +0 -26
  173. package/dist/config-loader.d.ts.map +0 -1
  174. package/dist/config-loader.js +0 -98
  175. package/dist/jwt.d.ts +0 -26
  176. package/dist/jwt.d.ts.map +0 -1
  177. package/dist/jwt.js +0 -102
  178. package/dist/lib/plunk.d.ts +0 -204
  179. package/dist/lib/plunk.d.ts.map +0 -1
  180. package/dist/lib/plunk.js +0 -259
  181. package/dist/template.d.ts +0 -2
  182. package/dist/template.d.ts.map +0 -1
  183. package/dist/template.js +0 -61
  184. package/dist/utils.d.ts +0 -23
  185. package/dist/utils.d.ts.map +0 -1
  186. package/dist/utils.js +0 -110
@@ -1,13 +1,9 @@
1
1
  /**
2
2
  * Invoice Handler
3
3
  *
4
- * Manages invoice template configuration (stored in GitHub) and PDF generation.
5
- * Uses global branding for logo when showLogo is enabled.
4
+ * PDF generation for shop invoices. Invoice config is now read from D1 email_settings.
6
5
  */
7
6
  import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
8
- import { getGitHubConfig } from '../../../lib/config';
9
- import { createGitHubClient } from '../../../lib/github';
10
- // Default invoice configuration
11
7
  const DEFAULT_INVOICE_CONFIG = {
12
8
  showLogo: true,
13
9
  primaryColor: '#1f2937',
@@ -24,133 +20,34 @@ const DEFAULT_INVOICE_CONFIG = {
24
20
  taxLabel: 'Tax',
25
21
  taxRate: 0,
26
22
  dueDays: 14,
27
- footerText: 'Thank you for your business!'
23
+ footerText: 'Thank you for your business!',
28
24
  };
29
- // Default invoice template
30
- function getDefaultInvoiceTemplate() {
31
- return {
32
- id: 'invoice',
33
- config: DEFAULT_INVOICE_CONFIG,
34
- createdAt: Date.now(),
35
- updatedAt: Date.now()
36
- };
37
- }
38
- /**
39
- * Get the settings file path
40
- */
41
- function getSettingsPath() {
42
- return `emails/settings.json`;
43
- }
44
- /**
45
- * GET /api/email/admin/invoice-template
46
- * Fetch the invoice template configuration from GitHub
47
- */
48
- export async function getInvoiceTemplate(c) {
49
- try {
50
- const gitConfig = getGitHubConfig(c.env);
51
- const github = createGitHubClient(gitConfig);
52
- const settingsPath = getSettingsPath();
53
- // Try to read settings from GitHub
54
- const result = await github.readJsonFile(settingsPath);
55
- if (!result || !result.data.invoice) {
56
- // Return default template if file doesn't exist
57
- return c.json({ success: true, template: getDefaultInvoiceTemplate() });
58
- }
59
- return c.json({ success: true, template: result.data.invoice });
60
- }
61
- catch (error) {
62
- console.error('Failed to fetch invoice template:', error);
63
- return c.json({ success: true, template: getDefaultInvoiceTemplate() });
64
- }
65
- }
66
- /**
67
- * PUT /api/email/admin/invoice-template
68
- * Save the invoice template configuration to GitHub
69
- */
70
- export async function saveInvoiceTemplate(c) {
71
- try {
72
- const body = await c.req.json();
73
- const { config: invoiceConfig, commitSha } = body;
74
- if (!invoiceConfig) {
75
- return c.json({ success: false, error: 'Config is required' }, 400);
76
- }
77
- const gitConfig = getGitHubConfig(c.env);
78
- const github = createGitHubClient(gitConfig);
79
- const settingsPath = getSettingsPath();
80
- const now = Date.now();
81
- // Read existing settings
82
- const existing = await github.readJsonFile(settingsPath);
83
- // Check for conflicts if commitSha provided
84
- if (commitSha) {
85
- const currentSha = await github.getCommitSha();
86
- if (commitSha !== currentSha) {
87
- const currentSettings = await github.readJsonFile(settingsPath);
88
- return c.json({
89
- conflict: true,
90
- currentCommitSha: currentSha,
91
- serverTemplate: currentSettings?.data.invoice || getDefaultInvoiceTemplate(),
92
- message: 'Settings have been modified. Please resolve conflicts.',
93
- }, 409);
94
- }
95
- }
96
- // Build updated invoice template
97
- const template = {
98
- id: 'invoice',
99
- config: invoiceConfig,
100
- createdAt: existing?.data.invoice?.createdAt || now,
101
- updatedAt: now
102
- };
103
- // Merge with existing settings (preserve branding config)
104
- const settings = {
105
- branding: existing?.data.branding,
106
- invoice: template,
107
- };
108
- // Write to GitHub
109
- await github.writeJsonFile(settingsPath, settings, 'Update invoice template [skip ci]');
110
- // Get new commit SHA
111
- const newCommitSha = await github.getCommitSha();
112
- return c.json({ success: true, template, commitSha: newCommitSha });
113
- }
114
- catch (error) {
115
- console.error('Failed to save invoice template:', error);
116
- return c.json({ success: false, error: 'Failed to save invoice template' }, 500);
117
- }
118
- }
119
- /**
120
- * Helper to parse hex color to RGB values
121
- */
122
25
  function hexToRgb(hex) {
123
26
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
124
27
  return result
125
28
  ? {
126
29
  r: parseInt(result[1], 16) / 255,
127
30
  g: parseInt(result[2], 16) / 255,
128
- b: parseInt(result[3], 16) / 255
31
+ b: parseInt(result[3], 16) / 255,
129
32
  }
130
33
  : { r: 0, g: 0, b: 0 };
131
34
  }
132
- /**
133
- * Format currency amount
134
- */
135
35
  function formatCurrency(amount, symbol, position) {
136
36
  const formattedAmount = amount.toFixed(2);
137
37
  return position === 'before' ? `${symbol}${formattedAmount}` : `${formattedAmount}${symbol}`;
138
38
  }
139
39
  /**
140
- * Generate PDF invoice
141
- * @param template Invoice template configuration
142
- * @param data Invoice data
143
- * @param branding Optional global branding for logo and company name
40
+ * Generate PDF invoice from InvoiceConfig + InvoiceData.
41
+ * Optionally provide logo (base64 data URL) and invoice company styling.
144
42
  */
145
- export async function generateInvoicePdf(template, data, branding) {
43
+ export async function generateInvoicePdf(config, data, branding) {
44
+ const mergedConfig = { ...DEFAULT_INVOICE_CONFIG, ...config };
146
45
  const pdfDoc = await PDFDocument.create();
147
- const page = pdfDoc.addPage([595.28, 841.89]); // A4 size in points
46
+ const page = pdfDoc.addPage([595.28, 841.89]);
148
47
  const { width, height } = page.getSize();
149
- // Get fonts
150
- const config = template.config;
151
48
  let font;
152
49
  let boldFont;
153
- switch (config.fontFamily) {
50
+ switch (mergedConfig.fontFamily) {
154
51
  case 'times':
155
52
  font = await pdfDoc.embedFont(StandardFonts.TimesRoman);
156
53
  boldFont = await pdfDoc.embedFont(StandardFonts.TimesRomanBold);
@@ -163,17 +60,15 @@ export async function generateInvoicePdf(template, data, branding) {
163
60
  font = await pdfDoc.embedFont(StandardFonts.Helvetica);
164
61
  boldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
165
62
  }
166
- // Use primary color from branding if available, otherwise default
167
- const primaryColor = hexToRgb(branding?.primaryColor || '#1f2937');
168
- const accentColor = hexToRgb(branding?.primaryColor || '#3b82f6');
63
+ const primaryColor = hexToRgb(branding?.primaryColor || mergedConfig.primaryColor);
64
+ const accentColor = hexToRgb(mergedConfig.accentColor);
169
65
  const margin = 50;
170
66
  let yPos = height - margin;
171
- // Logo (from global branding if available and enabled)
172
- const logo = config.showLogo ? branding?.logo : undefined;
67
+ // Logo
68
+ const logo = mergedConfig.showLogo ? branding?.logo : undefined;
173
69
  if (logo) {
174
70
  try {
175
- // Try to embed logo
176
- const logoData = logo.split(',')[1]; // Remove data:image/... prefix
71
+ const logoData = logo.split(',')[1];
177
72
  const logoBytes = Uint8Array.from(atob(logoData), (c) => c.charCodeAt(0));
178
73
  let logoImage;
179
74
  if (logo.includes('image/png')) {
@@ -187,14 +82,7 @@ export async function generateInvoicePdf(template, data, branding) {
187
82
  const scale = Math.min(logoMaxWidth / logoImage.width, logoMaxHeight / logoImage.height);
188
83
  const logoWidth = logoImage.width * scale;
189
84
  const logoHeight = logoImage.height * scale;
190
- // Always left-align logo for invoices
191
- const logoX = margin;
192
- page.drawImage(logoImage, {
193
- x: logoX,
194
- y: yPos - logoHeight,
195
- width: logoWidth,
196
- height: logoHeight
197
- });
85
+ page.drawImage(logoImage, { x: margin, y: yPos - logoHeight, width: logoWidth, height: logoHeight });
198
86
  yPos -= logoHeight + 20;
199
87
  }
200
88
  catch (e) {
@@ -202,107 +90,43 @@ export async function generateInvoicePdf(template, data, branding) {
202
90
  }
203
91
  }
204
92
  // Company info (right-aligned)
205
- const companyName = branding?.companyName || 'Your Company';
93
+ const companyName = branding?.companyName || mergedConfig.companyName;
206
94
  const companyInfoX = width - margin;
207
95
  page.drawText(companyName, {
208
96
  x: companyInfoX - boldFont.widthOfTextAtSize(companyName, 12),
209
- y: yPos,
210
- size: 12,
211
- font: boldFont,
212
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
97
+ y: yPos, size: 12, font: boldFont,
98
+ color: rgb(primaryColor.r, primaryColor.g, primaryColor.b),
213
99
  });
214
100
  yPos -= 15;
215
- const addressLines = config.companyAddress.split(',').map((s) => s.trim());
216
- for (const line of addressLines) {
217
- page.drawText(line, {
218
- x: companyInfoX - font.widthOfTextAtSize(line, 10),
219
- y: yPos,
220
- size: 10,
221
- font,
222
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
223
- });
101
+ for (const line of mergedConfig.companyAddress.split(',').map((s) => s.trim())) {
102
+ page.drawText(line, { x: companyInfoX - font.widthOfTextAtSize(line, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
224
103
  yPos -= 12;
225
104
  }
226
- if (config.companyEmail) {
227
- page.drawText(config.companyEmail, {
228
- x: companyInfoX - font.widthOfTextAtSize(config.companyEmail, 10),
229
- y: yPos,
230
- size: 10,
231
- font,
232
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
233
- });
105
+ if (mergedConfig.companyEmail) {
106
+ page.drawText(mergedConfig.companyEmail, { x: companyInfoX - font.widthOfTextAtSize(mergedConfig.companyEmail, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
234
107
  yPos -= 12;
235
108
  }
236
- if (config.companyPhone) {
237
- page.drawText(config.companyPhone, {
238
- x: companyInfoX - font.widthOfTextAtSize(config.companyPhone, 10),
239
- y: yPos,
240
- size: 10,
241
- font,
242
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
243
- });
109
+ if (mergedConfig.companyPhone) {
110
+ page.drawText(mergedConfig.companyPhone, { x: companyInfoX - font.widthOfTextAtSize(mergedConfig.companyPhone, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
244
111
  yPos -= 12;
245
112
  }
246
113
  yPos -= 30;
247
114
  // Invoice title
248
- page.drawText('INVOICE', {
249
- x: margin,
250
- y: yPos,
251
- size: 24,
252
- font: boldFont,
253
- color: rgb(accentColor.r, accentColor.g, accentColor.b)
254
- });
115
+ page.drawText('INVOICE', { x: margin, y: yPos, size: 24, font: boldFont, color: rgb(accentColor.r, accentColor.g, accentColor.b) });
255
116
  yPos -= 30;
256
- // Invoice details
257
- page.drawText(`Invoice #: ${data.invoiceNumber}`, {
258
- x: margin,
259
- y: yPos,
260
- size: 10,
261
- font,
262
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
263
- });
117
+ page.drawText(`Invoice #: ${data.invoiceNumber}`, { x: margin, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
264
118
  yPos -= 15;
265
- page.drawText(`Date: ${data.invoiceDate}`, {
266
- x: margin,
267
- y: yPos,
268
- size: 10,
269
- font,
270
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
271
- });
119
+ page.drawText(`Date: ${data.invoiceDate}`, { x: margin, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
272
120
  yPos -= 30;
273
121
  // Bill To
274
- page.drawText('Bill To:', {
275
- x: margin,
276
- y: yPos,
277
- size: 10,
278
- font: boldFont,
279
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
280
- });
122
+ page.drawText('Bill To:', { x: margin, y: yPos, size: 10, font: boldFont, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
281
123
  yPos -= 15;
282
- page.drawText(data.customerName, {
283
- x: margin,
284
- y: yPos,
285
- size: 10,
286
- font,
287
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
288
- });
124
+ page.drawText(data.customerName, { x: margin, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
289
125
  yPos -= 12;
290
- page.drawText(data.customerEmail, {
291
- x: margin,
292
- y: yPos,
293
- size: 10,
294
- font,
295
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
296
- });
126
+ page.drawText(data.customerEmail, { x: margin, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
297
127
  yPos -= 12;
298
128
  if (data.customerAddress) {
299
- page.drawText(data.customerAddress, {
300
- x: margin,
301
- y: yPos,
302
- size: 10,
303
- font,
304
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
305
- });
129
+ page.drawText(data.customerAddress, { x: margin, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
306
130
  yPos -= 12;
307
131
  }
308
132
  yPos -= 30;
@@ -312,152 +136,46 @@ export async function generateInvoicePdf(template, data, branding) {
312
136
  const colQty = width - margin - 200;
313
137
  const colPrice = width - margin - 120;
314
138
  const colTotal = width - margin - 40;
315
- // Header background
316
- page.drawRectangle({
317
- x: margin,
318
- y: yPos - tableHeaderHeight,
319
- width: width - 2 * margin,
320
- height: tableHeaderHeight,
321
- color: rgb(accentColor.r, accentColor.g, accentColor.b)
322
- });
323
- // Header text
324
- page.drawText('Description', {
325
- x: colDescription + 10,
326
- y: yPos - 17,
327
- size: 10,
328
- font: boldFont,
329
- color: rgb(1, 1, 1)
330
- });
331
- page.drawText('Qty', {
332
- x: colQty,
333
- y: yPos - 17,
334
- size: 10,
335
- font: boldFont,
336
- color: rgb(1, 1, 1)
337
- });
338
- page.drawText('Price', {
339
- x: colPrice,
340
- y: yPos - 17,
341
- size: 10,
342
- font: boldFont,
343
- color: rgb(1, 1, 1)
344
- });
345
- page.drawText('Total', {
346
- x: colTotal - font.widthOfTextAtSize('Total', 10),
347
- y: yPos - 17,
348
- size: 10,
349
- font: boldFont,
350
- color: rgb(1, 1, 1)
351
- });
139
+ page.drawRectangle({ x: margin, y: yPos - tableHeaderHeight, width: width - 2 * margin, height: tableHeaderHeight, color: rgb(accentColor.r, accentColor.g, accentColor.b) });
140
+ page.drawText('Description', { x: colDescription + 10, y: yPos - 17, size: 10, font: boldFont, color: rgb(1, 1, 1) });
141
+ page.drawText('Qty', { x: colQty, y: yPos - 17, size: 10, font: boldFont, color: rgb(1, 1, 1) });
142
+ page.drawText('Price', { x: colPrice, y: yPos - 17, size: 10, font: boldFont, color: rgb(1, 1, 1) });
143
+ page.drawText('Total', { x: colTotal - font.widthOfTextAtSize('Total', 10), y: yPos - 17, size: 10, font: boldFont, color: rgb(1, 1, 1) });
352
144
  yPos -= tableHeaderHeight + 15;
353
145
  // Table rows
354
146
  for (const item of data.items) {
355
- page.drawText(item.description, {
356
- x: colDescription + 10,
357
- y: yPos,
358
- size: 10,
359
- font,
360
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
361
- });
362
- page.drawText(item.quantity.toString(), {
363
- x: colQty,
364
- y: yPos,
365
- size: 10,
366
- font,
367
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
368
- });
369
- const priceStr = formatCurrency(item.unitPrice, config.currencySymbol, config.currencyPosition);
370
- page.drawText(priceStr, {
371
- x: colPrice,
372
- y: yPos,
373
- size: 10,
374
- font,
375
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
376
- });
377
- const totalStr = formatCurrency(item.total, config.currencySymbol, config.currencyPosition);
378
- page.drawText(totalStr, {
379
- x: colTotal - font.widthOfTextAtSize(totalStr, 10),
380
- y: yPos,
381
- size: 10,
382
- font,
383
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
384
- });
147
+ page.drawText(item.description, { x: colDescription + 10, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
148
+ page.drawText(item.quantity.toString(), { x: colQty, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
149
+ const priceStr = formatCurrency(item.unitPrice, mergedConfig.currencySymbol, mergedConfig.currencyPosition);
150
+ page.drawText(priceStr, { x: colPrice, y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
151
+ const totalStr = formatCurrency(item.total, mergedConfig.currencySymbol, mergedConfig.currencyPosition);
152
+ page.drawText(totalStr, { x: colTotal - font.widthOfTextAtSize(totalStr, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
385
153
  yPos -= 20;
386
154
  }
387
- // Line separator
388
155
  yPos -= 10;
389
- page.drawLine({
390
- start: { x: margin, y: yPos },
391
- end: { x: width - margin, y: yPos },
392
- thickness: 1,
393
- color: rgb(0.8, 0.8, 0.8)
394
- });
156
+ page.drawLine({ start: { x: margin, y: yPos }, end: { x: width - margin, y: yPos }, thickness: 1, color: rgb(0.8, 0.8, 0.8) });
395
157
  yPos -= 20;
396
- // Subtotal
397
- if (config.showTaxBreakdown) {
158
+ // Totals
159
+ if (mergedConfig.showTaxBreakdown) {
398
160
  const subtotalLabel = 'Subtotal:';
399
- const subtotalValue = formatCurrency(data.subtotal, config.currencySymbol, config.currencyPosition);
400
- page.drawText(subtotalLabel, {
401
- x: colPrice - font.widthOfTextAtSize(subtotalLabel, 10),
402
- y: yPos,
403
- size: 10,
404
- font,
405
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
406
- });
407
- page.drawText(subtotalValue, {
408
- x: colTotal - font.widthOfTextAtSize(subtotalValue, 10),
409
- y: yPos,
410
- size: 10,
411
- font,
412
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
413
- });
161
+ const subtotalValue = formatCurrency(data.subtotal, mergedConfig.currencySymbol, mergedConfig.currencyPosition);
162
+ page.drawText(subtotalLabel, { x: colPrice - font.widthOfTextAtSize(subtotalLabel, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
163
+ page.drawText(subtotalValue, { x: colTotal - font.widthOfTextAtSize(subtotalValue, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
414
164
  yPos -= 15;
415
- // Tax
416
165
  if (data.tax !== undefined) {
417
- const taxLabel = `${config.taxLabel} (${config.taxRate}%):`;
418
- const taxValue = formatCurrency(data.tax, config.currencySymbol, config.currencyPosition);
419
- page.drawText(taxLabel, {
420
- x: colPrice - font.widthOfTextAtSize(taxLabel, 10),
421
- y: yPos,
422
- size: 10,
423
- font,
424
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
425
- });
426
- page.drawText(taxValue, {
427
- x: colTotal - font.widthOfTextAtSize(taxValue, 10),
428
- y: yPos,
429
- size: 10,
430
- font,
431
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
432
- });
166
+ const taxLabel = `${mergedConfig.taxLabel} (${mergedConfig.taxRate}%):`;
167
+ const taxValue = formatCurrency(data.tax, mergedConfig.currencySymbol, mergedConfig.currencyPosition);
168
+ page.drawText(taxLabel, { x: colPrice - font.widthOfTextAtSize(taxLabel, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
169
+ page.drawText(taxValue, { x: colTotal - font.widthOfTextAtSize(taxValue, 10), y: yPos, size: 10, font, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
433
170
  yPos -= 15;
434
171
  }
435
172
  }
436
- // Total
437
173
  const totalLabel = 'Total:';
438
- const totalValue = formatCurrency(data.total, config.currencySymbol, config.currencyPosition);
439
- page.drawText(totalLabel, {
440
- x: colPrice - boldFont.widthOfTextAtSize(totalLabel, 12),
441
- y: yPos,
442
- size: 12,
443
- font: boldFont,
444
- color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
445
- });
446
- page.drawText(totalValue, {
447
- x: colTotal - boldFont.widthOfTextAtSize(totalValue, 12),
448
- y: yPos,
449
- size: 12,
450
- font: boldFont,
451
- color: rgb(accentColor.r, accentColor.g, accentColor.b)
452
- });
453
- // Footer - Thank you message
454
- const footerText = 'Thank you for your business!';
455
- page.drawText(footerText, {
456
- x: (width - font.widthOfTextAtSize(footerText, 10)) / 2,
457
- y: margin,
458
- size: 10,
459
- font,
460
- color: rgb(0.5, 0.5, 0.5)
461
- });
174
+ const totalValue = formatCurrency(data.total, mergedConfig.currencySymbol, mergedConfig.currencyPosition);
175
+ page.drawText(totalLabel, { x: colPrice - boldFont.widthOfTextAtSize(totalLabel, 12), y: yPos, size: 12, font: boldFont, color: rgb(primaryColor.r, primaryColor.g, primaryColor.b) });
176
+ page.drawText(totalValue, { x: colTotal - boldFont.widthOfTextAtSize(totalValue, 12), y: yPos, size: 12, font: boldFont, color: rgb(accentColor.r, accentColor.g, accentColor.b) });
177
+ // Footer
178
+ const footerText = mergedConfig.footerText || 'Thank you for your business!';
179
+ page.drawText(footerText, { x: (width - font.widthOfTextAtSize(footerText, 10)) / 2, y: margin, size: 10, font, color: rgb(0.5, 0.5, 0.5) });
462
180
  return await pdfDoc.save();
463
181
  }
@@ -1,36 +1,13 @@
1
1
  /**
2
- * Public Handler
3
- *
4
- * Handles public email subscription/unsubscription endpoints.
5
- * Uses Plunk for contact management.
2
+ * Public Handler — D1-backed subscribe/unsubscribe/confirm, no Plunk
6
3
  */
7
4
  import { Context } from 'hono';
8
- /**
9
- * POST /api/email/subscribe
10
- * Public endpoint for newsletter subscription
11
- *
12
- * Creates an unsubscribed contact in Plunk. Plunk's built-in double opt-in
13
- * will handle sending the confirmation email and updating the subscription status.
14
- */
5
+ /** POST /api/email/subscribe */
15
6
  export declare function subscribe(c: Context): Promise<Response>;
16
- /**
17
- * POST /api/email/unsubscribe
18
- * Public endpoint for newsletter unsubscription
19
- */
7
+ /** GET /api/email/confirm */
8
+ export declare function confirm(c: Context): Promise<Response>;
9
+ /** POST /api/email/unsubscribe */
20
10
  export declare function unsubscribe(c: Context): Promise<Response>;
21
- /**
22
- * GET /api/email/unsubscribe
23
- * Show unsubscribe page (for links in emails)
24
- */
11
+ /** GET /api/email/unsubscribe — HTML unsubscribe page */
25
12
  export declare function showUnsubscribePage(c: Context): Promise<Response>;
26
- /**
27
- * POST /api/email/track
28
- * Track an event for a contact (public endpoint using public key)
29
- */
30
- export declare function trackEvent(c: Context): Promise<Response>;
31
- /**
32
- * GET /api/email/confirm
33
- * Public endpoint to confirm subscription
34
- */
35
- export declare function confirm(c: Context): Promise<Response>;
36
13
  //# sourceMappingURL=public.handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/public.handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0G7D;AA6CD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuD/D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoFvE;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiC9D;AACD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkD3D"}
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;AAQ/B,gCAAgC;AAChC,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiD7D;AA2BD,6BAA6B;AAC7B,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0B3D;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"}