@hintergrund/worker 0.1.10 → 0.1.14
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.js +9 -9
- package/dist/api/cms/handlers/agent-conversations.handler.js +4 -4
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +7 -5
- package/dist/api/cms/handlers/github-secrets.handler.d.ts +8 -0
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/github-secrets.handler.js +51 -0
- package/dist/api/cms/handlers/setup.handler.d.ts +6 -0
- package/dist/api/cms/handlers/setup.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/setup.handler.js +121 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +6 -0
- package/dist/api/emails/handlers/webhook.handler.js +1 -1
- package/dist/api/shop/handlers/products.handler.js +1 -1
- package/dist/api/shop/handlers/public.handler.js +11 -11
- package/dist/hintergrund-assets.d.ts +1 -1
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +1 -1
- package/dist/index.d.ts +18 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- 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 -7
- package/dist/lib/config.d.ts +7 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +34 -22
- package/dist/lib/email.d.ts +1 -1
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +13 -10
- package/dist/lib/github-app.d.ts +1 -0
- package/dist/lib/github-app.d.ts.map +1 -1
- package/dist/lib/github-app.js +22 -1
- package/dist/lib/github.d.ts +18 -2
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +61 -3
- package/dist/lib/project-db.d.ts +0 -2
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +3 -7
- package/dist/lib/template.d.ts.map +1 -1
- package/dist/lib/template.js +79 -208
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +5 -4
- package/package.json +35 -33
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
export type Bindings = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
HG_SHOP_STRIPE_PUBLISHABLE_KEY?: string;
|
|
3
|
+
SECRET?: string;
|
|
4
|
+
BOOTSTRAP_TOKEN?: string;
|
|
5
|
+
ALLOWED_ORIGINS?: string;
|
|
6
|
+
GIT_OWNER?: string;
|
|
7
|
+
GIT_REPO?: string;
|
|
8
|
+
GIT_BRANCH?: string;
|
|
9
|
+
GITHUB_APP_ID?: string;
|
|
10
|
+
GITHUB_INSTALLATION_ID?: string;
|
|
11
|
+
GITHUB_APP_PRIVATE_KEY?: string;
|
|
12
|
+
GITHUB_TOKEN_URL?: string;
|
|
13
|
+
API_KEY?: string;
|
|
14
|
+
FROM_EMAIL?: string;
|
|
15
|
+
FROM_NAME?: string;
|
|
16
|
+
REPLY_TO?: string;
|
|
17
|
+
PLUNK_SECRET_KEY?: string;
|
|
18
|
+
STRIPE_SECRET_KEY?: string;
|
|
19
|
+
STRIPE_WEBHOOK_SECRET?: string;
|
|
20
|
+
STRIPE_PUBLISHABLE_KEY?: string;
|
|
22
21
|
GEMINI_API_KEY?: string;
|
|
23
22
|
UI_BASE_URL: string;
|
|
24
23
|
ASSETS: Fetcher;
|
|
25
24
|
PROJECT_DB?: D1Database;
|
|
26
|
-
SHOP_DB?: D1Database;
|
|
27
25
|
};
|
|
28
26
|
export type Variables = {
|
|
29
27
|
user?: {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAW5B,MAAM,MAAM,QAAQ,GAAG;IAEtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAG1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAG1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAGhC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAEnE,wBAAgB,SAAS,yDA0GxB;AAGD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,12 @@ import emailRoutes from './api/emails/routes';
|
|
|
5
5
|
import shopRoutes from './api/shop/routes';
|
|
6
6
|
import { authMiddleware } from './middleware/auth';
|
|
7
7
|
import { getTemplate } from './lib/template';
|
|
8
|
-
import {
|
|
8
|
+
import { ensureSchema } from './lib/project-db';
|
|
9
|
+
import { projectNeedsSetup } from './api/cms/handlers/setup.handler';
|
|
9
10
|
export function createApp() {
|
|
10
11
|
const app = new Hono();
|
|
11
12
|
app.use('*', async (c, next) => {
|
|
12
|
-
const allowedOrigins = (c.env.
|
|
13
|
+
const allowedOrigins = (c.env.ALLOWED_ORIGINS ?? '')
|
|
13
14
|
.split(',')
|
|
14
15
|
.map((origin) => origin.trim())
|
|
15
16
|
.filter(Boolean);
|
|
@@ -25,12 +26,20 @@ export function createApp() {
|
|
|
25
26
|
credentials: true,
|
|
26
27
|
})(c, next);
|
|
27
28
|
});
|
|
29
|
+
// Project-owned first-run setup. Once an admin exists, this route is no longer available.
|
|
30
|
+
app.get('/setup', async (c) => {
|
|
31
|
+
if (!(await projectNeedsSetup(c)))
|
|
32
|
+
return c.redirect('/login');
|
|
33
|
+
return c.html(getTemplate('setup', c.env.UI_BASE_URL));
|
|
34
|
+
});
|
|
28
35
|
// Login page route (public)
|
|
29
36
|
app.get('/login', async (c) => {
|
|
37
|
+
if (await projectNeedsSetup(c))
|
|
38
|
+
return c.redirect('/setup');
|
|
30
39
|
let configParams = '';
|
|
31
40
|
try {
|
|
32
|
-
if (c.env.PROJECT_DB
|
|
33
|
-
const db = await
|
|
41
|
+
if (c.env.PROJECT_DB) {
|
|
42
|
+
const db = await ensureSchema(c.env);
|
|
34
43
|
const methods = await db
|
|
35
44
|
.prepare('SELECT login_method, COUNT(*) AS count FROM admin_users WHERE disabled_at IS NULL GROUP BY login_method ORDER BY count DESC')
|
|
36
45
|
.all();
|
|
@@ -66,10 +75,10 @@ export function createApp() {
|
|
|
66
75
|
const adminConfig = getAdminConfig(appConfig);
|
|
67
76
|
adminConfig.canManageAdminUsers = true;
|
|
68
77
|
adminConfig.integrations = {
|
|
69
|
-
stripePublishableKeySet: !!c.env.
|
|
70
|
-
stripeSecretKeySet: !!c.env.
|
|
71
|
-
stripeWebhookSecretSet: !!c.env.
|
|
72
|
-
emailProviderApiKeySet: !!(c.env.
|
|
78
|
+
stripePublishableKeySet: !!c.env.STRIPE_PUBLISHABLE_KEY,
|
|
79
|
+
stripeSecretKeySet: !!c.env.STRIPE_SECRET_KEY && c.env.STRIPE_SECRET_KEY !== 'NOT_CONFIGURED',
|
|
80
|
+
stripeWebhookSecretSet: !!c.env.STRIPE_WEBHOOK_SECRET && c.env.STRIPE_WEBHOOK_SECRET !== 'NOT_CONFIGURED',
|
|
81
|
+
emailProviderApiKeySet: !!(c.env.API_KEY || c.env.PLUNK_SECRET_KEY),
|
|
73
82
|
geminiApiKeySet: !!c.env.GEMINI_API_KEY && c.env.GEMINI_API_KEY !== 'NOT_CONFIGURED',
|
|
74
83
|
};
|
|
75
84
|
const configParams = `config='${JSON.stringify(adminConfig)}'`;
|
package/dist/lib/auth/jwt.d.ts
CHANGED
|
@@ -22,10 +22,6 @@ export declare function signWithPayload(secret: string, customPayload: Record<st
|
|
|
22
22
|
* Verifies the integrity of the token and returns the payload if valid, null otherwise.
|
|
23
23
|
*/
|
|
24
24
|
export declare function verify(token: string, secret: string): Promise<JwtPayload | null>;
|
|
25
|
-
/**
|
|
26
|
-
* Verifies the integrity of the token and returns a boolean value (legacy).
|
|
27
|
-
*/
|
|
28
|
-
export declare function verifyBoolean(token: string, secret: string): Promise<boolean>;
|
|
29
25
|
/**
|
|
30
26
|
* Returns the payload **without** verifying the integrity of the token. Please use `verify()` first to keep your application secure!
|
|
31
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/jwt.ts"],"names":[],"mappings":"AAgEA,UAAU,SAAS;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,UAAU;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED,UAAU,OAAO;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;CACpB;AAOD;;;;;GAKG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClC,SAAS,GAAE,MAAqB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA0BtF;AAED;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/jwt.ts"],"names":[],"mappings":"AAgEA,UAAU,SAAS;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,UAAU;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED,UAAU,OAAO;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;CACpB;AAOD;;;;;GAKG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClC,SAAS,GAAE,MAAqB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA0BtF;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK7C"}
|
package/dist/lib/auth/jwt.js
CHANGED
|
@@ -96,13 +96,6 @@ export async function verify(token, secret) {
|
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Verifies the integrity of the token and returns a boolean value (legacy).
|
|
101
|
-
*/
|
|
102
|
-
export async function verifyBoolean(token, secret) {
|
|
103
|
-
const payload = await verify(token, secret);
|
|
104
|
-
return payload !== null;
|
|
105
|
-
}
|
|
106
99
|
/**
|
|
107
100
|
* Returns the payload **without** verifying the integrity of the token. Please use `verify()` first to keep your application secure!
|
|
108
101
|
*/
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AppConfig, AdminConfig, EmailsModuleConfig, ShopModuleConfig } from '@hintergrund/runtime-contracts';
|
|
2
2
|
/**
|
|
3
3
|
* Load application configuration from environment variables
|
|
4
|
-
*
|
|
4
|
+
* Reads the modular Worker environment bindings.
|
|
5
5
|
*/
|
|
6
6
|
export declare function loadConfig(env: Record<string, string | undefined> | any): AppConfig;
|
|
7
7
|
/**
|
|
@@ -25,11 +25,17 @@ export declare function getShopConfig(env: Record<string, string | undefined> |
|
|
|
25
25
|
* @throws Error if GitHub is not configured (required variables missing)
|
|
26
26
|
*/
|
|
27
27
|
export declare function getGitHubConfig(env: Record<string, string | undefined> | any): {
|
|
28
|
+
githubTokenUrl: string;
|
|
29
|
+
runtimeSecret: string;
|
|
28
30
|
gitOwner: string;
|
|
29
31
|
gitRepo: string;
|
|
30
32
|
gitBranch: any;
|
|
33
|
+
} | {
|
|
31
34
|
githubAppId: string;
|
|
32
35
|
githubInstallationId: string;
|
|
33
36
|
githubPrivateKey: string;
|
|
37
|
+
gitOwner: string;
|
|
38
|
+
gitRepo: string;
|
|
39
|
+
gitBranch: any;
|
|
34
40
|
};
|
|
35
41
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAe,MAAM,gCAAgC,CAAC;AAEhI;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,SAAS,CAOnF;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAe,MAAM,gCAAgC,CAAC;AAEhI;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,SAAS,CAOnF;AA6CD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,GAAG,WAAW,CAIjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,kBAAkB,CAQjG;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,gBAAgB,CAQ7F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG;oBAUX,MAAM;mBAA+B,MAAM;cANhF,MAAM;aACR,MAAM;;;iBAWG,MAAM;0BACY,MAAM;sBACV,MAAM;cAd3B,MAAM;aACR,MAAM;;EAehC"}
|
package/dist/lib/config.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Load application configuration from environment variables
|
|
3
|
-
*
|
|
3
|
+
* Reads the modular Worker environment bindings.
|
|
4
4
|
*/
|
|
5
5
|
export function loadConfig(env) {
|
|
6
6
|
// Try new env vars first - need either legacy password or new auth config
|
|
7
|
-
if (env.
|
|
7
|
+
if (env.SECRET) {
|
|
8
8
|
return loadFromEnvVars(env);
|
|
9
9
|
}
|
|
10
|
-
throw new Error('No configuration found. Set
|
|
10
|
+
throw new Error('No configuration found. Set SECRET.');
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Check which required variables are missing for a module
|
|
@@ -23,25 +23,26 @@ function getMissingVars(env, requiredVars) {
|
|
|
23
23
|
* Check if any variable from a list is set (module is attempted)
|
|
24
24
|
* Treats empty strings and "NOT_CONFIGURED" placeholder as not set
|
|
25
25
|
*/
|
|
26
|
-
const
|
|
26
|
+
const GIT_REPOSITORY_VARS = ['GIT_OWNER', 'GIT_REPO'];
|
|
27
|
+
const GITHUB_APP_VARS = ['GITHUB_APP_ID', 'GITHUB_INSTALLATION_ID', 'GITHUB_APP_PRIVATE_KEY'];
|
|
27
28
|
function loadFromEnvVars(env) {
|
|
28
29
|
const config = {
|
|
29
30
|
global: {
|
|
30
|
-
hgSecret: env.
|
|
31
|
+
hgSecret: env.SECRET || '',
|
|
31
32
|
},
|
|
32
33
|
};
|
|
33
34
|
config.emails = {
|
|
34
35
|
emailProvider: 'plunk',
|
|
35
|
-
emailApiKey: env.
|
|
36
|
-
fromEmail:
|
|
37
|
-
fromName:
|
|
38
|
-
replyTo:
|
|
36
|
+
emailApiKey: env.API_KEY || env.PLUNK_SECRET_KEY || '',
|
|
37
|
+
fromEmail: '',
|
|
38
|
+
fromName: '',
|
|
39
|
+
replyTo: undefined,
|
|
39
40
|
};
|
|
40
41
|
config.shop = {
|
|
41
|
-
paymentProvider: env.
|
|
42
|
-
stripeSecretKey: env.
|
|
43
|
-
stripeWebhookSecret: env.
|
|
44
|
-
stripePublishableKey: env.
|
|
42
|
+
paymentProvider: env.STRIPE_SECRET_KEY ? 'stripe' : 'bank_transfer',
|
|
43
|
+
stripeSecretKey: env.STRIPE_SECRET_KEY,
|
|
44
|
+
stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET,
|
|
45
|
+
stripePublishableKey: env.STRIPE_PUBLISHABLE_KEY,
|
|
45
46
|
};
|
|
46
47
|
return config;
|
|
47
48
|
}
|
|
@@ -82,15 +83,26 @@ export function getShopConfig(env) {
|
|
|
82
83
|
* @throws Error if GitHub is not configured (required variables missing)
|
|
83
84
|
*/
|
|
84
85
|
export function getGitHubConfig(env) {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
throw new Error(`GitHub not configured. Missing: ${
|
|
86
|
+
const missingRepositoryVars = getMissingVars(env, GIT_REPOSITORY_VARS);
|
|
87
|
+
if (missingRepositoryVars.length)
|
|
88
|
+
throw new Error(`GitHub not configured. Missing: ${missingRepositoryVars.join(', ')}`);
|
|
89
|
+
const repository = {
|
|
90
|
+
gitOwner: env.GIT_OWNER,
|
|
91
|
+
gitRepo: env.GIT_REPO,
|
|
92
|
+
gitBranch: env.GIT_BRANCH || 'main',
|
|
93
|
+
};
|
|
94
|
+
if (env.GITHUB_TOKEN_URL) {
|
|
95
|
+
if (!env.SECRET)
|
|
96
|
+
throw new Error('GitHub not configured. Missing: SECRET');
|
|
97
|
+
return { ...repository, githubTokenUrl: env.GITHUB_TOKEN_URL, runtimeSecret: env.SECRET };
|
|
98
|
+
}
|
|
99
|
+
const missingAppVars = getMissingVars(env, GITHUB_APP_VARS);
|
|
100
|
+
if (missingAppVars.length)
|
|
101
|
+
throw new Error(`GitHub not configured. Missing: ${missingAppVars.join(', ')}`);
|
|
88
102
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
githubInstallationId: env.HG_GITHUB_INSTALLATION_ID,
|
|
94
|
-
githubPrivateKey: env.HG_GITHUB_APP_PRIVATE_KEY,
|
|
103
|
+
...repository,
|
|
104
|
+
githubAppId: env.GITHUB_APP_ID,
|
|
105
|
+
githubInstallationId: env.GITHUB_INSTALLATION_ID,
|
|
106
|
+
githubPrivateKey: env.GITHUB_APP_PRIVATE_KEY,
|
|
95
107
|
};
|
|
96
108
|
}
|
package/dist/lib/email.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provider-agnostic email sending utility using Plunk.
|
|
3
|
-
* Reads
|
|
3
|
+
* Reads the API key from the Worker and sender details from GitHub-backed email settings.
|
|
4
4
|
*/
|
|
5
5
|
interface SendEmailParams {
|
|
6
6
|
to: string;
|
package/dist/lib/email.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,UAAU,eAAe;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAW/G;AAkCD;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BhB"}
|
package/dist/lib/email.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provider-agnostic email sending utility using Plunk.
|
|
3
|
-
* Reads
|
|
3
|
+
* Reads the API key from the Worker and sender details from GitHub-backed email settings.
|
|
4
4
|
*/
|
|
5
|
+
import { readEmailSettings } from '../api/emails/handlers/settings.handler';
|
|
5
6
|
import { renderEmailTemplate } from './email-template';
|
|
6
7
|
export async function sendEmail(env, params) {
|
|
7
|
-
const apiKey = env.
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const apiKey = env.API_KEY || env.PLUNK_SECRET_KEY;
|
|
9
|
+
const { settings } = await readEmailSettings(env);
|
|
10
|
+
const fromEmail = params.from ?? settings.fromEmail ?? '';
|
|
11
|
+
const fromName = params.fromName ?? settings.fromName ?? '';
|
|
12
|
+
const replyTo = params.replyTo ?? settings.replyTo;
|
|
10
13
|
if (!apiKey)
|
|
11
|
-
throw new Error('Plunk API key (
|
|
14
|
+
throw new Error('Plunk API key (API_KEY or PLUNK_SECRET_KEY) is not configured');
|
|
12
15
|
if (!fromEmail)
|
|
13
|
-
throw new Error('
|
|
14
|
-
await sendViaPlunk(apiKey, fromEmail, fromName, params);
|
|
16
|
+
throw new Error('Email sender address is not configured');
|
|
17
|
+
await sendViaPlunk(apiKey, fromEmail, fromName, { ...params, replyTo });
|
|
15
18
|
}
|
|
16
19
|
async function sendViaPlunk(apiKey, fromEmail, fromName, params) {
|
|
17
20
|
const body = {
|
|
@@ -59,9 +62,9 @@ export async function sendMagicLinkEmail(params) {
|
|
|
59
62
|
},
|
|
60
63
|
});
|
|
61
64
|
await sendEmail({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
API_KEY: params.apiKey,
|
|
66
|
+
FROM_EMAIL: params.fromEmail,
|
|
67
|
+
FROM_NAME: params.fromName,
|
|
65
68
|
}, {
|
|
66
69
|
to: params.to,
|
|
67
70
|
subject: 'Sign in to hintergrund',
|
package/dist/lib/github-app.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-app.d.ts","sourceRoot":"","sources":["../../src/lib/github-app.ts"],"names":[],"mappings":"AAiCA,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa1H"}
|
|
1
|
+
{"version":3,"file":"github-app.d.ts","sourceRoot":"","sources":["../../src/lib/github-app.ts"],"names":[],"mappings":"AAiCA,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBlG;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa1H"}
|
package/dist/lib/github-app.js
CHANGED
|
@@ -31,6 +31,27 @@ async function jwt(appId, pem) {
|
|
|
31
31
|
const signature = await crypto.subtle.sign('RSASSA-PKCS1-v1_5', key, encoder.encode(unsigned));
|
|
32
32
|
return `${unsigned}.${b64(new Uint8Array(signature))}`;
|
|
33
33
|
}
|
|
34
|
+
export async function brokeredGitHubToken(tokenUrl, runtimeSecret) {
|
|
35
|
+
const key = `broker:${tokenUrl}`;
|
|
36
|
+
const cached = cache.get(key);
|
|
37
|
+
if (cached && cached.expires > Date.now() + 60_000)
|
|
38
|
+
return cached.token;
|
|
39
|
+
const response = await fetch(tokenUrl, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: {
|
|
42
|
+
authorization: `Bearer ${runtimeSecret}`,
|
|
43
|
+
accept: 'application/json',
|
|
44
|
+
'user-agent': 'hintergrund-project',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok)
|
|
48
|
+
throw new Error('Managed GitHub authentication failed');
|
|
49
|
+
const result = await response.json();
|
|
50
|
+
if (!result.token || !result.expiresAt)
|
|
51
|
+
throw new Error('Managed GitHub authentication returned an invalid token');
|
|
52
|
+
cache.set(key, { token: result.token, expires: Date.parse(result.expiresAt) });
|
|
53
|
+
return result.token;
|
|
54
|
+
}
|
|
34
55
|
export async function githubToken(appId, installationId, privateKey, repo) {
|
|
35
56
|
const key = `${appId}:${installationId}:${repo}`;
|
|
36
57
|
const cached = cache.get(key);
|
|
@@ -39,7 +60,7 @@ export async function githubToken(appId, installationId, privateKey, repo) {
|
|
|
39
60
|
const response = await fetch(`https://api.github.com/app/installations/${installationId}/access_tokens`, {
|
|
40
61
|
method: 'POST',
|
|
41
62
|
headers: { authorization: `Bearer ${await jwt(appId, privateKey)}`, accept: 'application/vnd.github+json', 'user-agent': 'hintergrund-project' },
|
|
42
|
-
body: JSON.stringify({ repositories: [repo], permissions: { contents: 'write' } })
|
|
63
|
+
body: JSON.stringify({ repositories: [repo], permissions: { contents: 'write', actions: 'write' } })
|
|
43
64
|
});
|
|
44
65
|
if (!response.ok)
|
|
45
66
|
throw new Error('GitHub App authentication failed');
|
package/dist/lib/github.d.ts
CHANGED
|
@@ -8,14 +8,19 @@ import { Octokit } from '@octokit/rest';
|
|
|
8
8
|
/**
|
|
9
9
|
* GitHub configuration for a module
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
type GitHubRepositoryConfig = {
|
|
12
12
|
gitOwner: string;
|
|
13
13
|
gitRepo: string;
|
|
14
14
|
gitBranch: string;
|
|
15
|
+
};
|
|
16
|
+
export type GitHubConfig = GitHubRepositoryConfig & ({
|
|
17
|
+
githubTokenUrl: string;
|
|
18
|
+
runtimeSecret: string;
|
|
19
|
+
} | {
|
|
15
20
|
githubAppId: string;
|
|
16
21
|
githubInstallationId: string;
|
|
17
22
|
githubPrivateKey: string;
|
|
18
|
-
}
|
|
23
|
+
});
|
|
19
24
|
/**
|
|
20
25
|
* File entry for tree operations
|
|
21
26
|
*/
|
|
@@ -32,6 +37,11 @@ export interface FileReadResult {
|
|
|
32
37
|
content: string;
|
|
33
38
|
sha: string;
|
|
34
39
|
}
|
|
40
|
+
export interface GitHubSecret {
|
|
41
|
+
name: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
}
|
|
35
45
|
/**
|
|
36
46
|
* Decode base64 content to UTF-8 string.
|
|
37
47
|
* atob() decodes to Latin-1, which corrupts multi-byte UTF-8 characters.
|
|
@@ -121,6 +131,11 @@ export declare class GitHubClient {
|
|
|
121
131
|
* Get raw Octokit instance for advanced operations
|
|
122
132
|
*/
|
|
123
133
|
getOctokit(): Promise<Octokit>;
|
|
134
|
+
/** List repository Actions secrets. GitHub intentionally never returns their values. */
|
|
135
|
+
listActionsSecrets(): Promise<GitHubSecret[]>;
|
|
136
|
+
/** Create or replace a repository Actions secret. */
|
|
137
|
+
setActionsSecret(name: string, value: string): Promise<void>;
|
|
138
|
+
deleteActionsSecret(name: string): Promise<void>;
|
|
124
139
|
/**
|
|
125
140
|
* Get repository info
|
|
126
141
|
*/
|
|
@@ -134,4 +149,5 @@ export declare class GitHubClient {
|
|
|
134
149
|
* Create a GitHub client from CMS module config
|
|
135
150
|
*/
|
|
136
151
|
export declare function createGitHubClient(config: GitHubConfig): GitHubClient;
|
|
152
|
+
export {};
|
|
137
153
|
//# sourceMappingURL=github.d.ts.map
|
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;
|
|
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;AAKxC;;GAEG;AACH,KAAK,sBAAsB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,sBAAsB,GAAG,CACjD;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACtB,GACC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;CACzB,CACD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,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ub API interactions with proper UTF-8 handling.
|
|
6
6
|
*/
|
|
7
7
|
import { Octokit } from '@octokit/rest';
|
|
8
|
-
import
|
|
8
|
+
import nacl from 'tweetnacl';
|
|
9
|
+
import { blake2b } from 'blakejs';
|
|
10
|
+
import { brokeredGitHubToken, githubToken } from './github-app';
|
|
11
|
+
function toBase64(bytes) {
|
|
12
|
+
let binary = '';
|
|
13
|
+
for (const byte of bytes)
|
|
14
|
+
binary += String.fromCharCode(byte);
|
|
15
|
+
return btoa(binary);
|
|
16
|
+
}
|
|
17
|
+
/** Encrypt a value for GitHub Actions with its libsodium sealed-box format. */
|
|
18
|
+
function encryptActionsSecret(publicKey, value) {
|
|
19
|
+
const recipientKey = Uint8Array.from(atob(publicKey), (char) => char.charCodeAt(0));
|
|
20
|
+
const ephemeral = nacl.box.keyPair();
|
|
21
|
+
const nonceInput = new Uint8Array(ephemeral.publicKey.length + recipientKey.length);
|
|
22
|
+
nonceInput.set(ephemeral.publicKey);
|
|
23
|
+
nonceInput.set(recipientKey, ephemeral.publicKey.length);
|
|
24
|
+
const nonce = blake2b(nonceInput, undefined, 24);
|
|
25
|
+
const ciphertext = nacl.box(new TextEncoder().encode(value), nonce, recipientKey, ephemeral.secretKey);
|
|
26
|
+
if (!ciphertext)
|
|
27
|
+
throw new Error('Could not encrypt GitHub Actions secret');
|
|
28
|
+
const sealed = new Uint8Array(ephemeral.publicKey.length + ciphertext.length);
|
|
29
|
+
sealed.set(ephemeral.publicKey);
|
|
30
|
+
sealed.set(ciphertext, ephemeral.publicKey.length);
|
|
31
|
+
return toBase64(sealed);
|
|
32
|
+
}
|
|
9
33
|
/**
|
|
10
34
|
* Decode base64 content to UTF-8 string.
|
|
11
35
|
* atob() decodes to Latin-1, which corrupts multi-byte UTF-8 characters.
|
|
@@ -35,8 +59,10 @@ export function encodeUTF8Base64(str) {
|
|
|
35
59
|
*/
|
|
36
60
|
export class GitHubClient {
|
|
37
61
|
constructor(config) {
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
const token = 'githubTokenUrl' in config
|
|
63
|
+
? brokeredGitHubToken(config.githubTokenUrl, config.runtimeSecret)
|
|
64
|
+
: githubToken(config.githubAppId, config.githubInstallationId, config.githubPrivateKey, config.gitRepo);
|
|
65
|
+
this.octokitPromise = token.then((auth) => new Octokit({ auth }));
|
|
40
66
|
this.owner = config.gitOwner;
|
|
41
67
|
this.repo = config.gitRepo;
|
|
42
68
|
this.branch = config.gitBranch;
|
|
@@ -290,6 +316,38 @@ export class GitHubClient {
|
|
|
290
316
|
getOctokit() {
|
|
291
317
|
return this.octokit();
|
|
292
318
|
}
|
|
319
|
+
/** List repository Actions secrets. GitHub intentionally never returns their values. */
|
|
320
|
+
async listActionsSecrets() {
|
|
321
|
+
const response = await (await this.octokit()).rest.actions.listRepoSecrets({
|
|
322
|
+
owner: this.owner,
|
|
323
|
+
repo: this.repo,
|
|
324
|
+
per_page: 100,
|
|
325
|
+
});
|
|
326
|
+
return response.data.secrets.map((secret) => ({
|
|
327
|
+
name: secret.name,
|
|
328
|
+
createdAt: secret.created_at,
|
|
329
|
+
updatedAt: secret.updated_at,
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
/** Create or replace a repository Actions secret. */
|
|
333
|
+
async setActionsSecret(name, value) {
|
|
334
|
+
const octokit = await this.octokit();
|
|
335
|
+
const publicKey = await octokit.rest.actions.getRepoPublicKey({ owner: this.owner, repo: this.repo });
|
|
336
|
+
await octokit.rest.actions.createOrUpdateRepoSecret({
|
|
337
|
+
owner: this.owner,
|
|
338
|
+
repo: this.repo,
|
|
339
|
+
secret_name: name,
|
|
340
|
+
encrypted_value: encryptActionsSecret(publicKey.data.key, value),
|
|
341
|
+
key_id: publicKey.data.key_id,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
async deleteActionsSecret(name) {
|
|
345
|
+
await (await this.octokit()).rest.actions.deleteRepoSecret({
|
|
346
|
+
owner: this.owner,
|
|
347
|
+
repo: this.repo,
|
|
348
|
+
secret_name: name,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
293
351
|
/**
|
|
294
352
|
* Get repository info
|
|
295
353
|
*/
|
package/dist/lib/project-db.d.ts
CHANGED
|
@@ -11,10 +11,8 @@ export interface AdminUser {
|
|
|
11
11
|
updated_at: number;
|
|
12
12
|
}
|
|
13
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
14
|
export declare function getProjectDb(env: Bindings): D1Database;
|
|
16
15
|
export declare function ensureSchema(env: Bindings): Promise<D1Database>;
|
|
17
|
-
export declare const ensureProjectAdminSchema: typeof ensureSchema;
|
|
18
16
|
export declare function nowSeconds(): number;
|
|
19
17
|
export declare function createId(prefix: string): string;
|
|
20
18
|
export declare function sha256Base64Url(value: string): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-db.d.ts","sourceRoot":"","sources":["../../src/lib/project-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,YAAY,CAAC;AAEpD,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,aAAa,EAAE,MAAM,GAAG,IAAI,CA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,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAM/F;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM5E"}
|
package/dist/lib/project-db.js
CHANGED
|
@@ -113,10 +113,8 @@ CREATE INDEX IF NOT EXISTS idx_shop_orders_payment_method ON shop_orders(payment
|
|
|
113
113
|
CREATE INDEX IF NOT EXISTS idx_shop_orders_stripe_session ON shop_orders(stripe_session_id);
|
|
114
114
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_shop_orders_order_number ON shop_orders(order_number);
|
|
115
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
116
|
export function getProjectDb(env) {
|
|
119
|
-
const db = env.PROJECT_DB
|
|
117
|
+
const db = env.PROJECT_DB;
|
|
120
118
|
if (!db) {
|
|
121
119
|
throw new Error('PROJECT_DB binding is not configured');
|
|
122
120
|
}
|
|
@@ -133,8 +131,6 @@ export async function ensureSchema(env) {
|
|
|
133
131
|
}
|
|
134
132
|
return db;
|
|
135
133
|
}
|
|
136
|
-
// Backward-compatible alias
|
|
137
|
-
export const ensureProjectAdminSchema = ensureSchema;
|
|
138
134
|
export function nowSeconds() {
|
|
139
135
|
return Math.floor(Date.now() / 1000);
|
|
140
136
|
}
|
|
@@ -150,14 +146,14 @@ export async function sha256Base64Url(value) {
|
|
|
150
146
|
.replace(/\//g, '_');
|
|
151
147
|
}
|
|
152
148
|
export async function getAdminUserByEmail(env, email) {
|
|
153
|
-
const db = await
|
|
149
|
+
const db = await ensureSchema(env);
|
|
154
150
|
return await db
|
|
155
151
|
.prepare('SELECT * FROM admin_users WHERE email = ? AND disabled_at IS NULL LIMIT 1')
|
|
156
152
|
.bind(email.toLowerCase().trim())
|
|
157
153
|
.first();
|
|
158
154
|
}
|
|
159
155
|
export async function getAdminUserById(env, userId) {
|
|
160
|
-
const db = await
|
|
156
|
+
const db = await ensureSchema(env);
|
|
161
157
|
return await db
|
|
162
158
|
.prepare('SELECT * FROM admin_users WHERE id = ? AND disabled_at IS NULL LIMIT 1')
|
|
163
159
|
.bind(userId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/lib/template.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/lib/template.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAqG3F"}
|