OSDN Git Service

update node-sdk
[bytom/bytom-node-sdk.git] / src / api / accessTokens.js
1 /**
2  * Access tokens are `name:secret-token` pairs that are granted authorization for accessing Chain Core features.
3  *
4  * @typedef {Object} AccessToken
5  * @global
6  *
7  * @property {String} id
8  * User specified, unique identifier.
9  *
10  * @property {String} token
11  * Only returned in the response from {@link AccessTokensApi~create}.
12  *
13  * @property {String} created_at
14  * Timestamp of token creation, RFC3339 formatted.
15  */
16
17 /**
18  * API for interacting with {@link AccessToken access tokens}.
19  *
20  * @module AccessTokensApi
21  */
22 const accessTokensApi = (connection) => {
23   return {
24     /**
25      * Create a new access token.
26      *
27      * @param {Object} params - Access Token Object.
28      * @param {String} params.id - User specified, unique identifier.
29      * @param {String} params.type - type of token.
30      * @returns {Promise<AccessToken>} Newly created access token.
31      */
32     create: (params) => connection.request('/create-access-token', params),
33
34     /**
35      * Get all access tokens.
36      *
37      * @returns {Promise<Array<AccessToken>>} All access tokens.
38      */
39     list: () => connection.request('/list-access-tokens', {}),
40
41     /**
42      * Delete the target access token.
43      *
44      * @param {String} id- The to be deleted token id.
45      */
46     delete: (id) => connection.request('/delete-access-token', {id}),
47
48     /**
49      * Check the target access token.
50      *
51      * @param {Object} params - Parameters for access token check.
52      * @param {String} params.id - The to be deleted token id.
53      * @param {String} params.secret, secret of token, the second part of the colon division for token.
54      */
55     check: (params) => connection.request('/check-access-token', params),
56   }
57 }
58
59 export default accessTokensApi