@cynco/sdk 0.1.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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +410 -0
- package/dist/index.cjs +1222 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1169 -0
- package/dist/index.d.ts +1169 -0
- package/dist/index.js +1193 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1169 @@
|
|
|
1
|
+
interface WebhookVerifyOptions {
|
|
2
|
+
/** Override the tolerance window in seconds. Defaults to 300 (5 minutes). */
|
|
3
|
+
tolerance?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Utilities for verifying Cynco webhook signatures.
|
|
7
|
+
*
|
|
8
|
+
* All methods are static — no instantiation required.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import Cynco from 'cynco';
|
|
12
|
+
*
|
|
13
|
+
* const isValid = Cynco.webhooks.verify(
|
|
14
|
+
* rawBody,
|
|
15
|
+
* signature,
|
|
16
|
+
* timestamp,
|
|
17
|
+
* webhookSecret,
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const webhookVerifier: {
|
|
22
|
+
/**
|
|
23
|
+
* Verify a webhook signature.
|
|
24
|
+
*
|
|
25
|
+
* @param payload - The raw request body as a string.
|
|
26
|
+
* @param signature - The value of the `X-Webhook-Signature` header.
|
|
27
|
+
* @param timestamp - The value of the `X-Webhook-Timestamp` header.
|
|
28
|
+
* @param secret - Your webhook signing secret.
|
|
29
|
+
* @param options - Optional configuration.
|
|
30
|
+
* @returns `true` if the signature is valid and the timestamp is within tolerance.
|
|
31
|
+
*/
|
|
32
|
+
verify(payload: string, signature: string, timestamp: string, secret: string, options?: WebhookVerifyOptions): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Verify a webhook signature, throwing an error if invalid.
|
|
35
|
+
*
|
|
36
|
+
* @throws {Error} If the signature is invalid or the timestamp is stale.
|
|
37
|
+
*/
|
|
38
|
+
verifyOrThrow(payload: string, signature: string, timestamp: string, secret: string, options?: WebhookVerifyOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a signature for testing purposes.
|
|
41
|
+
*
|
|
42
|
+
* @param payload - The request body.
|
|
43
|
+
* @param secret - The webhook secret.
|
|
44
|
+
* @param timestamp - Unix timestamp in seconds (defaults to now).
|
|
45
|
+
* @returns An object with the signature and timestamp strings.
|
|
46
|
+
*/
|
|
47
|
+
sign(payload: string, secret: string, timestamp?: number): {
|
|
48
|
+
signature: string;
|
|
49
|
+
timestamp: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
interface CyncoClientOptions {
|
|
54
|
+
/** Base URL for the Cynco API. Defaults to https://app.cynco.io/api/v1 */
|
|
55
|
+
baseUrl?: string;
|
|
56
|
+
/** Request timeout in milliseconds. Defaults to 30000 (30s). */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
/** Maximum number of automatic retries on transient failures. Defaults to 3. */
|
|
59
|
+
maxRetries?: number;
|
|
60
|
+
/** Custom fetch implementation. Defaults to the global fetch. */
|
|
61
|
+
fetch?: typeof globalThis.fetch;
|
|
62
|
+
}
|
|
63
|
+
interface RequestOptions {
|
|
64
|
+
/** Idempotency key for safe retries on mutating requests. */
|
|
65
|
+
idempotencyKey?: string;
|
|
66
|
+
/** AbortSignal for request cancellation. */
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
/** Additional headers to merge into the request. */
|
|
69
|
+
headers?: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
interface CyncoResponse<T> {
|
|
72
|
+
success: true;
|
|
73
|
+
data: T;
|
|
74
|
+
meta?: ResponseMeta;
|
|
75
|
+
}
|
|
76
|
+
interface PaginatedResponse<T> {
|
|
77
|
+
success: true;
|
|
78
|
+
data: T[];
|
|
79
|
+
pagination: OffsetPagination;
|
|
80
|
+
links?: PaginationLinks;
|
|
81
|
+
meta?: ResponseMeta;
|
|
82
|
+
}
|
|
83
|
+
interface CursorPaginatedResponse<T> {
|
|
84
|
+
success: true;
|
|
85
|
+
data: T[];
|
|
86
|
+
pagination: CursorPagination;
|
|
87
|
+
links?: PaginationLinks;
|
|
88
|
+
meta?: ResponseMeta;
|
|
89
|
+
}
|
|
90
|
+
interface OffsetPagination {
|
|
91
|
+
total: number;
|
|
92
|
+
limit: number;
|
|
93
|
+
offset: number;
|
|
94
|
+
hasMore: boolean;
|
|
95
|
+
}
|
|
96
|
+
interface CursorPagination {
|
|
97
|
+
limit: number;
|
|
98
|
+
hasMore: boolean;
|
|
99
|
+
nextCursor: string | null;
|
|
100
|
+
}
|
|
101
|
+
interface PaginationLinks {
|
|
102
|
+
self?: string;
|
|
103
|
+
next?: string;
|
|
104
|
+
prev?: string;
|
|
105
|
+
first?: string;
|
|
106
|
+
last?: string;
|
|
107
|
+
}
|
|
108
|
+
interface ResponseMeta {
|
|
109
|
+
requestId?: string;
|
|
110
|
+
rateLimit?: RateLimitInfo;
|
|
111
|
+
apiVersion?: string;
|
|
112
|
+
}
|
|
113
|
+
interface RateLimitInfo {
|
|
114
|
+
limit: number;
|
|
115
|
+
remaining: number;
|
|
116
|
+
reset: number;
|
|
117
|
+
}
|
|
118
|
+
interface ErrorResponse {
|
|
119
|
+
success: false;
|
|
120
|
+
error: {
|
|
121
|
+
code: string;
|
|
122
|
+
message: string;
|
|
123
|
+
details?: ValidationDetail[];
|
|
124
|
+
};
|
|
125
|
+
meta?: ResponseMeta;
|
|
126
|
+
}
|
|
127
|
+
interface ValidationDetail {
|
|
128
|
+
field: string;
|
|
129
|
+
message: string;
|
|
130
|
+
}
|
|
131
|
+
interface ListParams {
|
|
132
|
+
limit?: number;
|
|
133
|
+
offset?: number;
|
|
134
|
+
cursor?: string;
|
|
135
|
+
sort?: string;
|
|
136
|
+
order?: 'asc' | 'desc';
|
|
137
|
+
}
|
|
138
|
+
interface InvoiceListParams extends ListParams {
|
|
139
|
+
status?: InvoiceStatus;
|
|
140
|
+
customerId?: string;
|
|
141
|
+
dateFrom?: string;
|
|
142
|
+
dateTo?: string;
|
|
143
|
+
dueDateFrom?: string;
|
|
144
|
+
dueDateTo?: string;
|
|
145
|
+
search?: string;
|
|
146
|
+
}
|
|
147
|
+
interface CustomerListParams extends ListParams {
|
|
148
|
+
search?: string;
|
|
149
|
+
type?: 'individual' | 'company';
|
|
150
|
+
isActive?: boolean;
|
|
151
|
+
}
|
|
152
|
+
interface VendorListParams extends ListParams {
|
|
153
|
+
search?: string;
|
|
154
|
+
isActive?: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface BillListParams extends ListParams {
|
|
157
|
+
status?: BillStatus;
|
|
158
|
+
vendorId?: string;
|
|
159
|
+
dateFrom?: string;
|
|
160
|
+
dateTo?: string;
|
|
161
|
+
dueDateFrom?: string;
|
|
162
|
+
dueDateTo?: string;
|
|
163
|
+
search?: string;
|
|
164
|
+
}
|
|
165
|
+
interface ItemListParams extends ListParams {
|
|
166
|
+
search?: string;
|
|
167
|
+
type?: 'product' | 'service';
|
|
168
|
+
isActive?: boolean;
|
|
169
|
+
}
|
|
170
|
+
interface AccountListParams extends ListParams {
|
|
171
|
+
search?: string;
|
|
172
|
+
type?: AccountType;
|
|
173
|
+
isActive?: boolean;
|
|
174
|
+
}
|
|
175
|
+
interface JournalEntryListParams extends ListParams {
|
|
176
|
+
dateFrom?: string;
|
|
177
|
+
dateTo?: string;
|
|
178
|
+
status?: 'draft' | 'posted' | 'voided';
|
|
179
|
+
search?: string;
|
|
180
|
+
}
|
|
181
|
+
interface BankAccountListParams extends ListParams {
|
|
182
|
+
search?: string;
|
|
183
|
+
isActive?: boolean;
|
|
184
|
+
}
|
|
185
|
+
interface BankTransactionListParams extends ListParams {
|
|
186
|
+
bankAccountId?: string;
|
|
187
|
+
dateFrom?: string;
|
|
188
|
+
dateTo?: string;
|
|
189
|
+
status?: 'pending' | 'cleared' | 'reconciled';
|
|
190
|
+
type?: 'credit' | 'debit';
|
|
191
|
+
search?: string;
|
|
192
|
+
}
|
|
193
|
+
interface WebhookListParams extends ListParams {
|
|
194
|
+
isActive?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface InvoiceCreateInput {
|
|
197
|
+
customerId: string;
|
|
198
|
+
issueDate: string;
|
|
199
|
+
dueDate: string;
|
|
200
|
+
lineItems: InvoiceLineItemInput[];
|
|
201
|
+
currency?: string;
|
|
202
|
+
notes?: string;
|
|
203
|
+
reference?: string;
|
|
204
|
+
taxInclusive?: boolean;
|
|
205
|
+
}
|
|
206
|
+
interface InvoiceUpdateInput {
|
|
207
|
+
customerId?: string;
|
|
208
|
+
issueDate?: string;
|
|
209
|
+
dueDate?: string;
|
|
210
|
+
lineItems?: InvoiceLineItemInput[];
|
|
211
|
+
currency?: string;
|
|
212
|
+
notes?: string;
|
|
213
|
+
reference?: string;
|
|
214
|
+
taxInclusive?: boolean;
|
|
215
|
+
}
|
|
216
|
+
interface InvoiceLineItemInput {
|
|
217
|
+
itemId?: string;
|
|
218
|
+
description: string;
|
|
219
|
+
quantity: number;
|
|
220
|
+
unitPrice: number;
|
|
221
|
+
taxRate?: number;
|
|
222
|
+
accountId?: string;
|
|
223
|
+
}
|
|
224
|
+
interface CustomerCreateInput {
|
|
225
|
+
name: string;
|
|
226
|
+
email?: string;
|
|
227
|
+
phone?: string;
|
|
228
|
+
type?: 'individual' | 'company';
|
|
229
|
+
taxNumber?: string;
|
|
230
|
+
currency?: string;
|
|
231
|
+
billingAddress?: Address;
|
|
232
|
+
shippingAddress?: Address;
|
|
233
|
+
notes?: string;
|
|
234
|
+
}
|
|
235
|
+
interface CustomerUpdateInput {
|
|
236
|
+
name?: string;
|
|
237
|
+
email?: string;
|
|
238
|
+
phone?: string;
|
|
239
|
+
type?: 'individual' | 'company';
|
|
240
|
+
taxNumber?: string;
|
|
241
|
+
currency?: string;
|
|
242
|
+
billingAddress?: Address;
|
|
243
|
+
shippingAddress?: Address;
|
|
244
|
+
notes?: string;
|
|
245
|
+
}
|
|
246
|
+
interface VendorCreateInput {
|
|
247
|
+
name: string;
|
|
248
|
+
email?: string;
|
|
249
|
+
phone?: string;
|
|
250
|
+
taxNumber?: string;
|
|
251
|
+
currency?: string;
|
|
252
|
+
address?: Address;
|
|
253
|
+
bankDetails?: BankDetails;
|
|
254
|
+
notes?: string;
|
|
255
|
+
}
|
|
256
|
+
interface VendorUpdateInput {
|
|
257
|
+
name?: string;
|
|
258
|
+
email?: string;
|
|
259
|
+
phone?: string;
|
|
260
|
+
taxNumber?: string;
|
|
261
|
+
currency?: string;
|
|
262
|
+
address?: Address;
|
|
263
|
+
bankDetails?: BankDetails;
|
|
264
|
+
notes?: string;
|
|
265
|
+
}
|
|
266
|
+
interface BillCreateInput {
|
|
267
|
+
vendorId: string;
|
|
268
|
+
issueDate: string;
|
|
269
|
+
dueDate: string;
|
|
270
|
+
lineItems: BillLineItemInput[];
|
|
271
|
+
currency?: string;
|
|
272
|
+
notes?: string;
|
|
273
|
+
reference?: string;
|
|
274
|
+
taxInclusive?: boolean;
|
|
275
|
+
}
|
|
276
|
+
interface BillUpdateInput {
|
|
277
|
+
vendorId?: string;
|
|
278
|
+
issueDate?: string;
|
|
279
|
+
dueDate?: string;
|
|
280
|
+
lineItems?: BillLineItemInput[];
|
|
281
|
+
currency?: string;
|
|
282
|
+
notes?: string;
|
|
283
|
+
reference?: string;
|
|
284
|
+
taxInclusive?: boolean;
|
|
285
|
+
}
|
|
286
|
+
interface BillLineItemInput {
|
|
287
|
+
itemId?: string;
|
|
288
|
+
description: string;
|
|
289
|
+
quantity: number;
|
|
290
|
+
unitPrice: number;
|
|
291
|
+
taxRate?: number;
|
|
292
|
+
accountId?: string;
|
|
293
|
+
}
|
|
294
|
+
interface ItemCreateInput {
|
|
295
|
+
name: string;
|
|
296
|
+
type: 'product' | 'service';
|
|
297
|
+
description?: string;
|
|
298
|
+
unitPrice?: number;
|
|
299
|
+
cost?: number;
|
|
300
|
+
taxRate?: number;
|
|
301
|
+
sku?: string;
|
|
302
|
+
unit?: string;
|
|
303
|
+
incomeAccountId?: string;
|
|
304
|
+
expenseAccountId?: string;
|
|
305
|
+
}
|
|
306
|
+
interface ItemUpdateInput {
|
|
307
|
+
name?: string;
|
|
308
|
+
type?: 'product' | 'service';
|
|
309
|
+
description?: string;
|
|
310
|
+
unitPrice?: number;
|
|
311
|
+
cost?: number;
|
|
312
|
+
taxRate?: number;
|
|
313
|
+
sku?: string;
|
|
314
|
+
unit?: string;
|
|
315
|
+
incomeAccountId?: string;
|
|
316
|
+
expenseAccountId?: string;
|
|
317
|
+
}
|
|
318
|
+
interface AccountCreateInput {
|
|
319
|
+
name: string;
|
|
320
|
+
code: string;
|
|
321
|
+
type: AccountType;
|
|
322
|
+
subType?: string;
|
|
323
|
+
description?: string;
|
|
324
|
+
currency?: string;
|
|
325
|
+
taxRate?: number;
|
|
326
|
+
isActive?: boolean;
|
|
327
|
+
}
|
|
328
|
+
interface AccountUpdateInput {
|
|
329
|
+
name?: string;
|
|
330
|
+
code?: string;
|
|
331
|
+
subType?: string;
|
|
332
|
+
description?: string;
|
|
333
|
+
currency?: string;
|
|
334
|
+
taxRate?: number;
|
|
335
|
+
isActive?: boolean;
|
|
336
|
+
}
|
|
337
|
+
interface JournalEntryCreateInput {
|
|
338
|
+
date: string;
|
|
339
|
+
reference?: string;
|
|
340
|
+
description?: string;
|
|
341
|
+
lines: JournalEntryLineInput[];
|
|
342
|
+
}
|
|
343
|
+
interface JournalEntryUpdateInput {
|
|
344
|
+
date?: string;
|
|
345
|
+
reference?: string;
|
|
346
|
+
description?: string;
|
|
347
|
+
lines?: JournalEntryLineInput[];
|
|
348
|
+
}
|
|
349
|
+
interface JournalEntryLineInput {
|
|
350
|
+
accountId: string;
|
|
351
|
+
debit: number;
|
|
352
|
+
credit: number;
|
|
353
|
+
description?: string;
|
|
354
|
+
}
|
|
355
|
+
interface BankAccountCreateInput {
|
|
356
|
+
name: string;
|
|
357
|
+
accountNumber: string;
|
|
358
|
+
bankName: string;
|
|
359
|
+
currency?: string;
|
|
360
|
+
accountId?: string;
|
|
361
|
+
routingNumber?: string;
|
|
362
|
+
swiftCode?: string;
|
|
363
|
+
}
|
|
364
|
+
interface BankAccountUpdateInput {
|
|
365
|
+
name?: string;
|
|
366
|
+
bankName?: string;
|
|
367
|
+
currency?: string;
|
|
368
|
+
accountId?: string;
|
|
369
|
+
routingNumber?: string;
|
|
370
|
+
swiftCode?: string;
|
|
371
|
+
}
|
|
372
|
+
interface WebhookCreateInput {
|
|
373
|
+
url: string;
|
|
374
|
+
events: WebhookEvent[];
|
|
375
|
+
secret?: string;
|
|
376
|
+
description?: string;
|
|
377
|
+
}
|
|
378
|
+
interface WebhookUpdateInput {
|
|
379
|
+
url?: string;
|
|
380
|
+
events?: WebhookEvent[];
|
|
381
|
+
secret?: string;
|
|
382
|
+
description?: string;
|
|
383
|
+
isActive?: boolean;
|
|
384
|
+
}
|
|
385
|
+
interface Invoice {
|
|
386
|
+
id: string;
|
|
387
|
+
invoiceNumber: string;
|
|
388
|
+
customerId: string;
|
|
389
|
+
customer?: Customer;
|
|
390
|
+
status: InvoiceStatus;
|
|
391
|
+
issueDate: string;
|
|
392
|
+
dueDate: string;
|
|
393
|
+
lineItems: InvoiceLineItem[];
|
|
394
|
+
subtotal: number;
|
|
395
|
+
taxTotal: number;
|
|
396
|
+
total: number;
|
|
397
|
+
amountDue: number;
|
|
398
|
+
currency: string;
|
|
399
|
+
notes: string | null;
|
|
400
|
+
reference: string | null;
|
|
401
|
+
taxInclusive: boolean;
|
|
402
|
+
pdfUrl: string | null;
|
|
403
|
+
createdAt: string;
|
|
404
|
+
updatedAt: string;
|
|
405
|
+
}
|
|
406
|
+
interface InvoiceLineItem {
|
|
407
|
+
id: string;
|
|
408
|
+
itemId: string | null;
|
|
409
|
+
description: string;
|
|
410
|
+
quantity: number;
|
|
411
|
+
unitPrice: number;
|
|
412
|
+
taxRate: number;
|
|
413
|
+
amount: number;
|
|
414
|
+
accountId: string | null;
|
|
415
|
+
}
|
|
416
|
+
type InvoiceStatus = 'draft' | 'sent' | 'viewed' | 'partially_paid' | 'paid' | 'overdue' | 'voided';
|
|
417
|
+
interface Customer {
|
|
418
|
+
id: string;
|
|
419
|
+
name: string;
|
|
420
|
+
email: string | null;
|
|
421
|
+
phone: string | null;
|
|
422
|
+
type: 'individual' | 'company';
|
|
423
|
+
taxNumber: string | null;
|
|
424
|
+
currency: string;
|
|
425
|
+
billingAddress: Address | null;
|
|
426
|
+
shippingAddress: Address | null;
|
|
427
|
+
notes: string | null;
|
|
428
|
+
isActive: boolean;
|
|
429
|
+
outstandingBalance: number;
|
|
430
|
+
createdAt: string;
|
|
431
|
+
updatedAt: string;
|
|
432
|
+
}
|
|
433
|
+
interface Vendor {
|
|
434
|
+
id: string;
|
|
435
|
+
name: string;
|
|
436
|
+
email: string | null;
|
|
437
|
+
phone: string | null;
|
|
438
|
+
taxNumber: string | null;
|
|
439
|
+
currency: string;
|
|
440
|
+
address: Address | null;
|
|
441
|
+
bankDetails: BankDetails | null;
|
|
442
|
+
notes: string | null;
|
|
443
|
+
isActive: boolean;
|
|
444
|
+
outstandingBalance: number;
|
|
445
|
+
createdAt: string;
|
|
446
|
+
updatedAt: string;
|
|
447
|
+
}
|
|
448
|
+
interface Bill {
|
|
449
|
+
id: string;
|
|
450
|
+
billNumber: string;
|
|
451
|
+
vendorId: string;
|
|
452
|
+
vendor?: Vendor;
|
|
453
|
+
status: BillStatus;
|
|
454
|
+
issueDate: string;
|
|
455
|
+
dueDate: string;
|
|
456
|
+
lineItems: BillLineItem[];
|
|
457
|
+
subtotal: number;
|
|
458
|
+
taxTotal: number;
|
|
459
|
+
total: number;
|
|
460
|
+
amountDue: number;
|
|
461
|
+
currency: string;
|
|
462
|
+
notes: string | null;
|
|
463
|
+
reference: string | null;
|
|
464
|
+
taxInclusive: boolean;
|
|
465
|
+
createdAt: string;
|
|
466
|
+
updatedAt: string;
|
|
467
|
+
}
|
|
468
|
+
interface BillLineItem {
|
|
469
|
+
id: string;
|
|
470
|
+
itemId: string | null;
|
|
471
|
+
description: string;
|
|
472
|
+
quantity: number;
|
|
473
|
+
unitPrice: number;
|
|
474
|
+
taxRate: number;
|
|
475
|
+
amount: number;
|
|
476
|
+
accountId: string | null;
|
|
477
|
+
}
|
|
478
|
+
type BillStatus = 'draft' | 'received' | 'partially_paid' | 'paid' | 'overdue' | 'voided';
|
|
479
|
+
interface Item {
|
|
480
|
+
id: string;
|
|
481
|
+
name: string;
|
|
482
|
+
type: 'product' | 'service';
|
|
483
|
+
description: string | null;
|
|
484
|
+
unitPrice: number | null;
|
|
485
|
+
cost: number | null;
|
|
486
|
+
taxRate: number | null;
|
|
487
|
+
sku: string | null;
|
|
488
|
+
unit: string | null;
|
|
489
|
+
incomeAccountId: string | null;
|
|
490
|
+
expenseAccountId: string | null;
|
|
491
|
+
isActive: boolean;
|
|
492
|
+
createdAt: string;
|
|
493
|
+
updatedAt: string;
|
|
494
|
+
}
|
|
495
|
+
type AccountType = 'asset' | 'liability' | 'equity' | 'revenue' | 'expense';
|
|
496
|
+
interface Account {
|
|
497
|
+
id: string;
|
|
498
|
+
name: string;
|
|
499
|
+
code: string;
|
|
500
|
+
type: AccountType;
|
|
501
|
+
subType: string | null;
|
|
502
|
+
description: string | null;
|
|
503
|
+
currency: string;
|
|
504
|
+
taxRate: number | null;
|
|
505
|
+
isActive: boolean;
|
|
506
|
+
balance: number;
|
|
507
|
+
createdAt: string;
|
|
508
|
+
updatedAt: string;
|
|
509
|
+
}
|
|
510
|
+
interface JournalEntry {
|
|
511
|
+
id: string;
|
|
512
|
+
entryNumber: string;
|
|
513
|
+
date: string;
|
|
514
|
+
reference: string | null;
|
|
515
|
+
description: string | null;
|
|
516
|
+
status: 'draft' | 'posted' | 'voided';
|
|
517
|
+
lines: JournalEntryLine[];
|
|
518
|
+
totalDebit: number;
|
|
519
|
+
totalCredit: number;
|
|
520
|
+
createdAt: string;
|
|
521
|
+
updatedAt: string;
|
|
522
|
+
}
|
|
523
|
+
interface JournalEntryLine {
|
|
524
|
+
id: string;
|
|
525
|
+
accountId: string;
|
|
526
|
+
account?: Account;
|
|
527
|
+
debit: number;
|
|
528
|
+
credit: number;
|
|
529
|
+
description: string | null;
|
|
530
|
+
}
|
|
531
|
+
interface BankAccount {
|
|
532
|
+
id: string;
|
|
533
|
+
name: string;
|
|
534
|
+
accountNumber: string;
|
|
535
|
+
bankName: string;
|
|
536
|
+
currency: string;
|
|
537
|
+
accountId: string | null;
|
|
538
|
+
routingNumber: string | null;
|
|
539
|
+
swiftCode: string | null;
|
|
540
|
+
balance: number;
|
|
541
|
+
isActive: boolean;
|
|
542
|
+
createdAt: string;
|
|
543
|
+
updatedAt: string;
|
|
544
|
+
}
|
|
545
|
+
interface BankTransaction {
|
|
546
|
+
id: string;
|
|
547
|
+
bankAccountId: string;
|
|
548
|
+
date: string;
|
|
549
|
+
description: string;
|
|
550
|
+
amount: number;
|
|
551
|
+
type: 'credit' | 'debit';
|
|
552
|
+
status: 'pending' | 'cleared' | 'reconciled';
|
|
553
|
+
reference: string | null;
|
|
554
|
+
category: string | null;
|
|
555
|
+
matchedTransactionId: string | null;
|
|
556
|
+
createdAt: string;
|
|
557
|
+
updatedAt: string;
|
|
558
|
+
}
|
|
559
|
+
interface Webhook {
|
|
560
|
+
id: string;
|
|
561
|
+
url: string;
|
|
562
|
+
events: WebhookEvent[];
|
|
563
|
+
secret: string;
|
|
564
|
+
description: string | null;
|
|
565
|
+
isActive: boolean;
|
|
566
|
+
createdAt: string;
|
|
567
|
+
updatedAt: string;
|
|
568
|
+
}
|
|
569
|
+
type WebhookEvent = 'invoice.created' | 'invoice.updated' | 'invoice.sent' | 'invoice.paid' | 'invoice.voided' | 'invoice.overdue' | 'customer.created' | 'customer.updated' | 'customer.deleted' | 'vendor.created' | 'vendor.updated' | 'vendor.deleted' | 'bill.created' | 'bill.updated' | 'bill.paid' | 'bill.voided' | 'payment.received' | 'payment.sent' | 'bank_transaction.created' | 'bank_transaction.reconciled';
|
|
570
|
+
interface WebhookPayload {
|
|
571
|
+
id: string;
|
|
572
|
+
event: WebhookEvent;
|
|
573
|
+
createdAt: string;
|
|
574
|
+
data: Record<string, unknown>;
|
|
575
|
+
}
|
|
576
|
+
interface ReportParams {
|
|
577
|
+
startDate: string;
|
|
578
|
+
endDate: string;
|
|
579
|
+
currency?: string;
|
|
580
|
+
comparePrevious?: boolean;
|
|
581
|
+
}
|
|
582
|
+
interface BalanceSheetReport {
|
|
583
|
+
reportType: 'balance_sheet';
|
|
584
|
+
asOf: string;
|
|
585
|
+
currency: string;
|
|
586
|
+
assets: ReportSection;
|
|
587
|
+
liabilities: ReportSection;
|
|
588
|
+
equity: ReportSection;
|
|
589
|
+
totalAssets: number;
|
|
590
|
+
totalLiabilities: number;
|
|
591
|
+
totalEquity: number;
|
|
592
|
+
}
|
|
593
|
+
interface ProfitAndLossReport {
|
|
594
|
+
reportType: 'profit_and_loss';
|
|
595
|
+
startDate: string;
|
|
596
|
+
endDate: string;
|
|
597
|
+
currency: string;
|
|
598
|
+
revenue: ReportSection;
|
|
599
|
+
costOfGoodsSold: ReportSection;
|
|
600
|
+
grossProfit: number;
|
|
601
|
+
operatingExpenses: ReportSection;
|
|
602
|
+
operatingIncome: number;
|
|
603
|
+
otherIncome: ReportSection;
|
|
604
|
+
otherExpenses: ReportSection;
|
|
605
|
+
netIncome: number;
|
|
606
|
+
}
|
|
607
|
+
interface TrialBalanceReport {
|
|
608
|
+
reportType: 'trial_balance';
|
|
609
|
+
asOf: string;
|
|
610
|
+
currency: string;
|
|
611
|
+
accounts: TrialBalanceRow[];
|
|
612
|
+
totalDebits: number;
|
|
613
|
+
totalCredits: number;
|
|
614
|
+
}
|
|
615
|
+
interface TrialBalanceRow {
|
|
616
|
+
accountId: string;
|
|
617
|
+
accountCode: string;
|
|
618
|
+
accountName: string;
|
|
619
|
+
accountType: AccountType;
|
|
620
|
+
debit: number;
|
|
621
|
+
credit: number;
|
|
622
|
+
}
|
|
623
|
+
interface ReportSection {
|
|
624
|
+
label: string;
|
|
625
|
+
rows: ReportRow[];
|
|
626
|
+
total: number;
|
|
627
|
+
}
|
|
628
|
+
interface ReportRow {
|
|
629
|
+
accountId: string;
|
|
630
|
+
accountCode: string;
|
|
631
|
+
accountName: string;
|
|
632
|
+
amount: number;
|
|
633
|
+
previousAmount?: number;
|
|
634
|
+
}
|
|
635
|
+
interface Address {
|
|
636
|
+
line1: string;
|
|
637
|
+
line2?: string;
|
|
638
|
+
city: string;
|
|
639
|
+
state?: string;
|
|
640
|
+
postalCode: string;
|
|
641
|
+
country: string;
|
|
642
|
+
}
|
|
643
|
+
interface BankDetails {
|
|
644
|
+
bankName: string;
|
|
645
|
+
accountNumber: string;
|
|
646
|
+
routingNumber?: string;
|
|
647
|
+
swiftCode?: string;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Low-level HTTP client that handles authentication, retries, rate limiting,
|
|
652
|
+
* and error mapping. Each Cynco instance has exactly one CyncoClient.
|
|
653
|
+
*/
|
|
654
|
+
declare class CyncoClient {
|
|
655
|
+
private readonly _apiKey;
|
|
656
|
+
readonly baseUrl: string;
|
|
657
|
+
private readonly _timeout;
|
|
658
|
+
private readonly _maxRetries;
|
|
659
|
+
private readonly _fetch;
|
|
660
|
+
constructor(apiKey: string, options?: CyncoClientOptions);
|
|
661
|
+
get<T>(path: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<CyncoResponse<T>>;
|
|
662
|
+
getList<T>(path: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<PaginatedResponse<T>>;
|
|
663
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<CyncoResponse<T>>;
|
|
664
|
+
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<CyncoResponse<T>>;
|
|
665
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<CyncoResponse<T>>;
|
|
666
|
+
delete<T = void>(path: string, options?: RequestOptions): Promise<CyncoResponse<T>>;
|
|
667
|
+
private _buildUrl;
|
|
668
|
+
private _request;
|
|
669
|
+
private _shouldRetry;
|
|
670
|
+
private _shouldRetryOnNetworkError;
|
|
671
|
+
/**
|
|
672
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
673
|
+
* For 429 responses, uses Retry-After header if present.
|
|
674
|
+
*/
|
|
675
|
+
private _getRetryDelay;
|
|
676
|
+
private _parseRateLimitHeaders;
|
|
677
|
+
private _safeParseJson;
|
|
678
|
+
private _buildError;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* A paginated list that doubles as an async iterator for auto-pagination.
|
|
683
|
+
*
|
|
684
|
+
* Standard usage (single page):
|
|
685
|
+
* ```ts
|
|
686
|
+
* const page = await cynco.invoices.list({ limit: 20 });
|
|
687
|
+
* console.log(page.data); // Invoice[]
|
|
688
|
+
* console.log(page.pagination); // { total, limit, offset, hasMore }
|
|
689
|
+
* ```
|
|
690
|
+
*
|
|
691
|
+
* Auto-pagination (all pages):
|
|
692
|
+
* ```ts
|
|
693
|
+
* for await (const invoice of cynco.invoices.list({ limit: 50 })) {
|
|
694
|
+
* console.log(invoice.id);
|
|
695
|
+
* }
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
declare class Page<T> implements AsyncIterable<T> {
|
|
699
|
+
readonly data: T[];
|
|
700
|
+
readonly pagination: PaginatedResponse<T>['pagination'];
|
|
701
|
+
readonly links?: PaginatedResponse<T>['links'];
|
|
702
|
+
readonly meta?: PaginatedResponse<T>['meta'];
|
|
703
|
+
private readonly _fetchPage;
|
|
704
|
+
private readonly _params;
|
|
705
|
+
constructor(response: PaginatedResponse<T>, fetchPage: (params: ListParams) => Promise<PaginatedResponse<T>>, params: ListParams);
|
|
706
|
+
/** Whether there are more pages after this one. */
|
|
707
|
+
get hasMore(): boolean;
|
|
708
|
+
/** Fetch the next page. Returns null if there are no more pages. */
|
|
709
|
+
nextPage(): Promise<Page<T> | null>;
|
|
710
|
+
/** Iterate over all items across all pages. */
|
|
711
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* A cursor-based paginated list with async iteration support.
|
|
715
|
+
*/
|
|
716
|
+
declare class CursorPage<T> implements AsyncIterable<T> {
|
|
717
|
+
readonly data: T[];
|
|
718
|
+
readonly pagination: CursorPaginatedResponse<T>['pagination'];
|
|
719
|
+
readonly links?: CursorPaginatedResponse<T>['links'];
|
|
720
|
+
readonly meta?: CursorPaginatedResponse<T>['meta'];
|
|
721
|
+
private readonly _fetchPage;
|
|
722
|
+
private readonly _params;
|
|
723
|
+
constructor(response: CursorPaginatedResponse<T>, fetchPage: (params: ListParams) => Promise<CursorPaginatedResponse<T>>, params: ListParams);
|
|
724
|
+
get hasMore(): boolean;
|
|
725
|
+
nextPage(): Promise<CursorPage<T> | null>;
|
|
726
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
declare class Invoices {
|
|
730
|
+
private readonly _client;
|
|
731
|
+
constructor(_client: CyncoClient);
|
|
732
|
+
/**
|
|
733
|
+
* List invoices with pagination.
|
|
734
|
+
*
|
|
735
|
+
* Returns a `Page` that can be used as an async iterator for auto-pagination:
|
|
736
|
+
* ```ts
|
|
737
|
+
* for await (const invoice of cynco.invoices.list({ limit: 50 })) {
|
|
738
|
+
* console.log(invoice.id);
|
|
739
|
+
* }
|
|
740
|
+
* ```
|
|
741
|
+
*/
|
|
742
|
+
list(params?: InvoiceListParams): Promise<Page<Invoice>>;
|
|
743
|
+
/** Retrieve a single invoice by ID. */
|
|
744
|
+
retrieve(id: string): Promise<Invoice>;
|
|
745
|
+
/** Create a new invoice. */
|
|
746
|
+
create(data: InvoiceCreateInput, options?: RequestOptions): Promise<Invoice>;
|
|
747
|
+
/** Update an existing invoice. */
|
|
748
|
+
update(id: string, data: InvoiceUpdateInput, options?: RequestOptions): Promise<Invoice>;
|
|
749
|
+
/** Delete an invoice. Only draft invoices can be deleted. */
|
|
750
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
751
|
+
/** Send an invoice to the customer via email. */
|
|
752
|
+
send(id: string, options?: RequestOptions): Promise<Invoice>;
|
|
753
|
+
/** Mark an invoice as paid. */
|
|
754
|
+
markPaid(id: string, data?: {
|
|
755
|
+
paidDate?: string;
|
|
756
|
+
paymentMethod?: string;
|
|
757
|
+
}, options?: RequestOptions): Promise<Invoice>;
|
|
758
|
+
/** Void an invoice. */
|
|
759
|
+
void(id: string, options?: RequestOptions): Promise<Invoice>;
|
|
760
|
+
/** Get the PDF download URL for an invoice. */
|
|
761
|
+
getPdf(id: string): Promise<{
|
|
762
|
+
url: string;
|
|
763
|
+
}>;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
declare class Customers {
|
|
767
|
+
private readonly _client;
|
|
768
|
+
constructor(_client: CyncoClient);
|
|
769
|
+
/**
|
|
770
|
+
* List customers with pagination.
|
|
771
|
+
*
|
|
772
|
+
* ```ts
|
|
773
|
+
* for await (const customer of cynco.customers.list({ limit: 50 })) {
|
|
774
|
+
* console.log(customer.name);
|
|
775
|
+
* }
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
list(params?: CustomerListParams): Promise<Page<Customer>>;
|
|
779
|
+
/** Retrieve a single customer by ID. */
|
|
780
|
+
retrieve(id: string): Promise<Customer>;
|
|
781
|
+
/** Create a new customer. */
|
|
782
|
+
create(data: CustomerCreateInput, options?: RequestOptions): Promise<Customer>;
|
|
783
|
+
/** Update an existing customer. */
|
|
784
|
+
update(id: string, data: CustomerUpdateInput, options?: RequestOptions): Promise<Customer>;
|
|
785
|
+
/** Delete a customer. Only customers with no associated records can be deleted. */
|
|
786
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
declare class Vendors {
|
|
790
|
+
private readonly _client;
|
|
791
|
+
constructor(_client: CyncoClient);
|
|
792
|
+
/**
|
|
793
|
+
* List vendors with pagination.
|
|
794
|
+
*
|
|
795
|
+
* ```ts
|
|
796
|
+
* for await (const vendor of cynco.vendors.list({ limit: 50 })) {
|
|
797
|
+
* console.log(vendor.name);
|
|
798
|
+
* }
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
list(params?: VendorListParams): Promise<Page<Vendor>>;
|
|
802
|
+
/** Retrieve a single vendor by ID. */
|
|
803
|
+
retrieve(id: string): Promise<Vendor>;
|
|
804
|
+
/** Create a new vendor. */
|
|
805
|
+
create(data: VendorCreateInput, options?: RequestOptions): Promise<Vendor>;
|
|
806
|
+
/** Update an existing vendor. */
|
|
807
|
+
update(id: string, data: VendorUpdateInput, options?: RequestOptions): Promise<Vendor>;
|
|
808
|
+
/** Delete a vendor. Only vendors with no associated records can be deleted. */
|
|
809
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
declare class Bills {
|
|
813
|
+
private readonly _client;
|
|
814
|
+
constructor(_client: CyncoClient);
|
|
815
|
+
/**
|
|
816
|
+
* List bills with pagination.
|
|
817
|
+
*
|
|
818
|
+
* ```ts
|
|
819
|
+
* for await (const bill of cynco.bills.list({ limit: 50 })) {
|
|
820
|
+
* console.log(bill.billNumber);
|
|
821
|
+
* }
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
list(params?: BillListParams): Promise<Page<Bill>>;
|
|
825
|
+
/** Retrieve a single bill by ID. */
|
|
826
|
+
retrieve(id: string): Promise<Bill>;
|
|
827
|
+
/** Create a new bill. */
|
|
828
|
+
create(data: BillCreateInput, options?: RequestOptions): Promise<Bill>;
|
|
829
|
+
/** Update an existing bill. */
|
|
830
|
+
update(id: string, data: BillUpdateInput, options?: RequestOptions): Promise<Bill>;
|
|
831
|
+
/** Delete a bill. Only draft bills can be deleted. */
|
|
832
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
833
|
+
/** Mark a bill as paid. */
|
|
834
|
+
markPaid(id: string, data?: {
|
|
835
|
+
paidDate?: string;
|
|
836
|
+
paymentMethod?: string;
|
|
837
|
+
}, options?: RequestOptions): Promise<Bill>;
|
|
838
|
+
/** Void a bill. */
|
|
839
|
+
void(id: string, options?: RequestOptions): Promise<Bill>;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
declare class Items {
|
|
843
|
+
private readonly _client;
|
|
844
|
+
constructor(_client: CyncoClient);
|
|
845
|
+
/**
|
|
846
|
+
* List items (products and services) with pagination.
|
|
847
|
+
*
|
|
848
|
+
* ```ts
|
|
849
|
+
* for await (const item of cynco.items.list({ type: 'service' })) {
|
|
850
|
+
* console.log(item.name);
|
|
851
|
+
* }
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
list(params?: ItemListParams): Promise<Page<Item>>;
|
|
855
|
+
/** Retrieve a single item by ID. */
|
|
856
|
+
retrieve(id: string): Promise<Item>;
|
|
857
|
+
/** Create a new item. */
|
|
858
|
+
create(data: ItemCreateInput, options?: RequestOptions): Promise<Item>;
|
|
859
|
+
/** Update an existing item. */
|
|
860
|
+
update(id: string, data: ItemUpdateInput, options?: RequestOptions): Promise<Item>;
|
|
861
|
+
/** Delete an item. Items referenced by invoices or bills cannot be deleted. */
|
|
862
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
declare class Accounts {
|
|
866
|
+
private readonly _client;
|
|
867
|
+
constructor(_client: CyncoClient);
|
|
868
|
+
/**
|
|
869
|
+
* List chart of accounts with pagination.
|
|
870
|
+
*
|
|
871
|
+
* ```ts
|
|
872
|
+
* for await (const account of cynco.accounts.list({ type: 'revenue' })) {
|
|
873
|
+
* console.log(`${account.code} — ${account.name}`);
|
|
874
|
+
* }
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
list(params?: AccountListParams): Promise<Page<Account>>;
|
|
878
|
+
/** Retrieve a single account by ID. */
|
|
879
|
+
retrieve(id: string): Promise<Account>;
|
|
880
|
+
/** Create a new account. */
|
|
881
|
+
create(data: AccountCreateInput, options?: RequestOptions): Promise<Account>;
|
|
882
|
+
/** Update an existing account. */
|
|
883
|
+
update(id: string, data: AccountUpdateInput, options?: RequestOptions): Promise<Account>;
|
|
884
|
+
/** Delete an account. Only unused accounts can be deleted. */
|
|
885
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
declare class JournalEntries {
|
|
889
|
+
private readonly _client;
|
|
890
|
+
constructor(_client: CyncoClient);
|
|
891
|
+
/**
|
|
892
|
+
* List journal entries with pagination.
|
|
893
|
+
*
|
|
894
|
+
* ```ts
|
|
895
|
+
* for await (const entry of cynco.journalEntries.list({ status: 'posted' })) {
|
|
896
|
+
* console.log(entry.entryNumber);
|
|
897
|
+
* }
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
list(params?: JournalEntryListParams): Promise<Page<JournalEntry>>;
|
|
901
|
+
/** Retrieve a single journal entry by ID. */
|
|
902
|
+
retrieve(id: string): Promise<JournalEntry>;
|
|
903
|
+
/** Create a new journal entry. */
|
|
904
|
+
create(data: JournalEntryCreateInput, options?: RequestOptions): Promise<JournalEntry>;
|
|
905
|
+
/** Update a draft journal entry. */
|
|
906
|
+
update(id: string, data: JournalEntryUpdateInput, options?: RequestOptions): Promise<JournalEntry>;
|
|
907
|
+
/** Delete a draft journal entry. */
|
|
908
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
909
|
+
/** Post a draft journal entry to the ledger. */
|
|
910
|
+
post(id: string, options?: RequestOptions): Promise<JournalEntry>;
|
|
911
|
+
/** Void a posted journal entry. */
|
|
912
|
+
void(id: string, options?: RequestOptions): Promise<JournalEntry>;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
declare class BankAccounts {
|
|
916
|
+
private readonly _client;
|
|
917
|
+
constructor(_client: CyncoClient);
|
|
918
|
+
/**
|
|
919
|
+
* List bank accounts with pagination.
|
|
920
|
+
*
|
|
921
|
+
* ```ts
|
|
922
|
+
* for await (const account of cynco.bankAccounts.list()) {
|
|
923
|
+
* console.log(`${account.bankName} — ${account.name}`);
|
|
924
|
+
* }
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
list(params?: BankAccountListParams): Promise<Page<BankAccount>>;
|
|
928
|
+
/** Retrieve a single bank account by ID. */
|
|
929
|
+
retrieve(id: string): Promise<BankAccount>;
|
|
930
|
+
/** Create a new bank account. */
|
|
931
|
+
create(data: BankAccountCreateInput, options?: RequestOptions): Promise<BankAccount>;
|
|
932
|
+
/** Update an existing bank account. */
|
|
933
|
+
update(id: string, data: BankAccountUpdateInput, options?: RequestOptions): Promise<BankAccount>;
|
|
934
|
+
/** Delete a bank account. */
|
|
935
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
936
|
+
/**
|
|
937
|
+
* List transactions for a specific bank account.
|
|
938
|
+
*
|
|
939
|
+
* ```ts
|
|
940
|
+
* for await (const txn of cynco.bankAccounts.listTransactions('ba_123', { status: 'cleared' })) {
|
|
941
|
+
* console.log(`${txn.date} ${txn.description} ${txn.amount}`);
|
|
942
|
+
* }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
listTransactions(bankAccountId: string, params?: BankTransactionListParams): Promise<Page<BankTransaction>>;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
declare class Reports {
|
|
949
|
+
private readonly _client;
|
|
950
|
+
constructor(_client: CyncoClient);
|
|
951
|
+
/** Generate a balance sheet report. */
|
|
952
|
+
balanceSheet(params: Pick<ReportParams, 'endDate' | 'currency' | 'comparePrevious'>): Promise<BalanceSheetReport>;
|
|
953
|
+
/** Generate a profit and loss (income statement) report. */
|
|
954
|
+
profitAndLoss(params: ReportParams): Promise<ProfitAndLossReport>;
|
|
955
|
+
/** Generate a trial balance report. */
|
|
956
|
+
trialBalance(params: Pick<ReportParams, 'endDate' | 'currency'>): Promise<TrialBalanceReport>;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
declare class Webhooks {
|
|
960
|
+
private readonly _client;
|
|
961
|
+
constructor(_client: CyncoClient);
|
|
962
|
+
/**
|
|
963
|
+
* List webhook endpoints with pagination.
|
|
964
|
+
*
|
|
965
|
+
* ```ts
|
|
966
|
+
* for await (const webhook of cynco.webhooks.list()) {
|
|
967
|
+
* console.log(`${webhook.url} — ${webhook.events.join(', ')}`);
|
|
968
|
+
* }
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
list(params?: WebhookListParams): Promise<Page<Webhook>>;
|
|
972
|
+
/** Retrieve a single webhook endpoint by ID. */
|
|
973
|
+
retrieve(id: string): Promise<Webhook>;
|
|
974
|
+
/** Create a new webhook endpoint. */
|
|
975
|
+
create(data: WebhookCreateInput, options?: RequestOptions): Promise<Webhook>;
|
|
976
|
+
/** Update an existing webhook endpoint. */
|
|
977
|
+
update(id: string, data: WebhookUpdateInput, options?: RequestOptions): Promise<Webhook>;
|
|
978
|
+
/** Delete a webhook endpoint. */
|
|
979
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
980
|
+
/** Rotate the signing secret for a webhook endpoint. Returns the new secret. */
|
|
981
|
+
rotateSecret(id: string): Promise<{
|
|
982
|
+
secret: string;
|
|
983
|
+
}>;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* Base error class for all Cynco API errors.
|
|
988
|
+
*
|
|
989
|
+
* Contains the HTTP status code, machine-readable error code, and optional
|
|
990
|
+
* field-level validation details.
|
|
991
|
+
*/
|
|
992
|
+
declare class CyncoError extends Error {
|
|
993
|
+
/** Machine-readable error code from the API (e.g. "validation_error"). */
|
|
994
|
+
readonly code: string;
|
|
995
|
+
/** HTTP status code returned by the API. */
|
|
996
|
+
readonly status: number;
|
|
997
|
+
/** Unique request identifier for support troubleshooting. */
|
|
998
|
+
readonly requestId: string;
|
|
999
|
+
/** Field-level validation details, present on 422 responses. */
|
|
1000
|
+
readonly details?: ValidationDetail[];
|
|
1001
|
+
/** Raw response metadata from the API. */
|
|
1002
|
+
readonly meta?: ResponseMeta;
|
|
1003
|
+
constructor(message: string, options: {
|
|
1004
|
+
code: string;
|
|
1005
|
+
status: number;
|
|
1006
|
+
requestId: string;
|
|
1007
|
+
details?: ValidationDetail[];
|
|
1008
|
+
meta?: ResponseMeta;
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* 401 Unauthorized — the API key is missing, invalid, or revoked.
|
|
1013
|
+
*/
|
|
1014
|
+
declare class AuthenticationError extends CyncoError {
|
|
1015
|
+
constructor(message: string, options: {
|
|
1016
|
+
code: string;
|
|
1017
|
+
status: number;
|
|
1018
|
+
requestId: string;
|
|
1019
|
+
meta?: ResponseMeta;
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* 403 Forbidden — the API key lacks permission for this operation.
|
|
1024
|
+
*/
|
|
1025
|
+
declare class PermissionError extends CyncoError {
|
|
1026
|
+
constructor(message: string, options: {
|
|
1027
|
+
code: string;
|
|
1028
|
+
status: number;
|
|
1029
|
+
requestId: string;
|
|
1030
|
+
meta?: ResponseMeta;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* 404 Not Found — the requested resource does not exist.
|
|
1035
|
+
*/
|
|
1036
|
+
declare class NotFoundError extends CyncoError {
|
|
1037
|
+
constructor(message: string, options: {
|
|
1038
|
+
code: string;
|
|
1039
|
+
status: number;
|
|
1040
|
+
requestId: string;
|
|
1041
|
+
meta?: ResponseMeta;
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* 409 Conflict — the request conflicts with current server state
|
|
1046
|
+
* (e.g. duplicate idempotency key with different parameters).
|
|
1047
|
+
*/
|
|
1048
|
+
declare class ConflictError extends CyncoError {
|
|
1049
|
+
constructor(message: string, options: {
|
|
1050
|
+
code: string;
|
|
1051
|
+
status: number;
|
|
1052
|
+
requestId: string;
|
|
1053
|
+
meta?: ResponseMeta;
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* 422 Unprocessable Entity — request body failed validation.
|
|
1058
|
+
*/
|
|
1059
|
+
declare class ValidationError extends CyncoError {
|
|
1060
|
+
constructor(message: string, options: {
|
|
1061
|
+
code: string;
|
|
1062
|
+
status: number;
|
|
1063
|
+
requestId: string;
|
|
1064
|
+
details?: ValidationDetail[];
|
|
1065
|
+
meta?: ResponseMeta;
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* 429 Too Many Requests — you have exceeded the rate limit.
|
|
1070
|
+
*
|
|
1071
|
+
* The SDK automatically retries rate-limited requests with exponential backoff.
|
|
1072
|
+
* This error is thrown only after all retries are exhausted.
|
|
1073
|
+
*/
|
|
1074
|
+
declare class RateLimitError extends CyncoError {
|
|
1075
|
+
/** Unix timestamp (seconds) when the rate limit resets. */
|
|
1076
|
+
readonly retryAfter: number;
|
|
1077
|
+
constructor(message: string, options: {
|
|
1078
|
+
code: string;
|
|
1079
|
+
status: number;
|
|
1080
|
+
requestId: string;
|
|
1081
|
+
retryAfter: number;
|
|
1082
|
+
meta?: ResponseMeta;
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* 500+ Internal Server Error — something went wrong on the Cynco side.
|
|
1087
|
+
*
|
|
1088
|
+
* The SDK automatically retries server errors with exponential backoff.
|
|
1089
|
+
* This error is thrown only after all retries are exhausted.
|
|
1090
|
+
*/
|
|
1091
|
+
declare class InternalError extends CyncoError {
|
|
1092
|
+
constructor(message: string, options: {
|
|
1093
|
+
code: string;
|
|
1094
|
+
status: number;
|
|
1095
|
+
requestId: string;
|
|
1096
|
+
meta?: ResponseMeta;
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Thrown when a request times out before completing.
|
|
1101
|
+
*/
|
|
1102
|
+
declare class TimeoutError extends CyncoError {
|
|
1103
|
+
constructor(requestId: string, timeoutMs: number);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Thrown when the network is unreachable or the connection was refused.
|
|
1107
|
+
*/
|
|
1108
|
+
declare class ConnectionError extends CyncoError {
|
|
1109
|
+
constructor(requestId: string, cause: Error);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* The official Cynco TypeScript SDK.
|
|
1114
|
+
*
|
|
1115
|
+
* ```ts
|
|
1116
|
+
* import Cynco from 'cynco';
|
|
1117
|
+
*
|
|
1118
|
+
* const cynco = new Cynco('cak_your_api_key');
|
|
1119
|
+
*
|
|
1120
|
+
* const { data } = await cynco.invoices.list({ limit: 20 });
|
|
1121
|
+
* ```
|
|
1122
|
+
*/
|
|
1123
|
+
declare class Cynco {
|
|
1124
|
+
/** Invoices resource. */
|
|
1125
|
+
readonly invoices: Invoices;
|
|
1126
|
+
/** Customers resource. */
|
|
1127
|
+
readonly customers: Customers;
|
|
1128
|
+
/** Vendors resource. */
|
|
1129
|
+
readonly vendors: Vendors;
|
|
1130
|
+
/** Bills resource. */
|
|
1131
|
+
readonly bills: Bills;
|
|
1132
|
+
/** Items (products & services) resource. */
|
|
1133
|
+
readonly items: Items;
|
|
1134
|
+
/** Chart of accounts resource. */
|
|
1135
|
+
readonly accounts: Accounts;
|
|
1136
|
+
/** Journal entries resource. */
|
|
1137
|
+
readonly journalEntries: JournalEntries;
|
|
1138
|
+
/** Bank accounts resource. */
|
|
1139
|
+
readonly bankAccounts: BankAccounts;
|
|
1140
|
+
/** Financial reports resource. */
|
|
1141
|
+
readonly reports: Reports;
|
|
1142
|
+
/** Webhook endpoints resource. */
|
|
1143
|
+
readonly webhooks: Webhooks;
|
|
1144
|
+
/**
|
|
1145
|
+
* Static webhook signature verification utilities.
|
|
1146
|
+
*
|
|
1147
|
+
* ```ts
|
|
1148
|
+
* const valid = Cynco.webhooks.verify(payload, signature, timestamp, secret);
|
|
1149
|
+
* ```
|
|
1150
|
+
*/
|
|
1151
|
+
static readonly webhooks: {
|
|
1152
|
+
verify(payload: string, signature: string, timestamp: string, secret: string, options?: WebhookVerifyOptions): boolean;
|
|
1153
|
+
verifyOrThrow(payload: string, signature: string, timestamp: string, secret: string, options?: WebhookVerifyOptions): void;
|
|
1154
|
+
sign(payload: string, secret: string, timestamp?: number): {
|
|
1155
|
+
signature: string;
|
|
1156
|
+
timestamp: string;
|
|
1157
|
+
};
|
|
1158
|
+
};
|
|
1159
|
+
private readonly _client;
|
|
1160
|
+
/**
|
|
1161
|
+
* Create a new Cynco client instance.
|
|
1162
|
+
*
|
|
1163
|
+
* @param apiKey - Your Cynco API key (starts with `cak_`).
|
|
1164
|
+
* @param options - Optional client configuration.
|
|
1165
|
+
*/
|
|
1166
|
+
constructor(apiKey: string, options?: CyncoClientOptions);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
export { type Account, type AccountCreateInput, type AccountListParams, type AccountType, type AccountUpdateInput, Accounts, type Address, AuthenticationError, type BalanceSheetReport, type BankAccount, type BankAccountCreateInput, type BankAccountListParams, type BankAccountUpdateInput, BankAccounts, type BankDetails, type BankTransaction, type BankTransactionListParams, type Bill, type BillCreateInput, type BillLineItem, type BillLineItemInput, type BillListParams, type BillStatus, type BillUpdateInput, Bills, ConflictError, ConnectionError, CursorPage, type CursorPaginatedResponse, type CursorPagination, type Customer, type CustomerCreateInput, type CustomerListParams, type CustomerUpdateInput, Customers, Cynco, CyncoClient, type CyncoClientOptions, CyncoError, type CyncoResponse, type ErrorResponse, InternalError, type Invoice, type InvoiceCreateInput, type InvoiceLineItem, type InvoiceLineItemInput, type InvoiceListParams, type InvoiceStatus, type InvoiceUpdateInput, Invoices, type Item, type ItemCreateInput, type ItemListParams, type ItemUpdateInput, Items, JournalEntries, type JournalEntry, type JournalEntryCreateInput, type JournalEntryLine, type JournalEntryLineInput, type JournalEntryListParams, type JournalEntryUpdateInput, type ListParams, NotFoundError, type OffsetPagination, Page, type PaginatedResponse, type PaginationLinks, PermissionError, type ProfitAndLossReport, RateLimitError, type RateLimitInfo, type ReportParams, type ReportRow, type ReportSection, Reports, type RequestOptions, type ResponseMeta, TimeoutError, type TrialBalanceReport, type TrialBalanceRow, type ValidationDetail, ValidationError, type Vendor, type VendorCreateInput, type VendorListParams, type VendorUpdateInput, Vendors, type Webhook, type WebhookCreateInput, type WebhookEvent, type WebhookListParams, type WebhookPayload, type WebhookUpdateInput, Webhooks, Cynco as default, webhookVerifier };
|