@scell/sdk 1.2.0 → 1.5.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 +0 -0
- package/README.md +61 -2
- package/dist/index.d.mts +2353 -236
- package/dist/index.d.ts +2353 -236
- package/dist/index.js +1308 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1308 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +3 -1
- package/src/errors.ts +0 -0
- package/src/index.ts +42 -2
- package/src/resources/api-keys.ts +0 -0
- package/src/resources/auth.ts +0 -0
- package/src/resources/balance.ts +0 -0
- package/src/resources/billing.ts +49 -0
- package/src/resources/companies.ts +0 -0
- package/src/resources/fiscal.ts +128 -0
- package/src/resources/invoices.ts +0 -0
- package/src/resources/signatures.ts +33 -0
- package/src/resources/stats.ts +29 -0
- package/src/resources/sub-tenants.ts +41 -0
- package/src/resources/tenant-credit-notes.ts +301 -0
- package/src/resources/tenant-direct-credit-notes.ts +360 -0
- package/src/resources/tenant-direct-invoices.ts +424 -0
- package/src/resources/tenant-incoming-invoices.ts +429 -0
- package/src/resources/webhooks.ts +0 -0
- package/src/tenant-client.ts +105 -0
- package/src/types/api-keys.ts +0 -0
- package/src/types/auth.ts +0 -0
- package/src/types/balance.ts +0 -0
- package/src/types/billing.ts +73 -0
- package/src/types/common.ts +0 -0
- package/src/types/companies.ts +0 -0
- package/src/types/fiscal.ts +251 -0
- package/src/types/index.ts +103 -0
- package/src/types/invoices.ts +0 -0
- package/src/types/signatures.ts +0 -0
- package/src/types/stats.ts +37 -0
- package/src/types/sub-tenants.ts +57 -0
- package/src/types/tenant-credit-notes.ts +128 -0
- package/src/types/tenant-invoices.ts +390 -0
- package/src/types/tenant-profile.ts +51 -0
- package/src/types/webhooks.ts +0 -0
- package/src/utils/retry.ts +0 -0
- package/src/utils/webhook-verify.ts +0 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant Direct Invoices Resource
|
|
3
|
+
*
|
|
4
|
+
* Manage direct invoices issued by a tenant to external buyers.
|
|
5
|
+
* Direct invoices are outgoing invoices that are not part of
|
|
6
|
+
* sub-tenant billing but billed directly to third-party clients.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { HttpClient, RequestOptions } from '../client.js';
|
|
12
|
+
import type {
|
|
13
|
+
MessageResponse,
|
|
14
|
+
PaginatedResponse,
|
|
15
|
+
SingleResponse,
|
|
16
|
+
} from '../types/common.js';
|
|
17
|
+
import type {
|
|
18
|
+
CreateTenantDirectInvoiceParams,
|
|
19
|
+
TenantInvoice,
|
|
20
|
+
TenantInvoiceFilters,
|
|
21
|
+
UpdateTenantInvoiceParams,
|
|
22
|
+
} from '../types/tenant-invoices.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Tenant Direct Invoices API resource
|
|
26
|
+
*
|
|
27
|
+
* Provides operations for managing direct invoices created by tenants
|
|
28
|
+
* for external buyers (not sub-tenants).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { ScellTenantClient } from '@scell/sdk';
|
|
33
|
+
*
|
|
34
|
+
* const client = new ScellTenantClient('your-tenant-key');
|
|
35
|
+
*
|
|
36
|
+
* // Create a direct invoice
|
|
37
|
+
* const { data: invoice } = await client.directInvoices.create({
|
|
38
|
+
* company_id: 'company-uuid',
|
|
39
|
+
* buyer: {
|
|
40
|
+
* company_name: 'Client Corp',
|
|
41
|
+
* siret: '12345678901234',
|
|
42
|
+
* address: {
|
|
43
|
+
* line1: '123 Rue Client',
|
|
44
|
+
* postal_code: '75001',
|
|
45
|
+
* city: 'Paris',
|
|
46
|
+
* country: 'FR'
|
|
47
|
+
* },
|
|
48
|
+
* email: 'billing@client.com'
|
|
49
|
+
* },
|
|
50
|
+
* lines: [{
|
|
51
|
+
* description: 'Consulting services',
|
|
52
|
+
* quantity: 10,
|
|
53
|
+
* unit_price: 150,
|
|
54
|
+
* tax_rate: 20,
|
|
55
|
+
* total_ht: 1500,
|
|
56
|
+
* total_tax: 300,
|
|
57
|
+
* total_ttc: 1800
|
|
58
|
+
* }]
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // List all direct invoices
|
|
62
|
+
* const { data: invoices, meta } = await client.directInvoices.list({
|
|
63
|
+
* status: 'validated',
|
|
64
|
+
* per_page: 50
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export class TenantDirectInvoicesResource {
|
|
69
|
+
constructor(private readonly http: HttpClient) {}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create a new direct invoice
|
|
73
|
+
*
|
|
74
|
+
* Creates an outgoing invoice from the tenant to an external buyer.
|
|
75
|
+
* The invoice will be generated in the specified format (Factur-X by default).
|
|
76
|
+
*
|
|
77
|
+
* @param params - Invoice creation parameters
|
|
78
|
+
* @param requestOptions - Optional request configuration
|
|
79
|
+
* @returns Created invoice
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const { data: invoice } = await client.directInvoices.create({
|
|
84
|
+
* company_id: 'company-uuid',
|
|
85
|
+
* buyer: {
|
|
86
|
+
* company_name: 'Acme Corporation',
|
|
87
|
+
* siret: '98765432109876',
|
|
88
|
+
* address: {
|
|
89
|
+
* line1: '456 Avenue Business',
|
|
90
|
+
* postal_code: '69001',
|
|
91
|
+
* city: 'Lyon',
|
|
92
|
+
* country: 'FR'
|
|
93
|
+
* },
|
|
94
|
+
* email: 'accounts@acme.com'
|
|
95
|
+
* },
|
|
96
|
+
* lines: [{
|
|
97
|
+
* description: 'Monthly subscription',
|
|
98
|
+
* quantity: 1,
|
|
99
|
+
* unit_price: 299,
|
|
100
|
+
* tax_rate: 20,
|
|
101
|
+
* total_ht: 299,
|
|
102
|
+
* total_tax: 59.80,
|
|
103
|
+
* total_ttc: 358.80
|
|
104
|
+
* }],
|
|
105
|
+
* issue_date: '2026-01-26',
|
|
106
|
+
* due_date: '2026-02-26',
|
|
107
|
+
* notes: 'Thank you for your business!'
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* console.log('Invoice created:', invoice.invoice_number);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async create(
|
|
114
|
+
params: CreateTenantDirectInvoiceParams,
|
|
115
|
+
requestOptions?: RequestOptions
|
|
116
|
+
): Promise<SingleResponse<TenantInvoice>> {
|
|
117
|
+
return this.http.post<SingleResponse<TenantInvoice>>(
|
|
118
|
+
'/tenant/invoices',
|
|
119
|
+
params,
|
|
120
|
+
requestOptions
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* List all direct invoices
|
|
126
|
+
*
|
|
127
|
+
* Returns a paginated list of direct invoices created by the tenant.
|
|
128
|
+
* Supports filtering by status, date range, buyer, and amount.
|
|
129
|
+
*
|
|
130
|
+
* @param filters - Filter and pagination options
|
|
131
|
+
* @param requestOptions - Optional request configuration
|
|
132
|
+
* @returns Paginated list of invoices
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // List all validated invoices
|
|
137
|
+
* const { data: invoices, meta } = await client.directInvoices.list({
|
|
138
|
+
* status: 'validated',
|
|
139
|
+
* per_page: 50
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* console.log(`Found ${meta.total} validated invoices`);
|
|
143
|
+
*
|
|
144
|
+
* // Filter by date range
|
|
145
|
+
* const januaryInvoices = await client.directInvoices.list({
|
|
146
|
+
* date_from: '2026-01-01',
|
|
147
|
+
* date_to: '2026-01-31'
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* // Search by buyer
|
|
151
|
+
* const acmeInvoices = await client.directInvoices.list({
|
|
152
|
+
* search: 'Acme'
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
async list(
|
|
157
|
+
filters: TenantInvoiceFilters = {},
|
|
158
|
+
requestOptions?: RequestOptions
|
|
159
|
+
): Promise<PaginatedResponse<TenantInvoice>> {
|
|
160
|
+
// Convert status array to comma-separated string if needed
|
|
161
|
+
const query: Record<string, string | number | boolean | undefined> = {
|
|
162
|
+
...filters,
|
|
163
|
+
status: Array.isArray(filters.status)
|
|
164
|
+
? filters.status.join(',')
|
|
165
|
+
: filters.status,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
return this.http.get<PaginatedResponse<TenantInvoice>>(
|
|
169
|
+
'/tenant/invoices',
|
|
170
|
+
query,
|
|
171
|
+
requestOptions
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Get a specific direct invoice by ID
|
|
177
|
+
*
|
|
178
|
+
* @param invoiceId - Invoice UUID
|
|
179
|
+
* @param requestOptions - Optional request configuration
|
|
180
|
+
* @returns Invoice details
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const { data: invoice } = await client.directInvoices.get('invoice-uuid');
|
|
185
|
+
*
|
|
186
|
+
* console.log('Invoice:', invoice.invoice_number);
|
|
187
|
+
* console.log('Status:', invoice.status);
|
|
188
|
+
* console.log('Total:', invoice.total_ttc, invoice.currency);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
async get(
|
|
192
|
+
invoiceId: string,
|
|
193
|
+
requestOptions?: RequestOptions
|
|
194
|
+
): Promise<SingleResponse<TenantInvoice>> {
|
|
195
|
+
return this.http.get<SingleResponse<TenantInvoice>>(
|
|
196
|
+
`/tenant/invoices/${invoiceId}`,
|
|
197
|
+
undefined,
|
|
198
|
+
requestOptions
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Update a direct invoice
|
|
204
|
+
*
|
|
205
|
+
* Only invoices in 'draft' status can be updated.
|
|
206
|
+
* Once validated or sent, invoices become immutable.
|
|
207
|
+
*
|
|
208
|
+
* @param invoiceId - Invoice UUID
|
|
209
|
+
* @param params - Update parameters
|
|
210
|
+
* @param requestOptions - Optional request configuration
|
|
211
|
+
* @returns Updated invoice
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const { data: invoice } = await client.directInvoices.update(
|
|
216
|
+
* 'invoice-uuid',
|
|
217
|
+
* {
|
|
218
|
+
* due_date: '2026-03-15',
|
|
219
|
+
* notes: 'Updated payment terms'
|
|
220
|
+
* }
|
|
221
|
+
* );
|
|
222
|
+
*
|
|
223
|
+
* console.log('Invoice updated:', invoice.due_date);
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
async update(
|
|
227
|
+
invoiceId: string,
|
|
228
|
+
params: UpdateTenantInvoiceParams,
|
|
229
|
+
requestOptions?: RequestOptions
|
|
230
|
+
): Promise<SingleResponse<TenantInvoice>> {
|
|
231
|
+
return this.http.patch<SingleResponse<TenantInvoice>>(
|
|
232
|
+
`/tenant/invoices/${invoiceId}`,
|
|
233
|
+
params,
|
|
234
|
+
requestOptions
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Delete a direct invoice
|
|
240
|
+
*
|
|
241
|
+
* Only invoices in 'draft' status can be deleted.
|
|
242
|
+
* Validated or sent invoices cannot be deleted for audit trail compliance.
|
|
243
|
+
*
|
|
244
|
+
* @param invoiceId - Invoice UUID
|
|
245
|
+
* @param requestOptions - Optional request configuration
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* await client.directInvoices.delete('draft-invoice-uuid');
|
|
250
|
+
* console.log('Invoice deleted successfully');
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
async delete(
|
|
254
|
+
invoiceId: string,
|
|
255
|
+
requestOptions?: RequestOptions
|
|
256
|
+
): Promise<MessageResponse> {
|
|
257
|
+
return this.http.delete<MessageResponse>(
|
|
258
|
+
`/tenant/invoices/${invoiceId}`,
|
|
259
|
+
requestOptions
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Validate a direct invoice
|
|
265
|
+
*
|
|
266
|
+
* Validates the invoice, generates the electronic invoice file,
|
|
267
|
+
* and changes status from 'draft' to 'validated'.
|
|
268
|
+
*
|
|
269
|
+
* @param invoiceId - Invoice UUID
|
|
270
|
+
* @param requestOptions - Optional request configuration
|
|
271
|
+
* @returns Validated invoice
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* const { data: invoice } = await client.directInvoices.validate('invoice-uuid');
|
|
276
|
+
* console.log('Invoice validated:', invoice.status); // 'validated'
|
|
277
|
+
* console.log('Validated at:', invoice.validated_at);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
async validate(
|
|
281
|
+
invoiceId: string,
|
|
282
|
+
requestOptions?: RequestOptions
|
|
283
|
+
): Promise<SingleResponse<TenantInvoice>> {
|
|
284
|
+
return this.http.post<SingleResponse<TenantInvoice>>(
|
|
285
|
+
`/tenant/invoices/${invoiceId}/validate`,
|
|
286
|
+
undefined,
|
|
287
|
+
requestOptions
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Send a direct invoice to the buyer
|
|
293
|
+
*
|
|
294
|
+
* Sends the validated invoice to the buyer via email.
|
|
295
|
+
* The invoice must be in 'validated' status.
|
|
296
|
+
*
|
|
297
|
+
* @param invoiceId - Invoice UUID
|
|
298
|
+
* @param requestOptions - Optional request configuration
|
|
299
|
+
* @returns Updated invoice
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* const { data: invoice } = await client.directInvoices.send('invoice-uuid');
|
|
304
|
+
* console.log('Invoice sent to:', invoice.buyer.email);
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
async send(
|
|
308
|
+
invoiceId: string,
|
|
309
|
+
requestOptions?: RequestOptions
|
|
310
|
+
): Promise<SingleResponse<TenantInvoice>> {
|
|
311
|
+
return this.http.post<SingleResponse<TenantInvoice>>(
|
|
312
|
+
`/tenant/invoices/${invoiceId}/send`,
|
|
313
|
+
undefined,
|
|
314
|
+
requestOptions
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Download invoice as PDF
|
|
320
|
+
*
|
|
321
|
+
* Downloads the electronic invoice file as a PDF (Factur-X).
|
|
322
|
+
*
|
|
323
|
+
* @param invoiceId - Invoice UUID
|
|
324
|
+
* @param requestOptions - Optional request configuration
|
|
325
|
+
* @returns ArrayBuffer containing the PDF file
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* // Download invoice PDF
|
|
330
|
+
* const pdfBuffer = await client.directInvoices.download('invoice-uuid');
|
|
331
|
+
*
|
|
332
|
+
* // In Node.js, save to file:
|
|
333
|
+
* import { writeFileSync } from 'fs';
|
|
334
|
+
* writeFileSync('invoice.pdf', Buffer.from(pdfBuffer));
|
|
335
|
+
*
|
|
336
|
+
* // In browser, trigger download:
|
|
337
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
338
|
+
* const url = URL.createObjectURL(blob);
|
|
339
|
+
* const a = document.createElement('a');
|
|
340
|
+
* a.href = url;
|
|
341
|
+
* a.download = 'invoice.pdf';
|
|
342
|
+
* a.click();
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
async download(
|
|
346
|
+
invoiceId: string,
|
|
347
|
+
requestOptions?: RequestOptions
|
|
348
|
+
): Promise<ArrayBuffer> {
|
|
349
|
+
return this.http.getRaw(
|
|
350
|
+
`/tenant/invoices/${invoiceId}/download`,
|
|
351
|
+
undefined,
|
|
352
|
+
requestOptions
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Download invoice XML
|
|
358
|
+
*
|
|
359
|
+
* Downloads the electronic invoice XML (UBL/CII format).
|
|
360
|
+
*
|
|
361
|
+
* @param invoiceId - Invoice UUID
|
|
362
|
+
* @param requestOptions - Optional request configuration
|
|
363
|
+
* @returns ArrayBuffer containing the XML file
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const xmlBuffer = await client.directInvoices.downloadXml('invoice-uuid');
|
|
368
|
+
* const xmlString = new TextDecoder().decode(xmlBuffer);
|
|
369
|
+
* console.log('XML:', xmlString);
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
async downloadXml(
|
|
373
|
+
invoiceId: string,
|
|
374
|
+
requestOptions?: RequestOptions
|
|
375
|
+
): Promise<ArrayBuffer> {
|
|
376
|
+
return this.http.getRaw(
|
|
377
|
+
`/tenant/invoices/${invoiceId}/download`,
|
|
378
|
+
{ format: 'xml' },
|
|
379
|
+
requestOptions
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Bulk create multiple invoices
|
|
385
|
+
*/
|
|
386
|
+
async bulkCreate(
|
|
387
|
+
invoices: CreateTenantDirectInvoiceParams[],
|
|
388
|
+
requestOptions?: RequestOptions
|
|
389
|
+
): Promise<MessageResponse> {
|
|
390
|
+
return this.http.post<MessageResponse>(
|
|
391
|
+
'/tenant/invoices/bulk',
|
|
392
|
+
{ invoices },
|
|
393
|
+
requestOptions
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Bulk submit multiple invoices
|
|
399
|
+
*/
|
|
400
|
+
async bulkSubmit(
|
|
401
|
+
invoiceIds: string[],
|
|
402
|
+
requestOptions?: RequestOptions
|
|
403
|
+
): Promise<MessageResponse> {
|
|
404
|
+
return this.http.post<MessageResponse>(
|
|
405
|
+
'/tenant/invoices/bulk-submit',
|
|
406
|
+
{ invoice_ids: invoiceIds },
|
|
407
|
+
requestOptions
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Get status of multiple invoices
|
|
413
|
+
*/
|
|
414
|
+
async bulkStatus(
|
|
415
|
+
invoiceIds: string[],
|
|
416
|
+
requestOptions?: RequestOptions
|
|
417
|
+
): Promise<SingleResponse<Record<string, unknown>[]>> {
|
|
418
|
+
return this.http.post<SingleResponse<Record<string, unknown>[]>>(
|
|
419
|
+
'/tenant/invoices/bulk-status',
|
|
420
|
+
{ invoice_ids: invoiceIds },
|
|
421
|
+
requestOptions
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
}
|