@hintergrund/worker 0.1.0
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/README.md +45 -0
- package/dist/api/builder/handlers/generate.handler.d.ts +12 -0
- package/dist/api/builder/handlers/generate.handler.d.ts.map +1 -0
- package/dist/api/builder/handlers/generate.handler.js +203 -0
- package/dist/api/builder/handlers/template.handler.d.ts +12 -0
- package/dist/api/builder/handlers/template.handler.d.ts.map +1 -0
- package/dist/api/builder/handlers/template.handler.js +208 -0
- package/dist/api/builder/routes.d.ts +7 -0
- package/dist/api/builder/routes.d.ts.map +1 -0
- package/dist/api/builder/routes.js +15 -0
- package/dist/api/cms/handlers/assets.handler.d.ts +8 -0
- package/dist/api/cms/handlers/assets.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/assets.handler.js +299 -0
- package/dist/api/cms/handlers/auth.handler.d.ts +11 -0
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/auth.handler.js +214 -0
- package/dist/api/cms/handlers/config.handler.d.ts +3 -0
- package/dist/api/cms/handlers/config.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/config.handler.js +88 -0
- package/dist/api/cms/handlers/content.handler.d.ts +10 -0
- package/dist/api/cms/handlers/content.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/content.handler.js +293 -0
- package/dist/api/cms/handlers/dashboard.handler.d.ts +6 -0
- package/dist/api/cms/handlers/dashboard.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/dashboard.handler.js +15 -0
- package/dist/api/cms/routes/assets.routes.d.ts +4 -0
- package/dist/api/cms/routes/assets.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/assets.routes.js +13 -0
- package/dist/api/cms/routes/auth.routes.d.ts +4 -0
- package/dist/api/cms/routes/auth.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/auth.routes.js +7 -0
- package/dist/api/cms/routes/content.routes.d.ts +4 -0
- package/dist/api/cms/routes/content.routes.d.ts.map +1 -0
- package/dist/api/cms/routes/content.routes.js +11 -0
- package/dist/api/cms/routes/index.d.ts +4 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -0
- package/dist/api/cms/routes/index.js +16 -0
- package/dist/api/newsletter/handlers/email.handler.d.ts +7 -0
- package/dist/api/newsletter/handlers/email.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/email.handler.js +102 -0
- package/dist/api/newsletter/handlers/emails.handler.d.ts +21 -0
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/emails.handler.js +134 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/public.handler.js +242 -0
- package/dist/api/newsletter/handlers/send.handler.d.ts +12 -0
- package/dist/api/newsletter/handlers/send.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/send.handler.js +153 -0
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +22 -0
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +1 -0
- package/dist/api/newsletter/handlers/subscribers.handler.js +191 -0
- package/dist/api/newsletter/routes/admin.routes.d.ts +4 -0
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +1 -0
- package/dist/api/newsletter/routes/admin.routes.js +21 -0
- package/dist/api/newsletter/routes/index.d.ts +4 -0
- package/dist/api/newsletter/routes/index.d.ts.map +1 -0
- package/dist/api/newsletter/routes/index.js +9 -0
- package/dist/api/newsletter/routes/public.routes.d.ts +4 -0
- package/dist/api/newsletter/routes/public.routes.d.ts.map +1 -0
- package/dist/api/newsletter/routes/public.routes.js +9 -0
- package/dist/api/shop/handlers/customers.handler.d.ts +17 -0
- package/dist/api/shop/handlers/customers.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/customers.handler.js +89 -0
- package/dist/api/shop/handlers/orders.handler.d.ts +17 -0
- package/dist/api/shop/handlers/orders.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/orders.handler.js +84 -0
- package/dist/api/shop/handlers/prices.handler.d.ts +17 -0
- package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/prices.handler.js +87 -0
- package/dist/api/shop/handlers/products.handler.d.ts +45 -0
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/products.handler.js +243 -0
- package/dist/api/shop/handlers/stats.handler.d.ts +10 -0
- package/dist/api/shop/handlers/stats.handler.d.ts.map +1 -0
- package/dist/api/shop/handlers/stats.handler.js +71 -0
- package/dist/api/shop/routes.d.ts +7 -0
- package/dist/api/shop/routes.d.ts.map +1 -0
- package/dist/api/shop/routes.js +31 -0
- package/dist/cms-assets.d.ts +4 -0
- package/dist/cms-assets.d.ts.map +1 -0
- package/dist/cms-assets.js +5 -0
- package/dist/cms-bundle.d.ts +3 -0
- package/dist/cms-bundle.d.ts.map +1 -0
- package/dist/cms-bundle.js +4 -0
- package/dist/config-loader.d.ts +26 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +98 -0
- package/dist/hintergrund-assets.d.ts +4 -0
- package/dist/hintergrund-assets.d.ts.map +1 -0
- package/dist/hintergrund-assets.js +9 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/jwt.d.ts +26 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +102 -0
- package/dist/lib/auth/crypto.d.ts +23 -0
- package/dist/lib/auth/crypto.d.ts.map +1 -0
- package/dist/lib/auth/crypto.js +110 -0
- package/dist/lib/auth/jwt.d.ts +38 -0
- package/dist/lib/auth/jwt.d.ts.map +1 -0
- package/dist/lib/auth/jwt.js +120 -0
- package/dist/lib/config.d.ts +31 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +174 -0
- package/dist/lib/email.d.ts +16 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +83 -0
- package/dist/lib/template.d.ts +2 -0
- package/dist/lib/template.d.ts.map +1 -0
- package/dist/lib/template.js +226 -0
- package/dist/middleware/auth.d.ts +9 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +93 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +61 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +110 -0
- package/package.json +32 -0
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
* GET /api/shop/admin/products
|
|
71
|
+
* List all products
|
|
72
|
+
*/
|
|
73
|
+
export async function getProducts(c) {
|
|
74
|
+
try {
|
|
75
|
+
const stripe = getStripe(c.env);
|
|
76
|
+
const active = c.req.query('active');
|
|
77
|
+
const limit = parseInt(c.req.query('limit') || '100');
|
|
78
|
+
const params = {
|
|
79
|
+
limit,
|
|
80
|
+
expand: ['data.default_price']
|
|
81
|
+
};
|
|
82
|
+
if (active !== undefined) {
|
|
83
|
+
params.active = active === 'true';
|
|
84
|
+
}
|
|
85
|
+
const products = await stripe.products.list(params);
|
|
86
|
+
const response = {
|
|
87
|
+
products: products.data.map((p) => mapStripeProduct(p, p.default_price)),
|
|
88
|
+
hasMore: products.has_more
|
|
89
|
+
};
|
|
90
|
+
return c.json(response);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('Failed to fetch products:', error);
|
|
94
|
+
return c.json({ success: false, error: 'Failed to fetch products' }, 500);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* GET /api/shop/admin/products/:id
|
|
99
|
+
* Get a single product with all its prices
|
|
100
|
+
*/
|
|
101
|
+
export async function getProduct(c) {
|
|
102
|
+
try {
|
|
103
|
+
const stripe = getStripe(c.env);
|
|
104
|
+
const productId = c.req.param('id');
|
|
105
|
+
const [product, prices] = await Promise.all([
|
|
106
|
+
stripe.products.retrieve(productId, { expand: ['default_price'] }),
|
|
107
|
+
stripe.prices.list({ product: productId, limit: 100 })
|
|
108
|
+
]);
|
|
109
|
+
const productWithPrices = {
|
|
110
|
+
...mapStripeProduct(product, product.default_price),
|
|
111
|
+
prices: prices.data.map(mapStripePrice)
|
|
112
|
+
};
|
|
113
|
+
const response = { product: productWithPrices };
|
|
114
|
+
return c.json(response);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Failed to fetch product:', error);
|
|
118
|
+
return c.json({ success: false, error: 'Failed to fetch product' }, 500);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* POST /api/shop/admin/products
|
|
123
|
+
* Create a new product
|
|
124
|
+
*/
|
|
125
|
+
export async function createProduct(c) {
|
|
126
|
+
try {
|
|
127
|
+
const stripe = getStripe(c.env);
|
|
128
|
+
const body = await c.req.json();
|
|
129
|
+
// Create product params
|
|
130
|
+
const productParams = {
|
|
131
|
+
name: body.name,
|
|
132
|
+
description: body.description,
|
|
133
|
+
images: body.images,
|
|
134
|
+
metadata: body.metadata,
|
|
135
|
+
statement_descriptor: body.statementDescriptor,
|
|
136
|
+
unit_label: body.unitLabel,
|
|
137
|
+
url: body.url
|
|
138
|
+
};
|
|
139
|
+
// If default price is provided, create it with the product
|
|
140
|
+
if (body.defaultPrice) {
|
|
141
|
+
productParams.default_price_data = {
|
|
142
|
+
currency: body.defaultPrice.currency,
|
|
143
|
+
unit_amount: body.defaultPrice.unitAmount,
|
|
144
|
+
recurring: body.defaultPrice.recurring
|
|
145
|
+
? {
|
|
146
|
+
interval: body.defaultPrice.recurring.interval,
|
|
147
|
+
interval_count: body.defaultPrice.recurring.intervalCount || 1
|
|
148
|
+
}
|
|
149
|
+
: undefined
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const product = await stripe.products.create(productParams);
|
|
153
|
+
// Fetch with expanded default_price
|
|
154
|
+
const expandedProduct = await stripe.products.retrieve(product.id, {
|
|
155
|
+
expand: ['default_price']
|
|
156
|
+
});
|
|
157
|
+
const response = {
|
|
158
|
+
success: true,
|
|
159
|
+
product: mapStripeProduct(expandedProduct, expandedProduct.default_price)
|
|
160
|
+
};
|
|
161
|
+
return c.json(response, 201);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Failed to create product:', error);
|
|
165
|
+
return c.json({ success: false, error: 'Failed to create product' }, 500);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* PATCH /api/shop/admin/products/:id
|
|
170
|
+
* Update a product
|
|
171
|
+
*/
|
|
172
|
+
export async function updateProduct(c) {
|
|
173
|
+
try {
|
|
174
|
+
const stripe = getStripe(c.env);
|
|
175
|
+
const productId = c.req.param('id');
|
|
176
|
+
const body = await c.req.json();
|
|
177
|
+
const updateParams = {};
|
|
178
|
+
if (body.name !== undefined)
|
|
179
|
+
updateParams.name = body.name;
|
|
180
|
+
if (body.description !== undefined)
|
|
181
|
+
updateParams.description = body.description || '';
|
|
182
|
+
if (body.active !== undefined)
|
|
183
|
+
updateParams.active = body.active;
|
|
184
|
+
if (body.images !== undefined)
|
|
185
|
+
updateParams.images = body.images;
|
|
186
|
+
if (body.metadata !== undefined)
|
|
187
|
+
updateParams.metadata = body.metadata;
|
|
188
|
+
if (body.statementDescriptor !== undefined)
|
|
189
|
+
updateParams.statement_descriptor = body.statementDescriptor || '';
|
|
190
|
+
if (body.unitLabel !== undefined)
|
|
191
|
+
updateParams.unit_label = body.unitLabel || '';
|
|
192
|
+
if (body.url !== undefined)
|
|
193
|
+
updateParams.url = body.url || '';
|
|
194
|
+
if (body.defaultPriceId !== undefined)
|
|
195
|
+
updateParams.default_price = body.defaultPriceId;
|
|
196
|
+
const product = await stripe.products.update(productId, updateParams);
|
|
197
|
+
// Fetch with expanded default_price
|
|
198
|
+
const expandedProduct = await stripe.products.retrieve(product.id, {
|
|
199
|
+
expand: ['default_price']
|
|
200
|
+
});
|
|
201
|
+
const response = {
|
|
202
|
+
success: true,
|
|
203
|
+
product: mapStripeProduct(expandedProduct, expandedProduct.default_price)
|
|
204
|
+
};
|
|
205
|
+
return c.json(response);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error('Failed to update product:', error);
|
|
209
|
+
return c.json({ success: false, error: 'Failed to update product' }, 500);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* DELETE /api/shop/admin/products/:id
|
|
214
|
+
* Delete a product (archive if has prices)
|
|
215
|
+
*/
|
|
216
|
+
export async function deleteProduct(c) {
|
|
217
|
+
try {
|
|
218
|
+
const stripe = getStripe(c.env);
|
|
219
|
+
const productId = c.req.param('id');
|
|
220
|
+
try {
|
|
221
|
+
// Try to delete - will fail if product has prices
|
|
222
|
+
await stripe.products.del(productId);
|
|
223
|
+
const response = {
|
|
224
|
+
success: true,
|
|
225
|
+
message: 'Product deleted'
|
|
226
|
+
};
|
|
227
|
+
return c.json(response);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
// If delete fails, archive instead
|
|
231
|
+
await stripe.products.update(productId, { active: false });
|
|
232
|
+
const response = {
|
|
233
|
+
success: true,
|
|
234
|
+
message: 'Product archived (has associated prices)'
|
|
235
|
+
};
|
|
236
|
+
return c.json(response);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error('Failed to delete product:', error);
|
|
241
|
+
return c.json({ success: false, error: 'Failed to delete product' }, 500);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Bindings } from '../../../index';
|
|
3
|
+
/**
|
|
4
|
+
* GET /api/shop/admin/stats
|
|
5
|
+
* Get shop statistics
|
|
6
|
+
*/
|
|
7
|
+
export declare function getStats(c: Context<{
|
|
8
|
+
Bindings: Bindings;
|
|
9
|
+
}>): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=stats.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/stats.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAY/C;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwEpF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* GET /api/shop/admin/stats
|
|
11
|
+
* Get shop statistics
|
|
12
|
+
*/
|
|
13
|
+
export async function getStats(c) {
|
|
14
|
+
try {
|
|
15
|
+
const stripe = getStripe(c.env);
|
|
16
|
+
// Fetch data in parallel
|
|
17
|
+
const [products, activeProducts, paymentIntents] = await Promise.all([
|
|
18
|
+
stripe.products.list({ limit: 1 }),
|
|
19
|
+
stripe.products.list({ active: true, limit: 1 }),
|
|
20
|
+
stripe.paymentIntents.list({
|
|
21
|
+
limit: 100,
|
|
22
|
+
expand: ['data.customer']
|
|
23
|
+
})
|
|
24
|
+
]);
|
|
25
|
+
// Get total counts (using total_count if available)
|
|
26
|
+
const totalProducts = products.data.length > 0 ? (await stripe.products.list({ limit: 100 })).data.length : 0;
|
|
27
|
+
const activeProductCount = activeProducts.data.length > 0 ? (await stripe.products.list({ active: true, limit: 100 })).data.length : 0;
|
|
28
|
+
// Calculate order stats
|
|
29
|
+
const succeededPayments = paymentIntents.data.filter((pi) => pi.status === 'succeeded');
|
|
30
|
+
const totalRevenue = succeededPayments.reduce((sum, pi) => sum + pi.amount_received, 0);
|
|
31
|
+
// Get default currency from first payment or default to USD
|
|
32
|
+
const currency = succeededPayments[0]?.currency || 'usd';
|
|
33
|
+
// Map recent orders
|
|
34
|
+
const recentOrders = paymentIntents.data.slice(0, 10).map((pi) => {
|
|
35
|
+
let customerEmail = pi.receipt_email || null;
|
|
36
|
+
let customerName = null;
|
|
37
|
+
if (typeof pi.customer !== 'string' && pi.customer && !pi.customer.deleted) {
|
|
38
|
+
const customer = pi.customer;
|
|
39
|
+
customerEmail = customerEmail || customer.email || null;
|
|
40
|
+
customerName = customer.name || null;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
id: pi.id,
|
|
44
|
+
customerId: typeof pi.customer === 'string' ? pi.customer : pi.customer?.id || null,
|
|
45
|
+
customerEmail,
|
|
46
|
+
customerName,
|
|
47
|
+
amount: pi.amount,
|
|
48
|
+
amountReceived: pi.amount_received,
|
|
49
|
+
currency: pi.currency,
|
|
50
|
+
status: pi.status,
|
|
51
|
+
paymentMethod: typeof pi.payment_method === 'string' ? pi.payment_method : pi.payment_method?.id || null,
|
|
52
|
+
lineItems: [],
|
|
53
|
+
metadata: pi.metadata || {},
|
|
54
|
+
createdAt: pi.created
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
const response = {
|
|
58
|
+
totalProducts,
|
|
59
|
+
activeProducts: activeProductCount,
|
|
60
|
+
totalOrders: succeededPayments.length,
|
|
61
|
+
totalRevenue,
|
|
62
|
+
currency,
|
|
63
|
+
recentOrders
|
|
64
|
+
};
|
|
65
|
+
return c.json(response);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Failed to fetch stats:', error);
|
|
69
|
+
return c.json({ success: false, error: 'Failed to fetch stats' }, 500);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +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;AAiB5C,QAAA,MAAM,UAAU;cAAwB,QAAQ;yCAAK,CAAC;AA8BtD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { authMiddleware } from '../../middleware/auth';
|
|
3
|
+
// Import handlers
|
|
4
|
+
import { getProducts, getPublicProducts, getProduct, createProduct, updateProduct, deleteProduct } from './handlers/products.handler';
|
|
5
|
+
import { createPrice, updatePrice } from './handlers/prices.handler';
|
|
6
|
+
import { getOrders, getOrder } from './handlers/orders.handler';
|
|
7
|
+
import { getCustomers, getCustomer } from './handlers/customers.handler';
|
|
8
|
+
import { getStats } from './handlers/stats.handler';
|
|
9
|
+
const shopRoutes = new Hono();
|
|
10
|
+
// Public routes (no auth required)
|
|
11
|
+
shopRoutes.get('/products', getPublicProducts);
|
|
12
|
+
// Apply auth middleware to all shop admin routes
|
|
13
|
+
shopRoutes.use('/admin/*', authMiddleware);
|
|
14
|
+
// Stats
|
|
15
|
+
shopRoutes.get('/admin/stats', getStats);
|
|
16
|
+
// Products
|
|
17
|
+
shopRoutes.get('/admin/products', getProducts);
|
|
18
|
+
shopRoutes.get('/admin/products/:id', getProduct);
|
|
19
|
+
shopRoutes.post('/admin/products', createProduct);
|
|
20
|
+
shopRoutes.patch('/admin/products/:id', updateProduct);
|
|
21
|
+
shopRoutes.delete('/admin/products/:id', deleteProduct);
|
|
22
|
+
// Prices
|
|
23
|
+
shopRoutes.post('/admin/prices', createPrice);
|
|
24
|
+
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
|
+
export default shopRoutes;
|