@voyant-travel/plugin-smartbill 0.119.2
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 +201 -0
- package/README.md +324 -0
- package/dist/artifacts.d.ts +80 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +295 -0
- package/dist/client/errors.d.ts +28 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +32 -0
- package/dist/client/fetch.d.ts +4 -0
- package/dist/client/fetch.d.ts.map +1 -0
- package/dist/client/fetch.js +32 -0
- package/dist/client/rate-limit.d.ts +8 -0
- package/dist/client/rate-limit.d.ts.map +1 -0
- package/dist/client/rate-limit.js +54 -0
- package/dist/client/resilience.d.ts +36 -0
- package/dist/client/resilience.d.ts.map +1 -0
- package/dist/client/resilience.js +23 -0
- package/dist/client.d.ts +67 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +234 -0
- package/dist/hono.d.ts +199 -0
- package/dist/hono.d.ts.map +1 -0
- package/dist/hono.js +77 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/invoice-ui-data.d.ts +46 -0
- package/dist/invoice-ui-data.d.ts.map +1 -0
- package/dist/invoice-ui-data.js +62 -0
- package/dist/invoice-ui.d.ts +438 -0
- package/dist/invoice-ui.d.ts.map +1 -0
- package/dist/invoice-ui.js +97 -0
- package/dist/mapping.d.ts +50 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +219 -0
- package/dist/mock/node.d.ts +4 -0
- package/dist/mock/node.d.ts.map +1 -0
- package/dist/mock/node.js +14 -0
- package/dist/mock/pdf.d.ts +7 -0
- package/dist/mock/pdf.d.ts.map +1 -0
- package/dist/mock/pdf.js +44 -0
- package/dist/mock/types.d.ts +94 -0
- package/dist/mock/types.d.ts.map +1 -0
- package/dist/mock/types.js +1 -0
- package/dist/mock.d.ts +4 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +431 -0
- package/dist/plugin.d.ts +55 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +192 -0
- package/dist/runtime.d.ts +25 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +42 -0
- package/dist/settlement.d.ts +33 -0
- package/dist/settlement.d.ts.map +1 -0
- package/dist/settlement.js +65 -0
- package/dist/sync/events.d.ts +5 -0
- package/dist/sync/events.d.ts.map +1 -0
- package/dist/sync/events.js +96 -0
- package/dist/sync/helpers.d.ts +66 -0
- package/dist/sync/helpers.d.ts.map +1 -0
- package/dist/sync/helpers.js +353 -0
- package/dist/sync/invoice.d.ts +3 -0
- package/dist/sync/invoice.d.ts.map +1 -0
- package/dist/sync/invoice.js +25 -0
- package/dist/sync/types.d.ts +71 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +1 -0
- package/dist/sync.d.ts +4 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +2 -0
- package/dist/types.d.ts +189 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +120 -0
- package/dist/workflow-candidates.d.ts +36 -0
- package/dist/workflow-candidates.d.ts.map +1 -0
- package/dist/workflow-candidates.js +182 -0
- package/dist/workflow-remote-discovery.d.ts +6 -0
- package/dist/workflow-remote-discovery.d.ts.map +1 -0
- package/dist/workflow-remote-discovery.js +83 -0
- package/dist/workflows/refs.d.ts +13 -0
- package/dist/workflows/refs.d.ts.map +1 -0
- package/dist/workflows/refs.js +51 -0
- package/dist/workflows/spaced-client.d.ts +5 -0
- package/dist/workflows/spaced-client.d.ts.map +1 -0
- package/dist/workflows/spaced-client.js +44 -0
- package/dist/workflows/types.d.ts +142 -0
- package/dist/workflows/types.d.ts.map +1 -0
- package/dist/workflows/types.js +1 -0
- package/dist/workflows.d.ts +5 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +229 -0
- package/package.json +129 -0
package/dist/mapping.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const DEFAULT_ART311_SPECIAL_REGIME_TEXT = "Regimul special de taxare - agentie de turism (Art. 311 Cod Fiscal)";
|
|
2
|
+
const COUNTRY_CODE_OVERRIDES = {
|
|
3
|
+
RO: "Romania",
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Extract the SmartBill client block from a Voyant invoice event.
|
|
7
|
+
* Falls back to SmartBill-parseable defaults for fields the API treats as required.
|
|
8
|
+
*/
|
|
9
|
+
export function mapClient(event) {
|
|
10
|
+
const vatCode = asStringOrUndefined(event.clientVatCode ?? event.customerVatCode);
|
|
11
|
+
return {
|
|
12
|
+
name: asString(event.clientName ?? event.customerName, "Client"),
|
|
13
|
+
vatCode,
|
|
14
|
+
regCom: asStringOrUndefined(event.clientRegCom),
|
|
15
|
+
address: asString(event.clientAddress ?? event.customerAddress, "-"),
|
|
16
|
+
city: asString(event.clientCity ?? event.customerCity, "-"),
|
|
17
|
+
county: asStringOrUndefined(event.clientCounty ?? event.customerCounty),
|
|
18
|
+
country: normalizeCountryName(asStringOrUndefined(event.clientCountry ?? event.customerCountry)) ??
|
|
19
|
+
"Romania",
|
|
20
|
+
isTaxPayer: Boolean(vatCode),
|
|
21
|
+
email: asStringOrUndefined(event.clientEmail ?? event.customerEmail),
|
|
22
|
+
phone: asStringOrUndefined(event.clientPhone ?? event.customerPhone),
|
|
23
|
+
saveToDb: false,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract SmartBill product lines from a Voyant invoice event.
|
|
28
|
+
* Expects `event.lineItems` to be an array of objects with at minimum
|
|
29
|
+
* `description`/`name`, `quantity`, `unitPrice`, `currency`.
|
|
30
|
+
*/
|
|
31
|
+
export function mapLineItems(event, options) {
|
|
32
|
+
const items = event.lineItems;
|
|
33
|
+
if (!Array.isArray(items))
|
|
34
|
+
return [];
|
|
35
|
+
return items.map((item) => ({
|
|
36
|
+
name: asString(item.description ?? item.name, "Item"),
|
|
37
|
+
code: asStringOrUndefined(item.code ?? item.sku),
|
|
38
|
+
measuringUnitName: asString(item.measuringUnitName ?? item.measureUnit ?? item.unit ?? options.measuringUnitName, "buc"),
|
|
39
|
+
quantity: asNumber(item.quantity, 1),
|
|
40
|
+
price: asNumber(item.unitPrice ?? item.price, 0),
|
|
41
|
+
currency: asString(item.currency ?? event.currency, "RON"),
|
|
42
|
+
isTaxIncluded: options.isTaxIncluded ?? true,
|
|
43
|
+
isDiscount: false,
|
|
44
|
+
taxName: asStringOrUndefined(item.taxName),
|
|
45
|
+
taxPercentage: item.taxPercentage != null ? asNumber(item.taxPercentage, 0) : undefined,
|
|
46
|
+
isService: item.isService === true,
|
|
47
|
+
saveToDb: false,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Map a full Voyant invoice event to a SmartBill invoice body.
|
|
52
|
+
*/
|
|
53
|
+
export function mapVoyantInvoiceToSmartbill(event, options) {
|
|
54
|
+
return buildSmartbillInvoiceBody(event, resolveMappingOptionsSync(event, options));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Async variant of the default mapper. Use this when mapping options include
|
|
58
|
+
* promise-returning callbacks such as `seriesName`, `mentions`, or
|
|
59
|
+
* `observations`.
|
|
60
|
+
*/
|
|
61
|
+
export async function mapVoyantInvoiceToSmartbillAsync(event, options) {
|
|
62
|
+
return buildSmartbillInvoiceBody(event, await resolveMappingOptions(event, options));
|
|
63
|
+
}
|
|
64
|
+
function buildSmartbillInvoiceBody(event, options) {
|
|
65
|
+
const body = {
|
|
66
|
+
companyVatCode: options.companyVatCode,
|
|
67
|
+
client: mapClient(event),
|
|
68
|
+
seriesName: options.seriesName,
|
|
69
|
+
currency: asString(event.currency, "RON"),
|
|
70
|
+
language: options.language ?? "RO",
|
|
71
|
+
products: mapLineItems(event, options),
|
|
72
|
+
};
|
|
73
|
+
if (event.isDraft === true)
|
|
74
|
+
body.isDraft = true;
|
|
75
|
+
if (event.externalAllocationRequired === true)
|
|
76
|
+
body.number = "";
|
|
77
|
+
if (typeof event.dueDate === "string")
|
|
78
|
+
body.dueDate = event.dueDate;
|
|
79
|
+
if (typeof event.issueDate === "string")
|
|
80
|
+
body.issueDate = event.issueDate;
|
|
81
|
+
if (typeof event.deliveryDate === "string")
|
|
82
|
+
body.deliveryDate = event.deliveryDate;
|
|
83
|
+
const exchangeRate = asNumberOrUndefined(event.effectiveRate ?? event.fxRate ?? event.exchangeRate);
|
|
84
|
+
if (exchangeRate)
|
|
85
|
+
body.exchangeRate = exchangeRate;
|
|
86
|
+
const mentions = options.hasMentionsOverride
|
|
87
|
+
? options.mentions
|
|
88
|
+
: asStringOrUndefined(event.mentions);
|
|
89
|
+
if (mentions)
|
|
90
|
+
body.mentions = mentions;
|
|
91
|
+
const observations = options.hasObservationsOverride
|
|
92
|
+
? options.observations
|
|
93
|
+
: asStringOrUndefined(event.observations);
|
|
94
|
+
if (observations)
|
|
95
|
+
body.observations = observations;
|
|
96
|
+
const fxCommissionMention = asStringOrUndefined(event.fxCommissionInvoiceMention);
|
|
97
|
+
if (fxCommissionMention && asNumber(event.fxCommissionBps, 0) > 0) {
|
|
98
|
+
body.mentions = [body.mentions, fxCommissionMention].filter(Boolean).join("\n");
|
|
99
|
+
}
|
|
100
|
+
if (options.art311SpecialRegime) {
|
|
101
|
+
body.mentions = [
|
|
102
|
+
body.mentions,
|
|
103
|
+
options.art311SpecialRegimeText ?? DEFAULT_ART311_SPECIAL_REGIME_TEXT,
|
|
104
|
+
]
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.join("\n");
|
|
107
|
+
}
|
|
108
|
+
return body;
|
|
109
|
+
}
|
|
110
|
+
// --- helpers ---
|
|
111
|
+
function resolveMappingOptionsSync(event, options) {
|
|
112
|
+
return {
|
|
113
|
+
companyVatCode: options.companyVatCode,
|
|
114
|
+
seriesName: resolveRequiredEventValueSync(event, options.seriesName, "seriesName"),
|
|
115
|
+
language: options.language,
|
|
116
|
+
isTaxIncluded: options.isTaxIncluded,
|
|
117
|
+
measuringUnitName: normalizeOptionalText(resolveEventValueSync(event, options.measuringUnitName, "measuringUnitName")),
|
|
118
|
+
art311SpecialRegime: options.art311SpecialRegime,
|
|
119
|
+
art311SpecialRegimeText: options.art311SpecialRegimeText,
|
|
120
|
+
mentions: normalizeOptionalText(resolveEventValueSync(event, options.mentions, "mentions")),
|
|
121
|
+
observations: normalizeOptionalText(resolveEventValueSync(event, options.observations, "observations")),
|
|
122
|
+
hasMentionsOverride: options.mentions !== undefined,
|
|
123
|
+
hasObservationsOverride: options.observations !== undefined,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function resolveMappingOptions(event, options) {
|
|
127
|
+
return {
|
|
128
|
+
companyVatCode: options.companyVatCode,
|
|
129
|
+
seriesName: await resolveRequiredEventValue(event, options.seriesName, "seriesName"),
|
|
130
|
+
language: options.language,
|
|
131
|
+
isTaxIncluded: options.isTaxIncluded,
|
|
132
|
+
measuringUnitName: normalizeOptionalText(await resolveEventValue(event, options.measuringUnitName)),
|
|
133
|
+
art311SpecialRegime: options.art311SpecialRegime,
|
|
134
|
+
art311SpecialRegimeText: options.art311SpecialRegimeText,
|
|
135
|
+
mentions: normalizeOptionalText(await resolveEventValue(event, options.mentions)),
|
|
136
|
+
observations: normalizeOptionalText(await resolveEventValue(event, options.observations)),
|
|
137
|
+
hasMentionsOverride: options.mentions !== undefined,
|
|
138
|
+
hasObservationsOverride: options.observations !== undefined,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function resolveEventValueSync(event, value, field) {
|
|
142
|
+
const resolved = typeof value === "function"
|
|
143
|
+
? value(event)
|
|
144
|
+
: value;
|
|
145
|
+
if (isPromiseLike(resolved)) {
|
|
146
|
+
throw new Error(`SmartBill mapping option "${field}" returned a Promise; use mapVoyantInvoiceToSmartbillAsync`);
|
|
147
|
+
}
|
|
148
|
+
return resolved;
|
|
149
|
+
}
|
|
150
|
+
function resolveRequiredEventValueSync(event, value, field) {
|
|
151
|
+
const resolved = resolveEventValueSync(event, value, field);
|
|
152
|
+
if (resolved === undefined || resolved === null) {
|
|
153
|
+
throw new Error(`SmartBill mapping option "${field}" is required`);
|
|
154
|
+
}
|
|
155
|
+
return resolved;
|
|
156
|
+
}
|
|
157
|
+
async function resolveEventValue(event, value) {
|
|
158
|
+
return typeof value === "function"
|
|
159
|
+
? await value(event)
|
|
160
|
+
: value;
|
|
161
|
+
}
|
|
162
|
+
async function resolveRequiredEventValue(event, value, field) {
|
|
163
|
+
const resolved = await resolveEventValue(event, value);
|
|
164
|
+
if (resolved === undefined || resolved === null) {
|
|
165
|
+
throw new Error(`SmartBill mapping option "${field}" is required`);
|
|
166
|
+
}
|
|
167
|
+
return resolved;
|
|
168
|
+
}
|
|
169
|
+
function isPromiseLike(value) {
|
|
170
|
+
return (value != null &&
|
|
171
|
+
typeof value === "object" &&
|
|
172
|
+
typeof value.then === "function");
|
|
173
|
+
}
|
|
174
|
+
function normalizeOptionalText(value) {
|
|
175
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
176
|
+
}
|
|
177
|
+
function normalizeCountryName(value) {
|
|
178
|
+
if (!value)
|
|
179
|
+
return undefined;
|
|
180
|
+
const trimmed = value.trim();
|
|
181
|
+
if (!trimmed)
|
|
182
|
+
return undefined;
|
|
183
|
+
const upper = trimmed.toUpperCase();
|
|
184
|
+
const overridden = COUNTRY_CODE_OVERRIDES[upper];
|
|
185
|
+
if (overridden)
|
|
186
|
+
return overridden;
|
|
187
|
+
if (/^[A-Z]{2}$/.test(upper)) {
|
|
188
|
+
try {
|
|
189
|
+
const displayName = new Intl.DisplayNames(["en"], { type: "region" }).of(upper);
|
|
190
|
+
return displayName && displayName !== upper && displayName !== "Unknown Region"
|
|
191
|
+
? displayName
|
|
192
|
+
: trimmed;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return trimmed;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return trimmed;
|
|
199
|
+
}
|
|
200
|
+
function asString(value, fallback) {
|
|
201
|
+
if (typeof value === "string" && value.length > 0)
|
|
202
|
+
return value;
|
|
203
|
+
return fallback;
|
|
204
|
+
}
|
|
205
|
+
function asStringOrUndefined(value) {
|
|
206
|
+
if (typeof value === "string" && value.length > 0)
|
|
207
|
+
return value;
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
function asNumber(value, fallback) {
|
|
211
|
+
if (typeof value === "number" && !Number.isNaN(value))
|
|
212
|
+
return value;
|
|
213
|
+
return fallback;
|
|
214
|
+
}
|
|
215
|
+
function asNumberOrUndefined(value) {
|
|
216
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
217
|
+
return value;
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/mock/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,2BAS1C;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAGjE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function concat(chunks) {
|
|
2
|
+
const length = chunks.reduce((total, chunk) => total + chunk.byteLength, 0);
|
|
3
|
+
const combined = new Uint8Array(length);
|
|
4
|
+
let offset = 0;
|
|
5
|
+
for (const chunk of chunks) {
|
|
6
|
+
combined.set(chunk, offset);
|
|
7
|
+
offset += chunk.byteLength;
|
|
8
|
+
}
|
|
9
|
+
return combined;
|
|
10
|
+
}
|
|
11
|
+
export async function importNodeHttp() {
|
|
12
|
+
const specifier = "node:http";
|
|
13
|
+
return import(specifier);
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a small but well-formed single-page PDF that satisfies SDKs
|
|
3
|
+
* expecting `application/pdf` bytes. The label is rendered on the page
|
|
4
|
+
* so the file is recognisable when opened by hand.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createPlaceholderPdf(label: string): Uint8Array;
|
|
7
|
+
//# sourceMappingURL=pdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../../src/mock/pdf.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAsC9D"}
|
package/dist/mock/pdf.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a small but well-formed single-page PDF that satisfies SDKs
|
|
3
|
+
* expecting `application/pdf` bytes. The label is rendered on the page
|
|
4
|
+
* so the file is recognisable when opened by hand.
|
|
5
|
+
*/
|
|
6
|
+
export function createPlaceholderPdf(label) {
|
|
7
|
+
const escapedLabel = label.replace(/[()\\]/g, (m) => `\\${m}`);
|
|
8
|
+
const stream = `BT /F1 18 Tf 72 720 Td (${escapedLabel}) Tj ET`;
|
|
9
|
+
const objects = [
|
|
10
|
+
"<< /Type /Catalog /Pages 2 0 R >>",
|
|
11
|
+
"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
|
|
12
|
+
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>",
|
|
13
|
+
`<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`,
|
|
14
|
+
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>",
|
|
15
|
+
];
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const parts = [];
|
|
18
|
+
parts.push(encoder.encode("%PDF-1.4\n%"));
|
|
19
|
+
// Binary marker: any four bytes >=128 satisfy PDF readers' "this file is binary" probe.
|
|
20
|
+
parts.push(new Uint8Array([0xe2, 0xe3, 0xcf, 0xd3, 0x0a]));
|
|
21
|
+
let length = parts.reduce((sum, p) => sum + p.byteLength, 0);
|
|
22
|
+
const offsets = [];
|
|
23
|
+
for (let i = 0; i < objects.length; i++) {
|
|
24
|
+
offsets.push(length);
|
|
25
|
+
const chunk = encoder.encode(`${i + 1} 0 obj\n${objects[i]}\nendobj\n`);
|
|
26
|
+
parts.push(chunk);
|
|
27
|
+
length += chunk.byteLength;
|
|
28
|
+
}
|
|
29
|
+
const xrefStart = length;
|
|
30
|
+
let xref = `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`;
|
|
31
|
+
for (const off of offsets) {
|
|
32
|
+
xref += `${String(off).padStart(10, "0")} 00000 n \n`;
|
|
33
|
+
}
|
|
34
|
+
xref += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xrefStart}\n%%EOF\n`;
|
|
35
|
+
parts.push(encoder.encode(xref));
|
|
36
|
+
const total = parts.reduce((sum, p) => sum + p.byteLength, 0);
|
|
37
|
+
const out = new Uint8Array(total);
|
|
38
|
+
let offset = 0;
|
|
39
|
+
for (const part of parts) {
|
|
40
|
+
out.set(part, offset);
|
|
41
|
+
offset += part.byteLength;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { SmartbillFetch, SmartbillInvoiceBody, SmartbillInvoiceResponse, SmartbillPaymentEntry } from "../types.js";
|
|
2
|
+
export type SmartbillMockDocumentKind = "invoice" | "estimate";
|
|
3
|
+
export type SmartbillMockDocumentStatus = "issued" | "cancelled" | "deleted" | "reversed" | "restored";
|
|
4
|
+
export interface SmartbillMockTax {
|
|
5
|
+
name: string;
|
|
6
|
+
percentage: number;
|
|
7
|
+
default?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SmartbillMockSeries {
|
|
10
|
+
name: string;
|
|
11
|
+
type: SmartbillMockDocumentKind;
|
|
12
|
+
nextNumber: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SmartbillMockDocument {
|
|
15
|
+
kind: SmartbillMockDocumentKind;
|
|
16
|
+
companyVatCode: string;
|
|
17
|
+
seriesName: string;
|
|
18
|
+
number: string;
|
|
19
|
+
status: SmartbillMockDocumentStatus;
|
|
20
|
+
body: SmartbillInvoiceBody;
|
|
21
|
+
url: string;
|
|
22
|
+
total: number;
|
|
23
|
+
paidAmount: number;
|
|
24
|
+
payments: SmartbillPaymentEntry[];
|
|
25
|
+
createdAt: string;
|
|
26
|
+
convertedInvoices: SmartbillInvoiceResponse[];
|
|
27
|
+
}
|
|
28
|
+
export interface SmartbillMockServerOptions {
|
|
29
|
+
taxes?: SmartbillMockTax[];
|
|
30
|
+
series?: SmartbillMockSeries[];
|
|
31
|
+
now?: () => Date;
|
|
32
|
+
}
|
|
33
|
+
export interface SmartbillMockListenOptions {
|
|
34
|
+
port?: number;
|
|
35
|
+
hostname?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SmartbillMockServerHandle {
|
|
38
|
+
apiUrl: string;
|
|
39
|
+
close: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface SmartbillMockRequest {
|
|
42
|
+
method: string;
|
|
43
|
+
url: string;
|
|
44
|
+
body?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SmartbillMockResponse {
|
|
47
|
+
status: number;
|
|
48
|
+
headers: Record<string, string>;
|
|
49
|
+
/**
|
|
50
|
+
* Serialised body. JSON endpoints emit a UTF-8 string; PDF endpoints
|
|
51
|
+
* emit raw bytes. The HTTP listener writes both as-is; the in-process
|
|
52
|
+
* `fetch` adapter exposes them through the matching Response method.
|
|
53
|
+
*/
|
|
54
|
+
body: string | Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
export interface SmartbillMockServer {
|
|
57
|
+
fetch: SmartbillFetch;
|
|
58
|
+
handleRequest: (request: SmartbillMockRequest) => Promise<SmartbillMockResponse>;
|
|
59
|
+
listen: (options?: SmartbillMockListenOptions) => Promise<SmartbillMockServerHandle>;
|
|
60
|
+
reset: () => void;
|
|
61
|
+
listDocuments: () => SmartbillMockDocument[];
|
|
62
|
+
getDocument: (kind: SmartbillMockDocumentKind, companyVatCode: string, seriesName: string, number: string) => SmartbillMockDocument | null;
|
|
63
|
+
convertEstimateToInvoice: (args: {
|
|
64
|
+
companyVatCode: string;
|
|
65
|
+
seriesName: string;
|
|
66
|
+
number: string;
|
|
67
|
+
invoiceSeriesName?: string;
|
|
68
|
+
}) => SmartbillInvoiceResponse;
|
|
69
|
+
}
|
|
70
|
+
export interface SmartbillNodeRequest extends AsyncIterable<Uint8Array | string> {
|
|
71
|
+
method?: string;
|
|
72
|
+
url?: string;
|
|
73
|
+
headers: {
|
|
74
|
+
host?: string | string[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface SmartbillNodeResponse {
|
|
78
|
+
setHeader: (key: string, value: string) => void;
|
|
79
|
+
statusCode: number;
|
|
80
|
+
end: (body: string | Uint8Array) => void;
|
|
81
|
+
}
|
|
82
|
+
export interface SmartbillNodeServer {
|
|
83
|
+
listen: (port: number, hostname: string, callback: () => void) => void;
|
|
84
|
+
once: (event: "error", handler: (error: Error) => void) => void;
|
|
85
|
+
off: (event: "error", handler: (error: Error) => void) => void;
|
|
86
|
+
address: () => string | {
|
|
87
|
+
port: number;
|
|
88
|
+
} | null;
|
|
89
|
+
close: (callback?: (error?: Error) => void) => void;
|
|
90
|
+
}
|
|
91
|
+
export interface SmartbillNodeHttp {
|
|
92
|
+
createServer: (handler: (req: SmartbillNodeRequest, res: SmartbillNodeResponse) => void | Promise<void>) => SmartbillNodeServer;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mock/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV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A;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,KAAK,IAAI,CAAA;CACzC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IACtE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,CAAA;IAC/D,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,CAAA;IAC9D,OAAO,EAAE,MAAM,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAC/C,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,CAAA;CACpD;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,CACZ,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KACrF,mBAAmB,CAAA;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SmartbillMockServer, SmartbillMockServerOptions } from "./mock/types.js";
|
|
2
|
+
export type { SmartbillMockDocument, SmartbillMockDocumentKind, SmartbillMockDocumentStatus, SmartbillMockListenOptions, SmartbillMockRequest, SmartbillMockResponse, SmartbillMockSeries, SmartbillMockServer, SmartbillMockServerHandle, SmartbillMockServerOptions, SmartbillMockTax, } from "./mock/types.js";
|
|
3
|
+
export declare function createSmartbillMockServer(options?: SmartbillMockServerOptions): SmartbillMockServer;
|
|
4
|
+
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAQV,mBAAmB,EACnB,0BAA0B,EAE3B,MAAM,iBAAiB,CAAA;AAYxB,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AAcxB,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,0BAA+B,GACvC,mBAAmB,CA0VrB"}
|