@cynco/sdk 0.1.0 → 0.1.1

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 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
- if (rateLimitInfo && typeof json === "object" && json !== null) {
206
- const withMeta = json;
207
- withMeta["meta"] = {
208
- ...withMeta["meta"],
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;
@@ -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,19 +596,28 @@ var Invoices = class {
549
596
  /**
550
597
  * List invoices with pagination.
551
598
  *
552
- * Returns a `Page` that can be used as an async iterator for auto-pagination:
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
- async list(params) {
612
+ list(params) {
560
613
  const fetchPage = async (p) => {
561
614
  return this._client.getList("/invoices", p);
562
615
  };
563
- const response = await fetchPage(params ?? {});
564
- return new Page(response, fetchPage, params ?? {});
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) {
@@ -640,15 +696,18 @@ var Customers = class {
640
696
  * }
641
697
  * ```
642
698
  */
643
- async list(params) {
699
+ list(params) {
644
700
  const fetchPage = async (p) => {
645
701
  return this._client.getList(
646
702
  "/customers",
647
703
  p
648
704
  );
649
705
  };
650
- const response = await fetchPage(params ?? {});
651
- return new Page(response, fetchPage, params ?? {});
706
+ return new PagePromise(
707
+ fetchPage(params ?? {}).then(
708
+ (response) => new Page(response, fetchPage, params ?? {})
709
+ )
710
+ );
652
711
  }
653
712
  /** Retrieve a single customer by ID. */
654
713
  async retrieve(id) {
@@ -693,15 +752,18 @@ var Vendors = class {
693
752
  * }
694
753
  * ```
695
754
  */
696
- async list(params) {
755
+ list(params) {
697
756
  const fetchPage = async (p) => {
698
757
  return this._client.getList(
699
758
  "/vendors",
700
759
  p
701
760
  );
702
761
  };
703
- const response = await fetchPage(params ?? {});
704
- return new Page(response, fetchPage, params ?? {});
762
+ return new PagePromise(
763
+ fetchPage(params ?? {}).then(
764
+ (response) => new Page(response, fetchPage, params ?? {})
765
+ )
766
+ );
705
767
  }
706
768
  /** Retrieve a single vendor by ID. */
707
769
  async retrieve(id) {
@@ -746,15 +808,18 @@ var Bills = class {
746
808
  * }
747
809
  * ```
748
810
  */
749
- async list(params) {
811
+ list(params) {
750
812
  const fetchPage = async (p) => {
751
813
  return this._client.getList(
752
814
  "/bills",
753
815
  p
754
816
  );
755
817
  };
756
- const response = await fetchPage(params ?? {});
757
- return new Page(response, fetchPage, params ?? {});
818
+ return new PagePromise(
819
+ fetchPage(params ?? {}).then(
820
+ (response) => new Page(response, fetchPage, params ?? {})
821
+ )
822
+ );
758
823
  }
759
824
  /** Retrieve a single bill by ID. */
760
825
  async retrieve(id) {
@@ -813,15 +878,18 @@ var Items = class {
813
878
  * }
814
879
  * ```
815
880
  */
816
- async list(params) {
881
+ list(params) {
817
882
  const fetchPage = async (p) => {
818
883
  return this._client.getList(
819
884
  "/items",
820
885
  p
821
886
  );
822
887
  };
823
- const response = await fetchPage(params ?? {});
824
- return new Page(response, fetchPage, params ?? {});
888
+ return new PagePromise(
889
+ fetchPage(params ?? {}).then(
890
+ (response) => new Page(response, fetchPage, params ?? {})
891
+ )
892
+ );
825
893
  }
826
894
  /** Retrieve a single item by ID. */
827
895
  async retrieve(id) {
@@ -862,15 +930,18 @@ var Accounts = class {
862
930
  * }
863
931
  * ```
864
932
  */
865
- async list(params) {
933
+ list(params) {
866
934
  const fetchPage = async (p) => {
867
935
  return this._client.getList(
868
936
  "/accounts",
869
937
  p
870
938
  );
871
939
  };
872
- const response = await fetchPage(params ?? {});
873
- return new Page(response, fetchPage, params ?? {});
940
+ return new PagePromise(
941
+ fetchPage(params ?? {}).then(
942
+ (response) => new Page(response, fetchPage, params ?? {})
943
+ )
944
+ );
874
945
  }
875
946
  /** Retrieve a single account by ID. */
876
947
  async retrieve(id) {
@@ -915,15 +986,18 @@ var JournalEntries = class {
915
986
  * }
916
987
  * ```
917
988
  */
918
- async list(params) {
989
+ list(params) {
919
990
  const fetchPage = async (p) => {
920
991
  return this._client.getList(
921
992
  "/journal-entries",
922
993
  p
923
994
  );
924
995
  };
925
- const response = await fetchPage(params ?? {});
926
- return new Page(response, fetchPage, params ?? {});
996
+ return new PagePromise(
997
+ fetchPage(params ?? {}).then(
998
+ (response) => new Page(response, fetchPage, params ?? {})
999
+ )
1000
+ );
927
1001
  }
928
1002
  /** Retrieve a single journal entry by ID. */
929
1003
  async retrieve(id) {
@@ -988,15 +1062,18 @@ var BankAccounts = class {
988
1062
  * }
989
1063
  * ```
990
1064
  */
991
- async list(params) {
1065
+ list(params) {
992
1066
  const fetchPage = async (p) => {
993
1067
  return this._client.getList(
994
1068
  "/bank-accounts",
995
1069
  p
996
1070
  );
997
1071
  };
998
- const response = await fetchPage(params ?? {});
999
- return new Page(response, fetchPage, params ?? {});
1072
+ return new PagePromise(
1073
+ fetchPage(params ?? {}).then(
1074
+ (response) => new Page(response, fetchPage, params ?? {})
1075
+ )
1076
+ );
1000
1077
  }
1001
1078
  /** Retrieve a single bank account by ID. */
1002
1079
  async retrieve(id) {
@@ -1036,15 +1113,18 @@ var BankAccounts = class {
1036
1113
  * }
1037
1114
  * ```
1038
1115
  */
1039
- async listTransactions(bankAccountId, params) {
1116
+ listTransactions(bankAccountId, params) {
1040
1117
  const fetchPage = async (p) => {
1041
1118
  return this._client.getList(
1042
1119
  `/bank-accounts/${bankAccountId}/transactions`,
1043
1120
  p
1044
1121
  );
1045
1122
  };
1046
- const response = await fetchPage(params ?? {});
1047
- return new Page(response, fetchPage, params ?? {});
1123
+ return new PagePromise(
1124
+ fetchPage(params ?? {}).then(
1125
+ (response) => new Page(response, fetchPage, params ?? {})
1126
+ )
1127
+ );
1048
1128
  }
1049
1129
  };
1050
1130
 
@@ -1093,15 +1173,18 @@ var Webhooks = class {
1093
1173
  * }
1094
1174
  * ```
1095
1175
  */
1096
- async list(params) {
1176
+ list(params) {
1097
1177
  const fetchPage = async (p) => {
1098
1178
  return this._client.getList(
1099
1179
  "/webhooks",
1100
1180
  p
1101
1181
  );
1102
1182
  };
1103
- const response = await fetchPage(params ?? {});
1104
- return new Page(response, fetchPage, params ?? {});
1183
+ return new PagePromise(
1184
+ fetchPage(params ?? {}).then(
1185
+ (response) => new Page(response, fetchPage, params ?? {})
1186
+ )
1187
+ );
1105
1188
  }
1106
1189
  /** Retrieve a single webhook endpoint by ID. */
1107
1190
  async retrieve(id) {
@@ -1199,6 +1282,7 @@ exports.Bills = Bills;
1199
1282
  exports.ConflictError = ConflictError;
1200
1283
  exports.ConnectionError = ConnectionError;
1201
1284
  exports.CursorPage = CursorPage;
1285
+ exports.CursorPagePromise = CursorPagePromise;
1202
1286
  exports.Customers = Customers;
1203
1287
  exports.Cynco = Cynco;
1204
1288
  exports.CyncoClient = CyncoClient;
@@ -1209,6 +1293,7 @@ exports.Items = Items;
1209
1293
  exports.JournalEntries = JournalEntries;
1210
1294
  exports.NotFoundError = NotFoundError;
1211
1295
  exports.Page = Page;
1296
+ exports.PagePromise = PagePromise;
1212
1297
  exports.PermissionError = PermissionError;
1213
1298
  exports.RateLimitError = RateLimitError;
1214
1299
  exports.Reports = Reports;