forked from flexbase-eng/postgrid-node-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmailing-lists.ts
More file actions
305 lines (272 loc) · 8.27 KB
/
mailing-lists.ts
File metadata and controls
305 lines (272 loc) · 8.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { PagePromise, SkipLimit, type SkipLimitParams } from '../../core/pagination';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class MailingLists extends APIResource {
/**
* Create a new mailing list.
*
* @example
* ```ts
* const mailingList =
* await client.printMail.mailingLists.create({
* description: 'Test Mailing List',
* metadata: { campaign: 'launch' },
* });
* ```
*/
create(params: MailingListCreateParams, options?: RequestOptions): APIPromise<MailingList> {
const { 'idempotency-key': idempotencyKey, ...body } = params;
return this._client.post('/print-mail/v1/mailing_lists', {
body,
...options,
headers: buildHeaders([
{ ...(idempotencyKey != null ? { 'idempotency-key': idempotencyKey } : undefined) },
options?.headers,
]),
});
}
/**
* Retrieve a specific mailing list by its ID.
*
* @example
* ```ts
* const mailingList =
* await client.printMail.mailingLists.retrieve('id');
* ```
*/
retrieve(id: string, options?: RequestOptions): APIPromise<MailingList> {
return this._client.get(path`/print-mail/v1/mailing_lists/${id}`, options);
}
/**
* Update an existing mailing list.
*
* @example
* ```ts
* const mailingListUpdate =
* await client.printMail.mailingLists.update('id', {
* description: 'Updated Mailing List Description',
* });
* ```
*/
update(id: string, body: MailingListUpdateParams, options?: RequestOptions): APIPromise<MailingListUpdate> {
return this._client.post(path`/print-mail/v1/mailing_lists/${id}`, { body, ...options });
}
/**
* Retrieve a list of mailing lists.
*
* Returns a paginated list of mailing lists associated with the authenticated
* organization, filterable by various parameters.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const mailingList of client.printMail.mailingLists.list()) {
* // ...
* }
* ```
*/
list(
query: MailingListListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<MailingListsSkipLimit, MailingList> {
return this._client.getAPIList('/print-mail/v1/mailing_lists', SkipLimit<MailingList>, {
query,
...options,
});
}
/**
* Delete a mailing list.
*
* This permanently deletes the mailing list and its associations. This operation
* cannot be undone.
*
* @example
* ```ts
* const mailingList =
* await client.printMail.mailingLists.delete('id');
* ```
*/
delete(id: string, options?: RequestOptions): APIPromise<MailingListDeleteResponse> {
return this._client.delete(path`/print-mail/v1/mailing_lists/${id}`, options);
}
/**
* Runs a mailing list job. Mailing list jobs allow you to add or remove contacts
* to your mailing list from mailing list imports or directly with contact IDs.
* Only one job can be ran at a time and jobs are only able to be ran while the
* mailing list has a `status` of "completed".
*
* Once a job as successfully been kicked off, the mailing list will have a
* `status` of either `creating_contacts` or `removing_contacts` depending on which
* job was ran. After the job has finished, the mailing list will go back into the
* `completed` state where more jobs can be ran. If there are any errors while
* running a job, the `errors` field on the mailing list will contain a list of
* error objects which describe the errors.
*
* @example
* ```ts
* const mailingList =
* await client.printMail.mailingLists.jobs('id', {
* removeMailingListImports: [
* 'mailing_list_import_123',
* 'mailing_list_import_456',
* ],
* });
* ```
*/
jobs(id: string, body: MailingListJobsParams, options?: RequestOptions): APIPromise<MailingList> {
return this._client.post(path`/print-mail/v1/mailing_lists/${id}/jobs`, { body, ...options });
}
}
export type MailingListsSkipLimit = SkipLimit<MailingList>;
/**
* Represents a mailing list.
*/
export interface MailingList {
/**
* A unique ID prefixed with mailing*list*
*/
id: string;
/**
* The UTC time at which this resource was created.
*/
createdAt: string;
/**
* `true` if this is a live mode resource else `false`.
*/
live: boolean;
/**
* Status of the mailing list processing.
*/
status: 'creating_contacts' | 'removing_contacts' | 'counting_recipient_country_codes' | 'completed';
/**
* The UTC time at which this resource was last updated.
*/
updatedAt: string;
/**
* An optional string describing this resource. Will be visible in the API and the
* dashboard.
*/
description?: string;
/**
* A list of processing errors encountered, if any.
*/
errors?: Array<MailingList.Error>;
/**
* See the section on Metadata.
*/
metadata?: { [key: string]: unknown };
}
export namespace MailingList {
/**
* Details of a specific error encountered during processing.
*/
export interface Error {
/**
* A human-readable message describing the error.
*/
message: string;
/**
* Type of error encountered during mailing list processing.
*/
type:
| 'mailing_list_imports_not_found_error'
| 'download_file_error'
| 'operational_error'
| 'internal_service_error';
}
}
/**
* Parameters for updating an existing mailing list.
*/
export interface MailingListUpdate {
/**
* An optional string describing this resource. Will be visible in the API and the
* dashboard.
*/
description?: string;
/**
* See the section on Metadata.
*/
metadata?: { [key: string]: unknown };
}
export interface MailingListDeleteResponse {
/**
* A unique ID prefixed with mailing*list*
*/
id: string;
deleted: true;
}
export interface MailingListCreateParams {
/**
* Body param: An optional string describing this resource. Will be visible in the
* API and the dashboard.
*/
description?: string;
/**
* Body param: See the section on Metadata.
*/
metadata?: { [key: string]: unknown };
/**
* Header param
*/
'idempotency-key'?: string;
}
export interface MailingListUpdateParams {
/**
* An optional string describing this resource. Will be visible in the API and the
* dashboard.
*/
description?: string;
/**
* See the section on Metadata.
*/
metadata?: { [key: string]: unknown };
}
export interface MailingListListParams extends SkipLimitParams {
/**
* You can supply any string to help narrow down the list of resources. For
* example, if you pass `"New York"` (quoted), it will return resources that have
* that string present somewhere in their response. Alternatively, you can supply a
* structured search query. See the documentation on `StructuredSearchQuery` for
* more details.
*/
search?: string;
}
export interface MailingListJobsParams {
/**
* List of contact IDs to add to the mailing list. Cannot be used with other
* operations.
*/
addContacts?: Array<string>;
/**
* List of mailing list import IDs to add to the mailing list. Cannot be used with
* other operations.
*/
addMailingListImports?: Array<string>;
/**
* List of contact IDs to remove from the mailing list. Cannot be used with other
* operations.
*/
removeContacts?: Array<string>;
/**
* List of mailing list import IDs to remove from the mailing list. Cannot be used
* with other operations.
*/
removeMailingListImports?: Array<string>;
}
export declare namespace MailingLists {
export {
type MailingList as MailingList,
type MailingListUpdate as MailingListUpdate,
type MailingListDeleteResponse as MailingListDeleteResponse,
type MailingListsSkipLimit as MailingListsSkipLimit,
type MailingListCreateParams as MailingListCreateParams,
type MailingListUpdateParams as MailingListUpdateParams,
type MailingListListParams as MailingListListParams,
type MailingListJobsParams as MailingListJobsParams,
};
}