@scell/sdk 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +61 -2
- package/dist/index.d.mts +2353 -236
- package/dist/index.d.ts +2353 -236
- package/dist/index.js +1308 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1308 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +3 -1
- package/src/errors.ts +0 -0
- package/src/index.ts +42 -2
- package/src/resources/api-keys.ts +0 -0
- package/src/resources/auth.ts +0 -0
- package/src/resources/balance.ts +0 -0
- package/src/resources/billing.ts +49 -0
- package/src/resources/companies.ts +0 -0
- package/src/resources/fiscal.ts +128 -0
- package/src/resources/invoices.ts +0 -0
- package/src/resources/signatures.ts +33 -0
- package/src/resources/stats.ts +29 -0
- package/src/resources/sub-tenants.ts +41 -0
- package/src/resources/tenant-credit-notes.ts +301 -0
- package/src/resources/tenant-direct-credit-notes.ts +360 -0
- package/src/resources/tenant-direct-invoices.ts +424 -0
- package/src/resources/tenant-incoming-invoices.ts +429 -0
- package/src/resources/webhooks.ts +0 -0
- package/src/tenant-client.ts +105 -0
- package/src/types/api-keys.ts +0 -0
- package/src/types/auth.ts +0 -0
- package/src/types/balance.ts +0 -0
- package/src/types/billing.ts +73 -0
- package/src/types/common.ts +0 -0
- package/src/types/companies.ts +0 -0
- package/src/types/fiscal.ts +251 -0
- package/src/types/index.ts +103 -0
- package/src/types/invoices.ts +0 -0
- package/src/types/signatures.ts +0 -0
- package/src/types/stats.ts +37 -0
- package/src/types/sub-tenants.ts +57 -0
- package/src/types/tenant-credit-notes.ts +128 -0
- package/src/types/tenant-invoices.ts +390 -0
- package/src/types/tenant-profile.ts +51 -0
- package/src/types/webhooks.ts +0 -0
- package/src/utils/retry.ts +0 -0
- package/src/utils/webhook-verify.ts +0 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant Credit Notes Resource
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { HttpClient, RequestOptions } from '../client.js';
|
|
8
|
+
import type {
|
|
9
|
+
MessageResponse,
|
|
10
|
+
PaginatedResponse,
|
|
11
|
+
SingleResponse,
|
|
12
|
+
} from '../types/common.js';
|
|
13
|
+
import type {
|
|
14
|
+
CreateTenantCreditNoteInput,
|
|
15
|
+
RemainingCreditable,
|
|
16
|
+
TenantCreditNote,
|
|
17
|
+
TenantCreditNoteListOptions,
|
|
18
|
+
UpdateTenantCreditNoteInput,
|
|
19
|
+
} from '../types/tenant-credit-notes.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Tenant Credit Notes API resource
|
|
23
|
+
*
|
|
24
|
+
* Manage credit notes for sub-tenant invoices.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // List credit notes for a sub-tenant
|
|
29
|
+
* const { data, meta } = await client.tenantCreditNotes.list('sub-tenant-uuid', {
|
|
30
|
+
* status: 'sent'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Create a credit note
|
|
34
|
+
* const creditNote = await client.tenantCreditNotes.create('sub-tenant-uuid', {
|
|
35
|
+
* invoice_id: 'invoice-uuid',
|
|
36
|
+
* reason: 'Product returned',
|
|
37
|
+
* type: 'partial',
|
|
38
|
+
* items: [{ invoice_line_id: 'line-uuid', quantity: 1 }]
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class TenantCreditNotesResource {
|
|
43
|
+
constructor(private readonly http: HttpClient) {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* List credit notes for a sub-tenant
|
|
47
|
+
*
|
|
48
|
+
* @param subTenantId - Sub-tenant UUID
|
|
49
|
+
* @param options - Filter and pagination options
|
|
50
|
+
* @param requestOptions - Request options
|
|
51
|
+
* @returns Paginated list of credit notes
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const { data, meta } = await client.tenantCreditNotes.list('sub-tenant-uuid', {
|
|
56
|
+
* status: 'sent',
|
|
57
|
+
* date_from: '2024-01-01',
|
|
58
|
+
* per_page: 50
|
|
59
|
+
* });
|
|
60
|
+
* console.log(`Found ${meta.total} credit notes`);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
async list(
|
|
64
|
+
subTenantId: string,
|
|
65
|
+
options: TenantCreditNoteListOptions = {},
|
|
66
|
+
requestOptions?: RequestOptions
|
|
67
|
+
): Promise<PaginatedResponse<TenantCreditNote>> {
|
|
68
|
+
return this.http.get<PaginatedResponse<TenantCreditNote>>(
|
|
69
|
+
`/tenant/sub-tenants/${subTenantId}/credit-notes`,
|
|
70
|
+
options as Record<string, string | number | boolean | undefined>,
|
|
71
|
+
requestOptions
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create a new credit note for a sub-tenant invoice
|
|
77
|
+
*
|
|
78
|
+
* @param subTenantId - Sub-tenant UUID
|
|
79
|
+
* @param input - Credit note creation data
|
|
80
|
+
* @param requestOptions - Request options
|
|
81
|
+
* @returns Created credit note
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Create a partial credit note
|
|
86
|
+
* const { data: creditNote } = await client.tenantCreditNotes.create(
|
|
87
|
+
* 'sub-tenant-uuid',
|
|
88
|
+
* {
|
|
89
|
+
* invoice_id: 'invoice-uuid',
|
|
90
|
+
* reason: 'Product returned - damaged item',
|
|
91
|
+
* type: 'partial',
|
|
92
|
+
* items: [
|
|
93
|
+
* { invoice_line_id: 'line-uuid-1', quantity: 2 }
|
|
94
|
+
* ]
|
|
95
|
+
* }
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* // Create a total credit note
|
|
99
|
+
* const { data: totalCreditNote } = await client.tenantCreditNotes.create(
|
|
100
|
+
* 'sub-tenant-uuid',
|
|
101
|
+
* {
|
|
102
|
+
* invoice_id: 'invoice-uuid',
|
|
103
|
+
* reason: 'Order cancelled',
|
|
104
|
+
* type: 'total'
|
|
105
|
+
* }
|
|
106
|
+
* );
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async create(
|
|
110
|
+
subTenantId: string,
|
|
111
|
+
input: CreateTenantCreditNoteInput,
|
|
112
|
+
requestOptions?: RequestOptions
|
|
113
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
114
|
+
return this.http.post<SingleResponse<TenantCreditNote>>(
|
|
115
|
+
`/tenant/sub-tenants/${subTenantId}/credit-notes`,
|
|
116
|
+
input,
|
|
117
|
+
requestOptions
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get a specific credit note by ID
|
|
123
|
+
*
|
|
124
|
+
* @param creditNoteId - Credit note UUID
|
|
125
|
+
* @param requestOptions - Request options
|
|
126
|
+
* @returns Credit note details
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const { data: creditNote } = await client.tenantCreditNotes.get('credit-note-uuid');
|
|
131
|
+
* console.log('Credit note number:', creditNote.credit_note_number);
|
|
132
|
+
* console.log('Total:', creditNote.total, creditNote.currency);
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
async get(
|
|
136
|
+
creditNoteId: string,
|
|
137
|
+
requestOptions?: RequestOptions
|
|
138
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
139
|
+
return this.http.get<SingleResponse<TenantCreditNote>>(
|
|
140
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
141
|
+
undefined,
|
|
142
|
+
requestOptions
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Update a credit note
|
|
148
|
+
*
|
|
149
|
+
* Only credit notes in 'draft' status can be updated.
|
|
150
|
+
*
|
|
151
|
+
* @param creditNoteId - Credit note UUID
|
|
152
|
+
* @param input - Update data
|
|
153
|
+
* @param requestOptions - Request options
|
|
154
|
+
* @returns Updated credit note
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const { data: creditNote } = await client.tenantCreditNotes.update(
|
|
159
|
+
* 'credit-note-uuid',
|
|
160
|
+
* {
|
|
161
|
+
* reason: 'Updated reason: Customer complaint resolved',
|
|
162
|
+
* items: [
|
|
163
|
+
* { invoice_line_id: 'line-uuid', quantity: 3 }
|
|
164
|
+
* ]
|
|
165
|
+
* }
|
|
166
|
+
* );
|
|
167
|
+
* console.log('Credit note updated:', creditNote.reason);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
async update(
|
|
171
|
+
creditNoteId: string,
|
|
172
|
+
input: UpdateTenantCreditNoteInput,
|
|
173
|
+
requestOptions?: RequestOptions
|
|
174
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
175
|
+
return this.http.patch<SingleResponse<TenantCreditNote>>(
|
|
176
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
177
|
+
input,
|
|
178
|
+
requestOptions
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Send a credit note
|
|
184
|
+
*
|
|
185
|
+
* Changes the status from 'draft' to 'sent'.
|
|
186
|
+
*
|
|
187
|
+
* @param creditNoteId - Credit note UUID
|
|
188
|
+
* @param requestOptions - Request options
|
|
189
|
+
* @returns Updated credit note
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const { data: sentCreditNote } = await client.tenantCreditNotes.send('credit-note-uuid');
|
|
194
|
+
* console.log('Status:', sentCreditNote.status); // 'sent'
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
async send(
|
|
198
|
+
creditNoteId: string,
|
|
199
|
+
requestOptions?: RequestOptions
|
|
200
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
201
|
+
return this.http.post<SingleResponse<TenantCreditNote>>(
|
|
202
|
+
`/tenant/credit-notes/${creditNoteId}/send`,
|
|
203
|
+
undefined,
|
|
204
|
+
requestOptions
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Delete a credit note (draft only)
|
|
210
|
+
*
|
|
211
|
+
* Only credit notes with status 'draft' can be deleted.
|
|
212
|
+
*
|
|
213
|
+
* @param creditNoteId - Credit note UUID
|
|
214
|
+
* @param requestOptions - Request options
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* await client.tenantCreditNotes.delete('credit-note-uuid');
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
async delete(
|
|
222
|
+
creditNoteId: string,
|
|
223
|
+
requestOptions?: RequestOptions
|
|
224
|
+
): Promise<MessageResponse> {
|
|
225
|
+
return this.http.delete<MessageResponse>(
|
|
226
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
227
|
+
requestOptions
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Download credit note as PDF
|
|
233
|
+
*
|
|
234
|
+
* @param creditNoteId - Credit note UUID
|
|
235
|
+
* @param requestOptions - Request options
|
|
236
|
+
* @returns ArrayBuffer containing the PDF file
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // Download credit note PDF
|
|
241
|
+
* const pdfBuffer = await client.tenantCreditNotes.download('credit-note-uuid');
|
|
242
|
+
*
|
|
243
|
+
* // In Node.js, save to file:
|
|
244
|
+
* import { writeFileSync } from 'fs';
|
|
245
|
+
* writeFileSync('credit-note.pdf', Buffer.from(pdfBuffer));
|
|
246
|
+
*
|
|
247
|
+
* // In browser, trigger download:
|
|
248
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
249
|
+
* const url = URL.createObjectURL(blob);
|
|
250
|
+
* const a = document.createElement('a');
|
|
251
|
+
* a.href = url;
|
|
252
|
+
* a.download = 'credit-note.pdf';
|
|
253
|
+
* a.click();
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
async download(
|
|
257
|
+
creditNoteId: string,
|
|
258
|
+
requestOptions?: RequestOptions
|
|
259
|
+
): Promise<ArrayBuffer> {
|
|
260
|
+
return this.http.getRaw(
|
|
261
|
+
`/tenant/credit-notes/${creditNoteId}/download`,
|
|
262
|
+
undefined,
|
|
263
|
+
requestOptions
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Get remaining creditable amount for an invoice
|
|
269
|
+
*
|
|
270
|
+
* Returns information about how much can still be credited for an invoice,
|
|
271
|
+
* including per-line breakdown.
|
|
272
|
+
*
|
|
273
|
+
* @param invoiceId - Invoice UUID
|
|
274
|
+
* @param requestOptions - Request options
|
|
275
|
+
* @returns Remaining creditable information
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const remaining = await client.tenantCreditNotes.remainingCreditable('invoice-uuid');
|
|
280
|
+
*
|
|
281
|
+
* console.log('Invoice total:', remaining.invoice_total);
|
|
282
|
+
* console.log('Already credited:', remaining.credited_total);
|
|
283
|
+
* console.log('Remaining to credit:', remaining.remaining_total);
|
|
284
|
+
*
|
|
285
|
+
* // Check remaining quantity per line
|
|
286
|
+
* remaining.lines.forEach(line => {
|
|
287
|
+
* console.log(`${line.description}: ${line.remaining_quantity} remaining`);
|
|
288
|
+
* });
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
async remainingCreditable(
|
|
292
|
+
invoiceId: string,
|
|
293
|
+
requestOptions?: RequestOptions
|
|
294
|
+
): Promise<RemainingCreditable> {
|
|
295
|
+
return this.http.get<RemainingCreditable>(
|
|
296
|
+
`/tenant/invoices/${invoiceId}/remaining-creditable`,
|
|
297
|
+
undefined,
|
|
298
|
+
requestOptions
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant Direct Credit Notes Resource
|
|
3
|
+
*
|
|
4
|
+
* Manage credit notes for direct invoices issued by a tenant.
|
|
5
|
+
* Direct credit notes are linked to direct invoices (not sub-tenant invoices)
|
|
6
|
+
* and allow partial or total refunds.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { HttpClient, RequestOptions } from '../client.js';
|
|
12
|
+
import type {
|
|
13
|
+
MessageResponse,
|
|
14
|
+
PaginatedResponse,
|
|
15
|
+
SingleResponse,
|
|
16
|
+
} from '../types/common.js';
|
|
17
|
+
import type {
|
|
18
|
+
CreateTenantDirectCreditNoteParams,
|
|
19
|
+
TenantCreditNote,
|
|
20
|
+
TenantCreditNoteFilters,
|
|
21
|
+
UpdateTenantCreditNoteParams,
|
|
22
|
+
} from '../types/tenant-invoices.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Remaining creditable information for a direct invoice
|
|
26
|
+
*/
|
|
27
|
+
export interface DirectInvoiceRemainingCreditable {
|
|
28
|
+
/** Invoice UUID */
|
|
29
|
+
invoice_id: string;
|
|
30
|
+
/** Original invoice total (TTC) */
|
|
31
|
+
invoice_total: number;
|
|
32
|
+
/** Total already credited */
|
|
33
|
+
credited_total: number;
|
|
34
|
+
/** Remaining amount that can be credited */
|
|
35
|
+
remaining_total: number;
|
|
36
|
+
/** Line-by-line breakdown */
|
|
37
|
+
lines: DirectInvoiceRemainingLine[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Remaining creditable information for an invoice line
|
|
42
|
+
*/
|
|
43
|
+
export interface DirectInvoiceRemainingLine {
|
|
44
|
+
/** Invoice line UUID */
|
|
45
|
+
invoice_line_id: string;
|
|
46
|
+
/** Line description */
|
|
47
|
+
description: string;
|
|
48
|
+
/** Original quantity */
|
|
49
|
+
original_quantity: number;
|
|
50
|
+
/** Quantity already credited */
|
|
51
|
+
credited_quantity: number;
|
|
52
|
+
/** Remaining quantity that can be credited */
|
|
53
|
+
remaining_quantity: number;
|
|
54
|
+
/** Unit price */
|
|
55
|
+
unit_price: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Tenant Direct Credit Notes API resource
|
|
60
|
+
*
|
|
61
|
+
* Provides operations for managing credit notes linked to direct invoices.
|
|
62
|
+
* Use this for refunds or corrections on invoices issued to external buyers.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { ScellTenantClient } from '@scell/sdk';
|
|
67
|
+
*
|
|
68
|
+
* const client = new ScellTenantClient('your-tenant-key');
|
|
69
|
+
*
|
|
70
|
+
* // Create a partial credit note
|
|
71
|
+
* const { data: creditNote } = await client.directCreditNotes.create({
|
|
72
|
+
* invoice_id: 'invoice-uuid',
|
|
73
|
+
* reason: 'Product returned - damaged in transit',
|
|
74
|
+
* type: 'partial',
|
|
75
|
+
* items: [
|
|
76
|
+
* { invoice_line_id: 'line-uuid', quantity: 2 }
|
|
77
|
+
* ]
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Create a total credit note (full refund)
|
|
81
|
+
* const { data: totalCreditNote } = await client.directCreditNotes.create({
|
|
82
|
+
* invoice_id: 'invoice-uuid',
|
|
83
|
+
* reason: 'Order cancelled by customer',
|
|
84
|
+
* type: 'total'
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* // List all credit notes
|
|
88
|
+
* const { data: creditNotes } = await client.directCreditNotes.list({
|
|
89
|
+
* status: 'sent'
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export class TenantDirectCreditNotesResource {
|
|
94
|
+
constructor(private readonly http: HttpClient) {}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create a new credit note for a direct invoice
|
|
98
|
+
*
|
|
99
|
+
* Creates a credit note (avoir) linked to a direct invoice.
|
|
100
|
+
* - For partial credit notes, specify the items and quantities to credit.
|
|
101
|
+
* - For total credit notes, all items are automatically credited.
|
|
102
|
+
*
|
|
103
|
+
* @param params - Credit note creation parameters
|
|
104
|
+
* @param requestOptions - Optional request configuration
|
|
105
|
+
* @returns Created credit note
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Partial credit note
|
|
110
|
+
* const { data: creditNote } = await client.directCreditNotes.create({
|
|
111
|
+
* invoice_id: 'invoice-uuid',
|
|
112
|
+
* reason: 'Returned items',
|
|
113
|
+
* type: 'partial',
|
|
114
|
+
* items: [
|
|
115
|
+
* { invoice_line_id: 'line-1-uuid', quantity: 2 },
|
|
116
|
+
* { invoice_line_id: 'line-2-uuid', quantity: 1 }
|
|
117
|
+
* ]
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Total credit note (cancels entire invoice)
|
|
121
|
+
* const { data: totalCreditNote } = await client.directCreditNotes.create({
|
|
122
|
+
* invoice_id: 'invoice-uuid',
|
|
123
|
+
* reason: 'Invoice issued in error',
|
|
124
|
+
* type: 'total'
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* console.log('Credit note number:', creditNote.credit_note_number);
|
|
128
|
+
* console.log('Amount:', creditNote.total, creditNote.currency);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
async create(
|
|
132
|
+
params: CreateTenantDirectCreditNoteParams,
|
|
133
|
+
requestOptions?: RequestOptions
|
|
134
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
135
|
+
return this.http.post<SingleResponse<TenantCreditNote>>(
|
|
136
|
+
'/tenant/credit-notes',
|
|
137
|
+
params,
|
|
138
|
+
requestOptions
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* List all direct credit notes
|
|
144
|
+
*
|
|
145
|
+
* Returns a paginated list of credit notes for direct invoices.
|
|
146
|
+
*
|
|
147
|
+
* @param filters - Filter and pagination options
|
|
148
|
+
* @param requestOptions - Optional request configuration
|
|
149
|
+
* @returns Paginated list of credit notes
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // List all sent credit notes
|
|
154
|
+
* const { data: creditNotes, meta } = await client.directCreditNotes.list({
|
|
155
|
+
* status: 'sent',
|
|
156
|
+
* per_page: 50
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* console.log(`Found ${meta.total} sent credit notes`);
|
|
160
|
+
*
|
|
161
|
+
* // Filter by date range
|
|
162
|
+
* const januaryCreditNotes = await client.directCreditNotes.list({
|
|
163
|
+
* date_from: '2026-01-01',
|
|
164
|
+
* date_to: '2026-01-31'
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
async list(
|
|
169
|
+
filters: TenantCreditNoteFilters = {},
|
|
170
|
+
requestOptions?: RequestOptions
|
|
171
|
+
): Promise<PaginatedResponse<TenantCreditNote>> {
|
|
172
|
+
return this.http.get<PaginatedResponse<TenantCreditNote>>(
|
|
173
|
+
'/tenant/credit-notes',
|
|
174
|
+
filters as Record<string, string | number | boolean | undefined>,
|
|
175
|
+
requestOptions
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Get a specific credit note by ID
|
|
181
|
+
*
|
|
182
|
+
* @param creditNoteId - Credit note UUID
|
|
183
|
+
* @param requestOptions - Optional request configuration
|
|
184
|
+
* @returns Credit note details
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const { data: creditNote } = await client.directCreditNotes.get('credit-note-uuid');
|
|
189
|
+
*
|
|
190
|
+
* console.log('Credit note:', creditNote.credit_note_number);
|
|
191
|
+
* console.log('Status:', creditNote.status);
|
|
192
|
+
* console.log('Reason:', creditNote.reason);
|
|
193
|
+
* console.log('Total:', creditNote.total, creditNote.currency);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
async get(
|
|
197
|
+
creditNoteId: string,
|
|
198
|
+
requestOptions?: RequestOptions
|
|
199
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
200
|
+
return this.http.get<SingleResponse<TenantCreditNote>>(
|
|
201
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
202
|
+
undefined,
|
|
203
|
+
requestOptions
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Update a credit note
|
|
209
|
+
*
|
|
210
|
+
* Only credit notes in 'draft' status can be updated.
|
|
211
|
+
*
|
|
212
|
+
* @param creditNoteId - Credit note UUID
|
|
213
|
+
* @param params - Update parameters
|
|
214
|
+
* @param requestOptions - Optional request configuration
|
|
215
|
+
* @returns Updated credit note
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const { data: creditNote } = await client.directCreditNotes.update(
|
|
220
|
+
* 'credit-note-uuid',
|
|
221
|
+
* {
|
|
222
|
+
* reason: 'Updated reason: Customer complaint resolved',
|
|
223
|
+
* items: [
|
|
224
|
+
* { invoice_line_id: 'line-uuid', quantity: 3 }
|
|
225
|
+
* ]
|
|
226
|
+
* }
|
|
227
|
+
* );
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async update(
|
|
231
|
+
creditNoteId: string,
|
|
232
|
+
params: UpdateTenantCreditNoteParams,
|
|
233
|
+
requestOptions?: RequestOptions
|
|
234
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
235
|
+
return this.http.patch<SingleResponse<TenantCreditNote>>(
|
|
236
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
237
|
+
params,
|
|
238
|
+
requestOptions
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Delete a credit note
|
|
244
|
+
*
|
|
245
|
+
* Only credit notes in 'draft' status can be deleted.
|
|
246
|
+
*
|
|
247
|
+
* @param creditNoteId - Credit note UUID
|
|
248
|
+
* @param requestOptions - Optional request configuration
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* await client.directCreditNotes.delete('draft-credit-note-uuid');
|
|
253
|
+
* console.log('Credit note deleted');
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
async delete(
|
|
257
|
+
creditNoteId: string,
|
|
258
|
+
requestOptions?: RequestOptions
|
|
259
|
+
): Promise<MessageResponse> {
|
|
260
|
+
return this.http.delete<MessageResponse>(
|
|
261
|
+
`/tenant/credit-notes/${creditNoteId}`,
|
|
262
|
+
requestOptions
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Send a credit note
|
|
268
|
+
*
|
|
269
|
+
* Validates and sends the credit note, changing status from 'draft' to 'sent'.
|
|
270
|
+
*
|
|
271
|
+
* @param creditNoteId - Credit note UUID
|
|
272
|
+
* @param requestOptions - Optional request configuration
|
|
273
|
+
* @returns Sent credit note
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const { data: creditNote } = await client.directCreditNotes.send('credit-note-uuid');
|
|
278
|
+
* console.log('Credit note sent:', creditNote.status); // 'sent'
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
async send(
|
|
282
|
+
creditNoteId: string,
|
|
283
|
+
requestOptions?: RequestOptions
|
|
284
|
+
): Promise<SingleResponse<TenantCreditNote>> {
|
|
285
|
+
return this.http.post<SingleResponse<TenantCreditNote>>(
|
|
286
|
+
`/tenant/credit-notes/${creditNoteId}/send`,
|
|
287
|
+
undefined,
|
|
288
|
+
requestOptions
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Download credit note as PDF
|
|
294
|
+
*
|
|
295
|
+
* @param creditNoteId - Credit note UUID
|
|
296
|
+
* @param requestOptions - Optional request configuration
|
|
297
|
+
* @returns ArrayBuffer containing the PDF file
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const pdfBuffer = await client.directCreditNotes.download('credit-note-uuid');
|
|
302
|
+
*
|
|
303
|
+
* // In Node.js:
|
|
304
|
+
* import { writeFileSync } from 'fs';
|
|
305
|
+
* writeFileSync('credit-note.pdf', Buffer.from(pdfBuffer));
|
|
306
|
+
*
|
|
307
|
+
* // In browser:
|
|
308
|
+
* const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
309
|
+
* const url = URL.createObjectURL(blob);
|
|
310
|
+
* window.open(url);
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
async download(
|
|
314
|
+
creditNoteId: string,
|
|
315
|
+
requestOptions?: RequestOptions
|
|
316
|
+
): Promise<ArrayBuffer> {
|
|
317
|
+
return this.http.getRaw(
|
|
318
|
+
`/tenant/credit-notes/${creditNoteId}/download`,
|
|
319
|
+
undefined,
|
|
320
|
+
requestOptions
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Get remaining creditable amount for a direct invoice
|
|
326
|
+
*
|
|
327
|
+
* Returns information about how much can still be credited,
|
|
328
|
+
* including line-by-line breakdown.
|
|
329
|
+
*
|
|
330
|
+
* @param invoiceId - Invoice UUID
|
|
331
|
+
* @param requestOptions - Optional request configuration
|
|
332
|
+
* @returns Remaining creditable information
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const remaining = await client.directCreditNotes.remainingCreditable('invoice-uuid');
|
|
337
|
+
*
|
|
338
|
+
* console.log('Invoice total:', remaining.invoice_total);
|
|
339
|
+
* console.log('Already credited:', remaining.credited_total);
|
|
340
|
+
* console.log('Can still credit:', remaining.remaining_total);
|
|
341
|
+
*
|
|
342
|
+
* // Check per-line
|
|
343
|
+
* remaining.lines.forEach(line => {
|
|
344
|
+
* if (line.remaining_quantity > 0) {
|
|
345
|
+
* console.log(`${line.description}: ${line.remaining_quantity} units remaining`);
|
|
346
|
+
* }
|
|
347
|
+
* });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
async remainingCreditable(
|
|
351
|
+
invoiceId: string,
|
|
352
|
+
requestOptions?: RequestOptions
|
|
353
|
+
): Promise<DirectInvoiceRemainingCreditable> {
|
|
354
|
+
return this.http.get<DirectInvoiceRemainingCreditable>(
|
|
355
|
+
`/tenant/invoices/${invoiceId}/remaining-creditable`,
|
|
356
|
+
undefined,
|
|
357
|
+
requestOptions
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|