@taxora/sdk 1.0.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.
@@ -0,0 +1,315 @@
1
+ declare class Token {
2
+ readonly accessToken: string;
3
+ readonly tokenType: string;
4
+ readonly expiresAt: Date;
5
+ constructor(accessToken: string, tokenType: string, expiresAt: Date);
6
+ isExpired(bufferSeconds?: number): boolean;
7
+ static fromArray(data: Record<string, unknown>): Token;
8
+ toArray(): {
9
+ access_token: string;
10
+ token_type: string;
11
+ expires_at: string;
12
+ };
13
+ }
14
+
15
+ declare const LoginIdentifier: {
16
+ readonly EMAIL: "email";
17
+ readonly CLIENT_ID: "client_id";
18
+ };
19
+ type LoginIdentifier = (typeof LoginIdentifier)[keyof typeof LoginIdentifier];
20
+
21
+ interface HttpClientInterface {
22
+ request(method: string, url: string, options?: RequestInit): Promise<Response>;
23
+ }
24
+
25
+ interface TokenStorageInterface {
26
+ get(): Token | null;
27
+ set(token: Token): void;
28
+ clear(): void;
29
+ }
30
+
31
+ declare class AuthEndpoint {
32
+ private readonly baseUrl;
33
+ private readonly apiKey;
34
+ private readonly tokenStorage;
35
+ private readonly httpClient;
36
+ constructor(baseUrl: string, apiKey: string, tokenStorage: TokenStorageInterface, httpClient: HttpClientInterface);
37
+ login(identifier: string, password: string, device?: string, loginIdentifier?: LoginIdentifier): Promise<Token>;
38
+ loginWithClientId(clientId: string, password: string, device?: string): Promise<Token>;
39
+ refresh(): Promise<Token>;
40
+ private parseResponse;
41
+ }
42
+
43
+ declare class CompanyEndpoint {
44
+ private readonly baseUrl;
45
+ private readonly apiKey;
46
+ private readonly tokenStorage;
47
+ private readonly httpClient;
48
+ constructor(baseUrl: string, apiKey: string, tokenStorage: TokenStorageInterface, httpClient: HttpClientInterface);
49
+ get(): Promise<Record<string, unknown>>;
50
+ }
51
+
52
+ declare const VatState: {
53
+ readonly VALID: "valid";
54
+ readonly INVALID: "invalid";
55
+ readonly FRAUD: "fraud";
56
+ readonly UNKNOWN: "unknown";
57
+ };
58
+ type VatState = (typeof VatState)[keyof typeof VatState];
59
+ declare function getFailedVatStates(): VatState[];
60
+ declare function describeVatState(state: VatState): string;
61
+
62
+ interface CompanyAddressProps {
63
+ fullAddress?: string | null;
64
+ name?: string | null;
65
+ street?: string | null;
66
+ postalCode?: string | null;
67
+ city?: string | null;
68
+ state?: string | null;
69
+ country?: string | null;
70
+ raw?: string | null;
71
+ }
72
+ declare class CompanyAddress {
73
+ readonly fullAddress: string | null;
74
+ readonly name: string | null;
75
+ readonly street: string | null;
76
+ readonly postalCode: string | null;
77
+ readonly city: string | null;
78
+ readonly state: string | null;
79
+ readonly country: string | null;
80
+ readonly raw: string | null;
81
+ constructor(props: CompanyAddressProps);
82
+ private assembleFullAddress;
83
+ static from(value: unknown): CompanyAddress | null;
84
+ static fromArray(data: Record<string, unknown>, raw: string | null): CompanyAddress;
85
+ toArray(): Record<string, string | null>;
86
+ toString(): string;
87
+ }
88
+
89
+ declare class ScoreBreakdown {
90
+ readonly stepName: string;
91
+ readonly scoreContribution: number;
92
+ readonly metadata: Record<string, unknown>;
93
+ constructor(stepName: string, scoreContribution: number, metadata: Record<string, unknown>);
94
+ static fromArray(data: Record<string, unknown>): ScoreBreakdown;
95
+ toArray(): {
96
+ step_name: string;
97
+ score_contribution: number;
98
+ metadata: Record<string, unknown>;
99
+ };
100
+ }
101
+
102
+ declare class ProviderDocumentLine {
103
+ readonly id: number | null;
104
+ readonly vatUid: string | null;
105
+ readonly rowNumber: number | null;
106
+ readonly entryIdentifier: string | null;
107
+ readonly reference: string | null;
108
+ readonly meta: Record<string, unknown>;
109
+ constructor(id: number | null, vatUid: string | null, rowNumber: number | null, entryIdentifier: string | null, reference: string | null, meta: Record<string, unknown>);
110
+ static fromArray(data: unknown): ProviderDocumentLine | null;
111
+ toArray(): Record<string, unknown>;
112
+ }
113
+
114
+ declare class ProviderDocument {
115
+ readonly id: number | null;
116
+ readonly provider: string | null;
117
+ readonly documentType: string | null;
118
+ readonly state: string | null;
119
+ readonly documentDate: Date | null;
120
+ readonly mime: string | null;
121
+ readonly size: number | null;
122
+ readonly hash: string | null;
123
+ readonly meta: Record<string, unknown>;
124
+ readonly line: ProviderDocumentLine | null;
125
+ constructor(id: number | null, provider: string | null, documentType: string | null, state: string | null, documentDate: Date | null, mime: string | null, size: number | null, hash: string | null, meta: Record<string, unknown>, line: ProviderDocumentLine | null);
126
+ static fromArray(data: unknown): ProviderDocument | null;
127
+ toArray(): Record<string, unknown>;
128
+ }
129
+
130
+ declare class VatResource {
131
+ readonly uuid: string | undefined;
132
+ readonly vatUid: string | undefined;
133
+ readonly state: VatState | undefined;
134
+ readonly countryCode: string | undefined;
135
+ readonly companyName: string | undefined;
136
+ readonly companyAddress: CompanyAddress | undefined;
137
+ readonly requestedCompanyName: string | undefined;
138
+ readonly requestedCompanyNameOriginal: string | undefined;
139
+ readonly requestedInputAddress: Record<string, string | null> | undefined;
140
+ readonly checkedAt: Date | undefined;
141
+ readonly score: number | undefined;
142
+ readonly scoreSource: string | undefined;
143
+ readonly scoreAttempts: Array<{
144
+ source?: string;
145
+ score?: number;
146
+ }> | undefined;
147
+ readonly breakdown: ScoreBreakdown[] | undefined;
148
+ readonly environment: string | undefined;
149
+ readonly provider: string | undefined;
150
+ readonly usedProviders: string[] | undefined;
151
+ readonly providerVatState: string | undefined;
152
+ readonly providerNote: string | undefined;
153
+ readonly providerLastCheckedAt: Date | undefined;
154
+ readonly providerDocument: ProviderDocument | undefined;
155
+ constructor(uuid: string | undefined, vatUid: string | undefined, state: VatState | undefined, countryCode: string | undefined, companyName: string | undefined, companyAddress: CompanyAddress | undefined, requestedCompanyName: string | undefined, requestedCompanyNameOriginal: string | undefined, requestedInputAddress: Record<string, string | null> | undefined, checkedAt: Date | undefined, score: number | undefined, scoreSource: string | undefined, scoreAttempts: Array<{
156
+ source?: string;
157
+ score?: number;
158
+ }> | undefined, breakdown: ScoreBreakdown[] | undefined, environment: string | undefined, provider: string | undefined, usedProviders: string[] | undefined, providerVatState: string | undefined, providerNote: string | undefined, providerLastCheckedAt: Date | undefined, providerDocument: ProviderDocument | undefined);
159
+ static fromArray(data: Record<string, unknown>): VatResource;
160
+ getBackendLink(): string | null;
161
+ toArray(): Record<string, unknown>;
162
+ }
163
+
164
+ declare class VatCollection implements Iterable<VatResource> {
165
+ private readonly items;
166
+ readonly self: string | undefined;
167
+ constructor(items: VatResource[], self?: string);
168
+ static fromResponse(data: unknown): VatCollection;
169
+ [Symbol.iterator](): Iterator<VatResource>;
170
+ get length(): number;
171
+ all(): VatResource[];
172
+ }
173
+
174
+ declare class VatCertificateExport {
175
+ readonly exportId: string;
176
+ readonly message?: string | undefined;
177
+ constructor(exportId: string, message?: string | undefined);
178
+ static fromArray(data: Record<string, unknown>): VatCertificateExport;
179
+ toArray(): {
180
+ export_id: string;
181
+ message?: string;
182
+ };
183
+ }
184
+
185
+ interface VatValidationAddressInputProps {
186
+ addressLine1?: string;
187
+ addressLine2?: string;
188
+ postalCode?: string;
189
+ city?: string;
190
+ countryCode?: string;
191
+ }
192
+ declare class VatValidationAddressInput {
193
+ readonly addressLine1?: string;
194
+ readonly addressLine2?: string;
195
+ readonly postalCode?: string;
196
+ readonly city?: string;
197
+ readonly countryCode?: string;
198
+ constructor(props: VatValidationAddressInputProps);
199
+ static fromArray(data: Record<string, unknown>): VatValidationAddressInput;
200
+ toArray(): Record<string, string>;
201
+ }
202
+
203
+ declare const Language: {
204
+ readonly ENGLISH: "en";
205
+ readonly GERMAN: "de";
206
+ };
207
+ type Language = (typeof Language)[keyof typeof Language];
208
+
209
+ declare class VatEndpoint {
210
+ private readonly baseUrl;
211
+ private readonly apiKey;
212
+ private readonly tokenStorage;
213
+ private readonly httpClient;
214
+ constructor(baseUrl: string, apiKey: string, tokenStorage: TokenStorageInterface, httpClient: HttpClientInterface);
215
+ validate(vatUid: string, companyName?: string, provider?: string, addressInput?: VatValidationAddressInput | Record<string, string>): Promise<VatResource>;
216
+ private validateWithGatewayRetry;
217
+ validateMultiple(vatUids: string[], companyNames?: string[], provider?: string): Promise<VatCollection>;
218
+ validateSchema(vatUid: string): Promise<Record<string, unknown>>;
219
+ state(vatUid: string): Promise<VatResource>;
220
+ history(vatUid?: string): Promise<VatCollection>;
221
+ search(term?: string, perPage?: number): Promise<VatCollection>;
222
+ certificate(uuid: string, lang?: Language): Promise<Uint8Array>;
223
+ certificatesBulkExport(fromDate: Date | string, toDate: Date | string, countries?: string[], lang?: Language): Promise<VatCertificateExport>;
224
+ certificatesListExport(fromDate: Date | string, toDate: Date | string, countries?: string[], lang?: Language): Promise<VatCertificateExport>;
225
+ private exportRequest;
226
+ downloadBulkExport(exportId: string): Promise<Uint8Array>;
227
+ private buildHeaders;
228
+ private sendRequest;
229
+ private sendBinaryRequest;
230
+ private parseJsonResponse;
231
+ private formatDate;
232
+ }
233
+
234
+ declare const Environment: {
235
+ readonly SANDBOX: "sandbox";
236
+ readonly PRODUCTION: "production";
237
+ };
238
+ type Environment = (typeof Environment)[keyof typeof Environment];
239
+ declare function getBaseUrl(environment: Environment): string;
240
+
241
+ interface TaxoraClientOptions {
242
+ apiKey: string;
243
+ environment?: Environment;
244
+ tokenStorage?: TokenStorageInterface;
245
+ httpClient?: HttpClientInterface;
246
+ }
247
+ declare class TaxoraClient {
248
+ readonly auth: AuthEndpoint;
249
+ readonly vat: VatEndpoint;
250
+ readonly company: CompanyEndpoint;
251
+ readonly baseUrl: string;
252
+ constructor(options: TaxoraClientOptions);
253
+ }
254
+
255
+ declare class TaxoraClientFactory {
256
+ static create(options: TaxoraClientOptions): TaxoraClient;
257
+ }
258
+
259
+ declare const ApiVersion: {
260
+ readonly V1: "v1";
261
+ };
262
+ type ApiVersion = (typeof ApiVersion)[keyof typeof ApiVersion];
263
+
264
+ declare class TaxoraException extends Error {
265
+ readonly context: Record<string, unknown>;
266
+ constructor(message: string, context?: Record<string, unknown>);
267
+ }
268
+
269
+ declare class AuthenticationException extends TaxoraException {
270
+ readonly statusCode = 401;
271
+ constructor(message: string, context?: Record<string, unknown>);
272
+ }
273
+
274
+ declare class HttpException extends TaxoraException {
275
+ readonly statusCode: number;
276
+ readonly responseBody: string;
277
+ constructor(message: string, statusCode: number, responseBody: string, context?: Record<string, unknown>);
278
+ getStatusCode(): number;
279
+ getResponseBody(): string;
280
+ }
281
+
282
+ declare class ValidationException extends TaxoraException {
283
+ readonly statusCode = 422;
284
+ private readonly errors;
285
+ constructor(message: string, errors: Record<string, string[]>, context?: Record<string, unknown>);
286
+ getErrors(): Record<string, string[]>;
287
+ }
288
+
289
+ declare class InMemoryTokenStorage implements TokenStorageInterface {
290
+ private token;
291
+ get(): Token | null;
292
+ set(token: Token): void;
293
+ clear(): void;
294
+ }
295
+
296
+ declare class FetchHttpClient implements HttpClientInterface {
297
+ request(method: string, url: string, options?: RequestInit): Promise<Response>;
298
+ }
299
+
300
+ /**
301
+ * HTTP client wrapper that handles:
302
+ * - Preemptive token refresh when the stored token is expired
303
+ * - Automatic retry with a fresh token on 401 responses
304
+ * - Passthrough for /auth/ routes (no interception)
305
+ */
306
+ declare class AuthRetryHttpClient implements HttpClientInterface {
307
+ private readonly inner;
308
+ private readonly tokenStorage;
309
+ private readonly refreshFn;
310
+ constructor(inner: HttpClientInterface, tokenStorage: TokenStorageInterface, refreshFn: () => Promise<Token>);
311
+ request(method: string, url: string, options?: RequestInit): Promise<Response>;
312
+ private injectAuthHeader;
313
+ }
314
+
315
+ export { ApiVersion, AuthEndpoint, AuthRetryHttpClient, AuthenticationException, CompanyAddress, CompanyEndpoint, Environment, Environment as EnvironmentType, FetchHttpClient, type HttpClientInterface, HttpException, InMemoryTokenStorage, Language, LoginIdentifier, ProviderDocument, ProviderDocumentLine, ScoreBreakdown, TaxoraClient, TaxoraClientFactory, type TaxoraClientOptions, TaxoraException, Token, type TokenStorageInterface, ValidationException, VatCertificateExport, VatCollection, VatEndpoint, VatResource, VatState, VatValidationAddressInput, describeVatState, getBaseUrl, getFailedVatStates };