@hintergrund/worker 0.1.2 → 0.1.3
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/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/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/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 +15 -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/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 +9 -17
- 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 +39 -44
- 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 +207 -0
- package/dist/lib/plunk.d.ts.map +1 -0
- package/dist/lib/plunk.js +262 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +2 -5
- package/package.json +2 -2
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
import { getShopConfig } from '../../../lib/config';
|
|
1
|
+
import { getShopConfig, getEmailsConfig, getGitHubConfig } from '../../../lib/config';
|
|
2
|
+
import { createGitHubClient } from '../../../lib/github';
|
|
2
3
|
import Stripe from 'stripe';
|
|
3
|
-
import { generateInvoicePdf } from '../../
|
|
4
|
+
import { generateInvoicePdf } from '../../emails/handlers/invoice.handler';
|
|
4
5
|
function getStripe(env) {
|
|
5
6
|
const config = getShopConfig(env);
|
|
6
7
|
return new Stripe(config.stripeSecretKey, {
|
|
7
8
|
apiVersion: '2025-02-24.acacia'
|
|
8
9
|
});
|
|
9
10
|
}
|
|
11
|
+
// Default invoice configuration
|
|
12
|
+
const DEFAULT_INVOICE_CONFIG = {
|
|
13
|
+
showLogo: true,
|
|
14
|
+
primaryColor: '#1f2937',
|
|
15
|
+
accentColor: '#3b82f6',
|
|
16
|
+
logoPosition: 'left',
|
|
17
|
+
fontFamily: 'helvetica',
|
|
18
|
+
companyName: 'Your Company',
|
|
19
|
+
companyAddress: '123 Main Street, City, Country',
|
|
20
|
+
companyEmail: 'contact@company.com',
|
|
21
|
+
companyPhone: '+1 234 567 890',
|
|
22
|
+
currencySymbol: '€',
|
|
23
|
+
currencyPosition: 'before',
|
|
24
|
+
showTaxBreakdown: true,
|
|
25
|
+
taxLabel: 'VAT',
|
|
26
|
+
taxRate: 19,
|
|
27
|
+
dueDays: 14,
|
|
28
|
+
footerText: 'Thank you for your business!'
|
|
29
|
+
};
|
|
10
30
|
/**
|
|
11
31
|
* POST /api/shop/webhook
|
|
12
32
|
* Handle Stripe webhook events
|
|
@@ -61,48 +81,34 @@ async function handleCheckoutSessionCompleted(c, stripe, session) {
|
|
|
61
81
|
const lineItems = await stripe.checkout.sessions.listLineItems(session.id, {
|
|
62
82
|
expand: ['data.price.product']
|
|
63
83
|
});
|
|
64
|
-
// Get invoice template
|
|
65
|
-
const db = c.env.DB;
|
|
66
|
-
if (!db) {
|
|
67
|
-
console.error('Database not configured');
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
// Fetch invoice template from database
|
|
71
|
-
const templateResult = await db
|
|
72
|
-
.prepare("SELECT * FROM templates WHERE type = 'invoice'")
|
|
73
|
-
.first();
|
|
84
|
+
// Get invoice template and branding from GitHub
|
|
74
85
|
let template;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
let branding;
|
|
87
|
+
try {
|
|
88
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
89
|
+
const github = createGitHubClient(gitConfig);
|
|
90
|
+
const settingsPath = `emails/settings.json`;
|
|
91
|
+
const result = await github.readJsonFile(settingsPath);
|
|
92
|
+
if (result?.data.invoice) {
|
|
93
|
+
template = result.data.invoice;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
template = {
|
|
97
|
+
id: 'invoice',
|
|
98
|
+
config: DEFAULT_INVOICE_CONFIG,
|
|
99
|
+
createdAt: Date.now(),
|
|
100
|
+
updatedAt: Date.now()
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (result?.data.branding) {
|
|
104
|
+
branding = result.data.branding;
|
|
105
|
+
}
|
|
83
106
|
}
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error('Failed to fetch settings from GitHub:', error);
|
|
86
109
|
template = {
|
|
87
110
|
id: 'invoice',
|
|
88
|
-
config:
|
|
89
|
-
primaryColor: '#1f2937',
|
|
90
|
-
accentColor: '#3b82f6',
|
|
91
|
-
fontFamily: 'helvetica',
|
|
92
|
-
logoPosition: 'left',
|
|
93
|
-
showLogo: false,
|
|
94
|
-
companyName: 'Your Company',
|
|
95
|
-
companyAddress: '123 Main Street, City, Country',
|
|
96
|
-
companyEmail: 'contact@company.com',
|
|
97
|
-
companyPhone: '+1 234 567 890',
|
|
98
|
-
footerText: 'Thank you for your business!',
|
|
99
|
-
currencySymbol: '€',
|
|
100
|
-
currencyPosition: 'before',
|
|
101
|
-
showTaxBreakdown: true,
|
|
102
|
-
taxLabel: 'VAT',
|
|
103
|
-
taxRate: 19,
|
|
104
|
-
dueDays: 14
|
|
105
|
-
},
|
|
111
|
+
config: DEFAULT_INVOICE_CONFIG,
|
|
106
112
|
createdAt: Date.now(),
|
|
107
113
|
updatedAt: Date.now()
|
|
108
114
|
};
|
|
@@ -139,8 +145,12 @@ async function handleCheckoutSessionCompleted(c, stripe, session) {
|
|
|
139
145
|
currency: session.currency?.toUpperCase() || 'EUR',
|
|
140
146
|
paymentMethod: session.payment_method_types?.[0] || 'card'
|
|
141
147
|
};
|
|
142
|
-
// Generate PDF
|
|
143
|
-
const pdfBytes = await generateInvoicePdf(template, invoiceData
|
|
148
|
+
// Generate PDF with branding
|
|
149
|
+
const pdfBytes = await generateInvoicePdf(template, invoiceData, branding ? {
|
|
150
|
+
logo: branding.logo,
|
|
151
|
+
companyName: branding.config.companyName,
|
|
152
|
+
primaryColor: branding.config.primaryColor,
|
|
153
|
+
} : undefined);
|
|
144
154
|
// Send email with PDF attachment
|
|
145
155
|
await sendInvoiceEmail(c, customerEmail, invoiceData, pdfBytes);
|
|
146
156
|
console.log(`Invoice sent to ${customerEmail} for session ${session.id}`);
|
|
@@ -170,9 +180,10 @@ function formatAddress(address) {
|
|
|
170
180
|
* Send invoice email with PDF attachment
|
|
171
181
|
*/
|
|
172
182
|
async function sendInvoiceEmail(c, to, invoiceData, pdfBytes) {
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
183
|
+
const emailsConfig = getEmailsConfig(c.env);
|
|
184
|
+
const apiKey = emailsConfig.plunkSecretKey;
|
|
185
|
+
const fromEmail = emailsConfig.fromEmail;
|
|
186
|
+
const fromName = emailsConfig.fromName || 'Shop';
|
|
176
187
|
if (!apiKey || !fromEmail) {
|
|
177
188
|
console.error('Email not configured');
|
|
178
189
|
return;
|
|
@@ -185,34 +196,29 @@ async function sendInvoiceEmail(c, to, invoiceData, pdfBytes) {
|
|
|
185
196
|
<h1 style="color: #1f2937;">Thank you for your purchase!</h1>
|
|
186
197
|
<p style="color: #4b5563;">Dear ${invoiceData.customerName},</p>
|
|
187
198
|
<p style="color: #4b5563;">Thank you for your order. Please find your invoice attached to this email.</p>
|
|
188
|
-
|
|
199
|
+
|
|
189
200
|
<div style="background-color: #f3f4f6; padding: 20px; border-radius: 8px; margin: 20px 0;">
|
|
190
201
|
<p style="margin: 0; color: #1f2937;"><strong>Invoice Number:</strong> ${invoiceData.invoiceNumber}</p>
|
|
191
|
-
<p style="margin: 8px 0
|
|
192
|
-
<p style="margin: 8px 0
|
|
202
|
+
<p style="margin: 8px 0; color: #1f2937;"><strong>Date:</strong> ${invoiceData.invoiceDate}</p>
|
|
203
|
+
<p style="margin: 8px 0; color: #1f2937;"><strong>Total:</strong> ${invoiceData.currency} ${invoiceData.total.toFixed(2)}</p>
|
|
193
204
|
</div>
|
|
194
|
-
|
|
205
|
+
|
|
195
206
|
<p style="color: #4b5563;">If you have any questions about your order, please don't hesitate to contact us.</p>
|
|
196
|
-
|
|
207
|
+
|
|
197
208
|
<p style="color: #9ca3af; font-size: 12px; margin-top: 40px;">
|
|
198
209
|
This is an automated email. Please do not reply directly to this message.
|
|
199
210
|
</p>
|
|
200
211
|
</div>
|
|
201
212
|
`;
|
|
213
|
+
// Send via Plunk API
|
|
202
214
|
const payload = {
|
|
203
|
-
from: `${fromName} <${fromEmail}>`,
|
|
204
215
|
to,
|
|
205
216
|
subject: `Your Invoice ${invoiceData.invoiceNumber}`,
|
|
206
|
-
html,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
content: pdfBase64,
|
|
210
|
-
filename: `invoice-${invoiceData.invoiceNumber}.pdf`,
|
|
211
|
-
type: 'application/pdf'
|
|
212
|
-
}
|
|
213
|
-
]
|
|
217
|
+
body: html,
|
|
218
|
+
from: fromEmail,
|
|
219
|
+
name: fromName,
|
|
214
220
|
};
|
|
215
|
-
const response = await fetch('https://api.
|
|
221
|
+
const response = await fetch('https://api.useplunk.com/v1/send', {
|
|
216
222
|
method: 'POST',
|
|
217
223
|
headers: {
|
|
218
224
|
Authorization: `Bearer ${apiKey}`,
|