@hintergrund/worker 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) 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/website-repo.handler.d.ts +8 -0
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  12. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  13. package/dist/api/cms/routes/index.d.ts.map +1 -1
  14. package/dist/api/cms/routes/index.js +16 -4
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  17. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  18. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  19. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  20. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  21. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  22. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  23. package/dist/api/emails/handlers/public.handler.js +150 -312
  24. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  25. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  26. package/dist/api/emails/handlers/send.handler.js +107 -92
  27. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  28. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  29. package/dist/api/emails/handlers/settings.handler.js +96 -287
  30. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  32. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  33. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  34. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  35. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  36. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  37. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  38. package/dist/api/emails/routes/admin.routes.js +19 -49
  39. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  40. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  41. package/dist/api/emails/routes/public.routes.js +2 -9
  42. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  43. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  44. package/dist/api/shop/handlers/prices.handler.js +2 -83
  45. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  46. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  47. package/dist/api/shop/handlers/products.handler.js +195 -162
  48. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  49. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  50. package/dist/api/shop/handlers/public.handler.js +525 -78
  51. package/dist/api/shop/routes.d.ts.map +1 -1
  52. package/dist/api/shop/routes.js +14 -9
  53. package/dist/hintergrund-assets.d.ts +3 -2
  54. package/dist/hintergrund-assets.d.ts.map +1 -1
  55. package/dist/hintergrund-assets.js +4 -2
  56. package/dist/index.d.ts +14 -7
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +44 -4
  59. package/dist/lib/auth/crypto.d.ts +2 -15
  60. package/dist/lib/auth/crypto.d.ts.map +1 -1
  61. package/dist/lib/auth/crypto.js +8 -95
  62. package/dist/lib/auth/jwt.d.ts +0 -4
  63. package/dist/lib/auth/jwt.d.ts.map +1 -1
  64. package/dist/lib/auth/jwt.js +0 -6
  65. package/dist/lib/config.d.ts +1 -1
  66. package/dist/lib/config.d.ts.map +1 -1
  67. package/dist/lib/config.js +42 -86
  68. package/dist/lib/email-template.d.ts +15 -0
  69. package/dist/lib/email-template.d.ts.map +1 -0
  70. package/dist/lib/email-template.js +58 -0
  71. package/dist/lib/email.d.ts +18 -8
  72. package/dist/lib/email.d.ts.map +1 -1
  73. package/dist/lib/email.js +59 -70
  74. package/dist/lib/github-config.d.ts +19 -0
  75. package/dist/lib/github-config.d.ts.map +1 -0
  76. package/dist/lib/github-config.js +23 -0
  77. package/dist/lib/github.d.ts +10 -0
  78. package/dist/lib/github.d.ts.map +1 -1
  79. package/dist/lib/github.js +20 -2
  80. package/dist/lib/project-db.d.ts +24 -0
  81. package/dist/lib/project-db.d.ts.map +1 -0
  82. package/dist/lib/project-db.js +172 -0
  83. package/dist/lib/template.js +4 -4
  84. package/dist/middleware/auth.d.ts +0 -2
  85. package/dist/middleware/auth.d.ts.map +1 -1
  86. package/dist/middleware/auth.js +21 -50
  87. package/package.json +2 -1
  88. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  89. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  90. package/dist/api/builder/handlers/generate.handler.js +0 -203
  91. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  92. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  93. package/dist/api/builder/handlers/template.handler.js +0 -208
  94. package/dist/api/builder/routes.d.ts +0 -7
  95. package/dist/api/builder/routes.d.ts.map +0 -1
  96. package/dist/api/builder/routes.js +0 -15
  97. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  98. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  99. package/dist/api/cms/handlers/assets.handler.js +0 -200
  100. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  101. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  102. package/dist/api/cms/handlers/config.handler.js +0 -37
  103. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  104. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  105. package/dist/api/cms/handlers/content.handler.js +0 -117
  106. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  107. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  108. package/dist/api/cms/routes/assets.routes.js +0 -13
  109. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  110. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  111. package/dist/api/cms/routes/content.routes.js +0 -11
  112. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  113. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  114. package/dist/api/emails/handlers/branding.handler.js +0 -120
  115. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  116. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  117. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  118. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  119. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  120. package/dist/api/emails/handlers/templates.handler.js +0 -132
  121. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  122. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  123. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  124. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  125. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  126. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  127. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  128. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  129. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  130. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  131. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  132. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  133. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  134. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  135. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  136. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  137. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  138. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  139. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  140. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  141. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  142. package/dist/api/newsletter/routes/index.d.ts +0 -4
  143. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  144. package/dist/api/newsletter/routes/index.js +0 -9
  145. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  146. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  147. package/dist/api/newsletter/routes/public.routes.js +0 -9
  148. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  149. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  150. package/dist/api/shop/handlers/assets.handler.js +0 -62
  151. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  152. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  153. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  154. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  155. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  156. package/dist/api/shop/handlers/customers.handler.js +0 -89
  157. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  158. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  159. package/dist/api/shop/handlers/orders.handler.js +0 -84
  160. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  161. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  162. package/dist/api/shop/handlers/stats.handler.js +0 -71
  163. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  164. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  165. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  166. package/dist/cms-assets.d.ts +0 -4
  167. package/dist/cms-assets.d.ts.map +0 -1
  168. package/dist/cms-assets.js +0 -5
  169. package/dist/cms-bundle.d.ts +0 -3
  170. package/dist/cms-bundle.d.ts.map +0 -1
  171. package/dist/cms-bundle.js +0 -4
  172. package/dist/config-loader.d.ts +0 -26
  173. package/dist/config-loader.d.ts.map +0 -1
  174. package/dist/config-loader.js +0 -98
  175. package/dist/jwt.d.ts +0 -26
  176. package/dist/jwt.d.ts.map +0 -1
  177. package/dist/jwt.js +0 -102
  178. package/dist/lib/plunk.d.ts +0 -204
  179. package/dist/lib/plunk.d.ts.map +0 -1
  180. package/dist/lib/plunk.js +0 -259
  181. package/dist/template.d.ts +0 -2
  182. package/dist/template.d.ts.map +0 -1
  183. package/dist/template.js +0 -61
  184. package/dist/utils.d.ts +0 -23
  185. package/dist/utils.d.ts.map +0 -1
  186. 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;
4
+ HG_BOOTSTRAP_TOKEN?: string;
5
+ HG_ALLOWED_ORIGINS?: string;
6
6
  HG_GIT_TOKEN?: string;
7
7
  HG_GIT_OWNER?: string;
8
8
  HG_GIT_REPO?: string;
9
9
  HG_GIT_BRANCH?: string;
10
- HG_EMAILS_PLUNK_SECRET_KEY?: string;
11
- HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
10
+ HG_EMAILS_API_KEY?: string;
11
+ HG_EMAILS_PROVIDER?: string;
12
12
  HG_EMAILS_FROM_EMAIL?: string;
13
13
  HG_EMAILS_FROM_NAME?: string;
14
14
  HG_EMAILS_REPLY_TO?: string;
15
+ HG_EMAILS_PLUNK_SECRET_KEY?: string;
16
+ HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
17
+ /** Set to 'true' to hide campaigns and only allow transactional sends */
18
+ HG_EMAILS_TRANSACTIONAL_ONLY?: 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,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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
@@ -31,7 +63,15 @@ export function createApp() {
31
63
  try {
32
64
  const { loadConfig, getAdminConfig } = await import('./lib/config');
33
65
  const appConfig = loadConfig(c.env);
34
- const adminConfig = getAdminConfig(appConfig);
66
+ const adminConfig = getAdminConfig(appConfig, c.env);
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
  }
@@ -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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7C"}
@@ -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
@@ -7,7 +7,7 @@ export declare function loadConfig(env: Record<string, string | undefined> | any
7
7
  /**
8
8
  * Get admin UI configuration (which modules are enabled)
9
9
  */
10
- export declare function getAdminConfig(appConfig: AppConfig): AdminConfig;
10
+ export declare function getAdminConfig(appConfig: AppConfig, env?: Record<string, string | undefined>): AdminConfig;
11
11
  /**
12
12
  * Get CMS module configuration
13
13
  * @throws Error if CMS module is not enabled
@@ -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,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AC,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"}
@@ -4,120 +4,76 @@
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
26
  function hasAnyVar(env, vars) {
22
- return vars.some(varName => !!env[varName]);
27
+ return vars.some(varName => {
28
+ const value = env[varName];
29
+ return !!value && value !== 'NOT_CONFIGURED';
30
+ });
23
31
  }
24
32
  // Module required variables definitions
25
33
  const GIT_REQUIRED_VARS = ['HG_GIT_TOKEN', 'HG_GIT_OWNER', 'HG_GIT_REPO'];
26
34
  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
- */
35
+ const EMAILS_REQUIRED_VARS = ['HG_EMAILS_API_KEY', 'HG_EMAILS_FROM_EMAIL'];
36
+ const SHOP_REQUIRED_VARS = [...GIT_REQUIRED_VARS];
52
37
  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
38
  const config = {
67
39
  global: {
68
40
  hgSecret: env.HG_SECRET || '',
69
- hgPassword: env.HG_PASSWORD,
70
- auth: authConfig,
71
41
  },
72
42
  };
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
- }
43
+ config.cms = {
44
+ gitToken: env.HG_GIT_TOKEN || '',
45
+ gitOwner: env.HG_GIT_OWNER || '',
46
+ gitRepo: env.HG_GIT_REPO || '',
47
+ gitBranch: env.HG_GIT_BRANCH || 'main',
48
+ contentDir: 'frontend/src/lib/content',
49
+ assetDir: 'frontend/static/cms',
50
+ };
51
+ config.emails = {
52
+ emailProvider: 'plunk',
53
+ emailApiKey: env.HG_EMAILS_API_KEY || env.HG_EMAILS_PLUNK_SECRET_KEY || '',
54
+ fromEmail: env.HG_EMAILS_FROM_EMAIL || '',
55
+ fromName: env.HG_EMAILS_FROM_NAME || '',
56
+ replyTo: env.HG_EMAILS_REPLY_TO,
57
+ };
58
+ config.shop = {
59
+ paymentProvider: env.HG_SHOP_STRIPE_SECRET_KEY ? 'stripe' : 'bank_transfer',
60
+ stripeSecretKey: env.HG_SHOP_STRIPE_SECRET_KEY,
61
+ stripeWebhookSecret: env.HG_SHOP_STRIPE_WEBHOOK_SECRET,
62
+ stripePublishableKey: env.HG_SHOP_STRIPE_PUBLISHABLE_KEY,
63
+ };
109
64
  return config;
110
65
  }
111
66
  /**
112
67
  * Get admin UI configuration (which modules are enabled)
113
68
  */
114
- export function getAdminConfig(appConfig) {
69
+ export function getAdminConfig(appConfig, env) {
115
70
  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),
71
+ builder: true,
72
+ cms: true,
73
+ emails: true,
74
+ shop: true,
75
+ loginMethod: 'password',
76
+ emailsTransactionalOnly: env?.HG_EMAILS_TRANSACTIONAL_ONLY === 'true' || undefined,
121
77
  };
122
78
  }
123
79
  /**
@@ -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"}