@scell/sdk 1.0.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.
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Invoices Resource
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import type { HttpClient, RequestOptions } from '../client.js';
8
+ import type {
9
+ MessageWithDataResponse,
10
+ PaginatedResponse,
11
+ SingleResponse,
12
+ } from '../types/common.js';
13
+ import type {
14
+ AuditTrailResponse,
15
+ ConvertInvoiceInput,
16
+ CreateInvoiceInput,
17
+ Invoice,
18
+ InvoiceDownloadResponse,
19
+ InvoiceDownloadType,
20
+ InvoiceListOptions,
21
+ } from '../types/invoices.js';
22
+
23
+ /**
24
+ * Invoices API resource
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // List invoices
29
+ * const invoices = await client.invoices.list({
30
+ * direction: 'outgoing',
31
+ * status: 'validated'
32
+ * });
33
+ *
34
+ * // Create an invoice
35
+ * const invoice = await client.invoices.create({
36
+ * invoice_number: 'FACT-2024-001',
37
+ * direction: 'outgoing',
38
+ * output_format: 'facturx',
39
+ * // ...
40
+ * });
41
+ *
42
+ * // Download invoice
43
+ * const download = await client.invoices.download(invoice.id, 'pdf');
44
+ * console.log('Download URL:', download.url);
45
+ * ```
46
+ */
47
+ export class InvoicesResource {
48
+ constructor(private readonly http: HttpClient) {}
49
+
50
+ /**
51
+ * List invoices with optional filtering
52
+ *
53
+ * @param options - Filter and pagination options
54
+ * @param requestOptions - Request options
55
+ * @returns Paginated list of invoices
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // List all outgoing invoices
60
+ * const { data, meta } = await client.invoices.list({
61
+ * direction: 'outgoing',
62
+ * per_page: 50
63
+ * });
64
+ * console.log(`Found ${meta.total} invoices`);
65
+ * ```
66
+ */
67
+ async list(
68
+ options: InvoiceListOptions = {},
69
+ requestOptions?: RequestOptions
70
+ ): Promise<PaginatedResponse<Invoice>> {
71
+ return this.http.get<PaginatedResponse<Invoice>>(
72
+ '/invoices',
73
+ options as Record<string, string | number | boolean | undefined>,
74
+ requestOptions
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Get a specific invoice by ID
80
+ *
81
+ * @param id - Invoice UUID
82
+ * @param requestOptions - Request options
83
+ * @returns Invoice details
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const { data: invoice } = await client.invoices.get('uuid-here');
88
+ * console.log('Invoice number:', invoice.invoice_number);
89
+ * ```
90
+ */
91
+ async get(
92
+ id: string,
93
+ requestOptions?: RequestOptions
94
+ ): Promise<SingleResponse<Invoice>> {
95
+ return this.http.get<SingleResponse<Invoice>>(
96
+ `/invoices/${id}`,
97
+ undefined,
98
+ requestOptions
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Create a new invoice
104
+ *
105
+ * Note: This endpoint requires API key authentication.
106
+ * Creating an invoice in production mode will debit your balance.
107
+ *
108
+ * @param input - Invoice creation data
109
+ * @param requestOptions - Request options
110
+ * @returns Created invoice
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const { data: invoice } = await client.invoices.create({
115
+ * invoice_number: 'FACT-2024-001',
116
+ * direction: 'outgoing',
117
+ * output_format: 'facturx',
118
+ * issue_date: '2024-01-15',
119
+ * total_ht: 100.00,
120
+ * total_tax: 20.00,
121
+ * total_ttc: 120.00,
122
+ * seller_siret: '12345678901234',
123
+ * seller_name: 'My Company',
124
+ * seller_address: {
125
+ * line1: '1 Rue Example',
126
+ * postal_code: '75001',
127
+ * city: 'Paris',
128
+ * country: 'FR'
129
+ * },
130
+ * buyer_siret: '98765432109876',
131
+ * buyer_name: 'Client Company',
132
+ * buyer_address: {
133
+ * line1: '2 Avenue Test',
134
+ * postal_code: '75002',
135
+ * city: 'Paris',
136
+ * country: 'FR'
137
+ * },
138
+ * lines: [{
139
+ * description: 'Service prestation',
140
+ * quantity: 1,
141
+ * unit_price: 100.00,
142
+ * tax_rate: 20.00,
143
+ * total_ht: 100.00,
144
+ * total_tax: 20.00,
145
+ * total_ttc: 120.00
146
+ * }]
147
+ * });
148
+ * ```
149
+ */
150
+ async create(
151
+ input: CreateInvoiceInput,
152
+ requestOptions?: RequestOptions
153
+ ): Promise<MessageWithDataResponse<Invoice>> {
154
+ return this.http.post<MessageWithDataResponse<Invoice>>(
155
+ '/invoices',
156
+ input,
157
+ requestOptions
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Download invoice file
163
+ *
164
+ * @param id - Invoice UUID
165
+ * @param type - File type to download
166
+ * @param requestOptions - Request options
167
+ * @returns Temporary download URL
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Download PDF version
172
+ * const { url, expires_at } = await client.invoices.download(
173
+ * 'invoice-uuid',
174
+ * 'pdf'
175
+ * );
176
+ * console.log('Download before:', expires_at);
177
+ * ```
178
+ */
179
+ async download(
180
+ id: string,
181
+ type: InvoiceDownloadType,
182
+ requestOptions?: RequestOptions
183
+ ): Promise<InvoiceDownloadResponse> {
184
+ return this.http.get<InvoiceDownloadResponse>(
185
+ `/invoices/${id}/download/${type}`,
186
+ undefined,
187
+ requestOptions
188
+ );
189
+ }
190
+
191
+ /**
192
+ * Get invoice audit trail (Piste d'Audit Fiable)
193
+ *
194
+ * @param id - Invoice UUID
195
+ * @param requestOptions - Request options
196
+ * @returns Audit trail entries with integrity validation
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * const { data: entries, integrity_valid } = await client.invoices.auditTrail(
201
+ * 'invoice-uuid'
202
+ * );
203
+ *
204
+ * if (integrity_valid) {
205
+ * console.log('Audit trail is valid');
206
+ * entries.forEach(e => console.log(e.action, e.created_at));
207
+ * }
208
+ * ```
209
+ */
210
+ async auditTrail(
211
+ id: string,
212
+ requestOptions?: RequestOptions
213
+ ): Promise<AuditTrailResponse> {
214
+ return this.http.get<AuditTrailResponse>(
215
+ `/invoices/${id}/audit-trail`,
216
+ undefined,
217
+ requestOptions
218
+ );
219
+ }
220
+
221
+ /**
222
+ * Convert invoice to another format
223
+ *
224
+ * @param input - Conversion parameters
225
+ * @param requestOptions - Request options
226
+ * @returns Conversion status
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * await client.invoices.convert({
231
+ * invoice_id: 'invoice-uuid',
232
+ * target_format: 'ubl'
233
+ * });
234
+ * ```
235
+ */
236
+ async convert(
237
+ input: ConvertInvoiceInput,
238
+ requestOptions?: RequestOptions
239
+ ): Promise<{ message: string; invoice_id: string; target_format: string }> {
240
+ return this.http.post<{
241
+ message: string;
242
+ invoice_id: string;
243
+ target_format: string;
244
+ }>('/invoices/convert', input, requestOptions);
245
+ }
246
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Signatures Resource
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import type { HttpClient, RequestOptions } from '../client.js';
8
+ import type {
9
+ MessageResponse,
10
+ MessageWithDataResponse,
11
+ PaginatedResponse,
12
+ SingleResponse,
13
+ } from '../types/common.js';
14
+ import type {
15
+ CreateSignatureInput,
16
+ Signature,
17
+ SignatureDownloadResponse,
18
+ SignatureDownloadType,
19
+ SignatureListOptions,
20
+ SignatureRemindResponse,
21
+ } from '../types/signatures.js';
22
+
23
+ /**
24
+ * Signatures API resource
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Create a signature request
29
+ * const signature = await client.signatures.create({
30
+ * title: 'Employment Contract',
31
+ * document: btoa(pdfContent), // Base64 encoded
32
+ * document_name: 'contract.pdf',
33
+ * signers: [{
34
+ * first_name: 'John',
35
+ * last_name: 'Doe',
36
+ * email: 'john@example.com',
37
+ * auth_method: 'email'
38
+ * }]
39
+ * });
40
+ *
41
+ * // Send reminder
42
+ * await client.signatures.remind(signature.id);
43
+ * ```
44
+ */
45
+ export class SignaturesResource {
46
+ constructor(private readonly http: HttpClient) {}
47
+
48
+ /**
49
+ * List signature requests with optional filtering
50
+ *
51
+ * @param options - Filter and pagination options
52
+ * @param requestOptions - Request options
53
+ * @returns Paginated list of signatures
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const { data, meta } = await client.signatures.list({
58
+ * status: 'pending',
59
+ * per_page: 25
60
+ * });
61
+ * console.log(`${meta.total} pending signatures`);
62
+ * ```
63
+ */
64
+ async list(
65
+ options: SignatureListOptions = {},
66
+ requestOptions?: RequestOptions
67
+ ): Promise<PaginatedResponse<Signature>> {
68
+ return this.http.get<PaginatedResponse<Signature>>(
69
+ '/signatures',
70
+ options as Record<string, string | number | boolean | undefined>,
71
+ requestOptions
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Get a specific signature by ID
77
+ *
78
+ * @param id - Signature UUID
79
+ * @param requestOptions - Request options
80
+ * @returns Signature details with signers
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const { data: signature } = await client.signatures.get('uuid-here');
85
+ * signature.signers?.forEach(signer => {
86
+ * console.log(`${signer.full_name}: ${signer.status}`);
87
+ * });
88
+ * ```
89
+ */
90
+ async get(
91
+ id: string,
92
+ requestOptions?: RequestOptions
93
+ ): Promise<SingleResponse<Signature>> {
94
+ return this.http.get<SingleResponse<Signature>>(
95
+ `/signatures/${id}`,
96
+ undefined,
97
+ requestOptions
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Create a new signature request
103
+ *
104
+ * Note: This endpoint requires API key authentication.
105
+ * Creating a signature in production mode will debit your balance.
106
+ *
107
+ * @param input - Signature creation data
108
+ * @param requestOptions - Request options
109
+ * @returns Created signature
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * import { readFileSync } from 'fs';
114
+ *
115
+ * const pdfContent = readFileSync('contract.pdf');
116
+ * const { data: signature } = await client.signatures.create({
117
+ * title: 'Service Agreement',
118
+ * description: 'Annual service contract',
119
+ * document: pdfContent.toString('base64'),
120
+ * document_name: 'contract.pdf',
121
+ * signers: [
122
+ * {
123
+ * first_name: 'Alice',
124
+ * last_name: 'Smith',
125
+ * email: 'alice@example.com',
126
+ * auth_method: 'email'
127
+ * },
128
+ * {
129
+ * first_name: 'Bob',
130
+ * last_name: 'Jones',
131
+ * phone: '+33612345678',
132
+ * auth_method: 'sms'
133
+ * }
134
+ * ],
135
+ * ui_config: {
136
+ * logo_url: 'https://mycompany.com/logo.png',
137
+ * primary_color: '#3b82f6',
138
+ * company_name: 'My Company'
139
+ * },
140
+ * redirect_complete_url: 'https://myapp.com/signed',
141
+ * redirect_cancel_url: 'https://myapp.com/cancelled'
142
+ * });
143
+ *
144
+ * // Send signing URLs to signers
145
+ * signature.signers?.forEach(signer => {
146
+ * console.log(`${signer.email}: ${signer.signing_url}`);
147
+ * });
148
+ * ```
149
+ */
150
+ async create(
151
+ input: CreateSignatureInput,
152
+ requestOptions?: RequestOptions
153
+ ): Promise<MessageWithDataResponse<Signature>> {
154
+ return this.http.post<MessageWithDataResponse<Signature>>(
155
+ '/signatures',
156
+ input,
157
+ requestOptions
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Download signature files
163
+ *
164
+ * @param id - Signature UUID
165
+ * @param type - File type to download
166
+ * @param requestOptions - Request options
167
+ * @returns Temporary download URL
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Download signed document
172
+ * const { url } = await client.signatures.download(
173
+ * 'signature-uuid',
174
+ * 'signed'
175
+ * );
176
+ *
177
+ * // Download audit trail (proof file)
178
+ * const { url: auditUrl } = await client.signatures.download(
179
+ * 'signature-uuid',
180
+ * 'audit_trail'
181
+ * );
182
+ * ```
183
+ */
184
+ async download(
185
+ id: string,
186
+ type: SignatureDownloadType,
187
+ requestOptions?: RequestOptions
188
+ ): Promise<SignatureDownloadResponse> {
189
+ return this.http.get<SignatureDownloadResponse>(
190
+ `/signatures/${id}/download/${type}`,
191
+ undefined,
192
+ requestOptions
193
+ );
194
+ }
195
+
196
+ /**
197
+ * Send reminder to pending signers
198
+ *
199
+ * @param id - Signature UUID
200
+ * @param requestOptions - Request options
201
+ * @returns Number of signers reminded
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const { signers_reminded } = await client.signatures.remind('uuid');
206
+ * console.log(`Reminded ${signers_reminded} signers`);
207
+ * ```
208
+ */
209
+ async remind(
210
+ id: string,
211
+ requestOptions?: RequestOptions
212
+ ): Promise<SignatureRemindResponse> {
213
+ return this.http.post<SignatureRemindResponse>(
214
+ `/signatures/${id}/remind`,
215
+ undefined,
216
+ requestOptions
217
+ );
218
+ }
219
+
220
+ /**
221
+ * Cancel a signature request
222
+ *
223
+ * Note: Cannot cancel completed signatures.
224
+ *
225
+ * @param id - Signature UUID
226
+ * @param requestOptions - Request options
227
+ * @returns Cancellation confirmation
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * await client.signatures.cancel('signature-uuid');
232
+ * console.log('Signature cancelled');
233
+ * ```
234
+ */
235
+ async cancel(
236
+ id: string,
237
+ requestOptions?: RequestOptions
238
+ ): Promise<MessageResponse> {
239
+ return this.http.post<MessageResponse>(
240
+ `/signatures/${id}/cancel`,
241
+ undefined,
242
+ requestOptions
243
+ );
244
+ }
245
+ }