@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for, the acceptance of support, warranty, indemnity, or
168
+ other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 PixelMakers Studio SRL
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # @voyant-travel/plugin-smartbill
2
+
3
+ SmartBill e-invoicing sync adapter bundle for Voyant.
4
+
5
+ Architecturally, this package is primarily:
6
+
7
+ - a SmartBill e-invoicing adapter
8
+ - a subscriber bundle for finance invoice events
9
+ - an optional packaged bundle when an app wants one installable entrypoint
10
+
11
+ It subscribes to invoice events and creates, cancels, or syncs invoices via the
12
+ SmartBill REST API for Romanian tax compliance.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pnpm add @voyant-travel/plugin-smartbill
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```typescript
23
+ import { smartbillPlugin } from "@voyant-travel/plugin-smartbill"
24
+ import { createApp } from "@voyant-travel/hono"
25
+
26
+ const smartbillSync = smartbillPlugin({
27
+ username: env.SMARTBILL_USERNAME,
28
+ apiToken: env.SMARTBILL_API_TOKEN,
29
+ companyVatCode: "RO12345678",
30
+ seriesName: (event) => (event.channel === "online" ? "WEB" : "A"),
31
+ mentions: async (event) => `Booking ${event.bookingCode ?? event.id}`,
32
+ observations: "Generated by Voyant",
33
+ art311SpecialRegimeText: "Custom Art. 311 disclosure",
34
+ // optional: language, art311SpecialRegime, events, mapEvent, logger, onError
35
+ artifacts: {
36
+ db: appDb,
37
+ documentStorage,
38
+ },
39
+ })
40
+
41
+ const app = createApp({
42
+ plugins: [smartbillSync],
43
+ })
44
+ ```
45
+
46
+ `smartbillPlugin(...)` is the packaged distribution helper. At runtime, the
47
+ package behaves primarily as a subscriber-driven SmartBill sync adapter. By
48
+ default it wires up 4 subscribers (`invoice.issued`,
49
+ `invoice.proforma.issued`, `invoice.voided`,
50
+ `invoice.external.sync.requested`) that create, cancel, and check payment
51
+ status on SmartBill. All error handling is fire-and-forget per the EventBus
52
+ contract.
53
+
54
+ When `artifacts.db` is configured, successful invoice/proforma creation also
55
+ registers the SmartBill external reference through `@voyant-travel/finance`. When
56
+ `artifacts.documentStorage` is configured, the plugin downloads the generated
57
+ SmartBill PDF, uploads it to document storage, and records both a ready
58
+ `invoice_renditions` row and a `smartbill_pdf` `invoice_attachments` row. The
59
+ upload path defaults to `invoices/<invoiceId>/smartbill/...`; pass
60
+ `artifacts.documentStorageKeyPrefix` to customize it. Existing
61
+ `smartbill_pdf` attachments are reused so repeat event delivery does not upload
62
+ the same PDF again.
63
+
64
+ `seriesName`, `mentions`, and `observations` may be static strings or
65
+ event-specific callbacks. The packaged plugin awaits these callbacks in its
66
+ default mapper, so each invoice event can choose a SmartBill series or
67
+ compliance text based on document type, sales channel, or booking metadata.
68
+
69
+ When `artifacts.db` is configured, duplicate `invoice.issued` and
70
+ `invoice.proforma.issued` deliveries are idempotent by default: the plugin
71
+ checks for an existing non-error SmartBill external reference before creating a
72
+ new SmartBill document. Disable this with
73
+ `idempotency: { skipExistingExternalRef: false }` only when the caller owns
74
+ deduplication elsewhere. Create failures are recorded as SmartBill external refs
75
+ with `status: "error"` and `syncError`; `onError(event, error)` can be supplied
76
+ for application-specific reporting.
77
+
78
+ Use `syncSmartbillInvoice({ db, invoiceId, pluginOptions })` to run the same
79
+ create-or-retry flow from an admin action. It loads the finance invoice,
80
+ booking, line items, and tax metadata, maps them through the configured
81
+ SmartBill options, reuses an existing non-error SmartBill ref when present, and
82
+ persists external refs/PDF artifacts through the configured artifact runtime.
83
+
84
+ Apps that use `@voyant-travel/hono` can mount the packaged admin module:
85
+
86
+ ```typescript
87
+ import { createSmartbillAdminModule } from "@voyant-travel/plugin-smartbill/hono"
88
+
89
+ const app = createApp({
90
+ plugins: [smartbillSync],
91
+ modules: [
92
+ createSmartbillAdminModule({
93
+ pluginOptions: {
94
+ username: env.SMARTBILL_USERNAME,
95
+ apiToken: env.SMARTBILL_API_TOKEN,
96
+ companyVatCode: "RO12345678",
97
+ seriesName: "A",
98
+ artifacts: { documentStorage },
99
+ },
100
+ }),
101
+ ],
102
+ })
103
+ ```
104
+
105
+ The admin module mounts `POST /v1/admin/smartbill/invoices/:id/sync`. The route
106
+ uses the request database for external-ref and artifact persistence unless
107
+ `pluginOptions.artifacts.db` supplies a custom database resolver.
108
+
109
+ Use `retrySmartbillInvoiceArtifact({ runtime, client, externalRef, documentType
110
+ })` to re-download and re-attach a SmartBill PDF from an existing external ref
111
+ without issuing a new document.
112
+
113
+ ## Invoice UI
114
+
115
+ The optional `./invoice-ui` entry ships React helpers for invoice detail pages.
116
+ It reads SmartBill refs from `/v1/finance/invoices/:id/external-refs` using the
117
+ `@voyant-travel/finance-react` provider context and can be mounted in
118
+ `InvoiceDetailPage`'s integration slot.
119
+
120
+ ```tsx
121
+ import { InvoiceDetailPage } from "@voyant-travel/finance-react/ui"
122
+ import { SmartbillInvoicePanel } from "@voyant-travel/plugin-smartbill/invoice-ui"
123
+
124
+ export function InvoicePage({ invoiceId }: { invoiceId: string }) {
125
+ return (
126
+ <InvoiceDetailPage
127
+ id={invoiceId}
128
+ slots={{
129
+ integrationsContent: ({ invoice }) => (
130
+ <SmartbillInvoicePanel invoiceId={invoice.id} />
131
+ ),
132
+ }}
133
+ />
134
+ )
135
+ }
136
+ ```
137
+
138
+ `SmartbillInvoicePanel` displays the SmartBill series, number, document type,
139
+ sync status, sync errors, and document/PDF links when the external ref contains
140
+ them. By default, send and retry actions call
141
+ `POST /v1/admin/smartbill/invoices/:id/sync`, and proforma conversion calls the
142
+ finance `POST /v1/finance/invoices/:id/convert-to-invoice` endpoint. Pass
143
+ `sendAction`, `retryAction`, or `convertProformaAction` to override those
144
+ defaults. For custom layouts, use `useSmartbillInvoiceRef(invoiceId)` together with
145
+ `resolveSmartbillInvoiceReferenceParts(ref)` and
146
+ `getSmartbillInvoiceDocumentLinks(ref)`.
147
+
148
+ ## Workflow Factories
149
+
150
+ The package also ships scheduler-agnostic workflow factories for recurring
151
+ SmartBill maintenance. They return async functions that can be called from
152
+ `@voyant-travel/workflows`, a Cloudflare cron handler, Trigger.dev, Hatchet, or any
153
+ other job runner.
154
+
155
+ ```typescript
156
+ import {
157
+ createSmartbillDriftReconciler,
158
+ createSmartbillProformaConversionPoller,
159
+ } from "@voyant-travel/plugin-smartbill"
160
+
161
+ const pollProformas = createSmartbillProformaConversionPoller({
162
+ db,
163
+ client: smartbillClient,
164
+ source: "invoices",
165
+ requestSpacingMs: 350,
166
+ onConverted: async (proformaRef, conversion) => {
167
+ // Record a Voyant payment or emit a domain event in the host app.
168
+ // The plugin reports the SmartBill invoice series/number and source
169
+ // proforma ref, but leaves payment semantics to the consumer.
170
+ },
171
+ })
172
+
173
+ const reconcileSmartbill = createSmartbillDriftReconciler({
174
+ db,
175
+ client: smartbillClient,
176
+ source: "invoices",
177
+ discoverRemote: true,
178
+ requestSpacingMs: 350,
179
+ onFinding: async (finding) => {
180
+ // Log, alert, or open an operator ticket.
181
+ },
182
+ onMissingLocal: async (finding) => {
183
+ const pdf = await finding.remote.accessors?.viewPdf()
184
+ // Create a local invoice or attach SmartBill evidence in the host app.
185
+ },
186
+ })
187
+ ```
188
+
189
+ `createSmartbillProformaConversionPoller` scans SmartBill proforma external refs
190
+ and calls `client.listEstimateInvoices(...)` to detect SmartBill-created final
191
+ invoices. `createSmartbillDriftReconciler` verifies known SmartBill refs by
192
+ default. Pass `discoverRemote: true` to walk SmartBill invoice/proforma series
193
+ with `client.listSeries()` and report documents that exist remotely without a
194
+ local external ref as `missing_local`; those findings include lazy PDF and
195
+ payment-status/conversion lookup accessors on `finding.remote.accessors`.
196
+ Both workflow factories use `invoice_external_refs` by default. Pass
197
+ `source: "invoices"` to derive candidates from finance invoice rows instead, or
198
+ pass `listCandidateInvoices` for a custom invoice-table/source query. Candidate
199
+ refs are materialized as SmartBill external refs when `db` is available; custom
200
+ sources can override that writeback with `recordCandidateExternalRef`. Consumers
201
+ can still pass `listRemoteDocuments` to provide their own remote inventory. The
202
+ reconciler only reports drift; it does not delete, void, or create finance
203
+ records. Pass `requestSpacingMs` to either factory to enforce a minimum interval
204
+ between SmartBill requests made by the workflow, including remote discovery and
205
+ lazy remote-document accessors returned by discovery.
206
+
207
+ ## Exports
208
+
209
+ | Entry | Description |
210
+ | --- | --- |
211
+ | `.` | Barrel re-exports |
212
+ | `./plugin` | `smartbillPlugin(options)` — packaged adapter/subscriber bundle |
213
+ | `./client` | `createSmartbillClient` — `createInvoice`, `cancelInvoice`, `viewPdf`, `getPaymentStatus`, etc. |
214
+ | `./hono` | `createSmartbillAdminModule(options)` and admin sync routes |
215
+ | `./sync` | `syncSmartbillInvoice(...)` and event-level sync helpers |
216
+ | `./invoice-ui` | Optional React hooks, display helpers, and `SmartbillInvoicePanel` for invoice detail integrations |
217
+ | `./mock` | `createSmartbillMockServer` — stateful local SmartBill-compatible mock for tests |
218
+ | `./workflows` | Proforma conversion polling and drift reconciliation factories |
219
+ | `./types` | SmartBill adapter and bundle types |
220
+
221
+ ## Rate limits
222
+
223
+ SmartBill can block an account after bursty traffic. `createSmartbillClient`
224
+ throws `SmartbillRateLimitError` when a response carries SmartBill's
225
+ rate-limit shape, with `retryAfterMs`, `retryAfterAt`, and `blockedAt` when the
226
+ response text contains enough timing data.
227
+
228
+ For cron or batch pollers, enable the process-local circuit breaker so repeated
229
+ calls do not keep hitting SmartBill while the account is blocked:
230
+
231
+ ```typescript
232
+ import {
233
+ createSmartbillClient,
234
+ SmartbillRateLimitCircuitOpenError,
235
+ SmartbillRateLimitError,
236
+ } from "@voyant-travel/plugin-smartbill/client"
237
+
238
+ const client = createSmartbillClient({
239
+ username,
240
+ apiToken,
241
+ rateLimit: {
242
+ circuitBreaker: true,
243
+ },
244
+ })
245
+
246
+ try {
247
+ await client.listEstimateInvoices(companyVatCode, seriesName, number)
248
+ } catch (err) {
249
+ if (
250
+ err instanceof SmartbillRateLimitError ||
251
+ err instanceof SmartbillRateLimitCircuitOpenError
252
+ ) {
253
+ // Stop the batch and retry after `err.retryAfterMs`.
254
+ }
255
+ }
256
+ ```
257
+
258
+ Workflow factories also stop the current run after `SmartbillRateLimitError` or
259
+ `SmartbillRateLimitCircuitOpenError`, returning results processed before the
260
+ limit was reached and recording the rate-limit failure through `onError`.
261
+
262
+ ## Local SmartBill Mock
263
+
264
+ SmartBill does not provide a practical sandbox, and invoice/proforma calls can
265
+ create real accounting documents. Use the packaged mock for local workflows and
266
+ end-to-end tests instead of pointing development credentials at the live API.
267
+
268
+ For in-process tests, pass the mock `fetch` implementation and any local
269
+ `apiUrl`:
270
+
271
+ ```typescript
272
+ import { createSmartbillClient } from "@voyant-travel/plugin-smartbill/client"
273
+ import { createSmartbillMockServer } from "@voyant-travel/plugin-smartbill/mock"
274
+
275
+ const smartbill = createSmartbillMockServer()
276
+ const client = createSmartbillClient({
277
+ username: "local",
278
+ apiToken: "local",
279
+ apiUrl: "http://smartbill.local/SBORO/api",
280
+ fetch: smartbill.fetch,
281
+ })
282
+ ```
283
+
284
+ For full app tests, start the local HTTP listener and wire the plugin/client to
285
+ the returned base URL:
286
+
287
+ ```typescript
288
+ const smartbill = createSmartbillMockServer()
289
+ const server = await smartbill.listen({ port: 4555 })
290
+
291
+ const plugin = smartbillPlugin({
292
+ username: "local",
293
+ apiToken: "local",
294
+ apiUrl: server.apiUrl,
295
+ companyVatCode: "RO12345678",
296
+ seriesName: "SB-TEST",
297
+ })
298
+
299
+ await server.close()
300
+ ```
301
+
302
+ The mock supports the SmartBill endpoints used by the plugin and common local
303
+ billing flows:
304
+
305
+ - `GET /tax`
306
+ - `GET /series`
307
+ - `POST /invoice`
308
+ - `GET /invoice/pdf`
309
+ - `GET /invoice/paymentstatus`
310
+ - `PUT /invoice/cancel`
311
+ - `PUT /invoice/reverse`
312
+ - `PUT /invoice/restore`
313
+ - `DELETE /invoice`
314
+ - `POST /estimate`
315
+ - `GET /estimate/pdf`
316
+ - `GET /estimate/invoices`
317
+
318
+ Documents are stateful and deterministic per series. Generated PDF URLs use the
319
+ `smartbill-mock://test-document/...` scheme, and stored document mentions are
320
+ marked with `TEST DOCUMENT - SmartBill local mock`.
321
+
322
+ ## License
323
+
324
+ Apache-2.0
@@ -0,0 +1,80 @@
1
+ import { financeService, type InvoiceExternalRef } from "@voyant-travel/finance";
2
+ import type { StorageProvider } from "@voyant-travel/storage";
3
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
4
+ import type { SmartbillClientApi } from "./client.js";
5
+ import type { SmartbillInvoiceBody, SmartbillInvoiceResponse, VoyantInvoiceEvent } from "./types.js";
6
+ export type SmartbillDocumentType = "invoice" | "proforma";
7
+ export interface SmartbillArtifactStorageContext {
8
+ event: VoyantInvoiceEvent;
9
+ documentType: SmartbillDocumentType;
10
+ body: SmartbillInvoiceBody;
11
+ result: SmartbillInvoiceResponse;
12
+ }
13
+ export type SmartbillDbResolver = PostgresJsDatabase | ((context: SmartbillArtifactStorageContext) => PostgresJsDatabase | null | Promise<PostgresJsDatabase | null>);
14
+ export type SmartbillDocumentStorageResolver = StorageProvider | null | ((context: SmartbillArtifactStorageContext) => StorageProvider | null | Promise<StorageProvider | null>);
15
+ export type SmartbillStorageKeyPrefixResolver = string | ((context: SmartbillArtifactStorageContext) => string | Promise<string>);
16
+ export interface SmartbillArtifactPersistenceOptions {
17
+ db?: SmartbillDbResolver;
18
+ documentStorage?: SmartbillDocumentStorageResolver;
19
+ documentStorageKeyPrefix?: SmartbillStorageKeyPrefixResolver;
20
+ }
21
+ export interface SmartbillArtifactPersistenceRuntime {
22
+ db?: SmartbillDbResolver;
23
+ documentStorage?: SmartbillDocumentStorageResolver;
24
+ documentStorageKeyPrefix?: SmartbillStorageKeyPrefixResolver;
25
+ }
26
+ export interface PersistSmartbillInvoiceArtifactInput {
27
+ runtime: SmartbillArtifactPersistenceRuntime;
28
+ client: SmartbillClientApi;
29
+ event: VoyantInvoiceEvent;
30
+ documentType: SmartbillDocumentType;
31
+ body: SmartbillInvoiceBody;
32
+ result: SmartbillInvoiceResponse;
33
+ }
34
+ export interface RecordSmartbillInvoiceArtifactFailureInput {
35
+ runtime: SmartbillArtifactPersistenceRuntime;
36
+ event: VoyantInvoiceEvent;
37
+ documentType: SmartbillDocumentType;
38
+ body: SmartbillInvoiceBody;
39
+ result: SmartbillInvoiceResponse;
40
+ error: unknown;
41
+ }
42
+ export type SmartbillExternalRef = Pick<InvoiceExternalRef, "id" | "invoiceId" | "externalId" | "externalNumber" | "externalUrl" | "metadata">;
43
+ export interface RetrySmartbillInvoiceArtifactInput {
44
+ runtime: SmartbillArtifactPersistenceRuntime;
45
+ client: SmartbillClientApi;
46
+ externalRef: SmartbillExternalRef;
47
+ documentType: SmartbillDocumentType;
48
+ }
49
+ type InvoiceAttachmentRecord = Awaited<ReturnType<typeof financeService.createInvoiceAttachment>>;
50
+ type InvoiceRenditionRecord = Awaited<ReturnType<typeof financeService.createInvoiceRendition>>;
51
+ export type SmartbillPdfPersistStage = "attachment_lookup" | "viewInvoicePdf" | "viewEstimatePdf" | "storage_upload" | "rendition_insert" | "attachment_insert" | "unknown";
52
+ export declare class SmartbillPdfPersistError extends Error {
53
+ readonly stage: SmartbillPdfPersistStage;
54
+ readonly originalError: unknown;
55
+ constructor(stage: SmartbillPdfPersistStage, error: unknown);
56
+ }
57
+ export declare class SmartbillPdfPersistMetadataUpdateError extends Error {
58
+ readonly originalError: unknown;
59
+ constructor(error: unknown);
60
+ }
61
+ export declare function isSmartbillPdfPersistMetadataUpdateError(error: unknown): error is SmartbillPdfPersistMetadataUpdateError;
62
+ export type SmartbillArtifactPersistenceResult = {
63
+ status: "skipped";
64
+ reason: "missing_db" | "missing_invoice" | "missing_document_storage" | "missing_smartbill_reference";
65
+ } | {
66
+ status: "registered_ref";
67
+ reason?: "missing_number";
68
+ } | {
69
+ status: "already_exists";
70
+ attachment: InvoiceAttachmentRecord;
71
+ } | {
72
+ status: "persisted";
73
+ rendition: InvoiceRenditionRecord;
74
+ attachment: InvoiceAttachmentRecord;
75
+ };
76
+ export declare function persistSmartbillInvoiceArtifact({ runtime, client, event, documentType, body, result, }: PersistSmartbillInvoiceArtifactInput): Promise<SmartbillArtifactPersistenceResult>;
77
+ export declare function recordSmartbillInvoiceArtifactFailure({ runtime, event, documentType, body, result, error, }: RecordSmartbillInvoiceArtifactFailureInput): Promise<SmartbillArtifactPersistenceResult>;
78
+ export declare function retrySmartbillInvoiceArtifact({ runtime, client, externalRef, documentType, }: RetrySmartbillInvoiceArtifactInput): Promise<SmartbillArtifactPersistenceResult>;
79
+ export {};
80
+ //# sourceMappingURL=artifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../src/artifacts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpG,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,UAAU,CAAA;AAE1D,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,kBAAkB,CAAA;IACzB,YAAY,EAAE,qBAAqB,CAAA;IACnC,IAAI,EAAE,oBAAoB,CAAA;IAC1B,MAAM,EAAE,wBAAwB,CAAA;CACjC;AAED,MAAM,MA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