@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.
- package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
- package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/admin-users.handler.js +121 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
- package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
- package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
- package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/auth.handler.js +74 -153
- package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/website-repo.handler.js +148 -0
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +16 -4
- package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +164 -92
- package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/invoice.handler.js +58 -340
- package/dist/api/emails/handlers/public.handler.d.ts +6 -29
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +150 -312
- package/dist/api/emails/handlers/send.handler.d.ts +5 -17
- package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/send.handler.js +107 -92
- package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +96 -287
- package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
- package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
- package/dist/api/emails/handlers/subscribers.handler.js +125 -0
- package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
- package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/webhook.handler.js +66 -166
- package/dist/api/emails/routes/admin.routes.d.ts +1 -3
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +19 -49
- package/dist/api/emails/routes/public.routes.d.ts +1 -3
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/public.routes.js +2 -9
- package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
- package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/prices.handler.js +2 -83
- package/dist/api/shop/handlers/products.handler.d.ts +29 -20
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +195 -162
- package/dist/api/shop/handlers/public.handler.d.ts +24 -8
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +525 -78
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +14 -9
- package/dist/hintergrund-assets.d.ts +3 -2
- package/dist/hintergrund-assets.d.ts.map +1 -1
- package/dist/hintergrund-assets.js +4 -2
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -4
- package/dist/lib/auth/crypto.d.ts +2 -15
- package/dist/lib/auth/crypto.d.ts.map +1 -1
- package/dist/lib/auth/crypto.js +8 -95
- package/dist/lib/auth/jwt.d.ts +0 -4
- package/dist/lib/auth/jwt.d.ts.map +1 -1
- package/dist/lib/auth/jwt.js +0 -6
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +42 -86
- package/dist/lib/email-template.d.ts +15 -0
- package/dist/lib/email-template.d.ts.map +1 -0
- package/dist/lib/email-template.js +58 -0
- package/dist/lib/email.d.ts +18 -8
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +59 -70
- package/dist/lib/github-config.d.ts +19 -0
- package/dist/lib/github-config.d.ts.map +1 -0
- package/dist/lib/github-config.js +23 -0
- package/dist/lib/github.d.ts +10 -0
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +20 -2
- package/dist/lib/project-db.d.ts +24 -0
- package/dist/lib/project-db.d.ts.map +1 -0
- package/dist/lib/project-db.js +172 -0
- package/dist/lib/template.js +4 -4
- package/dist/middleware/auth.d.ts +0 -2
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +21 -50
- package/package.json +2 -1
- package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
- package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/generate.handler.js +0 -203
- package/dist/api/builder/handlers/template.handler.d.ts +0 -12
- package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
- package/dist/api/builder/handlers/template.handler.js +0 -208
- package/dist/api/builder/routes.d.ts +0 -7
- package/dist/api/builder/routes.d.ts.map +0 -1
- package/dist/api/builder/routes.js +0 -15
- package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
- package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/assets.handler.js +0 -200
- package/dist/api/cms/handlers/config.handler.d.ts +0 -7
- package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/config.handler.js +0 -37
- package/dist/api/cms/handlers/content.handler.d.ts +0 -21
- package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/content.handler.js +0 -117
- package/dist/api/cms/routes/assets.routes.d.ts +0 -4
- package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/assets.routes.js +0 -13
- package/dist/api/cms/routes/content.routes.d.ts +0 -4
- package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
- package/dist/api/cms/routes/content.routes.js +0 -11
- package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
- package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/branding.handler.js +0 -120
- package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
- package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/contacts.handler.js +0 -161
- package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
- package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/templates.handler.js +0 -132
- package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
- package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/email.handler.js +0 -102
- package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
- package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/emails.handler.js +0 -262
- package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
- package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/public.handler.js +0 -300
- package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
- package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/send.handler.js +0 -153
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
- package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
- package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
- package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/admin.routes.js +0 -28
- package/dist/api/newsletter/routes/index.d.ts +0 -4
- package/dist/api/newsletter/routes/index.d.ts.map +0 -1
- package/dist/api/newsletter/routes/index.js +0 -9
- package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
- package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
- package/dist/api/newsletter/routes/public.routes.js +0 -9
- package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
- package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/assets.handler.js +0 -62
- package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
- package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/checkout.handler.js +0 -50
- package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
- package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/customers.handler.js +0 -89
- package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
- package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/orders.handler.js +0 -84
- package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
- package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/stats.handler.js +0 -71
- package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
- package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
- package/dist/api/shop/handlers/webhook.handler.js +0 -233
- package/dist/cms-assets.d.ts +0 -4
- package/dist/cms-assets.d.ts.map +0 -1
- package/dist/cms-assets.js +0 -5
- package/dist/cms-bundle.d.ts +0 -3
- package/dist/cms-bundle.d.ts.map +0 -1
- package/dist/cms-bundle.js +0 -4
- package/dist/config-loader.d.ts +0 -26
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -98
- package/dist/jwt.d.ts +0 -26
- package/dist/jwt.d.ts.map +0 -1
- package/dist/jwt.js +0 -102
- package/dist/lib/plunk.d.ts +0 -204
- package/dist/lib/plunk.d.ts.map +0 -1
- package/dist/lib/plunk.js +0 -259
- package/dist/template.d.ts +0 -2
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -61
- package/dist/utils.d.ts +0 -23
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -110
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"products.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/products.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"products.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/products.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EAOX,WAAW,EAEX,YAAY,EAKZ,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,kBAAkB,wCAAwC,CAAC;AACxE,eAAO,MAAM,kBAAkB,wCAAwC,CAAC;AAExE,eAAO,MAAM,qBAAqB,EAAE,YAAY,GAAG;IAClD,cAAc,EAAE;QACf,QAAQ,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;QAChD,gBAAgB,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;KACxD,CAAC;CAyBF,CAAC;AA+BF,wBAAsB,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAIzG;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,Q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
|
3
|
+
import { ConfigConflictError, readJsonConfig, writeJsonConfig } from '../../../lib/github-config';
|
|
4
|
+
export const SHOP_PRODUCTS_PATH = 'frontend/src/lib/shop/products.json';
|
|
5
|
+
export const SHOP_SETTINGS_PATH = 'frontend/src/lib/shop/settings.json';
|
|
6
|
+
export const DEFAULT_SHOP_SETTINGS = {
|
|
7
|
+
currency: 'eur',
|
|
8
|
+
enabledPaymentMethods: ['bank_transfer'],
|
|
9
|
+
bankTransfer: {
|
|
10
|
+
accountHolder: '',
|
|
11
|
+
iban: '',
|
|
12
|
+
bic: '',
|
|
13
|
+
bankName: '',
|
|
14
|
+
instructions: 'Please use your order number as the payment reference.'
|
|
15
|
+
},
|
|
16
|
+
shippingFlatRate: 0,
|
|
17
|
+
freeShippingThreshold: 0,
|
|
18
|
+
orderNumberPrefix: 'ORD',
|
|
19
|
+
invoiceNumberPrefix: 'INV',
|
|
20
|
+
emailTemplates: {
|
|
21
|
+
purchase: {
|
|
22
|
+
subject: 'Your order {{order_number}}',
|
|
23
|
+
bodyHtml: '<h2>Thank you for your order.</h2><p>Please find your invoice and payment instructions below.</p>'
|
|
24
|
+
},
|
|
25
|
+
paymentConfirmed: {
|
|
26
|
+
subject: 'Payment confirmed - {{order_number}}',
|
|
27
|
+
bodyHtml: '<h2>Payment confirmed</h2><p>We have received your payment of {{amount}} for order {{order_number}}. Thank you.</p>'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function getGitHub(c) {
|
|
32
|
+
return createGitHubClient(getGitHubConfig(c.env));
|
|
33
|
+
}
|
|
34
|
+
function nowSeconds() {
|
|
35
|
+
return Math.floor(Date.now() / 1000);
|
|
36
|
+
}
|
|
37
|
+
function slugify(value) {
|
|
38
|
+
return value
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.trim()
|
|
41
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
42
|
+
.replace(/^-+|-+$/g, '') || `product-${Date.now()}`;
|
|
43
|
+
}
|
|
44
|
+
function createId(prefix) {
|
|
45
|
+
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
8
46
|
}
|
|
9
|
-
function
|
|
47
|
+
async function readCatalog(github) {
|
|
48
|
+
const result = await github.readJsonFile(SHOP_PRODUCTS_PATH);
|
|
10
49
|
return {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
50
|
+
catalog: result?.data ?? { products: [], updatedAt: Date.now() },
|
|
51
|
+
commitSha: await github.getCommitSha(),
|
|
52
|
+
fileSha: result?.sha
|
|
27
53
|
};
|
|
28
54
|
}
|
|
29
|
-
function
|
|
55
|
+
export async function readShopCatalog(env) {
|
|
56
|
+
const github = createGitHubClient(getGitHubConfig(env));
|
|
57
|
+
const { catalog, commitSha } = await readCatalog(github);
|
|
58
|
+
return { catalog, commitSha };
|
|
59
|
+
}
|
|
60
|
+
export async function readShopSettings(env) {
|
|
61
|
+
const github = createGitHubClient(getGitHubConfig(env));
|
|
62
|
+
const { data, commitSha } = await readJsonConfig(github, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS, {
|
|
63
|
+
mergeNested: (raw, defaults) => ({
|
|
64
|
+
bankTransfer: { ...defaults.bankTransfer, ...(raw.bankTransfer ?? {}) },
|
|
65
|
+
shippingFlatRate: raw.shippingFlatRate ?? defaults.shippingFlatRate,
|
|
66
|
+
freeShippingThreshold: raw.freeShippingThreshold ?? defaults.freeShippingThreshold,
|
|
67
|
+
emailTemplates: {
|
|
68
|
+
purchase: { ...DEFAULT_SHOP_SETTINGS.emailTemplates.purchase, ...(raw.emailTemplates?.purchase ?? {}) },
|
|
69
|
+
paymentConfirmed: { ...DEFAULT_SHOP_SETTINGS.emailTemplates.paymentConfirmed, ...(raw.emailTemplates?.paymentConfirmed ?? {}) },
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
return { settings: data, commitSha };
|
|
74
|
+
}
|
|
75
|
+
async function writeCatalog(github, catalog, message, expectedCommitSha) {
|
|
76
|
+
if (expectedCommitSha && !(await github.checkNoConflict(expectedCommitSha))) {
|
|
77
|
+
const error = new Error('Catalog changed upstream. Reload before publishing.');
|
|
78
|
+
error.status = 409;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
catalog.updatedAt = Date.now();
|
|
82
|
+
await github.writeJsonFile(SHOP_PRODUCTS_PATH, catalog, message);
|
|
83
|
+
return github.getCommitSha();
|
|
84
|
+
}
|
|
85
|
+
function normalizeProduct(body, existing) {
|
|
86
|
+
const timestamp = nowSeconds();
|
|
87
|
+
const name = body.name?.trim() || existing?.name || 'Untitled product';
|
|
88
|
+
const id = existing?.id ?? createId('prod');
|
|
30
89
|
return {
|
|
31
|
-
id
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
images:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
90
|
+
id,
|
|
91
|
+
slug: body.slug?.trim() || existing?.slug || slugify(name),
|
|
92
|
+
name,
|
|
93
|
+
description: body.description ?? existing?.description ?? '',
|
|
94
|
+
active: body.active ?? existing?.active ?? true,
|
|
95
|
+
images: body.images ?? existing?.images ?? [],
|
|
96
|
+
prices: (body.prices ?? existing?.prices ?? []).map((price) => ({
|
|
97
|
+
...price,
|
|
98
|
+
id: price.id || createId('price'),
|
|
99
|
+
label: price.label || 'Standard',
|
|
100
|
+
currency: price.currency.toLowerCase(),
|
|
101
|
+
unitAmount: Math.round(price.unitAmount),
|
|
102
|
+
active: price.active ?? true
|
|
103
|
+
})),
|
|
104
|
+
metadata: body.metadata ?? existing?.metadata ?? {},
|
|
105
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
106
|
+
updatedAt: timestamp
|
|
44
107
|
};
|
|
45
108
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
109
|
+
function conflictResponse(c, error) {
|
|
110
|
+
if (error?.status !== 409)
|
|
111
|
+
return null;
|
|
112
|
+
return c.json({ success: false, error: error.message, code: 'conflict' }, 409);
|
|
113
|
+
}
|
|
50
114
|
export async function getProducts(c) {
|
|
51
115
|
try {
|
|
52
|
-
const stripe = getStripe(c.env);
|
|
53
116
|
const active = c.req.query('active');
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
expand: ['data.default_price']
|
|
58
|
-
};
|
|
59
|
-
if (active !== undefined) {
|
|
60
|
-
params.active = active === 'true';
|
|
61
|
-
}
|
|
62
|
-
const products = await stripe.products.list(params);
|
|
63
|
-
const response = {
|
|
64
|
-
products: products.data.map((p) => mapStripeProduct(p, p.default_price)),
|
|
65
|
-
hasMore: products.has_more
|
|
66
|
-
};
|
|
117
|
+
const { catalog, commitSha } = await readCatalog(getGitHub(c));
|
|
118
|
+
const products = active === undefined ? catalog.products : catalog.products.filter((product) => product.active === (active === 'true'));
|
|
119
|
+
const response = { products, hasMore: false, commitSha };
|
|
67
120
|
return c.json(response);
|
|
68
121
|
}
|
|
69
122
|
catch (error) {
|
|
@@ -71,23 +124,14 @@ export async function getProducts(c) {
|
|
|
71
124
|
return c.json({ success: false, error: 'Failed to fetch products' }, 500);
|
|
72
125
|
}
|
|
73
126
|
}
|
|
74
|
-
/**
|
|
75
|
-
* GET /api/shop/admin/products/:id
|
|
76
|
-
* Get a single product with all its prices
|
|
77
|
-
*/
|
|
78
127
|
export async function getProduct(c) {
|
|
79
128
|
try {
|
|
80
|
-
const stripe = getStripe(c.env);
|
|
81
129
|
const productId = c.req.param('id');
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
...mapStripeProduct(product, product.default_price),
|
|
88
|
-
prices: prices.data.map(mapStripePrice)
|
|
89
|
-
};
|
|
90
|
-
const response = { product: productWithPrices };
|
|
130
|
+
const { catalog, commitSha } = await readCatalog(getGitHub(c));
|
|
131
|
+
const product = catalog.products.find((item) => item.id === productId || item.slug === productId);
|
|
132
|
+
if (!product)
|
|
133
|
+
return c.json({ success: false, error: 'Product not found' }, 404);
|
|
134
|
+
const response = { product, commitSha };
|
|
91
135
|
return c.json(response);
|
|
92
136
|
}
|
|
93
137
|
catch (error) {
|
|
@@ -95,126 +139,115 @@ export async function getProduct(c) {
|
|
|
95
139
|
return c.json({ success: false, error: 'Failed to fetch product' }, 500);
|
|
96
140
|
}
|
|
97
141
|
}
|
|
98
|
-
/**
|
|
99
|
-
* POST /api/shop/admin/products
|
|
100
|
-
* Create a new product
|
|
101
|
-
*/
|
|
102
142
|
export async function createProduct(c) {
|
|
103
143
|
try {
|
|
104
|
-
const
|
|
144
|
+
const github = getGitHub(c);
|
|
105
145
|
const body = await c.req.json();
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
images: body.images,
|
|
111
|
-
metadata: body.metadata,
|
|
112
|
-
statement_descriptor: body.statementDescriptor,
|
|
113
|
-
unit_label: body.unitLabel,
|
|
114
|
-
url: body.url
|
|
115
|
-
};
|
|
116
|
-
// If default price is provided, create it with the product
|
|
117
|
-
if (body.defaultPrice) {
|
|
118
|
-
productParams.default_price_data = {
|
|
119
|
-
currency: body.defaultPrice.currency,
|
|
120
|
-
unit_amount: body.defaultPrice.unitAmount,
|
|
121
|
-
recurring: body.defaultPrice.recurring
|
|
122
|
-
? {
|
|
123
|
-
interval: body.defaultPrice.recurring.interval,
|
|
124
|
-
interval_count: body.defaultPrice.recurring.intervalCount || 1
|
|
125
|
-
}
|
|
126
|
-
: undefined
|
|
127
|
-
};
|
|
146
|
+
const { catalog } = await readCatalog(github);
|
|
147
|
+
const product = normalizeProduct(body);
|
|
148
|
+
if (catalog.products.some((item) => item.id === product.id || item.slug === product.slug)) {
|
|
149
|
+
return c.json({ success: false, error: 'Product id or slug already exists' }, 409);
|
|
128
150
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
expand: ['default_price']
|
|
133
|
-
});
|
|
134
|
-
const response = {
|
|
135
|
-
success: true,
|
|
136
|
-
product: mapStripeProduct(expandedProduct, expandedProduct.default_price)
|
|
137
|
-
};
|
|
151
|
+
catalog.products = [product, ...catalog.products];
|
|
152
|
+
const commitSha = await writeCatalog(github, catalog, `Create shop product ${product.name} [skip ci]`, body.commitSha);
|
|
153
|
+
const response = { success: true, product, commitSha };
|
|
138
154
|
return c.json(response, 201);
|
|
139
155
|
}
|
|
140
156
|
catch (error) {
|
|
157
|
+
const conflict = conflictResponse(c, error);
|
|
158
|
+
if (conflict)
|
|
159
|
+
return conflict;
|
|
141
160
|
console.error('Failed to create product:', error);
|
|
142
161
|
return c.json({ success: false, error: 'Failed to create product' }, 500);
|
|
143
162
|
}
|
|
144
163
|
}
|
|
145
|
-
/**
|
|
146
|
-
* PATCH /api/shop/admin/products/:id
|
|
147
|
-
* Update a product
|
|
148
|
-
*/
|
|
149
164
|
export async function updateProduct(c) {
|
|
150
165
|
try {
|
|
151
|
-
const
|
|
166
|
+
const github = getGitHub(c);
|
|
152
167
|
const productId = c.req.param('id');
|
|
153
168
|
const body = await c.req.json();
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (body.statementDescriptor !== undefined)
|
|
166
|
-
updateParams.statement_descriptor = body.statementDescriptor || '';
|
|
167
|
-
if (body.unitLabel !== undefined)
|
|
168
|
-
updateParams.unit_label = body.unitLabel || '';
|
|
169
|
-
if (body.url !== undefined)
|
|
170
|
-
updateParams.url = body.url || '';
|
|
171
|
-
if (body.defaultPriceId !== undefined)
|
|
172
|
-
updateParams.default_price = body.defaultPriceId;
|
|
173
|
-
const product = await stripe.products.update(productId, updateParams);
|
|
174
|
-
// Fetch with expanded default_price
|
|
175
|
-
const expandedProduct = await stripe.products.retrieve(product.id, {
|
|
176
|
-
expand: ['default_price']
|
|
177
|
-
});
|
|
178
|
-
const response = {
|
|
179
|
-
success: true,
|
|
180
|
-
product: mapStripeProduct(expandedProduct, expandedProduct.default_price)
|
|
181
|
-
};
|
|
169
|
+
const { catalog } = await readCatalog(github);
|
|
170
|
+
const index = catalog.products.findIndex((item) => item.id === productId || item.slug === productId);
|
|
171
|
+
if (index === -1)
|
|
172
|
+
return c.json({ success: false, error: 'Product not found' }, 404);
|
|
173
|
+
const product = normalizeProduct(body, catalog.products[index]);
|
|
174
|
+
const duplicate = catalog.products.find((item, itemIndex) => itemIndex !== index && item.slug === product.slug);
|
|
175
|
+
if (duplicate)
|
|
176
|
+
return c.json({ success: false, error: 'Product slug already exists' }, 409);
|
|
177
|
+
catalog.products[index] = product;
|
|
178
|
+
const commitSha = await writeCatalog(github, catalog, `Update shop product ${product.name} [skip ci]`, body.commitSha);
|
|
179
|
+
const response = { success: true, product, commitSha };
|
|
182
180
|
return c.json(response);
|
|
183
181
|
}
|
|
184
182
|
catch (error) {
|
|
183
|
+
const conflict = conflictResponse(c, error);
|
|
184
|
+
if (conflict)
|
|
185
|
+
return conflict;
|
|
185
186
|
console.error('Failed to update product:', error);
|
|
186
187
|
return c.json({ success: false, error: 'Failed to update product' }, 500);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
/**
|
|
190
|
-
* DELETE /api/shop/admin/products/:id
|
|
191
|
-
* Delete a product (archive if has prices)
|
|
192
|
-
*/
|
|
193
190
|
export async function deleteProduct(c) {
|
|
194
191
|
try {
|
|
195
|
-
const
|
|
192
|
+
const github = getGitHub(c);
|
|
196
193
|
const productId = c.req.param('id');
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
catch {
|
|
207
|
-
// If delete fails, archive instead
|
|
208
|
-
await stripe.products.update(productId, { active: false });
|
|
209
|
-
const response = {
|
|
210
|
-
success: true,
|
|
211
|
-
message: 'Product archived (has associated prices)'
|
|
212
|
-
};
|
|
213
|
-
return c.json(response);
|
|
214
|
-
}
|
|
194
|
+
const commitShaParam = c.req.query('commitSha');
|
|
195
|
+
const { catalog } = await readCatalog(github);
|
|
196
|
+
const before = catalog.products.length;
|
|
197
|
+
catalog.products = catalog.products.filter((item) => item.id !== productId && item.slug !== productId);
|
|
198
|
+
if (catalog.products.length === before)
|
|
199
|
+
return c.json({ success: false, error: 'Product not found' }, 404);
|
|
200
|
+
const commitSha = await writeCatalog(github, catalog, `Delete shop product ${productId} [skip ci]`, commitShaParam);
|
|
201
|
+
const response = { success: true, message: 'Product deleted', commitSha };
|
|
202
|
+
return c.json(response);
|
|
215
203
|
}
|
|
216
204
|
catch (error) {
|
|
205
|
+
const conflict = conflictResponse(c, error);
|
|
206
|
+
if (conflict)
|
|
207
|
+
return conflict;
|
|
217
208
|
console.error('Failed to delete product:', error);
|
|
218
209
|
return c.json({ success: false, error: 'Failed to delete product' }, 500);
|
|
219
210
|
}
|
|
220
211
|
}
|
|
212
|
+
export async function getSettings(c) {
|
|
213
|
+
try {
|
|
214
|
+
const { settings, commitSha } = await readShopSettings(c.env);
|
|
215
|
+
const response = {
|
|
216
|
+
settings,
|
|
217
|
+
commitSha,
|
|
218
|
+
stripeConfigured: !!c.env.HG_SHOP_STRIPE_SECRET_KEY
|
|
219
|
+
};
|
|
220
|
+
return c.json(response);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.error('Failed to fetch shop settings:', error);
|
|
224
|
+
return c.json({ success: false, error: 'Failed to fetch shop settings' }, 500);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export async function updateSettings(c) {
|
|
228
|
+
try {
|
|
229
|
+
const github = getGitHub(c);
|
|
230
|
+
const body = await c.req.json();
|
|
231
|
+
const settings = {
|
|
232
|
+
...DEFAULT_SHOP_SETTINGS,
|
|
233
|
+
...body.settings,
|
|
234
|
+
bankTransfer: { ...DEFAULT_SHOP_SETTINGS.bankTransfer, ...body.settings.bankTransfer },
|
|
235
|
+
shippingFlatRate: body.settings.shippingFlatRate ?? 0,
|
|
236
|
+
freeShippingThreshold: body.settings.freeShippingThreshold ?? 0,
|
|
237
|
+
emailTemplates: {
|
|
238
|
+
purchase: { ...DEFAULT_SHOP_SETTINGS.emailTemplates.purchase, ...(body.settings.emailTemplates?.purchase ?? {}) },
|
|
239
|
+
paymentConfirmed: { ...DEFAULT_SHOP_SETTINGS.emailTemplates.paymentConfirmed, ...(body.settings.emailTemplates?.paymentConfirmed ?? {}) },
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
const commitSha = await writeJsonConfig(github, SHOP_SETTINGS_PATH, settings, 'Update shop settings [skip ci]', body.commitSha);
|
|
243
|
+
const response = { success: true, settings, commitSha };
|
|
244
|
+
return c.json(response);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (error instanceof ConfigConflictError) {
|
|
248
|
+
return c.json({ success: false, error: error.message, code: 'conflict' }, 409);
|
|
249
|
+
}
|
|
250
|
+
console.error('Failed to update shop settings:', error);
|
|
251
|
+
return c.json({ success: false, error: 'Failed to update shop settings' }, 500);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { Bindings } from '../../../index';
|
|
3
|
-
/**
|
|
4
|
-
* GET /api/shop/products
|
|
5
|
-
* List all active products (public endpoint)
|
|
6
|
-
*/
|
|
7
3
|
export declare function getPublicProducts(c: Context<{
|
|
8
4
|
Bindings: Bindings;
|
|
9
5
|
}>): Promise<Response>;
|
|
10
|
-
/**
|
|
11
|
-
* POST /api/shop/checkout
|
|
12
|
-
* Create a Stripe Checkout Session
|
|
13
|
-
*/
|
|
14
6
|
export declare function createCheckoutSession(c: Context<{
|
|
15
7
|
Bindings: Bindings;
|
|
16
8
|
}>): Promise<Response>;
|
|
9
|
+
export declare function getOrders(c: Context<{
|
|
10
|
+
Bindings: Bindings;
|
|
11
|
+
}>): Promise<Response>;
|
|
12
|
+
export declare function getPublicOrder(c: Context<{
|
|
13
|
+
Bindings: Bindings;
|
|
14
|
+
}>): Promise<Response>;
|
|
15
|
+
export declare function getAdminOrder(c: Context<{
|
|
16
|
+
Bindings: Bindings;
|
|
17
|
+
}>): Promise<Response>;
|
|
18
|
+
export declare function updateOrderStatus(c: Context<{
|
|
19
|
+
Bindings: Bindings;
|
|
20
|
+
}>): Promise<Response>;
|
|
21
|
+
export declare function confirmPayment(c: Context<{
|
|
22
|
+
Bindings: Bindings;
|
|
23
|
+
}>): Promise<Response>;
|
|
24
|
+
export declare function generateOrderInvoice(c: Context<{
|
|
25
|
+
Bindings: Bindings;
|
|
26
|
+
}>): Promise<Response>;
|
|
27
|
+
export declare function sendOrderInvoice(c: Context<{
|
|
28
|
+
Bindings: Bindings;
|
|
29
|
+
}>): Promise<Response>;
|
|
30
|
+
export declare function handleStripeWebhook(c: Context<{
|
|
31
|
+
Bindings: Bindings;
|
|
32
|
+
}>): Promise<Response>;
|
|
17
33
|
//# sourceMappingURL=public.handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/shop/handlers/public.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAA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