UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

139 lines • 4.77 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 access token. * * @example * ```ts * const token = await client.user.tokens.create({ * name: 'readonly token', * policies: [ * { * effect: 'allow', * permission_groups: [ * { id: 'c8fed203ed3043cba015a93ad1616f1f' }, * { id: '82e64a83756745bbbb1c9c2701bf816b' }, * ], * resources: { * 'com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43': * '*', * }, * }, * ], * }); * ``` */ create(body, options) { return this._client.post('/user/tokens', { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Update an existing token. * * @example * ```ts * const token = await client.user.tokens.update( * 'ed17574386854bf78a67040be0a770b0', * { * name: 'readonly token', * policies: [ * { * effect: 'allow', * permission_groups: [ * { id: 'c8fed203ed3043cba015a93ad1616f1f' }, * { id: '82e64a83756745bbbb1c9c2701bf816b' }, * ], * resources: { * 'com.cloudflare.api.account.zone.22b1de5f1c0e4b3ea97bb1e963b06a43': * '*', * }, * }, * ], * }, * ); * ``` */ update(tokenID, body, options) { return this._client.put(path `/user/tokens/${tokenID}`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * List all access tokens you 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.user.tokens.list()) { * // ... * } * ``` */ list(query = {}, options) { return this._client.getAPIList('/user/tokens', (V4PagePaginationArray), { query, ...options, }); } /** * Destroy a token. * * @example * ```ts * const token = await client.user.tokens.delete( * 'ed17574386854bf78a67040be0a770b0', * ); * ``` */ delete(tokenID, options) { return this._client.delete(path `/user/tokens/${tokenID}`, options)._thenUnwrap((obj) => obj.result); } /** * Get information about a specific token. * * @example * ```ts * const token = await client.user.tokens.get( * 'ed17574386854bf78a67040be0a770b0', * ); * ``` */ get(tokenID, options) { return this._client.get(path `/user/tokens/${tokenID}`, options)._thenUnwrap((obj) => obj.result); } /** * Test whether a token works. * * @example * ```ts * const response = await client.user.tokens.verify(); * ``` */ verify(options) { return this._client.get('/user/tokens/verify', options)._thenUnwrap((obj) => obj.result); } } BaseTokens._key = Object.freeze(['user', '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