@scell/sdk 1.4.0 → 1.7.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.
Files changed (48) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +92 -9
  3. package/dist/index.d.mts +223 -4
  4. package/dist/index.d.ts +223 -4
  5. package/dist/index.js +207 -5
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +207 -5
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +1 -1
  10. package/src/client.ts +0 -0
  11. package/src/errors.ts +0 -0
  12. package/src/index.ts +32 -4
  13. package/src/resources/api-keys.ts +0 -0
  14. package/src/resources/auth.ts +0 -0
  15. package/src/resources/balance.ts +0 -0
  16. package/src/resources/billing.ts +0 -0
  17. package/src/resources/companies.ts +0 -0
  18. package/src/resources/credit-notes.ts +192 -0
  19. package/src/resources/fiscal.ts +1 -1
  20. package/src/resources/invoices.ts +24 -0
  21. package/src/resources/signatures.ts +33 -0
  22. package/src/resources/stats.ts +0 -0
  23. package/src/resources/sub-tenants.ts +0 -0
  24. package/src/resources/tenant-credit-notes.ts +0 -0
  25. package/src/resources/tenant-direct-credit-notes.ts +0 -0
  26. package/src/resources/tenant-direct-invoices.ts +0 -0
  27. package/src/resources/tenant-incoming-invoices.ts +0 -0
  28. package/src/resources/webhooks.ts +0 -0
  29. package/src/tenant-client.ts +0 -0
  30. package/src/types/api-keys.ts +0 -0
  31. package/src/types/auth.ts +0 -0
  32. package/src/types/balance.ts +0 -0
  33. package/src/types/billing.ts +0 -0
  34. package/src/types/common.ts +0 -0
  35. package/src/types/companies.ts +0 -0
  36. package/src/types/credit-notes.ts +57 -0
  37. package/src/types/fiscal.ts +0 -0
  38. package/src/types/index.ts +8 -0
  39. package/src/types/invoices.ts +0 -0
  40. package/src/types/signatures.ts +0 -0
  41. package/src/types/stats.ts +0 -0
  42. package/src/types/sub-tenants.ts +0 -0
  43. package/src/types/tenant-credit-notes.ts +0 -0
  44. package/src/types/tenant-invoices.ts +0 -0
  45. package/src/types/tenant-profile.ts +0 -0
  46. package/src/types/webhooks.ts +0 -0
  47. package/src/utils/retry.ts +0 -0
  48. package/src/utils/webhook-verify.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scell/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.7.0",
4
4
  "description": "Official TypeScript SDK for Scell.io - Electronic invoicing (Factur-X) and signatures (eIDAS) API",
5
5
  "author": "Scell.io <contact@scell.io>",
6
6
  "license": "MIT",
package/src/client.ts CHANGED
File without changes
package/src/errors.ts CHANGED
File without changes
package/src/index.ts CHANGED
@@ -38,10 +38,17 @@ import { ScellTenantClient } from './tenant-client.js';
38
38
  import { ApiKeysResource } from './resources/api-keys.js';
39
39
  import { AuthResource, ScellAuth } from './resources/auth.js';
40
40
  import { BalanceResource } from './resources/balance.js';
41
+ import { BillingResource } from './resources/billing.js';
41
42
  import { CompaniesResource } from './resources/companies.js';
43
+ import { CreditNotesResource } from './resources/credit-notes.js';
44
+ import { FiscalResource } from './resources/fiscal.js';
42
45
  import { InvoicesResource } from './resources/invoices.js';
43
46
  import { SignaturesResource } from './resources/signatures.js';
47
+ import { StatsResource } from './resources/stats.js';
48
+ import { SubTenantsResource } from './resources/sub-tenants.js';
44
49
  import { TenantCreditNotesResource } from './resources/tenant-credit-notes.js';
50
+ import { TenantDirectInvoicesResource } from './resources/tenant-direct-invoices.js';
51
+ import { TenantIncomingInvoicesResource } from './resources/tenant-incoming-invoices.js';
45
52
  import { WebhooksResource } from './resources/webhooks.js';
46
53
 
47
54
  // Utilities
@@ -88,6 +95,8 @@ export class ScellClient {
88
95
  public readonly invoices: InvoicesResource;
89
96
  /** Signature listing (read-only via dashboard) */
90
97
  public readonly signatures: SignaturesResource;
98
+ /** Credit notes management */
99
+ public readonly creditNotes: CreditNotesResource;
91
100
 
92
101
  /**
93
102
  * Create a new Scell Dashboard Client
@@ -114,6 +123,7 @@ export class ScellClient {
114
123
  this.webhooks = new WebhooksResource(this.http);
115
124
  this.invoices = new InvoicesResource(this.http);
116
125
  this.signatures = new SignaturesResource(this.http);
126
+ this.creditNotes = new CreditNotesResource(this.http);
117
127
  }
118
128
  }
119
129
 
@@ -153,13 +163,25 @@ export class ScellApiClient {
153
163
  public readonly invoices: InvoicesResource;
154
164
  /** Signature operations (create, download, remind, cancel) */
155
165
  public readonly signatures: SignaturesResource;
156
- /** Tenant credit notes operations (create, send, download) */
157
- public readonly tenantCreditNotes: TenantCreditNotesResource;
166
+ /** Sub-tenant management (provision, update, list) */
167
+ public readonly subTenants: SubTenantsResource;
168
+ /** NF525 fiscal compliance (closings, FEC, attestation) */
169
+ public readonly fiscal: FiscalResource;
170
+ /** Platform statistics */
171
+ public readonly stats: StatsResource;
172
+ /** Platform billing (usage, top-up, transactions) */
173
+ public readonly billing: BillingResource;
174
+ /** Credit notes operations (create, send, download) */
175
+ public readonly creditNotes: TenantCreditNotesResource;
176
+ /** Tenant invoice operations (create, submit, update, delete) */
177
+ public readonly tenantInvoices: TenantDirectInvoicesResource;
178
+ /** Incoming invoice operations (list, accept, reject) */
179
+ public readonly incomingInvoices: TenantIncomingInvoicesResource;
158
180
 
159
181
  /**
160
182
  * Create a new Scell API Client
161
183
  *
162
- * @param apiKey - Your API key (from dashboard)
184
+ * @param apiKey - Your API key (sk_live_xxx or sk_test_xxx)
163
185
  * @param config - Client configuration
164
186
  *
165
187
  * @example
@@ -178,7 +200,13 @@ export class ScellApiClient {
178
200
 
179
201
  this.invoices = new InvoicesResource(this.http);
180
202
  this.signatures = new SignaturesResource(this.http);
181
- this.tenantCreditNotes = new TenantCreditNotesResource(this.http);
203
+ this.subTenants = new SubTenantsResource(this.http);
204
+ this.fiscal = new FiscalResource(this.http);
205
+ this.stats = new StatsResource(this.http);
206
+ this.billing = new BillingResource(this.http);
207
+ this.creditNotes = new TenantCreditNotesResource(this.http);
208
+ this.tenantInvoices = new TenantDirectInvoicesResource(this.http);
209
+ this.incomingInvoices = new TenantIncomingInvoicesResource(this.http);
182
210
  }
183
211
  }
184
212
 
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Credit Notes Resource (direct user / dashboard)
3
+ *
4
+ * Note: Deletion is forbidden by NF525 fiscal compliance.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ import type { HttpClient, RequestOptions } from '../client.js';
10
+ import type {
11
+ MessageResponse,
12
+ PaginatedResponse,
13
+ SingleResponse,
14
+ } from '../types/common.js';
15
+ import type {
16
+ CreditNote,
17
+ CreateCreditNoteInput,
18
+ CreditNoteListOptions,
19
+ } from '../types/credit-notes.js';
20
+
21
+ /**
22
+ * Credit Notes API resource
23
+ *
24
+ * Manage credit notes for the authenticated dashboard user.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // List credit notes
29
+ * const { data, meta } = await client.creditNotes.list({ per_page: 50 });
30
+ *
31
+ * // Create a credit note
32
+ * const creditNote = await client.creditNotes.create({
33
+ * invoice_id: 'invoice-uuid',
34
+ * reason: 'Product returned',
35
+ * items: [{ description: 'Item', quantity: 1, unit_price: 100, tax_rate: 20, total: 120 }]
36
+ * });
37
+ * ```
38
+ */
39
+ export class CreditNotesResource {
40
+ constructor(private readonly http: HttpClient) {}
41
+
42
+ /**
43
+ * List credit notes with optional filtering
44
+ *
45
+ * @param options - Filter and pagination options
46
+ * @param requestOptions - Request options
47
+ * @returns Paginated list of credit notes
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const { data, meta } = await client.creditNotes.list({ per_page: 50 });
52
+ * console.log(`Found ${meta.total} credit notes`);
53
+ * ```
54
+ */
55
+ async list(
56
+ options: CreditNoteListOptions = {},
57
+ requestOptions?: RequestOptions
58
+ ): Promise<PaginatedResponse<CreditNote>> {
59
+ return this.http.get<PaginatedResponse<CreditNote>>(
60
+ '/credit-notes',
61
+ options as Record<string, string | number | boolean | undefined>,
62
+ requestOptions
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Get a specific credit note by ID
68
+ *
69
+ * @param id - Credit note UUID
70
+ * @param requestOptions - Request options
71
+ * @returns Credit note details
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const { data: creditNote } = await client.creditNotes.get('credit-note-uuid');
76
+ * console.log('Credit note number:', creditNote.number);
77
+ * ```
78
+ */
79
+ async get(
80
+ id: string,
81
+ requestOptions?: RequestOptions
82
+ ): Promise<SingleResponse<CreditNote>> {
83
+ return this.http.get<SingleResponse<CreditNote>>(
84
+ `/credit-notes/${id}`,
85
+ undefined,
86
+ requestOptions
87
+ );
88
+ }
89
+
90
+ /**
91
+ * Create a new credit note
92
+ *
93
+ * @param input - Credit note creation data
94
+ * @param requestOptions - Request options
95
+ * @returns Created credit note
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const { data: creditNote } = await client.creditNotes.create({
100
+ * invoice_id: 'invoice-uuid',
101
+ * reason: 'Product returned',
102
+ * items: [
103
+ * { description: 'Item A', quantity: 1, unit_price: 100, tax_rate: 20, total: 120 }
104
+ * ]
105
+ * });
106
+ * ```
107
+ */
108
+ async create(
109
+ input: CreateCreditNoteInput,
110
+ requestOptions?: RequestOptions
111
+ ): Promise<SingleResponse<CreditNote>> {
112
+ return this.http.post<SingleResponse<CreditNote>>(
113
+ '/credit-notes',
114
+ input,
115
+ requestOptions
116
+ );
117
+ }
118
+
119
+ /**
120
+ * Send a credit note
121
+ *
122
+ * @param id - Credit note UUID
123
+ * @param requestOptions - Request options
124
+ * @returns Success message
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * await client.creditNotes.send('credit-note-uuid');
129
+ * ```
130
+ */
131
+ async send(
132
+ id: string,
133
+ requestOptions?: RequestOptions
134
+ ): Promise<MessageResponse> {
135
+ return this.http.post<MessageResponse>(
136
+ `/credit-notes/${id}/send`,
137
+ undefined,
138
+ requestOptions
139
+ );
140
+ }
141
+
142
+ /**
143
+ * Download credit note as PDF
144
+ *
145
+ * @param id - Credit note UUID
146
+ * @param requestOptions - Request options
147
+ * @returns ArrayBuffer containing the PDF file
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const pdfBuffer = await client.creditNotes.download('credit-note-uuid');
152
+ *
153
+ * // In Node.js, save to file:
154
+ * import { writeFileSync } from 'fs';
155
+ * writeFileSync('credit-note.pdf', Buffer.from(pdfBuffer));
156
+ * ```
157
+ */
158
+ async download(
159
+ id: string,
160
+ requestOptions?: RequestOptions
161
+ ): Promise<ArrayBuffer> {
162
+ return this.http.getRaw(
163
+ `/credit-notes/${id}/download`,
164
+ undefined,
165
+ requestOptions
166
+ );
167
+ }
168
+
169
+ /**
170
+ * Get remaining creditable amount for an invoice
171
+ *
172
+ * @param invoiceId - Invoice UUID
173
+ * @param requestOptions - Request options
174
+ * @returns Remaining creditable information
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const { data } = await client.creditNotes.remainingCreditable('invoice-uuid');
179
+ * console.log('Remaining:', data);
180
+ * ```
181
+ */
182
+ async remainingCreditable(
183
+ invoiceId: string,
184
+ requestOptions?: RequestOptions
185
+ ): Promise<SingleResponse<Record<string, unknown>>> {
186
+ return this.http.get<SingleResponse<Record<string, unknown>>>(
187
+ `/invoices/${invoiceId}/remaining-creditable`,
188
+ undefined,
189
+ requestOptions
190
+ );
191
+ }
192
+ }
@@ -111,7 +111,7 @@ export class FiscalResource {
111
111
  }
112
112
 
113
113
  async updateRule(id: string, input: FiscalUpdateRuleInput, requestOptions?: RequestOptions): Promise<SingleResponse<FiscalRule>> {
114
- return this.http.post<SingleResponse<FiscalRule>>(`/tenant/fiscal/rules/${id}`, input, requestOptions);
114
+ return this.http.put<SingleResponse<FiscalRule>>(`/tenant/fiscal/rules/${id}`, input, requestOptions);
115
115
  }
116
116
 
117
117
  async exportRules(options: FiscalExportRulesOptions, requestOptions?: RequestOptions): Promise<SingleResponse<Record<string, unknown>>> {
@@ -6,6 +6,7 @@
6
6
 
7
7
  import type { HttpClient, RequestOptions } from '../client.js';
8
8
  import type {
9
+ MessageResponse,
9
10
  MessageWithDataResponse,
10
11
  PaginatedResponse,
11
12
  SingleResponse,
@@ -416,6 +417,29 @@ export class InvoicesResource {
416
417
  );
417
418
  }
418
419
 
420
+ /**
421
+ * Submit an invoice for processing
422
+ *
423
+ * @param id - Invoice UUID
424
+ * @param requestOptions - Request options
425
+ * @returns Success message
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * await client.invoices.submit('invoice-uuid');
430
+ * ```
431
+ */
432
+ async submit(
433
+ id: string,
434
+ requestOptions?: RequestOptions
435
+ ): Promise<MessageResponse> {
436
+ return this.http.post<MessageResponse>(
437
+ `/invoices/${id}/submit`,
438
+ undefined,
439
+ requestOptions
440
+ );
441
+ }
442
+
419
443
  /**
420
444
  * Download invoice source file as binary content
421
445
  *
@@ -11,6 +11,7 @@ import type {
11
11
  PaginatedResponse,
12
12
  SingleResponse,
13
13
  } from '../types/common.js';
14
+ import type { AuditTrailResponse } from '../types/invoices.js';
14
15
  import type {
15
16
  CreateSignatureInput,
16
17
  Signature,
@@ -242,4 +243,36 @@ export class SignaturesResource {
242
243
  requestOptions
243
244
  );
244
245
  }
246
+
247
+ /**
248
+ * Get signature audit trail (JSON)
249
+ *
250
+ * Returns the complete history of actions on the signature:
251
+ * creation, delivery, opening, signing, refusal, etc.
252
+ *
253
+ * @param id - Signature UUID
254
+ * @param requestOptions - Request options
255
+ * @returns Audit trail entries with integrity validation
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const { data: entries, integrity_valid } = await client.signatures.auditTrail(
260
+ * 'signature-uuid'
261
+ * );
262
+ *
263
+ * if (integrity_valid) {
264
+ * entries.forEach(e => console.log(e.action, e.created_at));
265
+ * }
266
+ * ```
267
+ */
268
+ async auditTrail(
269
+ id: string,
270
+ requestOptions?: RequestOptions
271
+ ): Promise<AuditTrailResponse> {
272
+ return this.http.get<AuditTrailResponse>(
273
+ `/signatures/${id}/audit-trail`,
274
+ undefined,
275
+ requestOptions
276
+ );
277
+ }
245
278
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/types/auth.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Credit Notes types (direct user / dashboard)
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import type {
8
+ CurrencyCode,
9
+ DateTimeString,
10
+ PaginationOptions,
11
+ UUID,
12
+ } from './common.js';
13
+
14
+ /**
15
+ * Credit note item
16
+ */
17
+ export interface CreditNoteItem {
18
+ description: string;
19
+ quantity: number;
20
+ unit_price: number;
21
+ tax_rate: number;
22
+ total: number;
23
+ }
24
+
25
+ /**
26
+ * Credit Note (direct user)
27
+ */
28
+ export interface CreditNote {
29
+ id: UUID;
30
+ invoice_id: UUID;
31
+ number: string;
32
+ status: string;
33
+ total_amount: number;
34
+ tax_amount: number;
35
+ currency: CurrencyCode;
36
+ reason: string;
37
+ items: CreditNoteItem[];
38
+ created_at: DateTimeString;
39
+ updated_at: DateTimeString;
40
+ }
41
+
42
+ /**
43
+ * Input for creating a credit note
44
+ */
45
+ export interface CreateCreditNoteInput {
46
+ invoice_id: UUID;
47
+ reason: string;
48
+ items: CreditNoteItem[];
49
+ }
50
+
51
+ /**
52
+ * List options for credit notes
53
+ */
54
+ export interface CreditNoteListOptions extends PaginationOptions {
55
+ sort?: string | undefined;
56
+ order?: 'asc' | 'desc' | undefined;
57
+ }
File without changes
@@ -123,6 +123,14 @@ export type {
123
123
  User,
124
124
  } from './auth.js';
125
125
 
126
+ // Credit Notes types (direct user)
127
+ export type {
128
+ CreditNote,
129
+ CreditNoteItem,
130
+ CreateCreditNoteInput,
131
+ CreditNoteListOptions,
132
+ } from './credit-notes.js';
133
+
126
134
  // Tenant Credit Notes types
127
135
  export type {
128
136
  CreateTenantCreditNoteInput,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes