@open-nav/core 0.1.0
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/LICENSE +29 -0
- package/README.md +132 -0
- package/dist/constants.d.ts +49 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +58 -0
- package/dist/constants.js.map +1 -0
- package/dist/crypto/hash.d.ts +16 -0
- package/dist/crypto/hash.d.ts.map +1 -0
- package/dist/crypto/hash.js +30 -0
- package/dist/crypto/hash.js.map +1 -0
- package/dist/crypto/node-provider.d.ts +9 -0
- package/dist/crypto/node-provider.d.ts.map +1 -0
- package/dist/crypto/node-provider.js +18 -0
- package/dist/crypto/node-provider.js.map +1 -0
- package/dist/crypto/provider.d.ts +28 -0
- package/dist/crypto/provider.d.ts.map +1 -0
- package/dist/crypto/provider.js +14 -0
- package/dist/crypto/provider.js.map +1 -0
- package/dist/crypto/request-id.d.ts +16 -0
- package/dist/crypto/request-id.d.ts.map +1 -0
- package/dist/crypto/request-id.js +59 -0
- package/dist/crypto/request-id.js.map +1 -0
- package/dist/crypto/signature.d.ts +40 -0
- package/dist/crypto/signature.d.ts.map +1 -0
- package/dist/crypto/signature.js +38 -0
- package/dist/crypto/signature.js.map +1 -0
- package/dist/crypto/token.d.ts +14 -0
- package/dist/crypto/token.d.ts.map +1 -0
- package/dist/crypto/token.js +82 -0
- package/dist/crypto/token.js.map +1 -0
- package/dist/crypto/web-provider.d.ts +18 -0
- package/dist/crypto/web-provider.d.ts.map +1 -0
- package/dist/crypto/web-provider.js +31 -0
- package/dist/crypto/web-provider.js.map +1 -0
- package/dist/errors.d.ts +75 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated/fault-codes.d.ts +1343 -0
- package/dist/generated/fault-codes.d.ts.map +1 -0
- package/dist/generated/fault-codes.js +1331 -0
- package/dist/generated/fault-codes.js.map +1 -0
- package/dist/generated/index.d.ts +4 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +5 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/schema.d.ts +13 -0
- package/dist/generated/schema.d.ts.map +1 -0
- package/dist/generated/schema.js +3756 -0
- package/dist/generated/schema.js.map +1 -0
- package/dist/generated/types.d.ts +5580 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +6 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/invoice/payload.d.ts +40 -0
- package/dist/invoice/payload.d.ts.map +1 -0
- package/dist/invoice/payload.js +66 -0
- package/dist/invoice/payload.js.map +1 -0
- package/dist/money/decimal.d.ts +69 -0
- package/dist/money/decimal.d.ts.map +1 -0
- package/dist/money/decimal.js +190 -0
- package/dist/money/decimal.js.map +1 -0
- package/dist/money/summary.d.ts +60 -0
- package/dist/money/summary.d.ts.map +1 -0
- package/dist/money/summary.js +236 -0
- package/dist/money/summary.js.map +1 -0
- package/dist/time.d.ts +16 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +41 -0
- package/dist/time.js.map +1 -0
- package/dist/validation/issue.d.ts +67 -0
- package/dist/validation/issue.d.ts.map +1 -0
- package/dist/validation/issue.js +40 -0
- package/dist/validation/issue.js.map +1 -0
- package/dist/validation/rules.d.ts +34 -0
- package/dist/validation/rules.d.ts.map +1 -0
- package/dist/validation/rules.js +290 -0
- package/dist/validation/rules.js.map +1 -0
- package/dist/validation/schema.d.ts +14 -0
- package/dist/validation/schema.d.ts.map +1 -0
- package/dist/validation/schema.js +231 -0
- package/dist/validation/schema.js.map +1 -0
- package/dist/validation/tax-number.d.ts +39 -0
- package/dist/validation/tax-number.d.ts.map +1 -0
- package/dist/validation/tax-number.js +79 -0
- package/dist/validation/tax-number.js.map +1 -0
- package/dist/validation/validate.d.ts +29 -0
- package/dist/validation/validate.d.ts.map +1 -0
- package/dist/validation/validate.js +33 -0
- package/dist/validation/validate.js.map +1 -0
- package/dist/xml/descriptor.d.ts +82 -0
- package/dist/xml/descriptor.d.ts.map +1 -0
- package/dist/xml/descriptor.js +32 -0
- package/dist/xml/descriptor.js.map +1 -0
- package/dist/xml/read.d.ts +25 -0
- package/dist/xml/read.d.ts.map +1 -0
- package/dist/xml/read.js +230 -0
- package/dist/xml/read.js.map +1 -0
- package/dist/xml/write.d.ts +28 -0
- package/dist/xml/write.d.ts.map +1 -0
- package/dist/xml/write.js +299 -0
- package/dist/xml/write.js.map +1 -0
- package/package.json +55 -0
- package/src/constants.ts +76 -0
- package/src/crypto/hash.ts +35 -0
- package/src/crypto/node-provider.ts +19 -0
- package/src/crypto/provider.ts +37 -0
- package/src/crypto/request-id.ts +63 -0
- package/src/crypto/signature.ts +58 -0
- package/src/crypto/token.ts +86 -0
- package/src/crypto/web-provider.ts +32 -0
- package/src/errors.ts +109 -0
- package/src/generated/fault-codes.ts +1338 -0
- package/src/generated/index.ts +4 -0
- package/src/generated/schema.ts +3760 -0
- package/src/generated/types.ts +5829 -0
- package/src/index.ts +22 -0
- package/src/invoice/payload.ts +102 -0
- package/src/money/decimal.ts +218 -0
- package/src/money/summary.ts +380 -0
- package/src/time.ts +44 -0
- package/src/validation/issue.ts +102 -0
- package/src/validation/rules.ts +548 -0
- package/src/validation/schema.ts +315 -0
- package/src/validation/tax-number.ts +96 -0
- package/src/validation/validate.ts +45 -0
- package/src/xml/descriptor.ts +112 -0
- package/src/xml/read.ts +303 -0
- package/src/xml/write.ts +391 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hungarian tax number checks.
|
|
3
|
+
*
|
|
4
|
+
* A tax number is eleven digits in three parts: an eight digit core
|
|
5
|
+
* (törzsszám) whose last digit is a check digit, a one digit VAT code
|
|
6
|
+
* (áfakód), and a two digit county code (megyekód). NAV's schemas carry the
|
|
7
|
+
* three parts separately, in `taxpayerId`, `vatCode` and `countyCode`.
|
|
8
|
+
*/
|
|
9
|
+
/** Weights applied to the first seven digits of the core number. */
|
|
10
|
+
const CHECK_WEIGHTS = [9, 7, 3, 1, 9, 7, 3];
|
|
11
|
+
/**
|
|
12
|
+
* County codes NAV issues.
|
|
13
|
+
*
|
|
14
|
+
* This set is **not** in the XSD, which only constrains the field to two
|
|
15
|
+
* digits, so it is best-effort and is reported as a warning rather than an
|
|
16
|
+
* error. Budapest and Pest county use 41 to 44; 51 is used for taxpayers
|
|
17
|
+
* registered by the large taxpayers directorate.
|
|
18
|
+
*/
|
|
19
|
+
const COUNTY_CODES = new Set([
|
|
20
|
+
...range(2, 20), // the counties, alphabetically
|
|
21
|
+
...range(22, 44), // remaining counties plus the capital
|
|
22
|
+
51,
|
|
23
|
+
]);
|
|
24
|
+
function range(from, to) {
|
|
25
|
+
return Array.from({ length: to - from + 1 }, (_, index) => from + index);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether the check digit of an eight digit core tax number is consistent.
|
|
29
|
+
*
|
|
30
|
+
* Verified against the real tax numbers in NAV's published samples. Note that
|
|
31
|
+
* two of the four tax numbers those samples use (`98765432`, `87654321`) are
|
|
32
|
+
* obvious placeholders and do *not* satisfy the check — evidence that NAV
|
|
33
|
+
* validates a tax number against its taxpayer registry rather than
|
|
34
|
+
* arithmetically. Treat a failure here as a likely typo, and use
|
|
35
|
+
* `queryTaxpayer` when you need an authoritative answer.
|
|
36
|
+
*/
|
|
37
|
+
export function isValidTaxpayerId(taxpayerId) {
|
|
38
|
+
if (!/^\d{8}$/.test(taxpayerId))
|
|
39
|
+
return false;
|
|
40
|
+
const sum = CHECK_WEIGHTS.reduce((total, weight, index) => total + Number(taxpayerId[index]) * weight, 0);
|
|
41
|
+
return (10 - (sum % 10)) % 10 === Number(taxpayerId[7]);
|
|
42
|
+
}
|
|
43
|
+
/** The check digit an eight digit core tax number should end with. */
|
|
44
|
+
export function taxpayerIdCheckDigit(firstSevenDigits) {
|
|
45
|
+
if (!/^\d{7}$/.test(firstSevenDigits)) {
|
|
46
|
+
throw new Error(`Expected seven digits, got ${JSON.stringify(firstSevenDigits)}`);
|
|
47
|
+
}
|
|
48
|
+
const sum = CHECK_WEIGHTS.reduce((total, weight, index) => total + Number(firstSevenDigits[index]) * weight, 0);
|
|
49
|
+
return (10 - (sum % 10)) % 10;
|
|
50
|
+
}
|
|
51
|
+
/** Whether a VAT code is one NAV defines. */
|
|
52
|
+
export function isValidVatCode(vatCode) {
|
|
53
|
+
return /^[1-5]$/.test(vatCode);
|
|
54
|
+
}
|
|
55
|
+
/** Whether a county code is one NAV issues. Best-effort; see COUNTY_CODES. */
|
|
56
|
+
export function isValidCountyCode(countyCode) {
|
|
57
|
+
return /^\d{2}$/.test(countyCode) && COUNTY_CODES.has(Number(countyCode));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Split an eleven digit tax number into the three parts NAV's schema wants.
|
|
61
|
+
*
|
|
62
|
+
* Accepts the common written forms — `12345678-2-41`, `12345678 2 41` and
|
|
63
|
+
* `12345678241` — because that is how the number appears on paper, and
|
|
64
|
+
* pasting it whole into `taxpayerId` is the mistake this avoids.
|
|
65
|
+
*/
|
|
66
|
+
export function parseTaxNumber(input) {
|
|
67
|
+
const digits = input.replace(/[\s-]/g, '');
|
|
68
|
+
if (/^\d{8}$/.test(digits))
|
|
69
|
+
return { taxpayerId: digits };
|
|
70
|
+
if (/^\d{11}$/.test(digits)) {
|
|
71
|
+
return {
|
|
72
|
+
taxpayerId: digits.slice(0, 8),
|
|
73
|
+
vatCode: digits.slice(8, 9),
|
|
74
|
+
countyCode: digits.slice(9, 11),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Expected an 8 or 11 digit Hungarian tax number, got ${JSON.stringify(input)}`);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=tax-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tax-number.js","sourceRoot":"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M,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { InvoiceData } from '../generated/types.js';
|
|
2
|
+
import { type MessageLanguage, type ValidationReport } from './issue.js';
|
|
3
|
+
import { type InvoiceValidationContext } from './rules.js';
|
|
4
|
+
export interface ValidateInvoiceOptions extends InvoiceValidationContext {
|
|
5
|
+
/** Language for NAV's own fault descriptions. Defaults to English. */
|
|
6
|
+
language?: MessageLanguage;
|
|
7
|
+
/** Skip the business rules and check only the schema. */
|
|
8
|
+
schemaOnly?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check an invoice data report before sending it.
|
|
12
|
+
*
|
|
13
|
+
* Two layers run: the schema, derived from NAV's XSDs, and the business rules
|
|
14
|
+
* that are decidable from the document alone. Every finding carries NAV's own
|
|
15
|
+
* fault code where one exists, so a failure here reads the same as the
|
|
16
|
+
* rejection it prevents.
|
|
17
|
+
*
|
|
18
|
+
* Warnings do not make a report invalid. The distinction matters: a tax number
|
|
19
|
+
* whose check digit is wrong is worth flagging, but NAV validates tax numbers
|
|
20
|
+
* against its registry, so treating it as an error would reject documents the
|
|
21
|
+
* service accepts.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const report = validateInvoice(invoice, { operation: 'CREATE' });
|
|
25
|
+
* if (!report.valid) console.error(report.errors);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateInvoice(document: InvoiceData, options?: ValidateInvoiceOptions): ValidationReport;
|
|
29
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAElF,MAAM,WAAW,sBAAuB,SAAQ,wBAAwB;IACtE,sEAAsE;IACtE,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,sBAA2B,GACnC,gBAAgB,CAWlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IssueCollector } from './issue.js';
|
|
2
|
+
import { collectSchemaIssues } from './schema.js';
|
|
3
|
+
import { collectBusinessIssues } from './rules.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check an invoice data report before sending it.
|
|
6
|
+
*
|
|
7
|
+
* Two layers run: the schema, derived from NAV's XSDs, and the business rules
|
|
8
|
+
* that are decidable from the document alone. Every finding carries NAV's own
|
|
9
|
+
* fault code where one exists, so a failure here reads the same as the
|
|
10
|
+
* rejection it prevents.
|
|
11
|
+
*
|
|
12
|
+
* Warnings do not make a report invalid. The distinction matters: a tax number
|
|
13
|
+
* whose check digit is wrong is worth flagging, but NAV validates tax numbers
|
|
14
|
+
* against its registry, so treating it as an error would reject documents the
|
|
15
|
+
* service accepts.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const report = validateInvoice(invoice, { operation: 'CREATE' });
|
|
19
|
+
* if (!report.valid) console.error(report.errors);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function validateInvoice(document, options = {}) {
|
|
23
|
+
const collector = new IssueCollector(options.language ?? 'en');
|
|
24
|
+
collectSchemaIssues('InvoiceData', document, collector);
|
|
25
|
+
const report = collector.report();
|
|
26
|
+
// Business rules read the document as typed data; running them over a
|
|
27
|
+
// structurally invalid document would produce noise, not findings.
|
|
28
|
+
if (options.schemaOnly || report.errors.length > 0)
|
|
29
|
+
return report;
|
|
30
|
+
collectBusinessIssues(document, collector, options);
|
|
31
|
+
return collector.report();
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAA+C,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAC;AASlF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAqB,EACrB,UAAkC,EAAE;IAEpC,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;IAC/D,mBAAmB,CAAC,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAExD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;IAClC,sEAAsE;IACtE,mEAAmE;IACnE,IAAI,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IAElE,qBAAqB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACpD,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime description of the NAV schemas.
|
|
3
|
+
*
|
|
4
|
+
* The generated `TYPES` table in `../generated/schema.js` is the single source
|
|
5
|
+
* of truth for element order, namespaces, cardinality, choice exclusivity and
|
|
6
|
+
* value constraints. Serialisation, parsing and validation are all driven from
|
|
7
|
+
* it, so moving to a future interface version is a regeneration rather than a
|
|
8
|
+
* rewrite of three separate hand-maintained code paths.
|
|
9
|
+
*/
|
|
10
|
+
/** Short key for each namespace in the Online Számla schemas. */
|
|
11
|
+
export type NsKey = 'common' | 'base' | 'data' | 'api' | 'annul' | 'metrics';
|
|
12
|
+
export declare const NAMESPACE_URIS: Record<NsKey, string>;
|
|
13
|
+
/** How a value is carried in XML. */
|
|
14
|
+
export type PrimitiveKind = 'string' | 'decimal' | 'integer' | 'boolean' | 'date' | 'dateTime' | 'base64Binary';
|
|
15
|
+
export interface FieldDescriptor {
|
|
16
|
+
/** Element local name. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Namespace that *declares* this element, which may differ from its parent's. */
|
|
19
|
+
ns: NsKey;
|
|
20
|
+
/** Key into the `TYPES` table, or an `xs:` primitive. */
|
|
21
|
+
type: string;
|
|
22
|
+
/** `minOccurs="0"`. Choice members are always optional. */
|
|
23
|
+
optional?: boolean;
|
|
24
|
+
/** `maxOccurs` greater than one, or unbounded. */
|
|
25
|
+
repeated?: boolean;
|
|
26
|
+
/** Upper bound when the schema states a finite one. */
|
|
27
|
+
maxOccurs?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ChoiceGroupDescriptor {
|
|
30
|
+
members: string[];
|
|
31
|
+
/** `true` when exactly one member must be present; `false` when at most one may be. */
|
|
32
|
+
required: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface AttributeDescriptor {
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
required: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface ComplexDescriptor {
|
|
40
|
+
kind: 'complex';
|
|
41
|
+
name: string;
|
|
42
|
+
ns: NsKey;
|
|
43
|
+
/** Name of the corresponding generated TypeScript type. */
|
|
44
|
+
tsName: string;
|
|
45
|
+
/** `element` for child elements, `simple` for text content plus attributes. */
|
|
46
|
+
content: 'element' | 'simple';
|
|
47
|
+
/** Type of the text value when `content` is `simple`. */
|
|
48
|
+
contentType?: string;
|
|
49
|
+
/** Child elements in schema order — which is the order NAV requires. */
|
|
50
|
+
fields: FieldDescriptor[];
|
|
51
|
+
choiceGroups?: ChoiceGroupDescriptor[];
|
|
52
|
+
attributes?: AttributeDescriptor[];
|
|
53
|
+
}
|
|
54
|
+
export interface SimpleDescriptor {
|
|
55
|
+
kind: 'simple';
|
|
56
|
+
name: string;
|
|
57
|
+
ns: NsKey;
|
|
58
|
+
tsName: string;
|
|
59
|
+
primitive: PrimitiveKind;
|
|
60
|
+
/** Permitted values, when the type is an enumeration. */
|
|
61
|
+
enumValues?: string[];
|
|
62
|
+
/** Most derived `xs:pattern` of the restriction chain. */
|
|
63
|
+
pattern?: string;
|
|
64
|
+
length?: number;
|
|
65
|
+
minLength?: number;
|
|
66
|
+
maxLength?: number;
|
|
67
|
+
totalDigits?: number;
|
|
68
|
+
fractionDigits?: number;
|
|
69
|
+
minInclusive?: string;
|
|
70
|
+
maxInclusive?: string;
|
|
71
|
+
minExclusive?: string;
|
|
72
|
+
maxExclusive?: string;
|
|
73
|
+
}
|
|
74
|
+
export type Descriptor = ComplexDescriptor | SimpleDescriptor;
|
|
75
|
+
export interface RootDescriptor {
|
|
76
|
+
name: string;
|
|
77
|
+
ns: NsKey;
|
|
78
|
+
type: string;
|
|
79
|
+
}
|
|
80
|
+
/** Primitive kinds of the `xs:` built-ins referenced directly by the schemas. */
|
|
81
|
+
export declare const XS_PRIMITIVES: Record<string, PrimitiveKind>;
|
|
82
|
+
//# sourceMappingURL=descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../../src/xml/descriptor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iEAAiE;AACjE,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;AAE7E,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CA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M,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,aAAa,CAAC;IACzB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd;AAED,iFAAiF;AACjF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAYvD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime description of the NAV schemas.
|
|
3
|
+
*
|
|
4
|
+
* The generated `TYPES` table in `../generated/schema.js` is the single source
|
|
5
|
+
* of truth for element order, namespaces, cardinality, choice exclusivity and
|
|
6
|
+
* value constraints. Serialisation, parsing and validation are all driven from
|
|
7
|
+
* it, so moving to a future interface version is a regeneration rather than a
|
|
8
|
+
* rewrite of three separate hand-maintained code paths.
|
|
9
|
+
*/
|
|
10
|
+
export const NAMESPACE_URIS = {
|
|
11
|
+
common: 'http://schemas.nav.gov.hu/NTCA/1.0/common',
|
|
12
|
+
base: 'http://schemas.nav.gov.hu/OSA/3.0/base',
|
|
13
|
+
data: 'http://schemas.nav.gov.hu/OSA/3.0/data',
|
|
14
|
+
api: 'http://schemas.nav.gov.hu/OSA/3.0/api',
|
|
15
|
+
annul: 'http://schemas.nav.gov.hu/OSA/3.0/annul',
|
|
16
|
+
metrics: 'http://schemas.nav.gov.hu/OSA/3.0/metrics',
|
|
17
|
+
};
|
|
18
|
+
/** Primitive kinds of the `xs:` built-ins referenced directly by the schemas. */
|
|
19
|
+
export const XS_PRIMITIVES = {
|
|
20
|
+
'xs:string': 'string',
|
|
21
|
+
'xs:decimal': 'decimal',
|
|
22
|
+
'xs:int': 'integer',
|
|
23
|
+
'xs:integer': 'integer',
|
|
24
|
+
'xs:long': 'integer',
|
|
25
|
+
'xs:nonNegativeInteger': 'integer',
|
|
26
|
+
'xs:positiveInteger': 'integer',
|
|
27
|
+
'xs:boolean': 'boolean',
|
|
28
|
+
'xs:date': 'date',
|
|
29
|
+
'xs:dateTime': 'dateTime',
|
|
30
|
+
'xs:base64Binary': 'base64Binary',
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../src/xml/descriptor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,CAAC,MAAM,cAAc,GAA0B;IACnD,MAAM,EAAE,2CAA2C;IACnD,IAAI,EAAE,wCAAwC;IAC9C,IAAI,EAAE,wCAAwC;IAC9C,GAAG,EAAE,uCAAuC;IAC5C,KAAK,EAAE,yCAAyC;IAChD,OAAO,EAAE,2CAA2C;CACrD,CAAC;AA8EF,iFAAiF;AACjF,MAAM,CAAC,MAAM,aAAa,GAAkC;IAC1D,WAAW,EAAE,QAAQ;IACrB,YAAY,EAAE,SAAS;IACvB,QAAQ,EAAE,SAAS;IACnB,YAAY,EAAE,SAAS;IACvB,SAAS,EAAE,SAAS;IACpB,uBAAuB,EAAE,SAAS;IAClC,oBAAoB,EAAE,SAAS;IAC/B,YAAY,EAAE,SAAS;IACvB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,UAAU;IACzB,iBAAiB,EAAE,cAAc;CAClC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ParseOptions {
|
|
2
|
+
/**
|
|
3
|
+
* What to do with elements the schema does not declare.
|
|
4
|
+
*
|
|
5
|
+
* `error` (the default) surfaces them, which is what you want for documents
|
|
6
|
+
* you produced yourself. Use `ignore` when reading responses from a NAV
|
|
7
|
+
* deployment that may be ahead of the vendored schema.
|
|
8
|
+
*/
|
|
9
|
+
unknownElements?: 'error' | 'ignore';
|
|
10
|
+
}
|
|
11
|
+
export interface ParsedDocument {
|
|
12
|
+
/** Root element name, e.g. `ManageInvoiceResponse`. */
|
|
13
|
+
root: string;
|
|
14
|
+
value: unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse a NAV document into the shape of its generated type.
|
|
18
|
+
*
|
|
19
|
+
* The root element name decides which descriptor is used, so responses and
|
|
20
|
+
* invoice payloads both go through the same path.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseDocument(xml: string, options?: ParseOptions): ParsedDocument;
|
|
23
|
+
/** Parse a document whose root is known, returning the generated type. */
|
|
24
|
+
export declare function parseDocumentAs<T>(xml: string, rootName: string, options?: ParseOptions): T;
|
|
25
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/xml/read.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAiED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,cAAc,CA8BrF;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,CAAC,CAM3F"}
|
package/dist/xml/read.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
2
|
+
import { NavValidationError } from '../errors.js';
|
|
3
|
+
import { ROOTS, TYPES } from '../generated/schema.js';
|
|
4
|
+
import { NAMESPACE_URIS, XS_PRIMITIVES, } from './descriptor.js';
|
|
5
|
+
const URI_TO_NS = Object.fromEntries(Object.entries(NAMESPACE_URIS).map(([key, uri]) => [uri, key]));
|
|
6
|
+
const parser = new XMLParser({
|
|
7
|
+
preserveOrder: true,
|
|
8
|
+
ignoreAttributes: false,
|
|
9
|
+
attributeNamePrefix: '@',
|
|
10
|
+
trimValues: true,
|
|
11
|
+
// Values are converted according to the schema, not guessed from their
|
|
12
|
+
// shape: an invoice number of "2021000123" must stay a string.
|
|
13
|
+
parseTagValue: false,
|
|
14
|
+
parseAttributeValue: false,
|
|
15
|
+
});
|
|
16
|
+
/** Namespace prefixes in scope, inherited down the tree. */
|
|
17
|
+
class Scope {
|
|
18
|
+
byPrefix;
|
|
19
|
+
defaultUri;
|
|
20
|
+
constructor(byPrefix = new Map(), defaultUri = undefined) {
|
|
21
|
+
this.byPrefix = byPrefix;
|
|
22
|
+
this.defaultUri = defaultUri;
|
|
23
|
+
}
|
|
24
|
+
extend(attributes) {
|
|
25
|
+
let next;
|
|
26
|
+
let defaultUri = this.defaultUri;
|
|
27
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
28
|
+
if (name === '@xmlns') {
|
|
29
|
+
defaultUri = value;
|
|
30
|
+
}
|
|
31
|
+
else if (name.startsWith('@xmlns:')) {
|
|
32
|
+
next ??= new Map(this.byPrefix);
|
|
33
|
+
next.set(name.slice('@xmlns:'.length), value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!next && defaultUri === this.defaultUri)
|
|
37
|
+
return this;
|
|
38
|
+
return new Scope(next ?? this.byPrefix, defaultUri);
|
|
39
|
+
}
|
|
40
|
+
resolve(prefix) {
|
|
41
|
+
return prefix === '' ? this.defaultUri : this.byPrefix.get(prefix);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function tagOf(node) {
|
|
45
|
+
const tag = Object.keys(node).find((key) => key !== ':@');
|
|
46
|
+
if (tag === undefined)
|
|
47
|
+
throw new NavValidationError('Malformed XML node');
|
|
48
|
+
return tag;
|
|
49
|
+
}
|
|
50
|
+
function childrenOf(node) {
|
|
51
|
+
const value = node[tagOf(node)];
|
|
52
|
+
return Array.isArray(value) ? value : [];
|
|
53
|
+
}
|
|
54
|
+
function attrsOf(node) {
|
|
55
|
+
return node[':@'] ?? {};
|
|
56
|
+
}
|
|
57
|
+
function textOf(node) {
|
|
58
|
+
return childrenOf(node)
|
|
59
|
+
.filter((child) => tagOf(child) === '#text')
|
|
60
|
+
.map((child) => String(child['#text']))
|
|
61
|
+
.join('');
|
|
62
|
+
}
|
|
63
|
+
function elementChildren(node) {
|
|
64
|
+
return childrenOf(node).filter((child) => {
|
|
65
|
+
const tag = tagOf(child);
|
|
66
|
+
return tag !== '#text' && tag !== '#comment' && !tag.startsWith('?');
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function splitName(qname) {
|
|
70
|
+
const index = qname.indexOf(':');
|
|
71
|
+
return index === -1
|
|
72
|
+
? { prefix: '', local: qname }
|
|
73
|
+
: { prefix: qname.slice(0, index), local: qname.slice(index + 1) };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parse a NAV document into the shape of its generated type.
|
|
77
|
+
*
|
|
78
|
+
* The root element name decides which descriptor is used, so responses and
|
|
79
|
+
* invoice payloads both go through the same path.
|
|
80
|
+
*/
|
|
81
|
+
export function parseDocument(xml, options = {}) {
|
|
82
|
+
const document = parser.parse(xml);
|
|
83
|
+
const rootNode = document.find((node) => {
|
|
84
|
+
const tag = tagOf(node);
|
|
85
|
+
return tag !== '#text' && tag !== '#comment' && !tag.startsWith('?');
|
|
86
|
+
});
|
|
87
|
+
if (!rootNode) {
|
|
88
|
+
throw new NavValidationError('No root element found in document');
|
|
89
|
+
}
|
|
90
|
+
const { local } = splitName(tagOf(rootNode));
|
|
91
|
+
const root = ROOTS[local];
|
|
92
|
+
if (!root) {
|
|
93
|
+
throw new NavValidationError(`Unknown document root ${local}`, [
|
|
94
|
+
{
|
|
95
|
+
path: '',
|
|
96
|
+
code: 'UNKNOWN_ROOT',
|
|
97
|
+
message: `expected one of ${Object.keys(ROOTS).join(', ')}`,
|
|
98
|
+
},
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
const issues = [];
|
|
102
|
+
const scope = new Scope().extend(attrsOf(rootNode));
|
|
103
|
+
const value = readComplex(rootNode, root.type, scope, local, issues, options);
|
|
104
|
+
if (issues.length > 0) {
|
|
105
|
+
throw new NavValidationError(`Cannot parse ${local}`, issues);
|
|
106
|
+
}
|
|
107
|
+
return { root: local, value };
|
|
108
|
+
}
|
|
109
|
+
/** Parse a document whose root is known, returning the generated type. */
|
|
110
|
+
export function parseDocumentAs(xml, rootName, options) {
|
|
111
|
+
const parsed = parseDocument(xml, options);
|
|
112
|
+
if (parsed.root !== rootName) {
|
|
113
|
+
throw new NavValidationError(`Expected a ${rootName} document but found ${parsed.root}`);
|
|
114
|
+
}
|
|
115
|
+
return parsed.value;
|
|
116
|
+
}
|
|
117
|
+
function readComplex(node, typeKey, scope, path, issues, options) {
|
|
118
|
+
const descriptor = TYPES[typeKey];
|
|
119
|
+
if (!descriptor) {
|
|
120
|
+
issues.push({
|
|
121
|
+
path,
|
|
122
|
+
code: 'UNKNOWN_TYPE',
|
|
123
|
+
message: `${typeKey} is not in the generated schema`,
|
|
124
|
+
});
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
if (descriptor.kind === 'simple') {
|
|
128
|
+
return readPrimitive(descriptor.primitive, textOf(node), path, issues);
|
|
129
|
+
}
|
|
130
|
+
if (descriptor.content === 'simple') {
|
|
131
|
+
return readSimpleContent(node, descriptor, path, issues);
|
|
132
|
+
}
|
|
133
|
+
const result = {};
|
|
134
|
+
const localScope = scope.extend(attrsOf(node));
|
|
135
|
+
for (const child of elementChildren(node)) {
|
|
136
|
+
const { prefix, local } = splitName(tagOf(child));
|
|
137
|
+
const childScope = localScope.extend(attrsOf(child));
|
|
138
|
+
const uri = childScope.resolve(prefix);
|
|
139
|
+
const ns = uri === undefined ? undefined : URI_TO_NS[uri];
|
|
140
|
+
const field = descriptor.fields.find((candidate) => candidate.name === local && (ns === undefined || candidate.ns === ns));
|
|
141
|
+
if (!field) {
|
|
142
|
+
if (options.unknownElements !== 'ignore') {
|
|
143
|
+
issues.push({
|
|
144
|
+
path: path ? `${path}.${local}` : local,
|
|
145
|
+
code: 'UNKNOWN_ELEMENT',
|
|
146
|
+
message: `is not declared on ${descriptor.name}`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const fieldPath = path ? `${path}.${field.name}` : field.name;
|
|
152
|
+
const primitive = XS_PRIMITIVES[field.type];
|
|
153
|
+
const value = primitive
|
|
154
|
+
? readPrimitive(primitive, textOf(child), fieldPath, issues)
|
|
155
|
+
: readComplex(child, field.type, childScope, fieldPath, issues, options);
|
|
156
|
+
if (field.repeated) {
|
|
157
|
+
result[field.name] ??= [];
|
|
158
|
+
result[field.name].push(value);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
result[field.name] = value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
function readSimpleContent(node, descriptor, path, issues) {
|
|
167
|
+
const contentDescriptor = descriptor.contentType ? TYPES[descriptor.contentType] : undefined;
|
|
168
|
+
const kind = XS_PRIMITIVES[descriptor.contentType ?? ''] ??
|
|
169
|
+
(contentDescriptor?.kind === 'simple' ? contentDescriptor.primitive : 'string');
|
|
170
|
+
const result = {
|
|
171
|
+
value: readPrimitive(kind, textOf(node), `${path}.value`, issues),
|
|
172
|
+
};
|
|
173
|
+
const attributes = attrsOf(node);
|
|
174
|
+
for (const attribute of descriptor.attributes ?? []) {
|
|
175
|
+
const raw = attributes[`@${attribute.name}`];
|
|
176
|
+
if (raw === undefined) {
|
|
177
|
+
if (attribute.required) {
|
|
178
|
+
issues.push({
|
|
179
|
+
path: `${path}@${attribute.name}`,
|
|
180
|
+
code: 'REQUIRED',
|
|
181
|
+
message: 'attribute is required',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const attributeDescriptor = TYPES[attribute.type];
|
|
187
|
+
const attributeKind = XS_PRIMITIVES[attribute.type] ??
|
|
188
|
+
(attributeDescriptor?.kind === 'simple' ? attributeDescriptor.primitive : 'string');
|
|
189
|
+
result[attribute.name] = readPrimitive(attributeKind, raw, `${path}@${attribute.name}`, issues);
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
function readPrimitive(kind, raw, path, issues) {
|
|
194
|
+
switch (kind) {
|
|
195
|
+
case 'boolean':
|
|
196
|
+
if (raw === 'true' || raw === '1')
|
|
197
|
+
return true;
|
|
198
|
+
if (raw === 'false' || raw === '0')
|
|
199
|
+
return false;
|
|
200
|
+
issues.push({ path, code: 'EXPECTED_BOOLEAN', message: `expected a boolean, got "${raw}"` });
|
|
201
|
+
return undefined;
|
|
202
|
+
case 'integer': {
|
|
203
|
+
if (!/^-?\d+$/.test(raw)) {
|
|
204
|
+
issues.push({
|
|
205
|
+
path,
|
|
206
|
+
code: 'EXPECTED_INTEGER',
|
|
207
|
+
message: `expected an integer, got "${raw}"`,
|
|
208
|
+
});
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
const parsed = Number(raw);
|
|
212
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
213
|
+
issues.push({
|
|
214
|
+
path,
|
|
215
|
+
code: 'INTEGER_OUT_OF_RANGE',
|
|
216
|
+
message: `${raw} exceeds the safe integer range`,
|
|
217
|
+
});
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
return parsed;
|
|
221
|
+
}
|
|
222
|
+
case 'base64Binary':
|
|
223
|
+
// XML permits whitespace inside base64; NAV's own samples wrap it.
|
|
224
|
+
return raw.replace(/\s+/g, '');
|
|
225
|
+
default:
|
|
226
|
+
// Decimals stay strings deliberately, see the generator's TS_PRIMITIVES.
|
|
227
|
+
return raw;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/xml/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAwB,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,aAAa,GAId,MAAM,iBAAiB,CAAC;AAEzB,MAAM,SAAS,GAA0B,MAAM,CAAC,WAAW,CACzD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAY,CAAC,CAAC,CAC/C,CAAC;AAK3B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,KAAK;IACvB,mBAAmB,EAAE,GAAG;IACxB,UAAU,EAAE,IAAI;IAChB,uEAAuE;IACvE,+DAA+D;IAC/D,aAAa,EAAE,KAAK;IACpB,mBAAmB,EAAE,KAAK;CAC3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AK,GAAG;gBAAE,OAAO,IAAI,CAAC;YAC/C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;YACjD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,4BAA4B,GAAG,GAAG,EAAE,CAAC,CAAC;YAC7F,OAAO,SAAS,CAAC;QAEnB,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI;oBACJ,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EAAE,6BAA6B,GAAG,GAAG;iBAC7C,CAAC,CAAC;gBACH,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI;oBACJ,IAAI,EAAE,sBAAsB;oBAC5B,OAAO,EAAE,GAAG,GAAG,iCAAiC;iBACjD,CAAC,CAAC;gBACH,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,KAAK,cAAc;YACjB,mEAAmE;YACnE,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEjC;YACE,yEAAyE;YACzE,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type NsKey } from './descriptor.js';
|
|
2
|
+
/** Prefixes used when a namespace is not the document's default. */
|
|
3
|
+
export declare const NS_PREFIXES: Record<NsKey, string>;
|
|
4
|
+
export interface SerializeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Indentation for pretty printing, or `false` for a single line.
|
|
7
|
+
*
|
|
8
|
+
* Defaults to `false`: these documents go over the wire, and for
|
|
9
|
+
* `manageInvoice` the invoice payload is hashed and base64 encoded, so
|
|
10
|
+
* there is nothing to be gained from whitespace. Pass `'\t'` or two spaces
|
|
11
|
+
* when a human has to read the result.
|
|
12
|
+
*/
|
|
13
|
+
indent?: string | false;
|
|
14
|
+
/** Emit the XML declaration. Defaults to `true`. */
|
|
15
|
+
declaration?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Serialise a document from its root element name.
|
|
19
|
+
*
|
|
20
|
+
* Element order, namespaces and cardinality all come from the generated
|
|
21
|
+
* descriptors, so the output follows the XSD's sequence order — which is what
|
|
22
|
+
* NAV validates against.
|
|
23
|
+
*
|
|
24
|
+
* @param rootName root element name, e.g. `InvoiceData` or `ManageInvoiceRequest`
|
|
25
|
+
* @param value the document, shaped like the generated type of that root
|
|
26
|
+
*/
|
|
27
|
+
export declare function serializeDocument(rootName: string, value: unknown, options?: SerializeOptions): string;
|
|
28
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/xml/write.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,KAAK,EAEX,MAAM,iBAAiB,CAAC;AAEzB,oEAAoE;AACpE,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAO7C,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAkCR"}
|