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