@hintergrund/worker 0.1.1 → 0.1.2
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/newsletter/handlers/emails.handler.d.ts +13 -3
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/emails.handler.js +140 -12
- package/dist/api/newsletter/handlers/invoice.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/invoice.handler.js +455 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts +4 -4
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/public.handler.js +78 -20
- package/dist/api/newsletter/handlers/send.handler.d.ts +2 -2
- package/dist/api/newsletter/handlers/send.handler.js +3 -3
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +4 -4
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/subscribers.handler.js +8 -4
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/newsletter/routes/admin.routes.js +8 -1
- package/dist/api/shop/handlers/assets.handler.d.ts +3 -0
- package/dist/api/shop/handlers/assets.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/assets.handler.js +62 -0
- package/dist/api/shop/handlers/checkout.handler.d.ts +10 -0
- package/dist/api/shop/handlers/checkout.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/checkout.handler.js +50 -0
- package/dist/api/shop/handlers/products.handler.d.ts +0 -7
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +0 -23
- package/dist/api/shop/handlers/public.handler.d.ts +17 -0
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/public.handler.js +108 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts +10 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/webhook.handler.js +227 -0
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +9 -12
- package/dist/index.js +2 -2
- package/package.json +32 -31
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* GET /api/
|
|
3
|
+
* GET /api/email/admin/emails
|
|
4
4
|
* Get all emails (sent emails and drafts)
|
|
5
5
|
*/
|
|
6
6
|
export declare function getEmails(c: Context): Promise<Response>;
|
|
7
7
|
/**
|
|
8
|
-
* POST /api/
|
|
8
|
+
* POST /api/email/admin/emails/draft
|
|
9
9
|
* Save email as draft
|
|
10
10
|
*/
|
|
11
11
|
export declare function saveDraft(c: Context): Promise<Response>;
|
|
12
12
|
/**
|
|
13
|
-
* DELETE /api/
|
|
13
|
+
* DELETE /api/email/admin/emails/:id
|
|
14
14
|
* Delete email (draft or sent)
|
|
15
15
|
*/
|
|
16
16
|
export declare function deleteEmail(c: Context): Promise<Response>;
|
|
@@ -18,4 +18,14 @@ export declare function deleteEmail(c: Context): Promise<Response>;
|
|
|
18
18
|
* Save sent email record to database
|
|
19
19
|
*/
|
|
20
20
|
export declare function saveSentEmail(db: D1Database, subject: string, htmlContent: string, recipientCount: number): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* GET /api/email/admin/template
|
|
23
|
+
* Get the global email template settings
|
|
24
|
+
*/
|
|
25
|
+
export declare function getTemplate(c: Context): Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* PUT /api/email/admin/template
|
|
28
|
+
* Save/update the global email template settings
|
|
29
|
+
*/
|
|
30
|
+
export declare function saveTemplate(c: Context): Promise<Response>;
|
|
21
31
|
//# sourceMappingURL=emails.handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emails.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/emails.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwB/B;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmB7D;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"emails.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/emails.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwB/B;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmB7D;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4G7D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+B/D;AAED;;GAEG;AACH,wBAAsB,aAAa,CAClC,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CAWf;AAuCD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2C/D;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoDhE"}
|
|
@@ -9,7 +9,7 @@ function parseEmailRecord(row) {
|
|
|
9
9
|
subject: row.subject,
|
|
10
10
|
htmlContent: row.html_content,
|
|
11
11
|
status: row.status,
|
|
12
|
-
|
|
12
|
+
emailType: row.email_type || undefined,
|
|
13
13
|
recipientCount: row.recipient_count || undefined,
|
|
14
14
|
sentAt: row.sent_at || undefined,
|
|
15
15
|
scheduledFor: row.scheduled_for || undefined,
|
|
@@ -18,7 +18,7 @@ function parseEmailRecord(row) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* GET /api/
|
|
21
|
+
* GET /api/email/admin/emails
|
|
22
22
|
* Get all emails (sent emails and drafts)
|
|
23
23
|
*/
|
|
24
24
|
export async function getEmails(c) {
|
|
@@ -37,26 +37,58 @@ export async function getEmails(c) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* POST /api/
|
|
40
|
+
* POST /api/email/admin/emails/draft
|
|
41
41
|
* Save email as draft
|
|
42
42
|
*/
|
|
43
43
|
export async function saveDraft(c) {
|
|
44
44
|
try {
|
|
45
45
|
const body = (await c.req.json());
|
|
46
|
-
const { subject, htmlContent, id,
|
|
46
|
+
const { subject, htmlContent, id, emailType } = body;
|
|
47
47
|
if (!subject || !htmlContent) {
|
|
48
48
|
return c.json({ success: false, message: 'Subject and content are required' }, 400);
|
|
49
49
|
}
|
|
50
50
|
const db = c.env.DB;
|
|
51
51
|
const now = Date.now();
|
|
52
|
+
// Handle auto emails (upsert by type)
|
|
53
|
+
if (emailType) {
|
|
54
|
+
const existing = await db
|
|
55
|
+
.prepare('SELECT id FROM emails WHERE email_type = ?')
|
|
56
|
+
.bind(emailType)
|
|
57
|
+
.first();
|
|
58
|
+
if (existing) {
|
|
59
|
+
// Update existing auto email
|
|
60
|
+
await db
|
|
61
|
+
.prepare(`UPDATE emails
|
|
62
|
+
SET subject = ?, html_content = ?, updated_at = ?
|
|
63
|
+
WHERE id = ?`)
|
|
64
|
+
.bind(subject, htmlContent, now, existing.id)
|
|
65
|
+
.run();
|
|
66
|
+
const row = await db.prepare('SELECT * FROM emails WHERE id = ?').bind(existing.id).first();
|
|
67
|
+
const email = parseEmailRecord(row);
|
|
68
|
+
return c.json({ success: true, email });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// Create new auto email
|
|
72
|
+
const newId = generateId();
|
|
73
|
+
await db
|
|
74
|
+
.prepare(`INSERT INTO emails
|
|
75
|
+
(id, subject, html_content, status, email_type, created_at, updated_at)
|
|
76
|
+
VALUES (?, ?, ?, 'auto', ?, ?, ?)`)
|
|
77
|
+
.bind(newId, subject, htmlContent, emailType, now, now)
|
|
78
|
+
.run();
|
|
79
|
+
const row = await db.prepare('SELECT * FROM emails WHERE id = ?').bind(newId).first();
|
|
80
|
+
const email = parseEmailRecord(row);
|
|
81
|
+
return c.json({ success: true, email });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Handle regular drafts
|
|
52
85
|
if (id) {
|
|
53
86
|
// Update existing draft
|
|
54
|
-
const configJson = config ? JSON.stringify(config) : null;
|
|
55
87
|
await db
|
|
56
88
|
.prepare(`UPDATE emails
|
|
57
|
-
SET subject = ?, html_content = ?,
|
|
89
|
+
SET subject = ?, html_content = ?, updated_at = ?
|
|
58
90
|
WHERE id = ? AND status = 'draft'`)
|
|
59
|
-
.bind(subject, htmlContent,
|
|
91
|
+
.bind(subject, htmlContent, now, id)
|
|
60
92
|
.run();
|
|
61
93
|
const row = await db.prepare('SELECT * FROM emails WHERE id = ?').bind(id).first();
|
|
62
94
|
if (!row) {
|
|
@@ -68,12 +100,11 @@ export async function saveDraft(c) {
|
|
|
68
100
|
else {
|
|
69
101
|
// Create new draft
|
|
70
102
|
const newId = generateId();
|
|
71
|
-
const configJson = config ? JSON.stringify(config) : null;
|
|
72
103
|
await db
|
|
73
104
|
.prepare(`INSERT INTO emails
|
|
74
|
-
(id, subject, html_content,
|
|
75
|
-
VALUES (?, ?, ?,
|
|
76
|
-
.bind(newId, subject, htmlContent,
|
|
105
|
+
(id, subject, html_content, status, created_at, updated_at)
|
|
106
|
+
VALUES (?, ?, ?, 'draft', ?, ?)`)
|
|
107
|
+
.bind(newId, subject, htmlContent, now, now)
|
|
77
108
|
.run();
|
|
78
109
|
const row = await db.prepare('SELECT * FROM emails WHERE id = ?').bind(newId).first();
|
|
79
110
|
if (!row) {
|
|
@@ -92,7 +123,7 @@ export async function saveDraft(c) {
|
|
|
92
123
|
}
|
|
93
124
|
}
|
|
94
125
|
/**
|
|
95
|
-
* DELETE /api/
|
|
126
|
+
* DELETE /api/email/admin/emails/:id
|
|
96
127
|
* Delete email (draft or sent)
|
|
97
128
|
*/
|
|
98
129
|
export async function deleteEmail(c) {
|
|
@@ -132,3 +163,100 @@ export async function saveSentEmail(db, subject, htmlContent, recipientCount) {
|
|
|
132
163
|
.bind(emailId, subject, htmlContent, recipientCount, now, now, now)
|
|
133
164
|
.run();
|
|
134
165
|
}
|
|
166
|
+
function parseTemplateRecord(row) {
|
|
167
|
+
return {
|
|
168
|
+
id: row.id,
|
|
169
|
+
config: row.config ? JSON.parse(row.config) : null,
|
|
170
|
+
logo: row.logo || null,
|
|
171
|
+
createdAt: row.created_at,
|
|
172
|
+
updatedAt: row.updated_at,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* GET /api/email/admin/template
|
|
177
|
+
* Get the global email template settings
|
|
178
|
+
*/
|
|
179
|
+
export async function getTemplate(c) {
|
|
180
|
+
try {
|
|
181
|
+
const db = c.env.DB;
|
|
182
|
+
const row = await db.prepare("SELECT * FROM templates WHERE type = 'email'").first();
|
|
183
|
+
if (!row) {
|
|
184
|
+
// Return default template if none exists
|
|
185
|
+
return c.json({
|
|
186
|
+
template: {
|
|
187
|
+
id: 'email',
|
|
188
|
+
config: {
|
|
189
|
+
backgroundColor: '#f6f6f6',
|
|
190
|
+
contentBackgroundColor: '#ffffff',
|
|
191
|
+
borderColor: '#ffffff',
|
|
192
|
+
borderWidth: '0px',
|
|
193
|
+
borderRadius: '3px',
|
|
194
|
+
maxWidth: '580px',
|
|
195
|
+
h1Color: '#000000',
|
|
196
|
+
h2Color: '#000000',
|
|
197
|
+
h3Color: '#000000',
|
|
198
|
+
h4Color: '#000000',
|
|
199
|
+
pColor: '#1f2328',
|
|
200
|
+
linkColor: '#3498db',
|
|
201
|
+
},
|
|
202
|
+
logo: null,
|
|
203
|
+
createdAt: null,
|
|
204
|
+
updatedAt: null,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const template = parseTemplateRecord(row);
|
|
209
|
+
return c.json({ template });
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
console.error('Get template error:', error);
|
|
213
|
+
return c.json({
|
|
214
|
+
success: false,
|
|
215
|
+
message: error instanceof Error ? error.message : 'Failed to fetch template',
|
|
216
|
+
}, 500);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* PUT /api/email/admin/template
|
|
221
|
+
* Save/update the global email template settings
|
|
222
|
+
*/
|
|
223
|
+
export async function saveTemplate(c) {
|
|
224
|
+
try {
|
|
225
|
+
const body = (await c.req.json());
|
|
226
|
+
const { config, logo } = body;
|
|
227
|
+
if (!config) {
|
|
228
|
+
return c.json({ success: false, message: 'Config is required' }, 400);
|
|
229
|
+
}
|
|
230
|
+
const db = c.env.DB;
|
|
231
|
+
const now = Date.now();
|
|
232
|
+
const configJson = JSON.stringify(config);
|
|
233
|
+
// Upsert: check if email template exists
|
|
234
|
+
const existing = await db.prepare("SELECT id FROM templates WHERE type = 'email'").first();
|
|
235
|
+
if (existing) {
|
|
236
|
+
await db
|
|
237
|
+
.prepare(`UPDATE templates
|
|
238
|
+
SET config = ?, logo = ?, updated_at = ?
|
|
239
|
+
WHERE type = 'email'`)
|
|
240
|
+
.bind(configJson, logo ?? null, now)
|
|
241
|
+
.run();
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
await db
|
|
245
|
+
.prepare(`INSERT INTO templates
|
|
246
|
+
(id, type, config, logo, created_at, updated_at)
|
|
247
|
+
VALUES ('email', 'email', ?, ?, ?, ?)`)
|
|
248
|
+
.bind(configJson, logo ?? null, now, now)
|
|
249
|
+
.run();
|
|
250
|
+
}
|
|
251
|
+
const row = await db.prepare("SELECT * FROM templates WHERE type = 'email'").first();
|
|
252
|
+
const template = parseTemplateRecord(row);
|
|
253
|
+
return c.json({ success: true, template });
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
console.error('Save template error:', error);
|
|
257
|
+
return c.json({
|
|
258
|
+
success: false,
|
|
259
|
+
message: error instanceof Error ? error.message : 'Failed to save template',
|
|
260
|
+
}, 500);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
import type { InvoiceTemplate, InvoiceData } from '@hintergrund/shared';
|
|
4
|
+
/**
|
|
5
|
+
* GET /api/email/admin/invoice-template
|
|
6
|
+
* Fetch the invoice template configuration
|
|
7
|
+
*/
|
|
8
|
+
export declare function getInvoiceTemplate(c: Context<{
|
|
9
|
+
Bindings: Bindings;
|
|
10
|
+
}>): Promise<Response>;
|
|
11
|
+
/**
|
|
12
|
+
* POST /api/email/admin/invoice-template
|
|
13
|
+
* Save the invoice template configuration
|
|
14
|
+
*/
|
|
15
|
+
export declare function saveInvoiceTemplate(c: Context<{
|
|
16
|
+
Bindings: Bindings;
|
|
17
|
+
}>): Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* Generate PDF invoice
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateInvoicePdf(template: InvoiceTemplate, data: InvoiceData): Promise<Uint8Array>;
|
|
22
|
+
//# sourceMappingURL=invoice.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/invoice.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAiB,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAuBvF;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmC9F;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwD/F;AAwBD;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,WAAW,GACf,OAAO,CAAC,UAAU,CAAC,CA6WrB"}
|