@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,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branding Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages global email branding stored in GitHub.
|
|
5
|
+
*/
|
|
6
|
+
import { getGitHubConfig } from '../../../lib/config';
|
|
7
|
+
import { createGitHubClient } from '../../../lib/github';
|
|
8
|
+
// Default branding configuration
|
|
9
|
+
function getDefaultBranding() {
|
|
10
|
+
return {
|
|
11
|
+
primaryColor: '#3498db',
|
|
12
|
+
companyName: 'Company Name',
|
|
13
|
+
footerText: 'You are receiving this email because you subscribed to our newsletter.',
|
|
14
|
+
backgroundColor: '#f6f6f6',
|
|
15
|
+
contentBackgroundColor: '#ffffff',
|
|
16
|
+
maxWidth: '580px',
|
|
17
|
+
borderRadius: '3px',
|
|
18
|
+
logoAlign: 'center',
|
|
19
|
+
logoSize: '120px',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Default branding record
|
|
23
|
+
function getDefaultBrandingRecord() {
|
|
24
|
+
return {
|
|
25
|
+
id: 'global',
|
|
26
|
+
config: getDefaultBranding(),
|
|
27
|
+
logo: undefined,
|
|
28
|
+
createdAt: Date.now(),
|
|
29
|
+
updatedAt: Date.now(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the settings file path
|
|
34
|
+
*/
|
|
35
|
+
function getSettingsPath() {
|
|
36
|
+
return `emails/settings.json`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* GET /api/email/admin/branding
|
|
40
|
+
* Get the global branding configuration from GitHub
|
|
41
|
+
*/
|
|
42
|
+
export async function getBranding(c) {
|
|
43
|
+
try {
|
|
44
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
45
|
+
const github = createGitHubClient(gitConfig);
|
|
46
|
+
const settingsPath = getSettingsPath();
|
|
47
|
+
// Try to read settings from GitHub
|
|
48
|
+
const result = await github.readJsonFile(settingsPath);
|
|
49
|
+
if (!result || !result.data.branding) {
|
|
50
|
+
// Return default branding if file doesn't exist
|
|
51
|
+
return c.json({ branding: getDefaultBrandingRecord() });
|
|
52
|
+
}
|
|
53
|
+
return c.json({ branding: result.data.branding });
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Get branding error:', error);
|
|
57
|
+
return c.json({ branding: getDefaultBrandingRecord() });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* PUT /api/email/admin/branding
|
|
62
|
+
* Save/update the global branding configuration to GitHub
|
|
63
|
+
*/
|
|
64
|
+
export async function saveBranding(c) {
|
|
65
|
+
try {
|
|
66
|
+
const body = await c.req.json();
|
|
67
|
+
if (!body.config) {
|
|
68
|
+
return c.json({ success: false, message: 'Config is required' }, 400);
|
|
69
|
+
}
|
|
70
|
+
// Validate required fields
|
|
71
|
+
if (!body.config.primaryColor || !body.config.companyName) {
|
|
72
|
+
return c.json({ success: false, message: 'primaryColor and companyName are required' }, 400);
|
|
73
|
+
}
|
|
74
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
75
|
+
const github = createGitHubClient(gitConfig);
|
|
76
|
+
const settingsPath = getSettingsPath();
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
// Read existing settings
|
|
79
|
+
const existing = await github.readJsonFile(settingsPath);
|
|
80
|
+
// Check for conflicts if commitSha provided
|
|
81
|
+
if (body.commitSha) {
|
|
82
|
+
const currentSha = await github.getCommitSha();
|
|
83
|
+
if (body.commitSha !== currentSha) {
|
|
84
|
+
// Fetch current branding for conflict resolution
|
|
85
|
+
const currentSettings = await github.readJsonFile(settingsPath);
|
|
86
|
+
return c.json({
|
|
87
|
+
conflict: true,
|
|
88
|
+
currentCommitSha: currentSha,
|
|
89
|
+
serverBranding: currentSettings?.data.branding || getDefaultBrandingRecord(),
|
|
90
|
+
message: 'Settings have been modified. Please resolve conflicts.',
|
|
91
|
+
}, 409);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Build updated branding record
|
|
95
|
+
const branding = {
|
|
96
|
+
id: 'global',
|
|
97
|
+
config: body.config,
|
|
98
|
+
logo: body.logo ?? existing?.data.branding?.logo ?? undefined,
|
|
99
|
+
createdAt: existing?.data.branding?.createdAt || now,
|
|
100
|
+
updatedAt: now,
|
|
101
|
+
};
|
|
102
|
+
// Merge with existing settings (preserve invoice config)
|
|
103
|
+
const settings = {
|
|
104
|
+
branding,
|
|
105
|
+
invoice: existing?.data.invoice,
|
|
106
|
+
};
|
|
107
|
+
// Write to GitHub
|
|
108
|
+
await github.writeJsonFile(settingsPath, settings, 'Update email branding [skip ci]');
|
|
109
|
+
// Get new commit SHA
|
|
110
|
+
const newCommitSha = await github.getCommitSha();
|
|
111
|
+
return c.json({ success: true, branding, commitSha: newCommitSha });
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('Save branding error:', error);
|
|
115
|
+
return c.json({
|
|
116
|
+
success: false,
|
|
117
|
+
message: error instanceof Error ? error.message : 'Failed to save branding',
|
|
118
|
+
}, 500);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campaigns Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email campaigns via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { Context } from 'hono';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/campaigns
|
|
9
|
+
* Get all campaigns from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCampaigns(c: Context): Promise<Response>;
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/email/admin/campaigns/:id
|
|
14
|
+
* Get a single campaign from Plunk
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCampaign(c: Context): Promise<Response>;
|
|
17
|
+
/**
|
|
18
|
+
* POST /api/email/admin/campaigns
|
|
19
|
+
* Create a new campaign in Plunk
|
|
20
|
+
*/
|
|
21
|
+
export declare function createCampaign(c: Context): Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* POST /api/email/admin/campaigns/:id/send
|
|
24
|
+
* Send a campaign to all subscribed contacts
|
|
25
|
+
*/
|
|
26
|
+
export declare function sendCampaign(c: Context): Promise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* POST /api/email/admin/campaigns/:id/test
|
|
29
|
+
* Send a test email for a campaign
|
|
30
|
+
*/
|
|
31
|
+
export declare function testCampaign(c: Context): Promise<Response>;
|
|
32
|
+
//# sourceMappingURL=campaigns.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaigns.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/campaigns.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,CA0ClE;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0BhE;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqChE"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campaigns Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email campaigns via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { createPlunkClient } from '../../../lib/plunk';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/campaigns
|
|
9
|
+
* Get all campaigns from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export async function getCampaigns(c) {
|
|
12
|
+
try {
|
|
13
|
+
const plunk = createPlunkClient(c.env);
|
|
14
|
+
const { campaigns } = await plunk.getCampaigns();
|
|
15
|
+
return c.json({ campaigns });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error('Get campaigns error:', error);
|
|
19
|
+
return c.json({
|
|
20
|
+
success: false,
|
|
21
|
+
message: error instanceof Error ? error.message : 'Failed to fetch campaigns',
|
|
22
|
+
}, 500);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GET /api/email/admin/campaigns/:id
|
|
27
|
+
* Get a single campaign from Plunk
|
|
28
|
+
*/
|
|
29
|
+
export async function getCampaign(c) {
|
|
30
|
+
try {
|
|
31
|
+
const id = c.req.param('id');
|
|
32
|
+
if (!id) {
|
|
33
|
+
return c.json({ success: false, message: 'Campaign ID is required' }, 400);
|
|
34
|
+
}
|
|
35
|
+
const plunk = createPlunkClient(c.env);
|
|
36
|
+
const campaign = await plunk.getCampaign(id);
|
|
37
|
+
return c.json({ campaign });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Get campaign error:', error);
|
|
41
|
+
return c.json({
|
|
42
|
+
success: false,
|
|
43
|
+
message: error instanceof Error ? error.message : 'Failed to fetch campaign',
|
|
44
|
+
}, 500);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* POST /api/email/admin/campaigns
|
|
49
|
+
* Create a new campaign in Plunk
|
|
50
|
+
*/
|
|
51
|
+
export async function createCampaign(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.createCampaign({
|
|
59
|
+
name: body.name,
|
|
60
|
+
subject: body.subject,
|
|
61
|
+
body: body.body,
|
|
62
|
+
from: body.from,
|
|
63
|
+
style: body.style,
|
|
64
|
+
});
|
|
65
|
+
return c.json({
|
|
66
|
+
success: true,
|
|
67
|
+
campaign: {
|
|
68
|
+
id: result.id,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Create campaign error:', error);
|
|
74
|
+
return c.json({
|
|
75
|
+
success: false,
|
|
76
|
+
message: error instanceof Error ? error.message : 'Failed to create campaign',
|
|
77
|
+
}, 500);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* POST /api/email/admin/campaigns/:id/send
|
|
82
|
+
* Send a campaign to all subscribed contacts
|
|
83
|
+
*/
|
|
84
|
+
export async function sendCampaign(c) {
|
|
85
|
+
try {
|
|
86
|
+
const id = c.req.param('id');
|
|
87
|
+
if (!id) {
|
|
88
|
+
return c.json({ success: false, message: 'Campaign ID is required' }, 400);
|
|
89
|
+
}
|
|
90
|
+
const plunk = createPlunkClient(c.env);
|
|
91
|
+
const result = await plunk.sendCampaign(id);
|
|
92
|
+
return c.json({
|
|
93
|
+
success: true,
|
|
94
|
+
timestamp: result.timestamp,
|
|
95
|
+
emails: result.emails?.length || 0,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error('Send campaign error:', error);
|
|
100
|
+
return c.json({
|
|
101
|
+
success: false,
|
|
102
|
+
message: error instanceof Error ? error.message : 'Failed to send campaign',
|
|
103
|
+
}, 500);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* POST /api/email/admin/campaigns/:id/test
|
|
108
|
+
* Send a test email for a campaign
|
|
109
|
+
*/
|
|
110
|
+
export async function testCampaign(c) {
|
|
111
|
+
try {
|
|
112
|
+
const id = c.req.param('id');
|
|
113
|
+
if (!id) {
|
|
114
|
+
return c.json({ success: false, message: 'Campaign ID is required' }, 400);
|
|
115
|
+
}
|
|
116
|
+
const body = await c.req.json();
|
|
117
|
+
if (!body.email) {
|
|
118
|
+
return c.json({ success: false, message: 'Test email is required' }, 400);
|
|
119
|
+
}
|
|
120
|
+
// Validate email format
|
|
121
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
122
|
+
if (!emailRegex.test(body.email)) {
|
|
123
|
+
return c.json({ success: false, message: 'Invalid email format' }, 400);
|
|
124
|
+
}
|
|
125
|
+
const plunk = createPlunkClient(c.env);
|
|
126
|
+
await plunk.testCampaign(id, body.email);
|
|
127
|
+
return c.json({
|
|
128
|
+
success: true,
|
|
129
|
+
message: `Test email sent to ${body.email}`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Test campaign error:', error);
|
|
134
|
+
return c.json({
|
|
135
|
+
success: false,
|
|
136
|
+
message: error instanceof Error ? error.message : 'Failed to send test email',
|
|
137
|
+
}, 500);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email contacts via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { Context } from 'hono';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/contacts
|
|
9
|
+
* Get all contacts from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export declare function getContacts(c: Context): Promise<Response>;
|
|
12
|
+
/**
|
|
13
|
+
* POST /api/email/admin/contacts
|
|
14
|
+
* Create a new contact in Plunk
|
|
15
|
+
*/
|
|
16
|
+
export declare function createContact(c: Context): Promise<Response>;
|
|
17
|
+
/**
|
|
18
|
+
* PATCH /api/email/admin/contacts/:id
|
|
19
|
+
* Update an existing contact in Plunk
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateContact(c: Context): Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* DELETE /api/email/admin/contacts/:id
|
|
24
|
+
* Delete a contact from Plunk
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteContact(c: Context): Promise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* POST /api/email/admin/contacts/:id/subscribe
|
|
29
|
+
* Subscribe a contact
|
|
30
|
+
*/
|
|
31
|
+
export declare function subscribeContact(c: Context): Promise<Response>;
|
|
32
|
+
/**
|
|
33
|
+
* POST /api/email/admin/contacts/:id/unsubscribe
|
|
34
|
+
* Unsubscribe a contact
|
|
35
|
+
*/
|
|
36
|
+
export declare function unsubscribeContact(c: Context): Promise<Response>;
|
|
37
|
+
//# sourceMappingURL=contacts.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contacts.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/contacts.handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgB/D;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2CjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqCjE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsBjE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsBpE;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsBtE"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contacts Handler
|
|
3
|
+
*
|
|
4
|
+
* Manages email contacts via Plunk API.
|
|
5
|
+
*/
|
|
6
|
+
import { createPlunkClient } from '../../../lib/plunk';
|
|
7
|
+
/**
|
|
8
|
+
* GET /api/email/admin/contacts
|
|
9
|
+
* Get all contacts from Plunk
|
|
10
|
+
*/
|
|
11
|
+
export async function getContacts(c) {
|
|
12
|
+
try {
|
|
13
|
+
const plunk = createPlunkClient(c.env);
|
|
14
|
+
const { contacts, count } = await plunk.getContacts();
|
|
15
|
+
return c.json({ contacts, count });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error('Get contacts error:', error);
|
|
19
|
+
return c.json({
|
|
20
|
+
success: false,
|
|
21
|
+
message: error instanceof Error ? error.message : 'Failed to fetch contacts',
|
|
22
|
+
}, 500);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* POST /api/email/admin/contacts
|
|
27
|
+
* Create a new contact in Plunk
|
|
28
|
+
*/
|
|
29
|
+
export async function createContact(c) {
|
|
30
|
+
try {
|
|
31
|
+
const body = await c.req.json();
|
|
32
|
+
if (!body.email) {
|
|
33
|
+
return c.json({ success: false, message: 'Email is required' }, 400);
|
|
34
|
+
}
|
|
35
|
+
// Validate email format
|
|
36
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
37
|
+
if (!emailRegex.test(body.email)) {
|
|
38
|
+
return c.json({ success: false, message: 'Invalid email format' }, 400);
|
|
39
|
+
}
|
|
40
|
+
const plunk = createPlunkClient(c.env);
|
|
41
|
+
const result = await plunk.createContact({
|
|
42
|
+
email: body.email.toLowerCase().trim(),
|
|
43
|
+
subscribed: body.subscribed ?? true, // Default to subscribed for admin-created contacts
|
|
44
|
+
data: body.data,
|
|
45
|
+
});
|
|
46
|
+
return c.json({
|
|
47
|
+
success: true,
|
|
48
|
+
contact: {
|
|
49
|
+
id: result.id,
|
|
50
|
+
email: result.email,
|
|
51
|
+
subscribed: result.subscribed,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Create contact error:', error);
|
|
57
|
+
return c.json({
|
|
58
|
+
success: false,
|
|
59
|
+
message: error instanceof Error ? error.message : 'Failed to create contact',
|
|
60
|
+
}, 500);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* PATCH /api/email/admin/contacts/:id
|
|
65
|
+
* Update an existing contact in Plunk
|
|
66
|
+
*/
|
|
67
|
+
export async function updateContact(c) {
|
|
68
|
+
try {
|
|
69
|
+
const id = c.req.param('id');
|
|
70
|
+
if (!id) {
|
|
71
|
+
return c.json({ success: false, message: 'Contact ID is required' }, 400);
|
|
72
|
+
}
|
|
73
|
+
const body = await c.req.json();
|
|
74
|
+
const plunk = createPlunkClient(c.env);
|
|
75
|
+
const result = await plunk.updateContact(id, {
|
|
76
|
+
subscribed: body.subscribed,
|
|
77
|
+
data: body.data,
|
|
78
|
+
});
|
|
79
|
+
return c.json({
|
|
80
|
+
success: true,
|
|
81
|
+
contact: {
|
|
82
|
+
id: result.id,
|
|
83
|
+
email: result.email,
|
|
84
|
+
subscribed: result.subscribed,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error('Update contact error:', error);
|
|
90
|
+
return c.json({
|
|
91
|
+
success: false,
|
|
92
|
+
message: error instanceof Error ? error.message : 'Failed to update contact',
|
|
93
|
+
}, 500);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* DELETE /api/email/admin/contacts/:id
|
|
98
|
+
* Delete a contact from Plunk
|
|
99
|
+
*/
|
|
100
|
+
export async function deleteContact(c) {
|
|
101
|
+
try {
|
|
102
|
+
const id = c.req.param('id');
|
|
103
|
+
if (!id) {
|
|
104
|
+
return c.json({ success: false, message: 'Contact ID is required' }, 400);
|
|
105
|
+
}
|
|
106
|
+
const plunk = createPlunkClient(c.env);
|
|
107
|
+
await plunk.deleteContact(id);
|
|
108
|
+
return c.json({ success: true });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('Delete contact error:', error);
|
|
112
|
+
return c.json({
|
|
113
|
+
success: false,
|
|
114
|
+
message: error instanceof Error ? error.message : 'Failed to delete contact',
|
|
115
|
+
}, 500);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* POST /api/email/admin/contacts/:id/subscribe
|
|
120
|
+
* Subscribe a contact
|
|
121
|
+
*/
|
|
122
|
+
export async function subscribeContact(c) {
|
|
123
|
+
try {
|
|
124
|
+
const id = c.req.param('id');
|
|
125
|
+
if (!id) {
|
|
126
|
+
return c.json({ success: false, message: 'Contact ID is required' }, 400);
|
|
127
|
+
}
|
|
128
|
+
const plunk = createPlunkClient(c.env);
|
|
129
|
+
await plunk.subscribeContact(id);
|
|
130
|
+
return c.json({ success: true });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Subscribe contact error:', error);
|
|
134
|
+
return c.json({
|
|
135
|
+
success: false,
|
|
136
|
+
message: error instanceof Error ? error.message : 'Failed to subscribe contact',
|
|
137
|
+
}, 500);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* POST /api/email/admin/contacts/:id/unsubscribe
|
|
142
|
+
* Unsubscribe a contact
|
|
143
|
+
*/
|
|
144
|
+
export async function unsubscribeContact(c) {
|
|
145
|
+
try {
|
|
146
|
+
const id = c.req.param('id');
|
|
147
|
+
if (!id) {
|
|
148
|
+
return c.json({ success: false, message: 'Contact ID is required' }, 400);
|
|
149
|
+
}
|
|
150
|
+
const plunk = createPlunkClient(c.env);
|
|
151
|
+
await plunk.unsubscribeContact(id);
|
|
152
|
+
return c.json({ success: true });
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error('Unsubscribe contact error:', error);
|
|
156
|
+
return c.json({
|
|
157
|
+
success: false,
|
|
158
|
+
message: error instanceof Error ? error.message : 'Failed to unsubscribe contact',
|
|
159
|
+
}, 500);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 type { Context } from 'hono';
|
|
8
|
+
import type { InvoiceTemplate, InvoiceData } from '@hintergrund/shared';
|
|
9
|
+
/**
|
|
10
|
+
* GET /api/email/admin/invoice-template
|
|
11
|
+
* Fetch the invoice template configuration from GitHub
|
|
12
|
+
*/
|
|
13
|
+
export declare function getInvoiceTemplate(c: Context): Promise<Response>;
|
|
14
|
+
/**
|
|
15
|
+
* PUT /api/email/admin/invoice-template
|
|
16
|
+
* Save the invoice template configuration to GitHub
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveInvoiceTemplate(c: Context): Promise<Response>;
|
|
19
|
+
/**
|
|
20
|
+
* Generate PDF invoice
|
|
21
|
+
* @param template Invoice template configuration
|
|
22
|
+
* @param data Invoice data
|
|
23
|
+
* @param branding Optional global branding for logo and company name
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateInvoicePdf(template: InvoiceTemplate, data: InvoiceData, branding?: {
|
|
26
|
+
logo?: string;
|
|
27
|
+
companyName?: string;
|
|
28
|
+
primaryColor?: string;
|
|
29
|
+
}): Promise<Uint8Array>;
|
|
30
|
+
//# sourceMappingURL=invoice.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/invoice.handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAiB,eAAe,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AA0CvG;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBtE;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2DvE;AAwBD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,WAAW,EACjB,QAAQ,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACvE,OAAO,CAAC,UAAU,CAAC,CA0WrB"}
|