@formfeed/devkit 0.3.11 → 0.3.12

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/index.cjs CHANGED
@@ -26,10 +26,12 @@ __export(index_exports, {
26
26
  collectPartials: () => collectPartials,
27
27
  contentHash: () => contentHash,
28
28
  contentTypeFor: () => contentTypeFor,
29
+ declaredEinvoice: () => declaredEinvoice,
29
30
  defaultData: () => defaultData,
30
31
  defaultProjectConfig: () => defaultProjectConfig,
31
32
  defaultTypesFile: () => defaultTypesFile,
32
33
  diagnose: () => diagnose,
34
+ diagnoseEinvoice: () => diagnoseEinvoice,
33
35
  findProject: () => findProject,
34
36
  generateTypes: () => generateTypes,
35
37
  htmlSnapshot: () => htmlSnapshot,
@@ -37,6 +39,7 @@ __export(index_exports, {
37
39
  listLocalFiles: () => listLocalFiles,
38
40
  listTemplateSlugs: () => listTemplateSlugs,
39
41
  loadProject: () => loadProject,
42
+ localEinvoiceXml: () => localEinvoiceXml,
40
43
  localFilePath: () => localFilePath,
41
44
  localTypeSource: () => localTypeSource,
42
45
  officeSnapshot: () => officeSnapshot,
@@ -809,10 +812,103 @@ function previewDocument(tpl, rendered, mode, pagedScriptUrl) {
809
812
  return mode === "paged" && kind === "pdf" ? (0, import_engine4.pagedDocument)(draft, { pagedScriptUrl }) : (0, import_engine4.flowDocument)(draft);
810
813
  }
811
814
 
812
- // packages/devkit/src/lib/files.ts
813
- var import_node_crypto2 = require("node:crypto");
815
+ // packages/devkit/src/lib/einvoice.ts
814
816
  var import_node_fs4 = require("node:fs");
815
817
  var import_node_path4 = require("node:path");
818
+ var import_engine5 = require("@formfeed/engine");
819
+ function declaredEinvoice(tpl, override) {
820
+ const resolved = (0, import_engine5.resolveEinvoiceOptions)(tpl.settings.einvoice, override);
821
+ if (!resolved.ok)
822
+ throw new DevkitError(
823
+ `${tpl.slug}: e-invoice ${resolved.field} "${resolved.value}": ${resolved.reason}`,
824
+ "validation"
825
+ );
826
+ return resolved.options;
827
+ }
828
+ var nowhere2 = { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } };
829
+ function diagnoseEinvoice(tpl) {
830
+ let options;
831
+ try {
832
+ options = declaredEinvoice(tpl);
833
+ } catch (e) {
834
+ return [
835
+ {
836
+ dataSet: "",
837
+ file: "settings.json",
838
+ diagnostics: [
839
+ {
840
+ severity: "error",
841
+ code: "einvoice-profile",
842
+ message: e instanceof Error ? e.message : String(e),
843
+ range: nowhere2
844
+ }
845
+ ]
846
+ }
847
+ ];
848
+ }
849
+ if (!options) return [];
850
+ if (tpl.meta.kind === "image")
851
+ return [
852
+ {
853
+ dataSet: "",
854
+ file: "settings.json",
855
+ diagnostics: [
856
+ {
857
+ severity: "warning",
858
+ code: "einvoice-image",
859
+ message: "settings.json declares an e-invoice, which an image template never produces: an e-invoice is a PDF",
860
+ range: nowhere2
861
+ }
862
+ ]
863
+ }
864
+ ];
865
+ const out = [];
866
+ for (const [name, data] of Object.entries(tpl.dataSets)) {
867
+ const result = (0, import_engine5.einvoiceXml)(data, options);
868
+ if (result.ok) continue;
869
+ const file = `data/${name}.json`;
870
+ const path = (0, import_node_path4.join)(tpl.dir, "data", `${name}.json`);
871
+ const text2 = (0, import_node_fs4.existsSync)(path) ? (0, import_node_fs4.readFileSync)(path, "utf8") : null;
872
+ out.push({
873
+ dataSet: name,
874
+ file,
875
+ diagnostics: result.problems.map((problem) => {
876
+ const at = text2 ? (0, import_engine5.locateJsonPath)(text2, [
877
+ import_engine5.INVOICE_DATA_KEY,
878
+ ...(0, import_engine5.invoicePathSegments)(problem.path)
879
+ ]) : null;
880
+ const start = at ? { line: at.line, column: at.column } : nowhere2.start;
881
+ return {
882
+ severity: "error",
883
+ code: `einvoice-${problem.code.replace(/_/g, "-")}`,
884
+ message: problem.message,
885
+ range: { start, end: start }
886
+ };
887
+ })
888
+ });
889
+ }
890
+ return out;
891
+ }
892
+ function localEinvoiceXml(tpl, data, override) {
893
+ const options = declaredEinvoice(tpl, override ?? {});
894
+ if (!options)
895
+ throw new DevkitError(`${tpl.slug} declares no e-invoice`, "validation");
896
+ const result = (0, import_engine5.einvoiceXml)(data, options);
897
+ if (!result.ok)
898
+ throw new DevkitError(
899
+ [
900
+ `${tpl.slug}: the _invoice block does not make an e-invoice`,
901
+ ...result.problems.map((problem) => ` ${problem.message}`)
902
+ ].join("\n"),
903
+ "validation"
904
+ );
905
+ return { xml: result.xml, invoice: result.invoice, options };
906
+ }
907
+
908
+ // packages/devkit/src/lib/files.ts
909
+ var import_node_crypto2 = require("node:crypto");
910
+ var import_node_fs5 = require("node:fs");
911
+ var import_node_path5 = require("node:path");
816
912
 
817
913
  // packages/api-types/src/lib/assets.ts
818
914
  var SEGMENT = "[A-Za-z0-9][A-Za-z0-9._-]*";
@@ -844,25 +940,25 @@ function sha256File(bytes) {
844
940
  }
845
941
  function listLocalFiles(project) {
846
942
  const listing = { files: [], skipped: [] };
847
- if (!(0, import_node_fs4.existsSync)(project.filesDir)) return listing;
943
+ if (!(0, import_node_fs5.existsSync)(project.filesDir)) return listing;
848
944
  const walk2 = (dir) => {
849
- for (const entry of (0, import_node_fs4.readdirSync)(dir, { withFileTypes: true })) {
945
+ for (const entry of (0, import_node_fs5.readdirSync)(dir, { withFileTypes: true })) {
850
946
  if (entry.name.startsWith(".")) continue;
851
- const path = (0, import_node_path4.join)(dir, entry.name);
947
+ const path = (0, import_node_path5.join)(dir, entry.name);
852
948
  if (entry.isDirectory()) {
853
949
  walk2(path);
854
950
  continue;
855
951
  }
856
952
  if (!entry.isFile()) continue;
857
- const name = (0, import_node_path4.relative)(project.filesDir, path).split(import_node_path4.sep).join("/");
858
- const size = (0, import_node_fs4.statSync)(path).size;
953
+ const name = (0, import_node_path5.relative)(project.filesDir, path).split(import_node_path5.sep).join("/");
954
+ const size = (0, import_node_fs5.statSync)(path).size;
859
955
  const contentType = contentTypeFor(name);
860
956
  const reason = !isAssetName(name) ? "the name has characters a library name cannot have (letters, digits, dot, dash, underscore)" : !contentType ? "not an image or a PDF" : size === 0 ? "empty" : size > ASSET_MAX_BYTES ? `larger than ${ASSET_MAX_BYTES / 1024 / 1024} MB` : null;
861
957
  if (reason) {
862
958
  listing.skipped.push({ path, reason });
863
959
  continue;
864
960
  }
865
- const bytes = (0, import_node_fs4.readFileSync)(path);
961
+ const bytes = (0, import_node_fs5.readFileSync)(path);
866
962
  listing.files.push({ name, path, bytes: size, sha256: sha256File(bytes), contentType });
867
963
  }
868
964
  };
@@ -872,14 +968,14 @@ function listLocalFiles(project) {
872
968
  }
873
969
  function localFilePath(project, name) {
874
970
  if (!isAssetName(name)) throw new DevkitError(`"${name}" is not a library file name`);
875
- const path = (0, import_node_path4.resolve)(project.filesDir, ...name.split("/"));
876
- if (!path.startsWith((0, import_node_path4.resolve)(project.filesDir) + import_node_path4.sep)) throw new DevkitError(`"${name}" is not inside the files folder`);
971
+ const path = (0, import_node_path5.resolve)(project.filesDir, ...name.split("/"));
972
+ if (!path.startsWith((0, import_node_path5.resolve)(project.filesDir) + import_node_path5.sep)) throw new DevkitError(`"${name}" is not inside the files folder`);
877
973
  return path;
878
974
  }
879
975
  function writeLocalFile(project, name, bytes) {
880
976
  const path = localFilePath(project, name);
881
- (0, import_node_fs4.mkdirSync)((0, import_node_path4.dirname)(path), { recursive: true });
882
- (0, import_node_fs4.writeFileSync)(path, bytes);
977
+ (0, import_node_fs5.mkdirSync)((0, import_node_path5.dirname)(path), { recursive: true });
978
+ (0, import_node_fs5.writeFileSync)(path, bytes);
883
979
  return path;
884
980
  }
885
981
 
@@ -947,7 +1043,7 @@ function isRecord(value) {
947
1043
  }
948
1044
 
949
1045
  // packages/devkit/src/lib/types/index.ts
950
- var import_engine5 = require("@formfeed/engine");
1046
+ var import_engine6 = require("@formfeed/engine");
951
1047
 
952
1048
  // packages/devkit/src/lib/types/model.ts
953
1049
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1435,7 +1531,7 @@ function localTypeSource(tpl) {
1435
1531
  const sets = Object.values(tpl.dataSets);
1436
1532
  return {
1437
1533
  slug: tpl.slug,
1438
- schema: (0, import_engine5.inferSchemaFromDataSets)(sets.length ? sets : [{}]),
1534
+ schema: (0, import_engine6.inferSchemaFromDataSets)(sets.length ? sets : [{}]),
1439
1535
  origin: "inferred"
1440
1536
  };
1441
1537
  }
@@ -1447,10 +1543,12 @@ function localTypeSource(tpl) {
1447
1543
  collectPartials,
1448
1544
  contentHash,
1449
1545
  contentTypeFor,
1546
+ declaredEinvoice,
1450
1547
  defaultData,
1451
1548
  defaultProjectConfig,
1452
1549
  defaultTypesFile,
1453
1550
  diagnose,
1551
+ diagnoseEinvoice,
1454
1552
  findProject,
1455
1553
  generateTypes,
1456
1554
  htmlSnapshot,
@@ -1458,6 +1556,7 @@ function localTypeSource(tpl) {
1458
1556
  listLocalFiles,
1459
1557
  listTemplateSlugs,
1460
1558
  loadProject,
1559
+ localEinvoiceXml,
1461
1560
  localFilePath,
1462
1561
  localTypeSource,
1463
1562
  officeSnapshot,
package/index.js CHANGED
@@ -760,10 +760,109 @@ function previewDocument(tpl, rendered, mode, pagedScriptUrl) {
760
760
  return mode === "paged" && kind === "pdf" ? pagedDocument(draft, { pagedScriptUrl }) : flowDocument(draft);
761
761
  }
762
762
 
763
+ // packages/devkit/src/lib/einvoice.ts
764
+ import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
765
+ import { join as join4 } from "node:path";
766
+ import {
767
+ INVOICE_DATA_KEY,
768
+ einvoiceXml,
769
+ invoicePathSegments,
770
+ locateJsonPath,
771
+ resolveEinvoiceOptions
772
+ } from "@formfeed/engine";
773
+ function declaredEinvoice(tpl, override) {
774
+ const resolved = resolveEinvoiceOptions(tpl.settings.einvoice, override);
775
+ if (!resolved.ok)
776
+ throw new DevkitError(
777
+ `${tpl.slug}: e-invoice ${resolved.field} "${resolved.value}": ${resolved.reason}`,
778
+ "validation"
779
+ );
780
+ return resolved.options;
781
+ }
782
+ var nowhere2 = { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } };
783
+ function diagnoseEinvoice(tpl) {
784
+ let options;
785
+ try {
786
+ options = declaredEinvoice(tpl);
787
+ } catch (e) {
788
+ return [
789
+ {
790
+ dataSet: "",
791
+ file: "settings.json",
792
+ diagnostics: [
793
+ {
794
+ severity: "error",
795
+ code: "einvoice-profile",
796
+ message: e instanceof Error ? e.message : String(e),
797
+ range: nowhere2
798
+ }
799
+ ]
800
+ }
801
+ ];
802
+ }
803
+ if (!options) return [];
804
+ if (tpl.meta.kind === "image")
805
+ return [
806
+ {
807
+ dataSet: "",
808
+ file: "settings.json",
809
+ diagnostics: [
810
+ {
811
+ severity: "warning",
812
+ code: "einvoice-image",
813
+ message: "settings.json declares an e-invoice, which an image template never produces: an e-invoice is a PDF",
814
+ range: nowhere2
815
+ }
816
+ ]
817
+ }
818
+ ];
819
+ const out = [];
820
+ for (const [name, data] of Object.entries(tpl.dataSets)) {
821
+ const result = einvoiceXml(data, options);
822
+ if (result.ok) continue;
823
+ const file = `data/${name}.json`;
824
+ const path = join4(tpl.dir, "data", `${name}.json`);
825
+ const text2 = existsSync4(path) ? readFileSync4(path, "utf8") : null;
826
+ out.push({
827
+ dataSet: name,
828
+ file,
829
+ diagnostics: result.problems.map((problem) => {
830
+ const at = text2 ? locateJsonPath(text2, [
831
+ INVOICE_DATA_KEY,
832
+ ...invoicePathSegments(problem.path)
833
+ ]) : null;
834
+ const start = at ? { line: at.line, column: at.column } : nowhere2.start;
835
+ return {
836
+ severity: "error",
837
+ code: `einvoice-${problem.code.replace(/_/g, "-")}`,
838
+ message: problem.message,
839
+ range: { start, end: start }
840
+ };
841
+ })
842
+ });
843
+ }
844
+ return out;
845
+ }
846
+ function localEinvoiceXml(tpl, data, override) {
847
+ const options = declaredEinvoice(tpl, override ?? {});
848
+ if (!options)
849
+ throw new DevkitError(`${tpl.slug} declares no e-invoice`, "validation");
850
+ const result = einvoiceXml(data, options);
851
+ if (!result.ok)
852
+ throw new DevkitError(
853
+ [
854
+ `${tpl.slug}: the _invoice block does not make an e-invoice`,
855
+ ...result.problems.map((problem) => ` ${problem.message}`)
856
+ ].join("\n"),
857
+ "validation"
858
+ );
859
+ return { xml: result.xml, invoice: result.invoice, options };
860
+ }
861
+
763
862
  // packages/devkit/src/lib/files.ts
764
863
  import { createHash as createHash2 } from "node:crypto";
765
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, statSync as statSync2, writeFileSync as writeFileSync4 } from "node:fs";
766
- import { dirname as dirname3, join as join4, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
864
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync4 } from "node:fs";
865
+ import { dirname as dirname3, join as join5, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
767
866
 
768
867
  // packages/api-types/src/lib/assets.ts
769
868
  var SEGMENT = "[A-Za-z0-9][A-Za-z0-9._-]*";
@@ -795,11 +894,11 @@ function sha256File(bytes) {
795
894
  }
796
895
  function listLocalFiles(project) {
797
896
  const listing = { files: [], skipped: [] };
798
- if (!existsSync4(project.filesDir)) return listing;
897
+ if (!existsSync5(project.filesDir)) return listing;
799
898
  const walk2 = (dir) => {
800
899
  for (const entry of readdirSync2(dir, { withFileTypes: true })) {
801
900
  if (entry.name.startsWith(".")) continue;
802
- const path = join4(dir, entry.name);
901
+ const path = join5(dir, entry.name);
803
902
  if (entry.isDirectory()) {
804
903
  walk2(path);
805
904
  continue;
@@ -813,7 +912,7 @@ function listLocalFiles(project) {
813
912
  listing.skipped.push({ path, reason });
814
913
  continue;
815
914
  }
816
- const bytes = readFileSync4(path);
915
+ const bytes = readFileSync5(path);
817
916
  listing.files.push({ name, path, bytes: size, sha256: sha256File(bytes), contentType });
818
917
  }
819
918
  };
@@ -1397,10 +1496,12 @@ export {
1397
1496
  collectPartials,
1398
1497
  contentHash,
1399
1498
  contentTypeFor,
1499
+ declaredEinvoice,
1400
1500
  defaultData,
1401
1501
  defaultProjectConfig,
1402
1502
  defaultTypesFile,
1403
1503
  diagnose,
1504
+ diagnoseEinvoice,
1404
1505
  findProject,
1405
1506
  generateTypes,
1406
1507
  htmlSnapshot,
@@ -1408,6 +1509,7 @@ export {
1408
1509
  listLocalFiles,
1409
1510
  listTemplateSlugs,
1410
1511
  loadProject,
1512
+ localEinvoiceXml,
1411
1513
  localFilePath,
1412
1514
  localTypeSource,
1413
1515
  officeSnapshot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formfeed/devkit",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "Formfeed template folders, project config and local rendering, shared by the CLI and @formfeed/testing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,8 +30,8 @@
30
30
  ],
31
31
  "sideEffects": false,
32
32
  "dependencies": {
33
- "@formfeed/engine": "0.3.11",
34
- "@formfeed/sdk": "0.3.11"
33
+ "@formfeed/engine": "0.3.12",
34
+ "@formfeed/sdk": "0.3.12"
35
35
  },
36
36
  "keywords": [
37
37
  "formfeed",
package/types/index.d.cts CHANGED
@@ -1,16 +1,18 @@
1
1
  export { DevkitError } from './lib/errors.cjs';
2
- export { defaultProjectConfig, findProject, isIgnored, loadProject, projectAround, writeProjectConfig } from './lib/project-config.cjs';
2
+ export { defaultProjectConfig, findProject, isIgnored, loadProject, projectAround, writeProjectConfig, } from './lib/project-config.cjs';
3
3
  export type { Project, ProjectConfig } from './lib/project-config.cjs';
4
4
  export { contentHash, defaultData, listTemplateSlugs, officeVersionPayload, partialContentHash, partialResolver, readState, readTemplate, recordSharedPartial, recordSync, sharedPartialNames, sharedPartialPath, templateDir, templateFileName, titleFromSlug, versionPayload, writePartials, writeState, writeTemplate, } from './lib/project.cjs';
5
- export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState } from './lib/project.cjs';
5
+ export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState, } from './lib/project.cjs';
6
6
  export { brandFromJson, brandPath, readBrand, writeBrand } from './lib/brand.cjs';
7
7
  export { collectPartials } from './lib/partials.cjs';
8
8
  export type { CollectedPartials } from './lib/partials.cjs';
9
- export { diagnose, htmlSnapshot, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal, renderedSettings } from './lib/local-render.cjs';
9
+ export { diagnose, htmlSnapshot, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal, renderedSettings, } from './lib/local-render.cjs';
10
10
  export type { LocalDiagnostic, OfficeLocalOptions } from './lib/local-render.cjs';
11
- export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile } from './lib/files.cjs';
11
+ export { declaredEinvoice, diagnoseEinvoice, localEinvoiceXml, } from './lib/einvoice.cjs';
12
+ export type { DataSetDiagnostics } from './lib/einvoice.cjs';
13
+ export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile, } from './lib/files.cjs';
12
14
  export type { LocalFile, LocalFileListing } from './lib/files.cjs';
13
15
  export type { LocalRenderOptions } from './lib/local-render.cjs';
14
16
  export { parseRedactPath, redactData, redactString } from './lib/redact.cjs';
15
17
  export { defaultTypesFile, generateTypes, localTypeSource } from './lib/types/index.cjs';
16
- export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage } from './lib/types/index.cjs';
18
+ export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage, } from './lib/types/index.cjs';
package/types/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  export { DevkitError } from './lib/errors.js';
2
- export { defaultProjectConfig, findProject, isIgnored, loadProject, projectAround, writeProjectConfig } from './lib/project-config.js';
2
+ export { defaultProjectConfig, findProject, isIgnored, loadProject, projectAround, writeProjectConfig, } from './lib/project-config.js';
3
3
  export type { Project, ProjectConfig } from './lib/project-config.js';
4
4
  export { contentHash, defaultData, listTemplateSlugs, officeVersionPayload, partialContentHash, partialResolver, readState, readTemplate, recordSharedPartial, recordSync, sharedPartialNames, sharedPartialPath, templateDir, templateFileName, titleFromSlug, versionPayload, writePartials, writeState, writeTemplate, } from './lib/project.js';
5
- export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState } from './lib/project.js';
5
+ export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState, } from './lib/project.js';
6
6
  export { brandFromJson, brandPath, readBrand, writeBrand } from './lib/brand.js';
7
7
  export { collectPartials } from './lib/partials.js';
8
8
  export type { CollectedPartials } from './lib/partials.js';
9
- export { diagnose, htmlSnapshot, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal, renderedSettings } from './lib/local-render.js';
9
+ export { diagnose, htmlSnapshot, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal, renderedSettings, } from './lib/local-render.js';
10
10
  export type { LocalDiagnostic, OfficeLocalOptions } from './lib/local-render.js';
11
- export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile } from './lib/files.js';
11
+ export { declaredEinvoice, diagnoseEinvoice, localEinvoiceXml, } from './lib/einvoice.js';
12
+ export type { DataSetDiagnostics } from './lib/einvoice.js';
13
+ export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile, } from './lib/files.js';
12
14
  export type { LocalFile, LocalFileListing } from './lib/files.js';
13
15
  export type { LocalRenderOptions } from './lib/local-render.js';
14
16
  export { parseRedactPath, redactData, redactString } from './lib/redact.js';
15
17
  export { defaultTypesFile, generateTypes, localTypeSource } from './lib/types/index.js';
16
- export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage } from './lib/types/index.js';
18
+ export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage, } from './lib/types/index.js';
@@ -0,0 +1,37 @@
1
+ import { type EinvoiceOptions, type EinvoiceOptionsInput, type Invoice } from '@formfeed/engine';
2
+ import type { LocalDiagnostic } from './local-render.cjs';
3
+ import type { LocalTemplate } from './project.cjs';
4
+ /**
5
+ * The e-invoice of a template folder (spec 17): what `settings.json` declares, the check of every
6
+ * data set against it, and the XML itself. All of it runs offline, with the code the API runs, so
7
+ * what `formfeed validate` accepts the API accepts too.
8
+ */
9
+ /**
10
+ * The e-invoice a template declares in `settings.json`, with every default filled in; `null` when
11
+ * it declares none. `override` is merged over it like a request's `post.einvoice`; `{}` asks for an
12
+ * e-invoice with the defaults from a template that declares nothing.
13
+ */
14
+ export declare function declaredEinvoice(tpl: LocalTemplate, override?: EinvoiceOptionsInput | false): EinvoiceOptions | null;
15
+ /** The findings of one data set, with the file they are in. */
16
+ export interface DataSetDiagnostics {
17
+ dataSet: string;
18
+ /** Relative to the template folder: `data/default.json`. */
19
+ file: string;
20
+ diagnostics: LocalDiagnostic[];
21
+ }
22
+ /**
23
+ * Every data set of an invoice template against the `_invoice` schema and the rules of EN 16931
24
+ * (spec 17 §8). Each is an error: a render with that data fails with `einvoice_data_invalid`, and a
25
+ * template that declares an e-invoice renders nothing else. Empty for a template that declares
26
+ * none; one warning for an image template, where the declaration has no effect.
27
+ */
28
+ export declare function diagnoseEinvoice(tpl: LocalTemplate): DataSetDiagnostics[];
29
+ /**
30
+ * The XML of one data set, as a render of the template would embed it. Throws a validation error
31
+ * that lists what is wrong with the block when it does not pass.
32
+ */
33
+ export declare function localEinvoiceXml(tpl: LocalTemplate, data: unknown, override?: EinvoiceOptionsInput): {
34
+ xml: string;
35
+ invoice: Invoice;
36
+ options: EinvoiceOptions;
37
+ };
@@ -0,0 +1,37 @@
1
+ import { type EinvoiceOptions, type EinvoiceOptionsInput, type Invoice } from '@formfeed/engine';
2
+ import type { LocalDiagnostic } from './local-render.js';
3
+ import type { LocalTemplate } from './project.js';
4
+ /**
5
+ * The e-invoice of a template folder (spec 17): what `settings.json` declares, the check of every
6
+ * data set against it, and the XML itself. All of it runs offline, with the code the API runs, so
7
+ * what `formfeed validate` accepts the API accepts too.
8
+ */
9
+ /**
10
+ * The e-invoice a template declares in `settings.json`, with every default filled in; `null` when
11
+ * it declares none. `override` is merged over it like a request's `post.einvoice`; `{}` asks for an
12
+ * e-invoice with the defaults from a template that declares nothing.
13
+ */
14
+ export declare function declaredEinvoice(tpl: LocalTemplate, override?: EinvoiceOptionsInput | false): EinvoiceOptions | null;
15
+ /** The findings of one data set, with the file they are in. */
16
+ export interface DataSetDiagnostics {
17
+ dataSet: string;
18
+ /** Relative to the template folder: `data/default.json`. */
19
+ file: string;
20
+ diagnostics: LocalDiagnostic[];
21
+ }
22
+ /**
23
+ * Every data set of an invoice template against the `_invoice` schema and the rules of EN 16931
24
+ * (spec 17 §8). Each is an error: a render with that data fails with `einvoice_data_invalid`, and a
25
+ * template that declares an e-invoice renders nothing else. Empty for a template that declares
26
+ * none; one warning for an image template, where the declaration has no effect.
27
+ */
28
+ export declare function diagnoseEinvoice(tpl: LocalTemplate): DataSetDiagnostics[];
29
+ /**
30
+ * The XML of one data set, as a render of the template would embed it. Throws a validation error
31
+ * that lists what is wrong with the block when it does not pass.
32
+ */
33
+ export declare function localEinvoiceXml(tpl: LocalTemplate, data: unknown, override?: EinvoiceOptionsInput): {
34
+ xml: string;
35
+ invoice: Invoice;
36
+ options: EinvoiceOptions;
37
+ };