cloudflare
Version:
The official TypeScript library for the Cloudflare API
161 lines • 6.19 kB
JavaScript
;
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 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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/tokens`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/tokens/verify`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseTokens._key = Object.freeze([
'accounts',
'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