@hintergrund/worker 0.3.7 → 0.3.9
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/setup.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/setup.handler.js +15 -23
- package/dist/api/cms/handlers/website-repo.handler.d.ts +7 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +45 -62
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +3 -2
- package/dist/api/emails/handlers/campaigns.handler.d.ts +6 -12
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +42 -132
- package/dist/api/emails/handlers/invoice.handler.d.ts +2 -2
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/invoice.handler.js +3 -2
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +5 -9
- package/dist/api/emails/handlers/settings.handler.d.ts +5 -46
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +12 -40
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +3 -11
- package/dist/api/shop/handlers/products.handler.d.ts +1 -38
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +8 -243
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +17 -24
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +0 -10
- package/dist/lib/github.d.ts +19 -3
- package/dist/lib/github.d.ts.map +1 -1
- package/dist/lib/github.js +39 -6
- package/dist/lib/invoice.js +3 -3
- package/dist/lib/project-db.d.ts +1 -1
- package/dist/lib/project-db.d.ts.map +1 -1
- package/dist/lib/project-db.js +5 -9
- package/dist/lib/website-i18n.d.ts +1 -1
- package/dist/lib/website-i18n.d.ts.map +1 -1
- package/dist/lib/website-i18n.js +8 -11
- package/package.json +2 -2
|
@@ -3,10 +3,9 @@ import Stripe from 'stripe';
|
|
|
3
3
|
import { renderInvoice } from '../../../lib/invoice';
|
|
4
4
|
import { base64 } from '../../../lib/design';
|
|
5
5
|
import { sendEmail } from '../../../lib/email';
|
|
6
|
-
import { DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
|
|
7
6
|
import { renderEmailTemplate } from '../../../lib/email-template';
|
|
8
7
|
import { readShopCatalog, readShopSettings } from './products.handler';
|
|
9
|
-
import { readEmailTemplateData } from '../../emails/handlers/settings.handler';
|
|
8
|
+
import { readEmailTemplateData, readEmailTemplates } from '../../emails/handlers/settings.handler';
|
|
10
9
|
import { ensureSchema } from '../../../lib/project-db';
|
|
11
10
|
const EUROPEAN_STRIPE_COUNTRIES = [
|
|
12
11
|
'AL', 'AD', 'AT', 'BY', 'BE', 'BA', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE',
|
|
@@ -14,9 +13,6 @@ const EUROPEAN_STRIPE_COUNTRIES = [
|
|
|
14
13
|
'MT', 'MD', 'MC', 'ME', 'NL', 'MK', 'NO', 'PL', 'PT', 'RO', 'SM', 'RS',
|
|
15
14
|
'SK', 'SI', 'ES', 'SE', 'CH', 'UA', 'GB', 'VA'
|
|
16
15
|
];
|
|
17
|
-
function nowSeconds() {
|
|
18
|
-
return Math.floor(Date.now() / 1000);
|
|
19
|
-
}
|
|
20
16
|
function createId(prefix) {
|
|
21
17
|
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
22
18
|
}
|
|
@@ -64,7 +60,7 @@ async function updateOrder(env, order) {
|
|
|
64
60
|
SET status = ?, customer_json = ?, items_json = ?, totals_json = ?, stripe_session_id = ?,
|
|
65
61
|
stripe_payment_intent_id = ?, invoice_number = ?, invoice_sent_at = ?, metadata_json = ?, updated_at = ?
|
|
66
62
|
WHERE id = ?`)
|
|
67
|
-
.bind(order.status, JSON.stringify(order.customer), JSON.stringify(order.items), JSON.stringify(order.totals), order.stripeSessionId ?? null, order.stripePaymentIntentId ?? null, order.invoiceNumber ?? null, order.invoiceSentAt ?? null, JSON.stringify(order.metadata),
|
|
63
|
+
.bind(order.status, JSON.stringify(order.customer), JSON.stringify(order.items), JSON.stringify(order.totals), order.stripeSessionId ?? null, order.stripePaymentIntentId ?? null, order.invoiceNumber ?? null, order.invoiceSentAt ?? null, JSON.stringify(order.metadata), Date.now(), order.id)
|
|
68
64
|
.run();
|
|
69
65
|
}
|
|
70
66
|
async function getOrderById(env, id) {
|
|
@@ -119,7 +115,7 @@ function createOrder(request, items, orderPrefix) {
|
|
|
119
115
|
const rate = item.taxRate ?? 0;
|
|
120
116
|
return sum + Math.round(item.totalAmount - item.totalAmount / (1 + rate / 100));
|
|
121
117
|
}, 0);
|
|
122
|
-
const timestamp =
|
|
118
|
+
const timestamp = Date.now();
|
|
123
119
|
return {
|
|
124
120
|
id: createId('order'),
|
|
125
121
|
orderNumber: numberWithPrefix(orderPrefix),
|
|
@@ -153,11 +149,10 @@ function applyShipping(order, settings) {
|
|
|
153
149
|
}
|
|
154
150
|
export async function getPublicProducts(c) {
|
|
155
151
|
try {
|
|
156
|
-
const { catalog
|
|
152
|
+
const { catalog } = await readShopCatalog(c.env);
|
|
157
153
|
const response = {
|
|
158
154
|
products: catalog.products.filter((product) => product.active),
|
|
159
|
-
hasMore: false
|
|
160
|
-
commitSha
|
|
155
|
+
hasMore: false
|
|
161
156
|
};
|
|
162
157
|
return c.json(response);
|
|
163
158
|
}
|
|
@@ -312,7 +307,7 @@ export async function updateOrderStatus(c) {
|
|
|
312
307
|
const body = await c.req.json();
|
|
313
308
|
const previousStatus = order.status;
|
|
314
309
|
order.status = body.status;
|
|
315
|
-
order.updatedAt =
|
|
310
|
+
order.updatedAt = Date.now();
|
|
316
311
|
await updateOrder(c.env, order);
|
|
317
312
|
if (previousStatus !== 'successful' && order.status === 'successful') {
|
|
318
313
|
sendPaymentConfirmationEmail(c.env, order).catch((err) => console.error('Failed to send payment confirmation email:', err));
|
|
@@ -332,7 +327,7 @@ export async function confirmPayment(c) {
|
|
|
332
327
|
if (order.status === 'successful')
|
|
333
328
|
return c.json({ success: true, order });
|
|
334
329
|
order.status = 'successful';
|
|
335
|
-
order.updatedAt =
|
|
330
|
+
order.updatedAt = Date.now();
|
|
336
331
|
await updateOrder(c.env, order);
|
|
337
332
|
sendPaymentConfirmationEmail(c.env, order).catch((err) => console.error('Failed to send payment confirmation email:', err));
|
|
338
333
|
return c.json({ success: true, order });
|
|
@@ -359,7 +354,7 @@ function orderToInvoiceData(order) {
|
|
|
359
354
|
}
|
|
360
355
|
return {
|
|
361
356
|
invoiceNumber: order.invoiceNumber || order.orderNumber,
|
|
362
|
-
invoiceDate: new Date(order.createdAt
|
|
357
|
+
invoiceDate: new Date(order.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }),
|
|
363
358
|
customerName: order.customer.name || order.customer.email,
|
|
364
359
|
customerEmail: order.customer.email,
|
|
365
360
|
customerAddress: order.customer.address,
|
|
@@ -388,11 +383,11 @@ async function sendInvoiceEmail(env, order, bankInstructions) {
|
|
|
388
383
|
order.invoiceNumber ||= numberWithPrefix(shopSettings.invoiceNumberPrefix);
|
|
389
384
|
const invoiceData = orderToInvoiceData(order);
|
|
390
385
|
const pdfBytes = await renderInvoice(env, invoiceData);
|
|
391
|
-
const
|
|
386
|
+
const { purchase } = await readEmailTemplates(env);
|
|
392
387
|
const formattedAmount = new Intl.NumberFormat('en-US', { style: 'currency', currency: order.totals.currency.toUpperCase() }).format(order.totals.total / 100);
|
|
393
388
|
const vars = { order_number: order.orderNumber, invoice_number: order.invoiceNumber ?? '', amount: formattedAmount };
|
|
394
|
-
|
|
395
|
-
let htmlBody = applyTemplateVars(
|
|
389
|
+
const subject = applyTemplateVars(purchase.subject, vars);
|
|
390
|
+
let htmlBody = applyTemplateVars(purchase.bodyHtml, vars);
|
|
396
391
|
if (bankInstructions) {
|
|
397
392
|
const lines = [
|
|
398
393
|
`Please transfer ${new Intl.NumberFormat('en-US', { style: 'currency', currency: order.totals.currency.toUpperCase() }).format(order.totals.total / 100)} to:`,
|
|
@@ -415,23 +410,21 @@ async function sendInvoiceEmail(env, order, bankInstructions) {
|
|
|
415
410
|
html: renderEmailTemplate({ bodyHtml: htmlBody, template: settings.emailTemplate, logoDataUrl }),
|
|
416
411
|
attachments: [{ filename: `${(order.invoiceNumber ?? order.orderNumber ?? 'invoice').replace(/[^a-zA-Z0-9_-]/g, '_')}.pdf`, content: base64(pdfBytes), contentType: 'application/pdf', disposition: 'attachment' }],
|
|
417
412
|
});
|
|
418
|
-
order.invoiceSentAt =
|
|
413
|
+
order.invoiceSentAt = Date.now();
|
|
419
414
|
await updateOrder(env, order);
|
|
420
415
|
}
|
|
421
416
|
async function sendPaymentConfirmationEmail(env, order) {
|
|
422
417
|
const emailsConfig = await tryGetEmailsConfig(env);
|
|
423
418
|
if (!emailsConfig)
|
|
424
419
|
return;
|
|
425
|
-
const { settings, logoDataUrl } = await readEmailTemplateData(env);
|
|
426
|
-
const { settings: shopSettings } = await readShopSettings(env);
|
|
420
|
+
const [{ settings, logoDataUrl }, { payment_confirmed: template }] = await Promise.all([readEmailTemplateData(env), readEmailTemplates(env)]);
|
|
427
421
|
const amount = new Intl.NumberFormat('en-US', {
|
|
428
422
|
style: 'currency',
|
|
429
423
|
currency: order.totals.currency.toUpperCase()
|
|
430
424
|
}).format(order.totals.total / 100);
|
|
431
|
-
const confirmTemplate = shopSettings.emailTemplates?.paymentConfirmed;
|
|
432
425
|
const vars = { order_number: order.orderNumber, amount };
|
|
433
|
-
const subject = applyTemplateVars(
|
|
434
|
-
const html = applyTemplateVars(
|
|
426
|
+
const subject = applyTemplateVars(template.subject, vars);
|
|
427
|
+
const html = applyTemplateVars(template.bodyHtml, vars);
|
|
435
428
|
try {
|
|
436
429
|
await sendEmail(env, {
|
|
437
430
|
to: order.customer.email,
|
|
@@ -473,7 +466,7 @@ export async function sendOrderInvoice(c) {
|
|
|
473
466
|
}
|
|
474
467
|
catch (error) {
|
|
475
468
|
console.error('Failed to send invoice:', error);
|
|
476
|
-
return c.json({ success: false, error: 'Failed to send invoice' }, 500);
|
|
469
|
+
return c.json({ success: false, error: error instanceof Error ? error.message : 'Failed to send invoice' }, 500);
|
|
477
470
|
}
|
|
478
471
|
}
|
|
479
472
|
export async function handleStripeWebhook(c) {
|
|
@@ -493,7 +486,7 @@ export async function handleStripeWebhook(c) {
|
|
|
493
486
|
if (order) {
|
|
494
487
|
order.status = 'successful';
|
|
495
488
|
order.stripePaymentIntentId = typeof session.payment_intent === 'string' ? session.payment_intent : session.payment_intent?.id;
|
|
496
|
-
order.updatedAt =
|
|
489
|
+
order.updatedAt = Date.now();
|
|
497
490
|
await updateOrder(c.env, order);
|
|
498
491
|
}
|
|
499
492
|
}
|
|
@@ -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;AAiB5C,QAAA,MAAM,UAAU;cAAwB,QAAQ;yCAAK,CAAC;AAmBtD,eAAe,UAAU,CAAC"}
|
package/dist/api/shop/routes.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
import { authMiddleware } from '../../middleware/auth';
|
|
3
3
|
// Import handlers
|
|
4
|
-
import { getProducts, getProduct, createProduct, updateProduct, deleteProduct, getSettings, updateSettings } from './handlers/products.handler';
|
|
5
4
|
import { getPublicProducts, createCheckoutSession, getOrders, getAdminOrder, getPublicOrder, updateOrderStatus, confirmPayment, generateOrderInvoice, sendOrderInvoice, handleStripeWebhook } from './handlers/public.handler';
|
|
6
5
|
const shopRoutes = new Hono();
|
|
7
6
|
// Public routes (no auth required)
|
|
@@ -11,15 +10,6 @@ shopRoutes.get('/orders/:id', getPublicOrder);
|
|
|
11
10
|
shopRoutes.post('/webhook', handleStripeWebhook);
|
|
12
11
|
// Apply auth middleware to all shop admin routes
|
|
13
12
|
shopRoutes.use('/admin/*', authMiddleware);
|
|
14
|
-
// Settings
|
|
15
|
-
shopRoutes.get('/admin/settings', getSettings);
|
|
16
|
-
shopRoutes.put('/admin/settings', updateSettings);
|
|
17
|
-
// Products
|
|
18
|
-
shopRoutes.get('/admin/products', getProducts);
|
|
19
|
-
shopRoutes.get('/admin/products/:id', getProduct);
|
|
20
|
-
shopRoutes.post('/admin/products', createProduct);
|
|
21
|
-
shopRoutes.patch('/admin/products/:id', updateProduct);
|
|
22
|
-
shopRoutes.delete('/admin/products/:id', deleteProduct);
|
|
23
13
|
// Orders
|
|
24
14
|
shopRoutes.get('/admin/orders', getOrders);
|
|
25
15
|
shopRoutes.get('/admin/orders/:id', getAdminOrder);
|
package/dist/lib/github.d.ts
CHANGED
|
@@ -70,13 +70,13 @@ export declare class GitHubClient {
|
|
|
70
70
|
* Read a single file from the repository
|
|
71
71
|
* Returns null if file doesn't exist
|
|
72
72
|
*/
|
|
73
|
-
readFile(path: string): Promise<FileReadResult | null>;
|
|
73
|
+
readFile(path: string, ref?: string): Promise<FileReadResult | null>;
|
|
74
74
|
/**
|
|
75
75
|
* Read a binary file from the repository (returns raw base64 without UTF-8 decoding)
|
|
76
76
|
* Use this for images, videos, and other binary files
|
|
77
77
|
* Returns null if file doesn't exist
|
|
78
78
|
*/
|
|
79
|
-
readFileBinary(path: string, maxBytes?: number): Promise<{
|
|
79
|
+
readFileBinary(path: string, maxBytes?: number, ref?: string): Promise<{
|
|
80
80
|
content: string;
|
|
81
81
|
sha: string;
|
|
82
82
|
} | null>;
|
|
@@ -99,7 +99,7 @@ export declare class GitHubClient {
|
|
|
99
99
|
/**
|
|
100
100
|
* Read multiple files in parallel
|
|
101
101
|
*/
|
|
102
|
-
readFiles(paths: string[]): Promise<Map<string, FileReadResult | null>>;
|
|
102
|
+
readFiles(paths: string[], ref?: string): Promise<Map<string, FileReadResult | null>>;
|
|
103
103
|
/**
|
|
104
104
|
* Write a single file to the repository
|
|
105
105
|
* Creates the file if it doesn't exist, updates if it does
|
|
@@ -122,6 +122,22 @@ export declare class GitHubClient {
|
|
|
122
122
|
* List files in a directory
|
|
123
123
|
*/
|
|
124
124
|
listDirectory(path: string): Promise<string[]>;
|
|
125
|
+
/** One page of the branch history, newest first. */
|
|
126
|
+
listCommits(page?: number, perPage?: number): Promise<Array<{
|
|
127
|
+
sha: string;
|
|
128
|
+
message: string;
|
|
129
|
+
date: string;
|
|
130
|
+
}>>;
|
|
131
|
+
/** Every blob of one commit (the branch head by default), pinned to that commit's SHA. */
|
|
132
|
+
readTree(ref?: string): Promise<{
|
|
133
|
+
commitSha: string;
|
|
134
|
+
blobs: Array<{
|
|
135
|
+
path: string;
|
|
136
|
+
sha: string;
|
|
137
|
+
}>;
|
|
138
|
+
}>;
|
|
139
|
+
/** UTF-8 contents by blob SHA. Blobs are immutable, so a caller never needs one twice. */
|
|
140
|
+
readTextBlobs(shas: string[]): Promise<Map<string, string>>;
|
|
125
141
|
/**
|
|
126
142
|
* Check if commit SHA matches current branch HEAD
|
|
127
143
|
* Returns true if they match (no conflict), false if there's a conflict
|
package/dist/lib/github.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/lib/github.ts"],"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AE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtD;;OAEG;IACH,WAAW;;;;;CAOX;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAErE"}
|
package/dist/lib/github.js
CHANGED
|
@@ -86,13 +86,13 @@ export class GitHubClient {
|
|
|
86
86
|
* Read a single file from the repository
|
|
87
87
|
* Returns null if file doesn't exist
|
|
88
88
|
*/
|
|
89
|
-
async readFile(path) {
|
|
89
|
+
async readFile(path, ref = this.branch) {
|
|
90
90
|
try {
|
|
91
91
|
const response = await (await this.octokit()).rest.repos.getContent({
|
|
92
92
|
owner: this.owner,
|
|
93
93
|
repo: this.repo,
|
|
94
94
|
path,
|
|
95
|
-
ref
|
|
95
|
+
ref
|
|
96
96
|
});
|
|
97
97
|
if (Array.isArray(response.data) || !('content' in response.data)) {
|
|
98
98
|
return null;
|
|
@@ -115,13 +115,13 @@ export class GitHubClient {
|
|
|
115
115
|
* Use this for images, videos, and other binary files
|
|
116
116
|
* Returns null if file doesn't exist
|
|
117
117
|
*/
|
|
118
|
-
async readFileBinary(path, maxBytes = 10 * 1024 * 1024) {
|
|
118
|
+
async readFileBinary(path, maxBytes = 10 * 1024 * 1024, ref = this.branch) {
|
|
119
119
|
try {
|
|
120
120
|
const response = await (await this.octokit()).rest.repos.getContent({
|
|
121
121
|
owner: this.owner,
|
|
122
122
|
repo: this.repo,
|
|
123
123
|
path,
|
|
124
|
-
ref
|
|
124
|
+
ref
|
|
125
125
|
});
|
|
126
126
|
if (Array.isArray(response.data) || !('content' in response.data)) {
|
|
127
127
|
return null;
|
|
@@ -184,9 +184,9 @@ export class GitHubClient {
|
|
|
184
184
|
/**
|
|
185
185
|
* Read multiple files in parallel
|
|
186
186
|
*/
|
|
187
|
-
async readFiles(paths) {
|
|
187
|
+
async readFiles(paths, ref = this.branch) {
|
|
188
188
|
const results = await Promise.all(paths.map(async (path) => {
|
|
189
|
-
const result = await this.readFile(path);
|
|
189
|
+
const result = await this.readFile(path, ref);
|
|
190
190
|
return [path, result];
|
|
191
191
|
}));
|
|
192
192
|
return new Map(results);
|
|
@@ -332,6 +332,39 @@ export class GitHubClient {
|
|
|
332
332
|
throw error;
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
+
/** One page of the branch history, newest first. */
|
|
336
|
+
async listCommits(page = 1, perPage = 30) {
|
|
337
|
+
const response = await (await this.octokit()).rest.repos.listCommits({
|
|
338
|
+
owner: this.owner,
|
|
339
|
+
repo: this.repo,
|
|
340
|
+
sha: this.branch,
|
|
341
|
+
per_page: perPage,
|
|
342
|
+
page
|
|
343
|
+
});
|
|
344
|
+
return response.data.map((commit) => ({
|
|
345
|
+
sha: commit.sha,
|
|
346
|
+
message: commit.commit.message.split('\n')[0],
|
|
347
|
+
date: commit.commit.committer?.date ?? commit.commit.author?.date ?? ''
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
/** Every blob of one commit (the branch head by default), pinned to that commit's SHA. */
|
|
351
|
+
async readTree(ref) {
|
|
352
|
+
const commitSha = ref ?? await this.getCommitSha();
|
|
353
|
+
const tree = await (await this.octokit()).rest.git.getTree({ owner: this.owner, repo: this.repo, tree_sha: commitSha, recursive: 'true' });
|
|
354
|
+
const blobs = tree.data.tree
|
|
355
|
+
.filter((item) => item.type === 'blob' && item.path && item.sha)
|
|
356
|
+
.map((item) => ({ path: item.path, sha: item.sha }));
|
|
357
|
+
return { commitSha, blobs };
|
|
358
|
+
}
|
|
359
|
+
/** UTF-8 contents by blob SHA. Blobs are immutable, so a caller never needs one twice. */
|
|
360
|
+
async readTextBlobs(shas) {
|
|
361
|
+
const octokit = await this.octokit();
|
|
362
|
+
const entries = await Promise.all([...new Set(shas)].map(async (sha) => {
|
|
363
|
+
const blob = await octokit.rest.git.getBlob({ owner: this.owner, repo: this.repo, file_sha: sha });
|
|
364
|
+
return [sha, decodeBase64UTF8(blob.data.content.replace(/\s/g, ''))];
|
|
365
|
+
}));
|
|
366
|
+
return new Map(entries);
|
|
367
|
+
}
|
|
335
368
|
/**
|
|
336
369
|
* Check if commit SHA matches current branch HEAD
|
|
337
370
|
* Returns true if they match (no conflict), false if there's a conflict
|
package/dist/lib/invoice.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { validateDesign, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
|
|
2
2
|
import { readDesign, readInvoiceDesign, readDesignAsset } from './design';
|
|
3
|
-
import {
|
|
3
|
+
import { readBusinessDetails } from '../api/emails/handlers/settings.handler';
|
|
4
4
|
import { generateInvoicePdf } from '../api/emails/handlers/invoice.handler';
|
|
5
5
|
export async function renderInvoice(env, data, draft) {
|
|
6
6
|
const design = draft?.design ?? await readDesign(env);
|
|
7
7
|
const invoiceDesign = draft?.invoiceDesign ?? await readInvoiceDesign(env);
|
|
8
|
-
const
|
|
8
|
+
const business = await readBusinessDetails(env);
|
|
9
9
|
const [logo, bodyFont, displayFont] = await Promise.all([
|
|
10
10
|
invoiceDesign.logoPath ? draft?.assets?.logo ?? readDesignAsset(env, invoiceDesign.logoPath) : undefined,
|
|
11
11
|
design.fonts.body.embed ? draft?.assets?.bodyFont ?? readDesignAsset(env, design.fonts.body.embed) : undefined,
|
|
12
12
|
design.fonts.headings.embed ? draft?.assets?.displayFont ?? readDesignAsset(env, design.fonts.headings.embed) : undefined,
|
|
13
13
|
]);
|
|
14
|
-
return generateInvoicePdf(
|
|
14
|
+
return generateInvoicePdf(business, data, design, invoiceDesign, { logo, bodyFont, displayFont });
|
|
15
15
|
}
|
|
16
16
|
/** Authenticated, side-effect-free preview. Only presentation can be supplied. */
|
|
17
17
|
export async function previewInvoice(c) {
|
package/dist/lib/project-db.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface AdminUser {
|
|
|
10
10
|
created_at: number;
|
|
11
11
|
updated_at: number;
|
|
12
12
|
}
|
|
13
|
-
export declare const PROJECT_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS admin_users (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tpassword_hash TEXT,\n\tlogin_method TEXT NOT NULL DEFAULT 'password',\n\tinitial_admin INTEGER UNIQUE,\n\tdisabled_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS subscribers (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'subscribed', 'unsubscribed', 'bounced', 'complained')),\n\tsource TEXT NOT NULL DEFAULT 'website' CHECK(source IN ('manual', 'import', 'website')),\n\tdata_json TEXT NOT NULL DEFAULT '{}',\n\tconfirmation_token TEXT,\n\tconfirmation_sent_at INTEGER,\n\tconfirmed_at INTEGER,\n\tsubscribed_at INTEGER,\n\tunsubscribed_at INTEGER,\n\tunsubscribe_token TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS idx_subscribers_email ON subscribers(email);\nCREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);\nCREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);\n\nCREATE TABLE IF NOT EXISTS campaigns (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tname TEXT NOT NULL,\n\tsubject TEXT NOT NULL,\n\tbody_html TEXT NOT NULL,\n\
|
|
13
|
+
export declare const PROJECT_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS admin_users (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tpassword_hash TEXT,\n\tlogin_method TEXT NOT NULL DEFAULT 'password',\n\tinitial_admin INTEGER UNIQUE,\n\tdisabled_at INTEGER,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS subscribers (\n\tid TEXT NOT NULL PRIMARY KEY,\n\temail TEXT NOT NULL UNIQUE,\n\tname TEXT,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'subscribed', 'unsubscribed', 'bounced', 'complained')),\n\tsource TEXT NOT NULL DEFAULT 'website' CHECK(source IN ('manual', 'import', 'website')),\n\tdata_json TEXT NOT NULL DEFAULT '{}',\n\tconfirmation_token TEXT,\n\tconfirmation_sent_at INTEGER,\n\tconfirmed_at INTEGER,\n\tsubscribed_at INTEGER,\n\tunsubscribed_at INTEGER,\n\tunsubscribe_token TEXT,\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS idx_subscribers_email ON subscribers(email);\nCREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);\nCREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);\n\n-- Sent newsletters only: drafts are authored in the repository.\nCREATE TABLE IF NOT EXISTS campaigns (\n\tid TEXT NOT NULL PRIMARY KEY,\n\tname TEXT NOT NULL,\n\tsubject TEXT NOT NULL,\n\tbody_html TEXT NOT NULL,\n\trecipient_count INTEGER NOT NULL,\n\tsent_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_campaigns_sent_at ON campaigns(sent_at DESC);\n\nCREATE TABLE IF NOT EXISTS shop_orders (\n\tid TEXT NOT NULL PRIMARY KEY,\n\torder_number TEXT NOT NULL UNIQUE,\n\tstatus TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'approved', 'successful', 'aborted', 'failed')),\n\tpayment_method TEXT NOT NULL DEFAULT 'bank_transfer' CHECK(payment_method IN ('bank_transfer', 'stripe')),\n\tcustomer_json TEXT NOT NULL DEFAULT '{}',\n\titems_json TEXT NOT NULL DEFAULT '[]',\n\ttotals_json TEXT NOT NULL DEFAULT '{\"subtotal\":0,\"shipping\":0,\"tax\":0,\"total\":0,\"currency\":\"eur\"}',\n\tstripe_session_id TEXT,\n\tstripe_payment_intent_id TEXT,\n\tinvoice_number TEXT,\n\tinvoice_sent_at INTEGER,\n\tmetadata_json TEXT NOT NULL DEFAULT '{}',\n\tcreated_at INTEGER NOT NULL,\n\tupdated_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_shop_orders_status ON shop_orders(status);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_payment_method ON shop_orders(payment_method);\nCREATE INDEX IF NOT EXISTS idx_shop_orders_stripe_session ON shop_orders(stripe_session_id);\nCREATE UNIQUE INDEX IF NOT EXISTS idx_shop_orders_order_number ON shop_orders(order_number);\n";
|
|
14
14
|
export declare function getProjectDb(env: Bindings): D1Database;
|
|
15
15
|
export declare function ensureSchema(env: Bindings): Promise<D1Database>;
|
|
16
16
|
export declare function nowSeconds(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-db.d.ts","sourceRoot":"","sources":["../../src/lib/project-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,4EAA4E;IAC5E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EA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mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAO3F"}
|
package/dist/lib/project-db.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MAIL_SCHEMA_SQL } from './mail-schema';
|
|
2
2
|
// Full project schema — all modules in one place.
|
|
3
|
-
//
|
|
3
|
+
// The only copy of the schema: ensureSchema applies it on first use.
|
|
4
4
|
// All statements use IF NOT EXISTS so this is safe to re-run on an existing DB.
|
|
5
5
|
export const PROJECT_SCHEMA_SQL = `
|
|
6
6
|
CREATE TABLE IF NOT EXISTS admin_users (
|
|
@@ -37,21 +37,17 @@ CREATE INDEX IF NOT EXISTS idx_subscribers_status ON subscribers(status);
|
|
|
37
37
|
CREATE INDEX IF NOT EXISTS idx_subscribers_created_at ON subscribers(created_at DESC);
|
|
38
38
|
CREATE INDEX IF NOT EXISTS idx_subscribers_source ON subscribers(source);
|
|
39
39
|
|
|
40
|
+
-- Sent newsletters only: drafts are authored in the repository.
|
|
40
41
|
CREATE TABLE IF NOT EXISTS campaigns (
|
|
41
42
|
id TEXT NOT NULL PRIMARY KEY,
|
|
42
43
|
name TEXT NOT NULL,
|
|
43
44
|
subject TEXT NOT NULL,
|
|
44
45
|
body_html TEXT NOT NULL,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
scheduled_at INTEGER,
|
|
48
|
-
sent_at INTEGER,
|
|
49
|
-
created_at INTEGER NOT NULL,
|
|
50
|
-
updated_at INTEGER NOT NULL
|
|
46
|
+
recipient_count INTEGER NOT NULL,
|
|
47
|
+
sent_at INTEGER NOT NULL
|
|
51
48
|
);
|
|
52
49
|
|
|
53
|
-
CREATE INDEX IF NOT EXISTS
|
|
54
|
-
CREATE INDEX IF NOT EXISTS idx_campaigns_created_at ON campaigns(created_at DESC);
|
|
50
|
+
CREATE INDEX IF NOT EXISTS idx_campaigns_sent_at ON campaigns(sent_at DESC);
|
|
55
51
|
|
|
56
52
|
CREATE TABLE IF NOT EXISTS shop_orders (
|
|
57
53
|
id TEXT NOT NULL PRIMARY KEY,
|
|
@@ -4,7 +4,7 @@ import type { FileEntry, GitHubClient } from './github';
|
|
|
4
4
|
/** Produces a complete catalogue before the atomic Git commit; never publishes stale translations. */
|
|
5
5
|
export declare function translateWebsite(files: Map<string, FileEntry>, env: Bindings): Promise<FileEntry | null>;
|
|
6
6
|
/** Used by direct product API writes as well as the website working-copy save. */
|
|
7
|
-
export declare function translateWebsiteFiles(github: GitHubClient, input: FileEntry[], env: Bindings, revision: string): Promise<FileEntry[]>;
|
|
7
|
+
export declare function translateWebsiteFiles(github: GitHubClient, input: FileEntry[], env: Bindings, revision: string, deletions?: string[]): Promise<FileEntry[]>;
|
|
8
8
|
/** Shipped starters are English. Convert their editable source, not just their presentation. */
|
|
9
9
|
export declare function initializeWebsiteLanguages(files: FileEntry[], config: WebsiteI18nConfig, env: Bindings): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=website-i18n.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website-i18n.d.ts","sourceRoot":"","sources":["../../src/lib/website-i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiL,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACvP,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4GxD,sGAAsG;AACtG,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CA2B9G;AAED,kFAAkF;AAClF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"website-i18n.d.ts","sourceRoot":"","sources":["../../src/lib/website-i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiL,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACvP,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4GxD,sGAAsG;AACtG,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CA2B9G;AAED,kFAAkF;AAClF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAUrK;AAED,gGAAgG;AAChG,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB5H"}
|
package/dist/lib/website-i18n.js
CHANGED
|
@@ -158,20 +158,17 @@ export async function translateWebsite(files, env) {
|
|
|
158
158
|
return old?.content === content ? null : { path: I18N_CATALOG_PATH, content, encoding: 'utf8' };
|
|
159
159
|
}
|
|
160
160
|
/** Used by direct product API writes as well as the website working-copy save. */
|
|
161
|
-
export async function translateWebsiteFiles(github, input, env, revision) {
|
|
162
|
-
const
|
|
163
|
-
if (!
|
|
161
|
+
export async function translateWebsiteFiles(github, input, env, revision, deletions = []) {
|
|
162
|
+
const { blobs } = await github.readTree(revision);
|
|
163
|
+
if (!blobs.some(({ path }) => path === CONFIG_PATH) && !input.some(({ path }) => path === CONFIG_PATH))
|
|
164
164
|
return input;
|
|
165
|
-
const {
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const snapshot = await github.readFiles(paths);
|
|
169
|
-
const files = new Map();
|
|
170
|
-
for (const [path, file] of snapshot)
|
|
171
|
-
if (file)
|
|
172
|
-
files.set(path, { path, content: file.content });
|
|
165
|
+
const relevant = blobs.filter(({ path }) => isTranslatableContentPath(path) || (path.startsWith(`${SRC_ROOT}/`) && path.endsWith('.svelte')) || [CONFIG_PATH, I18N_CATALOG_PATH, I18N_RUNTIME_PATH].includes(path));
|
|
166
|
+
const contents = await github.readTextBlobs(relevant.map(({ sha }) => sha));
|
|
167
|
+
const files = new Map(relevant.map(({ path, sha }) => [path, { path, content: contents.get(sha) }]));
|
|
173
168
|
for (const file of input)
|
|
174
169
|
files.set(file.path, file);
|
|
170
|
+
for (const path of deletions)
|
|
171
|
+
files.delete(path);
|
|
175
172
|
const catalog = await translateWebsite(files, env);
|
|
176
173
|
return catalog ? [...input.filter(file => file.path !== catalog.path), catalog] : input;
|
|
177
174
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hintergrund/worker",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"postal-mime": "^3.0.0",
|
|
30
30
|
"stripe": "^17.5.0",
|
|
31
31
|
"tweetnacl": "^1.0.3",
|
|
32
|
-
"@hintergrund/runtime-contracts": "0.3.
|
|
32
|
+
"@hintergrund/runtime-contracts": "0.3.9"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsc",
|