Skip to content

Commit 109f05f

Browse files
committed
fix: rewrite all types to match actual API serializer output
BREAKING: Resource types, list params, create/update inputs all rewritten to exactly match what the API returns. Removed phantom fields, added missing fields, fixed field name mismatches. Key changes: - Invoice: taxes (not taxTotal), totalAmount (not total), added customerName/Email, paidAmount, hasDeposit, depositAmount, memo - Customer/Vendor: flat address fields (not nested Address object) - Bill: subtotalAmount/taxAmount/totalAmount (not subtotal/taxTotal) - Item: added discountRate, removed phantom sku/unit/cost - Account: accountCode/accountName/accountType (not code/name/type), added 10 missing fields (normalBalance, path, level, etc.) - Status enums: Invoice finalized/deposit_paid/deposit_due, Bill in_review/pending_approval/approved/awaiting_payment/scheduled - ListParams: page-based (not offset), actual filter names from Zod - Removed phantom methods: invoices.create(), bills.create(), accounts.create/update/delete()
1 parent 06f343b commit 109f05f

9 files changed

Lines changed: 313 additions & 338 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cynco/sdk",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Official TypeScript SDK for the Cynco REST API",
55
"author": "Cynco Sdn Bhd",
66
"license": "MIT",

src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,14 @@ export type {
149149
BankTransactionListParams,
150150
WebhookListParams,
151151
// Create / update inputs
152-
InvoiceCreateInput,
153152
InvoiceUpdateInput,
154-
InvoiceLineItemInput,
155153
CustomerCreateInput,
156154
CustomerUpdateInput,
157155
VendorCreateInput,
158156
VendorUpdateInput,
159-
BillCreateInput,
160157
BillUpdateInput,
161-
BillLineItemInput,
162158
ItemCreateInput,
163159
ItemUpdateInput,
164-
AccountCreateInput,
165-
AccountUpdateInput,
166160
JournalEntryCreateInput,
167161
JournalEntryUpdateInput,
168162
JournalEntryLineInput,
@@ -172,12 +166,10 @@ export type {
172166
WebhookUpdateInput,
173167
// Resource types
174168
Invoice,
175-
InvoiceLineItem,
176169
InvoiceStatus,
177170
Customer,
178171
Vendor,
179172
Bill,
180-
BillLineItem,
181173
BillStatus,
182174
Item,
183175
Account,
@@ -197,7 +189,4 @@ export type {
197189
TrialBalanceRow,
198190
ReportSection,
199191
ReportRow,
200-
// Shared
201-
Address,
202-
BankDetails,
203192
} from './types.js';

src/pagination.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ export class Page<T> implements AsyncIterable<T> {
5757
return null;
5858
}
5959

60-
const nextOffset = this.pagination.offset + this.pagination.limit;
60+
// The API uses page-based params but returns offset in the pagination response.
61+
// Compute the next page number from the current offset + limit.
62+
const nextPage = Math.floor(this.pagination.offset / this.pagination.limit) + 2;
6163
const nextParams: ListParams = {
6264
...this._params,
63-
offset: nextOffset,
65+
page: nextPage,
6466
};
6567

6668
const response = await this._fetchPage(nextParams);

src/resources/accounts.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ import { Page, PagePromise } from '../pagination.js';
33
import type {
44
Account,
55
AccountListParams,
6-
AccountCreateInput,
7-
AccountUpdateInput,
86
PaginatedResponse,
9-
RequestOptions,
107
} from '../types.js';
118

129
export class Accounts {
1310
constructor(private readonly _client: CyncoClient) {}
1411

1512
/**
16-
* List chart of accounts with pagination.
13+
* List chart of accounts.
1714
*
1815
* ```ts
19-
* for await (const account of cynco.accounts.list({ type: 'revenue' })) {
20-
* console.log(`${account.code} — ${account.name}`);
16+
* const page = await cynco.accounts.list({ account_type: 'revenue' });
17+
* for (const account of page.data) {
18+
* console.log(`${account.accountCode} — ${account.accountName}`);
2119
* }
2220
* ```
2321
*/
@@ -40,39 +38,7 @@ export class Accounts {
4038

4139
/** Retrieve a single account by ID. */
4240
async retrieve(id: string): Promise<Account> {
43-
const response = await this._client.get<Account>(`/accounts/${id}`);
44-
return response.data;
45-
}
46-
47-
/** Create a new account. */
48-
async create(
49-
data: AccountCreateInput,
50-
options?: RequestOptions,
51-
): Promise<Account> {
52-
const response = await this._client.post<Account>(
53-
'/accounts',
54-
data,
55-
options,
56-
);
57-
return response.data;
58-
}
59-
60-
/** Update an existing account. */
61-
async update(
62-
id: string,
63-
data: AccountUpdateInput,
64-
options?: RequestOptions,
65-
): Promise<Account> {
66-
const response = await this._client.patch<Account>(
67-
`/accounts/${id}`,
68-
data,
69-
options,
70-
);
71-
return response.data;
72-
}
73-
74-
/** Delete an account. Only unused accounts can be deleted. */
75-
async delete(id: string, options?: RequestOptions): Promise<void> {
76-
await this._client.delete(`/accounts/${id}`, options);
41+
const response = await this._client.get<Account>(`/accounts?id=${encodeURIComponent(id)}`);
42+
return response.data; // accounts uses ?id= since there's no /:id route
7743
}
7844
}

src/resources/bills.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Page, PagePromise } from '../pagination.js';
33
import type {
44
Bill,
55
BillListParams,
6-
BillCreateInput,
76
BillUpdateInput,
87
PaginatedResponse,
98
RequestOptions,
@@ -44,15 +43,6 @@ export class Bills {
4443
return response.data;
4544
}
4645

47-
/** Create a new bill. */
48-
async create(
49-
data: BillCreateInput,
50-
options?: RequestOptions,
51-
): Promise<Bill> {
52-
const response = await this._client.post<Bill>('/bills', data, options);
53-
return response.data;
54-
}
55-
5646
/** Update an existing bill. */
5747
async update(
5848
id: string,

src/resources/invoices.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Page, PagePromise } from '../pagination.js';
33
import type {
44
Invoice,
55
InvoiceListParams,
6-
InvoiceCreateInput,
76
InvoiceUpdateInput,
87
PaginatedResponse,
98
RequestOptions,
@@ -48,20 +47,7 @@ export class Invoices {
4847
return response.data;
4948
}
5049

51-
/** Create a new invoice. */
52-
async create(
53-
data: InvoiceCreateInput,
54-
options?: RequestOptions,
55-
): Promise<Invoice> {
56-
const response = await this._client.post<Invoice>(
57-
'/invoices',
58-
data,
59-
options,
60-
);
61-
return response.data;
62-
}
63-
64-
/** Update an existing invoice. */
50+
/** Update an existing invoice (memo, paymentTerms, dueDate only). */
6551
async update(
6652
id: string,
6753
data: InvoiceUpdateInput,

0 commit comments

Comments
 (0)