@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,195 +0,0 @@
1
- // Email validation
2
- function isValidEmail(email) {
3
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4
- return emailRegex.test(email);
5
- }
6
- // Generate subscriber ID
7
- function generateId() {
8
- return Math.random().toString(36).substring(2, 14);
9
- }
10
- // Generate unsubscribe token
11
- function generateToken() {
12
- const array = new Uint8Array(32);
13
- crypto.getRandomValues(array);
14
- return Array.from(array, (b) => b.toString(16).padStart(2, '0')).join('');
15
- }
16
- // Parse D1 row to Subscriber
17
- function parseSubscriber(row) {
18
- return {
19
- id: row.id,
20
- email: row.email,
21
- name: row.name || undefined,
22
- status: row.status,
23
- source: row.source,
24
- confirmationToken: row.confirmation_token || undefined,
25
- confirmationSentAt: row.confirmation_sent_at || undefined,
26
- confirmedAt: row.confirmed_at || undefined,
27
- subscribedAt: row.subscribed_at || undefined,
28
- unsubscribedAt: row.unsubscribed_at || undefined,
29
- unsubscribeToken: row.unsubscribe_token || undefined,
30
- createdAt: row.created_at,
31
- updatedAt: row.updated_at,
32
- };
33
- }
34
- /**
35
- * GET /api/email/admin/subscribers
36
- * Get all subscribers (admin only)
37
- */
38
- export async function getSubscribers(c) {
39
- try {
40
- const db = c.env.DB;
41
- const result = await db.prepare('SELECT * FROM subscribers ORDER BY created_at DESC').all();
42
- const subscribers = result.results.map((row) => parseSubscriber(row));
43
- return c.json({ subscribers });
44
- }
45
- catch (error) {
46
- console.error('Get subscribers error:', error);
47
- return c.json({
48
- success: false,
49
- message: error instanceof Error ? error.message : 'Failed to fetch subscribers',
50
- }, 500);
51
- }
52
- }
53
- /**
54
- * POST /api/email/admin/subscribers
55
- * Manually add subscriber (admin only, bypasses confirmation)
56
- */
57
- export async function addSubscriber(c) {
58
- try {
59
- const body = (await c.req.json());
60
- const { email, name } = body;
61
- // Validate email
62
- if (!email || !isValidEmail(email)) {
63
- return c.json({ success: false, message: 'Invalid email address' }, 400);
64
- }
65
- const normalizedEmail = email.toLowerCase().trim();
66
- const db = c.env.DB;
67
- // Check for duplicates or unsubscribed
68
- const existing = await db.prepare('SELECT id, status FROM subscribers WHERE email = ?').bind(normalizedEmail).first();
69
- if (existing) {
70
- // Block manual re-add of unsubscribed users
71
- if (existing.status === 'unsubscribed') {
72
- return c.json({
73
- success: false,
74
- message: 'This user has unsubscribed. They can only re-subscribe via the public subscription form.'
75
- }, 403);
76
- }
77
- return c.json({ success: false, message: 'Subscriber already exists' }, 409);
78
- }
79
- // Create new subscriber with 'subscribed' status (bypass confirmation)
80
- const id = generateId();
81
- const unsubscribeToken = generateToken();
82
- const now = Date.now();
83
- await db
84
- .prepare(`INSERT INTO subscribers
85
- (id, email, name, status, source, unsubscribe_token, subscribed_at, created_at, updated_at)
86
- VALUES (?, ?, ?, 'subscribed', 'manual', ?, ?, ?, ?)`)
87
- .bind(id, normalizedEmail, name || null, unsubscribeToken, now, now, now)
88
- .run();
89
- // Fetch the created subscriber
90
- const row = await db.prepare('SELECT * FROM subscribers WHERE id = ?').bind(id).first();
91
- if (!row) {
92
- return c.json({ success: false, message: 'Failed to create subscriber' }, 500);
93
- }
94
- const subscriber = parseSubscriber(row);
95
- return c.json({ success: true, subscriber });
96
- }
97
- catch (error) {
98
- console.error('Add subscriber error:', error);
99
- return c.json({
100
- success: false,
101
- message: error instanceof Error ? error.message : 'Failed to add subscriber',
102
- }, 500);
103
- }
104
- }
105
- /**
106
- * DELETE /api/email/admin/subscribers/:id
107
- * Delete subscriber by ID (admin only)
108
- */
109
- export async function deleteSubscriber(c) {
110
- try {
111
- const id = c.req.param('id');
112
- if (!id) {
113
- return c.json({ success: false, message: 'Missing subscriber ID' }, 400);
114
- }
115
- const db = c.env.DB;
116
- // Check if subscriber exists
117
- const existing = await db.prepare('SELECT id FROM subscribers WHERE id = ?').bind(id).first();
118
- if (!existing) {
119
- return c.json({ success: false, message: 'Subscriber not found' }, 404);
120
- }
121
- // Delete subscriber
122
- await db.prepare('DELETE FROM subscribers WHERE id = ?').bind(id).run();
123
- return c.json({ success: true });
124
- }
125
- catch (error) {
126
- console.error('Delete subscriber error:', error);
127
- return c.json({
128
- success: false,
129
- message: error instanceof Error ? error.message : 'Failed to delete subscriber',
130
- }, 500);
131
- }
132
- }
133
- /**
134
- * PATCH /api/email/admin/subscribers/:id
135
- * Update subscriber (admin only)
136
- */
137
- export async function updateSubscriber(c) {
138
- try {
139
- const id = c.req.param('id');
140
- if (!id) {
141
- return c.json({ success: false, message: 'Missing subscriber ID' }, 400);
142
- }
143
- const body = (await c.req.json());
144
- const db = c.env.DB;
145
- // Check if subscriber exists
146
- const existing = await db.prepare('SELECT id FROM subscribers WHERE id = ?').bind(id).first();
147
- if (!existing) {
148
- return c.json({ success: false, message: 'Subscriber not found' }, 404);
149
- }
150
- // Build update query dynamically
151
- const updates = [];
152
- const params = [];
153
- if (body.name !== undefined) {
154
- updates.push('name = ?');
155
- params.push(body.name || null);
156
- }
157
- if (body.status !== undefined) {
158
- updates.push('status = ?');
159
- params.push(body.status);
160
- // Update status timestamps
161
- if (body.status === 'subscribed') {
162
- updates.push('subscribed_at = ?');
163
- params.push(Date.now());
164
- }
165
- else if (body.status === 'unsubscribed') {
166
- updates.push('unsubscribed_at = ?');
167
- params.push(Date.now());
168
- }
169
- }
170
- // Always update updated_at
171
- updates.push('updated_at = ?');
172
- params.push(Date.now());
173
- if (updates.length === 0) {
174
- return c.json({ success: false, message: 'No fields to update' }, 400);
175
- }
176
- // Add ID to params
177
- params.push(id);
178
- const query = `UPDATE subscribers SET ${updates.join(', ')} WHERE id = ?`;
179
- await db.prepare(query).bind(...params).run();
180
- // Fetch updated subscriber
181
- const row = await db.prepare('SELECT * FROM subscribers WHERE id = ?').bind(id).first();
182
- if (!row) {
183
- return c.json({ success: false, message: 'Failed to update subscriber' }, 500);
184
- }
185
- const subscriber = parseSubscriber(row);
186
- return c.json({ success: true, subscriber });
187
- }
188
- catch (error) {
189
- console.error('Update subscriber error:', error);
190
- return c.json({
191
- success: false,
192
- message: error instanceof Error ? error.message : 'Failed to update subscriber',
193
- }, 500);
194
- }
195
- }
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- declare const adminRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
- export default adminRoutes;
4
- //# sourceMappingURL=admin.routes.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,28 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { authMiddleware } from '../../../middleware/auth';
3
- import { getSubscribers, addSubscriber, deleteSubscriber, updateSubscriber } from '../handlers/subscribers.handler';
4
- import { sendBulkEmail, sendTestEmail } from '../handlers/send.handler';
5
- import { getEmails, saveDraft, deleteEmail, getTemplate, saveTemplate } from '../handlers/emails.handler';
6
- import { getInvoiceTemplate, saveInvoiceTemplate } from '../handlers/invoice.handler';
7
- const adminRoutes = new Hono();
8
- // Protect all admin routes with authentication
9
- adminRoutes.use('*', authMiddleware);
10
- // Admin subscriber management endpoints
11
- adminRoutes.get('/subscribers', getSubscribers);
12
- adminRoutes.post('/subscribers', addSubscriber);
13
- adminRoutes.delete('/subscribers/:id', deleteSubscriber);
14
- adminRoutes.patch('/subscribers/:id', updateSubscriber);
15
- // Admin email sending endpoint
16
- adminRoutes.post('/send', sendBulkEmail);
17
- // Admin email history/drafts endpoints
18
- adminRoutes.get('/emails', getEmails);
19
- adminRoutes.post('/emails/draft', saveDraft);
20
- adminRoutes.post('/emails/test', sendTestEmail);
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);
28
- export default adminRoutes;
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- declare const newsletterRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
- export default newsletterRoutes;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,QAAA,MAAM,gBAAgB,4EAAa,CAAC;AAQpC,eAAe,gBAAgB,CAAC"}
@@ -1,9 +0,0 @@
1
- import { Hono } from 'hono';
2
- import publicRoutes from './public.routes';
3
- import adminRoutes from './admin.routes';
4
- const newsletterRoutes = new Hono();
5
- // Mount public routes (no /admin prefix)
6
- newsletterRoutes.route('/', publicRoutes);
7
- // Mount admin routes (with /admin prefix)
8
- newsletterRoutes.route('/admin', adminRoutes);
9
- export default newsletterRoutes;
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- declare const publicRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
- export default publicRoutes;
4
- //# sourceMappingURL=public.routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/newsletter/routes/public.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,QAAA,MAAM,YAAY,4EAAa,CAAC;AAQhC,eAAe,YAAY,CAAC"}
@@ -1,9 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { subscribe, confirm, unsubscribe, showUnsubscribePage } from '../handlers/public.handler';
3
- const publicRoutes = new Hono();
4
- // Public newsletter endpoints (no authentication required)
5
- publicRoutes.post('/subscribe', subscribe);
6
- publicRoutes.get('/confirm', confirm);
7
- publicRoutes.get('/unsubscribe', showUnsubscribePage);
8
- publicRoutes.post('/unsubscribe', unsubscribe);
9
- export default publicRoutes;
@@ -1,3 +0,0 @@
1
- import { Context } from 'hono';
2
- export declare function uploadShopAsset(c: Context): Promise<Response>;
3
- //# sourceMappingURL=assets.handler.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,62 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,50 +0,0 @@
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,17 +0,0 @@
1
- import type { Context } from 'hono';
2
- import type { Bindings } from '../../../index';
3
- /**
4
- * GET /api/shop/admin/customers
5
- * List all customers
6
- */
7
- export declare function getCustomers(c: Context<{
8
- Bindings: Bindings;
9
- }>): Promise<Response>;
10
- /**
11
- * GET /api/shop/admin/customers/:id
12
- * Get a single customer with their orders
13
- */
14
- export declare function getCustomer(c: Context<{
15
- Bindings: Bindings;
16
- }>): Promise<Response>;
17
- //# sourceMappingURL=customers.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"customers.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/customers.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA4B/C;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoBxF;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkDvF"}
@@ -1,89 +0,0 @@
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
- function mapStripeCustomer(customer) {
10
- return {
11
- id: customer.id,
12
- email: customer.email,
13
- name: customer.name || null,
14
- phone: customer.phone || null,
15
- description: customer.description,
16
- metadata: customer.metadata || {},
17
- createdAt: customer.created
18
- };
19
- }
20
- /**
21
- * GET /api/shop/admin/customers
22
- * List all customers
23
- */
24
- export async function getCustomers(c) {
25
- try {
26
- const stripe = getStripe(c.env);
27
- const limit = parseInt(c.req.query('limit') || '25');
28
- const customers = await stripe.customers.list({
29
- limit
30
- });
31
- const response = {
32
- customers: customers.data.map(mapStripeCustomer),
33
- hasMore: customers.has_more
34
- };
35
- return c.json(response);
36
- }
37
- catch (error) {
38
- console.error('Failed to fetch customers:', error);
39
- return c.json({ success: false, error: 'Failed to fetch customers' }, 500);
40
- }
41
- }
42
- /**
43
- * GET /api/shop/admin/customers/:id
44
- * Get a single customer with their orders
45
- */
46
- export async function getCustomer(c) {
47
- try {
48
- const stripe = getStripe(c.env);
49
- const customerId = c.req.param('id');
50
- const [customer, paymentIntents] = await Promise.all([
51
- stripe.customers.retrieve(customerId),
52
- stripe.paymentIntents.list({
53
- customer: customerId,
54
- limit: 100
55
- })
56
- ]);
57
- if (customer.deleted) {
58
- return c.json({ success: false, error: 'Customer not found' }, 404);
59
- }
60
- const mappedCustomer = mapStripeCustomer(customer);
61
- // Calculate totals
62
- mappedCustomer.totalOrders = paymentIntents.data.filter((pi) => pi.status === 'succeeded').length;
63
- mappedCustomer.totalSpent = paymentIntents.data
64
- .filter((pi) => pi.status === 'succeeded')
65
- .reduce((sum, pi) => sum + pi.amount_received, 0);
66
- const response = {
67
- customer: mappedCustomer,
68
- orders: paymentIntents.data.map((pi) => ({
69
- id: pi.id,
70
- customerId: customerId,
71
- customerEmail: customer.email || null,
72
- customerName: customer.name || null,
73
- amount: pi.amount,
74
- amountReceived: pi.amount_received,
75
- currency: pi.currency,
76
- status: pi.status,
77
- paymentMethod: typeof pi.payment_method === 'string' ? pi.payment_method : pi.payment_method?.id || null,
78
- lineItems: [],
79
- metadata: pi.metadata || {},
80
- createdAt: pi.created
81
- }))
82
- };
83
- return c.json(response);
84
- }
85
- catch (error) {
86
- console.error('Failed to fetch customer:', error);
87
- return c.json({ success: false, error: 'Failed to fetch customer' }, 500);
88
- }
89
- }
@@ -1,17 +0,0 @@
1
- import type { Context } from 'hono';
2
- import type { Bindings } from '../../../index';
3
- /**
4
- * GET /api/shop/admin/orders
5
- * List payment intents (orders)
6
- */
7
- export declare function getOrders(c: Context<{
8
- Bindings: Bindings;
9
- }>): Promise<Response>;
10
- /**
11
- * GET /api/shop/admin/orders/:id
12
- * Get a single order
13
- */
14
- export declare function getOrder(c: Context<{
15
- Bindings: Bindings;
16
- }>): Promise<Response>;
17
- //# sourceMappingURL=orders.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orders.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/orders.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAsC/C;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkCrF;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsBpF"}
@@ -1,84 +0,0 @@
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
- function mapPaymentIntentStatus(status) {
10
- return status;
11
- }
12
- function mapPaymentIntent(pi) {
13
- return {
14
- id: pi.id,
15
- customerId: typeof pi.customer === 'string' ? pi.customer : pi.customer?.id || null,
16
- customerEmail: pi.receipt_email || null,
17
- customerName: null,
18
- amount: pi.amount,
19
- amountReceived: pi.amount_received,
20
- currency: pi.currency,
21
- status: mapPaymentIntentStatus(pi.status),
22
- paymentMethod: typeof pi.payment_method === 'string' ? pi.payment_method : pi.payment_method?.id || null,
23
- lineItems: [],
24
- metadata: pi.metadata || {},
25
- createdAt: pi.created
26
- };
27
- }
28
- /**
29
- * GET /api/shop/admin/orders
30
- * List payment intents (orders)
31
- */
32
- export async function getOrders(c) {
33
- try {
34
- const stripe = getStripe(c.env);
35
- const limit = parseInt(c.req.query('limit') || '25');
36
- const paymentIntents = await stripe.paymentIntents.list({
37
- limit,
38
- expand: ['data.customer']
39
- });
40
- const orders = paymentIntents.data.map((pi) => {
41
- const order = mapPaymentIntent(pi);
42
- // Add customer info if expanded
43
- if (pi.customer && typeof pi.customer !== 'string' && !pi.customer.deleted) {
44
- const customer = pi.customer;
45
- order.customerEmail = customer.email || order.customerEmail;
46
- order.customerName = customer.name || null;
47
- }
48
- return order;
49
- });
50
- const response = {
51
- orders,
52
- hasMore: paymentIntents.has_more
53
- };
54
- return c.json(response);
55
- }
56
- catch (error) {
57
- console.error('Failed to fetch orders:', error);
58
- return c.json({ success: false, error: 'Failed to fetch orders' }, 500);
59
- }
60
- }
61
- /**
62
- * GET /api/shop/admin/orders/:id
63
- * Get a single order
64
- */
65
- export async function getOrder(c) {
66
- try {
67
- const stripe = getStripe(c.env);
68
- const orderId = c.req.param('id');
69
- const paymentIntent = await stripe.paymentIntents.retrieve(orderId, {
70
- expand: ['customer']
71
- });
72
- const order = mapPaymentIntent(paymentIntent);
73
- if (paymentIntent.customer && typeof paymentIntent.customer !== 'string' && !paymentIntent.customer.deleted) {
74
- const customer = paymentIntent.customer;
75
- order.customerEmail = customer.email || order.customerEmail;
76
- order.customerName = customer.name || null;
77
- }
78
- return c.json({ order });
79
- }
80
- catch (error) {
81
- console.error('Failed to fetch order:', error);
82
- return c.json({ success: false, error: 'Failed to fetch order' }, 500);
83
- }
84
- }
@@ -1,10 +0,0 @@
1
- import type { Context } from 'hono';
2
- import type { Bindings } from '../../../index';
3
- /**
4
- * GET /api/shop/admin/stats
5
- * Get shop statistics
6
- */
7
- export declare function getStats(c: Context<{
8
- Bindings: Bindings;
9
- }>): Promise<Response>;
10
- //# sourceMappingURL=stats.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stats.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/stats.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAY/C;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwEpF"}