cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/accounts/roles.ts
73lines · 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 { RolesV4PagePaginationArray } from '../shared'; |
| 7 | import { type V4PagePaginationArrayParams } from '../../pagination'; |
| 8 | |
| 9 | export class Roles extends APIResource { |
| 10 | /** |
| 11 | * Get all available roles for an account. |
| 12 | * |
| 13 | * @example |
| 14 | * ```ts |
| 15 | * // Automatically fetches more pages as needed. |
| 16 | * for await (const role of client.accounts.roles.list({ |
| 17 | * account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 18 | * })) { |
| 19 | * // ... |
| 20 | * } |
| 21 | * ``` |
| 22 | */ |
| 23 | list( |
| 24 | params: RoleListParams, |
| 25 | options?: Core.RequestOptions, |
| 26 | ): Core.PagePromise<RolesV4PagePaginationArray, Shared.Role> { |
| 27 | const { account_id, ...query } = params; |
| 28 | return this._client.getAPIList(`/accounts/${account_id}/roles`, RolesV4PagePaginationArray, { |
| 29 | query, |
| 30 | ...options, |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get information about a specific role for an account. |
| 36 | * |
| 37 | * @example |
| 38 | * ```ts |
| 39 | * const role = await client.accounts.roles.get( |
| 40 | * '3536bcfad5faccb999b47003c79917fb', |
| 41 | * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, |
| 42 | * ); |
| 43 | * ``` |
| 44 | */ |
| 45 | get(roleId: string, params: RoleGetParams, options?: Core.RequestOptions): Core.APIPromise<Shared.Role> { |
| 46 | const { account_id } = params; |
| 47 | return ( |
| 48 | this._client.get(`/accounts/${account_id}/roles/${roleId}`, options) as Core.APIPromise<{ |
| 49 | result: Shared.Role; |
| 50 | }> |
| 51 | )._thenUnwrap((obj) => obj.result); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export interface RoleListParams extends V4PagePaginationArrayParams { |
| 56 | /** |
| 57 | * Path param: Account identifier tag. |
| 58 | */ |
| 59 | account_id: string; |
| 60 | } |
| 61 | |
| 62 | export interface RoleGetParams { |
| 63 | /** |
| 64 | * Account identifier tag. |
| 65 | */ |
| 66 | account_id: string; |
| 67 | } |
| 68 | |
| 69 | export declare namespace Roles { |
| 70 | export { type RoleListParams as RoleListParams, type RoleGetParams as RoleGetParams }; |
| 71 | } |
| 72 | |
| 73 | export { RolesV4PagePaginationArray }; |
| 74 | |