@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.
Files changed (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +324 -0
  3. package/dist/artifacts.d.ts +80 -0
  4. package/dist/artifacts.d.ts.map +1 -0
  5. package/dist/artifacts.js +295 -0
  6. package/dist/client/errors.d.ts +28 -0
  7. package/dist/client/errors.d.ts.map +1 -0
  8. package/dist/client/errors.js +32 -0
  9. package/dist/client/fetch.d.ts +4 -0
  10. package/dist/client/fetch.d.ts.map +1 -0
  11. package/dist/client/fetch.js +32 -0
  12. package/dist/client/rate-limit.d.ts +8 -0
  13. package/dist/client/rate-limit.d.ts.map +1 -0
  14. package/dist/client/rate-limit.js +54 -0
  15. package/dist/client/resilience.d.ts +36 -0
  16. package/dist/client/resilience.d.ts.map +1 -0
  17. package/dist/client/resilience.js +23 -0
  18. package/dist/client.d.ts +67 -0
  19. package/dist/client.d.ts.map +1 -0
  20. package/dist/client.js +234 -0
  21. package/dist/hono.d.ts +199 -0
  22. package/dist/hono.d.ts.map +1 -0
  23. package/dist/hono.js +77 -0
  24. package/dist/index.d.ts +22 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +10 -0
  27. package/dist/invoice-ui-data.d.ts +46 -0
  28. package/dist/invoice-ui-data.d.ts.map +1 -0
  29. package/dist/invoice-ui-data.js +62 -0
  30. package/dist/invoice-ui.d.ts +438 -0
  31. package/dist/invoice-ui.d.ts.map +1 -0
  32. package/dist/invoice-ui.js +97 -0
  33. package/dist/mapping.d.ts +50 -0
  34. package/dist/mapping.d.ts.map +1 -0
  35. package/dist/mapping.js +219 -0
  36. package/dist/mock/node.d.ts +4 -0
  37. package/dist/mock/node.d.ts.map +1 -0
  38. package/dist/mock/node.js +14 -0
  39. package/dist/mock/pdf.d.ts +7 -0
  40. package/dist/mock/pdf.d.ts.map +1 -0
  41. package/dist/mock/pdf.js +44 -0
  42. package/dist/mock/types.d.ts +94 -0
  43. package/dist/mock/types.d.ts.map +1 -0
  44. package/dist/mock/types.js +1 -0
  45. package/dist/mock.d.ts +4 -0
  46. package/dist/mock.d.ts.map +1 -0
  47. package/dist/mock.js +431 -0
  48. package/dist/plugin.d.ts +55 -0
  49. package/dist/plugin.d.ts.map +1 -0
  50. package/dist/plugin.js +192 -0
  51. package/dist/runtime.d.ts +25 -0
  52. package/dist/runtime.d.ts.map +1 -0
  53. package/dist/runtime.js +42 -0
  54. package/dist/settlement.d.ts +33 -0
  55. package/dist/settlement.d.ts.map +1 -0
  56. package/dist/settlement.js +65 -0
  57. package/dist/sync/events.d.ts +5 -0
  58. package/dist/sync/events.d.ts.map +1 -0
  59. package/dist/sync/events.js +96 -0
  60. package/dist/sync/helpers.d.ts +66 -0
  61. package/dist/sync/helpers.d.ts.map +1 -0
  62. package/dist/sync/helpers.js +353 -0
  63. package/dist/sync/invoice.d.ts +3 -0
  64. package/dist/sync/invoice.d.ts.map +1 -0
  65. package/dist/sync/invoice.js +25 -0
  66. package/dist/sync/types.d.ts +71 -0
  67. package/dist/sync/types.d.ts.map +1 -0
  68. package/dist/sync/types.js +1 -0
  69. package/dist/sync.d.ts +4 -0
  70. package/dist/sync.d.ts.map +1 -0
  71. package/dist/sync.js +2 -0
  72. package/dist/types.d.ts +189 -0
  73. package/dist/types.d.ts.map +1 -0
  74. package/dist/types.js +1 -0
  75. package/dist/validation.d.ts +39 -0
  76. package/dist/validation.d.ts.map +1 -0
  77. package/dist/validation.js +120 -0
  78. package/dist/workflow-candidates.d.ts +36 -0
  79. package/dist/workflow-candidates.d.ts.map +1 -0
  80. package/dist/workflow-candidates.js +182 -0
  81. package/dist/workflow-remote-discovery.d.ts +6 -0
  82. package/dist/workflow-remote-discovery.d.ts.map +1 -0
  83. package/dist/workflow-remote-discovery.js +83 -0
  84. package/dist/workflows/refs.d.ts +13 -0
  85. package/dist/workflows/refs.d.ts.map +1 -0
  86. package/dist/workflows/refs.js +51 -0
  87. package/dist/workflows/spaced-client.d.ts +5 -0
  88. package/dist/workflows/spaced-client.d.ts.map +1 -0
  89. package/dist/workflows/spaced-client.js +44 -0
  90. package/dist/workflows/types.d.ts +142 -0
  91. package/dist/workflows/types.d.ts.map +1 -0
  92. package/dist/workflows/types.js +1 -0
  93. package/dist/workflows.d.ts +5 -0
  94. package/dist/workflows.d.ts.map +1 -0
  95. package/dist/workflows.js +229 -0
  96. package/package.json +129 -0
@@ -0,0 +1,142 @@
1
+ import type { Invoice } from "@voyant-travel/finance";
2
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
3
+ import type { SmartbillClientApi } from "../client.js";
4
+ import type { SmartbillEstimateInvoicesResponse, SmartbillInvoiceResponse, SmartbillPdfResponse, SmartbillStatusResponse } from "../types.js";
5
+ import type { SmartbillCandidateExternalRefRecorder, SmartbillCandidateInvoice, SmartbillWorkflowCandidateSource } from "../workflow-candidates.js";
6
+ export type { SmartbillCandidateExternalRefRecorder, SmartbillCandidateExternalRefRecorderContext, SmartbillCandidateInvoice, SmartbillWorkflowCandidateSource, } from "../workflow-candidates.js";
7
+ export type SmartbillWorkflowDocumentType = "invoice" | "proforma";
8
+ export interface SmartbillWorkflowLogger {
9
+ info?: (message: string, meta?: unknown) => void;
10
+ error?: (message: string, meta?: unknown) => void;
11
+ }
12
+ export interface SmartbillWorkflowInvoice {
13
+ id: string;
14
+ invoiceNumber: string;
15
+ invoiceType: Invoice["invoiceType"];
16
+ status: Invoice["status"];
17
+ currency: string;
18
+ totalCents: number;
19
+ paidCents: number;
20
+ balanceDueCents: number;
21
+ }
22
+ export interface SmartbillWorkflowExternalRef {
23
+ id: string;
24
+ invoiceId: string;
25
+ provider: string;
26
+ externalId: string | null;
27
+ externalNumber: string | null;
28
+ externalUrl: string | null;
29
+ status: string | null;
30
+ metadata: unknown;
31
+ syncError: string | null;
32
+ createdAt?: Date | null;
33
+ updatedAt?: Date | null;
34
+ invoice?: SmartbillWorkflowInvoice | null;
35
+ }
36
+ export interface SmartbillReferenceParts {
37
+ companyVatCode: string;
38
+ seriesName: string;
39
+ number: string;
40
+ documentType: SmartbillWorkflowDocumentType;
41
+ }
42
+ export interface SmartbillProformaConversion {
43
+ proformaRef: SmartbillWorkflowExternalRef;
44
+ invoice: SmartbillWorkflowInvoice | null;
45
+ companyVatCode: string;
46
+ proformaSeriesName: string;
47
+ proformaNumber: string;
48
+ invoiceSeriesName: string;
49
+ invoiceNumber: string;
50
+ invoiceUrl: string | null;
51
+ response: SmartbillEstimateInvoicesResponse;
52
+ smartbillInvoice: SmartbillInvoiceResponse;
53
+ }
54
+ export interface SmartbillProformaConversionPollerOptions {
55
+ db?: PostgresJsDatabase;
56
+ client: SmartbillClientApi;
57
+ limit?: number;
58
+ requestSpacingMs?: number;
59
+ companyVatCode?: string;
60
+ source?: SmartbillWorkflowCandidateSource;
61
+ logger?: SmartbillWorkflowLogger;
62
+ listExternalRefs?: () => Promise<SmartbillWorkflowExternalRef[]>;
63
+ listCandidateInvoices?: () => Promise<SmartbillCandidateInvoice[]>;
64
+ recordCandidateExternalRef?: SmartbillCandidateExternalRefRecorder;
65
+ onConverted: (proformaRef: SmartbillWorkflowExternalRef, conversion: SmartbillProformaConversion) => void | Promise<void>;
66
+ onError?: (error: SmartbillWorkflowError) => void | Promise<void>;
67
+ }
68
+ export interface SmartbillWorkflowError {
69
+ ref?: SmartbillWorkflowExternalRef;
70
+ error: unknown;
71
+ }
72
+ export interface SmartbillProformaConversionPollerResult {
73
+ checked: number;
74
+ converted: SmartbillProformaConversion[];
75
+ skipped: Array<{
76
+ ref: SmartbillWorkflowExternalRef;
77
+ reason: string;
78
+ }>;
79
+ errors: SmartbillWorkflowError[];
80
+ }
81
+ export type SmartbillRemoteDocumentStatus = "present" | "issued" | "paid" | "unpaid" | "partially_paid" | "voided" | "cancelled" | "reversed" | "deleted" | "missing";
82
+ export interface SmartbillRemoteDocument extends SmartbillReferenceParts {
83
+ status?: SmartbillRemoteDocumentStatus;
84
+ metadata?: Record<string, unknown>;
85
+ accessors?: SmartbillRemoteDocumentAccessors;
86
+ }
87
+ export interface SmartbillRemoteDocumentAccessors {
88
+ viewPdf: () => Promise<SmartbillPdfResponse>;
89
+ getPaymentStatus?: () => Promise<SmartbillStatusResponse>;
90
+ listEstimateInvoices?: () => Promise<SmartbillEstimateInvoicesResponse>;
91
+ }
92
+ export type SmartbillDriftFindingType = "missing_local" | "missing_remote" | "voided_remote";
93
+ interface SmartbillDriftFindingBase {
94
+ document: SmartbillReferenceParts;
95
+ error?: unknown;
96
+ }
97
+ export interface SmartbillMissingLocalDriftFinding extends SmartbillDriftFindingBase {
98
+ type: "missing_local";
99
+ remote: SmartbillRemoteDocument;
100
+ }
101
+ export interface SmartbillKnownLocalDriftFinding extends SmartbillDriftFindingBase {
102
+ type: "missing_remote" | "voided_remote";
103
+ ref?: SmartbillWorkflowExternalRef;
104
+ invoice?: SmartbillWorkflowInvoice | null;
105
+ remote?: SmartbillRemoteDocument | null;
106
+ }
107
+ export type SmartbillDriftFinding = SmartbillMissingLocalDriftFinding | SmartbillKnownLocalDriftFinding;
108
+ export interface SmartbillDriftReconcilerOptions {
109
+ db?: PostgresJsDatabase;
110
+ client: SmartbillClientApi;
111
+ limit?: number;
112
+ requestSpacingMs?: number;
113
+ companyVatCode?: string;
114
+ logger?: SmartbillWorkflowLogger;
115
+ discoverRemote?: boolean;
116
+ source?: SmartbillWorkflowCandidateSource;
117
+ listExternalRefs?: () => Promise<SmartbillWorkflowExternalRef[]>;
118
+ listCandidateInvoices?: () => Promise<SmartbillCandidateInvoice[]>;
119
+ recordCandidateExternalRef?: SmartbillCandidateExternalRefRecorder;
120
+ listRemoteDocuments?: (context: {
121
+ refs: SmartbillWorkflowExternalRef[];
122
+ }) => Promise<SmartbillRemoteDocument[]>;
123
+ verifyRemoteDocument?: (context: {
124
+ ref: SmartbillWorkflowExternalRef;
125
+ document: SmartbillReferenceParts;
126
+ }) => Promise<SmartbillRemoteDocumentStatus | SmartbillRemoteDocument>;
127
+ onFinding?: (finding: SmartbillDriftFinding) => void | Promise<void>;
128
+ onMissingLocal?: (finding: SmartbillMissingLocalDriftFinding) => void | Promise<void>;
129
+ onError?: (error: SmartbillWorkflowError) => void | Promise<void>;
130
+ }
131
+ export interface SmartbillDriftReconcilerResult {
132
+ checked: number;
133
+ findings: SmartbillDriftFinding[];
134
+ skipped: Array<{
135
+ ref: SmartbillWorkflowExternalRef;
136
+ reason: string;
137
+ }>;
138
+ errors: SmartbillWorkflowError[];
139
+ }
140
+ export type SmartbillProformaConversionPoller = () => Promise<SmartbillProformaConversionPollerResult>;
141
+ export type SmartbillDriftReconciler = () => Promise<SmartbillDriftReconcilerResult>;
142
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workflows/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,KAAK,EACV,iCAAiC,EACjC,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EACV,qCAAqC,EACrC,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,2BAA2B,CAAA;AAElC,YAAY,EACV,qCAAqC,EACrC,4CAA4C,EAC5C,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,UAAU,CAAA;AAElE,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MA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EAAE,CAAA;CACjC;AAED,MAAM,MAAM,iCAAiC,GAC3C,MAAM,OAAO,CAAC,uCAAuC,CAAC,CAAA;AAExD,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,8BAA8B,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { SmartbillDriftReconciler, SmartbillDriftReconcilerOptions, SmartbillProformaConversionPoller, SmartbillProformaConversionPollerOptions } from "./workflows/types.js";
2
+ export type { SmartbillCandidateExternalRefRecorder, SmartbillCandidateExternalRefRecorderContext, SmartbillCandidateInvoice, SmartbillDriftFinding, SmartbillDriftFindingType, SmartbillDriftReconciler, SmartbillDriftReconcilerOptions, SmartbillDriftReconcilerResult, SmartbillKnownLocalDriftFinding, SmartbillMissingLocalDriftFinding, SmartbillProformaConversion, SmartbillProformaConversionPoller, SmartbillProformaConversionPollerOptions, SmartbillProformaConversionPollerResult, SmartbillReferenceParts, SmartbillRemoteDocument, SmartbillRemoteDocumentAccessors, SmartbillRemoteDocumentStatus, SmartbillWorkflowCandidateSource, SmartbillWorkflowDocumentType, SmartbillWorkflowError, SmartbillWorkflowExternalRef, SmartbillWorkflowInvoice, SmartbillWorkflowLogger, } from "./workflows/types.js";
3
+ export declare function createSmartbillProformaConversionPoller(options: SmartbillProformaConversionPollerOptions): SmartbillProformaConversionPoller;
4
+ export declare function createSmartbillDriftReconciler(options: SmartbillDriftReconcilerOptions): SmartbillDriftReconciler;
5
+ //# sourceMappingURL=workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../src/workflows.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEV,wBAAwB,EACxB,+BAA+B,EAI/B,iCAAiC,EACjC,wCAAwC,EASzC,MAAM,sBAAsB,CAAA;AAE7B,YAAY,EACV,qCAAqC,EACrC,4CAA4C,EAC5C,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,+BAA+B,EAC/B,8BAA8B,EAC9B,+BAA+B,EAC/B,iCAAiC,EACjC,2BAA2B,EAC3B,iCAAiC,EACjC,wCAAwC,EACxC,uCAAuC,EACvC,uBAAuB,EACvB,uBAAuB,EACvB,gCAAgC,EAChC,6BAA6B,EAC7B,gCAAgC,EAChC,6BAA6B,EAC7B,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAE7B,wBAAgB,uCAAuC,CACrD,OAAO,EAAE,wCAAwC,GAChD,iCAAiC,CA0DnC;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,wBAAwB,CAoF1B"}
@@ -0,0 +1,229 @@
1
+ import { discoverRemoteDocuments, paymentStatusToRemoteStatus, } from "./workflow-remote-discovery.js";
2
+ import { loadSmartbillWorkflowRefs } from "./workflows/refs.js";
3
+ import { createSpacedSmartbillClient, isSmartbillRateLimitError, } from "./workflows/spaced-client.js";
4
+ export function createSmartbillProformaConversionPoller(options) {
5
+ return async () => {
6
+ const result = {
7
+ checked: 0,
8
+ converted: [],
9
+ skipped: [],
10
+ errors: [],
11
+ };
12
+ const client = createSpacedSmartbillClient(options.client, options.requestSpacingMs);
13
+ const refs = await loadSmartbillWorkflowRefs(options);
14
+ for (const ref of refs) {
15
+ const document = resolveReferenceParts(ref, options.companyVatCode);
16
+ if (document?.documentType !== "proforma")
17
+ continue;
18
+ result.checked += 1;
19
+ try {
20
+ const response = await client.listEstimateInvoices(document.companyVatCode, document.seriesName, document.number);
21
+ const convertedInvoices = convertedInvoicesFromResponse(response);
22
+ if (convertedInvoices.length === 0) {
23
+ result.skipped.push({ ref, reason: "not_converted" });
24
+ continue;
25
+ }
26
+ for (const smartbillInvoice of convertedInvoices) {
27
+ if (!smartbillInvoice.series || !smartbillInvoice.number) {
28
+ result.skipped.push({ ref, reason: "missing_converted_invoice_number" });
29
+ continue;
30
+ }
31
+ const conversion = {
32
+ proformaRef: ref,
33
+ invoice: ref.invoice ?? null,
34
+ companyVatCode: document.companyVatCode,
35
+ proformaSeriesName: document.seriesName,
36
+ proformaNumber: document.number,
37
+ invoiceSeriesName: smartbillInvoice.series,
38
+ invoiceNumber: smartbillInvoice.number,
39
+ invoiceUrl: smartbillInvoice.url ?? null,
40
+ response,
41
+ smartbillInvoice,
42
+ };
43
+ await options.onConverted(ref, conversion);
44
+ options.logger?.info?.("[smartbill] proforma conversion detected", conversion);
45
+ result.converted.push(conversion);
46
+ }
47
+ }
48
+ catch (error) {
49
+ await recordWorkflowError(options, result.errors, { ref, error });
50
+ if (isSmartbillRateLimitError(error))
51
+ break;
52
+ }
53
+ }
54
+ return result;
55
+ };
56
+ }
57
+ export function createSmartbillDriftReconciler(options) {
58
+ return async () => {
59
+ const result = {
60
+ checked: 0,
61
+ findings: [],
62
+ skipped: [],
63
+ errors: [],
64
+ };
65
+ const workflowOptions = {
66
+ ...options,
67
+ client: createSpacedSmartbillClient(options.client, options.requestSpacingMs),
68
+ };
69
+ const refs = await loadSmartbillWorkflowRefs(options);
70
+ let remoteDocuments;
71
+ try {
72
+ remoteDocuments = await loadRemoteDocuments(workflowOptions, refs);
73
+ }
74
+ catch (error) {
75
+ if (!isSmartbillRateLimitError(error))
76
+ throw error;
77
+ await recordWorkflowError(options, result.errors, { error });
78
+ return result;
79
+ }
80
+ const remoteDocumentMap = new Map((remoteDocuments ?? []).map((remote) => [documentKey(remote), remote]));
81
+ const hasTrustedRemoteInventory = options.listRemoteDocuments !== undefined;
82
+ const localDocuments = new Map();
83
+ for (const ref of refs) {
84
+ const document = resolveReferenceParts(ref, options.companyVatCode);
85
+ if (!document) {
86
+ result.skipped.push({ ref, reason: "missing_smartbill_reference" });
87
+ continue;
88
+ }
89
+ const key = documentKey(document);
90
+ localDocuments.set(key, document);
91
+ result.checked += 1;
92
+ try {
93
+ const remote = hasTrustedRemoteInventory
94
+ ? (remoteDocumentMap.get(key) ?? { ...document, status: "missing" })
95
+ : await verifyRemoteDocument(workflowOptions, ref, document);
96
+ if (remote.status === "missing" || remote.status === "deleted") {
97
+ await recordFinding(options, result.findings, {
98
+ type: "missing_remote",
99
+ document,
100
+ ref,
101
+ invoice: ref.invoice ?? null,
102
+ remote,
103
+ });
104
+ }
105
+ else if (isVoidedRemote(remote.status) && ref.invoice?.status !== "void") {
106
+ await recordFinding(options, result.findings, {
107
+ type: "voided_remote",
108
+ document,
109
+ ref,
110
+ invoice: ref.invoice ?? null,
111
+ remote,
112
+ });
113
+ }
114
+ }
115
+ catch (error) {
116
+ await recordWorkflowError(options, result.errors, { ref, error });
117
+ if (isSmartbillRateLimitError(error))
118
+ return result;
119
+ await recordFinding(options, result.findings, {
120
+ type: "missing_remote",
121
+ document,
122
+ ref,
123
+ invoice: ref.invoice ?? null,
124
+ remote: null,
125
+ error,
126
+ });
127
+ }
128
+ }
129
+ for (const remote of remoteDocuments ?? []) {
130
+ if (!localDocuments.has(documentKey(remote))) {
131
+ await recordMissingLocalFinding(options, result.findings, {
132
+ type: "missing_local",
133
+ document: remote,
134
+ remote,
135
+ });
136
+ }
137
+ }
138
+ return result;
139
+ };
140
+ }
141
+ async function loadRemoteDocuments(options, refs) {
142
+ if (options.listRemoteDocuments)
143
+ return options.listRemoteDocuments({ refs });
144
+ if (!options.discoverRemote)
145
+ return undefined;
146
+ return discoverRemoteDocuments(options.client, resolveDiscoveryCompanyVatCode(options, refs));
147
+ }
148
+ function resolveDiscoveryCompanyVatCode(options, refs) {
149
+ if (options.companyVatCode)
150
+ return options.companyVatCode;
151
+ const companyVatCodes = new Set(refs
152
+ .map((ref) => resolveReferenceParts(ref, options.companyVatCode)?.companyVatCode)
153
+ .filter((value) => typeof value === "string" && value.length > 0));
154
+ if (companyVatCodes.size === 1)
155
+ return [...companyVatCodes][0];
156
+ throw new Error("SmartBill remote discovery requires companyVatCode");
157
+ }
158
+ function convertedInvoicesFromResponse(response) {
159
+ if (Array.isArray(response.invoices) && response.invoices.length > 0) {
160
+ return response.invoices.filter((invoice) => invoice.series && invoice.number);
161
+ }
162
+ if (response.areInvoicesCreated && response.series && response.number) {
163
+ return [{ series: response.series, number: response.number }];
164
+ }
165
+ return [];
166
+ }
167
+ async function verifyRemoteDocument(options, ref, document) {
168
+ const verified = await (options.verifyRemoteDocument
169
+ ? options.verifyRemoteDocument({ ref, document })
170
+ : defaultVerifyRemoteDocument(options.client, document));
171
+ return typeof verified === "string" ? { ...document, status: verified } : verified;
172
+ }
173
+ async function defaultVerifyRemoteDocument(client, document) {
174
+ if (document.documentType === "proforma") {
175
+ await client.listEstimateInvoices(document.companyVatCode, document.seriesName, document.number);
176
+ return "present";
177
+ }
178
+ const status = await client.getPaymentStatus(document.companyVatCode, document.seriesName, document.number);
179
+ return paymentStatusToRemoteStatus(status);
180
+ }
181
+ function resolveReferenceParts(ref, fallbackCompanyVatCode) {
182
+ const metadata = coerceMetadata(ref.metadata);
183
+ const documentType = coerceDocumentType(metadata?.documentType);
184
+ const companyVatCode = metadataString(metadata, "companyVatCode") ??
185
+ metadataString(metadata, "vatCode") ??
186
+ fallbackCompanyVatCode;
187
+ const seriesName = metadataString(metadata, "series") ?? metadataString(metadata, "seriesName");
188
+ const number = metadataString(metadata, "number") ?? ref.externalNumber ?? ref.externalId;
189
+ if (!documentType || !companyVatCode || !seriesName || !number)
190
+ return null;
191
+ return { companyVatCode, seriesName, number, documentType };
192
+ }
193
+ function coerceMetadata(value) {
194
+ return value && typeof value === "object" && !Array.isArray(value)
195
+ ? value
196
+ : null;
197
+ }
198
+ function metadataString(metadata, key) {
199
+ const value = metadata?.[key];
200
+ return typeof value === "string" && value.length > 0 ? value : null;
201
+ }
202
+ function coerceDocumentType(value) {
203
+ return value === "invoice" || value === "proforma" ? value : null;
204
+ }
205
+ function documentKey(document) {
206
+ return [
207
+ document.documentType,
208
+ document.companyVatCode,
209
+ document.seriesName,
210
+ document.number,
211
+ ].join(":");
212
+ }
213
+ function isVoidedRemote(status) {
214
+ return status === "voided" || status === "cancelled" || status === "reversed";
215
+ }
216
+ async function recordFinding(options, findings, finding) {
217
+ findings.push(finding);
218
+ options.logger?.info?.("[smartbill] drift finding", finding);
219
+ await options.onFinding?.(finding);
220
+ }
221
+ async function recordMissingLocalFinding(options, findings, finding) {
222
+ await recordFinding(options, findings, finding);
223
+ await options.onMissingLocal?.(finding);
224
+ }
225
+ async function recordWorkflowError(options, errors, error) {
226
+ errors.push(error);
227
+ options.logger?.error?.("[smartbill] workflow error", error);
228
+ await options.onError?.(error);
229
+ }
package/package.json ADDED
@@ -0,0 +1,129 @@
1
+ {
2
+ "name": "@voyant-travel/plugin-smartbill",
3
+ "version": "0.119.2",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./client": {
13
+ "types": "./dist/client.d.ts",
14
+ "import": "./dist/client.js",
15
+ "default": "./dist/client.js"
16
+ },
17
+ "./mock": {
18
+ "types": "./dist/mock.d.ts",
19
+ "import": "./dist/mock.js",
20
+ "default": "./dist/mock.js"
21
+ },
22
+ "./plugin": {
23
+ "types": "./dist/plugin.d.ts",
24
+ "import": "./dist/plugin.js",
25
+ "default": "./dist/plugin.js"
26
+ },
27
+ "./hono": {
28
+ "types": "./dist/hono.d.ts",
29
+ "import": "./dist/hono.js",
30
+ "default": "./dist/hono.js"
31
+ },
32
+ "./sync": {
33
+ "types": "./dist/sync.d.ts",
34
+ "import": "./dist/sync.js",
35
+ "default": "./dist/sync.js"
36
+ },
37
+ "./invoice-ui": {
38
+ "types": "./dist/invoice-ui.d.ts",
39
+ "import": "./dist/invoice-ui.js",
40
+ "default": "./dist/invoice-ui.js"
41
+ },
42
+ "./settlement": {
43
+ "types": "./dist/settlement.d.ts",
44
+ "import": "./dist/settlement.js",
45
+ "default": "./dist/settlement.js"
46
+ },
47
+ "./workflows": {
48
+ "types": "./dist/workflows.d.ts",
49
+ "import": "./dist/workflows.js",
50
+ "default": "./dist/workflows.js"
51
+ },
52
+ "./types": {
53
+ "types": "./dist/types.d.ts",
54
+ "import": "./dist/types.js",
55
+ "default": "./dist/types.js"
56
+ }
57
+ },
58
+ "dependencies": {
59
+ "drizzle-orm": "^0.45.2",
60
+ "hono": "^4.12.10",
61
+ "zod": "^4.3.6",
62
+ "@voyant-travel/storage": "^0.104.1",
63
+ "@voyant-travel/utils": "^0.105.1",
64
+ "@voyant-travel/finance": "^0.119.5",
65
+ "@voyant-travel/hono": "^0.109.1",
66
+ "@voyant-travel/core": "^0.109.0"
67
+ },
68
+ "peerDependencies": {
69
+ "@tanstack/react-query": "^5.0.0",
70
+ "lucide-react": "^0.475.0",
71
+ "react": "^19.0.0",
72
+ "react-dom": "^19.0.0",
73
+ "@voyant-travel/finance-react": "^0.119.5",
74
+ "@voyant-travel/ui": "^0.106.1"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@tanstack/react-query": {
78
+ "optional": true
79
+ },
80
+ "@voyant-travel/finance-react": {
81
+ "optional": true
82
+ },
83
+ "@voyant-travel/ui": {
84
+ "optional": true
85
+ },
86
+ "lucide-react": {
87
+ "optional": true
88
+ },
89
+ "react": {
90
+ "optional": true
91
+ },
92
+ "react-dom": {
93
+ "optional": true
94
+ }
95
+ },
96
+ "devDependencies": {
97
+ "@tanstack/react-query": "^5.100.11",
98
+ "@types/react": "^19.2.14",
99
+ "@types/react-dom": "^19.2.3",
100
+ "lucide-react": "^0.475.0",
101
+ "react": "^19.2.4",
102
+ "react-dom": "^19.2.4",
103
+ "typescript": "^6.0.2",
104
+ "vitest": "^4.1.2",
105
+ "@voyant-travel/ui": "^0.106.1",
106
+ "@voyant-travel/voyant-typescript-config": "^0.1.0",
107
+ "@voyant-travel/finance-react": "^0.119.5"
108
+ },
109
+ "files": [
110
+ "dist"
111
+ ],
112
+ "publishConfig": {
113
+ "access": "public"
114
+ },
115
+ "repository": {
116
+ "type": "git",
117
+ "url": "https://github.com/voyant-travel/voyant.git",
118
+ "directory": "packages/plugins/smartbill"
119
+ },
120
+ "scripts": {
121
+ "typecheck": "tsc --noEmit",
122
+ "lint": "biome check src/",
123
+ "test": "vitest run",
124
+ "build": "pnpm run clean && tsc -p tsconfig.json",
125
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
126
+ },
127
+ "main": "./dist/index.js",
128
+ "types": "./dist/index.d.ts"
129
+ }