@hintergrund/worker 0.1.6 → 0.1.8

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 (190) 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/dashboard.handler.js +1 -1
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
  12. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  13. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  14. package/dist/api/cms/routes/index.d.ts.map +1 -1
  15. package/dist/api/cms/routes/index.js +16 -4
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  17. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  18. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  19. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  20. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  21. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  22. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  23. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  24. package/dist/api/emails/handlers/public.handler.js +150 -312
  25. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  26. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  27. package/dist/api/emails/handlers/send.handler.js +107 -92
  28. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  29. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  30. package/dist/api/emails/handlers/settings.handler.js +96 -287
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  32. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  33. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  34. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  35. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  36. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  37. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  38. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  39. package/dist/api/emails/routes/admin.routes.js +19 -49
  40. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  41. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  42. package/dist/api/emails/routes/public.routes.js +2 -9
  43. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  44. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  45. package/dist/api/shop/handlers/prices.handler.js +2 -83
  46. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  47. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  48. package/dist/api/shop/handlers/products.handler.js +195 -162
  49. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  50. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  51. package/dist/api/shop/handlers/public.handler.js +525 -78
  52. package/dist/api/shop/routes.d.ts.map +1 -1
  53. package/dist/api/shop/routes.js +14 -9
  54. package/dist/hintergrund-assets.d.ts +3 -2
  55. package/dist/hintergrund-assets.d.ts.map +1 -1
  56. package/dist/hintergrund-assets.js +4 -2
  57. package/dist/index.d.ts +15 -8
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +44 -4
  60. package/dist/lib/auth/crypto.d.ts +2 -15
  61. package/dist/lib/auth/crypto.d.ts.map +1 -1
  62. package/dist/lib/auth/crypto.js +8 -95
  63. package/dist/lib/auth/jwt.d.ts +0 -4
  64. package/dist/lib/auth/jwt.d.ts.map +1 -1
  65. package/dist/lib/auth/jwt.js +0 -6
  66. package/dist/lib/config.d.ts +8 -10
  67. package/dist/lib/config.d.ts.map +1 -1
  68. package/dist/lib/config.js +30 -106
  69. package/dist/lib/email-template.d.ts +15 -0
  70. package/dist/lib/email-template.d.ts.map +1 -0
  71. package/dist/lib/email-template.js +58 -0
  72. package/dist/lib/email.d.ts +18 -8
  73. package/dist/lib/email.d.ts.map +1 -1
  74. package/dist/lib/email.js +59 -70
  75. package/dist/lib/github-app.d.ts +2 -0
  76. package/dist/lib/github-app.d.ts.map +1 -0
  77. package/dist/lib/github-app.js +49 -0
  78. package/dist/lib/github-config.d.ts +19 -0
  79. package/dist/lib/github-config.d.ts.map +1 -0
  80. package/dist/lib/github-config.js +23 -0
  81. package/dist/lib/github.d.ts +16 -3
  82. package/dist/lib/github.d.ts.map +1 -1
  83. package/dist/lib/github.js +38 -15
  84. package/dist/lib/project-db.d.ts +24 -0
  85. package/dist/lib/project-db.d.ts.map +1 -0
  86. package/dist/lib/project-db.js +172 -0
  87. package/dist/lib/template.js +4 -4
  88. package/dist/middleware/auth.d.ts +0 -2
  89. package/dist/middleware/auth.d.ts.map +1 -1
  90. package/dist/middleware/auth.js +21 -50
  91. package/package.json +3 -2
  92. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  93. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  94. package/dist/api/builder/handlers/generate.handler.js +0 -203
  95. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  96. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  97. package/dist/api/builder/handlers/template.handler.js +0 -208
  98. package/dist/api/builder/routes.d.ts +0 -7
  99. package/dist/api/builder/routes.d.ts.map +0 -1
  100. package/dist/api/builder/routes.js +0 -15
  101. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  102. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  103. package/dist/api/cms/handlers/assets.handler.js +0 -200
  104. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  105. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  106. package/dist/api/cms/handlers/config.handler.js +0 -37
  107. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  108. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  109. package/dist/api/cms/handlers/content.handler.js +0 -117
  110. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  111. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  112. package/dist/api/cms/routes/assets.routes.js +0 -13
  113. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  114. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  115. package/dist/api/cms/routes/content.routes.js +0 -11
  116. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  117. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  118. package/dist/api/emails/handlers/branding.handler.js +0 -120
  119. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  120. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  121. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  122. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  123. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  124. package/dist/api/emails/handlers/templates.handler.js +0 -132
  125. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  126. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  127. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  128. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  129. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  130. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  131. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  132. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  133. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  134. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  135. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  136. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  137. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  138. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  139. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  140. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  141. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  142. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  143. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  144. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  145. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  146. package/dist/api/newsletter/routes/index.d.ts +0 -4
  147. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  148. package/dist/api/newsletter/routes/index.js +0 -9
  149. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  150. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  151. package/dist/api/newsletter/routes/public.routes.js +0 -9
  152. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  153. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  154. package/dist/api/shop/handlers/assets.handler.js +0 -62
  155. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  156. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  157. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  158. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  159. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  160. package/dist/api/shop/handlers/customers.handler.js +0 -89
  161. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  162. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  163. package/dist/api/shop/handlers/orders.handler.js +0 -84
  164. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  165. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  166. package/dist/api/shop/handlers/stats.handler.js +0 -71
  167. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  168. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  169. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  170. package/dist/cms-assets.d.ts +0 -4
  171. package/dist/cms-assets.d.ts.map +0 -1
  172. package/dist/cms-assets.js +0 -5
  173. package/dist/cms-bundle.d.ts +0 -3
  174. package/dist/cms-bundle.d.ts.map +0 -1
  175. package/dist/cms-bundle.js +0 -4
  176. package/dist/config-loader.d.ts +0 -26
  177. package/dist/config-loader.d.ts.map +0 -1
  178. package/dist/config-loader.js +0 -98
  179. package/dist/jwt.d.ts +0 -26
  180. package/dist/jwt.d.ts.map +0 -1
  181. package/dist/jwt.js +0 -102
  182. package/dist/lib/plunk.d.ts +0 -204
  183. package/dist/lib/plunk.d.ts.map +0 -1
  184. package/dist/lib/plunk.js +0 -259
  185. package/dist/template.d.ts +0 -2
  186. package/dist/template.d.ts.map +0 -1
  187. package/dist/template.js +0 -61
  188. package/dist/utils.d.ts +0 -23
  189. package/dist/utils.d.ts.map +0 -1
  190. package/dist/utils.js +0 -110
package/dist/lib/plunk.js DELETED
@@ -1,259 +0,0 @@
1
- /**
2
- * Plunk API Client
3
- *
4
- * Provides methods for interacting with Plunk's email marketing API:
5
- * - Contacts management
6
- * - Templates management
7
- * - Campaigns management
8
- * - Transactional email sending
9
- * - Event tracking
10
- */
11
- export class PlunkClient {
12
- constructor(config) {
13
- this.baseUrl = 'https://next-api.useplunk.com';
14
- this.secretKey = config.secretKey;
15
- this.publicKey = config.publicKey;
16
- }
17
- async request(endpoint, options = {}, usePublicKey = false) {
18
- const apiKey = usePublicKey && this.publicKey ? this.publicKey : this.secretKey;
19
- const response = await fetch(`${this.baseUrl}${endpoint}`, {
20
- ...options,
21
- headers: {
22
- 'Content-Type': 'application/json',
23
- 'Authorization': `Bearer ${apiKey}`,
24
- ...options.headers,
25
- },
26
- });
27
- const data = await response.json();
28
- if (!response.ok) {
29
- const error = data;
30
- // Enhanced error logging
31
- console.error(`Plunk API Error: ${error.error || error.message}`);
32
- throw new Error(error.message || error.error || `Plunk API error: ${response.status}`);
33
- }
34
- return data;
35
- }
36
- // ==========================================================================
37
- // Contacts
38
- // ==========================================================================
39
- /**
40
- * Get all contacts
41
- */
42
- async getContacts() {
43
- const response = await this.request('/contacts');
44
- return {
45
- contacts: response.data || [],
46
- count: response.count || 0,
47
- };
48
- }
49
- /**
50
- * Get a single contact by ID
51
- */
52
- async getContact(id) {
53
- return this.request(`/contacts/${id}`);
54
- }
55
- /**
56
- * Create a new contact
57
- */
58
- async createContact(data) {
59
- return this.request('/contacts', {
60
- method: 'POST',
61
- body: JSON.stringify(data),
62
- });
63
- }
64
- /**
65
- * Update an existing contact
66
- */
67
- async updateContact(id, data) {
68
- return this.request(`/contacts/${id}`, {
69
- method: 'PUT',
70
- body: JSON.stringify(data),
71
- });
72
- }
73
- /**
74
- * Delete a contact
75
- */
76
- async deleteContact(id) {
77
- return this.request(`/contacts/${id}`, {
78
- method: 'DELETE',
79
- });
80
- }
81
- /**
82
- * Subscribe a contact (set subscribed to true)
83
- */
84
- async subscribeContact(id) {
85
- return this.updateContact(id, { subscribed: true });
86
- }
87
- /**
88
- * Unsubscribe a contact (set subscribed to false)
89
- */
90
- async unsubscribeContact(id) {
91
- return this.updateContact(id, { subscribed: false });
92
- }
93
- // ==========================================================================
94
- // Templates
95
- // ==========================================================================
96
- /**
97
- * Get all templates
98
- */
99
- async getTemplates() {
100
- const response = await this.request('/templates');
101
- return {
102
- templates: response.data || [],
103
- };
104
- }
105
- /**
106
- * Get a single template by ID
107
- */
108
- async getTemplate(id) {
109
- return this.request(`/templates/${id}`);
110
- }
111
- /**
112
- * Create a new template
113
- */
114
- async createTemplate(data) {
115
- return this.request('/templates', {
116
- method: 'POST',
117
- body: JSON.stringify({
118
- ...data,
119
- type: data.type || 'TRANSACTIONAL',
120
- }),
121
- });
122
- }
123
- /**
124
- * Update an existing template
125
- */
126
- async updateTemplate(id, data) {
127
- return this.request(`/templates/${id}`, {
128
- method: 'PUT',
129
- body: JSON.stringify(data),
130
- });
131
- }
132
- /**
133
- * Delete a template
134
- */
135
- async deleteTemplate(id) {
136
- return this.request(`/templates/${id}`, {
137
- method: 'DELETE',
138
- });
139
- }
140
- // ==========================================================================
141
- // Campaigns
142
- // ==========================================================================
143
- /**
144
- * Get all campaigns
145
- */
146
- async getCampaigns() {
147
- const response = await this.request('/campaigns');
148
- return {
149
- campaigns: response.data || [],
150
- };
151
- }
152
- /**
153
- * Get a single campaign by ID
154
- */
155
- async getCampaign(id) {
156
- return this.request(`/campaigns/${id}`);
157
- }
158
- /**
159
- * Create a new campaign (draft)
160
- */
161
- async createCampaign(data) {
162
- return this.request('/campaigns', {
163
- method: 'POST',
164
- body: JSON.stringify({
165
- ...data,
166
- recipients: 'all', // Send to all subscribed contacts
167
- }),
168
- });
169
- }
170
- /**
171
- * Send a campaign to all subscribed contacts
172
- */
173
- async sendCampaign(id) {
174
- return this.request(`/campaigns/${id}/send`, {
175
- method: 'POST',
176
- });
177
- }
178
- /**
179
- * Send a test email for a campaign to a specific email
180
- */
181
- async testCampaign(id, email) {
182
- // Get the campaign to use its content
183
- const campaign = await this.getCampaign(id);
184
- // Send as transactional to the test email
185
- return this.send({
186
- to: email,
187
- subject: `[TEST] ${campaign.subject}`,
188
- body: campaign.body || '',
189
- });
190
- }
191
- // ==========================================================================
192
- // Transactional Emails
193
- // ==========================================================================
194
- /**
195
- * Send a transactional email
196
- */
197
- async send(data) {
198
- return this.request('/v1/send', {
199
- method: 'POST',
200
- body: JSON.stringify(data),
201
- });
202
- }
203
- // ==========================================================================
204
- // Event Tracking
205
- // ==========================================================================
206
- /**
207
- * Track an event for a contact
208
- * Uses the public key if available for client-side tracking
209
- */
210
- async track(data) {
211
- return this.request('/v1/track', {
212
- method: 'POST',
213
- body: JSON.stringify(data),
214
- }, true // Use public key for tracking
215
- );
216
- }
217
- // ==========================================================================
218
- // Utility Methods
219
- // ==========================================================================
220
- /**
221
- * Find a contact by email
222
- */
223
- async findContactByEmail(email) {
224
- const { contacts } = await this.getContacts();
225
- return contacts.find(c => c.email.toLowerCase() === email.toLowerCase()) || null;
226
- }
227
- /**
228
- * Create or update a contact by email
229
- */
230
- async upsertContact(data) {
231
- const existing = await this.findContactByEmail(data.email);
232
- if (existing) {
233
- return this.updateContact(existing.id, {
234
- subscribed: data.subscribed,
235
- data: data.data,
236
- });
237
- }
238
- return this.createContact(data);
239
- }
240
- /**
241
- * Get count of subscribed contacts
242
- */
243
- async getSubscribedCount() {
244
- const { contacts } = await this.getContacts();
245
- return contacts.filter(c => c.subscribed).length;
246
- }
247
- }
248
- /**
249
- * Create a Plunk client from environment configuration
250
- */
251
- export function createPlunkClient(env) {
252
- if (!env.HG_EMAILS_PLUNK_SECRET_KEY) {
253
- throw new Error('HG_EMAILS_PLUNK_SECRET_KEY is required');
254
- }
255
- return new PlunkClient({
256
- secretKey: env.HG_EMAILS_PLUNK_SECRET_KEY,
257
- publicKey: env.HG_EMAILS_PLUNK_PUBLIC_KEY,
258
- });
259
- }
@@ -1,2 +0,0 @@
1
- export declare function getTemplate(element: string, uiBaseUrl: string, params?: string): string;
2
- //# sourceMappingURL=template.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CA8D3F"}
package/dist/template.js DELETED
@@ -1,61 +0,0 @@
1
- export function getTemplate(element, uiBaseUrl, params = '') {
2
- if (element === 'login') {
3
- return `
4
- <!doctype html>
5
- <html>
6
- <head>
7
- <meta charset="utf-8">
8
- <meta name="viewport" content="width=device-width, initial-scale=1">
9
- <title>Login</title>
10
- <style>
11
- * { box-sizing: border-box; margin: 0; padding: 0; }
12
- body { margin: 0; height: 100vh; }
13
- </style>
14
- <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
15
- </head>
16
- <body>
17
- <hintergrund-login></hintergrund-login>
18
- <script type="module" src="${uiBaseUrl}/login.js"></script>
19
- </body>
20
- </html>
21
- `;
22
- }
23
- if (element === 'admin') {
24
- return `
25
- <!doctype html>
26
- <html>
27
- <head>
28
- <meta charset="utf-8">
29
- <meta name="viewport" content="width=device-width, initial-scale=1">
30
- <title>Hintergrund Admin</title>
31
- <meta name="description" content="Admin Panel for Hintergrund">
32
- <style>
33
- * { box-sizing: border-box; margin: 0; padding: 0; }
34
- body { margin: 0; height: 100vh; }
35
- </style>
36
- <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
37
- </head>
38
- <body>
39
- <hintergrund-admin ${params}></hintergrund-admin>
40
- <script type="module" src="${uiBaseUrl}/admin.js"></script>
41
- </body>
42
- </html>
43
- `;
44
- }
45
- return `
46
- <!doctype html>
47
- <html>
48
- <head>
49
- <meta charset="utf-8">
50
- <meta name="viewport" content="width=device-width, initial-scale=1">
51
- <title>Hintergrund CMS</title>
52
- <meta name="description" content="Admin Panel for Hintergrund CMS">
53
- <style>body{margin:0}</style>
54
- </head>
55
- <body>
56
- <${element} ${params}></${element}>
57
- <script type="module" src="/index.js"></script>
58
- </body>
59
- </html>
60
- `;
61
- }
package/dist/utils.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Generates a random token used as a Secret Key
3
- */
4
- export declare function generateRandomToken(): string;
5
- /**
6
- * Hash a password with salt and pepper
7
- */
8
- export declare function hashPw(password: string, pepper: string): Promise<string>;
9
- /**
10
- * Verify a password against an encrypted password
11
- * Uses AES-GCM decryption to match hintergrund.cloud's encryption method
12
- */
13
- export declare function verifyPw(encryptedPassword: string, password: string, secret: string): Promise<boolean>;
14
- /**
15
- * Decrypts an encrypted string using AES-GCM
16
- * Matches hintergrund.cloud's decrypt function
17
- */
18
- export declare function decrypt(ciphertext: string, secret: string): Promise<string>;
19
- /**
20
- * Read and parse request body
21
- */
22
- export declare function readRequestBody(request: Request): Promise<any>;
23
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2B9E;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5G;AAiBD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BjF;AAiBD;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAepE"}
package/dist/utils.js DELETED
@@ -1,110 +0,0 @@
1
- /**
2
- * Generates a random token used as a Secret Key
3
- */
4
- export function generateRandomToken() {
5
- const tokenBytes = crypto.getRandomValues(new Uint8Array(32));
6
- return btoa(String.fromCharCode(...tokenBytes));
7
- }
8
- /**
9
- * Hash a password with salt and pepper
10
- */
11
- export async function hashPw(password, pepper) {
12
- // Create salt
13
- const salt = crypto.getRandomValues(new Uint8Array(16));
14
- // Convert password and pepper to Uint8Array
15
- const pass = new TextEncoder().encode(password);
16
- const pepp = new TextEncoder().encode(pepper);
17
- // Combine salt, pepper, and password hash
18
- const combined = new Uint8Array(salt.length + pepper.length + password.length);
19
- combined.set(salt);
20
- combined.set(pepp, salt.length);
21
- combined.set(pass, salt.length + pepper.length);
22
- // Hash combined
23
- const hashBuffer = await crypto.subtle.digest('SHA-256', combined);
24
- // Convert hashBuffer to Uint8Array
25
- const hash = new Uint8Array(hashBuffer);
26
- // Combine salt and hash
27
- const combinedHash = new Uint8Array(salt.length + hash.length);
28
- combinedHash.set(salt);
29
- combinedHash.set(hash, salt.length);
30
- // Return combined hash as base64 string
31
- return btoa(new Uint8Array(combinedHash).reduce((s, b) => s + String.fromCharCode(b), ''));
32
- }
33
- /**
34
- * Verify a password against an encrypted password
35
- * Uses AES-GCM decryption to match hintergrund.cloud's encryption method
36
- */
37
- export async function verifyPw(encryptedPassword, password, secret) {
38
- try {
39
- const decryptedPassword = await decrypt(encryptedPassword, secret);
40
- return decryptedPassword === password;
41
- }
42
- catch (error) {
43
- return false;
44
- }
45
- }
46
- /**
47
- * Derives a cryptographic key from the secret string
48
- */
49
- async function deriveKey(secret) {
50
- const secretBytes = new TextEncoder().encode(secret);
51
- const keyMaterial = await crypto.subtle.digest('SHA-256', secretBytes);
52
- return await crypto.subtle.importKey('raw', keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
53
- }
54
- /**
55
- * Decrypts an encrypted string using AES-GCM
56
- * Matches hintergrund.cloud's decrypt function
57
- */
58
- export async function decrypt(ciphertext, secret) {
59
- try {
60
- // Decode from base64
61
- const combined = Uint8Array.from(atob(ciphertext), (c) => c.charCodeAt(0));
62
- // Extract IV (first 12 bytes)
63
- const iv = combined.slice(0, 12);
64
- // Extract encrypted data (remaining bytes)
65
- const encryptedData = combined.slice(12);
66
- // Derive decryption key
67
- const key = await deriveKey(secret);
68
- // Decrypt
69
- const decryptedBuffer = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedData);
70
- // Convert bytes back to string
71
- return new TextDecoder().decode(decryptedBuffer);
72
- }
73
- catch (error) {
74
- throw new Error('Decryption failed');
75
- }
76
- }
77
- /**
78
- * Compare two Uint8Arrays for equality
79
- */
80
- function areUint8ArraysEqual(a, b) {
81
- if (a.length !== b.length) {
82
- return false;
83
- }
84
- for (let i = 0; i < a.length; i++) {
85
- if (a[i] !== b[i]) {
86
- return false;
87
- }
88
- }
89
- return true;
90
- }
91
- /**
92
- * Read and parse request body
93
- */
94
- export async function readRequestBody(request) {
95
- const contentType = request.headers.get('content-type');
96
- if (!contentType)
97
- throw new Error('Content-Type not set');
98
- if (contentType.includes('application/json')) {
99
- return await request.json();
100
- }
101
- else if (contentType.includes('form')) {
102
- const formData = await request.formData();
103
- const body = {};
104
- for (const entry of formData.entries()) {
105
- body[entry[0]] = entry[1];
106
- }
107
- return body;
108
- }
109
- throw new Error('Content-Type not supported');
110
- }