@hintergrund/worker 0.3.17 → 0.3.19
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/appointments/admin.d.ts +171 -0
- package/dist/api/appointments/admin.d.ts.map +1 -0
- package/dist/api/appointments/admin.js +275 -0
- package/dist/api/appointments/core.d.ts +114 -0
- package/dist/api/appointments/core.d.ts.map +1 -0
- package/dist/api/appointments/core.js +208 -0
- package/dist/api/appointments/cron.d.ts +9 -0
- package/dist/api/appointments/cron.d.ts.map +1 -0
- package/dist/api/appointments/cron.js +71 -0
- package/dist/api/appointments/emails.d.ts +5 -0
- package/dist/api/appointments/emails.d.ts.map +1 -0
- package/dist/api/appointments/emails.js +53 -0
- package/dist/api/appointments/public.d.ts +104 -0
- package/dist/api/appointments/public.d.ts.map +1 -0
- package/dist/api/appointments/public.js +129 -0
- package/dist/api/appointments/routes.d.ts +7 -0
- package/dist/api/appointments/routes.d.ts.map +1 -0
- package/dist/api/appointments/routes.js +28 -0
- package/dist/api/cms/handlers/agent-provider.handler.d.ts +1 -0
- package/dist/api/cms/handlers/agent-provider.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/agent-provider.handler.js +13 -23
- package/dist/api/cms/handlers/github-secrets.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/github-secrets.handler.js +3 -18
- package/dist/api/cms/handlers/integrations.handler.d.ts +2 -2
- package/dist/api/cms/handlers/integrations.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/integrations.handler.js +5 -11
- package/dist/api/cms/handlers/runtime.handler.d.ts +6 -0
- package/dist/api/cms/handlers/runtime.handler.d.ts.map +1 -0
- package/dist/api/cms/handlers/runtime.handler.js +42 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts +2 -0
- package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -1
- package/dist/api/cms/handlers/website-repo.handler.js +31 -14
- package/dist/api/cms/routes/index.d.ts.map +1 -1
- package/dist/api/cms/routes/index.js +6 -6
- package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -6
- package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/campaigns.handler.js +127 -30
- package/dist/api/emails/handlers/public.handler.d.ts +0 -2
- package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/public.handler.js +32 -77
- package/dist/api/emails/handlers/send.handler.js +2 -2
- package/dist/api/emails/handlers/settings.handler.d.ts +1 -3
- package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/settings.handler.js +1 -6
- package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -1
- package/dist/api/emails/handlers/subscribers.handler.js +9 -0
- package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/admin.routes.js +3 -1
- package/dist/api/emails/routes/mail.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/mail.routes.js +19 -17
- package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
- package/dist/api/emails/routes/public.routes.js +1 -2
- package/dist/api/enquiries/routes.d.ts +7 -0
- package/dist/api/enquiries/routes.d.ts.map +1 -0
- package/dist/api/enquiries/routes.js +73 -0
- package/dist/api/members/handlers.d.ts +36 -0
- package/dist/api/members/handlers.d.ts.map +1 -0
- package/dist/api/members/handlers.js +322 -0
- package/dist/api/members/routes.d.ts +5 -0
- package/dist/api/members/routes.d.ts.map +1 -0
- package/dist/api/members/routes.js +20 -0
- package/dist/api/reservations/core.d.ts +25 -0
- package/dist/api/reservations/core.d.ts.map +1 -0
- package/dist/api/reservations/core.js +59 -0
- package/dist/api/reservations/mail.d.ts +7 -0
- package/dist/api/reservations/mail.d.ts.map +1 -0
- package/dist/api/reservations/mail.js +63 -0
- package/dist/api/reservations/routes.d.ts +7 -0
- package/dist/api/reservations/routes.d.ts.map +1 -0
- package/dist/api/reservations/routes.js +186 -0
- package/dist/api/shop/handlers/products.handler.d.ts +1 -1
- package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/products.handler.js +3 -3
- package/dist/api/shop/handlers/public.handler.d.ts +3 -3
- package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
- package/dist/api/shop/handlers/public.handler.js +25 -28
- package/dist/api/shop/routes.d.ts +2 -4
- package/dist/api/shop/routes.d.ts.map +1 -1
- package/dist/api/shop/routes.js +8 -11
- package/dist/api/stays/actions.d.ts +13 -0
- package/dist/api/stays/actions.d.ts.map +1 -0
- package/dist/api/stays/actions.js +28 -0
- package/dist/api/stays/admin.d.ts +209 -0
- package/dist/api/stays/admin.d.ts.map +1 -0
- package/dist/api/stays/admin.js +228 -0
- package/dist/api/stays/bookings.d.ts +113 -0
- package/dist/api/stays/bookings.d.ts.map +1 -0
- package/dist/api/stays/bookings.js +254 -0
- package/dist/api/stays/core.d.ts +214 -0
- package/dist/api/stays/core.d.ts.map +1 -0
- package/dist/api/stays/core.js +361 -0
- package/dist/api/stays/cron.d.ts +7 -0
- package/dist/api/stays/cron.d.ts.map +1 -0
- package/dist/api/stays/cron.js +56 -0
- package/dist/api/stays/mail.d.ts +8 -0
- package/dist/api/stays/mail.d.ts.map +1 -0
- package/dist/api/stays/mail.js +50 -0
- package/dist/api/stays/offers.d.ts +27 -0
- package/dist/api/stays/offers.d.ts.map +1 -0
- package/dist/api/stays/offers.js +56 -0
- package/dist/api/stays/payments.d.ts +47 -0
- package/dist/api/stays/payments.d.ts.map +1 -0
- package/dist/api/stays/payments.js +148 -0
- package/dist/api/stays/public.d.ts +207 -0
- package/dist/api/stays/public.d.ts.map +1 -0
- package/dist/api/stays/public.js +137 -0
- package/dist/api/stays/routes.d.ts +7 -0
- package/dist/api/stays/routes.d.ts.map +1 -0
- package/dist/api/stays/routes.js +39 -0
- package/dist/api/stripe/webhook.d.ts +5 -0
- package/dist/api/stripe/webhook.d.ts.map +1 -0
- package/dist/api/stripe/webhook.js +45 -0
- package/dist/api/tickets/core.d.ts +40 -0
- package/dist/api/tickets/core.d.ts.map +1 -0
- package/dist/api/tickets/core.js +115 -0
- package/dist/api/tickets/routes.d.ts +5 -0
- package/dist/api/tickets/routes.d.ts.map +1 -0
- package/dist/api/tickets/routes.js +70 -0
- package/dist/index.d.ts +16 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -27
- package/dist/lib/appointments-schema.d.ts +6 -0
- package/dist/lib/appointments-schema.d.ts.map +1 -0
- package/dist/lib/appointments-schema.js +96 -0
- package/dist/lib/config.js +4 -4
- package/dist/lib/email-template.d.ts +2 -2
- package/dist/lib/email-template.d.ts.map +1 -1
- package/dist/lib/email-template.js +3 -3
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +12 -3
- package/dist/lib/features.d.ts +13 -0
- package/dist/lib/features.d.ts.map +1 -0
- package/dist/lib/features.js +19 -0
- package/dist/lib/invoice.js +3 -3
- package/dist/lib/mail-schema.d.ts +1 -1
- package/dist/lib/mail-schema.d.ts.map +1 -1
- package/dist/lib/mail-schema.js +0 -1
- package/dist/lib/mail.d.ts +23 -3
- package/dist/lib/mail.d.ts.map +1 -1
- package/dist/lib/mail.js +69 -23
- package/dist/lib/members.d.ts +41 -0
- package/dist/lib/members.d.ts.map +1 -0
- package/dist/lib/members.js +92 -0
- 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 +67 -8
- package/dist/lib/reservations-schema.d.ts +3 -0
- package/dist/lib/reservations-schema.d.ts.map +1 -0
- package/dist/lib/reservations-schema.js +35 -0
- package/dist/lib/stays-schema.d.ts +3 -0
- package/dist/lib/stays-schema.d.ts.map +1 -0
- package/dist/lib/stays-schema.js +247 -0
- package/dist/lib/stripe.d.ts +6 -0
- package/dist/lib/stripe.d.ts.map +1 -0
- package/dist/lib/stripe.js +9 -0
- package/dist/lib/template.d.ts +2 -1
- package/dist/lib/template.d.ts.map +1 -1
- package/dist/lib/template.js +4 -82
- package/dist/lib/user-recovery.d.ts.map +1 -1
- package/dist/lib/user-recovery.js +4 -2
- package/dist/lib/website-i18n.d.ts +17 -0
- package/dist/lib/website-i18n.d.ts.map +1 -1
- package/dist/lib/website-i18n.js +90 -19
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +8 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +2 -2
- package/dist/api/cms/handlers/setup.handler.d.ts +0 -8
- package/dist/api/cms/handlers/setup.handler.d.ts.map +0 -1
- package/dist/api/cms/handlers/setup.handler.js +0 -291
- package/dist/api/emails/handlers/invoice.handler.d.ts +0 -9
- package/dist/api/emails/handlers/invoice.handler.d.ts.map +0 -1
- package/dist/api/emails/handlers/invoice.handler.js +0 -154
- package/dist/lib/brand.d.ts +0 -6
- package/dist/lib/brand.d.ts.map +0 -1
- package/dist/lib/brand.js +0 -31
- package/dist/lib/integration-health.d.ts +0 -18
- package/dist/lib/integration-health.d.ts.map +0 -1
- package/dist/lib/integration-health.js +0 -51
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
|
|
2
|
-
import fontkit from '@pdf-lib/fontkit';
|
|
3
|
-
import { validateDesign, validateInvoiceDesign } from '@hintergrund/runtime-contracts';
|
|
4
|
-
/** Same deterministic renderer for preview, downloads and email attachments. */
|
|
5
|
-
export async function generateInvoicePdf(business, data, design, invoiceDesign, assets = {}) {
|
|
6
|
-
validateDesign(design);
|
|
7
|
-
validateInvoiceDesign(invoiceDesign);
|
|
8
|
-
const pdf = await PDFDocument.create();
|
|
9
|
-
pdf.registerFontkit(fontkit);
|
|
10
|
-
const standard = (name) => name === 'Georgia' ? StandardFonts.TimesRoman : name === 'Courier New' ? StandardFonts.Courier : StandardFonts.Helvetica;
|
|
11
|
-
// PDFs embed the TTF/OTF `embed` file, never the woff2 the site downloads.
|
|
12
|
-
if ((design.fonts.body.embed && !assets.bodyFont) || (design.fonts.headings.embed && !assets.displayFont))
|
|
13
|
-
throw new Error('Missing design font asset.');
|
|
14
|
-
const font = await pdf.embedFont(assets.bodyFont ?? standard(design.fonts.body.family), { subset: true });
|
|
15
|
-
const heading = await pdf.embedFont(assets.displayFont ?? standard(design.fonts.headings.family), { subset: true });
|
|
16
|
-
const color = (hex) => rgb(...[1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16) / 255));
|
|
17
|
-
const ink = color(design.colors.text), primary = color(design.colors.primary), muted = color(design.colors.muted);
|
|
18
|
-
const [width, height] = invoiceDesign.pageSize === 'A4' ? [595.28, 841.89] : [612, 792];
|
|
19
|
-
const margin = invoiceDesign.margin, size = invoiceDesign.fontSize, line = size * invoiceDesign.lineHeight;
|
|
20
|
-
const contentWidth = width - 2 * margin;
|
|
21
|
-
let page, y;
|
|
22
|
-
const wrap = (text, maxWidth, face = font, fontSize = size) => {
|
|
23
|
-
const lines = [];
|
|
24
|
-
for (const paragraph of String(text).replace(/\r/g, '').split('\n')) {
|
|
25
|
-
let current = '';
|
|
26
|
-
for (const word of paragraph.split(/\s+/)) {
|
|
27
|
-
const candidate = current ? `${current} ${word}` : word;
|
|
28
|
-
if (face.widthOfTextAtSize(candidate, fontSize) <= maxWidth) {
|
|
29
|
-
current = candidate;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
if (current) {
|
|
33
|
-
lines.push(current);
|
|
34
|
-
current = '';
|
|
35
|
-
}
|
|
36
|
-
// Only split within a word when a single token cannot fit the column.
|
|
37
|
-
for (const char of word) {
|
|
38
|
-
if (current && face.widthOfTextAtSize(current + char, fontSize) > maxWidth) {
|
|
39
|
-
lines.push(current);
|
|
40
|
-
current = '';
|
|
41
|
-
}
|
|
42
|
-
current += char;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
lines.push(current);
|
|
46
|
-
}
|
|
47
|
-
return lines;
|
|
48
|
-
};
|
|
49
|
-
const footerLines = wrap(invoiceDesign.footerText, contentWidth, font, 8);
|
|
50
|
-
const bottom = margin + footerLines.length * 11 + 22;
|
|
51
|
-
function newPage() {
|
|
52
|
-
page = pdf.addPage([width, height]);
|
|
53
|
-
page.drawRectangle({ x: 0, y: 0, width, height, color: color(design.colors.surface) });
|
|
54
|
-
y = height - margin;
|
|
55
|
-
}
|
|
56
|
-
function ensure(space) { if (y - space < bottom)
|
|
57
|
-
newPage(); }
|
|
58
|
-
function text(value, face = font, fontSize = size, tone = ink) {
|
|
59
|
-
for (const row of wrap(value, contentWidth, face, fontSize)) {
|
|
60
|
-
ensure(fontSize * invoiceDesign.lineHeight);
|
|
61
|
-
page.drawText(row, { x: margin, y: y - fontSize, size: fontSize, font: face, color: tone });
|
|
62
|
-
y -= fontSize * invoiceDesign.lineHeight;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
newPage();
|
|
66
|
-
// The letterhead is chosen in invoice design, independent of the website.
|
|
67
|
-
if (invoiceDesign.logoPath && assets.logo) {
|
|
68
|
-
const image = /\.png$/i.test(invoiceDesign.logoPath) ? await pdf.embedPng(assets.logo) : await pdf.embedJpg(assets.logo);
|
|
69
|
-
const scale = Math.min(invoiceDesign.logoWidth / image.width, 64 / image.height);
|
|
70
|
-
const w = image.width * scale, h = image.height * scale;
|
|
71
|
-
const x = invoiceDesign.logoPosition === 'right' ? width - margin - w : invoiceDesign.logoPosition === 'center' ? (width - w) / 2 : margin;
|
|
72
|
-
page.drawImage(image, { x, y: y - h, width: w, height: h });
|
|
73
|
-
y -= h + line;
|
|
74
|
-
}
|
|
75
|
-
const locality = [business.postalCode, business.city].filter(Boolean).join(' ');
|
|
76
|
-
for (const value of [business.companyName, business.street, locality, business.country, business.email, business.phone, business.vatId && `VAT ID: ${business.vatId}`])
|
|
77
|
-
if (value)
|
|
78
|
-
text(value);
|
|
79
|
-
y -= line;
|
|
80
|
-
text('INVOICE', heading, invoiceDesign.titleSize, primary);
|
|
81
|
-
text(`Invoice: ${data.invoiceNumber}`);
|
|
82
|
-
text(`Date: ${data.invoiceDate}`);
|
|
83
|
-
if (data.dueDate)
|
|
84
|
-
text(`Due: ${data.dueDate}`);
|
|
85
|
-
y -= line;
|
|
86
|
-
text('Bill to', heading);
|
|
87
|
-
for (const value of [data.customerName, data.customerEmail, data.customerAddress])
|
|
88
|
-
if (value)
|
|
89
|
-
text(value);
|
|
90
|
-
y -= line;
|
|
91
|
-
const descriptionWidth = contentWidth * .45;
|
|
92
|
-
const qtyX = margin + contentWidth * .59, priceX = margin + contentWidth * .78, totalX = width - margin - 6;
|
|
93
|
-
function right(value, x, at) {
|
|
94
|
-
page.drawText(value, { x: x - font.widthOfTextAtSize(value, size), y: at, size, font, color: ink });
|
|
95
|
-
}
|
|
96
|
-
function tableHeader() {
|
|
97
|
-
ensure(line * 3);
|
|
98
|
-
page.drawRectangle({ x: margin, y: y - line - 10, width: contentWidth, height: line + 10, color: primary });
|
|
99
|
-
const headerColor = (() => { const c = design.colors.primary; const brightness = .299 * parseInt(c.slice(1, 3), 16) + .587 * parseInt(c.slice(3, 5), 16) + .114 * parseInt(c.slice(5, 7), 16); return brightness > 155 ? rgb(0, 0, 0) : rgb(1, 1, 1); })();
|
|
100
|
-
for (const [label, x] of [['Description', margin + 6], ['Qty', qtyX - 20], ['Price', priceX - 30], ['Total', totalX - 30]])
|
|
101
|
-
page.drawText(label, { x, y: y - size - 5, size, font, color: headerColor });
|
|
102
|
-
y -= line + 16;
|
|
103
|
-
}
|
|
104
|
-
const money = (amount) => new Intl.NumberFormat('en', { style: 'currency', currency: data.currency }).format(amount);
|
|
105
|
-
tableHeader();
|
|
106
|
-
for (const [index, item] of data.items.entries()) {
|
|
107
|
-
const lines = wrap(item.description, descriptionWidth - 12);
|
|
108
|
-
const rowHeight = lines.length * line + 6;
|
|
109
|
-
if (rowHeight < height - margin - bottom - line - 16 && y - rowHeight < bottom) {
|
|
110
|
-
newPage();
|
|
111
|
-
tableHeader();
|
|
112
|
-
}
|
|
113
|
-
for (let i = 0; i < lines.length; i++) {
|
|
114
|
-
if (y - line - 6 < bottom) {
|
|
115
|
-
newPage();
|
|
116
|
-
tableHeader();
|
|
117
|
-
}
|
|
118
|
-
if (invoiceDesign.tableStyle === 'striped' && index % 2 === 0)
|
|
119
|
-
page.drawRectangle({ x: margin, y: y - line, width: contentWidth, height: line, color: primary, opacity: .06 });
|
|
120
|
-
page.drawText(lines[i], { x: margin + 6, y: y - size, size, font, color: ink });
|
|
121
|
-
if (i === 0) {
|
|
122
|
-
right(String(item.quantity), qtyX, y - size);
|
|
123
|
-
right(money(item.unitPrice), priceX, y - size);
|
|
124
|
-
right(money(item.total), totalX, y - size);
|
|
125
|
-
}
|
|
126
|
-
y -= line;
|
|
127
|
-
}
|
|
128
|
-
y -= 6;
|
|
129
|
-
}
|
|
130
|
-
ensure(line * 5 + 16);
|
|
131
|
-
y -= 12;
|
|
132
|
-
page.drawLine({ start: { x: margin, y: y }, end: { x: width - margin, y: y }, color: muted, thickness: .5 });
|
|
133
|
-
y -= line;
|
|
134
|
-
// Display recorded monetary values, never recompute them using design/settings.
|
|
135
|
-
for (const [label, amount] of [['Subtotal', data.subtotal], ['Tax', data.tax], ['Total', data.total]]) {
|
|
136
|
-
if (amount === undefined)
|
|
137
|
-
continue;
|
|
138
|
-
text(`${label}: ${money(amount)}`);
|
|
139
|
-
}
|
|
140
|
-
if (data.paymentMethod) {
|
|
141
|
-
y -= line;
|
|
142
|
-
text(`Payment method: ${data.paymentMethod}`);
|
|
143
|
-
}
|
|
144
|
-
if (data.notes) {
|
|
145
|
-
y -= line;
|
|
146
|
-
text(data.notes);
|
|
147
|
-
}
|
|
148
|
-
for (const [index, p] of pdf.getPages().entries()) {
|
|
149
|
-
footerLines.forEach((row, i) => p.drawText(row, { x: margin, y: margin + (footerLines.length - i) * 11, size: 8, font, color: muted }));
|
|
150
|
-
p.drawText(`${index + 1} / ${pdf.getPageCount()}`, { x: width - margin - 35, y: margin - 10, size: 8, font, color: muted });
|
|
151
|
-
}
|
|
152
|
-
pdf.setTitle(`Invoice ${data.invoiceNumber}`);
|
|
153
|
-
return pdf.save();
|
|
154
|
-
}
|
package/dist/lib/brand.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Bindings } from '../index';
|
|
2
|
-
export declare function readDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").Design>;
|
|
3
|
-
export declare function readInvoiceDesign(env: Bindings): Promise<import("@hintergrund/runtime-contracts").InvoiceDesign>;
|
|
4
|
-
export declare function readDesignAsset(env: Bindings, path: string): Promise<Uint8Array>;
|
|
5
|
-
export declare function base64(bytes: Uint8Array): string;
|
|
6
|
-
//# sourceMappingURL=brand.d.ts.map
|
package/dist/lib/brand.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/lib/brand.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKzC,wBAAsB,UAAU,CAAC,GAAG,EAAE,QAAQ,4DAK7C;AACD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,mEAIpD;AACD,wBAAsB,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMtF;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIhD"}
|
package/dist/lib/brand.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DESIGN_PATH, validateDesign, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN, validateInvoiceDesign, publicAssetPath } from '@hintergrund/runtime-contracts';
|
|
2
|
-
import { createGitHubClient } from './github';
|
|
3
|
-
import { getGitHubConfig } from './config';
|
|
4
|
-
import { readJsonConfig } from './github-config';
|
|
5
|
-
export async function readDesign(env) {
|
|
6
|
-
const github = createGitHubClient(getGitHubConfig(env));
|
|
7
|
-
const file = await github.readJsonFileIfExists(DESIGN_PATH);
|
|
8
|
-
if (!file)
|
|
9
|
-
throw new Error(`Missing ${DESIGN_PATH}. Every website template ships one.`);
|
|
10
|
-
return validateDesign(file.data);
|
|
11
|
-
}
|
|
12
|
-
export async function readInvoiceDesign(env) {
|
|
13
|
-
const github = createGitHubClient(getGitHubConfig(env));
|
|
14
|
-
const { data } = await readJsonConfig(github, INVOICE_DESIGN_PATH, DEFAULT_INVOICE_DESIGN);
|
|
15
|
-
return validateInvoiceDesign(data);
|
|
16
|
-
}
|
|
17
|
-
export async function readDesignAsset(env, path) {
|
|
18
|
-
publicAssetPath(path);
|
|
19
|
-
const file = await createGitHubClient(getGitHubConfig(env)).readFileBinary(path);
|
|
20
|
-
if (!file)
|
|
21
|
-
throw new Error(`Design asset not found: ${path}`);
|
|
22
|
-
if (file.content.length > 8 * 1024 * 1024)
|
|
23
|
-
throw new Error('Design asset exceeds 6 MB.');
|
|
24
|
-
return Uint8Array.from(atob(file.content), char => char.charCodeAt(0));
|
|
25
|
-
}
|
|
26
|
-
export function base64(bytes) {
|
|
27
|
-
let result = '';
|
|
28
|
-
for (let i = 0; i < bytes.length; i += 8192)
|
|
29
|
-
result += String.fromCharCode(...bytes.subarray(i, i + 8192));
|
|
30
|
-
return btoa(result);
|
|
31
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const INTEGRATION_SECRETS: {
|
|
2
|
-
readonly stripe: "STRIPE_SECRET_KEY";
|
|
3
|
-
readonly plunk: "API_KEY";
|
|
4
|
-
readonly google: "GEMINI_API_KEY";
|
|
5
|
-
readonly deepseek: "DEEPSEEK_API_KEY";
|
|
6
|
-
};
|
|
7
|
-
export type IntegrationProvider = keyof typeof INTEGRATION_SECRETS;
|
|
8
|
-
export interface IntegrationHealth {
|
|
9
|
-
status: 'healthy' | 'warning' | 'invalid' | 'unavailable' | 'missing';
|
|
10
|
-
valid: boolean;
|
|
11
|
-
message: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function isIntegrationProvider(value: string): value is IntegrationProvider;
|
|
14
|
-
/** Read-only probes: never send mail, create a charge, or run billable inference.
|
|
15
|
-
* Provider response bodies/errors and credentials must never be returned to callers.
|
|
16
|
-
*/
|
|
17
|
-
export declare function checkIntegrationKey(provider: IntegrationProvider, rawKey: string): Promise<IntegrationHealth>;
|
|
18
|
-
//# sourceMappingURL=integration-health.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"integration-health.d.ts","sourceRoot":"","sources":["../../src/lib/integration-health.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB;;;;;CAEtB,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AACnE,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,CAAC;IACtE,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB;AACD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,mBAAmB,CAEjF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqCnH"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const INTEGRATION_SECRETS = {
|
|
2
|
-
stripe: 'STRIPE_SECRET_KEY', plunk: 'API_KEY', google: 'GEMINI_API_KEY', deepseek: 'DEEPSEEK_API_KEY',
|
|
3
|
-
};
|
|
4
|
-
export function isIntegrationProvider(value) {
|
|
5
|
-
return Object.prototype.hasOwnProperty.call(INTEGRATION_SECRETS, value);
|
|
6
|
-
}
|
|
7
|
-
/** Read-only probes: never send mail, create a charge, or run billable inference.
|
|
8
|
-
* Provider response bodies/errors and credentials must never be returned to callers.
|
|
9
|
-
*/
|
|
10
|
-
export async function checkIntegrationKey(provider, rawKey) {
|
|
11
|
-
const key = rawKey.trim();
|
|
12
|
-
if (!key || key === 'NOT_CONFIGURED')
|
|
13
|
-
return { status: 'missing', valid: false, message: 'No key is configured.' };
|
|
14
|
-
if (key.length > 4096 || /[\r\n]/.test(key))
|
|
15
|
-
return { status: 'invalid', valid: false, message: 'Invalid API key format.' };
|
|
16
|
-
const endpoints = {
|
|
17
|
-
stripe: 'https://api.stripe.com/v1/account',
|
|
18
|
-
plunk: 'https://next-api.useplunk.com/contacts?limit=1',
|
|
19
|
-
google: 'https://generativelanguage.googleapis.com/v1beta/models?pageSize=1',
|
|
20
|
-
deepseek: 'https://api.deepseek.com/models',
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
const response = await fetch(endpoints[provider], {
|
|
24
|
-
headers: provider === 'google' ? { 'x-goog-api-key': key } : { Authorization: `Bearer ${key}` },
|
|
25
|
-
signal: AbortSignal.timeout(10000), redirect: 'error',
|
|
26
|
-
});
|
|
27
|
-
if (!response.ok) {
|
|
28
|
-
await response.body?.cancel();
|
|
29
|
-
const invalid = [400, 401, 403].includes(response.status);
|
|
30
|
-
return { status: invalid ? 'invalid' : 'unavailable', valid: false, message: invalid
|
|
31
|
-
? 'The provider rejected this key or its permissions. Check the secret key and try again.'
|
|
32
|
-
: 'The provider is temporarily unavailable or rate-limiting requests. Try again later.' };
|
|
33
|
-
}
|
|
34
|
-
if (provider === 'stripe') {
|
|
35
|
-
const account = await response.json();
|
|
36
|
-
if (!account.charges_enabled || !account.payouts_enabled)
|
|
37
|
-
return {
|
|
38
|
-
status: 'warning', valid: true,
|
|
39
|
-
message: 'Key accepted. Payments or payouts are not enabled yet; finish account setup in Stripe. Webhook delivery is not tested.',
|
|
40
|
-
};
|
|
41
|
-
return { status: 'healthy', valid: true, message: 'Key accepted; Stripe API is reachable and payments/payouts are enabled. Webhook delivery is not tested.' };
|
|
42
|
-
}
|
|
43
|
-
await response.body?.cancel();
|
|
44
|
-
return { status: 'healthy', valid: true, message: provider === 'plunk'
|
|
45
|
-
? 'Secret key accepted; Plunk API is reachable. Verify your sender domain in Plunk before sending. No email was sent.'
|
|
46
|
-
: 'Key accepted; model API is reachable. Inference quota and billing are not tested.' };
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return { status: 'unavailable', valid: false, message: 'Could not reach the provider within 10 seconds. Try again.' };
|
|
50
|
-
}
|
|
51
|
-
}
|