@hintergrund/worker 0.2.2 → 0.3.0
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 -74
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts +0 -1
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/agent-conversations.handler.js +0 -7
- package/dist/api/cms/handlers/agent-provider.handler.d.ts +12 -0
- package/dist/api/cms/handlers/agent-provider.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/agent-provider.handler.js +64 -0
- 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 -62
- 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 +3 -4
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.js +12 -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 +159 -29
- package/dist/api/cms/handlers/website-repo.handler.d.ts +2 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +124 -16
- package/dist/api/cms/handlers/website-templates.handler.d.ts +2 -0
- package/dist/api/cms/handlers/website-templates.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-templates.handler.js +22 -2
- 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 +14 -9
- 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 +38 -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-events.routes.d.ts +5 -0
- package/dist/api/emails/routes/mail-events.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/mail-events.routes.js +29 -0
- 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 +30 -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 +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -22
- package/dist/lib/brand.d.ts +6 -0
- package/dist/lib/brand.d.ts.map +1 -0
- package/dist/lib/brand.js +29 -0
- package/dist/lib/config.d.ts +5 -11
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +21 -39
- package/dist/lib/email-template.d.ts +2 -5
- package/dist/lib/email-template.d.ts.map +1 -1
- package/dist/lib/email-template.js +6 -27
- 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/launch-draft.d.ts +14 -0
- package/dist/lib/launch-draft.d.ts.map +1 -0
- package/dist/lib/launch-draft.js +45 -0
- package/dist/lib/launch.d.ts +3 -0
- package/dist/lib/launch.d.ts.map +1 -0
- package/dist/lib/launch.js +18 -0
- package/dist/lib/mail-schema.d.ts +5 -0
- package/dist/lib/mail-schema.d.ts.map +1 -0
- package/dist/lib/mail-schema.js +62 -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 +5 -4
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +27 -42
- package/dist/lib/template-installer.d.ts +9 -0
- package/dist/lib/template-installer.d.ts.map +1 -0
- package/dist/lib/template-installer.js +97 -0
- 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 +5 -3
- 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,11 +2,15 @@ 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
|
-
|
|
10
|
+
import { AGENT_PROVIDERS, AGENT_PROVIDER_SECRETS, BRAND_CSS_PATH, BRAND_PATH, SETUP_PATH as WEBSITE_SETUP_PATH, SHOP_SETTINGS_PATH, DEFAULT_BRAND, brandCss, normalizeProjectGoals, subscriptionAutomation, validateBrand, DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
|
|
11
|
+
import { installSetupTemplate, setupTemplateCatalog } from '../../../lib/template-installer';
|
|
12
|
+
import { validateI18nConfig, DEFAULT_I18N_CONFIG } from '@hintergrund/runtime-contracts';
|
|
13
|
+
import { initializeWebsiteLanguages } from '../../../lib/website-i18n';
|
|
10
14
|
const DEFAULT_SHOP_SETTINGS = {
|
|
11
15
|
currency: 'eur',
|
|
12
16
|
enabledPaymentMethods: ['bank_transfer'],
|
|
@@ -47,7 +51,14 @@ export async function setupContext(c) {
|
|
|
47
51
|
return c.json({ error: 'Project setup has already been completed.' }, 409);
|
|
48
52
|
if (!(await hasValidSetupToken(c.env, c.req.query('token'))))
|
|
49
53
|
return c.json({ error: 'Invalid setup link.' }, 403);
|
|
50
|
-
|
|
54
|
+
try {
|
|
55
|
+
const catalog = await setupTemplateCatalog(c.env.TEMPLATE_REGISTRY_URL);
|
|
56
|
+
return c.json({ suggestedEmail: c.env.SETUP_ADMIN_EMAIL?.trim() || undefined, templates: catalog.templates });
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Setup template catalog failed:', error);
|
|
60
|
+
return c.json({ error: 'Website templates are temporarily unavailable.' }, 503);
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
export async function setupProject(c) {
|
|
53
64
|
if (await hasAdminUsers(c))
|
|
@@ -56,29 +67,98 @@ export async function setupProject(c) {
|
|
|
56
67
|
if (!(await hasValidSetupToken(c.env, body.setupToken)))
|
|
57
68
|
return c.json({ error: 'Invalid setup link.' }, 403);
|
|
58
69
|
const email = typeof body.email === 'string' ? body.email.trim().toLowerCase() : '';
|
|
59
|
-
|
|
70
|
+
if (!body.goals || typeof body.goals !== 'object' || Array.isArray(body.goals)
|
|
71
|
+
|| typeof body.goals.sell !== 'boolean'
|
|
72
|
+
|| typeof body.goals.newsletters !== 'boolean') {
|
|
73
|
+
return c.json({ error: 'Choose your project goals.' }, 400);
|
|
74
|
+
}
|
|
75
|
+
let languages;
|
|
76
|
+
try {
|
|
77
|
+
languages = validateI18nConfig(body.languages ?? DEFAULT_I18N_CONFIG);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return c.json({ error: error instanceof Error ? error.message : 'Invalid website languages.' }, 400);
|
|
81
|
+
}
|
|
82
|
+
const goals = normalizeProjectGoals(body.goals);
|
|
83
|
+
const needsEmail = goals.sell || goals.newsletters;
|
|
84
|
+
const MIN_PASSWORD_LENGTH = 12;
|
|
60
85
|
const password = typeof body.password === 'string' ? body.password : '';
|
|
61
86
|
const plunkApiKey = typeof body.plunkApiKey === 'string' ? body.plunkApiKey.trim() : '';
|
|
62
87
|
const fromEmail = typeof body.fromEmail === 'string' ? body.fromEmail.trim() : '';
|
|
63
88
|
const paymentProvider = body.paymentProvider === 'stripe' || body.paymentProvider === 'bank_transfer' ? body.paymentProvider : null;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
89
|
+
const agentProvider = typeof body.agentProvider === 'string' && AGENT_PROVIDERS.includes(body.agentProvider) ? body.agentProvider : null;
|
|
90
|
+
const agentProviderKey = typeof body.agentProviderKey === 'string' ? body.agentProviderKey.trim() : '';
|
|
91
|
+
const templateId = typeof body.templateId === 'string' ? body.templateId.trim() : '';
|
|
92
|
+
const templateVersion = typeof body.templateVersion === 'string' ? body.templateVersion.trim() : '';
|
|
93
|
+
let logo = null;
|
|
94
|
+
if (body.logo !== undefined && body.logo !== null) {
|
|
95
|
+
try {
|
|
96
|
+
const input = body.logo;
|
|
97
|
+
if (typeof input.content !== 'string' || input.content.length > 2_800_000 || !/^[A-Za-z0-9+/]*={0,2}$/.test(input.content))
|
|
98
|
+
throw new Error();
|
|
99
|
+
const bytes = atob(input.content);
|
|
100
|
+
if (bytes.length > 2 * 1024 * 1024 || bytes.length < 8)
|
|
101
|
+
throw new Error();
|
|
102
|
+
const png = input.mimeType === 'image/png' && bytes.startsWith('\x89PNG\r\n\x1a\n');
|
|
103
|
+
const jpeg = input.mimeType === 'image/jpeg' && bytes.charCodeAt(0) === 255 && bytes.charCodeAt(1) === 216 && bytes.charCodeAt(2) === 255;
|
|
104
|
+
if (!png && !jpeg)
|
|
105
|
+
throw new Error();
|
|
106
|
+
logo = { content: input.content, path: `frontend/static/brand/logo.${png ? 'png' : 'jpg'}` };
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return c.json({ error: 'Use a valid PNG or JPEG logo up to 2 MB.' }, 400);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let brand;
|
|
113
|
+
try {
|
|
114
|
+
brand = validateBrand({ ...DEFAULT_BRAND, colors: body.brandColors, bodyFont: body.bodyFont ?? DEFAULT_BRAND.bodyFont, displayFont: body.displayFont ?? DEFAULT_BRAND.displayFont, cornerRadius: body.cornerRadius ?? DEFAULT_BRAND.cornerRadius, logoPath: logo?.path ?? null });
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return c.json({ error: 'Choose valid brand colors, fonts and corners.' }, 400);
|
|
118
|
+
}
|
|
119
|
+
const invoiceInput = body.invoice && typeof body.invoice === 'object' && !Array.isArray(body.invoice) ? body.invoice : {};
|
|
120
|
+
const invoice = { companyName: '', companyAddress: '', companyEmail: '', companyPhone: '', dueDays: 14 };
|
|
121
|
+
for (const key of ['companyName', 'companyAddress', 'companyEmail', 'companyPhone']) {
|
|
122
|
+
if (typeof invoiceInput[key] === 'string')
|
|
123
|
+
invoice[key] = invoiceInput[key].trim().slice(0, 4000);
|
|
124
|
+
}
|
|
125
|
+
if (goals.sell && (!invoice.companyName || !invoice.companyAddress))
|
|
126
|
+
return c.json({ error: 'Enter your business name and address for invoices.' }, 400);
|
|
127
|
+
const footerText = typeof body.footerText === 'string' ? body.footerText.trim().slice(0, 8000) : 'If you have any questions, please contact us.';
|
|
128
|
+
const footerHtml = `<p>${footerText.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\n', '<br>')}</p>`;
|
|
129
|
+
if (!email)
|
|
130
|
+
return c.json({ error: 'An email address is required.' }, 400);
|
|
131
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
132
|
+
return c.json({ error: `Choose a password of at least ${MIN_PASSWORD_LENGTH} characters.` }, 400);
|
|
133
|
+
}
|
|
134
|
+
if (needsEmail && (!plunkApiKey || !fromEmail)) {
|
|
135
|
+
return c.json({ error: 'An email provider API key and sender address are required.' }, 400);
|
|
136
|
+
}
|
|
137
|
+
if (!agentProvider || !agentProviderKey)
|
|
138
|
+
return c.json({ error: 'Choose an AI provider and enter its API key.' }, 400);
|
|
139
|
+
if (!templateId || !templateVersion)
|
|
140
|
+
return c.json({ error: 'Choose a website template.' }, 400);
|
|
141
|
+
if (goals.sell && !paymentProvider)
|
|
72
142
|
return c.json({ error: 'Choose a payment provider.' }, 400);
|
|
73
143
|
const bankTransfer = typeof body.bankTransfer === 'object' && body.bankTransfer !== null ? body.bankTransfer : {};
|
|
74
144
|
const accountHolder = typeof bankTransfer.accountHolder === 'string' ? bankTransfer.accountHolder.trim() : '';
|
|
75
145
|
const iban = typeof bankTransfer.iban === 'string' ? bankTransfer.iban.trim() : '';
|
|
76
|
-
const stripeSecretKey = paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
|
|
77
|
-
if (paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
|
|
146
|
+
const stripeSecretKey = goals.sell && paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
|
|
147
|
+
if (goals.sell && paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
|
|
78
148
|
return c.json({ error: 'An account holder and IBAN are required for bank transfers.' }, 400);
|
|
79
149
|
}
|
|
80
|
-
if (paymentProvider === 'stripe' && !stripeSecretKey)
|
|
150
|
+
if (goals.sell && paymentProvider === 'stripe' && !stripeSecretKey) {
|
|
81
151
|
return c.json({ error: 'Your Stripe secret key is required for card payments.' }, 400);
|
|
152
|
+
}
|
|
153
|
+
// Validate credentials before creating an administrator or changing the repository.
|
|
154
|
+
const health = await Promise.all([
|
|
155
|
+
checkIntegrationKey(agentProvider, agentProviderKey),
|
|
156
|
+
...(needsEmail ? [checkIntegrationKey('plunk', plunkApiKey)] : []),
|
|
157
|
+
...(stripeSecretKey ? [checkIntegrationKey('stripe', stripeSecretKey)] : []),
|
|
158
|
+
]);
|
|
159
|
+
const failed = health.find(result => !result.valid);
|
|
160
|
+
if (failed)
|
|
161
|
+
return c.json({ error: failed.message }, 400);
|
|
82
162
|
// Do not consume the one-time setup route until GitHub is reachable. A project
|
|
83
163
|
// without its repository cannot complete setup and must remain retryable.
|
|
84
164
|
let client;
|
|
@@ -90,21 +170,35 @@ export async function setupProject(c) {
|
|
|
90
170
|
console.error('Project setup GitHub preflight failed:', error);
|
|
91
171
|
return c.json({ error: 'GitHub repository is unavailable. Check the project GitHub App configuration and try again.' }, 503);
|
|
92
172
|
}
|
|
173
|
+
// Translation is the longest setup operation. Finish it before consuming the
|
|
174
|
+
// setup link so a timeout/disconnect cannot leave a half-created administrator.
|
|
175
|
+
let staged;
|
|
176
|
+
try {
|
|
177
|
+
staged = await installSetupTemplate(client, templateId, templateVersion, c.env.TEMPLATE_REGISTRY_URL, true);
|
|
178
|
+
await initializeWebsiteLanguages(staged.files, languages, {
|
|
179
|
+
...c.env, GEMINI_API_KEY: agentProvider === 'google' ? agentProviderKey : undefined,
|
|
180
|
+
DEEPSEEK_API_KEY: agentProvider === 'deepseek' ? agentProviderKey : undefined,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
console.error('Setup template translation failed:', error);
|
|
185
|
+
return c.json({ error: `Website preparation failed: ${error instanceof Error ? error.message : 'Please retry.'} No administrator was created.` }, 502);
|
|
186
|
+
}
|
|
93
187
|
const db = await ensureSchema(c.env);
|
|
94
188
|
const now = nowSeconds();
|
|
95
189
|
const user = {
|
|
96
190
|
id: createId('user'),
|
|
97
191
|
email,
|
|
98
192
|
name: null,
|
|
99
|
-
|
|
100
|
-
|
|
193
|
+
password_hash: await hashPw(password, c.env.SECRET ?? ''),
|
|
194
|
+
initial_admin: 1,
|
|
101
195
|
disabled_at: null,
|
|
102
196
|
created_at: now,
|
|
103
197
|
updated_at: now,
|
|
104
198
|
};
|
|
105
199
|
try {
|
|
106
|
-
await db.prepare(`INSERT INTO admin_users (id, email, password_hash, login_method, initial_admin, disabled_at, created_at, updated_at) VALUES (?, ?, ?,
|
|
107
|
-
.bind(user.id, user.email, user.password_hash,
|
|
200
|
+
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, ?, ?)`)
|
|
201
|
+
.bind(user.id, user.email, user.password_hash, now, now).run();
|
|
108
202
|
}
|
|
109
203
|
catch (error) {
|
|
110
204
|
console.error('Initial admin creation failed', error);
|
|
@@ -120,25 +214,49 @@ export async function setupProject(c) {
|
|
|
120
214
|
});
|
|
121
215
|
stripeWebhookSecret = webhook.secret ?? '';
|
|
122
216
|
}
|
|
123
|
-
catch
|
|
124
|
-
|
|
217
|
+
catch {
|
|
218
|
+
throw new Error('Stripe webhook configuration failed. Check webhook permissions on the Stripe key.');
|
|
125
219
|
}
|
|
126
220
|
}
|
|
221
|
+
// Setup keeps the selected website private in D1 until the explicit first launch.
|
|
222
|
+
const stageConfig = async (_client, path, value, _message, _sha) => {
|
|
223
|
+
staged.files.push({ path, content: JSON.stringify(value, null, 2), encoding: 'utf8' });
|
|
224
|
+
};
|
|
225
|
+
if (logo)
|
|
226
|
+
staged.files.push({ path: logo.path, content: logo.content, encoding: 'base64' });
|
|
227
|
+
staged.files.push(...[
|
|
228
|
+
{ path: BRAND_PATH, content: JSON.stringify(brand, null, 2) },
|
|
229
|
+
{ path: BRAND_CSS_PATH, content: brandCss(brand) },
|
|
230
|
+
]);
|
|
127
231
|
const secrets = {};
|
|
128
232
|
for (const [name, value] of [
|
|
129
|
-
['API_KEY', plunkApiKey],
|
|
233
|
+
['API_KEY', needsEmail ? plunkApiKey : ''],
|
|
130
234
|
['STRIPE_SECRET_KEY', stripeSecretKey],
|
|
131
|
-
['STRIPE_WEBHOOK_SECRET', stripeWebhookSecret],
|
|
235
|
+
['STRIPE_WEBHOOK_SECRET', goals.sell && paymentProvider === 'stripe' ? stripeWebhookSecret : ''],
|
|
236
|
+
[AGENT_PROVIDER_SECRETS[agentProvider], agentProviderKey],
|
|
132
237
|
]) {
|
|
133
238
|
if (typeof value === 'string' && value)
|
|
134
239
|
secrets[name] = value;
|
|
135
240
|
}
|
|
136
241
|
await Promise.all(Object.entries(secrets).map(([secretName, value]) => client.setActionsSecret(secretName, value)));
|
|
242
|
+
const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_SETUP_PATH, {});
|
|
243
|
+
delete setupState.modules;
|
|
244
|
+
await stageConfig(client, WEBSITE_SETUP_PATH, {
|
|
245
|
+
...setupState,
|
|
246
|
+
version: 1,
|
|
247
|
+
complete: true,
|
|
248
|
+
goals,
|
|
249
|
+
template: { id: templateId, version: templateVersion },
|
|
250
|
+
updatedAt: Date.now(),
|
|
251
|
+
}, 'Record project goals [skip ci]', setupCommitSha);
|
|
137
252
|
const { data: shopSettings, commitSha: shopCommitSha } = await readJsonConfig(client, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS);
|
|
138
|
-
await
|
|
253
|
+
await stageConfig(client, SHOP_SETTINGS_PATH, {
|
|
139
254
|
...DEFAULT_SHOP_SETTINGS,
|
|
140
255
|
...shopSettings,
|
|
141
|
-
|
|
256
|
+
// No shop means no payment method was chosen; leave it empty rather than
|
|
257
|
+
// implying the shipped default was a decision.
|
|
258
|
+
enabledPaymentMethods: goals.sell && paymentProvider ? [paymentProvider] : [],
|
|
259
|
+
...(goals.sell ? { emailTemplates: { ...DEFAULT_SHOP_EMAIL_TEMPLATES, ...shopSettings.emailTemplates } } : {}),
|
|
142
260
|
bankTransfer: {
|
|
143
261
|
...DEFAULT_SHOP_SETTINGS.bankTransfer,
|
|
144
262
|
...(shopSettings.bankTransfer ?? {}),
|
|
@@ -150,14 +268,29 @@ export async function setupProject(c) {
|
|
|
150
268
|
},
|
|
151
269
|
}, 'Configure bank transfer payments [skip ci]', shopCommitSha);
|
|
152
270
|
const { data: emailSettings, commitSha } = await readJsonConfig(client, EMAIL_SETTINGS_PATH, DEFAULT_EMAIL_SETTINGS);
|
|
153
|
-
await
|
|
271
|
+
await stageConfig(client, EMAIL_SETTINGS_PATH, {
|
|
154
272
|
...emailSettings,
|
|
273
|
+
invoice,
|
|
274
|
+
footerHtml,
|
|
275
|
+
automation: subscriptionAutomation(goals.newsletters, emailSettings.automation),
|
|
155
276
|
fromEmail: typeof body.fromEmail === 'string' ? body.fromEmail.trim() : emailSettings.fromEmail,
|
|
156
277
|
fromName: typeof body.fromName === 'string' ? body.fromName.trim() : emailSettings.fromName,
|
|
157
278
|
replyTo: typeof body.replyTo === 'string' ? body.replyTo.trim() : emailSettings.replyTo,
|
|
158
279
|
updatedAt: Date.now(),
|
|
159
280
|
}, 'Configure email sender settings [skip ci]', commitSha);
|
|
281
|
+
const baseCommitSha = await client.getCommitSha();
|
|
282
|
+
// Deploy secrets/admin runtime against the existing scaffold, never the draft website.
|
|
160
283
|
await deploy(c, client);
|
|
284
|
+
const token = await signWithPayload(c.env.SECRET ?? '', await issueSessionForUser({ ...user, password_hash: user.password_hash }));
|
|
285
|
+
const secureCookie = c.req.url.startsWith('https://') ? '; Secure' : '';
|
|
286
|
+
return c.json({
|
|
287
|
+
success: true,
|
|
288
|
+
draft: {
|
|
289
|
+
files: staged.files,
|
|
290
|
+
deletions: staged.deletions,
|
|
291
|
+
baseCommitSha,
|
|
292
|
+
},
|
|
293
|
+
}, 201, { 'Set-Cookie': `token=${token}; HttpOnly; Path=/; SameSite=Strict${secureCookie}` });
|
|
161
294
|
}
|
|
162
295
|
catch (error) {
|
|
163
296
|
console.error('Project setup integrations could not be saved:', error);
|
|
@@ -169,9 +302,6 @@ export async function setupProject(c) {
|
|
|
169
302
|
}
|
|
170
303
|
return c.json({ error: 'Project setup could not be completed. No administrator was created; fix the integration error and try again.' }, 502);
|
|
171
304
|
}
|
|
172
|
-
const token = await signWithPayload(c.env.SECRET ?? '', issueSessionForUser({ ...user, password_hash: user.password_hash }));
|
|
173
|
-
const secureCookie = c.req.url.startsWith('https://') ? '; Secure' : '';
|
|
174
|
-
return c.json({ success: true }, 201, { 'Set-Cookie': `token=${token}; HttpOnly; Path=/; SameSite=Strict${secureCookie}` });
|
|
175
305
|
}
|
|
176
306
|
export async function projectNeedsSetup(c) {
|
|
177
307
|
return !(await hasAdminUsers(c));
|
|
@@ -1,6 +1,8 @@
|
|
|
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>;
|
|
@@ -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;AAuC9C,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,CAO5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAe5E;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyF9E;AASD,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6C/E"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { getGitHubConfig } from '../../../lib/config';
|
|
2
2
|
import { createGitHubClient } from '../../../lib/github';
|
|
3
|
+
import { isLaunchPending } from '../../../lib/launch';
|
|
4
|
+
import { I18N_CONFIG_PATH, launchTasks, LAUNCH_PATH, launchJson, SETUP_PATH, SHOP_SETTINGS_PATH, STATIC_DIR, isWebsitePath } from '@hintergrund/runtime-contracts';
|
|
5
|
+
import { checkIntegrationKey } from '../../../lib/integration-health';
|
|
6
|
+
import { translateWebsite } from '../../../lib/website-i18n';
|
|
3
7
|
const STATIC_MIME_TYPES = {
|
|
4
8
|
'.jpg': 'image/jpeg',
|
|
5
9
|
'.jpeg': 'image/jpeg',
|
|
@@ -8,8 +12,18 @@ const STATIC_MIME_TYPES = {
|
|
|
8
12
|
'.svg': 'image/svg+xml',
|
|
9
13
|
'.webp': 'image/webp',
|
|
10
14
|
'.ico': 'image/x-icon',
|
|
15
|
+
'.avif': 'image/avif',
|
|
16
|
+
'.bmp': 'image/bmp',
|
|
17
|
+
'.woff': 'font/woff',
|
|
18
|
+
'.woff2': 'font/woff2',
|
|
19
|
+
'.ttf': 'font/ttf',
|
|
20
|
+
'.otf': 'font/otf',
|
|
11
21
|
};
|
|
12
22
|
const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
|
|
23
|
+
function integrationStatus(c) {
|
|
24
|
+
const configured = (value) => !!value?.trim() && value !== 'NOT_CONFIGURED';
|
|
25
|
+
return { plunk: configured(c.env.API_KEY || c.env.PLUNK_SECRET_KEY), stripe: configured(c.env.STRIPE_SECRET_KEY), stripeWebhook: configured(c.env.STRIPE_WEBHOOK_SECRET) };
|
|
26
|
+
}
|
|
13
27
|
function getStaticMimeType(path) {
|
|
14
28
|
const ext = path.slice(((path.lastIndexOf('.') - 1) >>> 0) + 2).toLowerCase();
|
|
15
29
|
return STATIC_MIME_TYPES['.' + ext] ?? null;
|
|
@@ -18,10 +32,7 @@ function normalizePath(path) {
|
|
|
18
32
|
return path.replace(/^\/+/, '').replace(/\\/g, '/');
|
|
19
33
|
}
|
|
20
34
|
export function isAllowedWebsitePath(path) {
|
|
21
|
-
|
|
22
|
-
if (normalized.includes('..'))
|
|
23
|
-
return false;
|
|
24
|
-
return normalized.startsWith('frontend/');
|
|
35
|
+
return isWebsitePath(normalizePath(path));
|
|
25
36
|
}
|
|
26
37
|
async function listRepoFiles(c) {
|
|
27
38
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
@@ -48,33 +59,68 @@ async function listStaticAssets(c) {
|
|
|
48
59
|
const assetPaths = tree.data.tree
|
|
49
60
|
.filter((item) => item.type === 'blob' &&
|
|
50
61
|
item.path &&
|
|
51
|
-
item.path.startsWith(
|
|
62
|
+
item.path.startsWith(STATIC_DIR) &&
|
|
52
63
|
getStaticMimeType(item.path) !== null)
|
|
53
|
-
.map((item) => item.path);
|
|
54
|
-
return assetPaths.map((path) => {
|
|
64
|
+
.map((item) => ({ path: item.path, sha: item.sha }));
|
|
65
|
+
return assetPaths.map(({ path, sha }) => {
|
|
55
66
|
const name = path.split('/').pop();
|
|
56
67
|
const mimeType = getStaticMimeType(path);
|
|
57
|
-
return { name, path, content: '', mimeType };
|
|
68
|
+
return { name, path, content: '', mimeType, sha };
|
|
58
69
|
});
|
|
59
70
|
}
|
|
71
|
+
/** Admin-only access to Git-backed images, including before the next site deployment. */
|
|
72
|
+
export async function getWebsiteAsset(c) {
|
|
73
|
+
const path = c.req.param('path') || '';
|
|
74
|
+
const mimeType = getStaticMimeType(path);
|
|
75
|
+
if (!path.startsWith(STATIC_DIR) || path.split('/').some((part) => !part || part === '.' || part === '..') || /[\\\\\x00-\x1f]/.test(path) || !mimeType) {
|
|
76
|
+
return c.json({ error: 'Invalid static asset path' }, 400);
|
|
77
|
+
}
|
|
78
|
+
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
79
|
+
try {
|
|
80
|
+
const asset = await client.readFileBinary(path, MAX_UPLOAD_BYTES);
|
|
81
|
+
if (!asset)
|
|
82
|
+
return c.notFound();
|
|
83
|
+
const headers = {
|
|
84
|
+
'Content-Type': mimeType,
|
|
85
|
+
'Cache-Control': 'private, no-cache',
|
|
86
|
+
'ETag': `"${asset.sha}"`,
|
|
87
|
+
'X-Content-Type-Options': 'nosniff',
|
|
88
|
+
// SVGs may be opened directly; never allow repository scripts to execute.
|
|
89
|
+
'Content-Security-Policy': "default-src 'none'; sandbox",
|
|
90
|
+
};
|
|
91
|
+
if (c.req.header('If-None-Match') === headers.ETag)
|
|
92
|
+
return new Response(null, { status: 304, headers });
|
|
93
|
+
const bytes = Uint8Array.from(atob(asset.content), (char) => char.charCodeAt(0));
|
|
94
|
+
return new Response(bytes, { headers });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error instanceof RangeError)
|
|
98
|
+
return c.json({ error: 'Asset exceeds 10 MB limit' }, 413);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
60
102
|
export async function headWebsiteRepo(c) {
|
|
61
103
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
62
|
-
const commitSha = await
|
|
63
|
-
|
|
104
|
+
const [commitSha, launchPending] = await Promise.all([
|
|
105
|
+
client.getCommitSha(),
|
|
106
|
+
isLaunchPending(client),
|
|
107
|
+
]);
|
|
108
|
+
return c.json({ commitSha, launchPending, integrations: integrationStatus(c) });
|
|
64
109
|
}
|
|
65
110
|
export async function syncWebsiteRepo(c) {
|
|
66
111
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
67
|
-
const [files, commitSha, staticAssets] = await Promise.all([
|
|
112
|
+
const [files, commitSha, staticAssets, launchPending] = await Promise.all([
|
|
68
113
|
listRepoFiles(c),
|
|
69
114
|
client.getCommitSha(),
|
|
70
115
|
listStaticAssets(c),
|
|
116
|
+
isLaunchPending(client),
|
|
71
117
|
]);
|
|
72
118
|
const srcFiles = Object.entries(files).map(([path, file]) => ({
|
|
73
119
|
path,
|
|
74
120
|
content: file.content,
|
|
75
121
|
sha: file.sha,
|
|
76
122
|
}));
|
|
77
|
-
return c.json({ files, srcFiles, staticAssets, commitSha });
|
|
123
|
+
return c.json({ files, srcFiles, staticAssets, commitSha, launchPending, integrations: integrationStatus(c) });
|
|
78
124
|
}
|
|
79
125
|
export async function commitWebsiteRepo(c) {
|
|
80
126
|
const body = await c.req.json();
|
|
@@ -95,7 +141,7 @@ export async function commitWebsiteRepo(c) {
|
|
|
95
141
|
if (deletions.some((path) => writtenPaths.has(path))) {
|
|
96
142
|
return c.json({ error: 'A path cannot be written and deleted in the same commit' }, 400);
|
|
97
143
|
}
|
|
98
|
-
if (files.length === 0 && deletions.length === 0) {
|
|
144
|
+
if (files.length === 0 && deletions.length === 0 && body.launch !== true) {
|
|
99
145
|
return c.json({ error: 'No files to commit' }, 400);
|
|
100
146
|
}
|
|
101
147
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
@@ -105,8 +151,70 @@ export async function commitWebsiteRepo(c) {
|
|
|
105
151
|
return c.json({ conflict: true, message: 'Repository changed since the last sync' }, 409);
|
|
106
152
|
}
|
|
107
153
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
154
|
+
const launchPending = await isLaunchPending(client);
|
|
155
|
+
if (launchPending) {
|
|
156
|
+
if (body.launch !== true)
|
|
157
|
+
return c.json({ error: 'Complete the launch checklist and explicitly launch the website before its first Git push.' }, 422);
|
|
158
|
+
const snapshot = await listRepoFiles(c);
|
|
159
|
+
const combined = new Map(Object.entries(snapshot).map(([path, file]) => [path, { path, content: file.content }]));
|
|
160
|
+
for (const file of files)
|
|
161
|
+
combined.set(file.path, file);
|
|
162
|
+
for (const path of deletions)
|
|
163
|
+
combined.delete(path);
|
|
164
|
+
const read = (path) => combined.get(path)?.content ?? null;
|
|
165
|
+
const missing = launchTasks(read, [...combined.keys()]).filter(task => !task.complete);
|
|
166
|
+
if (missing.length)
|
|
167
|
+
return c.json({ error: `Finish launch tasks: ${missing.map(task => task.label).join(', ')}` }, 422);
|
|
168
|
+
const setup = launchJson(read, SETUP_PATH), shop = launchJson(read, SHOP_SETTINGS_PATH);
|
|
169
|
+
const checks = await Promise.all([
|
|
170
|
+
...(setup.goals?.sell || setup.goals?.newsletters ? [checkIntegrationKey('plunk', c.env.API_KEY || c.env.PLUNK_SECRET_KEY || '')] : []),
|
|
171
|
+
...(setup.goals?.sell && shop.enabledPaymentMethods?.includes('stripe') ? [checkIntegrationKey('stripe', c.env.STRIPE_SECRET_KEY || '')] : []),
|
|
172
|
+
]);
|
|
173
|
+
const failed = checks.find(check => !check.valid || check.status === 'warning');
|
|
174
|
+
if (failed)
|
|
175
|
+
return c.json({ error: failed.message }, 422);
|
|
176
|
+
if (setup.goals?.sell && shop.enabledPaymentMethods?.includes('stripe') && (!c.env.STRIPE_WEBHOOK_SECRET || c.env.STRIPE_WEBHOOK_SECRET === 'NOT_CONFIGURED'))
|
|
177
|
+
return c.json({ error: 'Configure the Stripe webhook secret before launching.' }, 422);
|
|
178
|
+
let translation;
|
|
179
|
+
try {
|
|
180
|
+
translation = await translateWebsite(combined, c.env);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return c.json({ error: error instanceof Error ? error.message : 'Website translation failed. Retry your changes.' }, 422);
|
|
184
|
+
}
|
|
185
|
+
if (translation)
|
|
186
|
+
combined.set(translation.path, translation);
|
|
187
|
+
const receipt = launchJson(read, LAUNCH_PATH);
|
|
188
|
+
const baseCommitSha = body.baseCommitSha ? String(body.baseCommitSha) : await client.getCommitSha();
|
|
189
|
+
combined.set(LAUNCH_PATH, { path: LAUNCH_PATH, content: JSON.stringify({ ...receipt, launchedAt: Date.now(), launchBaseCommitSha: baseCommitSha }, null, 2) });
|
|
190
|
+
const written = new Set(files.map(file => file.path));
|
|
191
|
+
written.add(LAUNCH_PATH);
|
|
192
|
+
if (translation)
|
|
193
|
+
written.add(translation.path);
|
|
194
|
+
const commitSha = await client.writeFilesAtomic([...combined.values()].filter(file => written.has(file.path)), 'Launch website', baseCommitSha, deletions.filter(path => !combined.has(path)));
|
|
195
|
+
return c.json({ success: true, commitSha, launched: true, generatedFiles: translation ? [translation] : [] });
|
|
196
|
+
}
|
|
197
|
+
const baseCommitSha = body.baseCommitSha ? String(body.baseCommitSha) : await client.getCommitSha();
|
|
198
|
+
let translation = null;
|
|
199
|
+
try {
|
|
200
|
+
if (files.some(file => file.path === I18N_CONFIG_PATH) || await client.readFile(I18N_CONFIG_PATH)) {
|
|
201
|
+
const snapshot = await listRepoFiles(c);
|
|
202
|
+
const combined = new Map(Object.entries(snapshot).map(([path, file]) => [path, { path, content: file.content }]));
|
|
203
|
+
for (const file of files)
|
|
204
|
+
combined.set(file.path, file);
|
|
205
|
+
for (const path of deletions)
|
|
206
|
+
combined.delete(path);
|
|
207
|
+
translation = await translateWebsite(combined, c.env);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return c.json({ error: error instanceof Error ? error.message : 'Website translation failed. Your changes have not been published.' }, 422);
|
|
212
|
+
}
|
|
213
|
+
const output = new Map(files.map(file => [file.path, file]));
|
|
214
|
+
if (translation)
|
|
215
|
+
output.set(translation.path, translation);
|
|
216
|
+
const commitSha = await client.writeFilesAtomic([...output.values()], String(body.message || 'Publish website changes'), baseCommitSha, deletions.filter(path => !output.has(path)));
|
|
217
|
+
return c.json({ success: true, commitSha, generatedFiles: translation ? [translation] : [] });
|
|
110
218
|
}
|
|
111
219
|
function sanitizeFilename(name) {
|
|
112
220
|
const lower = name.toLowerCase();
|
|
@@ -143,7 +251,7 @@ export async function uploadWebsiteAsset(c) {
|
|
|
143
251
|
}
|
|
144
252
|
const contentBase64 = btoa(binaryString);
|
|
145
253
|
const staticDir = module === 'email' ? 'emails' : module === 'shop' ? 'shop' : 'cms';
|
|
146
|
-
const path =
|
|
254
|
+
const path = `${STATIC_DIR}${staticDir}/${name}`;
|
|
147
255
|
return c.json({
|
|
148
256
|
success: true,
|
|
149
257
|
path,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { HonoEnv } from '../../../index';
|
|
3
|
+
/** Prepare source-language content before it is staged/reviewed; never writes to Git. */
|
|
4
|
+
export declare function prepareWebsiteTemplateLanguages(c: Context<HonoEnv>): Promise<Response>;
|
|
3
5
|
export declare function listWebsiteTemplates(c: Context<HonoEnv>): Promise<Response>;
|
|
4
6
|
export declare function getWebsiteTemplateManifest(c: Context<HonoEnv>): Promise<Response>;
|
|
5
7
|
export declare function getWebsiteTemplateFile(c: Context<HonoEnv>): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website-templates.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-templates.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"website-templates.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-templates.handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA6C9C,yFAAyF;AACzF,wBAAsB,+BAA+B,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc5F;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEjF;AAED,wBAAsB,0BAA0B,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKvF;AAED,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQnF"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { isWebsitePath } from '@hintergrund/runtime-contracts';
|
|
2
|
+
import { validateI18nConfig, I18N_CONFIG_PATH, I18N_CATALOG_PATH } from '@hintergrund/runtime-contracts';
|
|
3
|
+
import { initializeWebsiteLanguages } from '../../../lib/website-i18n';
|
|
1
4
|
const DEFAULT_TEMPLATE_REGISTRY_URL = 'https://hintergrund.cloud/template-registry';
|
|
2
5
|
const TEMPLATE_ID = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
3
6
|
const TEMPLATE_VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[a-z0-9.-]+)?$/i;
|
|
@@ -9,7 +12,7 @@ function validTemplate(id, version) {
|
|
|
9
12
|
}
|
|
10
13
|
function validOverlayPath(value) {
|
|
11
14
|
const path = value.replace(/^\/+/, '').replace(/\\/g, '/');
|
|
12
|
-
return
|
|
15
|
+
return isWebsitePath(path) && !path.includes('\0');
|
|
13
16
|
}
|
|
14
17
|
function encodedPath(value) {
|
|
15
18
|
return value.split('/').map(encodeURIComponent).join('/');
|
|
@@ -32,6 +35,23 @@ async function proxy(c, upstreamUrl) {
|
|
|
32
35
|
headers.set('X-Content-Type-Options', 'nosniff');
|
|
33
36
|
return new Response(upstream.body, { status: upstream.status, headers });
|
|
34
37
|
}
|
|
38
|
+
/** Prepare source-language content before it is staged/reviewed; never writes to Git. */
|
|
39
|
+
export async function prepareWebsiteTemplateLanguages(c) {
|
|
40
|
+
try {
|
|
41
|
+
const body = await c.req.json();
|
|
42
|
+
const config = validateI18nConfig(body.config);
|
|
43
|
+
if (!Array.isArray(body.files) || body.files.length > 500 || body.files.some(file => !file || typeof file.path !== 'string' || !validOverlayPath(file.path) || typeof file.content !== 'string' || file.encoding === 'base64')) {
|
|
44
|
+
return c.json({ error: 'Invalid template source files.' }, 400);
|
|
45
|
+
}
|
|
46
|
+
const files = body.files.map(file => ({ path: file.path, content: file.content, encoding: 'utf8' }));
|
|
47
|
+
const original = new Map(files.map(file => [file.path, file.content]));
|
|
48
|
+
await initializeWebsiteLanguages(files, config, c.env);
|
|
49
|
+
return c.json({ files: files.filter(file => file.content !== original.get(file.path) || [I18N_CONFIG_PATH, I18N_CATALOG_PATH].includes(file.path)) });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return c.json({ error: error instanceof Error ? error.message : 'Could not prepare template translations.' }, 422);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
35
55
|
export async function listWebsiteTemplates(c) {
|
|
36
56
|
return proxy(c, `${registryBase(c)}/catalog.json`);
|
|
37
57
|
}
|
|
@@ -45,7 +65,7 @@ export async function getWebsiteTemplateManifest(c) {
|
|
|
45
65
|
export async function getWebsiteTemplateFile(c) {
|
|
46
66
|
const id = c.req.param('templateId') || '';
|
|
47
67
|
const version = c.req.param('version') || '';
|
|
48
|
-
const filePath = c.req.param('
|
|
68
|
+
const filePath = c.req.param('path') || '';
|
|
49
69
|
if (!validTemplate(id, version) || !validOverlayPath(filePath)) {
|
|
50
70
|
return c.json({ error: 'Invalid template file path' }, 400);
|
|
51
71
|
}
|
|
@@ -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;AAiB5B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,QAAA,MAAM,SAAS,sDAAsB,CAAC;AAkCtC,eAAe,SAAS,CAAC"}
|