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/roles.ts

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