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.
- package/README.md +9 -9
- package/errors.d.mts +67 -0
- package/errors.mjs +94 -0
- package/fatoora_ffi.wasm +0 -0
- package/generated/Adjustment.d.mts +9 -3
- package/generated/Adjustment.mjs +12 -6
- package/generated/AdjustmentKind.d.mts +24 -0
- package/generated/AdjustmentKind.mjs +72 -0
- package/generated/AllowanceCharge.d.mts +6 -4
- package/generated/AllowanceCharge.mjs +10 -8
- package/generated/ClearanceMode.d.mts +30 -0
- package/generated/ClearanceMode.mjs +78 -0
- package/generated/ClearanceStatus.d.mts +34 -0
- package/generated/ClearanceStatus.mjs +84 -0
- package/generated/{CsidCompliance.d.mts → ComplianceCsid.d.mts} +4 -3
- package/generated/{CsidCompliance.mjs → ComplianceCsid.mjs} +21 -13
- package/generated/ComplianceRequest.d.mts +2 -2
- package/generated/ComplianceRequest.mjs +2 -2
- package/generated/Config.d.mts +3 -2
- package/generated/Config.mjs +11 -3
- package/generated/CsrProperties.d.mts +6 -2
- package/generated/CsrProperties.mjs +7 -3
- package/generated/Environment.d.mts +28 -0
- package/generated/Environment.mjs +78 -0
- package/generated/FinalizedInvoice.d.mts +1 -1
- package/generated/FinalizedInvoice.mjs +2 -2
- package/generated/InvoiceBuilder.d.mts +18 -21
- package/generated/InvoiceBuilder.mjs +31 -168
- package/generated/InvoiceData.d.mts +7 -4
- package/generated/InvoiceData.mjs +8 -5
- package/generated/InvoiceFlag.d.mts +36 -0
- package/generated/InvoiceFlag.mjs +105 -0
- package/generated/InvoiceLineItem.d.mts +5 -3
- package/generated/InvoiceLineItem.mjs +8 -6
- package/generated/{Signer.d.mts → InvoiceSigner.d.mts} +3 -3
- package/generated/{Signer.mjs → InvoiceSigner.mjs} +13 -13
- package/generated/InvoiceSubType.d.mts +26 -0
- package/generated/InvoiceSubType.mjs +74 -0
- package/generated/InvoiceTypeKind.d.mts +40 -0
- package/generated/InvoiceTypeKind.mjs +92 -0
- package/generated/LineItemBuilder.d.mts +2 -1
- package/generated/LineItemBuilder.mjs +2 -1
- package/generated/MessageType.d.mts +38 -0
- package/generated/MessageType.mjs +90 -0
- package/generated/{CsidProduction.d.mts → ProductionCsid.d.mts} +4 -3
- package/generated/{CsidProduction.mjs → ProductionCsid.mjs} +21 -13
- package/generated/ProductionRequest.d.mts +2 -2
- package/generated/ProductionRequest.mjs +2 -2
- package/generated/ReportingStatus.d.mts +34 -0
- package/generated/ReportingStatus.mjs +84 -0
- package/generated/Severity.d.mts +30 -0
- package/generated/Severity.mjs +78 -0
- package/generated/SignedInvoice.d.mts +1 -1
- package/generated/SignedInvoice.mjs +2 -2
- package/generated/ValidationLayer.d.mts +49 -0
- package/generated/ValidationLayer.mjs +107 -0
- package/generated/ValidationLocationKind.d.mts +37 -0
- package/generated/ValidationLocationKind.mjs +89 -0
- package/generated/ValidationMessage.d.mts +20 -2
- package/generated/ValidationMessage.mjs +52 -0
- package/generated/ValidationResponse.d.mts +21 -3
- package/generated/ValidationResponse.mjs +52 -0
- package/generated/ValidationResults.d.mts +10 -1
- package/generated/ValidationResults.mjs +26 -0
- package/generated/ValidationStatus.d.mts +38 -0
- package/generated/ValidationStatus.mjs +90 -0
- package/generated/VatBreakdown.d.mts +4 -3
- package/generated/VatBreakdown.mjs +5 -4
- package/generated/VatCategory.d.mts +40 -0
- package/generated/VatCategory.mjs +92 -0
- package/generated/Xml.d.mts +12 -5
- package/generated/Xml.mjs +15 -11
- package/generated/ZatcaClient.d.mts +10 -9
- package/generated/ZatcaClient.mjs +15 -14
- package/generated/ZatcaFinding.d.mts +59 -0
- package/generated/ZatcaFinding.mjs +239 -0
- package/generated/ZatcaRuleSource.d.mts +26 -0
- package/generated/ZatcaRuleSource.mjs +97 -0
- package/generated/ZatcaStage.d.mts +49 -0
- package/generated/ZatcaStage.mjs +107 -0
- package/generated/ZatcaStageReport.d.mts +41 -0
- package/generated/ZatcaStageReport.mjs +168 -0
- package/generated/ZatcaStageStatus.d.mts +45 -0
- package/generated/ZatcaStageStatus.mjs +101 -0
- package/generated/ZatcaValidationReport.d.mts +63 -0
- package/generated/ZatcaValidationReport.mjs +228 -0
- package/generated/index.d.mts +45 -5
- package/generated/index.mjs +45 -5
- package/index.d.mts +131 -15
- package/index.mjs +111 -33
- package/members.mjs +67 -0
- package/package.json +10 -4
- package/patch.mjs +121 -0
- package/raw.d.mts +731 -0
- package/raw.mjs +4 -0
package/generated/index.d.mts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export { codepoint } from './diplomat-runtime.mjs';
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
export { CsidCompliance } from "./CsidCompliance.mjs"
|
|
5
|
+
export { ComplianceCsid } from "./ComplianceCsid.mjs"
|
|
8
6
|
|
|
9
|
-
export {
|
|
7
|
+
export { ComplianceRequest } from "./ComplianceRequest.mjs"
|
|
10
8
|
|
|
11
9
|
export { InvoiceRequest } from "./InvoiceRequest.mjs"
|
|
12
10
|
|
|
11
|
+
export { ProductionCsid } from "./ProductionCsid.mjs"
|
|
12
|
+
|
|
13
13
|
export { ProductionRequest } from "./ProductionRequest.mjs"
|
|
14
14
|
|
|
15
15
|
export { ValidationMessage } from "./ValidationMessage.mjs"
|
|
@@ -34,7 +34,7 @@ export { Csr } from "./Csr.mjs"
|
|
|
34
34
|
|
|
35
35
|
export { CsrProperties } from "./CsrProperties.mjs"
|
|
36
36
|
|
|
37
|
-
export {
|
|
37
|
+
export { InvoiceSigner } from "./InvoiceSigner.mjs"
|
|
38
38
|
|
|
39
39
|
export { SigningKey } from "./SigningKey.mjs"
|
|
40
40
|
|
|
@@ -76,4 +76,44 @@ export { VatId } from "./VatId.mjs"
|
|
|
76
76
|
|
|
77
77
|
export { Xml } from "./Xml.mjs"
|
|
78
78
|
|
|
79
|
+
export { ZatcaFinding } from "./ZatcaFinding.mjs"
|
|
80
|
+
|
|
81
|
+
export { ZatcaRuleSource } from "./ZatcaRuleSource.mjs"
|
|
82
|
+
|
|
83
|
+
export { ZatcaStageReport } from "./ZatcaStageReport.mjs"
|
|
84
|
+
|
|
85
|
+
export { ZatcaValidationReport } from "./ZatcaValidationReport.mjs"
|
|
86
|
+
|
|
87
|
+
export { ClearanceMode } from "./ClearanceMode.mjs"
|
|
88
|
+
|
|
89
|
+
export { ClearanceStatus } from "./ClearanceStatus.mjs"
|
|
90
|
+
|
|
79
91
|
export { InvoiceOutcome } from "./InvoiceOutcome.mjs"
|
|
92
|
+
|
|
93
|
+
export { MessageType } from "./MessageType.mjs"
|
|
94
|
+
|
|
95
|
+
export { ReportingStatus } from "./ReportingStatus.mjs"
|
|
96
|
+
|
|
97
|
+
export { ValidationStatus } from "./ValidationStatus.mjs"
|
|
98
|
+
|
|
99
|
+
export { Environment } from "./Environment.mjs"
|
|
100
|
+
|
|
101
|
+
export { AdjustmentKind } from "./AdjustmentKind.mjs"
|
|
102
|
+
|
|
103
|
+
export { InvoiceFlag } from "./InvoiceFlag.mjs"
|
|
104
|
+
|
|
105
|
+
export { InvoiceSubType } from "./InvoiceSubType.mjs"
|
|
106
|
+
|
|
107
|
+
export { InvoiceTypeKind } from "./InvoiceTypeKind.mjs"
|
|
108
|
+
|
|
109
|
+
export { VatCategory } from "./VatCategory.mjs"
|
|
110
|
+
|
|
111
|
+
export { Severity } from "./Severity.mjs"
|
|
112
|
+
|
|
113
|
+
export { ValidationLayer } from "./ValidationLayer.mjs"
|
|
114
|
+
|
|
115
|
+
export { ValidationLocationKind } from "./ValidationLocationKind.mjs"
|
|
116
|
+
|
|
117
|
+
export { ZatcaStage } from "./ZatcaStage.mjs"
|
|
118
|
+
|
|
119
|
+
export { ZatcaStageStatus } from "./ZatcaStageStatus.mjs"
|
package/generated/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
export { CsidCompliance } from "./CsidCompliance.mjs"
|
|
3
|
+
export { ComplianceCsid } from "./ComplianceCsid.mjs"
|
|
6
4
|
|
|
7
|
-
export {
|
|
5
|
+
export { ComplianceRequest } from "./ComplianceRequest.mjs"
|
|
8
6
|
|
|
9
7
|
export { InvoiceRequest } from "./InvoiceRequest.mjs"
|
|
10
8
|
|
|
9
|
+
export { ProductionCsid } from "./ProductionCsid.mjs"
|
|
10
|
+
|
|
11
11
|
export { ProductionRequest } from "./ProductionRequest.mjs"
|
|
12
12
|
|
|
13
13
|
export { ValidationMessage } from "./ValidationMessage.mjs"
|
|
@@ -32,7 +32,7 @@ export { Csr } from "./Csr.mjs"
|
|
|
32
32
|
|
|
33
33
|
export { CsrProperties } from "./CsrProperties.mjs"
|
|
34
34
|
|
|
35
|
-
export {
|
|
35
|
+
export { InvoiceSigner } from "./InvoiceSigner.mjs"
|
|
36
36
|
|
|
37
37
|
export { SigningKey } from "./SigningKey.mjs"
|
|
38
38
|
|
|
@@ -74,8 +74,48 @@ export { VatId } from "./VatId.mjs"
|
|
|
74
74
|
|
|
75
75
|
export { Xml } from "./Xml.mjs"
|
|
76
76
|
|
|
77
|
+
export { ZatcaFinding } from "./ZatcaFinding.mjs"
|
|
78
|
+
|
|
79
|
+
export { ZatcaRuleSource } from "./ZatcaRuleSource.mjs"
|
|
80
|
+
|
|
81
|
+
export { ZatcaStageReport } from "./ZatcaStageReport.mjs"
|
|
82
|
+
|
|
83
|
+
export { ZatcaValidationReport } from "./ZatcaValidationReport.mjs"
|
|
84
|
+
|
|
85
|
+
export { ClearanceMode } from "./ClearanceMode.mjs"
|
|
86
|
+
|
|
87
|
+
export { ClearanceStatus } from "./ClearanceStatus.mjs"
|
|
88
|
+
|
|
77
89
|
export { InvoiceOutcome } from "./InvoiceOutcome.mjs"
|
|
78
90
|
|
|
91
|
+
export { MessageType } from "./MessageType.mjs"
|
|
92
|
+
|
|
93
|
+
export { ReportingStatus } from "./ReportingStatus.mjs"
|
|
94
|
+
|
|
95
|
+
export { ValidationStatus } from "./ValidationStatus.mjs"
|
|
96
|
+
|
|
97
|
+
export { Environment } from "./Environment.mjs"
|
|
98
|
+
|
|
99
|
+
export { AdjustmentKind } from "./AdjustmentKind.mjs"
|
|
100
|
+
|
|
101
|
+
export { InvoiceFlag } from "./InvoiceFlag.mjs"
|
|
102
|
+
|
|
103
|
+
export { InvoiceSubType } from "./InvoiceSubType.mjs"
|
|
104
|
+
|
|
105
|
+
export { InvoiceTypeKind } from "./InvoiceTypeKind.mjs"
|
|
106
|
+
|
|
107
|
+
export { VatCategory } from "./VatCategory.mjs"
|
|
108
|
+
|
|
109
|
+
export { Severity } from "./Severity.mjs"
|
|
110
|
+
|
|
111
|
+
export { ValidationLayer } from "./ValidationLayer.mjs"
|
|
112
|
+
|
|
113
|
+
export { ValidationLocationKind } from "./ValidationLocationKind.mjs"
|
|
114
|
+
|
|
115
|
+
export { ZatcaStage } from "./ZatcaStage.mjs"
|
|
116
|
+
|
|
117
|
+
export { ZatcaStageStatus } from "./ZatcaStageStatus.mjs"
|
|
118
|
+
|
|
79
119
|
import wasm from "./diplomat-wasm.mjs";
|
|
80
120
|
import {FUNCTION_PARAM_ALLOC, internalConstructor} from "./diplomat-runtime.mjs";
|
|
81
121
|
|
package/index.d.mts
CHANGED
|
@@ -1,21 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// The generated classes as adapted by patch.mjs (raw.d.mts, generated by
|
|
2
|
+
// scripts/generate_js_facade.py). Value getters are read-only properties,
|
|
3
|
+
// optional text is `string | null` and a Rust `new` constructor is `create`.
|
|
4
|
+
// `Xml`, `ZatcaClient` and the validation report types are replaced below.
|
|
5
|
+
export * from './raw.mjs';
|
|
6
|
+
export * from './errors.mjs';
|
|
7
|
+
import type {
|
|
8
|
+
ClearanceMode, ComplianceCsid, ComplianceRequest, Config, Csr, InvoiceRequest,
|
|
9
|
+
ProductionCsid, ProductionRequest, SignedInvoice, ValidationResponse,
|
|
10
|
+
} from './raw.mjs';
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Enum value names. Each union lists the `.value` strings of the enum class of
|
|
14
|
+
// the same name; tests/runtime.test.mjs checks them against the runtime.
|
|
15
|
+
|
|
16
|
+
export type AdjustmentKindValue = 'Allowance' | 'Charge';
|
|
17
|
+
export type ClearanceModeValue = 'Disabled' | 'Enabled';
|
|
18
|
+
export type ClearanceStatusValue = 'Unknown' | 'Cleared' | 'NotCleared';
|
|
19
|
+
export type EnvironmentValue = 'NonProduction' | 'Simulation' | 'Production';
|
|
20
|
+
export type InvoiceFlagValue = 'ThirdParty' | 'Nominal' | 'Export' | 'Summary' | 'SelfBilled';
|
|
21
|
+
export type InvoiceOutcomeValue = 'Unknown' | 'Accepted' | 'Rejected';
|
|
22
|
+
export type InvoiceSubTypeValue = 'Standard' | 'Simplified';
|
|
23
|
+
export type InvoiceTypeKindValue = 'Tax' | 'Prepayment' | 'CreditNote' | 'DebitNote';
|
|
24
|
+
export type MessageTypeValue = 'Unknown' | 'Info' | 'Warning' | 'Error';
|
|
25
|
+
export type ReportingStatusValue = 'Unknown' | 'Reported' | 'NotReported';
|
|
26
|
+
export type SeverityValue = 'Warning' | 'Error';
|
|
27
|
+
export type ValidationLayerValue = 'Unknown' | 'FieldChecks' | 'Xsd' | 'BusinessRules' | 'Signature' | 'Qr' | 'PreviousInvoiceHash';
|
|
28
|
+
export type ValidationLocationKindValue = 'Unknown' | 'Field' | 'XPath' | 'Xml';
|
|
29
|
+
export type ValidationStatusValue = 'Unknown' | 'Pass' | 'Warning' | 'Error';
|
|
30
|
+
export type VatCategoryValue = 'Exempt' | 'Standard' | 'Zero' | 'OutOfScope';
|
|
31
|
+
export type ZatcaStageValue = 'Unknown' | 'Xsd' | 'Cen' | 'Ksa' | 'Signature' | 'Qr' | 'PreviousInvoiceHash';
|
|
32
|
+
export type ZatcaStageStatusValue = 'Unknown' | 'NotRun' | 'Completed' | 'NotApplicable' | 'ContextRequired' | 'EvaluationFailed';
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Local validation report: plain data copied out of WASM by `Xml.validateZatca`.
|
|
36
|
+
|
|
37
|
+
/** Where a finding points, discriminated by `kind`. */
|
|
38
|
+
export type ZatcaFindingLocation =
|
|
39
|
+
| { readonly kind: 'Field' | 'XPath'; readonly path: string | null }
|
|
40
|
+
| { readonly kind: 'Xml'; readonly line: number | null; readonly column: number | null }
|
|
41
|
+
| { readonly kind: 'Unknown' };
|
|
42
|
+
|
|
43
|
+
/** One validation finding. */
|
|
44
|
+
export interface ZatcaFinding {
|
|
45
|
+
/** Library-owned rule identifier, independent of message wording. */
|
|
46
|
+
readonly code: string;
|
|
47
|
+
readonly severity: SeverityValue;
|
|
48
|
+
readonly layer: ValidationLayerValue;
|
|
49
|
+
/** Human-readable text; the wording is not a stable API. */
|
|
50
|
+
readonly message: string;
|
|
51
|
+
/** Rule assertion that produced the finding, for business-rule findings. */
|
|
52
|
+
readonly assertionSite: string | null;
|
|
53
|
+
/** `null` when the source cannot locate the finding. */
|
|
54
|
+
readonly location: ZatcaFindingLocation | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Pinned upstream rule source of a business-rule stage. */
|
|
58
|
+
export interface ZatcaRuleSource {
|
|
59
|
+
/** File name of the upstream rule stylesheet. */
|
|
60
|
+
readonly stylesheet: string;
|
|
61
|
+
/** Hex SHA-256 digest of the pinned stylesheet. */
|
|
62
|
+
readonly sha256: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Coverage and findings from one validation stage. */
|
|
66
|
+
export interface ZatcaStageReport {
|
|
67
|
+
readonly stage: ZatcaStageValue;
|
|
68
|
+
readonly status: ZatcaStageStatusValue;
|
|
69
|
+
/** Pinned rule source, for the CEN and KSA business-rule stages. */
|
|
70
|
+
readonly provenance: ZatcaRuleSource | null;
|
|
71
|
+
/** Assertion sites whose selected contexts were all evaluated. */
|
|
72
|
+
readonly evaluatedAssertions: readonly string[];
|
|
73
|
+
readonly findings: readonly ZatcaFinding[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Results of local ZATCA validation with explicit stage coverage. Completion
|
|
78
|
+
* and validity describe only the local profile; they do not establish
|
|
79
|
+
* acceptance by ZATCA or certificate issuer trust.
|
|
80
|
+
*/
|
|
81
|
+
export interface ZatcaValidationReport {
|
|
82
|
+
/** Version of the report's serialized format. */
|
|
83
|
+
readonly schemaVersion: number;
|
|
84
|
+
/** Identifier of the validation profile (the ZATCA SDK release it mirrors). */
|
|
85
|
+
readonly profile: string;
|
|
86
|
+
/** RFC 3339 instant used for time-dependent rules. */
|
|
87
|
+
readonly evaluatedAt: string;
|
|
88
|
+
/** Whether every required stage finished exactly once. */
|
|
89
|
+
readonly isComplete: boolean;
|
|
90
|
+
/** Whether any stage, including an incomplete stage, reported an error. */
|
|
91
|
+
readonly hasErrors: boolean;
|
|
92
|
+
/** Whether validation is complete and contains no error findings. */
|
|
93
|
+
readonly isValid: boolean;
|
|
94
|
+
/** Stage reports, in stage order. */
|
|
95
|
+
readonly stages: readonly ZatcaStageReport[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ZatcaValidationOptions {
|
|
99
|
+
/** Hash of the preceding invoice; without it the chain stage is incomplete. */
|
|
100
|
+
previousInvoiceHash?: string | null;
|
|
101
|
+
/** Instant for time-dependent rules; defaults to the host clock. */
|
|
102
|
+
evaluatedAt?: string | Date | null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare class Xml {
|
|
106
|
+
private constructor();
|
|
107
|
+
/** Check the XML against the UBL schema and business rules; throws on failure. */
|
|
108
|
+
static validate(xml: string): boolean;
|
|
109
|
+
/** Base64 invoice hash. */
|
|
110
|
+
static hash(xml: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Run the local ZATCA validation profile. Inspect `isValid` before acceptance.
|
|
113
|
+
* `options` may also be the raw options JSON string (`previous_invoice_hash`,
|
|
114
|
+
* `evaluated_at`). The host clock is used when no instant is given.
|
|
115
|
+
*/
|
|
116
|
+
static validateZatca(xml: string, options?: ZatcaValidationOptions | string | null): ZatcaValidationReport;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Async API client.
|
|
121
|
+
|
|
4
122
|
export interface RequestOptions { signal?: AbortSignal; }
|
|
5
123
|
export interface TransportOptions extends RequestOptions { fetch?: typeof fetch; }
|
|
6
|
-
|
|
124
|
+
/** The Clearance-Status request header: a boolean, a `ClearanceMode` or its value name. */
|
|
125
|
+
export type ClearanceModeInput = boolean | ClearanceMode | ClearanceModeValue;
|
|
7
126
|
export function sendPrepared(request: InvoiceRequest, options?: TransportOptions): Promise<ValidationResponse>;
|
|
8
|
-
export function sendPrepared(request: ComplianceRequest, options?: TransportOptions): Promise<
|
|
9
|
-
export function sendPrepared(request: ProductionRequest, options?: TransportOptions): Promise<
|
|
127
|
+
export function sendPrepared(request: ComplianceRequest, options?: TransportOptions): Promise<ComplianceCsid>;
|
|
128
|
+
export function sendPrepared(request: ProductionRequest, options?: TransportOptions): Promise<ProductionCsid>;
|
|
10
129
|
export class ZatcaClient {
|
|
11
130
|
constructor(config: Config, options?: Pick<TransportOptions, 'fetch'>);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
renewCsid(credentials:
|
|
15
|
-
checkInvoiceCompliance(invoice: SignedInvoice, credentials:
|
|
16
|
-
reportSimplifiedInvoice(invoice: SignedInvoice, credentials:
|
|
17
|
-
clearStandardInvoice(invoice: SignedInvoice, credentials:
|
|
18
|
-
}
|
|
19
|
-
export class Xml extends NativeXml {
|
|
20
|
-
static validateZatca(config: Config, xml: string, optionsJson?: string | null): string;
|
|
131
|
+
requestComplianceCsid(csr: Csr, otp: string, options?: RequestOptions): Promise<ComplianceCsid>;
|
|
132
|
+
requestProductionCsid(credentials: ComplianceCsid, options?: RequestOptions): Promise<ProductionCsid>;
|
|
133
|
+
renewCsid(credentials: ProductionCsid, csr: Csr, otp: string, acceptLanguage?: string | null, options?: RequestOptions): Promise<ProductionCsid>;
|
|
134
|
+
checkInvoiceCompliance(invoice: SignedInvoice, credentials: ComplianceCsid, options?: RequestOptions): Promise<ValidationResponse>;
|
|
135
|
+
reportSimplifiedInvoice(invoice: SignedInvoice, credentials: ProductionCsid, clearanceStatus?: ClearanceModeInput, acceptLanguage?: string | null, options?: RequestOptions): Promise<ValidationResponse>;
|
|
136
|
+
clearStandardInvoice(invoice: SignedInvoice, credentials: ProductionCsid, clearanceStatus?: ClearanceModeInput, acceptLanguage?: string | null, options?: RequestOptions): Promise<ValidationResponse>;
|
|
21
137
|
}
|
package/index.mjs
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import { ZatcaClient as NativeClient, Xml as NativeXml } from './generated/index.mjs';
|
|
1
|
+
import './patch.mjs';
|
|
2
|
+
import { ClearanceMode, ZatcaClient as NativeClient, Xml as NativeXml } from './generated/index.mjs';
|
|
3
|
+
import { TransportError } from './errors.mjs';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
// Generated classes re-exported unchanged (after patch.mjs). The native
|
|
6
|
+
// validation report classes stay in `fatoority/raw`; `Xml` and `ZatcaClient`
|
|
7
|
+
// are replaced below. tests/runtime.test.mjs checks this list stays complete.
|
|
8
|
+
export {
|
|
9
|
+
Address, Adjustment, AdjustmentKind, AllowanceCharge, BindingError, Bytes, BytesList,
|
|
10
|
+
ClearanceMode, ClearanceStatus, ComplianceCsid, ComplianceRequest, Config, Csr, CsrProperties,
|
|
11
|
+
Environment, FinalizedInvoice, InvoiceBuilder, InvoiceData, InvoiceFlag, InvoiceLineItem,
|
|
12
|
+
InvoiceNote, InvoiceOutcome, InvoiceRequest, InvoiceSigner, InvoiceSubType, InvoiceTotals,
|
|
13
|
+
InvoiceTypeKind, LineItemBuilder, MessageType, OriginalInvoiceRef, OtherId, Party, PaymentMeans,
|
|
14
|
+
ProductionCsid, ProductionRequest, ReportingStatus, Severity, SignedInvoice, SigningKey,
|
|
15
|
+
TaxExemption, Text, ValidationLayer, ValidationLocationKind, ValidationMessage,
|
|
16
|
+
ValidationResponse, ValidationResults, ValidationStatus, VatBreakdown, VatCategory, VatId,
|
|
17
|
+
ZatcaStage, ZatcaStageStatus,
|
|
18
|
+
} from './generated/index.mjs';
|
|
19
|
+
export {
|
|
20
|
+
ErrorCode, FatooraError, InvalidInputError, ValidationError, ParseError, XmlError, CryptoError,
|
|
21
|
+
IoError, NetworkError, UnauthorizedError, InternalError, ApiError, TransportError,
|
|
22
|
+
errorClassForCode,
|
|
23
|
+
} from './errors.mjs';
|
|
24
|
+
|
|
25
|
+
/** Accept a boolean, a ClearanceMode or its value name for the Clearance-Status header. */
|
|
26
|
+
function clearanceMode(value) {
|
|
27
|
+
if (value instanceof ClearanceMode) return value;
|
|
28
|
+
if (typeof value === 'boolean') return value ? ClearanceMode.Enabled : ClearanceMode.Disabled;
|
|
29
|
+
if (value === 'Enabled' || value === 'Disabled') return ClearanceMode[value];
|
|
30
|
+
throw new TypeError('clearanceStatus must be a boolean or ClearanceMode');
|
|
11
31
|
}
|
|
12
32
|
|
|
13
33
|
/** Send an owned prepared request using the caller's fetch implementation. */
|
|
14
34
|
export async function sendPrepared(request, { fetch: fetchImpl = globalThis.fetch, signal } = {}) {
|
|
15
35
|
// Complete every read of WASM memory before invoking user code or awaiting IO.
|
|
16
|
-
const url = request.url
|
|
36
|
+
const url = request.url;
|
|
17
37
|
const init = {
|
|
18
|
-
method: request.method
|
|
38
|
+
method: request.method, headers: JSON.parse(request.headersJson),
|
|
19
39
|
body: Uint8Array.from(request.body().asSlice()), redirect: 'error', signal,
|
|
20
40
|
};
|
|
21
41
|
let response;
|
|
@@ -36,11 +56,11 @@ export class ZatcaClient {
|
|
|
36
56
|
this.#native = NativeClient.create(config);
|
|
37
57
|
this.#fetch = fetchImpl;
|
|
38
58
|
}
|
|
39
|
-
async
|
|
40
|
-
return this.#send(this.#native.
|
|
59
|
+
async requestComplianceCsid(csr, otp, options = {}) {
|
|
60
|
+
return this.#send(this.#native.prepareRequestComplianceCsid(csr, otp), options);
|
|
41
61
|
}
|
|
42
|
-
async
|
|
43
|
-
return this.#send(this.#native.
|
|
62
|
+
async requestProductionCsid(credentials, options = {}) {
|
|
63
|
+
return this.#send(this.#native.prepareRequestProductionCsid(credentials), options);
|
|
44
64
|
}
|
|
45
65
|
async renewCsid(credentials, csr, otp, acceptLanguage = null, options = {}) {
|
|
46
66
|
return this.#send(this.#native.prepareRenewCsid(credentials, csr, otp, acceptLanguage), options);
|
|
@@ -49,29 +69,87 @@ export class ZatcaClient {
|
|
|
49
69
|
return this.#send(this.#native.prepareCheckInvoiceCompliance(invoice, credentials), options);
|
|
50
70
|
}
|
|
51
71
|
async reportSimplifiedInvoice(invoice, credentials, clearanceStatus = false, acceptLanguage = null, options = {}) {
|
|
52
|
-
return this.#send(this.#native.prepareReportSimplifiedInvoice(invoice, credentials, clearanceStatus, acceptLanguage), options);
|
|
72
|
+
return this.#send(this.#native.prepareReportSimplifiedInvoice(invoice, credentials, clearanceMode(clearanceStatus), acceptLanguage), options);
|
|
53
73
|
}
|
|
54
74
|
async clearStandardInvoice(invoice, credentials, clearanceStatus = true, acceptLanguage = null, options = {}) {
|
|
55
|
-
return this.#send(this.#native.prepareClearStandardInvoice(invoice, credentials, clearanceStatus, acceptLanguage), options);
|
|
75
|
+
return this.#send(this.#native.prepareClearStandardInvoice(invoice, credentials, clearanceMode(clearanceStatus), acceptLanguage), options);
|
|
56
76
|
}
|
|
57
77
|
#send(request, options) { return sendPrepared(request, { ...options, fetch: this.#fetch }); }
|
|
58
78
|
}
|
|
59
79
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
function location(finding) {
|
|
81
|
+
const kind = finding.locationKind;
|
|
82
|
+
if (kind === null) return null;
|
|
83
|
+
switch (kind.value) {
|
|
84
|
+
case 'Field': case 'XPath': return { kind: kind.value, path: finding.locationPath };
|
|
85
|
+
case 'Xml': return { kind: 'Xml', line: finding.locationLine, column: finding.locationColumn };
|
|
86
|
+
default: return { kind: kind.value };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function finding(native) {
|
|
91
|
+
return {
|
|
92
|
+
code: native.code, severity: native.severity.value, layer: native.layer.value,
|
|
93
|
+
message: native.message, assertionSite: native.assertionSite, location: location(native),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function stage(native) {
|
|
98
|
+
const provenance = native.provenance();
|
|
99
|
+
return {
|
|
100
|
+
stage: native.stage.value,
|
|
101
|
+
status: native.status.value,
|
|
102
|
+
provenance: provenance === null ? null : { stylesheet: provenance.stylesheet, sha256: provenance.sha256 },
|
|
103
|
+
evaluatedAssertions: Array.from({ length: native.evaluatedAssertionsLen }, (_, i) => native.evaluatedAssertion(i)),
|
|
104
|
+
findings: Array.from({ length: native.findingsLen }, (_, i) => finding(native.finding(i))),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Copy a native report into plain data once, so no WASM handle outlives the call. */
|
|
109
|
+
function report(native) {
|
|
110
|
+
return {
|
|
111
|
+
schemaVersion: native.schemaVersion,
|
|
112
|
+
profile: native.profile,
|
|
113
|
+
evaluatedAt: native.evaluatedAt,
|
|
114
|
+
isComplete: native.isComplete,
|
|
115
|
+
hasErrors: native.hasErrors,
|
|
116
|
+
isValid: native.isValid,
|
|
117
|
+
stages: Array.from({ length: native.stagesLen }, (_, i) => stage(native.stage(i))),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function optionsJson(options) {
|
|
122
|
+
if (options === null || options === undefined) return null;
|
|
123
|
+
if (typeof options === 'string') return options;
|
|
124
|
+
if (typeof options !== 'object' || Array.isArray(options)) {
|
|
125
|
+
throw new TypeError('options must be an object, a JSON string or null');
|
|
126
|
+
}
|
|
127
|
+
const { previousInvoiceHash = null, evaluatedAt = null } = options;
|
|
128
|
+
return JSON.stringify({
|
|
129
|
+
previous_invoice_hash: previousInvoiceHash,
|
|
130
|
+
evaluated_at: evaluatedAt instanceof Date ? evaluatedAt.toISOString() : evaluatedAt,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Supply the host clock once; explicit evaluated_at remains reproducible. */
|
|
135
|
+
function withClock(json) {
|
|
136
|
+
// Let Rust produce its error for malformed, non-object or oversized input.
|
|
137
|
+
// Check the original bytes before normalization so whitespace cannot evade the limit.
|
|
138
|
+
if (json === null) return JSON.stringify({ evaluated_at: new Date().toISOString() });
|
|
139
|
+
if (new TextEncoder().encode(json).length > 4096) return json;
|
|
140
|
+
let options;
|
|
141
|
+
try { options = JSON.parse(json); }
|
|
142
|
+
catch { return json; }
|
|
143
|
+
if (options === null || typeof options !== 'object' || Array.isArray(options)) return json;
|
|
144
|
+
options.evaluated_at ??= new Date().toISOString();
|
|
145
|
+
return JSON.stringify(options);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class Xml {
|
|
149
|
+
constructor() { throw new TypeError('Xml has only static methods'); }
|
|
150
|
+
static validate(xml) { return NativeXml.validate(xml); }
|
|
151
|
+
static hash(xml) { return NativeXml.hash(xml); }
|
|
152
|
+
static validateZatca(xml, options = null) {
|
|
153
|
+
return report(NativeXml.validateZatca(xml, withClock(optionsJson(options))));
|
|
76
154
|
}
|
|
77
155
|
}
|
package/members.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Generated by scripts/generate_js_facade.py; do not edit.
|
|
2
|
+
// Read by patch.mjs; see scripts/generate_js_facade.py for the rules.
|
|
3
|
+
|
|
4
|
+
/** Zero-argument value getters exposed as read-only properties. */
|
|
5
|
+
export const properties = {
|
|
6
|
+
Address: ['province', 'city', 'street', 'buildingNumber', 'postalCode', 'countryCode', 'additionalStreet', 'additionalNumber', 'district'],
|
|
7
|
+
Adjustment: ['value', 'baseAmount', 'percentage', 'reason', 'reasonCode'],
|
|
8
|
+
AllowanceCharge: ['hasVatRate', 'baseAmount', 'percentage', 'kind', 'amount', 'rate', 'category', 'taxCategoryCount', 'reason', 'reasonCode'],
|
|
9
|
+
ComplianceCsid: ['env', 'requestId', 'binarySecurityToken', 'secret'],
|
|
10
|
+
ComplianceRequest: ['method', 'url', 'headersJson'],
|
|
11
|
+
Config: ['env'],
|
|
12
|
+
Csr: ['subjectString'],
|
|
13
|
+
FinalizedInvoice: ['hash', 'xml'],
|
|
14
|
+
InvoiceData: ['issueTime', 'issueDate', 'paymentMeansLen', 'purchaseOrderId', 'contractId', 'paymentInstruction', 'actualDeliveryDate', 'latestDeliveryDate', 'taxCurrency', 'taxCurrencyAmount', 'adjustmentsLen', 'id', 'uuid', 'previousInvoiceHash', 'paymentMeansCode', 'currency', 'issueDatetime', 'invoiceLevelCharge', 'invoiceLevelDiscount', 'allowanceReason', 'invoiceCounter', 'vatCategory', 'flags', 'invoiceTypeKind', 'invoiceSubType', 'lineItemsLen', 'originalInvoiceReason', 'notesLen', 'billingReferencesLen'],
|
|
15
|
+
InvoiceFlag: ['bit'],
|
|
16
|
+
InvoiceLineItem: ['itemGrossPrice', 'itemPriceDiscount', 'itemPriceBaseQuantity', 'itemPriceBaseQuantityUnitCode', 'adjustmentsLen', 'documentReferencesLen', 'taxSubtotalsLen', 'id', 'description', 'unitCode', 'quantity', 'unitPrice', 'totalAmount', 'vatRate', 'vatAmount', 'hasVatRate', 'hasTaxTotal', 'hasGrossAmount', 'vatCategory'],
|
|
17
|
+
InvoiceNote: ['languageId', 'language', 'text'],
|
|
18
|
+
InvoiceRequest: ['method', 'url', 'headersJson'],
|
|
19
|
+
InvoiceSigner: ['certificatePem'],
|
|
20
|
+
InvoiceTotals: ['vatBreakdownLen', 'taxInclusive', 'taxAmount', 'lineExtension', 'allowanceTotal', 'chargeTotal', 'taxableAmount', 'prepaidAmount', 'payableRoundingAmount', 'payableAmount'],
|
|
21
|
+
OriginalInvoiceRef: ['issueTime', 'documentTypeCode', 'id', 'uuid', 'issueDate'],
|
|
22
|
+
OtherId: ['value', 'scheme'],
|
|
23
|
+
Party: ['identifiersLen', 'name'],
|
|
24
|
+
PaymentMeans: ['instructionNotesLen', 'code', 'instructionNote', 'hasAccount', 'accountIdentifier', 'paymentTerms'],
|
|
25
|
+
ProductionCsid: ['env', 'requestId', 'binarySecurityToken', 'secret'],
|
|
26
|
+
ProductionRequest: ['method', 'url', 'headersJson'],
|
|
27
|
+
SignedInvoice: ['hash', 'xml', 'qrCode', 'signature', 'publicKey', 'invoiceHash', 'issuer', 'serial', 'certHash', 'signedPropsHash', 'signingTime', 'zatcaKeySignature'],
|
|
28
|
+
TaxExemption: ['reasonCode', 'reason'],
|
|
29
|
+
ValidationMessage: ['messageType', 'messageTypeRaw', 'code', 'category', 'message', 'status', 'statusRaw'],
|
|
30
|
+
ValidationResponse: ['httpStatus', 'outcome', 'clearedInvoiceXml', 'clearedInvoiceBase64', 'reportingStatus', 'reportingStatusRaw', 'clearanceStatus', 'clearanceStatusRaw', 'qrSellerStatus', 'qrBuyerStatus'],
|
|
31
|
+
ValidationResults: ['status', 'statusRaw', 'infoLen', 'warningLen', 'errorLen'],
|
|
32
|
+
VatBreakdown: ['hasVatRate', 'category', 'rate', 'taxableAmount', 'taxAmount'],
|
|
33
|
+
VatId: ['value'],
|
|
34
|
+
ZatcaFinding: ['assertionSite', 'layer', 'code', 'severity', 'message', 'locationKind', 'locationPath', 'locationLine', 'locationColumn'],
|
|
35
|
+
ZatcaRuleSource: ['stylesheet', 'sha256'],
|
|
36
|
+
ZatcaStageReport: ['stage', 'status', 'evaluatedAssertionsLen', 'findingsLen'],
|
|
37
|
+
ZatcaValidationReport: ['schemaVersion', 'profile', 'evaluatedAt', 'isComplete', 'hasErrors', 'isValid', 'stagesLen'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Members whose generated `Text` result is returned as a string. */
|
|
41
|
+
export const textResults = {
|
|
42
|
+
Address: ['province', 'additionalStreet', 'additionalNumber', 'district'],
|
|
43
|
+
Adjustment: ['baseAmount', 'percentage', 'reason', 'reasonCode'],
|
|
44
|
+
AllowanceCharge: ['baseAmount', 'percentage', 'reason', 'reasonCode'],
|
|
45
|
+
ComplianceCsid: ['requestId'],
|
|
46
|
+
InvoiceData: ['purchaseOrderId', 'contractId', 'paymentInstruction', 'actualDeliveryDate', 'latestDeliveryDate', 'taxCurrency', 'taxCurrencyAmount', 'allowanceReason', 'originalInvoiceReason'],
|
|
47
|
+
InvoiceLineItem: ['itemGrossPrice', 'itemPriceDiscount', 'itemPriceBaseQuantity', 'itemPriceBaseQuantityUnitCode', 'id'],
|
|
48
|
+
InvoiceNote: ['languageId'],
|
|
49
|
+
OriginalInvoiceRef: ['issueTime', 'documentTypeCode', 'uuid', 'issueDate'],
|
|
50
|
+
OtherId: ['scheme'],
|
|
51
|
+
PaymentMeans: ['instructionNoteAt', 'instructionNote', 'accountIdentifier', 'paymentTerms'],
|
|
52
|
+
ProductionCsid: ['requestId'],
|
|
53
|
+
SignedInvoice: ['zatcaKeySignature'],
|
|
54
|
+
TaxExemption: ['reasonCode', 'reason'],
|
|
55
|
+
ValidationMessage: ['messageTypeRaw', 'code', 'category', 'message', 'statusRaw'],
|
|
56
|
+
ValidationResponse: ['clearedInvoiceXml', 'clearedInvoiceBase64', 'reportingStatusRaw', 'clearanceStatusRaw', 'qrSellerStatus', 'qrBuyerStatus'],
|
|
57
|
+
ValidationResults: ['statusRaw'],
|
|
58
|
+
ZatcaFinding: ['assertionSite', 'locationPath'],
|
|
59
|
+
ZatcaStageReport: ['evaluatedAssertion'],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** 0.5 names of members renamed in 0.6 to match the Rust core; removed in 0.7. */
|
|
63
|
+
export const renamedMembers = {
|
|
64
|
+
Adjustment: { prototype: { percent: 'percentage', withSuppliedAmount: 'suppliedAmount' }, static: { percentage: 'percentOf' } },
|
|
65
|
+
AllowanceCharge: { prototype: { withoutVatRate: 'omitVatRate' } },
|
|
66
|
+
VatBreakdown: { prototype: { withoutVatRate: 'omitVatRate' } },
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fatoority",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "ZATCA invoice SDK with Diplomat WebAssembly bindings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN THIRD_PARTY_NOTICES.md",
|
|
@@ -14,14 +14,20 @@
|
|
|
14
14
|
"default": "./index.mjs"
|
|
15
15
|
},
|
|
16
16
|
"./raw": {
|
|
17
|
-
"types": "./
|
|
18
|
-
"import": "./
|
|
19
|
-
"default": "./
|
|
17
|
+
"types": "./raw.d.mts",
|
|
18
|
+
"import": "./raw.mjs",
|
|
19
|
+
"default": "./raw.mjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"index.mjs",
|
|
24
24
|
"index.d.mts",
|
|
25
|
+
"errors.mjs",
|
|
26
|
+
"errors.d.mts",
|
|
27
|
+
"patch.mjs",
|
|
28
|
+
"raw.mjs",
|
|
29
|
+
"raw.d.mts",
|
|
30
|
+
"members.mjs",
|
|
25
31
|
"generated",
|
|
26
32
|
"licenses",
|
|
27
33
|
"fatoora_ffi.wasm",
|