forked from flexbase-eng/postgrid-node-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsub-organizations.ts
More file actions
398 lines (343 loc) · 9.7 KB
/
sub-organizations.ts
File metadata and controls
398 lines (343 loc) · 9.7 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import * as SubOrganizationsAPI from './sub-organizations';
import { APIPromise } from '../../core/api-promise';
import { PagePromise, SkipLimit, type SkipLimitParams } from '../../core/pagination';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
/**
* Sub-organizations enable you to create isolated PostGrid accounts
* ("sub-organizations") under your PostGrid account (the "parent organization").
* Each sub-organization has fully isolated resources
* and users, and can act independently.
*
* This allows you to isolate different departments or even re-sell PostGrid
* entirely.
*
* You can request access to this feature by reaching out to
* support@postgrid.com
*/
export class SubOrganizations extends APIResource {
/**
* Get a sub-organization.
*
* @example
* ```ts
* const subOrganization =
* await client.printMail.subOrganizations.retrieve('id');
* ```
*/
retrieve(id: string, options?: RequestOptions): APIPromise<SubOrganization> {
return this._client.get(path`/print-mail/v1/sub_organizations/${id}`, options);
}
/**
* When creating a user through the API, the verifiedEmail field will automatically
* be set to true. However, if public signups are used, the email will need to be
* verified by the user.
*
* @example
* ```ts
* const subOrganization =
* await client.printMail.subOrganizations.update({
* countryCode: 'CA',
* email: 'suborg@postgrid.com',
* name: 'Calvin',
* organizationName: 'PostGrid',
* password: 'very-strong-password',
* phoneNumber: '9059059059',
* });
* ```
*/
update(
body: SubOrganizationUpdateParams,
options?: RequestOptions,
): APIPromise<SubOrganizationUpdateResponse> {
return this._client.post('/print-mail/v1/sub_organizations', { body, ...options });
}
/**
* List sub-organizations.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const subOrganization of client.printMail.subOrganizations.list()) {
* // ...
* }
* ```
*/
list(
query: SubOrganizationListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<SubOrganizationsSkipLimit, SubOrganization> {
return this._client.getAPIList('/print-mail/v1/sub_organizations', SkipLimit<SubOrganization>, {
query,
...options,
});
}
/**
* List users for a sub-organization.
*
* @example
* ```ts
* const response =
* await client.printMail.subOrganizations.retrieveUsers(
* 'id',
* );
* ```
*/
retrieveUsers(
id: string,
query: SubOrganizationRetrieveUsersParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<SubOrganizationRetrieveUsersResponse> {
return this._client.get(path`/print-mail/v1/sub_organizations/${id}/users`, { query, ...options });
}
}
export type SubOrganizationsSkipLimit = SkipLimit<SubOrganization>;
/**
* A set of preferences for how a user should receive emails.
*/
export interface EmailPreferences {
/**
* The list of preferences for receiving order preview emails.
*/
orderPreviewSendPreference?: 'do_not_send' | 'send_live_only' | 'send_live_and_test';
}
/**
* The Sub-Organization object.
*/
export interface SubOrganization {
/**
* A unique ID prefixed with `sub_org_`.
*/
id: string;
/**
* The country code of the sub-organization.
*/
countryCode: string;
/**
* The UTC time at which this resource was created.
*/
createdAt: string;
/**
* The limit of mailings the sub-organization can send before being charged
* overages for the month.
*/
limit: number;
/**
* The name of the sub-organization.
*/
name: string;
/**
* Always `sub_org`.
*/
object: 'sub_org';
/**
* The current rolling charge for the sub-organization for the month, in cents.
*/
spend: number;
/**
* The UTC time at which this resource was last update.
*/
updatedAt: string;
/**
* The amount of mail the sub-organization has sent out this month.
*/
usage: number;
}
export interface SubOrganizationUpdateResponse {
/**
* The Sub-Organization object.
*/
subOrganization: SubOrganization;
/**
* The user object.
*/
user: SubOrganizationUpdateResponse.User;
}
export namespace SubOrganizationUpdateResponse {
/**
* The user object.
*/
export interface User {
/**
* A unique ID prefixed with `user_`.
*/
id: string;
/**
* The user's API keys. Contains live and test mode API keys.
*/
apiKeys: Array<User.APIKey>;
/**
* The email of the user.
*/
email: string;
/**
* The name of the user.
*/
name: string;
/**
* A unique ID prefixed with `user_`.
*/
organization: string;
/**
* Indicates if the user has a pending invite.
*/
pendingInvite: boolean;
/**
* The roles given to the user. Roles can be used to restrict access for users.
*/
roles: Array<string>;
/**
* Indicates if the user has a verified email or not.
*/
verifiedEmail: boolean;
/**
* A set of preferences for how a user should receive emails.
*/
emailPreferences?: SubOrganizationsAPI.EmailPreferences;
/**
* The date and time at which the user last logged in.
*/
lastLoginTime?: string;
/**
* The phone number of the user.
*/
phoneNumber?: string;
/**
* A list of emails the user has previously had. If a user has changed their email
* before, this list will be populated with all of the emails they once had.
*/
previousEmails?: Array<string>;
}
export namespace User {
/**
* An API key.
*/
export interface APIKey {
/**
* The value of the API key.
*/
value: string;
/**
* An optional date which the API key is active until. After this date, the API key
* will no longer be valid.
*/
activeUntil?: string;
}
}
}
export type SubOrganizationRetrieveUsersResponse =
Array<SubOrganizationRetrieveUsersResponse.SubOrganizationRetrieveUsersResponseItem>;
export namespace SubOrganizationRetrieveUsersResponse {
/**
* The user object.
*/
export interface SubOrganizationRetrieveUsersResponseItem {
/**
* A unique ID prefixed with `user_`.
*/
id: string;
/**
* The email of the user.
*/
email: string;
/**
* The name of the user.
*/
name: string;
/**
* A unique ID prefixed with `user_`.
*/
organization: string;
/**
* Indicates if the user has a pending invite.
*/
pendingInvite: boolean;
/**
* The roles given to the user. Roles can be used to restrict access for users.
*/
roles: Array<string>;
/**
* Indicates if the user has a verified email or not.
*/
verifiedEmail: boolean;
/**
* A set of preferences for how a user should receive emails.
*/
emailPreferences?: SubOrganizationsAPI.EmailPreferences;
/**
* The date and time at which the user last logged in.
*/
lastLoginTime?: string;
/**
* The phone number of the user.
*/
phoneNumber?: string;
/**
* A list of emails the user has previously had. If a user has changed their email
* before, this list will be populated with all of the emails they once had.
*/
previousEmails?: Array<string>;
}
}
export interface SubOrganizationUpdateParams {
/**
* The country code of the sub-organization.
*/
countryCode: string;
/**
* The email of the user to be created alongside the sub-organization.
*/
email: string;
/**
* The name of the user to be created alongside the sub-organization.
*/
name: string;
/**
* The name of the sub-organization.
*/
organizationName: string;
/**
* The password of the user to be created alongside the sub-organization.
*/
password: string;
/**
* The phone number of the user to be created alongside the sub-organization.
*/
phoneNumber?: string;
}
export interface SubOrganizationListParams 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 SubOrganizationRetrieveUsersParams {
limit?: number;
/**
* 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;
skip?: number;
}
export declare namespace SubOrganizations {
export {
type EmailPreferences as EmailPreferences,
type SubOrganization as SubOrganization,
type SubOrganizationUpdateResponse as SubOrganizationUpdateResponse,
type SubOrganizationRetrieveUsersResponse as SubOrganizationRetrieveUsersResponse,
type SubOrganizationsSkipLimit as SubOrganizationsSkipLimit,
type SubOrganizationUpdateParams as SubOrganizationUpdateParams,
type SubOrganizationListParams as SubOrganizationListParams,
type SubOrganizationRetrieveUsersParams as SubOrganizationRetrieveUsersParams,
};
}