cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/roles.ts

81lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../core/resource';
4import * as Shared from '../shared';
5import { RolesV4PagePaginationArray } from '../shared';
6import { APIPromise } from '../../core/api-promise';
7import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../core/pagination';
8import { RequestOptions } from '../../internal/request-options';
9import { path } from '../../internal/utils/path';
10
11export class BaseRoles extends APIResource {
12 static override readonly _key: readonly ['accounts', 'roles'] = Object.freeze([
13 'accounts',
14 'roles',
15 ] as const);
16
17 /**
18 * Get all available roles for an account.
19 *
20 * @example
21 * ```ts
22 * // Automatically fetches more pages as needed.
23 * for await (const role of client.accounts.roles.list({
24 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
25 * })) {
26 * // ...
27 * }
28 * ```
29 */
30 list(
31 params: RoleListParams,
32 options?: RequestOptions,
33 ): PagePromise<RolesV4PagePaginationArray, Shared.Role> {
34 const { account_id, ...query } = params;
35 return this._client.getAPIList(path`/accounts/${account_id}/roles`, V4PagePaginationArray<Shared.Role>, {
36 query,
37 ...options,
38 });
39 }
40
41 /**
42 * Get information about a specific role for an account.
43 *
44 * @example
45 * ```ts
46 * const role = await client.accounts.roles.get(
47 * '3536bcfad5faccb999b47003c79917fb',
48 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
49 * );
50 * ```
51 */
52 get(roleID: string, params: RoleGetParams, options?: RequestOptions): APIPromise<Shared.Role> {
53 const { account_id } = params;
54 return (
55 this._client.get(path`/accounts/${account_id}/roles/${roleID}`, options) as APIPromise<{
56 result: Shared.Role;
57 }>
58 )._thenUnwrap((obj) => obj.result);
59 }
60}
61export class Roles extends BaseRoles {}
62
63export interface RoleListParams extends V4PagePaginationArrayParams {
64 /**
65 * Path param: Account identifier tag.
66 */
67 account_id: string;
68}
69
70export interface RoleGetParams {
71 /**
72 * Account identifier tag.
73 */
74 account_id: string;
75}
76
77export declare namespace Roles {
78 export { type RoleListParams as RoleListParams, type RoleGetParams as RoleGetParams };
79}
80
81export { type RolesV4PagePaginationArray };
82