Skip to content

Commit

Permalink
new tokens API uri
Browse files Browse the repository at this point in the history
zefir-git committed Sep 1, 2023
1 parent 89bb378 commit 94e43c2
Showing 7 changed files with 120 additions and 112 deletions.
59 changes: 30 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -100,13 +100,13 @@ console.log(newsletter._response.status); // 200
- [`cloudnode.subscriptions.delete(id)`](#cloudnodesubscriptionsdeleteid)
- [`cloudnode.subscriptions.get(id)`](#cloudnodesubscriptionsgetid)
- [`cloudnode.subscriptions.list([limit], [page])`](#cloudnodesubscriptionslistlimit-page)
- [`cloudnode.token.create(permissions, lifetime, [note])`](#cloudnodetokencreatepermissions-lifetime-note)
- [`cloudnode.token.get(id)`](#cloudnodetokengetid)
- [`cloudnode.token.getRequest(id, request)`](#cloudnodetokengetrequestid-request)
- [`cloudnode.token.list([limit], [page], [internal])`](#cloudnodetokenlistlimit-page-internal)
- [`cloudnode.token.listRequests(id, [limit], [page])`](#cloudnodetokenlistrequestsid-limit-page)
- [`cloudnode.token.revoke(id)`](#cloudnodetokenrevokeid)
- [`cloudnode.tokens.refresh()`](#cloudnodetokensrefresh)
- [`cloudnode.tokens.create(permissions, lifetime, [note])`](#cloudnodetokenscreatepermissions-lifetime-note)
- [`cloudnode.tokens.get(id)`](#cloudnodetokensgetid)
- [`cloudnode.tokens.getRequest(id, request)`](#cloudnodetokensgetrequestid-request)
- [`cloudnode.tokens.list([limit], [page], [internal])`](#cloudnodetokenslistlimit-page-internal)
- [`cloudnode.tokens.listRequests(id, [limit], [page])`](#cloudnodetokenslistrequestsid-limit-page)
- [`cloudnode.tokens.refresh(id)`](#cloudnodetokensrefreshid)
- [`cloudnode.tokens.revoke(id)`](#cloudnodetokensrevokeid)

- [Namespace: `Cloudnode`](#namespace-cloudnode)
- [Class: `Cloudnode.ApiResponse<T>`](#class-cloudnodeapiresponset)
@@ -538,9 +538,9 @@ List newsletter subscriptions. Requires token with scope `newsletter.subscriptio
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokencreatepermissions-lifetime-note"></a>
<a name="cloudnodetokenscreatepermissions-lifetime-note"></a>

### `cloudnode.token.create(permissions, lifetime, [note])`
### `cloudnode.tokens.create(permissions, lifetime, [note])`

Create token. Requires token with scope `tokens.create.own`.

@@ -555,9 +555,9 @@ Create token. Requires token with scope `tokens.create.own`.
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokengetid"></a>
<a name="cloudnodetokensgetid"></a>

### `cloudnode.token.get(id)`
### `cloudnode.tokens.get(id)`

Get token details. Requires token with scope `tokens.get.own`.

@@ -571,9 +571,9 @@ Get token details. Requires token with scope `tokens.get.own`.
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokengetrequestid-request"></a>
<a name="cloudnodetokensgetrequestid-request"></a>

### `cloudnode.token.getRequest(id, request)`
### `cloudnode.tokens.getRequest(id, request)`

Get a recent request by ID. Requires token with scope `tokens.get.own.requests`.

@@ -582,15 +582,16 @@ Get a recent request by ID. Requires token with scope `tokens.get.own.requests`.
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Request](#interface-cloudnoderequest)>></code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokenlistlimit-page-internal"></a>
<a name="cloudnodetokenslistlimit-page-internal"></a>

### `cloudnode.token.list([limit], [page], [internal])`
### `cloudnode.tokens.list([limit], [page], [internal])`

List tokens of user. Requires token with scope `tokens.list.own`.

@@ -604,9 +605,9 @@ List tokens of user. Requires token with scope `tokens.list.own`.
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokenlistrequestsid-limit-page"></a>
<a name="cloudnodetokenslistrequestsid-limit-page"></a>

### `cloudnode.token.listRequests(id, [limit], [page])`
### `cloudnode.tokens.listRequests(id, [limit], [page])`

Get list of recent requests made with the token. Requires token with scope `tokens.get.own.requests`.

@@ -622,32 +623,32 @@ Get list of recent requests made with the token. Requires token with scope `toke
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokenrevokeid"></a>
<a name="cloudnodetokensrefreshid"></a>

### `cloudnode.token.revoke(id)`
### `cloudnode.tokens.refresh(id)`

Revoke token. Requires token with scope `tokens.revoke.own`.
Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely. Requires token with scope `token.refresh`.

- `id` <code>string | "current"</code> The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>></code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"}</code>
- `id` <code>string | "current"</code> The ID of the token to refresh. Specify `current` to refresh the token that was used to authenticate the request.
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Token](#interface-cloudnodetoken)>></code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>

<a name="cloudnodetokensrefresh"></a>
<a name="cloudnodetokensrevokeid"></a>

### `cloudnode.tokens.refresh()`

Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely. Requires token with scope `token.refresh`.
### `cloudnode.tokens.revoke(id)`

Revoke token. Requires token with scope `tokens.revoke.own`.

- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Token](#interface-cloudnodetoken)>></code>
- `id` <code>string | "current"</code> The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>></code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"}</code>
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"}</code>
36 changes: 18 additions & 18 deletions browser/Cloudnode.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion browser/Cloudnode.min.js

Large diffs are not rendered by default.

41 changes: 24 additions & 17 deletions schema.json
Original file line number Diff line number Diff line change
@@ -689,15 +689,15 @@
}
}
},
"token": {
"tokens": {
"type": "namespace",
"operations": {
"list": {
"type": "operation",
"description": "List tokens of user",
"token": "tokens.list.own",
"method": "GET",
"path": "/token",
"path": "/tokens",
"parameters": {
"query": {
"limit": {
@@ -731,7 +731,7 @@
"description": "Create token",
"token": "tokens.create.own",
"method": "POST",
"path": "/token",
"path": "/tokens",
"parameters": {
"body": {
"permissions": {
@@ -767,7 +767,7 @@
"description": "Get token details",
"token": "tokens.get.own",
"method": "GET",
"path": "/token/:id",
"path": "/tokens/:id",
"parameters": {
"path": {
"id": {
@@ -797,7 +797,7 @@
"description": "Revoke token",
"token": "tokens.revoke.own",
"method": "DELETE",
"path": "/token/:id",
"path": "/tokens/:id",
"parameters": {
"path": {
"id": {
@@ -821,7 +821,7 @@
"type": "Error & {code: \"INVALID_DATA\"}"
},
{
"status": 400,
"status": 423,
"type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}"
}
]
@@ -831,7 +831,7 @@
"description": "Get list of recent requests made with the token",
"token": "tokens.get.own.requests",
"method": "GET",
"path": "/token/:id/requests",
"path": "/tokens/:id/requests",
"parameters": {
"path": {
"id": {
@@ -875,7 +875,7 @@
"description": "Get a recent request by ID",
"token": "tokens.get.own.requests",
"method": "GET",
"path": "/token/:id/requests/:request",
"path": "/tokens/:id/requests/:request",
"parameters": {
"path": {
"id": {
@@ -902,24 +902,31 @@
{
"status": 422,
"type": "Error & {code: \"INVALID_DATA\"}"
},
{
"status": 423,
"type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}"
}
]
}
}
},
"tokens": {
"type": "namespace",
"operations": {
},
"refresh": {
"type": "operation",
"description": "Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely.",
"token": "token.refresh",
"method": "POST",
"path": "/token/refresh",
"parameters": {},
"path": "/tokens/:id",
"parameters": {
"path": {
"id": {
"description": "The ID of the token to refresh. Specify `current` to refresh the token that was used to authenticate the request.",
"type": "string | \"current\"",
"required": true
}
}
},
"returns": [
{
"status": 201,
"status": 200,
"type": "Token"
},
{
22 changes: 11 additions & 11 deletions src/Cloudnode.d.ts
Original file line number Diff line number Diff line change
@@ -116,10 +116,10 @@ declare class Cloudnode {
*/
readonly delete: (id: string) => Promise<Cloudnode.ApiResponse<void>>;
};
token: {
tokens: {
/**
* List tokens of user
* @GET /token
* @GET /tokens
* @param limit The number of tokens to return per page. No more than 50.
* @param page The page number. No more than 2³² (4294967296).
* @param internal Internal tokens are returned as well if this parameter is present.
@@ -132,7 +132,7 @@ declare class Cloudnode {
readonly list: (limit?: number, page?: number, internal?: any) => Promise<Cloudnode.ApiResponse<Cloudnode.PaginatedData<Cloudnode.PartialToken[]>>>;
/**
* Create token
* @POST /token
* @POST /tokens
* @param permissions List of permissions to grant to the token. You must already have each of these permissions with your current token.
* @param lifetime Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).
* @param note A user-specified note to label the token. Max length: 2⁸ (256) characters.
@@ -146,7 +146,7 @@ declare class Cloudnode {
readonly create: (permissions: string[], lifetime: number, note?: string) => Promise<Cloudnode.ApiResponse<Cloudnode.Token>>;
/**
* Get token details
* @GET /token/:id
* @GET /tokens/:id
* @param id The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
@@ -159,7 +159,7 @@ declare class Cloudnode {
readonly get: (id: string | "current") => Promise<Cloudnode.ApiResponse<Cloudnode.Token>>;
/**
* Revoke token
* @DELETE /token/:id
* @DELETE /tokens/:id
* @param id The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
@@ -173,7 +173,7 @@ declare class Cloudnode {
readonly revoke: (id: string | "current") => Promise<Cloudnode.ApiResponse<void>>;
/**
* Get list of recent requests made with the token
* @GET /token/:id/requests
* @GET /tokens/:id/requests
* @param id The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
* @param limit The number of requests to return per page. No more than 50.
* @param page The page number. No more than 2³² (4294967296).
@@ -188,31 +188,31 @@ declare class Cloudnode {
readonly listRequests: (id: string | "current", limit?: number, page?: number) => Promise<Cloudnode.ApiResponse<Cloudnode.PaginatedData<Cloudnode.ShortRequest[]>>>;
/**
* Get a recent request by ID
* @GET /token/:id/requests/:request
* @GET /tokens/:id/requests/:request
* @param id The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
* @param request The ID of the request.
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
* @throws {Cloudnode.Error & {code: "MODIFICATION_NOT_ALLOWED"}}
* @throws {Cloudnode.Error & {code: "UNAUTHORIZED"}}
* @throws {Cloudnode.Error & {code: "NO_PERMISSION"}}
* @throws {Cloudnode.Error & {code: "RATE_LIMITED"}}
* @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}}
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
*/
readonly getRequest: (id: string | "current", request: string) => Promise<Cloudnode.ApiResponse<Cloudnode.Request>>;
};
tokens: {
/**
* Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely.
* @POST /token/refresh
* @POST /tokens/:id
* @param id The ID of the token to refresh. Specify `current` to refresh the token that was used to authenticate the request.
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
* @throws {Cloudnode.Error & {code: "UNAUTHORIZED"}}
* @throws {Cloudnode.Error & {code: "NO_PERMISSION"}}
* @throws {Cloudnode.Error & {code: "RATE_LIMITED"}}
* @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}}
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
*/
readonly refresh: () => Promise<Cloudnode.ApiResponse<Cloudnode.Token>>;
readonly refresh: (id: string | "current") => Promise<Cloudnode.ApiResponse<Cloudnode.Token>>;
};
auth: {
/**
36 changes: 18 additions & 18 deletions src/Cloudnode.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions src/Cloudnode.ts

Large diffs are not rendered by default.

0 comments on commit 94e43c2

Please sign in to comment.