@hintergrund/worker 0.2.3 → 0.3.1
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 +1 -0
- package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/admin-users.handler.js +60 -79
- package/dist/api/cms/handlers/auth.handler.d.ts +1 -1
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +13 -94
- package/dist/api/cms/handlers/dashboard.handler.d.ts +1 -1
- package/dist/api/cms/handlers/dashboard.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/dashboard.handler.js +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.js +8 -1
- package/dist/api/cms/handlers/integrations.handler.d.ts +5 -0
- package/dist/api/cms/handlers/integrations.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/integrations.handler.js +24 -0
- package/dist/api/cms/handlers/recovery.handler.d.ts +5 -0
- package/dist/api/cms/handlers/recovery.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/recovery.handler.js +53 -0
- package/dist/api/cms/handlers/setup.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/setup.handler.js +97 -35
- package/dist/api/cms/handlers/website-repo.handler.d.ts +2 -1
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +64 -55
- package/dist/api/cms/routes/auth.routes.d.ts +1 -1
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
- package/dist/api/cms/routes/auth.routes.js +7 -2
- package/dist/api/cms/routes/index.d.ts +1 -1
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +7 -11
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +3 -4
- package/dist/api/emails/handlers/invoice.handler.d.ts +8 -15
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/invoice.handler.js +142 -170
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +27 -8
- package/dist/api/emails/handlers/send.handler.d.ts +1 -3
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/send.handler.js +18 -65
- package/dist/api/emails/handlers/settings.handler.d.ts +60 -12
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +35 -94
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +5 -6
- package/dist/api/emails/routes/mail.routes.d.ts +5 -0
- package/dist/api/emails/routes/mail.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/mail.routes.js +188 -0
- package/dist/api/shop/handlers/products.handler.d.ts +2 -2
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +21 -8
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +17 -66
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -18
- package/dist/lib/auth/crypto.d.ts +0 -1
- package/dist/lib/auth/crypto.d.ts.map +1 -1
- package/dist/lib/auth/crypto.js +1 -4
- package/dist/lib/brand.d.ts +6 -0
- package/dist/lib/brand.d.ts.map +1 -0
- package/dist/lib/brand.js +31 -0
- package/dist/lib/config.d.ts +1 -2
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +1 -8
- package/dist/lib/email-template.d.ts +4 -7
- package/dist/lib/email-template.d.ts.map +1 -1
- package/dist/lib/email-template.js +9 -31
- package/dist/lib/email.d.ts +20 -11
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +29 -19
- package/dist/lib/github.d.ts +1 -1
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +13 -4
- package/dist/lib/integration-health.d.ts +18 -0
- package/dist/lib/integration-health.d.ts.map +1 -0
- package/dist/lib/integration-health.js +51 -0
- package/dist/lib/invoice.d.ts +13 -0
- package/dist/lib/invoice.d.ts.map +1 -0
- package/dist/lib/invoice.js +41 -0
- package/dist/lib/mail-schema.d.ts +2 -0
- package/dist/lib/mail-schema.d.ts.map +1 -0
- package/dist/lib/mail-schema.js +56 -0
- package/dist/lib/mail.d.ts +83 -0
- package/dist/lib/mail.d.ts.map +1 -0
- package/dist/lib/mail.js +211 -0
- package/dist/lib/project-db.d.ts +3 -4
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +14 -43
- package/dist/lib/template.d.ts.map +1 -1
- package/dist/lib/template.js +28 -0
- package/dist/lib/user-recovery.d.ts +9 -0
- package/dist/lib/user-recovery.d.ts.map +1 -0
- package/dist/lib/user-recovery.js +42 -0
- package/dist/lib/website-i18n.d.ts +10 -0
- package/dist/lib/website-i18n.d.ts.map +1 -0
- package/dist/lib/website-i18n.js +195 -0
- package/dist/middleware/auth.d.ts +3 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +8 -4
- package/package.json +4 -2
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts +0 -6
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/agent-conversations.handler.js +0 -87
- package/dist/api/cms/handlers/website-templates.handler.d.ts +0 -6
- package/dist/api/cms/handlers/website-templates.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/website-templates.handler.js +0 -53
- package/dist/api/shop/handlers/prices.handler.d.ts +0 -4
- package/dist/api/shop/handlers/prices.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/prices.handler.js +0 -6
- package/dist/hintergrund-assets.d.ts +0 -5
- package/dist/hintergrund-assets.d.ts.map +0 -1
- package/dist/hintergrund-assets.js +0 -11
|
@@ -2,13 +2,14 @@ import { hashPw } from '../../../lib/auth/crypto';
|
|
|
2
2
|
import { signWithPayload } from '../../../lib/auth/jwt';
|
|
3
3
|
import { getGitHubConfig } from '../../../lib/config';
|
|
4
4
|
import { createGitHubClient } from '../../../lib/github';
|
|
5
|
-
import { readJsonConfig
|
|
5
|
+
import { readJsonConfig } from '../../../lib/github-config';
|
|
6
6
|
import { DEFAULT_EMAIL_SETTINGS, EMAIL_SETTINGS_PATH } from '../../emails/handlers/settings.handler';
|
|
7
7
|
import Stripe from 'stripe';
|
|
8
|
+
import { checkIntegrationKey } from '../../../lib/integration-health';
|
|
8
9
|
import { createId, ensureSchema, issueSessionForUser, nowSeconds } from '../../../lib/project-db';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import { AGENT_PROVIDERS, AGENT_PROVIDER_SECRETS, SETUP_PATH as WEBSITE_SETUP_PATH, SHOP_SETTINGS_PATH, normalizeProjectGoals, subscriptionAutomation, DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
|
|
11
|
+
import { validateI18nConfig, DEFAULT_I18N_CONFIG } from '@hintergrund/runtime-contracts';
|
|
12
|
+
import { initializeWebsiteLanguages } from '../../../lib/website-i18n';
|
|
12
13
|
const DEFAULT_SHOP_SETTINGS = {
|
|
13
14
|
currency: 'eur',
|
|
14
15
|
enabledPaymentMethods: ['bank_transfer'],
|
|
@@ -58,40 +59,68 @@ export async function setupProject(c) {
|
|
|
58
59
|
if (!(await hasValidSetupToken(c.env, body.setupToken)))
|
|
59
60
|
return c.json({ error: 'Invalid setup link.' }, 403);
|
|
60
61
|
const email = typeof body.email === 'string' ? body.email.trim().toLowerCase() : '';
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
if (!body.goals || typeof body.goals !== 'object' || Array.isArray(body.goals)
|
|
63
|
+
|| typeof body.goals.sell !== 'boolean'
|
|
64
|
+
|| typeof body.goals.newsletters !== 'boolean') {
|
|
65
|
+
return c.json({ error: 'Choose your project goals.' }, 400);
|
|
66
|
+
}
|
|
67
|
+
let languages;
|
|
68
|
+
try {
|
|
69
|
+
languages = validateI18nConfig(body.languages ?? DEFAULT_I18N_CONFIG);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return c.json({ error: error instanceof Error ? error.message : 'Invalid website languages.' }, 400);
|
|
73
|
+
}
|
|
74
|
+
const goals = normalizeProjectGoals(body.goals);
|
|
75
|
+
const needsEmail = goals.sell || goals.newsletters;
|
|
70
76
|
const MIN_PASSWORD_LENGTH = 12;
|
|
71
77
|
const password = typeof body.password === 'string' ? body.password : '';
|
|
72
78
|
const plunkApiKey = typeof body.plunkApiKey === 'string' ? body.plunkApiKey.trim() : '';
|
|
73
79
|
const fromEmail = typeof body.fromEmail === 'string' ? body.fromEmail.trim() : '';
|
|
74
80
|
const paymentProvider = body.paymentProvider === 'stripe' || body.paymentProvider === 'bank_transfer' ? body.paymentProvider : null;
|
|
81
|
+
const agentProvider = typeof body.agentProvider === 'string' && AGENT_PROVIDERS.includes(body.agentProvider) ? body.agentProvider : null;
|
|
82
|
+
const agentProviderKey = typeof body.agentProviderKey === 'string' ? body.agentProviderKey.trim() : '';
|
|
83
|
+
const invoiceInput = body.invoice && typeof body.invoice === 'object' && !Array.isArray(body.invoice) ? body.invoice : {};
|
|
84
|
+
const invoice = { companyName: '', companyAddress: '', companyEmail: '', companyPhone: '', dueDays: 14 };
|
|
85
|
+
for (const key of ['companyName', 'companyAddress', 'companyEmail', 'companyPhone']) {
|
|
86
|
+
if (typeof invoiceInput[key] === 'string')
|
|
87
|
+
invoice[key] = invoiceInput[key].trim().slice(0, 4000);
|
|
88
|
+
}
|
|
89
|
+
if (goals.sell && (!invoice.companyName || !invoice.companyAddress))
|
|
90
|
+
return c.json({ error: 'Enter your business name and address for invoices.' }, 400);
|
|
91
|
+
const footerText = typeof body.footerText === 'string' ? body.footerText.trim().slice(0, 8000) : 'If you have any questions, please contact us.';
|
|
92
|
+
const footerHtml = `<p>${footerText.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\n', '<br>')}</p>`;
|
|
75
93
|
if (!email)
|
|
76
94
|
return c.json({ error: 'An email address is required.' }, 400);
|
|
77
95
|
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
78
96
|
return c.json({ error: `Choose a password of at least ${MIN_PASSWORD_LENGTH} characters.` }, 400);
|
|
79
97
|
}
|
|
80
|
-
if (
|
|
98
|
+
if (needsEmail && (!plunkApiKey || !fromEmail)) {
|
|
81
99
|
return c.json({ error: 'An email provider API key and sender address are required.' }, 400);
|
|
82
100
|
}
|
|
83
|
-
if (
|
|
101
|
+
if (!agentProvider || !agentProviderKey)
|
|
102
|
+
return c.json({ error: 'Choose an AI provider and enter its API key.' }, 400);
|
|
103
|
+
if (goals.sell && !paymentProvider)
|
|
84
104
|
return c.json({ error: 'Choose a payment provider.' }, 400);
|
|
85
105
|
const bankTransfer = typeof body.bankTransfer === 'object' && body.bankTransfer !== null ? body.bankTransfer : {};
|
|
86
106
|
const accountHolder = typeof bankTransfer.accountHolder === 'string' ? bankTransfer.accountHolder.trim() : '';
|
|
87
107
|
const iban = typeof bankTransfer.iban === 'string' ? bankTransfer.iban.trim() : '';
|
|
88
|
-
const stripeSecretKey = paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
|
|
89
|
-
if (
|
|
108
|
+
const stripeSecretKey = goals.sell && paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
|
|
109
|
+
if (goals.sell && paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
|
|
90
110
|
return c.json({ error: 'An account holder and IBAN are required for bank transfers.' }, 400);
|
|
91
111
|
}
|
|
92
|
-
if (
|
|
112
|
+
if (goals.sell && paymentProvider === 'stripe' && !stripeSecretKey) {
|
|
93
113
|
return c.json({ error: 'Your Stripe secret key is required for card payments.' }, 400);
|
|
94
114
|
}
|
|
115
|
+
// Validate credentials before creating an administrator or changing the repository.
|
|
116
|
+
const health = await Promise.all([
|
|
117
|
+
checkIntegrationKey(agentProvider, agentProviderKey),
|
|
118
|
+
...(needsEmail ? [checkIntegrationKey('plunk', plunkApiKey)] : []),
|
|
119
|
+
...(stripeSecretKey ? [checkIntegrationKey('stripe', stripeSecretKey)] : []),
|
|
120
|
+
]);
|
|
121
|
+
const failed = health.find(result => !result.valid);
|
|
122
|
+
if (failed)
|
|
123
|
+
return c.json({ error: failed.message }, 400);
|
|
95
124
|
// Do not consume the one-time setup route until GitHub is reachable. A project
|
|
96
125
|
// without its repository cannot complete setup and must remain retryable.
|
|
97
126
|
let client;
|
|
@@ -103,14 +132,16 @@ export async function setupProject(c) {
|
|
|
103
132
|
console.error('Project setup GitHub preflight failed:', error);
|
|
104
133
|
return c.json({ error: 'GitHub repository is unavailable. Check the project GitHub App configuration and try again.' }, 503);
|
|
105
134
|
}
|
|
135
|
+
// The website itself arrives with the repository: it is committed at provisioning
|
|
136
|
+
// from the site the owner built in the demo. Setup only stages the configuration
|
|
137
|
+
// that depends on the answers given here.
|
|
138
|
+
const staged = { files: [], deletions: [] };
|
|
106
139
|
const db = await ensureSchema(c.env);
|
|
107
140
|
const now = nowSeconds();
|
|
108
141
|
const user = {
|
|
109
142
|
id: createId('user'),
|
|
110
143
|
email,
|
|
111
144
|
name: null,
|
|
112
|
-
login_method: loginMethod,
|
|
113
|
-
// Always stored, including for an email-code owner: this is the fallback credential.
|
|
114
145
|
password_hash: await hashPw(password, c.env.SECRET ?? ''),
|
|
115
146
|
initial_admin: 1,
|
|
116
147
|
disabled_at: null,
|
|
@@ -118,8 +149,8 @@ export async function setupProject(c) {
|
|
|
118
149
|
updated_at: now,
|
|
119
150
|
};
|
|
120
151
|
try {
|
|
121
|
-
await db.prepare(`INSERT INTO admin_users (id, email, password_hash, login_method, initial_admin, disabled_at, created_at, updated_at) VALUES (?, ?, ?,
|
|
122
|
-
.bind(user.id, user.email, user.password_hash,
|
|
152
|
+
await db.prepare(`INSERT INTO admin_users (id, email, password_hash, login_method, initial_admin, disabled_at, created_at, updated_at) VALUES (?, ?, ?, 'password', 1, NULL, ?, ?)`)
|
|
153
|
+
.bind(user.id, user.email, user.password_hash, now, now).run();
|
|
123
154
|
}
|
|
124
155
|
catch (error) {
|
|
125
156
|
console.error('Initial admin creation failed', error);
|
|
@@ -135,34 +166,41 @@ export async function setupProject(c) {
|
|
|
135
166
|
});
|
|
136
167
|
stripeWebhookSecret = webhook.secret ?? '';
|
|
137
168
|
}
|
|
138
|
-
catch
|
|
139
|
-
|
|
169
|
+
catch {
|
|
170
|
+
throw new Error('Stripe webhook configuration failed. Check webhook permissions on the Stripe key.');
|
|
140
171
|
}
|
|
141
172
|
}
|
|
173
|
+
// Setup keeps the selected website private in D1 until the first publish.
|
|
174
|
+
const stageConfig = async (_client, path, value, _message, _sha) => {
|
|
175
|
+
staged.files.push({ path, content: JSON.stringify(value, null, 2), encoding: 'utf8' });
|
|
176
|
+
};
|
|
142
177
|
const secrets = {};
|
|
143
178
|
for (const [name, value] of [
|
|
144
|
-
['API_KEY', plunkApiKey],
|
|
179
|
+
['API_KEY', needsEmail ? plunkApiKey : ''],
|
|
145
180
|
['STRIPE_SECRET_KEY', stripeSecretKey],
|
|
146
|
-
['STRIPE_WEBHOOK_SECRET', stripeWebhookSecret],
|
|
181
|
+
['STRIPE_WEBHOOK_SECRET', goals.sell && paymentProvider === 'stripe' ? stripeWebhookSecret : ''],
|
|
182
|
+
[AGENT_PROVIDER_SECRETS[agentProvider], agentProviderKey],
|
|
147
183
|
]) {
|
|
148
184
|
if (typeof value === 'string' && value)
|
|
149
185
|
secrets[name] = value;
|
|
150
186
|
}
|
|
151
187
|
await Promise.all(Object.entries(secrets).map(([secretName, value]) => client.setActionsSecret(secretName, value)));
|
|
152
188
|
const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_SETUP_PATH, {});
|
|
153
|
-
await
|
|
189
|
+
await stageConfig(client, WEBSITE_SETUP_PATH, {
|
|
154
190
|
...setupState,
|
|
155
191
|
version: 1,
|
|
156
|
-
|
|
192
|
+
complete: true,
|
|
193
|
+
goals,
|
|
157
194
|
updatedAt: Date.now(),
|
|
158
|
-
}, 'Record
|
|
195
|
+
}, 'Record project goals [skip ci]', setupCommitSha);
|
|
159
196
|
const { data: shopSettings, commitSha: shopCommitSha } = await readJsonConfig(client, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS);
|
|
160
|
-
await
|
|
197
|
+
await stageConfig(client, SHOP_SETTINGS_PATH, {
|
|
161
198
|
...DEFAULT_SHOP_SETTINGS,
|
|
162
199
|
...shopSettings,
|
|
163
200
|
// No shop means no payment method was chosen; leave it empty rather than
|
|
164
201
|
// implying the shipped default was a decision.
|
|
165
|
-
enabledPaymentMethods:
|
|
202
|
+
enabledPaymentMethods: goals.sell && paymentProvider ? [paymentProvider] : [],
|
|
203
|
+
...(goals.sell ? { emailTemplates: { ...DEFAULT_SHOP_EMAIL_TEMPLATES, ...shopSettings.emailTemplates } } : {}),
|
|
166
204
|
bankTransfer: {
|
|
167
205
|
...DEFAULT_SHOP_SETTINGS.bankTransfer,
|
|
168
206
|
...(shopSettings.bankTransfer ?? {}),
|
|
@@ -174,14 +212,41 @@ export async function setupProject(c) {
|
|
|
174
212
|
},
|
|
175
213
|
}, 'Configure bank transfer payments [skip ci]', shopCommitSha);
|
|
176
214
|
const { data: emailSettings, commitSha } = await readJsonConfig(client, EMAIL_SETTINGS_PATH, DEFAULT_EMAIL_SETTINGS);
|
|
177
|
-
await
|
|
215
|
+
await stageConfig(client, EMAIL_SETTINGS_PATH, {
|
|
178
216
|
...emailSettings,
|
|
217
|
+
invoice,
|
|
218
|
+
footerHtml,
|
|
219
|
+
automation: subscriptionAutomation(goals.newsletters, emailSettings.automation),
|
|
179
220
|
fromEmail: typeof body.fromEmail === 'string' ? body.fromEmail.trim() : emailSettings.fromEmail,
|
|
180
221
|
fromName: typeof body.fromName === 'string' ? body.fromName.trim() : emailSettings.fromName,
|
|
181
222
|
replyTo: typeof body.replyTo === 'string' ? body.replyTo.trim() : emailSettings.replyTo,
|
|
182
223
|
updatedAt: Date.now(),
|
|
183
224
|
}, 'Configure email sender settings [skip ci]', commitSha);
|
|
225
|
+
// Translate the staged configuration and record the chosen languages. The website's
|
|
226
|
+
// own content was translated when its demo draft was committed at provisioning.
|
|
227
|
+
try {
|
|
228
|
+
await initializeWebsiteLanguages(staged.files, languages, {
|
|
229
|
+
...c.env, GEMINI_API_KEY: agentProvider === 'google' ? agentProviderKey : undefined,
|
|
230
|
+
DEEPSEEK_API_KEY: agentProvider === 'deepseek' ? agentProviderKey : undefined,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.error('Setup translation failed:', error);
|
|
235
|
+
return c.json({ error: `Website preparation failed: ${error instanceof Error ? error.message : 'Please retry.'}` }, 502);
|
|
236
|
+
}
|
|
237
|
+
const baseCommitSha = await client.getCommitSha();
|
|
238
|
+
// Deploy secrets/admin runtime against the existing scaffold, never the draft website.
|
|
184
239
|
await deploy(c, client);
|
|
240
|
+
const token = await signWithPayload(c.env.SECRET ?? '', await issueSessionForUser({ ...user, password_hash: user.password_hash }));
|
|
241
|
+
const secureCookie = c.req.url.startsWith('https://') ? '; Secure' : '';
|
|
242
|
+
return c.json({
|
|
243
|
+
success: true,
|
|
244
|
+
draft: {
|
|
245
|
+
files: staged.files,
|
|
246
|
+
deletions: staged.deletions,
|
|
247
|
+
baseCommitSha,
|
|
248
|
+
},
|
|
249
|
+
}, 201, { 'Set-Cookie': `token=${token}; HttpOnly; Path=/; SameSite=Strict${secureCookie}` });
|
|
185
250
|
}
|
|
186
251
|
catch (error) {
|
|
187
252
|
console.error('Project setup integrations could not be saved:', error);
|
|
@@ -193,9 +258,6 @@ export async function setupProject(c) {
|
|
|
193
258
|
}
|
|
194
259
|
return c.json({ error: 'Project setup could not be completed. No administrator was created; fix the integration error and try again.' }, 502);
|
|
195
260
|
}
|
|
196
|
-
const token = await signWithPayload(c.env.SECRET ?? '', issueSessionForUser({ ...user, password_hash: user.password_hash }));
|
|
197
|
-
const secureCookie = c.req.url.startsWith('https://') ? '; Secure' : '';
|
|
198
|
-
return c.json({ success: true }, 201, { 'Set-Cookie': `token=${token}; HttpOnly; Path=/; SameSite=Strict${secureCookie}` });
|
|
199
261
|
}
|
|
200
262
|
export async function projectNeedsSetup(c) {
|
|
201
263
|
return !(await hasAdminUsers(c));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { HonoEnv } from '../../../index';
|
|
3
3
|
export declare function isAllowedWebsitePath(path: string): boolean;
|
|
4
|
+
/** Admin-only access to Git-backed images, including before the next site deployment. */
|
|
5
|
+
export declare function getWebsiteAsset(c: Context<HonoEnv>): Promise<Response>;
|
|
4
6
|
export declare function headWebsiteRepo(c: Context<HonoEnv>): Promise<Response>;
|
|
5
7
|
export declare function syncWebsiteRepo(c: Context<HonoEnv>): Promise<Response>;
|
|
6
8
|
export declare function commitWebsiteRepo(c: Context<HonoEnv>): Promise<Response>;
|
|
7
|
-
export declare function uploadWebsiteAsset(c: Context<HonoEnv>): Promise<Response>;
|
|
8
9
|
//# sourceMappingURL=website-repo.handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website-repo.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-repo.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"website-repo.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-repo.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAgC9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AA4CD,yFAAyF;AACzF,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0B5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc5E;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqD9E"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getGitHubConfig } from '../../../lib/config';
|
|
2
2
|
import { createGitHubClient } from '../../../lib/github';
|
|
3
|
+
import { I18N_CONFIG_PATH, STATIC_DIR, isWebsitePath } from '@hintergrund/runtime-contracts';
|
|
4
|
+
import { translateWebsite } from '../../../lib/website-i18n';
|
|
3
5
|
const STATIC_MIME_TYPES = {
|
|
4
6
|
'.jpg': 'image/jpeg',
|
|
5
7
|
'.jpeg': 'image/jpeg',
|
|
@@ -8,6 +10,12 @@ const STATIC_MIME_TYPES = {
|
|
|
8
10
|
'.svg': 'image/svg+xml',
|
|
9
11
|
'.webp': 'image/webp',
|
|
10
12
|
'.ico': 'image/x-icon',
|
|
13
|
+
'.avif': 'image/avif',
|
|
14
|
+
'.bmp': 'image/bmp',
|
|
15
|
+
'.woff': 'font/woff',
|
|
16
|
+
'.woff2': 'font/woff2',
|
|
17
|
+
'.ttf': 'font/ttf',
|
|
18
|
+
'.otf': 'font/otf',
|
|
11
19
|
};
|
|
12
20
|
const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
|
|
13
21
|
function getStaticMimeType(path) {
|
|
@@ -18,10 +26,7 @@ function normalizePath(path) {
|
|
|
18
26
|
return path.replace(/^\/+/, '').replace(/\\/g, '/');
|
|
19
27
|
}
|
|
20
28
|
export function isAllowedWebsitePath(path) {
|
|
21
|
-
|
|
22
|
-
if (normalized.includes('..'))
|
|
23
|
-
return false;
|
|
24
|
-
return normalized.startsWith('frontend/');
|
|
29
|
+
return isWebsitePath(normalizePath(path));
|
|
25
30
|
}
|
|
26
31
|
async function listRepoFiles(c) {
|
|
27
32
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
@@ -48,19 +53,49 @@ async function listStaticAssets(c) {
|
|
|
48
53
|
const assetPaths = tree.data.tree
|
|
49
54
|
.filter((item) => item.type === 'blob' &&
|
|
50
55
|
item.path &&
|
|
51
|
-
item.path.startsWith(
|
|
56
|
+
item.path.startsWith(STATIC_DIR) &&
|
|
52
57
|
getStaticMimeType(item.path) !== null)
|
|
53
|
-
.map((item) => item.path);
|
|
54
|
-
return assetPaths.map((path) => {
|
|
58
|
+
.map((item) => ({ path: item.path, sha: item.sha }));
|
|
59
|
+
return assetPaths.map(({ path, sha }) => {
|
|
55
60
|
const name = path.split('/').pop();
|
|
56
61
|
const mimeType = getStaticMimeType(path);
|
|
57
|
-
return { name, path, content: '', mimeType };
|
|
62
|
+
return { name, path, content: '', mimeType, sha };
|
|
58
63
|
});
|
|
59
64
|
}
|
|
65
|
+
/** Admin-only access to Git-backed images, including before the next site deployment. */
|
|
66
|
+
export async function getWebsiteAsset(c) {
|
|
67
|
+
const path = c.req.param('path') || '';
|
|
68
|
+
const mimeType = getStaticMimeType(path);
|
|
69
|
+
if (!path.startsWith(STATIC_DIR) || path.split('/').some((part) => !part || part === '.' || part === '..') || /[\\\\\x00-\x1f]/.test(path) || !mimeType) {
|
|
70
|
+
return c.json({ error: 'Invalid static asset path' }, 400);
|
|
71
|
+
}
|
|
72
|
+
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
73
|
+
try {
|
|
74
|
+
const asset = await client.readFileBinary(path, MAX_UPLOAD_BYTES);
|
|
75
|
+
if (!asset)
|
|
76
|
+
return c.notFound();
|
|
77
|
+
const headers = {
|
|
78
|
+
'Content-Type': mimeType,
|
|
79
|
+
'Cache-Control': 'private, no-cache',
|
|
80
|
+
'ETag': `"${asset.sha}"`,
|
|
81
|
+
'X-Content-Type-Options': 'nosniff',
|
|
82
|
+
// SVGs may be opened directly; never allow repository scripts to execute.
|
|
83
|
+
'Content-Security-Policy': "default-src 'none'; sandbox",
|
|
84
|
+
};
|
|
85
|
+
if (c.req.header('If-None-Match') === headers.ETag)
|
|
86
|
+
return new Response(null, { status: 304, headers });
|
|
87
|
+
const bytes = Uint8Array.from(atob(asset.content), (char) => char.charCodeAt(0));
|
|
88
|
+
return new Response(bytes, { headers });
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof RangeError)
|
|
92
|
+
return c.json({ error: 'Asset exceeds 10 MB limit' }, 413);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
60
96
|
export async function headWebsiteRepo(c) {
|
|
61
97
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
62
|
-
|
|
63
|
-
return c.json({ commitSha });
|
|
98
|
+
return c.json({ commitSha: await client.getCommitSha() });
|
|
64
99
|
}
|
|
65
100
|
export async function syncWebsiteRepo(c) {
|
|
66
101
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
@@ -105,51 +140,25 @@ export async function commitWebsiteRepo(c) {
|
|
|
105
140
|
return c.json({ conflict: true, message: 'Repository changed since the last sync' }, 409);
|
|
106
141
|
}
|
|
107
142
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const fileVal = formData.get('file');
|
|
121
|
-
const nameOverride = formData.get('name');
|
|
122
|
-
if (typeof moduleVal !== 'string' || !['cms', 'shop', 'builder', 'email'].includes(moduleVal)) {
|
|
123
|
-
return c.json({ error: 'module must be cms, shop, builder, or email' }, 400);
|
|
124
|
-
}
|
|
125
|
-
const module = moduleVal;
|
|
126
|
-
if (!fileVal || typeof fileVal === 'string') {
|
|
127
|
-
return c.json({ error: 'file field is required' }, 400);
|
|
128
|
-
}
|
|
129
|
-
const uploadedFile = fileVal;
|
|
130
|
-
if (uploadedFile.size > MAX_UPLOAD_BYTES) {
|
|
131
|
-
return c.json({ error: 'File exceeds 10 MB limit' }, 400);
|
|
143
|
+
const baseCommitSha = body.baseCommitSha ? String(body.baseCommitSha) : await client.getCommitSha();
|
|
144
|
+
let translation = null;
|
|
145
|
+
try {
|
|
146
|
+
if (files.some(file => file.path === I18N_CONFIG_PATH) || await client.readFile(I18N_CONFIG_PATH)) {
|
|
147
|
+
const snapshot = await listRepoFiles(c);
|
|
148
|
+
const combined = new Map(Object.entries(snapshot).map(([path, file]) => [path, { path, content: file.content }]));
|
|
149
|
+
for (const file of files)
|
|
150
|
+
combined.set(file.path, file);
|
|
151
|
+
for (const path of deletions)
|
|
152
|
+
combined.delete(path);
|
|
153
|
+
translation = await translateWebsite(combined, c.env);
|
|
154
|
+
}
|
|
132
155
|
}
|
|
133
|
-
|
|
134
|
-
?
|
|
135
|
-
: uploadedFile.name;
|
|
136
|
-
const name = sanitizeFilename(rawName);
|
|
137
|
-
const mimeType = uploadedFile.type || getStaticMimeType(name) || 'application/octet-stream';
|
|
138
|
-
const arrayBuffer = await uploadedFile.arrayBuffer();
|
|
139
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
140
|
-
let binaryString = '';
|
|
141
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
142
|
-
binaryString += String.fromCharCode(bytes[i]);
|
|
156
|
+
catch (error) {
|
|
157
|
+
return c.json({ error: error instanceof Error ? error.message : 'Website translation failed. Your changes have not been published.' }, 422);
|
|
143
158
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
path,
|
|
150
|
-
name,
|
|
151
|
-
mimeType,
|
|
152
|
-
contentBase64,
|
|
153
|
-
size: uploadedFile.size,
|
|
154
|
-
});
|
|
159
|
+
const output = new Map(files.map(file => [file.path, file]));
|
|
160
|
+
if (translation)
|
|
161
|
+
output.set(translation.path, translation);
|
|
162
|
+
const commitSha = await client.writeFilesAtomic([...output.values()], String(body.message || 'Publish website changes'), baseCommitSha, deletions.filter(path => !output.has(path)));
|
|
163
|
+
return c.json({ success: true, commitSha, generatedFiles: translation ? [translation] : [] });
|
|
155
164
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import { HonoEnv } from '../../../index';
|
|
2
|
+
import type { HonoEnv } from '../../../index';
|
|
3
3
|
declare const authRoutes: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
|
|
4
4
|
export default authRoutes;
|
|
5
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;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,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,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAM9C,QAAA,MAAM,UAAU,sDAAsB,CAAC;AAcvC,eAAe,UAAU,CAAC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
import { login, logout } from '../handlers/auth.handler';
|
|
3
|
+
import { requestPasswordReset, completePasswordReset } from '../handlers/recovery.handler';
|
|
4
|
+
import { bodyLimit } from 'hono/body-limit';
|
|
5
|
+
import { authMiddleware } from '../../../middleware/auth';
|
|
3
6
|
const authRoutes = new Hono();
|
|
4
|
-
authRoutes.post('/
|
|
7
|
+
authRoutes.post('/password-reset/request', bodyLimit({ maxSize: 4096 }), requestPasswordReset);
|
|
8
|
+
authRoutes.post('/password-reset/complete', bodyLimit({ maxSize: 4096 }), completePasswordReset);
|
|
9
|
+
authRoutes.post('/login', bodyLimit({ maxSize: 4096 }), login);
|
|
5
10
|
authRoutes.post('/logout', logout);
|
|
6
|
-
authRoutes.get('/me', (c) => {
|
|
11
|
+
authRoutes.get('/me', authMiddleware, (c) => {
|
|
7
12
|
const user = c.get('user');
|
|
8
13
|
if (user) {
|
|
9
14
|
return c.json({ success: true, user });
|
|
@@ -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;
|
|
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;AAe5B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,QAAA,MAAM,SAAS,sDAAsB,CAAC;AA6BtC,eAAe,SAAS,CAAC"}
|
|
@@ -2,13 +2,12 @@ import { Hono } from 'hono';
|
|
|
2
2
|
import { getDashboard } from '../handlers/dashboard.handler';
|
|
3
3
|
import { authMiddleware } from '../../../middleware/auth';
|
|
4
4
|
import authRoutes from './auth.routes';
|
|
5
|
-
import { createAdminUser, deleteAdminUser, listAdminUsers, patchAdminUser } from '../handlers/admin-users.handler';
|
|
6
|
-
import { deleteConversation, listConversations, upsertConversation } from '../handlers/agent-conversations.handler';
|
|
5
|
+
import { createAdminUser, deleteAdminUser, listAdminUsers, patchAdminUser, sendUserRecovery } from '../handlers/admin-users.handler';
|
|
7
6
|
import { getAgentConfig, proxyAgentRequest } from '../handlers/agent-provider.handler';
|
|
8
|
-
import { commitWebsiteRepo, headWebsiteRepo, syncWebsiteRepo
|
|
9
|
-
import { getWebsiteTemplateFile, getWebsiteTemplateManifest, listWebsiteTemplates } from '../handlers/website-templates.handler';
|
|
7
|
+
import { commitWebsiteRepo, getWebsiteAsset, headWebsiteRepo, syncWebsiteRepo } from '../handlers/website-repo.handler';
|
|
10
8
|
import { deleteGitHubSecret, listGitHubSecrets, upsertGitHubSecret } from '../handlers/github-secrets.handler';
|
|
11
9
|
import { setupContext, setupProject } from '../handlers/setup.handler';
|
|
10
|
+
import { testIntegration, testSetupIntegration } from '../handlers/integrations.handler';
|
|
12
11
|
const cmsRoutes = new Hono();
|
|
13
12
|
// Dashboard route (protected)
|
|
14
13
|
cmsRoutes.get('/', authMiddleware, getDashboard);
|
|
@@ -16,24 +15,21 @@ cmsRoutes.get('/', authMiddleware, getDashboard);
|
|
|
16
15
|
cmsRoutes.route('/', authRoutes);
|
|
17
16
|
cmsRoutes.get('/setup', setupContext);
|
|
18
17
|
cmsRoutes.post('/setup', setupProject);
|
|
18
|
+
cmsRoutes.post('/setup/integrations/:provider/test', testSetupIntegration);
|
|
19
19
|
// Protected routes
|
|
20
20
|
cmsRoutes.use('/*', authMiddleware);
|
|
21
21
|
cmsRoutes.get('/users', listAdminUsers);
|
|
22
22
|
cmsRoutes.post('/users', createAdminUser);
|
|
23
|
+
cmsRoutes.post('/users/:id/recovery', sendUserRecovery);
|
|
23
24
|
cmsRoutes.patch('/users/:id', patchAdminUser);
|
|
24
25
|
cmsRoutes.delete('/users/:id', deleteAdminUser);
|
|
25
|
-
cmsRoutes.get('/agent/conversations', listConversations);
|
|
26
|
-
cmsRoutes.post('/agent/conversations', upsertConversation);
|
|
27
|
-
cmsRoutes.delete('/agent/conversations/:id', deleteConversation);
|
|
28
26
|
cmsRoutes.get('/agent/config', getAgentConfig);
|
|
29
27
|
cmsRoutes.all('/agent/llm/:path{.+}', proxyAgentRequest);
|
|
30
28
|
cmsRoutes.get('/website/repo/head', headWebsiteRepo);
|
|
31
29
|
cmsRoutes.get('/website/repo/sync', syncWebsiteRepo);
|
|
32
30
|
cmsRoutes.put('/website/repo/commit', commitWebsiteRepo);
|
|
33
|
-
cmsRoutes.
|
|
34
|
-
cmsRoutes.
|
|
35
|
-
cmsRoutes.get('/website/templates/:templateId/:version/manifest', getWebsiteTemplateManifest);
|
|
36
|
-
cmsRoutes.get('/website/templates/:templateId/:version/files/*', getWebsiteTemplateFile);
|
|
31
|
+
cmsRoutes.get('/website/repo/assets/:path{.+}', getWebsiteAsset);
|
|
32
|
+
cmsRoutes.post('/integrations/:provider/test', testIntegration);
|
|
37
33
|
cmsRoutes.get('/github/secrets', listGitHubSecrets);
|
|
38
34
|
cmsRoutes.put('/github/secrets/:name', upsertGitHubSecret);
|
|
39
35
|
cmsRoutes.delete('/github/secrets/:name', deleteGitHubSecret);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaigns.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/campaigns.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsB/B,qCAAqC;AACrC,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWhE;AAED,yCAAyC;AACzC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW/D;AAED,sCAAsC;AACtC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBlE;AAED,2CAA2C;AAC3C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2BlE;AAED,4CAA4C;AAC5C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYlE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"campaigns.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/campaigns.handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsB/B,qCAAqC;AACrC,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWhE;AAED,yCAAyC;AACzC,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW/D;AAED,sCAAsC;AACtC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBlE;AAED,2CAA2C;AAC3C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2BlE;AAED,4CAA4C;AAC5C,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYlE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6DhE;AAED,+CAA+C;AAC/C,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8BhE"}
|
|
@@ -138,8 +138,10 @@ export async function sendCampaign(c) {
|
|
|
138
138
|
return c.json({ success: false, message: 'No subscribed contacts found' }, 400);
|
|
139
139
|
}
|
|
140
140
|
const now = Date.now();
|
|
141
|
-
const sendId = createId('snd');
|
|
142
141
|
const { settings, logoDataUrl } = await readEmailTemplateData(c.env);
|
|
142
|
+
if (settings.automation?.newsletterEnabled === false) {
|
|
143
|
+
return c.json({ success: false, message: 'Newsletters are disabled.' }, 403);
|
|
144
|
+
}
|
|
143
145
|
let sentCount = 0;
|
|
144
146
|
let lastError;
|
|
145
147
|
const origin = new URL(c.req.url).origin;
|
|
@@ -168,9 +170,6 @@ export async function sendCampaign(c) {
|
|
|
168
170
|
const status = sentCount > 0 ? 'sent' : 'failed';
|
|
169
171
|
// Update campaign status
|
|
170
172
|
await db.prepare('UPDATE campaigns SET status = ?, recipient_count = ?, sent_at = ?, updated_at = ? WHERE id = ?').bind(status, sentCount, now, now, id).run();
|
|
171
|
-
// Record send history
|
|
172
|
-
await db.prepare(`INSERT INTO email_sends (id, type, campaign_id, subject, recipient_count, status, error, sent_at, created_at)
|
|
173
|
-
VALUES (?, 'campaign', ?, ?, ?, ?, ?, ?, ?)`).bind(sendId, id, row.subject, sentCount, status, lastError ?? null, now, now).run();
|
|
174
173
|
return c.json({ success: true, recipientCount: sentCount });
|
|
175
174
|
}
|
|
176
175
|
catch (error) {
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
* Optionally provide logo (base64 data URL) and invoice company styling.
|
|
10
|
-
*/
|
|
11
|
-
export declare function generateInvoicePdf(config: InvoiceConfig, data: InvoiceData, branding?: {
|
|
12
|
-
logo?: string;
|
|
13
|
-
companyName?: string;
|
|
14
|
-
primaryColor?: string;
|
|
15
|
-
}): Promise<Uint8Array>;
|
|
1
|
+
import { type Brand, type InvoiceDesign, type InvoiceConfig, type InvoiceData } from '@hintergrund/runtime-contracts';
|
|
2
|
+
export interface InvoiceAssets {
|
|
3
|
+
logo?: Uint8Array;
|
|
4
|
+
bodyFont?: Uint8Array;
|
|
5
|
+
displayFont?: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
/** Same deterministic renderer for preview, downloads and email attachments. */
|
|
8
|
+
export declare function generateInvoicePdf(config: InvoiceConfig, data: InvoiceData, brand: Brand, design: InvoiceDesign, assets?: InvoiceAssets): Promise<Uint8Array>;
|
|
16
9
|
//# sourceMappingURL=invoice.handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/invoice.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invoice.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/invoice.handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwC,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE5J,MAAM,WAAW,aAAa;IAAG,IAAI,CAAC,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,UAAU,CAAA;CAAE;AAErG,gFAAgF;AAChF,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4GvK"}
|