@hintergrund/worker 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/api/cms/handlers/assets.handler.d.ts +24 -1
  2. package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
  3. package/dist/api/cms/handlers/assets.handler.js +111 -210
  4. package/dist/api/cms/handlers/auth.handler.d.ts +4 -3
  5. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  6. package/dist/api/cms/handlers/auth.handler.js +24 -14
  7. package/dist/api/cms/handlers/config.handler.d.ts +4 -0
  8. package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/config.handler.js +20 -71
  10. package/dist/api/cms/handlers/content.handler.d.ts +12 -1
  11. package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
  12. package/dist/api/cms/handlers/content.handler.js +57 -233
  13. package/dist/api/cms/handlers/dashboard.handler.js +1 -1
  14. package/dist/api/cms/routes/auth.routes.d.ts +2 -1
  15. package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
  16. package/dist/api/cms/routes/auth.routes.js +7 -0
  17. package/dist/api/cms/routes/index.d.ts +2 -1
  18. package/dist/api/cms/routes/index.d.ts.map +1 -1
  19. package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
  20. package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
  21. package/dist/api/emails/handlers/branding.handler.js +120 -0
  22. package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
  23. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
  24. package/dist/api/emails/handlers/campaigns.handler.js +139 -0
  25. package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
  26. package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
  27. package/dist/api/emails/handlers/contacts.handler.js +161 -0
  28. package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
  29. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
  30. package/dist/api/emails/handlers/invoice.handler.js +463 -0
  31. package/dist/api/emails/handlers/public.handler.d.ts +36 -0
  32. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
  33. package/dist/api/emails/handlers/public.handler.js +350 -0
  34. package/dist/api/emails/handlers/send.handler.d.ts +23 -0
  35. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
  36. package/dist/api/emails/handlers/send.handler.js +117 -0
  37. package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
  38. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
  39. package/dist/api/emails/handlers/settings.handler.js +312 -0
  40. package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
  41. package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
  42. package/dist/api/emails/handlers/templates.handler.js +132 -0
  43. package/dist/api/emails/handlers/webhook.handler.d.ts +10 -0
  44. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -0
  45. package/dist/api/emails/handlers/webhook.handler.js +261 -0
  46. package/dist/api/emails/routes/admin.routes.d.ts +9 -0
  47. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
  48. package/dist/api/emails/routes/admin.routes.js +77 -0
  49. package/dist/api/emails/routes/index.d.ts +9 -0
  50. package/dist/api/emails/routes/index.d.ts.map +1 -0
  51. package/dist/api/emails/routes/index.js +14 -0
  52. package/dist/api/emails/routes/public.routes.d.ts +9 -0
  53. package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
  54. package/dist/api/emails/routes/public.routes.js +18 -0
  55. package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -1
  56. package/dist/api/shop/handlers/webhook.handler.js +66 -60
  57. package/dist/api/shop/routes.d.ts.map +1 -1
  58. package/dist/api/shop/routes.js +0 -3
  59. package/dist/hintergrund-assets.d.ts +2 -2
  60. package/dist/hintergrund-assets.d.ts.map +1 -1
  61. package/dist/hintergrund-assets.js +2 -2
  62. package/dist/index.d.ts +20 -19
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +4 -7
  65. package/dist/lib/config.d.ts +13 -7
  66. package/dist/lib/config.d.ts.map +1 -1
  67. package/dist/lib/config.js +44 -46
  68. package/dist/lib/email.d.ts +2 -2
  69. package/dist/lib/email.d.ts.map +1 -1
  70. package/dist/lib/email.js +7 -9
  71. package/dist/lib/github.d.ts +124 -0
  72. package/dist/lib/github.d.ts.map +1 -0
  73. package/dist/lib/github.js +286 -0
  74. package/dist/lib/plunk.d.ts +204 -0
  75. package/dist/lib/plunk.d.ts.map +1 -0
  76. package/dist/lib/plunk.js +259 -0
  77. package/dist/middleware/auth.d.ts.map +1 -1
  78. package/dist/middleware/auth.js +2 -5
  79. package/package.json +32 -32
@@ -1,88 +1,37 @@
1
- import { Octokit } from '@octokit/rest';
2
- import { getCmsConfig } from '../../../lib/config';
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
+ */
3
7
  export async function updateConfig(c) {
4
8
  try {
5
9
  const request = await c.req.json();
6
10
  const config = getCmsConfig(c.env);
7
- const octokit = new Octokit({
8
- auth: config.gitToken
9
- });
10
- // Get reference from branch
11
- const ref = await octokit.rest.git.getRef({
12
- owner: config.gitOwner,
13
- repo: config.gitRepo,
14
- ref: `heads/${config.gitBranch}`
15
- });
16
- const currentCommitSha = ref.data.object.sha;
17
- // Check for conflicts - if commit SHA doesn't match, someone else has committed
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
18
16
  if (request.commitSha !== currentCommitSha) {
19
- // Fetch current config to show in conflict UI
20
- const configFile = await octokit.rest.repos.getContent({
21
- owner: config.gitOwner,
22
- repo: config.gitRepo,
23
- path: `${config.contentDir}/config.json`
24
- });
25
- if (Array.isArray(configFile.data) || !('content' in configFile.data)) {
26
- throw new Error('Config file not found or is not a file');
27
- }
28
- const serverConfig = JSON.parse(atob(configFile.data.content || ''));
17
+ // Fetch current config for conflict resolution
18
+ const configResult = await github.readJsonFile(`${config.contentDir}/config.json`);
19
+ const serverConfig = configResult?.data || {};
29
20
  const conflictResponse = {
30
21
  conflict: true,
31
22
  currentCommitSha,
32
23
  serverConfig,
33
24
  message: 'Configuration has been modified by another user. Please resolve conflicts.'
34
25
  };
35
- return new Response(JSON.stringify(conflictResponse), { status: 409 });
26
+ return c.json(conflictResponse, 409);
36
27
  }
37
- // Get latest commit
38
- const commit = await octokit.rest.git.getCommit({
39
- owner: config.gitOwner,
40
- repo: config.gitRepo,
41
- commit_sha: currentCommitSha
42
- });
43
- // Create blob for config.json
44
- const blob = await octokit.rest.git.createBlob({
45
- owner: config.gitOwner,
46
- repo: config.gitRepo,
47
- content: JSON.stringify(request.config, null, 4),
48
- encoding: 'utf-8'
49
- });
50
- // Create tree with the updated config file
51
- const newTree = await octokit.rest.git.createTree({
52
- owner: config.gitOwner,
53
- repo: config.gitRepo,
54
- tree: [
55
- {
56
- path: `${config.contentDir}/config.json`,
57
- mode: '100644',
58
- type: 'blob',
59
- sha: blob.data.sha
60
- }
61
- ],
62
- base_tree: commit.data.tree.sha
63
- });
64
- // Create commit
65
- const newCommit = await octokit.rest.git.createCommit({
66
- owner: config.gitOwner,
67
- repo: config.gitRepo,
68
- message: 'Update configuration',
69
- tree: newTree.data.sha,
70
- parents: [commit.data.sha]
71
- });
72
- // Update reference
73
- await octokit.rest.git.updateRef({
74
- owner: config.gitOwner,
75
- repo: config.gitRepo,
76
- ref: `heads/${config.gitBranch}`,
77
- sha: newCommit.data.sha
78
- });
28
+ // Write updated config file
29
+ await github.writeJsonFile(`${config.contentDir}/config.json`, request.config, 'Update configuration [skip ci]');
79
30
  const response = { success: true };
80
- return new Response(JSON.stringify(response), { status: 200 });
31
+ return c.json(response);
81
32
  }
82
33
  catch (error) {
83
- console.log(error);
84
- return new Response(JSON.stringify(error), {
85
- status: 500
86
- });
34
+ console.error('Update config error:', error);
35
+ return c.json({ error: error.message || 'Failed to update config' }, 500);
87
36
  }
88
37
  }
@@ -1,10 +1,21 @@
1
1
  import { Context } from 'hono';
2
+ /**
3
+ * GET /api/admin/contents
4
+ * Fetch all content collections from GitHub
5
+ */
2
6
  export declare function getContents(c: Context): Promise<Response>;
3
7
  /**
4
8
  * Sync contents from GitHub - optimized for conditional fetching
5
- * Only fetches content data from GitHub if commitSha has changed
6
9
  */
7
10
  export declare function syncContents(c: Context): Promise<Response>;
11
+ /**
12
+ * PUT /api/admin/contents
13
+ * Update content collections in GitHub atomically
14
+ */
8
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
+ */
9
20
  export declare function deleteContent(c: Context): Promise<Response>;
10
21
  //# sourceMappingURL=content.handler.d.ts.map
@@ -1 +1 @@
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;AAoC/B,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqE/D;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2EhE;AAED,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwHlE;AAED,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6CjE"}
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,64 +1,28 @@
1
- import { Octokit } from '@octokit/rest';
2
- import { getCmsConfig } from '../../../lib/config';
1
+ import { getCmsConfig, getGitHubConfig } from '../../../lib/config';
2
+ import { createGitHubClient } from '../../../lib/github';
3
3
  /**
4
- * Decode base64 content to UTF-8 string.
5
- * atob() decodes to Latin-1, which corrupts multi-byte UTF-8 characters.
4
+ * GET /api/admin/contents
5
+ * Fetch all content collections from GitHub
6
6
  */
7
- function decodeBase64UTF8(base64) {
8
- const binaryString = atob(base64);
9
- const bytes = new Uint8Array(binaryString.length);
10
- for (let i = 0; i < binaryString.length; i++) {
11
- bytes[i] = binaryString.charCodeAt(i);
12
- }
13
- return new TextDecoder('utf-8').decode(bytes);
14
- }
15
- /**
16
- * Encode UTF-8 string to base64.
17
- * btoa() only works with Latin-1, which corrupts multi-byte UTF-8 characters like ß.
18
- */
19
- function encodeUTF8Base64(str) {
20
- const bytes = new TextEncoder().encode(str);
21
- let binaryString = '';
22
- for (let i = 0; i < bytes.length; i++) {
23
- binaryString += String.fromCharCode(bytes[i]);
24
- }
25
- return btoa(binaryString);
26
- }
27
7
  export async function getContents(c) {
28
8
  try {
29
9
  const config = getCmsConfig(c.env);
30
- const octokit = new Octokit({
31
- auth: config.gitToken
32
- });
10
+ const gitConfig = getGitHubConfig(c.env);
11
+ const github = createGitHubClient(gitConfig);
33
12
  // Get current commit SHA from branch
34
- const ref = await octokit.rest.git.getRef({
35
- owner: config.gitOwner,
36
- repo: config.gitRepo,
37
- ref: `heads/${config.gitBranch}`
38
- });
39
- const commitSha = ref.data.object.sha;
40
- const configFile = await octokit.rest.repos.getContent({
41
- owner: config.gitOwner,
42
- repo: config.gitRepo,
43
- path: `${config.contentDir}/config.json`
44
- });
45
- // Type guard to check if data is a file (not array or directory)
46
- if (Array.isArray(configFile.data) || !('content' in configFile.data)) {
47
- throw new Error('Config file not found or is not a file');
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');
48
18
  }
49
- const contentConfig = JSON.parse(decodeBase64UTF8(configFile.data.content || ''));
50
- const collections = await Promise.all(Object.keys(contentConfig).map(async (content) => {
51
- const contentFile = await octokit.rest.repos.getContent({
52
- owner: config.gitOwner,
53
- repo: config.gitRepo,
54
- path: `${config.contentDir}/${content}.json`
55
- });
56
- // Type guard to check if data is a file (not array or directory)
57
- if (Array.isArray(contentFile.data) || !('content' in contentFile.data)) {
58
- throw new Error(`Content file ${content}.json not found or is not a file`);
59
- }
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`);
60
24
  return {
61
- [content]: JSON.parse(decodeBase64UTF8(contentFile.data.content || ''))
25
+ [content]: result?.data || {}
62
26
  };
63
27
  }));
64
28
  const collectionsObject = collections.reduce((acc, cur) => ({ ...acc, ...cur }), {});
@@ -67,125 +31,44 @@ export async function getContents(c) {
67
31
  collections: collectionsObject,
68
32
  commitSha
69
33
  };
70
- return new Response(JSON.stringify(response), {
71
- status: 200
72
- });
34
+ return c.json(response);
73
35
  }
74
36
  catch (error) {
75
37
  console.error('Error fetching contents:', error);
76
- return new Response(JSON.stringify({
38
+ return c.json({
77
39
  error: error.message || 'Failed to fetch contents',
78
40
  details: error.toString()
79
- }), {
80
- status: 500,
81
- headers: { 'Content-Type': 'application/json' }
82
- });
41
+ }, 500);
83
42
  }
84
43
  }
85
44
  /**
86
45
  * Sync contents from GitHub - optimized for conditional fetching
87
- * Only fetches content data from GitHub if commitSha has changed
88
46
  */
89
47
  export async function syncContents(c) {
90
- try {
91
- const config = getCmsConfig(c.env);
92
- const octokit = new Octokit({
93
- auth: config.gitToken
94
- });
95
- // Get current commit SHA from branch
96
- const ref = await octokit.rest.git.getRef({
97
- owner: config.gitOwner,
98
- repo: config.gitRepo,
99
- ref: `heads/${config.gitBranch}`
100
- });
101
- const commitSha = ref.data.object.sha;
102
- // Always fetch config (it's small and may change without commitSha changing)
103
- const configFile = await octokit.rest.repos.getContent({
104
- owner: config.gitOwner,
105
- repo: config.gitRepo,
106
- path: `${config.contentDir}/config.json`
107
- });
108
- // Type guard to check if data is a file (not array or directory)
109
- if (Array.isArray(configFile.data) || !('content' in configFile.data)) {
110
- throw new Error('Config file not found or is not a file');
111
- }
112
- const contentConfig = JSON.parse(decodeBase64UTF8(configFile.data.content || ''));
113
- // Fetch all content files from GitHub
114
- const collections = await Promise.all(Object.keys(contentConfig).map(async (content) => {
115
- const contentFile = await octokit.rest.repos.getContent({
116
- owner: config.gitOwner,
117
- repo: config.gitRepo,
118
- path: `${config.contentDir}/${content}.json`
119
- });
120
- // Type guard to check if data is a file (not array or directory)
121
- if (Array.isArray(contentFile.data) || !('content' in contentFile.data)) {
122
- throw new Error(`Content file ${content}.json not found or is not a file`);
123
- }
124
- return {
125
- [content]: JSON.parse(decodeBase64UTF8(contentFile.data.content || ''))
126
- };
127
- }));
128
- const collectionsObject = collections.reduce((acc, cur) => ({ ...acc, ...cur }), {});
129
- const response = {
130
- config: contentConfig,
131
- collections: collectionsObject,
132
- commitSha
133
- };
134
- return new Response(JSON.stringify(response), {
135
- status: 200,
136
- headers: {
137
- 'Content-Type': 'application/json'
138
- }
139
- });
140
- }
141
- catch (error) {
142
- console.error('Error syncing contents:', error);
143
- return new Response(JSON.stringify({
144
- error: error.message || 'Failed to sync contents',
145
- details: error.toString()
146
- }), {
147
- status: 500,
148
- headers: { 'Content-Type': 'application/json' }
149
- });
150
- }
48
+ // For now, this is same as getContents, but could be optimized later with If-None-Match
49
+ return getContents(c);
151
50
  }
51
+ /**
52
+ * PUT /api/admin/contents
53
+ * Update content collections in GitHub atomically
54
+ */
152
55
  export async function updateContents(c) {
153
56
  try {
154
57
  const request = await c.req.json();
155
58
  const config = getCmsConfig(c.env);
156
- const octokit = new Octokit({
157
- auth: config.gitToken
158
- });
159
- // Get reference from branch
160
- const ref = await octokit.rest.git.getRef({
161
- owner: config.gitOwner,
162
- repo: config.gitRepo,
163
- ref: `heads/${config.gitBranch}`
164
- });
165
- const currentCommitSha = ref.data.object.sha;
166
- // Check for conflicts - if commit SHA doesn't match, someone else has committed
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
167
64
  if (request.commitSha !== currentCommitSha) {
168
- // Fetch current collections to show in conflict UI
169
- const configFile = await octokit.rest.repos.getContent({
170
- owner: config.gitOwner,
171
- repo: config.gitRepo,
172
- path: `${config.contentDir}/config.json`
173
- });
174
- if (Array.isArray(configFile.data) || !('content' in configFile.data)) {
175
- throw new Error('Config file not found or is not a file');
176
- }
177
- const contentConfig = JSON.parse(decodeBase64UTF8(configFile.data.content || ''));
65
+ // Fetch current state for conflict resolution
66
+ const configResult = await github.readJsonFile(`${config.contentDir}/config.json`);
67
+ const contentConfig = configResult?.data || {};
178
68
  const collections = await Promise.all(Object.keys(contentConfig).map(async (content) => {
179
- const contentFile = await octokit.rest.repos.getContent({
180
- owner: config.gitOwner,
181
- repo: config.gitRepo,
182
- path: `${config.contentDir}/${content}.json`
183
- });
184
- if (Array.isArray(contentFile.data) || !('content' in contentFile.data)) {
185
- throw new Error(`Content file ${content}.json not found or is not a file`);
186
- }
69
+ const result = await github.readJsonFile(`${config.contentDir}/${content}.json`);
187
70
  return {
188
- [content]: JSON.parse(decodeBase64UTF8(contentFile.data.content || ''))
71
+ [content]: result?.data || {}
189
72
  };
190
73
  }));
191
74
  const serverCollections = collections.reduce((acc, cur) => ({ ...acc, ...cur }), {});
@@ -195,99 +78,40 @@ export async function updateContents(c) {
195
78
  serverCollections,
196
79
  message: 'Content has been modified by another user. Please resolve conflicts.'
197
80
  };
198
- return new Response(JSON.stringify(conflictResponse), { status: 409 });
81
+ return c.json(conflictResponse, 409);
199
82
  }
200
- // Get latest commit
201
- const commit = await octokit.rest.git.getCommit({
202
- owner: config.gitOwner,
203
- repo: config.gitRepo,
204
- commit_sha: currentCommitSha
205
- });
206
- // Create blob for each change and save file tree
207
- const blobs = await Promise.all(Object.keys(request.collections).map(async (content) => {
208
- const blob = await octokit.rest.git.createBlob({
209
- owner: config.gitOwner,
210
- repo: config.gitRepo,
211
- content: JSON.stringify(request.collections[content], null, 4),
212
- encoding: 'utf-8'
213
- });
214
- return {
215
- path: `${config.contentDir}/${content}.json`,
216
- mode: '100644',
217
- type: 'blob',
218
- sha: blob.data.sha
219
- };
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)
220
87
  }));
221
- // Create tree
222
- const newTree = await octokit.rest.git.createTree({
223
- owner: config.gitOwner,
224
- repo: config.gitRepo,
225
- tree: blobs,
226
- base_tree: commit.data.tree.sha
227
- });
228
- // Create commit
229
- const newCommit = await octokit.rest.git.createCommit({
230
- owner: config.gitOwner,
231
- repo: config.gitRepo,
232
- message: 'Update content',
233
- tree: newTree.data.sha,
234
- parents: [commit.data.sha]
235
- });
236
- // Update reference
237
- await octokit.rest.git.updateRef({
238
- owner: config.gitOwner,
239
- repo: config.gitRepo,
240
- ref: `heads/${config.gitBranch}`,
241
- sha: newCommit.data.sha
242
- });
88
+ // Write to GitHub atomically
89
+ await github.writeFilesAtomic(files, 'Update content', currentCommitSha);
243
90
  const response = { success: true };
244
- return new Response(JSON.stringify(response), { status: 200 });
91
+ return c.json(response);
245
92
  }
246
93
  catch (error) {
247
- console.log(error);
248
- return new Response(JSON.stringify(error), {
249
- status: 500
250
- });
94
+ console.error('Update contents error:', error);
95
+ return c.json({ error: error.message || 'Failed to update contents' }, 500);
251
96
  }
252
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
+ */
253
102
  export async function deleteContent(c) {
254
103
  try {
255
104
  const deleteData = await c.req.json();
256
105
  const contentId = Object.keys(deleteData)[0];
257
106
  const config = getCmsConfig(c.env);
258
- const octokit = new Octokit({
259
- auth: config.gitToken
260
- });
261
- const fileInfo = await octokit.rest.repos.getContent({
262
- owner: config.gitOwner,
263
- repo: config.gitRepo,
264
- path: `${config.contentDir}/${contentId}.json`,
265
- ref: config.gitBranch
266
- });
267
- // Type guard to check if data is a file (not array or directory)
268
- if (Array.isArray(fileInfo.data) || !('sha' in fileInfo.data)) {
269
- throw new Error(`File ${contentId}.json not found or is not a file`);
270
- }
271
- const response = await octokit.rest.repos.createOrUpdateFileContents({
272
- owner: config.gitOwner,
273
- repo: config.gitRepo,
274
- path: `${config.contentDir}/${contentId}.json`,
275
- message: `Delete record(s) from ${contentId} [CI SKIP]`,
276
- content: encodeUTF8Base64(JSON.stringify(deleteData[contentId], null, 4)),
277
- branch: config.gitBranch,
278
- sha: fileInfo.data.sha
279
- });
280
- if (response.status !== 200) {
281
- return new Response(`Error deleting record(s) from ${contentId}`, {
282
- status: 500
283
- });
284
- }
285
- return new Response(`Deleted record from ${contentId}`, { status: 200 });
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}` });
286
112
  }
287
113
  catch (error) {
288
- console.log(error);
289
- return new Response(error.message, {
290
- status: 500
291
- });
114
+ console.error('Delete content error:', error);
115
+ return c.json({ error: error.message || 'Failed to delete content' }, 500);
292
116
  }
293
117
  }
@@ -9,7 +9,7 @@ export async function getDashboard(c) {
9
9
  }
10
10
  catch (error) {
11
11
  // Fallback to default config if parsing fails
12
- const configParams = 'config=\'{"cms":true,"newsletter":false,"shop":false}\'';
12
+ const configParams = 'config=\'{"cms":true,"emails":false,"shop":false}\'';
13
13
  return c.html(getTemplate('admin', c.env.UI_BASE_URL, configParams));
14
14
  }
15
15
  }
@@ -1,4 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- declare const authRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
2
+ import { HonoEnv } from '../../../index';
3
+ declare const authRoutes: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
3
4
  export default authRoutes;
4
5
  //# sourceMappingURL=auth.routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/auth.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,QAAA,MAAM,UAAU,4EAAa,CAAC;AAM9B,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"auth.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/auth.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,QAAA,MAAM,UAAU,sDAAsB,CAAC;AAavC,eAAe,UAAU,CAAC"}
@@ -3,5 +3,12 @@ import { login, logout, verifyMagicLink } from '../handlers/auth.handler';
3
3
  const authRoutes = new Hono();
4
4
  authRoutes.post('/login', login);
5
5
  authRoutes.post('/logout', logout);
6
+ authRoutes.get('/me', (c) => {
7
+ const user = c.get('user');
8
+ if (user) {
9
+ return c.json({ success: true, user });
10
+ }
11
+ return c.json({ success: false, message: 'Not logged in' }, 401);
12
+ });
6
13
  authRoutes.get('/verify-magic-link', verifyMagicLink);
7
14
  export default authRoutes;
@@ -1,4 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- declare const cmsRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
2
+ import { HonoEnv } from '../../../index';
3
+ declare const cmsRoutes: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
3
4
  export default cmsRoutes;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,QAAA,MAAM,SAAS,4EAAa,CAAC;AAa7B,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAM5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,QAAA,MAAM,SAAS,sDAAsB,CAAC;AAatC,eAAe,SAAS,CAAC"}
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}