@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/dist/index.js
CHANGED
|
@@ -198,10 +198,10 @@ var CyncoClient = class {
|
|
|
198
198
|
return { success: true, data: void 0 };
|
|
199
199
|
}
|
|
200
200
|
const json = await response.json();
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
...
|
|
201
|
+
json["success"] = true;
|
|
202
|
+
if (rateLimitInfo) {
|
|
203
|
+
json["meta"] = {
|
|
204
|
+
...json["meta"],
|
|
205
205
|
requestId,
|
|
206
206
|
rateLimit: rateLimitInfo
|
|
207
207
|
};
|
|
@@ -455,6 +455,7 @@ var webhookVerifier = {
|
|
|
455
455
|
|
|
456
456
|
// src/pagination.ts
|
|
457
457
|
var Page = class _Page {
|
|
458
|
+
success = true;
|
|
458
459
|
data;
|
|
459
460
|
pagination;
|
|
460
461
|
links;
|
|
@@ -478,10 +479,10 @@ var Page = class _Page {
|
|
|
478
479
|
if (!this.hasMore) {
|
|
479
480
|
return null;
|
|
480
481
|
}
|
|
481
|
-
const
|
|
482
|
+
const nextPage = Math.floor(this.pagination.offset / this.pagination.limit) + 2;
|
|
482
483
|
const nextParams = {
|
|
483
484
|
...this._params,
|
|
484
|
-
|
|
485
|
+
page: nextPage
|
|
485
486
|
};
|
|
486
487
|
const response = await this._fetchPage(nextParams);
|
|
487
488
|
return new _Page(response, this._fetchPage, nextParams);
|
|
@@ -498,6 +499,7 @@ var Page = class _Page {
|
|
|
498
499
|
}
|
|
499
500
|
};
|
|
500
501
|
var CursorPage = class _CursorPage {
|
|
502
|
+
success = true;
|
|
501
503
|
data;
|
|
502
504
|
pagination;
|
|
503
505
|
links;
|
|
@@ -536,6 +538,51 @@ var CursorPage = class _CursorPage {
|
|
|
536
538
|
}
|
|
537
539
|
}
|
|
538
540
|
};
|
|
541
|
+
var PagePromise = class {
|
|
542
|
+
_promise;
|
|
543
|
+
constructor(promise) {
|
|
544
|
+
this._promise = promise;
|
|
545
|
+
}
|
|
546
|
+
/** Satisfy PromiseLike so `await` works. */
|
|
547
|
+
then(onfulfilled, onrejected) {
|
|
548
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
549
|
+
}
|
|
550
|
+
/** Satisfy Promise-like `catch`. */
|
|
551
|
+
catch(onrejected) {
|
|
552
|
+
return this._promise.catch(onrejected);
|
|
553
|
+
}
|
|
554
|
+
/** Satisfy Promise-like `finally`. */
|
|
555
|
+
finally(onfinally) {
|
|
556
|
+
return this._promise.finally(onfinally);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Iterate over all items across all pages.
|
|
560
|
+
* Fetches the first page lazily, then auto-paginates.
|
|
561
|
+
*/
|
|
562
|
+
async *[Symbol.asyncIterator]() {
|
|
563
|
+
const page = await this._promise;
|
|
564
|
+
yield* page;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
var CursorPagePromise = class {
|
|
568
|
+
_promise;
|
|
569
|
+
constructor(promise) {
|
|
570
|
+
this._promise = promise;
|
|
571
|
+
}
|
|
572
|
+
then(onfulfilled, onrejected) {
|
|
573
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
574
|
+
}
|
|
575
|
+
catch(onrejected) {
|
|
576
|
+
return this._promise.catch(onrejected);
|
|
577
|
+
}
|
|
578
|
+
finally(onfinally) {
|
|
579
|
+
return this._promise.finally(onfinally);
|
|
580
|
+
}
|
|
581
|
+
async *[Symbol.asyncIterator]() {
|
|
582
|
+
const page = await this._promise;
|
|
583
|
+
yield* page;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
539
586
|
|
|
540
587
|
// src/resources/invoices.ts
|
|
541
588
|
var Invoices = class {
|
|
@@ -545,35 +592,35 @@ var Invoices = class {
|
|
|
545
592
|
/**
|
|
546
593
|
* List invoices with pagination.
|
|
547
594
|
*
|
|
548
|
-
* Returns a `
|
|
595
|
+
* Returns a `PagePromise` that can be awaited for a single page or used
|
|
596
|
+
* directly as an async iterator for auto-pagination:
|
|
549
597
|
* ```ts
|
|
598
|
+
* // Single page
|
|
599
|
+
* const page = await cynco.invoices.list({ limit: 20 });
|
|
600
|
+
* console.log(page.data);
|
|
601
|
+
*
|
|
602
|
+
* // Auto-pagination
|
|
550
603
|
* for await (const invoice of cynco.invoices.list({ limit: 50 })) {
|
|
551
604
|
* console.log(invoice.id);
|
|
552
605
|
* }
|
|
553
606
|
* ```
|
|
554
607
|
*/
|
|
555
|
-
|
|
608
|
+
list(params) {
|
|
556
609
|
const fetchPage = async (p) => {
|
|
557
610
|
return this._client.getList("/invoices", p);
|
|
558
611
|
};
|
|
559
|
-
|
|
560
|
-
|
|
612
|
+
return new PagePromise(
|
|
613
|
+
fetchPage(params ?? {}).then(
|
|
614
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
615
|
+
)
|
|
616
|
+
);
|
|
561
617
|
}
|
|
562
618
|
/** Retrieve a single invoice by ID. */
|
|
563
619
|
async retrieve(id) {
|
|
564
620
|
const response = await this._client.get(`/invoices/${id}`);
|
|
565
621
|
return response.data;
|
|
566
622
|
}
|
|
567
|
-
/**
|
|
568
|
-
async create(data, options) {
|
|
569
|
-
const response = await this._client.post(
|
|
570
|
-
"/invoices",
|
|
571
|
-
data,
|
|
572
|
-
options
|
|
573
|
-
);
|
|
574
|
-
return response.data;
|
|
575
|
-
}
|
|
576
|
-
/** Update an existing invoice. */
|
|
623
|
+
/** Update an existing invoice (memo, paymentTerms, dueDate only). */
|
|
577
624
|
async update(id, data, options) {
|
|
578
625
|
const response = await this._client.patch(
|
|
579
626
|
`/invoices/${id}`,
|
|
@@ -636,15 +683,18 @@ var Customers = class {
|
|
|
636
683
|
* }
|
|
637
684
|
* ```
|
|
638
685
|
*/
|
|
639
|
-
|
|
686
|
+
list(params) {
|
|
640
687
|
const fetchPage = async (p) => {
|
|
641
688
|
return this._client.getList(
|
|
642
689
|
"/customers",
|
|
643
690
|
p
|
|
644
691
|
);
|
|
645
692
|
};
|
|
646
|
-
|
|
647
|
-
|
|
693
|
+
return new PagePromise(
|
|
694
|
+
fetchPage(params ?? {}).then(
|
|
695
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
696
|
+
)
|
|
697
|
+
);
|
|
648
698
|
}
|
|
649
699
|
/** Retrieve a single customer by ID. */
|
|
650
700
|
async retrieve(id) {
|
|
@@ -689,15 +739,18 @@ var Vendors = class {
|
|
|
689
739
|
* }
|
|
690
740
|
* ```
|
|
691
741
|
*/
|
|
692
|
-
|
|
742
|
+
list(params) {
|
|
693
743
|
const fetchPage = async (p) => {
|
|
694
744
|
return this._client.getList(
|
|
695
745
|
"/vendors",
|
|
696
746
|
p
|
|
697
747
|
);
|
|
698
748
|
};
|
|
699
|
-
|
|
700
|
-
|
|
749
|
+
return new PagePromise(
|
|
750
|
+
fetchPage(params ?? {}).then(
|
|
751
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
752
|
+
)
|
|
753
|
+
);
|
|
701
754
|
}
|
|
702
755
|
/** Retrieve a single vendor by ID. */
|
|
703
756
|
async retrieve(id) {
|
|
@@ -742,26 +795,24 @@ var Bills = class {
|
|
|
742
795
|
* }
|
|
743
796
|
* ```
|
|
744
797
|
*/
|
|
745
|
-
|
|
798
|
+
list(params) {
|
|
746
799
|
const fetchPage = async (p) => {
|
|
747
800
|
return this._client.getList(
|
|
748
801
|
"/bills",
|
|
749
802
|
p
|
|
750
803
|
);
|
|
751
804
|
};
|
|
752
|
-
|
|
753
|
-
|
|
805
|
+
return new PagePromise(
|
|
806
|
+
fetchPage(params ?? {}).then(
|
|
807
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
808
|
+
)
|
|
809
|
+
);
|
|
754
810
|
}
|
|
755
811
|
/** Retrieve a single bill by ID. */
|
|
756
812
|
async retrieve(id) {
|
|
757
813
|
const response = await this._client.get(`/bills/${id}`);
|
|
758
814
|
return response.data;
|
|
759
815
|
}
|
|
760
|
-
/** Create a new bill. */
|
|
761
|
-
async create(data, options) {
|
|
762
|
-
const response = await this._client.post("/bills", data, options);
|
|
763
|
-
return response.data;
|
|
764
|
-
}
|
|
765
816
|
/** Update an existing bill. */
|
|
766
817
|
async update(id, data, options) {
|
|
767
818
|
const response = await this._client.patch(
|
|
@@ -809,15 +860,18 @@ var Items = class {
|
|
|
809
860
|
* }
|
|
810
861
|
* ```
|
|
811
862
|
*/
|
|
812
|
-
|
|
863
|
+
list(params) {
|
|
813
864
|
const fetchPage = async (p) => {
|
|
814
865
|
return this._client.getList(
|
|
815
866
|
"/items",
|
|
816
867
|
p
|
|
817
868
|
);
|
|
818
869
|
};
|
|
819
|
-
|
|
820
|
-
|
|
870
|
+
return new PagePromise(
|
|
871
|
+
fetchPage(params ?? {}).then(
|
|
872
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
873
|
+
)
|
|
874
|
+
);
|
|
821
875
|
}
|
|
822
876
|
/** Retrieve a single item by ID. */
|
|
823
877
|
async retrieve(id) {
|
|
@@ -850,51 +904,33 @@ var Accounts = class {
|
|
|
850
904
|
this._client = _client;
|
|
851
905
|
}
|
|
852
906
|
/**
|
|
853
|
-
* List chart of accounts
|
|
907
|
+
* List chart of accounts.
|
|
854
908
|
*
|
|
855
909
|
* ```ts
|
|
856
|
-
*
|
|
857
|
-
*
|
|
910
|
+
* const page = await cynco.accounts.list({ account_type: 'revenue' });
|
|
911
|
+
* for (const account of page.data) {
|
|
912
|
+
* console.log(`${account.accountCode} — ${account.accountName}`);
|
|
858
913
|
* }
|
|
859
914
|
* ```
|
|
860
915
|
*/
|
|
861
|
-
|
|
916
|
+
list(params) {
|
|
862
917
|
const fetchPage = async (p) => {
|
|
863
918
|
return this._client.getList(
|
|
864
919
|
"/accounts",
|
|
865
920
|
p
|
|
866
921
|
);
|
|
867
922
|
};
|
|
868
|
-
|
|
869
|
-
|
|
923
|
+
return new PagePromise(
|
|
924
|
+
fetchPage(params ?? {}).then(
|
|
925
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
926
|
+
)
|
|
927
|
+
);
|
|
870
928
|
}
|
|
871
929
|
/** Retrieve a single account by ID. */
|
|
872
930
|
async retrieve(id) {
|
|
873
|
-
const response = await this._client.get(`/accounts
|
|
874
|
-
return response.data;
|
|
875
|
-
}
|
|
876
|
-
/** Create a new account. */
|
|
877
|
-
async create(data, options) {
|
|
878
|
-
const response = await this._client.post(
|
|
879
|
-
"/accounts",
|
|
880
|
-
data,
|
|
881
|
-
options
|
|
882
|
-
);
|
|
931
|
+
const response = await this._client.get(`/accounts?id=${encodeURIComponent(id)}`);
|
|
883
932
|
return response.data;
|
|
884
933
|
}
|
|
885
|
-
/** Update an existing account. */
|
|
886
|
-
async update(id, data, options) {
|
|
887
|
-
const response = await this._client.patch(
|
|
888
|
-
`/accounts/${id}`,
|
|
889
|
-
data,
|
|
890
|
-
options
|
|
891
|
-
);
|
|
892
|
-
return response.data;
|
|
893
|
-
}
|
|
894
|
-
/** Delete an account. Only unused accounts can be deleted. */
|
|
895
|
-
async delete(id, options) {
|
|
896
|
-
await this._client.delete(`/accounts/${id}`, options);
|
|
897
|
-
}
|
|
898
934
|
};
|
|
899
935
|
|
|
900
936
|
// src/resources/journal-entries.ts
|
|
@@ -911,15 +947,18 @@ var JournalEntries = class {
|
|
|
911
947
|
* }
|
|
912
948
|
* ```
|
|
913
949
|
*/
|
|
914
|
-
|
|
950
|
+
list(params) {
|
|
915
951
|
const fetchPage = async (p) => {
|
|
916
952
|
return this._client.getList(
|
|
917
953
|
"/journal-entries",
|
|
918
954
|
p
|
|
919
955
|
);
|
|
920
956
|
};
|
|
921
|
-
|
|
922
|
-
|
|
957
|
+
return new PagePromise(
|
|
958
|
+
fetchPage(params ?? {}).then(
|
|
959
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
960
|
+
)
|
|
961
|
+
);
|
|
923
962
|
}
|
|
924
963
|
/** Retrieve a single journal entry by ID. */
|
|
925
964
|
async retrieve(id) {
|
|
@@ -984,15 +1023,18 @@ var BankAccounts = class {
|
|
|
984
1023
|
* }
|
|
985
1024
|
* ```
|
|
986
1025
|
*/
|
|
987
|
-
|
|
1026
|
+
list(params) {
|
|
988
1027
|
const fetchPage = async (p) => {
|
|
989
1028
|
return this._client.getList(
|
|
990
1029
|
"/bank-accounts",
|
|
991
1030
|
p
|
|
992
1031
|
);
|
|
993
1032
|
};
|
|
994
|
-
|
|
995
|
-
|
|
1033
|
+
return new PagePromise(
|
|
1034
|
+
fetchPage(params ?? {}).then(
|
|
1035
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1036
|
+
)
|
|
1037
|
+
);
|
|
996
1038
|
}
|
|
997
1039
|
/** Retrieve a single bank account by ID. */
|
|
998
1040
|
async retrieve(id) {
|
|
@@ -1032,15 +1074,18 @@ var BankAccounts = class {
|
|
|
1032
1074
|
* }
|
|
1033
1075
|
* ```
|
|
1034
1076
|
*/
|
|
1035
|
-
|
|
1077
|
+
listTransactions(bankAccountId, params) {
|
|
1036
1078
|
const fetchPage = async (p) => {
|
|
1037
1079
|
return this._client.getList(
|
|
1038
1080
|
`/bank-accounts/${bankAccountId}/transactions`,
|
|
1039
1081
|
p
|
|
1040
1082
|
);
|
|
1041
1083
|
};
|
|
1042
|
-
|
|
1043
|
-
|
|
1084
|
+
return new PagePromise(
|
|
1085
|
+
fetchPage(params ?? {}).then(
|
|
1086
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1087
|
+
)
|
|
1088
|
+
);
|
|
1044
1089
|
}
|
|
1045
1090
|
};
|
|
1046
1091
|
|
|
@@ -1089,15 +1134,18 @@ var Webhooks = class {
|
|
|
1089
1134
|
* }
|
|
1090
1135
|
* ```
|
|
1091
1136
|
*/
|
|
1092
|
-
|
|
1137
|
+
list(params) {
|
|
1093
1138
|
const fetchPage = async (p) => {
|
|
1094
1139
|
return this._client.getList(
|
|
1095
1140
|
"/webhooks",
|
|
1096
1141
|
p
|
|
1097
1142
|
);
|
|
1098
1143
|
};
|
|
1099
|
-
|
|
1100
|
-
|
|
1144
|
+
return new PagePromise(
|
|
1145
|
+
fetchPage(params ?? {}).then(
|
|
1146
|
+
(response) => new Page(response, fetchPage, params ?? {})
|
|
1147
|
+
)
|
|
1148
|
+
);
|
|
1101
1149
|
}
|
|
1102
1150
|
/** Retrieve a single webhook endpoint by ID. */
|
|
1103
1151
|
async retrieve(id) {
|
|
@@ -1188,6 +1236,6 @@ var Cynco = class {
|
|
|
1188
1236
|
};
|
|
1189
1237
|
var index_default = Cynco;
|
|
1190
1238
|
|
|
1191
|
-
export { Accounts, AuthenticationError, BankAccounts, Bills, ConflictError, ConnectionError, CursorPage, Customers, Cynco, CyncoClient, CyncoError, InternalError, Invoices, Items, JournalEntries, NotFoundError, Page, PermissionError, RateLimitError, Reports, TimeoutError, ValidationError, Vendors, Webhooks, index_default as default, webhookVerifier };
|
|
1239
|
+
export { Accounts, AuthenticationError, BankAccounts, Bills, ConflictError, ConnectionError, CursorPage, CursorPagePromise, Customers, Cynco, CyncoClient, CyncoError, InternalError, Invoices, Items, JournalEntries, NotFoundError, Page, PagePromise, PermissionError, RateLimitError, Reports, TimeoutError, ValidationError, Vendors, Webhooks, index_default as default, webhookVerifier };
|
|
1192
1240
|
//# sourceMappingURL=index.js.map
|
|
1193
1241
|
//# sourceMappingURL=index.js.map
|