cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/members.ts

355lines · modecode

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