@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,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages combined email settings (branding + invoice) stored in GitHub.
|
|
5
|
+
* Now uses split files: branding.json, invoice.json, and templates/*.json
|
|
6
|
+
* Provides local-first sync support with commit SHA tracking.
|
|
7
|
+
*/
|
|
8
|
+
import { getGitHubConfig } from '../../../lib/config';
|
|
9
|
+
import { createGitHubClient } from '../../../lib/github';
|
|
10
|
+
// Default branding configuration
|
|
11
|
+
function getDefaultBranding() {
|
|
12
|
+
return {
|
|
13
|
+
primaryColor: '#3498db',
|
|
14
|
+
companyName: '',
|
|
15
|
+
footerText: '',
|
|
16
|
+
backgroundColor: '#f6f6f6',
|
|
17
|
+
contentBackgroundColor: '#ffffff',
|
|
18
|
+
maxWidth: '580px',
|
|
19
|
+
borderRadius: '6px',
|
|
20
|
+
logoAlign: 'center',
|
|
21
|
+
logoSize: '120px',
|
|
22
|
+
logoInside: true,
|
|
23
|
+
footerColor: '#999999',
|
|
24
|
+
socialLinks: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Default branding record
|
|
28
|
+
function getDefaultBrandingRecord() {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
return {
|
|
31
|
+
id: 'global',
|
|
32
|
+
config: getDefaultBranding(),
|
|
33
|
+
logo: undefined,
|
|
34
|
+
createdAt: now,
|
|
35
|
+
updatedAt: now,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Default invoice configuration
|
|
39
|
+
function getDefaultInvoiceConfig() {
|
|
40
|
+
return {
|
|
41
|
+
primaryColor: '#1f2937',
|
|
42
|
+
accentColor: '#6b7280',
|
|
43
|
+
fontFamily: 'helvetica',
|
|
44
|
+
logoPosition: 'left',
|
|
45
|
+
showLogo: true,
|
|
46
|
+
companyName: 'Musterfirma GmbH',
|
|
47
|
+
companyAddress: 'Musterstraße 1, 12345 Musterstadt, Deutschland',
|
|
48
|
+
companyEmail: 'info@musterfirma.de',
|
|
49
|
+
companyPhone: '+49 123 456789',
|
|
50
|
+
footerText: 'Vielen Dank für Ihre Bestellung!',
|
|
51
|
+
currencySymbol: '€',
|
|
52
|
+
currencyPosition: 'before',
|
|
53
|
+
showTaxBreakdown: true,
|
|
54
|
+
taxLabel: 'MwSt.',
|
|
55
|
+
taxRate: 19,
|
|
56
|
+
dueDays: 14
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Default invoice template
|
|
60
|
+
function getDefaultInvoiceTemplate() {
|
|
61
|
+
const now = Date.now();
|
|
62
|
+
return {
|
|
63
|
+
id: 'invoice',
|
|
64
|
+
config: getDefaultInvoiceConfig(),
|
|
65
|
+
createdAt: now,
|
|
66
|
+
updatedAt: now
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Default settings
|
|
70
|
+
function getDefaultSettings() {
|
|
71
|
+
return {
|
|
72
|
+
branding: getDefaultBrandingRecord(),
|
|
73
|
+
invoice: getDefaultInvoiceTemplate(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* File paths for the new split structure
|
|
78
|
+
*/
|
|
79
|
+
const PATHS = {
|
|
80
|
+
branding: 'emails/branding.json',
|
|
81
|
+
invoice: 'emails/invoice.json',
|
|
82
|
+
templates: {
|
|
83
|
+
confirm: 'emails/templates/confirm.json',
|
|
84
|
+
welcome: 'emails/templates/welcome.json',
|
|
85
|
+
purchase: 'emails/templates/purchase.json',
|
|
86
|
+
},
|
|
87
|
+
// Legacy path for backward compatibility
|
|
88
|
+
legacy: 'emails/settings.json',
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* GET /api/email/admin/settings
|
|
92
|
+
* Fetch all email settings (branding + invoice) with commit SHA
|
|
93
|
+
*/
|
|
94
|
+
export async function getSettings(c) {
|
|
95
|
+
try {
|
|
96
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
97
|
+
const github = createGitHubClient(gitConfig);
|
|
98
|
+
// Get current commit SHA
|
|
99
|
+
const commitSha = await github.getCommitSha();
|
|
100
|
+
// Try to read from new split files first
|
|
101
|
+
const [brandingResult, invoiceResult] = await Promise.all([
|
|
102
|
+
github.readJsonFile(PATHS.branding).catch(() => null),
|
|
103
|
+
github.readJsonFile(PATHS.invoice).catch(() => null),
|
|
104
|
+
]);
|
|
105
|
+
let branding = brandingResult?.data;
|
|
106
|
+
let invoice = invoiceResult?.data;
|
|
107
|
+
// Fall back to legacy settings.json if new files don't exist
|
|
108
|
+
if (!branding || !invoice) {
|
|
109
|
+
const legacyResult = await github.readJsonFile(PATHS.legacy).catch(() => null);
|
|
110
|
+
if (legacyResult?.data) {
|
|
111
|
+
branding = branding || legacyResult.data.branding;
|
|
112
|
+
invoice = invoice || legacyResult.data.invoice;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const settings = {
|
|
116
|
+
branding: branding || getDefaultBrandingRecord(),
|
|
117
|
+
invoice: invoice || getDefaultInvoiceTemplate(),
|
|
118
|
+
commitSha,
|
|
119
|
+
};
|
|
120
|
+
return c.json({ settings, commitSha });
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('Get settings error:', error);
|
|
124
|
+
return c.json({
|
|
125
|
+
settings: getDefaultSettings(),
|
|
126
|
+
commitSha: '',
|
|
127
|
+
}, 200);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* GET /api/email/admin/settings/sync
|
|
132
|
+
* Sync settings - only returns data if commit SHA has changed
|
|
133
|
+
* Client sends current SHA in query param, we return new data only if different
|
|
134
|
+
*/
|
|
135
|
+
export async function syncSettings(c) {
|
|
136
|
+
try {
|
|
137
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
138
|
+
const github = createGitHubClient(gitConfig);
|
|
139
|
+
// Get current commit SHA
|
|
140
|
+
const commitSha = await github.getCommitSha();
|
|
141
|
+
// Read from split files
|
|
142
|
+
const [brandingResult, invoiceResult] = await Promise.all([
|
|
143
|
+
github.readJsonFile(PATHS.branding).catch(() => null),
|
|
144
|
+
github.readJsonFile(PATHS.invoice).catch(() => null),
|
|
145
|
+
]);
|
|
146
|
+
let branding = brandingResult?.data;
|
|
147
|
+
let invoice = invoiceResult?.data;
|
|
148
|
+
// Fall back to legacy if needed
|
|
149
|
+
if (!branding || !invoice) {
|
|
150
|
+
const legacyResult = await github.readJsonFile(PATHS.legacy).catch(() => null);
|
|
151
|
+
if (legacyResult?.data) {
|
|
152
|
+
branding = branding || legacyResult.data.branding;
|
|
153
|
+
invoice = invoice || legacyResult.data.invoice;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const settings = {
|
|
157
|
+
branding: branding || getDefaultBrandingRecord(),
|
|
158
|
+
invoice: invoice || getDefaultInvoiceTemplate(),
|
|
159
|
+
commitSha,
|
|
160
|
+
};
|
|
161
|
+
return c.json({ settings, commitSha });
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Sync settings error:', error);
|
|
165
|
+
return c.json({
|
|
166
|
+
settings: getDefaultSettings(),
|
|
167
|
+
commitSha: '',
|
|
168
|
+
}, 200);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* PUT /api/email/admin/settings
|
|
173
|
+
* Save all email settings atomically with conflict detection
|
|
174
|
+
* Now saves to split files instead of combined settings.json
|
|
175
|
+
*/
|
|
176
|
+
export async function saveSettings(c) {
|
|
177
|
+
try {
|
|
178
|
+
const body = await c.req.json();
|
|
179
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
180
|
+
const github = createGitHubClient(gitConfig);
|
|
181
|
+
const now = Date.now();
|
|
182
|
+
// Check for conflicts if commitSha provided
|
|
183
|
+
if (body.commitSha) {
|
|
184
|
+
const currentSha = await github.getCommitSha();
|
|
185
|
+
if (body.commitSha !== currentSha) {
|
|
186
|
+
// Read current server state for conflict resolution
|
|
187
|
+
const [brandingResult, invoiceResult] = await Promise.all([
|
|
188
|
+
github.readJsonFile(PATHS.branding).catch(() => null),
|
|
189
|
+
github.readJsonFile(PATHS.invoice).catch(() => null),
|
|
190
|
+
]);
|
|
191
|
+
const serverSettings = {
|
|
192
|
+
branding: brandingResult?.data || getDefaultBrandingRecord(),
|
|
193
|
+
invoice: invoiceResult?.data || getDefaultInvoiceTemplate(),
|
|
194
|
+
commitSha: currentSha,
|
|
195
|
+
};
|
|
196
|
+
return c.json({
|
|
197
|
+
conflict: true,
|
|
198
|
+
currentCommitSha: currentSha,
|
|
199
|
+
serverSettings,
|
|
200
|
+
message: 'Settings have been modified. Please resolve conflicts.',
|
|
201
|
+
}, 409);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Read existing data for merge
|
|
205
|
+
const [existingBranding, existingInvoice] = await Promise.all([
|
|
206
|
+
github.readJsonFile(PATHS.branding).catch(() => null),
|
|
207
|
+
github.readJsonFile(PATHS.invoice).catch(() => null),
|
|
208
|
+
]);
|
|
209
|
+
// Build updated branding
|
|
210
|
+
const branding = body.branding ? {
|
|
211
|
+
id: 'global',
|
|
212
|
+
config: body.branding.config,
|
|
213
|
+
logo: body.branding.logo ?? existingBranding?.data?.logo ?? undefined,
|
|
214
|
+
createdAt: existingBranding?.data?.createdAt || now,
|
|
215
|
+
updatedAt: now,
|
|
216
|
+
} : (existingBranding?.data || getDefaultBrandingRecord());
|
|
217
|
+
// Build updated invoice
|
|
218
|
+
const invoice = body.invoice ? {
|
|
219
|
+
id: 'invoice',
|
|
220
|
+
config: body.invoice.config,
|
|
221
|
+
createdAt: existingInvoice?.data?.createdAt || now,
|
|
222
|
+
updatedAt: now,
|
|
223
|
+
} : (existingInvoice?.data || getDefaultInvoiceTemplate());
|
|
224
|
+
// Write to separate files
|
|
225
|
+
const writePromises = [];
|
|
226
|
+
if (body.branding) {
|
|
227
|
+
writePromises.push(github.writeJsonFile(PATHS.branding, branding, 'Update email branding'));
|
|
228
|
+
}
|
|
229
|
+
if (body.invoice) {
|
|
230
|
+
writePromises.push(github.writeJsonFile(PATHS.invoice, invoice, 'Update invoice template'));
|
|
231
|
+
}
|
|
232
|
+
await Promise.all(writePromises);
|
|
233
|
+
// Get new commit SHA
|
|
234
|
+
const newCommitSha = await github.getCommitSha();
|
|
235
|
+
const responseSettings = {
|
|
236
|
+
branding,
|
|
237
|
+
invoice,
|
|
238
|
+
commitSha: newCommitSha,
|
|
239
|
+
};
|
|
240
|
+
return c.json({ success: true, settings: responseSettings, commitSha: newCommitSha });
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
console.error('Save settings error:', error);
|
|
244
|
+
return c.json({
|
|
245
|
+
success: false,
|
|
246
|
+
message: error instanceof Error ? error.message : 'Failed to save settings',
|
|
247
|
+
}, 500);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* GET /api/email/admin/settings/templates
|
|
252
|
+
* Get all transactional email templates from GitHub
|
|
253
|
+
*/
|
|
254
|
+
export async function getEmailTemplates(c) {
|
|
255
|
+
try {
|
|
256
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
257
|
+
const github = createGitHubClient(gitConfig);
|
|
258
|
+
const [confirmResult, welcomeResult, purchaseResult] = await Promise.all([
|
|
259
|
+
github.readJsonFile(PATHS.templates.confirm).catch(() => null),
|
|
260
|
+
github.readJsonFile(PATHS.templates.welcome).catch(() => null),
|
|
261
|
+
github.readJsonFile(PATHS.templates.purchase).catch(() => null),
|
|
262
|
+
]);
|
|
263
|
+
const templates = {
|
|
264
|
+
confirm: confirmResult?.data || null,
|
|
265
|
+
welcome: welcomeResult?.data || null,
|
|
266
|
+
purchase: purchaseResult?.data || null,
|
|
267
|
+
};
|
|
268
|
+
return c.json({ templates });
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
console.error('Get email templates error:', error);
|
|
272
|
+
return c.json({ templates: {} }, 200);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* PUT /api/email/admin/settings/templates/:type
|
|
277
|
+
* Save a transactional email template to GitHub
|
|
278
|
+
*/
|
|
279
|
+
export async function saveEmailTemplate(c) {
|
|
280
|
+
try {
|
|
281
|
+
const type = c.req.param('type');
|
|
282
|
+
if (!PATHS.templates[type]) {
|
|
283
|
+
return c.json({ success: false, message: 'Invalid template type' }, 400);
|
|
284
|
+
}
|
|
285
|
+
const body = await c.req.json();
|
|
286
|
+
if (!body.name || !body.subject || !body.body) {
|
|
287
|
+
return c.json({ success: false, message: 'Name, subject, and body are required' }, 400);
|
|
288
|
+
}
|
|
289
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
290
|
+
const github = createGitHubClient(gitConfig);
|
|
291
|
+
const now = Date.now();
|
|
292
|
+
// Read existing template
|
|
293
|
+
const existing = await github.readJsonFile(PATHS.templates[type]).catch(() => null);
|
|
294
|
+
const template = {
|
|
295
|
+
name: body.name,
|
|
296
|
+
subject: body.subject,
|
|
297
|
+
body: body.body,
|
|
298
|
+
type: 'TRANSACTIONAL',
|
|
299
|
+
createdAt: existing?.data?.createdAt || now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
};
|
|
302
|
+
await github.writeJsonFile(PATHS.templates[type], template, `Update ${type} email template`);
|
|
303
|
+
return c.json({ success: true, template });
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error('Save email template error:', error);
|
|
307
|
+
return c.json({
|
|
308
|
+
success: false,
|
|
309
|
+
message: error instanceof Error ? error.message : 'Failed to save template',
|
|
310
|
+
}, 500);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email templates via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { Context } from 'hono';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/templates
|
|
9
|
+
* Get all templates from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTemplates(c: Context): Promise<Response>;
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/email/admin/templates/:id
|
|
14
|
+
* Get a single template from Plunk
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTemplate(c: Context): Promise<Response>;
|
|
17
|
+
/**
|
|
18
|
+
* POST /api/email/admin/templates
|
|
19
|
+
* Create a new template in Plunk
|
|
20
|
+
*/
|
|
21
|
+
export declare function createTemplate(c: Context): Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* PATCH /api/email/admin/templates/:id
|
|
24
|
+
* Update an existing template in Plunk
|
|
25
|
+
*/
|
|
26
|
+
export declare function updateTemplate(c: Context): Promise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* DELETE /api/email/admin/templates/:id
|
|
29
|
+
* Delete a template from Plunk
|
|
30
|
+
*/
|
|
31
|
+
export declare function deleteTemplate(c: Context): Promise<Response>;
|
|
32
|
+
//# sourceMappingURL=templates.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/templates.handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgBhE;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsB/D;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwClE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqClE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsBlE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email templates via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { createPlunkClient } from '../../../lib/plunk';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/templates
|
|
9
|
+
* Get all templates from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export async function getTemplates(c) {
|
|
12
|
+
try {
|
|
13
|
+
const plunk = createPlunkClient(c.env);
|
|
14
|
+
const { templates } = await plunk.getTemplates();
|
|
15
|
+
return c.json({ templates });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error('Get templates error:', error);
|
|
19
|
+
return c.json({
|
|
20
|
+
success: false,
|
|
21
|
+
message: error instanceof Error ? error.message : 'Failed to fetch templates',
|
|
22
|
+
}, 500);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GET /api/email/admin/templates/:id
|
|
27
|
+
* Get a single template from Plunk
|
|
28
|
+
*/
|
|
29
|
+
export async function getTemplate(c) {
|
|
30
|
+
try {
|
|
31
|
+
const id = c.req.param('id');
|
|
32
|
+
if (!id) {
|
|
33
|
+
return c.json({ success: false, message: 'Template ID is required' }, 400);
|
|
34
|
+
}
|
|
35
|
+
const plunk = createPlunkClient(c.env);
|
|
36
|
+
const template = await plunk.getTemplate(id);
|
|
37
|
+
return c.json({ template });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Get template error:', error);
|
|
41
|
+
return c.json({
|
|
42
|
+
success: false,
|
|
43
|
+
message: error instanceof Error ? error.message : 'Failed to fetch template',
|
|
44
|
+
}, 500);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* POST /api/email/admin/templates
|
|
49
|
+
* Create a new template in Plunk
|
|
50
|
+
*/
|
|
51
|
+
export async function createTemplate(c) {
|
|
52
|
+
try {
|
|
53
|
+
const body = await c.req.json();
|
|
54
|
+
if (!body.name || !body.subject || !body.body) {
|
|
55
|
+
return c.json({ success: false, message: 'Name, subject, and body are required' }, 400);
|
|
56
|
+
}
|
|
57
|
+
const plunk = createPlunkClient(c.env);
|
|
58
|
+
const result = await plunk.createTemplate({
|
|
59
|
+
name: body.name,
|
|
60
|
+
subject: body.subject,
|
|
61
|
+
body: body.body,
|
|
62
|
+
type: body.type || 'TRANSACTIONAL',
|
|
63
|
+
});
|
|
64
|
+
return c.json({
|
|
65
|
+
success: true,
|
|
66
|
+
template: {
|
|
67
|
+
id: result.id,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('Create template error:', error);
|
|
73
|
+
return c.json({
|
|
74
|
+
success: false,
|
|
75
|
+
message: error instanceof Error ? error.message : 'Failed to create template',
|
|
76
|
+
}, 500);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* PATCH /api/email/admin/templates/:id
|
|
81
|
+
* Update an existing template in Plunk
|
|
82
|
+
*/
|
|
83
|
+
export async function updateTemplate(c) {
|
|
84
|
+
try {
|
|
85
|
+
const id = c.req.param('id');
|
|
86
|
+
if (!id) {
|
|
87
|
+
return c.json({ success: false, message: 'Template ID is required' }, 400);
|
|
88
|
+
}
|
|
89
|
+
const body = await c.req.json();
|
|
90
|
+
const plunk = createPlunkClient(c.env);
|
|
91
|
+
const result = await plunk.updateTemplate(id, {
|
|
92
|
+
name: body.name,
|
|
93
|
+
subject: body.subject,
|
|
94
|
+
body: body.body,
|
|
95
|
+
});
|
|
96
|
+
return c.json({
|
|
97
|
+
success: true,
|
|
98
|
+
template: {
|
|
99
|
+
id: result.id,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error('Update template error:', error);
|
|
105
|
+
return c.json({
|
|
106
|
+
success: false,
|
|
107
|
+
message: error instanceof Error ? error.message : 'Failed to update template',
|
|
108
|
+
}, 500);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* DELETE /api/email/admin/templates/:id
|
|
113
|
+
* Delete a template from Plunk
|
|
114
|
+
*/
|
|
115
|
+
export async function deleteTemplate(c) {
|
|
116
|
+
try {
|
|
117
|
+
const id = c.req.param('id');
|
|
118
|
+
if (!id) {
|
|
119
|
+
return c.json({ success: false, message: 'Template ID is required' }, 400);
|
|
120
|
+
}
|
|
121
|
+
const plunk = createPlunkClient(c.env);
|
|
122
|
+
await plunk.deleteTemplate(id);
|
|
123
|
+
return c.json({ success: true });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.error('Delete template error:', error);
|
|
127
|
+
return c.json({
|
|
128
|
+
success: false,
|
|
129
|
+
message: error instanceof Error ? error.message : 'Failed to delete template',
|
|
130
|
+
}, 500);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/email/webhook
|
|
5
|
+
* Handle Stripe webhook events
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleStripeWebhook(c: Context<{
|
|
8
|
+
Bindings: Bindings;
|
|
9
|
+
}>): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=webhook.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/webhook.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAkC/C;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsC/F"}
|