@hintergrund/worker 0.1.14 → 0.2.3
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 +0 -1
- package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/admin-users.handler.js +7 -27
- 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 +0 -4
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +88 -106
- package/dist/api/cms/handlers/dashboard.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/dashboard.handler.js +2 -3
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.js +37 -7
- package/dist/api/cms/handlers/setup.handler.d.ts +2 -0
- package/dist/api/cms/handlers/setup.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/setup.handler.js +111 -30
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +11 -4
- package/dist/api/cms/handlers/website-templates.handler.d.ts +6 -0
- package/dist/api/cms/handlers/website-templates.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/website-templates.handler.js +53 -0
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
- package/dist/api/cms/routes/auth.routes.js +1 -2
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +11 -5
- package/dist/hintergrund-assets.d.ts +4 -4
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +4 -4
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/lib/config.d.ts +5 -11
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +21 -36
- package/dist/lib/email.d.ts +3 -5
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +8 -25
- package/dist/lib/github-app.d.ts.map +1 -1
- package/dist/lib/github-app.js +4 -1
- package/dist/lib/github.d.ts +1 -1
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +30 -9
- package/dist/lib/jsonc.d.ts +3 -0
- package/dist/lib/jsonc.d.ts.map +1 -0
- package/dist/lib/jsonc.js +76 -0
- package/dist/lib/project-db.d.ts +4 -2
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +12 -11
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +0 -1
- package/package.json +35 -35
- package/dist/api/emails/handlers/webhook.handler.d.ts +0 -9
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/webhook.handler.js +0 -161
|
@@ -6,8 +6,9 @@ import { readJsonConfig, writeJsonConfig } 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
8
|
import { createId, ensureSchema, issueSessionForUser, nowSeconds } from '../../../lib/project-db';
|
|
9
|
+
import { resolveModuleDependencies } from '@hintergrund/runtime-contracts';
|
|
10
|
+
const WEBSITE_SETUP_PATH = 'frontend/src/lib/website/setup.json';
|
|
9
11
|
const SHOP_SETTINGS_PATH = 'frontend/src/lib/shop/settings.json';
|
|
10
|
-
const GLOBALS_PATH = 'frontend/src/lib/content/globals.json';
|
|
11
12
|
const DEFAULT_SHOP_SETTINGS = {
|
|
12
13
|
currency: 'eur',
|
|
13
14
|
enabledPaymentMethods: ['bank_transfer'],
|
|
@@ -17,43 +18,114 @@ const DEFAULT_SHOP_SETTINGS = {
|
|
|
17
18
|
orderNumberPrefix: 'ORD',
|
|
18
19
|
invoiceNumberPrefix: 'INV',
|
|
19
20
|
};
|
|
20
|
-
function slugify(value) {
|
|
21
|
-
return value.toLowerCase().normalize('NFKD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'site';
|
|
22
|
-
}
|
|
23
21
|
async function hasAdminUsers(c) {
|
|
24
22
|
const db = await ensureSchema(c.env);
|
|
25
23
|
const row = await db.prepare('SELECT COUNT(*) AS count FROM admin_users').first();
|
|
26
24
|
return (row?.count ?? 0) > 0;
|
|
27
25
|
}
|
|
28
|
-
async function
|
|
29
|
-
|
|
26
|
+
async function tokenHash(value) {
|
|
27
|
+
return new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value)));
|
|
28
|
+
}
|
|
29
|
+
export async function hasValidSetupToken(env, provided) {
|
|
30
|
+
const expected = env.SETUP_TOKEN?.trim();
|
|
31
|
+
const received = typeof provided === 'string' ? provided.trim() : '';
|
|
32
|
+
if (!expected || !received)
|
|
33
|
+
return false;
|
|
34
|
+
const [expectedHash, receivedHash] = await Promise.all([tokenHash(expected), tokenHash(received)]);
|
|
35
|
+
let difference = 0;
|
|
36
|
+
for (let index = 0; index < expectedHash.length; index += 1)
|
|
37
|
+
difference |= expectedHash[index] ^ receivedHash[index];
|
|
38
|
+
return difference === 0;
|
|
39
|
+
}
|
|
40
|
+
async function deploy(c, client = createGitHubClient(getGitHubConfig(c.env))) {
|
|
41
|
+
if (c.env.DISABLE_DEPLOYMENTS === 'true')
|
|
42
|
+
return;
|
|
30
43
|
const { owner, repo, branch } = client.getRepoInfo();
|
|
31
44
|
await (await client.getOctokit()).rest.actions.createWorkflowDispatch({ owner, repo, workflow_id: 'deploy.yml', ref: branch });
|
|
32
45
|
}
|
|
33
46
|
/** One-time, project-owned bootstrap. It is unavailable as soon as an admin exists. */
|
|
47
|
+
export async function setupContext(c) {
|
|
48
|
+
if (await hasAdminUsers(c))
|
|
49
|
+
return c.json({ error: 'Project setup has already been completed.' }, 409);
|
|
50
|
+
if (!(await hasValidSetupToken(c.env, c.req.query('token'))))
|
|
51
|
+
return c.json({ error: 'Invalid setup link.' }, 403);
|
|
52
|
+
return c.json({ suggestedEmail: c.env.SETUP_ADMIN_EMAIL?.trim() || undefined });
|
|
53
|
+
}
|
|
34
54
|
export async function setupProject(c) {
|
|
35
55
|
if (await hasAdminUsers(c))
|
|
36
56
|
return c.json({ error: 'Project setup has already been completed.' }, 409);
|
|
37
57
|
const body = await c.req.json();
|
|
58
|
+
if (!(await hasValidSetupToken(c.env, body.setupToken)))
|
|
59
|
+
return c.json({ error: 'Invalid setup link.' }, 403);
|
|
38
60
|
const email = typeof body.email === 'string' ? body.email.trim().toLowerCase() : '';
|
|
61
|
+
// Modules chosen during setup decide which of the remaining answers are required.
|
|
62
|
+
const requestedModules = typeof body.modules === 'object' && body.modules !== null ? body.modules : {};
|
|
63
|
+
const modules = resolveModuleDependencies({
|
|
64
|
+
shop: requestedModules.shop !== false,
|
|
65
|
+
emails: requestedModules.emails !== false,
|
|
66
|
+
});
|
|
67
|
+
// The owner signs in with email codes when the project sends email, but always sets a
|
|
68
|
+
// password too: it is the way back in if email delivery ever fails.
|
|
69
|
+
const loginMethod = modules.emails ? 'otp' : 'password';
|
|
70
|
+
const MIN_PASSWORD_LENGTH = 12;
|
|
39
71
|
const password = typeof body.password === 'string' ? body.password : '';
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
72
|
+
const plunkApiKey = typeof body.plunkApiKey === 'string' ? body.plunkApiKey.trim() : '';
|
|
73
|
+
const fromEmail = typeof body.fromEmail === 'string' ? body.fromEmail.trim() : '';
|
|
74
|
+
const paymentProvider = body.paymentProvider === 'stripe' || body.paymentProvider === 'bank_transfer' ? body.paymentProvider : null;
|
|
75
|
+
if (!email)
|
|
76
|
+
return c.json({ error: 'An email address is required.' }, 400);
|
|
77
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
78
|
+
return c.json({ error: `Choose a password of at least ${MIN_PASSWORD_LENGTH} characters.` }, 400);
|
|
79
|
+
}
|
|
80
|
+
if (modules.emails && (!plunkApiKey || !fromEmail)) {
|
|
81
|
+
return c.json({ error: 'An email provider API key and sender address are required.' }, 400);
|
|
82
|
+
}
|
|
83
|
+
if (modules.shop && !paymentProvider)
|
|
84
|
+
return c.json({ error: 'Choose a payment provider.' }, 400);
|
|
85
|
+
const bankTransfer = typeof body.bankTransfer === 'object' && body.bankTransfer !== null ? body.bankTransfer : {};
|
|
86
|
+
const accountHolder = typeof bankTransfer.accountHolder === 'string' ? bankTransfer.accountHolder.trim() : '';
|
|
87
|
+
const iban = typeof bankTransfer.iban === 'string' ? bankTransfer.iban.trim() : '';
|
|
88
|
+
const stripeSecretKey = paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
|
|
89
|
+
if (modules.shop && paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
|
|
90
|
+
return c.json({ error: 'An account holder and IBAN are required for bank transfers.' }, 400);
|
|
91
|
+
}
|
|
92
|
+
if (modules.shop && paymentProvider === 'stripe' && !stripeSecretKey) {
|
|
93
|
+
return c.json({ error: 'Your Stripe secret key is required for card payments.' }, 400);
|
|
94
|
+
}
|
|
95
|
+
// Do not consume the one-time setup route until GitHub is reachable. A project
|
|
96
|
+
// without its repository cannot complete setup and must remain retryable.
|
|
97
|
+
let client;
|
|
98
|
+
try {
|
|
99
|
+
client = createGitHubClient(getGitHubConfig(c.env));
|
|
100
|
+
await client.getCommitSha();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('Project setup GitHub preflight failed:', error);
|
|
104
|
+
return c.json({ error: 'GitHub repository is unavailable. Check the project GitHub App configuration and try again.' }, 503);
|
|
105
|
+
}
|
|
46
106
|
const db = await ensureSchema(c.env);
|
|
47
107
|
const now = nowSeconds();
|
|
48
108
|
const user = {
|
|
49
|
-
id: createId('user'),
|
|
50
|
-
|
|
109
|
+
id: createId('user'),
|
|
110
|
+
email,
|
|
111
|
+
name: null,
|
|
112
|
+
login_method: loginMethod,
|
|
113
|
+
// Always stored, including for an email-code owner: this is the fallback credential.
|
|
114
|
+
password_hash: await hashPw(password, c.env.SECRET ?? ''),
|
|
115
|
+
initial_admin: 1,
|
|
116
|
+
disabled_at: null,
|
|
117
|
+
created_at: now,
|
|
118
|
+
updated_at: now,
|
|
51
119
|
};
|
|
52
|
-
await db.prepare(`INSERT INTO admin_users (id, email, name, password_hash, login_method, disabled_at, created_at, updated_at) VALUES (?, ?, ?, ?, ?, NULL, ?, ?)`)
|
|
53
|
-
.bind(user.id, user.email, user.name, user.password_hash, user.login_method, now, now).run();
|
|
54
120
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
121
|
+
await db.prepare(`INSERT INTO admin_users (id, email, password_hash, login_method, initial_admin, disabled_at, created_at, updated_at) VALUES (?, ?, ?, ?, 1, NULL, ?, ?)`)
|
|
122
|
+
.bind(user.id, user.email, user.password_hash, user.login_method, now, now).run();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error('Initial admin creation failed', error);
|
|
126
|
+
return c.json({ error: 'Project setup has already been completed.' }, 409);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
57
129
|
let stripeWebhookSecret = typeof body.stripeWebhookSecret === 'string' ? body.stripeWebhookSecret : '';
|
|
58
130
|
if (stripeSecretKey && !stripeWebhookSecret) {
|
|
59
131
|
try {
|
|
@@ -69,7 +141,7 @@ export async function setupProject(c) {
|
|
|
69
141
|
}
|
|
70
142
|
const secrets = {};
|
|
71
143
|
for (const [name, value] of [
|
|
72
|
-
['API_KEY',
|
|
144
|
+
['API_KEY', plunkApiKey],
|
|
73
145
|
['STRIPE_SECRET_KEY', stripeSecretKey],
|
|
74
146
|
['STRIPE_WEBHOOK_SECRET', stripeWebhookSecret],
|
|
75
147
|
]) {
|
|
@@ -77,23 +149,25 @@ export async function setupProject(c) {
|
|
|
77
149
|
secrets[name] = value;
|
|
78
150
|
}
|
|
79
151
|
await Promise.all(Object.entries(secrets).map(([secretName, value]) => client.setActionsSecret(secretName, value)));
|
|
80
|
-
const { data:
|
|
81
|
-
await writeJsonConfig(client,
|
|
82
|
-
...
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
152
|
+
const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_SETUP_PATH, {});
|
|
153
|
+
await writeJsonConfig(client, WEBSITE_SETUP_PATH, {
|
|
154
|
+
...setupState,
|
|
155
|
+
version: 1,
|
|
156
|
+
modules,
|
|
157
|
+
updatedAt: Date.now(),
|
|
158
|
+
}, 'Record enabled modules [skip ci]', setupCommitSha);
|
|
86
159
|
const { data: shopSettings, commitSha: shopCommitSha } = await readJsonConfig(client, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS);
|
|
87
|
-
const bankTransfer = typeof body.bankTransfer === 'object' && body.bankTransfer !== null ? body.bankTransfer : {};
|
|
88
160
|
await writeJsonConfig(client, SHOP_SETTINGS_PATH, {
|
|
89
161
|
...DEFAULT_SHOP_SETTINGS,
|
|
90
162
|
...shopSettings,
|
|
91
|
-
|
|
163
|
+
// No shop means no payment method was chosen; leave it empty rather than
|
|
164
|
+
// implying the shipped default was a decision.
|
|
165
|
+
enabledPaymentMethods: modules.shop && paymentProvider ? [paymentProvider] : [],
|
|
92
166
|
bankTransfer: {
|
|
93
167
|
...DEFAULT_SHOP_SETTINGS.bankTransfer,
|
|
94
168
|
...(shopSettings.bankTransfer ?? {}),
|
|
95
|
-
accountHolder
|
|
96
|
-
iban
|
|
169
|
+
accountHolder,
|
|
170
|
+
iban,
|
|
97
171
|
bic: typeof bankTransfer.bic === 'string' ? bankTransfer.bic.trim() : '',
|
|
98
172
|
bankName: typeof bankTransfer.bankName === 'string' ? bankTransfer.bankName.trim() : '',
|
|
99
173
|
instructions: typeof bankTransfer.instructions === 'string' ? bankTransfer.instructions.trim() : DEFAULT_SHOP_SETTINGS.bankTransfer.instructions,
|
|
@@ -107,10 +181,17 @@ export async function setupProject(c) {
|
|
|
107
181
|
replyTo: typeof body.replyTo === 'string' ? body.replyTo.trim() : emailSettings.replyTo,
|
|
108
182
|
updatedAt: Date.now(),
|
|
109
183
|
}, 'Configure email sender settings [skip ci]', commitSha);
|
|
110
|
-
await deploy(c);
|
|
184
|
+
await deploy(c, client);
|
|
111
185
|
}
|
|
112
186
|
catch (error) {
|
|
113
187
|
console.error('Project setup integrations could not be saved:', error);
|
|
188
|
+
try {
|
|
189
|
+
await db.prepare('DELETE FROM admin_users WHERE id = ?').bind(user.id).run();
|
|
190
|
+
}
|
|
191
|
+
catch (rollbackError) {
|
|
192
|
+
console.error('Could not roll back incomplete project setup:', rollbackError);
|
|
193
|
+
}
|
|
194
|
+
return c.json({ error: 'Project setup could not be completed. No administrator was created; fix the integration error and try again.' }, 502);
|
|
114
195
|
}
|
|
115
196
|
const token = await signWithPayload(c.env.SECRET ?? '', issueSessionForUser({ ...user, password_hash: user.password_hash }));
|
|
116
197
|
const secureCookie = c.req.url.startsWith('https://') ? '; Secure' : '';
|
|
@@ -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;AAyB9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI1D;AA4CD,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI5E;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,
|
|
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;AAyB9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI1D;AA4CD,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI5E;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,CAwC9E;AASD,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6C/E"}
|
|
@@ -84,11 +84,18 @@ export async function commitWebsiteRepo(c) {
|
|
|
84
84
|
content: String(file.content ?? ''),
|
|
85
85
|
encoding: file.encoding === 'base64' ? 'base64' : 'utf8',
|
|
86
86
|
}));
|
|
87
|
-
const
|
|
87
|
+
const deletions = Array.isArray(body.deletions)
|
|
88
|
+
? [...new Set(body.deletions.map((path) => normalizePath(String(path ?? ''))))]
|
|
89
|
+
: [];
|
|
90
|
+
const invalidPath = [...files.map((file) => file.path), ...deletions].find((path) => !isAllowedWebsitePath(path));
|
|
88
91
|
if (invalidPath) {
|
|
89
|
-
return c.json({ error: `Path is not allowed for website sync: ${invalidPath
|
|
92
|
+
return c.json({ error: `Path is not allowed for website sync: ${invalidPath}` }, 400);
|
|
90
93
|
}
|
|
91
|
-
|
|
94
|
+
const writtenPaths = new Set(files.map((file) => file.path));
|
|
95
|
+
if (deletions.some((path) => writtenPaths.has(path))) {
|
|
96
|
+
return c.json({ error: 'A path cannot be written and deleted in the same commit' }, 400);
|
|
97
|
+
}
|
|
98
|
+
if (files.length === 0 && deletions.length === 0) {
|
|
92
99
|
return c.json({ error: 'No files to commit' }, 400);
|
|
93
100
|
}
|
|
94
101
|
const client = createGitHubClient(getGitHubConfig(c.env));
|
|
@@ -98,7 +105,7 @@ export async function commitWebsiteRepo(c) {
|
|
|
98
105
|
return c.json({ conflict: true, message: 'Repository changed since the last sync' }, 409);
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
|
-
const commitSha = await client.writeFilesAtomic(files, String(body.message || 'Publish website changes'), body.baseCommitSha ? String(body.baseCommitSha) : undefined);
|
|
108
|
+
const commitSha = await client.writeFilesAtomic(files, String(body.message || 'Publish website changes'), body.baseCommitSha ? String(body.baseCommitSha) : undefined, deletions);
|
|
102
109
|
return c.json({ success: true, commitSha });
|
|
103
110
|
}
|
|
104
111
|
function sanitizeFilename(name) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { HonoEnv } from '../../../index';
|
|
3
|
+
export declare function listWebsiteTemplates(c: Context<HonoEnv>): Promise<Response>;
|
|
4
|
+
export declare function getWebsiteTemplateManifest(c: Context<HonoEnv>): Promise<Response>;
|
|
5
|
+
export declare function getWebsiteTemplateFile(c: Context<HonoEnv>): Promise<Response>;
|
|
6
|
+
//# sourceMappingURL=website-templates.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"website-templates.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-templates.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA0C9C,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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const DEFAULT_TEMPLATE_REGISTRY_URL = 'https://hintergrund.cloud/template-registry';
|
|
2
|
+
const TEMPLATE_ID = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
3
|
+
const TEMPLATE_VERSION = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[a-z0-9.-]+)?$/i;
|
|
4
|
+
function registryBase(c) {
|
|
5
|
+
return (c.env.TEMPLATE_REGISTRY_URL || DEFAULT_TEMPLATE_REGISTRY_URL).replace(/\/+$/, '');
|
|
6
|
+
}
|
|
7
|
+
function validTemplate(id, version) {
|
|
8
|
+
return TEMPLATE_ID.test(id) && (!version || TEMPLATE_VERSION.test(version));
|
|
9
|
+
}
|
|
10
|
+
function validOverlayPath(value) {
|
|
11
|
+
const path = value.replace(/^\/+/, '').replace(/\\/g, '/');
|
|
12
|
+
return path.startsWith('frontend/') && !path.includes('..') && !path.includes('\0');
|
|
13
|
+
}
|
|
14
|
+
function encodedPath(value) {
|
|
15
|
+
return value.split('/').map(encodeURIComponent).join('/');
|
|
16
|
+
}
|
|
17
|
+
async function proxy(c, upstreamUrl) {
|
|
18
|
+
const upstream = await fetch(upstreamUrl, {
|
|
19
|
+
headers: { Accept: c.req.header('Accept') || '*/*' },
|
|
20
|
+
});
|
|
21
|
+
if (!upstream.ok) {
|
|
22
|
+
console.error('Template registry request failed', { upstreamUrl, status: upstream.status });
|
|
23
|
+
return c.json({ error: upstream.status === 404 ? 'Template resource not found' : 'Template registry is unavailable' }, upstream.status === 404 ? 404 : 502);
|
|
24
|
+
}
|
|
25
|
+
const headers = new Headers();
|
|
26
|
+
for (const name of ['Content-Type', 'Content-Length', 'ETag', 'Last-Modified']) {
|
|
27
|
+
const value = upstream.headers.get(name);
|
|
28
|
+
if (value)
|
|
29
|
+
headers.set(name, value);
|
|
30
|
+
}
|
|
31
|
+
headers.set('Cache-Control', upstream.headers.get('Cache-Control') || 'public, max-age=300');
|
|
32
|
+
headers.set('X-Content-Type-Options', 'nosniff');
|
|
33
|
+
return new Response(upstream.body, { status: upstream.status, headers });
|
|
34
|
+
}
|
|
35
|
+
export async function listWebsiteTemplates(c) {
|
|
36
|
+
return proxy(c, `${registryBase(c)}/catalog.json`);
|
|
37
|
+
}
|
|
38
|
+
export async function getWebsiteTemplateManifest(c) {
|
|
39
|
+
const id = c.req.param('templateId') || '';
|
|
40
|
+
const version = c.req.param('version') || '';
|
|
41
|
+
if (!validTemplate(id, version))
|
|
42
|
+
return c.json({ error: 'Invalid template identifier' }, 400);
|
|
43
|
+
return proxy(c, `${registryBase(c)}/${encodeURIComponent(id)}/${encodeURIComponent(version)}/manifest.json`);
|
|
44
|
+
}
|
|
45
|
+
export async function getWebsiteTemplateFile(c) {
|
|
46
|
+
const id = c.req.param('templateId') || '';
|
|
47
|
+
const version = c.req.param('version') || '';
|
|
48
|
+
const filePath = c.req.param('*') || '';
|
|
49
|
+
if (!validTemplate(id, version) || !validOverlayPath(filePath)) {
|
|
50
|
+
return c.json({ error: 'Invalid template file path' }, 400);
|
|
51
|
+
}
|
|
52
|
+
return proxy(c, `${registryBase(c)}/${encodeURIComponent(id)}/${encodeURIComponent(version)}/files/${encodedPath(filePath)}`);
|
|
53
|
+
}
|
|
@@ -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;AAGzC,QAAA,MAAM,UAAU,sDAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.routes.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/routes/auth.routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,QAAA,MAAM,UAAU,sDAAsB,CAAC;AAYvC,eAAe,UAAU,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import { login, logout
|
|
2
|
+
import { login, logout } from '../handlers/auth.handler';
|
|
3
3
|
const authRoutes = new Hono();
|
|
4
4
|
authRoutes.post('/login', login);
|
|
5
5
|
authRoutes.post('/logout', logout);
|
|
@@ -10,5 +10,4 @@ authRoutes.get('/me', (c) => {
|
|
|
10
10
|
}
|
|
11
11
|
return c.json({ success: false, message: 'Not logged in' }, 401);
|
|
12
12
|
});
|
|
13
|
-
authRoutes.get('/verify-magic-link', verifyMagicLink);
|
|
14
13
|
export default authRoutes;
|
|
@@ -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;AAoB5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,QAAA,MAAM,SAAS,sDAAsB,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;AAoB5B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,QAAA,MAAM,SAAS,sDAAsB,CAAC;AAgCtC,eAAe,SAAS,CAAC"}
|
|
@@ -2,17 +2,19 @@ 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 {
|
|
6
|
-
import { deleteConversation,
|
|
5
|
+
import { createAdminUser, deleteAdminUser, listAdminUsers, patchAdminUser } from '../handlers/admin-users.handler';
|
|
6
|
+
import { deleteConversation, listConversations, upsertConversation } from '../handlers/agent-conversations.handler';
|
|
7
|
+
import { getAgentConfig, proxyAgentRequest } from '../handlers/agent-provider.handler';
|
|
7
8
|
import { commitWebsiteRepo, headWebsiteRepo, syncWebsiteRepo, uploadWebsiteAsset } from '../handlers/website-repo.handler';
|
|
9
|
+
import { getWebsiteTemplateFile, getWebsiteTemplateManifest, listWebsiteTemplates } from '../handlers/website-templates.handler';
|
|
8
10
|
import { deleteGitHubSecret, listGitHubSecrets, upsertGitHubSecret } from '../handlers/github-secrets.handler';
|
|
9
|
-
import { setupProject } from '../handlers/setup.handler';
|
|
11
|
+
import { setupContext, setupProject } from '../handlers/setup.handler';
|
|
10
12
|
const cmsRoutes = new Hono();
|
|
11
13
|
// Dashboard route (protected)
|
|
12
14
|
cmsRoutes.get('/', authMiddleware, getDashboard);
|
|
13
15
|
// Auth routes (public)
|
|
14
16
|
cmsRoutes.route('/', authRoutes);
|
|
15
|
-
cmsRoutes.
|
|
17
|
+
cmsRoutes.get('/setup', setupContext);
|
|
16
18
|
cmsRoutes.post('/setup', setupProject);
|
|
17
19
|
// Protected routes
|
|
18
20
|
cmsRoutes.use('/*', authMiddleware);
|
|
@@ -23,11 +25,15 @@ cmsRoutes.delete('/users/:id', deleteAdminUser);
|
|
|
23
25
|
cmsRoutes.get('/agent/conversations', listConversations);
|
|
24
26
|
cmsRoutes.post('/agent/conversations', upsertConversation);
|
|
25
27
|
cmsRoutes.delete('/agent/conversations/:id', deleteConversation);
|
|
26
|
-
cmsRoutes.get('/agent/
|
|
28
|
+
cmsRoutes.get('/agent/config', getAgentConfig);
|
|
29
|
+
cmsRoutes.all('/agent/llm/:path{.+}', proxyAgentRequest);
|
|
27
30
|
cmsRoutes.get('/website/repo/head', headWebsiteRepo);
|
|
28
31
|
cmsRoutes.get('/website/repo/sync', syncWebsiteRepo);
|
|
29
32
|
cmsRoutes.put('/website/repo/commit', commitWebsiteRepo);
|
|
30
33
|
cmsRoutes.put('/website/repo/upload', uploadWebsiteAsset);
|
|
34
|
+
cmsRoutes.get('/website/templates', listWebsiteTemplates);
|
|
35
|
+
cmsRoutes.get('/website/templates/:templateId/:version/manifest', getWebsiteTemplateManifest);
|
|
36
|
+
cmsRoutes.get('/website/templates/:templateId/:version/files/*', getWebsiteTemplateFile);
|
|
31
37
|
cmsRoutes.get('/github/secrets', listGitHubSecrets);
|
|
32
38
|
cmsRoutes.put('/github/secrets/:name', upsertGitHubSecret);
|
|
33
39
|
cmsRoutes.delete('/github/secrets/:name', deleteGitHubSecret);
|