cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v5.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/accounts.ts

365lines · 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 MembersAPI from './members';
7import {
8 MemberCreateParams,
9 MemberDeleteParams,
10 MemberDeleteResponse,
11 MemberGetParams,
12 MemberListParams,
13 MemberUpdateParams,
14 Members,
15 Status,
16} from './members';
17import * as RolesAPI from './roles';
18import { RoleGetParams, RoleListParams, Roles } from './roles';
19import * as SubscriptionsAPI from './subscriptions';
20import {
21 SubscriptionCreateParams,
22 SubscriptionDeleteParams,
23 SubscriptionDeleteResponse,
24 SubscriptionGetParams,
25 SubscriptionUpdateParams,
26 Subscriptions,
27} from './subscriptions';
28import * as LogsAPI from './logs/logs';
29import { Logs } from './logs/logs';
30import * as TokensAPI from './tokens/tokens';
31import {
32 TokenCreateParams,
33 TokenCreateResponse,
34 TokenDeleteParams,
35 TokenDeleteResponse,
36 TokenGetParams,
37 TokenListParams,
38 TokenUpdateParams,
39 TokenVerifyParams,
40 TokenVerifyResponse,
41 Tokens,
42} from './tokens/tokens';
43import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
44
45export class Accounts extends APIResource {
46 members: MembersAPI.Members = new MembersAPI.Members(this._client);
47 roles: RolesAPI.Roles = new RolesAPI.Roles(this._client);
48 subscriptions: SubscriptionsAPI.Subscriptions = new SubscriptionsAPI.Subscriptions(this._client);
49 tokens: TokensAPI.Tokens = new TokensAPI.Tokens(this._client);
50 logs: LogsAPI.Logs = new LogsAPI.Logs(this._client);
51
52 /**
53 * Create an account (only available for tenant admins at this time)
54 *
55 * @example
56 * ```ts
57 * const account = await client.accounts.create({
58 * name: 'name',
59 * });
60 * ```
61 */
62 create(body: AccountCreateParams, options?: Core.RequestOptions): Core.APIPromise<Account> {
63 return (
64 this._client.post('/accounts', { body, ...options }) as Core.APIPromise<{ result: Account }>
65 )._thenUnwrap((obj) => obj.result);
66 }
67
68 /**
69 * Update an existing account.
70 *
71 * @example
72 * ```ts
73 * const account = await client.accounts.update({
74 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
75 * id: '023e105f4ecef8ad9ca31a8372d0c353',
76 * name: 'Demo Account',
77 * type: 'standard',
78 * });
79 * ```
80 */
81 update(params: AccountUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Account> {
82 const { account_id, ...body } = params;
83 return (
84 this._client.put(`/accounts/${account_id}`, { body, ...options }) as Core.APIPromise<{
85 result: Account;
86 }>
87 )._thenUnwrap((obj) => obj.result);
88 }
89
90 /**
91 * List all accounts you have ownership or verified access to.
92 *
93 * @example
94 * ```ts
95 * // Automatically fetches more pages as needed.
96 * for await (const account of client.accounts.list()) {
97 * // ...
98 * }
99 * ```
100 */
101 list(
102 query?: AccountListParams,
103 options?: Core.RequestOptions,
104 ): Core.PagePromise<AccountsV4PagePaginationArray, Account>;
105 list(options?: Core.RequestOptions): Core.PagePromise<AccountsV4PagePaginationArray, Account>;
106 list(
107 query: AccountListParams | Core.RequestOptions = {},
108 options?: Core.RequestOptions,
109 ): Core.PagePromise<AccountsV4PagePaginationArray, Account> {
110 if (isRequestOptions(query)) {
111 return this.list({}, query);
112 }
113 return this._client.getAPIList('/accounts', AccountsV4PagePaginationArray, { query, ...options });
114 }
115
116 /**
117 * Delete a specific account (only available for tenant admins at this time). This
118 * is a permanent operation that will delete any zones or other resources under the
119 * account
120 *
121 * @example
122 * ```ts
123 * const account = await client.accounts.delete({
124 * account_id: 'account_id',
125 * });
126 * ```
127 */
128 delete(
129 params: AccountDeleteParams,
130 options?: Core.RequestOptions,
131 ): Core.APIPromise<AccountDeleteResponse | null> {
132 const { account_id } = params;
133 return (
134 this._client.delete(`/accounts/${account_id}`, options) as Core.APIPromise<{
135 result: AccountDeleteResponse | null;
136 }>
137 )._thenUnwrap((obj) => obj.result);
138 }
139
140 /**
141 * Get information about a specific account that you are a member of.
142 *
143 * @example
144 * ```ts
145 * const account = await client.accounts.get({
146 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
147 * });
148 * ```
149 */
150 get(params: AccountGetParams, options?: Core.RequestOptions): Core.APIPromise<Account> {
151 const { account_id } = params;
152 return (
153 this._client.get(`/accounts/${account_id}`, options) as Core.APIPromise<{ result: Account }>
154 )._thenUnwrap((obj) => obj.result);
155 }
156}
157
158export class AccountsV4PagePaginationArray extends V4PagePaginationArray<Account> {}
159
160export interface Account {
161 /**
162 * Identifier
163 */
164 id: string;
165
166 /**
167 * Account name
168 */
169 name: string;
170
171 type: 'standard' | 'enterprise';
172
173 /**
174 * Timestamp for the creation of the account
175 */
176 created_on?: string;
177
178 /**
179 * Account settings
180 */
181 settings?: Account.Settings;
182}
183
184export namespace Account {
185 /**
186 * Account settings
187 */
188 export interface Settings {
189 /**
190 * Sets an abuse contact email to notify for abuse reports.
191 */
192 abuse_contact_email?: string;
193
194 /**
195 * Indicates whether membership in this account requires that Two-Factor
196 * Authentication is enabled
197 */
198 enforce_twofactor?: boolean;
199 }
200}
201
202export interface AccountDeleteResponse {
203 /**
204 * Identifier
205 */
206 id: string;
207}
208
209export interface AccountCreateParams {
210 /**
211 * Account name
212 */
213 name: string;
214
215 type?: 'standard' | 'enterprise';
216
217 /**
218 * information related to the tenant unit, and optionally, an id of the unit to
219 * create the account on. see
220 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
221 */
222 unit?: AccountCreateParams.Unit;
223}
224
225export namespace AccountCreateParams {
226 /**
227 * information related to the tenant unit, and optionally, an id of the unit to
228 * create the account on. see
229 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
230 */
231 export interface Unit {
232 /**
233 * Tenant unit ID
234 */
235 id?: string;
236 }
237}
238
239export interface AccountUpdateParams {
240 /**
241 * Path param: Account identifier tag.
242 */
243 account_id: string;
244
245 /**
246 * Body param: Identifier
247 */
248 id: string;
249
250 /**
251 * Body param: Account name
252 */
253 name: string;
254
255 /**
256 * Body param:
257 */
258 type: 'standard' | 'enterprise';
259
260 /**
261 * Body param: Account settings
262 */
263 settings?: AccountUpdateParams.Settings;
264}
265
266export namespace AccountUpdateParams {
267 /**
268 * Account settings
269 */
270 export interface Settings {
271 /**
272 * Sets an abuse contact email to notify for abuse reports.
273 */
274 abuse_contact_email?: string;
275
276 /**
277 * Indicates whether membership in this account requires that Two-Factor
278 * Authentication is enabled
279 */
280 enforce_twofactor?: boolean;
281 }
282}
283
284export interface AccountListParams extends V4PagePaginationArrayParams {
285 /**
286 * Direction to order results.
287 */
288 direction?: 'asc' | 'desc';
289
290 /**
291 * Name of the account.
292 */
293 name?: string;
294}
295
296export interface AccountDeleteParams {
297 /**
298 * The account ID of the account to be deleted
299 */
300 account_id: string;
301}
302
303export interface AccountGetParams {
304 /**
305 * Account identifier tag.
306 */
307 account_id: string;
308}
309
310Accounts.AccountsV4PagePaginationArray = AccountsV4PagePaginationArray;
311Accounts.Members = Members;
312Accounts.Roles = Roles;
313Accounts.Subscriptions = Subscriptions;
314Accounts.Tokens = Tokens;
315Accounts.Logs = Logs;
316
317export declare namespace Accounts {
318 export {
319 type Account as Account,
320 type AccountDeleteResponse as AccountDeleteResponse,
321 AccountsV4PagePaginationArray as AccountsV4PagePaginationArray,
322 type AccountCreateParams as AccountCreateParams,
323 type AccountUpdateParams as AccountUpdateParams,
324 type AccountListParams as AccountListParams,
325 type AccountDeleteParams as AccountDeleteParams,
326 type AccountGetParams as AccountGetParams,
327 };
328
329 export {
330 Members as Members,
331 type Status as Status,
332 type MemberDeleteResponse as MemberDeleteResponse,
333 type MemberCreateParams as MemberCreateParams,
334 type MemberUpdateParams as MemberUpdateParams,
335 type MemberListParams as MemberListParams,
336 type MemberDeleteParams as MemberDeleteParams,
337 type MemberGetParams as MemberGetParams,
338 };
339
340 export { Roles as Roles, type RoleListParams as RoleListParams, type RoleGetParams as RoleGetParams };
341
342 export {
343 Subscriptions as Subscriptions,
344 type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
345 type SubscriptionCreateParams as SubscriptionCreateParams,
346 type SubscriptionUpdateParams as SubscriptionUpdateParams,
347 type SubscriptionDeleteParams as SubscriptionDeleteParams,
348 type SubscriptionGetParams as SubscriptionGetParams,
349 };
350
351 export {
352 Tokens as Tokens,
353 type TokenCreateResponse as TokenCreateResponse,
354 type TokenDeleteResponse as TokenDeleteResponse,
355 type TokenVerifyResponse as TokenVerifyResponse,
356 type TokenCreateParams as TokenCreateParams,
357 type TokenUpdateParams as TokenUpdateParams,
358 type TokenListParams as TokenListParams,
359 type TokenDeleteParams as TokenDeleteParams,
360 type TokenGetParams as TokenGetParams,
361 type TokenVerifyParams as TokenVerifyParams,
362 };
363
364 export { Logs as Logs };
365}