cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/accounts.ts

395lines · 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 * Parent container details
180 */
181 managed_by?: Account.ManagedBy;
182
183 /**
184 * Account settings
185 */
186 settings?: Account.Settings;
187}
188
189export namespace Account {
190 /**
191 * Parent container details
192 */
193 export interface ManagedBy {
194 /**
195 * ID of the parent Organization, if one exists
196 */
197 parent_org_id?: string;
198
199 /**
200 * Name of the parent Organization, if one exists
201 */
202 parent_org_name?: string;
203 }
204
205 /**
206 * Account settings
207 */
208 export interface Settings {
209 /**
210 * Sets an abuse contact email to notify for abuse reports.
211 */
212 abuse_contact_email?: string;
213
214 /**
215 * Indicates whether membership in this account requires that Two-Factor
216 * Authentication is enabled
217 */
218 enforce_twofactor?: boolean;
219 }
220}
221
222export interface AccountDeleteResponse {
223 /**
224 * Identifier
225 */
226 id: string;
227}
228
229export interface AccountCreateParams {
230 /**
231 * Account name
232 */
233 name: string;
234
235 type?: 'standard' | 'enterprise';
236
237 /**
238 * information related to the tenant unit, and optionally, an id of the unit to
239 * create the account on. see
240 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
241 */
242 unit?: AccountCreateParams.Unit;
243}
244
245export namespace AccountCreateParams {
246 /**
247 * information related to the tenant unit, and optionally, an id of the unit to
248 * create the account on. see
249 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
250 */
251 export interface Unit {
252 /**
253 * Tenant unit ID
254 */
255 id?: string;
256 }
257}
258
259export interface AccountUpdateParams {
260 /**
261 * Path param: Account identifier tag.
262 */
263 account_id: string;
264
265 /**
266 * Body param: Identifier
267 */
268 id: string;
269
270 /**
271 * Body param: Account name
272 */
273 name: string;
274
275 /**
276 * Body param
277 */
278 type: 'standard' | 'enterprise';
279
280 /**
281 * Body param: Parent container details
282 */
283 managed_by?: AccountUpdateParams.ManagedBy;
284
285 /**
286 * Body param: Account settings
287 */
288 settings?: AccountUpdateParams.Settings;
289}
290
291export namespace AccountUpdateParams {
292 /**
293 * Parent container details
294 */
295 export interface ManagedBy {}
296
297 /**
298 * Account settings
299 */
300 export interface Settings {
301 /**
302 * Sets an abuse contact email to notify for abuse reports.
303 */
304 abuse_contact_email?: string;
305
306 /**
307 * Indicates whether membership in this account requires that Two-Factor
308 * Authentication is enabled
309 */
310 enforce_twofactor?: boolean;
311 }
312}
313
314export interface AccountListParams extends V4PagePaginationArrayParams {
315 /**
316 * Direction to order results.
317 */
318 direction?: 'asc' | 'desc';
319
320 /**
321 * Name of the account.
322 */
323 name?: string;
324}
325
326export interface AccountDeleteParams {
327 /**
328 * The account ID of the account to be deleted
329 */
330 account_id: string;
331}
332
333export interface AccountGetParams {
334 /**
335 * Account identifier tag.
336 */
337 account_id: string;
338}
339
340Accounts.AccountsV4PagePaginationArray = AccountsV4PagePaginationArray;
341Accounts.Members = Members;
342Accounts.Roles = Roles;
343Accounts.Subscriptions = Subscriptions;
344Accounts.Tokens = Tokens;
345Accounts.Logs = Logs;
346
347export declare namespace Accounts {
348 export {
349 type Account as Account,
350 type AccountDeleteResponse as AccountDeleteResponse,
351 AccountsV4PagePaginationArray as AccountsV4PagePaginationArray,
352 type AccountCreateParams as AccountCreateParams,
353 type AccountUpdateParams as AccountUpdateParams,
354 type AccountListParams as AccountListParams,
355 type AccountDeleteParams as AccountDeleteParams,
356 type AccountGetParams as AccountGetParams,
357 };
358
359 export {
360 Members as Members,
361 type Status as Status,
362 type MemberDeleteResponse as MemberDeleteResponse,
363 type MemberCreateParams as MemberCreateParams,
364 type MemberUpdateParams as MemberUpdateParams,
365 type MemberListParams as MemberListParams,
366 type MemberDeleteParams as MemberDeleteParams,
367 type MemberGetParams as MemberGetParams,
368 };
369
370 export { Roles as Roles, type RoleListParams as RoleListParams, type RoleGetParams as RoleGetParams };
371
372 export {
373 Subscriptions as Subscriptions,
374 type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
375 type SubscriptionCreateParams as SubscriptionCreateParams,
376 type SubscriptionUpdateParams as SubscriptionUpdateParams,
377 type SubscriptionDeleteParams as SubscriptionDeleteParams,
378 type SubscriptionGetParams as SubscriptionGetParams,
379 };
380
381 export {
382 Tokens as Tokens,
383 type TokenCreateResponse as TokenCreateResponse,
384 type TokenDeleteResponse as TokenDeleteResponse,
385 type TokenVerifyResponse as TokenVerifyResponse,
386 type TokenCreateParams as TokenCreateParams,
387 type TokenUpdateParams as TokenUpdateParams,
388 type TokenListParams as TokenListParams,
389 type TokenDeleteParams as TokenDeleteParams,
390 type TokenGetParams as TokenGetParams,
391 type TokenVerifyParams as TokenVerifyParams,
392 };
393
394 export { Logs as Logs };
395}
396