@hintergrund/worker 0.1.2 → 0.1.5
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.
- package/dist/api/cms/handlers/assets.handler.d.ts +24 -1
- package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/assets.handler.js +111 -210
- package/dist/api/cms/handlers/auth.handler.d.ts +4 -3
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +24 -14
- package/dist/api/cms/handlers/config.handler.d.ts +4 -0
- package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/config.handler.js +20 -71
- package/dist/api/cms/handlers/content.handler.d.ts +12 -1
- package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/content.handler.js +57 -233
- package/dist/api/cms/handlers/dashboard.handler.js +1 -1
- package/dist/api/cms/routes/auth.routes.d.ts +2 -1
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
- package/dist/api/cms/routes/auth.routes.js +7 -0
- package/dist/api/cms/routes/index.d.ts +2 -1
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
- package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/branding.handler.js +120 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/campaigns.handler.js +139 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/contacts.handler.js +161 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/invoice.handler.js +463 -0
- package/dist/api/emails/handlers/public.handler.d.ts +36 -0
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/public.handler.js +350 -0
- package/dist/api/emails/handlers/send.handler.d.ts +23 -0
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/send.handler.js +117 -0
- package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/settings.handler.js +312 -0
- package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
- package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/templates.handler.js +132 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts +10 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/webhook.handler.js +261 -0
- package/dist/api/emails/routes/admin.routes.d.ts +9 -0
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/admin.routes.js +77 -0
- package/dist/api/emails/routes/index.d.ts +9 -0
- package/dist/api/emails/routes/index.d.ts.map +1 -0
- package/dist/api/emails/routes/index.js +14 -0
- package/dist/api/emails/routes/public.routes.d.ts +9 -0
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/public.routes.js +18 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/webhook.handler.js +66 -60
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +0 -3
- package/dist/hintergrund-assets.d.ts +2 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +2 -2
- package/dist/index.d.ts +20 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/lib/config.d.ts +13 -7
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +44 -46
- package/dist/lib/email.d.ts +2 -2
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +7 -9
- package/dist/lib/github.d.ts +124 -0
- package/dist/lib/github.d.ts.map +1 -0
- package/dist/lib/github.js +286 -0
- package/dist/lib/plunk.d.ts +204 -0
- package/dist/lib/plunk.d.ts.map +1 -0
- package/dist/lib/plunk.js +259 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +2 -5
- package/package.json +32 -32
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoice Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages invoice template configuration (stored in GitHub) and PDF generation.
|
|
5
|
+
* Uses global branding for logo when showLogo is enabled.
|
|
6
|
+
*/
|
|
7
|
+
import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
|
|
8
|
+
import { getGitHubConfig } from '../../../lib/config';
|
|
9
|
+
import { createGitHubClient } from '../../../lib/github';
|
|
10
|
+
// Default invoice configuration
|
|
11
|
+
const DEFAULT_INVOICE_CONFIG = {
|
|
12
|
+
showLogo: true,
|
|
13
|
+
primaryColor: '#1f2937',
|
|
14
|
+
accentColor: '#3b82f6',
|
|
15
|
+
logoPosition: 'left',
|
|
16
|
+
fontFamily: 'helvetica',
|
|
17
|
+
companyName: 'Your Company',
|
|
18
|
+
companyAddress: '123 Main Street, City, Country',
|
|
19
|
+
companyEmail: 'contact@company.com',
|
|
20
|
+
companyPhone: '+1 234 567 890',
|
|
21
|
+
currencySymbol: '$',
|
|
22
|
+
currencyPosition: 'before',
|
|
23
|
+
showTaxBreakdown: true,
|
|
24
|
+
taxLabel: 'Tax',
|
|
25
|
+
taxRate: 0,
|
|
26
|
+
dueDays: 14,
|
|
27
|
+
footerText: 'Thank you for your business!'
|
|
28
|
+
};
|
|
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
|
+
function hexToRgb(hex) {
|
|
123
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
124
|
+
return result
|
|
125
|
+
? {
|
|
126
|
+
r: parseInt(result[1], 16) / 255,
|
|
127
|
+
g: parseInt(result[2], 16) / 255,
|
|
128
|
+
b: parseInt(result[3], 16) / 255
|
|
129
|
+
}
|
|
130
|
+
: { r: 0, g: 0, b: 0 };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Format currency amount
|
|
134
|
+
*/
|
|
135
|
+
function formatCurrency(amount, symbol, position) {
|
|
136
|
+
const formattedAmount = amount.toFixed(2);
|
|
137
|
+
return position === 'before' ? `${symbol}${formattedAmount}` : `${formattedAmount}${symbol}`;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
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
|
|
144
|
+
*/
|
|
145
|
+
export async function generateInvoicePdf(template, data, branding) {
|
|
146
|
+
const pdfDoc = await PDFDocument.create();
|
|
147
|
+
const page = pdfDoc.addPage([595.28, 841.89]); // A4 size in points
|
|
148
|
+
const { width, height } = page.getSize();
|
|
149
|
+
// Get fonts
|
|
150
|
+
const config = template.config;
|
|
151
|
+
let font;
|
|
152
|
+
let boldFont;
|
|
153
|
+
switch (config.fontFamily) {
|
|
154
|
+
case 'times':
|
|
155
|
+
font = await pdfDoc.embedFont(StandardFonts.TimesRoman);
|
|
156
|
+
boldFont = await pdfDoc.embedFont(StandardFonts.TimesRomanBold);
|
|
157
|
+
break;
|
|
158
|
+
case 'courier':
|
|
159
|
+
font = await pdfDoc.embedFont(StandardFonts.Courier);
|
|
160
|
+
boldFont = await pdfDoc.embedFont(StandardFonts.CourierBold);
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
164
|
+
boldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
|
|
165
|
+
}
|
|
166
|
+
// Use primary color from branding if available, otherwise default
|
|
167
|
+
const primaryColor = hexToRgb(branding?.primaryColor || '#1f2937');
|
|
168
|
+
const accentColor = hexToRgb(branding?.primaryColor || '#3b82f6');
|
|
169
|
+
const margin = 50;
|
|
170
|
+
let yPos = height - margin;
|
|
171
|
+
// Logo (from global branding if available and enabled)
|
|
172
|
+
const logo = config.showLogo ? branding?.logo : undefined;
|
|
173
|
+
if (logo) {
|
|
174
|
+
try {
|
|
175
|
+
// Try to embed logo
|
|
176
|
+
const logoData = logo.split(',')[1]; // Remove data:image/... prefix
|
|
177
|
+
const logoBytes = Uint8Array.from(atob(logoData), (c) => c.charCodeAt(0));
|
|
178
|
+
let logoImage;
|
|
179
|
+
if (logo.includes('image/png')) {
|
|
180
|
+
logoImage = await pdfDoc.embedPng(logoBytes);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
logoImage = await pdfDoc.embedJpg(logoBytes);
|
|
184
|
+
}
|
|
185
|
+
const logoMaxHeight = 50;
|
|
186
|
+
const logoMaxWidth = 150;
|
|
187
|
+
const scale = Math.min(logoMaxWidth / logoImage.width, logoMaxHeight / logoImage.height);
|
|
188
|
+
const logoWidth = logoImage.width * scale;
|
|
189
|
+
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
|
+
});
|
|
198
|
+
yPos -= logoHeight + 20;
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
console.error('Failed to embed logo:', e);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Company info (right-aligned)
|
|
205
|
+
const companyName = branding?.companyName || 'Your Company';
|
|
206
|
+
const companyInfoX = width - margin;
|
|
207
|
+
page.drawText(companyName, {
|
|
208
|
+
x: companyInfoX - boldFont.widthOfTextAtSize(companyName, 12),
|
|
209
|
+
y: yPos,
|
|
210
|
+
size: 12,
|
|
211
|
+
font: boldFont,
|
|
212
|
+
color: rgb(primaryColor.r, primaryColor.g, primaryColor.b)
|
|
213
|
+
});
|
|
214
|
+
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
|
+
});
|
|
224
|
+
yPos -= 12;
|
|
225
|
+
}
|
|
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
|
+
});
|
|
234
|
+
yPos -= 12;
|
|
235
|
+
}
|
|
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
|
+
});
|
|
244
|
+
yPos -= 12;
|
|
245
|
+
}
|
|
246
|
+
yPos -= 30;
|
|
247
|
+
// 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
|
+
});
|
|
255
|
+
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
|
+
});
|
|
264
|
+
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
|
+
});
|
|
272
|
+
yPos -= 30;
|
|
273
|
+
// 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
|
+
});
|
|
281
|
+
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
|
+
});
|
|
289
|
+
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
|
+
});
|
|
297
|
+
yPos -= 12;
|
|
298
|
+
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
|
+
});
|
|
306
|
+
yPos -= 12;
|
|
307
|
+
}
|
|
308
|
+
yPos -= 30;
|
|
309
|
+
// Table header
|
|
310
|
+
const tableHeaderHeight = 25;
|
|
311
|
+
const colDescription = margin;
|
|
312
|
+
const colQty = width - margin - 200;
|
|
313
|
+
const colPrice = width - margin - 120;
|
|
314
|
+
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
|
+
});
|
|
352
|
+
yPos -= tableHeaderHeight + 15;
|
|
353
|
+
// Table rows
|
|
354
|
+
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
|
+
});
|
|
385
|
+
yPos -= 20;
|
|
386
|
+
}
|
|
387
|
+
// Line separator
|
|
388
|
+
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
|
+
});
|
|
395
|
+
yPos -= 20;
|
|
396
|
+
// Subtotal
|
|
397
|
+
if (config.showTaxBreakdown) {
|
|
398
|
+
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
|
+
});
|
|
414
|
+
yPos -= 15;
|
|
415
|
+
// Tax
|
|
416
|
+
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
|
+
});
|
|
433
|
+
yPos -= 15;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// Total
|
|
437
|
+
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
|
+
});
|
|
462
|
+
return await pdfDoc.save();
|
|
463
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Handler
|
|
3
|
+
*
|
|
4
|
+
* Handles public email subscription/unsubscription endpoints.
|
|
5
|
+
* Uses Plunk for contact management.
|
|
6
|
+
*/
|
|
7
|
+
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
|
+
*/
|
|
15
|
+
export declare function subscribe(c: Context): Promise<Response>;
|
|
16
|
+
/**
|
|
17
|
+
* POST /api/email/unsubscribe
|
|
18
|
+
* Public endpoint for newsletter unsubscription
|
|
19
|
+
*/
|
|
20
|
+
export declare function unsubscribe(c: Context): Promise<Response>;
|
|
21
|
+
/**
|
|
22
|
+
* GET /api/email/unsubscribe
|
|
23
|
+
* Show unsubscribe page (for links in emails)
|
|
24
|
+
*/
|
|
25
|
+
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
|
+
//# sourceMappingURL=public.handler.d.ts.map
|
|
@@ -0,0 +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"}
|