mcp-server-acube 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cipay Srl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,422 @@
1
+ # mcp-server-acube
2
+
3
+ [![npm version](https://img.shields.io/npm/v/mcp-server-acube.svg)](https://www.npmjs.com/package/mcp-server-acube)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![MCP](https://img.shields.io/badge/MCP-compatible-blue.svg)](https://modelcontextprotocol.io)
6
+
7
+ A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that provides **38 tools** for interacting with the [A-Cube API](https://www.acubeapi.com/) -- the Italian electronic invoicing platform for SDI (Sistema di Interscambio), FatturaPA, smart receipts, company verification, and more.
8
+
9
+ Connect this server to Claude Desktop, Claude Code, or any MCP-compatible client to manage Italian electronic invoicing through natural language.
10
+
11
+ ## Features
12
+
13
+ - **Electronic Invoicing** -- Send, list, and retrieve FatturaPA invoices via SDI, with support for JSON, XML, PDF, and HTML formats
14
+ - **AI-Powered PDF Extraction** -- Convert PDF invoices to FatturaPA format using A-Cube's AI extraction pipeline
15
+ - **Smart Receipts** -- Issue, void, and manage electronic receipts (scontrini elettronici)
16
+ - **Company Verification** -- Look up Italian companies by P.IVA or codice fiscale, verify fiscal IDs, and check split payment status
17
+ - **SDI Notifications** -- Monitor delivery receipts, rejections, and all other SDI notification types
18
+ - **Cassetto Fiscale** -- Schedule recurring or one-time bulk downloads from the Agenzia delle Entrate tax drawer
19
+ - **Webhooks** -- Configure real-time event callbacks for 13 different event types
20
+ - **Business Registry & ADE Appointees** -- Manage company profiles and fiscal intermediary configurations
21
+ - **Token-Optimized Responses** -- Compact JSON output with null stripping and field selection to minimize LLM token consumption
22
+ - **Automatic Authentication** -- JWT token management with automatic refresh (24h token lifetime)
23
+ - **Sandbox & Production** -- Seamlessly switch between A-Cube sandbox and production environments
24
+
25
+ ## Quick Start
26
+
27
+ ### Prerequisites
28
+
29
+ You need an [A-Cube API](https://www.acubeapi.com/) account. Sign up at [acubeapi.com](https://www.acubeapi.com/) to get your credentials.
30
+
31
+ ### Claude Desktop
32
+
33
+ Add the following to your Claude Desktop configuration file (`claude_desktop_config.json`):
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "acube": {
39
+ "command": "npx",
40
+ "args": ["-y", "mcp-server-acube"],
41
+ "env": {
42
+ "ACUBE_EMAIL": "your-email@example.com",
43
+ "ACUBE_PASSWORD": "your-password",
44
+ "ACUBE_ENVIRONMENT": "sandbox"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### Claude Code
52
+
53
+ ```bash
54
+ claude mcp add acube -- npx -y mcp-server-acube \
55
+ -e ACUBE_EMAIL=your-email@example.com \
56
+ -e ACUBE_PASSWORD=your-password \
57
+ -e ACUBE_ENVIRONMENT=sandbox
58
+ ```
59
+
60
+ Or add it manually to `.mcp.json` in your project root:
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "acube": {
66
+ "command": "npx",
67
+ "args": ["-y", "mcp-server-acube"],
68
+ "env": {
69
+ "ACUBE_EMAIL": "your-email@example.com",
70
+ "ACUBE_PASSWORD": "your-password",
71
+ "ACUBE_ENVIRONMENT": "sandbox"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ The server is configured through environment variables:
81
+
82
+ | Variable | Required | Default | Description |
83
+ |---|---|---|---|
84
+ | `ACUBE_EMAIL` | Yes | -- | Your A-Cube account email |
85
+ | `ACUBE_PASSWORD` | Yes | -- | Your A-Cube account password |
86
+ | `ACUBE_ENVIRONMENT` | No | `sandbox` | API environment: `sandbox` or `production` |
87
+
88
+ ## Available Tools
89
+
90
+ ### Invoices (4 tools)
91
+
92
+ | Tool | Description |
93
+ |---|---|
94
+ | `send_invoice` | Send a FatturaPA electronic invoice to SDI. Accepts the complete FatturaPA JSON object. Returns the UUID assigned by SDI (HTTP 202). Supports optional digital signing. |
95
+ | `send_simplified_invoice` | Send a simplified FatturaPA invoice (fattura semplificata) for amounts up to 400 EUR. |
96
+ | `list_invoices` | List and filter invoices with 20+ filters (sender/recipient name, VAT, status, date ranges, etc.). Returns a **compact default view** -- see [Response Optimization](#response-optimization). |
97
+ | `get_invoice` | Retrieve a specific invoice by UUID. Output formats: JSON, XML (FatturaPA), PDF (base64), or HTML. Supports field selection. |
98
+
99
+ ### Invoice Extraction (3 tools)
100
+
101
+ | Tool | Description |
102
+ |---|---|
103
+ | `extract_invoice_from_pdf` | Upload a PDF invoice (base64-encoded) for AI-powered conversion to FatturaPA format. Returns a job UUID. |
104
+ | `get_extraction_status` | Poll the status of a PDF extraction job by UUID. |
105
+ | `get_extraction_result` | Retrieve the converted FatturaPA invoice from a completed extraction job. Available in JSON or XML format. |
106
+
107
+ ### Notifications (3 tools)
108
+
109
+ | Tool | Description |
110
+ |---|---|
111
+ | `list_notifications` | List SDI notifications with filtering by type (NS, MT, RC, MC, EC, SE, NE, DT, AT) and download status. |
112
+ | `get_notification` | Get a specific SDI notification by UUID in JSON or original XML format. |
113
+ | `mark_notifications_downloaded` | Mark one or more notifications as downloaded by providing their UUIDs. |
114
+
115
+ ### Verification (4 tools)
116
+
117
+ | Tool | Description |
118
+ |---|---|
119
+ | `verify_fiscal_id` | Validate an Italian codice fiscale or P.IVA against the Agenzia delle Entrate. |
120
+ | `verify_company` | Full company lookup by P.IVA or codice fiscale. Returns name, PEC, SDI code, address, ATECO code, shareholders, and more. |
121
+ | `verify_simple_company` | Basic company info lookup -- a lightweight alternative to `verify_company`. |
122
+ | `verify_split_payment` | Check if a company has split payment (scissione dei pagamenti) status for public administration invoicing. |
123
+
124
+ ### Smart Receipts (4 tools)
125
+
126
+ | Tool | Description |
127
+ |---|---|
128
+ | `send_receipt` | Issue an electronic receipt (scontrino elettronico) with items, payment amounts, and fiscal ID. |
129
+ | `get_receipt_details` | Get receipt transaction details including document number. |
130
+ | `void_receipt` | Void/cancel an electronic receipt (annullamento). |
131
+ | `return_receipt_items` | Process item returns against an existing receipt. |
132
+
133
+ ### Webhooks (5 tools)
134
+
135
+ | Tool | Description |
136
+ |---|---|
137
+ | `list_webhook_configs` | List all webhook configurations. |
138
+ | `create_webhook_config` | Subscribe to events by specifying an event type and target URL. Supports 13 event types including supplier-invoice, customer-invoice, receipt, and more. |
139
+ | `get_webhook_config` | Get a specific webhook configuration by ID. |
140
+ | `update_webhook_config` | Update webhook settings (event type, URL, authentication). |
141
+ | `delete_webhook_config` | Remove a webhook configuration. |
142
+
143
+ ### Business Registry & ADE Appointees (8 tools)
144
+
145
+ | Tool | Description |
146
+ |---|---|
147
+ | `list_business_registries` | List all business registry configurations (anagrafiche aziendali). |
148
+ | `create_business_registry` | Create a new company profile for electronic invoicing, including fiscal ID, signature, and legal storage settings. |
149
+ | `get_business_registry` | Get a specific business registry configuration by ID. |
150
+ | `update_business_registry` | Update an existing company profile. |
151
+ | `list_appointees` | List all ADE tax appointees (intermediari fiscali). |
152
+ | `create_appointee` | Register a new fiscal intermediary authorized to operate with the Agenzia delle Entrate. |
153
+ | `get_appointee` | Get a specific ADE appointee by ID. |
154
+ | `update_appointee` | Update an existing fiscal intermediary. |
155
+
156
+ ### Cassetto Fiscale & Rejected Invoices (7 tools)
157
+
158
+ | Tool | Description |
159
+ |---|---|
160
+ | `schedule_invoice_download` | Set up recurring daily invoice downloads from the Cassetto Fiscale (tax drawer) at 03:00 UTC. |
161
+ | `get_download_schedule` | Check the status of an invoice download schedule (active, auto-renewal, last execution). |
162
+ | `update_download_schedule` | Modify download schedule options. |
163
+ | `delete_download_schedule` | Stop recurring invoice downloads. |
164
+ | `download_invoices_once` | Trigger a one-time bulk invoice download by date range from the Agenzia delle Entrate. |
165
+ | `count_rejected_invoices` | Count invoices that were rejected during Cassetto Fiscale processing. |
166
+ | `recover_rejected_invoices` | Reprocess previously rejected invoices for a given fiscal ID and date range. |
167
+
168
+ ## Response Optimization
169
+
170
+ This server is designed to minimize LLM token consumption. Every response goes through three optimizations:
171
+
172
+ ### 1. Null stripping
173
+
174
+ All `null` and `undefined` values are recursively removed from responses. A typical invoice `sender` object has ~40 fields, of which ~30 are null. After stripping, only the 5--8 populated fields remain.
175
+
176
+ ### 2. Compact JSON
177
+
178
+ Responses are serialized without indentation (`JSON.stringify(data)` instead of `JSON.stringify(data, null, 2)`). This eliminates whitespace tokens that provide no information to the LLM.
179
+
180
+ ### 3. Default field selection on `list_invoices`
181
+
182
+ The `list_invoices` tool returns a **compact default view** instead of the full A-Cube response. The raw API response includes the entire FatturaPA payload (~2000 tokens per invoice) and full sender/recipient objects. The compact view extracts only the essential fields:
183
+
184
+ | Default field | Description |
185
+ |---|---|
186
+ | `uuid` | Invoice UUID |
187
+ | `created_at` | Creation timestamp on A-Cube |
188
+ | `document_type` | FatturaPA type code (TD01, TD04, etc.) |
189
+ | `marking` | SDI status (delivered, rejected, sent, etc.) |
190
+ | `notice` | Error message from SDI (if rejected) |
191
+ | `invoice_number` | Invoice number (extracted from payload) |
192
+ | `invoice_date` | Invoice date (extracted from payload) |
193
+ | `total_amount` | Total document amount (extracted from payload) |
194
+ | `currency` | Currency code (extracted from payload) |
195
+ | `sender.business_name` | Sender company name |
196
+ | `sender.business_vat_number_code` | Sender P.IVA |
197
+ | `recipient.business_name` | Recipient company name |
198
+ | `recipient.business_vat_number_code` | Recipient P.IVA |
199
+ | `notifications` | Array of SDI notifications (type + date) |
200
+
201
+ The `invoice_number`, `invoice_date`, `total_amount`, and `currency` fields are **computed** by parsing the FatturaPA payload JSON on the server side, so they're available without transferring the entire payload.
202
+
203
+ ### Using the `fields` parameter
204
+
205
+ Both `list_invoices` and `get_invoice` accept an optional `fields` parameter to control which fields are returned:
206
+
207
+ ```
208
+ # Default compact view (no fields parameter needed)
209
+ list_invoices(marking: "rejected")
210
+
211
+ # Request specific fields
212
+ list_invoices(marking: "rejected", fields: ["uuid", "notice", "recipient.business_name"])
213
+
214
+ # Request all fields (full A-Cube response, nulls still stripped)
215
+ list_invoices(marking: "rejected", fields: ["*"])
216
+
217
+ # Get specific fields from a single invoice
218
+ get_invoice(uuid: "...", fields: ["payload", "sender", "recipient"])
219
+ ```
220
+
221
+ The `fields` parameter supports **dot-notation** for nested objects (e.g., `sender.business_name`).
222
+
223
+ ### Estimated token savings
224
+
225
+ For a typical `list_invoices` call returning 10 invoices:
226
+
227
+ | Metric | Without optimization | With optimization |
228
+ |---|---|---|
229
+ | Null fields per invoice | ~60 | 0 |
230
+ | Payload per invoice | ~2000 tokens | 0 (excluded) |
231
+ | JSON whitespace | ~500 tokens | 0 |
232
+ | **Total** | **~25,000 tokens** | **~1,500 tokens** |
233
+
234
+ ## Usage Examples
235
+
236
+ Once the server is connected, you can ask Claude things like:
237
+
238
+ ### Invoicing
239
+ > "Send this invoice to SDI for customer ACME Srl with P.IVA 01234567890"
240
+ >
241
+ > "List all my invoices from January 2025 that were rejected"
242
+ >
243
+ > "Show me invoice abc-123-def in XML format"
244
+
245
+ ### PDF Extraction
246
+ > "Convert this PDF invoice to FatturaPA format"
247
+ >
248
+ > "Check if my PDF extraction job is done yet"
249
+
250
+ ### Company Verification
251
+ > "Look up the company with P.IVA 01234567890 -- I need their PEC and SDI code"
252
+ >
253
+ > "Is this codice fiscale valid: RSSMRA85M01H501Z?"
254
+ >
255
+ > "Does this company use split payment?"
256
+
257
+ ### Smart Receipts
258
+ > "Issue an electronic receipt for 3 items totaling 45.50 EUR paid by card"
259
+ >
260
+ > "Void receipt number 12345"
261
+
262
+ ### Notifications
263
+ > "Show me all undownloaded SDI notifications"
264
+ >
265
+ > "Are there any rejected notifications (NS type) from last week?"
266
+
267
+ ### Cassetto Fiscale
268
+ > "Set up daily invoice downloads for fiscal ID 01234567890"
269
+ >
270
+ > "Download all invoices from Q1 2025 for my company"
271
+ >
272
+ > "How many rejected invoices do I have?"
273
+
274
+ ### Configuration
275
+ > "List all my webhook configurations"
276
+ >
277
+ > "Set up a webhook for new supplier invoices pointing to https://my-app.com/webhooks/acube"
278
+ >
279
+ > "Show me all my business registry profiles"
280
+
281
+ ## Development
282
+
283
+ ### Setup
284
+
285
+ ```bash
286
+ git clone https://github.com/nick-preda/mcp-server-acube.git
287
+ cd mcp-server-acube
288
+ npm install
289
+ ```
290
+
291
+ ### Build
292
+
293
+ ```bash
294
+ npm run build
295
+ ```
296
+
297
+ ### Run in development mode
298
+
299
+ ```bash
300
+ ACUBE_EMAIL=you@example.com ACUBE_PASSWORD=secret npm run dev
301
+ ```
302
+
303
+ ### Test
304
+
305
+ ```bash
306
+ npm test
307
+ npm run test:watch # watch mode
308
+ ```
309
+
310
+ ### Project Structure
311
+
312
+ ```
313
+ src/
314
+ index.ts # MCP server entry point, env validation, tool registration
315
+ client.ts # A-Cube HTTP client with JWT authentication
316
+ response.ts # Response utilities: field picking, null stripping, formatting
317
+ tools/
318
+ invoices.ts # send_invoice, send_simplified_invoice, list_invoices, get_invoice
319
+ invoice-extract.ts # extract_invoice_from_pdf, get_extraction_status, get_extraction_result
320
+ notifications.ts # list_notifications, get_notification, mark_notifications_downloaded
321
+ verify.ts # verify_fiscal_id, verify_company, verify_simple_company, verify_split_payment
322
+ receipts.ts # send_receipt, get_receipt_details, void_receipt, return_receipt_items
323
+ webhooks.ts # list/create/get/update/delete_webhook_config
324
+ configurations.ts # business registries + ADE appointees (list/create/get/update)
325
+ cassetto-fiscale.ts # download schedules, one-time downloads, rejected invoices
326
+ tests/
327
+ client.test.ts # API client tests
328
+ tools/ # Tool-specific tests
329
+ ```
330
+
331
+ ## Reference
332
+
333
+ ### A-Cube API Environments
334
+
335
+ | Environment | Base URL (Gov.it) | Base URL (Common) | Purpose |
336
+ |---|---|---|---|
337
+ | `sandbox` | `https://api-sandbox.acubeapi.com` | `https://common-sandbox.api.acubeapi.com` | Testing and development |
338
+ | `production` | `https://api.acubeapi.com` | `https://common.api.acubeapi.com` | Live invoicing via SDI |
339
+
340
+ The sandbox environment is used by default. Set `ACUBE_ENVIRONMENT=production` only when you are ready to send real invoices through SDI.
341
+
342
+ ### FatturaPA Document Types
343
+
344
+ | Code | Description |
345
+ |---|---|
346
+ | `TD01` | Fattura (invoice) |
347
+ | `TD04` | Nota di credito (credit note) |
348
+ | `TD05` | Nota di debito (debit note) |
349
+ | `TD06` | Parcella (professional fee) |
350
+ | `TD07` | Fattura semplificata (simplified invoice) |
351
+ | `TD08` | Nota di credito semplificata |
352
+ | `TD09` | Nota di debito semplificata |
353
+ | `TD16` | Integrazione fattura reverse charge interno |
354
+ | `TD17` | Integrazione/autofattura acquisto servizi estero |
355
+ | `TD18` | Integrazione acquisto beni intracomunitari |
356
+ | `TD19` | Integrazione/autofattura acquisto beni art. 17 c.2 |
357
+ | `TD20` | Autofattura/regolarizzazione |
358
+ | `TD24` | Fattura differita (art. 21 c.4 lett. a) |
359
+ | `TD25` | Fattura differita (art. 21 c.4 terzo periodo lett. b) |
360
+ | `TD26` | Cessione beni ammortizzabili / passaggi interni |
361
+ | `TD27` | Fattura autoconsumo / cessioni gratuite senza rivalsa |
362
+
363
+ ### SDI Notification Types
364
+
365
+ | Code | Name | Description |
366
+ |---|---|---|
367
+ | `NS` | Notifica di Scarto | Invoice rejected by SDI due to validation errors |
368
+ | `MT` | Metadati | Metadata file from SDI |
369
+ | `RC` | Ricevuta di Consegna | Delivery receipt -- invoice successfully delivered to the recipient |
370
+ | `MC` | Mancata Consegna | Non-delivery notification -- recipient's SDI channel unreachable |
371
+ | `EC` | Esito Committente | Recipient outcome (accepted/refused by the recipient) |
372
+ | `SE` | Scarto Esito | Outcome rejection by SDI |
373
+ | `NE` | Notifica Esito | Outcome notification |
374
+ | `DT` | Decorrenza Termini | Deadline passed -- 15 days without response, invoice considered accepted |
375
+ | `AT` | Attestazione di Trasmissione | Transmission attestation |
376
+
377
+ ### SDI Invoice Statuses (marking)
378
+
379
+ | Status | Description |
380
+ |---|---|
381
+ | `waiting` | Invoice queued for submission to SDI |
382
+ | `quarantena` | Invoice held in quarantine for review |
383
+ | `sent` | Invoice submitted to SDI, awaiting notification |
384
+ | `invoice-error` | Invoice processing error |
385
+ | `received` | Incoming invoice received from SDI |
386
+ | `rejected` | Invoice rejected by SDI (NS notification) |
387
+ | `delivered` | Invoice delivered to recipient (RC notification) |
388
+ | `not-delivered` | Invoice could not be delivered (MC notification) |
389
+
390
+ ### Webhook Event Types
391
+
392
+ The following events can be subscribed to via `create_webhook_config`:
393
+
394
+ | Event | Description |
395
+ |---|---|
396
+ | `supplier-invoice` | New supplier invoice received via SDI |
397
+ | `customer-invoice` | Customer invoice sent via SDI |
398
+ | `customer-notification` | SDI notification received for a customer invoice |
399
+ | `invoice-status-quarantena` | Invoice entered quarantine status |
400
+ | `invoice-status-invoice-error` | Invoice processing error |
401
+ | `legal-storage-missing-vat` | Legal storage: missing VAT number |
402
+ | `legal-storage-receipt` | Legal storage receipt generated |
403
+ | `receipt` | Electronic receipt processed |
404
+ | `receipt-retry` | Electronic receipt retry |
405
+ | `receipt-error` | Electronic receipt error |
406
+ | `appointee` | ADE appointee event |
407
+ | `sistemats-receipt-ready` | SistemaTS receipt ready |
408
+ | `job` | Asynchronous job completed |
409
+
410
+ ## Links
411
+
412
+ - [A-Cube API Documentation](https://docs.acubeapi.com/)
413
+ - [A-Cube Website](https://www.acubeapi.com/)
414
+ - [Model Context Protocol (MCP)](https://modelcontextprotocol.io)
415
+ - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
416
+ - [Report Issues](https://github.com/nick-preda/mcp-server-acube/issues)
417
+
418
+ ## License
419
+
420
+ MIT -- see [LICENSE](./LICENSE) for details.
421
+
422
+ Copyright (c) 2026 [Cipay Srl](https://www.cipay.it)
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @module client
3
+ *
4
+ * HTTP client for the A-Cube API with automatic JWT authentication.
5
+ *
6
+ * The client handles:
7
+ * - Login via email/password and JWT token caching (24h lifetime, 23h refresh).
8
+ * - Automatic token injection on every request.
9
+ * - Content negotiation: JSON, XML, PDF (base64), HTML.
10
+ * - Two base URLs per environment: `common` (authentication) and `govIt` (API operations).
11
+ * - Error handling with clear messages including HTTP status codes.
12
+ *
13
+ * @see https://docs.acubeapi.com/
14
+ */
15
+ /** A-Cube API environment: sandbox for testing, production for live SDI operations. */
16
+ export type AcubeEnvironment = "production" | "sandbox";
17
+ interface AcubeConfig {
18
+ email: string;
19
+ password: string;
20
+ environment: AcubeEnvironment;
21
+ }
22
+ /**
23
+ * A-Cube API client with automatic JWT authentication.
24
+ *
25
+ * Usage:
26
+ * ```ts
27
+ * const client = new AcubeClient({ email: "...", password: "...", environment: "sandbox" });
28
+ * const invoices = await client.get("/invoices?page=1");
29
+ * ```
30
+ *
31
+ * The client automatically handles login and token refresh. The JWT token is
32
+ * cached for 23 hours (1h safety buffer before the actual 24h expiry).
33
+ */
34
+ export declare class AcubeClient {
35
+ private config;
36
+ private token;
37
+ private tokenExpiresAt;
38
+ constructor(config: AcubeConfig);
39
+ /** Returns the base URL for the given service in the configured environment. */
40
+ getBaseUrl(service: "common" | "govIt"): string;
41
+ /**
42
+ * Authenticate with A-Cube and cache the JWT token.
43
+ *
44
+ * The token has a 24h lifetime. We cache it for 23h to avoid edge-case
45
+ * expiry during a request. As per A-Cube best practices, we minimize
46
+ * login calls by reusing the cached token.
47
+ */
48
+ private login;
49
+ /** Returns a valid token, refreshing it if expired. */
50
+ private getToken;
51
+ /**
52
+ * Make an authenticated API request.
53
+ *
54
+ * Handles:
55
+ * - Automatic Bearer token injection.
56
+ * - Content-Type negotiation based on body presence.
57
+ * - Binary responses (PDF) returned as base64 strings.
58
+ * - JSON parsing with fallback to raw text.
59
+ * - HTTP 202 treated as success (used by A-Cube for invoice submission).
60
+ *
61
+ * @param method - HTTP method (GET, POST, PUT, DELETE).
62
+ * @param path - API path (e.g., `/invoices`). Appended to the base URL.
63
+ * @param options - Request options: service, body, headers, accept type.
64
+ * @returns Object with `status`, `data` (parsed), and optionally `raw` (for binary).
65
+ */
66
+ request<T = unknown>(method: string, path: string, options?: {
67
+ service?: "common" | "govIt";
68
+ body?: unknown;
69
+ headers?: Record<string, string>;
70
+ accept?: string;
71
+ }): Promise<{
72
+ status: number;
73
+ data: T;
74
+ raw?: ArrayBuffer;
75
+ }>;
76
+ /** Shorthand for `request("GET", path, options)`. */
77
+ get<T = unknown>(path: string, options?: Parameters<typeof this.request>[2]): Promise<{
78
+ status: number;
79
+ data: T;
80
+ raw?: ArrayBuffer;
81
+ }>;
82
+ /** Shorthand for `request("POST", path, { body, ...options })`. */
83
+ post<T = unknown>(path: string, body?: unknown, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<{
84
+ status: number;
85
+ data: T;
86
+ raw?: ArrayBuffer;
87
+ }>;
88
+ /** Shorthand for `request("PUT", path, { body, ...options })`. */
89
+ put<T = unknown>(path: string, body?: unknown, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<{
90
+ status: number;
91
+ data: T;
92
+ raw?: ArrayBuffer;
93
+ }>;
94
+ /** Shorthand for `request("DELETE", path, options)`. */
95
+ delete<T = unknown>(path: string, options?: Parameters<typeof this.request>[2]): Promise<{
96
+ status: number;
97
+ data: T;
98
+ raw?: ArrayBuffer;
99
+ }>;
100
+ }
101
+ export {};