@hintergrund/worker 0.1.14 → 0.2.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 (57) hide show
  1. package/dist/api/cms/handlers/admin-users.handler.d.ts +0 -1
  2. package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -1
  3. package/dist/api/cms/handlers/admin-users.handler.js +7 -27
  4. package/dist/api/cms/handlers/agent-conversations.handler.d.ts +0 -1
  5. package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -1
  6. package/dist/api/cms/handlers/agent-conversations.handler.js +0 -7
  7. package/dist/api/cms/handlers/agent-provider.handler.d.ts +12 -0
  8. package/dist/api/cms/handlers/agent-provider.handler.d.ts.map +1 -0
  9. package/dist/api/cms/handlers/agent-provider.handler.js +64 -0
  10. package/dist/api/cms/handlers/auth.handler.d.ts +0 -4
  11. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  12. package/dist/api/cms/handlers/auth.handler.js +88 -106
  13. package/dist/api/cms/handlers/dashboard.handler.d.ts.map +1 -1
  14. package/dist/api/cms/handlers/dashboard.handler.js +2 -3
  15. package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
  16. package/dist/api/cms/handlers/github-secrets.handler.js +37 -7
  17. package/dist/api/cms/handlers/setup.handler.d.ts +2 -0
  18. package/dist/api/cms/handlers/setup.handler.d.ts.map +1 -1
  19. package/dist/api/cms/handlers/setup.handler.js +111 -30
  20. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
  21. package/dist/api/cms/handlers/website-repo.handler.js +11 -4
  22. package/dist/api/cms/handlers/website-templates.handler.d.ts +6 -0
  23. package/dist/api/cms/handlers/website-templates.handler.d.ts.map +1 -0
  24. package/dist/api/cms/handlers/website-templates.handler.js +53 -0
  25. package/dist/api/cms/routes/auth.routes.d.ts.map +1 -1
  26. package/dist/api/cms/routes/auth.routes.js +1 -2
  27. package/dist/api/cms/routes/index.d.ts.map +1 -1
  28. package/dist/api/cms/routes/index.js +11 -5
  29. package/dist/hintergrund-assets.d.ts +4 -4
  30. package/dist/hintergrund-assets.d.ts.map +1 -1
  31. package/dist/hintergrund-assets.js +4 -4
  32. package/dist/index.d.ts +7 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +8 -6
  35. package/dist/lib/config.d.ts +5 -11
  36. package/dist/lib/config.d.ts.map +1 -1
  37. package/dist/lib/config.js +21 -36
  38. package/dist/lib/email.d.ts +3 -5
  39. package/dist/lib/email.d.ts.map +1 -1
  40. package/dist/lib/email.js +8 -25
  41. package/dist/lib/github-app.d.ts.map +1 -1
  42. package/dist/lib/github-app.js +4 -1
  43. package/dist/lib/github.d.ts +1 -1
  44. package/dist/lib/github.d.ts.map +1 -1
  45. package/dist/lib/github.js +30 -9
  46. package/dist/lib/jsonc.d.ts +3 -0
  47. package/dist/lib/jsonc.d.ts.map +1 -0
  48. package/dist/lib/jsonc.js +76 -0
  49. package/dist/lib/project-db.d.ts +4 -2
  50. package/dist/lib/project-db.d.ts.map +1 -1
  51. package/dist/lib/project-db.js +12 -11
  52. package/dist/middleware/auth.d.ts.map +1 -1
  53. package/dist/middleware/auth.js +0 -1
  54. package/package.json +35 -35
  55. package/dist/api/emails/handlers/webhook.handler.d.ts +0 -9
  56. package/dist/api/emails/handlers/webhook.handler.d.ts.map +0 -1
  57. package/dist/api/emails/handlers/webhook.handler.js +0 -161
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "@hintergrund/worker",
3
- "version": "0.1.14",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js"
11
- }
12
- },
13
- "files": [
14
- "dist"
15
- ],
16
- "devDependencies": {
17
- "@cloudflare/workers-types": "^4.20250111.0",
18
- "concurrently": "^9.2.1",
19
- "typescript": "^5.5.2",
20
- "@hintergrund/runtime-contracts": "^0.1.9"
21
- },
22
- "dependencies": {
23
- "@hintergrund/auth": "^0.1.2",
24
- "@octokit/rest": "^22.0.0",
25
- "blakejs": "^1.2.1",
26
- "cookie": "^1.0.2",
27
- "hono": "^4.10.2",
28
- "pdf-lib": "^1.17.1",
29
- "stripe": "^17.5.0",
30
- "tweetnacl": "^1.0.3"
31
- },
32
- "scripts": {
33
- "build": "tsc",
34
- "dev": "tsc --watch"
35
- }
36
- }
2
+ "name": "@hintergrund/worker",
3
+ "version": "0.2.3",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "dev": "tsc --watch"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "devDependencies": {
21
+ "@cloudflare/workers-types": "^4.20250111.0",
22
+ "concurrently": "^9.2.1",
23
+ "typescript": "^5.5.2"
24
+ },
25
+ "dependencies": {
26
+ "@hintergrund/auth": "^0.1.2",
27
+ "@hintergrund/runtime-contracts": "^0.2.3",
28
+ "@octokit/rest": "^22.0.0",
29
+ "blakejs": "^1.2.1",
30
+ "cookie": "^1.0.2",
31
+ "hono": "^4.10.2",
32
+ "pdf-lib": "^1.17.1",
33
+ "stripe": "^17.5.0",
34
+ "tweetnacl": "^1.0.3"
35
+ }
36
+ }
@@ -1,9 +0,0 @@
1
- import type { Context } from 'hono';
2
- import type { Bindings } from '../../../index';
3
- /**
4
- * Legacy Stripe webhook helper. The active route is /api/shop/webhook.
5
- */
6
- export declare function handleStripeWebhook(c: Context<{
7
- Bindings: Bindings;
8
- }>): Promise<Response>;
9
- //# sourceMappingURL=webhook.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/emails/handlers/webhook.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAyB/C;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiC/F"}
@@ -1,161 +0,0 @@
1
- import { getGitHubConfig, getShopConfig } from '../../../lib/config';
2
- import { createGitHubClient } from '../../../lib/github';
3
- import { sendEmail } from '../../../lib/email';
4
- import { renderEmailTemplate } from '../../../lib/email-template';
5
- import Stripe from 'stripe';
6
- import { generateInvoicePdf } from './invoice.handler';
7
- import { readEmailSettings, readEmailTemplateData } from './settings.handler';
8
- function guessLogoMime(path) {
9
- const ext = path.split('.').pop()?.toLowerCase();
10
- if (ext === 'png')
11
- return 'image/png';
12
- if (ext === 'jpg' || ext === 'jpeg')
13
- return 'image/jpeg';
14
- if (ext === 'gif')
15
- return 'image/gif';
16
- if (ext === 'svg')
17
- return 'image/svg+xml';
18
- return 'image/png';
19
- }
20
- function getStripe(env) {
21
- const config = getShopConfig(env);
22
- if (!config.stripeSecretKey)
23
- throw new Error('Stripe secret key is not configured');
24
- return new Stripe(config.stripeSecretKey, { apiVersion: '2025-02-24.acacia' });
25
- }
26
- /**
27
- * Legacy Stripe webhook helper. The active route is /api/shop/webhook.
28
- */
29
- export async function handleStripeWebhook(c) {
30
- const stripe = getStripe(c.env);
31
- const webhookSecret = c.env.STRIPE_WEBHOOK_SECRET;
32
- if (!webhookSecret) {
33
- console.error('Stripe webhook secret not configured');
34
- return c.json({ error: 'Webhook not configured' }, 500);
35
- }
36
- const signature = c.req.header('stripe-signature');
37
- if (!signature)
38
- return c.json({ error: 'Missing stripe-signature header' }, 400);
39
- const rawBody = await c.req.text();
40
- let event;
41
- try {
42
- event = await stripe.webhooks.constructEventAsync(rawBody, signature, webhookSecret);
43
- }
44
- catch (err) {
45
- console.error('Webhook signature verification failed:', err.message);
46
- return c.json({ error: 'Webhook signature verification failed' }, 400);
47
- }
48
- switch (event.type) {
49
- case 'checkout.session.completed': {
50
- const session = event.data.object;
51
- await handleCheckoutSessionCompleted(c, stripe, session);
52
- break;
53
- }
54
- default:
55
- console.log(`Unhandled event type: ${event.type}`);
56
- }
57
- return c.json({ received: true });
58
- }
59
- async function handleCheckoutSessionCompleted(c, stripe, session) {
60
- try {
61
- const customerEmail = session.customer_details?.email;
62
- if (!customerEmail) {
63
- console.error('No customer email in checkout session');
64
- return;
65
- }
66
- const lineItems = await stripe.checkout.sessions.listLineItems(session.id, {
67
- expand: ['data.price.product'],
68
- });
69
- // Load invoice config and generated email template settings.
70
- let invoiceConfig;
71
- let branding;
72
- try {
73
- const { settings } = await readEmailSettings(c.env);
74
- invoiceConfig = settings.invoice;
75
- let logoDataUrl;
76
- if (settings.logoPath) {
77
- try {
78
- const github = createGitHubClient(getGitHubConfig(c.env));
79
- const file = await github.readFileBinary(settings.logoPath);
80
- if (file)
81
- logoDataUrl = `data:${guessLogoMime(settings.logoPath)};base64,${file.content}`;
82
- }
83
- catch (error) {
84
- console.error('Failed to load logo from GitHub:', error);
85
- }
86
- }
87
- branding = {
88
- logo: logoDataUrl,
89
- companyName: settings.invoice.companyName,
90
- primaryColor: settings.invoice.primaryColor,
91
- };
92
- }
93
- catch (error) {
94
- console.error('Failed to fetch email settings from GitHub:', error);
95
- }
96
- const invoiceItems = lineItems.data.map((item) => {
97
- const product = item.price?.product;
98
- return {
99
- description: product?.name || item.description || 'Item',
100
- quantity: item.quantity || 1,
101
- unitPrice: (item.price?.unit_amount || 0) / 100,
102
- total: (item.amount_total || 0) / 100,
103
- };
104
- });
105
- const invoiceData = {
106
- invoiceNumber: `INV-${session.id.slice(-8).toUpperCase()}`,
107
- invoiceDate: new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }),
108
- customerName: session.customer_details?.name || 'Customer',
109
- customerEmail,
110
- customerAddress: session.customer_details?.address
111
- ? formatAddress(session.customer_details.address)
112
- : undefined,
113
- items: invoiceItems,
114
- subtotal: (session.amount_subtotal || 0) / 100,
115
- tax: session.total_details?.amount_tax ? session.total_details.amount_tax / 100 : undefined,
116
- total: (session.amount_total || 0) / 100,
117
- currency: session.currency?.toUpperCase() || 'EUR',
118
- paymentMethod: session.payment_method_types?.[0] || 'card',
119
- };
120
- const pdfBytes = await generateInvoicePdf((invoiceConfig ?? {}), invoiceData, branding);
121
- await sendInvoiceEmail(c.env, customerEmail, invoiceData, pdfBytes);
122
- console.log(`Invoice sent to ${customerEmail} for session ${session.id}`);
123
- }
124
- catch (error) {
125
- console.error('Failed to handle checkout session completed:', error);
126
- }
127
- }
128
- function formatAddress(address) {
129
- const parts = [];
130
- if (address.line1)
131
- parts.push(address.line1);
132
- if (address.line2)
133
- parts.push(address.line2);
134
- if (address.city)
135
- parts.push(address.city);
136
- if (address.postal_code)
137
- parts.push(address.postal_code);
138
- if (address.country)
139
- parts.push(address.country);
140
- return parts.join(', ');
141
- }
142
- async function sendInvoiceEmail(env, to, invoiceData, _pdfBytes) {
143
- const html = `
144
- <div style="font-family:sans-serif;max-width:600px;margin:0 auto;padding:20px;">
145
- <h1 style="color:#1f2937;">Thank you for your purchase!</h1>
146
- <p style="color:#4b5563;">Dear ${invoiceData.customerName},</p>
147
- <p style="color:#4b5563;">Thank you for your order.</p>
148
- <div style="background:#f3f4f6;padding:20px;border-radius:8px;margin:20px 0;">
149
- <p style="margin:0;color:#1f2937;"><strong>Invoice Number:</strong> ${invoiceData.invoiceNumber}</p>
150
- <p style="margin:8px 0;color:#1f2937;"><strong>Date:</strong> ${invoiceData.invoiceDate}</p>
151
- <p style="margin:8px 0;color:#1f2937;"><strong>Total:</strong> ${invoiceData.currency} ${invoiceData.total.toFixed(2)}</p>
152
- </div>
153
- <p style="color:#9ca3af;font-size:12px;margin-top:40px;">This is an automated email.</p>
154
- </div>`;
155
- const { settings, logoDataUrl } = await readEmailTemplateData(env);
156
- await sendEmail(env, {
157
- to,
158
- subject: `Your Invoice ${invoiceData.invoiceNumber}`,
159
- html: renderEmailTemplate({ bodyHtml: html, template: settings.emailTemplate, logoDataUrl }),
160
- });
161
- }