iobroker.e-invoices 0.8.2 → 0.8.4

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 CHANGED
@@ -56,6 +56,25 @@ preview, backups and a status page. The header bar carries the tabs only — the
56
56
  "+ Neu" buttons sit where their lists are, and the status page names the app
57
57
  next to the version and the schema.
58
58
 
59
+ ### Language of the web app
60
+
61
+ The web app speaks German and English. The language is chosen in the instance
62
+ settings (`Web app language`: `auto`, `Deutsch`, `English`, tab *Server*) and the
63
+ app starts in it. The first match wins:
64
+
65
+ 1. `?lang=de` / `?lang=en` in the address bar (remembered on that device),
66
+ 2. the choice remembered on that device,
67
+ 3. the instance setting — `auto` means "ask the browser",
68
+ 4. the language of the browser (German or English),
69
+ 5. English.
70
+
71
+ The login page already speaks the language of the instance: `GET /api/health`
72
+ (the one open route) carries the setting as `pwaLanguage`. What is **document
73
+ content** stays German whatever the screen language is: the invoice and offer
74
+ PDFs, the XML, the document titles (`Rechnung`, `Angebot`, …), the payment-term
75
+ presets and the text of the customer mail. Only their labels in the dropdowns
76
+ follow the language of the page.
77
+
59
78
  ### Attachments (Anlagen)
60
79
 
61
80
  A draft can carry up to 10 files (PDF, PNG or JPEG, 5 MB each) — delivery
@@ -170,7 +189,11 @@ preview, backups, restore). With an API token configured, every route except
170
189
 
171
190
  - **Token:** set `authToken` in the instance configuration. Every API route except
172
191
  `/api/health` then requires `Authorization: Bearer <token>`; without a token the
173
- API trusts every client that can reach the port.
192
+ API trusts every client that can reach the port. In that case it only answers
193
+ requests whose host name is an IP address or `localhost` (so a web page cannot
194
+ steer your browser to the adapter by DNS rebinding) and refuses writes that carry a
195
+ foreign `Origin`; reach the PWA by IP address, or set a token to use a host name.
196
+ Use a long random token (the adapter warns below 16 characters).
174
197
  - **Bind address:** `bind` defaults to `127.0.0.1`, so only the host running the
175
198
  adapter can reach the API. An unauthenticated bind to another interface is
176
199
  logged as a warning on startup — use a token in that case.
@@ -183,6 +206,10 @@ preview, backups, restore). With an API token configured, every route except
183
206
  `X-Forwarded-*` headers are not trusted (`trust proxy` disabled) — the adapter
184
207
  is meant to be reached directly; put it behind a reverse proxy only with HTTPS
185
208
  and a token.
209
+ - **Restore safety:** before a restore replaces the database, the current state is
210
+ written to `backups/e-invoices-prerestore-<time>.zip`; if that fails, nothing is
211
+ restored. Number counters are never lowered, and every restore is appended to
212
+ `backups/restore-log.jsonl`.
186
213
  - **Restore limits:** a backup ZIP may be at most 512 MB and expand to at most
187
214
  1 GB (`dump.json` at most 256 MB); a crafted archive is rejected before it is
188
215
  unpacked. Entry paths, per-file checksums and the manifest are verified.
@@ -254,7 +281,48 @@ validation and hybrid embedding, `pdfkit`, `exceljs`, `jszip`,
254
281
  Placeholder for the next version (at the beginning of the line):
255
282
  ### **WORK IN PROGRESS**
256
283
  -->
257
- ### **WORK IN PROGRESS**
284
+ ### 0.8.4 (2026-10-02)
285
+
286
+ * (alex) The toolbar of the invoice and offer lists lays out as a grid now: the filters share the first line in equal parts, the search takes the free width of the second line and the buttons keep their size.
287
+ * (alex) The web app speaks English now (R7.2): the instance setting `Web app language`
288
+ (`auto`, `Deutsch`, `English`) decides the start language, `?lang=de|en` overrides it on a
289
+ device, `auto` follows the browser, and the login page already uses the language of the
290
+ instance (`/api/health` carries `pwaLanguage`). The German sentence is the key of the
291
+ translation, so a missing English entry shows German instead of a hole; a test keeps
292
+ both languages in step. PDFs, XML, document titles and payment-term presets are document
293
+ content and stay German. The status badges of the lists read `Entwurf` / `ausgestellt` /
294
+ `storniert` (German) or `draft` / `issued` / `cancelled` (English) instead of the raw
295
+ API words, and the wizard names the invoice number format `JJJJ-EE-LLL` like the docs.
296
+
297
+ ### 0.8.3 (2026-10-02)
298
+
299
+ * (alex) The toolbar of the invoice and offer lists sits on two lines now: the filters above, the search and the buttons below, so it no longer wraps into a ragged shape on narrow screens.
300
+ * (alex) Three safeguards from the code review of 2 October 2026:
301
+ **Re-render** never overwrites an archive any more — every run keeps its own
302
+ `<number>.orig-<n>.pdf`, so the delivered original stays retrievable however often the
303
+ sight PDF is rendered again — and it embeds the XML as issued instead of generating it
304
+ anew, so database, `.xml` file and the XML inside the PDF cannot drift apart.
305
+ **Without an API token** the API now accepts only IP addresses and `localhost` as host
306
+ name and refuses cross-origin writes (DNS rebinding, CSRF); with a token nothing
307
+ changes. **Restore** saves the current state as `backups/e-invoices-prerestore-<time>.zip`
308
+ first (no safety copy, no restore), never moves a number counter backwards — an
309
+ invoice number is not issued twice after restoring an older backup — and appends
310
+ every restore to `backups/restore-log.jsonl`.
311
+ * (alex) The web app sources are linted now (R5.3): `src-www/src/**/*.ts` runs through the
312
+ same ESLint set as the adapter, with the browser globals and the `src-www` tsconfig, so
313
+ the PWA is no longer the one corner of the repository that no rule looks at. The first
314
+ run paid for itself: the wizard read its settings object before declaring it (the same
315
+ class of temporal-dead-zone bug as the wizard defect of September 2026 — the
316
+ declaration now sits above its use), the customer-number button printed
317
+ "[object Object] vergeben." instead of the count, and the two identical `FileReader`
318
+ copies in the backup and template views became one checked helper (`fileToBase64`),
319
+ which no longer turns a missing string into `[object ArrayBuffer]`. Only formatting
320
+ changed beyond that (Prettier, braces). `npm run lint` covers the PWA: 0 errors,
321
+ remaining warnings are JSDoc wishes, not defects.
322
+ * (alex) The invoice and offer lists lay their controls on two lines: the filters
323
+ (status, sort, sent) share the first line and the search sits on the second next
324
+ to the buttons ("+ Neu", Excel, CSV, DATEV, "Ausstellen"). One single row had
325
+ grown too crowded and wrapped into a ragged shape on a narrow screen.
258
326
 
259
327
  ### 0.8.2 (2026-10-01)
260
328
  * (alex) The header bar carries the tabs and nothing else now: the "+ Neu" button
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "USt-IdNr.",
33
33
  "Website": "Webseite",
34
34
  "Dunning check interval in hours": "Mahnintervall in Stunden",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = aus. Der Adapter zählt überfällige Rechnungen nur in info.overdue*, er versendet selbst keine Mails."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = aus. Der Adapter zählt überfällige Rechnungen nur in info.overdue*, er versendet selbst keine Mails.",
36
+ "Web app language": "Sprache der Web-App",
37
+ "auto = language of the browser; German and English are available": "auto = Sprache des Browsers; Deutsch und Englisch stehen zur Verfügung"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "VAT ID (USt-IdNr.)",
33
33
  "Website": "Website",
34
34
  "Dunning check interval in hours": "Dunning check interval in hours",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.",
36
+ "Web app language": "Web app language",
37
+ "auto = language of the browser; German and English are available": "auto = language of the browser; German and English are available"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "NIF/IVA (USt-IdNr.)",
33
33
  "Website": "Sitio web",
34
34
  "Dunning check interval in hours": "Intervalo de cobro en horas",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = desactivado. El adaptador solo cuenta las facturas vencidas en info.overdue*, no envía correos por sí mismo."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = desactivado. El adaptador solo cuenta las facturas vencidas en info.overdue*, no envía correos por sí mismo.",
36
+ "Web app language": "Idioma de la aplicación web",
37
+ "auto = language of the browser; German and English are available": "auto = idioma del navegador; alemán e inglés disponibles"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "N° de TVA",
33
33
  "Website": "Site web",
34
34
  "Dunning check interval in hours": "Intervalle de relance en heures",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = désactivé. L\u0027adaptateur ne compte que les factures échues dans info.overdue*, il n\u0027envoie aucun e-mail lui-même."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = désactivé. L\u0027adaptateur ne compte que les factures échues dans info.overdue*, il n\u0027envoie aucun e-mail lui-même.",
36
+ "Web app language": "Langue de l'application web",
37
+ "auto = language of the browser; German and English are available": "auto = langue du navigateur ; allemand et anglais disponibles"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "P. IVA",
33
33
  "Website": "Sito web",
34
34
  "Dunning check interval in hours": "Intervallo di sollecitazione in ore",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = disattivato. L\u0027adattatore conta solo le fatture scadute in info.overdue*, non invia email per conto proprio."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = disattivato. L\u0027adattatore conta solo le fatture scadute in info.overdue*, non invia email per conto proprio.",
36
+ "Web app language": "Lingua dell'app web",
37
+ "auto = language of the browser; German and English are available": "auto = lingua del browser; tedesco e inglese disponibili"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "Btw-identificatienummer",
33
33
  "Website": "Website",
34
34
  "Dunning check interval in hours": "Herinneringsinterval in uren",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = uit. De adapter telt alleen vervallen facturen in info.overdue*, hij verzendt zelf geen e-mails."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = uit. De adapter telt alleen vervallen facturen in info.overdue*, hij verzendt zelf geen e-mails.",
36
+ "Web app language": "Taal van de web-app",
37
+ "auto = language of the browser; German and English are available": "auto = taal van de browser; Duits en Engels beschikbaar"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "NIP (VAT)",
33
33
  "Website": "Strona internetowa",
34
34
  "Dunning check interval in hours": "Interwał przypomnień w godzinach",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = wyłączone. Adapter liczy tylko zaległe faktury w info.overdue*, sam nie wysyła e-maili."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = wyłączone. Adapter liczy tylko zaległe faktury w info.overdue*, sam nie wysyła e-maili.",
36
+ "Web app language": "Język aplikacji webowej",
37
+ "auto = language of the browser; German and English are available": "auto = język przeglądarki; dostępne niemiecki i angielski"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "NIF / IVA",
33
33
  "Website": "Site web",
34
34
  "Dunning check interval in hours": "Intervalo de cobrança em horas",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = desligado. O adaptador apenas conta faturas vencidas em info.overdue*, não envia e-mails por si próprio."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = desligado. O adaptador apenas conta faturas vencidas em info.overdue*, não envia e-mails por si próprio.",
36
+ "Web app language": "Idioma da aplicação web",
37
+ "auto = language of the browser; German and English are available": "auto = idioma do navegador; alemão e inglês disponíveis"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "НДС-номер",
33
33
  "Website": "Веб-сайт",
34
34
  "Dunning check interval in hours": "Интервал напоминаний в часах",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = выключено. Адаптер только считает просроченные счета в info.overdue*, сам письма не отправляет."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = выключено. Адаптер только считает просроченные счета в info.overdue*, сам письма не отправляет.",
36
+ "Web app language": "Язык веб-приложения",
37
+ "auto = language of the browser; German and English are available": "auto = язык браузера; доступны немецкий и английский"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "Номер ПДВ",
33
33
  "Website": "Вебсайт",
34
34
  "Dunning check interval in hours": "Інтервал нагадувань у годинах",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = вимкнено. Адаптер лише рахує прострочені рахунки в info.overdue*, сам листа не надсилає."
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = вимкнено. Адаптер лише рахує прострочені рахунки в info.overdue*, сам листа не надсилає.",
36
+ "Web app language": "Мова веб-застосунку",
37
+ "auto = language of the browser; German and English are available": "auto = мова браузера; доступні німецька та англійська"
36
38
  }
@@ -32,5 +32,7 @@
32
32
  "VAT ID (USt-IdNr.)": "增值税号",
33
33
  "Website": "网站",
34
34
  "Dunning check interval in hours": "催款检查间隔(小时)",
35
- "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = 关闭。适配器只统计逾期发票到 info.overdue*,不会自行发送邮件。"
35
+ "0 = off. The adapter only counts overdue invoices into info.overdue*, it never sends mails by itself.": "0 = 关闭。适配器只统计逾期发票到 info.overdue*,不会自行发送邮件。",
36
+ "Web app language": "网页应用语言",
37
+ "auto = language of the browser; German and English are available": "auto = 浏览器语言;提供德语和英语"
36
38
  }
@@ -67,6 +67,22 @@
67
67
  "lg": 4,
68
68
  "xl": 4
69
69
  },
70
+ "pwaLanguage": {
71
+ "type": "select",
72
+ "label": "Web app language",
73
+ "help": "auto = language of the browser; German and English are available",
74
+ "options": [
75
+ { "label": "auto", "value": "auto" },
76
+ { "label": "Deutsch", "value": "de" },
77
+ { "label": "English", "value": "en" }
78
+ ],
79
+ "newLine": true,
80
+ "xs": 12,
81
+ "sm": 12,
82
+ "md": 6,
83
+ "lg": 4,
84
+ "xl": 4
85
+ },
70
86
  "authToken": {
71
87
  "type": "password",
72
88
  "label": "API token (optional)",
@@ -36,6 +36,7 @@ __export(api_server_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(api_server_exports);
38
38
  var import_node_crypto = require("node:crypto");
39
+ var import_node_net = require("node:net");
39
40
  var import_express = __toESM(require("express"));
40
41
  var import_node_fs = require("node:fs");
41
42
  var import_node_path = require("node:path");
@@ -204,27 +205,61 @@ async function storeValidationReport(db, storage, log, invoice, result) {
204
205
  return null;
205
206
  }
206
207
  }
208
+ function hostNameOf(host) {
209
+ const trimmed = host.trim().toLowerCase();
210
+ if (trimmed.startsWith("[")) {
211
+ return trimmed.slice(1, trimmed.indexOf("]"));
212
+ }
213
+ return trimmed.split(":")[0];
214
+ }
215
+ function untrustedRequestReason(req) {
216
+ var _a;
217
+ const host = (_a = req.headers.host) != null ? _a : "";
218
+ const name = hostNameOf(host);
219
+ if (!name || (0, import_node_net.isIP)(name) === 0 && name !== "localhost" && !name.endsWith(".localhost")) {
220
+ return "Host name not allowed without an API token - open the PWA by IP address or set an API token";
221
+ }
222
+ if (!["GET", "HEAD", "OPTIONS"].includes(req.method)) {
223
+ const origin = req.headers.origin;
224
+ if (origin !== void 0) {
225
+ let originHost = "";
226
+ try {
227
+ originHost = new URL(origin).host.toLowerCase();
228
+ } catch {
229
+ }
230
+ if (originHost !== host.trim().toLowerCase()) {
231
+ return "Cross-origin request refused";
232
+ }
233
+ }
234
+ if (req.headers["sec-fetch-site"] === "cross-site") {
235
+ return "Cross-site request refused";
236
+ }
237
+ }
238
+ return void 0;
239
+ }
207
240
  function secretEquals(provided, expected) {
208
241
  const a = (0, import_node_crypto.createHash)("sha256").update(provided, "utf8").digest();
209
242
  const b = (0, import_node_crypto.createHash)("sha256").update(expected, "utf8").digest();
210
243
  return (0, import_node_crypto.timingSafeEqual)(a, b);
211
244
  }
212
245
  function createApiServer(deps) {
213
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
246
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
214
247
  const { db, storage, log, version, authToken } = deps;
215
248
  const settings = {
216
249
  defaultVatRate: import_invoice_model.ALLOWED_VAT_RATES.includes(Number((_a = deps.settings) == null ? void 0 : _a.defaultVatRate)) ? Number((_b = deps.settings) == null ? void 0 : _b.defaultVatRate) : 19,
217
250
  defaultPaymentTerms: (_e = (_d = (_c = deps.settings) == null ? void 0 : _c.defaultPaymentTerms) == null ? void 0 : _d.trim()) != null ? _e : "",
218
- numberFormat: ((_g = (_f = deps.settings) == null ? void 0 : _f.numberFormat) == null ? void 0 : _g.trim()) || import_invoice_model.DEFAULT_NUMBER_FORMAT,
251
+ // only languages the web app really ships; anything else means "decide in the browser"
252
+ pwaLanguage: ["de", "en"].includes(String((_f = deps.settings) == null ? void 0 : _f.pwaLanguage)) ? String((_g = deps.settings) == null ? void 0 : _g.pwaLanguage) : "auto",
253
+ numberFormat: ((_i = (_h = deps.settings) == null ? void 0 : _h.numberFormat) == null ? void 0 : _i.trim()) || import_invoice_model.DEFAULT_NUMBER_FORMAT,
219
254
  // R8: quotations number in their own circle, so the PWA shows the
220
255
  // matching format next to the invoice one.
221
- quoteNumberFormat: ((_i = (_h = deps.settings) == null ? void 0 : _h.quoteNumberFormat) == null ? void 0 : _i.trim()) || import_invoice_model.DEFAULT_QUOTE_NUMBER_FORMAT,
222
- storageMount: (_l = (_k = (_j = deps.settings) == null ? void 0 : _j.storageMount) == null ? void 0 : _k.trim()) != null ? _l : "",
223
- backupIntervalMinutes: Math.max(0, Math.round(Number((_m = deps.settings) == null ? void 0 : _m.backupIntervalMinutes) || 0))
256
+ quoteNumberFormat: ((_k = (_j = deps.settings) == null ? void 0 : _j.quoteNumberFormat) == null ? void 0 : _k.trim()) || import_invoice_model.DEFAULT_QUOTE_NUMBER_FORMAT,
257
+ storageMount: (_n = (_m = (_l = deps.settings) == null ? void 0 : _l.storageMount) == null ? void 0 : _m.trim()) != null ? _n : "",
258
+ backupIntervalMinutes: Math.max(0, Math.round(Number((_o = deps.settings) == null ? void 0 : _o.backupIntervalMinutes) || 0))
224
259
  };
225
260
  const limits = {
226
- api: Math.max(1, Math.round((_o = (_n = deps.limits) == null ? void 0 : _n.api) != null ? _o : 600)),
227
- restore: Math.max(1, Math.round((_q = (_p = deps.limits) == null ? void 0 : _p.restore) != null ? _q : 10))
261
+ api: Math.max(1, Math.round((_q = (_p = deps.limits) == null ? void 0 : _p.api) != null ? _q : 600)),
262
+ restore: Math.max(1, Math.round((_s = (_r = deps.limits) == null ? void 0 : _r.restore) != null ? _s : 10))
228
263
  };
229
264
  const app = (0, import_express.default)();
230
265
  app.disable("x-powered-by");
@@ -279,6 +314,18 @@ function createApiServer(deps) {
279
314
  res.set("Pragma", "no-cache");
280
315
  next();
281
316
  });
317
+ if (!authToken) {
318
+ app.use("/api", (req, res, next) => {
319
+ var _a2;
320
+ const reason = untrustedRequestReason(req);
321
+ if (reason) {
322
+ (_a2 = log.warn) == null ? void 0 : _a2.call(log, `Request refused: ${req.method} ${req.path} (${reason})`);
323
+ res.status(403).json({ error: reason });
324
+ return;
325
+ }
326
+ next();
327
+ });
328
+ }
282
329
  if (authToken) {
283
330
  app.use("/api", (req, res, next) => {
284
331
  if (req.path === "/health") {
@@ -303,7 +350,13 @@ function createApiServer(deps) {
303
350
  }
304
351
  };
305
352
  app.get("/api/health", (_req, res) => {
306
- res.json({ status: "ok", version, schemaVersion: db.currentVersion(), counts: db.countByStatus() });
353
+ res.json({
354
+ status: "ok",
355
+ version,
356
+ schemaVersion: db.currentVersion(),
357
+ counts: db.countByStatus(),
358
+ pwaLanguage: settings.pwaLanguage
359
+ });
307
360
  });
308
361
  app.get("/api/settings", (_req, res) => {
309
362
  res.json(settings);
@@ -1195,7 +1248,9 @@ ${(0, import_csv.renderDatevRows)(filteredInvoices(db, req.query, "invoice"))}`)
1195
1248
  return;
1196
1249
  }
1197
1250
  try {
1198
- res.json(await (0, import_backup.restoreBackup)(db, storage, data, log));
1251
+ res.json(
1252
+ await (0, import_backup.restoreBackup)(db, storage, data, log, void 0, { adapterVersion: version, source: "api" })
1253
+ );
1199
1254
  } catch (error) {
1200
1255
  res.status(400).json({ error: error.message });
1201
1256
  }