@hintergrund/worker 0.1.1 → 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/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 +233 -0
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +9 -12
- 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 +32 -31
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* POST /api/
|
|
3
|
+
* POST /api/email/subscribe
|
|
4
4
|
* Public endpoint to subscribe to newsletter
|
|
5
5
|
*/
|
|
6
6
|
export declare function subscribe(c: Context): Promise<Response>;
|
|
7
7
|
/**
|
|
8
|
-
* GET /api/
|
|
8
|
+
* GET /api/email/confirm?token=xxx
|
|
9
9
|
* Public endpoint to confirm subscription
|
|
10
10
|
*/
|
|
11
11
|
export declare function confirm(c: Context): Promise<Response>;
|
|
12
12
|
/**
|
|
13
|
-
* GET /api/
|
|
13
|
+
* GET /api/email/unsubscribe?token=xxx
|
|
14
14
|
* Public endpoint to show unsubscribe confirmation page
|
|
15
15
|
*/
|
|
16
16
|
export declare function showUnsubscribePage(c: Context): Promise<Response>;
|
|
17
17
|
/**
|
|
18
|
-
* POST /api/
|
|
18
|
+
* POST /api/email/unsubscribe
|
|
19
19
|
* Public endpoint to unsubscribe from newsletter
|
|
20
20
|
*/
|
|
21
21
|
export declare function unsubscribe(c: Context): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/public.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/public.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AA0F/B;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuH7D;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8F3D;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAcvE;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqD/D"}
|
|
@@ -12,15 +12,16 @@ function isValidEmail(email) {
|
|
|
12
12
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13
13
|
return emailRegex.test(email);
|
|
14
14
|
}
|
|
15
|
-
//
|
|
16
|
-
async function
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
// Helper to get auto email template
|
|
16
|
+
async function getAutoEmailTemplate(db, type) {
|
|
17
|
+
const template = await db
|
|
18
|
+
.prepare('SELECT subject, html_content FROM emails WHERE email_type = ? LIMIT 1')
|
|
19
|
+
.bind(type)
|
|
20
|
+
.first();
|
|
21
|
+
return template;
|
|
22
|
+
}
|
|
23
|
+
// Send email via Resend
|
|
24
|
+
async function sendEmailViaResend(apiKey, to, from, fromName, subject, html) {
|
|
24
25
|
const response = await fetch('https://api.resend.com/emails', {
|
|
25
26
|
method: 'POST',
|
|
26
27
|
headers: {
|
|
@@ -29,18 +30,39 @@ async function sendConfirmationEmail(email, token, apiKey, from, fromName, confi
|
|
|
29
30
|
},
|
|
30
31
|
body: JSON.stringify({
|
|
31
32
|
from: `${fromName} <${from}>`,
|
|
32
|
-
to
|
|
33
|
-
subject
|
|
33
|
+
to,
|
|
34
|
+
subject,
|
|
34
35
|
html,
|
|
35
36
|
}),
|
|
36
37
|
});
|
|
37
38
|
if (!response.ok) {
|
|
38
39
|
const error = await response.text();
|
|
39
|
-
throw new Error(`Failed to send
|
|
40
|
+
throw new Error(`Failed to send email: ${error}`);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
// Send confirmation email via Resend
|
|
44
|
+
async function sendConfirmationEmail(db, email, token, apiKey, from, fromName, confirmationUrl) {
|
|
45
|
+
const confirmLink = `${confirmationUrl}?token=${token}`;
|
|
46
|
+
const template = await getAutoEmailTemplate(db, 'confirm');
|
|
47
|
+
let html = '';
|
|
48
|
+
let subject = 'Confirm your subscription';
|
|
49
|
+
if (template) {
|
|
50
|
+
subject = template.subject;
|
|
51
|
+
html = template.html_content.replace(/{{confirm_url}}/g, confirmLink);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Default template
|
|
55
|
+
html = `
|
|
56
|
+
<h2>Confirm your subscription</h2>
|
|
57
|
+
<p>Thank you for subscribing! Please confirm your email address by clicking the link below:</p>
|
|
58
|
+
<p><a href="${confirmLink}">${confirmLink}</a></p>
|
|
59
|
+
<p>If you didn't request this, you can safely ignore this email.</p>
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
await sendEmailViaResend(apiKey, email, from, fromName, subject, html);
|
|
63
|
+
}
|
|
42
64
|
/**
|
|
43
|
-
* POST /api/
|
|
65
|
+
* POST /api/email/subscribe
|
|
44
66
|
* Public endpoint to subscribe to newsletter
|
|
45
67
|
*/
|
|
46
68
|
export async function subscribe(c) {
|
|
@@ -86,7 +108,7 @@ export async function subscribe(c) {
|
|
|
86
108
|
.bind(token, now, now, normalizedEmail)
|
|
87
109
|
.run();
|
|
88
110
|
// Send confirmation email
|
|
89
|
-
await sendConfirmationEmail(normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
111
|
+
await sendConfirmationEmail(db, normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
90
112
|
return c.json({
|
|
91
113
|
success: true,
|
|
92
114
|
message: 'Please check your email to confirm your subscription',
|
|
@@ -104,7 +126,7 @@ export async function subscribe(c) {
|
|
|
104
126
|
.bind(token, now, now, normalizedEmail)
|
|
105
127
|
.run();
|
|
106
128
|
// Send confirmation email
|
|
107
|
-
await sendConfirmationEmail(normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
129
|
+
await sendConfirmationEmail(db, normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
108
130
|
return c.json({
|
|
109
131
|
success: true,
|
|
110
132
|
message: 'Please check your email to confirm your subscription',
|
|
@@ -123,7 +145,7 @@ export async function subscribe(c) {
|
|
|
123
145
|
.bind(id, normalizedEmail, name || null, token, unsubscribeToken, now, now, now)
|
|
124
146
|
.run();
|
|
125
147
|
// Send confirmation email
|
|
126
|
-
await sendConfirmationEmail(normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
148
|
+
await sendConfirmationEmail(db, normalizedEmail, token, apiKey, fromEmail, fromName || 'Newsletter', confirmationUrl);
|
|
127
149
|
return c.json({
|
|
128
150
|
success: true,
|
|
129
151
|
message: 'Please check your email to confirm your subscription',
|
|
@@ -138,7 +160,7 @@ export async function subscribe(c) {
|
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
162
|
/**
|
|
141
|
-
* GET /api/
|
|
163
|
+
* GET /api/email/confirm?token=xxx
|
|
142
164
|
* Public endpoint to confirm subscription
|
|
143
165
|
*/
|
|
144
166
|
export async function confirm(c) {
|
|
@@ -150,7 +172,7 @@ export async function confirm(c) {
|
|
|
150
172
|
const db = c.env.DB;
|
|
151
173
|
// Find subscriber by confirmation token
|
|
152
174
|
const subscriber = await db
|
|
153
|
-
.prepare('SELECT id, status FROM subscribers WHERE confirmation_token = ?')
|
|
175
|
+
.prepare('SELECT id, status, email FROM subscribers WHERE confirmation_token = ?')
|
|
154
176
|
.bind(token)
|
|
155
177
|
.first();
|
|
156
178
|
if (!subscriber) {
|
|
@@ -164,6 +186,42 @@ export async function confirm(c) {
|
|
|
164
186
|
WHERE id = ?`)
|
|
165
187
|
.bind(now, now, now, subscriber.id)
|
|
166
188
|
.run();
|
|
189
|
+
// Send welcome email if configured
|
|
190
|
+
try {
|
|
191
|
+
const welcomeTemplate = await getAutoEmailTemplate(db, 'welcome');
|
|
192
|
+
if (welcomeTemplate) {
|
|
193
|
+
const apiKey = c.env.HG_NEWSLETTER_EMAIL_API_KEY;
|
|
194
|
+
const fromEmail = c.env.HG_NEWSLETTER_FROM_EMAIL;
|
|
195
|
+
const fromName = c.env.HG_NEWSLETTER_FROM_NAME;
|
|
196
|
+
if (apiKey && fromEmail) {
|
|
197
|
+
// We need unsubscribe link for welcome email usually, but public handler might not have easy access to generate it
|
|
198
|
+
// without the unsubscribe token. Wait, we have the subscriber, we can get their unsubscribe token.
|
|
199
|
+
// But we just updated the record. Let's fetch the unsubscribe token.
|
|
200
|
+
const subData = await db
|
|
201
|
+
.prepare('SELECT unsubscribe_token FROM subscribers WHERE id = ?')
|
|
202
|
+
.bind(subscriber.id)
|
|
203
|
+
.first();
|
|
204
|
+
// If we can't get it easily, we might skip it or use a placeholder.
|
|
205
|
+
// Assuming the template has {{unsubscribe_url}}.
|
|
206
|
+
// The unsubscribe URL is likely /newsletter/unsubscribe?token=...
|
|
207
|
+
// Base URL? We can use c.req.url origin or an env var.
|
|
208
|
+
// The confirmation URL env var base can be used.
|
|
209
|
+
const confirmationUrl = c.env.HG_NEWSLETTER_CONFIRMATION_URL;
|
|
210
|
+
let unsubscribeUrl = '#';
|
|
211
|
+
if (confirmationUrl && subData?.unsubscribe_token) {
|
|
212
|
+
// Assuming confirmationUrl is .../newsletter/confirm
|
|
213
|
+
const baseUrl = new URL(confirmationUrl).origin;
|
|
214
|
+
unsubscribeUrl = `${baseUrl}/newsletter/unsubscribe?token=${subData.unsubscribe_token}`;
|
|
215
|
+
}
|
|
216
|
+
const html = welcomeTemplate.html_content.replace(/{{unsubscribe_url}}/g, unsubscribeUrl);
|
|
217
|
+
await sendEmailViaResend(apiKey, subscriber.email, fromEmail, fromName || 'Newsletter', welcomeTemplate.subject, html);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (emailError) {
|
|
222
|
+
console.error('Failed to send welcome email:', emailError);
|
|
223
|
+
// Don't fail the confirmation request just because welcome email failed
|
|
224
|
+
}
|
|
167
225
|
return c.json({
|
|
168
226
|
success: true,
|
|
169
227
|
message: 'Your subscription has been confirmed! Thank you for subscribing.',
|
|
@@ -178,7 +236,7 @@ export async function confirm(c) {
|
|
|
178
236
|
}
|
|
179
237
|
}
|
|
180
238
|
/**
|
|
181
|
-
* GET /api/
|
|
239
|
+
* GET /api/email/unsubscribe?token=xxx
|
|
182
240
|
* Public endpoint to show unsubscribe confirmation page
|
|
183
241
|
*/
|
|
184
242
|
export async function showUnsubscribePage(c) {
|
|
@@ -193,7 +251,7 @@ export async function showUnsubscribePage(c) {
|
|
|
193
251
|
return c.html(getTemplate('unsubscribe', '', tokenScript));
|
|
194
252
|
}
|
|
195
253
|
/**
|
|
196
|
-
* POST /api/
|
|
254
|
+
* POST /api/email/unsubscribe
|
|
197
255
|
* Public endpoint to unsubscribe from newsletter
|
|
198
256
|
*/
|
|
199
257
|
export async function unsubscribe(c) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* POST /api/
|
|
3
|
+
* POST /api/email/admin/send
|
|
4
4
|
* Send bulk email to all subscribed users (admin only)
|
|
5
5
|
*/
|
|
6
6
|
export declare function sendBulkEmail(c: Context): Promise<Response>;
|
|
7
7
|
/**
|
|
8
|
-
* POST /api/
|
|
8
|
+
* POST /api/email/admin/emails/test
|
|
9
9
|
* Send test email to a single email address
|
|
10
10
|
*/
|
|
11
11
|
export declare function sendTestEmail(c: Context): Promise<Response>;
|
|
@@ -40,7 +40,7 @@ function toResendAttachments(images) {
|
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* POST /api/
|
|
43
|
+
* POST /api/email/admin/send
|
|
44
44
|
* Send bulk email to all subscribed users (admin only)
|
|
45
45
|
*/
|
|
46
46
|
export async function sendBulkEmail(c) {
|
|
@@ -72,7 +72,7 @@ export async function sendBulkEmail(c) {
|
|
|
72
72
|
for (const subscriber of subscribers) {
|
|
73
73
|
try {
|
|
74
74
|
// Append unsubscribe link to HTML
|
|
75
|
-
const unsubscribeUrl = `${c.req.url.split('/api')[0]}/api/
|
|
75
|
+
const unsubscribeUrl = `${c.req.url.split('/api')[0]}/api/email/unsubscribe?token=${subscriber.unsubscribe_token}`;
|
|
76
76
|
const htmlWithUnsubscribe = `
|
|
77
77
|
${html}
|
|
78
78
|
<hr style="margin-top: 2rem; margin-bottom: 1rem; border: none; border-top: 1px solid #eee;">
|
|
@@ -112,7 +112,7 @@ export async function sendBulkEmail(c) {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
* POST /api/
|
|
115
|
+
* POST /api/email/admin/emails/test
|
|
116
116
|
* Send test email to a single email address
|
|
117
117
|
*/
|
|
118
118
|
export async function sendTestEmail(c) {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
2
|
/**
|
|
3
|
-
* GET /api/
|
|
3
|
+
* GET /api/email/admin/subscribers
|
|
4
4
|
* Get all subscribers (admin only)
|
|
5
5
|
*/
|
|
6
6
|
export declare function getSubscribers(c: Context): Promise<Response>;
|
|
7
7
|
/**
|
|
8
|
-
* POST /api/
|
|
8
|
+
* POST /api/email/admin/subscribers
|
|
9
9
|
* Manually add subscriber (admin only, bypasses confirmation)
|
|
10
10
|
*/
|
|
11
11
|
export declare function addSubscriber(c: Context): Promise<Response>;
|
|
12
12
|
/**
|
|
13
|
-
* DELETE /api/
|
|
13
|
+
* DELETE /api/email/admin/subscribers/:id
|
|
14
14
|
* Delete subscriber by ID (admin only)
|
|
15
15
|
*/
|
|
16
16
|
export declare function deleteSubscriber(c: Context): Promise<Response>;
|
|
17
17
|
/**
|
|
18
|
-
* PATCH /api/
|
|
18
|
+
* PATCH /api/email/admin/subscribers/:id
|
|
19
19
|
* Update subscriber (admin only)
|
|
20
20
|
*/
|
|
21
21
|
export declare function updateSubscriber(c: Context): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribers.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/subscribers.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwC/B;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBlE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6DjE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+BpE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"subscribers.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/subscribers.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwC/B;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBlE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6DjE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+BpE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+EpE"}
|
|
@@ -32,7 +32,7 @@ function parseSubscriber(row) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* GET /api/
|
|
35
|
+
* GET /api/email/admin/subscribers
|
|
36
36
|
* Get all subscribers (admin only)
|
|
37
37
|
*/
|
|
38
38
|
export async function getSubscribers(c) {
|
|
@@ -51,7 +51,7 @@ export async function getSubscribers(c) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* POST /api/
|
|
54
|
+
* POST /api/email/admin/subscribers
|
|
55
55
|
* Manually add subscriber (admin only, bypasses confirmation)
|
|
56
56
|
*/
|
|
57
57
|
export async function addSubscriber(c) {
|
|
@@ -103,7 +103,7 @@ export async function addSubscriber(c) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
* DELETE /api/
|
|
106
|
+
* DELETE /api/email/admin/subscribers/:id
|
|
107
107
|
* Delete subscriber by ID (admin only)
|
|
108
108
|
*/
|
|
109
109
|
export async function deleteSubscriber(c) {
|
|
@@ -131,7 +131,7 @@ export async function deleteSubscriber(c) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
* PATCH /api/
|
|
134
|
+
* PATCH /api/email/admin/subscribers/:id
|
|
135
135
|
* Update subscriber (admin only)
|
|
136
136
|
*/
|
|
137
137
|
export async function updateSubscriber(c) {
|
|
@@ -162,6 +162,10 @@ export async function updateSubscriber(c) {
|
|
|
162
162
|
updates.push('subscribed_at = ?');
|
|
163
163
|
params.push(Date.now());
|
|
164
164
|
}
|
|
165
|
+
else if (body.status === 'unsubscribed') {
|
|
166
|
+
updates.push('unsubscribed_at = ?');
|
|
167
|
+
params.push(Date.now());
|
|
168
|
+
}
|
|
165
169
|
}
|
|
166
170
|
// Always update updated_at
|
|
167
171
|
updates.push('updated_at = ?');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/routes/admin.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"admin.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/routes/admin.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,QAAA,MAAM,WAAW,4EAAa,CAAC;AA4B/B,eAAe,WAAW,CAAC"}
|
|
@@ -2,7 +2,8 @@ import { Hono } from 'hono';
|
|
|
2
2
|
import { authMiddleware } from '../../../middleware/auth';
|
|
3
3
|
import { getSubscribers, addSubscriber, deleteSubscriber, updateSubscriber } from '../handlers/subscribers.handler';
|
|
4
4
|
import { sendBulkEmail, sendTestEmail } from '../handlers/send.handler';
|
|
5
|
-
import { getEmails, saveDraft, deleteEmail } from '../handlers/emails.handler';
|
|
5
|
+
import { getEmails, saveDraft, deleteEmail, getTemplate, saveTemplate } from '../handlers/emails.handler';
|
|
6
|
+
import { getInvoiceTemplate, saveInvoiceTemplate } from '../handlers/invoice.handler';
|
|
6
7
|
const adminRoutes = new Hono();
|
|
7
8
|
// Protect all admin routes with authentication
|
|
8
9
|
adminRoutes.use('*', authMiddleware);
|
|
@@ -18,4 +19,10 @@ adminRoutes.get('/emails', getEmails);
|
|
|
18
19
|
adminRoutes.post('/emails/draft', saveDraft);
|
|
19
20
|
adminRoutes.post('/emails/test', sendTestEmail);
|
|
20
21
|
adminRoutes.delete('/emails/:id', deleteEmail);
|
|
22
|
+
// Admin template settings endpoints
|
|
23
|
+
adminRoutes.get('/template', getTemplate);
|
|
24
|
+
adminRoutes.put('/template', saveTemplate);
|
|
25
|
+
// Admin invoice template endpoints
|
|
26
|
+
adminRoutes.get('/invoice-template', getInvoiceTemplate);
|
|
27
|
+
adminRoutes.put('/invoice-template', saveInvoiceTemplate);
|
|
21
28
|
export default adminRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/assets.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwEnE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import { getShopConfig } from '../../../lib/config';
|
|
3
|
+
export async function uploadShopAsset(c) {
|
|
4
|
+
try {
|
|
5
|
+
const config = getShopConfig(c.env);
|
|
6
|
+
const stripe = new Stripe(config.stripeSecretKey, {
|
|
7
|
+
apiVersion: '2025-02-24.acacia'
|
|
8
|
+
});
|
|
9
|
+
const { file, content, mimeType } = await c.req.json();
|
|
10
|
+
const filename = file || (await c.req.json()).name;
|
|
11
|
+
if (!filename || !content) {
|
|
12
|
+
return new Response('Missing filename or content', { status: 400 });
|
|
13
|
+
}
|
|
14
|
+
// Convert base64 to Uint8Array/Blob for Stripe
|
|
15
|
+
const binaryString = atob(content);
|
|
16
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
17
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
18
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
19
|
+
}
|
|
20
|
+
const fileObject = new File([bytes], filename, { type: mimeType });
|
|
21
|
+
// Upload to Stripe Files API
|
|
22
|
+
const stripeFile = await stripe.files.create({
|
|
23
|
+
file: {
|
|
24
|
+
data: bytes,
|
|
25
|
+
name: filename,
|
|
26
|
+
type: mimeType
|
|
27
|
+
},
|
|
28
|
+
purpose: 'product_image'
|
|
29
|
+
});
|
|
30
|
+
// Create a public file link so the image is accessible
|
|
31
|
+
const fileLink = await stripe.fileLinks.create({
|
|
32
|
+
file: stripeFile.id
|
|
33
|
+
});
|
|
34
|
+
const url = fileLink.url;
|
|
35
|
+
console.log('[Upload] Stripe File ID:', stripeFile.id);
|
|
36
|
+
console.log('[Upload] Generated URL:', url);
|
|
37
|
+
console.log('[Upload] File Type:', mimeType);
|
|
38
|
+
console.log('[Upload] Original Name:', filename);
|
|
39
|
+
if (!url) {
|
|
40
|
+
throw new Error('Failed to get URL from Stripe File upload');
|
|
41
|
+
}
|
|
42
|
+
return new Response(JSON.stringify({
|
|
43
|
+
success: true,
|
|
44
|
+
url,
|
|
45
|
+
message: `Uploaded ${filename} to Stripe`
|
|
46
|
+
}), {
|
|
47
|
+
status: 200,
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Shop asset upload error:', error);
|
|
55
|
+
return new Response(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }), {
|
|
56
|
+
status: 500,
|
|
57
|
+
headers: {
|
|
58
|
+
'Content-Type': 'application/json'
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/shop/checkout
|
|
5
|
+
* Create a Stripe Checkout Session
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCheckoutSession(c: Context<{
|
|
8
|
+
Bindings: Bindings;
|
|
9
|
+
}>): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=checkout.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/checkout.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAW/C;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8CjG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getShopConfig } from '../../../lib/config';
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
function getStripe(env) {
|
|
4
|
+
const config = getShopConfig(env);
|
|
5
|
+
return new Stripe(config.stripeSecretKey, {
|
|
6
|
+
apiVersion: '2025-02-24.acacia'
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* POST /api/shop/checkout
|
|
11
|
+
* Create a Stripe Checkout Session
|
|
12
|
+
*/
|
|
13
|
+
export async function createCheckoutSession(c) {
|
|
14
|
+
try {
|
|
15
|
+
const stripe = getStripe(c.env);
|
|
16
|
+
const body = await c.req.json();
|
|
17
|
+
const { priceId, quantity = 1, successUrl, cancelUrl, customerEmail, metadata, mode = 'payment' } = body;
|
|
18
|
+
const items = body.items || [];
|
|
19
|
+
if (priceId) {
|
|
20
|
+
items.push({ priceId, quantity });
|
|
21
|
+
}
|
|
22
|
+
if (items.length === 0) {
|
|
23
|
+
return c.json({ success: false, error: 'No items provided' }, 400);
|
|
24
|
+
}
|
|
25
|
+
if (!successUrl || !cancelUrl) {
|
|
26
|
+
return c.json({ success: false, error: 'Missing successUrl or cancelUrl' }, 400);
|
|
27
|
+
}
|
|
28
|
+
const lineItems = items.map((item) => ({
|
|
29
|
+
price: item.priceId,
|
|
30
|
+
quantity: item.quantity,
|
|
31
|
+
}));
|
|
32
|
+
const sessionParams = {
|
|
33
|
+
line_items: lineItems,
|
|
34
|
+
mode: mode,
|
|
35
|
+
success_url: successUrl,
|
|
36
|
+
cancel_url: cancelUrl,
|
|
37
|
+
customer_email: customerEmail,
|
|
38
|
+
metadata: metadata,
|
|
39
|
+
allow_promotion_codes: true,
|
|
40
|
+
};
|
|
41
|
+
// If customer is logged in or provided, we could attach it.
|
|
42
|
+
// For now, simple checkout.
|
|
43
|
+
const session = await stripe.checkout.sessions.create(sessionParams);
|
|
44
|
+
return c.json({ url: session.url, sessionId: session.id });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error('Checkout error:', error);
|
|
48
|
+
return c.json({ success: false, error: error.message }, 500);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { Bindings } from '../../../index';
|
|
3
|
-
/**
|
|
4
|
-
* GET /api/shop/products
|
|
5
|
-
* List all active products (public endpoint)
|
|
6
|
-
*/
|
|
7
|
-
export declare function getPublicProducts(c: Context<{
|
|
8
|
-
Bindings: Bindings;
|
|
9
|
-
}>): Promise<Response>;
|
|
10
3
|
/**
|
|
11
4
|
* GET /api/shop/admin/products
|
|
12
5
|
* List all products
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"products.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/products.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"products.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/products.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA+D/C;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8BvF;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqBtF;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+CzF;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmCzF;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4BzF"}
|
|
@@ -43,29 +43,6 @@ function mapStripeProduct(product, defaultPrice) {
|
|
|
43
43
|
defaultPrice: defaultPrice ? mapStripePrice(defaultPrice) : undefined
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
* GET /api/shop/products
|
|
48
|
-
* List all active products (public endpoint)
|
|
49
|
-
*/
|
|
50
|
-
export async function getPublicProducts(c) {
|
|
51
|
-
try {
|
|
52
|
-
const stripe = getStripe(c.env);
|
|
53
|
-
const products = await stripe.products.list({
|
|
54
|
-
active: true,
|
|
55
|
-
limit: 100,
|
|
56
|
-
expand: ['data.default_price']
|
|
57
|
-
});
|
|
58
|
-
const response = {
|
|
59
|
-
products: products.data.map((p) => mapStripeProduct(p, p.default_price)),
|
|
60
|
-
hasMore: products.has_more
|
|
61
|
-
};
|
|
62
|
-
return c.json(response);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
console.error('Failed to fetch products:', error);
|
|
66
|
-
return c.json({ success: false, error: 'Failed to fetch products' }, 500);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
46
|
/**
|
|
70
47
|
* GET /api/shop/admin/products
|
|
71
48
|
* List all products
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
/**
|
|
4
|
+
* GET /api/shop/products
|
|
5
|
+
* List all active products (public endpoint)
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPublicProducts(c: Context<{
|
|
8
|
+
Bindings: Bindings;
|
|
9
|
+
}>): Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* POST /api/shop/checkout
|
|
12
|
+
* Create a Stripe Checkout Session
|
|
13
|
+
*/
|
|
14
|
+
export declare function createCheckoutSession(c: Context<{
|
|
15
|
+
Bindings: Bindings;
|
|
16
|
+
}>): Promise<Response>;
|
|
17
|
+
//# sourceMappingURL=public.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/public.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAuD/C;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsB7F;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2CjG"}
|