evatr-api 0.1.1
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/LICENSE.md +21 -0
- package/README.md +434 -0
- package/dist/api-updater.d.ts +67 -0
- package/dist/api-updater.d.ts.map +1 -0
- package/dist/api-updater.js +283 -0
- package/dist/api-updater.js.map +1 -0
- package/dist/client.d.ts +111 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +278 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +39 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +268 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/migration-helper.d.ts +92 -0
- package/dist/migration-helper.d.ts.map +1 -0
- package/dist/migration-helper.js +222 -0
- package/dist/migration-helper.js.map +1 -0
- package/dist/status-loader.d.ts +71 -0
- package/dist/status-loader.d.ts.map +1 -0
- package/dist/status-loader.js +191 -0
- package/dist/status-loader.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +135 -0
- package/dist/utils.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration helper for backward compatibility with the evatr library
|
|
3
|
+
* The XML-RPC eVatR is planned to be sunset on 2025-11-30
|
|
4
|
+
*
|
|
5
|
+
* Provides a similar API as https://github.com/qqilihq/evatr
|
|
6
|
+
*
|
|
7
|
+
* Some of the breaking changes:
|
|
8
|
+
* - request
|
|
9
|
+
* - `includeRawXml` is here `includeRaw` (as server response is JSON)
|
|
10
|
+
* - response
|
|
11
|
+
* - `rawXml` is here `raw` (as server response is JSON)
|
|
12
|
+
* - error codes do not match new status messages
|
|
13
|
+
* - errorDescription contains the message from the REST-API server not the message text based on errorCode of XML-RPC
|
|
14
|
+
* - status is additionally returned
|
|
15
|
+
*/
|
|
16
|
+
interface ISimpleParams {
|
|
17
|
+
includeRaw?: boolean;
|
|
18
|
+
ownVatNumber: string;
|
|
19
|
+
validateVatNumber: string;
|
|
20
|
+
}
|
|
21
|
+
interface IQualifiedParams extends ISimpleParams {
|
|
22
|
+
companyName: string;
|
|
23
|
+
city: string;
|
|
24
|
+
zip?: string;
|
|
25
|
+
street?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ISimpleResult {
|
|
28
|
+
raw?: string;
|
|
29
|
+
date: string;
|
|
30
|
+
time: string;
|
|
31
|
+
errorCode: number;
|
|
32
|
+
errorDescription?: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
ownVatNumber: string;
|
|
35
|
+
validatedVatNumber: string;
|
|
36
|
+
validFrom?: string;
|
|
37
|
+
validUntil?: string;
|
|
38
|
+
/** `true` if the given data was valid (i.e. error code is `200`). */
|
|
39
|
+
valid: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface IQualifiedResult extends ISimpleResult {
|
|
42
|
+
companyName?: string;
|
|
43
|
+
city?: string;
|
|
44
|
+
zip?: string;
|
|
45
|
+
street?: string;
|
|
46
|
+
resultName?: ResultType;
|
|
47
|
+
resultCity?: ResultType;
|
|
48
|
+
resultZip?: ResultType;
|
|
49
|
+
resultStreet?: ResultType;
|
|
50
|
+
/** Human-readable, German description for the name result. */
|
|
51
|
+
resultNameDescription?: string;
|
|
52
|
+
/** Human-readable, German description for the city result. */
|
|
53
|
+
resultCityDescription?: string;
|
|
54
|
+
/** Human-readable, German description for the zip result. */
|
|
55
|
+
resultZipDescription?: string;
|
|
56
|
+
/** Human-readable, German description for the street result. */
|
|
57
|
+
resultStreetDescription?: string;
|
|
58
|
+
}
|
|
59
|
+
export declare enum ResultType {
|
|
60
|
+
MATCH = "A",
|
|
61
|
+
NO_MATCH = "B",
|
|
62
|
+
NOT_QUERIED = "C",
|
|
63
|
+
NOT_RETURNED = "D"
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Migration helper class that provides the same API as the evatr library
|
|
67
|
+
*/
|
|
68
|
+
export declare class EvatrMigrationHelper {
|
|
69
|
+
private static client;
|
|
70
|
+
/**
|
|
71
|
+
* Perform a simple VAT-ID validation
|
|
72
|
+
* @param params Simple validation parameters
|
|
73
|
+
* @returns Promise<ISimpleResult>
|
|
74
|
+
*/
|
|
75
|
+
static checkSimple(params: ISimpleParams): Promise<ISimpleResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Perform a qualified VAT-ID validation
|
|
78
|
+
* @param params Qualified validation parameters
|
|
79
|
+
* @returns Promise<IQualifiedResult>
|
|
80
|
+
*/
|
|
81
|
+
static checkQualified(params: IQualifiedParams): Promise<IQualifiedResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Map status codes to HTTP-like error codes for backward compatibility
|
|
84
|
+
*/
|
|
85
|
+
private static mapStatusToErrorCode;
|
|
86
|
+
/**
|
|
87
|
+
* Get human-readable description for result types
|
|
88
|
+
*/
|
|
89
|
+
private static getResultDescription;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=migration-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-helper.d.ts","sourceRoot":"","sources":["../src/migration-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgDH,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAA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M,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwEhF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAInC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAcpC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Migration helper for backward compatibility with the evatr library
|
|
4
|
+
* The XML-RPC eVatR is planned to be sunset on 2025-11-30
|
|
5
|
+
*
|
|
6
|
+
* Provides a similar API as https://github.com/qqilihq/evatr
|
|
7
|
+
*
|
|
8
|
+
* Some of the breaking changes:
|
|
9
|
+
* - request
|
|
10
|
+
* - `includeRawXml` is here `includeRaw` (as server response is JSON)
|
|
11
|
+
* - response
|
|
12
|
+
* - `rawXml` is here `raw` (as server response is JSON)
|
|
13
|
+
* - error codes do not match new status messages
|
|
14
|
+
* - errorDescription contains the message from the REST-API server not the message text based on errorCode of XML-RPC
|
|
15
|
+
* - status is additionally returned
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.EvatrMigrationHelper = exports.ResultType = void 0;
|
|
19
|
+
const client_1 = require("./client");
|
|
20
|
+
const status_loader_1 = require("./status-loader");
|
|
21
|
+
/**
|
|
22
|
+
* Mapping from new eVatR status codes to legacy error codes for backward compatibility
|
|
23
|
+
* Based on the XML-RPC error codes
|
|
24
|
+
*
|
|
25
|
+
* Some error codes are vague or not possible to map:
|
|
26
|
+
* - 201 // Die angefragte USt-IdNr. ist ungültig.
|
|
27
|
+
* - 205 // Ihre Anfrage kann derzeit durch den angefragten EU-Mitgliedstaat oder aus anderen Gründen nicht beantwortet werden. Bitte versuchen Sie es später noch einmal. Bei wiederholten Problemen wenden Sie sich bitte an das Bundeszentralamt für Steuern - Dienstsitz Saarlouis.
|
|
28
|
+
* - 208 // evatr-0008? Für die von Ihnen angefragte USt-IdNr. läuft gerade eine Anfrage von einem anderen Nutzer. Eine Bearbeitung ist daher nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
29
|
+
* - 210 // evatr-0012? Die angefragte USt-IdNr. ist ungültig. Sie entspricht nicht den Prüfziffernregeln die für diesen EU-Mitgliedstaat gelten.
|
|
30
|
+
* - 211 // Die angefragte USt-IdNr. ist ungültig. Sie enthält unzulässige Zeichen (wie z.B. Leerzeichen oder Punkt oder Bindestrich usw.).
|
|
31
|
+
* - 219 // Bei der Durchführung der qualifizierten Bestätigungsanfrage ist ein Fehler aufgetreten. Es wurde eine einfache Bestätigungsanfrage mit folgendem Ergebnis durchgeführt: Die angefragte USt-IdNr. ist gültig.
|
|
32
|
+
* - 223 // Die angefragte USt-IdNr. ist gültig. Die Druckfunktion steht nicht mehr zur Verfügung, da der Nachweis gem. UStAE zu § 18e.1 zu führen ist.
|
|
33
|
+
*/
|
|
34
|
+
const STATUS_TO_ERROR_CODE_MAP = {
|
|
35
|
+
'evatr-0000': 200, // Die angefragte USt-IdNr. ist gültig.
|
|
36
|
+
'evatr-0001': 221, // Die Anfragedaten enthalten nicht alle notwendigen Parameter oder einen ungültigen Datentyp. Weitere Informationen erhalten Sie bei den Hinweisen zum Schnittstellen - Aufruf (s.o.)
|
|
37
|
+
'evatr-0002': 215, // Ihre Anfrage enthält nicht alle notwendigen Angaben für eine einfache Bestätigungsanfrage (Ihre deutsche USt-IdNr. und die ausl. USt-IdNr.). Ihre Anfrage kann deshalb nicht bearbeitet werden.
|
|
38
|
+
'evatr-0003': 216, // Ihre Anfrage enthält nicht alle notwendigen Angaben für eine qualifizierte Bestätigungsanfrage (Ihre deutsche USt-IdNr., die ausl. USt-IdNr., Firmenname einschl. Rechtsform und Ort). Es wurde eine einfache Bestätigungsanfrage durchgeführt mit folgenden Ergebnis: Die angefragte USt-IdNr. ist gültig.
|
|
39
|
+
'evatr-0004': 214, // Ihre deutsche USt-IdNr. ist fehlerhaft. Sie beginnt mit 'DE' gefolgt von 9 Ziffern.
|
|
40
|
+
'evatr-0005': 209, // Die angefragte USt-IdNr. ist ungültig. Sie entspricht nicht dem Aufbau der für diesen EU-Mitgliedstaat gilt.
|
|
41
|
+
'evatr-0006': 213, // Sie sind nicht zur Abfrage einer deutschen USt-IdNr. berechtigt.
|
|
42
|
+
'evatr-0007': 221, // Die Anfragedaten enthalten nicht alle notwendigen Parameter oder einen ungültigen Datentyp. Weitere Informationen erhalten Sie bei den Hinweisen zum Schnittstellen - Aufruf (s.o.)
|
|
43
|
+
'evatr-0008': 999, // 208? // Für die von Ihnen angefragte USt-IdNr. läuft gerade eine Anfrage von einem anderen Nutzer. Eine Bearbeitung ist daher nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
44
|
+
'evatr-0011': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
45
|
+
'evatr-0012': 209, // 210? // Die angefragte USt-IdNr. ist ungültig. Sie entspricht nicht dem Aufbau der für diesen EU-Mitgliedstaat gilt.
|
|
46
|
+
'evatr-0013': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
47
|
+
'evatr-1001': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
48
|
+
'evatr-1002': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
49
|
+
'evatr-1003': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
50
|
+
'evatr-1004': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
51
|
+
'evatr-2001': 202, // Die angefragte USt-IdNr. ist ungültig. Sie ist nicht in der Unternehmerdatei des betreffenden EU-Mitgliedstaates registriert. Hinweis: Ihr Geschäftspartner kann seine gültige USt-IdNr. bei der für ihn zuständigen Finanzbehörde in Erfahrung bringen. Möglicherweise muss er einen Antrag stellen, damit seine USt-IdNr. in die Datenbank aufgenommen wird.
|
|
52
|
+
'evatr-2002': 203, // Die angefragte USt-IdNr. ist ungültig. Sie ist erst ab dem ... gültig (siehe Feld 'Gueltig_ab').
|
|
53
|
+
'evatr-2003': 212, // Die angefragte USt-IdNr. ist ungültig. Sie enthält ein unzulässiges Länderkennzeichen.
|
|
54
|
+
'evatr-2004': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
55
|
+
'evatr-2005': 206, // Ihre deutsche USt-IdNr. ist ungültig. Eine Bestätigungsanfrage ist daher nicht möglich. Den Grund hierfür können Sie beim Bundeszentralamt für Steuern - Dienstsitz Saarlouis - erfragen.
|
|
56
|
+
'evatr-2006': 204, // Die angefragte USt-IdNr. ist ungültig. Sie war im Zeitraum von ... bis ... gültig (siehe Feld 'Gueltig_ab' und 'Gueltig_bis').
|
|
57
|
+
'evatr-2007': 217, // Bei der Verarbeitung der Daten aus dem angefragten EU-Mitgliedstaat ist ein Fehler aufgetreten. Ihre Anfrage kann deshalb nicht bearbeitet werden.
|
|
58
|
+
'evatr-2008': 218, // Eine qualifizierte Bestätigung ist zur Zeit nicht möglich. Es wurde eine einfache Bestätigungsanfrage mit folgendem Ergebnis durchgeführt: Die angefragte USt-IdNr. ist gültig.
|
|
59
|
+
'evatr-2011': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
60
|
+
'evatr-3011': 999, // Eine Bearbeitung Ihrer Anfrage ist zurzeit nicht möglich. Bitte versuchen Sie es später noch einmal.
|
|
61
|
+
};
|
|
62
|
+
var ResultType;
|
|
63
|
+
(function (ResultType) {
|
|
64
|
+
ResultType["MATCH"] = "A";
|
|
65
|
+
ResultType["NO_MATCH"] = "B";
|
|
66
|
+
ResultType["NOT_QUERIED"] = "C";
|
|
67
|
+
ResultType["NOT_RETURNED"] = "D";
|
|
68
|
+
})(ResultType || (exports.ResultType = ResultType = {}));
|
|
69
|
+
/**
|
|
70
|
+
* Migration helper class that provides the same API as the evatr library
|
|
71
|
+
*/
|
|
72
|
+
class EvatrMigrationHelper {
|
|
73
|
+
/**
|
|
74
|
+
* Perform a simple VAT-ID validation
|
|
75
|
+
* @param params Simple validation parameters
|
|
76
|
+
* @returns Promise<ISimpleResult>
|
|
77
|
+
*/
|
|
78
|
+
static async checkSimple(params) {
|
|
79
|
+
try {
|
|
80
|
+
const response = await this.client.validateSimple({
|
|
81
|
+
vatIdOwn: params.ownVatNumber,
|
|
82
|
+
vatIdForeign: params.validateVatNumber,
|
|
83
|
+
});
|
|
84
|
+
const statusMessage = status_loader_1.StatusMessages.getStatusMessage(response.status);
|
|
85
|
+
// Parse timestamp to extract date and time
|
|
86
|
+
const timestamp = new Date(response.timestamp);
|
|
87
|
+
const date = timestamp.toLocaleDateString('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit' }); // DD.MM.YYY
|
|
88
|
+
const time = timestamp.toTimeString().split(' ')[0]; // HH:MM:SS
|
|
89
|
+
// Map status to legacy error code
|
|
90
|
+
const errorCode = this.mapStatusToErrorCode(response.status);
|
|
91
|
+
const result = {
|
|
92
|
+
date,
|
|
93
|
+
time,
|
|
94
|
+
errorCode,
|
|
95
|
+
errorDescription: statusMessage?.message,
|
|
96
|
+
status: statusMessage?.status,
|
|
97
|
+
ownVatNumber: response.vatIdOwn,
|
|
98
|
+
validatedVatNumber: response.vatIdForeign,
|
|
99
|
+
validFrom: response.validFrom,
|
|
100
|
+
validUntil: response.validTill,
|
|
101
|
+
valid: this.client.isSuccessStatus(response.status),
|
|
102
|
+
};
|
|
103
|
+
if (params.includeRaw) {
|
|
104
|
+
// Note: The new API doesn't provide raw XML, so we'll include the JSON response
|
|
105
|
+
result.raw = JSON.stringify(response, null, 2);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// Map API errors to the expected format
|
|
112
|
+
const errorCode = error.http || 500;
|
|
113
|
+
const timestamp = new Date();
|
|
114
|
+
return {
|
|
115
|
+
date: timestamp.toLocaleDateString('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit' }), // DD.MM.YYY
|
|
116
|
+
time: timestamp.toTimeString().split(' ')[0],
|
|
117
|
+
errorCode,
|
|
118
|
+
errorDescription: error.message,
|
|
119
|
+
ownVatNumber: params.ownVatNumber,
|
|
120
|
+
validatedVatNumber: params.validateVatNumber,
|
|
121
|
+
valid: false,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Perform a qualified VAT-ID validation
|
|
127
|
+
* @param params Qualified validation parameters
|
|
128
|
+
* @returns Promise<IQualifiedResult>
|
|
129
|
+
*/
|
|
130
|
+
static async checkQualified(params) {
|
|
131
|
+
try {
|
|
132
|
+
const response = await this.client.validateQualified({
|
|
133
|
+
vatIdOwn: params.ownVatNumber,
|
|
134
|
+
vatIdForeign: params.validateVatNumber,
|
|
135
|
+
company: params.companyName,
|
|
136
|
+
location: params.city,
|
|
137
|
+
street: params.street,
|
|
138
|
+
zip: params.zip,
|
|
139
|
+
});
|
|
140
|
+
const statusMessage = status_loader_1.StatusMessages.getStatusMessage(response.status);
|
|
141
|
+
const errorCode = this.mapStatusToErrorCode(response.status);
|
|
142
|
+
// Parse timestamp to extract date and time
|
|
143
|
+
const timestamp = new Date(response.timestamp);
|
|
144
|
+
const date = timestamp.toLocaleDateString('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit' }); // DD.MM.YYY
|
|
145
|
+
const time = timestamp.toTimeString().split(' ')[0]; // HH:MM:SS
|
|
146
|
+
const result = {
|
|
147
|
+
date,
|
|
148
|
+
time,
|
|
149
|
+
errorCode,
|
|
150
|
+
errorDescription: statusMessage?.message,
|
|
151
|
+
status: statusMessage?.status,
|
|
152
|
+
ownVatNumber: response.vatIdOwn,
|
|
153
|
+
validatedVatNumber: response.vatIdForeign,
|
|
154
|
+
validFrom: response.validFrom,
|
|
155
|
+
validUntil: response.validTill,
|
|
156
|
+
valid: this.client.isSuccessStatus(response.status),
|
|
157
|
+
companyName: params.companyName,
|
|
158
|
+
city: params.city,
|
|
159
|
+
zip: params.zip,
|
|
160
|
+
street: params.street,
|
|
161
|
+
resultName: response.company,
|
|
162
|
+
resultCity: response.location,
|
|
163
|
+
resultZip: response.zip,
|
|
164
|
+
resultStreet: response.street,
|
|
165
|
+
resultNameDescription: this.getResultDescription(response.company),
|
|
166
|
+
resultCityDescription: this.getResultDescription(response.location),
|
|
167
|
+
resultZipDescription: this.getResultDescription(response.zip),
|
|
168
|
+
resultStreetDescription: this.getResultDescription(response.street),
|
|
169
|
+
};
|
|
170
|
+
if (params.includeRaw) {
|
|
171
|
+
// Note: The new API doesn't provide raw XML, so we'll include the JSON response
|
|
172
|
+
result.raw = JSON.stringify(response, null, 2);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
// Map API errors to the expected format
|
|
179
|
+
const errorCode = error.http || 500;
|
|
180
|
+
const timestamp = new Date();
|
|
181
|
+
return {
|
|
182
|
+
date: timestamp.toLocaleDateString('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit' }), // DD.MM.YYY
|
|
183
|
+
time: timestamp.toTimeString().split(' ')[0],
|
|
184
|
+
errorCode,
|
|
185
|
+
errorDescription: error.message,
|
|
186
|
+
ownVatNumber: params.ownVatNumber,
|
|
187
|
+
validatedVatNumber: params.validateVatNumber,
|
|
188
|
+
valid: false,
|
|
189
|
+
companyName: params.companyName,
|
|
190
|
+
city: params.city,
|
|
191
|
+
zip: params.zip,
|
|
192
|
+
street: params.street,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Map status codes to HTTP-like error codes for backward compatibility
|
|
198
|
+
*/
|
|
199
|
+
static mapStatusToErrorCode(status) {
|
|
200
|
+
return STATUS_TO_ERROR_CODE_MAP[status] || 999;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get human-readable description for result types
|
|
204
|
+
*/
|
|
205
|
+
static getResultDescription(resultType) {
|
|
206
|
+
switch (resultType) {
|
|
207
|
+
case ResultType.MATCH:
|
|
208
|
+
return 'stimmt überein';
|
|
209
|
+
case ResultType.NO_MATCH:
|
|
210
|
+
return 'stimmt nicht überein';
|
|
211
|
+
case ResultType.NOT_QUERIED:
|
|
212
|
+
return 'nicht angefragt';
|
|
213
|
+
case ResultType.NOT_RETURNED:
|
|
214
|
+
return 'vom EU-Mitgliedsstaat nicht mitgeteilt';
|
|
215
|
+
default:
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.EvatrMigrationHelper = EvatrMigrationHelper;
|
|
221
|
+
EvatrMigrationHelper.client = new client_1.EvatrClient();
|
|
222
|
+
//# sourceMappingURL=migration-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-helper.js","sourceRoot":"","sources":["../src/migration-helper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,qCAAuC;AACvC,mDAAiD;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,wBAAwB,GAA2B;IACvD,YAAY,EAAE,GAAG,EAAE,uCAAuC;IAC1D,YAAY,EAAE,GAAG,EAAE,sLAAsL;IACzM,YAAY,EAAE,GAAG,EAAE,kMAAkM;IACrN,YAAY,EAAE,GAAG,EAAE,8SAA8S;IACjU,YAAY,EAAE,GAAG,EAAE,sFAAsF;IACzG,YAAY,EAAE,GAAG,EAAE,+GAA+G;IAClI,YAAY,EAAE,GAAG,EAAE,mEAAmE;IACtF,YAAY,EAAE,GAA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BAAsB,CAAC;YAChC,KAAK,UAAU,CAAC,WAAW;gBACzB,OAAO,iBAAiB,CAAC;YAC3B,KAAK,UAAU,CAAC,YAAY;gBAC1B,OAAO,wCAAwC,CAAC;YAClD;gBACE,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;;AAjKH,oDAkKC;AAjKgB,2BAAM,GAAG,IAAI,oBAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic status message loader for eVatR API
|
|
3
|
+
*/
|
|
4
|
+
import { ApiStatusMessage, StatusMessage, StatusMessageCategory } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Status message loader that can load from files or fallback to constants
|
|
7
|
+
*/
|
|
8
|
+
export declare class StatusMessages {
|
|
9
|
+
private static cache;
|
|
10
|
+
private static cachedMessages;
|
|
11
|
+
private static lastLoadTime;
|
|
12
|
+
private static readonly CACHE_TTL;
|
|
13
|
+
/**
|
|
14
|
+
* Load status messages with caching
|
|
15
|
+
*/
|
|
16
|
+
static getStatusMessages(): Record<string, StatusMessage>;
|
|
17
|
+
/**
|
|
18
|
+
* Load status messages with caching
|
|
19
|
+
*/
|
|
20
|
+
static getAndCacheStatusMessages(): Record<string, StatusMessage>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a specific status message
|
|
23
|
+
*/
|
|
24
|
+
static getStatusMessage(statusCode: string): StatusMessage | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Clear the cache to force reload
|
|
27
|
+
*/
|
|
28
|
+
static clearCache(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Load status messages from file
|
|
31
|
+
*/
|
|
32
|
+
static loadFromFile(): Record<string, StatusMessage> | null;
|
|
33
|
+
/**
|
|
34
|
+
* Load status messages from a specific file path
|
|
35
|
+
*/
|
|
36
|
+
static loadFromPath(filePath: string): Record<string, ApiStatusMessage> | null;
|
|
37
|
+
/**
|
|
38
|
+
* Get all available status codes
|
|
39
|
+
*/
|
|
40
|
+
static getAvailableStatusCodes(): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Get status messages by category
|
|
43
|
+
*/
|
|
44
|
+
static getStatusMessagesByCategory(category: StatusMessageCategory): StatusMessage[];
|
|
45
|
+
/**
|
|
46
|
+
* Get status messages by HTTP code
|
|
47
|
+
*/
|
|
48
|
+
static getStatusMessagesByHttp(http: number): StatusMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* Check if status code indicates success
|
|
51
|
+
*/
|
|
52
|
+
static isSuccessStatus(statusCode: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if status code indicates an error
|
|
55
|
+
*/
|
|
56
|
+
static isErrorStatus(statusCode: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Check if status code indicates a warning/hint
|
|
59
|
+
*/
|
|
60
|
+
static isWarningStatus(statusCode: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get statistics about loaded status messages
|
|
63
|
+
*/
|
|
64
|
+
static getStatistics(): {
|
|
65
|
+
total: number;
|
|
66
|
+
byCategory: Record<string, number>;
|
|
67
|
+
byHttp: Record<number, number>;
|
|
68
|
+
source: 'file' | 'constants';
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=status-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-loader.d.ts","sourceRoot":"","sources":["../src/status-loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGjF;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAC,cAAc,CAA8C;IAC3E,OAAO,CAAC,MAAM,CAAC,YAAY,CAAa;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAElD;;OAEG;IACH,MAAM,CAAC,iBA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
|
+
* Dynamic status message loader for eVatR API
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StatusMessages = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
/**
|
|
11
|
+
* Status message loader that can load from files or fallback to constants
|
|
12
|
+
*/
|
|
13
|
+
class StatusMessages {
|
|
14
|
+
/**
|
|
15
|
+
* Load status messages with caching
|
|
16
|
+
*/
|
|
17
|
+
static getStatusMessages() {
|
|
18
|
+
if (this.cache === false) {
|
|
19
|
+
return constants_1.STATUS_MESSAGES;
|
|
20
|
+
}
|
|
21
|
+
return this.getAndCacheStatusMessages();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load status messages with caching
|
|
25
|
+
*/
|
|
26
|
+
static getAndCacheStatusMessages() {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
// Return cached messages if still valid
|
|
29
|
+
if (this.cachedMessages && (now - this.lastLoadTime) < this.CACHE_TTL) {
|
|
30
|
+
return this.cachedMessages;
|
|
31
|
+
}
|
|
32
|
+
// Try to load from file first
|
|
33
|
+
const fileMessages = this.loadFromFile();
|
|
34
|
+
if (fileMessages) {
|
|
35
|
+
this.cachedMessages = fileMessages;
|
|
36
|
+
this.lastLoadTime = now;
|
|
37
|
+
return fileMessages;
|
|
38
|
+
}
|
|
39
|
+
// Fallback to constants
|
|
40
|
+
this.cachedMessages = constants_1.STATUS_MESSAGES;
|
|
41
|
+
this.lastLoadTime = now;
|
|
42
|
+
return constants_1.STATUS_MESSAGES;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get a specific status message
|
|
46
|
+
*/
|
|
47
|
+
static getStatusMessage(statusCode) {
|
|
48
|
+
const messages = this.getStatusMessages();
|
|
49
|
+
return messages[statusCode];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear the cache to force reload
|
|
53
|
+
*/
|
|
54
|
+
static clearCache() {
|
|
55
|
+
this.cachedMessages = null;
|
|
56
|
+
this.lastLoadTime = 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Load status messages from file
|
|
60
|
+
*/
|
|
61
|
+
static loadFromFile() {
|
|
62
|
+
const possiblePaths = [
|
|
63
|
+
// Try docs directory first
|
|
64
|
+
(0, path_1.join)(process.cwd(), 'docs', 'statusmeldungen.json'),
|
|
65
|
+
// Try relative to this file
|
|
66
|
+
(0, path_1.join)(__dirname, '..', '..', 'docs', 'statusmeldungen.json'),
|
|
67
|
+
// Try current directory
|
|
68
|
+
(0, path_1.join)(process.cwd(), 'statusmeldungen.json'),
|
|
69
|
+
];
|
|
70
|
+
for (const path of possiblePaths) {
|
|
71
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
72
|
+
try {
|
|
73
|
+
const fileContent = (0, fs_1.readFileSync)(path, 'utf8');
|
|
74
|
+
const messages = JSON.parse(fileContent);
|
|
75
|
+
// Convert array to object keyed by status code
|
|
76
|
+
const messagesObj = messages.reduce((acc, msg) => {
|
|
77
|
+
acc[msg.status] = msg;
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.log(`✅ Loaded ${messages.length} status messages from: ${path}`);
|
|
82
|
+
return messagesObj;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.warn(`⚠️ Could not load status messages from ${path}:`, error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Load status messages from a specific file path
|
|
94
|
+
*/
|
|
95
|
+
static loadFromPath(filePath) {
|
|
96
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.error(`Status messages file not found: ${filePath}`);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const fileContent = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
103
|
+
const messages = JSON.parse(fileContent);
|
|
104
|
+
const messagesObj = messages.reduce((acc, msg) => {
|
|
105
|
+
acc[msg.status] = msg;
|
|
106
|
+
return acc;
|
|
107
|
+
}, {});
|
|
108
|
+
// Update cache
|
|
109
|
+
// @TODO: map
|
|
110
|
+
// this.cachedMessages = messagesObj;
|
|
111
|
+
this.lastLoadTime = Date.now();
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.log(`✅ Loaded ${messages.length} status messages from: ${filePath}`);
|
|
114
|
+
return messagesObj;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
// eslint-disable-next-line no-console
|
|
118
|
+
console.error(`Error loading status messages from ${filePath}:`, error);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get all available status codes
|
|
124
|
+
*/
|
|
125
|
+
static getAvailableStatusCodes() {
|
|
126
|
+
const messages = this.getStatusMessages();
|
|
127
|
+
return Object.keys(messages).sort();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get status messages by category
|
|
131
|
+
*/
|
|
132
|
+
static getStatusMessagesByCategory(category) {
|
|
133
|
+
const messages = this.getStatusMessages();
|
|
134
|
+
return Object.values(messages).filter(msg => msg.category === category);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get status messages by HTTP code
|
|
138
|
+
*/
|
|
139
|
+
static getStatusMessagesByHttp(http) {
|
|
140
|
+
const messages = this.getStatusMessages();
|
|
141
|
+
return Object.values(messages).filter(msg => msg.http === http);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if status code indicates success
|
|
145
|
+
*/
|
|
146
|
+
static isSuccessStatus(statusCode) {
|
|
147
|
+
const message = this.getStatusMessage(statusCode);
|
|
148
|
+
return message?.category === 'Result' || message?.http === 200;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if status code indicates an error
|
|
152
|
+
*/
|
|
153
|
+
static isErrorStatus(statusCode) {
|
|
154
|
+
const message = this.getStatusMessage(statusCode);
|
|
155
|
+
return message?.category === 'Error';
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if status code indicates a warning/hint
|
|
159
|
+
*/
|
|
160
|
+
static isWarningStatus(statusCode) {
|
|
161
|
+
const message = this.getStatusMessage(statusCode);
|
|
162
|
+
return message?.category === 'Hint';
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get statistics about loaded status messages
|
|
166
|
+
*/
|
|
167
|
+
static getStatistics() {
|
|
168
|
+
const messages = this.getStatusMessages();
|
|
169
|
+
const messageArray = Object.values(messages);
|
|
170
|
+
const byCategory = messageArray.reduce((acc, msg) => {
|
|
171
|
+
acc[msg.category] = (acc[msg.category] || 0) + 1;
|
|
172
|
+
return acc;
|
|
173
|
+
}, {});
|
|
174
|
+
const byHttp = messageArray.reduce((acc, msg) => {
|
|
175
|
+
acc[msg.http || 0] = (acc[msg.http || 0] || 0) + 1;
|
|
176
|
+
return acc;
|
|
177
|
+
}, {});
|
|
178
|
+
return {
|
|
179
|
+
total: messageArray.length,
|
|
180
|
+
byCategory,
|
|
181
|
+
byHttp,
|
|
182
|
+
source: this.cachedMessages === constants_1.STATUS_MESSAGES ? 'constants' : 'file'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.StatusMessages = StatusMessages;
|
|
187
|
+
StatusMessages.cache = false; // currently disabled by default, without a way to enable it programatically
|
|
188
|
+
StatusMessages.cachedMessages = null;
|
|
189
|
+
StatusMessages.lastLoadTime = 0;
|
|
190
|
+
StatusMessages.CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
191
|
+
//# sourceMappingURL=status-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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