@voyantjs/plugin-smartbill 0.77.12 → 0.77.13
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 +39 -12
- 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 +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/invoice-ui.d.ts +2 -0
- package/dist/invoice-ui.d.ts.map +1 -1
- package/dist/invoice-ui.js +45 -4
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +22 -278
- package/dist/runtime.d.ts +5 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +2 -2
- package/dist/sync.d.ts +45 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +299 -0
- package/dist/validation.d.ts +2 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +18 -1
- package/package.json +20 -8
package/dist/plugin.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { financeService } from "@voyantjs/finance";
|
|
2
|
-
import { ZodError } from "zod";
|
|
3
|
-
import { isSmartbillPdfPersistMetadataUpdateError, persistSmartbillInvoiceArtifact, recordSmartbillInvoiceArtifactFailure, retrySmartbillInvoiceArtifact, } from "./artifacts.js";
|
|
4
1
|
import { createSmartbillSyncRuntime } from "./runtime.js";
|
|
5
|
-
import {
|
|
2
|
+
import { syncSmartbillInvoiceEvent } from "./sync.js";
|
|
3
|
+
import { parseSmartbillPluginOptions } from "./validation.js";
|
|
6
4
|
function coerceEvent(data) {
|
|
7
5
|
if (data == null || typeof data !== "object")
|
|
8
6
|
return null;
|
|
@@ -16,203 +14,8 @@ function coerceEvent(data) {
|
|
|
16
14
|
}
|
|
17
15
|
export function smartbillPlugin(options) {
|
|
18
16
|
const validatedOptions = parseSmartbillPluginOptions(options);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
return typeof value === "function"
|
|
22
|
-
? await value(context)
|
|
23
|
-
: value;
|
|
24
|
-
}
|
|
25
|
-
async function resolveArtifactDb(event, documentType, body, result) {
|
|
26
|
-
if (!artifacts.db)
|
|
27
|
-
return null;
|
|
28
|
-
const context = {
|
|
29
|
-
event,
|
|
30
|
-
documentType,
|
|
31
|
-
body: body ?? {
|
|
32
|
-
companyVatCode: validatedOptions.companyVatCode,
|
|
33
|
-
client: { name: "Client" },
|
|
34
|
-
seriesName: "unknown",
|
|
35
|
-
currency: "RON",
|
|
36
|
-
products: [],
|
|
37
|
-
},
|
|
38
|
-
result: result ?? {},
|
|
39
|
-
};
|
|
40
|
-
return (await resolveMaybe(artifacts.db, context)) ?? null;
|
|
41
|
-
}
|
|
42
|
-
async function findExistingSmartbillRef(event, documentType, body) {
|
|
43
|
-
if (idempotency.skipExistingExternalRef === false)
|
|
44
|
-
return null;
|
|
45
|
-
const db = await resolveArtifactDb(event, documentType, body);
|
|
46
|
-
if (!db)
|
|
47
|
-
return null;
|
|
48
|
-
const refs = await financeService.listInvoiceExternalRefs(db, event.id);
|
|
49
|
-
return refs.find((ref) => isMatchingSmartbillRef(ref, documentType)) ?? null;
|
|
50
|
-
}
|
|
51
|
-
async function handleExistingSmartbillRef(event, documentType, body, externalRef) {
|
|
52
|
-
logger.info?.(`[smartbill] ${documentType} already has SmartBill ref for ${event.id}; skipping create`, externalRef);
|
|
53
|
-
await applyExternalAllocationFromRefIfRequired(event, documentType, body, externalRef);
|
|
54
|
-
await writeBackInvoiceNumberFromRefIfRequired(event, documentType, body, externalRef);
|
|
55
|
-
try {
|
|
56
|
-
const persisted = await retrySmartbillInvoiceArtifact({
|
|
57
|
-
runtime: artifacts,
|
|
58
|
-
client,
|
|
59
|
-
externalRef,
|
|
60
|
-
documentType,
|
|
61
|
-
});
|
|
62
|
-
if (persisted.status === "persisted") {
|
|
63
|
-
logger.info?.(`[smartbill] ${documentType} PDF re-attached for ${event.id}`, persisted);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
const message = isSmartbillPdfPersistMetadataUpdateError(err)
|
|
68
|
-
? `[smartbill] artifact re-attach metadata update failed for ${event.id}`
|
|
69
|
-
: `[smartbill] artifact re-attach failed for ${event.id}`;
|
|
70
|
-
logger.error(message, err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function persistArtifact(event, documentType, body, result) {
|
|
74
|
-
try {
|
|
75
|
-
const persisted = await persistSmartbillInvoiceArtifact({
|
|
76
|
-
runtime: artifacts,
|
|
77
|
-
client,
|
|
78
|
-
event,
|
|
79
|
-
documentType,
|
|
80
|
-
body,
|
|
81
|
-
result,
|
|
82
|
-
});
|
|
83
|
-
if (persisted.status === "persisted") {
|
|
84
|
-
logger.info?.(`[smartbill] ${documentType} PDF persisted for ${event.id}`, persisted);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
if (isSmartbillPdfPersistMetadataUpdateError(err)) {
|
|
89
|
-
logger.error(`[smartbill] artifact persistence metadata update failed for ${event.id}`, err);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
logger.error(`[smartbill] artifact persistence failed for ${event.id}`, err);
|
|
93
|
-
try {
|
|
94
|
-
await recordSmartbillInvoiceArtifactFailure({
|
|
95
|
-
runtime: artifacts,
|
|
96
|
-
event,
|
|
97
|
-
documentType,
|
|
98
|
-
body,
|
|
99
|
-
result,
|
|
100
|
-
error: err,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
catch (recordError) {
|
|
104
|
-
logger.error(`[smartbill] artifact failure external-ref update failed for ${event.id}`, recordError);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
async function applyExternalAllocationIfRequired(event, documentType, body, result) {
|
|
109
|
-
if (event.externalAllocationRequired !== true || !result.number)
|
|
110
|
-
return;
|
|
111
|
-
const db = await resolveArtifactDb(event, documentType, body, result);
|
|
112
|
-
if (!db) {
|
|
113
|
-
throw new Error("SmartBill external allocation requires artifact database access");
|
|
114
|
-
}
|
|
115
|
-
const allocation = await financeService.applyExternalInvoiceAllocation(db, event.id, {
|
|
116
|
-
invoiceNumber: formatExternalInvoiceNumber(result.series ?? body.seriesName, result.number),
|
|
117
|
-
});
|
|
118
|
-
if (allocation.status === "applied") {
|
|
119
|
-
logger.info?.(`[smartbill] external number applied for ${event.id}`, allocation.invoice);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async function applyExternalAllocationFromRefIfRequired(event, documentType, body, externalRef) {
|
|
123
|
-
if (event.externalAllocationRequired !== true)
|
|
124
|
-
return;
|
|
125
|
-
const metadata = coerceMetadata(externalRef.metadata);
|
|
126
|
-
const number = metadataString(metadata, "number") ??
|
|
127
|
-
externalRef.externalNumber ??
|
|
128
|
-
externalRef.externalId ??
|
|
129
|
-
null;
|
|
130
|
-
if (!number) {
|
|
131
|
-
throw new Error("SmartBill external allocation requires an existing external number");
|
|
132
|
-
}
|
|
133
|
-
await applyExternalAllocationIfRequired(event, documentType, body, {
|
|
134
|
-
number,
|
|
135
|
-
series: metadataString(metadata, "series") ??
|
|
136
|
-
metadataString(metadata, "seriesName") ??
|
|
137
|
-
body.seriesName,
|
|
138
|
-
url: externalRef.externalUrl ?? undefined,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
async function resolveWriteBackInvoiceNumber(event, body, result) {
|
|
142
|
-
if (!writeBackInvoiceNumber)
|
|
143
|
-
return null;
|
|
144
|
-
if (typeof writeBackInvoiceNumber === "function") {
|
|
145
|
-
const invoiceNumber = await writeBackInvoiceNumber(event, result);
|
|
146
|
-
if (typeof invoiceNumber !== "string" || invoiceNumber.trim().length === 0) {
|
|
147
|
-
throw new Error("SmartBill invoice number write-back formatter returned an empty value");
|
|
148
|
-
}
|
|
149
|
-
return invoiceNumber;
|
|
150
|
-
}
|
|
151
|
-
if (!result.number)
|
|
152
|
-
return null;
|
|
153
|
-
return formatExternalInvoiceNumber(result.series ?? body.seriesName, result.number);
|
|
154
|
-
}
|
|
155
|
-
async function writeBackInvoiceNumberIfRequired(event, documentType, body, result) {
|
|
156
|
-
const invoiceNumber = await resolveWriteBackInvoiceNumber(event, body, result);
|
|
157
|
-
if (!invoiceNumber)
|
|
158
|
-
return;
|
|
159
|
-
const db = await resolveArtifactDb(event, documentType, body, result);
|
|
160
|
-
if (!db) {
|
|
161
|
-
throw new Error("SmartBill invoice number write-back requires artifact database access");
|
|
162
|
-
}
|
|
163
|
-
const invoice = await financeService.updateInvoice(db, event.id, { invoiceNumber });
|
|
164
|
-
if (!invoice) {
|
|
165
|
-
throw new Error(`SmartBill invoice number write-back failed for missing invoice ${event.id}`);
|
|
166
|
-
}
|
|
167
|
-
logger.info?.(`[smartbill] invoice number write-back applied for ${event.id}`, invoice);
|
|
168
|
-
}
|
|
169
|
-
async function writeBackInvoiceNumberFromRefIfRequired(event, documentType, body, externalRef) {
|
|
170
|
-
if (!writeBackInvoiceNumber)
|
|
171
|
-
return;
|
|
172
|
-
const metadata = coerceMetadata(externalRef.metadata);
|
|
173
|
-
const number = metadataString(metadata, "number") ??
|
|
174
|
-
externalRef.externalNumber ??
|
|
175
|
-
externalRef.externalId ??
|
|
176
|
-
null;
|
|
177
|
-
if (!number)
|
|
178
|
-
return;
|
|
179
|
-
await writeBackInvoiceNumberIfRequired(event, documentType, body, {
|
|
180
|
-
number,
|
|
181
|
-
series: metadataString(metadata, "series") ??
|
|
182
|
-
metadataString(metadata, "seriesName") ??
|
|
183
|
-
body.seriesName,
|
|
184
|
-
url: externalRef.externalUrl ?? undefined,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
async function recordSyncError(event, documentType, err) {
|
|
188
|
-
try {
|
|
189
|
-
await onError?.(event, err);
|
|
190
|
-
}
|
|
191
|
-
catch (handlerError) {
|
|
192
|
-
logger.error(`[smartbill] onError handler failed for ${event.id}`, handlerError);
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
const db = await resolveArtifactDb(event, documentType);
|
|
196
|
-
if (!db)
|
|
197
|
-
return;
|
|
198
|
-
const refs = await financeService.listInvoiceExternalRefs(db, event.id);
|
|
199
|
-
if (refs.some((ref) => isMatchingSmartbillRef(ref, documentType)))
|
|
200
|
-
return;
|
|
201
|
-
await financeService.registerInvoiceExternalRef(db, event.id, {
|
|
202
|
-
provider: "smartbill",
|
|
203
|
-
externalId: null,
|
|
204
|
-
externalNumber: null,
|
|
205
|
-
externalUrl: null,
|
|
206
|
-
status: "error",
|
|
207
|
-
syncedAt: new Date().toISOString(),
|
|
208
|
-
syncError: errorMessage(err),
|
|
209
|
-
metadata: { documentType },
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
catch (recordError) {
|
|
213
|
-
logger.error(`[smartbill] error external-ref recording failed for ${event.id}`, recordError);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
17
|
+
const runtime = createSmartbillSyncRuntime(validatedOptions);
|
|
18
|
+
const { client, logger, eventNames } = runtime;
|
|
216
19
|
async function resolveConfiguredSeriesName(event) {
|
|
217
20
|
const value = validatedOptions.seriesName;
|
|
218
21
|
return typeof value === "function" ? await value(event) : value;
|
|
@@ -230,21 +33,16 @@ export function smartbillPlugin(options) {
|
|
|
230
33
|
if (!event)
|
|
231
34
|
return;
|
|
232
35
|
try {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
logger.info?.(`[smartbill] invoice created: ${result.series}-${result.number} for ${event.id}`, result);
|
|
241
|
-
await persistArtifact(event, "invoice", body, result);
|
|
242
|
-
await writeBackInvoiceNumberIfRequired(event, "invoice", body, result);
|
|
243
|
-
await applyExternalAllocationIfRequired(event, "invoice", body, result);
|
|
36
|
+
await syncSmartbillInvoiceEvent({
|
|
37
|
+
event,
|
|
38
|
+
documentType: "invoice",
|
|
39
|
+
runtime,
|
|
40
|
+
pluginOptions: validatedOptions,
|
|
41
|
+
operationLabel: `createInvoice on "${eventNames.issued}"`,
|
|
42
|
+
});
|
|
244
43
|
}
|
|
245
|
-
catch
|
|
246
|
-
|
|
247
|
-
await recordSyncError(event, "invoice", err);
|
|
44
|
+
catch {
|
|
45
|
+
// `syncSmartbillInvoiceEvent` logs and records retryable state.
|
|
248
46
|
}
|
|
249
47
|
},
|
|
250
48
|
},
|
|
@@ -255,23 +53,16 @@ export function smartbillPlugin(options) {
|
|
|
255
53
|
if (!event)
|
|
256
54
|
return;
|
|
257
55
|
try {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
const result = await client.createProforma(body);
|
|
267
|
-
logger.info?.(`[smartbill] proforma created: ${result.series}-${result.number} for ${event.id}`, result);
|
|
268
|
-
await persistArtifact(event, "proforma", body, result);
|
|
269
|
-
await writeBackInvoiceNumberIfRequired(event, "proforma", body, result);
|
|
270
|
-
await applyExternalAllocationIfRequired(event, "proforma", body, result);
|
|
56
|
+
await syncSmartbillInvoiceEvent({
|
|
57
|
+
event,
|
|
58
|
+
documentType: "proforma",
|
|
59
|
+
runtime,
|
|
60
|
+
pluginOptions: validatedOptions,
|
|
61
|
+
operationLabel: `createProforma on "${eventNames.proformaIssued}"`,
|
|
62
|
+
});
|
|
271
63
|
}
|
|
272
|
-
catch
|
|
273
|
-
|
|
274
|
-
await recordSyncError(event, "proforma", err);
|
|
64
|
+
catch {
|
|
65
|
+
// `syncSmartbillInvoiceEvent` logs and records retryable state.
|
|
275
66
|
}
|
|
276
67
|
},
|
|
277
68
|
},
|
|
@@ -337,50 +128,3 @@ export function smartbillPlugin(options) {
|
|
|
337
128
|
subscribers,
|
|
338
129
|
};
|
|
339
130
|
}
|
|
340
|
-
function errorMessage(error) {
|
|
341
|
-
return error instanceof Error ? error.message : String(error);
|
|
342
|
-
}
|
|
343
|
-
function coerceMetadata(value) {
|
|
344
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
345
|
-
? value
|
|
346
|
-
: null;
|
|
347
|
-
}
|
|
348
|
-
function metadataString(metadata, key) {
|
|
349
|
-
const value = metadata?.[key];
|
|
350
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
351
|
-
}
|
|
352
|
-
function formatExternalInvoiceNumber(seriesName, number) {
|
|
353
|
-
const trimmedNumber = number.trim();
|
|
354
|
-
const trimmedSeries = seriesName?.trim();
|
|
355
|
-
if (!trimmedSeries || trimmedNumber.startsWith(`${trimmedSeries}-`))
|
|
356
|
-
return trimmedNumber;
|
|
357
|
-
return `${trimmedSeries}-${trimmedNumber}`;
|
|
358
|
-
}
|
|
359
|
-
function isUsableSmartbillRef(ref) {
|
|
360
|
-
return (ref.provider === "smartbill" &&
|
|
361
|
-
ref.status !== "error" &&
|
|
362
|
-
!ref.syncError &&
|
|
363
|
-
Boolean(ref.externalNumber || ref.externalId));
|
|
364
|
-
}
|
|
365
|
-
function isMatchingSmartbillRef(ref, documentType) {
|
|
366
|
-
if (!isUsableSmartbillRef(ref))
|
|
367
|
-
return false;
|
|
368
|
-
return metadataString(coerceMetadata(ref.metadata), "documentType") === documentType;
|
|
369
|
-
}
|
|
370
|
-
function parseSmartbillPluginOptions(options) {
|
|
371
|
-
try {
|
|
372
|
-
return smartbillPluginOptionsSchema.parse(options);
|
|
373
|
-
}
|
|
374
|
-
catch (error) {
|
|
375
|
-
if (error instanceof ZodError) {
|
|
376
|
-
const detail = error.issues
|
|
377
|
-
.map((issue) => {
|
|
378
|
-
const path = issue.path.join(".") || "options";
|
|
379
|
-
return `${path}: ${issue.message}`;
|
|
380
|
-
})
|
|
381
|
-
.join("; ");
|
|
382
|
-
throw new Error(`Invalid SmartBill plugin options: ${detail}`);
|
|
383
|
-
}
|
|
384
|
-
throw error;
|
|
385
|
-
}
|
|
386
|
-
}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SmartbillArtifactPersistenceOptions } from "./artifacts.js";
|
|
2
|
-
import { createSmartbillClient } from "./client.js";
|
|
2
|
+
import { createSmartbillClient, type SmartbillClientApi } from "./client.js";
|
|
3
3
|
import type { SmartbillLogger, SmartbillMapFn, SmartbillPluginOptions } from "./plugin.js";
|
|
4
4
|
export interface ResolvedSmartbillSyncEventNames {
|
|
5
5
|
issued: string;
|
|
@@ -17,5 +17,8 @@ export interface SmartbillSyncRuntime {
|
|
|
17
17
|
onError: SmartbillPluginOptions["onError"];
|
|
18
18
|
writeBackInvoiceNumber: SmartbillPluginOptions["writeBackInvoiceNumber"];
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export interface SmartbillSyncRuntimeOverrides {
|
|
21
|
+
client?: SmartbillClientApi;
|
|
22
|
+
}
|
|
23
|
+
export declare function createSmartbillSyncRuntime(options: SmartbillPluginOptions, overrides?: SmartbillSyncRuntimeOverrides): SmartbillSyncRuntime;
|
|
21
24
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAG1F,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAA;IAChD,MAAM,EAAE,eAAe,CAAA;IACvB,QAAQ,EAAE,cAAc,CAAA;IACxB,UAAU,EAAE,+BAA+B,CAAA;IAC3C,SAAS,EAAE,mCAAmC,CAAA;IAC9C,WAAW,EAAE,WAAW,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,CAAA;IAC/D,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAA;IAC1C,sBAAsB,EAAE,sBAAsB,CAAC,wBAAwB,CAAC,CAAA;CACzE;AAED,MAAM,WAAW,6BAA6B;IAC5C,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAC5B;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,sBAAsB,EAC/B,SAAS,GAAE,6BAAkC,GAC5C,oBAAoB,CAyCtB"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createSmartbillClient } from "./client.js";
|
|
2
2
|
import { mapVoyantInvoiceToSmartbillAsync } from "./mapping.js";
|
|
3
|
-
export function createSmartbillSyncRuntime(options) {
|
|
4
|
-
const client = createSmartbillClient(options);
|
|
3
|
+
export function createSmartbillSyncRuntime(options, overrides = {}) {
|
|
4
|
+
const client = overrides.client ?? createSmartbillClient(options);
|
|
5
5
|
const logger = options.logger ?? console;
|
|
6
6
|
const mappingOptions = {
|
|
7
7
|
companyVatCode: options.companyVatCode,
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type InvoiceIssueRuntime } from "@voyantjs/finance";
|
|
2
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
3
|
+
import { persistSmartbillInvoiceArtifact, retrySmartbillInvoiceArtifact, type SmartbillDocumentType, type SmartbillExternalRef } from "./artifacts.js";
|
|
4
|
+
import type { SmartbillClientApi } from "./client.js";
|
|
5
|
+
import type { SmartbillPluginOptions } from "./plugin.js";
|
|
6
|
+
import { type SmartbillSyncRuntime } from "./runtime.js";
|
|
7
|
+
import type { SmartbillInvoiceResponse, VoyantInvoiceEvent } from "./types.js";
|
|
8
|
+
export interface SyncSmartbillInvoiceInput {
|
|
9
|
+
db: PostgresJsDatabase;
|
|
10
|
+
invoiceId: string;
|
|
11
|
+
pluginOptions: SmartbillPluginOptions;
|
|
12
|
+
client?: SmartbillClientApi;
|
|
13
|
+
issueRuntime?: Omit<InvoiceIssueRuntime, "eventBus">;
|
|
14
|
+
}
|
|
15
|
+
export interface SyncSmartbillInvoiceEventInput {
|
|
16
|
+
event: VoyantInvoiceEvent;
|
|
17
|
+
documentType: SmartbillDocumentType;
|
|
18
|
+
runtime: SmartbillSyncRuntime;
|
|
19
|
+
pluginOptions: Pick<SmartbillPluginOptions, "companyVatCode" | "seriesName">;
|
|
20
|
+
operationLabel?: string;
|
|
21
|
+
}
|
|
22
|
+
export type SyncSmartbillInvoiceResult = {
|
|
23
|
+
status: "not_found";
|
|
24
|
+
invoiceId: string;
|
|
25
|
+
} | {
|
|
26
|
+
status: "unsupported_document_type";
|
|
27
|
+
invoiceId: string;
|
|
28
|
+
invoiceType: string;
|
|
29
|
+
} | SyncSmartbillInvoiceEventResult;
|
|
30
|
+
export type SyncSmartbillInvoiceEventResult = {
|
|
31
|
+
status: "existing_ref";
|
|
32
|
+
invoiceId: string;
|
|
33
|
+
documentType: SmartbillDocumentType;
|
|
34
|
+
externalRef: SmartbillExternalRef;
|
|
35
|
+
artifact: Awaited<ReturnType<typeof retrySmartbillInvoiceArtifact>> | null;
|
|
36
|
+
} | {
|
|
37
|
+
status: "created";
|
|
38
|
+
invoiceId: string;
|
|
39
|
+
documentType: SmartbillDocumentType;
|
|
40
|
+
result: SmartbillInvoiceResponse;
|
|
41
|
+
artifact: Awaited<ReturnType<typeof persistSmartbillInvoiceArtifact>> | null;
|
|
42
|
+
};
|
|
43
|
+
export declare function syncSmartbillInvoice({ db, invoiceId, pluginOptions, client, issueRuntime, }: SyncSmartbillInvoiceInput): Promise<SyncSmartbillInvoiceResult>;
|
|
44
|
+
export declare function syncSmartbillInvoiceEvent({ event, documentType, runtime, pluginOptions, operationLabel, }: SyncSmartbillInvoiceEventInput): Promise<SyncSmartbillInvoiceEventResult>;
|
|
45
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,EAEL,+BAA+B,EAE/B,6BAA6B,EAE7B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAGV,sBAAsB,EACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAA8B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACpF,OAAO,KAAK,EAAwB,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGpG,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,kBAAkB,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,sBAAsB,CAAA;IACrC,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,YAAY,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,8BAA8B;IAC7C,KAAK,EAAE,kBAAkB,CAAA;IACzB,YAAY,EAAE,qBAAqB,CAAA;IACnC,OAAO,EAAE,oBAAoB,CAAA;IAC7B,aAAa,EAAE,IAAI,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,YAAY,CAAC,CAAA;IAC5E,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,MAAM,0BAA0B,GAClC;IACE,MAAM,EAAE,WAAW,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,GACD;IACE,MAAM,EAAE,2BAA2B,CAAA;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB,GACD,+BAA+B,CAAA;AAEnC,MAAM,MAAM,+BAA+B,GACvC;IACE,MAAM,EAAE,cAAc,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,qBAAqB,CAAA;IACnC,WAAW,EAAE,oBAAoB,CAAA;IACjC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAC,GAAG,IAAI,CAAA;CAC3E,GACD;IACE,MAAM,EAAE,SAAS,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,qBAAqB,CAAA;IACnC,MAAM,EAAE,wBAAwB,CAAA;IAChC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,+BAA+B,CAAC,CAAC,GAAG,IAAI,CAAA;CAC7E,CAAA;AAEL,wBAAsB,oBAAoB,CAAC,EACzC,EAAE,EACF,SAAS,EACT,aAAa,EACb,MAAM,EACN,YAAY,GACb,EAAE,yBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAqBjE;AAED,wBAAsB,yBAAyB,CAAC,EAC9C,KAAK,EACL,YAAY,EACZ,OAAO,EACP,aAAa,EACb,cAAiF,GAClF,EAAE,8BAA8B,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAyB3E"}
|