@hintergrund/worker 0.1.1 → 0.1.3

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 (94) hide show
  1. package/dist/api/cms/handlers/assets.handler.d.ts +24 -1
  2. package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
  3. package/dist/api/cms/handlers/assets.handler.js +111 -210
  4. package/dist/api/cms/handlers/config.handler.d.ts +4 -0
  5. package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
  6. package/dist/api/cms/handlers/config.handler.js +20 -71
  7. package/dist/api/cms/handlers/content.handler.d.ts +12 -1
  8. package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/content.handler.js +57 -233
  10. package/dist/api/cms/handlers/dashboard.handler.js +1 -1
  11. package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
  12. package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
  13. package/dist/api/emails/handlers/branding.handler.js +120 -0
  14. package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
  16. package/dist/api/emails/handlers/campaigns.handler.js +139 -0
  17. package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
  18. package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
  19. package/dist/api/emails/handlers/contacts.handler.js +161 -0
  20. package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
  21. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
  22. package/dist/api/emails/handlers/invoice.handler.js +463 -0
  23. package/dist/api/emails/handlers/public.handler.d.ts +36 -0
  24. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
  25. package/dist/api/emails/handlers/public.handler.js +350 -0
  26. package/dist/api/emails/handlers/send.handler.d.ts +23 -0
  27. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
  28. package/dist/api/emails/handlers/send.handler.js +117 -0
  29. package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
  30. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
  31. package/dist/api/emails/handlers/settings.handler.js +312 -0
  32. package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
  33. package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
  34. package/dist/api/emails/handlers/templates.handler.js +132 -0
  35. package/dist/api/emails/routes/admin.routes.d.ts +9 -0
  36. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
  37. package/dist/api/emails/routes/admin.routes.js +77 -0
  38. package/dist/api/emails/routes/index.d.ts +9 -0
  39. package/dist/api/emails/routes/index.d.ts.map +1 -0
  40. package/dist/api/emails/routes/index.js +14 -0
  41. package/dist/api/emails/routes/public.routes.d.ts +9 -0
  42. package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
  43. package/dist/api/emails/routes/public.routes.js +15 -0
  44. package/dist/api/newsletter/handlers/emails.handler.d.ts +13 -3
  45. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -1
  46. package/dist/api/newsletter/handlers/emails.handler.js +140 -12
  47. package/dist/api/newsletter/handlers/invoice.handler.d.ts +22 -0
  48. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +1 -0
  49. package/dist/api/newsletter/handlers/invoice.handler.js +455 -0
  50. package/dist/api/newsletter/handlers/public.handler.d.ts +4 -4
  51. package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -1
  52. package/dist/api/newsletter/handlers/public.handler.js +78 -20
  53. package/dist/api/newsletter/handlers/send.handler.d.ts +2 -2
  54. package/dist/api/newsletter/handlers/send.handler.js +3 -3
  55. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +4 -4
  56. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -1
  57. package/dist/api/newsletter/handlers/subscribers.handler.js +8 -4
  58. package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -1
  59. package/dist/api/newsletter/routes/admin.routes.js +8 -1
  60. package/dist/api/shop/handlers/assets.handler.d.ts +3 -0
  61. package/dist/api/shop/handlers/assets.handler.d.ts.map +1 -0
  62. package/dist/api/shop/handlers/assets.handler.js +62 -0
  63. package/dist/api/shop/handlers/checkout.handler.d.ts +10 -0
  64. package/dist/api/shop/handlers/checkout.handler.d.ts.map +1 -0
  65. package/dist/api/shop/handlers/checkout.handler.js +50 -0
  66. package/dist/api/shop/handlers/products.handler.d.ts +0 -7
  67. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  68. package/dist/api/shop/handlers/products.handler.js +0 -23
  69. package/dist/api/shop/handlers/public.handler.d.ts +17 -0
  70. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -0
  71. package/dist/api/shop/handlers/public.handler.js +108 -0
  72. package/dist/api/shop/handlers/webhook.handler.d.ts +10 -0
  73. package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -0
  74. package/dist/api/shop/handlers/webhook.handler.js +233 -0
  75. package/dist/api/shop/routes.d.ts.map +1 -1
  76. package/dist/api/shop/routes.js +9 -12
  77. package/dist/hintergrund-assets.d.ts +2 -2
  78. package/dist/hintergrund-assets.d.ts.map +1 -1
  79. package/dist/hintergrund-assets.js +2 -2
  80. package/dist/index.d.ts +9 -17
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +4 -7
  83. package/dist/lib/config.d.ts +13 -7
  84. package/dist/lib/config.d.ts.map +1 -1
  85. package/dist/lib/config.js +39 -44
  86. package/dist/lib/github.d.ts +124 -0
  87. package/dist/lib/github.d.ts.map +1 -0
  88. package/dist/lib/github.js +286 -0
  89. package/dist/lib/plunk.d.ts +207 -0
  90. package/dist/lib/plunk.d.ts.map +1 -0
  91. package/dist/lib/plunk.js +262 -0
  92. package/dist/middleware/auth.d.ts.map +1 -1
  93. package/dist/middleware/auth.js +2 -5
  94. package/package.json +32 -31
package/dist/index.d.ts CHANGED
@@ -3,28 +3,20 @@ export type Bindings = {
3
3
  HG_CONFIG?: string;
4
4
  HG_SECRET?: string;
5
5
  HG_PASSWORD?: string;
6
- HG_CMS_GIT_TOKEN?: string;
7
- HG_CMS_GIT_OWNER?: string;
8
- HG_CMS_GIT_REPO?: string;
9
- HG_CMS_GIT_BRANCH?: string;
10
- HG_CMS_CONTENT_DIR?: string;
11
- HG_CMS_ASSET_DIR?: string;
12
- HG_NEWSLETTER_EMAIL_PROVIDER?: string;
13
- HG_NEWSLETTER_EMAIL_API_KEY?: string;
14
- HG_NEWSLETTER_FROM_EMAIL?: string;
15
- HG_NEWSLETTER_FROM_NAME?: string;
16
- HG_NEWSLETTER_REPLY_TO?: string;
17
- HG_NEWSLETTER_CONFIRMATION_URL?: string;
6
+ HG_GIT_TOKEN?: string;
7
+ HG_GIT_OWNER?: string;
8
+ HG_GIT_REPO?: string;
9
+ HG_GIT_BRANCH?: string;
10
+ HG_EMAILS_PLUNK_SECRET_KEY?: string;
11
+ HG_EMAILS_PLUNK_PUBLIC_KEY?: string;
12
+ HG_EMAILS_FROM_EMAIL?: string;
13
+ HG_EMAILS_FROM_NAME?: string;
14
+ HG_EMAILS_REPLY_TO?: string;
18
15
  HG_SHOP_STRIPE_SECRET_KEY?: string;
19
16
  HG_SHOP_STRIPE_WEBHOOK_SECRET?: string;
20
17
  HG_SHOP_STRIPE_PUBLISHABLE_KEY?: string;
21
- HG_BUILDER_GEMINI_API_KEY?: string;
22
- HG_BUILDER_GIT_TOKEN?: string;
23
- HG_BUILDER_TEMPLATE_REPO?: string;
24
- HG_BUILDER_GIT_BRANCH?: string;
25
18
  UI_BASE_URL: string;
26
19
  ASSETS: Fetcher;
27
- DB: D1Database;
28
20
  };
29
21
  export declare function createApp(): Hono<{
30
22
  Bindings: Bindings;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAS5B,MAAM,MAAM,QAAQ,GAAG;IAEtB,SAAS,CAAC,EAAE,MAAM,CAAC;I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AAS,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,wBAAgB,SAAS;cACS,QAAQ;0CA6DzC;AAGD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { Hono } from 'hono';
2
2
  import { cors } from 'hono/cors';
3
3
  import cmsRoutes from './api/cms/routes';
4
- import newsletterRoutes from './api/newsletter/routes';
4
+ import emailRoutes from './api/emails/routes';
5
5
  import shopRoutes from './api/shop/routes';
6
- // import builderRoutes from './api/builder/routes';
7
6
  import { authMiddleware } from './middleware/auth';
8
7
  import { getTemplate } from './lib/template';
9
8
  export function createApp() {
@@ -14,12 +13,10 @@ export function createApp() {
14
13
  app.get('/login', (c) => c.html(getTemplate('login', c.env.UI_BASE_URL)));
15
14
  // Mount CMS routes under /api/admin
16
15
  app.route('/api/admin', cmsRoutes);
17
- // Mount newsletter routes under /api/newsletter
18
- app.route('/api/newsletter', newsletterRoutes);
16
+ // Mount email routes under /api/email
17
+ app.route('/api/email', emailRoutes);
19
18
  // Mount shop routes under /api/shop
20
19
  app.route('/api/shop', shopRoutes);
21
- // Mount builder routes under /api/builder
22
- // app.route('/api/builder', builderRoutes);
23
20
  // Admin main page (protected)
24
21
  app.get('/admin', async (c) => {
25
22
  // Check authentication
@@ -40,7 +37,7 @@ export function createApp() {
40
37
  }
41
38
  catch (error) {
42
39
  // Fallback to default config if parsing fails
43
- const configParams = 'config=\'{"cms":true,"newsletter":false,"shop":false}\'';
40
+ const configParams = 'config=\'{"cms":true,"emails":false,"shop":false}\'';
44
41
  return c.html(getTemplate('admin', c.env.UI_BASE_URL, configParams));
45
42
  }
46
43
  });
@@ -1,4 +1,4 @@
1
- import type { AppConfig, AdminConfig, CmsModuleConfig, NewsletterModuleConfig, ShopModuleConfig, BuilderModuleConfig } from '@hintergrund/shared';
1
+ import type { AppConfig, AdminConfig, CmsModuleConfig, EmailsModuleConfig, ShopModuleConfig } from '@hintergrund/shared';
2
2
  /**
3
3
  * Load application configuration from environment variables
4
4
  * Supports both new modular env vars and legacy HG_CONFIG format
@@ -14,18 +14,24 @@ export declare function getAdminConfig(appConfig: AppConfig): AdminConfig;
14
14
  */
15
15
  export declare function getCmsConfig(env: Record<string, string | undefined> | any): CmsModuleConfig;
16
16
  /**
17
- * Get Newsletter module configuration
18
- * @throws Error if Newsletter module is not enabled
17
+ * Get Emails module configuration
18
+ * @throws Error if Emails module is not enabled
19
19
  */
20
- export declare function getNewsletterConfig(env: Record<string, string | undefined> | any): NewsletterModuleConfig;
20
+ export declare function getEmailsConfig(env: Record<string, string | undefined> | any): EmailsModuleConfig;
21
21
  /**
22
22
  * Get Shop module configuration
23
23
  * @throws Error if Shop module is not enabled
24
24
  */
25
25
  export declare function getShopConfig(env: Record<string, string | undefined> | any): ShopModuleConfig;
26
26
  /**
27
- * Get Builder module configuration
28
- * @throws Error if Builder module is not enabled
27
+ * Get GitHub configuration from environment variables
28
+ * Used by CMS, emails and other modules for GitHub storage
29
+ * @throws Error if GitHub is not configured (required variables missing)
29
30
  */
30
- export declare function getBuilderConfig(env: Record<string, string | undefined> | any): BuilderModuleConfig;
31
+ export declare function getGitHubConfig(env: Record<string, string | undefined> | any): {
32
+ gitToken: string;
33
+ gitOwner: string;
34
+ gitRepo: string;
35
+ gitBranch: string;
36
+ };
31
37
  //# 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,sBAAsB,EAAE,gBAAgB,EAAE,mBAAmB,EAAsC,MAAM,qBAAqB,CAAC;AAEtL;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,SAAS,CAOnF;AA0HD;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW,CAShE;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,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,sBAAsB,CAQzG;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,gBAAgB,CAQ7F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,GAAG,GAAG,mBAAmB,CAQnG"}
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;AA+GD;;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"}
@@ -22,10 +22,10 @@ function hasAnyVar(env, vars) {
22
22
  return vars.some(varName => !!env[varName]);
23
23
  }
24
24
  // Module required variables definitions
25
- const CMS_REQUIRED_VARS = ['HG_CMS_GIT_TOKEN', 'HG_CMS_GIT_OWNER', 'HG_CMS_GIT_REPO'];
26
- const NEWSLETTER_REQUIRED_VARS = ['HG_NEWSLETTER_EMAIL_API_KEY', 'HG_NEWSLETTER_FROM_EMAIL'];
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'];
27
28
  const SHOP_REQUIRED_VARS = ['HG_SHOP_STRIPE_SECRET_KEY'];
28
- const BUILDER_REQUIRED_VARS = ['HG_BUILDER_GEMINI_API_KEY', 'HG_BUILDER_GIT_TOKEN'];
29
29
  /**
30
30
  * Parse user groups from environment variable
31
31
  * Format: JSON array of UserGroup objects
@@ -71,24 +71,25 @@ function loadFromEnvVars(env) {
71
71
  if (cmsMissing.length === 0) {
72
72
  config.cms = {
73
73
  enabled: true,
74
- gitToken: env.HG_CMS_GIT_TOKEN || '',
75
- gitOwner: env.HG_CMS_GIT_OWNER || '',
76
- gitRepo: env.HG_CMS_GIT_REPO || '',
77
- gitBranch: env.HG_CMS_GIT_BRANCH || 'main',
78
- contentDir: env.HG_CMS_CONTENT_DIR || 'content',
79
- assetDir: env.HG_CMS_ASSET_DIR || 'assets',
74
+ gitToken: env.HG_GIT_TOKEN || '',
75
+ gitOwner: env.HG_GIT_OWNER || '',
76
+ gitRepo: env.HG_GIT_REPO || '',
77
+ gitBranch: env.HG_GIT_BRANCH || 'main',
78
+ contentDir: 'frontend/src/lib/content',
79
+ assetDir: 'frontend/static',
80
80
  };
81
81
  }
82
- // Load Newsletter module config (auto-detect based on required vars)
83
- const newsletterMissing = getMissingVars(env, NEWSLETTER_REQUIRED_VARS);
84
- if (newsletterMissing.length === 0) {
85
- config.newsletter = {
82
+ // Load Emails module config (auto-detect based on required vars)
83
+ const emailsMissing = getMissingVars(env, EMAILS_REQUIRED_VARS);
84
+ if (emailsMissing.length === 0) {
85
+ config.emails = {
86
86
  enabled: true,
87
- emailProvider: env.HG_NEWSLETTER_EMAIL_PROVIDER || 'resend',
88
- emailApiKey: env.HG_NEWSLETTER_EMAIL_API_KEY || '',
89
- fromEmail: env.HG_NEWSLETTER_FROM_EMAIL || '',
90
- fromName: env.HG_NEWSLETTER_FROM_NAME || '',
91
- replyTo: env.HG_NEWSLETTER_REPLY_TO,
87
+ plunkSecretKey: env.HG_EMAILS_PLUNK_SECRET_KEY || '',
88
+ plunkPublicKey: env.HG_EMAILS_PLUNK_PUBLIC_KEY,
89
+ plunkProjectName: env.HG_EMAILS_PLUNK_PROJECT,
90
+ fromEmail: env.HG_EMAILS_FROM_EMAIL || '',
91
+ fromName: env.HG_EMAILS_FROM_NAME || '',
92
+ replyTo: env.HG_EMAILS_REPLY_TO,
92
93
  };
93
94
  }
94
95
  // Load Shop module config (auto-detect based on required vars)
@@ -102,17 +103,6 @@ function loadFromEnvVars(env) {
102
103
  stripePublishableKey: env.HG_SHOP_STRIPE_PUBLISHABLE_KEY,
103
104
  };
104
105
  }
105
- // Load Builder module config (auto-detect based on required vars)
106
- /* const builderMissing = getMissingVars(env, BUILDER_REQUIRED_VARS);
107
- if (builderMissing.length === 0) {
108
- config.builder = {
109
- enabled: true,
110
- geminiApiKey: env.HG_BUILDER_GEMINI_API_KEY || '',
111
- gitToken: env.HG_BUILDER_GIT_TOKEN || '',
112
- templateRepo: env.HG_BUILDER_TEMPLATE_REPO || 'hintergrund-cloud/demo-shop',
113
- gitBranch: env.HG_BUILDER_GIT_BRANCH || 'main',
114
- };
115
- } */
116
106
  return config;
117
107
  }
118
108
  /**
@@ -121,9 +111,8 @@ function loadFromEnvVars(env) {
121
111
  export function getAdminConfig(appConfig) {
122
112
  return {
123
113
  cms: appConfig.cms?.enabled ?? false,
124
- newsletter: appConfig.newsletter?.enabled ?? false,
114
+ emails: appConfig.emails?.enabled ?? false,
125
115
  shop: appConfig.shop?.enabled ?? false,
126
- builder: false, // appConfig.builder?.enabled ?? false,
127
116
  loginMethod: appConfig.global.auth?.loginMethod ?? 'password',
128
117
  userGroups: appConfig.global.auth?.userGroups?.map(g => g.name),
129
118
  };
@@ -140,15 +129,15 @@ export function getCmsConfig(env) {
140
129
  return config.cms;
141
130
  }
142
131
  /**
143
- * Get Newsletter module configuration
144
- * @throws Error if Newsletter module is not enabled
132
+ * Get Emails module configuration
133
+ * @throws Error if Emails module is not enabled
145
134
  */
146
- export function getNewsletterConfig(env) {
135
+ export function getEmailsConfig(env) {
147
136
  const config = loadConfig(env);
148
- if (!config.newsletter) {
149
- throw new Error('Newsletter module is not enabled');
137
+ if (!config.emails) {
138
+ throw new Error('Emails module is not enabled');
150
139
  }
151
- return config.newsletter;
140
+ return config.emails;
152
141
  }
153
142
  /**
154
143
  * Get Shop module configuration
@@ -162,13 +151,19 @@ export function getShopConfig(env) {
162
151
  return config.shop;
163
152
  }
164
153
  /**
165
- * Get Builder module configuration
166
- * @throws Error if Builder module is not enabled
154
+ * Get GitHub configuration from environment variables
155
+ * Used by CMS, emails and other modules for GitHub storage
156
+ * @throws Error if GitHub is not configured (required variables missing)
167
157
  */
168
- export function getBuilderConfig(env) {
169
- const config = loadConfig(env);
170
- if (!config.builder) {
171
- throw new Error('Builder module is not enabled');
158
+ export function getGitHubConfig(env) {
159
+ const missing = getMissingVars(env, GIT_REQUIRED_VARS);
160
+ if (missing.length > 0) {
161
+ throw new Error(`GitHub not configured. Missing: ${missing.join(', ')}`);
172
162
  }
173
- return config.builder;
163
+ return {
164
+ gitToken: env.HG_GIT_TOKEN,
165
+ gitOwner: env.HG_GIT_OWNER,
166
+ gitRepo: env.HG_GIT_REPO,
167
+ gitBranch: env.HG_GIT_BRANCH || 'main',
168
+ };
174
169
  }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Shared GitHub Utilities
3
+ *
4
+ * Provides common GitHub operations for both CMS and Emails modules.
5
+ * Uses Octokit for GitHub API interactions with proper UTF-8 handling.
6
+ */
7
+ import { Octokit } from '@octokit/rest';
8
+ /**
9
+ * GitHub configuration for a module
10
+ */
11
+ export interface GitHubConfig {
12
+ gitToken: string;
13
+ gitOwner: string;
14
+ gitRepo: string;
15
+ gitBranch: string;
16
+ }
17
+ /**
18
+ * File entry for tree operations
19
+ */
20
+ export interface FileEntry {
21
+ path: string;
22
+ content: string;
23
+ }
24
+ /**
25
+ * File read result
26
+ */
27
+ export interface FileReadResult {
28
+ content: string;
29
+ sha: string;
30
+ }
31
+ /**
32
+ * Decode base64 content to UTF-8 string.
33
+ * atob() decodes to Latin-1, which corrupts multi-byte UTF-8 characters.
34
+ */
35
+ export declare function decodeBase64UTF8(base64: string): string;
36
+ /**
37
+ * Encode UTF-8 string to base64.
38
+ * btoa() only works with Latin-1, which corrupts multi-byte UTF-8 characters like ß.
39
+ */
40
+ export declare function encodeUTF8Base64(str: string): string;
41
+ /**
42
+ * GitHub client wrapper for common operations
43
+ */
44
+ export declare class GitHubClient {
45
+ private octokit;
46
+ private owner;
47
+ private repo;
48
+ private branch;
49
+ constructor(config: GitHubConfig);
50
+ /**
51
+ * Get the current commit SHA of the branch
52
+ */
53
+ getCommitSha(): Promise<string>;
54
+ /**
55
+ * Read a single file from the repository
56
+ * Returns null if file doesn't exist
57
+ */
58
+ readFile(path: string): Promise<FileReadResult | null>;
59
+ /**
60
+ * Read a binary file from the repository (returns raw base64 without UTF-8 decoding)
61
+ * Use this for images, videos, and other binary files
62
+ * Returns null if file doesn't exist
63
+ */
64
+ readFileBinary(path: string): Promise<{
65
+ content: string;
66
+ sha: string;
67
+ } | null>;
68
+ /**
69
+ * Read a JSON file from the repository
70
+ * Returns null if file doesn't exist
71
+ */
72
+ readJsonFile<T>(path: string): Promise<{
73
+ data: T;
74
+ sha: string;
75
+ } | null>;
76
+ /**
77
+ * Read multiple files in parallel
78
+ */
79
+ readFiles(paths: string[]): Promise<Map<string, FileReadResult | null>>;
80
+ /**
81
+ * Write a single file to the repository
82
+ * Creates the file if it doesn't exist, updates if it does
83
+ */
84
+ writeFile(path: string, content: string, message: string): Promise<string>;
85
+ /**
86
+ * Write a JSON file to the repository
87
+ */
88
+ writeJsonFile<T>(path: string, data: T, message: string): Promise<string>;
89
+ /**
90
+ * Write multiple files atomically in a single commit
91
+ * This uses the Git Data API (blob → tree → commit → update ref)
92
+ */
93
+ writeFilesAtomic(files: FileEntry[], message: string, baseCommitSha?: string): Promise<string>;
94
+ /**
95
+ * Delete a file from the repository
96
+ */
97
+ deleteFile(path: string, message: string): Promise<void>;
98
+ /**
99
+ * List files in a directory
100
+ */
101
+ listDirectory(path: string): Promise<string[]>;
102
+ /**
103
+ * Check if commit SHA matches current branch HEAD
104
+ * Returns true if they match (no conflict), false if there's a conflict
105
+ */
106
+ checkNoConflict(expectedSha: string): Promise<boolean>;
107
+ /**
108
+ * Get raw Octokit instance for advanced operations
109
+ */
110
+ getOctokit(): Octokit;
111
+ /**
112
+ * Get repository info
113
+ */
114
+ getRepoInfo(): {
115
+ owner: string;
116
+ repo: string;
117
+ branch: string;
118
+ };
119
+ }
120
+ /**
121
+ * Create a GitHub client from CMS module config
122
+ */
123
+ export declare function createGitHubClient(config: GitHubConfig): GitHubClient;
124
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/lib/github.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,C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,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0DpG;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB9D;;OAEG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAyBpD;;;OAGG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK5D;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,WAAW;;;;;CAOX;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAErE"}
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Shared GitHub Utilities
3
+ *
4
+ * Provides common GitHub operations for both CMS and Emails modules.
5
+ * Uses Octokit for GitHub API interactions with proper UTF-8 handling.
6
+ */
7
+ import { Octokit } from '@octokit/rest';
8
+ /**
9
+ * Decode base64 content to UTF-8 string.
10
+ * atob() decodes to Latin-1, which corrupts multi-byte UTF-8 characters.
11
+ */
12
+ export function decodeBase64UTF8(base64) {
13
+ const binaryString = atob(base64);
14
+ const bytes = new Uint8Array(binaryString.length);
15
+ for (let i = 0; i < binaryString.length; i++) {
16
+ bytes[i] = binaryString.charCodeAt(i);
17
+ }
18
+ return new TextDecoder('utf-8').decode(bytes);
19
+ }
20
+ /**
21
+ * Encode UTF-8 string to base64.
22
+ * btoa() only works with Latin-1, which corrupts multi-byte UTF-8 characters like ß.
23
+ */
24
+ export function encodeUTF8Base64(str) {
25
+ const bytes = new TextEncoder().encode(str);
26
+ let binaryString = '';
27
+ for (let i = 0; i < bytes.length; i++) {
28
+ binaryString += String.fromCharCode(bytes[i]);
29
+ }
30
+ return btoa(binaryString);
31
+ }
32
+ /**
33
+ * GitHub client wrapper for common operations
34
+ */
35
+ export class GitHubClient {
36
+ constructor(config) {
37
+ this.octokit = new Octokit({ auth: config.gitToken });
38
+ this.owner = config.gitOwner;
39
+ this.repo = config.gitRepo;
40
+ this.branch = config.gitBranch;
41
+ }
42
+ /**
43
+ * Get the current commit SHA of the branch
44
+ */
45
+ async getCommitSha() {
46
+ const ref = await this.octokit.rest.git.getRef({
47
+ owner: this.owner,
48
+ repo: this.repo,
49
+ ref: `heads/${this.branch}`
50
+ });
51
+ return ref.data.object.sha;
52
+ }
53
+ /**
54
+ * Read a single file from the repository
55
+ * Returns null if file doesn't exist
56
+ */
57
+ async readFile(path) {
58
+ try {
59
+ const response = await this.octokit.rest.repos.getContent({
60
+ owner: this.owner,
61
+ repo: this.repo,
62
+ path,
63
+ ref: this.branch
64
+ });
65
+ if (Array.isArray(response.data) || !('content' in response.data)) {
66
+ return null;
67
+ }
68
+ return {
69
+ content: decodeBase64UTF8(response.data.content || ''),
70
+ sha: response.data.sha
71
+ };
72
+ }
73
+ catch (error) {
74
+ if (error.status === 404) {
75
+ console.warn(`[GitHub] File not found: ${path}`);
76
+ return null;
77
+ }
78
+ throw error;
79
+ }
80
+ }
81
+ /**
82
+ * Read a binary file from the repository (returns raw base64 without UTF-8 decoding)
83
+ * Use this for images, videos, and other binary files
84
+ * Returns null if file doesn't exist
85
+ */
86
+ async readFileBinary(path) {
87
+ try {
88
+ const response = await this.octokit.rest.repos.getContent({
89
+ owner: this.owner,
90
+ repo: this.repo,
91
+ path,
92
+ ref: this.branch
93
+ });
94
+ if (Array.isArray(response.data) || !('content' in response.data)) {
95
+ return null;
96
+ }
97
+ // Return raw base64 content without decoding (for binary files)
98
+ // GitHub returns base64 with newlines, so we need to clean it
99
+ const rawContent = (response.data.content || '').replace(/\n/g, '');
100
+ return {
101
+ content: rawContent,
102
+ sha: response.data.sha
103
+ };
104
+ }
105
+ catch (error) {
106
+ if (error.status === 404) {
107
+ console.warn(`[GitHub] File not found: ${path}`);
108
+ return null;
109
+ }
110
+ throw error;
111
+ }
112
+ }
113
+ /**
114
+ * Read a JSON file from the repository
115
+ * Returns null if file doesn't exist
116
+ */
117
+ async readJsonFile(path) {
118
+ const result = await this.readFile(path);
119
+ if (!result)
120
+ return null;
121
+ return {
122
+ data: JSON.parse(result.content),
123
+ sha: result.sha
124
+ };
125
+ }
126
+ /**
127
+ * Read multiple files in parallel
128
+ */
129
+ async readFiles(paths) {
130
+ const results = await Promise.all(paths.map(async (path) => {
131
+ const result = await this.readFile(path);
132
+ return [path, result];
133
+ }));
134
+ return new Map(results);
135
+ }
136
+ /**
137
+ * Write a single file to the repository
138
+ * Creates the file if it doesn't exist, updates if it does
139
+ */
140
+ async writeFile(path, content, message) {
141
+ // Get existing file SHA if it exists
142
+ const existing = await this.readFile(path);
143
+ const response = await this.octokit.rest.repos.createOrUpdateFileContents({
144
+ owner: this.owner,
145
+ repo: this.repo,
146
+ path,
147
+ message,
148
+ content: encodeUTF8Base64(content),
149
+ branch: this.branch,
150
+ sha: existing?.sha
151
+ });
152
+ return response.data.commit.sha || '';
153
+ }
154
+ /**
155
+ * Write a JSON file to the repository
156
+ */
157
+ async writeJsonFile(path, data, message) {
158
+ const content = JSON.stringify(data, null, 2);
159
+ return this.writeFile(path, content, message);
160
+ }
161
+ /**
162
+ * Write multiple files atomically in a single commit
163
+ * This uses the Git Data API (blob → tree → commit → update ref)
164
+ */
165
+ async writeFilesAtomic(files, message, baseCommitSha) {
166
+ // Get base commit SHA if not provided
167
+ const commitSha = baseCommitSha || await this.getCommitSha();
168
+ // Get the commit to find tree SHA
169
+ const commit = await this.octokit.rest.git.getCommit({
170
+ owner: this.owner,
171
+ repo: this.repo,
172
+ commit_sha: commitSha
173
+ });
174
+ // Create blobs for all files
175
+ const blobs = await Promise.all(files.map(async (file) => {
176
+ const blob = await this.octokit.rest.git.createBlob({
177
+ owner: this.owner,
178
+ repo: this.repo,
179
+ content: file.content,
180
+ encoding: 'utf-8'
181
+ });
182
+ return {
183
+ path: file.path,
184
+ mode: '100644',
185
+ type: 'blob',
186
+ sha: blob.data.sha
187
+ };
188
+ }));
189
+ // Create new tree
190
+ const newTree = await this.octokit.rest.git.createTree({
191
+ owner: this.owner,
192
+ repo: this.repo,
193
+ tree: blobs,
194
+ base_tree: commit.data.tree.sha
195
+ });
196
+ // Create new commit
197
+ const newCommit = await this.octokit.rest.git.createCommit({
198
+ owner: this.owner,
199
+ repo: this.repo,
200
+ message,
201
+ tree: newTree.data.sha,
202
+ parents: [commit.data.sha]
203
+ });
204
+ // Update reference
205
+ await this.octokit.rest.git.updateRef({
206
+ owner: this.owner,
207
+ repo: this.repo,
208
+ ref: `heads/${this.branch}`,
209
+ sha: newCommit.data.sha
210
+ });
211
+ return newCommit.data.sha;
212
+ }
213
+ /**
214
+ * Delete a file from the repository
215
+ */
216
+ async deleteFile(path, message) {
217
+ const existing = await this.readFile(path);
218
+ if (!existing) {
219
+ return; // File doesn't exist, nothing to delete
220
+ }
221
+ await this.octokit.rest.repos.deleteFile({
222
+ owner: this.owner,
223
+ repo: this.repo,
224
+ path,
225
+ message,
226
+ sha: existing.sha,
227
+ branch: this.branch
228
+ });
229
+ }
230
+ /**
231
+ * List files in a directory
232
+ */
233
+ async listDirectory(path) {
234
+ try {
235
+ const response = await this.octokit.rest.repos.getContent({
236
+ owner: this.owner,
237
+ repo: this.repo,
238
+ path,
239
+ ref: this.branch
240
+ });
241
+ if (!Array.isArray(response.data)) {
242
+ return [];
243
+ }
244
+ return response.data
245
+ .filter((item) => item.type === 'file')
246
+ .map((item) => item.path);
247
+ }
248
+ catch (error) {
249
+ if (error.status === 404) {
250
+ console.warn(`[GitHub] Directory not found: ${path}`);
251
+ return [];
252
+ }
253
+ throw error;
254
+ }
255
+ }
256
+ /**
257
+ * Check if commit SHA matches current branch HEAD
258
+ * Returns true if they match (no conflict), false if there's a conflict
259
+ */
260
+ async checkNoConflict(expectedSha) {
261
+ const currentSha = await this.getCommitSha();
262
+ return expectedSha === currentSha;
263
+ }
264
+ /**
265
+ * Get raw Octokit instance for advanced operations
266
+ */
267
+ getOctokit() {
268
+ return this.octokit;
269
+ }
270
+ /**
271
+ * Get repository info
272
+ */
273
+ getRepoInfo() {
274
+ return {
275
+ owner: this.owner,
276
+ repo: this.repo,
277
+ branch: this.branch
278
+ };
279
+ }
280
+ }
281
+ /**
282
+ * Create a GitHub client from CMS module config
283
+ */
284
+ export function createGitHubClient(config) {
285
+ return new GitHubClient(config);
286
+ }