@scell/sdk 1.0.0 → 1.4.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/README.md +134 -5
- package/dist/index.d.mts +2502 -170
- package/dist/index.d.ts +2502 -170
- package/dist/index.js +1497 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1497 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +79 -1
- package/src/index.ts +17 -1
- package/src/resources/billing.ts +49 -0
- package/src/resources/fiscal.ts +128 -0
- package/src/resources/invoices.ts +217 -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/tenant-client.ts +105 -0
- package/src/types/billing.ts +73 -0
- package/src/types/fiscal.ts +251 -0
- package/src/types/index.ts +112 -0
- package/src/types/invoices.ts +91 -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 +30 -1
package/dist/index.js
CHANGED
|
@@ -277,6 +277,8 @@ var HttpClient = class {
|
|
|
277
277
|
};
|
|
278
278
|
if (this.authMode === "bearer") {
|
|
279
279
|
headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
280
|
+
} else if (this.authMode === "tenant-key") {
|
|
281
|
+
headers["X-Tenant-Key"] = this.authToken;
|
|
280
282
|
} else {
|
|
281
283
|
headers["X-API-Key"] = this.authToken;
|
|
282
284
|
}
|
|
@@ -403,6 +405,1315 @@ var HttpClient = class {
|
|
|
403
405
|
...options
|
|
404
406
|
});
|
|
405
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* GET request that returns raw binary data as ArrayBuffer
|
|
410
|
+
*
|
|
411
|
+
* Use this for downloading files (PDF, XML, etc.)
|
|
412
|
+
*
|
|
413
|
+
* @param path - API endpoint path
|
|
414
|
+
* @param query - Query parameters
|
|
415
|
+
* @param options - Request options
|
|
416
|
+
* @returns ArrayBuffer containing the file content
|
|
417
|
+
*/
|
|
418
|
+
async getRaw(path, query, options) {
|
|
419
|
+
const url = this.buildUrl(path, query);
|
|
420
|
+
const requestHeaders = this.buildHeaders(options?.headers);
|
|
421
|
+
const requestTimeout = options?.timeout ?? this.timeout;
|
|
422
|
+
delete requestHeaders["Content-Type"];
|
|
423
|
+
requestHeaders["Accept"] = "*/*";
|
|
424
|
+
const controller = new AbortController();
|
|
425
|
+
const timeoutId = setTimeout(() => controller.abort(), requestTimeout);
|
|
426
|
+
if (options?.signal) {
|
|
427
|
+
options.signal.addEventListener("abort", () => controller.abort());
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
const response = await this.fetchFn(url, {
|
|
431
|
+
method: "GET",
|
|
432
|
+
headers: requestHeaders,
|
|
433
|
+
signal: controller.signal
|
|
434
|
+
});
|
|
435
|
+
clearTimeout(timeoutId);
|
|
436
|
+
if (!response.ok) {
|
|
437
|
+
const contentType = response.headers.get("Content-Type") ?? "";
|
|
438
|
+
let responseBody;
|
|
439
|
+
if (contentType.includes("application/json")) {
|
|
440
|
+
responseBody = await response.json();
|
|
441
|
+
} else {
|
|
442
|
+
responseBody = await response.text();
|
|
443
|
+
}
|
|
444
|
+
parseApiError(response.status, responseBody, response.headers);
|
|
445
|
+
}
|
|
446
|
+
return response.arrayBuffer();
|
|
447
|
+
} catch (error) {
|
|
448
|
+
clearTimeout(timeoutId);
|
|
449
|
+
if (error instanceof Error) {
|
|
450
|
+
if (error.name === "AbortError") {
|
|
451
|
+
throw new exports.ScellTimeoutError(
|
|
452
|
+
`Request timed out after ${requestTimeout}ms`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
if (error.name === "TypeError" && error.message.includes("fetch")) {
|
|
456
|
+
throw new exports.ScellNetworkError("Network request failed", error);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// src/resources/tenant-direct-invoices.ts
|
|
465
|
+
var TenantDirectInvoicesResource = class {
|
|
466
|
+
constructor(http) {
|
|
467
|
+
this.http = http;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Create a new direct invoice
|
|
471
|
+
*
|
|
472
|
+
* Creates an outgoing invoice from the tenant to an external buyer.
|
|
473
|
+
* The invoice will be generated in the specified format (Factur-X by default).
|
|
474
|
+
*
|
|
475
|
+
* @param params - Invoice creation parameters
|
|
476
|
+
* @param requestOptions - Optional request configuration
|
|
477
|
+
* @returns Created invoice
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* const { data: invoice } = await client.directInvoices.create({
|
|
482
|
+
* company_id: 'company-uuid',
|
|
483
|
+
* buyer: {
|
|
484
|
+
* company_name: 'Acme Corporation',
|
|
485
|
+
* siret: '98765432109876',
|
|
486
|
+
* address: {
|
|
487
|
+
* line1: '456 Avenue Business',
|
|
488
|
+
* postal_code: '69001',
|
|
489
|
+
* city: 'Lyon',
|
|
490
|
+
* country: 'FR'
|
|
491
|
+
* },
|
|
492
|
+
* email: 'accounts@acme.com'
|
|
493
|
+
* },
|
|
494
|
+
* lines: [{
|
|
495
|
+
* description: 'Monthly subscription',
|
|
496
|
+
* quantity: 1,
|
|
497
|
+
* unit_price: 299,
|
|
498
|
+
* tax_rate: 20,
|
|
499
|
+
* total_ht: 299,
|
|
500
|
+
* total_tax: 59.80,
|
|
501
|
+
* total_ttc: 358.80
|
|
502
|
+
* }],
|
|
503
|
+
* issue_date: '2026-01-26',
|
|
504
|
+
* due_date: '2026-02-26',
|
|
505
|
+
* notes: 'Thank you for your business!'
|
|
506
|
+
* });
|
|
507
|
+
*
|
|
508
|
+
* console.log('Invoice created:', invoice.invoice_number);
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
async create(params, requestOptions) {
|
|
512
|
+
return this.http.post(
|
|
513
|
+
"/tenant/invoices",
|
|
514
|
+
params,
|
|
515
|
+
requestOptions
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* List all direct invoices
|
|
520
|
+
*
|
|
521
|
+
* Returns a paginated list of direct invoices created by the tenant.
|
|
522
|
+
* Supports filtering by status, date range, buyer, and amount.
|
|
523
|
+
*
|
|
524
|
+
* @param filters - Filter and pagination options
|
|
525
|
+
* @param requestOptions - Optional request configuration
|
|
526
|
+
* @returns Paginated list of invoices
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* // List all validated invoices
|
|
531
|
+
* const { data: invoices, meta } = await client.directInvoices.list({
|
|
532
|
+
* status: 'validated',
|
|
533
|
+
* per_page: 50
|
|
534
|
+
* });
|
|
535
|
+
*
|
|
536
|
+
* console.log(`Found ${meta.total} validated invoices`);
|
|
537
|
+
*
|
|
538
|
+
* // Filter by date range
|
|
539
|
+
* const januaryInvoices = await client.directInvoices.list({
|
|
540
|
+
* date_from: '2026-01-01',
|
|
541
|
+
* date_to: '2026-01-31'
|
|
542
|
+
* });
|
|
543
|
+
*
|
|
544
|
+
* // Search by buyer
|
|
545
|
+
* const acmeInvoices = await client.directInvoices.list({
|
|
546
|
+
* search: 'Acme'
|
|
547
|
+
* });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
async list(filters = {}, requestOptions) {
|
|
551
|
+
const query = {
|
|
552
|
+
...filters,
|
|
553
|
+
status: Array.isArray(filters.status) ? filters.status.join(",") : filters.status
|
|
554
|
+
};
|
|
555
|
+
return this.http.get(
|
|
556
|
+
"/tenant/invoices",
|
|
557
|
+
query,
|
|
558
|
+
requestOptions
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Get a specific direct invoice by ID
|
|
563
|
+
*
|
|
564
|
+
* @param invoiceId - Invoice UUID
|
|
565
|
+
* @param requestOptions - Optional request configuration
|
|
566
|
+
* @returns Invoice details
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* const { data: invoice } = await client.directInvoices.get('invoice-uuid');
|
|
571
|
+
*
|
|
572
|
+
* console.log('Invoice:', invoice.invoice_number);
|
|
573
|
+
* console.log('Status:', invoice.status);
|
|
574
|
+
* console.log('Total:', invoice.total_ttc, invoice.currency);
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
async get(invoiceId, requestOptions) {
|
|
578
|
+
return this.http.get(
|
|
579
|
+
`/tenant/invoices/${invoiceId}`,
|
|
580
|
+
void 0,
|
|
581
|
+
requestOptions
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Update a direct invoice
|
|
586
|
+
*
|
|
587
|
+
* Only invoices in 'draft' status can be updated.
|
|
588
|
+
* Once validated or sent, invoices become immutable.
|
|
589
|
+
*
|
|
590
|
+
* @param invoiceId - Invoice UUID
|
|
591
|
+
* @param params - Update parameters
|
|
592
|
+
* @param requestOptions - Optional request configuration
|
|
593
|
+
* @returns Updated invoice
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```typescript
|
|
597
|
+
* const { data: invoice } = await client.directInvoices.update(
|
|
598
|
+
* 'invoice-uuid',
|
|
599
|
+
* {
|
|
600
|
+
* due_date: '2026-03-15',
|
|
601
|
+
* notes: 'Updated payment terms'
|
|
602
|
+
* }
|
|
603
|
+
* );
|
|
604
|
+
*
|
|
605
|
+
* console.log('Invoice updated:', invoice.due_date);
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
async update(invoiceId, params, requestOptions) {
|
|
609
|
+
return this.http.patch(
|
|
610
|
+
`/tenant/invoices/${invoiceId}`,
|
|
611
|
+
params,
|
|
612
|
+
requestOptions
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Delete a direct invoice
|
|
617
|
+
*
|
|
618
|
+
* Only invoices in 'draft' status can be deleted.
|
|
619
|
+
* Validated or sent invoices cannot be deleted for audit trail compliance.
|
|
620
|
+
*
|
|
621
|
+
* @param invoiceId - Invoice UUID
|
|
622
|
+
* @param requestOptions - Optional request configuration
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* await client.directInvoices.delete('draft-invoice-uuid');
|
|
627
|
+
* console.log('Invoice deleted successfully');
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
async delete(invoiceId, requestOptions) {
|
|
631
|
+
return this.http.delete(
|
|
632
|
+
`/tenant/invoices/${invoiceId}`,
|
|
633
|
+
requestOptions
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Validate a direct invoice
|
|
638
|
+
*
|
|
639
|
+
* Validates the invoice, generates the electronic invoice file,
|
|
640
|
+
* and changes status from 'draft' to 'validated'.
|
|
641
|
+
*
|
|
642
|
+
* @param invoiceId - Invoice UUID
|
|
643
|
+
* @param requestOptions - Optional request configuration
|
|
644
|
+
* @returns Validated invoice
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* const { data: invoice } = await client.directInvoices.validate('invoice-uuid');
|
|
649
|
+
* console.log('Invoice validated:', invoice.status); // 'validated'
|
|
650
|
+
* console.log('Validated at:', invoice.validated_at);
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
async validate(invoiceId, requestOptions) {
|
|
654
|
+
return this.http.post(
|
|
655
|
+
`/tenant/invoices/${invoiceId}/validate`,
|
|
656
|
+
void 0,
|
|
657
|
+
requestOptions
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Send a direct invoice to the buyer
|
|
662
|
+
*
|
|
663
|
+
* Sends the validated invoice to the buyer via email.
|
|
664
|
+
* The invoice must be in 'validated' status.
|
|
665
|
+
*
|
|
666
|
+
* @param invoiceId - Invoice UUID
|
|
667
|
+
* @param requestOptions - Optional request configuration
|
|
668
|
+
* @returns Updated invoice
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```typescript
|
|
672
|
+
* const { data: invoice } = await client.directInvoices.send('invoice-uuid');
|
|
673
|
+
* console.log('Invoice sent to:', invoice.buyer.email);
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
async send(invoiceId, requestOptions) {
|
|
677
|
+
return this.http.post(
|
|
678
|
+
`/tenant/invoices/${invoiceId}/send`,
|
|
679
|
+
void 0,
|
|
680
|
+
requestOptions
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Download invoice as PDF
|
|
685
|
+
*
|
|
686
|
+
* Downloads the electronic invoice file as a PDF (Factur-X).
|
|
687
|
+
*
|
|
688
|
+
* @param invoiceId - Invoice UUID
|
|
689
|
+
* @param requestOptions - Optional request configuration
|
|
690
|
+
* @returns ArrayBuffer containing the PDF file
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* ```typescript
|
|
694
|
+
* // Download invoice PDF
|
|
695
|
+
* const pdfBuffer = await client.directInvoices.download('invoice-uuid');
|
|
696
|
+
*
|
|
697
|
+
* // In Node.js, save to file:
|
|
698
|
+
* import { writeFileSync } from 'fs';
|
|
699
|
+
* writeFileSync('invoice.pdf', Buffer.from(pdfBuffer));
|
|
700
|
+
*
|
|
701
|
+
* // In browser, trigger download:
|
|
702
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
703
|
+
* const url = URL.createObjectURL(blob);
|
|
704
|
+
* const a = document.createElement('a');
|
|
705
|
+
* a.href = url;
|
|
706
|
+
* a.download = 'invoice.pdf';
|
|
707
|
+
* a.click();
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
async download(invoiceId, requestOptions) {
|
|
711
|
+
return this.http.getRaw(
|
|
712
|
+
`/tenant/invoices/${invoiceId}/download`,
|
|
713
|
+
void 0,
|
|
714
|
+
requestOptions
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Download invoice XML
|
|
719
|
+
*
|
|
720
|
+
* Downloads the electronic invoice XML (UBL/CII format).
|
|
721
|
+
*
|
|
722
|
+
* @param invoiceId - Invoice UUID
|
|
723
|
+
* @param requestOptions - Optional request configuration
|
|
724
|
+
* @returns ArrayBuffer containing the XML file
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```typescript
|
|
728
|
+
* const xmlBuffer = await client.directInvoices.downloadXml('invoice-uuid');
|
|
729
|
+
* const xmlString = new TextDecoder().decode(xmlBuffer);
|
|
730
|
+
* console.log('XML:', xmlString);
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
async downloadXml(invoiceId, requestOptions) {
|
|
734
|
+
return this.http.getRaw(
|
|
735
|
+
`/tenant/invoices/${invoiceId}/download`,
|
|
736
|
+
{ format: "xml" },
|
|
737
|
+
requestOptions
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Bulk create multiple invoices
|
|
742
|
+
*/
|
|
743
|
+
async bulkCreate(invoices, requestOptions) {
|
|
744
|
+
return this.http.post(
|
|
745
|
+
"/tenant/invoices/bulk",
|
|
746
|
+
{ invoices },
|
|
747
|
+
requestOptions
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Bulk submit multiple invoices
|
|
752
|
+
*/
|
|
753
|
+
async bulkSubmit(invoiceIds, requestOptions) {
|
|
754
|
+
return this.http.post(
|
|
755
|
+
"/tenant/invoices/bulk-submit",
|
|
756
|
+
{ invoice_ids: invoiceIds },
|
|
757
|
+
requestOptions
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Get status of multiple invoices
|
|
762
|
+
*/
|
|
763
|
+
async bulkStatus(invoiceIds, requestOptions) {
|
|
764
|
+
return this.http.post(
|
|
765
|
+
"/tenant/invoices/bulk-status",
|
|
766
|
+
{ invoice_ids: invoiceIds },
|
|
767
|
+
requestOptions
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// src/resources/tenant-direct-credit-notes.ts
|
|
773
|
+
var TenantDirectCreditNotesResource = class {
|
|
774
|
+
constructor(http) {
|
|
775
|
+
this.http = http;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Create a new credit note for a direct invoice
|
|
779
|
+
*
|
|
780
|
+
* Creates a credit note (avoir) linked to a direct invoice.
|
|
781
|
+
* - For partial credit notes, specify the items and quantities to credit.
|
|
782
|
+
* - For total credit notes, all items are automatically credited.
|
|
783
|
+
*
|
|
784
|
+
* @param params - Credit note creation parameters
|
|
785
|
+
* @param requestOptions - Optional request configuration
|
|
786
|
+
* @returns Created credit note
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```typescript
|
|
790
|
+
* // Partial credit note
|
|
791
|
+
* const { data: creditNote } = await client.directCreditNotes.create({
|
|
792
|
+
* invoice_id: 'invoice-uuid',
|
|
793
|
+
* reason: 'Returned items',
|
|
794
|
+
* type: 'partial',
|
|
795
|
+
* items: [
|
|
796
|
+
* { invoice_line_id: 'line-1-uuid', quantity: 2 },
|
|
797
|
+
* { invoice_line_id: 'line-2-uuid', quantity: 1 }
|
|
798
|
+
* ]
|
|
799
|
+
* });
|
|
800
|
+
*
|
|
801
|
+
* // Total credit note (cancels entire invoice)
|
|
802
|
+
* const { data: totalCreditNote } = await client.directCreditNotes.create({
|
|
803
|
+
* invoice_id: 'invoice-uuid',
|
|
804
|
+
* reason: 'Invoice issued in error',
|
|
805
|
+
* type: 'total'
|
|
806
|
+
* });
|
|
807
|
+
*
|
|
808
|
+
* console.log('Credit note number:', creditNote.credit_note_number);
|
|
809
|
+
* console.log('Amount:', creditNote.total, creditNote.currency);
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
async create(params, requestOptions) {
|
|
813
|
+
return this.http.post(
|
|
814
|
+
"/tenant/credit-notes",
|
|
815
|
+
params,
|
|
816
|
+
requestOptions
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* List all direct credit notes
|
|
821
|
+
*
|
|
822
|
+
* Returns a paginated list of credit notes for direct invoices.
|
|
823
|
+
*
|
|
824
|
+
* @param filters - Filter and pagination options
|
|
825
|
+
* @param requestOptions - Optional request configuration
|
|
826
|
+
* @returns Paginated list of credit notes
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```typescript
|
|
830
|
+
* // List all sent credit notes
|
|
831
|
+
* const { data: creditNotes, meta } = await client.directCreditNotes.list({
|
|
832
|
+
* status: 'sent',
|
|
833
|
+
* per_page: 50
|
|
834
|
+
* });
|
|
835
|
+
*
|
|
836
|
+
* console.log(`Found ${meta.total} sent credit notes`);
|
|
837
|
+
*
|
|
838
|
+
* // Filter by date range
|
|
839
|
+
* const januaryCreditNotes = await client.directCreditNotes.list({
|
|
840
|
+
* date_from: '2026-01-01',
|
|
841
|
+
* date_to: '2026-01-31'
|
|
842
|
+
* });
|
|
843
|
+
* ```
|
|
844
|
+
*/
|
|
845
|
+
async list(filters = {}, requestOptions) {
|
|
846
|
+
return this.http.get(
|
|
847
|
+
"/tenant/credit-notes",
|
|
848
|
+
filters,
|
|
849
|
+
requestOptions
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Get a specific credit note by ID
|
|
854
|
+
*
|
|
855
|
+
* @param creditNoteId - Credit note UUID
|
|
856
|
+
* @param requestOptions - Optional request configuration
|
|
857
|
+
* @returns Credit note details
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```typescript
|
|
861
|
+
* const { data: creditNote } = await client.directCreditNotes.get('credit-note-uuid');
|
|
862
|
+
*
|
|
863
|
+
* console.log('Credit note:', creditNote.credit_note_number);
|
|
864
|
+
* console.log('Status:', creditNote.status);
|
|
865
|
+
* console.log('Reason:', creditNote.reason);
|
|
866
|
+
* console.log('Total:', creditNote.total, creditNote.currency);
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
async get(creditNoteId, requestOptions) {
|
|
870
|
+
return this.http.get(
|
|
871
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
872
|
+
void 0,
|
|
873
|
+
requestOptions
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Update a credit note
|
|
878
|
+
*
|
|
879
|
+
* Only credit notes in 'draft' status can be updated.
|
|
880
|
+
*
|
|
881
|
+
* @param creditNoteId - Credit note UUID
|
|
882
|
+
* @param params - Update parameters
|
|
883
|
+
* @param requestOptions - Optional request configuration
|
|
884
|
+
* @returns Updated credit note
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```typescript
|
|
888
|
+
* const { data: creditNote } = await client.directCreditNotes.update(
|
|
889
|
+
* 'credit-note-uuid',
|
|
890
|
+
* {
|
|
891
|
+
* reason: 'Updated reason: Customer complaint resolved',
|
|
892
|
+
* items: [
|
|
893
|
+
* { invoice_line_id: 'line-uuid', quantity: 3 }
|
|
894
|
+
* ]
|
|
895
|
+
* }
|
|
896
|
+
* );
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
899
|
+
async update(creditNoteId, params, requestOptions) {
|
|
900
|
+
return this.http.patch(
|
|
901
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
902
|
+
params,
|
|
903
|
+
requestOptions
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Delete a credit note
|
|
908
|
+
*
|
|
909
|
+
* Only credit notes in 'draft' status can be deleted.
|
|
910
|
+
*
|
|
911
|
+
* @param creditNoteId - Credit note UUID
|
|
912
|
+
* @param requestOptions - Optional request configuration
|
|
913
|
+
*
|
|
914
|
+
* @example
|
|
915
|
+
* ```typescript
|
|
916
|
+
* await client.directCreditNotes.delete('draft-credit-note-uuid');
|
|
917
|
+
* console.log('Credit note deleted');
|
|
918
|
+
* ```
|
|
919
|
+
*/
|
|
920
|
+
async delete(creditNoteId, requestOptions) {
|
|
921
|
+
return this.http.delete(
|
|
922
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
923
|
+
requestOptions
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Send a credit note
|
|
928
|
+
*
|
|
929
|
+
* Validates and sends the credit note, changing status from 'draft' to 'sent'.
|
|
930
|
+
*
|
|
931
|
+
* @param creditNoteId - Credit note UUID
|
|
932
|
+
* @param requestOptions - Optional request configuration
|
|
933
|
+
* @returns Sent credit note
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```typescript
|
|
937
|
+
* const { data: creditNote } = await client.directCreditNotes.send('credit-note-uuid');
|
|
938
|
+
* console.log('Credit note sent:', creditNote.status); // 'sent'
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
async send(creditNoteId, requestOptions) {
|
|
942
|
+
return this.http.post(
|
|
943
|
+
`/tenant/credit-notes/${creditNoteId}/send`,
|
|
944
|
+
void 0,
|
|
945
|
+
requestOptions
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Download credit note as PDF
|
|
950
|
+
*
|
|
951
|
+
* @param creditNoteId - Credit note UUID
|
|
952
|
+
* @param requestOptions - Optional request configuration
|
|
953
|
+
* @returns ArrayBuffer containing the PDF file
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* ```typescript
|
|
957
|
+
* const pdfBuffer = await client.directCreditNotes.download('credit-note-uuid');
|
|
958
|
+
*
|
|
959
|
+
* // In Node.js:
|
|
960
|
+
* import { writeFileSync } from 'fs';
|
|
961
|
+
* writeFileSync('credit-note.pdf', Buffer.from(pdfBuffer));
|
|
962
|
+
*
|
|
963
|
+
* // In browser:
|
|
964
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
965
|
+
* const url = URL.createObjectURL(blob);
|
|
966
|
+
* window.open(url);
|
|
967
|
+
* ```
|
|
968
|
+
*/
|
|
969
|
+
async download(creditNoteId, requestOptions) {
|
|
970
|
+
return this.http.getRaw(
|
|
971
|
+
`/tenant/credit-notes/${creditNoteId}/download`,
|
|
972
|
+
void 0,
|
|
973
|
+
requestOptions
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Get remaining creditable amount for a direct invoice
|
|
978
|
+
*
|
|
979
|
+
* Returns information about how much can still be credited,
|
|
980
|
+
* including line-by-line breakdown.
|
|
981
|
+
*
|
|
982
|
+
* @param invoiceId - Invoice UUID
|
|
983
|
+
* @param requestOptions - Optional request configuration
|
|
984
|
+
* @returns Remaining creditable information
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* const remaining = await client.directCreditNotes.remainingCreditable('invoice-uuid');
|
|
989
|
+
*
|
|
990
|
+
* console.log('Invoice total:', remaining.invoice_total);
|
|
991
|
+
* console.log('Already credited:', remaining.credited_total);
|
|
992
|
+
* console.log('Can still credit:', remaining.remaining_total);
|
|
993
|
+
*
|
|
994
|
+
* // Check per-line
|
|
995
|
+
* remaining.lines.forEach(line => {
|
|
996
|
+
* if (line.remaining_quantity > 0) {
|
|
997
|
+
* console.log(`${line.description}: ${line.remaining_quantity} units remaining`);
|
|
998
|
+
* }
|
|
999
|
+
* });
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
1002
|
+
async remainingCreditable(invoiceId, requestOptions) {
|
|
1003
|
+
return this.http.get(
|
|
1004
|
+
`/tenant/invoices/${invoiceId}/remaining-creditable`,
|
|
1005
|
+
void 0,
|
|
1006
|
+
requestOptions
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
// src/resources/tenant-incoming-invoices.ts
|
|
1012
|
+
var TenantIncomingInvoicesResource = class {
|
|
1013
|
+
constructor(http) {
|
|
1014
|
+
this.http = http;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Create a new incoming invoice for a sub-tenant
|
|
1018
|
+
*
|
|
1019
|
+
* Creates a purchase invoice received by a sub-tenant from an external supplier.
|
|
1020
|
+
* The seller's SIREN is validated using the Luhn algorithm.
|
|
1021
|
+
*
|
|
1022
|
+
* @param subTenantId - Sub-tenant UUID
|
|
1023
|
+
* @param params - Invoice creation parameters
|
|
1024
|
+
* @param requestOptions - Optional request configuration
|
|
1025
|
+
* @returns Created invoice
|
|
1026
|
+
*
|
|
1027
|
+
* @example
|
|
1028
|
+
* ```typescript
|
|
1029
|
+
* const { data: invoice } = await client.incomingInvoices.create(
|
|
1030
|
+
* 'sub-tenant-uuid',
|
|
1031
|
+
* {
|
|
1032
|
+
* invoice_number: 'SUPP-2026-001',
|
|
1033
|
+
* company_id: 'company-uuid',
|
|
1034
|
+
* seller: {
|
|
1035
|
+
* company_name: 'Acme Supplies',
|
|
1036
|
+
* siren: '123456789',
|
|
1037
|
+
* siret: '12345678901234',
|
|
1038
|
+
* vat_number: 'FR12123456789',
|
|
1039
|
+
* address: {
|
|
1040
|
+
* line1: '123 Industrial Park',
|
|
1041
|
+
* postal_code: '31000',
|
|
1042
|
+
* city: 'Toulouse',
|
|
1043
|
+
* country: 'FR'
|
|
1044
|
+
* },
|
|
1045
|
+
* email: 'billing@acme-supplies.com'
|
|
1046
|
+
* },
|
|
1047
|
+
* lines: [
|
|
1048
|
+
* {
|
|
1049
|
+
* description: 'Widget A - Bulk order',
|
|
1050
|
+
* quantity: 500,
|
|
1051
|
+
* unit_price: 2.50,
|
|
1052
|
+
* tax_rate: 20,
|
|
1053
|
+
* total_ht: 1250,
|
|
1054
|
+
* total_tax: 250,
|
|
1055
|
+
* total_ttc: 1500
|
|
1056
|
+
* }
|
|
1057
|
+
* ],
|
|
1058
|
+
* issue_date: '2026-01-15',
|
|
1059
|
+
* due_date: '2026-02-15',
|
|
1060
|
+
* total_ht: 1250,
|
|
1061
|
+
* total_ttc: 1500
|
|
1062
|
+
* }
|
|
1063
|
+
* );
|
|
1064
|
+
*
|
|
1065
|
+
* console.log('Incoming invoice created:', invoice.invoice_number);
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
async create(subTenantId, params, requestOptions) {
|
|
1069
|
+
return this.http.post(
|
|
1070
|
+
`/tenant/sub-tenants/${subTenantId}/incoming-invoices`,
|
|
1071
|
+
params,
|
|
1072
|
+
requestOptions
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* List incoming invoices for a sub-tenant
|
|
1077
|
+
*
|
|
1078
|
+
* Returns a paginated list of purchase invoices received by the sub-tenant.
|
|
1079
|
+
*
|
|
1080
|
+
* @param subTenantId - Sub-tenant UUID
|
|
1081
|
+
* @param filters - Filter and pagination options
|
|
1082
|
+
* @param requestOptions - Optional request configuration
|
|
1083
|
+
* @returns Paginated list of invoices
|
|
1084
|
+
*
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```typescript
|
|
1087
|
+
* // List all pending invoices
|
|
1088
|
+
* const { data: invoices, meta } = await client.incomingInvoices.listForSubTenant(
|
|
1089
|
+
* 'sub-tenant-uuid',
|
|
1090
|
+
* { status: 'pending', per_page: 50 }
|
|
1091
|
+
* );
|
|
1092
|
+
*
|
|
1093
|
+
* console.log(`Found ${meta.total} pending invoices to review`);
|
|
1094
|
+
*
|
|
1095
|
+
* // Filter by supplier
|
|
1096
|
+
* const acmeInvoices = await client.incomingInvoices.listForSubTenant(
|
|
1097
|
+
* 'sub-tenant-uuid',
|
|
1098
|
+
* { seller_siret: '12345678901234' }
|
|
1099
|
+
* );
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
async listForSubTenant(subTenantId, filters = {}, requestOptions) {
|
|
1103
|
+
const query = {
|
|
1104
|
+
...filters,
|
|
1105
|
+
status: Array.isArray(filters.status) ? filters.status.join(",") : filters.status
|
|
1106
|
+
};
|
|
1107
|
+
return this.http.get(
|
|
1108
|
+
`/tenant/sub-tenants/${subTenantId}/incoming-invoices`,
|
|
1109
|
+
query,
|
|
1110
|
+
requestOptions
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Get a specific incoming invoice by ID
|
|
1115
|
+
*
|
|
1116
|
+
* @param invoiceId - Invoice UUID
|
|
1117
|
+
* @param requestOptions - Optional request configuration
|
|
1118
|
+
* @returns Invoice details
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* const { data: invoice } = await client.incomingInvoices.get('invoice-uuid');
|
|
1123
|
+
*
|
|
1124
|
+
* console.log('Invoice from:', invoice.seller.name);
|
|
1125
|
+
* console.log('Status:', invoice.status);
|
|
1126
|
+
* console.log('Amount:', invoice.total_ttc, invoice.currency);
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
async get(invoiceId, requestOptions) {
|
|
1130
|
+
return this.http.get(
|
|
1131
|
+
`/tenant/incoming-invoices/${invoiceId}`,
|
|
1132
|
+
void 0,
|
|
1133
|
+
requestOptions
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Accept an incoming invoice
|
|
1138
|
+
*
|
|
1139
|
+
* Marks the invoice as accepted, indicating approval for payment.
|
|
1140
|
+
* Optionally specify an expected payment date.
|
|
1141
|
+
*
|
|
1142
|
+
* @param invoiceId - Invoice UUID
|
|
1143
|
+
* @param input - Optional acceptance details
|
|
1144
|
+
* @param requestOptions - Optional request configuration
|
|
1145
|
+
* @returns Updated invoice
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```typescript
|
|
1149
|
+
* // Accept with payment date
|
|
1150
|
+
* const { data: invoice } = await client.incomingInvoices.accept(
|
|
1151
|
+
* 'invoice-uuid',
|
|
1152
|
+
* {
|
|
1153
|
+
* payment_date: '2026-02-15',
|
|
1154
|
+
* note: 'Approved by CFO'
|
|
1155
|
+
* }
|
|
1156
|
+
* );
|
|
1157
|
+
*
|
|
1158
|
+
* console.log('Invoice accepted:', invoice.status); // 'accepted'
|
|
1159
|
+
*
|
|
1160
|
+
* // Simple acceptance
|
|
1161
|
+
* await client.incomingInvoices.accept('invoice-uuid');
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
async accept(invoiceId, input, requestOptions) {
|
|
1165
|
+
return this.http.post(
|
|
1166
|
+
`/tenant/incoming-invoices/${invoiceId}/accept`,
|
|
1167
|
+
input,
|
|
1168
|
+
requestOptions
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Reject an incoming invoice
|
|
1173
|
+
*
|
|
1174
|
+
* Marks the invoice as rejected with a reason and optional code.
|
|
1175
|
+
*
|
|
1176
|
+
* @param invoiceId - Invoice UUID
|
|
1177
|
+
* @param reason - Reason for rejection
|
|
1178
|
+
* @param code - Optional standardized rejection code
|
|
1179
|
+
* @param requestOptions - Optional request configuration
|
|
1180
|
+
* @returns Updated invoice
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```typescript
|
|
1184
|
+
* const { data: invoice } = await client.incomingInvoices.reject(
|
|
1185
|
+
* 'invoice-uuid',
|
|
1186
|
+
* 'Amount does not match purchase order PO-2026-042',
|
|
1187
|
+
* 'incorrect_amount'
|
|
1188
|
+
* );
|
|
1189
|
+
*
|
|
1190
|
+
* console.log('Invoice rejected:', invoice.status); // 'rejected'
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
async reject(invoiceId, reason, code, requestOptions) {
|
|
1194
|
+
const input = { reason };
|
|
1195
|
+
if (code) {
|
|
1196
|
+
input.reason_code = code;
|
|
1197
|
+
}
|
|
1198
|
+
return this.http.post(
|
|
1199
|
+
`/tenant/incoming-invoices/${invoiceId}/reject`,
|
|
1200
|
+
input,
|
|
1201
|
+
requestOptions
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Mark an incoming invoice as paid
|
|
1206
|
+
*
|
|
1207
|
+
* Records payment information for an accepted invoice.
|
|
1208
|
+
* This is a mandatory step in the French e-invoicing lifecycle.
|
|
1209
|
+
*
|
|
1210
|
+
* @param invoiceId - Invoice UUID
|
|
1211
|
+
* @param input - Optional payment details
|
|
1212
|
+
* @param requestOptions - Optional request configuration
|
|
1213
|
+
* @returns Updated invoice with payment information
|
|
1214
|
+
*
|
|
1215
|
+
* @example
|
|
1216
|
+
* ```typescript
|
|
1217
|
+
* // Mark as paid with details
|
|
1218
|
+
* const { data: invoice } = await client.incomingInvoices.markPaid(
|
|
1219
|
+
* 'invoice-uuid',
|
|
1220
|
+
* {
|
|
1221
|
+
* payment_reference: 'VIR-2026-0150',
|
|
1222
|
+
* paid_at: '2026-02-14T14:30:00Z',
|
|
1223
|
+
* note: 'Payment via bank transfer'
|
|
1224
|
+
* }
|
|
1225
|
+
* );
|
|
1226
|
+
*
|
|
1227
|
+
* console.log('Invoice paid:', invoice.status); // 'paid'
|
|
1228
|
+
* console.log('Payment ref:', invoice.payment_reference);
|
|
1229
|
+
*
|
|
1230
|
+
* // Simple mark as paid (current date)
|
|
1231
|
+
* await client.incomingInvoices.markPaid('invoice-uuid');
|
|
1232
|
+
* ```
|
|
1233
|
+
*/
|
|
1234
|
+
async markPaid(invoiceId, input, requestOptions) {
|
|
1235
|
+
return this.http.post(
|
|
1236
|
+
`/tenant/incoming-invoices/${invoiceId}/mark-paid`,
|
|
1237
|
+
input,
|
|
1238
|
+
requestOptions
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Delete an incoming invoice
|
|
1243
|
+
*
|
|
1244
|
+
* Only invoices in 'pending' status can be deleted.
|
|
1245
|
+
*
|
|
1246
|
+
* @param invoiceId - Invoice UUID
|
|
1247
|
+
* @param requestOptions - Optional request configuration
|
|
1248
|
+
*
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```typescript
|
|
1251
|
+
* await client.incomingInvoices.delete('pending-invoice-uuid');
|
|
1252
|
+
* console.log('Incoming invoice deleted');
|
|
1253
|
+
* ```
|
|
1254
|
+
*/
|
|
1255
|
+
async delete(invoiceId, requestOptions) {
|
|
1256
|
+
return this.http.delete(
|
|
1257
|
+
`/tenant/incoming-invoices/${invoiceId}`,
|
|
1258
|
+
requestOptions
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Download incoming invoice as PDF
|
|
1263
|
+
*
|
|
1264
|
+
* @param invoiceId - Invoice UUID
|
|
1265
|
+
* @param requestOptions - Optional request configuration
|
|
1266
|
+
* @returns ArrayBuffer containing the PDF file
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```typescript
|
|
1270
|
+
* const pdfBuffer = await client.incomingInvoices.download('invoice-uuid');
|
|
1271
|
+
*
|
|
1272
|
+
* // Save to file (Node.js)
|
|
1273
|
+
* import { writeFileSync } from 'fs';
|
|
1274
|
+
* writeFileSync('supplier-invoice.pdf', Buffer.from(pdfBuffer));
|
|
1275
|
+
* ```
|
|
1276
|
+
*/
|
|
1277
|
+
async download(invoiceId, requestOptions) {
|
|
1278
|
+
return this.http.getRaw(
|
|
1279
|
+
`/tenant/incoming-invoices/${invoiceId}/download`,
|
|
1280
|
+
void 0,
|
|
1281
|
+
requestOptions
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
// src/resources/tenant-credit-notes.ts
|
|
1287
|
+
var TenantCreditNotesResource = class {
|
|
1288
|
+
constructor(http) {
|
|
1289
|
+
this.http = http;
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* List credit notes for a sub-tenant
|
|
1293
|
+
*
|
|
1294
|
+
* @param subTenantId - Sub-tenant UUID
|
|
1295
|
+
* @param options - Filter and pagination options
|
|
1296
|
+
* @param requestOptions - Request options
|
|
1297
|
+
* @returns Paginated list of credit notes
|
|
1298
|
+
*
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```typescript
|
|
1301
|
+
* const { data, meta } = await client.tenantCreditNotes.list('sub-tenant-uuid', {
|
|
1302
|
+
* status: 'sent',
|
|
1303
|
+
* date_from: '2024-01-01',
|
|
1304
|
+
* per_page: 50
|
|
1305
|
+
* });
|
|
1306
|
+
* console.log(`Found ${meta.total} credit notes`);
|
|
1307
|
+
* ```
|
|
1308
|
+
*/
|
|
1309
|
+
async list(subTenantId, options = {}, requestOptions) {
|
|
1310
|
+
return this.http.get(
|
|
1311
|
+
`/tenant/sub-tenants/${subTenantId}/credit-notes`,
|
|
1312
|
+
options,
|
|
1313
|
+
requestOptions
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Create a new credit note for a sub-tenant invoice
|
|
1318
|
+
*
|
|
1319
|
+
* @param subTenantId - Sub-tenant UUID
|
|
1320
|
+
* @param input - Credit note creation data
|
|
1321
|
+
* @param requestOptions - Request options
|
|
1322
|
+
* @returns Created credit note
|
|
1323
|
+
*
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* // Create a partial credit note
|
|
1327
|
+
* const { data: creditNote } = await client.tenantCreditNotes.create(
|
|
1328
|
+
* 'sub-tenant-uuid',
|
|
1329
|
+
* {
|
|
1330
|
+
* invoice_id: 'invoice-uuid',
|
|
1331
|
+
* reason: 'Product returned - damaged item',
|
|
1332
|
+
* type: 'partial',
|
|
1333
|
+
* items: [
|
|
1334
|
+
* { invoice_line_id: 'line-uuid-1', quantity: 2 }
|
|
1335
|
+
* ]
|
|
1336
|
+
* }
|
|
1337
|
+
* );
|
|
1338
|
+
*
|
|
1339
|
+
* // Create a total credit note
|
|
1340
|
+
* const { data: totalCreditNote } = await client.tenantCreditNotes.create(
|
|
1341
|
+
* 'sub-tenant-uuid',
|
|
1342
|
+
* {
|
|
1343
|
+
* invoice_id: 'invoice-uuid',
|
|
1344
|
+
* reason: 'Order cancelled',
|
|
1345
|
+
* type: 'total'
|
|
1346
|
+
* }
|
|
1347
|
+
* );
|
|
1348
|
+
* ```
|
|
1349
|
+
*/
|
|
1350
|
+
async create(subTenantId, input, requestOptions) {
|
|
1351
|
+
return this.http.post(
|
|
1352
|
+
`/tenant/sub-tenants/${subTenantId}/credit-notes`,
|
|
1353
|
+
input,
|
|
1354
|
+
requestOptions
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Get a specific credit note by ID
|
|
1359
|
+
*
|
|
1360
|
+
* @param creditNoteId - Credit note UUID
|
|
1361
|
+
* @param requestOptions - Request options
|
|
1362
|
+
* @returns Credit note details
|
|
1363
|
+
*
|
|
1364
|
+
* @example
|
|
1365
|
+
* ```typescript
|
|
1366
|
+
* const { data: creditNote } = await client.tenantCreditNotes.get('credit-note-uuid');
|
|
1367
|
+
* console.log('Credit note number:', creditNote.credit_note_number);
|
|
1368
|
+
* console.log('Total:', creditNote.total, creditNote.currency);
|
|
1369
|
+
* ```
|
|
1370
|
+
*/
|
|
1371
|
+
async get(creditNoteId, requestOptions) {
|
|
1372
|
+
return this.http.get(
|
|
1373
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
1374
|
+
void 0,
|
|
1375
|
+
requestOptions
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Update a credit note
|
|
1380
|
+
*
|
|
1381
|
+
* Only credit notes in 'draft' status can be updated.
|
|
1382
|
+
*
|
|
1383
|
+
* @param creditNoteId - Credit note UUID
|
|
1384
|
+
* @param input - Update data
|
|
1385
|
+
* @param requestOptions - Request options
|
|
1386
|
+
* @returns Updated credit note
|
|
1387
|
+
*
|
|
1388
|
+
* @example
|
|
1389
|
+
* ```typescript
|
|
1390
|
+
* const { data: creditNote } = await client.tenantCreditNotes.update(
|
|
1391
|
+
* 'credit-note-uuid',
|
|
1392
|
+
* {
|
|
1393
|
+
* reason: 'Updated reason: Customer complaint resolved',
|
|
1394
|
+
* items: [
|
|
1395
|
+
* { invoice_line_id: 'line-uuid', quantity: 3 }
|
|
1396
|
+
* ]
|
|
1397
|
+
* }
|
|
1398
|
+
* );
|
|
1399
|
+
* console.log('Credit note updated:', creditNote.reason);
|
|
1400
|
+
* ```
|
|
1401
|
+
*/
|
|
1402
|
+
async update(creditNoteId, input, requestOptions) {
|
|
1403
|
+
return this.http.patch(
|
|
1404
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
1405
|
+
input,
|
|
1406
|
+
requestOptions
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Send a credit note
|
|
1411
|
+
*
|
|
1412
|
+
* Changes the status from 'draft' to 'sent'.
|
|
1413
|
+
*
|
|
1414
|
+
* @param creditNoteId - Credit note UUID
|
|
1415
|
+
* @param requestOptions - Request options
|
|
1416
|
+
* @returns Updated credit note
|
|
1417
|
+
*
|
|
1418
|
+
* @example
|
|
1419
|
+
* ```typescript
|
|
1420
|
+
* const { data: sentCreditNote } = await client.tenantCreditNotes.send('credit-note-uuid');
|
|
1421
|
+
* console.log('Status:', sentCreditNote.status); // 'sent'
|
|
1422
|
+
* ```
|
|
1423
|
+
*/
|
|
1424
|
+
async send(creditNoteId, requestOptions) {
|
|
1425
|
+
return this.http.post(
|
|
1426
|
+
`/tenant/credit-notes/${creditNoteId}/send`,
|
|
1427
|
+
void 0,
|
|
1428
|
+
requestOptions
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Delete a credit note (draft only)
|
|
1433
|
+
*
|
|
1434
|
+
* Only credit notes with status 'draft' can be deleted.
|
|
1435
|
+
*
|
|
1436
|
+
* @param creditNoteId - Credit note UUID
|
|
1437
|
+
* @param requestOptions - Request options
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```typescript
|
|
1441
|
+
* await client.tenantCreditNotes.delete('credit-note-uuid');
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
async delete(creditNoteId, requestOptions) {
|
|
1445
|
+
return this.http.delete(
|
|
1446
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
1447
|
+
requestOptions
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Download credit note as PDF
|
|
1452
|
+
*
|
|
1453
|
+
* @param creditNoteId - Credit note UUID
|
|
1454
|
+
* @param requestOptions - Request options
|
|
1455
|
+
* @returns ArrayBuffer containing the PDF file
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```typescript
|
|
1459
|
+
* // Download credit note PDF
|
|
1460
|
+
* const pdfBuffer = await client.tenantCreditNotes.download('credit-note-uuid');
|
|
1461
|
+
*
|
|
1462
|
+
* // In Node.js, save to file:
|
|
1463
|
+
* import { writeFileSync } from 'fs';
|
|
1464
|
+
* writeFileSync('credit-note.pdf', Buffer.from(pdfBuffer));
|
|
1465
|
+
*
|
|
1466
|
+
* // In browser, trigger download:
|
|
1467
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
1468
|
+
* const url = URL.createObjectURL(blob);
|
|
1469
|
+
* const a = document.createElement('a');
|
|
1470
|
+
* a.href = url;
|
|
1471
|
+
* a.download = 'credit-note.pdf';
|
|
1472
|
+
* a.click();
|
|
1473
|
+
* ```
|
|
1474
|
+
*/
|
|
1475
|
+
async download(creditNoteId, requestOptions) {
|
|
1476
|
+
return this.http.getRaw(
|
|
1477
|
+
`/tenant/credit-notes/${creditNoteId}/download`,
|
|
1478
|
+
void 0,
|
|
1479
|
+
requestOptions
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Get remaining creditable amount for an invoice
|
|
1484
|
+
*
|
|
1485
|
+
* Returns information about how much can still be credited for an invoice,
|
|
1486
|
+
* including per-line breakdown.
|
|
1487
|
+
*
|
|
1488
|
+
* @param invoiceId - Invoice UUID
|
|
1489
|
+
* @param requestOptions - Request options
|
|
1490
|
+
* @returns Remaining creditable information
|
|
1491
|
+
*
|
|
1492
|
+
* @example
|
|
1493
|
+
* ```typescript
|
|
1494
|
+
* const remaining = await client.tenantCreditNotes.remainingCreditable('invoice-uuid');
|
|
1495
|
+
*
|
|
1496
|
+
* console.log('Invoice total:', remaining.invoice_total);
|
|
1497
|
+
* console.log('Already credited:', remaining.credited_total);
|
|
1498
|
+
* console.log('Remaining to credit:', remaining.remaining_total);
|
|
1499
|
+
*
|
|
1500
|
+
* // Check remaining quantity per line
|
|
1501
|
+
* remaining.lines.forEach(line => {
|
|
1502
|
+
* console.log(`${line.description}: ${line.remaining_quantity} remaining`);
|
|
1503
|
+
* });
|
|
1504
|
+
* ```
|
|
1505
|
+
*/
|
|
1506
|
+
async remainingCreditable(invoiceId, requestOptions) {
|
|
1507
|
+
return this.http.get(
|
|
1508
|
+
`/tenant/invoices/${invoiceId}/remaining-creditable`,
|
|
1509
|
+
void 0,
|
|
1510
|
+
requestOptions
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
// src/resources/fiscal.ts
|
|
1516
|
+
var FiscalResource = class {
|
|
1517
|
+
constructor(http) {
|
|
1518
|
+
this.http = http;
|
|
1519
|
+
}
|
|
1520
|
+
async compliance(requestOptions) {
|
|
1521
|
+
return this.http.get("/tenant/fiscal/compliance", void 0, requestOptions);
|
|
1522
|
+
}
|
|
1523
|
+
async integrity(options = {}, requestOptions) {
|
|
1524
|
+
return this.http.get("/tenant/fiscal/integrity", options, requestOptions);
|
|
1525
|
+
}
|
|
1526
|
+
async integrityHistory(options = {}, requestOptions) {
|
|
1527
|
+
return this.http.get("/tenant/fiscal/integrity/history", options, requestOptions);
|
|
1528
|
+
}
|
|
1529
|
+
async integrityForDate(date, requestOptions) {
|
|
1530
|
+
return this.http.get(`/tenant/fiscal/integrity/${date}`, void 0, requestOptions);
|
|
1531
|
+
}
|
|
1532
|
+
async closings(options = {}, requestOptions) {
|
|
1533
|
+
return this.http.get("/tenant/fiscal/closings", options, requestOptions);
|
|
1534
|
+
}
|
|
1535
|
+
async performDailyClosing(input = {}, requestOptions) {
|
|
1536
|
+
return this.http.post("/tenant/fiscal/closings/daily", input, requestOptions);
|
|
1537
|
+
}
|
|
1538
|
+
async fecExport(options, requestOptions) {
|
|
1539
|
+
return this.http.get("/tenant/fiscal/fec", options, requestOptions);
|
|
1540
|
+
}
|
|
1541
|
+
async fecDownload(options, requestOptions) {
|
|
1542
|
+
return this.http.getRaw("/tenant/fiscal/fec", { ...options, download: true }, requestOptions);
|
|
1543
|
+
}
|
|
1544
|
+
async attestation(year, requestOptions) {
|
|
1545
|
+
return this.http.get(`/tenant/fiscal/attestation/${year}`, void 0, requestOptions);
|
|
1546
|
+
}
|
|
1547
|
+
async attestationDownload(year, requestOptions) {
|
|
1548
|
+
return this.http.getRaw(`/tenant/fiscal/attestation/${year}/download`, void 0, requestOptions);
|
|
1549
|
+
}
|
|
1550
|
+
async entries(options = {}, requestOptions) {
|
|
1551
|
+
return this.http.get("/tenant/fiscal/entries", options, requestOptions);
|
|
1552
|
+
}
|
|
1553
|
+
async killSwitchStatus(requestOptions) {
|
|
1554
|
+
return this.http.get("/tenant/fiscal/kill-switch/status", void 0, requestOptions);
|
|
1555
|
+
}
|
|
1556
|
+
async killSwitchActivate(input, requestOptions) {
|
|
1557
|
+
return this.http.post("/tenant/fiscal/kill-switch/activate", input, requestOptions);
|
|
1558
|
+
}
|
|
1559
|
+
async killSwitchDeactivate(requestOptions) {
|
|
1560
|
+
return this.http.post("/tenant/fiscal/kill-switch/deactivate", void 0, requestOptions);
|
|
1561
|
+
}
|
|
1562
|
+
async anchors(options = {}, requestOptions) {
|
|
1563
|
+
return this.http.get("/tenant/fiscal/anchors", options, requestOptions);
|
|
1564
|
+
}
|
|
1565
|
+
async rules(options = {}, requestOptions) {
|
|
1566
|
+
return this.http.get("/tenant/fiscal/rules", options, requestOptions);
|
|
1567
|
+
}
|
|
1568
|
+
async ruleDetail(key, requestOptions) {
|
|
1569
|
+
return this.http.get(`/tenant/fiscal/rules/${key}`, void 0, requestOptions);
|
|
1570
|
+
}
|
|
1571
|
+
async ruleHistory(key, requestOptions) {
|
|
1572
|
+
return this.http.get(`/tenant/fiscal/rules/${key}/history`, void 0, requestOptions);
|
|
1573
|
+
}
|
|
1574
|
+
async createRule(input, requestOptions) {
|
|
1575
|
+
return this.http.post("/tenant/fiscal/rules", input, requestOptions);
|
|
1576
|
+
}
|
|
1577
|
+
async updateRule(id, input, requestOptions) {
|
|
1578
|
+
return this.http.post(`/tenant/fiscal/rules/${id}`, input, requestOptions);
|
|
1579
|
+
}
|
|
1580
|
+
async exportRules(options, requestOptions) {
|
|
1581
|
+
return this.http.get("/tenant/fiscal/rules/export", options, requestOptions);
|
|
1582
|
+
}
|
|
1583
|
+
async replayRules(input, requestOptions) {
|
|
1584
|
+
return this.http.post("/tenant/fiscal/rules/replay", input, requestOptions);
|
|
1585
|
+
}
|
|
1586
|
+
async forensicExport(options, requestOptions) {
|
|
1587
|
+
return this.http.get("/tenant/fiscal/forensic-export", options, requestOptions);
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
|
|
1591
|
+
// src/resources/billing.ts
|
|
1592
|
+
var BillingResource = class {
|
|
1593
|
+
constructor(http) {
|
|
1594
|
+
this.http = http;
|
|
1595
|
+
}
|
|
1596
|
+
async invoices(options = {}, requestOptions) {
|
|
1597
|
+
return this.http.get("/tenant/billing/invoices", options, requestOptions);
|
|
1598
|
+
}
|
|
1599
|
+
async showInvoice(invoiceId, requestOptions) {
|
|
1600
|
+
return this.http.get(`/tenant/billing/invoices/${invoiceId}`, void 0, requestOptions);
|
|
1601
|
+
}
|
|
1602
|
+
async downloadInvoice(invoiceId, requestOptions) {
|
|
1603
|
+
return this.http.getRaw(`/tenant/billing/invoices/${invoiceId}/download`, void 0, requestOptions);
|
|
1604
|
+
}
|
|
1605
|
+
async usage(options = {}, requestOptions) {
|
|
1606
|
+
return this.http.get("/tenant/billing/usage", options, requestOptions);
|
|
1607
|
+
}
|
|
1608
|
+
async topUp(input, requestOptions) {
|
|
1609
|
+
return this.http.post("/tenant/billing/top-up", input, requestOptions);
|
|
1610
|
+
}
|
|
1611
|
+
async confirmTopUp(input, requestOptions) {
|
|
1612
|
+
return this.http.post("/tenant/billing/top-up/confirm", input, requestOptions);
|
|
1613
|
+
}
|
|
1614
|
+
async transactions(options = {}, requestOptions) {
|
|
1615
|
+
return this.http.get("/tenant/billing/transactions", options, requestOptions);
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1619
|
+
// src/resources/stats.ts
|
|
1620
|
+
var StatsResource = class {
|
|
1621
|
+
constructor(http) {
|
|
1622
|
+
this.http = http;
|
|
1623
|
+
}
|
|
1624
|
+
async overview(options = {}, requestOptions) {
|
|
1625
|
+
return this.http.get("/tenant/stats/overview", options, requestOptions);
|
|
1626
|
+
}
|
|
1627
|
+
async monthly(options = {}, requestOptions) {
|
|
1628
|
+
return this.http.get("/tenant/stats/monthly", options, requestOptions);
|
|
1629
|
+
}
|
|
1630
|
+
async subTenantOverview(subTenantId, options = {}, requestOptions) {
|
|
1631
|
+
return this.http.get(`/tenant/sub-tenants/${subTenantId}/stats/overview`, options, requestOptions);
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1635
|
+
// src/resources/sub-tenants.ts
|
|
1636
|
+
var SubTenantsResource = class {
|
|
1637
|
+
constructor(http) {
|
|
1638
|
+
this.http = http;
|
|
1639
|
+
}
|
|
1640
|
+
async list(options = {}, requestOptions) {
|
|
1641
|
+
return this.http.get("/tenant/sub-tenants", options, requestOptions);
|
|
1642
|
+
}
|
|
1643
|
+
async create(input, requestOptions) {
|
|
1644
|
+
return this.http.post("/tenant/sub-tenants", input, requestOptions);
|
|
1645
|
+
}
|
|
1646
|
+
async get(id, requestOptions) {
|
|
1647
|
+
return this.http.get(`/tenant/sub-tenants/${id}`, void 0, requestOptions);
|
|
1648
|
+
}
|
|
1649
|
+
async update(id, input, requestOptions) {
|
|
1650
|
+
return this.http.patch(`/tenant/sub-tenants/${id}`, input, requestOptions);
|
|
1651
|
+
}
|
|
1652
|
+
async delete(id, requestOptions) {
|
|
1653
|
+
return this.http.delete(`/tenant/sub-tenants/${id}`, requestOptions);
|
|
1654
|
+
}
|
|
1655
|
+
async findByExternalId(externalId, requestOptions) {
|
|
1656
|
+
return this.http.get(`/tenant/sub-tenants/by-external-id/${externalId}`, void 0, requestOptions);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
// src/tenant-client.ts
|
|
1661
|
+
var ScellTenantClient = class {
|
|
1662
|
+
http;
|
|
1663
|
+
/** Direct invoices resource */
|
|
1664
|
+
directInvoices;
|
|
1665
|
+
/** Direct credit notes resource */
|
|
1666
|
+
directCreditNotes;
|
|
1667
|
+
/** Incoming invoices resource */
|
|
1668
|
+
incomingInvoices;
|
|
1669
|
+
/** Sub-tenant credit notes resource */
|
|
1670
|
+
subTenantCreditNotes;
|
|
1671
|
+
/** Fiscal compliance resource (LF 2026) */
|
|
1672
|
+
fiscal;
|
|
1673
|
+
/** Billing resource */
|
|
1674
|
+
billing;
|
|
1675
|
+
/** Stats resource */
|
|
1676
|
+
stats;
|
|
1677
|
+
/** Sub-tenants resource */
|
|
1678
|
+
subTenants;
|
|
1679
|
+
/**
|
|
1680
|
+
* Create a new Scell Tenant Client
|
|
1681
|
+
*
|
|
1682
|
+
* @param tenantKey - Your tenant API key (from dashboard)
|
|
1683
|
+
* @param config - Optional client configuration
|
|
1684
|
+
*/
|
|
1685
|
+
constructor(tenantKey, config = {}) {
|
|
1686
|
+
this.http = new HttpClient("tenant-key", tenantKey, config);
|
|
1687
|
+
this.directInvoices = new TenantDirectInvoicesResource(this.http);
|
|
1688
|
+
this.directCreditNotes = new TenantDirectCreditNotesResource(this.http);
|
|
1689
|
+
this.incomingInvoices = new TenantIncomingInvoicesResource(this.http);
|
|
1690
|
+
this.subTenantCreditNotes = new TenantCreditNotesResource(this.http);
|
|
1691
|
+
this.fiscal = new FiscalResource(this.http);
|
|
1692
|
+
this.billing = new BillingResource(this.http);
|
|
1693
|
+
this.stats = new StatsResource(this.http);
|
|
1694
|
+
this.subTenants = new SubTenantsResource(this.http);
|
|
1695
|
+
}
|
|
1696
|
+
// ── Tenant Profile Methods ──────────────────────────────
|
|
1697
|
+
/** Get tenant profile */
|
|
1698
|
+
async me(requestOptions) {
|
|
1699
|
+
return this.http.get("/tenant/me", void 0, requestOptions);
|
|
1700
|
+
}
|
|
1701
|
+
/** Update tenant profile */
|
|
1702
|
+
async updateProfile(input, requestOptions) {
|
|
1703
|
+
return this.http.post("/tenant/me", input, requestOptions);
|
|
1704
|
+
}
|
|
1705
|
+
/** Get tenant balance */
|
|
1706
|
+
async balance(requestOptions) {
|
|
1707
|
+
return this.http.get("/tenant/balance", void 0, requestOptions);
|
|
1708
|
+
}
|
|
1709
|
+
/** Get quick stats */
|
|
1710
|
+
async quickStats(requestOptions) {
|
|
1711
|
+
return this.http.get("/tenant/stats", void 0, requestOptions);
|
|
1712
|
+
}
|
|
1713
|
+
/** Regenerate tenant key */
|
|
1714
|
+
async regenerateKey(requestOptions) {
|
|
1715
|
+
return this.http.post("/tenant/regenerate-key", void 0, requestOptions);
|
|
1716
|
+
}
|
|
406
1717
|
};
|
|
407
1718
|
|
|
408
1719
|
// src/resources/api-keys.ts
|
|
@@ -1137,6 +2448,188 @@ var InvoicesResource = class {
|
|
|
1137
2448
|
async convert(input, requestOptions) {
|
|
1138
2449
|
return this.http.post("/invoices/convert", input, requestOptions);
|
|
1139
2450
|
}
|
|
2451
|
+
/**
|
|
2452
|
+
* List incoming invoices (from suppliers)
|
|
2453
|
+
*
|
|
2454
|
+
* Returns invoices where your company is the buyer.
|
|
2455
|
+
*
|
|
2456
|
+
* @param params - Filter and pagination options
|
|
2457
|
+
* @param requestOptions - Request options
|
|
2458
|
+
* @returns Paginated list of incoming invoices
|
|
2459
|
+
*
|
|
2460
|
+
* @example
|
|
2461
|
+
* ```typescript
|
|
2462
|
+
* // List all incoming invoices
|
|
2463
|
+
* const { data, meta } = await client.invoices.incoming({
|
|
2464
|
+
* status: 'pending',
|
|
2465
|
+
* per_page: 50
|
|
2466
|
+
* });
|
|
2467
|
+
* console.log(`Found ${meta.total} incoming invoices`);
|
|
2468
|
+
*
|
|
2469
|
+
* // Filter by seller
|
|
2470
|
+
* const fromSupplier = await client.invoices.incoming({
|
|
2471
|
+
* seller_siret: '12345678901234'
|
|
2472
|
+
* });
|
|
2473
|
+
* ```
|
|
2474
|
+
*/
|
|
2475
|
+
async incoming(params = {}, requestOptions) {
|
|
2476
|
+
return this.http.get(
|
|
2477
|
+
"/invoices/incoming",
|
|
2478
|
+
params,
|
|
2479
|
+
requestOptions
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Accept an incoming invoice
|
|
2484
|
+
*
|
|
2485
|
+
* Mark an incoming invoice as accepted, optionally specifying a payment date.
|
|
2486
|
+
*
|
|
2487
|
+
* @param id - Invoice UUID
|
|
2488
|
+
* @param data - Optional acceptance data
|
|
2489
|
+
* @param requestOptions - Request options
|
|
2490
|
+
* @returns Updated invoice
|
|
2491
|
+
*
|
|
2492
|
+
* @example
|
|
2493
|
+
* ```typescript
|
|
2494
|
+
* // Accept with payment date
|
|
2495
|
+
* const { data: invoice } = await client.invoices.accept('invoice-uuid', {
|
|
2496
|
+
* payment_date: '2024-02-15',
|
|
2497
|
+
* note: 'Approved by accounting'
|
|
2498
|
+
* });
|
|
2499
|
+
*
|
|
2500
|
+
* // Simple acceptance
|
|
2501
|
+
* await client.invoices.accept('invoice-uuid');
|
|
2502
|
+
* ```
|
|
2503
|
+
*/
|
|
2504
|
+
async accept(id, data, requestOptions) {
|
|
2505
|
+
return this.http.post(
|
|
2506
|
+
`/invoices/${id}/accept`,
|
|
2507
|
+
data,
|
|
2508
|
+
requestOptions
|
|
2509
|
+
);
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Reject an incoming invoice
|
|
2513
|
+
*
|
|
2514
|
+
* Mark an incoming invoice as rejected with a reason.
|
|
2515
|
+
*
|
|
2516
|
+
* @param id - Invoice UUID
|
|
2517
|
+
* @param data - Rejection details
|
|
2518
|
+
* @param requestOptions - Request options
|
|
2519
|
+
* @returns Updated invoice
|
|
2520
|
+
*
|
|
2521
|
+
* @example
|
|
2522
|
+
* ```typescript
|
|
2523
|
+
* const { data: invoice } = await client.invoices.reject('invoice-uuid', {
|
|
2524
|
+
* reason: 'Invoice amount does not match purchase order',
|
|
2525
|
+
* reason_code: 'incorrect_amount'
|
|
2526
|
+
* });
|
|
2527
|
+
* ```
|
|
2528
|
+
*/
|
|
2529
|
+
async reject(id, data, requestOptions) {
|
|
2530
|
+
return this.http.post(
|
|
2531
|
+
`/invoices/${id}/reject`,
|
|
2532
|
+
data,
|
|
2533
|
+
requestOptions
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Dispute an incoming invoice
|
|
2538
|
+
*
|
|
2539
|
+
* Open a dispute on an incoming invoice for resolution.
|
|
2540
|
+
*
|
|
2541
|
+
* @param id - Invoice UUID
|
|
2542
|
+
* @param data - Dispute details
|
|
2543
|
+
* @param requestOptions - Request options
|
|
2544
|
+
* @returns Updated invoice
|
|
2545
|
+
*
|
|
2546
|
+
* @example
|
|
2547
|
+
* ```typescript
|
|
2548
|
+
* const { data: invoice } = await client.invoices.dispute('invoice-uuid', {
|
|
2549
|
+
* reason: 'Billed amount exceeds agreed price',
|
|
2550
|
+
* dispute_type: 'amount_dispute',
|
|
2551
|
+
* expected_amount: 950.00
|
|
2552
|
+
* });
|
|
2553
|
+
* ```
|
|
2554
|
+
*/
|
|
2555
|
+
async dispute(id, data, requestOptions) {
|
|
2556
|
+
return this.http.post(
|
|
2557
|
+
`/invoices/${id}/dispute`,
|
|
2558
|
+
data,
|
|
2559
|
+
requestOptions
|
|
2560
|
+
);
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* Mark an incoming invoice as paid
|
|
2564
|
+
*
|
|
2565
|
+
* This is a mandatory step in the French e-invoicing lifecycle for incoming invoices.
|
|
2566
|
+
* Once marked as paid, the invoice status changes to 'paid' and payment details are recorded.
|
|
2567
|
+
*
|
|
2568
|
+
* @param id - Invoice UUID
|
|
2569
|
+
* @param data - Optional payment details (reference, date, note)
|
|
2570
|
+
* @param requestOptions - Request options
|
|
2571
|
+
* @returns Updated invoice with payment information
|
|
2572
|
+
*
|
|
2573
|
+
* @example
|
|
2574
|
+
* ```typescript
|
|
2575
|
+
* // Mark as paid with payment details
|
|
2576
|
+
* const { data: invoice } = await client.invoices.markPaid('invoice-uuid', {
|
|
2577
|
+
* payment_reference: 'VIR-2026-0124',
|
|
2578
|
+
* paid_at: '2026-01-24T10:30:00Z',
|
|
2579
|
+
* note: 'Payment received via bank transfer'
|
|
2580
|
+
* });
|
|
2581
|
+
*
|
|
2582
|
+
* // Simple mark as paid (uses current date/time)
|
|
2583
|
+
* await client.invoices.markPaid('invoice-uuid');
|
|
2584
|
+
* ```
|
|
2585
|
+
*/
|
|
2586
|
+
async markPaid(id, data, requestOptions) {
|
|
2587
|
+
return this.http.post(
|
|
2588
|
+
`/invoices/${id}/mark-paid`,
|
|
2589
|
+
data,
|
|
2590
|
+
requestOptions
|
|
2591
|
+
);
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Download invoice source file as binary content
|
|
2595
|
+
*
|
|
2596
|
+
* Downloads the original invoice file (PDF with embedded XML for Factur-X,
|
|
2597
|
+
* or standalone XML for UBL/CII formats).
|
|
2598
|
+
*
|
|
2599
|
+
* @param id - Invoice UUID
|
|
2600
|
+
* @param format - File format to download: 'pdf' (default) or 'xml'
|
|
2601
|
+
* @param requestOptions - Request options
|
|
2602
|
+
* @returns ArrayBuffer containing the file content
|
|
2603
|
+
*
|
|
2604
|
+
* @example
|
|
2605
|
+
* ```typescript
|
|
2606
|
+
* // Download invoice as PDF (Factur-X)
|
|
2607
|
+
* const pdfBuffer = await client.invoices.downloadFile('invoice-uuid');
|
|
2608
|
+
*
|
|
2609
|
+
* // In Node.js, save to file:
|
|
2610
|
+
* import { writeFileSync } from 'fs';
|
|
2611
|
+
* writeFileSync('invoice.pdf', Buffer.from(pdfBuffer));
|
|
2612
|
+
*
|
|
2613
|
+
* // Download XML version (UBL/CII)
|
|
2614
|
+
* const xmlBuffer = await client.invoices.downloadFile('invoice-uuid', 'xml');
|
|
2615
|
+
* writeFileSync('invoice.xml', Buffer.from(xmlBuffer));
|
|
2616
|
+
*
|
|
2617
|
+
* // In browser, trigger download:
|
|
2618
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
2619
|
+
* const url = URL.createObjectURL(blob);
|
|
2620
|
+
* const a = document.createElement('a');
|
|
2621
|
+
* a.href = url;
|
|
2622
|
+
* a.download = 'invoice.pdf';
|
|
2623
|
+
* a.click();
|
|
2624
|
+
* ```
|
|
2625
|
+
*/
|
|
2626
|
+
async downloadFile(id, format = "pdf", requestOptions) {
|
|
2627
|
+
return this.http.getRaw(
|
|
2628
|
+
`/invoices/${id}/download`,
|
|
2629
|
+
{ format },
|
|
2630
|
+
requestOptions
|
|
2631
|
+
);
|
|
2632
|
+
}
|
|
1140
2633
|
};
|
|
1141
2634
|
|
|
1142
2635
|
// src/resources/signatures.ts
|
|
@@ -1721,6 +3214,8 @@ var ScellApiClient = class {
|
|
|
1721
3214
|
invoices;
|
|
1722
3215
|
/** Signature operations (create, download, remind, cancel) */
|
|
1723
3216
|
signatures;
|
|
3217
|
+
/** Tenant credit notes operations (create, send, download) */
|
|
3218
|
+
tenantCreditNotes;
|
|
1724
3219
|
/**
|
|
1725
3220
|
* Create a new Scell API Client
|
|
1726
3221
|
*
|
|
@@ -1742,12 +3237,14 @@ var ScellApiClient = class {
|
|
|
1742
3237
|
this.http = new HttpClient("api-key", apiKey, config);
|
|
1743
3238
|
this.invoices = new InvoicesResource(this.http);
|
|
1744
3239
|
this.signatures = new SignaturesResource(this.http);
|
|
3240
|
+
this.tenantCreditNotes = new TenantCreditNotesResource(this.http);
|
|
1745
3241
|
}
|
|
1746
3242
|
};
|
|
1747
3243
|
|
|
1748
3244
|
exports.ScellApiClient = ScellApiClient;
|
|
1749
3245
|
exports.ScellAuth = ScellAuth;
|
|
1750
3246
|
exports.ScellClient = ScellClient;
|
|
3247
|
+
exports.ScellTenantClient = ScellTenantClient;
|
|
1751
3248
|
exports.ScellWebhooks = ScellWebhooks;
|
|
1752
3249
|
exports.createRetryWrapper = createRetryWrapper;
|
|
1753
3250
|
exports.withRetry = withRetry;
|