fatoority 0.5.0 → 0.6.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.
Files changed (95) hide show
  1. package/README.md +9 -9
  2. package/errors.d.mts +67 -0
  3. package/errors.mjs +94 -0
  4. package/fatoora_ffi.wasm +0 -0
  5. package/generated/Adjustment.d.mts +9 -3
  6. package/generated/Adjustment.mjs +12 -6
  7. package/generated/AdjustmentKind.d.mts +24 -0
  8. package/generated/AdjustmentKind.mjs +72 -0
  9. package/generated/AllowanceCharge.d.mts +6 -4
  10. package/generated/AllowanceCharge.mjs +10 -8
  11. package/generated/ClearanceMode.d.mts +30 -0
  12. package/generated/ClearanceMode.mjs +78 -0
  13. package/generated/ClearanceStatus.d.mts +34 -0
  14. package/generated/ClearanceStatus.mjs +84 -0
  15. package/generated/{CsidCompliance.d.mts → ComplianceCsid.d.mts} +4 -3
  16. package/generated/{CsidCompliance.mjs → ComplianceCsid.mjs} +21 -13
  17. package/generated/ComplianceRequest.d.mts +2 -2
  18. package/generated/ComplianceRequest.mjs +2 -2
  19. package/generated/Config.d.mts +3 -2
  20. package/generated/Config.mjs +11 -3
  21. package/generated/CsrProperties.d.mts +6 -2
  22. package/generated/CsrProperties.mjs +7 -3
  23. package/generated/Environment.d.mts +28 -0
  24. package/generated/Environment.mjs +78 -0
  25. package/generated/FinalizedInvoice.d.mts +1 -1
  26. package/generated/FinalizedInvoice.mjs +2 -2
  27. package/generated/InvoiceBuilder.d.mts +18 -21
  28. package/generated/InvoiceBuilder.mjs +31 -168
  29. package/generated/InvoiceData.d.mts +7 -4
  30. package/generated/InvoiceData.mjs +8 -5
  31. package/generated/InvoiceFlag.d.mts +36 -0
  32. package/generated/InvoiceFlag.mjs +105 -0
  33. package/generated/InvoiceLineItem.d.mts +5 -3
  34. package/generated/InvoiceLineItem.mjs +8 -6
  35. package/generated/{Signer.d.mts → InvoiceSigner.d.mts} +3 -3
  36. package/generated/{Signer.mjs → InvoiceSigner.mjs} +13 -13
  37. package/generated/InvoiceSubType.d.mts +26 -0
  38. package/generated/InvoiceSubType.mjs +74 -0
  39. package/generated/InvoiceTypeKind.d.mts +40 -0
  40. package/generated/InvoiceTypeKind.mjs +92 -0
  41. package/generated/LineItemBuilder.d.mts +2 -1
  42. package/generated/LineItemBuilder.mjs +2 -1
  43. package/generated/MessageType.d.mts +38 -0
  44. package/generated/MessageType.mjs +90 -0
  45. package/generated/{CsidProduction.d.mts → ProductionCsid.d.mts} +4 -3
  46. package/generated/{CsidProduction.mjs → ProductionCsid.mjs} +21 -13
  47. package/generated/ProductionRequest.d.mts +2 -2
  48. package/generated/ProductionRequest.mjs +2 -2
  49. package/generated/ReportingStatus.d.mts +34 -0
  50. package/generated/ReportingStatus.mjs +84 -0
  51. package/generated/Severity.d.mts +30 -0
  52. package/generated/Severity.mjs +78 -0
  53. package/generated/SignedInvoice.d.mts +1 -1
  54. package/generated/SignedInvoice.mjs +2 -2
  55. package/generated/ValidationLayer.d.mts +49 -0
  56. package/generated/ValidationLayer.mjs +107 -0
  57. package/generated/ValidationLocationKind.d.mts +37 -0
  58. package/generated/ValidationLocationKind.mjs +89 -0
  59. package/generated/ValidationMessage.d.mts +20 -2
  60. package/generated/ValidationMessage.mjs +52 -0
  61. package/generated/ValidationResponse.d.mts +21 -3
  62. package/generated/ValidationResponse.mjs +52 -0
  63. package/generated/ValidationResults.d.mts +10 -1
  64. package/generated/ValidationResults.mjs +26 -0
  65. package/generated/ValidationStatus.d.mts +38 -0
  66. package/generated/ValidationStatus.mjs +90 -0
  67. package/generated/VatBreakdown.d.mts +4 -3
  68. package/generated/VatBreakdown.mjs +5 -4
  69. package/generated/VatCategory.d.mts +40 -0
  70. package/generated/VatCategory.mjs +92 -0
  71. package/generated/Xml.d.mts +12 -5
  72. package/generated/Xml.mjs +15 -11
  73. package/generated/ZatcaClient.d.mts +10 -9
  74. package/generated/ZatcaClient.mjs +15 -14
  75. package/generated/ZatcaFinding.d.mts +59 -0
  76. package/generated/ZatcaFinding.mjs +239 -0
  77. package/generated/ZatcaRuleSource.d.mts +26 -0
  78. package/generated/ZatcaRuleSource.mjs +97 -0
  79. package/generated/ZatcaStage.d.mts +49 -0
  80. package/generated/ZatcaStage.mjs +107 -0
  81. package/generated/ZatcaStageReport.d.mts +41 -0
  82. package/generated/ZatcaStageReport.mjs +168 -0
  83. package/generated/ZatcaStageStatus.d.mts +45 -0
  84. package/generated/ZatcaStageStatus.mjs +101 -0
  85. package/generated/ZatcaValidationReport.d.mts +63 -0
  86. package/generated/ZatcaValidationReport.mjs +228 -0
  87. package/generated/index.d.mts +45 -5
  88. package/generated/index.mjs +45 -5
  89. package/index.d.mts +131 -15
  90. package/index.mjs +111 -33
  91. package/members.mjs +67 -0
  92. package/package.json +11 -5
  93. package/patch.mjs +121 -0
  94. package/raw.d.mts +731 -0
  95. package/raw.mjs +4 -0
@@ -1,6 +1,8 @@
1
1
  // generated by diplomat-tool
2
2
  import type { BindingError } from "./BindingError.mjs"
3
+ import type { ClearanceStatus } from "./ClearanceStatus.mjs"
3
4
  import type { InvoiceOutcome } from "./InvoiceOutcome.mjs"
5
+ import type { ReportingStatus } from "./ReportingStatus.mjs"
4
6
  import type { Text } from "./Text.mjs"
5
7
  import type { ValidationResults } from "./ValidationResults.mjs"
6
8
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
@@ -26,9 +28,25 @@ export class ValidationResponse {
26
28
 
27
29
  clearedInvoiceBase64(): Text | null;
28
30
 
29
- reportingStatus(): Text | null;
30
-
31
- clearanceStatus(): Text | null;
31
+ /**
32
+ * The parsed `reportingStatus`, or null when the response has none.
33
+ */
34
+ reportingStatus(): ReportingStatus | null;
35
+
36
+ /**
37
+ * The `reportingStatus` exactly as ZATCA sent it, or null when absent.
38
+ */
39
+ reportingStatusRaw(): Text | null;
40
+
41
+ /**
42
+ * The parsed `clearanceStatus`, or null when the response has none.
43
+ */
44
+ clearanceStatus(): ClearanceStatus | null;
45
+
46
+ /**
47
+ * The `clearanceStatus` exactly as ZATCA sent it, or null when absent.
48
+ */
49
+ clearanceStatusRaw(): Text | null;
32
50
 
33
51
  qrSellerStatus(): Text | null;
34
52
 
@@ -1,6 +1,8 @@
1
1
  // generated by diplomat-tool
2
2
  import { BindingError } from "./BindingError.mjs"
3
+ import { ClearanceStatus } from "./ClearanceStatus.mjs"
3
4
  import { InvoiceOutcome } from "./InvoiceOutcome.mjs"
5
+ import { ReportingStatus } from "./ReportingStatus.mjs"
4
6
  import { Text } from "./Text.mjs"
5
7
  import { ValidationResults } from "./ValidationResults.mjs"
6
8
  import wasm from "./diplomat-wasm.mjs";
@@ -150,12 +152,37 @@ export class ValidationResponse {
150
152
  }
151
153
  }
152
154
 
155
+ /**
156
+ * The parsed `reportingStatus`, or null when the response has none.
157
+ */
153
158
  reportingStatus() {
154
159
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
155
160
 
156
161
 
157
162
  const result = wasm.fatoora_ValidationResponse_reporting_status(diplomatReceive.buffer, this.ffiValue);
158
163
 
164
+ try {
165
+ if (!diplomatReceive.resultFlag) {
166
+ return null;
167
+ }
168
+ return new ReportingStatus(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
169
+ }
170
+
171
+ finally {
172
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
173
+ diplomatReceive.free();
174
+ }
175
+ }
176
+
177
+ /**
178
+ * The `reportingStatus` exactly as ZATCA sent it, or null when absent.
179
+ */
180
+ reportingStatusRaw() {
181
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
182
+
183
+
184
+ const result = wasm.fatoora_ValidationResponse_reporting_status_raw(diplomatReceive.buffer, this.ffiValue);
185
+
159
186
  try {
160
187
  if (!diplomatReceive.resultFlag) {
161
188
  const cause = new BindingError(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
@@ -170,12 +197,37 @@ export class ValidationResponse {
170
197
  }
171
198
  }
172
199
 
200
+ /**
201
+ * The parsed `clearanceStatus`, or null when the response has none.
202
+ */
173
203
  clearanceStatus() {
174
204
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
175
205
 
176
206
 
177
207
  const result = wasm.fatoora_ValidationResponse_clearance_status(diplomatReceive.buffer, this.ffiValue);
178
208
 
209
+ try {
210
+ if (!diplomatReceive.resultFlag) {
211
+ return null;
212
+ }
213
+ return new ClearanceStatus(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
214
+ }
215
+
216
+ finally {
217
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
218
+ diplomatReceive.free();
219
+ }
220
+ }
221
+
222
+ /**
223
+ * The `clearanceStatus` exactly as ZATCA sent it, or null when absent.
224
+ */
225
+ clearanceStatusRaw() {
226
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
227
+
228
+
229
+ const result = wasm.fatoora_ValidationResponse_clearance_status_raw(diplomatReceive.buffer, this.ffiValue);
230
+
179
231
  try {
180
232
  if (!diplomatReceive.resultFlag) {
181
233
  const cause = new BindingError(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
@@ -2,6 +2,7 @@
2
2
  import type { BindingError } from "./BindingError.mjs"
3
3
  import type { Text } from "./Text.mjs"
4
4
  import type { ValidationMessage } from "./ValidationMessage.mjs"
5
+ import type { ValidationStatus } from "./ValidationStatus.mjs"
5
6
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
6
7
 
7
8
 
@@ -13,7 +14,15 @@ export class ValidationResults {
13
14
  constructor();
14
15
 
15
16
 
16
- status(): Text | null;
17
+ /**
18
+ * The parsed overall status, or null when the response has none.
19
+ */
20
+ status(): ValidationStatus | null;
21
+
22
+ /**
23
+ * The overall status exactly as ZATCA sent it, or null when absent.
24
+ */
25
+ statusRaw(): Text | null;
17
26
 
18
27
  infoLen(): number;
19
28
 
@@ -2,6 +2,7 @@
2
2
  import { BindingError } from "./BindingError.mjs"
3
3
  import { Text } from "./Text.mjs"
4
4
  import { ValidationMessage } from "./ValidationMessage.mjs"
5
+ import { ValidationStatus } from "./ValidationStatus.mjs"
5
6
  import wasm from "./diplomat-wasm.mjs";
6
7
  import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
8
 
@@ -38,12 +39,37 @@ export class ValidationResults {
38
39
  }
39
40
 
40
41
 
42
+ /**
43
+ * The parsed overall status, or null when the response has none.
44
+ */
41
45
  status() {
42
46
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
43
47
 
44
48
 
45
49
  const result = wasm.fatoora_ValidationResults_status(diplomatReceive.buffer, this.ffiValue);
46
50
 
51
+ try {
52
+ if (!diplomatReceive.resultFlag) {
53
+ return null;
54
+ }
55
+ return new ValidationStatus(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
56
+ }
57
+
58
+ finally {
59
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
60
+ diplomatReceive.free();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * The overall status exactly as ZATCA sent it, or null when absent.
66
+ */
67
+ statusRaw() {
68
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
69
+
70
+
71
+ const result = wasm.fatoora_ValidationResults_status_raw(diplomatReceive.buffer, this.ffiValue);
72
+
47
73
  try {
48
74
  if (!diplomatReceive.resultFlag) {
49
75
  const cause = new BindingError(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
@@ -0,0 +1,38 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.mjs";
3
+
4
+
5
+
6
+ /**
7
+ * Overall `validationResults.status`, or the `status` of one validation message.
8
+ *
9
+ * `Unknown` marks a value this binding version does not recognize; read the
10
+ * verbatim wire value with the sibling `*_raw` getter.
11
+ */
12
+ export class ValidationStatus {
13
+
14
+ /** @internal */
15
+ static fromValue(value: ValidationStatus | string): ValidationStatus;
16
+
17
+ get value(): string;
18
+
19
+ /** @internal */
20
+ get ffiValue(): number;
21
+
22
+ static Unknown : ValidationStatus;
23
+ /**
24
+ * Wire value `PASS`.
25
+ */
26
+ static Pass : ValidationStatus;
27
+ /**
28
+ * Wire value `WARNING`.
29
+ */
30
+ static Warning : ValidationStatus;
31
+ /**
32
+ * Wire value `ERROR`.
33
+ */
34
+ static Error : ValidationStatus;
35
+
36
+
37
+ constructor(value: ValidationStatus | string );
38
+ }
@@ -0,0 +1,90 @@
1
+ // generated by diplomat-tool
2
+ import wasm from "./diplomat-wasm.mjs";
3
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
+
5
+
6
+
7
+ /**
8
+ * Overall `validationResults.status`, or the `status` of one validation message.
9
+ *
10
+ * `Unknown` marks a value this binding version does not recognize; read the
11
+ * verbatim wire value with the sibling `*_raw` getter.
12
+ */
13
+ export class ValidationStatus {
14
+ #value = undefined;
15
+
16
+ static #values = new Map([
17
+ ["Unknown", 0],
18
+ ["Pass", 1],
19
+ ["Warning", 2],
20
+ ["Error", 3]
21
+ ]);
22
+
23
+ static getAllEntries() {
24
+ return ValidationStatus.#values.entries();
25
+ }
26
+
27
+ #internalConstructor(value) {
28
+ if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
29
+ // We pass in two internalConstructor arguments to create *new*
30
+ // instances of this type, otherwise the enums are treated as singletons.
31
+ if (arguments[1] === diplomatRuntime.internalConstructor ) {
32
+ this.#value = arguments[2];
33
+ return this;
34
+ }
35
+ return ValidationStatus.#objectValues[arguments[1]];
36
+ }
37
+
38
+ if (value instanceof ValidationStatus) {
39
+ return value;
40
+ }
41
+
42
+ let intVal = ValidationStatus.#values.get(value);
43
+
44
+ // Nullish check, checks for null or undefined
45
+ if (intVal != null) {
46
+ return ValidationStatus.#objectValues[intVal];
47
+ }
48
+
49
+ throw TypeError(value + " is not a ValidationStatus and does not correspond to any of its enumerator values.");
50
+ }
51
+
52
+ /** @internal */
53
+ static fromValue(value) {
54
+ return new ValidationStatus(value);
55
+ }
56
+
57
+ get value(){
58
+ return [...ValidationStatus.#values.keys()][this.#value];
59
+ }
60
+
61
+ /** @internal */
62
+ get ffiValue(){
63
+ return this.#value;
64
+ }
65
+ static #objectValues = [
66
+ new ValidationStatus(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
67
+ new ValidationStatus(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
68
+ new ValidationStatus(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
69
+ new ValidationStatus(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
70
+ ];
71
+
72
+ static Unknown = ValidationStatus.#objectValues[0];
73
+ /**
74
+ * Wire value `PASS`.
75
+ */
76
+ static Pass = ValidationStatus.#objectValues[1];
77
+ /**
78
+ * Wire value `WARNING`.
79
+ */
80
+ static Warning = ValidationStatus.#objectValues[2];
81
+ /**
82
+ * Wire value `ERROR`.
83
+ */
84
+ static Error = ValidationStatus.#objectValues[3];
85
+
86
+
87
+ constructor(value) {
88
+ return this.#internalConstructor(...arguments)
89
+ }
90
+ }
@@ -1,6 +1,7 @@
1
1
  // generated by diplomat-tool
2
2
  import type { BindingError } from "./BindingError.mjs"
3
3
  import type { TaxExemption } from "./TaxExemption.mjs"
4
+ import type { VatCategory } from "./VatCategory.mjs"
4
5
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
5
6
 
6
7
 
@@ -14,11 +15,11 @@ export class VatBreakdown {
14
15
 
15
16
  hasVatRate(): boolean;
16
17
 
17
- withoutVatRate(): VatBreakdown;
18
+ omitVatRate(): VatBreakdown;
18
19
 
19
- static new_(category: number, rate: string, taxableAmount: string, taxAmount: string, exemption: TaxExemption): VatBreakdown;
20
+ static new_(category: VatCategory, rate: string, taxableAmount: string, taxAmount: string, exemption: TaxExemption): VatBreakdown;
20
21
 
21
- category(): number;
22
+ category(): VatCategory;
22
23
 
23
24
  rate(): string;
24
25
 
@@ -1,6 +1,7 @@
1
1
  // generated by diplomat-tool
2
2
  import { BindingError } from "./BindingError.mjs"
3
3
  import { TaxExemption } from "./TaxExemption.mjs"
4
+ import { VatCategory } from "./VatCategory.mjs"
4
5
  import wasm from "./diplomat-wasm.mjs";
5
6
  import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
7
 
@@ -50,11 +51,11 @@ export class VatBreakdown {
50
51
  }
51
52
  }
52
53
 
53
- withoutVatRate() {
54
+ omitVatRate() {
54
55
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
55
56
 
56
57
 
57
- const result = wasm.fatoora_VatBreakdown_without_vat_rate(diplomatReceive.buffer, this.ffiValue);
58
+ const result = wasm.fatoora_VatBreakdown_omit_vat_rate(diplomatReceive.buffer, this.ffiValue);
58
59
 
59
60
  try {
60
61
  if (!diplomatReceive.resultFlag) {
@@ -79,7 +80,7 @@ export class VatBreakdown {
79
80
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
80
81
 
81
82
 
82
- const result = wasm.fatoora_VatBreakdown_new(diplomatReceive.buffer, category, rateSlice.ptr, taxableAmountSlice.ptr, taxAmountSlice.ptr, exemption instanceof TaxExemption ? exemption.ffiValue : typeError('exemption', 'TaxExemption'));
83
+ const result = wasm.fatoora_VatBreakdown_new(diplomatReceive.buffer, new VatCategory(category).ffiValue, rateSlice.ptr, taxableAmountSlice.ptr, taxAmountSlice.ptr, exemption instanceof TaxExemption ? exemption.ffiValue : typeError('exemption', 'TaxExemption'));
83
84
 
84
85
  try {
85
86
  if (!diplomatReceive.resultFlag) {
@@ -102,7 +103,7 @@ export class VatBreakdown {
102
103
  const result = wasm.fatoora_VatBreakdown_category(this.ffiValue);
103
104
 
104
105
  try {
105
- return result;
106
+ return new VatCategory(diplomatRuntime.internalConstructor, result);
106
107
  }
107
108
 
108
109
  finally {
@@ -0,0 +1,40 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.mjs";
3
+
4
+
5
+
6
+ /**
7
+ * VAT category of a line, breakdown, or document-level adjustment.
8
+ *
9
+ * Discriminants match the `u8` codes used before 0.6.
10
+ */
11
+ export class VatCategory {
12
+
13
+ /** @internal */
14
+ static fromValue(value: VatCategory | string): VatCategory;
15
+
16
+ get value(): string;
17
+
18
+ /** @internal */
19
+ get ffiValue(): number;
20
+
21
+ /**
22
+ * UNCL5305 `E`.
23
+ */
24
+ static Exempt : VatCategory;
25
+ /**
26
+ * UNCL5305 `S`.
27
+ */
28
+ static Standard : VatCategory;
29
+ /**
30
+ * UNCL5305 `Z`.
31
+ */
32
+ static Zero : VatCategory;
33
+ /**
34
+ * UNCL5305 `O`.
35
+ */
36
+ static OutOfScope : VatCategory;
37
+
38
+
39
+ constructor(value: VatCategory | string );
40
+ }
@@ -0,0 +1,92 @@
1
+ // generated by diplomat-tool
2
+ import wasm from "./diplomat-wasm.mjs";
3
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
+
5
+
6
+
7
+ /**
8
+ * VAT category of a line, breakdown, or document-level adjustment.
9
+ *
10
+ * Discriminants match the `u8` codes used before 0.6.
11
+ */
12
+ export class VatCategory {
13
+ #value = undefined;
14
+
15
+ static #values = new Map([
16
+ ["Exempt", 0],
17
+ ["Standard", 1],
18
+ ["Zero", 2],
19
+ ["OutOfScope", 3]
20
+ ]);
21
+
22
+ static getAllEntries() {
23
+ return VatCategory.#values.entries();
24
+ }
25
+
26
+ #internalConstructor(value) {
27
+ if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
28
+ // We pass in two internalConstructor arguments to create *new*
29
+ // instances of this type, otherwise the enums are treated as singletons.
30
+ if (arguments[1] === diplomatRuntime.internalConstructor ) {
31
+ this.#value = arguments[2];
32
+ return this;
33
+ }
34
+ return VatCategory.#objectValues[arguments[1]];
35
+ }
36
+
37
+ if (value instanceof VatCategory) {
38
+ return value;
39
+ }
40
+
41
+ let intVal = VatCategory.#values.get(value);
42
+
43
+ // Nullish check, checks for null or undefined
44
+ if (intVal != null) {
45
+ return VatCategory.#objectValues[intVal];
46
+ }
47
+
48
+ throw TypeError(value + " is not a VatCategory and does not correspond to any of its enumerator values.");
49
+ }
50
+
51
+ /** @internal */
52
+ static fromValue(value) {
53
+ return new VatCategory(value);
54
+ }
55
+
56
+ get value(){
57
+ return [...VatCategory.#values.keys()][this.#value];
58
+ }
59
+
60
+ /** @internal */
61
+ get ffiValue(){
62
+ return this.#value;
63
+ }
64
+ static #objectValues = [
65
+ new VatCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
66
+ new VatCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
67
+ new VatCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
68
+ new VatCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
69
+ ];
70
+
71
+ /**
72
+ * UNCL5305 `E`.
73
+ */
74
+ static Exempt = VatCategory.#objectValues[0];
75
+ /**
76
+ * UNCL5305 `S`.
77
+ */
78
+ static Standard = VatCategory.#objectValues[1];
79
+ /**
80
+ * UNCL5305 `Z`.
81
+ */
82
+ static Zero = VatCategory.#objectValues[2];
83
+ /**
84
+ * UNCL5305 `O`.
85
+ */
86
+ static OutOfScope = VatCategory.#objectValues[3];
87
+
88
+
89
+ constructor(value) {
90
+ return this.#internalConstructor(...arguments)
91
+ }
92
+ }
@@ -1,6 +1,6 @@
1
1
  // generated by diplomat-tool
2
2
  import type { BindingError } from "./BindingError.mjs"
3
- import type { Config } from "./Config.mjs"
3
+ import type { ZatcaValidationReport } from "./ZatcaValidationReport.mjs"
4
4
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
5
5
 
6
6
 
@@ -13,12 +13,19 @@ export class Xml {
13
13
 
14
14
 
15
15
  /**
16
- * Produce an owned local ZATCA report as JSON. Inspect is_valid before acceptance.
17
- * Options default when absent; JSON inputs are limited to 4 KiB.
16
+ * Run the local ZATCA validation profile and return its owned report.
17
+ *
18
+ * Inspect `is_valid` before acceptance. Options default when absent;
19
+ * `options_json` is limited to 4 KiB. Validation needs no configuration:
20
+ * it mirrors the stateless core `Validator::validate_zatca`.
18
21
  */
19
- static validateZatca(config: Config, xml: string, optionsJson: string | null): string;
22
+ static validateZatca(xml: string, optionsJson: string | null): ZatcaValidationReport;
20
23
 
21
- static validate(config: Config, xml: string): boolean;
24
+ /**
25
+ * Check the XML against the UBL schema and business rules, mirroring core
26
+ * `Validator::validate_xml`. Returns true or a validation error.
27
+ */
28
+ static validate(xml: string): boolean;
22
29
 
23
30
  static hash(xml: string): string;
24
31
  }
package/generated/Xml.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // generated by diplomat-tool
2
2
  import { BindingError } from "./BindingError.mjs"
3
- import { Config } from "./Config.mjs"
3
+ import { ZatcaValidationReport } from "./ZatcaValidationReport.mjs"
4
4
  import wasm from "./diplomat-wasm.mjs";
5
5
  import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
6
 
@@ -38,26 +38,27 @@ export class Xml {
38
38
 
39
39
 
40
40
  /**
41
- * Produce an owned local ZATCA report as JSON. Inspect is_valid before acceptance.
42
- * Options default when absent; JSON inputs are limited to 4 KiB.
41
+ * Run the local ZATCA validation profile and return its owned report.
42
+ *
43
+ * Inspect `is_valid` before acceptance. Options default when absent;
44
+ * `options_json` is limited to 4 KiB. Validation needs no configuration:
45
+ * it mirrors the stateless core `Validator::validate_zatca`.
43
46
  */
44
- static validateZatca(config, xml, optionsJson) {
47
+ static validateZatca(xml, optionsJson) {
45
48
  let functionCleanupArena = new diplomatRuntime.CleanupArena();
46
49
 
47
50
  const xmlSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, xml)));
48
51
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
49
52
 
50
- const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
51
-
52
53
 
53
- const result = wasm.fatoora_Xml_validate_zatca(diplomatReceive.buffer, config instanceof Config ? config.ffiValue : typeError('config', 'Config'), xmlSlice.ptr, diplomatRuntime.optionToBufferForCalling(wasm, optionsJson, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]), write.buffer);
54
+ const result = wasm.fatoora_Xml_validate_zatca(diplomatReceive.buffer, xmlSlice.ptr, diplomatRuntime.optionToBufferForCalling(wasm, optionsJson, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]));
54
55
 
55
56
  try {
56
57
  if (!diplomatReceive.resultFlag) {
57
58
  const cause = new BindingError(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
58
59
  throw new globalThis.Error('BindingError: ' + cause.toString(), { cause });
59
60
  }
60
- return write.readString8();
61
+ return new ZatcaValidationReport(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
61
62
  }
62
63
 
63
64
  finally {
@@ -65,18 +66,21 @@ export class Xml {
65
66
  functionCleanupArena.free();
66
67
 
67
68
  diplomatReceive.free();
68
- write.free();
69
69
  }
70
70
  }
71
71
 
72
- static validate(config, xml) {
72
+ /**
73
+ * Check the XML against the UBL schema and business rules, mirroring core
74
+ * `Validator::validate_xml`. Returns true or a validation error.
75
+ */
76
+ static validate(xml) {
73
77
  let functionCleanupArena = new diplomatRuntime.CleanupArena();
74
78
 
75
79
  const xmlSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, xml)));
76
80
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 1, true);
77
81
 
78
82
 
79
- const result = wasm.fatoora_Xml_validate(diplomatReceive.buffer, config instanceof Config ? config.ffiValue : typeError('config', 'Config'), xmlSlice.ptr);
83
+ const result = wasm.fatoora_Xml_validate(diplomatReceive.buffer, xmlSlice.ptr);
80
84
 
81
85
  try {
82
86
  if (!diplomatReceive.resultFlag) {
@@ -1,11 +1,12 @@
1
1
  // generated by diplomat-tool
2
2
  import type { BindingError } from "./BindingError.mjs"
3
+ import type { ClearanceMode } from "./ClearanceMode.mjs"
4
+ import type { ComplianceCsid } from "./ComplianceCsid.mjs"
3
5
  import type { ComplianceRequest } from "./ComplianceRequest.mjs"
4
6
  import type { Config } from "./Config.mjs"
5
- import type { CsidCompliance } from "./CsidCompliance.mjs"
6
- import type { CsidProduction } from "./CsidProduction.mjs"
7
7
  import type { Csr } from "./Csr.mjs"
8
8
  import type { InvoiceRequest } from "./InvoiceRequest.mjs"
9
+ import type { ProductionCsid } from "./ProductionCsid.mjs"
9
10
  import type { ProductionRequest } from "./ProductionRequest.mjs"
10
11
  import type { SignedInvoice } from "./SignedInvoice.mjs"
11
12
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
@@ -19,17 +20,17 @@ export class ZatcaClient {
19
20
  constructor();
20
21
 
21
22
 
22
- static create(config: Config): ZatcaClient;
23
+ static new_(config: Config): ZatcaClient;
23
24
 
24
- preparePostCsrForCcsid(csr: Csr, otp: string): ComplianceRequest;
25
+ prepareRequestComplianceCsid(csr: Csr, otp: string): ComplianceRequest;
25
26
 
26
- preparePostCcsidForPcsid(credentials: CsidCompliance): ProductionRequest;
27
+ prepareRequestProductionCsid(credentials: ComplianceCsid): ProductionRequest;
27
28
 
28
- prepareRenewCsid(credentials: CsidProduction, csr: Csr, otp: string, acceptLanguage: string | null): ProductionRequest;
29
+ prepareRenewCsid(credentials: ProductionCsid, csr: Csr, otp: string, acceptLanguage: string | null): ProductionRequest;
29
30
 
30
- prepareCheckInvoiceCompliance(invoice: SignedInvoice, credentials: CsidCompliance): InvoiceRequest;
31
+ prepareCheckInvoiceCompliance(invoice: SignedInvoice, credentials: ComplianceCsid): InvoiceRequest;
31
32
 
32
- prepareReportSimplifiedInvoice(invoice: SignedInvoice, credentials: CsidProduction, clearanceStatus: boolean, acceptLanguage: string | null): InvoiceRequest;
33
+ prepareReportSimplifiedInvoice(invoice: SignedInvoice, credentials: ProductionCsid, clearanceMode: ClearanceMode, acceptLanguage: string | null): InvoiceRequest;
33
34
 
34
- prepareClearStandardInvoice(invoice: SignedInvoice, credentials: CsidProduction, clearanceStatus: boolean, acceptLanguage: string | null): InvoiceRequest;
35
+ prepareClearStandardInvoice(invoice: SignedInvoice, credentials: ProductionCsid, clearanceMode: ClearanceMode, acceptLanguage: string | null): InvoiceRequest;
35
36
  }