UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

155 lines • 5.81 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../core/resource.mjs"; import * as PermissionGroupsAPI from "./permission-groups.mjs"; import { BasePermissionGroups, PermissionGroups, } from "./permission-groups.mjs"; import * as ValueAPI from "./value.mjs"; import { BaseValue, Value } from "./value.mjs"; import { V4PagePaginationArray, } from "../../../core/pagination.mjs"; import { path } from "../../../internal/utils/path.mjs"; export var BaseTokens = /* @__PURE__ */ (() => { class BaseTokens extends APIResource { /** * Create a new Account Owned API token. * * @example * ```ts * const token = await client.accounts.tokens.create({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * name: 'readonly token', * policies: [ * { * effect: 'allow', * permission_groups: [ * { id: 'c8fed203ed3043cba015a93ad1616f1f' }, * { id: '82e64a83756745bbbb1c9c2701bf816b' }, * ], * resources: { * 'com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43': * '*', * }, * }, * ], * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/tokens`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Update an existing token. * * @example * ```ts * const token = await client.accounts.tokens.update( * 'ed17574386854bf78a67040be0a770b0', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * name: 'readonly token', * policies: [ * { * effect: 'allow', * permission_groups: [ * { id: 'c8fed203ed3043cba015a93ad1616f1f' }, * { id: '82e64a83756745bbbb1c9c2701bf816b' }, * ], * resources: { * 'com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43': * '*', * }, * }, * ], * }, * ); * ``` */ update(tokenID, params, options) { const { account_id, ...body } = params; return this._client.put(path `/accounts/${account_id}/tokens/${tokenID}`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * List Account Owned API tokens created for this account. Callers with * `com.cloudflare.api.account.token.list_self` permission only receive tokens they * created. Results include active, disabled, and recently-expired tokens when * `include_expired` is set to true. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const token of client.accounts.tokens.list({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * })) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList(path `/accounts/${account_id}/tokens`, (V4PagePaginationArray), { query, ...options }); } /** * Destroy an Account Owned API token. * * @example * ```ts * const token = await client.accounts.tokens.delete( * 'ed17574386854bf78a67040be0a770b0', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(tokenID, params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/tokens/${tokenID}`, options)._thenUnwrap((obj) => obj.result); } /** * Get information about a specific Account Owned API token. * * @example * ```ts * const token = await client.accounts.tokens.get( * 'ed17574386854bf78a67040be0a770b0', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(tokenID, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/tokens/${tokenID}`, options)._thenUnwrap((obj) => obj.result); } /** * Test whether a token works. * * @example * ```ts * const response = await client.accounts.tokens.verify({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ verify(params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/tokens/verify`, options)._thenUnwrap((obj) => obj.result); } } BaseTokens._key = Object.freeze([ 'accounts', 'tokens', ]); return BaseTokens; })(); export var Tokens = /* @__PURE__ */ (() => { class Tokens extends BaseTokens { constructor() { super(...arguments); this.permissionGroups = new PermissionGroupsAPI.PermissionGroups(this._client); this.value = new ValueAPI.Value(this._client); } } Tokens.PermissionGroups = PermissionGroups; Tokens.BasePermissionGroups = BasePermissionGroups; Tokens.Value = Value; Tokens.BaseValue = BaseValue; return Tokens; })(); //# sourceMappingURL=tokens.mjs.map