cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/accounts.ts

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