Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
feat(api): implement UserTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
akowalsk authored and terinjokes committed Sep 22, 2021
1 parent 35b4c08 commit 7170ef3
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const resources = {
zoneWorkersScript: require('./lib/resources/ZoneWorkersScript'),
zoneWorkersRoutes: require('./lib/resources/ZoneWorkersRoutes'),
user: require('./lib/resources/User'),
userTokens: require('./lib/resources/UserTokens'),
stream: require('./lib/resources/Stream'),
};
/* eslint-enable global-require */
Expand Down
109 changes: 109 additions & 0 deletions lib/resources/UserTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2014-present Cloudflare, Inc.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

'use strict';

const prototypal = require('es-class');
const auto = require('autocreate');

const Resource = require('../Resource');
const method = require('../method');

/**
* UserTokens represents the /user/tokens API endpoint.
*
* @class UserTokens
* @hideconstructor
* @extends Resource
*/
module.exports = auto(
prototypal({
extends: Resource,
path: 'user/tokens',

includeBasic: ['browse', 'read', 'edit', 'add', 'del'],
/**
* roll rotates the token secret
*
* @function roll
* @memberof UserTokens
* @instance
* @async
* @param {string} id - The User Token ID
* @returns {Promise<Object>} The User Token response object.
*/
roll: method({
method: 'PUT',
path: ':id/value',
}),
/**
* verify the token secret
*
* @function verify
* @memberof UserTokens
* @instance
* @async
* @returns {Promise<Object>} The User Token response object.
*/
verify: method({
method: 'GET',
path: 'verify',
}),
/**
* browsePermissionGroups browse all available permission groups
*
* @function browsePermissionGroups
* @memberof UserTokens
* @instance
* @async
* @returns {Promise<Object>} The response object.
*/
browsePermissionGroups: method({
method: 'GET',
path: 'permission_groups',
}),
/**
* browse allows for listing user tokens
*
* @function browse
* @memberof UserTokens
* @instance
* @async
* @returns {Promise<Object>} The User Token response object.
*/
/**
* read allows for retrieving a user token's details
*
* @function read
* @memberof UserTokens
* @instance
* @async
* @param {string} id - The User Token ID
* @returns {Promise<Object>} The User Token object.
*/
/**
* add allows for creating a user token.
*
* @function add
* @memberof UserTokens
* @instance
* @async
* @param {Object} token - The new user token object
* @returns {Promise<Object>} The created user token object.
*/
/**
* del allows for deleting a user token.
*
* @function del
* @memberof UserTokens
* @instance
* @async
* @param {string} id - The user token ID to delete
* @returns {Promise<Object>} The deleted user token object.
*/
})
);

0 comments on commit 7170ef3

Please sign in to comment.