postgrid-node 0.3.0 → 0.4.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.
Files changed (238) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/client.d.mts +8 -2
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +8 -2
  5. package/client.d.ts.map +1 -1
  6. package/client.js +8 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +9 -1
  9. package/client.mjs.map +1 -1
  10. package/core/pagination.d.mts +60 -0
  11. package/core/pagination.d.mts.map +1 -0
  12. package/core/pagination.d.ts +60 -0
  13. package/core/pagination.d.ts.map +1 -0
  14. package/core/pagination.js +107 -0
  15. package/core/pagination.js.map +1 -0
  16. package/core/pagination.mjs +101 -0
  17. package/core/pagination.mjs.map +1 -0
  18. package/index.d.mts +1 -0
  19. package/index.d.mts.map +1 -1
  20. package/index.d.ts +1 -0
  21. package/index.d.ts.map +1 -1
  22. package/index.js +3 -1
  23. package/index.js.map +1 -1
  24. package/index.mjs +1 -0
  25. package/index.mjs.map +1 -1
  26. package/internal/tslib.js +17 -17
  27. package/package.json +11 -1
  28. package/pagination.d.mts +2 -0
  29. package/pagination.d.mts.map +1 -0
  30. package/pagination.d.ts +2 -0
  31. package/pagination.d.ts.map +1 -0
  32. package/pagination.js +6 -0
  33. package/pagination.js.map +1 -0
  34. package/pagination.mjs +2 -0
  35. package/pagination.mjs.map +1 -0
  36. package/resources/index.d.mts +1 -1
  37. package/resources/index.d.mts.map +1 -1
  38. package/resources/index.d.ts +1 -1
  39. package/resources/index.d.ts.map +1 -1
  40. package/resources/index.js.map +1 -1
  41. package/resources/index.mjs +1 -1
  42. package/resources/index.mjs.map +1 -1
  43. package/resources/print-mail/bank-accounts.d.mts +9 -14
  44. package/resources/print-mail/bank-accounts.d.mts.map +1 -1
  45. package/resources/print-mail/bank-accounts.d.ts +9 -14
  46. package/resources/print-mail/bank-accounts.d.ts.map +1 -1
  47. package/resources/print-mail/bank-accounts.js +9 -3
  48. package/resources/print-mail/bank-accounts.js.map +1 -1
  49. package/resources/print-mail/bank-accounts.mjs +9 -3
  50. package/resources/print-mail/bank-accounts.mjs.map +1 -1
  51. package/resources/print-mail/boxes.d.mts +14 -566
  52. package/resources/print-mail/boxes.d.mts.map +1 -1
  53. package/resources/print-mail/boxes.d.ts +14 -566
  54. package/resources/print-mail/boxes.d.ts.map +1 -1
  55. package/resources/print-mail/boxes.js +6 -2
  56. package/resources/print-mail/boxes.js.map +1 -1
  57. package/resources/print-mail/boxes.mjs +6 -2
  58. package/resources/print-mail/boxes.mjs.map +1 -1
  59. package/resources/print-mail/campaigns.d.mts +9 -16
  60. package/resources/print-mail/campaigns.d.mts.map +1 -1
  61. package/resources/print-mail/campaigns.d.ts +9 -16
  62. package/resources/print-mail/campaigns.d.ts.map +1 -1
  63. package/resources/print-mail/campaigns.js +6 -2
  64. package/resources/print-mail/campaigns.js.map +1 -1
  65. package/resources/print-mail/campaigns.mjs +6 -2
  66. package/resources/print-mail/campaigns.mjs.map +1 -1
  67. package/resources/print-mail/cheques.d.mts +13 -426
  68. package/resources/print-mail/cheques.d.mts.map +1 -1
  69. package/resources/print-mail/cheques.d.ts +13 -426
  70. package/resources/print-mail/cheques.d.ts.map +1 -1
  71. package/resources/print-mail/cheques.js +6 -2
  72. package/resources/print-mail/cheques.js.map +1 -1
  73. package/resources/print-mail/cheques.mjs +6 -2
  74. package/resources/print-mail/cheques.mjs.map +1 -1
  75. package/resources/print-mail/contacts.d.mts +11 -152
  76. package/resources/print-mail/contacts.d.mts.map +1 -1
  77. package/resources/print-mail/contacts.d.ts +11 -152
  78. package/resources/print-mail/contacts.d.ts.map +1 -1
  79. package/resources/print-mail/contacts.js +6 -2
  80. package/resources/print-mail/contacts.js.map +1 -1
  81. package/resources/print-mail/contacts.mjs +6 -2
  82. package/resources/print-mail/contacts.mjs.map +1 -1
  83. package/resources/print-mail/index.d.mts +14 -14
  84. package/resources/print-mail/index.d.mts.map +1 -1
  85. package/resources/print-mail/index.d.ts +14 -14
  86. package/resources/print-mail/index.d.ts.map +1 -1
  87. package/resources/print-mail/index.js.map +1 -1
  88. package/resources/print-mail/index.mjs.map +1 -1
  89. package/resources/print-mail/letters.d.mts +14 -565
  90. package/resources/print-mail/letters.d.mts.map +1 -1
  91. package/resources/print-mail/letters.d.ts +14 -565
  92. package/resources/print-mail/letters.d.ts.map +1 -1
  93. package/resources/print-mail/letters.js +6 -2
  94. package/resources/print-mail/letters.js.map +1 -1
  95. package/resources/print-mail/letters.mjs +6 -2
  96. package/resources/print-mail/letters.mjs.map +1 -1
  97. package/resources/print-mail/mailing-list-imports.d.mts +9 -17
  98. package/resources/print-mail/mailing-list-imports.d.mts.map +1 -1
  99. package/resources/print-mail/mailing-list-imports.d.ts +9 -17
  100. package/resources/print-mail/mailing-list-imports.d.ts.map +1 -1
  101. package/resources/print-mail/mailing-list-imports.js +6 -3
  102. package/resources/print-mail/mailing-list-imports.js.map +1 -1
  103. package/resources/print-mail/mailing-list-imports.mjs +6 -3
  104. package/resources/print-mail/mailing-list-imports.mjs.map +1 -1
  105. package/resources/print-mail/mailing-lists.d.mts +9 -17
  106. package/resources/print-mail/mailing-lists.d.mts.map +1 -1
  107. package/resources/print-mail/mailing-lists.d.ts +9 -17
  108. package/resources/print-mail/mailing-lists.d.ts.map +1 -1
  109. package/resources/print-mail/mailing-lists.js +9 -3
  110. package/resources/print-mail/mailing-lists.js.map +1 -1
  111. package/resources/print-mail/mailing-lists.mjs +9 -3
  112. package/resources/print-mail/mailing-lists.mjs.map +1 -1
  113. package/resources/print-mail/order-profiles/cheques.d.mts +80 -90
  114. package/resources/print-mail/order-profiles/cheques.d.mts.map +1 -1
  115. package/resources/print-mail/order-profiles/cheques.d.ts +80 -90
  116. package/resources/print-mail/order-profiles/cheques.d.ts.map +1 -1
  117. package/resources/print-mail/order-profiles/cheques.js +9 -3
  118. package/resources/print-mail/order-profiles/cheques.js.map +1 -1
  119. package/resources/print-mail/order-profiles/cheques.mjs +9 -3
  120. package/resources/print-mail/order-profiles/cheques.mjs.map +1 -1
  121. package/resources/print-mail/order-profiles/index.d.mts +4 -4
  122. package/resources/print-mail/order-profiles/index.d.mts.map +1 -1
  123. package/resources/print-mail/order-profiles/index.d.ts +4 -4
  124. package/resources/print-mail/order-profiles/index.d.ts.map +1 -1
  125. package/resources/print-mail/order-profiles/index.js.map +1 -1
  126. package/resources/print-mail/order-profiles/index.mjs.map +1 -1
  127. package/resources/print-mail/order-profiles/letters.d.mts +9 -17
  128. package/resources/print-mail/order-profiles/letters.d.mts.map +1 -1
  129. package/resources/print-mail/order-profiles/letters.d.ts +9 -17
  130. package/resources/print-mail/order-profiles/letters.d.ts.map +1 -1
  131. package/resources/print-mail/order-profiles/letters.js +9 -3
  132. package/resources/print-mail/order-profiles/letters.js.map +1 -1
  133. package/resources/print-mail/order-profiles/letters.mjs +9 -3
  134. package/resources/print-mail/order-profiles/letters.mjs.map +1 -1
  135. package/resources/print-mail/order-profiles/order-profiles.d.mts +8 -8
  136. package/resources/print-mail/order-profiles/order-profiles.d.mts.map +1 -1
  137. package/resources/print-mail/order-profiles/order-profiles.d.ts +8 -8
  138. package/resources/print-mail/order-profiles/order-profiles.d.ts.map +1 -1
  139. package/resources/print-mail/order-profiles/order-profiles.js.map +1 -1
  140. package/resources/print-mail/order-profiles/order-profiles.mjs.map +1 -1
  141. package/resources/print-mail/order-profiles/postcards.d.mts +9 -17
  142. package/resources/print-mail/order-profiles/postcards.d.mts.map +1 -1
  143. package/resources/print-mail/order-profiles/postcards.d.ts +9 -17
  144. package/resources/print-mail/order-profiles/postcards.d.ts.map +1 -1
  145. package/resources/print-mail/order-profiles/postcards.js +9 -3
  146. package/resources/print-mail/order-profiles/postcards.js.map +1 -1
  147. package/resources/print-mail/order-profiles/postcards.mjs +9 -3
  148. package/resources/print-mail/order-profiles/postcards.mjs.map +1 -1
  149. package/resources/print-mail/order-profiles/self-mailers.d.mts +9 -17
  150. package/resources/print-mail/order-profiles/self-mailers.d.mts.map +1 -1
  151. package/resources/print-mail/order-profiles/self-mailers.d.ts +9 -17
  152. package/resources/print-mail/order-profiles/self-mailers.d.ts.map +1 -1
  153. package/resources/print-mail/order-profiles/self-mailers.js +6 -3
  154. package/resources/print-mail/order-profiles/self-mailers.js.map +1 -1
  155. package/resources/print-mail/order-profiles/self-mailers.mjs +6 -3
  156. package/resources/print-mail/order-profiles/self-mailers.mjs.map +1 -1
  157. package/resources/print-mail/postcards.d.mts +16 -841
  158. package/resources/print-mail/postcards.d.mts.map +1 -1
  159. package/resources/print-mail/postcards.d.ts +16 -841
  160. package/resources/print-mail/postcards.d.ts.map +1 -1
  161. package/resources/print-mail/postcards.js +6 -2
  162. package/resources/print-mail/postcards.js.map +1 -1
  163. package/resources/print-mail/postcards.mjs +6 -2
  164. package/resources/print-mail/postcards.mjs.map +1 -1
  165. package/resources/print-mail/print-mail.d.mts +163 -26
  166. package/resources/print-mail/print-mail.d.mts.map +1 -1
  167. package/resources/print-mail/print-mail.d.ts +163 -26
  168. package/resources/print-mail/print-mail.d.ts.map +1 -1
  169. package/resources/print-mail/print-mail.js.map +1 -1
  170. package/resources/print-mail/print-mail.mjs.map +1 -1
  171. package/resources/print-mail/reports/index.d.mts +1 -1
  172. package/resources/print-mail/reports/index.d.mts.map +1 -1
  173. package/resources/print-mail/reports/index.d.ts +1 -1
  174. package/resources/print-mail/reports/index.d.ts.map +1 -1
  175. package/resources/print-mail/reports/reports.d.mts +9 -16
  176. package/resources/print-mail/reports/reports.d.mts.map +1 -1
  177. package/resources/print-mail/reports/reports.d.ts +9 -16
  178. package/resources/print-mail/reports/reports.d.ts.map +1 -1
  179. package/resources/print-mail/reports/reports.js +6 -2
  180. package/resources/print-mail/reports/reports.js.map +1 -1
  181. package/resources/print-mail/reports/reports.mjs +6 -2
  182. package/resources/print-mail/reports/reports.mjs.map +1 -1
  183. package/resources/print-mail/self-mailers.d.mts +16 -842
  184. package/resources/print-mail/self-mailers.d.mts.map +1 -1
  185. package/resources/print-mail/self-mailers.d.ts +16 -842
  186. package/resources/print-mail/self-mailers.d.ts.map +1 -1
  187. package/resources/print-mail/self-mailers.js +9 -3
  188. package/resources/print-mail/self-mailers.js.map +1 -1
  189. package/resources/print-mail/self-mailers.mjs +9 -3
  190. package/resources/print-mail/self-mailers.mjs.map +1 -1
  191. package/resources/print-mail/sub-organizations.d.mts +9 -14
  192. package/resources/print-mail/sub-organizations.d.mts.map +1 -1
  193. package/resources/print-mail/sub-organizations.d.ts +9 -14
  194. package/resources/print-mail/sub-organizations.d.ts.map +1 -1
  195. package/resources/print-mail/sub-organizations.js +9 -3
  196. package/resources/print-mail/sub-organizations.js.map +1 -1
  197. package/resources/print-mail/sub-organizations.mjs +9 -3
  198. package/resources/print-mail/sub-organizations.mjs.map +1 -1
  199. package/resources/print-mail/templates.d.mts +9 -13
  200. package/resources/print-mail/templates.d.mts.map +1 -1
  201. package/resources/print-mail/templates.d.ts +9 -13
  202. package/resources/print-mail/templates.d.ts.map +1 -1
  203. package/resources/print-mail/templates.js +6 -2
  204. package/resources/print-mail/templates.js.map +1 -1
  205. package/resources/print-mail/templates.mjs +6 -2
  206. package/resources/print-mail/templates.mjs.map +1 -1
  207. package/src/client.ts +34 -2
  208. package/src/core/pagination.ts +171 -0
  209. package/src/index.ts +1 -0
  210. package/src/pagination.ts +2 -0
  211. package/src/resources/index.ts +5 -1
  212. package/src/resources/print-mail/bank-accounts.ts +14 -22
  213. package/src/resources/print-mail/boxes.ts +19 -686
  214. package/src/resources/print-mail/campaigns.ts +11 -24
  215. package/src/resources/print-mail/cheques.ts +15 -527
  216. package/src/resources/print-mail/contacts.ts +14 -189
  217. package/src/resources/print-mail/index.ts +14 -14
  218. package/src/resources/print-mail/letters.ts +16 -697
  219. package/src/resources/print-mail/mailing-list-imports.ts +15 -25
  220. package/src/resources/print-mail/mailing-lists.ts +14 -25
  221. package/src/resources/print-mail/order-profiles/cheques.ts +91 -103
  222. package/src/resources/print-mail/order-profiles/index.ts +4 -3
  223. package/src/resources/print-mail/order-profiles/letters.ts +14 -25
  224. package/src/resources/print-mail/order-profiles/order-profiles.ts +8 -6
  225. package/src/resources/print-mail/order-profiles/postcards.ts +14 -25
  226. package/src/resources/print-mail/order-profiles/self-mailers.ts +15 -25
  227. package/src/resources/print-mail/postcards.ts +18 -1035
  228. package/src/resources/print-mail/print-mail.ts +195 -26
  229. package/src/resources/print-mail/reports/index.ts +1 -1
  230. package/src/resources/print-mail/reports/reports.ts +11 -24
  231. package/src/resources/print-mail/self-mailers.ts +21 -1036
  232. package/src/resources/print-mail/sub-organizations.ts +14 -22
  233. package/src/resources/print-mail/templates.ts +11 -21
  234. package/src/version.ts +1 -1
  235. package/version.d.mts +1 -1
  236. package/version.d.ts +1 -1
  237. package/version.js +1 -1
  238. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -14,6 +14,8 @@ import * as Opts from './internal/request-options';
14
14
  import * as qs from './internal/qs';
15
15
  import { VERSION } from './version';
16
16
  import * as Errors from './core/error';
17
+ import * as Pagination from './core/pagination';
18
+ import { AbstractPage, type SkipLimitParams, SkipLimitResponse } from './core/pagination';
17
19
  import * as Uploads from './core/uploads';
18
20
  import * as API from './resources/index';
19
21
  import { APIPromise } from './core/api-promise';
@@ -29,7 +31,11 @@ import {
29
31
  IntlAddressVerificationVerifyParams,
30
32
  IntlAddressVerificationVerifyResponse,
31
33
  } from './resources/intl-address-verification';
32
- import { PrintMail } from './resources/print-mail/print-mail';
34
+ import {
35
+ ContactCreateWithCompanyName,
36
+ ContactCreateWithFirstName,
37
+ PrintMail,
38
+ } from './resources/print-mail/print-mail';
33
39
  import { type Fetch } from './internal/builtin-types';
34
40
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
35
41
  import { FinalRequestOptions, RequestOptions } from './internal/request-options';
@@ -531,6 +537,25 @@ export class PostGrid {
531
537
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
532
538
  }
533
539
 
540
+ getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
541
+ path: string,
542
+ Page: new (...args: any[]) => PageClass,
543
+ opts?: RequestOptions,
544
+ ): Pagination.PagePromise<PageClass, Item> {
545
+ return this.requestAPIList(Page, { method: 'get', path, ...opts });
546
+ }
547
+
548
+ requestAPIList<
549
+ Item = unknown,
550
+ PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
551
+ >(
552
+ Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
553
+ options: FinalRequestOptions,
554
+ ): Pagination.PagePromise<PageClass, Item> {
555
+ const request = this.makeRequest(options, null, undefined);
556
+ return new Pagination.PagePromise<PageClass, Item>(this as any as PostGrid, request, Page);
557
+ }
558
+
534
559
  async fetchWithTimeout(
535
560
  url: RequestInfo,
536
561
  init: RequestInit | undefined,
@@ -775,6 +800,9 @@ PostGrid.PrintMail = PrintMail;
775
800
  export declare namespace PostGrid {
776
801
  export type RequestOptions = Opts.RequestOptions;
777
802
 
803
+ export import SkipLimit = Pagination.SkipLimit;
804
+ export { type SkipLimitParams as SkipLimitParams, type SkipLimitResponse as SkipLimitResponse };
805
+
778
806
  export {
779
807
  AddressVerification as AddressVerification,
780
808
  type AddressVerificationAPIErrors as Errors,
@@ -789,5 +817,9 @@ export declare namespace PostGrid {
789
817
  type IntlAddressVerificationVerifyParams as IntlAddressVerificationVerifyParams,
790
818
  };
791
819
 
792
- export { PrintMail as PrintMail };
820
+ export {
821
+ PrintMail as PrintMail,
822
+ type ContactCreateWithCompanyName as ContactCreateWithCompanyName,
823
+ type ContactCreateWithFirstName as ContactCreateWithFirstName,
824
+ };
793
825
  }
@@ -0,0 +1,171 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { PostGridError } from './error';
4
+ import { FinalRequestOptions } from '../internal/request-options';
5
+ import { defaultParseResponse } from '../internal/parse';
6
+ import { type PostGrid } from '../client';
7
+ import { APIPromise } from './api-promise';
8
+ import { type APIResponseProps } from '../internal/parse';
9
+ import { maybeObj } from '../internal/utils/values';
10
+
11
+ export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
12
+
13
+ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
14
+ #client: PostGrid;
15
+ protected options: FinalRequestOptions;
16
+
17
+ protected response: Response;
18
+ protected body: unknown;
19
+
20
+ constructor(client: PostGrid, response: Response, body: unknown, options: FinalRequestOptions) {
21
+ this.#client = client;
22
+ this.options = options;
23
+ this.response = response;
24
+ this.body = body;
25
+ }
26
+
27
+ abstract nextPageRequestOptions(): PageRequestOptions | null;
28
+
29
+ abstract getPaginatedItems(): Item[];
30
+
31
+ hasNextPage(): boolean {
32
+ const items = this.getPaginatedItems();
33
+ if (!items.length) return false;
34
+ return this.nextPageRequestOptions() != null;
35
+ }
36
+
37
+ async getNextPage(): Promise<this> {
38
+ const nextOptions = this.nextPageRequestOptions();
39
+ if (!nextOptions) {
40
+ throw new PostGridError(
41
+ 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
42
+ );
43
+ }
44
+
45
+ return await this.#client.requestAPIList(this.constructor as any, nextOptions);
46
+ }
47
+
48
+ async *iterPages(): AsyncGenerator<this> {
49
+ let page: this = this;
50
+ yield page;
51
+ while (page.hasNextPage()) {
52
+ page = await page.getNextPage();
53
+ yield page;
54
+ }
55
+ }
56
+
57
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
58
+ for await (const page of this.iterPages()) {
59
+ for (const item of page.getPaginatedItems()) {
60
+ yield item;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This subclass of Promise will resolve to an instantiated Page once the request completes.
68
+ *
69
+ * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
70
+ *
71
+ * for await (const item of client.items.list()) {
72
+ * console.log(item)
73
+ * }
74
+ */
75
+ export class PagePromise<
76
+ PageClass extends AbstractPage<Item>,
77
+ Item = ReturnType<PageClass['getPaginatedItems']>[number],
78
+ >
79
+ extends APIPromise<PageClass>
80
+ implements AsyncIterable<Item>
81
+ {
82
+ constructor(
83
+ client: PostGrid,
84
+ request: Promise<APIResponseProps>,
85
+ Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
86
+ ) {
87
+ super(
88
+ client,
89
+ request,
90
+ async (client, props) =>
91
+ new Page(client, props.response, await defaultParseResponse(client, props), props.options),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Allow auto-paginating iteration on an unawaited list call, eg:
97
+ *
98
+ * for await (const item of client.items.list()) {
99
+ * console.log(item)
100
+ * }
101
+ */
102
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
103
+ const page = await this;
104
+ for await (const item of page) {
105
+ yield item;
106
+ }
107
+ }
108
+ }
109
+
110
+ export interface SkipLimitResponse<Item> {
111
+ data: Array<Item>;
112
+
113
+ totalCount: number;
114
+ }
115
+
116
+ export interface SkipLimitParams {
117
+ /**
118
+ * The number of elements to skip.
119
+ */
120
+ skip?: number;
121
+
122
+ /**
123
+ * The maximum number of elements to fetch.
124
+ */
125
+ limit?: number;
126
+ }
127
+
128
+ export class SkipLimit<Item> extends AbstractPage<Item> implements SkipLimitResponse<Item> {
129
+ data: Array<Item>;
130
+
131
+ totalCount: number;
132
+
133
+ constructor(
134
+ client: PostGrid,
135
+ response: Response,
136
+ body: SkipLimitResponse<Item>,
137
+ options: FinalRequestOptions,
138
+ ) {
139
+ super(client, response, body, options);
140
+
141
+ this.data = body.data || [];
142
+ this.totalCount = body.totalCount || 0;
143
+ }
144
+
145
+ getPaginatedItems(): Item[] {
146
+ return this.data ?? [];
147
+ }
148
+
149
+ nextPageRequestOptions(): PageRequestOptions | null {
150
+ const offset = (this.options.query as SkipLimitParams).skip ?? 0;
151
+ const length = this.getPaginatedItems().length;
152
+ const currentCount = offset + length;
153
+
154
+ const totalCount = this.totalCount;
155
+ if (!totalCount) {
156
+ return null;
157
+ }
158
+
159
+ if (currentCount < totalCount) {
160
+ return {
161
+ ...this.options,
162
+ query: {
163
+ ...maybeObj(this.options.query),
164
+ skip: currentCount,
165
+ },
166
+ };
167
+ }
168
+
169
+ return null;
170
+ }
171
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { PostGrid as default } from './client';
5
5
  export { type Uploadable, toFile } from './core/uploads';
6
6
  export { APIPromise } from './core/api-promise';
7
7
  export { PostGrid, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
8
9
  export {
9
10
  PostGridError,
10
11
  APIError,
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';
@@ -12,4 +12,8 @@ export {
12
12
  type IntlAddressVerificationVerifyResponse,
13
13
  type IntlAddressVerificationVerifyParams,
14
14
  } from './intl-address-verification';
15
- export { PrintMail } from './print-mail/print-mail';
15
+ export {
16
+ PrintMail,
17
+ type ContactCreateWithCompanyName,
18
+ type ContactCreateWithFirstName,
19
+ } from './print-mail/print-mail';
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { APIResource } from '../../core/resource';
4
4
  import { APIPromise } from '../../core/api-promise';
5
+ import { PagePromise, SkipLimit, type SkipLimitParams } from '../../core/pagination';
5
6
  import { RequestOptions } from '../../internal/request-options';
6
7
  import { path } from '../../internal/utils/path';
7
8
 
@@ -51,15 +52,20 @@ export class BankAccounts extends APIResource {
51
52
  *
52
53
  * @example
53
54
  * ```ts
54
- * const bankAccounts =
55
- * await client.printMail.bankAccounts.list();
55
+ * // Automatically fetches more pages as needed.
56
+ * for await (const bankAccount of client.printMail.bankAccounts.list()) {
57
+ * // ...
58
+ * }
56
59
  * ```
57
60
  */
58
61
  list(
59
62
  query: BankAccountListParams | null | undefined = {},
60
63
  options?: RequestOptions,
61
- ): APIPromise<BankAccountListResponse> {
62
- return this._client.get('/print-mail/v1/bank_accounts', { query, ...options });
64
+ ): PagePromise<BankAccountsSkipLimit, BankAccount> {
65
+ return this._client.getAPIList('/print-mail/v1/bank_accounts', SkipLimit<BankAccount>, {
66
+ query,
67
+ ...options,
68
+ });
63
69
  }
64
70
 
65
71
  /**
@@ -76,6 +82,8 @@ export class BankAccounts extends APIResource {
76
82
  }
77
83
  }
78
84
 
85
+ export type BankAccountsSkipLimit = SkipLimit<BankAccount>;
86
+
79
87
  export interface BankAccount {
80
88
  /**
81
89
  * A unique ID prefixed with bank*account*
@@ -178,18 +186,6 @@ export interface BankAccount {
178
186
  */
179
187
  export type BankAccountCountryCode = 'CA' | 'US';
180
188
 
181
- export interface BankAccountListResponse {
182
- data: Array<BankAccount>;
183
-
184
- limit: number;
185
-
186
- object: 'list';
187
-
188
- skip: number;
189
-
190
- totalCount: number;
191
- }
192
-
193
189
  export interface BankAccountDeleteResponse {
194
190
  /**
195
191
  * A unique ID prefixed with bank*account*
@@ -405,9 +401,7 @@ export declare namespace BankAccountCreateParams {
405
401
  }
406
402
  }
407
403
 
408
- export interface BankAccountListParams {
409
- limit?: number;
410
-
404
+ export interface BankAccountListParams extends SkipLimitParams {
411
405
  /**
412
406
  * You can supply any string to help narrow down the list of resources. For
413
407
  * example, if you pass `"New York"` (quoted), it will return resources that have
@@ -416,16 +410,14 @@ export interface BankAccountListParams {
416
410
  * more details.
417
411
  */
418
412
  search?: string;
419
-
420
- skip?: number;
421
413
  }
422
414
 
423
415
  export declare namespace BankAccounts {
424
416
  export {
425
417
  type BankAccount as BankAccount,
426
418
  type BankAccountCountryCode as BankAccountCountryCode,
427
- type BankAccountListResponse as BankAccountListResponse,
428
419
  type BankAccountDeleteResponse as BankAccountDeleteResponse,
420
+ type BankAccountsSkipLimit as BankAccountsSkipLimit,
429
421
  type BankAccountCreateParams as BankAccountCreateParams,
430
422
  type BankAccountListParams as BankAccountListParams,
431
423
  };