postgrid-node 0.1.0-alpha.2 → 0.1.0-alpha.4

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 (265) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +26 -40
  3. package/_shims/index.d.ts +2 -0
  4. package/_shims/index.js +5 -1
  5. package/_shims/index.mjs +5 -1
  6. package/core.d.ts +19 -5
  7. package/core.d.ts.map +1 -1
  8. package/core.js +25 -15
  9. package/core.js.map +1 -1
  10. package/core.mjs +26 -16
  11. package/core.mjs.map +1 -1
  12. package/index.d.mts +21 -8
  13. package/index.d.ts +21 -8
  14. package/index.d.ts.map +1 -1
  15. package/index.js +28 -5
  16. package/index.js.map +1 -1
  17. package/index.mjs +28 -5
  18. package/index.mjs.map +1 -1
  19. package/internal/qs/formats.d.ts +6 -0
  20. package/internal/qs/formats.d.ts.map +1 -0
  21. package/internal/qs/formats.js +11 -0
  22. package/internal/qs/formats.js.map +1 -0
  23. package/internal/qs/formats.mjs +8 -0
  24. package/internal/qs/formats.mjs.map +1 -0
  25. package/internal/qs/index.d.ts +10 -0
  26. package/internal/qs/index.d.ts.map +1 -0
  27. package/internal/qs/index.js +14 -0
  28. package/internal/qs/index.js.map +1 -0
  29. package/internal/qs/index.mjs +10 -0
  30. package/internal/qs/index.mjs.map +1 -0
  31. package/internal/qs/stringify.d.ts +3 -0
  32. package/internal/qs/stringify.d.ts.map +1 -0
  33. package/internal/qs/stringify.js +280 -0
  34. package/internal/qs/stringify.js.map +1 -0
  35. package/internal/qs/stringify.mjs +276 -0
  36. package/internal/qs/stringify.mjs.map +1 -0
  37. package/internal/qs/types.d.ts +57 -0
  38. package/internal/qs/types.d.ts.map +1 -0
  39. package/internal/qs/types.js +3 -0
  40. package/internal/qs/types.js.map +1 -0
  41. package/internal/qs/types.mjs +2 -0
  42. package/internal/qs/types.mjs.map +1 -0
  43. package/internal/qs/utils.d.ts +14 -0
  44. package/internal/qs/utils.d.ts.map +1 -0
  45. package/internal/qs/utils.js +229 -0
  46. package/internal/qs/utils.js.map +1 -0
  47. package/internal/qs/utils.mjs +217 -0
  48. package/internal/qs/utils.mjs.map +1 -0
  49. package/package.json +8 -29
  50. package/pagination.d.ts +2 -0
  51. package/pagination.d.ts.map +1 -1
  52. package/pagination.js +2 -1
  53. package/pagination.js.map +1 -1
  54. package/pagination.mjs +2 -1
  55. package/pagination.mjs.map +1 -1
  56. package/resource.d.ts +1 -1
  57. package/resource.d.ts.map +1 -1
  58. package/resource.js.map +1 -1
  59. package/resource.mjs.map +1 -1
  60. package/resources/bank-accounts.d.ts +61 -4
  61. package/resources/bank-accounts.d.ts.map +1 -1
  62. package/resources/bank-accounts.js +25 -0
  63. package/resources/bank-accounts.js.map +1 -1
  64. package/resources/bank-accounts.mjs +25 -0
  65. package/resources/bank-accounts.mjs.map +1 -1
  66. package/resources/boxes.d.ts +80 -15
  67. package/resources/boxes.d.ts.map +1 -1
  68. package/resources/boxes.js +27 -0
  69. package/resources/boxes.js.map +1 -1
  70. package/resources/boxes.mjs +27 -0
  71. package/resources/boxes.mjs.map +1 -1
  72. package/resources/campaigns.d.ts +22 -8
  73. package/resources/campaigns.d.ts.map +1 -1
  74. package/resources/cheques/cheques.d.ts +43 -4
  75. package/resources/cheques/cheques.d.ts.map +1 -1
  76. package/resources/cheques/cheques.js +23 -0
  77. package/resources/cheques/cheques.js.map +1 -1
  78. package/resources/cheques/cheques.mjs +23 -0
  79. package/resources/cheques/cheques.mjs.map +1 -1
  80. package/resources/cheques/url.d.ts +5 -0
  81. package/resources/cheques/url.d.ts.map +1 -1
  82. package/resources/cheques/url.js +5 -0
  83. package/resources/cheques/url.js.map +1 -1
  84. package/resources/cheques/url.mjs +5 -0
  85. package/resources/cheques/url.mjs.map +1 -1
  86. package/resources/cheques/with-deposit-ready-pdf.d.ts +6 -0
  87. package/resources/cheques/with-deposit-ready-pdf.d.ts.map +1 -1
  88. package/resources/cheques/with-deposit-ready-pdf.js +6 -0
  89. package/resources/cheques/with-deposit-ready-pdf.js.map +1 -1
  90. package/resources/cheques/with-deposit-ready-pdf.mjs +6 -0
  91. package/resources/cheques/with-deposit-ready-pdf.mjs.map +1 -1
  92. package/resources/cheques.d.ts +2 -0
  93. package/resources/cheques.d.ts.map +1 -0
  94. package/resources/cheques.js +19 -0
  95. package/resources/cheques.js.map +1 -0
  96. package/resources/cheques.mjs +3 -0
  97. package/resources/cheques.mjs.map +1 -0
  98. package/resources/contacts.d.ts +37 -3
  99. package/resources/contacts.d.ts.map +1 -1
  100. package/resources/contacts.js +20 -0
  101. package/resources/contacts.js.map +1 -1
  102. package/resources/contacts.mjs +20 -0
  103. package/resources/contacts.mjs.map +1 -1
  104. package/resources/index.d.ts +5 -1
  105. package/resources/index.d.ts.map +1 -1
  106. package/resources/index.js +12 -1
  107. package/resources/index.js.map +1 -1
  108. package/resources/index.mjs +4 -0
  109. package/resources/index.mjs.map +1 -1
  110. package/resources/letters.d.ts +50 -6
  111. package/resources/letters.d.ts.map +1 -1
  112. package/resources/letters.js +24 -0
  113. package/resources/letters.js.map +1 -1
  114. package/resources/letters.mjs +24 -0
  115. package/resources/letters.mjs.map +1 -1
  116. package/resources/mailing-list-imports.d.ts +919 -0
  117. package/resources/mailing-list-imports.d.ts.map +1 -0
  118. package/resources/mailing-list-imports.js +95 -0
  119. package/resources/mailing-list-imports.js.map +1 -0
  120. package/resources/mailing-list-imports.mjs +90 -0
  121. package/resources/mailing-list-imports.mjs.map +1 -0
  122. package/resources/mailing-lists.d.ts +398 -0
  123. package/resources/mailing-lists.d.ts.map +1 -0
  124. package/resources/mailing-lists.js +101 -0
  125. package/resources/mailing-lists.js.map +1 -0
  126. package/resources/mailing-lists.mjs +96 -0
  127. package/resources/mailing-lists.mjs.map +1 -0
  128. package/resources/order-profiles/cheques.d.ts +588 -0
  129. package/resources/order-profiles/cheques.d.ts.map +1 -0
  130. package/resources/order-profiles/cheques.js +74 -0
  131. package/resources/order-profiles/cheques.js.map +1 -0
  132. package/resources/order-profiles/cheques.mjs +69 -0
  133. package/resources/order-profiles/cheques.mjs.map +1 -0
  134. package/resources/order-profiles/index.d.ts +6 -0
  135. package/resources/order-profiles/index.d.ts.map +1 -0
  136. package/resources/order-profiles/index.js +19 -0
  137. package/resources/order-profiles/index.js.map +1 -0
  138. package/resources/order-profiles/index.mjs +7 -0
  139. package/resources/order-profiles/index.mjs.map +1 -0
  140. package/resources/order-profiles/letters.d.ts +647 -0
  141. package/resources/order-profiles/letters.d.ts.map +1 -0
  142. package/resources/order-profiles/letters.js +80 -0
  143. package/resources/order-profiles/letters.js.map +1 -0
  144. package/resources/order-profiles/letters.mjs +75 -0
  145. package/resources/order-profiles/letters.mjs.map +1 -0
  146. package/resources/order-profiles/order-profiles.d.ts +22 -0
  147. package/resources/order-profiles/order-profiles.d.ts.map +1 -0
  148. package/resources/order-profiles/order-profiles.js +55 -0
  149. package/resources/order-profiles/order-profiles.js.map +1 -0
  150. package/resources/order-profiles/order-profiles.mjs +28 -0
  151. package/resources/order-profiles/order-profiles.mjs.map +1 -0
  152. package/resources/order-profiles/postcards.d.ts +423 -0
  153. package/resources/order-profiles/postcards.d.ts.map +1 -0
  154. package/resources/order-profiles/postcards.js +73 -0
  155. package/resources/order-profiles/postcards.js.map +1 -0
  156. package/resources/order-profiles/postcards.mjs +68 -0
  157. package/resources/order-profiles/postcards.mjs.map +1 -0
  158. package/resources/order-profiles/self-mailers.d.ts +435 -0
  159. package/resources/order-profiles/self-mailers.d.ts.map +1 -0
  160. package/resources/order-profiles/self-mailers.js +75 -0
  161. package/resources/order-profiles/self-mailers.js.map +1 -0
  162. package/resources/order-profiles/self-mailers.mjs +70 -0
  163. package/resources/order-profiles/self-mailers.mjs.map +1 -0
  164. package/resources/order-profiles.d.ts +2 -0
  165. package/resources/order-profiles.d.ts.map +1 -0
  166. package/resources/order-profiles.js +19 -0
  167. package/resources/order-profiles.js.map +1 -0
  168. package/resources/order-profiles.mjs +3 -0
  169. package/resources/order-profiles.mjs.map +1 -0
  170. package/resources/postcards.d.ts +58 -8
  171. package/resources/postcards.d.ts.map +1 -1
  172. package/resources/postcards.js +26 -0
  173. package/resources/postcards.js.map +1 -1
  174. package/resources/postcards.mjs +26 -0
  175. package/resources/postcards.mjs.map +1 -1
  176. package/resources/reports/exports.d.ts +36 -3
  177. package/resources/reports/exports.d.ts.map +1 -1
  178. package/resources/reports/exports.js +27 -0
  179. package/resources/reports/exports.js.map +1 -1
  180. package/resources/reports/exports.mjs +27 -0
  181. package/resources/reports/exports.mjs.map +1 -1
  182. package/resources/reports/reports.d.ts +76 -8
  183. package/resources/reports/reports.d.ts.map +1 -1
  184. package/resources/reports/reports.js +44 -0
  185. package/resources/reports/reports.js.map +1 -1
  186. package/resources/reports/reports.mjs +44 -0
  187. package/resources/reports/reports.mjs.map +1 -1
  188. package/resources/reports.d.ts +2 -0
  189. package/resources/reports.d.ts.map +1 -0
  190. package/resources/reports.js +19 -0
  191. package/resources/reports.js.map +1 -0
  192. package/resources/reports.mjs +3 -0
  193. package/resources/reports.mjs.map +1 -0
  194. package/resources/self-mailers.d.ts +99 -15
  195. package/resources/self-mailers.d.ts.map +1 -1
  196. package/resources/self-mailers.js +38 -0
  197. package/resources/self-mailers.js.map +1 -1
  198. package/resources/self-mailers.mjs +38 -0
  199. package/resources/self-mailers.mjs.map +1 -1
  200. package/resources/shared.d.ts +6 -2
  201. package/resources/shared.d.ts.map +1 -1
  202. package/resources/sub-organizations.d.ts +394 -0
  203. package/resources/sub-organizations.d.ts.map +1 -0
  204. package/resources/sub-organizations.js +63 -0
  205. package/resources/sub-organizations.js.map +1 -0
  206. package/resources/sub-organizations.mjs +58 -0
  207. package/resources/sub-organizations.mjs.map +1 -0
  208. package/resources/templates.d.ts +43 -3
  209. package/resources/templates.d.ts.map +1 -1
  210. package/resources/templates.js +26 -0
  211. package/resources/templates.js.map +1 -1
  212. package/resources/templates.mjs +26 -0
  213. package/resources/templates.mjs.map +1 -1
  214. package/resources.d.ts +2 -0
  215. package/resources.d.ts.map +1 -0
  216. package/resources.js +18 -0
  217. package/resources.js.map +1 -0
  218. package/resources.mjs +2 -0
  219. package/resources.mjs.map +1 -0
  220. package/src/_shims/index.d.ts +2 -0
  221. package/src/_shims/index.js +5 -1
  222. package/src/_shims/index.mjs +5 -1
  223. package/src/core.ts +44 -16
  224. package/src/index.ts +112 -11
  225. package/src/internal/qs/LICENSE.md +13 -0
  226. package/src/internal/qs/README.md +3 -0
  227. package/src/internal/qs/formats.ts +9 -0
  228. package/src/internal/qs/index.ts +13 -0
  229. package/src/internal/qs/stringify.ts +388 -0
  230. package/src/internal/qs/types.ts +71 -0
  231. package/src/internal/qs/utils.ts +265 -0
  232. package/src/pagination.ts +6 -1
  233. package/src/resource.ts +1 -1
  234. package/src/resources/bank-accounts.ts +57 -4
  235. package/src/resources/boxes.ts +50 -15
  236. package/src/resources/campaigns.ts +8 -8
  237. package/src/resources/cheques/cheques.ts +35 -4
  238. package/src/resources/cheques/url.ts +5 -0
  239. package/src/resources/cheques/with-deposit-ready-pdf.ts +6 -0
  240. package/src/resources/cheques.ts +3 -0
  241. package/src/resources/contacts.ts +31 -3
  242. package/src/resources/index.ts +39 -0
  243. package/src/resources/letters.ts +38 -6
  244. package/src/resources/mailing-list-imports.ts +1076 -0
  245. package/src/resources/mailing-lists.ts +511 -0
  246. package/src/resources/order-profiles/cheques.ts +888 -0
  247. package/src/resources/order-profiles/index.ts +55 -0
  248. package/src/resources/order-profiles/letters.ts +956 -0
  249. package/src/resources/order-profiles/order-profiles.ts +133 -0
  250. package/src/resources/order-profiles/postcards.ts +694 -0
  251. package/src/resources/order-profiles/self-mailers.ts +707 -0
  252. package/src/resources/order-profiles.ts +3 -0
  253. package/src/resources/postcards.ts +42 -8
  254. package/src/resources/reports/exports.ts +30 -3
  255. package/src/resources/reports/reports.ts +60 -8
  256. package/src/resources/reports.ts +3 -0
  257. package/src/resources/self-mailers.ts +80 -14
  258. package/src/resources/shared.ts +2 -2
  259. package/src/resources/sub-organizations.ts +518 -0
  260. package/src/resources/templates.ts +37 -3
  261. package/src/resources.ts +1 -0
  262. package/src/version.ts +1 -1
  263. package/version.d.ts +1 -1
  264. package/version.js +1 -1
  265. package/version.mjs +1 -1
@@ -0,0 +1,265 @@
1
+ import { RFC1738 } from './formats';
2
+ import type { DefaultEncoder, Format } from './types';
3
+
4
+ const has = Object.prototype.hasOwnProperty;
5
+ const is_array = Array.isArray;
6
+
7
+ const hex_table = (() => {
8
+ const array = [];
9
+ for (let i = 0; i < 256; ++i) {
10
+ array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
11
+ }
12
+
13
+ return array;
14
+ })();
15
+
16
+ function compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; prop: string }>) {
17
+ while (queue.length > 1) {
18
+ const item = queue.pop();
19
+ if (!item) continue;
20
+
21
+ const obj = item.obj[item.prop];
22
+
23
+ if (is_array(obj)) {
24
+ const compacted: unknown[] = [];
25
+
26
+ for (let j = 0; j < obj.length; ++j) {
27
+ if (typeof obj[j] !== 'undefined') {
28
+ compacted.push(obj[j]);
29
+ }
30
+ }
31
+
32
+ // @ts-ignore
33
+ item.obj[item.prop] = compacted;
34
+ }
35
+ }
36
+ }
37
+
38
+ function array_to_object(source: any[], options: { plainObjects: boolean }) {
39
+ const obj = options && options.plainObjects ? Object.create(null) : {};
40
+ for (let i = 0; i < source.length; ++i) {
41
+ if (typeof source[i] !== 'undefined') {
42
+ obj[i] = source[i];
43
+ }
44
+ }
45
+
46
+ return obj;
47
+ }
48
+
49
+ export function merge(
50
+ target: any,
51
+ source: any,
52
+ options: { plainObjects?: boolean; allowPrototypes?: boolean } = {},
53
+ ) {
54
+ if (!source) {
55
+ return target;
56
+ }
57
+
58
+ if (typeof source !== 'object') {
59
+ if (is_array(target)) {
60
+ target.push(source);
61
+ } else if (target && typeof target === 'object') {
62
+ if (
63
+ (options && (options.plainObjects || options.allowPrototypes)) ||
64
+ !has.call(Object.prototype, source)
65
+ ) {
66
+ target[source] = true;
67
+ }
68
+ } else {
69
+ return [target, source];
70
+ }
71
+
72
+ return target;
73
+ }
74
+
75
+ if (!target || typeof target !== 'object') {
76
+ return [target].concat(source);
77
+ }
78
+
79
+ let mergeTarget = target;
80
+ if (is_array(target) && !is_array(source)) {
81
+ // @ts-ignore
82
+ mergeTarget = array_to_object(target, options);
83
+ }
84
+
85
+ if (is_array(target) && is_array(source)) {
86
+ source.forEach(function (item, i) {
87
+ if (has.call(target, i)) {
88
+ const targetItem = target[i];
89
+ if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
90
+ target[i] = merge(targetItem, item, options);
91
+ } else {
92
+ target.push(item);
93
+ }
94
+ } else {
95
+ target[i] = item;
96
+ }
97
+ });
98
+ return target;
99
+ }
100
+
101
+ return Object.keys(source).reduce(function (acc, key) {
102
+ const value = source[key];
103
+
104
+ if (has.call(acc, key)) {
105
+ acc[key] = merge(acc[key], value, options);
106
+ } else {
107
+ acc[key] = value;
108
+ }
109
+ return acc;
110
+ }, mergeTarget);
111
+ }
112
+
113
+ export function assign_single_source(target: any, source: any) {
114
+ return Object.keys(source).reduce(function (acc, key) {
115
+ acc[key] = source[key];
116
+ return acc;
117
+ }, target);
118
+ }
119
+
120
+ export function decode(str: string, _: any, charset: string) {
121
+ const strWithoutPlus = str.replace(/\+/g, ' ');
122
+ if (charset === 'iso-8859-1') {
123
+ // unescape never throws, no try...catch needed:
124
+ return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
125
+ }
126
+ // utf-8
127
+ try {
128
+ return decodeURIComponent(strWithoutPlus);
129
+ } catch (e) {
130
+ return strWithoutPlus;
131
+ }
132
+ }
133
+
134
+ const limit = 1024;
135
+
136
+ export const encode: (
137
+ str: any,
138
+ defaultEncoder: DefaultEncoder,
139
+ charset: string,
140
+ type: 'key' | 'value',
141
+ format: Format,
142
+ ) => string = (str, _defaultEncoder, charset, _kind, format: Format) => {
143
+ // This code was originally written by Brian White for the io.js core querystring library.
144
+ // It has been adapted here for stricter adherence to RFC 3986
145
+ if (str.length === 0) {
146
+ return str;
147
+ }
148
+
149
+ let string = str;
150
+ if (typeof str === 'symbol') {
151
+ string = Symbol.prototype.toString.call(str);
152
+ } else if (typeof str !== 'string') {
153
+ string = String(str);
154
+ }
155
+
156
+ if (charset === 'iso-8859-1') {
157
+ return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
158
+ return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
159
+ });
160
+ }
161
+
162
+ let out = '';
163
+ for (let j = 0; j < string.length; j += limit) {
164
+ const segment = string.length >= limit ? string.slice(j, j + limit) : string;
165
+ const arr = [];
166
+
167
+ for (let i = 0; i < segment.length; ++i) {
168
+ let c = segment.charCodeAt(i);
169
+ if (
170
+ c === 0x2d || // -
171
+ c === 0x2e || // .
172
+ c === 0x5f || // _
173
+ c === 0x7e || // ~
174
+ (c >= 0x30 && c <= 0x39) || // 0-9
175
+ (c >= 0x41 && c <= 0x5a) || // a-z
176
+ (c >= 0x61 && c <= 0x7a) || // A-Z
177
+ (format === RFC1738 && (c === 0x28 || c === 0x29)) // ( )
178
+ ) {
179
+ arr[arr.length] = segment.charAt(i);
180
+ continue;
181
+ }
182
+
183
+ if (c < 0x80) {
184
+ arr[arr.length] = hex_table[c];
185
+ continue;
186
+ }
187
+
188
+ if (c < 0x800) {
189
+ arr[arr.length] = hex_table[0xc0 | (c >> 6)]! + hex_table[0x80 | (c & 0x3f)];
190
+ continue;
191
+ }
192
+
193
+ if (c < 0xd800 || c >= 0xe000) {
194
+ arr[arr.length] =
195
+ hex_table[0xe0 | (c >> 12)]! + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];
196
+ continue;
197
+ }
198
+
199
+ i += 1;
200
+ c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));
201
+
202
+ arr[arr.length] =
203
+ hex_table[0xf0 | (c >> 18)]! +
204
+ hex_table[0x80 | ((c >> 12) & 0x3f)] +
205
+ hex_table[0x80 | ((c >> 6) & 0x3f)] +
206
+ hex_table[0x80 | (c & 0x3f)];
207
+ }
208
+
209
+ out += arr.join('');
210
+ }
211
+
212
+ return out;
213
+ };
214
+
215
+ export function compact(value: any) {
216
+ const queue = [{ obj: { o: value }, prop: 'o' }];
217
+ const refs = [];
218
+
219
+ for (let i = 0; i < queue.length; ++i) {
220
+ const item = queue[i];
221
+ // @ts-ignore
222
+ const obj = item.obj[item.prop];
223
+
224
+ const keys = Object.keys(obj);
225
+ for (let j = 0; j < keys.length; ++j) {
226
+ const key = keys[j]!;
227
+ const val = obj[key];
228
+ if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
229
+ queue.push({ obj: obj, prop: key });
230
+ refs.push(val);
231
+ }
232
+ }
233
+ }
234
+
235
+ compact_queue(queue);
236
+
237
+ return value;
238
+ }
239
+
240
+ export function is_regexp(obj: any) {
241
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
242
+ }
243
+
244
+ export function is_buffer(obj: any) {
245
+ if (!obj || typeof obj !== 'object') {
246
+ return false;
247
+ }
248
+
249
+ return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
250
+ }
251
+
252
+ export function combine(a: any, b: any) {
253
+ return [].concat(a, b);
254
+ }
255
+
256
+ export function maybe_map<T>(val: T[], fn: (v: T) => T) {
257
+ if (is_array(val)) {
258
+ const mapped = [];
259
+ for (let i = 0; i < val.length; i += 1) {
260
+ mapped.push(fn(val[i]!));
261
+ }
262
+ return mapped;
263
+ }
264
+ return fn(val);
265
+ }
package/src/pagination.ts CHANGED
@@ -6,6 +6,8 @@ export interface ListResponse<Item> {
6
6
  data: Array<Item>;
7
7
 
8
8
  totalCount: number;
9
+
10
+ limit: number;
9
11
  }
10
12
 
11
13
  export interface ListParams {
@@ -25,11 +27,14 @@ export class List<Item> extends AbstractPage<Item> implements ListResponse<Item>
25
27
 
26
28
  totalCount: number;
27
29
 
30
+ limit: number;
31
+
28
32
  constructor(client: APIClient, response: Response, body: ListResponse<Item>, options: FinalRequestOptions) {
29
33
  super(client, response, body, options);
30
34
 
31
35
  this.data = body.data || [];
32
36
  this.totalCount = body.totalCount || 0;
37
+ this.limit = body.limit || 0;
33
38
  }
34
39
 
35
40
  getPaginatedItems(): Item[] {
@@ -47,7 +52,7 @@ export class List<Item> extends AbstractPage<Item> implements ListResponse<Item>
47
52
  }
48
53
 
49
54
  nextPageInfo(): PageInfo | null {
50
- const offset = (this.options.query as ListParams).skip ?? 0;
55
+ const offset = this.limit;
51
56
  if (!offset) {
52
57
  return null;
53
58
  }
package/src/resource.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type { PostGrid } from './index';
4
4
 
5
- export class APIResource {
5
+ export abstract class APIResource {
6
6
  protected _client: PostGrid;
7
7
 
8
8
  constructor(client: PostGrid) {
@@ -14,6 +14,19 @@ export class BankAccounts extends APIResource {
14
14
  *
15
15
  * You must specify _either_ `signatureImage` or `signatureText`. The image can be
16
16
  * supplied as either a URL or a multipart file upload.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const bankAccount = await client.bankAccounts.create({
21
+ * accountNumber: '1234567',
22
+ * bankCountryCode: 'US',
23
+ * bankName: 'Test Bank',
24
+ * signatureText: 'Example',
25
+ * bankPrimaryLine: '145 mulberry st',
26
+ * bankSecondaryLine: 'new york ny 10013',
27
+ * routingNumber: '123456789',
28
+ * });
29
+ * ```
17
30
  */
18
31
  create(body: BankAccountCreateParams, options?: Core.RequestOptions): Core.APIPromise<BankAccount> {
19
32
  return this._client.post('/bank_accounts', { body, ...options });
@@ -21,6 +34,13 @@ export class BankAccounts extends APIResource {
21
34
 
22
35
  /**
23
36
  * Retrieve a bank account by ID.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const bankAccount = await client.bankAccounts.retrieve(
41
+ * 'id',
42
+ * );
43
+ * ```
24
44
  */
25
45
  retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<BankAccount> {
26
46
  return this._client.get(`/bank_accounts/${id}`, options);
@@ -28,6 +48,14 @@ export class BankAccounts extends APIResource {
28
48
 
29
49
  /**
30
50
  * Get a list of bank accounts.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // Automatically fetches more pages as needed.
55
+ * for await (const bankAccount of client.bankAccounts.list()) {
56
+ * // ...
57
+ * }
58
+ * ```
31
59
  */
32
60
  list(
33
61
  query?: BankAccountListParams,
@@ -46,6 +74,11 @@ export class BankAccounts extends APIResource {
46
74
 
47
75
  /**
48
76
  * Delete a bank account by ID. Note that this operation cannot be undone.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const bankAccount = await client.bankAccounts.delete('id');
81
+ * ```
49
82
  */
50
83
  delete(id: string, options?: Core.RequestOptions): Core.APIPromise<BankAccountDeleteResponse> {
51
84
  return this._client.delete(`/bank_accounts/${id}`, options);
@@ -106,6 +139,11 @@ export interface BankAccount {
106
139
  */
107
140
  bankSecondaryLine?: string;
108
141
 
142
+ /**
143
+ * The designation number of the bank account (for CA).
144
+ */
145
+ caDesignationNumber?: string;
146
+
109
147
  /**
110
148
  * An optional string describing this resource. Will be visible in the API and the
111
149
  * dashboard.
@@ -115,7 +153,7 @@ export interface BankAccount {
115
153
  /**
116
154
  * See the section on Metadata.
117
155
  */
118
- metadata?: Record<string, unknown>;
156
+ metadata?: { [key: string]: unknown };
119
157
 
120
158
  /**
121
159
  * The route number of the bank account (for CA).
@@ -209,6 +247,11 @@ export declare namespace BankAccountCreateParams {
209
247
  */
210
248
  bankSecondaryLine?: string;
211
249
 
250
+ /**
251
+ * The designation number of the bank account (for CA).
252
+ */
253
+ caDesignationNumber?: string;
254
+
212
255
  /**
213
256
  * An optional string describing this resource. Will be visible in the API and the
214
257
  * dashboard.
@@ -218,7 +261,7 @@ export declare namespace BankAccountCreateParams {
218
261
  /**
219
262
  * See the section on Metadata.
220
263
  */
221
- metadata?: Record<string, unknown>;
264
+ metadata?: { [key: string]: unknown };
222
265
 
223
266
  /**
224
267
  * The route number of the bank account (for CA).
@@ -269,6 +312,11 @@ export declare namespace BankAccountCreateParams {
269
312
  */
270
313
  bankSecondaryLine?: string;
271
314
 
315
+ /**
316
+ * The designation number of the bank account (for CA).
317
+ */
318
+ caDesignationNumber?: string;
319
+
272
320
  /**
273
321
  * An optional string describing this resource. Will be visible in the API and the
274
322
  * dashboard.
@@ -278,7 +326,7 @@ export declare namespace BankAccountCreateParams {
278
326
  /**
279
327
  * See the section on Metadata.
280
328
  */
281
- metadata?: Record<string, unknown>;
329
+ metadata?: { [key: string]: unknown };
282
330
 
283
331
  /**
284
332
  * The route number of the bank account (for CA).
@@ -329,6 +377,11 @@ export declare namespace BankAccountCreateParams {
329
377
  */
330
378
  bankSecondaryLine?: string;
331
379
 
380
+ /**
381
+ * The designation number of the bank account (for CA).
382
+ */
383
+ caDesignationNumber?: string;
384
+
332
385
  /**
333
386
  * An optional string describing this resource. Will be visible in the API and the
334
387
  * dashboard.
@@ -338,7 +391,7 @@ export declare namespace BankAccountCreateParams {
338
391
  /**
339
392
  * See the section on Metadata.
340
393
  */
341
- metadata?: Record<string, unknown>;
394
+ metadata?: { [key: string]: unknown };
342
395
 
343
396
  /**
344
397
  * The route number of the bank account (for CA).
@@ -25,6 +25,23 @@ export class Boxes extends APIResource {
25
25
  * - `bankAccount`: The bank account ID
26
26
  * - `amount`: The amount to be sent
27
27
  * - `number`: The cheque number
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const box = await client.boxes.create({
32
+ * cheques: [
33
+ * {
34
+ * from: 'contact_456',
35
+ * to: 'contact_123',
36
+ * bankAccount: 'bank_abc',
37
+ * amount: 5000,
38
+ * number: 1042,
39
+ * },
40
+ * ],
41
+ * from: 'contact_456',
42
+ * to: 'contact_123',
43
+ * });
44
+ * ```
28
45
  */
29
46
  create(body: BoxCreateParams, options?: Core.RequestOptions): Core.APIPromise<BoxCreateResponse> {
30
47
  return this._client.post('/boxes', { body, ...options });
@@ -32,6 +49,11 @@ export class Boxes extends APIResource {
32
49
 
33
50
  /**
34
51
  * Retrieve a box by ID.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const box = await client.boxes.retrieve('id');
56
+ * ```
35
57
  */
36
58
  retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<BoxRetrieveResponse> {
37
59
  return this._client.get(`/boxes/${id}`, options);
@@ -39,6 +61,14 @@ export class Boxes extends APIResource {
39
61
 
40
62
  /**
41
63
  * List all boxes.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * // Automatically fetches more pages as needed.
68
+ * for await (const boxListResponse of client.boxes.list()) {
69
+ * // ...
70
+ * }
71
+ * ```
42
72
  */
43
73
  list(
44
74
  query?: BoxListParams,
@@ -57,6 +87,11 @@ export class Boxes extends APIResource {
57
87
 
58
88
  /**
59
89
  * Cancel a box by ID (cannot be undone).
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const response = await client.boxes.cancel('id');
94
+ * ```
60
95
  */
61
96
  cancel(id: string, options?: Core.RequestOptions): Core.APIPromise<BoxCancelResponse> {
62
97
  return this._client.delete(`/boxes/${id}`, options);
@@ -187,12 +222,12 @@ export interface BoxCreateResponse {
187
222
  * template _exactly_ as they are case-sensitive. Note that these _do not_ apply to
188
223
  * PDFs uploaded with the order.
189
224
  */
190
- mergeVariables?: Record<string, unknown>;
225
+ mergeVariables?: { [key: string]: unknown };
191
226
 
192
227
  /**
193
228
  * See the section on Metadata.
194
229
  */
195
- metadata?: Record<string, unknown>;
230
+ metadata?: { [key: string]: unknown };
196
231
 
197
232
  /**
198
233
  * The tracking number of this order. Populated after an express/certified order
@@ -248,7 +283,7 @@ export namespace BoxCreateResponse {
248
283
  * A set of dynamic merge variables for customizing the cheque or accompanying
249
284
  * documents (optional).
250
285
  */
251
- mergeVariables?: Record<string, unknown>;
286
+ mergeVariables?: { [key: string]: unknown };
252
287
 
253
288
  /**
254
289
  * An optional message template to be printed on or with the cheque.
@@ -379,12 +414,12 @@ export interface BoxRetrieveResponse {
379
414
  * template _exactly_ as they are case-sensitive. Note that these _do not_ apply to
380
415
  * PDFs uploaded with the order.
381
416
  */
382
- mergeVariables?: Record<string, unknown>;
417
+ mergeVariables?: { [key: string]: unknown };
383
418
 
384
419
  /**
385
420
  * See the section on Metadata.
386
421
  */
387
- metadata?: Record<string, unknown>;
422
+ metadata?: { [key: string]: unknown };
388
423
 
389
424
  /**
390
425
  * The tracking number of this order. Populated after an express/certified order
@@ -440,7 +475,7 @@ export namespace BoxRetrieveResponse {
440
475
  * A set of dynamic merge variables for customizing the cheque or accompanying
441
476
  * documents (optional).
442
477
  */
443
- mergeVariables?: Record<string, unknown>;
478
+ mergeVariables?: { [key: string]: unknown };
444
479
 
445
480
  /**
446
481
  * An optional message template to be printed on or with the cheque.
@@ -571,12 +606,12 @@ export interface BoxListResponse {
571
606
  * template _exactly_ as they are case-sensitive. Note that these _do not_ apply to
572
607
  * PDFs uploaded with the order.
573
608
  */
574
- mergeVariables?: Record<string, unknown>;
609
+ mergeVariables?: { [key: string]: unknown };
575
610
 
576
611
  /**
577
612
  * See the section on Metadata.
578
613
  */
579
- metadata?: Record<string, unknown>;
614
+ metadata?: { [key: string]: unknown };
580
615
 
581
616
  /**
582
617
  * The tracking number of this order. Populated after an express/certified order
@@ -632,7 +667,7 @@ export namespace BoxListResponse {
632
667
  * A set of dynamic merge variables for customizing the cheque or accompanying
633
668
  * documents (optional).
634
669
  */
635
- mergeVariables?: Record<string, unknown>;
670
+ mergeVariables?: { [key: string]: unknown };
636
671
 
637
672
  /**
638
673
  * An optional message template to be printed on or with the cheque.
@@ -763,12 +798,12 @@ export interface BoxCancelResponse {
763
798
  * template _exactly_ as they are case-sensitive. Note that these _do not_ apply to
764
799
  * PDFs uploaded with the order.
765
800
  */
766
- mergeVariables?: Record<string, unknown>;
801
+ mergeVariables?: { [key: string]: unknown };
767
802
 
768
803
  /**
769
804
  * See the section on Metadata.
770
805
  */
771
- metadata?: Record<string, unknown>;
806
+ metadata?: { [key: string]: unknown };
772
807
 
773
808
  /**
774
809
  * The tracking number of this order. Populated after an express/certified order
@@ -824,7 +859,7 @@ export namespace BoxCancelResponse {
824
859
  * A set of dynamic merge variables for customizing the cheque or accompanying
825
860
  * documents (optional).
826
861
  */
827
- mergeVariables?: Record<string, unknown>;
862
+ mergeVariables?: { [key: string]: unknown };
828
863
 
829
864
  /**
830
865
  * An optional message template to be printed on or with the cheque.
@@ -898,12 +933,12 @@ export interface BoxCreateParams {
898
933
  * template _exactly_ as they are case-sensitive. Note that these _do not_ apply to
899
934
  * PDFs uploaded with the order.
900
935
  */
901
- mergeVariables?: Record<string, unknown>;
936
+ mergeVariables?: { [key: string]: unknown };
902
937
 
903
938
  /**
904
939
  * See the section on Metadata.
905
940
  */
906
- metadata?: Record<string, unknown>;
941
+ metadata?: { [key: string]: unknown };
907
942
 
908
943
  /**
909
944
  * This order will transition from `ready` to `printing` on the day after this
@@ -947,7 +982,7 @@ export namespace BoxCreateParams {
947
982
  * A set of dynamic merge variables for customizing the cheque or accompanying
948
983
  * documents (optional).
949
984
  */
950
- mergeVariables?: Record<string, unknown>;
985
+ mergeVariables?: { [key: string]: unknown };
951
986
 
952
987
  /**
953
988
  * An optional message template to be printed on or with the cheque.
@@ -166,7 +166,7 @@ export interface CampaignCreateResponse {
166
166
  /**
167
167
  * See the section on Metadata.
168
168
  */
169
- metadata?: Record<string, unknown>;
169
+ metadata?: { [key: string]: unknown };
170
170
 
171
171
  /**
172
172
  * A temporary URL to preview the first rendered order, available once the campaign
@@ -290,7 +290,7 @@ export interface CampaignRetrieveResponse {
290
290
  /**
291
291
  * See the section on Metadata.
292
292
  */
293
- metadata?: Record<string, unknown>;
293
+ metadata?: { [key: string]: unknown };
294
294
 
295
295
  /**
296
296
  * A temporary URL to preview the first rendered order, available once the campaign
@@ -414,7 +414,7 @@ export interface CampaignUpdateResponse {
414
414
  /**
415
415
  * See the section on Metadata.
416
416
  */
417
- metadata?: Record<string, unknown>;
417
+ metadata?: { [key: string]: unknown };
418
418
 
419
419
  /**
420
420
  * A temporary URL to preview the first rendered order, available once the campaign
@@ -538,7 +538,7 @@ export interface CampaignListResponse {
538
538
  /**
539
539
  * See the section on Metadata.
540
540
  */
541
- metadata?: Record<string, unknown>;
541
+ metadata?: { [key: string]: unknown };
542
542
 
543
543
  /**
544
544
  * A temporary URL to preview the first rendered order, available once the campaign
@@ -671,7 +671,7 @@ export interface CampaignSendResponse {
671
671
  /**
672
672
  * See the section on Metadata.
673
673
  */
674
- metadata?: Record<string, unknown>;
674
+ metadata?: { [key: string]: unknown };
675
675
 
676
676
  /**
677
677
  * A temporary URL to preview the first rendered order, available once the campaign
@@ -749,7 +749,7 @@ export interface CampaignCreateParams {
749
749
  /**
750
750
  * See the section on Metadata.
751
751
  */
752
- metadata?: Record<string, unknown>;
752
+ metadata?: { [key: string]: unknown };
753
753
 
754
754
  /**
755
755
  * The ID of the postcard profile used for this campaign, if applicable.
@@ -800,7 +800,7 @@ export interface CampaignUpdateParams {
800
800
  * Optional key-value data associated with the campaign. Set to `null` to remove
801
801
  * existing metadata.
802
802
  */
803
- metadata?: Record<string, string> | null;
803
+ metadata?: { [key: string]: string } | null;
804
804
 
805
805
  /**
806
806
  * The ID of the postcard profile to use. Setting this will remove other profile
@@ -831,7 +831,7 @@ export interface CampaignSendParams {
831
831
  * The date and time the campaign should be sent. Must be in the future. If
832
832
  * omitted, defaults to the earliest possible processing date.
833
833
  */
834
- sendDate?: string | string;
834
+ sendDate?: (string & {}) | string;
835
835
  }
836
836
 
837
837
  Campaigns.CampaignListResponsesList = CampaignListResponsesList;