@hintergrund/worker 0.1.5 → 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 +2 -1
  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,200 +0,0 @@
1
- import { getCmsConfig, getGitHubConfig } from '../../../lib/config';
2
- import { createGitHubClient } from '../../../lib/github';
3
- const mimeTypes = {
4
- '.jpg': 'image/jpeg',
5
- '.png': 'image/png',
6
- '.gif': 'image/gif',
7
- '.svg': 'image/svg+xml',
8
- '.ico': 'image/x-icon',
9
- '.webp': 'image/webp',
10
- '.mp4': 'video/mp4',
11
- '.webm': 'video/webm',
12
- '.ogg': 'video/ogg',
13
- '.ogv': 'video/ogg',
14
- '.mov': 'video/quicktime',
15
- '.avi': 'video/x-msvideo',
16
- '.mkv': 'video/x-matroska',
17
- '.mp3': 'audio/mpeg',
18
- '.wav': 'audio/wav',
19
- '.m4a': 'audio/mp4',
20
- '.aac': 'audio/aac',
21
- '.oga': 'audio/ogg'
22
- };
23
- function getMimeType(path) {
24
- const extension = path.slice(((path.lastIndexOf('.') - 1) >>> 0) + 2);
25
- return mimeTypes['.' + extension] || 'text/plain';
26
- }
27
- /**
28
- * GET /api/admin/assets
29
- * List all assets in the asset directory
30
- */
31
- export async function listAssets(c) {
32
- try {
33
- const config = getCmsConfig(c.env);
34
- const gitConfig = getGitHubConfig(c.env);
35
- const github = createGitHubClient(gitConfig);
36
- const octokit = github.getOctokit();
37
- const repoInfo = github.getRepoInfo();
38
- // List files in asset directory
39
- const response = await octokit.rest.repos.getContent({
40
- ...repoInfo,
41
- path: config.assetDir,
42
- ref: repoInfo.branch
43
- });
44
- if (!Array.isArray(response.data)) {
45
- return c.json({ error: 'Asset directory not found' }, 404);
46
- }
47
- const assets = response.data.map((item) => ({
48
- name: item.name,
49
- path: item.path,
50
- download_url: item.download_url
51
- }));
52
- return c.json(assets);
53
- }
54
- catch (error) {
55
- console.error('List assets error:', error);
56
- return c.json({ error: error.message || 'Failed to list assets' }, 500);
57
- }
58
- }
59
- /**
60
- * POST /api/admin/assets
61
- * Upload an asset to GitHub
62
- */
63
- export async function uploadAsset(c) {
64
- try {
65
- const config = getCmsConfig(c.env);
66
- const gitConfig = getGitHubConfig(c.env);
67
- const github = createGitHubClient(gitConfig);
68
- const { file, content } = await c.req.json();
69
- await github.writeFile(`${config.assetDir}/${file}`, content, // Note: content is already base64 from frontend
70
- `Upload asset ${file} [skip ci]`);
71
- const response = {
72
- success: true,
73
- message: `Uploaded ${file} to ${config.assetDir}`
74
- };
75
- return c.json(response);
76
- }
77
- catch (error) {
78
- console.error('Upload asset error:', error);
79
- return c.json({ error: error.message || 'Failed to upload asset' }, 500);
80
- }
81
- }
82
- /**
83
- * DELETE /api/admin/assets
84
- * Delete an asset from GitHub
85
- */
86
- export async function deleteAsset(c) {
87
- try {
88
- const { file } = await c.req.json();
89
- const config = getCmsConfig(c.env);
90
- const gitConfig = getGitHubConfig(c.env);
91
- const github = createGitHubClient(gitConfig);
92
- await github.deleteFile(`${config.assetDir}/${file}`, `Delete asset ${file} [skip ci]`);
93
- return c.json({ message: `Deleted asset ${file}` });
94
- }
95
- catch (error) {
96
- console.error('Delete asset error:', error);
97
- return c.json({ error: error.message || 'Failed to delete asset' }, 500);
98
- }
99
- }
100
- /**
101
- * GET /api/admin/assets/:path
102
- * Get asset content
103
- */
104
- export async function getAssetByPath(c) {
105
- try {
106
- const path = c.req.param('path');
107
- const config = getCmsConfig(c.env);
108
- const gitConfig = getGitHubConfig(c.env);
109
- const github = createGitHubClient(gitConfig);
110
- const result = await github.readFile(`${config.assetDir}/${path}`);
111
- if (!result) {
112
- return c.json({ error: 'Asset not found' }, 404);
113
- }
114
- const mimeType = getMimeType(path);
115
- const response = { image: result.content, mimeType };
116
- return c.json(response);
117
- }
118
- catch (error) {
119
- console.error('Get asset error:', error);
120
- return c.json({ error: error.message || 'Failed to get asset' }, 500);
121
- }
122
- }
123
- /**
124
- * GET /api/admin/assets/sync
125
- * Sync all assets (with content)
126
- */
127
- export async function syncAssets(c) {
128
- try {
129
- const config = getCmsConfig(c.env);
130
- const gitConfig = getGitHubConfig(c.env);
131
- const github = createGitHubClient(gitConfig);
132
- const commitSha = await github.getCommitSha();
133
- const octokit = github.getOctokit();
134
- const repoInfo = github.getRepoInfo();
135
- // Get directory listing
136
- const dirResponse = await octokit.rest.repos.getContent({
137
- ...repoInfo,
138
- path: config.assetDir,
139
- ref: repoInfo.branch
140
- });
141
- if (!Array.isArray(dirResponse.data)) {
142
- return c.json({ assets: [], commitSha });
143
- }
144
- // Fetch content for each file
145
- const filesWithContent = await Promise.all(dirResponse.data.map(async (item) => {
146
- try {
147
- // Use readFileBinary for assets to avoid UTF-8 decoding corruption
148
- const fileResult = await github.readFileBinary(item.path);
149
- if (!fileResult)
150
- return null;
151
- let content = fileResult.content;
152
- // For large files, GitHub might not return content in the first call
153
- // But our GitHubClient.readFile handles the basic case.
154
- // If content is empty but it's a file, we might need to fetch download_url
155
- if (!content && item.download_url) {
156
- const dlResponse = await fetch(item.download_url);
157
- if (dlResponse.ok) {
158
- const arrayBuffer = await dlResponse.arrayBuffer();
159
- const uint8Array = new Uint8Array(arrayBuffer);
160
- const chunkSize = 8192;
161
- let binary = '';
162
- for (let i = 0; i < uint8Array.length; i += chunkSize) {
163
- const chunk = uint8Array.subarray(i, Math.min(i + chunkSize, uint8Array.length));
164
- binary += String.fromCharCode.apply(null, Array.from(chunk));
165
- }
166
- content = btoa(binary);
167
- }
168
- }
169
- return {
170
- name: item.name,
171
- path: item.path,
172
- content,
173
- mimeType: getMimeType(item.name),
174
- lastModified: Date.now()
175
- };
176
- }
177
- catch (e) {
178
- console.error(`Failed to fetch ${item.name}:`, e);
179
- return null;
180
- }
181
- }));
182
- const validFiles = filesWithContent.filter((f) => f !== null);
183
- const response = {
184
- assets: validFiles,
185
- commitSha
186
- };
187
- return c.json(response);
188
- }
189
- catch (error) {
190
- console.error('Sync assets error:', error);
191
- return c.json({ error: error.message || 'Failed to sync assets' }, 500);
192
- }
193
- }
194
- /**
195
- * Mock assets for development
196
- */
197
- export async function syncAssetsMock(c) {
198
- // Implementation omitted for brevity, keeping same logic as before if needed
199
- return c.json({ assets: [], commitSha: '' });
200
- }
@@ -1,7 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * PUT /api/admin/config
4
- * Update CMS configuration in GitHub
5
- */
6
- export declare function updateConfig(c: Context): Promise<Response>;
7
- //# sourceMappingURL=config.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/config.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAS/B;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuChE"}
@@ -1,37 +0,0 @@
1
- import { getCmsConfig, getGitHubConfig } from '../../../lib/config';
2
- import { createGitHubClient } from '../../../lib/github';
3
- /**
4
- * PUT /api/admin/config
5
- * Update CMS configuration in GitHub
6
- */
7
- export async function updateConfig(c) {
8
- try {
9
- const request = await c.req.json();
10
- const config = getCmsConfig(c.env);
11
- const gitConfig = getGitHubConfig(c.env);
12
- const github = createGitHubClient(gitConfig);
13
- // Get current commit SHA
14
- const currentCommitSha = await github.getCommitSha();
15
- // Check for conflicts
16
- if (request.commitSha !== currentCommitSha) {
17
- // Fetch current config for conflict resolution
18
- const configResult = await github.readJsonFile(`${config.contentDir}/config.json`);
19
- const serverConfig = configResult?.data || {};
20
- const conflictResponse = {
21
- conflict: true,
22
- currentCommitSha,
23
- serverConfig,
24
- message: 'Configuration has been modified by another user. Please resolve conflicts.'
25
- };
26
- return c.json(conflictResponse, 409);
27
- }
28
- // Write updated config file
29
- await github.writeJsonFile(`${config.contentDir}/config.json`, request.config, 'Update configuration [skip ci]');
30
- const response = { success: true };
31
- return c.json(response);
32
- }
33
- catch (error) {
34
- console.error('Update config error:', error);
35
- return c.json({ error: error.message || 'Failed to update config' }, 500);
36
- }
37
- }
@@ -1,21 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * GET /api/admin/contents
4
- * Fetch all content collections from GitHub
5
- */
6
- export declare function getContents(c: Context): Promise<Response>;
7
- /**
8
- * Sync contents from GitHub - optimized for conditional fetching
9
- */
10
- export declare function syncContents(c: Context): Promise<Response>;
11
- /**
12
- * PUT /api/admin/contents
13
- * Update content collections in GitHub atomically
14
- */
15
- export declare function updateContents(c: Context): Promise<Response>;
16
- /**
17
- * DELETE /api/admin/contents
18
- * Actually this seems to be an update operation in disguise (updating a file with filtered records)
19
- */
20
- export declare function deleteContent(c: Context): Promise<Response>;
21
- //# sourceMappingURL=content.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/content.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAU/B;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2C/D;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAGhE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoDlE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoBjE"}
@@ -1,117 +0,0 @@
1
- import { getCmsConfig, getGitHubConfig } from '../../../lib/config';
2
- import { createGitHubClient } from '../../../lib/github';
3
- /**
4
- * GET /api/admin/contents
5
- * Fetch all content collections from GitHub
6
- */
7
- export async function getContents(c) {
8
- try {
9
- const config = getCmsConfig(c.env);
10
- const gitConfig = getGitHubConfig(c.env);
11
- const github = createGitHubClient(gitConfig);
12
- // Get current commit SHA from branch
13
- const commitSha = await github.getCommitSha();
14
- // Read content config
15
- const configResult = await github.readJsonFile(`${config.contentDir}/config.json`);
16
- if (!configResult) {
17
- throw new Error('Config file not found');
18
- }
19
- const contentConfig = configResult.data;
20
- // Fetch all content files in parallel
21
- const collectionKeys = Object.keys(contentConfig);
22
- const collections = await Promise.all(collectionKeys.map(async (content) => {
23
- const result = await github.readJsonFile(`${config.contentDir}/${content}.json`);
24
- return {
25
- [content]: result?.data || {}
26
- };
27
- }));
28
- const collectionsObject = collections.reduce((acc, cur) => ({ ...acc, ...cur }), {});
29
- const response = {
30
- config: contentConfig,
31
- collections: collectionsObject,
32
- commitSha
33
- };
34
- return c.json(response);
35
- }
36
- catch (error) {
37
- console.error('Error fetching contents:', error);
38
- return c.json({
39
- error: error.message || 'Failed to fetch contents',
40
- details: error.toString()
41
- }, 500);
42
- }
43
- }
44
- /**
45
- * Sync contents from GitHub - optimized for conditional fetching
46
- */
47
- export async function syncContents(c) {
48
- // For now, this is same as getContents, but could be optimized later with If-None-Match
49
- return getContents(c);
50
- }
51
- /**
52
- * PUT /api/admin/contents
53
- * Update content collections in GitHub atomically
54
- */
55
- export async function updateContents(c) {
56
- try {
57
- const request = await c.req.json();
58
- const config = getCmsConfig(c.env);
59
- const gitConfig = getGitHubConfig(c.env);
60
- const github = createGitHubClient(gitConfig);
61
- // Get current commit SHA
62
- const currentCommitSha = await github.getCommitSha();
63
- // Check for conflicts
64
- if (request.commitSha !== currentCommitSha) {
65
- // Fetch current state for conflict resolution
66
- const configResult = await github.readJsonFile(`${config.contentDir}/config.json`);
67
- const contentConfig = configResult?.data || {};
68
- const collections = await Promise.all(Object.keys(contentConfig).map(async (content) => {
69
- const result = await github.readJsonFile(`${config.contentDir}/${content}.json`);
70
- return {
71
- [content]: result?.data || {}
72
- };
73
- }));
74
- const serverCollections = collections.reduce((acc, cur) => ({ ...acc, ...cur }), {});
75
- const conflictResponse = {
76
- conflict: true,
77
- currentCommitSha,
78
- serverCollections,
79
- message: 'Content has been modified by another user. Please resolve conflicts.'
80
- };
81
- return c.json(conflictResponse, 409);
82
- }
83
- // Prepare files for atomic update
84
- const files = Object.keys(request.collections).map((content) => ({
85
- path: `${config.contentDir}/${content}.json`,
86
- content: JSON.stringify(request.collections[content], null, 4)
87
- }));
88
- // Write to GitHub atomically
89
- await github.writeFilesAtomic(files, 'Update content', currentCommitSha);
90
- const response = { success: true };
91
- return c.json(response);
92
- }
93
- catch (error) {
94
- console.error('Update contents error:', error);
95
- return c.json({ error: error.message || 'Failed to update contents' }, 500);
96
- }
97
- }
98
- /**
99
- * DELETE /api/admin/contents
100
- * Actually this seems to be an update operation in disguise (updating a file with filtered records)
101
- */
102
- export async function deleteContent(c) {
103
- try {
104
- const deleteData = await c.req.json();
105
- const contentId = Object.keys(deleteData)[0];
106
- const config = getCmsConfig(c.env);
107
- const gitConfig = getGitHubConfig(c.env);
108
- const github = createGitHubClient(gitConfig);
109
- // This handler in the old code was just writing the updated file
110
- await github.writeJsonFile(`${config.contentDir}/${contentId}.json`, deleteData[contentId], `Delete record(s) from ${contentId} [CI SKIP]`);
111
- return c.json({ message: `Deleted record from ${contentId}` });
112
- }
113
- catch (error) {
114
- console.error('Delete content error:', error);
115
- return c.json({ error: error.message || 'Failed to delete content' }, 500);
116
- }
117
- }
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- declare const assetsRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
- export default assetsRoutes;
4
- //# sourceMappingURL=assets.routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/assets.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,QAAA,MAAM,YAAY,4EAAa,CAAC;AAYhC,eAAe,YAAY,CAAC"}
@@ -1,13 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { listAssets, uploadAsset, deleteAsset, getAssetByPath, syncAssets, syncAssetsMock } from '../handlers/assets.handler';
3
- const assetsRoutes = new Hono();
4
- assetsRoutes.get('/', listAssets);
5
- assetsRoutes.put('/', uploadAsset);
6
- assetsRoutes.delete('/', deleteAsset);
7
- assetsRoutes.get('/sync', (c) => {
8
- // Check if we should use mock data
9
- const useMock = c.req.header('X-Use-Mock') === 'true';
10
- return useMock ? syncAssetsMock(c) : syncAssets(c);
11
- });
12
- assetsRoutes.get('/:path', getAssetByPath);
13
- export default assetsRoutes;
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- declare const contentRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
3
- export default contentRoutes;
4
- //# sourceMappingURL=content.routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/content.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,QAAA,MAAM,aAAa,4EAAa,CAAC;AASjC,eAAe,aAAa,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { getContents, updateContents, deleteContent, syncContents } from '../handlers/content.handler';
3
- import { updateConfig } from '../handlers/config.handler';
4
- const contentRoutes = new Hono();
5
- // IMPORTANT: More specific routes must come before generic routes
6
- contentRoutes.get('/collections/sync', syncContents);
7
- contentRoutes.get('/collections', getContents);
8
- contentRoutes.put('/collections', updateContents);
9
- contentRoutes.delete('/collections', deleteContent);
10
- contentRoutes.put('/config', updateConfig);
11
- export default contentRoutes;
@@ -1,17 +0,0 @@
1
- /**
2
- * Branding Handler
3
- *
4
- * Manages global email branding stored in GitHub.
5
- */
6
- import { Context } from 'hono';
7
- /**
8
- * GET /api/email/admin/branding
9
- * Get the global branding configuration from GitHub
10
- */
11
- export declare function getBranding(c: Context): Promise<Response>;
12
- /**
13
- * PUT /api/email/admin/branding
14
- * Save/update the global branding configuration to GitHub
15
- */
16
- export declare function saveBranding(c: Context): Promise<Response>;
17
- //# sourceMappingURL=branding.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"branding.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/branding.handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsC/B;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmB/D;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8EhE"}
@@ -1,120 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
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
@@ -1 +0,0 @@
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"}