@hintergrund/worker 0.1.6 → 0.1.8

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.
Files changed (190) hide show
  1. package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
  2. package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
  3. package/dist/api/cms/handlers/admin-users.handler.js +121 -0
  4. package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
  5. package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
  6. package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
  7. package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
  8. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/auth.handler.js +74 -153
  10. package/dist/api/cms/handlers/dashboard.handler.js +1 -1
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
  12. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  13. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  14. package/dist/api/cms/routes/index.d.ts.map +1 -1
  15. package/dist/api/cms/routes/index.js +16 -4
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  17. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  18. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  19. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  20. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  21. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  22. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  23. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  24. package/dist/api/emails/handlers/public.handler.js +150 -312
  25. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  26. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  27. package/dist/api/emails/handlers/send.handler.js +107 -92
  28. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  29. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  30. package/dist/api/emails/handlers/settings.handler.js +96 -287
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  32. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  33. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  34. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  35. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  36. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  37. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  38. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  39. package/dist/api/emails/routes/admin.routes.js +19 -49
  40. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  41. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  42. package/dist/api/emails/routes/public.routes.js +2 -9
  43. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  44. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  45. package/dist/api/shop/handlers/prices.handler.js +2 -83
  46. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  47. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  48. package/dist/api/shop/handlers/products.handler.js +195 -162
  49. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  50. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  51. package/dist/api/shop/handlers/public.handler.js +525 -78
  52. package/dist/api/shop/routes.d.ts.map +1 -1
  53. package/dist/api/shop/routes.js +14 -9
  54. package/dist/hintergrund-assets.d.ts +3 -2
  55. package/dist/hintergrund-assets.d.ts.map +1 -1
  56. package/dist/hintergrund-assets.js +4 -2
  57. package/dist/index.d.ts +15 -8
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +44 -4
  60. package/dist/lib/auth/crypto.d.ts +2 -15
  61. package/dist/lib/auth/crypto.d.ts.map +1 -1
  62. package/dist/lib/auth/crypto.js +8 -95
  63. package/dist/lib/auth/jwt.d.ts +0 -4
  64. package/dist/lib/auth/jwt.d.ts.map +1 -1
  65. package/dist/lib/auth/jwt.js +0 -6
  66. package/dist/lib/config.d.ts +8 -10
  67. package/dist/lib/config.d.ts.map +1 -1
  68. package/dist/lib/config.js +30 -106
  69. package/dist/lib/email-template.d.ts +15 -0
  70. package/dist/lib/email-template.d.ts.map +1 -0
  71. package/dist/lib/email-template.js +58 -0
  72. package/dist/lib/email.d.ts +18 -8
  73. package/dist/lib/email.d.ts.map +1 -1
  74. package/dist/lib/email.js +59 -70
  75. package/dist/lib/github-app.d.ts +2 -0
  76. package/dist/lib/github-app.d.ts.map +1 -0
  77. package/dist/lib/github-app.js +49 -0
  78. package/dist/lib/github-config.d.ts +19 -0
  79. package/dist/lib/github-config.d.ts.map +1 -0
  80. package/dist/lib/github-config.js +23 -0
  81. package/dist/lib/github.d.ts +16 -3
  82. package/dist/lib/github.d.ts.map +1 -1
  83. package/dist/lib/github.js +38 -15
  84. package/dist/lib/project-db.d.ts +24 -0
  85. package/dist/lib/project-db.d.ts.map +1 -0
  86. package/dist/lib/project-db.js +172 -0
  87. package/dist/lib/template.js +4 -4
  88. package/dist/middleware/auth.d.ts +0 -2
  89. package/dist/middleware/auth.d.ts.map +1 -1
  90. package/dist/middleware/auth.js +21 -50
  91. package/package.json +3 -2
  92. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  93. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  94. package/dist/api/builder/handlers/generate.handler.js +0 -203
  95. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  96. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  97. package/dist/api/builder/handlers/template.handler.js +0 -208
  98. package/dist/api/builder/routes.d.ts +0 -7
  99. package/dist/api/builder/routes.d.ts.map +0 -1
  100. package/dist/api/builder/routes.js +0 -15
  101. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  102. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  103. package/dist/api/cms/handlers/assets.handler.js +0 -200
  104. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  105. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  106. package/dist/api/cms/handlers/config.handler.js +0 -37
  107. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  108. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  109. package/dist/api/cms/handlers/content.handler.js +0 -117
  110. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  111. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  112. package/dist/api/cms/routes/assets.routes.js +0 -13
  113. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  114. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  115. package/dist/api/cms/routes/content.routes.js +0 -11
  116. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  117. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  118. package/dist/api/emails/handlers/branding.handler.js +0 -120
  119. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  120. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  121. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  122. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  123. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  124. package/dist/api/emails/handlers/templates.handler.js +0 -132
  125. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  126. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  127. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  128. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  129. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  130. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  131. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  132. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  133. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  134. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  135. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  136. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  137. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  138. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  139. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  140. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  141. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  142. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  143. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  144. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  145. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  146. package/dist/api/newsletter/routes/index.d.ts +0 -4
  147. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  148. package/dist/api/newsletter/routes/index.js +0 -9
  149. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  150. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  151. package/dist/api/newsletter/routes/public.routes.js +0 -9
  152. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  153. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  154. package/dist/api/shop/handlers/assets.handler.js +0 -62
  155. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  156. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  157. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  158. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  159. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  160. package/dist/api/shop/handlers/customers.handler.js +0 -89
  161. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  162. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  163. package/dist/api/shop/handlers/orders.handler.js +0 -84
  164. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  165. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  166. package/dist/api/shop/handlers/stats.handler.js +0 -71
  167. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  168. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  169. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  170. package/dist/cms-assets.d.ts +0 -4
  171. package/dist/cms-assets.d.ts.map +0 -1
  172. package/dist/cms-assets.js +0 -5
  173. package/dist/cms-bundle.d.ts +0 -3
  174. package/dist/cms-bundle.d.ts.map +0 -1
  175. package/dist/cms-bundle.js +0 -4
  176. package/dist/config-loader.d.ts +0 -26
  177. package/dist/config-loader.d.ts.map +0 -1
  178. package/dist/config-loader.js +0 -98
  179. package/dist/jwt.d.ts +0 -26
  180. package/dist/jwt.d.ts.map +0 -1
  181. package/dist/jwt.js +0 -102
  182. package/dist/lib/plunk.d.ts +0 -204
  183. package/dist/lib/plunk.d.ts.map +0 -1
  184. package/dist/lib/plunk.js +0 -259
  185. package/dist/template.d.ts +0 -2
  186. package/dist/template.d.ts.map +0 -1
  187. package/dist/template.js +0 -61
  188. package/dist/utils.d.ts +0 -23
  189. package/dist/utils.d.ts.map +0 -1
  190. package/dist/utils.js +0 -110
package/dist/index.d.ts CHANGED
@@ -1,28 +1,35 @@
1
1
  import { Hono } from 'hono';
2
2
  export type Bindings = {
3
- HG_CONFIG?: string;
4
3
  HG_SECRET?: string;
5
- HG_PASSWORD?: string;
6
- HG_GIT_TOKEN?: string;
4
+ HG_BOOTSTRAP_TOKEN?: string;
5
+ HG_ALLOWED_ORIGINS?: string;
7
6
  HG_GIT_OWNER?: string;
8
7
  HG_GIT_REPO?: string;
9
8
  HG_GIT_BRANCH?: string;
10
- HG_EMAILS_PLUNK_SECRET_KEY?: string;
11
- HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
9
+ HG_GITHUB_APP_ID?: string;
10
+ HG_GITHUB_INSTALLATION_ID?: string;
11
+ HG_GITHUB_APP_PRIVATE_KEY?: string;
12
+ HG_EMAILS_API_KEY?: string;
13
+ HG_EMAILS_PROVIDER?: string;
12
14
  HG_EMAILS_FROM_EMAIL?: string;
13
15
  HG_EMAILS_FROM_NAME?: string;
14
16
  HG_EMAILS_REPLY_TO?: string;
17
+ HG_EMAILS_PLUNK_SECRET_KEY?: string;
18
+ HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
15
19
  HG_SHOP_STRIPE_SECRET_KEY?: string;
16
20
  HG_SHOP_STRIPE_WEBHOOK_SECRET?: string;
17
21
  HG_SHOP_STRIPE_PUBLISHABLE_KEY?: string;
22
+ GEMINI_API_KEY?: string;
18
23
  UI_BASE_URL: string;
19
24
  ASSETS: Fetcher;
25
+ PROJECT_DB?: D1Database;
26
+ SHOP_DB?: D1Database;
20
27
  };
21
28
  export type Variables = {
22
29
  user?: {
23
- email: string;
24
- userGroup?: string;
25
- modules?: string[];
30
+ userId?: string;
31
+ email?: string;
32
+ name?: string | null;
26
33
  };
27
34
  };
28
35
  export type HonoEnv = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAQ5B,MAAM,MAAM,QAAQ,GAAG;IAEtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAG5B,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,8BAA8B,CAAC,EAAE,MAAM,CAAC;IAGxC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,CAAC,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAEnE,wBAAgB,SAAS,yDA8DxB;AAGD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAU5B,MAAM,MAAM,QAAQ,GAAG;IAEtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAG5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAGnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAGpC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,8BAA8B,CAAC,EAAE,MAAM,CAAC;IAGxC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,UAAU,CAAC;CACrB,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,yDAmGxB;AAGD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -5,12 +5,44 @@ 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 { ensureProjectAdminSchema } from './lib/project-db';
8
9
  export function createApp() {
9
10
  const app = new Hono();
10
- // Add CORS middleware
11
- app.use('*', cors());
11
+ app.use('*', async (c, next) => {
12
+ const allowedOrigins = (c.env.HG_ALLOWED_ORIGINS ?? '')
13
+ .split(',')
14
+ .map((origin) => origin.trim())
15
+ .filter(Boolean);
16
+ return cors({
17
+ origin: (origin) => {
18
+ if (!origin)
19
+ return null;
20
+ if (allowedOrigins.length === 0) {
21
+ return new URL(c.req.url).origin === origin ? origin : null;
22
+ }
23
+ return allowedOrigins.includes(origin) ? origin : null;
24
+ },
25
+ credentials: true,
26
+ })(c, next);
27
+ });
12
28
  // Login page route (public)
13
- app.get('/login', (c) => c.html(getTemplate('login', c.env.UI_BASE_URL)));
29
+ app.get('/login', async (c) => {
30
+ let configParams = '';
31
+ try {
32
+ if (c.env.PROJECT_DB || c.env.SHOP_DB) {
33
+ const db = await ensureProjectAdminSchema(c.env);
34
+ const methods = await db
35
+ .prepare('SELECT login_method, COUNT(*) AS count FROM admin_users WHERE disabled_at IS NULL GROUP BY login_method ORDER BY count DESC')
36
+ .all();
37
+ const loginMethod = methods.results?.[0]?.login_method === 'magic-link' ? 'magic-link' : 'password';
38
+ configParams = `config='${JSON.stringify({ loginMethod })}'`;
39
+ }
40
+ }
41
+ catch (error) {
42
+ console.error('Failed to load project login config:', error);
43
+ }
44
+ return c.html(getTemplate('login', c.env.UI_BASE_URL, configParams));
45
+ });
14
46
  // Mount CMS routes under /api/admin
15
47
  app.route('/api/admin', cmsRoutes);
16
48
  // Mount email routes under /api/email
@@ -32,12 +64,20 @@ export function createApp() {
32
64
  const { loadConfig, getAdminConfig } = await import('./lib/config');
33
65
  const appConfig = loadConfig(c.env);
34
66
  const adminConfig = getAdminConfig(appConfig);
67
+ adminConfig.canManageAdminUsers = true;
68
+ adminConfig.integrations = {
69
+ stripePublishableKeySet: !!c.env.HG_SHOP_STRIPE_PUBLISHABLE_KEY,
70
+ stripeSecretKeySet: !!c.env.HG_SHOP_STRIPE_SECRET_KEY && c.env.HG_SHOP_STRIPE_SECRET_KEY !== 'NOT_CONFIGURED',
71
+ stripeWebhookSecretSet: !!c.env.HG_SHOP_STRIPE_WEBHOOK_SECRET && c.env.HG_SHOP_STRIPE_WEBHOOK_SECRET !== 'NOT_CONFIGURED',
72
+ emailProviderApiKeySet: !!(c.env.HG_EMAILS_API_KEY || c.env.HG_EMAILS_PLUNK_SECRET_KEY),
73
+ geminiApiKeySet: !!c.env.GEMINI_API_KEY && c.env.GEMINI_API_KEY !== 'NOT_CONFIGURED',
74
+ };
35
75
  const configParams = `config='${JSON.stringify(adminConfig)}'`;
36
76
  return c.html(getTemplate('admin', c.env.UI_BASE_URL, configParams));
37
77
  }
38
78
  catch (error) {
39
79
  // Fallback to default config if parsing fails
40
- const configParams = 'config=\'{"cms":true,"emails":false,"shop":false}\'';
80
+ const configParams = 'config=\'{"loginMethod":"password"}\'';
41
81
  return c.html(getTemplate('admin', c.env.UI_BASE_URL, configParams));
42
82
  }
43
83
  });
@@ -1,23 +1,10 @@
1
- /**
2
- * Generates a random token used as a Secret Key
3
- */
1
+ import { decrypt, readRequestBody } from '@hintergrund/auth';
2
+ export { decrypt, readRequestBody };
4
3
  export declare function generateRandomToken(): string;
5
- /**
6
- * Hash a password with salt and pepper
7
- */
8
4
  export declare function hashPw(password: string, pepper: string): Promise<string>;
9
5
  /**
10
6
  * Verify a password against an encrypted password
11
7
  * Uses AES-GCM decryption to match hintergrund.cloud's encryption method
12
8
  */
13
9
  export declare function verifyPw(encryptedPassword: string, password: string, secret: string): Promise<boolean>;
14
- /**
15
- * Decrypts an encrypted string using AES-GCM
16
- * Matches hintergrund.cloud's decrypt function
17
- */
18
- export declare function decrypt(ciphertext: string, secret: string): Promise<string>;
19
- /**
20
- * Read and parse request body
21
- */
22
- export declare function readRequestBody(request: Request): Promise<any>;
23
10
  //# sourceMappingURL=crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/crypto.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2B9E;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5G;AAiBD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BjF;AAiBD;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAepE"}
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EAGP,eAAe,EAEf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AAEpC,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,wBAAsB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9E;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAU5G"}
@@ -1,110 +1,23 @@
1
- /**
2
- * Generates a random token used as a Secret Key
3
- */
1
+ import { decrypt, generateRandomSecret, hashPassword, readRequestBody, verifyPassword } from '@hintergrund/auth';
2
+ export { decrypt, readRequestBody };
4
3
  export function generateRandomToken() {
5
- const tokenBytes = crypto.getRandomValues(new Uint8Array(32));
6
- return btoa(String.fromCharCode(...tokenBytes));
4
+ return generateRandomSecret();
7
5
  }
8
- /**
9
- * Hash a password with salt and pepper
10
- */
11
6
  export async function hashPw(password, pepper) {
12
- // Create salt
13
- const salt = crypto.getRandomValues(new Uint8Array(16));
14
- // Convert password and pepper to Uint8Array
15
- const pass = new TextEncoder().encode(password);
16
- const pepp = new TextEncoder().encode(pepper);
17
- // Combine salt, pepper, and password hash
18
- const combined = new Uint8Array(salt.length + pepper.length + password.length);
19
- combined.set(salt);
20
- combined.set(pepp, salt.length);
21
- combined.set(pass, salt.length + pepper.length);
22
- // Hash combined
23
- const hashBuffer = await crypto.subtle.digest('SHA-256', combined);
24
- // Convert hashBuffer to Uint8Array
25
- const hash = new Uint8Array(hashBuffer);
26
- // Combine salt and hash
27
- const combinedHash = new Uint8Array(salt.length + hash.length);
28
- combinedHash.set(salt);
29
- combinedHash.set(hash, salt.length);
30
- // Return combined hash as base64 string
31
- return btoa(new Uint8Array(combinedHash).reduce((s, b) => s + String.fromCharCode(b), ''));
7
+ return hashPassword(password, pepper);
32
8
  }
33
9
  /**
34
10
  * Verify a password against an encrypted password
35
11
  * Uses AES-GCM decryption to match hintergrund.cloud's encryption method
36
12
  */
37
13
  export async function verifyPw(encryptedPassword, password, secret) {
38
- try {
39
- const decryptedPassword = await decrypt(encryptedPassword, secret);
40
- return decryptedPassword === password;
41
- }
42
- catch (error) {
43
- return false;
14
+ if (await verifyPassword(password, secret, encryptedPassword)) {
15
+ return true;
44
16
  }
45
- }
46
- /**
47
- * Derives a cryptographic key from the secret string
48
- */
49
- async function deriveKey(secret) {
50
- const secretBytes = new TextEncoder().encode(secret);
51
- const keyMaterial = await crypto.subtle.digest('SHA-256', secretBytes);
52
- return await crypto.subtle.importKey('raw', keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
53
- }
54
- /**
55
- * Decrypts an encrypted string using AES-GCM
56
- * Matches hintergrund.cloud's decrypt function
57
- */
58
- export async function decrypt(ciphertext, secret) {
59
17
  try {
60
- // Decode from base64
61
- const combined = Uint8Array.from(atob(ciphertext), (c) => c.charCodeAt(0));
62
- // Extract IV (first 12 bytes)
63
- const iv = combined.slice(0, 12);
64
- // Extract encrypted data (remaining bytes)
65
- const encryptedData = combined.slice(12);
66
- // Derive decryption key
67
- const key = await deriveKey(secret);
68
- // Decrypt
69
- const decryptedBuffer = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encryptedData);
70
- // Convert bytes back to string
71
- return new TextDecoder().decode(decryptedBuffer);
72
- }
73
- catch (error) {
74
- throw new Error('Decryption failed');
18
+ return (await decrypt(encryptedPassword, secret)) === password;
75
19
  }
76
- }
77
- /**
78
- * Compare two Uint8Arrays for equality
79
- */
80
- function areUint8ArraysEqual(a, b) {
81
- if (a.length !== b.length) {
20
+ catch {
82
21
  return false;
83
22
  }
84
- for (let i = 0; i < a.length; i++) {
85
- if (a[i] !== b[i]) {
86
- return false;
87
- }
88
- }
89
- return true;
90
- }
91
- /**
92
- * Read and parse request body
93
- */
94
- export async function readRequestBody(request) {
95
- const contentType = request.headers.get('content-type');
96
- if (!contentType)
97
- throw new Error('Content-Type not set');
98
- if (contentType.includes('application/json')) {
99
- return await request.json();
100
- }
101
- else if (contentType.includes('form')) {
102
- const formData = await request.formData();
103
- const body = {};
104
- for (const entry of formData.entries()) {
105
- body[entry[0]] = entry[1];
106
- }
107
- return body;
108
- }
109
- throw new Error('Content-Type not supported');
110
23
  }
@@ -11,10 +11,6 @@ interface JwtData {
11
11
  header: JwtHeader;
12
12
  payload: JwtPayload;
13
13
  }
14
- /**
15
- * Signs a payload and returns the token
16
- */
17
- export declare function sign(secret: string): Promise<string>;
18
14
  /**
19
15
  * Signs a payload with custom data and returns the token
20
16
  * @param secret The secret key for signing
@@ -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;;GAEG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1D;AAED;;;;;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,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGnF;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK7C"}
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,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGnF;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK7C"}
@@ -51,12 +51,6 @@ function decodePayload(raw) {
51
51
  return;
52
52
  }
53
53
  }
54
- /**
55
- * Signs a payload and returns the token
56
- */
57
- export async function sign(secret) {
58
- return signWithPayload(secret, {});
59
- }
60
54
  /**
61
55
  * Signs a payload with custom data and returns the token
62
56
  * @param secret The secret key for signing
@@ -1,18 +1,14 @@
1
- import type { AppConfig, AdminConfig, CmsModuleConfig, EmailsModuleConfig, ShopModuleConfig } from '@hintergrund/shared';
1
+ import type { AppConfig, AdminConfig, EmailsModuleConfig, ShopModuleConfig } from '@hintergrund/runtime-contracts';
2
2
  /**
3
3
  * Load application configuration from environment variables
4
4
  * Supports both new modular env vars and legacy HG_CONFIG format
5
5
  */
6
6
  export declare function loadConfig(env: Record<string, string | undefined> | any): AppConfig;
7
7
  /**
8
- * Get admin UI configuration (which modules are enabled)
8
+ * Get admin UI configuration.
9
+ * All product modules are always active; the newsletter is toggled in email settings.
9
10
  */
10
- export declare function getAdminConfig(appConfig: AppConfig): AdminConfig;
11
- /**
12
- * Get CMS module configuration
13
- * @throws Error if CMS module is not enabled
14
- */
15
- export declare function getCmsConfig(env: Record<string, string | undefined> | any): CmsModuleConfig;
11
+ export declare function getAdminConfig(_appConfig: AppConfig): AdminConfig;
16
12
  /**
17
13
  * Get Emails module configuration
18
14
  * @throws Error if Emails module is not enabled
@@ -29,9 +25,11 @@ export declare function getShopConfig(env: Record<string, string | undefined> |
29
25
  * @throws Error if GitHub is not configured (required variables missing)
30
26
  */
31
27
  export declare function getGitHubConfig(env: Record<string, string | undefined> | any): {
32
- gitToken: string;
33
28
  gitOwner: string;
34
29
  gitRepo: string;
35
- gitBranch: string;
30
+ gitBranch: any;
31
+ githubAppId: string;
32
+ githubInstallationId: string;
33
+ githubPrivateKey: string;
36
34
  };
37
35
  //# 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,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAsC,MAAM,qBAAqB,CAAC;AAE7J;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,SAAS,CAOnF;AAmHD;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW,CAQhE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,eAAe,CAQ3F;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,GAAG;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB,CAYA"}
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;cAI7C,MAAM;aACR,MAAM;;iBAEG,MAAM;0BACY,MAAM;sBACV,MAAM;EAE1D"}
@@ -4,133 +4,56 @@
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.HG_SECRET && (env.HG_PASSWORD || env.HG_AUTH_METHOD)) {
7
+ if (env.HG_SECRET) {
8
8
  return loadFromEnvVars(env);
9
9
  }
10
- throw new Error('No configuration found. Set HG_SECRET and either HG_PASSWORD or HG_AUTH_METHOD.');
10
+ throw new Error('No configuration found. Set HG_SECRET.');
11
11
  }
12
12
  /**
13
13
  * Check which required variables are missing for a module
14
+ * Treats empty strings and "NOT_CONFIGURED" placeholder as missing
14
15
  */
15
16
  function getMissingVars(env, requiredVars) {
16
- return requiredVars.filter(varName => !env[varName]);
17
+ return requiredVars.filter(varName => {
18
+ const value = env[varName];
19
+ return !value || value === 'NOT_CONFIGURED';
20
+ });
17
21
  }
18
22
  /**
19
23
  * Check if any variable from a list is set (module is attempted)
24
+ * Treats empty strings and "NOT_CONFIGURED" placeholder as not set
20
25
  */
21
- function hasAnyVar(env, vars) {
22
- return vars.some(varName => !!env[varName]);
23
- }
24
- // Module required variables definitions
25
- const GIT_REQUIRED_VARS = ['HG_GIT_TOKEN', 'HG_GIT_OWNER', 'HG_GIT_REPO'];
26
- const CMS_REQUIRED_VARS = [...GIT_REQUIRED_VARS];
27
- const EMAILS_REQUIRED_VARS = ['HG_EMAILS_PLUNK_SECRET_KEY', 'HG_EMAILS_FROM_EMAIL'];
28
- const SHOP_REQUIRED_VARS = ['HG_SHOP_STRIPE_SECRET_KEY'];
29
- /**
30
- * Parse user groups from environment variable
31
- * Format: JSON array of UserGroup objects
32
- * Example: [{"name":"admin","password":"encrypted"},{"name":"editors","emails":["a@b.com"]}]
33
- */
34
- function parseUserGroups(env) {
35
- if (!env.HG_AUTH_USER_GROUPS)
36
- return undefined;
37
- try {
38
- const groups = JSON.parse(env.HG_AUTH_USER_GROUPS);
39
- if (Array.isArray(groups)) {
40
- return groups;
41
- }
42
- }
43
- catch (e) {
44
- console.error('Failed to parse HG_AUTH_USER_GROUPS:', e);
45
- }
46
- return undefined;
47
- }
48
- /**
49
- * Load config from new modular environment variables
50
- * Auto-detects module availability based on required variables
51
- */
26
+ const GIT_REQUIRED_VARS = ['HG_GIT_OWNER', 'HG_GIT_REPO', 'HG_GITHUB_APP_ID', 'HG_GITHUB_INSTALLATION_ID', 'HG_GITHUB_APP_PRIVATE_KEY'];
52
27
  function loadFromEnvVars(env) {
53
- // Build auth configuration
54
- const loginMethod = env.HG_AUTH_METHOD || 'password';
55
- const userGroups = parseUserGroups(env);
56
- // Parse allowed emails whitelist
57
- const allowedEmailsRaw = env.HG_AUTH_ALLOWED_EMAILS;
58
- const allowedEmails = allowedEmailsRaw
59
- ? allowedEmailsRaw.split(',').map((e) => e.trim()).filter((e) => e.length > 0)
60
- : undefined;
61
- const authConfig = env.HG_AUTH_METHOD ? {
62
- loginMethod,
63
- allowedEmails,
64
- userGroups,
65
- } : undefined;
66
28
  const config = {
67
29
  global: {
68
30
  hgSecret: env.HG_SECRET || '',
69
- hgPassword: env.HG_PASSWORD,
70
- auth: authConfig,
71
31
  },
72
32
  };
73
- // Load CMS module config (auto-detect based on required vars)
74
- const cmsMissing = getMissingVars(env, CMS_REQUIRED_VARS);
75
- if (cmsMissing.length === 0) {
76
- config.cms = {
77
- enabled: true,
78
- gitToken: env.HG_GIT_TOKEN || '',
79
- gitOwner: env.HG_GIT_OWNER || '',
80
- gitRepo: env.HG_GIT_REPO || '',
81
- gitBranch: env.HG_GIT_BRANCH || 'main',
82
- contentDir: 'frontend/src/lib/content',
83
- assetDir: 'frontend/static',
84
- };
85
- }
86
- // Load Emails module config (auto-detect based on required vars)
87
- const emailsMissing = getMissingVars(env, EMAILS_REQUIRED_VARS);
88
- if (emailsMissing.length === 0) {
89
- config.emails = {
90
- enabled: true,
91
- plunkSecretKey: env.HG_EMAILS_PLUNK_SECRET_KEY || '',
92
- plunkPublicKey: env.HG_EMAILS_PLUNK_PUBLIC_KEY,
93
- fromEmail: env.HG_EMAILS_FROM_EMAIL || '',
94
- fromName: env.HG_EMAILS_FROM_NAME || '',
95
- replyTo: env.HG_EMAILS_REPLY_TO,
96
- };
97
- }
98
- // Load Shop module config (auto-detect based on required vars)
99
- const shopMissing = getMissingVars(env, SHOP_REQUIRED_VARS);
100
- if (shopMissing.length === 0) {
101
- config.shop = {
102
- enabled: true,
103
- paymentProvider: 'stripe',
104
- stripeSecretKey: env.HG_SHOP_STRIPE_SECRET_KEY || '',
105
- stripeWebhookSecret: env.HG_SHOP_STRIPE_WEBHOOK_SECRET,
106
- stripePublishableKey: env.HG_SHOP_STRIPE_PUBLISHABLE_KEY,
107
- };
108
- }
33
+ config.emails = {
34
+ emailProvider: 'plunk',
35
+ emailApiKey: env.HG_EMAILS_API_KEY || env.HG_EMAILS_PLUNK_SECRET_KEY || '',
36
+ fromEmail: env.HG_EMAILS_FROM_EMAIL || '',
37
+ fromName: env.HG_EMAILS_FROM_NAME || '',
38
+ replyTo: env.HG_EMAILS_REPLY_TO,
39
+ };
40
+ config.shop = {
41
+ paymentProvider: env.HG_SHOP_STRIPE_SECRET_KEY ? 'stripe' : 'bank_transfer',
42
+ stripeSecretKey: env.HG_SHOP_STRIPE_SECRET_KEY,
43
+ stripeWebhookSecret: env.HG_SHOP_STRIPE_WEBHOOK_SECRET,
44
+ stripePublishableKey: env.HG_SHOP_STRIPE_PUBLISHABLE_KEY,
45
+ };
109
46
  return config;
110
47
  }
111
48
  /**
112
- * Get admin UI configuration (which modules are enabled)
49
+ * Get admin UI configuration.
50
+ * All product modules are always active; the newsletter is toggled in email settings.
113
51
  */
114
- export function getAdminConfig(appConfig) {
52
+ export function getAdminConfig(_appConfig) {
115
53
  return {
116
- cms: appConfig.cms?.enabled ?? false,
117
- emails: appConfig.emails?.enabled ?? false,
118
- shop: appConfig.shop?.enabled ?? false,
119
- loginMethod: appConfig.global.auth?.loginMethod ?? 'password',
120
- userGroups: appConfig.global.auth?.userGroups?.map(g => g.name),
54
+ loginMethod: 'password',
121
55
  };
122
56
  }
123
- /**
124
- * Get CMS module configuration
125
- * @throws Error if CMS module is not enabled
126
- */
127
- export function getCmsConfig(env) {
128
- const config = loadConfig(env);
129
- if (!config.cms) {
130
- throw new Error('CMS module is not enabled');
131
- }
132
- return config.cms;
133
- }
134
57
  /**
135
58
  * Get Emails module configuration
136
59
  * @throws Error if Emails module is not enabled
@@ -160,13 +83,14 @@ export function getShopConfig(env) {
160
83
  */
161
84
  export function getGitHubConfig(env) {
162
85
  const missing = getMissingVars(env, GIT_REQUIRED_VARS);
163
- if (missing.length > 0) {
86
+ if (missing.length)
164
87
  throw new Error(`GitHub not configured. Missing: ${missing.join(', ')}`);
165
- }
166
88
  return {
167
- gitToken: env.HG_GIT_TOKEN,
168
89
  gitOwner: env.HG_GIT_OWNER,
169
90
  gitRepo: env.HG_GIT_REPO,
170
91
  gitBranch: env.HG_GIT_BRANCH || 'main',
92
+ githubAppId: env.HG_GITHUB_APP_ID,
93
+ githubInstallationId: env.HG_GITHUB_INSTALLATION_ID,
94
+ githubPrivateKey: env.HG_GITHUB_APP_PRIVATE_KEY,
171
95
  };
172
96
  }
@@ -0,0 +1,15 @@
1
+ export interface RenderEmailTemplateOptions {
2
+ bodyHtml: string;
3
+ template?: Partial<EmailTemplateConfig>;
4
+ logoDataUrl?: string;
5
+ unsubscribeUrl?: string;
6
+ footerHtml?: string;
7
+ }
8
+ export interface EmailTemplateConfig {
9
+ html: string;
10
+ primaryColor: string;
11
+ footerHtml: string;
12
+ }
13
+ export declare const DEFAULT_EMAIL_TEMPLATE: EmailTemplateConfig;
14
+ export declare function renderEmailTemplate(options: RenderEmailTemplateOptions): string;
15
+ //# sourceMappingURL=email-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-template.d.ts","sourceRoot":"","sources":["../../src/lib/email-template.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,sBAAsB,EAAE,mBAsBpC,CAAC;AAoBF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAkB/E"}
@@ -0,0 +1,58 @@
1
+ export const DEFAULT_EMAIL_TEMPLATE = {
2
+ primaryColor: '#111827',
3
+ footerHtml: '<p>You are receiving this email because you subscribed to updates from us.</p>',
4
+ html: `<!doctype html>
5
+ <html>
6
+ <head>
7
+ <meta charset="utf-8">
8
+ <meta name="viewport" content="width=device-width,initial-scale=1">
9
+ </head>
10
+ <body style="margin:0;padding:0;background:#f6f8fa;">
11
+ <div style="background:#f6f8fa;padding:40px 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;font-size:14px;line-height:1.5;color:#24292f;">
12
+ <div style="max-width:580px;margin:0 auto;background:#ffffff;border:1px solid #d0d7de;border-radius:8px;padding:32px;">
13
+ {{logo}}
14
+ {{content}}
15
+ </div>
16
+ <div style="max-width:580px;margin:20px auto 0;padding:0 32px;font-size:12px;color:#6e7781;text-align:center;">
17
+ {{footer}}
18
+ {{unsubscribe}}
19
+ </div>
20
+ </div>
21
+ </body>
22
+ </html>`,
23
+ };
24
+ function cleanCssValue(value, fallback) {
25
+ return value && !/[<>"']/.test(value) ? value : fallback;
26
+ }
27
+ function styleEmailBody(bodyHtml, primaryColor) {
28
+ return bodyHtml
29
+ .replace(/<(h[1-4])([^>]*)>/gi, (match, tag, attributes) => {
30
+ if (/style=/i.test(attributes)) {
31
+ return match.replace(/style=(["'])(.*?)\1/i, `style=$1color:${primaryColor};$2$1`);
32
+ }
33
+ return `<${tag}${attributes} style="color:${primaryColor};">`;
34
+ })
35
+ .replace(/<img([^>]*)>/gi, (match) => {
36
+ if (/style=/i.test(match))
37
+ return match;
38
+ return match.replace(/>$/, ' style="max-width:300px;display:block;margin:0 auto;height:auto;">');
39
+ });
40
+ }
41
+ export function renderEmailTemplate(options) {
42
+ const template = { ...DEFAULT_EMAIL_TEMPLATE, ...(options.template ?? {}) };
43
+ const primaryColor = cleanCssValue(template.primaryColor, DEFAULT_EMAIL_TEMPLATE.primaryColor);
44
+ const bodyHtml = styleEmailBody(options.bodyHtml, primaryColor);
45
+ const logoHtml = options.logoDataUrl
46
+ ? `<div style="text-align:center;margin:0 0 20px 0;"><img src="${options.logoDataUrl}" alt="Logo" style="max-width:120px;max-height:80px;height:auto;"></div>`
47
+ : '';
48
+ const footerHtml = options.footerHtml ?? template.footerHtml ?? '';
49
+ const unsubscribeHtml = options.unsubscribeUrl
50
+ ? `<p style="margin:10px 0 0 0;"><a href="${options.unsubscribeUrl}" style="color:inherit;text-decoration:underline;">Unsubscribe</a></p>`
51
+ : '';
52
+ return template.html
53
+ .replaceAll('{{content}}', bodyHtml)
54
+ .replaceAll('{{logo}}', logoHtml)
55
+ .replaceAll('{{footer}}', footerHtml)
56
+ .replaceAll('{{unsubscribe}}', unsubscribeHtml)
57
+ .replaceAll('{{unsubscribe_url}}', options.unsubscribeUrl ?? '');
58
+ }
@@ -1,16 +1,26 @@
1
1
  /**
2
- * Email sending utilities using Resend API
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
- interface SendMagicLinkParams {
5
+ interface SendEmailParams {
5
6
  to: string;
6
- resendApiKey?: string;
7
- plunkSecretKey: string;
8
- magicLinkUrl: string;
9
- userGroup?: string;
7
+ toName?: string;
8
+ subject: string;
9
+ html: string;
10
+ from?: string;
11
+ fromName?: string;
12
+ replyTo?: string;
10
13
  }
14
+ export declare function sendEmail(env: Record<string, string | undefined>, params: SendEmailParams): Promise<void>;
11
15
  /**
12
- * Send a magic link email for passwordless authentication
16
+ * Send a magic link email for passwordless admin authentication.
13
17
  */
14
- export declare function sendMagicLinkEmail(params: SendMagicLinkParams): Promise<void>;
18
+ export declare function sendMagicLinkEmail(params: {
19
+ to: string;
20
+ apiKey: string;
21
+ fromEmail: string;
22
+ fromName?: string;
23
+ magicLinkUrl: string;
24
+ }): Promise<void>;
15
25
  export {};
16
26
  //# sourceMappingURL=email.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,UAAU,mBAAmB;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+EnF"}
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,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,CAS/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"}