@hintergrund/worker 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
- package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/admin-users.handler.js +121 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
- package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +74 -153
- package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/website-repo.handler.js +148 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +16 -4
- package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +164 -92
- package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/invoice.handler.js +58 -340
- package/dist/api/emails/handlers/public.handler.d.ts +6 -29
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +150 -312
- package/dist/api/emails/handlers/send.handler.d.ts +5 -17
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/send.handler.js +107 -92
- package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +96 -287
- package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
- package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/subscribers.handler.js +125 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/webhook.handler.js +66 -166
- package/dist/api/emails/routes/admin.routes.d.ts +1 -3
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +19 -49
- package/dist/api/emails/routes/public.routes.d.ts +1 -3
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/public.routes.js +2 -9
- package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
- package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/prices.handler.js +2 -83
- package/dist/api/shop/handlers/products.handler.d.ts +29 -20
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +195 -162
- package/dist/api/shop/handlers/public.handler.d.ts +24 -8
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +525 -78
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +14 -9
- package/dist/hintergrund-assets.d.ts +3 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +4 -2
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -4
- package/dist/lib/auth/crypto.d.ts +2 -15
- package/dist/lib/auth/crypto.d.ts.map +1 -1
- package/dist/lib/auth/crypto.js +8 -95
- package/dist/lib/auth/jwt.d.ts +0 -4
- package/dist/lib/auth/jwt.d.ts.map +1 -1
- package/dist/lib/auth/jwt.js +0 -6
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +42 -86
- package/dist/lib/email-template.d.ts +15 -0
- package/dist/lib/email-template.d.ts.map +1 -0
- package/dist/lib/email-template.js +58 -0
- package/dist/lib/email.d.ts +18 -8
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +59 -70
- package/dist/lib/github-config.d.ts +19 -0
- package/dist/lib/github-config.d.ts.map +1 -0
- package/dist/lib/github-config.js +23 -0
- package/dist/lib/github.d.ts +10 -0
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +20 -2
- package/dist/lib/project-db.d.ts +24 -0
- package/dist/lib/project-db.d.ts.map +1 -0
- package/dist/lib/project-db.js +172 -0
- package/dist/lib/template.js +4 -4
- package/dist/middleware/auth.d.ts +0 -2
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +21 -50
- package/package.json +2 -1
- package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
- package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/generate.handler.js +0 -203
- package/dist/api/builder/handlers/template.handler.d.ts +0 -12
- package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/template.handler.js +0 -208
- package/dist/api/builder/routes.d.ts +0 -7
- package/dist/api/builder/routes.d.ts.map +0 -1
- package/dist/api/builder/routes.js +0 -15
- package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
- package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/assets.handler.js +0 -200
- package/dist/api/cms/handlers/config.handler.d.ts +0 -7
- package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/config.handler.js +0 -37
- package/dist/api/cms/handlers/content.handler.d.ts +0 -21
- package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/content.handler.js +0 -117
- package/dist/api/cms/routes/assets.routes.d.ts +0 -4
- package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/assets.routes.js +0 -13
- package/dist/api/cms/routes/content.routes.d.ts +0 -4
- package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/content.routes.js +0 -11
- package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
- package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/branding.handler.js +0 -120
- package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/contacts.handler.js +0 -161
- package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
- package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/templates.handler.js +0 -132
- package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
- package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/email.handler.js +0 -102
- package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/emails.handler.js +0 -262
- package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
- package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/public.handler.js +0 -300
- package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
- package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/send.handler.js +0 -153
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
- package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/admin.routes.js +0 -28
- package/dist/api/newsletter/routes/index.d.ts +0 -4
- package/dist/api/newsletter/routes/index.d.ts.map +0 -1
- package/dist/api/newsletter/routes/index.js +0 -9
- package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/public.routes.js +0 -9
- package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
- package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/assets.handler.js +0 -62
- package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
- package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/checkout.handler.js +0 -50
- package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
- package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/customers.handler.js +0 -89
- package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
- package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/orders.handler.js +0 -84
- package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
- package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/stats.handler.js +0 -71
- package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/webhook.handler.js +0 -233
- package/dist/cms-assets.d.ts +0 -4
- package/dist/cms-assets.d.ts.map +0 -1
- package/dist/cms-assets.js +0 -5
- package/dist/cms-bundle.d.ts +0 -3
- package/dist/cms-bundle.d.ts.map +0 -1
- package/dist/cms-bundle.js +0 -4
- package/dist/config-loader.d.ts +0 -26
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -98
- package/dist/jwt.d.ts +0 -26
- package/dist/jwt.d.ts.map +0 -1
- package/dist/jwt.js +0 -102
- package/dist/lib/plunk.d.ts +0 -204
- package/dist/lib/plunk.d.ts.map +0 -1
- package/dist/lib/plunk.js +0 -259
- package/dist/template.d.ts +0 -2
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -61
- package/dist/utils.d.ts +0 -23
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -110
package/dist/lib/email.js
CHANGED
|
@@ -1,81 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provider-agnostic email sending utility using Plunk.
|
|
3
|
+
* Reads HG_EMAILS_API_KEY, HG_EMAILS_FROM_EMAIL, HG_EMAILS_FROM_NAME.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<p style="margin-bottom: 24px; text-align: center; color: #57606a;">
|
|
31
|
-
Click the button below to sign in. This link will expire in 15 minutes.
|
|
32
|
-
</p>
|
|
33
|
-
|
|
34
|
-
<div style="text-align: center; margin-bottom: 32px;">
|
|
35
|
-
<a href="${magicLinkUrl}" style="display: inline-block; background-color: #1f883d; color: white; text-decoration: none; padding: 12px 24px; border-radius: 6px; font-weight: 500; font-size: 16px;">
|
|
36
|
-
Sign in to hintergrund
|
|
37
|
-
</a>
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
<p style="font-size: 14px; color: #57606a; text-align: center; margin-bottom: 16px;">
|
|
41
|
-
If you didn't request this email, you can safely ignore it.
|
|
42
|
-
</p>
|
|
43
|
-
|
|
44
|
-
<hr style="border: none; border-top: 1px solid #d0d7de; margin: 32px 0;">
|
|
45
|
-
|
|
46
|
-
<p style="font-size: 12px; color: #8c959f; text-align: center;">
|
|
47
|
-
If the button doesn't work, copy and paste this link into your browser:
|
|
48
|
-
</p>
|
|
49
|
-
<p style="font-size: 12px; color: #0969da; text-align: center; word-break: break-all;">
|
|
50
|
-
${magicLinkUrl}
|
|
51
|
-
</p>
|
|
52
|
-
</body>
|
|
53
|
-
</html>
|
|
54
|
-
`;
|
|
55
|
-
const body = `
|
|
56
|
-
Sign in to hintergrund${groupInfo}
|
|
57
|
-
|
|
58
|
-
Click the link below to sign in. This link will expire in 15 minutes.
|
|
59
|
-
|
|
60
|
-
${magicLinkUrl}
|
|
61
|
-
|
|
62
|
-
If you didn't request this email, you can safely ignore it.
|
|
63
|
-
`;
|
|
64
|
-
const response = await fetch('https://api.useplunk.com/v1/send', {
|
|
5
|
+
import { renderEmailTemplate } from './email-template';
|
|
6
|
+
export async function sendEmail(env, params) {
|
|
7
|
+
const apiKey = env.HG_EMAILS_API_KEY || env.HG_EMAILS_PLUNK_SECRET_KEY;
|
|
8
|
+
const fromEmail = params.from ?? env.HG_EMAILS_FROM_EMAIL ?? '';
|
|
9
|
+
const fromName = params.fromName ?? env.HG_EMAILS_FROM_NAME ?? '';
|
|
10
|
+
if (!apiKey)
|
|
11
|
+
throw new Error('Plunk API key (HG_EMAILS_API_KEY or HG_EMAILS_PLUNK_SECRET_KEY) is not configured');
|
|
12
|
+
if (!fromEmail)
|
|
13
|
+
throw new Error('HG_EMAILS_FROM_EMAIL is not configured');
|
|
14
|
+
await sendViaPlunk(apiKey, fromEmail, fromName, params);
|
|
15
|
+
}
|
|
16
|
+
async function sendViaPlunk(apiKey, fromEmail, fromName, params) {
|
|
17
|
+
const body = {
|
|
18
|
+
to: params.to,
|
|
19
|
+
subject: params.subject,
|
|
20
|
+
body: params.html,
|
|
21
|
+
type: 'html',
|
|
22
|
+
subscribed: true,
|
|
23
|
+
from: fromName ? `${fromName} <${fromEmail}>` : fromEmail,
|
|
24
|
+
};
|
|
25
|
+
if (params.toName)
|
|
26
|
+
body.name = params.toName;
|
|
27
|
+
if (params.replyTo)
|
|
28
|
+
body.reply = params.replyTo;
|
|
29
|
+
const response = await fetch('https://next-api.useplunk.com/v1/send', {
|
|
65
30
|
method: 'POST',
|
|
66
31
|
headers: {
|
|
67
|
-
|
|
32
|
+
Authorization: `Bearer ${apiKey}`,
|
|
68
33
|
'Content-Type': 'application/json',
|
|
69
34
|
},
|
|
70
|
-
body: JSON.stringify(
|
|
71
|
-
to,
|
|
72
|
-
subject,
|
|
73
|
-
body: html,
|
|
74
|
-
}),
|
|
35
|
+
body: JSON.stringify(body),
|
|
75
36
|
});
|
|
76
37
|
if (!response.ok) {
|
|
77
38
|
const error = await response.text();
|
|
78
|
-
|
|
79
|
-
throw new Error(`Failed to send email: ${response.status}`);
|
|
39
|
+
throw new Error(`Plunk API error ${response.status}: ${error}`);
|
|
80
40
|
}
|
|
81
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Send a magic link email for passwordless admin authentication.
|
|
44
|
+
*/
|
|
45
|
+
export async function sendMagicLinkEmail(params) {
|
|
46
|
+
const html = renderEmailTemplate({
|
|
47
|
+
bodyHtml: `
|
|
48
|
+
<h1 style="font-size:24px;font-weight:600;text-align:center;margin-bottom:24px;">Sign in to hintergrund</h1>
|
|
49
|
+
<p style="margin-bottom:24px;text-align:center;color:#57606a;">Click the button below to sign in. This link will expire in 15 minutes.</p>
|
|
50
|
+
<div style="text-align:center;margin-bottom:32px;">
|
|
51
|
+
<a href="${params.magicLinkUrl}" style="display:inline-block;background-color:#1f883d;color:white;text-decoration:none;padding:12px 24px;border-radius:6px;font-weight:500;font-size:16px;">Sign in to hintergrund</a>
|
|
52
|
+
</div>
|
|
53
|
+
<p style="font-size:14px;color:#57606a;text-align:center;">If you didn't request this email, you can safely ignore it.</p>
|
|
54
|
+
<hr style="border:none;border-top:1px solid #d0d7de;margin:32px 0;">
|
|
55
|
+
<p style="font-size:12px;color:#8c959f;text-align:center;">${params.magicLinkUrl}</p>`,
|
|
56
|
+
template: {
|
|
57
|
+
primaryColor: '#1f883d',
|
|
58
|
+
footerHtml: '',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
await sendEmail({
|
|
62
|
+
HG_EMAILS_API_KEY: params.apiKey,
|
|
63
|
+
HG_EMAILS_FROM_EMAIL: params.fromEmail,
|
|
64
|
+
HG_EMAILS_FROM_NAME: params.fromName,
|
|
65
|
+
}, {
|
|
66
|
+
to: params.to,
|
|
67
|
+
subject: 'Sign in to hintergrund',
|
|
68
|
+
html,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GitHubClient } from './github';
|
|
2
|
+
export declare class ConfigConflictError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
code: string;
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export interface ReadJsonConfigOptions<T> {
|
|
8
|
+
/** Optional commit SHA to read the tree at. If omitted, the current branch HEAD is used. */
|
|
9
|
+
commitSha?: string;
|
|
10
|
+
/** Per-call merge hook for deep merges that a top-level spread cannot express. */
|
|
11
|
+
mergeNested?: (raw: Partial<T>, defaults: T) => Partial<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare function readJsonConfig<T extends object>(github: GitHubClient, path: string, defaults: T, options?: ReadJsonConfigOptions<T>): Promise<{
|
|
14
|
+
data: T;
|
|
15
|
+
commitSha: string;
|
|
16
|
+
fileSha?: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function writeJsonConfig<T>(github: GitHubClient, path: string, data: T, message: string, expectedCommitSha?: string): Promise<string>;
|
|
19
|
+
//# sourceMappingURL=github-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-config.d.ts","sourceRoot":"","sources":["../../src/lib/github-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,MAAM,SAAO;IACb,IAAI,SAAc;gBACN,OAAO,SAAuD;CAI1E;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACvC,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC3D;AAED,wBAAsB,cAAc,CAAC,CAAC,SAAS,MAAM,EACpD,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,EACX,OAAO,GAAE,qBAAqB,CAAC,CAAC,CAAM,GACpC,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAO3D;AAED,wBAAsB,eAAe,CAAC,CAAC,EACtC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAMjB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class ConfigConflictError extends Error {
|
|
2
|
+
constructor(message = 'Config changed upstream. Reload before publishing.') {
|
|
3
|
+
super(message);
|
|
4
|
+
this.status = 409;
|
|
5
|
+
this.code = 'conflict';
|
|
6
|
+
this.name = 'ConfigConflictError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export async function readJsonConfig(github, path, defaults, options = {}) {
|
|
10
|
+
const commitSha = options.commitSha ?? (await github.getCommitSha());
|
|
11
|
+
const result = await github.readJsonFileIfExists(path, commitSha);
|
|
12
|
+
const raw = result?.data ?? {};
|
|
13
|
+
const nested = options.mergeNested ? options.mergeNested(raw, defaults) : {};
|
|
14
|
+
const data = { ...defaults, ...raw, ...nested };
|
|
15
|
+
return { data, commitSha, fileSha: result?.sha };
|
|
16
|
+
}
|
|
17
|
+
export async function writeJsonConfig(github, path, data, message, expectedCommitSha) {
|
|
18
|
+
if (expectedCommitSha && !(await github.checkNoConflict(expectedCommitSha))) {
|
|
19
|
+
throw new ConfigConflictError();
|
|
20
|
+
}
|
|
21
|
+
await github.writeJsonFile(path, data, message);
|
|
22
|
+
return github.getCommitSha();
|
|
23
|
+
}
|
package/dist/lib/github.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface GitHubConfig {
|
|
|
20
20
|
export interface FileEntry {
|
|
21
21
|
path: string;
|
|
22
22
|
content: string;
|
|
23
|
+
/** 'utf8' (default) or 'base64' — determines blob encoding sent to GitHub */
|
|
24
|
+
encoding?: 'utf8' | 'base64';
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* File read result
|
|
@@ -73,6 +75,14 @@ export declare class GitHubClient {
|
|
|
73
75
|
data: T;
|
|
74
76
|
sha: string;
|
|
75
77
|
} | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Read a JSON file only when it is present in the Git tree.
|
|
80
|
+
* Useful for optional files where a Contents API 404 would be noisy in Worker logs.
|
|
81
|
+
*/
|
|
82
|
+
readJsonFileIfExists<T>(path: string, commitSha?: string): Promise<{
|
|
83
|
+
data: T;
|
|
84
|
+
sha: string;
|
|
85
|
+
} | null>;
|
|
76
86
|
/**
|
|
77
87
|
* Read multiple files in parallel
|
|
78
88
|
*/
|
package/dist/lib/github.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/lib/github.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QA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O,CAAC,MAAM,EAAE,CAAC;IAyBpD;;;OAGG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK5D;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,WAAW;;;;;CAOX;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAErE"}
|
package/dist/lib/github.js
CHANGED
|
@@ -123,6 +123,23 @@ export class GitHubClient {
|
|
|
123
123
|
sha: result.sha
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Read a JSON file only when it is present in the Git tree.
|
|
128
|
+
* Useful for optional files where a Contents API 404 would be noisy in Worker logs.
|
|
129
|
+
*/
|
|
130
|
+
async readJsonFileIfExists(path, commitSha) {
|
|
131
|
+
const treeSha = commitSha || await this.getCommitSha();
|
|
132
|
+
const tree = await this.octokit.rest.git.getTree({
|
|
133
|
+
owner: this.owner,
|
|
134
|
+
repo: this.repo,
|
|
135
|
+
tree_sha: treeSha,
|
|
136
|
+
recursive: 'true'
|
|
137
|
+
});
|
|
138
|
+
const exists = tree.data.tree.some((item) => item.type === 'blob' && item.path === path);
|
|
139
|
+
if (!exists)
|
|
140
|
+
return null;
|
|
141
|
+
return this.readJsonFile(path);
|
|
142
|
+
}
|
|
126
143
|
/**
|
|
127
144
|
* Read multiple files in parallel
|
|
128
145
|
*/
|
|
@@ -173,11 +190,12 @@ export class GitHubClient {
|
|
|
173
190
|
});
|
|
174
191
|
// Create blobs for all files
|
|
175
192
|
const blobs = await Promise.all(files.map(async (file) => {
|
|
193
|
+
const isBase64 = file.encoding === 'base64';
|
|
176
194
|
const blob = await this.octokit.rest.git.createBlob({
|
|
177
195
|
owner: this.owner,
|
|
178
196
|
repo: this.repo,
|
|
179
|
-
content: file.content,
|
|
180
|
-
encoding: '
|
|
197
|
+
content: isBase64 ? file.content : encodeUTF8Base64(file.content),
|
|
198
|
+
encoding: 'base64'
|
|
181
199
|
});
|
|
182
200
|
return {
|
|
183
201
|
path: file.path,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Bindings } from '../index';
|
|
2
|
+
export type LoginMethod = 'password' | 'magic-link';
|
|
3
|
+
export interface AdminUser {
|
|
4
|
+
id: string;
|
|
5
|
+
email: string;
|
|
6
|
+
name: string | null;
|
|
7
|
+
password_hash: string | null;
|
|
8
|
+
login_method: LoginMethod;
|
|
9
|
+
disabled_at: number | null;
|
|
10
|
+
created_at: number;
|
|
11
|
+
updated_at: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const PROJECT_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS admin_users (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tpassword_hash TEXT,\n\tlogin_method TEXT NOT NULL CHECK(login_method IN ('password', 'magic-link')),\n\tdisabled_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS admin_magic_links (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tuser_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,\n\ttoken_hash TEXT NOT NULL UNIQUE,\n\texpires_at INTEGER NOT NULL,\n\tused_at INTEGER,\n\tcreated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS agent_conversations (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tuser_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,\n\tmode TEXT NOT NULL CHECK(mode IN ('builder', 'cms')),\n\ttitle TEXT NOT NULL,\n\tmessages_json TEXT NOT NULL,\n\tmodel_metadata_json TEXT NOT NULL DEFAULT '{}',\n\tgit_diff TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_admin_magic_links_token ON admin_magic_links(token_hash);\nCREATE INDEX IF NOT EXISTS idx_agent_conversations_user_mode ON agent_conversations(user_id, mode, updated_at);\n\nCREATE TABLE IF NOT EXISTS subscribers (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'subscribed', 'unsubscribed', 'bounced', 'complained')),\n\tsource TEXT NOT NULL DEFAULT 'website' CHECK(source IN ('manual', 'import', 'website')),\n\tdata_json TEXT NOT NULL DEFAULT '{}',\n\tconfirmation_token TEXT,\n\tconfirmation_sent_at INTEGER,\n\tconfirmed_at INTEGER,\n\tsubscribed_at INTEGER,\n\tunsubscribed_at INTEGER,\n\tunsubscribe_token TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS idx_subscribers_email ON subscribers(email);\nCREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);\nCREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);\n\nCREATE TABLE IF NOT EXISTS campaigns (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tname TEXT NOT NULL,\n\tsubject TEXT NOT NULL,\n\tbody_html TEXT NOT NULL,\n\tstatus TEXT NOT NULL DEFAULT 'draft' CHECK(status IN ('draft', 'scheduled', 'sent')),\n\trecipient_count INTEGER,\n\tscheduled_at INTEGER,\n\tsent_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_campaigns_status ON campaigns(status);\nCREATE INDEX IF NOT EXISTS idx_campaigns_created_at ON campaigns(created_at DESC);\n\nCREATE TABLE IF NOT EXISTS email_sends (\n\tid TEXT NOT NULL PRIMARY KEY,\n\ttype TEXT NOT NULL CHECK(type IN ('campaign', 'transactional', 'auto')),\n\tcampaign_id TEXT REFERENCES campaigns(id) ON DELETE SET NULL,\n\tsubject TEXT NOT NULL,\n\trecipient_count INTEGER NOT NULL DEFAULT 0,\n\tstatus TEXT NOT NULL DEFAULT 'queued' CHECK(status IN ('queued', 'sent', 'failed')),\n\terror TEXT,\n\tsent_at INTEGER,\n\tcreated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_email_sends_type ON email_sends(type);\nCREATE INDEX IF NOT EXISTS idx_email_sends_created_at ON email_sends(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_email_sends_campaign_id ON email_sends(campaign_id);\n\nCREATE TABLE IF NOT EXISTS shop_orders (\n\tid TEXT NOT NULL PRIMARY KEY,\n\torder_number TEXT NOT NULL UNIQUE,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'approved', 'successful', 'aborted', 'failed')),\n\tpayment_method TEXT NOT NULL DEFAULT 'bank_transfer' CHECK(payment_method IN ('bank_transfer', 'stripe')),\n\tcustomer_json TEXT NOT NULL DEFAULT '{}',\n\titems_json TEXT NOT NULL DEFAULT '[]',\n\ttotals_json TEXT NOT NULL DEFAULT '{\"subtotal\":0,\"shipping\":0,\"tax\":0,\"total\":0,\"currency\":\"eur\"}',\n\tstripe_session_id TEXT,\n\tstripe_payment_intent_id TEXT,\n\tinvoice_number TEXT,\n\tinvoice_sent_at INTEGER,\n\tmetadata_json TEXT NOT NULL DEFAULT '{}',\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_shop_orders_status ON shop_orders(status);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_payment_method ON shop_orders(payment_method);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_stripe_session ON shop_orders(stripe_session_id);\nCREATE UNIQUE INDEX IF NOT EXISTS idx_shop_orders_order_number ON shop_orders(order_number);\n";
|
|
14
|
+
export declare const PROJECT_ADMIN_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS admin_users (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tpassword_hash TEXT,\n\tlogin_method TEXT NOT NULL CHECK(login_method IN ('password', 'magic-link')),\n\tdisabled_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS admin_magic_links (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tuser_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,\n\ttoken_hash TEXT NOT NULL UNIQUE,\n\texpires_at INTEGER NOT NULL,\n\tused_at INTEGER,\n\tcreated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS agent_conversations (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tuser_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,\n\tmode TEXT NOT NULL CHECK(mode IN ('builder', 'cms')),\n\ttitle TEXT NOT NULL,\n\tmessages_json TEXT NOT NULL,\n\tmodel_metadata_json TEXT NOT NULL DEFAULT '{}',\n\tgit_diff TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_admin_magic_links_token ON admin_magic_links(token_hash);\nCREATE INDEX IF NOT EXISTS idx_agent_conversations_user_mode ON agent_conversations(user_id, mode, updated_at);\n\nCREATE TABLE IF NOT EXISTS subscribers (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'subscribed', 'unsubscribed', 'bounced', 'complained')),\n\tsource TEXT NOT NULL DEFAULT 'website' CHECK(source IN ('manual', 'import', 'website')),\n\tdata_json TEXT NOT NULL DEFAULT '{}',\n\tconfirmation_token TEXT,\n\tconfirmation_sent_at INTEGER,\n\tconfirmed_at INTEGER,\n\tsubscribed_at INTEGER,\n\tunsubscribed_at INTEGER,\n\tunsubscribe_token TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS idx_subscribers_email ON subscribers(email);\nCREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);\nCREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);\n\nCREATE TABLE IF NOT EXISTS campaigns (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tname TEXT NOT NULL,\n\tsubject TEXT NOT NULL,\n\tbody_html TEXT NOT NULL,\n\tstatus TEXT NOT NULL DEFAULT 'draft' CHECK(status IN ('draft', 'scheduled', 'sent')),\n\trecipient_count INTEGER,\n\tscheduled_at INTEGER,\n\tsent_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_campaigns_status ON campaigns(status);\nCREATE INDEX IF NOT EXISTS idx_campaigns_created_at ON campaigns(created_at DESC);\n\nCREATE TABLE IF NOT EXISTS email_sends (\n\tid TEXT NOT NULL PRIMARY KEY,\n\ttype TEXT NOT NULL CHECK(type IN ('campaign', 'transactional', 'auto')),\n\tcampaign_id TEXT REFERENCES campaigns(id) ON DELETE SET NULL,\n\tsubject TEXT NOT NULL,\n\trecipient_count INTEGER NOT NULL DEFAULT 0,\n\tstatus TEXT NOT NULL DEFAULT 'queued' CHECK(status IN ('queued', 'sent', 'failed')),\n\terror TEXT,\n\tsent_at INTEGER,\n\tcreated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_email_sends_type ON email_sends(type);\nCREATE INDEX IF NOT EXISTS idx_email_sends_created_at ON email_sends(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_email_sends_campaign_id ON email_sends(campaign_id);\n\nCREATE TABLE IF NOT EXISTS shop_orders (\n\tid TEXT NOT NULL PRIMARY KEY,\n\torder_number TEXT NOT NULL UNIQUE,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'approved', 'successful', 'aborted', 'failed')),\n\tpayment_method TEXT NOT NULL DEFAULT 'bank_transfer' CHECK(payment_method IN ('bank_transfer', 'stripe')),\n\tcustomer_json TEXT NOT NULL DEFAULT '{}',\n\titems_json TEXT NOT NULL DEFAULT '[]',\n\ttotals_json TEXT NOT NULL DEFAULT '{\"subtotal\":0,\"shipping\":0,\"tax\":0,\"total\":0,\"currency\":\"eur\"}',\n\tstripe_session_id TEXT,\n\tstripe_payment_intent_id TEXT,\n\tinvoice_number TEXT,\n\tinvoice_sent_at INTEGER,\n\tmetadata_json TEXT NOT NULL DEFAULT '{}',\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_shop_orders_status ON shop_orders(status);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_payment_method ON shop_orders(payment_method);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_stripe_session ON shop_orders(stripe_session_id);\nCREATE UNIQUE INDEX IF NOT EXISTS idx_shop_orders_order_number ON shop_orders(order_number);\n";
|
|
15
|
+
export declare function getProjectDb(env: Bindings): D1Database;
|
|
16
|
+
export declare function ensureSchema(env: Bindings): Promise<D1Database>;
|
|
17
|
+
export declare const ensureProjectAdminSchema: typeof ensureSchema;
|
|
18
|
+
export declare function nowSeconds(): number;
|
|
19
|
+
export declare function createId(prefix: string): string;
|
|
20
|
+
export declare function sha256Base64Url(value: string): Promise<string>;
|
|
21
|
+
export declare function getAdminUserByEmail(env: Bindings, email: string): Promise<AdminUser | null>;
|
|
22
|
+
export declare function getAdminUserById(env: Bindings, userId: string): Promise<AdminUser | null>;
|
|
23
|
+
export declare function issueSessionForUser(user: AdminUser): Record<string, unknown>;
|
|
24
|
+
//# sourceMappingURL=project-db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;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM5E"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Full project schema — all modules in one place.
|
|
2
|
+
// Mirrors db/schema.sql exactly; kept in sync manually.
|
|
3
|
+
// All statements use IF NOT EXISTS so this is safe to re-run on an existing DB.
|
|
4
|
+
export const PROJECT_SCHEMA_SQL = `
|
|
5
|
+
CREATE TABLE IF NOT EXISTS admin_users (
|
|
6
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
7
|
+
email TEXT NOT NULL UNIQUE,
|
|
8
|
+
name TEXT,
|
|
9
|
+
password_hash TEXT,
|
|
10
|
+
login_method TEXT NOT NULL CHECK(login_method IN ('password', 'magic-link')),
|
|
11
|
+
disabled_at INTEGER,
|
|
12
|
+
created_at INTEGER NOT NULL,
|
|
13
|
+
updated_at INTEGER NOT NULL
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE TABLE IF NOT EXISTS admin_magic_links (
|
|
17
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
18
|
+
user_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
|
|
19
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
20
|
+
expires_at INTEGER NOT NULL,
|
|
21
|
+
used_at INTEGER,
|
|
22
|
+
created_at INTEGER NOT NULL
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE IF NOT EXISTS agent_conversations (
|
|
26
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
27
|
+
user_id TEXT NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
|
|
28
|
+
mode TEXT NOT NULL CHECK(mode IN ('builder', 'cms')),
|
|
29
|
+
title TEXT NOT NULL,
|
|
30
|
+
messages_json TEXT NOT NULL,
|
|
31
|
+
model_metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
32
|
+
git_diff TEXT,
|
|
33
|
+
created_at INTEGER NOT NULL,
|
|
34
|
+
updated_at INTEGER NOT NULL
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
CREATE INDEX IF NOT EXISTS idx_admin_magic_links_token ON admin_magic_links(token_hash);
|
|
38
|
+
CREATE INDEX IF NOT EXISTS idx_agent_conversations_user_mode ON agent_conversations(user_id, mode, updated_at);
|
|
39
|
+
|
|
40
|
+
CREATE TABLE IF NOT EXISTS subscribers (
|
|
41
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
42
|
+
email TEXT NOT NULL UNIQUE,
|
|
43
|
+
name TEXT,
|
|
44
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'subscribed', 'unsubscribed', 'bounced', 'complained')),
|
|
45
|
+
source TEXT NOT NULL DEFAULT 'website' CHECK(source IN ('manual', 'import', 'website')),
|
|
46
|
+
data_json TEXT NOT NULL DEFAULT '{}',
|
|
47
|
+
confirmation_token TEXT,
|
|
48
|
+
confirmation_sent_at INTEGER,
|
|
49
|
+
confirmed_at INTEGER,
|
|
50
|
+
subscribed_at INTEGER,
|
|
51
|
+
unsubscribed_at INTEGER,
|
|
52
|
+
unsubscribe_token TEXT,
|
|
53
|
+
created_at INTEGER NOT NULL,
|
|
54
|
+
updated_at INTEGER NOT NULL
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_subscribers_email ON subscribers(email);
|
|
58
|
+
CREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);
|
|
59
|
+
CREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);
|
|
60
|
+
CREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);
|
|
61
|
+
|
|
62
|
+
CREATE TABLE IF NOT EXISTS campaigns (
|
|
63
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
64
|
+
name TEXT NOT NULL,
|
|
65
|
+
subject TEXT NOT NULL,
|
|
66
|
+
body_html TEXT NOT NULL,
|
|
67
|
+
status TEXT NOT NULL DEFAULT 'draft' CHECK(status IN ('draft', 'scheduled', 'sent')),
|
|
68
|
+
recipient_count INTEGER,
|
|
69
|
+
scheduled_at INTEGER,
|
|
70
|
+
sent_at INTEGER,
|
|
71
|
+
created_at INTEGER NOT NULL,
|
|
72
|
+
updated_at INTEGER NOT NULL
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_campaigns_status ON campaigns(status);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_campaigns_created_at ON campaigns(created_at DESC);
|
|
77
|
+
|
|
78
|
+
CREATE TABLE IF NOT EXISTS email_sends (
|
|
79
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
80
|
+
type TEXT NOT NULL CHECK(type IN ('campaign', 'transactional', 'auto')),
|
|
81
|
+
campaign_id TEXT REFERENCES campaigns(id) ON DELETE SET NULL,
|
|
82
|
+
subject TEXT NOT NULL,
|
|
83
|
+
recipient_count INTEGER NOT NULL DEFAULT 0,
|
|
84
|
+
status TEXT NOT NULL DEFAULT 'queued' CHECK(status IN ('queued', 'sent', 'failed')),
|
|
85
|
+
error TEXT,
|
|
86
|
+
sent_at INTEGER,
|
|
87
|
+
created_at INTEGER NOT NULL
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE INDEX IF NOT EXISTS idx_email_sends_type ON email_sends(type);
|
|
91
|
+
CREATE INDEX IF NOT EXISTS idx_email_sends_created_at ON email_sends(created_at DESC);
|
|
92
|
+
CREATE INDEX IF NOT EXISTS idx_email_sends_campaign_id ON email_sends(campaign_id);
|
|
93
|
+
|
|
94
|
+
CREATE TABLE IF NOT EXISTS shop_orders (
|
|
95
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
96
|
+
order_number TEXT NOT NULL UNIQUE,
|
|
97
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'approved', 'successful', 'aborted', 'failed')),
|
|
98
|
+
payment_method TEXT NOT NULL DEFAULT 'bank_transfer' CHECK(payment_method IN ('bank_transfer', 'stripe')),
|
|
99
|
+
customer_json TEXT NOT NULL DEFAULT '{}',
|
|
100
|
+
items_json TEXT NOT NULL DEFAULT '[]',
|
|
101
|
+
totals_json TEXT NOT NULL DEFAULT '{"subtotal":0,"shipping":0,"tax":0,"total":0,"currency":"eur"}',
|
|
102
|
+
stripe_session_id TEXT,
|
|
103
|
+
stripe_payment_intent_id TEXT,
|
|
104
|
+
invoice_number TEXT,
|
|
105
|
+
invoice_sent_at INTEGER,
|
|
106
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
107
|
+
created_at INTEGER NOT NULL,
|
|
108
|
+
updated_at INTEGER NOT NULL
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
CREATE INDEX IF NOT EXISTS idx_shop_orders_status ON shop_orders(status);
|
|
112
|
+
CREATE INDEX IF NOT EXISTS idx_shop_orders_payment_method ON shop_orders(payment_method);
|
|
113
|
+
CREATE INDEX IF NOT EXISTS idx_shop_orders_stripe_session ON shop_orders(stripe_session_id);
|
|
114
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_shop_orders_order_number ON shop_orders(order_number);
|
|
115
|
+
`;
|
|
116
|
+
// Keep the old export name as an alias so existing call-sites don't break.
|
|
117
|
+
export const PROJECT_ADMIN_SCHEMA_SQL = PROJECT_SCHEMA_SQL;
|
|
118
|
+
export function getProjectDb(env) {
|
|
119
|
+
const db = env.PROJECT_DB ?? env.SHOP_DB;
|
|
120
|
+
if (!db) {
|
|
121
|
+
throw new Error('PROJECT_DB binding is not configured');
|
|
122
|
+
}
|
|
123
|
+
return db;
|
|
124
|
+
}
|
|
125
|
+
export async function ensureSchema(env) {
|
|
126
|
+
const db = getProjectDb(env);
|
|
127
|
+
const statements = PROJECT_SCHEMA_SQL
|
|
128
|
+
.split(';')
|
|
129
|
+
.map((s) => s.trim())
|
|
130
|
+
.filter((s) => s.length > 0);
|
|
131
|
+
for (const stmt of statements) {
|
|
132
|
+
await db.prepare(stmt).run();
|
|
133
|
+
}
|
|
134
|
+
return db;
|
|
135
|
+
}
|
|
136
|
+
// Backward-compatible alias
|
|
137
|
+
export const ensureProjectAdminSchema = ensureSchema;
|
|
138
|
+
export function nowSeconds() {
|
|
139
|
+
return Math.floor(Date.now() / 1000);
|
|
140
|
+
}
|
|
141
|
+
export function createId(prefix) {
|
|
142
|
+
return `${prefix}_${Date.now().toString(36)}_${crypto.randomUUID().replace(/-/g, '').slice(0, 12)}`;
|
|
143
|
+
}
|
|
144
|
+
export async function sha256Base64Url(value) {
|
|
145
|
+
const bytes = new TextEncoder().encode(value);
|
|
146
|
+
const hash = await crypto.subtle.digest('SHA-256', bytes);
|
|
147
|
+
return btoa(String.fromCharCode(...new Uint8Array(hash)))
|
|
148
|
+
.replace(/=/g, '')
|
|
149
|
+
.replace(/\+/g, '-')
|
|
150
|
+
.replace(/\//g, '_');
|
|
151
|
+
}
|
|
152
|
+
export async function getAdminUserByEmail(env, email) {
|
|
153
|
+
const db = await ensureProjectAdminSchema(env);
|
|
154
|
+
return await db
|
|
155
|
+
.prepare('SELECT * FROM admin_users WHERE email = ? AND disabled_at IS NULL LIMIT 1')
|
|
156
|
+
.bind(email.toLowerCase().trim())
|
|
157
|
+
.first();
|
|
158
|
+
}
|
|
159
|
+
export async function getAdminUserById(env, userId) {
|
|
160
|
+
const db = await ensureProjectAdminSchema(env);
|
|
161
|
+
return await db
|
|
162
|
+
.prepare('SELECT * FROM admin_users WHERE id = ? AND disabled_at IS NULL LIMIT 1')
|
|
163
|
+
.bind(userId)
|
|
164
|
+
.first();
|
|
165
|
+
}
|
|
166
|
+
export function issueSessionForUser(user) {
|
|
167
|
+
return {
|
|
168
|
+
userId: user.id,
|
|
169
|
+
email: user.email,
|
|
170
|
+
name: user.name,
|
|
171
|
+
};
|
|
172
|
+
}
|
package/dist/lib/template.js
CHANGED
|
@@ -16,7 +16,7 @@ export function getTemplate(element, uiBaseUrl, params = '') {
|
|
|
16
16
|
<link rel="stylesheet" href="${uiBaseUrl}/ui.css">
|
|
17
17
|
</head>
|
|
18
18
|
<body>
|
|
19
|
-
<hintergrund-login></hintergrund-login>
|
|
19
|
+
<hintergrund-login ${params}></hintergrund-login>
|
|
20
20
|
<script type="module" src="${uiBaseUrl}/login.js"></script>
|
|
21
21
|
</body>
|
|
22
22
|
</html>
|
|
@@ -151,10 +151,10 @@ export function getTemplate(element, uiBaseUrl, params = '') {
|
|
|
151
151
|
</head>
|
|
152
152
|
<body>
|
|
153
153
|
<div class="container">
|
|
154
|
-
<h1>Unsubscribe from
|
|
154
|
+
<h1>Unsubscribe from Emails</h1>
|
|
155
155
|
<div id="message" class="message"></div>
|
|
156
156
|
<div id="content">
|
|
157
|
-
<p>Are you sure you want to unsubscribe from
|
|
157
|
+
<p>Are you sure you want to unsubscribe from updates?</p>
|
|
158
158
|
<div class="buttons">
|
|
159
159
|
<button class="btn-secondary" onclick="window.close()">Cancel</button>
|
|
160
160
|
<button class="btn-primary" onclick="handleUnsubscribe()">Unsubscribe</button>
|
|
@@ -174,7 +174,7 @@ export function getTemplate(element, uiBaseUrl, params = '') {
|
|
|
174
174
|
spinner.style.display = 'block';
|
|
175
175
|
|
|
176
176
|
try {
|
|
177
|
-
const response = await fetch('/api/
|
|
177
|
+
const response = await fetch('/api/email/unsubscribe', {
|
|
178
178
|
method: 'POST',
|
|
179
179
|
headers: { 'Content-Type': 'application/json' },
|
|
180
180
|
body: JSON.stringify({ token })
|
|
@@ -3,7 +3,5 @@ export declare function authMiddleware(c: Context, next: Next): Promise<void | (
|
|
|
3
3
|
error: string;
|
|
4
4
|
}, 500, "json">) | (Response & import("hono").TypedResponse<"Server configuration error: No configuration found", 500, "text">) | (Response & import("hono").TypedResponse<{
|
|
5
5
|
error: string;
|
|
6
|
-
}, 403, "json">) | (Response & import("hono").TypedResponse<"Access denied to this module", 403, "text">) | (Response & import("hono").TypedResponse<{
|
|
7
|
-
error: string;
|
|
8
6
|
}, 401, "json">) | (Response & import("hono").TypedResponse<undefined, 302, "redirect">)>;
|
|
9
7
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAMrC,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;;;;0FAqE1D"}
|
package/dist/middleware/auth.js
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
1
|
import { parse } from 'cookie';
|
|
2
2
|
import { verify } from '../lib/auth/jwt';
|
|
3
3
|
import { loadConfig } from '../lib/config';
|
|
4
|
-
|
|
5
|
-
* Determines which module is being accessed based on the pathname
|
|
6
|
-
*/
|
|
7
|
-
function getModuleFromPath(pathname) {
|
|
8
|
-
if (pathname.includes('/api/admin/cms') || pathname.includes('/api/admin/collections') || pathname.includes('/api/admin/assets')) {
|
|
9
|
-
return 'cms';
|
|
10
|
-
}
|
|
11
|
-
if (pathname.includes('/api/email/admin')) {
|
|
12
|
-
return 'emails';
|
|
13
|
-
}
|
|
14
|
-
if (pathname.includes('/api/admin/shop')) {
|
|
15
|
-
return 'shop';
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Check if user has access to a specific module based on their group
|
|
21
|
-
*/
|
|
22
|
-
function hasModuleAccess(userModules, targetModule) {
|
|
23
|
-
// If no target module, allow access (general admin routes)
|
|
24
|
-
if (!targetModule)
|
|
25
|
-
return true;
|
|
26
|
-
// If user has no module restrictions, allow all
|
|
27
|
-
if (!userModules || userModules.length === 0)
|
|
28
|
-
return true;
|
|
29
|
-
// Check if the target module is in the allowed list
|
|
30
|
-
return userModules.includes(targetModule);
|
|
31
|
-
}
|
|
4
|
+
import { getAdminUserById } from '../lib/project-db';
|
|
32
5
|
export async function authMiddleware(c, next) {
|
|
33
6
|
const { pathname } = new URL(c.req.url);
|
|
34
7
|
console.log('[AUTH MIDDLEWARE] Checking:', pathname);
|
|
35
|
-
// Skip authentication for login, logout, and magic link verification routes
|
|
36
8
|
if (pathname === '/login' ||
|
|
37
9
|
pathname === '/api/admin/login' ||
|
|
38
10
|
pathname === '/api/admin/logout' ||
|
|
@@ -40,9 +12,8 @@ export async function authMiddleware(c, next) {
|
|
|
40
12
|
console.log('[AUTH MIDDLEWARE] Skipping auth for:', pathname);
|
|
41
13
|
return await next();
|
|
42
14
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.error('No configuration found. Set HG_SECRET/HG_PASSWORD or HG_CONFIG');
|
|
15
|
+
if (!c.env.HG_SECRET) {
|
|
16
|
+
console.error('No configuration found. Set HG_SECRET or HG_CONFIG');
|
|
46
17
|
if (pathname.startsWith('/api/')) {
|
|
47
18
|
return c.json({ error: 'Server configuration error' }, 500);
|
|
48
19
|
}
|
|
@@ -55,36 +26,36 @@ export async function authMiddleware(c, next) {
|
|
|
55
26
|
const appConfig = loadConfig(c.env);
|
|
56
27
|
const payload = await verify(token, appConfig.global.hgSecret);
|
|
57
28
|
if (payload) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
29
|
+
let user = {
|
|
30
|
+
userId: payload.userId,
|
|
31
|
+
email: payload.email,
|
|
32
|
+
name: payload.name,
|
|
33
|
+
};
|
|
34
|
+
if (payload.userId && (c.env.PROJECT_DB || c.env.SHOP_DB)) {
|
|
35
|
+
const dbUser = await getAdminUserById(c.env, String(payload.userId));
|
|
36
|
+
if (!dbUser) {
|
|
37
|
+
if (pathname.startsWith('/api/')) {
|
|
38
|
+
return c.json({ error: 'Unauthorized' }, 401);
|
|
39
|
+
}
|
|
40
|
+
return c.redirect('/login');
|
|
65
41
|
}
|
|
66
|
-
|
|
42
|
+
user = {
|
|
43
|
+
userId: dbUser.id,
|
|
44
|
+
email: dbUser.email,
|
|
45
|
+
name: dbUser.name,
|
|
46
|
+
};
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
c.set('user', {
|
|
70
|
-
email: payload.email,
|
|
71
|
-
userGroup: payload.userGroup,
|
|
72
|
-
modules: userModules,
|
|
73
|
-
});
|
|
48
|
+
c.set('user', user);
|
|
74
49
|
return await next();
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
52
|
catch (error) {
|
|
78
53
|
console.error('Token verification error:', error);
|
|
79
|
-
// Continue to unauthorized handling
|
|
80
54
|
}
|
|
81
55
|
}
|
|
82
|
-
// No cookie or incorrect hash in cookie
|
|
83
56
|
console.log('[AUTH MIDDLEWARE] No valid token, redirecting to login');
|
|
84
|
-
// Check if this is an API request
|
|
85
57
|
if (pathname.startsWith('/api/')) {
|
|
86
58
|
return c.json({ error: 'Unauthorized' }, 401);
|
|
87
59
|
}
|
|
88
|
-
// For non-API requests, redirect to login
|
|
89
60
|
return c.redirect('/login');
|
|
90
61
|
}
|