fatoority 0.5.1 → 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 +10 -4
  93. package/patch.mjs +121 -0
  94. package/raw.d.mts +731 -0
  95. package/raw.mjs +4 -0
package/README.md CHANGED
@@ -26,26 +26,26 @@ Build a local tarball with `npm pack` in `bindings/js`. Version tags publish the
26
26
  See the [JS/TS reference](https://docs.fatoority.com/reference/bindings/javascript/) for complete installation, browser deployment and API examples.
27
27
 
28
28
  ```js
29
- import { Config, SigningKey, CsidCompliance, ZatcaClient } from 'fatoority';
29
+ import { Config, Environment, SigningKey, ComplianceCsid, ZatcaClient } from 'fatoority';
30
30
 
31
31
  const key = SigningKey.generate();
32
- const config = Config.new_(0); // 0: nonproduction, 1: simulation, 2: production
32
+ const config = Config.create(Environment.NonProduction); // or Simulation, Production
33
33
  const client = new ZatcaClient(config);
34
- const compliance = CsidCompliance.create(0, 'request-id', 'token', 'secret');
35
- const production = await client.postCcsidForPcsid(compliance, {
34
+ const compliance = ComplianceCsid.create(Environment.NonProduction, 'request-id', 'token', 'secret');
35
+ const production = await client.requestProductionCsid(compliance, {
36
36
  signal: AbortSignal.timeout(30_000),
37
37
  });
38
38
  ```
39
39
 
40
- API methods prepare requests and decode responses in Rust; the facade calls `fetch`. Inject a fetch implementation with `new ZatcaClient(config, {fetch})`. Requests refuse redirects. HTTP errors go to Rust decoding, and a successful invoice HTTP response still requires `response.ensureAccepted()` or inspection of `response.outcome()`.
40
+ API methods prepare requests and decode responses in Rust; the facade calls `fetch`. Inject a fetch implementation with `new ZatcaClient(config, {fetch})`. Requests refuse redirects. HTTP errors go to Rust decoding, and a successful invoice HTTP response still requires `response.ensureAccepted()` or inspection of `response.outcome`.
41
41
 
42
- For your own transport, import `ZatcaClient` from `fatoority/raw`, call a `prepare*` method, and read `method()`, `url()`, `headersJson()` (an array of header pairs), and `body().asSlice()`. Complete with `request.decode(status, bytes)`, or use `sendPrepared(request, {fetch, signal})`. The request owns its data and the operation/environment needed for decoding. It contains authorization headers and must not be logged.
42
+ For your own transport, import `ZatcaClient` from `fatoority/raw`, call a `prepare*` method, and read `method`, `url`, `headersJson` (an array of header pairs), and `body().asSlice()`. Complete with `request.decode(status, bytes)`, or use `sendPrepared(request, {fetch, signal})`. The request owns its data and the operation/environment needed for decoding. It contains authorization headers and must not be logged.
43
43
 
44
- The generated API preserves Rust names in camelCase; a Rust `new` constructor is `new_`. Decimal arguments and outputs are strings, and invoice counters are `bigint`. Optional strings use `null`, distinct from `''`. Consuming operations such as `build()`, signing and `intoXml()` reject reuse. Generated owners are released by FinalizationRegistry; do not manually free pointers or share handles between workers. Byte slices returned by the generated JS are copies. The facade snapshots outgoing bytes before awaiting the network.
44
+ The package root exposes the generated classes with Rust names in camelCase; a Rust `new` constructor is `create` (the generated `new_` remains as a deprecated alias). Value getters are read-only properties (`invoice.xml`, `address.city`, `totals.taxAmount`, `response.reportingStatus`); members that take arguments, return another native object (`invoice.data()`), convert or consume stay methods. Optional text is `string | null`. Decimal arguments and outputs are exact decimal strings (never `number`), and invoice counters are `bigint`. Enumerated codes are enum classes such as `Environment.NonProduction`, `VatCategory.Standard`, `AdjustmentKind.Charge` and `ClearanceMode.Disabled` (`.value` is the variant name); each enum has a string-literal union type such as `VatCategoryValue`. Response statuses such as `reportingStatus` are an enum (with `Unknown` for unrecognized values) or `null`; `reportingStatusRaw` and the other `*Raw` properties hold the exact text. The async `ZatcaClient` also accepts a boolean or variant name for `clearanceStatus`; the `fatoority/raw` `prepare*` methods take a `ClearanceMode`. Optional strings use `null`, distinct from `''`. Consuming operations such as `build()`, signing and `intoXml()` reject reuse. Generated owners are released by FinalizationRegistry; do not manually free pointers or share handles between workers. Byte slices returned by the generated JS are copies. The facade snapshots outgoing bytes before awaiting the network.
45
45
 
46
- Generated Rust errors are JavaScript `Error` objects whose `cause` is a `BindingError`. Inspect `error.cause.code()`, `.message()` and `.detailsJson()`. Network, cancellation and response-body read failures throw `TransportError`, retaining the original cause and, when available, `httpStatus`.
46
+ Library failures throw one `FatooraError` subclass per error code (`InvalidInputError`, `ValidationError`, `ParseError`, `XmlError`, `CryptoError`, `IoError`, `NetworkError`, `UnauthorizedError`, `InternalError`, `ApiError`) with `code`, `kind`, `message`, parsed `details`, and the `BindingError` as `cause`. `fatoority/raw` throws the same classes. Network, cancellation and response-body read failures throw `TransportError`, a `NetworkError` retaining the original cause and, when available, `httpStatus`.
47
47
 
48
- `Xml.validateZatca(config, xml, optionsJson)` supplies the host clock when `evaluated_at` is absent. An explicit timestamp makes validation reproducible. The raw API requires `evaluated_at` on WASM. Filesystem helpers are excluded from JS; read files in the host and pass their contents.
48
+ `Xml.validateZatca(xml, {previousInvoiceHash, evaluatedAt})` returns the `ZatcaValidationReport` as a plain, typed object (`isValid`, `stages[].findings[]` with `severity`, `layer`, `code`, `message`, `location`) and supplies the host clock when `evaluatedAt` is absent. An explicit timestamp makes validation reproducible. The raw API returns the native report and requires `evaluated_at` on WASM. Filesystem helpers are excluded from JS; read files in the host and pass their contents.
49
49
 
50
50
  The browser loader resolves `fatoora_ffi.wasm` relative to the package modules. Deploy the generated modules and WASM together, or configure the bundler to copy the WASM at that URL. Direct gateway requests depend on the gateway's CORS policy. Keep signing keys and credentials in the host environment appropriate to your application.
51
51
 
package/errors.d.mts ADDED
@@ -0,0 +1,67 @@
1
+ /** Library error codes reported by `BindingError.code()`, mirroring Rust `ErrorKind`. */
2
+ export declare const ErrorCode: Readonly<{
3
+ InvalidInput: 1;
4
+ Validation: 2;
5
+ Parse: 3;
6
+ Xml: 4;
7
+ Crypto: 5;
8
+ Io: 6;
9
+ Network: 7;
10
+ Unauthorized: 8;
11
+ Internal: 9;
12
+ Api: 10;
13
+ }>;
14
+ /** Variant name of a library error code. */
15
+ export type ErrorKind = keyof typeof ErrorCode;
16
+
17
+ export interface FatooraErrorOptions {
18
+ code?: number | null;
19
+ details?: Record<string, unknown>;
20
+ cause?: unknown;
21
+ }
22
+
23
+ /**
24
+ * Base class of every error the package throws for a library failure.
25
+ * For failures reported by Rust, `cause` is the generated `BindingError`.
26
+ */
27
+ export declare class FatooraError extends Error {
28
+ constructor(message: string, options?: FatooraErrorOptions);
29
+ /** Numeric library code, or `null` when the failure did not come from Rust. */
30
+ readonly code: number | null;
31
+ /** Variant name of `code`, or `null` when this version does not recognize it. */
32
+ readonly kind: ErrorKind | null;
33
+ /** Structured details, such as validation findings or an HTTP response body. */
34
+ readonly details: Record<string, unknown>;
35
+ }
36
+ /** Code 1: a caller-supplied value is malformed or out of range. */
37
+ export declare class InvalidInputError extends FatooraError { readonly code: 1; readonly kind: 'InvalidInput'; }
38
+ /** Code 2: input is well-formed but fails invoice, CSR or schema rules. */
39
+ export declare class ValidationError extends FatooraError { readonly code: 2; readonly kind: 'Validation'; }
40
+ /** Code 3: structured input, such as a ZATCA API response body, could not be parsed. */
41
+ export declare class ParseError extends FatooraError { readonly code: 3; readonly kind: 'Parse'; }
42
+ /** Code 4: XML could not be serialized, parsed or processed. */
43
+ export declare class XmlError extends FatooraError { readonly code: 4; readonly kind: 'Xml'; }
44
+ /** Code 5: key handling, signing, hashing or certificate processing failed. */
45
+ export declare class CryptoError extends FatooraError { readonly code: 5; readonly kind: 'Crypto'; }
46
+ /** Code 6: an I/O operation failed. */
47
+ export declare class IoError extends FatooraError { readonly code: 6; readonly kind: 'Io'; }
48
+ /** Code 7: the HTTP request or response transport failed. */
49
+ export declare class NetworkError extends FatooraError { readonly code: 7; readonly kind: 'Network'; }
50
+ /** Code 8: the ZATCA API rejected the supplied credentials. */
51
+ export declare class UnauthorizedError extends FatooraError { readonly code: 8; readonly kind: 'Unauthorized'; }
52
+ /** Code 9: an internal invariant or client state error. */
53
+ export declare class InternalError extends FatooraError { readonly code: 9; readonly kind: 'Internal'; }
54
+ /** Code 10: the ZATCA API returned an error or non-accepted response. */
55
+ export declare class ApiError extends FatooraError { readonly code: 10; readonly kind: 'Api'; }
56
+
57
+ /**
58
+ * Fetch, cancellation and response-body read failures in the JavaScript host.
59
+ * `cause` is the original host error; `httpStatus` is set when a response arrived.
60
+ */
61
+ export declare class TransportError extends NetworkError {
62
+ constructor(message: string, cause?: unknown, httpStatus?: number);
63
+ readonly httpStatus?: number;
64
+ }
65
+
66
+ /** The error subclass for a library code; `FatooraError` for an unrecognized code. */
67
+ export declare function errorClassForCode(code: number | null): typeof FatooraError;
package/errors.mjs ADDED
@@ -0,0 +1,94 @@
1
+ /** Library error codes reported by `BindingError.code()`, mirroring Rust `ErrorKind`. */
2
+ export const ErrorCode = Object.freeze({
3
+ InvalidInput: 1,
4
+ Validation: 2,
5
+ Parse: 3,
6
+ Xml: 4,
7
+ Crypto: 5,
8
+ Io: 6,
9
+ Network: 7,
10
+ Unauthorized: 8,
11
+ Internal: 9,
12
+ Api: 10,
13
+ });
14
+
15
+ const kinds = new Map(Object.entries(ErrorCode).map(([kind, code]) => [code, kind]));
16
+ // Filled in below: a subclass constructed directly takes its own code.
17
+ const defaultCodes = new Map();
18
+
19
+ /** Base class of every error the package throws for a library failure. */
20
+ export class FatooraError extends Error {
21
+ constructor(message, { code = defaultCodes.get(new.target) ?? null, details = {}, cause } = {}) {
22
+ super(message, cause === undefined ? undefined : { cause });
23
+ /** Numeric library code, or `null` when the failure did not come from Rust. */
24
+ this.code = code;
25
+ /** Variant name of `code`, or `null` when this version does not recognize it. */
26
+ this.kind = kinds.get(code) ?? null;
27
+ /** Structured details from the library, such as findings or an HTTP response body. */
28
+ this.details = details;
29
+ }
30
+ }
31
+
32
+ export class InvalidInputError extends FatooraError {}
33
+ export class ValidationError extends FatooraError {}
34
+ export class ParseError extends FatooraError {}
35
+ export class XmlError extends FatooraError {}
36
+ export class CryptoError extends FatooraError {}
37
+ export class IoError extends FatooraError {}
38
+ export class NetworkError extends FatooraError {}
39
+ export class UnauthorizedError extends FatooraError {}
40
+ export class InternalError extends FatooraError {}
41
+ export class ApiError extends FatooraError {}
42
+
43
+ const classes = new Map([
44
+ [ErrorCode.InvalidInput, InvalidInputError],
45
+ [ErrorCode.Validation, ValidationError],
46
+ [ErrorCode.Parse, ParseError],
47
+ [ErrorCode.Xml, XmlError],
48
+ [ErrorCode.Crypto, CryptoError],
49
+ [ErrorCode.Io, IoError],
50
+ [ErrorCode.Network, NetworkError],
51
+ [ErrorCode.Unauthorized, UnauthorizedError],
52
+ [ErrorCode.Internal, InternalError],
53
+ [ErrorCode.Api, ApiError],
54
+ ]);
55
+ for (const [code, ErrorClass] of classes) defaultCodes.set(ErrorClass, code);
56
+
57
+ // Explicit names survive bundler minification of class identifiers.
58
+ for (const [ErrorClass, name] of [
59
+ [FatooraError, 'FatooraError'], [InvalidInputError, 'InvalidInputError'],
60
+ [ValidationError, 'ValidationError'], [ParseError, 'ParseError'], [XmlError, 'XmlError'],
61
+ [CryptoError, 'CryptoError'], [IoError, 'IoError'], [NetworkError, 'NetworkError'],
62
+ [UnauthorizedError, 'UnauthorizedError'], [InternalError, 'InternalError'], [ApiError, 'ApiError'],
63
+ ]) {
64
+ Object.defineProperty(ErrorClass.prototype, 'name', { value: name, writable: true, configurable: true });
65
+ }
66
+
67
+ /** The error subclass for a library code; `FatooraError` for an unrecognized code. */
68
+ export function errorClassForCode(code) {
69
+ return classes.get(code) ?? FatooraError;
70
+ }
71
+
72
+ /**
73
+ * Fetch, cancellation and response-body read failures in the JavaScript host.
74
+ * `cause` is the original host error; `httpStatus` is set when a response arrived.
75
+ */
76
+ export class TransportError extends NetworkError {
77
+ constructor(message, cause, httpStatus = undefined) {
78
+ super(message, { code: ErrorCode.Network, cause });
79
+ this.httpStatus = httpStatus;
80
+ }
81
+ }
82
+ Object.defineProperty(TransportError.prototype, 'name', { value: 'TransportError', writable: true, configurable: true });
83
+
84
+ /** Convert a generated `BindingError` into its typed error, reading it eagerly. */
85
+ export function fromBindingError(binding) {
86
+ const code = binding.code();
87
+ let details = {};
88
+ try {
89
+ const parsed = JSON.parse(binding.detailsJson());
90
+ if (parsed !== null && typeof parsed === 'object') details = parsed;
91
+ } catch { /* details are best-effort */ }
92
+ const ErrorClass = errorClassForCode(code);
93
+ return new ErrorClass(binding.message(), { code, details, cause: binding });
94
+ }
package/fatoora_ffi.wasm CHANGED
Binary file
@@ -14,9 +14,15 @@ export class Adjustment {
14
14
 
15
15
  static amount(value: string): Adjustment;
16
16
 
17
- static percentage(base: string, percent: string): Adjustment;
17
+ /**
18
+ * Create an adjustment of `percent` percent of `base`.
19
+ */
20
+ static percentOf(base: string, percent: string): Adjustment;
18
21
 
19
- withSuppliedAmount(value: string): Adjustment;
22
+ /**
23
+ * Return a copy with an explicit amount, checked against the percentage calculation.
24
+ */
25
+ suppliedAmount(value: string): Adjustment;
20
26
 
21
27
  withReason(reason: string | null, code: string | null): Adjustment;
22
28
 
@@ -24,7 +30,7 @@ export class Adjustment {
24
30
 
25
31
  baseAmount(): Text | null;
26
32
 
27
- percent(): Text | null;
33
+ percentage(): Text | null;
28
34
 
29
35
  reason(): Text | null;
30
36
 
@@ -62,7 +62,10 @@ export class Adjustment {
62
62
  }
63
63
  }
64
64
 
65
- static percentage(base, percent) {
65
+ /**
66
+ * Create an adjustment of `percent` percent of `base`.
67
+ */
68
+ static percentOf(base, percent) {
66
69
  let functionCleanupArena = new diplomatRuntime.CleanupArena();
67
70
 
68
71
  const baseSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, base)));
@@ -70,7 +73,7 @@ export class Adjustment {
70
73
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
71
74
 
72
75
 
73
- const result = wasm.fatoora_Adjustment_percentage(diplomatReceive.buffer, baseSlice.ptr, percentSlice.ptr);
76
+ const result = wasm.fatoora_Adjustment_percent_of(diplomatReceive.buffer, baseSlice.ptr, percentSlice.ptr);
74
77
 
75
78
  try {
76
79
  if (!diplomatReceive.resultFlag) {
@@ -88,14 +91,17 @@ export class Adjustment {
88
91
  }
89
92
  }
90
93
 
91
- withSuppliedAmount(value) {
94
+ /**
95
+ * Return a copy with an explicit amount, checked against the percentage calculation.
96
+ */
97
+ suppliedAmount(value) {
92
98
  let functionCleanupArena = new diplomatRuntime.CleanupArena();
93
99
 
94
100
  const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, value)));
95
101
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
96
102
 
97
103
 
98
- const result = wasm.fatoora_Adjustment_with_supplied_amount(diplomatReceive.buffer, this.ffiValue, valueSlice.ptr);
104
+ const result = wasm.fatoora_Adjustment_supplied_amount(diplomatReceive.buffer, this.ffiValue, valueSlice.ptr);
99
105
 
100
106
  try {
101
107
  if (!diplomatReceive.resultFlag) {
@@ -180,11 +186,11 @@ export class Adjustment {
180
186
  }
181
187
  }
182
188
 
183
- percent() {
189
+ percentage() {
184
190
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
185
191
 
186
192
 
187
- const result = wasm.fatoora_Adjustment_percent(diplomatReceive.buffer, this.ffiValue);
193
+ const result = wasm.fatoora_Adjustment_percentage(diplomatReceive.buffer, this.ffiValue);
188
194
 
189
195
  try {
190
196
  if (!diplomatReceive.resultFlag) {
@@ -0,0 +1,24 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.mjs";
3
+
4
+
5
+
6
+ /**
7
+ * Whether a document-level adjustment is an allowance (discount) or a charge.
8
+ */
9
+ export class AdjustmentKind {
10
+
11
+ /** @internal */
12
+ static fromValue(value: AdjustmentKind | string): AdjustmentKind;
13
+
14
+ get value(): string;
15
+
16
+ /** @internal */
17
+ get ffiValue(): number;
18
+
19
+ static Allowance : AdjustmentKind;
20
+ static Charge : AdjustmentKind;
21
+
22
+
23
+ constructor(value: AdjustmentKind | string );
24
+ }
@@ -0,0 +1,72 @@
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
+ * Whether a document-level adjustment is an allowance (discount) or a charge.
9
+ */
10
+ export class AdjustmentKind {
11
+ #value = undefined;
12
+
13
+ static #values = new Map([
14
+ ["Allowance", 0],
15
+ ["Charge", 1]
16
+ ]);
17
+
18
+ static getAllEntries() {
19
+ return AdjustmentKind.#values.entries();
20
+ }
21
+
22
+ #internalConstructor(value) {
23
+ if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
24
+ // We pass in two internalConstructor arguments to create *new*
25
+ // instances of this type, otherwise the enums are treated as singletons.
26
+ if (arguments[1] === diplomatRuntime.internalConstructor ) {
27
+ this.#value = arguments[2];
28
+ return this;
29
+ }
30
+ return AdjustmentKind.#objectValues[arguments[1]];
31
+ }
32
+
33
+ if (value instanceof AdjustmentKind) {
34
+ return value;
35
+ }
36
+
37
+ let intVal = AdjustmentKind.#values.get(value);
38
+
39
+ // Nullish check, checks for null or undefined
40
+ if (intVal != null) {
41
+ return AdjustmentKind.#objectValues[intVal];
42
+ }
43
+
44
+ throw TypeError(value + " is not a AdjustmentKind and does not correspond to any of its enumerator values.");
45
+ }
46
+
47
+ /** @internal */
48
+ static fromValue(value) {
49
+ return new AdjustmentKind(value);
50
+ }
51
+
52
+ get value(){
53
+ return [...AdjustmentKind.#values.keys()][this.#value];
54
+ }
55
+
56
+ /** @internal */
57
+ get ffiValue(){
58
+ return this.#value;
59
+ }
60
+ static #objectValues = [
61
+ new AdjustmentKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
62
+ new AdjustmentKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
63
+ ];
64
+
65
+ static Allowance = AdjustmentKind.#objectValues[0];
66
+ static Charge = AdjustmentKind.#objectValues[1];
67
+
68
+
69
+ constructor(value) {
70
+ return this.#internalConstructor(...arguments)
71
+ }
72
+ }
@@ -1,7 +1,9 @@
1
1
  // generated by diplomat-tool
2
+ import type { AdjustmentKind } from "./AdjustmentKind.mjs"
2
3
  import type { BindingError } from "./BindingError.mjs"
3
4
  import type { TaxExemption } from "./TaxExemption.mjs"
4
5
  import type { Text } from "./Text.mjs"
6
+ import type { VatCategory } from "./VatCategory.mjs"
5
7
  import type { pointer, codepoint } from "./diplomat-runtime.mjs";
6
8
 
7
9
 
@@ -15,7 +17,7 @@ export class AllowanceCharge {
15
17
 
16
18
  hasVatRate(): boolean;
17
19
 
18
- withoutVatRate(): AllowanceCharge;
20
+ omitVatRate(): AllowanceCharge;
19
21
 
20
22
  /**
21
23
  * Retain this adjustment's metadata and check its percentage calculation.
@@ -26,15 +28,15 @@ export class AllowanceCharge {
26
28
 
27
29
  percentage(): Text | null;
28
30
 
29
- static new_(charge: boolean, amount: string, reason: string | null, reasonCode: string | null, category: number, rate: string, exemption: TaxExemption): AllowanceCharge;
31
+ static new_(kind: AdjustmentKind, amount: string, reason: string | null, reasonCode: string | null, category: VatCategory, rate: string, exemption: TaxExemption): AllowanceCharge;
30
32
 
31
- isCharge(): boolean;
33
+ kind(): AdjustmentKind;
32
34
 
33
35
  amount(): string;
34
36
 
35
37
  rate(): string;
36
38
 
37
- category(): number;
39
+ category(): VatCategory;
38
40
 
39
41
  /**
40
42
  * Return an independent adjustment with the given number of identical tax classifications.
@@ -1,7 +1,9 @@
1
1
  // generated by diplomat-tool
2
+ import { AdjustmentKind } from "./AdjustmentKind.mjs"
2
3
  import { BindingError } from "./BindingError.mjs"
3
4
  import { TaxExemption } from "./TaxExemption.mjs"
4
5
  import { Text } from "./Text.mjs"
6
+ import { VatCategory } from "./VatCategory.mjs"
5
7
  import wasm from "./diplomat-wasm.mjs";
6
8
  import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
9
 
@@ -51,11 +53,11 @@ export class AllowanceCharge {
51
53
  }
52
54
  }
53
55
 
54
- withoutVatRate() {
56
+ omitVatRate() {
55
57
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
56
58
 
57
59
 
58
- const result = wasm.fatoora_AllowanceCharge_without_vat_rate(diplomatReceive.buffer, this.ffiValue);
60
+ const result = wasm.fatoora_AllowanceCharge_omit_vat_rate(diplomatReceive.buffer, this.ffiValue);
59
61
 
60
62
  try {
61
63
  if (!diplomatReceive.resultFlag) {
@@ -140,7 +142,7 @@ export class AllowanceCharge {
140
142
  }
141
143
  }
142
144
 
143
- static new_(charge, amount, reason, reasonCode, category, rate, exemption) {
145
+ static new_(kind, amount, reason, reasonCode, category, rate, exemption) {
144
146
  let functionCleanupArena = new diplomatRuntime.CleanupArena();
145
147
 
146
148
  const amountSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, amount)));
@@ -148,7 +150,7 @@ export class AllowanceCharge {
148
150
  const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
149
151
 
150
152
 
151
- const result = wasm.fatoora_AllowanceCharge_new(diplomatReceive.buffer, charge, amountSlice.ptr, diplomatRuntime.optionToBufferForCalling(wasm, reason, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]), diplomatRuntime.optionToBufferForCalling(wasm, reasonCode, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]), category, rateSlice.ptr, exemption instanceof TaxExemption ? exemption.ffiValue : typeError('exemption', 'TaxExemption'));
153
+ const result = wasm.fatoora_AllowanceCharge_new(diplomatReceive.buffer, new AdjustmentKind(kind).ffiValue, amountSlice.ptr, diplomatRuntime.optionToBufferForCalling(wasm, reason, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]), diplomatRuntime.optionToBufferForCalling(wasm, reasonCode, 8, 4, functionCleanupArena, (arrayBuffer, offset, jsValue) => [functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, jsValue)).writePtrLenToArrayBuffer(arrayBuffer, offset + 0)]), new VatCategory(category).ffiValue, rateSlice.ptr, exemption instanceof TaxExemption ? exemption.ffiValue : typeError('exemption', 'TaxExemption'));
152
154
 
153
155
  try {
154
156
  if (!diplomatReceive.resultFlag) {
@@ -166,12 +168,12 @@ export class AllowanceCharge {
166
168
  }
167
169
  }
168
170
 
169
- isCharge() {
171
+ kind() {
170
172
 
171
- const result = wasm.fatoora_AllowanceCharge_is_charge(this.ffiValue);
173
+ const result = wasm.fatoora_AllowanceCharge_kind(this.ffiValue);
172
174
 
173
175
  try {
174
- return result;
176
+ return new AdjustmentKind(diplomatRuntime.internalConstructor, result);
175
177
  }
176
178
 
177
179
  finally {
@@ -230,7 +232,7 @@ export class AllowanceCharge {
230
232
  const result = wasm.fatoora_AllowanceCharge_category(this.ffiValue);
231
233
 
232
234
  try {
233
- return result;
235
+ return new VatCategory(diplomatRuntime.internalConstructor, result);
234
236
  }
235
237
 
236
238
  finally {
@@ -0,0 +1,30 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.mjs";
3
+
4
+
5
+
6
+ /**
7
+ * Value of the `Clearance-Status` header sent with reporting and clearance requests.
8
+ */
9
+ export class ClearanceMode {
10
+
11
+ /** @internal */
12
+ static fromValue(value: ClearanceMode | string): ClearanceMode;
13
+
14
+ get value(): string;
15
+
16
+ /** @internal */
17
+ get ffiValue(): number;
18
+
19
+ /**
20
+ * Header value `0` (clearance is switched off for the taxpayer).
21
+ */
22
+ static Disabled : ClearanceMode;
23
+ /**
24
+ * Header value `1` (clearance is switched on for the taxpayer).
25
+ */
26
+ static Enabled : ClearanceMode;
27
+
28
+
29
+ constructor(value: ClearanceMode | string );
30
+ }
@@ -0,0 +1,78 @@
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
+ * Value of the `Clearance-Status` header sent with reporting and clearance requests.
9
+ */
10
+ export class ClearanceMode {
11
+ #value = undefined;
12
+
13
+ static #values = new Map([
14
+ ["Disabled", 0],
15
+ ["Enabled", 1]
16
+ ]);
17
+
18
+ static getAllEntries() {
19
+ return ClearanceMode.#values.entries();
20
+ }
21
+
22
+ #internalConstructor(value) {
23
+ if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
24
+ // We pass in two internalConstructor arguments to create *new*
25
+ // instances of this type, otherwise the enums are treated as singletons.
26
+ if (arguments[1] === diplomatRuntime.internalConstructor ) {
27
+ this.#value = arguments[2];
28
+ return this;
29
+ }
30
+ return ClearanceMode.#objectValues[arguments[1]];
31
+ }
32
+
33
+ if (value instanceof ClearanceMode) {
34
+ return value;
35
+ }
36
+
37
+ let intVal = ClearanceMode.#values.get(value);
38
+
39
+ // Nullish check, checks for null or undefined
40
+ if (intVal != null) {
41
+ return ClearanceMode.#objectValues[intVal];
42
+ }
43
+
44
+ throw TypeError(value + " is not a ClearanceMode and does not correspond to any of its enumerator values.");
45
+ }
46
+
47
+ /** @internal */
48
+ static fromValue(value) {
49
+ return new ClearanceMode(value);
50
+ }
51
+
52
+ get value(){
53
+ return [...ClearanceMode.#values.keys()][this.#value];
54
+ }
55
+
56
+ /** @internal */
57
+ get ffiValue(){
58
+ return this.#value;
59
+ }
60
+ static #objectValues = [
61
+ new ClearanceMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
62
+ new ClearanceMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
63
+ ];
64
+
65
+ /**
66
+ * Header value `0` (clearance is switched off for the taxpayer).
67
+ */
68
+ static Disabled = ClearanceMode.#objectValues[0];
69
+ /**
70
+ * Header value `1` (clearance is switched on for the taxpayer).
71
+ */
72
+ static Enabled = ClearanceMode.#objectValues[1];
73
+
74
+
75
+ constructor(value) {
76
+ return this.#internalConstructor(...arguments)
77
+ }
78
+ }
@@ -0,0 +1,34 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.mjs";
3
+
4
+
5
+
6
+ /**
7
+ * `clearanceStatus` of a clearance response.
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 ClearanceStatus {
13
+
14
+ /** @internal */
15
+ static fromValue(value: ClearanceStatus | string): ClearanceStatus;
16
+
17
+ get value(): string;
18
+
19
+ /** @internal */
20
+ get ffiValue(): number;
21
+
22
+ static Unknown : ClearanceStatus;
23
+ /**
24
+ * Wire value `CLEARED`.
25
+ */
26
+ static Cleared : ClearanceStatus;
27
+ /**
28
+ * Wire value `NOT_CLEARED`.
29
+ */
30
+ static NotCleared : ClearanceStatus;
31
+
32
+
33
+ constructor(value: ClearanceStatus | string );
34
+ }