@cynco/sdk 0.1.0 → 0.2.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 +8 -8
- package/dist/index.cjs +128 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +320 -237
- package/dist/index.d.ts +320 -237
- package/dist/index.js +127 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# cynco
|
|
1
|
+
# @cynco/sdk
|
|
2
2
|
|
|
3
3
|
The official TypeScript SDK for the [Cynco](https://cynco.io) REST API.
|
|
4
4
|
|
|
@@ -7,15 +7,15 @@ Cynco is an AI-native business platform for accounting, invoicing, payments, and
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install cynco
|
|
10
|
+
npm install @cynco/sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
pnpm add cynco
|
|
14
|
+
pnpm add @cynco/sdk
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
yarn add cynco
|
|
18
|
+
yarn add @cynco/sdk
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**Requirements:** Node.js 18 or later.
|
|
@@ -23,7 +23,7 @@ yarn add cynco
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import Cynco from 'cynco';
|
|
26
|
+
import Cynco from '@cynco/sdk';
|
|
27
27
|
|
|
28
28
|
const cynco = new Cynco('cak_your_api_key');
|
|
29
29
|
|
|
@@ -270,7 +270,7 @@ import Cynco, {
|
|
|
270
270
|
ValidationError,
|
|
271
271
|
NotFoundError,
|
|
272
272
|
RateLimitError,
|
|
273
|
-
} from 'cynco';
|
|
273
|
+
} from '@cynco/sdk';
|
|
274
274
|
|
|
275
275
|
try {
|
|
276
276
|
await cynco.customers.create({ name: '' });
|
|
@@ -324,7 +324,7 @@ If a request with the same idempotency key was already processed, the API return
|
|
|
324
324
|
Verify incoming webhook signatures using the static `Cynco.webhooks` utility. No client instantiation needed.
|
|
325
325
|
|
|
326
326
|
```typescript
|
|
327
|
-
import Cynco from 'cynco';
|
|
327
|
+
import Cynco from '@cynco/sdk';
|
|
328
328
|
|
|
329
329
|
// In your webhook handler (e.g. Express)
|
|
330
330
|
app.post('/webhooks/cynco', (req, res) => {
|
|
@@ -393,7 +393,7 @@ import type {
|
|
|
393
393
|
CustomerListParams,
|
|
394
394
|
PaginatedResponse,
|
|
395
395
|
WebhookEvent,
|
|
396
|
-
} from 'cynco';
|
|
396
|
+
} from '@cynco/sdk';
|
|
397
397
|
```
|
|
398
398
|
|
|
399
399
|
## CommonJS
|
package/dist/index.cjs
CHANGED
|
@@ -202,10 +202,10 @@ var CyncoClient = class {
|
|
|
202
202
|
return { success: true, data: void 0 };
|
|
203
203
|
}
|
|
204
204
|
const json = await response.json();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
...
|
|
205
|
+
json["success"] = true;
|
|
206
|
+
if (rateLimitInfo) {
|
|
207
|
+
json["meta"] = {
|
|
208
|
+
...json["meta"],
|
|
209
209
|
requestId,
|
|
210
210
|
rateLimit: rateLimitInfo
|
|
211
211
|
};
|
|
@@ -459,6 +459,7 @@ var webhookVerifier = {
|
|
|
459
459
|
|
|
460
460
|
// src/pagination.ts
|
|
461
461
|
var Page = class _Page {
|
|
462
|
+
success = true;
|
|
462
463
|
data;
|
|
463
464
|
pagination;
|
|
464
465
|
links;
|
|
@@ -482,10 +483,10 @@ var Page = class _Page {
|
|
|
482
483
|
if (!this.hasMore) {
|
|
483
484
|
return null;
|
|
484
485
|
}
|
|
485
|
-
const
|
|
486
|
+
const nextPage = Math.floor(this.pagination.offset / this.pagination.limit) + 2;
|
|
486
487
|
const nextParams = {
|
|
487
488
|
...this._params,
|
|
488
|
-
|
|
489
|
+
page: nextPage
|
|
489
490
|
};
|
|
490
491
|
const response = await this._fetchPage(nextParams);
|
|
491
492
|
return new _Page(response, this._fetchPage, nextParams);
|
|
@@ -502,6 +503,7 @@ var Page = class _Page {
|
|
|
502
503
|
}
|
|
503
504
|
};
|
|
504
505
|
var CursorPage = class _CursorPage {
|
|
506
|
+
success = true;
|
|
505
507
|
data;
|
|
506
508
|
pagination;
|
|
507
509
|
links;
|
|
@@ -540,6 +542,51 @@ var CursorPage = class _CursorPage {
|
|
|
540
542
|
}
|
|
541
543
|
}
|
|
542
544
|
};
|
|
545
|
+
var PagePromise = class {
|
|
546
|
+
_promise;
|
|
547
|
+
constructor(promise) {
|
|
548
|
+
this._promise = promise;
|
|
549
|
+
}
|
|
550
|
+
/** Satisfy PromiseLike so `await` works. */
|
|
551
|
+
then(onfulfilled, onrejected) {
|
|
552
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
553
|
+
}
|
|
554
|
+
/** Satisfy Promise-like `catch`. */
|
|
555
|
+
catch(onrejected) {
|
|
556
|
+
return this._promise.catch(onrejected);
|
|
557
|
+
}
|
|
558
|
+
/** Satisfy Promise-like `finally`. */
|
|
559
|
+
finally(onfinally) {
|
|
560
|
+
return this._promise.finally(onfinally);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Iterate over all items across all pages.
|
|
564
|
+
* Fetches the first page lazily, then auto-paginates.
|
|
565
|
+
*/
|
|
566
|
+
async *[Symbol.asyncIterator]() {
|
|
567
|
+
const page = await this._promise;
|
|
568
|
+
yield* page;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
var CursorPagePromise = class {
|
|
572
|
+
_promise;
|
|
573
|
+
constructor(promise) {
|
|
574
|
+
this._promise = promise;
|
|
575
|
+
}
|
|
576
|
+
then(onfulfilled, onrejected) {
|
|
577
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
578
|
+
}
|
|
579
|
+
catch(onrejected) {
|
|
580
|
+
return this._promise.catch(onrejected);
|
|
581
|
+
}
|
|
582
|
+
finally(onfinally) {
|
|
583
|
+
return this._promise.finally(onfinally);
|
|
584
|
+
}
|
|
585
|
+
async *[Symbol.asyncIterator]() {
|
|
586
|
+
const page = await this._promise;
|
|
587
|
+
yield* page;
|
|
588
|
+
}
|
|
589
|
+
};
|
|
543
590
|
|
|
544
591
|
// src/resources/invoices.ts
|
|
545
592
|
var Invoices = class {
|
|
@@ -549,35 +596,35 @@ var Invoices = class {
|
|
|
549
596
|
/**
|
|
550
597
|
* List invoices with pagination.
|
|
551
598
|
*
|
|
552
|
-
* Returns a `
|
|
599
|
+
* Returns a `PagePromise` that can be awaited for a single page or used
|
|
600
|
+
* directly as an async iterator for auto-pagination:
|
|
553
601
|
* ```ts
|
|
602
|
+
* // Single page
|
|
603
|
+
* const page = await cynco.invoices.list({ limit: 20 });
|
|
604
|
+
* console.log(page.data);
|
|
605
|
+
*
|
|
606
|
+
* // Auto-pagination
|
|
554
607
|
* for await (const invoice of cynco.invoices.list({ limit: 50 })) {
|
|
555
608
|
* console.log(invoice.id);
|
|
556
609
|
* }
|
|
557
610
|
* ```
|
|
558
611
|
*/
|
|
559
|
-
|
|
612
|
+
list(params) {
|
|
560
613
|
const fetchPage = async (p) => {
|
|
561
614
|
return this._client.getList("/invoices", p);
|
|
562
615
|
};
|
|
563
|
-
|
|
564
|
-
|
|
616
|
+
return new PagePromise(
|
|
617
|
+
fetchPage(params ?? {}).then(
|
|
618
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
619
|
+
)
|
|
620
|
+
);
|
|
565
621
|
}
|
|
566
622
|
/** Retrieve a single invoice by ID. */
|
|
567
623
|
async retrieve(id) {
|
|
568
624
|
const response = await this._client.get(`/invoices/${id}`);
|
|
569
625
|
return response.data;
|
|
570
626
|
}
|
|
571
|
-
/**
|
|
572
|
-
async create(data, options) {
|
|
573
|
-
const response = await this._client.post(
|
|
574
|
-
"/invoices",
|
|
575
|
-
data,
|
|
576
|
-
options
|
|
577
|
-
);
|
|
578
|
-
return response.data;
|
|
579
|
-
}
|
|
580
|
-
/** Update an existing invoice. */
|
|
627
|
+
/** Update an existing invoice (memo, paymentTerms, dueDate only). */
|
|
581
628
|
async update(id, data, options) {
|
|
582
629
|
const response = await this._client.patch(
|
|
583
630
|
`/invoices/${id}`,
|
|
@@ -640,15 +687,18 @@ var Customers = class {
|
|
|
640
687
|
* }
|
|
641
688
|
* ```
|
|
642
689
|
*/
|
|
643
|
-
|
|
690
|
+
list(params) {
|
|
644
691
|
const fetchPage = async (p) => {
|
|
645
692
|
return this._client.getList(
|
|
646
693
|
"/customers",
|
|
647
694
|
p
|
|
648
695
|
);
|
|
649
696
|
};
|
|
650
|
-
|
|
651
|
-
|
|
697
|
+
return new PagePromise(
|
|
698
|
+
fetchPage(params ?? {}).then(
|
|
699
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
700
|
+
)
|
|
701
|
+
);
|
|
652
702
|
}
|
|
653
703
|
/** Retrieve a single customer by ID. */
|
|
654
704
|
async retrieve(id) {
|
|
@@ -693,15 +743,18 @@ var Vendors = class {
|
|
|
693
743
|
* }
|
|
694
744
|
* ```
|
|
695
745
|
*/
|
|
696
|
-
|
|
746
|
+
list(params) {
|
|
697
747
|
const fetchPage = async (p) => {
|
|
698
748
|
return this._client.getList(
|
|
699
749
|
"/vendors",
|
|
700
750
|
p
|
|
701
751
|
);
|
|
702
752
|
};
|
|
703
|
-
|
|
704
|
-
|
|
753
|
+
return new PagePromise(
|
|
754
|
+
fetchPage(params ?? {}).then(
|
|
755
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
756
|
+
)
|
|
757
|
+
);
|
|
705
758
|
}
|
|
706
759
|
/** Retrieve a single vendor by ID. */
|
|
707
760
|
async retrieve(id) {
|
|
@@ -746,26 +799,24 @@ var Bills = class {
|
|
|
746
799
|
* }
|
|
747
800
|
* ```
|
|
748
801
|
*/
|
|
749
|
-
|
|
802
|
+
list(params) {
|
|
750
803
|
const fetchPage = async (p) => {
|
|
751
804
|
return this._client.getList(
|
|
752
805
|
"/bills",
|
|
753
806
|
p
|
|
754
807
|
);
|
|
755
808
|
};
|
|
756
|
-
|
|
757
|
-
|
|
809
|
+
return new PagePromise(
|
|
810
|
+
fetchPage(params ?? {}).then(
|
|
811
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
812
|
+
)
|
|
813
|
+
);
|
|
758
814
|
}
|
|
759
815
|
/** Retrieve a single bill by ID. */
|
|
760
816
|
async retrieve(id) {
|
|
761
817
|
const response = await this._client.get(`/bills/${id}`);
|
|
762
818
|
return response.data;
|
|
763
819
|
}
|
|
764
|
-
/** Create a new bill. */
|
|
765
|
-
async create(data, options) {
|
|
766
|
-
const response = await this._client.post("/bills", data, options);
|
|
767
|
-
return response.data;
|
|
768
|
-
}
|
|
769
820
|
/** Update an existing bill. */
|
|
770
821
|
async update(id, data, options) {
|
|
771
822
|
const response = await this._client.patch(
|
|
@@ -813,15 +864,18 @@ var Items = class {
|
|
|
813
864
|
* }
|
|
814
865
|
* ```
|
|
815
866
|
*/
|
|
816
|
-
|
|
867
|
+
list(params) {
|
|
817
868
|
const fetchPage = async (p) => {
|
|
818
869
|
return this._client.getList(
|
|
819
870
|
"/items",
|
|
820
871
|
p
|
|
821
872
|
);
|
|
822
873
|
};
|
|
823
|
-
|
|
824
|
-
|
|
874
|
+
return new PagePromise(
|
|
875
|
+
fetchPage(params ?? {}).then(
|
|
876
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
877
|
+
)
|
|
878
|
+
);
|
|
825
879
|
}
|
|
826
880
|
/** Retrieve a single item by ID. */
|
|
827
881
|
async retrieve(id) {
|
|
@@ -854,51 +908,33 @@ var Accounts = class {
|
|
|
854
908
|
this._client = _client;
|
|
855
909
|
}
|
|
856
910
|
/**
|
|
857
|
-
* List chart of accounts
|
|
911
|
+
* List chart of accounts.
|
|
858
912
|
*
|
|
859
913
|
* ```ts
|
|
860
|
-
*
|
|
861
|
-
*
|
|
914
|
+
* const page = await cynco.accounts.list({ account_type: 'revenue' });
|
|
915
|
+
* for (const account of page.data) {
|
|
916
|
+
* console.log(`${account.accountCode} — ${account.accountName}`);
|
|
862
917
|
* }
|
|
863
918
|
* ```
|
|
864
919
|
*/
|
|
865
|
-
|
|
920
|
+
list(params) {
|
|
866
921
|
const fetchPage = async (p) => {
|
|
867
922
|
return this._client.getList(
|
|
868
923
|
"/accounts",
|
|
869
924
|
p
|
|
870
925
|
);
|
|
871
926
|
};
|
|
872
|
-
|
|
873
|
-
|
|
927
|
+
return new PagePromise(
|
|
928
|
+
fetchPage(params ?? {}).then(
|
|
929
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
930
|
+
)
|
|
931
|
+
);
|
|
874
932
|
}
|
|
875
933
|
/** Retrieve a single account by ID. */
|
|
876
934
|
async retrieve(id) {
|
|
877
|
-
const response = await this._client.get(`/accounts
|
|
878
|
-
return response.data;
|
|
879
|
-
}
|
|
880
|
-
/** Create a new account. */
|
|
881
|
-
async create(data, options) {
|
|
882
|
-
const response = await this._client.post(
|
|
883
|
-
"/accounts",
|
|
884
|
-
data,
|
|
885
|
-
options
|
|
886
|
-
);
|
|
935
|
+
const response = await this._client.get(`/accounts?id=${encodeURIComponent(id)}`);
|
|
887
936
|
return response.data;
|
|
888
937
|
}
|
|
889
|
-
/** Update an existing account. */
|
|
890
|
-
async update(id, data, options) {
|
|
891
|
-
const response = await this._client.patch(
|
|
892
|
-
`/accounts/${id}`,
|
|
893
|
-
data,
|
|
894
|
-
options
|
|
895
|
-
);
|
|
896
|
-
return response.data;
|
|
897
|
-
}
|
|
898
|
-
/** Delete an account. Only unused accounts can be deleted. */
|
|
899
|
-
async delete(id, options) {
|
|
900
|
-
await this._client.delete(`/accounts/${id}`, options);
|
|
901
|
-
}
|
|
902
938
|
};
|
|
903
939
|
|
|
904
940
|
// src/resources/journal-entries.ts
|
|
@@ -915,15 +951,18 @@ var JournalEntries = class {
|
|
|
915
951
|
* }
|
|
916
952
|
* ```
|
|
917
953
|
*/
|
|
918
|
-
|
|
954
|
+
list(params) {
|
|
919
955
|
const fetchPage = async (p) => {
|
|
920
956
|
return this._client.getList(
|
|
921
957
|
"/journal-entries",
|
|
922
958
|
p
|
|
923
959
|
);
|
|
924
960
|
};
|
|
925
|
-
|
|
926
|
-
|
|
961
|
+
return new PagePromise(
|
|
962
|
+
fetchPage(params ?? {}).then(
|
|
963
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
964
|
+
)
|
|
965
|
+
);
|
|
927
966
|
}
|
|
928
967
|
/** Retrieve a single journal entry by ID. */
|
|
929
968
|
async retrieve(id) {
|
|
@@ -988,15 +1027,18 @@ var BankAccounts = class {
|
|
|
988
1027
|
* }
|
|
989
1028
|
* ```
|
|
990
1029
|
*/
|
|
991
|
-
|
|
1030
|
+
list(params) {
|
|
992
1031
|
const fetchPage = async (p) => {
|
|
993
1032
|
return this._client.getList(
|
|
994
1033
|
"/bank-accounts",
|
|
995
1034
|
p
|
|
996
1035
|
);
|
|
997
1036
|
};
|
|
998
|
-
|
|
999
|
-
|
|
1037
|
+
return new PagePromise(
|
|
1038
|
+
fetchPage(params ?? {}).then(
|
|
1039
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1040
|
+
)
|
|
1041
|
+
);
|
|
1000
1042
|
}
|
|
1001
1043
|
/** Retrieve a single bank account by ID. */
|
|
1002
1044
|
async retrieve(id) {
|
|
@@ -1036,15 +1078,18 @@ var BankAccounts = class {
|
|
|
1036
1078
|
* }
|
|
1037
1079
|
* ```
|
|
1038
1080
|
*/
|
|
1039
|
-
|
|
1081
|
+
listTransactions(bankAccountId, params) {
|
|
1040
1082
|
const fetchPage = async (p) => {
|
|
1041
1083
|
return this._client.getList(
|
|
1042
1084
|
`/bank-accounts/${bankAccountId}/transactions`,
|
|
1043
1085
|
p
|
|
1044
1086
|
);
|
|
1045
1087
|
};
|
|
1046
|
-
|
|
1047
|
-
|
|
1088
|
+
return new PagePromise(
|
|
1089
|
+
fetchPage(params ?? {}).then(
|
|
1090
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1091
|
+
)
|
|
1092
|
+
);
|
|
1048
1093
|
}
|
|
1049
1094
|
};
|
|
1050
1095
|
|
|
@@ -1093,15 +1138,18 @@ var Webhooks = class {
|
|
|
1093
1138
|
* }
|
|
1094
1139
|
* ```
|
|
1095
1140
|
*/
|
|
1096
|
-
|
|
1141
|
+
list(params) {
|
|
1097
1142
|
const fetchPage = async (p) => {
|
|
1098
1143
|
return this._client.getList(
|
|
1099
1144
|
"/webhooks",
|
|
1100
1145
|
p
|
|
1101
1146
|
);
|
|
1102
1147
|
};
|
|
1103
|
-
|
|
1104
|
-
|
|
1148
|
+
return new PagePromise(
|
|
1149
|
+
fetchPage(params ?? {}).then(
|
|
1150
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1151
|
+
)
|
|
1152
|
+
);
|
|
1105
1153
|
}
|
|
1106
1154
|
/** Retrieve a single webhook endpoint by ID. */
|
|
1107
1155
|
async retrieve(id) {
|
|
@@ -1199,6 +1247,7 @@ exports.Bills = Bills;
|
|
|
1199
1247
|
exports.ConflictError = ConflictError;
|
|
1200
1248
|
exports.ConnectionError = ConnectionError;
|
|
1201
1249
|
exports.CursorPage = CursorPage;
|
|
1250
|
+
exports.CursorPagePromise = CursorPagePromise;
|
|
1202
1251
|
exports.Customers = Customers;
|
|
1203
1252
|
exports.Cynco = Cynco;
|
|
1204
1253
|
exports.CyncoClient = CyncoClient;
|
|
@@ -1209,6 +1258,7 @@ exports.Items = Items;
|
|
|
1209
1258
|
exports.JournalEntries = JournalEntries;
|
|
1210
1259
|
exports.NotFoundError = NotFoundError;
|
|
1211
1260
|
exports.Page = Page;
|
|
1261
|
+
exports.PagePromise = PagePromise;
|
|
1212
1262
|
exports.PermissionError = PermissionError;
|
|
1213
1263
|
exports.RateLimitError = RateLimitError;
|
|
1214
1264
|
exports.Reports = Reports;
|