@hintergrund/worker 0.1.6 → 0.1.7

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.
Files changed (186) hide show
  1. package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
  2. package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
  3. package/dist/api/cms/handlers/admin-users.handler.js +121 -0
  4. package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
  5. package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
  6. package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
  7. package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
  8. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/auth.handler.js +74 -153
  10. package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  12. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  13. package/dist/api/cms/routes/index.d.ts.map +1 -1
  14. package/dist/api/cms/routes/index.js +16 -4
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  17. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  18. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  19. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  20. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  21. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  22. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  23. package/dist/api/emails/handlers/public.handler.js +150 -312
  24. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  25. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  26. package/dist/api/emails/handlers/send.handler.js +107 -92
  27. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  28. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  29. package/dist/api/emails/handlers/settings.handler.js +96 -287
  30. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  32. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  33. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  34. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  35. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  36. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  37. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  38. package/dist/api/emails/routes/admin.routes.js +19 -49
  39. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  40. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  41. package/dist/api/emails/routes/public.routes.js +2 -9
  42. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  43. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  44. package/dist/api/shop/handlers/prices.handler.js +2 -83
  45. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  46. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  47. package/dist/api/shop/handlers/products.handler.js +195 -162
  48. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  49. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  50. package/dist/api/shop/handlers/public.handler.js +525 -78
  51. package/dist/api/shop/routes.d.ts.map +1 -1
  52. package/dist/api/shop/routes.js +14 -9
  53. package/dist/hintergrund-assets.d.ts +3 -2
  54. package/dist/hintergrund-assets.d.ts.map +1 -1
  55. package/dist/hintergrund-assets.js +4 -2
  56. package/dist/index.d.ts +14 -7
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +44 -4
  59. package/dist/lib/auth/crypto.d.ts +2 -15
  60. package/dist/lib/auth/crypto.d.ts.map +1 -1
  61. package/dist/lib/auth/crypto.js +8 -95
  62. package/dist/lib/auth/jwt.d.ts +0 -4
  63. package/dist/lib/auth/jwt.d.ts.map +1 -1
  64. package/dist/lib/auth/jwt.js +0 -6
  65. package/dist/lib/config.d.ts +1 -1
  66. package/dist/lib/config.d.ts.map +1 -1
  67. package/dist/lib/config.js +42 -86
  68. package/dist/lib/email-template.d.ts +15 -0
  69. package/dist/lib/email-template.d.ts.map +1 -0
  70. package/dist/lib/email-template.js +58 -0
  71. package/dist/lib/email.d.ts +18 -8
  72. package/dist/lib/email.d.ts.map +1 -1
  73. package/dist/lib/email.js +59 -70
  74. package/dist/lib/github-config.d.ts +19 -0
  75. package/dist/lib/github-config.d.ts.map +1 -0
  76. package/dist/lib/github-config.js +23 -0
  77. package/dist/lib/github.d.ts +10 -0
  78. package/dist/lib/github.d.ts.map +1 -1
  79. package/dist/lib/github.js +20 -2
  80. package/dist/lib/project-db.d.ts +24 -0
  81. package/dist/lib/project-db.d.ts.map +1 -0
  82. package/dist/lib/project-db.js +172 -0
  83. package/dist/lib/template.js +4 -4
  84. package/dist/middleware/auth.d.ts +0 -2
  85. package/dist/middleware/auth.d.ts.map +1 -1
  86. package/dist/middleware/auth.js +21 -50
  87. package/package.json +3 -2
  88. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  89. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  90. package/dist/api/builder/handlers/generate.handler.js +0 -203
  91. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  92. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  93. package/dist/api/builder/handlers/template.handler.js +0 -208
  94. package/dist/api/builder/routes.d.ts +0 -7
  95. package/dist/api/builder/routes.d.ts.map +0 -1
  96. package/dist/api/builder/routes.js +0 -15
  97. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  98. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  99. package/dist/api/cms/handlers/assets.handler.js +0 -200
  100. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  101. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  102. package/dist/api/cms/handlers/config.handler.js +0 -37
  103. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  104. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  105. package/dist/api/cms/handlers/content.handler.js +0 -117
  106. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  107. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  108. package/dist/api/cms/routes/assets.routes.js +0 -13
  109. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  110. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  111. package/dist/api/cms/routes/content.routes.js +0 -11
  112. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  113. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  114. package/dist/api/emails/handlers/branding.handler.js +0 -120
  115. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  116. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  117. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  118. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  119. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  120. package/dist/api/emails/handlers/templates.handler.js +0 -132
  121. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  122. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  123. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  124. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  125. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  126. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  127. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  128. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  129. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  130. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  131. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  132. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  133. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  134. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  135. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  136. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  137. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  138. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  139. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  140. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  141. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  142. package/dist/api/newsletter/routes/index.d.ts +0 -4
  143. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  144. package/dist/api/newsletter/routes/index.js +0 -9
  145. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  146. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  147. package/dist/api/newsletter/routes/public.routes.js +0 -9
  148. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  149. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  150. package/dist/api/shop/handlers/assets.handler.js +0 -62
  151. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  152. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  153. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  154. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  155. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  156. package/dist/api/shop/handlers/customers.handler.js +0 -89
  157. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  158. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  159. package/dist/api/shop/handlers/orders.handler.js +0 -84
  160. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  161. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  162. package/dist/api/shop/handlers/stats.handler.js +0 -71
  163. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  164. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  165. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  166. package/dist/cms-assets.d.ts +0 -4
  167. package/dist/cms-assets.d.ts.map +0 -1
  168. package/dist/cms-assets.js +0 -5
  169. package/dist/cms-bundle.d.ts +0 -3
  170. package/dist/cms-bundle.d.ts.map +0 -1
  171. package/dist/cms-bundle.js +0 -4
  172. package/dist/config-loader.d.ts +0 -26
  173. package/dist/config-loader.d.ts.map +0 -1
  174. package/dist/config-loader.js +0 -98
  175. package/dist/jwt.d.ts +0 -26
  176. package/dist/jwt.d.ts.map +0 -1
  177. package/dist/jwt.js +0 -102
  178. package/dist/lib/plunk.d.ts +0 -204
  179. package/dist/lib/plunk.d.ts.map +0 -1
  180. package/dist/lib/plunk.js +0 -259
  181. package/dist/template.d.ts +0 -2
  182. package/dist/template.d.ts.map +0 -1
  183. package/dist/template.js +0 -61
  184. package/dist/utils.d.ts +0 -23
  185. package/dist/utils.d.ts.map +0 -1
  186. package/dist/utils.js +0 -110
@@ -1,161 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,132 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * POST /api/newsletter/admin/send
4
- * Send bulk email to all subscribed users (admin only)
5
- */
6
- export declare function sendBulkEmail(c: Context): Promise<Response>;
7
- //# sourceMappingURL=email.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/handlers/email.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsC/B;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuFjE"}
@@ -1,102 +0,0 @@
1
- // Send email via Resend
2
- async function sendEmail(to, subject, html, apiKey, from, fromName, replyTo) {
3
- const response = await fetch('https://api.resend.com/emails', {
4
- method: 'POST',
5
- headers: {
6
- Authorization: `Bearer ${apiKey}`,
7
- 'Content-Type': 'application/json',
8
- },
9
- body: JSON.stringify({
10
- from: `${fromName} <${from}>`,
11
- to,
12
- subject,
13
- html,
14
- reply_to: replyTo,
15
- }),
16
- });
17
- if (!response.ok) {
18
- const error = await response.text();
19
- throw new Error(`Failed to send email to ${to}: ${error}`);
20
- }
21
- }
22
- // Generate email ID
23
- function generateId() {
24
- return Math.random().toString(36).substring(2, 14);
25
- }
26
- /**
27
- * POST /api/newsletter/admin/send
28
- * Send bulk email to all subscribed users (admin only)
29
- */
30
- export async function sendBulkEmail(c) {
31
- try {
32
- const body = (await c.req.json());
33
- const { subject, html } = body;
34
- if (!subject || !html) {
35
- return c.json({ success: false, message: 'Subject and HTML content are required' }, 400);
36
- }
37
- const db = c.env.DB;
38
- const apiKey = c.env.HG_NEWSLETTER_EMAIL_API_KEY;
39
- const fromEmail = c.env.HG_NEWSLETTER_FROM_EMAIL;
40
- const fromName = c.env.HG_NEWSLETTER_FROM_NAME;
41
- const replyTo = c.env.HG_NEWSLETTER_REPLY_TO;
42
- if (!db || !apiKey || !fromEmail) {
43
- return c.json({ success: false, message: 'Newsletter not configured' }, 500);
44
- }
45
- // Fetch all subscribed users
46
- const result = await db.prepare('SELECT id, email, unsubscribe_token FROM subscribers WHERE status = \'subscribed\'').all();
47
- const subscribers = result.results;
48
- if (subscribers.length === 0) {
49
- return c.json({ success: true, sent: 0, message: 'No subscribed users found' });
50
- }
51
- // Send emails to all subscribers
52
- let sent = 0;
53
- const errors = [];
54
- for (const subscriber of subscribers) {
55
- try {
56
- // Append unsubscribe link to HTML
57
- const unsubscribeUrl = `${c.req.url.split('/api')[0]}/api/newsletter/unsubscribe?token=${subscriber.unsubscribe_token}`;
58
- const htmlWithUnsubscribe = `
59
- ${html}
60
- <hr style="margin-top: 2rem; margin-bottom: 1rem; border: none; border-top: 1px solid #eee;">
61
- <p style="font-size: 0.875rem; color: #666;">
62
- <a href="${unsubscribeUrl}" style="color: #666;">Unsubscribe from this newsletter</a>
63
- </p>
64
- `;
65
- await sendEmail(subscriber.email, subject, htmlWithUnsubscribe, apiKey, fromEmail, fromName || 'Newsletter', replyTo);
66
- sent++;
67
- }
68
- catch (error) {
69
- console.error(`Failed to send email to ${subscriber.email}:`, error);
70
- errors.push(subscriber.email);
71
- }
72
- }
73
- // Save sent email to database
74
- const emailId = generateId();
75
- const now = Date.now();
76
- await db
77
- .prepare(`INSERT INTO emails
78
- (id, subject, html_content, status, recipient_count, sent_at, created_at, updated_at)
79
- VALUES (?, ?, ?, 'sent', ?, ?, ?, ?)`)
80
- .bind(emailId, subject, html, sent, now, now, now)
81
- .run();
82
- if (errors.length > 0) {
83
- return c.json({
84
- success: true,
85
- sent,
86
- message: `Sent to ${sent} subscribers. Failed to send to: ${errors.join(', ')}`,
87
- });
88
- }
89
- return c.json({
90
- success: true,
91
- sent,
92
- message: `Successfully sent email to ${sent} subscriber${sent === 1 ? '' : 's'}`,
93
- });
94
- }
95
- catch (error) {
96
- console.error('Send bulk email error:', error);
97
- return c.json({
98
- success: false,
99
- message: error instanceof Error ? error.message : 'Failed to send emails',
100
- }, 500);
101
- }
102
- }
@@ -1,31 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * GET /api/email/admin/emails
4
- * Get all emails (sent emails and drafts)
5
- */
6
- export declare function getEmails(c: Context): Promise<Response>;
7
- /**
8
- * POST /api/email/admin/emails/draft
9
- * Save email as draft
10
- */
11
- export declare function saveDraft(c: Context): Promise<Response>;
12
- /**
13
- * DELETE /api/email/admin/emails/:id
14
- * Delete email (draft or sent)
15
- */
16
- export declare function deleteEmail(c: Context): Promise<Response>;
17
- /**
18
- * Save sent email record to database
19
- */
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>;
31
- //# sourceMappingURL=emails.handler.d.ts.map
@@ -1 +0,0 @@
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"}