cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.0.0-beta.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/accounts/members.ts

382lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../resource';
4import { isRequestOptions } from '../../core';
5import * as Core from '../../core';
6import * as Shared from '../shared';
7import { MembersV4PagePaginationArray } from '../shared';
8import { type V4PagePaginationArrayParams } from '../../pagination';
9
10export class Members extends APIResource {
11 /**
12 * Add a user to the list of members for this account.
13 *
14 * @example
15 * ```ts
16 * const member = await client.accounts.members.create({
17 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
18 * email: 'user@example.com',
19 * roles: ['3536bcfad5faccb999b47003c79917fb'],
20 * });
21 * ```
22 */
23 create(params: MemberCreateParams, options?: Core.RequestOptions): Core.APIPromise<Shared.Member> {
24 const { account_id = this._client.accountId, ...body } = params;
25 return (
26 this._client.post(`/accounts/${account_id}/members`, { body, ...options }) as Core.APIPromise<{
27 result: Shared.Member;
28 }>
29 )._thenUnwrap((obj) => obj.result);
30 }
31
32 /**
33 * Modify an account member.
34 *
35 * @example
36 * ```ts
37 * const member = await client.accounts.members.update(
38 * '4536bcfad5faccb111b47003c79917fa',
39 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
40 * );
41 * ```
42 */
43 update(
44 memberId: string,
45 params: MemberUpdateParams,
46 options?: Core.RequestOptions,
47 ): Core.APIPromise<Shared.Member> {
48 const { account_id = this._client.accountId, ...body } = params;
49 return (
50 this._client.put(`/accounts/${account_id}/members/${memberId}`, {
51 body,
52 ...options,
53 }) as Core.APIPromise<{ result: Shared.Member }>
54 )._thenUnwrap((obj) => obj.result);
55 }
56
57 /**
58 * List all members of an account.
59 *
60 * @example
61 * ```ts
62 * // Automatically fetches more pages as needed.
63 * for await (const member of client.accounts.members.list({
64 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
65 * })) {
66 * // ...
67 * }
68 * ```
69 */
70 list(
71 params?: MemberListParams,
72 options?: Core.RequestOptions,
73 ): Core.PagePromise<MembersV4PagePaginationArray, Shared.Member>;
74 list(options?: Core.RequestOptions): Core.PagePromise<MembersV4PagePaginationArray, Shared.Member>;
75 list(
76 params: MemberListParams | Core.RequestOptions = {},
77 options?: Core.RequestOptions,
78 ): Core.PagePromise<MembersV4PagePaginationArray, Shared.Member> {
79 if (isRequestOptions(params)) {
80 return this.list({}, params);
81 }
82 const { account_id = this._client.accountId, ...query } = params;
83 return this._client.getAPIList(`/accounts/${account_id}/members`, MembersV4PagePaginationArray, {
84 query,
85 ...options,
86 });
87 }
88
89 /**
90 * Remove a member from an account.
91 *
92 * @example
93 * ```ts
94 * const member = await client.accounts.members.delete(
95 * '4536bcfad5faccb111b47003c79917fa',
96 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
97 * );
98 * ```
99 */
100 delete(
101 memberId: string,
102 params?: MemberDeleteParams,
103 options?: Core.RequestOptions,
104 ): Core.APIPromise<MemberDeleteResponse | null>;
105 delete(memberId: string, options?: Core.RequestOptions): Core.APIPromise<MemberDeleteResponse | null>;
106 delete(
107 memberId: string,
108 params: MemberDeleteParams | Core.RequestOptions = {},
109 options?: Core.RequestOptions,
110 ): Core.APIPromise<MemberDeleteResponse | null> {
111 if (isRequestOptions(params)) {
112 return this.delete(memberId, {}, params);
113 }
114 const { account_id = this._client.accountId } = params;
115 return (
116 this._client.delete(`/accounts/${account_id}/members/${memberId}`, options) as Core.APIPromise<{
117 result: MemberDeleteResponse | null;
118 }>
119 )._thenUnwrap((obj) => obj.result);
120 }
121
122 /**
123 * Get information about a specific member of an account.
124 *
125 * @example
126 * ```ts
127 * const member = await client.accounts.members.get(
128 * '4536bcfad5faccb111b47003c79917fa',
129 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
130 * );
131 * ```
132 */
133 get(
134 memberId: string,
135 params?: MemberGetParams,
136 options?: Core.RequestOptions,
137 ): Core.APIPromise<Shared.Member>;
138 get(memberId: string, options?: Core.RequestOptions): Core.APIPromise<Shared.Member>;
139 get(
140 memberId: string,
141 params: MemberGetParams | Core.RequestOptions = {},
142 options?: Core.RequestOptions,
143 ): Core.APIPromise<Shared.Member> {
144 if (isRequestOptions(params)) {
145 return this.get(memberId, {}, params);
146 }
147 const { account_id = this._client.accountId } = params;
148 return (
149 this._client.get(`/accounts/${account_id}/members/${memberId}`, options) as Core.APIPromise<{
150 result: Shared.Member;
151 }>
152 )._thenUnwrap((obj) => obj.result);
153 }
154}
155
156/**
157 * Whether the user is a member of the organization or has an invitation pending.
158 */
159export type Status = 'member' | 'invited';
160
161export interface MemberDeleteResponse {
162 /**
163 * Identifier
164 */
165 id: string;
166}
167
168export type MemberCreateParams =
169 | MemberCreateParams.IAMCreateMemberWithRoles
170 | MemberCreateParams.IAMCreateMemberWithPolicies;
171
172export declare namespace MemberCreateParams {
173 export interface IAMCreateMemberWithRoles {
174 /**
175 * Path param: Account identifier tag.
176 */
177 account_id?: string;
178
179 /**
180 * Body param: The contact email address of the user.
181 */
182 email: string;
183
184 /**
185 * Body param: Array of roles associated with this member.
186 */
187 roles: Array<string>;
188
189 /**
190 * Body param: Status of the member invitation. If not provided during creation,
191 * defaults to 'pending'. Changing from 'accepted' back to 'pending' will trigger a
192 * replacement of the member resource in Terraform.
193 */
194 status?: 'accepted' | 'pending';
195 }
196
197 export interface IAMCreateMemberWithPolicies {
198 /**
199 * Path param: Account identifier tag.
200 */
201 account_id?: string;
202
203 /**
204 * Body param: The contact email address of the user.
205 */
206 email: string;
207
208 /**
209 * Body param: Array of policies associated with this member.
210 */
211 policies: Array<IAMCreateMemberWithPolicies.Policy>;
212
213 /**
214 * Body param: Status of the member invitation. If not provided during creation,
215 * defaults to 'pending'. Changing from 'accepted' back to 'pending' will trigger a
216 * replacement of the member resource in Terraform.
217 */
218 status?: 'accepted' | 'pending';
219 }
220
221 export namespace IAMCreateMemberWithPolicies {
222 export interface Policy {
223 /**
224 * Allow or deny operations against the resources.
225 */
226 access: 'allow' | 'deny';
227
228 /**
229 * A set of permission groups that are specified to the policy.
230 */
231 permission_groups: Array<Policy.PermissionGroup>;
232
233 /**
234 * A list of resource groups that the policy applies to.
235 */
236 resource_groups: Array<Policy.ResourceGroup>;
237 }
238
239 export namespace Policy {
240 /**
241 * A group of permissions.
242 */
243 export interface PermissionGroup {
244 /**
245 * Identifier of the group.
246 */
247 id: string;
248 }
249
250 /**
251 * A group of scoped resources.
252 */
253 export interface ResourceGroup {
254 /**
255 * Identifier of the group.
256 */
257 id: string;
258 }
259 }
260 }
261}
262
263export type MemberUpdateParams =
264 | MemberUpdateParams.IAMUpdateMemberWithRoles
265 | MemberUpdateParams.IAMUpdateMemberWithPolicies;
266
267export declare namespace MemberUpdateParams {
268 export interface IAMUpdateMemberWithRoles {
269 /**
270 * Path param: Account identifier tag.
271 */
272 account_id?: string;
273
274 /**
275 * Body param: Roles assigned to this member.
276 */
277 roles?: Array<Shared.RoleParam>;
278 }
279
280 export interface IAMUpdateMemberWithPolicies {
281 /**
282 * Path param: Account identifier tag.
283 */
284 account_id?: string;
285
286 /**
287 * Body param: Array of policies associated with this member.
288 */
289 policies: Array<IAMUpdateMemberWithPolicies.Policy>;
290 }
291
292 export namespace IAMUpdateMemberWithPolicies {
293 export interface Policy {
294 /**
295 * Allow or deny operations against the resources.
296 */
297 access: 'allow' | 'deny';
298
299 /**
300 * A set of permission groups that are specified to the policy.
301 */
302 permission_groups: Array<Policy.PermissionGroup>;
303
304 /**
305 * A list of resource groups that the policy applies to.
306 */
307 resource_groups: Array<Policy.ResourceGroup>;
308 }
309
310 export namespace Policy {
311 /**
312 * A group of permissions.
313 */
314 export interface PermissionGroup {
315 /**
316 * Identifier of the group.
317 */
318 id: string;
319 }
320
321 /**
322 * A group of scoped resources.
323 */
324 export interface ResourceGroup {
325 /**
326 * Identifier of the group.
327 */
328 id: string;
329 }
330 }
331 }
332}
333
334export interface MemberListParams extends V4PagePaginationArrayParams {
335 /**
336 * Path param: Account identifier tag.
337 */
338 account_id?: string;
339
340 /**
341 * Query param: Direction to order results.
342 */
343 direction?: 'asc' | 'desc';
344
345 /**
346 * Query param: Field to order results by.
347 */
348 order?: 'user.first_name' | 'user.last_name' | 'user.email' | 'status';
349
350 /**
351 * Query param: A member's status in the account.
352 */
353 status?: 'accepted' | 'pending' | 'rejected';
354}
355
356export interface MemberDeleteParams {
357 /**
358 * Account identifier tag.
359 */
360 account_id?: string;
361}
362
363export interface MemberGetParams {
364 /**
365 * Account identifier tag.
366 */
367 account_id?: string;
368}
369
370export declare namespace Members {
371 export {
372 type Status as Status,
373 type MemberDeleteResponse as MemberDeleteResponse,
374 type MemberCreateParams as MemberCreateParams,
375 type MemberUpdateParams as MemberUpdateParams,
376 type MemberListParams as MemberListParams,
377 type MemberDeleteParams as MemberDeleteParams,
378 type MemberGetParams as MemberGetParams,
379 };
380}
381
382export { MembersV4PagePaginationArray };
383