@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.
- package/dist/api/cms/handlers/assets.handler.d.ts +24 -1
- package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/assets.handler.js +111 -210
- package/dist/api/cms/handlers/config.handler.d.ts +4 -0
- package/dist/api/cms/handlers/config.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/config.handler.js +20 -71
- package/dist/api/cms/handlers/content.handler.d.ts +12 -1
- package/dist/api/cms/handlers/content.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/content.handler.js +57 -233
- package/dist/api/cms/handlers/dashboard.handler.js +1 -1
- package/dist/api/emails/handlers/branding.handler.d.ts +17 -0
- package/dist/api/emails/handlers/branding.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/branding.handler.js +120 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts +32 -0
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/campaigns.handler.js +139 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts +37 -0
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/contacts.handler.js +161 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts +30 -0
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/invoice.handler.js +463 -0
- package/dist/api/emails/handlers/public.handler.d.ts +36 -0
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/public.handler.js +350 -0
- package/dist/api/emails/handlers/send.handler.d.ts +23 -0
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/send.handler.js +117 -0
- package/dist/api/emails/handlers/settings.handler.d.ts +36 -0
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/settings.handler.js +312 -0
- package/dist/api/emails/handlers/templates.handler.d.ts +32 -0
- package/dist/api/emails/handlers/templates.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/templates.handler.js +132 -0
- package/dist/api/emails/routes/admin.routes.d.ts +9 -0
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/admin.routes.js +77 -0
- package/dist/api/emails/routes/index.d.ts +9 -0
- package/dist/api/emails/routes/index.d.ts.map +1 -0
- package/dist/api/emails/routes/index.js +14 -0
- package/dist/api/emails/routes/public.routes.d.ts +9 -0
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -0
- package/dist/api/emails/routes/public.routes.js +15 -0
- package/dist/api/newsletter/handlers/emails.handler.d.ts +13 -3
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/emails.handler.js +140 -12
- package/dist/api/newsletter/handlers/invoice.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/invoice.handler.js +455 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts +4 -4
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/public.handler.js +78 -20
- package/dist/api/newsletter/handlers/send.handler.d.ts +2 -2
- package/dist/api/newsletter/handlers/send.handler.js +3 -3
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +4 -4
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -1
- package/dist/api/newsletter/handlers/subscribers.handler.js +8 -4
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/newsletter/routes/admin.routes.js +8 -1
- package/dist/api/shop/handlers/assets.handler.d.ts +3 -0
- package/dist/api/shop/handlers/assets.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/assets.handler.js +62 -0
- package/dist/api/shop/handlers/checkout.handler.d.ts +10 -0
- package/dist/api/shop/handlers/checkout.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/checkout.handler.js +50 -0
- package/dist/api/shop/handlers/products.handler.d.ts +0 -7
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +0 -23
- package/dist/api/shop/handlers/public.handler.d.ts +17 -0
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/public.handler.js +108 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts +10 -0
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/webhook.handler.js +233 -0
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +9 -12
- package/dist/hintergrund-assets.d.ts +2 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +2 -2
- package/dist/index.d.ts +9 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/lib/config.d.ts +13 -7
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +39 -44
- package/dist/lib/github.d.ts +124 -0
- package/dist/lib/github.d.ts.map +1 -0
- package/dist/lib/github.js +286 -0
- package/dist/lib/plunk.d.ts +207 -0
- package/dist/lib/plunk.d.ts.map +1 -0
- package/dist/lib/plunk.js +262 -0
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +2 -5
- package/package.json +32 -31
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { getShopConfig } from '../../../lib/config';
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
function getStripe(env) {
|
|
4
|
+
const config = getShopConfig(env);
|
|
5
|
+
return new Stripe(config.stripeSecretKey, {
|
|
6
|
+
apiVersion: '2025-02-24.acacia'
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function mapStripePrice(price) {
|
|
10
|
+
return {
|
|
11
|
+
id: price.id,
|
|
12
|
+
productId: typeof price.product === 'string' ? price.product : price.product?.id || '',
|
|
13
|
+
active: price.active,
|
|
14
|
+
currency: price.currency,
|
|
15
|
+
unitAmount: price.unit_amount,
|
|
16
|
+
unitAmountDecimal: price.unit_amount_decimal,
|
|
17
|
+
billingScheme: price.billing_scheme,
|
|
18
|
+
type: price.type,
|
|
19
|
+
recurring: price.recurring
|
|
20
|
+
? {
|
|
21
|
+
interval: price.recurring.interval,
|
|
22
|
+
intervalCount: price.recurring.interval_count
|
|
23
|
+
}
|
|
24
|
+
: undefined,
|
|
25
|
+
metadata: price.metadata || {},
|
|
26
|
+
createdAt: price.created
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mapStripeProduct(product, defaultPrice) {
|
|
30
|
+
return {
|
|
31
|
+
id: product.id,
|
|
32
|
+
name: product.name,
|
|
33
|
+
description: product.description,
|
|
34
|
+
active: product.active,
|
|
35
|
+
defaultPriceId: typeof product.default_price === 'string' ? product.default_price : product.default_price?.id || null,
|
|
36
|
+
images: product.images,
|
|
37
|
+
metadata: product.metadata || {},
|
|
38
|
+
statementDescriptor: product.statement_descriptor || null,
|
|
39
|
+
unitLabel: product.unit_label || null,
|
|
40
|
+
url: product.url,
|
|
41
|
+
createdAt: product.created,
|
|
42
|
+
updatedAt: product.updated,
|
|
43
|
+
defaultPrice: defaultPrice ? mapStripePrice(defaultPrice) : undefined
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* GET /api/shop/products
|
|
48
|
+
* List all active products (public endpoint)
|
|
49
|
+
*/
|
|
50
|
+
export async function getPublicProducts(c) {
|
|
51
|
+
try {
|
|
52
|
+
const stripe = getStripe(c.env);
|
|
53
|
+
const products = await stripe.products.list({
|
|
54
|
+
active: true,
|
|
55
|
+
limit: 100,
|
|
56
|
+
expand: ['data.default_price']
|
|
57
|
+
});
|
|
58
|
+
const response = {
|
|
59
|
+
products: products.data.map((p) => mapStripeProduct(p, p.default_price)),
|
|
60
|
+
hasMore: products.has_more
|
|
61
|
+
};
|
|
62
|
+
return c.json(response);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('Failed to fetch products:', error);
|
|
66
|
+
return c.json({ success: false, error: 'Failed to fetch products' }, 500);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* POST /api/shop/checkout
|
|
71
|
+
* Create a Stripe Checkout Session
|
|
72
|
+
*/
|
|
73
|
+
export async function createCheckoutSession(c) {
|
|
74
|
+
try {
|
|
75
|
+
const stripe = getStripe(c.env);
|
|
76
|
+
const body = await c.req.json();
|
|
77
|
+
const { priceId, quantity = 1, successUrl, cancelUrl, customerEmail, metadata, mode = 'payment' } = body;
|
|
78
|
+
const items = body.items || [];
|
|
79
|
+
if (priceId) {
|
|
80
|
+
items.push({ priceId, quantity });
|
|
81
|
+
}
|
|
82
|
+
if (items.length === 0) {
|
|
83
|
+
return c.json({ success: false, error: 'No items provided' }, 400);
|
|
84
|
+
}
|
|
85
|
+
if (!successUrl || !cancelUrl) {
|
|
86
|
+
return c.json({ success: false, error: 'Missing successUrl or cancelUrl' }, 400);
|
|
87
|
+
}
|
|
88
|
+
const lineItems = items.map((item) => ({
|
|
89
|
+
price: item.priceId,
|
|
90
|
+
quantity: item.quantity,
|
|
91
|
+
}));
|
|
92
|
+
const sessionParams = {
|
|
93
|
+
line_items: lineItems,
|
|
94
|
+
mode: mode,
|
|
95
|
+
success_url: successUrl,
|
|
96
|
+
cancel_url: cancelUrl,
|
|
97
|
+
customer_email: customerEmail,
|
|
98
|
+
metadata: metadata,
|
|
99
|
+
allow_promotion_codes: true,
|
|
100
|
+
};
|
|
101
|
+
const session = await stripe.checkout.sessions.create(sessionParams);
|
|
102
|
+
return c.json({ url: session.url, sessionId: session.id });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error('Checkout error:', error);
|
|
106
|
+
return c.json({ success: false, error: error.message }, 500);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/shop/webhook
|
|
5
|
+
* Handle Stripe webhook events
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleStripeWebhook(c: Context<{
|
|
8
|
+
Bindings: Bindings;
|
|
9
|
+
}>): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=webhook.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/webhook.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAkC/C;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsC/F"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { getShopConfig, getEmailsConfig, getGitHubConfig } from '../../../lib/config';
|
|
2
|
+
import { createGitHubClient } from '../../../lib/github';
|
|
3
|
+
import Stripe from 'stripe';
|
|
4
|
+
import { generateInvoicePdf } from '../../emails/handlers/invoice.handler';
|
|
5
|
+
function getStripe(env) {
|
|
6
|
+
const config = getShopConfig(env);
|
|
7
|
+
return new Stripe(config.stripeSecretKey, {
|
|
8
|
+
apiVersion: '2025-02-24.acacia'
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
// Default invoice configuration
|
|
12
|
+
const DEFAULT_INVOICE_CONFIG = {
|
|
13
|
+
showLogo: true,
|
|
14
|
+
primaryColor: '#1f2937',
|
|
15
|
+
accentColor: '#3b82f6',
|
|
16
|
+
logoPosition: 'left',
|
|
17
|
+
fontFamily: 'helvetica',
|
|
18
|
+
companyName: 'Your Company',
|
|
19
|
+
companyAddress: '123 Main Street, City, Country',
|
|
20
|
+
companyEmail: 'contact@company.com',
|
|
21
|
+
companyPhone: '+1 234 567 890',
|
|
22
|
+
currencySymbol: '€',
|
|
23
|
+
currencyPosition: 'before',
|
|
24
|
+
showTaxBreakdown: true,
|
|
25
|
+
taxLabel: 'VAT',
|
|
26
|
+
taxRate: 19,
|
|
27
|
+
dueDays: 14,
|
|
28
|
+
footerText: 'Thank you for your business!'
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* POST /api/shop/webhook
|
|
32
|
+
* Handle Stripe webhook events
|
|
33
|
+
*/
|
|
34
|
+
export async function handleStripeWebhook(c) {
|
|
35
|
+
const stripe = getStripe(c.env);
|
|
36
|
+
const webhookSecret = c.env.HG_SHOP_STRIPE_WEBHOOK_SECRET;
|
|
37
|
+
if (!webhookSecret) {
|
|
38
|
+
console.error('Stripe webhook secret not configured');
|
|
39
|
+
return c.json({ error: 'Webhook not configured' }, 500);
|
|
40
|
+
}
|
|
41
|
+
// Get the raw body and signature
|
|
42
|
+
const signature = c.req.header('stripe-signature');
|
|
43
|
+
if (!signature) {
|
|
44
|
+
return c.json({ error: 'Missing stripe-signature header' }, 400);
|
|
45
|
+
}
|
|
46
|
+
const rawBody = await c.req.text();
|
|
47
|
+
let event;
|
|
48
|
+
try {
|
|
49
|
+
event = await stripe.webhooks.constructEventAsync(rawBody, signature, webhookSecret);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error('Webhook signature verification failed:', err.message);
|
|
53
|
+
return c.json({ error: 'Webhook signature verification failed' }, 400);
|
|
54
|
+
}
|
|
55
|
+
// Handle the event
|
|
56
|
+
switch (event.type) {
|
|
57
|
+
case 'checkout.session.completed': {
|
|
58
|
+
const session = event.data.object;
|
|
59
|
+
await handleCheckoutSessionCompleted(c, stripe, session);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
// Add more event handlers as needed
|
|
63
|
+
default:
|
|
64
|
+
console.log(`Unhandled event type: ${event.type}`);
|
|
65
|
+
}
|
|
66
|
+
return c.json({ received: true });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle checkout.session.completed event
|
|
70
|
+
* Generate and send invoice PDF to customer
|
|
71
|
+
*/
|
|
72
|
+
async function handleCheckoutSessionCompleted(c, stripe, session) {
|
|
73
|
+
try {
|
|
74
|
+
// Get customer email
|
|
75
|
+
const customerEmail = session.customer_details?.email;
|
|
76
|
+
if (!customerEmail) {
|
|
77
|
+
console.error('No customer email in checkout session');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Get line items
|
|
81
|
+
const lineItems = await stripe.checkout.sessions.listLineItems(session.id, {
|
|
82
|
+
expand: ['data.price.product']
|
|
83
|
+
});
|
|
84
|
+
// Get invoice template and branding from GitHub
|
|
85
|
+
let template;
|
|
86
|
+
let branding;
|
|
87
|
+
try {
|
|
88
|
+
const gitConfig = getGitHubConfig(c.env);
|
|
89
|
+
const github = createGitHubClient(gitConfig);
|
|
90
|
+
const settingsPath = `emails/settings.json`;
|
|
91
|
+
const result = await github.readJsonFile(settingsPath);
|
|
92
|
+
if (result?.data.invoice) {
|
|
93
|
+
template = result.data.invoice;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
template = {
|
|
97
|
+
id: 'invoice',
|
|
98
|
+
config: DEFAULT_INVOICE_CONFIG,
|
|
99
|
+
createdAt: Date.now(),
|
|
100
|
+
updatedAt: Date.now()
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (result?.data.branding) {
|
|
104
|
+
branding = result.data.branding;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error('Failed to fetch settings from GitHub:', error);
|
|
109
|
+
template = {
|
|
110
|
+
id: 'invoice',
|
|
111
|
+
config: DEFAULT_INVOICE_CONFIG,
|
|
112
|
+
createdAt: Date.now(),
|
|
113
|
+
updatedAt: Date.now()
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Build invoice data
|
|
117
|
+
const invoiceItems = lineItems.data.map((item) => {
|
|
118
|
+
const product = item.price?.product;
|
|
119
|
+
return {
|
|
120
|
+
description: product?.name || item.description || 'Item',
|
|
121
|
+
quantity: item.quantity || 1,
|
|
122
|
+
unitPrice: (item.price?.unit_amount || 0) / 100,
|
|
123
|
+
total: (item.amount_total || 0) / 100
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
const subtotal = (session.amount_subtotal || 0) / 100;
|
|
127
|
+
const tax = session.total_details?.amount_tax ? session.total_details.amount_tax / 100 : undefined;
|
|
128
|
+
const total = (session.amount_total || 0) / 100;
|
|
129
|
+
const invoiceData = {
|
|
130
|
+
invoiceNumber: `INV-${session.id.slice(-8).toUpperCase()}`,
|
|
131
|
+
invoiceDate: new Date().toLocaleDateString('en-US', {
|
|
132
|
+
year: 'numeric',
|
|
133
|
+
month: 'long',
|
|
134
|
+
day: 'numeric'
|
|
135
|
+
}),
|
|
136
|
+
customerName: session.customer_details?.name || 'Customer',
|
|
137
|
+
customerEmail,
|
|
138
|
+
customerAddress: session.customer_details?.address
|
|
139
|
+
? formatAddress(session.customer_details.address)
|
|
140
|
+
: undefined,
|
|
141
|
+
items: invoiceItems,
|
|
142
|
+
subtotal,
|
|
143
|
+
tax,
|
|
144
|
+
total,
|
|
145
|
+
currency: session.currency?.toUpperCase() || 'EUR',
|
|
146
|
+
paymentMethod: session.payment_method_types?.[0] || 'card'
|
|
147
|
+
};
|
|
148
|
+
// Generate PDF with branding
|
|
149
|
+
const pdfBytes = await generateInvoicePdf(template, invoiceData, branding ? {
|
|
150
|
+
logo: branding.logo,
|
|
151
|
+
companyName: branding.config.companyName,
|
|
152
|
+
primaryColor: branding.config.primaryColor,
|
|
153
|
+
} : undefined);
|
|
154
|
+
// Send email with PDF attachment
|
|
155
|
+
await sendInvoiceEmail(c, customerEmail, invoiceData, pdfBytes);
|
|
156
|
+
console.log(`Invoice sent to ${customerEmail} for session ${session.id}`);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('Failed to handle checkout session completed:', error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Format Stripe address object to string
|
|
164
|
+
*/
|
|
165
|
+
function formatAddress(address) {
|
|
166
|
+
const parts = [];
|
|
167
|
+
if (address.line1)
|
|
168
|
+
parts.push(address.line1);
|
|
169
|
+
if (address.line2)
|
|
170
|
+
parts.push(address.line2);
|
|
171
|
+
if (address.city)
|
|
172
|
+
parts.push(address.city);
|
|
173
|
+
if (address.postal_code)
|
|
174
|
+
parts.push(address.postal_code);
|
|
175
|
+
if (address.country)
|
|
176
|
+
parts.push(address.country);
|
|
177
|
+
return parts.join(', ');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Send invoice email with PDF attachment
|
|
181
|
+
*/
|
|
182
|
+
async function sendInvoiceEmail(c, to, invoiceData, pdfBytes) {
|
|
183
|
+
const emailsConfig = getEmailsConfig(c.env);
|
|
184
|
+
const apiKey = emailsConfig.plunkSecretKey;
|
|
185
|
+
const fromEmail = emailsConfig.fromEmail;
|
|
186
|
+
const fromName = emailsConfig.fromName || 'Shop';
|
|
187
|
+
if (!apiKey || !fromEmail) {
|
|
188
|
+
console.error('Email not configured');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Convert PDF to base64
|
|
192
|
+
const pdfBase64 = btoa(String.fromCharCode(...pdfBytes));
|
|
193
|
+
// Build email HTML
|
|
194
|
+
const html = `
|
|
195
|
+
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;">
|
|
196
|
+
<h1 style="color: #1f2937;">Thank you for your purchase!</h1>
|
|
197
|
+
<p style="color: #4b5563;">Dear ${invoiceData.customerName},</p>
|
|
198
|
+
<p style="color: #4b5563;">Thank you for your order. Please find your invoice attached to this email.</p>
|
|
199
|
+
|
|
200
|
+
<div style="background-color: #f3f4f6; padding: 20px; border-radius: 8px; margin: 20px 0;">
|
|
201
|
+
<p style="margin: 0; color: #1f2937;"><strong>Invoice Number:</strong> ${invoiceData.invoiceNumber}</p>
|
|
202
|
+
<p style="margin: 8px 0; color: #1f2937;"><strong>Date:</strong> ${invoiceData.invoiceDate}</p>
|
|
203
|
+
<p style="margin: 8px 0; color: #1f2937;"><strong>Total:</strong> ${invoiceData.currency} ${invoiceData.total.toFixed(2)}</p>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<p style="color: #4b5563;">If you have any questions about your order, please don't hesitate to contact us.</p>
|
|
207
|
+
|
|
208
|
+
<p style="color: #9ca3af; font-size: 12px; margin-top: 40px;">
|
|
209
|
+
This is an automated email. Please do not reply directly to this message.
|
|
210
|
+
</p>
|
|
211
|
+
</div>
|
|
212
|
+
`;
|
|
213
|
+
// Send via Plunk API
|
|
214
|
+
const payload = {
|
|
215
|
+
to,
|
|
216
|
+
subject: `Your Invoice ${invoiceData.invoiceNumber}`,
|
|
217
|
+
body: html,
|
|
218
|
+
from: fromEmail,
|
|
219
|
+
name: fromName,
|
|
220
|
+
};
|
|
221
|
+
const response = await fetch('https://api.useplunk.com/v1/send', {
|
|
222
|
+
method: 'POST',
|
|
223
|
+
headers: {
|
|
224
|
+
Authorization: `Bearer ${apiKey}`,
|
|
225
|
+
'Content-Type': 'application/json'
|
|
226
|
+
},
|
|
227
|
+
body: JSON.stringify(payload)
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
const error = await response.text();
|
|
231
|
+
throw new Error(`Failed to send invoice email: ${error}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/api/shop/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/api/shop/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAgB5C,QAAA,MAAM,UAAU;cAAwB,QAAQ;yCAAK,CAAC;AA0BtD,eAAe,UAAU,CAAC"}
|
package/dist/api/shop/routes.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
import { authMiddleware } from '../../middleware/auth';
|
|
3
3
|
// Import handlers
|
|
4
|
-
import { getProducts,
|
|
4
|
+
import { getProducts, getProduct, createProduct, updateProduct, deleteProduct } from './handlers/products.handler';
|
|
5
5
|
import { createPrice, updatePrice } from './handlers/prices.handler';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { uploadShopAsset } from './handlers/assets.handler';
|
|
7
|
+
import { getPublicProducts, createCheckoutSession } from './handlers/public.handler';
|
|
8
|
+
import { handleStripeWebhook } from './handlers/webhook.handler';
|
|
9
9
|
const shopRoutes = new Hono();
|
|
10
10
|
// Public routes (no auth required)
|
|
11
11
|
shopRoutes.get('/products', getPublicProducts);
|
|
12
|
+
shopRoutes.post('/checkout', createCheckoutSession);
|
|
13
|
+
// Stripe webhook (no auth, but verified by signature)
|
|
14
|
+
shopRoutes.post('/webhook', handleStripeWebhook);
|
|
12
15
|
// Apply auth middleware to all shop admin routes
|
|
13
16
|
shopRoutes.use('/admin/*', authMiddleware);
|
|
14
|
-
//
|
|
15
|
-
shopRoutes.
|
|
17
|
+
// Assets
|
|
18
|
+
shopRoutes.post('/admin/assets', uploadShopAsset);
|
|
16
19
|
// Products
|
|
17
20
|
shopRoutes.get('/admin/products', getProducts);
|
|
18
21
|
shopRoutes.get('/admin/products/:id', getProduct);
|
|
@@ -22,10 +25,4 @@ shopRoutes.delete('/admin/products/:id', deleteProduct);
|
|
|
22
25
|
// Prices
|
|
23
26
|
shopRoutes.post('/admin/prices', createPrice);
|
|
24
27
|
shopRoutes.patch('/admin/prices/:id', updatePrice);
|
|
25
|
-
// Orders
|
|
26
|
-
shopRoutes.get('/admin/orders', getOrders);
|
|
27
|
-
shopRoutes.get('/admin/orders/:id', getOrder);
|
|
28
|
-
// Customers
|
|
29
|
-
shopRoutes.get('/admin/customers', getCustomers);
|
|
30
|
-
shopRoutes.get('/admin/customers/:id', getCustomer);
|
|
31
28
|
export default shopRoutes;
|