@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.
- package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
- package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/admin-users.handler.js +121 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
- package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +74 -153
- package/dist/api/cms/handlers/dashboard.handler.js +1 -1
- package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/website-repo.handler.js +148 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +16 -4
- package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +164 -92
- package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/invoice.handler.js +58 -340
- package/dist/api/emails/handlers/public.handler.d.ts +6 -29
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +150 -312
- package/dist/api/emails/handlers/send.handler.d.ts +5 -17
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/send.handler.js +107 -92
- package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +96 -287
- package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
- package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/subscribers.handler.js +125 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/webhook.handler.js +66 -166
- package/dist/api/emails/routes/admin.routes.d.ts +1 -3
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +19 -49
- package/dist/api/emails/routes/public.routes.d.ts +1 -3
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/public.routes.js +2 -9
- package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
- package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/prices.handler.js +2 -83
- package/dist/api/shop/handlers/products.handler.d.ts +29 -20
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +195 -162
- package/dist/api/shop/handlers/public.handler.d.ts +24 -8
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +525 -78
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +14 -9
- package/dist/hintergrund-assets.d.ts +3 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +4 -2
- package/dist/index.d.ts +15 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -4
- package/dist/lib/auth/crypto.d.ts +2 -15
- package/dist/lib/auth/crypto.d.ts.map +1 -1
- package/dist/lib/auth/crypto.js +8 -95
- package/dist/lib/auth/jwt.d.ts +0 -4
- package/dist/lib/auth/jwt.d.ts.map +1 -1
- package/dist/lib/auth/jwt.js +0 -6
- package/dist/lib/config.d.ts +8 -10
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +30 -106
- package/dist/lib/email-template.d.ts +15 -0
- package/dist/lib/email-template.d.ts.map +1 -0
- package/dist/lib/email-template.js +58 -0
- package/dist/lib/email.d.ts +18 -8
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +59 -70
- package/dist/lib/github-app.d.ts +2 -0
- package/dist/lib/github-app.d.ts.map +1 -0
- package/dist/lib/github-app.js +49 -0
- package/dist/lib/github-config.d.ts +19 -0
- package/dist/lib/github-config.d.ts.map +1 -0
- package/dist/lib/github-config.js +23 -0
- package/dist/lib/github.d.ts +16 -3
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +38 -15
- package/dist/lib/project-db.d.ts +24 -0
- package/dist/lib/project-db.d.ts.map +1 -0
- package/dist/lib/project-db.js +172 -0
- package/dist/lib/template.js +4 -4
- package/dist/middleware/auth.d.ts +0 -2
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +21 -50
- package/package.json +3 -2
- package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
- package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/generate.handler.js +0 -203
- package/dist/api/builder/handlers/template.handler.d.ts +0 -12
- package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/template.handler.js +0 -208
- package/dist/api/builder/routes.d.ts +0 -7
- package/dist/api/builder/routes.d.ts.map +0 -1
- package/dist/api/builder/routes.js +0 -15
- package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
- package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/assets.handler.js +0 -200
- package/dist/api/cms/handlers/config.handler.d.ts +0 -7
- package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/config.handler.js +0 -37
- package/dist/api/cms/handlers/content.handler.d.ts +0 -21
- package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/content.handler.js +0 -117
- package/dist/api/cms/routes/assets.routes.d.ts +0 -4
- package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/assets.routes.js +0 -13
- package/dist/api/cms/routes/content.routes.d.ts +0 -4
- package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/content.routes.js +0 -11
- package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
- package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/branding.handler.js +0 -120
- package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/contacts.handler.js +0 -161
- package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
- package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/templates.handler.js +0 -132
- package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
- package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/email.handler.js +0 -102
- package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/emails.handler.js +0 -262
- package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
- package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/public.handler.js +0 -300
- package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
- package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/send.handler.js +0 -153
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
- package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/admin.routes.js +0 -28
- package/dist/api/newsletter/routes/index.d.ts +0 -4
- package/dist/api/newsletter/routes/index.d.ts.map +0 -1
- package/dist/api/newsletter/routes/index.js +0 -9
- package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/public.routes.js +0 -9
- package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
- package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/assets.handler.js +0 -62
- package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
- package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/checkout.handler.js +0 -50
- package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
- package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/customers.handler.js +0 -89
- package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
- package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/orders.handler.js +0 -84
- package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
- package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/stats.handler.js +0 -71
- package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/webhook.handler.js +0 -233
- package/dist/cms-assets.d.ts +0 -4
- package/dist/cms-assets.d.ts.map +0 -1
- package/dist/cms-assets.js +0 -5
- package/dist/cms-bundle.d.ts +0 -3
- package/dist/cms-bundle.d.ts.map +0 -1
- package/dist/cms-bundle.js +0 -4
- package/dist/config-loader.d.ts +0 -26
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -98
- package/dist/jwt.d.ts +0 -26
- package/dist/jwt.d.ts.map +0 -1
- package/dist/jwt.js +0 -102
- package/dist/lib/plunk.d.ts +0 -204
- package/dist/lib/plunk.d.ts.map +0 -1
- package/dist/lib/plunk.js +0 -259
- package/dist/template.d.ts +0 -2
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -61
- package/dist/utils.d.ts +0 -23
- package/dist/utils.d.ts.map +0 -1
- 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
|
-
}
|
package/dist/template.d.ts
DELETED
package/dist/template.d.ts.map
DELETED
|
@@ -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
|
package/dist/utils.d.ts.map
DELETED
|
@@ -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
|
-
}
|