@scell/sdk 1.0.0 → 1.2.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 CHANGED
@@ -259,6 +259,57 @@ const { data: trail, integrity_valid } = await apiClient.invoices.auditTrail(inv
259
259
  await apiClient.invoices.convert({ invoice_id: invoiceId, target_format: 'ubl' });
260
260
  ```
261
261
 
262
+ ### Incoming Invoices (Supplier Invoices)
263
+
264
+ ```typescript
265
+ // List incoming invoices
266
+ const { data: incoming, meta } = await apiClient.invoices.incoming({
267
+ status: 'pending',
268
+ seller_siret: '12345678901234',
269
+ from: '2024-01-01',
270
+ min_amount: 100,
271
+ per_page: 50,
272
+ });
273
+
274
+ console.log(`Found ${meta.total} incoming invoices`);
275
+
276
+ // Accept an incoming invoice
277
+ const { data: accepted } = await apiClient.invoices.accept(invoiceId, {
278
+ payment_date: '2024-02-15',
279
+ note: 'Approved by accounting department',
280
+ });
281
+
282
+ // Reject an incoming invoice
283
+ const { data: rejected } = await apiClient.invoices.reject(invoiceId, {
284
+ reason: 'Invoice amount does not match purchase order #PO-2024-001',
285
+ reason_code: 'incorrect_amount',
286
+ });
287
+
288
+ // Dispute an incoming invoice
289
+ const { data: disputed } = await apiClient.invoices.dispute(invoiceId, {
290
+ reason: 'Billed amount exceeds agreed price by 50 EUR',
291
+ dispute_type: 'amount_dispute',
292
+ expected_amount: 950.00,
293
+ });
294
+
295
+ // Mark an invoice as paid (mandatory in French e-invoicing lifecycle)
296
+ const { data: paidInvoice } = await apiClient.invoices.markPaid(invoiceId, {
297
+ payment_reference: 'VIR-2026-0124',
298
+ paid_at: '2026-01-24T10:30:00Z',
299
+ note: 'Payment received via bank transfer',
300
+ });
301
+
302
+ // Download invoice file as PDF (Factur-X with embedded XML)
303
+ const pdfBuffer = await apiClient.invoices.downloadFile(invoiceId);
304
+ // In Node.js:
305
+ import { writeFileSync } from 'fs';
306
+ writeFileSync('invoice.pdf', Buffer.from(pdfBuffer));
307
+
308
+ // Download XML version (UBL/CII standalone)
309
+ const xmlBuffer = await apiClient.invoices.downloadFile(invoiceId, 'xml');
310
+ writeFileSync('invoice.xml', Buffer.from(xmlBuffer));
311
+ ```
312
+
262
313
  ### Signatures
263
314
 
264
315
  ```typescript
@@ -412,6 +463,12 @@ const result = await withRetry(
412
463
  | `invoice.accepted` | Invoice accepted |
413
464
  | `invoice.rejected` | Invoice rejected |
414
465
  | `invoice.error` | Invoice processing error |
466
+ | `invoice.incoming.received` | Incoming invoice received from supplier |
467
+ | `invoice.incoming.validated` | Incoming invoice validated |
468
+ | `invoice.incoming.accepted` | Incoming invoice accepted |
469
+ | `invoice.incoming.rejected` | Incoming invoice rejected |
470
+ | `invoice.incoming.disputed` | Incoming invoice disputed |
471
+ | `invoice.incoming.paid` | Incoming invoice marked as paid |
415
472
  | `signature.created` | Signature request created |
416
473
  | `signature.waiting` | Waiting for signers |
417
474
  | `signature.signed` | A signer has signed |
@@ -431,17 +488,30 @@ import type {
431
488
  Invoice,
432
489
  InvoiceStatus,
433
490
  InvoiceDirection,
491
+ InvoiceFileFormat,
434
492
  CreateInvoiceInput,
493
+ // Incoming invoices
494
+ IncomingInvoiceParams,
495
+ AcceptInvoiceInput,
496
+ RejectInvoiceInput,
497
+ DisputeInvoiceInput,
498
+ MarkPaidInput,
499
+ RejectionCode,
500
+ DisputeType,
501
+ // Signatures
435
502
  Signature,
436
503
  SignatureStatus,
437
504
  CreateSignatureInput,
438
505
  Signer,
439
- Company,
440
- Balance,
441
- Transaction,
506
+ // Webhooks
442
507
  Webhook,
443
508
  WebhookEvent,
444
509
  WebhookPayload,
510
+ InvoiceIncomingPaidPayload,
511
+ // Other
512
+ Company,
513
+ Balance,
514
+ Transaction,
445
515
  } from '@scell/sdk';
446
516
  ```
447
517
 
package/dist/index.d.mts CHANGED
@@ -131,6 +131,17 @@ declare class HttpClient {
131
131
  * DELETE request
132
132
  */
133
133
  delete<T>(path: string, options?: RequestOptions): Promise<T>;
134
+ /**
135
+ * GET request that returns raw binary data as ArrayBuffer
136
+ *
137
+ * Use this for downloading files (PDF, XML, etc.)
138
+ *
139
+ * @param path - API endpoint path
140
+ * @param query - Query parameters
141
+ * @param options - Request options
142
+ * @returns ArrayBuffer containing the file content
143
+ */
144
+ getRaw(path: string, query?: Record<string, string | number | boolean | undefined>, options?: RequestOptions): Promise<ArrayBuffer>;
134
145
  }
135
146
 
136
147
  /**
@@ -996,7 +1007,7 @@ type InvoiceFormat = 'facturx' | 'ubl' | 'cii';
996
1007
  /**
997
1008
  * Invoice status
998
1009
  */
999
- type InvoiceStatus = 'draft' | 'pending' | 'validated' | 'converted' | 'transmitted' | 'accepted' | 'rejected' | 'error';
1010
+ type InvoiceStatus = 'draft' | 'pending' | 'validated' | 'converted' | 'transmitted' | 'accepted' | 'rejected' | 'paid' | 'disputed' | 'cancelled' | 'error';
1000
1011
  /**
1001
1012
  * Invoice download file type
1002
1013
  */
@@ -1049,6 +1060,12 @@ interface Invoice {
1049
1060
  validated_at: DateTimeString | null;
1050
1061
  transmitted_at: DateTimeString | null;
1051
1062
  completed_at: DateTimeString | null;
1063
+ /** Date when the invoice was marked as paid (ISO 8601) */
1064
+ paid_at: DateTimeString | null;
1065
+ /** Payment reference (bank transfer ID, check number, etc.) */
1066
+ payment_reference: string | null;
1067
+ /** Optional note about the payment */
1068
+ payment_note: string | null;
1052
1069
  }
1053
1070
  /**
1054
1071
  * Invoice line input for creation
@@ -1145,6 +1162,71 @@ interface AuditTrailResponse {
1145
1162
  data: AuditTrailEntry[];
1146
1163
  integrity_valid: boolean;
1147
1164
  }
1165
+ /**
1166
+ * Incoming invoice list filter options
1167
+ */
1168
+ interface IncomingInvoiceParams {
1169
+ status?: InvoiceStatus | undefined;
1170
+ seller_siret?: Siret | undefined;
1171
+ from?: DateString | undefined;
1172
+ to?: DateString | undefined;
1173
+ min_amount?: number | undefined;
1174
+ max_amount?: number | undefined;
1175
+ page?: number | undefined;
1176
+ per_page?: number | undefined;
1177
+ }
1178
+ /**
1179
+ * Rejection reason code for incoming invoices
1180
+ */
1181
+ type RejectionCode = 'incorrect_amount' | 'duplicate' | 'unknown_order' | 'incorrect_vat' | 'other';
1182
+ /**
1183
+ * Dispute type for incoming invoices
1184
+ */
1185
+ type DisputeType = 'amount_dispute' | 'quality_dispute' | 'delivery_dispute' | 'other';
1186
+ /**
1187
+ * Input for accepting an incoming invoice
1188
+ */
1189
+ interface AcceptInvoiceInput {
1190
+ /** Expected payment date (YYYY-MM-DD) */
1191
+ payment_date?: DateString | undefined;
1192
+ /** Optional note about the acceptance */
1193
+ note?: string | undefined;
1194
+ }
1195
+ /**
1196
+ * Input for rejecting an incoming invoice
1197
+ */
1198
+ interface RejectInvoiceInput {
1199
+ /** Reason for rejection */
1200
+ reason: string;
1201
+ /** Standardized rejection code */
1202
+ reason_code: RejectionCode;
1203
+ }
1204
+ /**
1205
+ * Input for disputing an incoming invoice
1206
+ */
1207
+ interface DisputeInvoiceInput {
1208
+ /** Reason for the dispute */
1209
+ reason: string;
1210
+ /** Type of dispute */
1211
+ dispute_type: DisputeType;
1212
+ /** Expected correct amount (if amount dispute) */
1213
+ expected_amount?: number | undefined;
1214
+ }
1215
+ /**
1216
+ * Input for marking an incoming invoice as paid
1217
+ */
1218
+ interface MarkPaidInput {
1219
+ /** Payment reference (bank transfer ID, check number, etc.) */
1220
+ payment_reference?: string | undefined;
1221
+ /** Payment date (ISO 8601) - defaults to current date/time if not provided */
1222
+ paid_at?: DateTimeString | undefined;
1223
+ /** Optional note about the payment */
1224
+ note?: string | undefined;
1225
+ }
1226
+ /**
1227
+ * Invoice file download format
1228
+ */
1229
+ type InvoiceFileFormat = 'pdf' | 'xml';
1148
1230
 
1149
1231
  /**
1150
1232
  * Invoices Resource
@@ -1319,6 +1401,152 @@ declare class InvoicesResource {
1319
1401
  invoice_id: string;
1320
1402
  target_format: string;
1321
1403
  }>;
1404
+ /**
1405
+ * List incoming invoices (from suppliers)
1406
+ *
1407
+ * Returns invoices where your company is the buyer.
1408
+ *
1409
+ * @param params - Filter and pagination options
1410
+ * @param requestOptions - Request options
1411
+ * @returns Paginated list of incoming invoices
1412
+ *
1413
+ * @example
1414
+ * ```typescript
1415
+ * // List all incoming invoices
1416
+ * const { data, meta } = await client.invoices.incoming({
1417
+ * status: 'pending',
1418
+ * per_page: 50
1419
+ * });
1420
+ * console.log(`Found ${meta.total} incoming invoices`);
1421
+ *
1422
+ * // Filter by seller
1423
+ * const fromSupplier = await client.invoices.incoming({
1424
+ * seller_siret: '12345678901234'
1425
+ * });
1426
+ * ```
1427
+ */
1428
+ incoming(params?: IncomingInvoiceParams, requestOptions?: RequestOptions): Promise<PaginatedResponse<Invoice>>;
1429
+ /**
1430
+ * Accept an incoming invoice
1431
+ *
1432
+ * Mark an incoming invoice as accepted, optionally specifying a payment date.
1433
+ *
1434
+ * @param id - Invoice UUID
1435
+ * @param data - Optional acceptance data
1436
+ * @param requestOptions - Request options
1437
+ * @returns Updated invoice
1438
+ *
1439
+ * @example
1440
+ * ```typescript
1441
+ * // Accept with payment date
1442
+ * const { data: invoice } = await client.invoices.accept('invoice-uuid', {
1443
+ * payment_date: '2024-02-15',
1444
+ * note: 'Approved by accounting'
1445
+ * });
1446
+ *
1447
+ * // Simple acceptance
1448
+ * await client.invoices.accept('invoice-uuid');
1449
+ * ```
1450
+ */
1451
+ accept(id: string, data?: AcceptInvoiceInput, requestOptions?: RequestOptions): Promise<SingleResponse<Invoice>>;
1452
+ /**
1453
+ * Reject an incoming invoice
1454
+ *
1455
+ * Mark an incoming invoice as rejected with a reason.
1456
+ *
1457
+ * @param id - Invoice UUID
1458
+ * @param data - Rejection details
1459
+ * @param requestOptions - Request options
1460
+ * @returns Updated invoice
1461
+ *
1462
+ * @example
1463
+ * ```typescript
1464
+ * const { data: invoice } = await client.invoices.reject('invoice-uuid', {
1465
+ * reason: 'Invoice amount does not match purchase order',
1466
+ * reason_code: 'incorrect_amount'
1467
+ * });
1468
+ * ```
1469
+ */
1470
+ reject(id: string, data: RejectInvoiceInput, requestOptions?: RequestOptions): Promise<SingleResponse<Invoice>>;
1471
+ /**
1472
+ * Dispute an incoming invoice
1473
+ *
1474
+ * Open a dispute on an incoming invoice for resolution.
1475
+ *
1476
+ * @param id - Invoice UUID
1477
+ * @param data - Dispute details
1478
+ * @param requestOptions - Request options
1479
+ * @returns Updated invoice
1480
+ *
1481
+ * @example
1482
+ * ```typescript
1483
+ * const { data: invoice } = await client.invoices.dispute('invoice-uuid', {
1484
+ * reason: 'Billed amount exceeds agreed price',
1485
+ * dispute_type: 'amount_dispute',
1486
+ * expected_amount: 950.00
1487
+ * });
1488
+ * ```
1489
+ */
1490
+ dispute(id: string, data: DisputeInvoiceInput, requestOptions?: RequestOptions): Promise<SingleResponse<Invoice>>;
1491
+ /**
1492
+ * Mark an incoming invoice as paid
1493
+ *
1494
+ * This is a mandatory step in the French e-invoicing lifecycle for incoming invoices.
1495
+ * Once marked as paid, the invoice status changes to 'paid' and payment details are recorded.
1496
+ *
1497
+ * @param id - Invoice UUID
1498
+ * @param data - Optional payment details (reference, date, note)
1499
+ * @param requestOptions - Request options
1500
+ * @returns Updated invoice with payment information
1501
+ *
1502
+ * @example
1503
+ * ```typescript
1504
+ * // Mark as paid with payment details
1505
+ * const { data: invoice } = await client.invoices.markPaid('invoice-uuid', {
1506
+ * payment_reference: 'VIR-2026-0124',
1507
+ * paid_at: '2026-01-24T10:30:00Z',
1508
+ * note: 'Payment received via bank transfer'
1509
+ * });
1510
+ *
1511
+ * // Simple mark as paid (uses current date/time)
1512
+ * await client.invoices.markPaid('invoice-uuid');
1513
+ * ```
1514
+ */
1515
+ markPaid(id: string, data?: MarkPaidInput, requestOptions?: RequestOptions): Promise<SingleResponse<Invoice>>;
1516
+ /**
1517
+ * Download invoice source file as binary content
1518
+ *
1519
+ * Downloads the original invoice file (PDF with embedded XML for Factur-X,
1520
+ * or standalone XML for UBL/CII formats).
1521
+ *
1522
+ * @param id - Invoice UUID
1523
+ * @param format - File format to download: 'pdf' (default) or 'xml'
1524
+ * @param requestOptions - Request options
1525
+ * @returns ArrayBuffer containing the file content
1526
+ *
1527
+ * @example
1528
+ * ```typescript
1529
+ * // Download invoice as PDF (Factur-X)
1530
+ * const pdfBuffer = await client.invoices.downloadFile('invoice-uuid');
1531
+ *
1532
+ * // In Node.js, save to file:
1533
+ * import { writeFileSync } from 'fs';
1534
+ * writeFileSync('invoice.pdf', Buffer.from(pdfBuffer));
1535
+ *
1536
+ * // Download XML version (UBL/CII)
1537
+ * const xmlBuffer = await client.invoices.downloadFile('invoice-uuid', 'xml');
1538
+ * writeFileSync('invoice.xml', Buffer.from(xmlBuffer));
1539
+ *
1540
+ * // In browser, trigger download:
1541
+ * const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
1542
+ * const url = URL.createObjectURL(blob);
1543
+ * const a = document.createElement('a');
1544
+ * a.href = url;
1545
+ * a.download = 'invoice.pdf';
1546
+ * a.click();
1547
+ * ```
1548
+ */
1549
+ downloadFile(id: string, format?: InvoiceFileFormat, requestOptions?: RequestOptions): Promise<ArrayBuffer>;
1322
1550
  }
1323
1551
 
1324
1552
  /**
@@ -1627,7 +1855,7 @@ declare class SignaturesResource {
1627
1855
  /**
1628
1856
  * Available webhook events
1629
1857
  */
1630
- type WebhookEvent = 'invoice.created' | 'invoice.validated' | 'invoice.transmitted' | 'invoice.accepted' | 'invoice.rejected' | 'invoice.error' | 'signature.created' | 'signature.waiting' | 'signature.signed' | 'signature.completed' | 'signature.refused' | 'signature.expired' | 'signature.error' | 'balance.low' | 'balance.critical';
1858
+ type WebhookEvent = 'invoice.created' | 'invoice.validated' | 'invoice.transmitted' | 'invoice.accepted' | 'invoice.rejected' | 'invoice.error' | 'invoice.incoming.received' | 'invoice.incoming.validated' | 'invoice.incoming.accepted' | 'invoice.incoming.rejected' | 'invoice.incoming.disputed' | 'invoice.incoming.paid' | 'signature.created' | 'signature.waiting' | 'signature.signed' | 'signature.completed' | 'signature.refused' | 'signature.expired' | 'signature.error' | 'balance.low' | 'balance.critical';
1631
1859
  /**
1632
1860
  * Webhook entity
1633
1861
  */
@@ -1739,6 +1967,27 @@ interface BalanceWebhookData {
1739
1967
  currency: string;
1740
1968
  threshold: number;
1741
1969
  }
1970
+ /**
1971
+ * Invoice incoming paid webhook payload data
1972
+ */
1973
+ interface InvoiceIncomingPaidPayload {
1974
+ /** Invoice UUID */
1975
+ invoice_id: string;
1976
+ /** Invoice number */
1977
+ invoice_number: string;
1978
+ /** Seller company name */
1979
+ seller_name: string;
1980
+ /** Seller SIRET (14 digits) */
1981
+ seller_siret: string;
1982
+ /** Total amount including tax */
1983
+ total_amount: number;
1984
+ /** Currency code (ISO 4217) */
1985
+ currency: string;
1986
+ /** Date when the invoice was marked as paid (ISO 8601) */
1987
+ paid_at: string;
1988
+ /** Payment reference (if provided) */
1989
+ payment_reference?: string | undefined;
1990
+ }
1742
1991
 
1743
1992
  /**
1744
1993
  * Webhooks Resource
@@ -2289,4 +2538,4 @@ declare class ScellApiClient {
2289
2538
  constructor(apiKey: string, config?: ClientConfig);
2290
2539
  }
2291
2540
 
2292
- export { type Address, type ApiErrorResponse, type ApiKey, type ApiKeyWithSecret, type AuditTrailEntry, type AuditTrailResponse, type AuthResponse, type Balance, type BalanceWebhookData, type ClientConfig, type Company, type CompanyStatus, type ConvertInvoiceInput, type CreateApiKeyInput, type CreateCompanyInput, type CreateInvoiceInput, type CreateSignatureInput, type CreateWebhookInput, type CurrencyCode, type DateRangeOptions, type DateString, type DateTimeString, type Environment, type ForgotPasswordInput, type Invoice, type InvoiceDirection, type InvoiceDownloadResponse, type InvoiceDownloadType, type InvoiceFormat, type InvoiceLine, type InvoiceLineInput, type InvoiceListOptions, type InvoiceParty, type InvoiceStatus, type InvoiceWebhookData, type KycInitiateResponse, type KycStatusResponse, type LoginCredentials, type MessageResponse, type MessageWithDataResponse, type PaginatedResponse, type PaginationMeta, type PaginationOptions, type RegisterInput, type ReloadBalanceInput, type ReloadBalanceResponse, type ResetPasswordInput, type RetryOptions, ScellApiClient, ScellAuth, ScellAuthenticationError, ScellAuthorizationError, ScellClient, ScellError, ScellInsufficientBalanceError, ScellNetworkError, ScellNotFoundError, ScellRateLimitError, ScellServerError, ScellTimeoutError, ScellValidationError, ScellWebhooks, type Signature, type SignatureDownloadResponse, type SignatureDownloadType, type SignatureListOptions, type SignaturePosition, type SignatureRemindResponse, type SignatureStatus, type SignatureUIConfig, type SignatureWebhookData, type Signer, type SignerAuthMethod, type SignerInput, type SignerStatus, type SingleResponse, type Siren, type Siret, type Transaction, type TransactionListOptions, type TransactionService, type TransactionType, type UUID, type UpdateBalanceSettingsInput, type UpdateCompanyInput, type UpdateWebhookInput, type User, type VerifySignatureOptions, type Webhook, type WebhookEvent, type WebhookListOptions, type WebhookLog, type WebhookPayload, type WebhookTestResponse, type WebhookWithSecret, createRetryWrapper, withRetry };
2541
+ export { type AcceptInvoiceInput, type Address, type ApiErrorResponse, type ApiKey, type ApiKeyWithSecret, type AuditTrailEntry, type AuditTrailResponse, type AuthResponse, type Balance, type BalanceWebhookData, type ClientConfig, type Company, type CompanyStatus, type ConvertInvoiceInput, type CreateApiKeyInput, type CreateCompanyInput, type CreateInvoiceInput, type CreateSignatureInput, type CreateWebhookInput, type CurrencyCode, type DateRangeOptions, type DateString, type DateTimeString, type DisputeInvoiceInput, type DisputeType, type Environment, type ForgotPasswordInput, type IncomingInvoiceParams, type Invoice, type InvoiceDirection, type InvoiceDownloadResponse, type InvoiceDownloadType, type InvoiceFileFormat, type InvoiceFormat, type InvoiceIncomingPaidPayload, type InvoiceLine, type InvoiceLineInput, type InvoiceListOptions, type InvoiceParty, type InvoiceStatus, type InvoiceWebhookData, type KycInitiateResponse, type KycStatusResponse, type LoginCredentials, type MarkPaidInput, type MessageResponse, type MessageWithDataResponse, type PaginatedResponse, type PaginationMeta, type PaginationOptions, type RegisterInput, type RejectInvoiceInput, type RejectionCode, type ReloadBalanceInput, type ReloadBalanceResponse, type ResetPasswordInput, type RetryOptions, ScellApiClient, ScellAuth, ScellAuthenticationError, ScellAuthorizationError, ScellClient, ScellError, ScellInsufficientBalanceError, ScellNetworkError, ScellNotFoundError, ScellRateLimitError, ScellServerError, ScellTimeoutError, ScellValidationError, ScellWebhooks, type Signature, type SignatureDownloadResponse, type SignatureDownloadType, type SignatureListOptions, type SignaturePosition, type SignatureRemindResponse, type SignatureStatus, type SignatureUIConfig, type SignatureWebhookData, type Signer, type SignerAuthMethod, type SignerInput, type SignerStatus, type SingleResponse, type Siren, type Siret, type Transaction, type TransactionListOptions, type TransactionService, type TransactionType, type UUID, type UpdateBalanceSettingsInput, type UpdateCompanyInput, type UpdateWebhookInput, type User, type VerifySignatureOptions, type Webhook, type WebhookEvent, type WebhookListOptions, type WebhookLog, type WebhookPayload, type WebhookTestResponse, type WebhookWithSecret, createRetryWrapper, withRetry };