@hintergrund/worker 0.1.12 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"setup.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/setup.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AASpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAc9C,uFAAuF;AACvF,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0DzE;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7E"}
1
+ {"version":3,"file":"setup.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/setup.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AASpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA8B9C,uFAAuF;AACvF,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiFzE;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAE7E"}
@@ -6,6 +6,20 @@ 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
+ const SHOP_SETTINGS_PATH = 'frontend/src/lib/shop/settings.json';
10
+ const GLOBALS_PATH = 'frontend/src/lib/content/globals.json';
11
+ const DEFAULT_SHOP_SETTINGS = {
12
+ currency: 'eur',
13
+ enabledPaymentMethods: ['bank_transfer'],
14
+ bankTransfer: { accountHolder: '', iban: '', bic: '', bankName: '', instructions: 'Please use your order number as the payment reference.' },
15
+ shippingFlatRate: 0,
16
+ freeShippingThreshold: 0,
17
+ orderNumberPrefix: 'ORD',
18
+ invoiceNumberPrefix: 'INV',
19
+ };
20
+ function slugify(value) {
21
+ return value.toLowerCase().normalize('NFKD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'site';
22
+ }
9
23
  async function hasAdminUsers(c) {
10
24
  const db = await ensureSchema(c.env);
11
25
  const row = await db.prepare('SELECT COUNT(*) AS count FROM admin_users').first();
@@ -23,9 +37,10 @@ export async function setupProject(c) {
23
37
  const body = await c.req.json();
24
38
  const email = typeof body.email === 'string' ? body.email.trim().toLowerCase() : '';
25
39
  const password = typeof body.password === 'string' ? body.password : '';
26
- const name = typeof body.name === 'string' ? body.name.trim() : null;
27
- if (!email || !password)
28
- return c.json({ error: 'Email and password are required.' }, 400);
40
+ const name = typeof body.username === 'string' ? body.username.trim() : null;
41
+ const siteTitle = typeof body.siteTitle === 'string' ? body.siteTitle.trim() : '';
42
+ if (!email || !password || !siteTitle)
43
+ return c.json({ error: 'Site title, email, and password are required.' }, 400);
29
44
  if (password.length < 12)
30
45
  return c.json({ error: 'Use a password of at least 12 characters.' }, 400);
31
46
  const db = await ensureSchema(c.env);
@@ -38,7 +53,7 @@ export async function setupProject(c) {
38
53
  .bind(user.id, user.email, user.name, user.password_hash, user.login_method, now, now).run();
39
54
  try {
40
55
  const client = createGitHubClient(getGitHubConfig(c.env));
41
- const stripeSecretKey = typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey : '';
56
+ const stripeSecretKey = body.paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
42
57
  let stripeWebhookSecret = typeof body.stripeWebhookSecret === 'string' ? body.stripeWebhookSecret : '';
43
58
  if (stripeSecretKey && !stripeWebhookSecret) {
44
59
  try {
@@ -62,6 +77,28 @@ export async function setupProject(c) {
62
77
  secrets[name] = value;
63
78
  }
64
79
  await Promise.all(Object.entries(secrets).map(([secretName, value]) => client.setActionsSecret(secretName, value)));
80
+ const { data: globals, commitSha: globalsCommitSha } = await readJsonConfig(client, GLOBALS_PATH, { siteName: '', siteSlug: '' });
81
+ await writeJsonConfig(client, GLOBALS_PATH, {
82
+ ...globals,
83
+ siteName: siteTitle,
84
+ siteSlug: slugify(siteTitle),
85
+ }, 'Set initial site title [skip ci]', globalsCommitSha);
86
+ 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
+ await writeJsonConfig(client, SHOP_SETTINGS_PATH, {
89
+ ...DEFAULT_SHOP_SETTINGS,
90
+ ...shopSettings,
91
+ enabledPaymentMethods: stripeSecretKey ? ['bank_transfer', 'stripe'] : ['bank_transfer'],
92
+ bankTransfer: {
93
+ ...DEFAULT_SHOP_SETTINGS.bankTransfer,
94
+ ...(shopSettings.bankTransfer ?? {}),
95
+ accountHolder: typeof bankTransfer.accountHolder === 'string' ? bankTransfer.accountHolder.trim() : '',
96
+ iban: typeof bankTransfer.iban === 'string' ? bankTransfer.iban.trim() : '',
97
+ bic: typeof bankTransfer.bic === 'string' ? bankTransfer.bic.trim() : '',
98
+ bankName: typeof bankTransfer.bankName === 'string' ? bankTransfer.bankName.trim() : '',
99
+ instructions: typeof bankTransfer.instructions === 'string' ? bankTransfer.instructions.trim() : DEFAULT_SHOP_SETTINGS.bankTransfer.instructions,
100
+ },
101
+ }, 'Configure bank transfer payments [skip ci]', shopCommitSha);
65
102
  const { data: emailSettings, commitSha } = await readJsonConfig(client, EMAIL_SETTINGS_PATH, DEFAULT_EMAIL_SETTINGS);
66
103
  await writeJsonConfig(client, EMAIL_SETTINGS_PATH, {
67
104
  ...emailSettings,
@@ -70,8 +107,7 @@ export async function setupProject(c) {
70
107
  replyTo: typeof body.replyTo === 'string' ? body.replyTo.trim() : emailSettings.replyTo,
71
108
  updatedAt: Date.now(),
72
109
  }, 'Configure email sender settings [skip ci]', commitSha);
73
- if (Object.keys(secrets).length)
74
- await deploy(c);
110
+ await deploy(c);
75
111
  }
76
112
  catch (error) {
77
113
  console.error('Project setup integrations could not be saved:', error);
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export type Bindings = {
9
9
  GITHUB_APP_ID?: string;
10
10
  GITHUB_INSTALLATION_ID?: string;
11
11
  GITHUB_APP_PRIVATE_KEY?: string;
12
+ GITHUB_TOKEN_URL?: string;
12
13
  API_KEY?: string;
13
14
  FROM_EMAIL?: string;
14
15
  FROM_NAME?: string;
@@ -1 +1 @@
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;IAGhC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,g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B,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"}
@@ -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
@@ -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;AA4CD;;;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;cAIhD,MAAM;aACR,MAAM;;iBAEG,MAAM;0BACY,MAAM;sBACV,MAAM;EAEvD"}
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"}
@@ -23,7 +23,8 @@ 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 GIT_REQUIRED_VARS = ['GIT_OWNER', 'GIT_REPO', 'GITHUB_APP_ID', 'GITHUB_INSTALLATION_ID', 'GITHUB_APP_PRIVATE_KEY'];
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: {
@@ -82,13 +83,24 @@ 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 missing = getMissingVars(env, GIT_REQUIRED_VARS);
86
- if (missing.length)
87
- throw new Error(`GitHub not configured. Missing: ${missing.join(', ')}`);
88
- return {
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 = {
89
90
  gitOwner: env.GIT_OWNER,
90
91
  gitRepo: env.GIT_REPO,
91
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(', ')}`);
102
+ return {
103
+ ...repository,
92
104
  githubAppId: env.GITHUB_APP_ID,
93
105
  githubInstallationId: env.GITHUB_INSTALLATION_ID,
94
106
  githubPrivateKey: env.GITHUB_APP_PRIVATE_KEY,
@@ -1,2 +1,3 @@
1
+ export declare function brokeredGitHubToken(tokenUrl: string, runtimeSecret: string): Promise<string>;
1
2
  export declare function githubToken(appId: string, installationId: string, privateKey: string, repo: string): Promise<string>;
2
3
  //# sourceMappingURL=github-app.d.ts.map
@@ -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"}
@@ -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);
@@ -8,14 +8,19 @@ import { Octokit } from '@octokit/rest';
8
8
  /**
9
9
  * GitHub configuration for a module
10
10
  */
11
- export interface GitHubConfig {
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
  */
@@ -144,4 +149,5 @@ export declare class GitHubClient {
144
149
  * Create a GitHub client from CMS module config
145
150
  */
146
151
  export declare function createGitHubClient(config: GitHubConfig): GitHubClient;
152
+ export {};
147
153
  //# source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EAAE,YAAY,GAAG,YAAY,CAErE"}
@@ -7,7 +7,7 @@
7
7
  import { Octokit } from '@octokit/rest';
8
8
  import nacl from 'tweetnacl';
9
9
  import { blake2b } from 'blakejs';
10
- import { githubToken } from './github-app';
10
+ import { brokeredGitHubToken, githubToken } from './github-app';
11
11
  function toBase64(bytes) {
12
12
  let binary = '';
13
13
  for (const byte of bytes)
@@ -59,8 +59,10 @@ export function encodeUTF8Base64(str) {
59
59
  */
60
60
  export class GitHubClient {
61
61
  constructor(config) {
62
- this.octokitPromise = githubToken(config.githubAppId, config.githubInstallationId, config.githubPrivateKey, config.gitRepo)
63
- .then((token) => new Octokit({ auth: token }));
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 }));
64
66
  this.owner = config.gitOwner;
65
67
  this.repo = config.gitRepo;
66
68
  this.branch = config.gitBranch;
@@ -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,CA+O3F"}
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"}
@@ -4,232 +4,94 @@ export function getTemplate(element, uiBaseUrl, params = '') {
4
4
  return `
5
5
  <!doctype html>
6
6
  <html>
7
- <head>
8
- <meta charset="utf-8">
9
- <meta name="viewport" content="width=device-width, initial-scale=1">
10
- <title>Login</title>
11
- <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
12
- <style>
13
- * { box-sizing: border-box; margin: 0; padding: 0; }
14
- body { margin: 0; height: 100vh; }
15
- </style>
16
- <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
17
- </head>
18
- <body>
19
- <hintergrund-login ${params}></hintergrund-login>
20
- <script type="module" src="${uiBaseUrl}/login.js"></script>
21
- </body>
22
- </html>
23
- `;
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <title>Login</title>
11
+ <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
12
+ <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; height: 100vh; }</style>
13
+ <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
14
+ </head>
15
+ <body>
16
+ <hintergrund-login ${params}></hintergrund-login>
17
+ <script type="module" src="${uiBaseUrl}/login.js"></script>
18
+ </body>
19
+ </html>`;
24
20
  }
25
21
  if (element === 'setup') {
26
22
  return `
27
23
  <!doctype html>
28
- <html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Set up your project</title>
29
- <style>body{margin:0;background:#f6f8fa;color:#24292f;font:16px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}.card{max-width:560px;margin:8vh auto;padding:2rem;background:#fff;border:1px solid #d0d7de;border-radius:8px}h1{margin:0 0 .5rem}p{color:#57606a;line-height:1.5}form{display:grid;gap:.8rem;margin-top:1.5rem}label{font-weight:600;font-size:.9rem}input{padding:.7rem;border:1px solid #d0d7de;border-radius:6px;font:inherit}button{padding:.75rem;border:0;border-radius:6px;background:#1f883d;color:#fff;font:inherit;font-weight:600;cursor:pointer}.optional{font-weight:400;color:#57606a}.error{color:#cf222e;min-height:1.3em}</style></head>
30
- <body><main class="card"><h1>Set up your project</h1><p>Create the first administrator. Stripe and Plunk are optional and can be changed later from the project admin.</p>
31
- <form id="setup"><label>Email<input name="email" type="email" required autocomplete="email"></label><label>Name <span class="optional">(optional)</span><input name="name" autocomplete="name"></label><label>Password<input name="password" type="password" required minlength="12" autocomplete="new-password"></label><label>Plunk API key <span class="optional">(optional)</span><input name="plunkApiKey" type="password"></label><label>Sender email <span class="optional">(for magic links)</span><input name="fromEmail" type="email"></label><label>Sender name <span class="optional">(optional)</span><input name="fromName"></label><label>Reply-to email <span class="optional">(optional)</span><input name="replyTo" type="email"></label><label>Stripe secret key <span class="optional">(optional)</span><input name="stripeSecretKey" type="password"></label><label>Stripe webhook secret <span class="optional">(auto-created if blank)</span><input name="stripeWebhookSecret" type="password"></label><p class="error" id="error"></p><button>Finish setup</button></form></main>
32
- <script>document.querySelector('#setup').addEventListener('submit',async(e)=>{e.preventDefault();const form=e.currentTarget,button=form.querySelector('button'),error=document.querySelector('#error');button.disabled=true;error.textContent='';const data=Object.fromEntries(new FormData(form));try{const response=await fetch('/api/admin/setup',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(data)});const result=await response.json();if(!response.ok)throw new Error(result.error||'Setup failed');location.href='/admin'}catch(err){error.textContent=err.message||'Setup failed';button.disabled=false}})</script></body></html>`;
24
+ <html>
25
+ <head>
26
+ <meta charset="utf-8">
27
+ <meta name="viewport" content="width=device-width, initial-scale=1">
28
+ <title>Set up your site</title>
29
+ <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
30
+ <style>body { margin: 0; }</style>
31
+ <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
32
+ </head>
33
+ <body>
34
+ <hintergrund-setup></hintergrund-setup>
35
+ <script type="module" src="${uiBaseUrl}/setup.js"></script>
36
+ </body>
37
+ </html>`;
33
38
  }
34
39
  if (element === 'admin') {
35
40
  return `
36
41
  <!doctype html>
37
42
  <html>
38
- <head>
39
- <meta charset="utf-8">
40
- <meta name="viewport" content="width=device-width, initial-scale=1">
41
- <title>Hintergrund Admin</title>
42
- <meta name="description" content="Admin Panel for Hintergrund">
43
- <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
44
- <style>
45
- * { box-sizing: border-box; margin: 0; padding: 0; }
46
- body { margin: 0; height: 100vh; }
47
- </style>
48
- <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
49
- </head>
50
- <body>
51
- <hintergrund-admin ${params}></hintergrund-admin>
52
- <script type="module" src="${uiBaseUrl}/admin.js"></script>
53
- </body>
54
- </html>
55
- `;
43
+ <head>
44
+ <meta charset="utf-8">
45
+ <meta name="viewport" content="width=device-width, initial-scale=1">
46
+ <title>Hintergrund Admin</title>
47
+ <meta name="description" content="Admin Panel for Hintergrund">
48
+ <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
49
+ <style>* { box-sizing: border-box; margin: 0; padding: 0; } body { margin: 0; height: 100vh; }</style>
50
+ <link rel="stylesheet" href="${uiBaseUrl}/ui.css">
51
+ </head>
52
+ <body>
53
+ <hintergrund-admin ${params}></hintergrund-admin>
54
+ <script type="module" src="${uiBaseUrl}/admin.js"></script>
55
+ </body>
56
+ </html>`;
56
57
  }
57
58
  if (element === 'unsubscribe') {
58
59
  return `
59
60
  <!doctype html>
60
61
  <html>
61
- <head>
62
- <meta charset="utf-8">
63
- <meta name="viewport" content="width=device-width, initial-scale=1">
64
- <title>Unsubscribe</title>
65
- <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
66
- <style>
67
- * { box-sizing: border-box; margin: 0; padding: 0; }
68
- body {
69
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
70
- background: #f6f8fa;
71
- display: flex;
72
- align-items: center;
73
- justify-content: center;
74
- min-height: 100vh;
75
- padding: 1rem;
76
- }
77
- .container {
78
- background: white;
79
- border-radius: 8px;
80
- border: 1px solid #d0d7de;
81
- padding: 2rem;
82
- max-width: 480px;
83
- width: 100%;
84
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
85
- }
86
- h1 {
87
- font-size: 1.5rem;
88
- font-weight: 600;
89
- margin-bottom: 1rem;
90
- color: #24292f;
91
- }
92
- p {
93
- color: #57606a;
94
- line-height: 1.5;
95
- margin-bottom: 1.5rem;
96
- }
97
- .buttons {
98
- display: flex;
99
- gap: 0.75rem;
100
- }
101
- button {
102
- flex: 1;
103
- padding: 0.75rem 1rem;
104
- font-size: 0.875rem;
105
- font-weight: 500;
106
- border-radius: 6px;
107
- border: 1px solid;
108
- cursor: pointer;
109
- transition: all 0.15s ease;
110
- }
111
- .btn-primary {
112
- background: #cf222e;
113
- color: white;
114
- border-color: #cf222e;
115
- }
116
- .btn-primary:hover {
117
- background: #a40e26;
118
- border-color: #a40e26;
119
- }
120
- .btn-secondary {
121
- background: #f6f8fa;
122
- color: #24292f;
123
- border-color: #d0d7de;
124
- }
125
- .btn-secondary:hover {
126
- background: #f3f4f6;
127
- border-color: #b1b9c2;
128
- }
129
- .message {
130
- padding: 1rem;
131
- border-radius: 6px;
132
- margin-bottom: 1rem;
133
- display: none;
134
- }
135
- .message.success {
136
- background: #dafbe1;
137
- color: #1a7f37;
138
- border: 1px solid #1a7f37;
139
- }
140
- .message.error {
141
- background: #ffebe9;
142
- color: #cf222e;
143
- border: 1px solid #cf222e;
144
- }
145
- .spinner {
146
- display: none;
147
- border: 2px solid #f3f4f6;
148
- border-top: 2px solid #cf222e;
149
- border-radius: 50%;
150
- width: 16px;
151
- height: 16px;
152
- animation: spin 0.6s linear infinite;
153
- margin: 0 auto;
154
- }
155
- @keyframes spin {
156
- 0% { transform: rotate(0deg); }
157
- 100% { transform: rotate(360deg); }
158
- }
159
- </style>
160
- </head>
161
- <body>
162
- <div class="container">
163
- <h1>Unsubscribe from Emails</h1>
164
- <div id="message" class="message"></div>
165
- <div id="content">
166
- <p>Are you sure you want to unsubscribe from updates?</p>
167
- <div class="buttons">
168
- <button class="btn-secondary" onclick="window.close()">Cancel</button>
169
- <button class="btn-primary" onclick="handleUnsubscribe()">Unsubscribe</button>
170
- </div>
171
- </div>
172
- <div id="spinner" class="spinner"></div>
173
- </div>
174
- <script>
175
- ${params}
176
-
177
- async function handleUnsubscribe() {
178
- const content = document.getElementById('content');
179
- const spinner = document.getElementById('spinner');
180
- const message = document.getElementById('message');
181
-
182
- content.style.display = 'none';
183
- spinner.style.display = 'block';
184
-
185
- try {
186
- const response = await fetch('/api/email/unsubscribe', {
187
- method: 'POST',
188
- headers: { 'Content-Type': 'application/json' },
189
- body: JSON.stringify({ token })
190
- });
191
-
192
- const data = await response.json();
193
- spinner.style.display = 'none';
194
-
195
- if (data.success) {
196
- message.className = 'message success';
197
- message.textContent = data.message || 'You have been unsubscribed successfully.';
198
- message.style.display = 'block';
199
- } else {
200
- message.className = 'message error';
201
- message.textContent = data.message || 'Failed to unsubscribe. Please try again.';
202
- message.style.display = 'block';
203
- content.style.display = 'block';
204
- }
205
- } catch (error) {
206
- spinner.style.display = 'none';
207
- message.className = 'message error';
208
- message.textContent = 'Network error. Please try again.';
209
- message.style.display = 'block';
210
- content.style.display = 'block';
211
- }
212
- }
213
- </script>
214
- </body>
215
- </html>
216
- `;
62
+ <head>
63
+ <meta charset="utf-8">
64
+ <meta name="viewport" content="width=device-width, initial-scale=1">
65
+ <title>Unsubscribe</title>
66
+ <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
67
+ <style>
68
+ * { box-sizing: border-box; margin: 0; padding: 0; }
69
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f6f8fa; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
70
+ .container { background: white; border-radius: 8px; border: 1px solid #d0d7de; padding: 2rem; max-width: 480px; width: 100%; }
71
+ h1 { font-size: 1.5rem; margin-bottom: 1rem; } p { color: #57606a; line-height: 1.5; margin-bottom: 1.5rem; }
72
+ .buttons { display: flex; gap: .75rem; } button { flex: 1; padding: .75rem 1rem; border-radius: 6px; border: 1px solid; cursor: pointer; }
73
+ .btn-primary { background: #cf222e; color: white; border-color: #cf222e; } .btn-secondary { background: #f6f8fa; color: #24292f; border-color: #d0d7de; }
74
+ .message { padding: 1rem; border-radius: 6px; margin-bottom: 1rem; display: none; } .message.success { background: #dafbe1; color: #1a7f37; border: 1px solid #1a7f37; } .message.error { background: #ffebe9; color: #cf222e; border: 1px solid #cf222e; }
75
+ .spinner { display: none; border: 2px solid #f3f4f6; border-top-color: #cf222e; border-radius: 50%; width: 16px; height: 16px; animation: spin .6s linear infinite; margin: 0 auto; } @keyframes spin { to { transform: rotate(360deg); } }
76
+ </style>
77
+ </head>
78
+ <body>
79
+ <div class="container"><h1>Unsubscribe from Emails</h1><div id="message" class="message"></div><div id="content"><p>Are you sure you want to unsubscribe from updates?</p><div class="buttons"><button class="btn-secondary" onclick="window.close()">Cancel</button><button class="btn-primary" onclick="handleUnsubscribe()">Unsubscribe</button></div></div><div id="spinner" class="spinner"></div></div>
80
+ <script>
81
+ ${params}
82
+ async function handleUnsubscribe() {
83
+ const content = document.getElementById('content'), spinner = document.getElementById('spinner'), message = document.getElementById('message');
84
+ content.style.display = 'none'; spinner.style.display = 'block';
85
+ try {
86
+ const response = await fetch('/api/email/unsubscribe', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }) });
87
+ const data = await response.json(); spinner.style.display = 'none';
88
+ if (data.success) { message.className = 'message success'; message.textContent = data.message || 'You have been unsubscribed successfully.'; message.style.display = 'block'; }
89
+ else { message.className = 'message error'; message.textContent = data.message || 'Failed to unsubscribe. Please try again.'; message.style.display = 'block'; content.style.display = 'block'; }
90
+ } catch (error) { spinner.style.display = 'none'; message.className = 'message error'; message.textContent = 'Network error. Please try again.'; message.style.display = 'block'; content.style.display = 'block'; }
91
+ }
92
+ </script>
93
+ </body>
94
+ </html>`;
217
95
  }
218
- return `
219
- <!doctype html>
220
- <html>
221
- <head>
222
- <meta charset="utf-8">
223
- <meta name="viewport" content="width=device-width, initial-scale=1">
224
- <title>Hintergrund CMS</title>
225
- <meta name="description" content="Admin Panel for Hintergrund CMS">
226
- <link rel="icon" type="image/svg+xml" href="${faviconSvg}">
227
- <style>body{margin:0}</style>
228
- </head>
229
- <body>
230
- <${element} ${params}></${element}>
231
- <script type="module" src="/index.js"></script>
232
- </body>
233
- </html>
234
- `;
96
+ return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Hintergrund CMS</title><meta name="description" content="Admin Panel for Hintergrund CMS"><link rel="icon" type="image/svg+xml" href="${faviconSvg}"><style>body{margin:0}</style></head><body><${element} ${params}></${element}><script type="module" src="/index.js"></script></body></html>`;
235
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hintergrund/worker",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",