cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/accounts/members.ts
351lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../resource'; |
| 4 | import * as Core from '../../core'; |
| 5 | import * as Shared from '../shared'; |
| 6 | import { MembersV4PagePaginationArray } from '../shared'; |
| 7 | import { type V4PagePaginationArrayParams } from '../../pagination'; |
| 8 | |
| 9 | export 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 | */ |
| 132 | export type Status = 'member' | 'invited'; |
| 133 | |
| 134 | export interface MemberDeleteResponse { |
| 135 | /** |
| 136 | * Identifier |
| 137 | */ |
| 138 | id: string; |
| 139 | } |
| 140 | |
| 141 | export type MemberCreateParams = |
| 142 | | MemberCreateParams.IAMCreateMemberWithRoles |
| 143 | | MemberCreateParams.IAMCreateMemberWithPolicies; |
| 144 | |
| 145 | export 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: |
| 164 | */ |
| 165 | status?: 'accepted' | 'pending'; |
| 166 | } |
| 167 | |
| 168 | export interface IAMCreateMemberWithPolicies { |
| 169 | /** |
| 170 | * Path param: Account identifier tag. |
| 171 | */ |
| 172 | account_id: string; |
| 173 | |
| 174 | /** |
| 175 | * Body param: The contact email address of the user. |
| 176 | */ |
| 177 | email: string; |
| 178 | |
| 179 | /** |
| 180 | * Body param: Array of policies associated with this member. |
| 181 | */ |
| 182 | policies: Array<IAMCreateMemberWithPolicies.Policy>; |
| 183 | |
| 184 | /** |
| 185 | * Body param: |
| 186 | */ |
| 187 | status?: 'accepted' | 'pending'; |
| 188 | } |
| 189 | |
| 190 | export namespace IAMCreateMemberWithPolicies { |
| 191 | export interface Policy { |
| 192 | /** |
| 193 | * Allow or deny operations against the resources. |
| 194 | */ |
| 195 | access: 'allow' | 'deny'; |
| 196 | |
| 197 | /** |
| 198 | * A set of permission groups that are specified to the policy. |
| 199 | */ |
| 200 | permission_groups: Array<Policy.PermissionGroup>; |
| 201 | |
| 202 | /** |
| 203 | * A list of resource groups that the policy applies to. |
| 204 | */ |
| 205 | resource_groups: Array<Policy.ResourceGroup>; |
| 206 | } |
| 207 | |
| 208 | export namespace Policy { |
| 209 | /** |
| 210 | * A group of permissions. |
| 211 | */ |
| 212 | export interface PermissionGroup { |
| 213 | /** |
| 214 | * Identifier of the group. |
| 215 | */ |
| 216 | id: string; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * A group of scoped resources. |
| 221 | */ |
| 222 | export interface ResourceGroup { |
| 223 | /** |
| 224 | * Identifier of the group. |
| 225 | */ |
| 226 | id: string; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | export type MemberUpdateParams = |
| 233 | | MemberUpdateParams.IAMUpdateMemberWithRoles |
| 234 | | MemberUpdateParams.IAMUpdateMemberWithPolicies; |
| 235 | |
| 236 | export declare namespace MemberUpdateParams { |
| 237 | export interface IAMUpdateMemberWithRoles { |
| 238 | /** |
| 239 | * Path param: Account identifier tag. |
| 240 | */ |
| 241 | account_id: string; |
| 242 | |
| 243 | /** |
| 244 | * Body param: Roles assigned to this member. |
| 245 | */ |
| 246 | roles?: Array<Shared.RoleParam>; |
| 247 | } |
| 248 | |
| 249 | export interface IAMUpdateMemberWithPolicies { |
| 250 | /** |
| 251 | * Path param: Account identifier tag. |
| 252 | */ |
| 253 | account_id: string; |
| 254 | |
| 255 | /** |
| 256 | * Body param: Array of policies associated with this member. |
| 257 | */ |
| 258 | policies: Array<IAMUpdateMemberWithPolicies.Policy>; |
| 259 | } |
| 260 | |
| 261 | export namespace IAMUpdateMemberWithPolicies { |
| 262 | export interface Policy { |
| 263 | /** |
| 264 | * Allow or deny operations against the resources. |
| 265 | */ |
| 266 | access: 'allow' | 'deny'; |
| 267 | |
| 268 | /** |
| 269 | * A set of permission groups that are specified to the policy. |
| 270 | */ |
| 271 | permission_groups: Array<Policy.PermissionGroup>; |
| 272 | |
| 273 | /** |
| 274 | * A list of resource groups that the policy applies to. |
| 275 | */ |
| 276 | resource_groups: Array<Policy.ResourceGroup>; |
| 277 | } |
| 278 | |
| 279 | export namespace Policy { |
| 280 | /** |
| 281 | * A group of permissions. |
| 282 | */ |
| 283 | export interface PermissionGroup { |
| 284 | /** |
| 285 | * Identifier of the group. |
| 286 | */ |
| 287 | id: string; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * A group of scoped resources. |
| 292 | */ |
| 293 | export interface ResourceGroup { |
| 294 | /** |
| 295 | * Identifier of the group. |
| 296 | */ |
| 297 | id: string; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | export interface MemberListParams extends V4PagePaginationArrayParams { |
| 304 | /** |
| 305 | * Path param: Account identifier tag. |
| 306 | */ |
| 307 | account_id: string; |
| 308 | |
| 309 | /** |
| 310 | * Query param: Direction to order results. |
| 311 | */ |
| 312 | direction?: 'asc' | 'desc'; |
| 313 | |
| 314 | /** |
| 315 | * Query param: Field to order results by. |
| 316 | */ |
| 317 | order?: 'user.first_name' | 'user.last_name' | 'user.email' | 'status'; |
| 318 | |
| 319 | /** |
| 320 | * Query param: A member's status in the account. |
| 321 | */ |
| 322 | status?: 'accepted' | 'pending' | 'rejected'; |
| 323 | } |
| 324 | |
| 325 | export interface MemberDeleteParams { |
| 326 | /** |
| 327 | * Account identifier tag. |
| 328 | */ |
| 329 | account_id: string; |
| 330 | } |
| 331 | |
| 332 | export interface MemberGetParams { |
| 333 | /** |
| 334 | * Account identifier tag. |
| 335 | */ |
| 336 | account_id: string; |
| 337 | } |
| 338 | |
| 339 | export declare namespace Members { |
| 340 | export { |
| 341 | type Status as Status, |
| 342 | type MemberDeleteResponse as MemberDeleteResponse, |
| 343 | type MemberCreateParams as MemberCreateParams, |
| 344 | type MemberUpdateParams as MemberUpdateParams, |
| 345 | type MemberListParams as MemberListParams, |
| 346 | type MemberDeleteParams as MemberDeleteParams, |
| 347 | type MemberGetParams as MemberGetParams, |
| 348 | }; |
| 349 | } |
| 350 | |
| 351 | export { MembersV4PagePaginationArray }; |
| 352 | |