UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

145 lines • 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Tokens = exports.BaseTokens = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const PermissionGroupsAPI = tslib_1.__importStar(require("./permission-groups.js")); const permission_groups_1 = require("./permission-groups.js"); const ValueAPI = tslib_1.__importStar(require("./value.js")); const value_1 = require("./value.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseTokens = /* @__PURE__ */ (() => { class BaseTokens extends resource_1.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((0, path_1.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', (pagination_1.V4PagePaginationArray), { query, ...options, }); } /** * Destroy a token. * * @example * ```ts * const token = await client.user.tokens.delete( * 'ed17574386854bf78a67040be0a770b0', * ); * ``` */ delete(tokenID, options) { return this._client.delete((0, path_1.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((0, path_1.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; })(); exports.BaseTokens = BaseTokens; 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 = permission_groups_1.PermissionGroups; Tokens.BasePermissionGroups = permission_groups_1.BasePermissionGroups; Tokens.Value = value_1.Value; Tokens.BaseValue = value_1.BaseValue; return Tokens; })(); exports.Tokens = Tokens; //# sourceMappingURL=tokens.js.map