@scell/sdk 1.5.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.
- package/README.md +92 -9
- package/dist/index.d.mts +186 -1
- package/dist/index.d.ts +186 -1
- package/dist/index.js +157 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/resources/credit-notes.ts +192 -0
- package/src/resources/fiscal.ts +1 -1
- package/src/resources/invoices.ts +24 -0
- package/src/types/credit-notes.ts +57 -0
- package/src/types/index.ts +8 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { AuthResource, ScellAuth } from './resources/auth.js';
|
|
|
40
40
|
import { BalanceResource } from './resources/balance.js';
|
|
41
41
|
import { BillingResource } from './resources/billing.js';
|
|
42
42
|
import { CompaniesResource } from './resources/companies.js';
|
|
43
|
+
import { CreditNotesResource } from './resources/credit-notes.js';
|
|
43
44
|
import { FiscalResource } from './resources/fiscal.js';
|
|
44
45
|
import { InvoicesResource } from './resources/invoices.js';
|
|
45
46
|
import { SignaturesResource } from './resources/signatures.js';
|
|
@@ -94,6 +95,8 @@ export class ScellClient {
|
|
|
94
95
|
public readonly invoices: InvoicesResource;
|
|
95
96
|
/** Signature listing (read-only via dashboard) */
|
|
96
97
|
public readonly signatures: SignaturesResource;
|
|
98
|
+
/** Credit notes management */
|
|
99
|
+
public readonly creditNotes: CreditNotesResource;
|
|
97
100
|
|
|
98
101
|
/**
|
|
99
102
|
* Create a new Scell Dashboard Client
|
|
@@ -120,6 +123,7 @@ export class ScellClient {
|
|
|
120
123
|
this.webhooks = new WebhooksResource(this.http);
|
|
121
124
|
this.invoices = new InvoicesResource(this.http);
|
|
122
125
|
this.signatures = new SignaturesResource(this.http);
|
|
126
|
+
this.creditNotes = new CreditNotesResource(this.http);
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
129
|
|
|
@@ -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
|
+
}
|
package/src/resources/fiscal.ts
CHANGED
|
@@ -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.
|
|
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
|
*
|
|
@@ -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
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -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,
|