@sentdm/sentdm 0.36.0 → 0.38.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 (137) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +31 -0
  3. package/client.d.mts +28 -14
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +28 -14
  6. package/client.d.ts.map +1 -1
  7. package/client.js +10 -0
  8. package/client.js.map +1 -1
  9. package/client.mjs +10 -0
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +164 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +164 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +212 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +202 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +1 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +3 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +1 -0
  26. package/index.mjs.map +1 -1
  27. package/internal/tslib.js +17 -17
  28. package/package.json +11 -1
  29. package/pagination.d.mts +3 -0
  30. package/pagination.d.mts.map +1 -0
  31. package/pagination.d.ts +3 -0
  32. package/pagination.d.ts.map +1 -0
  33. package/pagination.js +6 -0
  34. package/pagination.js.map +1 -0
  35. package/pagination.mjs +3 -0
  36. package/pagination.mjs.map +1 -0
  37. package/resources/contacts.d.mts +79 -626
  38. package/resources/contacts.d.mts.map +1 -1
  39. package/resources/contacts.d.ts +79 -626
  40. package/resources/contacts.d.ts.map +1 -1
  41. package/resources/contacts.js +12 -11
  42. package/resources/contacts.js.map +1 -1
  43. package/resources/contacts.mjs +12 -11
  44. package/resources/contacts.mjs.map +1 -1
  45. package/resources/conversations.d.mts +72 -346
  46. package/resources/conversations.d.mts.map +1 -1
  47. package/resources/conversations.d.ts +72 -346
  48. package/resources/conversations.d.ts.map +1 -1
  49. package/resources/conversations.js +16 -13
  50. package/resources/conversations.js.map +1 -1
  51. package/resources/conversations.mjs +16 -13
  52. package/resources/conversations.mjs.map +1 -1
  53. package/resources/index.d.mts +7 -7
  54. package/resources/index.d.mts.map +1 -1
  55. package/resources/index.d.ts +7 -7
  56. package/resources/index.d.ts.map +1 -1
  57. package/resources/index.js.map +1 -1
  58. package/resources/index.mjs.map +1 -1
  59. package/resources/me.d.mts +48 -129
  60. package/resources/me.d.mts.map +1 -1
  61. package/resources/me.d.ts +48 -129
  62. package/resources/me.d.ts.map +1 -1
  63. package/resources/me.js.map +1 -1
  64. package/resources/me.mjs.map +1 -1
  65. package/resources/messages.d.mts +8 -171
  66. package/resources/messages.d.mts.map +1 -1
  67. package/resources/messages.d.ts +8 -171
  68. package/resources/messages.d.ts.map +1 -1
  69. package/resources/messages.js.map +1 -1
  70. package/resources/messages.mjs.map +1 -1
  71. package/resources/numbers.d.mts +3 -42
  72. package/resources/numbers.d.mts.map +1 -1
  73. package/resources/numbers.d.ts +3 -42
  74. package/resources/numbers.d.ts.map +1 -1
  75. package/resources/numbers.js.map +1 -1
  76. package/resources/numbers.mjs.map +1 -1
  77. package/resources/profiles/campaigns.d.mts +149 -544
  78. package/resources/profiles/campaigns.d.mts.map +1 -1
  79. package/resources/profiles/campaigns.d.ts +149 -544
  80. package/resources/profiles/campaigns.d.ts.map +1 -1
  81. package/resources/profiles/index.d.mts +2 -2
  82. package/resources/profiles/index.d.mts.map +1 -1
  83. package/resources/profiles/index.d.ts +2 -2
  84. package/resources/profiles/index.d.ts.map +1 -1
  85. package/resources/profiles/index.js.map +1 -1
  86. package/resources/profiles/index.mjs.map +1 -1
  87. package/resources/profiles/profiles.d.mts +411 -1821
  88. package/resources/profiles/profiles.d.mts.map +1 -1
  89. package/resources/profiles/profiles.d.ts +411 -1821
  90. package/resources/profiles/profiles.d.ts.map +1 -1
  91. package/resources/profiles/profiles.js.map +1 -1
  92. package/resources/profiles/profiles.mjs.map +1 -1
  93. package/resources/templates.d.mts +87 -532
  94. package/resources/templates.d.mts.map +1 -1
  95. package/resources/templates.d.ts +87 -532
  96. package/resources/templates.d.ts.map +1 -1
  97. package/resources/templates.js +11 -10
  98. package/resources/templates.js.map +1 -1
  99. package/resources/templates.mjs +11 -10
  100. package/resources/templates.mjs.map +1 -1
  101. package/resources/users.d.mts +47 -437
  102. package/resources/users.d.mts.map +1 -1
  103. package/resources/users.d.ts +47 -437
  104. package/resources/users.d.ts.map +1 -1
  105. package/resources/users.js +3 -3
  106. package/resources/users.js.map +1 -1
  107. package/resources/users.mjs +3 -3
  108. package/resources/users.mjs.map +1 -1
  109. package/resources/webhooks.d.mts +192 -856
  110. package/resources/webhooks.d.mts.map +1 -1
  111. package/resources/webhooks.d.ts +192 -856
  112. package/resources/webhooks.d.ts.map +1 -1
  113. package/resources/webhooks.js +23 -19
  114. package/resources/webhooks.js.map +1 -1
  115. package/resources/webhooks.mjs +23 -19
  116. package/resources/webhooks.mjs.map +1 -1
  117. package/src/client.ts +124 -45
  118. package/src/core/pagination.ts +428 -0
  119. package/src/index.ts +1 -0
  120. package/src/pagination.ts +2 -0
  121. package/src/resources/contacts.ts +89 -726
  122. package/src/resources/conversations.ts +99 -427
  123. package/src/resources/index.ts +31 -23
  124. package/src/resources/me.ts +59 -148
  125. package/src/resources/messages.ts +8 -194
  126. package/src/resources/numbers.ts +3 -47
  127. package/src/resources/profiles/campaigns.ts +174 -673
  128. package/src/resources/profiles/index.ts +14 -6
  129. package/src/resources/profiles/profiles.ts +529 -2216
  130. package/src/resources/templates.ts +110 -629
  131. package/src/resources/users.ts +48 -505
  132. package/src/resources/webhooks.ts +307 -1091
  133. package/src/version.ts +1 -1
  134. package/version.d.mts +1 -1
  135. package/version.d.ts +1 -1
  136. package/version.js +1 -1
  137. package/version.mjs +1 -1
@@ -0,0 +1,428 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { SentError } from './error';
4
+ import { FinalRequestOptions } from '../internal/request-options';
5
+ import { defaultParseResponse } from '../internal/parse';
6
+ import { type Sent } 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: Sent;
15
+ protected options: FinalRequestOptions;
16
+
17
+ protected response: Response;
18
+ protected body: unknown;
19
+
20
+ constructor(client: Sent, 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 SentError(
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: Sent,
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 ContactsPageResponse<Item> {
111
+ data: ContactsPageResponse.Data<Item>;
112
+ }
113
+
114
+ export namespace ContactsPageResponse {
115
+ export interface Data<Item> {
116
+ contacts?: Array<Item>;
117
+
118
+ pagination?: Data.Pagination;
119
+ }
120
+
121
+ export namespace Data {
122
+ export interface Pagination {
123
+ has_more?: boolean;
124
+ }
125
+ }
126
+ }
127
+
128
+ export interface ContactsPageParams {
129
+ page?: number;
130
+
131
+ page_size?: number;
132
+ }
133
+
134
+ export class ContactsPage<Item> extends AbstractPage<Item> implements ContactsPageResponse<Item> {
135
+ data: ContactsPageResponse.Data<Item>;
136
+
137
+ constructor(
138
+ client: Sent,
139
+ response: Response,
140
+ body: ContactsPageResponse<Item>,
141
+ options: FinalRequestOptions,
142
+ ) {
143
+ super(client, response, body, options);
144
+
145
+ this.data = body.data || {};
146
+ }
147
+
148
+ getPaginatedItems(): Item[] {
149
+ return this.data?.contacts ?? [];
150
+ }
151
+
152
+ override hasNextPage(): boolean {
153
+ if (this.data?.pagination?.has_more === false) {
154
+ return false;
155
+ }
156
+
157
+ return super.hasNextPage();
158
+ }
159
+
160
+ nextPageRequestOptions(): PageRequestOptions | null {
161
+ const query = this.options.query as ContactsPageParams;
162
+ const currentPage = query?.page ?? 1;
163
+
164
+ return {
165
+ ...this.options,
166
+ query: {
167
+ ...maybeObj(this.options.query),
168
+ page: currentPage + 1,
169
+ },
170
+ };
171
+ }
172
+ }
173
+
174
+ export interface ConversationsPageResponse<Item> {
175
+ data: ConversationsPageResponse.Data<Item>;
176
+ }
177
+
178
+ export namespace ConversationsPageResponse {
179
+ export interface Data<Item> {
180
+ messages?: Array<Item>;
181
+
182
+ pagination?: Data.Pagination;
183
+ }
184
+
185
+ export namespace Data {
186
+ export interface Pagination {
187
+ has_more?: boolean;
188
+ }
189
+ }
190
+ }
191
+
192
+ export interface ConversationsPageParams {
193
+ page?: number;
194
+
195
+ page_size?: number;
196
+ }
197
+
198
+ export class ConversationsPage<Item> extends AbstractPage<Item> implements ConversationsPageResponse<Item> {
199
+ data: ConversationsPageResponse.Data<Item>;
200
+
201
+ constructor(
202
+ client: Sent,
203
+ response: Response,
204
+ body: ConversationsPageResponse<Item>,
205
+ options: FinalRequestOptions,
206
+ ) {
207
+ super(client, response, body, options);
208
+
209
+ this.data = body.data || {};
210
+ }
211
+
212
+ getPaginatedItems(): Item[] {
213
+ return this.data?.messages ?? [];
214
+ }
215
+
216
+ override hasNextPage(): boolean {
217
+ if (this.data?.pagination?.has_more === false) {
218
+ return false;
219
+ }
220
+
221
+ return super.hasNextPage();
222
+ }
223
+
224
+ nextPageRequestOptions(): PageRequestOptions | null {
225
+ const query = this.options.query as ConversationsPageParams;
226
+ const currentPage = query?.page ?? 1;
227
+
228
+ return {
229
+ ...this.options,
230
+ query: {
231
+ ...maybeObj(this.options.query),
232
+ page: currentPage + 1,
233
+ },
234
+ };
235
+ }
236
+ }
237
+
238
+ export interface TemplatesPageResponse<Item> {
239
+ data: TemplatesPageResponse.Data<Item>;
240
+ }
241
+
242
+ export namespace TemplatesPageResponse {
243
+ export interface Data<Item> {
244
+ pagination?: Data.Pagination;
245
+
246
+ templates?: Array<Item>;
247
+ }
248
+
249
+ export namespace Data {
250
+ export interface Pagination {
251
+ has_more?: boolean;
252
+ }
253
+ }
254
+ }
255
+
256
+ export interface TemplatesPageParams {
257
+ page?: number;
258
+
259
+ page_size?: number;
260
+ }
261
+
262
+ export class TemplatesPage<Item> extends AbstractPage<Item> implements TemplatesPageResponse<Item> {
263
+ data: TemplatesPageResponse.Data<Item>;
264
+
265
+ constructor(
266
+ client: Sent,
267
+ response: Response,
268
+ body: TemplatesPageResponse<Item>,
269
+ options: FinalRequestOptions,
270
+ ) {
271
+ super(client, response, body, options);
272
+
273
+ this.data = body.data || {};
274
+ }
275
+
276
+ getPaginatedItems(): Item[] {
277
+ return this.data?.templates ?? [];
278
+ }
279
+
280
+ override hasNextPage(): boolean {
281
+ if (this.data?.pagination?.has_more === false) {
282
+ return false;
283
+ }
284
+
285
+ return super.hasNextPage();
286
+ }
287
+
288
+ nextPageRequestOptions(): PageRequestOptions | null {
289
+ const query = this.options.query as TemplatesPageParams;
290
+ const currentPage = query?.page ?? 1;
291
+
292
+ return {
293
+ ...this.options,
294
+ query: {
295
+ ...maybeObj(this.options.query),
296
+ page: currentPage + 1,
297
+ },
298
+ };
299
+ }
300
+ }
301
+
302
+ export interface WebhooksPageResponse<Item> {
303
+ data: WebhooksPageResponse.Data<Item>;
304
+ }
305
+
306
+ export namespace WebhooksPageResponse {
307
+ export interface Data<Item> {
308
+ pagination?: Data.Pagination;
309
+
310
+ webhooks?: Array<Item>;
311
+ }
312
+
313
+ export namespace Data {
314
+ export interface Pagination {
315
+ has_more?: boolean;
316
+ }
317
+ }
318
+ }
319
+
320
+ export interface WebhooksPageParams {
321
+ page?: number;
322
+
323
+ page_size?: number;
324
+ }
325
+
326
+ export class WebhooksPage<Item> extends AbstractPage<Item> implements WebhooksPageResponse<Item> {
327
+ data: WebhooksPageResponse.Data<Item>;
328
+
329
+ constructor(
330
+ client: Sent,
331
+ response: Response,
332
+ body: WebhooksPageResponse<Item>,
333
+ options: FinalRequestOptions,
334
+ ) {
335
+ super(client, response, body, options);
336
+
337
+ this.data = body.data || {};
338
+ }
339
+
340
+ getPaginatedItems(): Item[] {
341
+ return this.data?.webhooks ?? [];
342
+ }
343
+
344
+ override hasNextPage(): boolean {
345
+ if (this.data?.pagination?.has_more === false) {
346
+ return false;
347
+ }
348
+
349
+ return super.hasNextPage();
350
+ }
351
+
352
+ nextPageRequestOptions(): PageRequestOptions | null {
353
+ const query = this.options.query as WebhooksPageParams;
354
+ const currentPage = query?.page ?? 1;
355
+
356
+ return {
357
+ ...this.options,
358
+ query: {
359
+ ...maybeObj(this.options.query),
360
+ page: currentPage + 1,
361
+ },
362
+ };
363
+ }
364
+ }
365
+
366
+ export interface WebhookEventsPageResponse<Item> {
367
+ data: WebhookEventsPageResponse.Data<Item>;
368
+ }
369
+
370
+ export namespace WebhookEventsPageResponse {
371
+ export interface Data<Item> {
372
+ events?: Array<Item>;
373
+
374
+ pagination?: Data.Pagination;
375
+ }
376
+
377
+ export namespace Data {
378
+ export interface Pagination {
379
+ has_more?: boolean;
380
+ }
381
+ }
382
+ }
383
+
384
+ export interface WebhookEventsPageParams {
385
+ page?: number;
386
+
387
+ page_size?: number;
388
+ }
389
+
390
+ export class WebhookEventsPage<Item> extends AbstractPage<Item> implements WebhookEventsPageResponse<Item> {
391
+ data: WebhookEventsPageResponse.Data<Item>;
392
+
393
+ constructor(
394
+ client: Sent,
395
+ response: Response,
396
+ body: WebhookEventsPageResponse<Item>,
397
+ options: FinalRequestOptions,
398
+ ) {
399
+ super(client, response, body, options);
400
+
401
+ this.data = body.data || {};
402
+ }
403
+
404
+ getPaginatedItems(): Item[] {
405
+ return this.data?.events ?? [];
406
+ }
407
+
408
+ override hasNextPage(): boolean {
409
+ if (this.data?.pagination?.has_more === false) {
410
+ return false;
411
+ }
412
+
413
+ return super.hasNextPage();
414
+ }
415
+
416
+ nextPageRequestOptions(): PageRequestOptions | null {
417
+ const query = this.options.query as WebhookEventsPageParams;
418
+ const currentPage = query?.page ?? 1;
419
+
420
+ return {
421
+ ...this.options,
422
+ query: {
423
+ ...maybeObj(this.options.query),
424
+ page: currentPage + 1,
425
+ },
426
+ };
427
+ }
428
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { Sent as default } from './client';
5
5
  export { type Uploadable, toFile } from './core/uploads';
6
6
  export { APIPromise } from './core/api-promise';
7
7
  export { Sent, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
8
9
  export {
9
10
  SentError,
10
11
  APIError,
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';