cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.4.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/accounts.ts

362lines · 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 * type: 'standard',
60 * });
61 * ```
62 */
63 create(body: AccountCreateParams, options?: Core.RequestOptions): Core.APIPromise<Account> {
64 return (
65 this._client.post('/accounts', { body, ...options }) as Core.APIPromise<{ result: Account }>
66 )._thenUnwrap((obj) => obj.result);
67 }
68
69 /**
70 * Update an existing account.
71 *
72 * @example
73 * ```ts
74 * const account = await client.accounts.update({
75 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
76 * id: '023e105f4ecef8ad9ca31a8372d0c353',
77 * name: 'Demo Account',
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 /**
172 * Timestamp for the creation of the account
173 */
174 created_on?: string;
175
176 /**
177 * Account settings
178 */
179 settings?: Account.Settings;
180}
181
182export namespace Account {
183 /**
184 * Account settings
185 */
186 export interface Settings {
187 /**
188 * Sets an abuse contact email to notify for abuse reports.
189 */
190 abuse_contact_email?: string;
191
192 /**
193 * Indicates whether membership in this account requires that Two-Factor
194 * Authentication is enabled
195 */
196 enforce_twofactor?: boolean;
197 }
198}
199
200export interface AccountDeleteResponse {
201 /**
202 * Identifier
203 */
204 id: string;
205}
206
207export interface AccountCreateParams {
208 /**
209 * Account name
210 */
211 name: string;
212
213 /**
214 * the type of account being created. For self-serve customers, use standard. for
215 * enterprise customers, use enterprise.
216 */
217 type: 'standard' | 'enterprise';
218
219 /**
220 * information related to the tenant unit, and optionally, an id of the unit to
221 * create the account on. see
222 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
223 */
224 unit?: AccountCreateParams.Unit;
225}
226
227export namespace AccountCreateParams {
228 /**
229 * information related to the tenant unit, and optionally, an id of the unit to
230 * create the account on. see
231 * https://developers.cloudflare.com/tenant/how-to/manage-accounts/
232 */
233 export interface Unit {
234 /**
235 * Tenant unit ID
236 */
237 id?: string;
238 }
239}
240
241export interface AccountUpdateParams {
242 /**
243 * Path param: Account identifier tag.
244 */
245 account_id: string;
246
247 /**
248 * Body param: Identifier
249 */
250 id: string;
251
252 /**
253 * Body param: Account name
254 */
255 name: string;
256
257 /**
258 * Body param: Account settings
259 */
260 settings?: AccountUpdateParams.Settings;
261}
262
263export namespace AccountUpdateParams {
264 /**
265 * Account settings
266 */
267 export interface Settings {
268 /**
269 * Sets an abuse contact email to notify for abuse reports.
270 */
271 abuse_contact_email?: string;
272
273 /**
274 * Indicates whether membership in this account requires that Two-Factor
275 * Authentication is enabled
276 */
277 enforce_twofactor?: boolean;
278 }
279}
280
281export interface AccountListParams extends V4PagePaginationArrayParams {
282 /**
283 * Direction to order results.
284 */
285 direction?: 'asc' | 'desc';
286
287 /**
288 * Name of the account.
289 */
290 name?: string;
291}
292
293export interface AccountDeleteParams {
294 /**
295 * The account ID of the account to be deleted
296 */
297 account_id: string;
298}
299
300export interface AccountGetParams {
301 /**
302 * Account identifier tag.
303 */
304 account_id: string;
305}
306
307Accounts.AccountsV4PagePaginationArray = AccountsV4PagePaginationArray;
308Accounts.Members = Members;
309Accounts.Roles = Roles;
310Accounts.Subscriptions = Subscriptions;
311Accounts.Tokens = Tokens;
312Accounts.Logs = Logs;
313
314export declare namespace Accounts {
315 export {
316 type Account as Account,
317 type AccountDeleteResponse as AccountDeleteResponse,
318 AccountsV4PagePaginationArray as AccountsV4PagePaginationArray,
319 type AccountCreateParams as AccountCreateParams,
320 type AccountUpdateParams as AccountUpdateParams,
321 type AccountListParams as AccountListParams,
322 type AccountDeleteParams as AccountDeleteParams,
323 type AccountGetParams as AccountGetParams,
324 };
325
326 export {
327 Members as Members,
328 type Status as Status,
329 type MemberDeleteResponse as MemberDeleteResponse,
330 type MemberCreateParams as MemberCreateParams,
331 type MemberUpdateParams as MemberUpdateParams,
332 type MemberListParams as MemberListParams,
333 type MemberDeleteParams as MemberDeleteParams,
334 type MemberGetParams as MemberGetParams,
335 };
336
337 export { Roles as Roles, type RoleListParams as RoleListParams, type RoleGetParams as RoleGetParams };
338
339 export {
340 Subscriptions as Subscriptions,
341 type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
342 type SubscriptionCreateParams as SubscriptionCreateParams,
343 type SubscriptionUpdateParams as SubscriptionUpdateParams,
344 type SubscriptionDeleteParams as SubscriptionDeleteParams,
345 type SubscriptionGetParams as SubscriptionGetParams,
346 };
347
348 export {
349 Tokens as Tokens,
350 type TokenCreateResponse as TokenCreateResponse,
351 type TokenDeleteResponse as TokenDeleteResponse,
352 type TokenVerifyResponse as TokenVerifyResponse,
353 type TokenCreateParams as TokenCreateParams,
354 type TokenUpdateParams as TokenUpdateParams,
355 type TokenListParams as TokenListParams,
356 type TokenDeleteParams as TokenDeleteParams,
357 type TokenGetParams as TokenGetParams,
358 type TokenVerifyParams as TokenVerifyParams,
359 };
360
361 export { Logs as Logs };
362}
363