@endevops/peppol-schema 0.1.2 → 0.1.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.
Files changed (174) hide show
  1. package/README.md +5 -5
  2. package/dist/constants.d.ts +131 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +114 -1
  5. package/dist/constants.js.map +1 -1
  6. package/dist/{index-BBzPjq7o.d.ts → index-CILtZytZ.d.ts} +1710 -669
  7. package/dist/index-CILtZytZ.d.ts.map +1 -0
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +1234 -187
  10. package/dist/index.js.map +1 -1
  11. package/dist/invoice-response-code-not-needs-schema-DNrfKYLh.js +36 -0
  12. package/dist/invoice-response-code-not-needs-schema-DNrfKYLh.js.map +1 -0
  13. package/dist/invoice-response-codes.d.ts +28 -0
  14. package/dist/invoice-response-codes.d.ts.map +1 -1
  15. package/dist/invoice-response-codes.js +11 -1
  16. package/dist/invoice-response-codes.js.map +1 -1
  17. package/dist/{is-valid-abn-160i38PG.js → is-valid-abn-D7eSygBG.js} +115 -2
  18. package/dist/is-valid-abn-D7eSygBG.js.map +1 -0
  19. package/dist/{is-valid-mod97-0208-CzMOXMO-.js → is-valid-mod97-0208-CjR324eG.js} +11 -1
  20. package/dist/is-valid-mod97-0208-CjR324eG.js.map +1 -0
  21. package/dist/message-level-response-profile-id-B9c0A7S_.js +27 -0
  22. package/dist/message-level-response-profile-id-B9c0A7S_.js.map +1 -0
  23. package/dist/{nodable-parser-CyDZtLCK.js → nodable-parser-CupS2H55.js} +31 -1
  24. package/dist/nodable-parser-CupS2H55.js.map +1 -0
  25. package/dist/schematron.d.ts +57 -1
  26. package/dist/schematron.d.ts.map +1 -1
  27. package/dist/schematron.js +453 -2
  28. package/dist/schematron.js.map +1 -1
  29. package/dist/validations.d.ts +132 -0
  30. package/dist/validations.d.ts.map +1 -1
  31. package/dist/validations.js +11 -2
  32. package/dist/validations.js.map +1 -1
  33. package/dist/values.d.ts +67 -2
  34. package/dist/values.d.ts.map +1 -1
  35. package/dist/xml.d.ts +30 -0
  36. package/dist/xml.d.ts.map +1 -1
  37. package/dist/xml.js +10 -1
  38. package/dist/xml.js.map +1 -1
  39. package/package.json +3 -2
  40. package/src/constants/credit-note-doctype-id.ts +9 -0
  41. package/src/constants/credit-note-process-id.ts +9 -0
  42. package/src/constants/document-scheme.ts +9 -0
  43. package/src/constants/invoice-doctype-id.ts +9 -0
  44. package/src/constants/invoice-process-id.ts +10 -0
  45. package/src/constants/invoice-response-doctype-id.ts +10 -0
  46. package/src/constants/invoice-response-process-id.ts +9 -0
  47. package/src/constants/invoice-response-profile-id.ts +9 -0
  48. package/src/constants/message-level-response-doctype-id.ts +10 -0
  49. package/src/constants/message-level-response-process-id.ts +9 -0
  50. package/src/constants/message-level-response-profile-id.ts +9 -0
  51. package/src/constants/participant-scheme.ts +10 -0
  52. package/src/constants/process-scheme.ts +9 -0
  53. package/src/constants/transport-profile.ts +10 -0
  54. package/src/invoice-response-codes/invoice-response-code-needs-schema.ts +9 -0
  55. package/src/invoice-response-codes/invoice-response-code-not-needs-schema.ts +9 -0
  56. package/src/invoice-response-codes/invoice-response-codes-order.ts +10 -0
  57. package/src/peppol-validations/add-piva.ts +12 -0
  58. package/src/peppol-validations/check-cf.ts +11 -0
  59. package/src/peppol-validations/check-cf16.ts +12 -0
  60. package/src/peppol-validations/check-piva-se-it.ts +11 -0
  61. package/src/peppol-validations/check-piva.ts +11 -0
  62. package/src/peppol-validations/check-se-orgnr.ts +9 -0
  63. package/src/peppol-validations/greek-tin-verification.ts +9 -0
  64. package/src/peppol-validations/is-valid-abn.ts +9 -0
  65. package/src/peppol-validations/is-valid-gln.ts +10 -0
  66. package/src/peppol-validations/is-valid-iban.ts +10 -0
  67. package/src/peppol-validations/is-valid-mod11.ts +9 -0
  68. package/src/peppol-validations/is-valid-mod97-0208.ts +10 -0
  69. package/src/peppol-validations/luhn-check.ts +9 -0
  70. package/src/schemas/fields/default-customization-id.ts +9 -0
  71. package/src/schemas/fields/default-profile-id.ts +9 -0
  72. package/src/schemas/fields/peppol-additional-document-reference-schema.ts +41 -2
  73. package/src/schemas/fields/peppol-address-schema.ts +25 -2
  74. package/src/schemas/fields/peppol-allowance-charge-schema.ts +65 -9
  75. package/src/schemas/fields/peppol-amount-schema.ts +15 -2
  76. package/src/schemas/fields/peppol-base-line-schema.ts +12 -2
  77. package/src/schemas/fields/peppol-billing-reference-schema.ts +13 -0
  78. package/src/schemas/fields/peppol-binary-object-schema.ts +12 -4
  79. package/src/schemas/fields/peppol-contact-schema.ts +11 -0
  80. package/src/schemas/fields/peppol-credit-note-line-schema.ts +7 -2
  81. package/src/schemas/fields/peppol-delivery-schema.ts +44 -2
  82. package/src/schemas/fields/peppol-identifier-schema.ts +8 -0
  83. package/src/schemas/fields/peppol-invoice-line-period-schema.ts +11 -0
  84. package/src/schemas/fields/peppol-invoice-line-schema.ts +9 -2
  85. package/src/schemas/fields/peppol-invoice-period-schema.ts +2 -2
  86. package/src/schemas/fields/peppol-item-classification-schema.ts +2 -2
  87. package/src/schemas/fields/peppol-line-allowance-charge-schema.ts +57 -9
  88. package/src/schemas/fields/peppol-line-item-schema.ts +69 -4
  89. package/src/schemas/fields/peppol-line-price-allowance-charge-schema.ts +20 -0
  90. package/src/schemas/fields/peppol-line-price-schema.ts +2 -0
  91. package/src/schemas/fields/peppol-order-reference-schema.ts +2 -0
  92. package/src/schemas/fields/peppol-party-base-schema.ts +36 -4
  93. package/src/schemas/fields/peppol-party-legal-entity-schema.ts +13 -0
  94. package/src/schemas/fields/peppol-party-tax-scheme-schema.ts +5 -0
  95. package/src/schemas/fields/peppol-payee-party-schema.ts +2 -2
  96. package/src/schemas/fields/peppol-payment-means-schema.ts +62 -2
  97. package/src/schemas/fields/peppol-payment-terms-schema.ts +2 -0
  98. package/src/schemas/fields/peppol-quantity-schema.ts +4 -2
  99. package/src/schemas/fields/peppol-reference-schema.ts +20 -1
  100. package/src/schemas/fields/peppol-tax-category-schema.ts +12 -2
  101. package/src/schemas/fields/peppol-tax-representative-schema.ts +5 -0
  102. package/src/schemas/fields/peppol-tax-subtotal-category-schema.ts +3 -0
  103. package/src/schemas/fields/peppol-tax-subtotal-schema.ts +2 -0
  104. package/src/schemas/fields/peppol-tax-totals-base-schema.ts +5 -0
  105. package/src/schemas/peppol-billing-base-schema.ts +47 -7
  106. package/src/schemas/peppol-credit-note-schema.ts +2 -2
  107. package/src/schemas/peppol-document-response-document-reference-schema.ts +15 -2
  108. package/src/schemas/peppol-document-response-document-schema.ts +8 -3
  109. package/src/schemas/peppol-document-response-line-response-content-schema.ts +22 -2
  110. package/src/schemas/peppol-document-response-line-response-schema.ts +26 -0
  111. package/src/schemas/peppol-document-schema.ts +74 -9
  112. package/src/schemas/peppol-invoice-response-document-actual-response-schema.ts +58 -5
  113. package/src/schemas/peppol-invoice-response-document-actual-response-status-schema.ts +25 -2
  114. package/src/schemas/peppol-invoice-response-schema.ts +57 -4
  115. package/src/schemas/peppol-invoice-response-status-reason-code-schema.ts +37 -10
  116. package/src/schemas/peppol-invoice-schema.ts +30 -2
  117. package/src/schemas/peppol-message-level-response-document-response-schema.ts +10 -0
  118. package/src/schemas/peppol-message-level-response-party-schema.ts +10 -0
  119. package/src/schemas/peppol-message-level-response-schema.ts +18 -0
  120. package/src/schemas/utils/format-quantity-with-unit.ts +19 -0
  121. package/src/schemas/utils/get-credit-note-type-code-description.ts +12 -0
  122. package/src/schemas/utils/get-invoice-type-code-description.ts +12 -0
  123. package/src/schemas/utils/is-valid-credit-note-type-code.ts +13 -0
  124. package/src/schemas/utils/is-valid-invoice-type-code.ts +13 -0
  125. package/src/schemas/utils/is-valid-process.ts +13 -0
  126. package/src/schemas/utils/peppol-base-64-schema.ts +14 -4
  127. package/src/schemas/utils/peppol-vat-regex-schema.ts +38 -30
  128. package/src/schemas/utils/peppol-xsd-time-schema.ts +12 -2
  129. package/src/schemas/utils/quantity-unit-code-to-intl-unit.ts +34 -0
  130. package/src/schemas/values/additional-document-reference-code-schema.ts +9 -15
  131. package/src/schemas/values/allowance-charge-reason-code-schema.ts +12 -14
  132. package/src/schemas/values/application-response-type-code-schema.ts +10 -14
  133. package/src/schemas/values/charge-reason-code-schema.ts +12 -14
  134. package/src/schemas/values/credit-note-type-code-schema.ts +8 -14
  135. package/src/schemas/values/currency-code-schema.ts +13 -16
  136. package/src/schemas/values/document-type-schemes-schema.ts +9 -5
  137. package/src/schemas/values/document-type-values-schema.ts +5 -6
  138. package/src/schemas/values/duty-tax-fee-category-schema.ts +15 -13
  139. package/src/schemas/values/electronic-codes-schema.ts +10 -12
  140. package/src/schemas/values/icd-codes-schema.ts +8 -12
  141. package/src/schemas/values/invoice-status-code-schema.ts +10 -12
  142. package/src/schemas/values/invoice-type-code-schema.ts +10 -12
  143. package/src/schemas/values/item-classification-codes-schema.ts +10 -12
  144. package/src/schemas/values/mime-codes-schema.ts +12 -14
  145. package/src/schemas/values/op-status-action-schema.ts +10 -12
  146. package/src/schemas/values/op-status-reason-schema.ts +10 -12
  147. package/src/schemas/values/participant-identifier-code-schema.ts +10 -13
  148. package/src/schemas/values/payment-means-code-schema.ts +10 -12
  149. package/src/schemas/values/peppol-country-code-schema.ts +10 -9
  150. package/src/schemas/values/peppol-document-type-code-schema.ts +10 -12
  151. package/src/schemas/values/peppol-document-type-schema.ts +12 -21
  152. package/src/schemas/values/peppol-process-schema.ts +19 -15
  153. package/src/schemas/values/process-from-document-type-schema.ts +3 -3
  154. package/src/schemas/values/quantity-unit-codes-schema.ts +10 -12
  155. package/src/schemas/values/vat-date-code-schema.ts +12 -5
  156. package/src/schemas/values/vatex-code-schema.ts +8 -12
  157. package/src/schematron/errors.ts +14 -0
  158. package/src/schematron/helpers.ts +451 -0
  159. package/src/schematron/run-all-rules.ts +10 -0
  160. package/src/schematron/schematron.ts +25 -0
  161. package/src/xml/builder-options.ts +9 -0
  162. package/src/xml/common-xml-options.ts +9 -0
  163. package/src/xml/nodable-parser.ts +12 -0
  164. package/src/xml/parser-options.ts +9 -0
  165. package/dist/index-BBzPjq7o.d.ts.map +0 -1
  166. package/dist/invoice-response-code-not-needs-schema-p_RKKNLc.js +0 -18
  167. package/dist/invoice-response-code-not-needs-schema-p_RKKNLc.js.map +0 -1
  168. package/dist/is-valid-abn-160i38PG.js.map +0 -1
  169. package/dist/is-valid-mod97-0208-CzMOXMO-.js.map +0 -1
  170. package/dist/message-level-response-profile-id-DBpOW91B.js +0 -9
  171. package/dist/message-level-response-profile-id-DBpOW91B.js.map +0 -1
  172. package/dist/nodable-parser-CyDZtLCK.js.map +0 -1
  173. package/dist/vat-dates.generated-CxFvt7m3.d.ts +0 -68
  174. package/dist/vat-dates.generated-CxFvt7m3.d.ts.map +0 -1
@@ -1,5 +1,15 @@
1
+ /**
2
+ * @description PEPPOL AS4 transport profile identifier for transport profile version 2.0.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * TRANSPORT_PROFILE; // 'peppol-transport-as4-v2_0'
7
+ * ```;
8
+ */
1
9
  export const TRANSPORT_PROFILE = 'peppol-transport-as4-v2_0' as const;
2
10
  /**
11
+ * @description Deprecated alias of {@link TRANSPORT_PROFILE}.
12
+ *
3
13
  * @deprecated
4
14
  */
5
15
  export const transportProfile = TRANSPORT_PROFILE;
@@ -1 +1,10 @@
1
+ /**
2
+ * @description Invoice response status codes that require a clarification. The codes are Under query (UQ), Rejected (RE), and Conditionally accepted (CA).
3
+ * Consumed by {@link withStatusCodes}, where the `status` array must contain at least one entry.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * invoiceResponseCodeNeedsSchema; // ['UQ', 'RE', 'CA']
8
+ * ```;
9
+ */
1
10
  export const invoiceResponseCodeNeedsSchema = ['UQ', 'RE', 'CA'] as const;
@@ -1 +1,10 @@
1
+ /**
2
+ * @description Invoice response status codes that do not require a clarification. The codes are Message acknowledgement (AB), Accepted (AP), In process (IP), and
3
+ * Paid (PD). Consumed by {@link withoutStatusCodes}, where `status` is optional.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * invoiceResponseCodeNotNeedsSchema; // ['AB', 'AP', 'IP', 'PD']
8
+ * ```;
9
+ */
1
10
  export const invoiceResponseCodeNotNeedsSchema = ['AB', 'AP', 'IP', 'PD'] as const;
@@ -1,5 +1,15 @@
1
1
  import type { InvoiceStatusCodesKeys } from '#/values/invoice-status-codes.generated';
2
2
 
3
+ /**
4
+ * @description Map of allowed status transitions for an invoice response, keyed by the current status code. Each value lists the status codes that may follow the
5
+ * key. Keys and values are {@link InvoiceStatusCodesKeys}. The terminal statuses PD and RE map to empty arrays.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * invoiceResponseCodesOrder.UQ; // ['CA', 'AP', 'RE']
10
+ * invoiceResponseCodesOrder.PD; // []
11
+ * ```;
12
+ */
3
13
  export const invoiceResponseCodesOrder: Record<InvoiceStatusCodesKeys, Array<InvoiceStatusCodesKeys>> = {
4
14
  AB: ['IP', 'UQ', 'AP', 'CA', 'PD', 'RE'],
5
15
  AP: ['PD'],
@@ -2,6 +2,18 @@
2
2
 
3
3
  /**
4
4
  * @description Helper function for calculating weighted sum for Italian PIVA validation.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * addPIVA('123', 0); // 8
9
+ * ```;
10
+ *
11
+ * @param arg - The digit string to sum, processed one character at a time.
12
+ * @param pari - Parity flag toggled at each recursion; `1` maps the digit through the `0246813579` table, `0` keeps it as is.
13
+ *
14
+ * @returns The weighted sum, or `0` when `arg` contains a non-digit.
15
+ *
16
+ * @see {@link checkPIVA}
5
17
  */
6
18
  export function addPIVA(arg: string, pari: number): number {
7
19
  if (!/^\d+$/.test(arg)) return 0;
@@ -3,6 +3,17 @@ import { normalizeSpace } from './normalize-space.ts';
3
3
 
4
4
  /**
5
5
  * @description Validates both 16 and 11 character Italian fiscal codes.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * checkCF('RSSMRA80A01H501U'); // true
10
+ * ```;
11
+ *
12
+ * @param arg - The fiscal code to validate. Whitespace is normalised first.
13
+ *
14
+ * @returns `true` when the normalised code is a valid 16 character personal fiscal code or an 11 digit VAT code, otherwise `false`.
15
+ *
16
+ * @see {@link checkCF16}
6
17
  */
7
18
  export function checkCF(arg: string): boolean {
8
19
  const s = normalizeSpace(arg);
@@ -2,6 +2,18 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Validates 16-character Italian fiscal codes.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * checkCF16('RSSMRA80A01H501U'); // true
9
+ * ```;
10
+ *
11
+ * @param arg - The fiscal code to validate. Whitespace is normalised first.
12
+ *
13
+ * @returns `true` when the normalised code is 16 characters and matches `{6 letters}{2 digits}{letter}{2 digits}{letter}{3 digits}{letter}`,
14
+ * otherwise `false`.
15
+ *
16
+ * @see {@link checkCF}
5
17
  */
6
18
  export function checkCF16(arg: string): boolean {
7
19
  const s = normalizeSpace(arg);
@@ -2,6 +2,17 @@ import { checkPIVA } from './check-piva.ts';
2
2
 
3
3
  /**
4
4
  * @description Validates Italian VAT numbers with IT prefix.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * checkPIVAseIT('IT00743110157'); // true
9
+ * ```;
10
+ *
11
+ * @param arg - The VAT identifier including its two letter country prefix.
12
+ *
13
+ * @returns `true` when the prefix is not `IT`, or when the 11 digit Italian part passes {@link checkPIVA}; otherwise `false`.
14
+ *
15
+ * @see {@link checkPIVA}
5
16
  */
6
17
  export function checkPIVAseIT(arg: string): boolean {
7
18
  const paese = arg.substring(0, 2);
@@ -2,6 +2,17 @@ import { addPIVA } from './add-piva.ts';
2
2
 
3
3
  /**
4
4
  * @description Validates Italian VAT numbers (PIVA)
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * checkPIVA('00743110157'); // 0
9
+ * ```;
10
+ *
11
+ * @param arg - The Italian VAT number without the `IT` prefix.
12
+ *
13
+ * @returns `0` when valid, otherwise the non-zero remainder of {@link addPIVA}, or `1` when `arg` contains a non-digit.
14
+ *
15
+ * @see {@link addPIVA}
5
16
  */
6
17
  export function checkPIVA(arg: string): number {
7
18
  if (!/^\d+$/.test(arg)) return 1;
@@ -2,6 +2,15 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Validates Swedish organization numbers (0007)
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * checkSEOrgnr('5560160680'); // true
9
+ * ```;
10
+ *
11
+ * @param number - The organization number to validate. Whitespace is normalised first.
12
+ *
13
+ * @returns `true` when the normalised number is 10 digits and its Luhn check digit matches, otherwise `false`.
5
14
  */
6
15
  export function checkSEOrgnr(number: string): boolean {
7
16
  const s = normalizeSpace(number);
@@ -1,5 +1,14 @@
1
1
  /**
2
2
  * @description Greek TIN verification.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * greekTinVerification('123456783'); // true
7
+ * ```;
8
+ *
9
+ * @param val - The nine digit Greek tax identification number.
10
+ *
11
+ * @returns `true` when the value is nine digits and the computed checksum matches the last digit, otherwise `false`.
3
12
  */
4
13
  export function greekTinVerification(val: string): boolean {
5
14
  if (!/^\d{9}$/.test(val)) return false;
@@ -2,6 +2,15 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Australian Business Number (ABN) validation.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isValidABN('51 824 753 556'); // true
9
+ * ```;
10
+ *
11
+ * @param val - The ABN to validate. Whitespace is normalised first.
12
+ *
13
+ * @returns `true` when the normalised value is 11 digits and the weighted checksum is divisible by 89, otherwise `false`.
5
14
  */
6
15
  export function isValidABN(val: string): boolean {
7
16
  const s = normalizeSpace(val);
@@ -1,5 +1,15 @@
1
1
  /**
2
2
  * @description [GLN](https://en.wikipedia.org/wiki/Global_Location_Number) check (GS1)
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * isValidGLN('1234567890128'); // { success: true }
7
+ * ```;
8
+ *
9
+ * @param val - The GLN to validate. Whitespace is stripped first.
10
+ *
11
+ * @returns `{ success: true }` when the computed check digit matches the last digit, otherwise `{ success: false, expected, actual }` with the
12
+ * computed and supplied check digits.
3
13
  */
4
14
  export function isValidGLN(val: string): { success: true } | { success: false; expected: number; actual: number } {
5
15
  const value = (val ?? '').replace(/\s+/g, '');
@@ -2,6 +2,16 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description IBAN validation using mod 97 algorithm.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isValidIBAN('GB82 WEST 1234 5698 7654 32'); // true
9
+ * ```;
10
+ *
11
+ * @param iban - The IBAN to validate, with or without spaces.
12
+ *
13
+ * @returns `true` when the normalised value matches the `{2 letters}{2 digits}{up to 30 alphanumerics}` shape and its mod 97 remainder is 1,
14
+ * otherwise `false`.
5
15
  */
6
16
  export function isValidIBAN(iban: string): boolean {
7
17
  const s = normalizeSpace(iban).replace(/[ \t\r\n]/g, '');
@@ -2,6 +2,15 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Validates Norwegian organization numbers using mod11 algorithm.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isValidMod11('923609016'); // true
9
+ * ```;
10
+ *
11
+ * @param val - The organization number to validate. Whitespace is normalised first.
12
+ *
13
+ * @returns `true` when the normalised value is at least two digits and its mod 11 check digit matches, otherwise `false`.
5
14
  */
6
15
  export function isValidMod11(val: string): boolean {
7
16
  const s = normalizeSpace(val);
@@ -2,6 +2,16 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Belgian enterprise number validation (mod 97-0208)
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isValidMod97_0208('0123456749'); // { success: true }
9
+ * ```;
10
+ *
11
+ * @param val - The enterprise number to validate. Whitespace is normalised first.
12
+ *
13
+ * @returns `{ success: true }` when the last two digits equal `97 - (first eight digits % 97)`, otherwise `{ success: false, expected, actual }` with
14
+ * the computed and supplied check digits.
5
15
  */
6
16
  export function isValidMod97_0208(val: string): { success: true } | { success: false; expected: number; actual: number } {
7
17
  const s = normalizeSpace(val);
@@ -2,6 +2,15 @@ import { normalizeSpace } from './normalize-space.ts';
2
2
 
3
3
  /**
4
4
  * @description Luhn algorithm check (used for credit card validation)
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * luhnCheck('4242424242424242'); // true
9
+ * ```;
10
+ *
11
+ * @param number - The numeric string to check. Whitespace is normalised first.
12
+ *
13
+ * @returns `true` when the value contains only digits and its Luhn checksum is divisible by 10, otherwise `false`.
5
14
  */
6
15
  export function luhnCheck(number: string): boolean {
7
16
  const s = normalizeSpace(number);
@@ -1 +1,10 @@
1
+ /**
2
+ * @description The default PEPPOL BIS Billing 3.0 customization identifier, which identifies the EN 16931 compliant billing rule set. Used as the decoding default
3
+ * for the `customizationId` field of {@link PeppolBillingBase}.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * DEFAULT_CUSTOMIZATION_ID; // 'urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0'
8
+ * ```;
9
+ */
1
10
  export const DEFAULT_CUSTOMIZATION_ID = 'urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0' as const;
@@ -1 +1,10 @@
1
+ /**
2
+ * @description The default PEPPOL BIS Billing 3.0 profile identifier, which identifies the billing process the document follows. Used as the decoding default for
3
+ * the `profileId` field of {@link PeppolBillingBase}.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * DEFAULT_PROFILE_ID; // 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'
8
+ * ```;
9
+ */
1
10
  export const DEFAULT_PROFILE_ID = 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0' as const;
@@ -3,8 +3,19 @@ import { Schema } from 'effect';
3
3
  import { PeppolBinaryObject } from '#/schemas/fields/peppol-binary-object-schema.ts';
4
4
  import { PeppolIdentifier } from '#/schemas/fields/peppol-identifier-schema.ts';
5
5
  import { opaque } from '#/schemas/utils/opaque.ts';
6
- import { additionalDocumentReferenceCodeSchema } from '#/schemas/values/additional-document-reference-code-schema.ts';
6
+ import { PeppolAdditionalDocumentReferenceCode } from '#/schemas/values/additional-document-reference-code-schema.ts';
7
7
 
8
+ /**
9
+ * @description A reference to a supporting document that is stored outside the Invoice, identified by a URI. Wraps the `cac:ExternalReference` element of an
10
+ * attachment group.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * { uri: 'http://www.example.com/index.html' }
15
+ * ```;
16
+ *
17
+ * @see {@link PeppolAttachment}
18
+ */
8
19
  export class PeppolAttachmentExternalReference extends opaque<PeppolAttachmentExternalReference>()(
9
20
  Schema.Struct({
10
21
  /**
@@ -22,6 +33,23 @@ export class PeppolAttachmentExternalReference extends opaque<PeppolAttachmentEx
22
33
  })
23
34
  ) {}
24
35
 
36
+ /**
37
+ * @description The attachment of a supporting document to the Invoice, either embedded as a Base64 binary object or referenced by URI. Wraps the `cac:Attachment`
38
+ * element of an additional supporting document.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * {
43
+ * embeddedDocumentBinaryObject: {
44
+ * content: 'aHR0cHM6Ly90ZXN0LXZlZmEuZGlmaS5uby9wZXBwb2xiaXM=',
45
+ * mimeCode: 'text/csv',
46
+ * filename: 'Hours - spent.csv'
47
+ * }
48
+ * }
49
+ * ```;
50
+ *
51
+ * @see {@link PeppolAdditionalDocumentReference}
52
+ */
25
53
  export class PeppolAttachment extends opaque<PeppolAttachment>()(
26
54
  Schema.Struct({
27
55
  /**
@@ -46,6 +74,17 @@ export class PeppolAttachment extends opaque<PeppolAttachment>()(
46
74
  })
47
75
  ) {}
48
76
 
77
+ /**
78
+ * @description The identifier of an additional supporting document, an invoiced object reference or a project reference, together with an optional identification
79
+ * scheme identifier.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * { id: '9873242' }
84
+ * ```;
85
+ *
86
+ * @see {@link PeppolAdditionalDocumentReference}
87
+ */
49
88
  export class PeppolId extends opaque<PeppolId>()(
50
89
  Schema.Struct({
51
90
  /**
@@ -64,7 +103,7 @@ export class PeppolId extends opaque<PeppolId>()(
64
103
  *
65
104
  * @name `@schemeID`
66
105
  */
67
- schemeId: Schema.optional(additionalDocumentReferenceCodeSchema),
106
+ schemeId: Schema.optional(PeppolAdditionalDocumentReferenceCode),
68
107
  })
69
108
  ) {}
70
109
 
@@ -1,8 +1,18 @@
1
1
  import { Schema } from 'effect';
2
2
 
3
3
  import { opaque } from '#/schemas/utils/opaque.ts';
4
- import { peppolCountryCodeSchema } from '#/schemas/values/peppol-country-code-schema.ts';
4
+ import { PeppolCountryCodeValue } from '#/schemas/values/peppol-country-code-schema.ts';
5
5
 
6
+ /**
7
+ * @description An additional address line that supplements the main address line. Wraps the `cac:AddressLine` element, whose `cbc:Line` value carries the text.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * { line: 'Building 23' }
12
+ * ```;
13
+ *
14
+ * @see {@link PeppolAddress}
15
+ */
6
16
  export class PeppolAddressLine extends opaque<PeppolAddressLine>()(
7
17
  Schema.Struct({
8
18
  /**
@@ -16,6 +26,16 @@ export class PeppolAddressLine extends opaque<PeppolAddressLine>()(
16
26
  })
17
27
  ) {}
18
28
 
29
+ /**
30
+ * @description The country of an address, expressed as a two-letter ISO 3166-1 alpha-2 code. Wraps the `cac:Country` element and its `cbc:IdentificationCode`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * { identificationCode: 'GB' }
35
+ * ```;
36
+ *
37
+ * @see {@link PeppolAddress}
38
+ */
19
39
  export class PeppolCountryCode extends opaque<PeppolCountryCode>()(
20
40
  Schema.Struct({
21
41
  /**
@@ -28,11 +48,14 @@ export class PeppolCountryCode extends opaque<PeppolCountryCode>()(
28
48
  *
29
49
  * @name `cbc:IdentificationCode`
30
50
  */
31
- identificationCode: peppolCountryCodeSchema,
51
+ identificationCode: PeppolCountryCodeValue,
32
52
  })
33
53
  ) {}
34
54
 
35
55
  /**
56
+ * @description The postal address of a party, used for the seller, buyer, payee and delivery locations. Carries the street lines, city, postal zone, country
57
+ * subdivision, country code and optional additional address lines.
58
+ *
36
59
  * @summary Postal address
37
60
  *
38
61
  * @name `cac:PostalAddress`
@@ -3,10 +3,20 @@ import { Effect, Schema } from 'effect';
3
3
  import { BaseLineAllowanceCharge } from '#/schemas/fields/peppol-line-allowance-charge-schema.ts';
4
4
  import { PeppolTaxCategory } from '#/schemas/fields/peppol-tax-category-schema.ts';
5
5
  import { opaque } from '#/schemas/utils/opaque.ts';
6
- import { allowanceChargeReasonCodeSchema } from '#/schemas/values/allowance-charge-reason-code-schema.ts';
7
- import { chargeReasonCodeSchema } from '#/schemas/values/charge-reason-code-schema.ts';
8
- import { peppolDutyTaxFeeCategorySchema } from '#/schemas/values/duty-tax-fee-category-schema.ts';
6
+ import { PeppolAllowanceChargeReasonCode } from '#/schemas/values/allowance-charge-reason-code-schema.ts';
7
+ import { PeppolChargeReasonCode } from '#/schemas/values/charge-reason-code-schema.ts';
8
+ import { PeppolDutyTaxFeeCategoryCode } from '#/schemas/values/duty-tax-fee-category-schema.ts';
9
9
 
10
+ /**
11
+ * @description The identifier of the tax scheme that applies to a document level allowance or charge. Defaults to `VAT` when the value is absent.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * { id: 'VAT' }
16
+ * ```;
17
+ *
18
+ * @see {@link PeppolTaxCategory}
19
+ */
10
20
  export class PeppolTaxCategoryTaxSchemeId extends opaque<PeppolTaxCategoryTaxSchemeId>()(
11
21
  Schema.Struct({
12
22
  /**
@@ -18,6 +28,22 @@ export class PeppolTaxCategoryTaxSchemeId extends opaque<PeppolTaxCategoryTaxSch
18
28
  })
19
29
  ) {}
20
30
 
31
+ /**
32
+ * @description Shared fields for a document level allowance or charge. Combines the common line allowance and charge fields with the tax category that applies to
33
+ * the document level amount.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * {
38
+ * amount: { value: 25, currencyId: 'EUR' },
39
+ * chargeIndicator: true,
40
+ * allowanceChargeReason: 'Insurance',
41
+ * taxCategory: { id: 'S', percent: 25, taxSchemeId: { id: 'VAT' } }
42
+ * }
43
+ * ```;
44
+ *
45
+ * @see {@link PeppolAllowanceCharge}
46
+ */
21
47
  export class BaseAllowanceCharge extends opaque<BaseAllowanceCharge>()(
22
48
  Schema.Struct({
23
49
  ...BaseLineAllowanceCharge.fields,
@@ -36,7 +62,7 @@ export class BaseAllowanceCharge extends opaque<BaseAllowanceCharge>()(
36
62
  *
37
63
  * @name `cbc:ID`
38
64
  */
39
- id: peppolDutyTaxFeeCategorySchema,
65
+ id: PeppolDutyTaxFeeCategoryCode,
40
66
  /**
41
67
  * @description The VAT rate, represented as percentage that applies to the document level allowance or charge.
42
68
  *
@@ -57,13 +83,24 @@ export class BaseAllowanceCharge extends opaque<BaseAllowanceCharge>()(
57
83
  })
58
84
  ) {}
59
85
 
86
+ /**
87
+ * @description A document level allowance, marked by a `cbc:ChargeIndicator` of `false`. Adds an allowance reason code to the shared document level allowance and
88
+ * charge fields.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * { amount: { value: 200, currencyId: 'EUR' }, chargeIndicator: false, allowanceChargeReasonCode: '95' }
93
+ * ```;
94
+ *
95
+ * @see {@link PeppolAllowanceCharge}
96
+ */
60
97
  export class PeppolAllowance extends opaque<PeppolAllowance>()(
61
98
  Schema.Struct({
62
99
  ...BaseAllowanceCharge.fields,
63
100
  /**
64
101
  * @name cbc:AllowanceChargeReasonCode
65
102
  */
66
- allowanceChargeReasonCode: Schema.optional(allowanceChargeReasonCodeSchema),
103
+ allowanceChargeReasonCode: Schema.optional(PeppolAllowanceChargeReasonCode),
67
104
  /**
68
105
  * @name cbc:ChargeIndicator
69
106
  *
@@ -75,13 +112,24 @@ export class PeppolAllowance extends opaque<PeppolAllowance>()(
75
112
  })
76
113
  ) {}
77
114
 
115
+ /**
116
+ * @description A document level charge, marked by a `cbc:ChargeIndicator` of `true`. Adds a charge reason code to the shared document level allowance and charge
117
+ * fields.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * { amount: { value: 25, currencyId: 'EUR' }, chargeIndicator: true, allowanceChargeReasonCode: 'AA' }
122
+ * ```;
123
+ *
124
+ * @see {@link PeppolAllowanceCharge}
125
+ */
78
126
  export class PeppolCharge extends opaque<PeppolCharge>()(
79
127
  Schema.Struct({
80
128
  ...BaseAllowanceCharge.fields,
81
129
  /**
82
130
  * @name cbc:AllowanceChargeReasonCode
83
131
  */
84
- allowanceChargeReasonCode: Schema.optional(chargeReasonCodeSchema),
132
+ allowanceChargeReasonCode: Schema.optional(PeppolChargeReasonCode),
85
133
  /**
86
134
  * @name cbc:ChargeIndicator
87
135
  *
@@ -94,11 +142,19 @@ export class PeppolCharge extends opaque<PeppolCharge>()(
94
142
  ) {}
95
143
 
96
144
  /**
145
+ * @description A document level allowance or charge, selected by the `cbc:ChargeIndicator` value: `false` selects an allowance, `true` selects a charge.
146
+ *
97
147
  * @summary Allowance/Charge
98
148
  *
99
149
  * @name cac:AllowanceCharge
100
150
  */
101
- export const peppolAllowanceChargeSchema = Schema.Union([PeppolAllowance, PeppolCharge]).annotate({ message: 'unable to decode allowance charge' });
151
+ export class PeppolAllowanceCharge extends opaque<PeppolAllowanceCharge>()(
152
+ Schema.Union([PeppolAllowance, PeppolCharge]).annotate({ message: 'unable to decode allowance charge' })
153
+ ) {}
102
154
 
103
- export type PeppolAllowanceCharge = Schema.Schema.Type<typeof peppolAllowanceChargeSchema>;
104
- export type PeppolAllowanceChargeEncoded = Schema.Codec.Encoded<typeof peppolAllowanceChargeSchema>;
155
+ /**
156
+ * @description Encoded form of {@link PeppolAllowanceCharge} produced by the Effect Schema codec.
157
+ *
158
+ * @see {@link PeppolAllowanceCharge}
159
+ */
160
+ export type PeppolAllowanceChargeEncoded = Schema.Codec.Encoded<typeof PeppolAllowanceCharge>;
@@ -1,9 +1,17 @@
1
1
  import { Schema } from 'effect';
2
2
 
3
3
  import { opaque } from '#/schemas/utils/opaque.ts';
4
- import { currencyCodeSchema } from '#/schemas/values/currency-code-schema.ts';
4
+ import { PeppolCurrencyCode } from '#/schemas/values/currency-code-schema.ts';
5
5
 
6
6
  /**
7
+ * @description A monetary amount paired with the currency it is expressed in. Wraps a `cbc:*` amount element whose `@currencyID` attribute names the currency and
8
+ * whose text is the value.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * { currencyId: 'EUR', value: 4500.0 }
13
+ * ```;
14
+ *
7
15
  * @summary Monetary amount with mandatory currency
8
16
  *
9
17
  * @name cbc:* (+ @currencyID)
@@ -13,11 +21,16 @@ export class PeppolAmount extends opaque<PeppolAmount>()(
13
21
  /**
14
22
  * @name \@currencyID
15
23
  */
16
- currencyId: currencyCodeSchema,
24
+ currencyId: PeppolCurrencyCode,
17
25
  /**
18
26
  * @name #text (value)
19
27
  */
20
28
  value: Schema.Finite,
21
29
  })
22
30
  ) {}
31
+ /**
32
+ * @description Encoded form of {@link PeppolAmount} produced by the Effect Schema codec. Fields mirror the decoded shape.
33
+ *
34
+ * @see {@link PeppolAmount}
35
+ */
23
36
  export interface PeppolAmountEncoded extends Schema.Codec.Encoded<typeof PeppolAmount> {}
@@ -3,11 +3,21 @@ import { Effect, Schema } from 'effect';
3
3
  import { PeppolAmount } from '#/schemas/fields/peppol-amount-schema.ts';
4
4
  import { PeppolIdentifier } from '#/schemas/fields/peppol-identifier-schema.ts';
5
5
  import { PeppolInvoiceLinePeriod } from '#/schemas/fields/peppol-invoice-line-period-schema.ts';
6
- import { peppolLineAllowanceChargeSchema } from '#/schemas/fields/peppol-line-allowance-charge-schema.ts';
6
+ import { PeppolLineAllowanceCharge } from '#/schemas/fields/peppol-line-allowance-charge-schema.ts';
7
7
  import { PeppolLineItem } from '#/schemas/fields/peppol-line-item-schema.ts';
8
8
  import { PeppolLinePrice } from '#/schemas/fields/peppol-line-price-schema.ts';
9
9
  import { opaque } from '#/schemas/utils/opaque.ts';
10
10
 
11
+ /**
12
+ * @description A reference to the order line that the Invoice line fulfils. Wraps the `cac:OrderLineReference` element and its `cbc:LineID`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * { lineId: '123' }
17
+ * ```;
18
+ *
19
+ * @see {@link PeppolBaseLine}
20
+ */
11
21
  export class PeppolOrderLineReference extends opaque<PeppolOrderLineReference>()(Schema.Struct({ lineId: Schema.String })) {}
12
22
 
13
23
  /**
@@ -37,7 +47,7 @@ export class PeppolBaseLine extends opaque<PeppolBaseLine>()(
37
47
  *
38
48
  * @cardinality 0..n
39
49
  */
40
- allowanceCharges: Schema.optional(Schema.Array(peppolLineAllowanceChargeSchema)),
50
+ allowanceCharges: Schema.optional(Schema.Array(PeppolLineAllowanceCharge)),
41
51
  /**
42
52
  * @summary Line object identifier
43
53
  *
@@ -3,6 +3,17 @@ import { Schema } from 'effect';
3
3
  import { PeppolIsoDateString } from '#/schemas/peppol-iso-date-string.ts';
4
4
  import { opaque } from '#/schemas/utils/opaque.ts';
5
5
 
6
+ /**
7
+ * @description A reference to an Invoice that was previously sent by the Seller, carrying the preceding invoice number and, when the number is not unique, its
8
+ * issue date. Wraps the `cac:InvoiceDocumentReference` element.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * { id: 'inv123', issueDate: '2017-09-15' }
13
+ * ```;
14
+ *
15
+ * @see {@link PeppolBillingReference}
16
+ */
6
17
  export class PeppolInvoiceDocumentReference extends opaque<PeppolInvoiceDocumentReference>()(
7
18
  Schema.Struct({
8
19
  /**
@@ -33,6 +44,8 @@ export class PeppolInvoiceDocumentReference extends opaque<PeppolInvoiceDocument
33
44
  ) {}
34
45
 
35
46
  /**
47
+ * @description A reference to a preceding Invoice, used when the Invoice corrects or replaces an earlier one. Wraps the `cac:BillingReference` element.
48
+ *
36
49
  * @summary PRECEDING INVOICE REFERENCE (0..n)
37
50
  *
38
51
  * @name cac:BillingReference