From 94e43c2a6aec3e7d66bbd669937de6ec5ced2d58 Mon Sep 17 00:00:00 2001 From: Zefir Kirilov Date: Sat, 2 Sep 2023 02:13:15 +0300 Subject: [PATCH] new tokens API uri --- README.md | 59 ++++++++++++++++++++-------------------- browser/Cloudnode.js | 36 ++++++++++++------------ browser/Cloudnode.min.js | 2 +- schema.json | 41 ++++++++++++++++------------ src/Cloudnode.d.ts | 22 +++++++-------- src/Cloudnode.js | 36 ++++++++++++------------ src/Cloudnode.ts | 36 ++++++++++++------------ 7 files changed, 120 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 12bd028..6443c7a 100644 --- a/README.md +++ b/README.md @@ -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`](#class-cloudnodeapiresponset) @@ -538,9 +538,9 @@ List newsletter subscriptions. Requires token with scope `newsletter.subscriptio - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)<[Cloudnode.Request](#interface-cloudnoderequest)>> - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"} + - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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` string | "current" The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request. - - Returns: [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)<[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>> - - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"} + - `id` string | "current" The ID of the token to refresh. Specify `current` to refresh the token that was used to authenticate the request. + - Returns: [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)<[Cloudnode.Token](#interface-cloudnodetoken)>> - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"} - - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"} - + -### `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: [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)<[Cloudnode.Token](#interface-cloudnodetoken)>> + - `id` string | "current" The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request. + - Returns: [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)<[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>> + - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"} + - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "MODIFICATION_NOT_ALLOWED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"} - Throws: [Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"} diff --git a/browser/Cloudnode.js b/browser/Cloudnode.js index 9cf5582..b34450a 100644 --- a/browser/Cloudnode.js +++ b/browser/Cloudnode.js @@ -303,10 +303,10 @@ class Cloudnode { return await this.#sendRequest({ "type": "operation", "description": "Unsubscribe from newsletter", "method": "DELETE", "path": "/subscriptions/:id", "parameters": { "path": { "id": { "description": "The ID of the subscription to revoke", "type": "string", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, }; - 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. @@ -317,11 +317,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ list: async (limit = 10, page = 1, internal) => { - return await this.#sendRequest({ "type": "operation", "description": "List tokens of user", "token": "tokens.list.own", "method": "GET", "path": "/token", "parameters": { "query": { "limit": { "description": "The number of tokens to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false }, "internal": { "description": "Internal tokens are returned as well if this parameter is present.", "type": "any", "required": false } } }, "returns": [{ "status": 200, "type": "PartialToken[]" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, { limit: `${limit}`, page: `${page}`, internal: `${internal}` }, {}); + return await this.#sendRequest({ "type": "operation", "description": "List tokens of user", "token": "tokens.list.own", "method": "GET", "path": "/tokens", "parameters": { "query": { "limit": { "description": "The number of tokens to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false }, "internal": { "description": "Internal tokens are returned as well if this parameter is present.", "type": "any", "required": false } } }, "returns": [{ "status": 200, "type": "PartialToken[]" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, { limit: `${limit}`, page: `${page}`, internal: `${internal}` }, {}); }, /** * 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. @@ -333,11 +333,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ create: async (permissions, lifetime, note) => { - return await this.#sendRequest({ "type": "operation", "description": "Create token", "token": "tokens.create.own", "method": "POST", "path": "/token", "parameters": { "body": { "permissions": { "description": "List of permissions to grant to the token. You must already have each of these permissions with your current token.", "type": "string[]", "required": true }, "lifetime": { "description": "Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).", "type": "number", "required": true }, "note": { "description": "A user-specified note to label the token. Max length: 2⁸ (256) characters.", "type": "string", "required": false } } }, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { permissions, lifetime, note }); + return await this.#sendRequest({ "type": "operation", "description": "Create token", "token": "tokens.create.own", "method": "POST", "path": "/tokens", "parameters": { "body": { "permissions": { "description": "List of permissions to grant to the token. You must already have each of these permissions with your current token.", "type": "string[]", "required": true }, "lifetime": { "description": "Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).", "type": "number", "required": true }, "note": { "description": "A user-specified note to label the token. Max length: 2⁸ (256) characters.", "type": "string", "required": false } } }, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { permissions, lifetime, note }); }, /** * 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"}} @@ -348,11 +348,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ get: async (id) => { - return await this.#sendRequest({ "type": "operation", "description": "Get token details", "token": "tokens.get.own", "method": "GET", "path": "/token/:id", "parameters": { "path": { "id": { "description": "The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 200, "type": "Token" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get token details", "token": "tokens.get.own", "method": "GET", "path": "/tokens/:id", "parameters": { "path": { "id": { "description": "The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 200, "type": "Token" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, /** * 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"}} @@ -364,11 +364,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ revoke: async (id) => { - return await this.#sendRequest({ "type": "operation", "description": "Revoke token", "token": "tokens.revoke.own", "method": "DELETE", "path": "/token/:id", "parameters": { "path": { "id": { "description": "The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 400, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Revoke token", "token": "tokens.revoke.own", "method": "DELETE", "path": "/tokens/:id", "parameters": { "path": { "id": { "description": "The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 423, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, /** * 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). @@ -381,15 +381,16 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ listRequests: async (id, limit = 10, page = 1) => { - return await this.#sendRequest({ "type": "operation", "description": "Get list of recent requests made with the token", "token": "tokens.get.own.requests", "method": "GET", "path": "/token/:id/requests", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } }, "query": { "limit": { "description": "The number of requests to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false } } }, "returns": [{ "status": 200, "type": "ShortRequest[]" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, { limit: `${limit}`, page: `${page}` }, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get list of recent requests made with the token", "token": "tokens.get.own.requests", "method": "GET", "path": "/tokens/:id/requests", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } }, "query": { "limit": { "description": "The number of requests to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false } } }, "returns": [{ "status": 200, "type": "ShortRequest[]" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, { limit: `${limit}`, page: `${page}` }, {}); }, /** * 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"}} @@ -397,13 +398,12 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ getRequest: async (id, request) => { - return await this.#sendRequest({ "type": "operation", "description": "Get a recent request by ID", "token": "tokens.get.own.requests", "method": "GET", "path": "/token/:id/requests/:request", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true }, "request": { "description": "The ID of the request.", "type": "string", "required": true } } }, "returns": [{ "status": 200, "type": "Request" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}`, request: `${request}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get a recent request by ID", "token": "tokens.get.own.requests", "method": "GET", "path": "/tokens/:id/requests/:request", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true }, "request": { "description": "The ID of the request.", "type": "string", "required": true } } }, "returns": [{ "status": 200, "type": "Request" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 423, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}`, request: `${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"}} @@ -411,8 +411,8 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}} * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ - refresh: async () => { - return await this.#sendRequest({ "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": {}, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, {}); + refresh: async (id) => { + return await this.#sendRequest({ "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": "/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": 200, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, }; auth = { diff --git a/browser/Cloudnode.min.js b/browser/Cloudnode.min.js index 3d59a67..b852b69 100644 --- a/browser/Cloudnode.min.js +++ b/browser/Cloudnode.min.js @@ -1 +1 @@ -class Cloudnode{#e;#t;static#r={baseUrl:"https://api.cloudnode.pro/v5/",autoRetry:!0,maxRetryDelay:5,maxRetries:3};#s="5.13.0";#o="cloudnode/2.1.0";constructor(e,t=Cloudnode.#r){const r=Cloudnode.#r;r.baseUrl=t.baseUrl??Cloudnode.#r.baseUrl,r.autoRetry=t.autoRetry??Cloudnode.#r.autoRetry,r.maxRetryDelay=t.maxRetryDelay??Cloudnode.#r.maxRetryDelay,r.maxRetries=t.maxRetries??Cloudnode.#r.maxRetries,this.#e=e,this.#t=r}async#a(e,t,r,s){const o=new URL(e.path.replace(/^\/+/,""),this.#t.baseUrl);for(const[e,r]of Object.entries(t))o.pathname=o.pathname.replaceAll(`/:${e}`,`/${r}`);for(const[e,t]of Object.entries(r))o.searchParams.append(e,t);const a={method:e.method,headers:{}};s&&!["GET","HEAD"].includes(e.method)&&("string"!=typeof s?(a.body=JSON.stringify(s),a.headers["Content-Type"]="application/json"):(a.body=s,a.headers["Content-Type"]="text/plain")),a.headers["User-Agent"]=this.#o,this.#e&&void 0!==e.token&&(a.headers.Authorization=`Bearer ${this.#e}`),void 0!==e.token&&(a.credentials="include");const n=await fetch(o.toString(),a);if(204===n.status)return;const i=await n.text();let p;p=n.headers.get("Content-Type")?.startsWith("application/json")?JSON.parse(i,((e,t)=>/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(t)?new Date(t):t)):i;const d=Cloudnode.makeApiResponse(p,new Cloudnode.RawResponse(n,{operation:e,pathParams:t,queryParams:r,body:s}));if(n.ok)return d;throw d}#n(e,t,r,s,o){return new Promise((async(a,n)=>{const i=(p=0)=>{this.#a(e,t,r,s).then((e=>a(e))).catch((e=>{if(o??=this.#t,o.baseUrl??=this.#t.baseUrl,o.autoRetry??=this.#t.autoRetry,o.maxRetries??=this.#t.maxRetries,o.maxRetryDelay??=this.#t.maxRetryDelay,o.autoRetry&&po.maxRetryDelay)return n(e);setTimeout(i,1e3*Number(r),++p)}else n(e)}))};i(0)}))}#i(e,t){const r=e.split("."),s=t.split("."),o=[r[0]||"0",r[1]||"0"],a=[s[0]||"0",s[1]||"0"];return o[0]!==a[0]?"incompatible":o[1]!==a[1]?"outdated":"compatible"}async checkCompatibility(){const e=await(await fetch(new URL("../",this.#t.baseUrl).toString(),{method:"GET",headers:{"User-Agent":this.#o}})).json();return this.#i(e.version,this.#s)}async getPage(e,t){if(t*e.limit>e.total||t<1)return null;const r=Object.assign({},e._response.request.queryParams);return r.page=t.toString(),await this.#n(e._response.request.operation,e._response.request.pathParams,r,e._response.request.body)}async getNextPage(e){return await this.getPage(e,e.page+1)}async getPreviousPage(e){return await this.getPage(e,e.page-1)}async getAllPages(e){const t=new Array(Math.ceil(e.total/e.limit)).fill(null);t[e.page-1]=!0;const r=t.map(((t,r)=>null!==t||this.getPage(e,r+1))),s=await Promise.all(r.filter((e=>!0!==e)));s.splice(e.page-1,0,e);return{items:s.filter((e=>null!==e)).map((e=>e.items)).flat(),total:e.total,limit:e.limit,page:1}}newsletters={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletters",method:"GET",path:"/newsletters",parameters:{query:{limit:{description:"The number of newsletters to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Newsletter[]"},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter",method:"GET",path:"/newsletters/:id",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}}},returns:[{status:200,type:"Newsletter"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})};subscriptions={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletter subscriptions",token:"newsletter.subscriptions.list.own",method:"GET",path:"/subscriptions",parameters:{query:{limit:{description:"The number of subscriptions to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"DatedNewsletterSubscription[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter subscription",method:"GET",path:"/subscriptions/:id",parameters:{path:{id:{description:"The ID of the subscription to get",type:"string",required:!0}}},returns:[{status:200,type:"DatedNewsletterSubscription"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Subscribe to newsletter",method:"POST",path:"/subscriptions",parameters:{body:{newsletter:{description:"The ID of the newsletter to subscribe to",type:"string",required:!0},email:{description:"Subscriber's email address",type:"string",required:!0},data:{description:"Additional data that this newsletter requires",type:"Record",required:!1}}},returns:[{status:201,type:"NewsletterSubscription"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{newsletter:e,email:t,data:r}),delete:async e=>await this.#n({type:"operation",description:"Unsubscribe from newsletter",method:"DELETE",path:"/subscriptions/:id",parameters:{path:{id:{description:"The ID of the subscription to revoke",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})};token={list:async(e=10,t=1,r)=>await this.#n({type:"operation",description:"List tokens of user",token:"tokens.list.own",method:"GET",path:"/token",parameters:{query:{limit:{description:"The number of tokens to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1},internal:{description:"Internal tokens are returned as well if this parameter is present.",type:"any",required:!1}}},returns:[{status:200,type:"PartialToken[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`,internal:`${r}`},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Create token",token:"tokens.create.own",method:"POST",path:"/token",parameters:{body:{permissions:{description:"List of permissions to grant to the token. You must already have each of these permissions with your current token.",type:"string[]",required:!0},lifetime:{description:"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).",type:"number",required:!0},note:{description:"A user-specified note to label the token. Max length: 2⁸ (256) characters.",type:"string",required:!1}}},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{permissions:e,lifetime:t,note:r}),get:async e=>await this.#n({type:"operation",description:"Get token details",token:"tokens.get.own",method:"GET",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:200,type:"Token"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),revoke:async e=>await this.#n({type:"operation",description:"Revoke token",token:"tokens.revoke.own",method:"DELETE",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:400,type:'Error & {code: "MODIFICATION_NOT_ALLOWED"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),listRequests:async(e,t=10,r=1)=>await this.#n({type:"operation",description:"Get list of recent requests made with the token",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}},query:{limit:{description:"The number of requests to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"ShortRequest[]"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{limit:`${t}`,page:`${r}`},{}),getRequest:async(e,t)=>await this.#n({type:"operation",description:"Get a recent request by ID",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests/:request",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0},request:{description:"The ID of the request.",type:"string",required:!0}}},returns:[{status:200,type:"Request"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`,request:`${t}`},{},{})};tokens={refresh:async()=>await this.#n({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:{},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})};auth={register:async(e,t,r)=>await this.#n({type:"operation",description:"Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.",method:"POST",path:"/auth/register",token:null,parameters:{body:{username:{description:"The username to use for the account. Must be between 3 and 20 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.",type:"string",required:!0},email:{description:"The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.",type:"string",required:!0},password:{description:"The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,email:t,password:r}),login:async(e,t)=>await this.#n({type:"operation",description:"Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.",method:"POST",path:"/auth/login",token:null,parameters:{body:{user:{description:"User ID (starts with `user_`), username or e-mail address.",type:"string",required:!0},password:{description:"The password of the account.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{user:e,password:t})};account={get:async()=>await this.#n({type:"operation",description:"Get account details",token:"account.details",method:"GET",path:"/account",parameters:{},returns:[{status:200,type:"AccountDetails"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getIdentity:async()=>await this.#n({type:"operation",description:"Get account identity",token:"account.details.identity",method:"GET",path:"/account/identity",parameters:{},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),updateIdentity:async(e,t)=>await this.#n({type:"operation",description:"Update account identity",token:"account.details.identity.update",method:"PATCH",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 20 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove. Min 2 characters, max 32. Allowed characters (lowercase as well): A–Z `',-.,` and `ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞSŸ`",type:"string | null",required:!1}}},returns:[{status:200,type:"AccountIdentity"},{status:204,type:"void",description:"`void` if nothing was changed."},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),replaceIdentity:async(e,t)=>await this.#n({type:"operation",description:"Replace account identity",token:"account.details.identity.update",method:"PUT",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 20 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove. Min 2 characters, max 32. Allowed characters (lowercase as well): A–Z `',-.,` and `ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞSŸ`",type:"string | null",required:!0}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),listEmails:async()=>await this.#n({type:"operation",description:"List account e-mail addresses",token:"account.details.email.list",method:"GET",path:"/account/email",parameters:{},returns:[{status:200,type:"AccountEmail[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getEmail:async()=>await this.#n({type:"operation",description:"Get your primary e-mail address",token:"account.details.email",method:"GET",path:"/account/email/primary",parameters:{},returns:[{status:200,type:"DatedPrimaryEmail"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),setEmail:async e=>await this.#n({type:"operation",description:"Set your primary e-mail address",token:"account.details.email.update",method:"PUT",path:"/account/email/primary",parameters:{body:{email:{description:"E-mail address to set as primary.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{email:e}),changePassword:async(e,t)=>await this.#n({type:"operation",description:"Change account password",token:"account.details.password.update",method:"PUT",path:"/account/password",parameters:{body:{currentPassword:{description:"Your current password.",type:"string",required:!0},newPassword:{description:"The new password. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{currentPassword:e,newPassword:t}),listPermissions:async()=>await this.#n({type:"operation",description:"List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description.",token:"account.details",method:"GET",path:"/account/permissions",parameters:{},returns:[{status:200,type:"Permission[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})};projects={list:async(e=20,t=1)=>await this.#n({type:"operation",description:"List projects",token:"projects.get.own",method:"GET",path:"/projects",parameters:{query:{limit:{description:"The number of projects to return per page. No more than 100.",default:"20",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Project[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),create:async e=>await this.#n({type:"operation",description:"Create a project",token:"projects.create.own",method:"POST",path:"/projects",parameters:{body:{name:{description:"Project name. Max 255 characters.",type:"string",required:!0}}},returns:[{status:201,type:"Project"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{name:e}),get:async e=>await this.#n({type:"operation",description:"Get a project",token:"projects.get.own",method:"GET",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}}},returns:[{status:200,type:"Project"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),update:async(e,t)=>await this.#n({type:"operation",description:"Update a project",token:"projects.update.own",method:"PATCH",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}},body:{name:{description:"Project name. Max 255 characters.",type:"string",required:!0}}},returns:[{status:200,type:"Project"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{name:t}),delete:async e=>await this.#n({type:"operation",description:"Delete a project",token:"projects.delete.own",method:"DELETE",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})}}!function(e){let t;e.RawResponse=class{headers;ok;redirected;status;statusText;url;request;constructor(e,t){this.headers=Object.fromEntries([...e.headers.entries()].map((([e,t])=>[e.toLowerCase(),t]))),this.ok=e.ok,this.redirected=e.redirected,this.status=e.status,this.statusText=e.statusText,this.url=new URL(e.url),this.request=t}},function(e){e.ApiResponse=class{#p;constructor(e){this.#p=e}get _response(){return this.#p}}}(t=e.R||(e.R={})),e.makeApiResponse=function(e,r){return Object.assign(new t.ApiResponse(r),e)}}(Cloudnode||(Cloudnode={})); \ No newline at end of file +class Cloudnode{#e;#t;static#r={baseUrl:"https://api.cloudnode.pro/v5/",autoRetry:!0,maxRetryDelay:5,maxRetries:3};#s="5.13.0";#o="cloudnode/2.1.0";constructor(e,t=Cloudnode.#r){const r=Cloudnode.#r;r.baseUrl=t.baseUrl??Cloudnode.#r.baseUrl,r.autoRetry=t.autoRetry??Cloudnode.#r.autoRetry,r.maxRetryDelay=t.maxRetryDelay??Cloudnode.#r.maxRetryDelay,r.maxRetries=t.maxRetries??Cloudnode.#r.maxRetries,this.#e=e,this.#t=r}async#a(e,t,r,s){const o=new URL(e.path.replace(/^\/+/,""),this.#t.baseUrl);for(const[e,r]of Object.entries(t))o.pathname=o.pathname.replaceAll(`/:${e}`,`/${r}`);for(const[e,t]of Object.entries(r))o.searchParams.append(e,t);const a={method:e.method,headers:{}};s&&!["GET","HEAD"].includes(e.method)&&("string"!=typeof s?(a.body=JSON.stringify(s),a.headers["Content-Type"]="application/json"):(a.body=s,a.headers["Content-Type"]="text/plain")),a.headers["User-Agent"]=this.#o,this.#e&&void 0!==e.token&&(a.headers.Authorization=`Bearer ${this.#e}`),void 0!==e.token&&(a.credentials="include");const n=await fetch(o.toString(),a);if(204===n.status)return;const i=await n.text();let p;p=n.headers.get("Content-Type")?.startsWith("application/json")?JSON.parse(i,((e,t)=>/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(t)?new Date(t):t)):i;const d=Cloudnode.makeApiResponse(p,new Cloudnode.RawResponse(n,{operation:e,pathParams:t,queryParams:r,body:s}));if(n.ok)return d;throw d}#n(e,t,r,s,o){return new Promise((async(a,n)=>{const i=(p=0)=>{this.#a(e,t,r,s).then((e=>a(e))).catch((e=>{if(o??=this.#t,o.baseUrl??=this.#t.baseUrl,o.autoRetry??=this.#t.autoRetry,o.maxRetries??=this.#t.maxRetries,o.maxRetryDelay??=this.#t.maxRetryDelay,o.autoRetry&&po.maxRetryDelay)return n(e);setTimeout(i,1e3*Number(r),++p)}else n(e)}))};i(0)}))}#i(e,t){const r=e.split("."),s=t.split("."),o=[r[0]||"0",r[1]||"0"],a=[s[0]||"0",s[1]||"0"];return o[0]!==a[0]?"incompatible":o[1]!==a[1]?"outdated":"compatible"}async checkCompatibility(){const e=await(await fetch(new URL("../",this.#t.baseUrl).toString(),{method:"GET",headers:{"User-Agent":this.#o}})).json();return this.#i(e.version,this.#s)}async getPage(e,t){if(t*e.limit>e.total||t<1)return null;const r=Object.assign({},e._response.request.queryParams);return r.page=t.toString(),await this.#n(e._response.request.operation,e._response.request.pathParams,r,e._response.request.body)}async getNextPage(e){return await this.getPage(e,e.page+1)}async getPreviousPage(e){return await this.getPage(e,e.page-1)}async getAllPages(e){const t=new Array(Math.ceil(e.total/e.limit)).fill(null);t[e.page-1]=!0;const r=t.map(((t,r)=>null!==t||this.getPage(e,r+1))),s=await Promise.all(r.filter((e=>!0!==e)));s.splice(e.page-1,0,e);return{items:s.filter((e=>null!==e)).map((e=>e.items)).flat(),total:e.total,limit:e.limit,page:1}}newsletters={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletters",method:"GET",path:"/newsletters",parameters:{query:{limit:{description:"The number of newsletters to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Newsletter[]"},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter",method:"GET",path:"/newsletters/:id",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}}},returns:[{status:200,type:"Newsletter"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})};subscriptions={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletter subscriptions",token:"newsletter.subscriptions.list.own",method:"GET",path:"/subscriptions",parameters:{query:{limit:{description:"The number of subscriptions to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"DatedNewsletterSubscription[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter subscription",method:"GET",path:"/subscriptions/:id",parameters:{path:{id:{description:"The ID of the subscription to get",type:"string",required:!0}}},returns:[{status:200,type:"DatedNewsletterSubscription"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Subscribe to newsletter",method:"POST",path:"/subscriptions",parameters:{body:{newsletter:{description:"The ID of the newsletter to subscribe to",type:"string",required:!0},email:{description:"Subscriber's email address",type:"string",required:!0},data:{description:"Additional data that this newsletter requires",type:"Record",required:!1}}},returns:[{status:201,type:"NewsletterSubscription"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{newsletter:e,email:t,data:r}),delete:async e=>await this.#n({type:"operation",description:"Unsubscribe from newsletter",method:"DELETE",path:"/subscriptions/:id",parameters:{path:{id:{description:"The ID of the subscription to revoke",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})};tokens={list:async(e=10,t=1,r)=>await this.#n({type:"operation",description:"List tokens of user",token:"tokens.list.own",method:"GET",path:"/tokens",parameters:{query:{limit:{description:"The number of tokens to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1},internal:{description:"Internal tokens are returned as well if this parameter is present.",type:"any",required:!1}}},returns:[{status:200,type:"PartialToken[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`,internal:`${r}`},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Create token",token:"tokens.create.own",method:"POST",path:"/tokens",parameters:{body:{permissions:{description:"List of permissions to grant to the token. You must already have each of these permissions with your current token.",type:"string[]",required:!0},lifetime:{description:"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).",type:"number",required:!0},note:{description:"A user-specified note to label the token. Max length: 2⁸ (256) characters.",type:"string",required:!1}}},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{permissions:e,lifetime:t,note:r}),get:async e=>await this.#n({type:"operation",description:"Get token details",token:"tokens.get.own",method:"GET",path:"/tokens/:id",parameters:{path:{id:{description:"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:200,type:"Token"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),revoke:async e=>await this.#n({type:"operation",description:"Revoke token",token:"tokens.revoke.own",method:"DELETE",path:"/tokens/:id",parameters:{path:{id:{description:"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:423,type:'Error & {code: "MODIFICATION_NOT_ALLOWED"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),listRequests:async(e,t=10,r=1)=>await this.#n({type:"operation",description:"Get list of recent requests made with the token",token:"tokens.get.own.requests",method:"GET",path:"/tokens/:id/requests",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}},query:{limit:{description:"The number of requests to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"ShortRequest[]"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{limit:`${t}`,page:`${r}`},{}),getRequest:async(e,t)=>await this.#n({type:"operation",description:"Get a recent request by ID",token:"tokens.get.own.requests",method:"GET",path:"/tokens/:id/requests/:request",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0},request:{description:"The ID of the request.",type:"string",required:!0}}},returns:[{status:200,type:"Request"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:423,type:'Error & {code: "MODIFICATION_NOT_ALLOWED"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`,request:`${t}`},{},{}),refresh:async e=>await this.#n({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:"/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:!0}}},returns:[{status:200,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})};auth={register:async(e,t,r)=>await this.#n({type:"operation",description:"Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.",method:"POST",path:"/auth/register",token:null,parameters:{body:{username:{description:"The username to use for the account. Must be between 3 and 20 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.",type:"string",required:!0},email:{description:"The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.",type:"string",required:!0},password:{description:"The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,email:t,password:r}),login:async(e,t)=>await this.#n({type:"operation",description:"Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.",method:"POST",path:"/auth/login",token:null,parameters:{body:{user:{description:"User ID (starts with `user_`), username or e-mail address.",type:"string",required:!0},password:{description:"The password of the account.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{user:e,password:t})};account={get:async()=>await this.#n({type:"operation",description:"Get account details",token:"account.details",method:"GET",path:"/account",parameters:{},returns:[{status:200,type:"AccountDetails"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getIdentity:async()=>await this.#n({type:"operation",description:"Get account identity",token:"account.details.identity",method:"GET",path:"/account/identity",parameters:{},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),updateIdentity:async(e,t)=>await this.#n({type:"operation",description:"Update account identity",token:"account.details.identity.update",method:"PATCH",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 20 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove. Min 2 characters, max 32. Allowed characters (lowercase as well): A–Z `',-.,` and `ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞSŸ`",type:"string | null",required:!1}}},returns:[{status:200,type:"AccountIdentity"},{status:204,type:"void",description:"`void` if nothing was changed."},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),replaceIdentity:async(e,t)=>await this.#n({type:"operation",description:"Replace account identity",token:"account.details.identity.update",method:"PUT",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 20 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove. Min 2 characters, max 32. Allowed characters (lowercase as well): A–Z `',-.,` and `ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞSŸ`",type:"string | null",required:!0}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),listEmails:async()=>await this.#n({type:"operation",description:"List account e-mail addresses",token:"account.details.email.list",method:"GET",path:"/account/email",parameters:{},returns:[{status:200,type:"AccountEmail[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getEmail:async()=>await this.#n({type:"operation",description:"Get your primary e-mail address",token:"account.details.email",method:"GET",path:"/account/email/primary",parameters:{},returns:[{status:200,type:"DatedPrimaryEmail"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),setEmail:async e=>await this.#n({type:"operation",description:"Set your primary e-mail address",token:"account.details.email.update",method:"PUT",path:"/account/email/primary",parameters:{body:{email:{description:"E-mail address to set as primary.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{email:e}),changePassword:async(e,t)=>await this.#n({type:"operation",description:"Change account password",token:"account.details.password.update",method:"PUT",path:"/account/password",parameters:{body:{currentPassword:{description:"Your current password.",type:"string",required:!0},newPassword:{description:"The new password. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{currentPassword:e,newPassword:t}),listPermissions:async()=>await this.#n({type:"operation",description:"List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description.",token:"account.details",method:"GET",path:"/account/permissions",parameters:{},returns:[{status:200,type:"Permission[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})};projects={list:async(e=20,t=1)=>await this.#n({type:"operation",description:"List projects",token:"projects.get.own",method:"GET",path:"/projects",parameters:{query:{limit:{description:"The number of projects to return per page. No more than 100.",default:"20",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Project[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),create:async e=>await this.#n({type:"operation",description:"Create a project",token:"projects.create.own",method:"POST",path:"/projects",parameters:{body:{name:{description:"Project name. Max 255 characters.",type:"string",required:!0}}},returns:[{status:201,type:"Project"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{name:e}),get:async e=>await this.#n({type:"operation",description:"Get a project",token:"projects.get.own",method:"GET",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}}},returns:[{status:200,type:"Project"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),update:async(e,t)=>await this.#n({type:"operation",description:"Update a project",token:"projects.update.own",method:"PATCH",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}},body:{name:{description:"Project name. Max 255 characters.",type:"string",required:!0}}},returns:[{status:200,type:"Project"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{name:t}),delete:async e=>await this.#n({type:"operation",description:"Delete a project",token:"projects.delete.own",method:"DELETE",path:"/projects/:id",parameters:{path:{id:{description:"Project ID",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{})}}!function(e){let t;e.RawResponse=class{headers;ok;redirected;status;statusText;url;request;constructor(e,t){this.headers=Object.fromEntries([...e.headers.entries()].map((([e,t])=>[e.toLowerCase(),t]))),this.ok=e.ok,this.redirected=e.redirected,this.status=e.status,this.statusText=e.statusText,this.url=new URL(e.url),this.request=t}},function(e){e.ApiResponse=class{#p;constructor(e){this.#p=e}get _response(){return this.#p}}}(t=e.R||(e.R={})),e.makeApiResponse=function(e,r){return Object.assign(new t.ApiResponse(r),e)}}(Cloudnode||(Cloudnode={})); \ No newline at end of file diff --git a/schema.json b/schema.json index a908a02..aea53f8 100644 --- a/schema.json +++ b/schema.json @@ -689,7 +689,7 @@ } } }, - "token": { + "tokens": { "type": "namespace", "operations": { "list": { @@ -697,7 +697,7 @@ "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" }, { diff --git a/src/Cloudnode.d.ts b/src/Cloudnode.d.ts index 71ad1af..8601deb 100644 --- a/src/Cloudnode.d.ts +++ b/src/Cloudnode.d.ts @@ -116,10 +116,10 @@ declare class Cloudnode { */ readonly delete: (id: string) => Promise>; }; - 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>>; /** * 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>; /** * 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>; /** * 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>; /** * 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,11 +188,12 @@ declare class Cloudnode { readonly listRequests: (id: string | "current", limit?: number, page?: number) => Promise>>; /** * 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"}} @@ -200,11 +201,10 @@ declare class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ readonly getRequest: (id: string | "current", request: string) => Promise>; - }; - 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"}} @@ -212,7 +212,7 @@ declare class Cloudnode { * @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}} * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ - readonly refresh: () => Promise>; + readonly refresh: (id: string | "current") => Promise>; }; auth: { /** diff --git a/src/Cloudnode.js b/src/Cloudnode.js index 51ddd6f..c34e494 100644 --- a/src/Cloudnode.js +++ b/src/Cloudnode.js @@ -303,10 +303,10 @@ class Cloudnode { return await this.#sendRequest({ "type": "operation", "description": "Unsubscribe from newsletter", "method": "DELETE", "path": "/subscriptions/:id", "parameters": { "path": { "id": { "description": "The ID of the subscription to revoke", "type": "string", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, }; - 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. @@ -317,11 +317,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ list: async (limit = 10, page = 1, internal) => { - return await this.#sendRequest({ "type": "operation", "description": "List tokens of user", "token": "tokens.list.own", "method": "GET", "path": "/token", "parameters": { "query": { "limit": { "description": "The number of tokens to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false }, "internal": { "description": "Internal tokens are returned as well if this parameter is present.", "type": "any", "required": false } } }, "returns": [{ "status": 200, "type": "PartialToken[]" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, { limit: `${limit}`, page: `${page}`, internal: `${internal}` }, {}); + return await this.#sendRequest({ "type": "operation", "description": "List tokens of user", "token": "tokens.list.own", "method": "GET", "path": "/tokens", "parameters": { "query": { "limit": { "description": "The number of tokens to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false }, "internal": { "description": "Internal tokens are returned as well if this parameter is present.", "type": "any", "required": false } } }, "returns": [{ "status": 200, "type": "PartialToken[]" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, { limit: `${limit}`, page: `${page}`, internal: `${internal}` }, {}); }, /** * 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. @@ -333,11 +333,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ create: async (permissions, lifetime, note) => { - return await this.#sendRequest({ "type": "operation", "description": "Create token", "token": "tokens.create.own", "method": "POST", "path": "/token", "parameters": { "body": { "permissions": { "description": "List of permissions to grant to the token. You must already have each of these permissions with your current token.", "type": "string[]", "required": true }, "lifetime": { "description": "Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).", "type": "number", "required": true }, "note": { "description": "A user-specified note to label the token. Max length: 2⁸ (256) characters.", "type": "string", "required": false } } }, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { permissions, lifetime, note }); + return await this.#sendRequest({ "type": "operation", "description": "Create token", "token": "tokens.create.own", "method": "POST", "path": "/tokens", "parameters": { "body": { "permissions": { "description": "List of permissions to grant to the token. You must already have each of these permissions with your current token.", "type": "string[]", "required": true }, "lifetime": { "description": "Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).", "type": "number", "required": true }, "note": { "description": "A user-specified note to label the token. Max length: 2⁸ (256) characters.", "type": "string", "required": false } } }, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { permissions, lifetime, note }); }, /** * 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"}} @@ -348,11 +348,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ get: async (id) => { - return await this.#sendRequest({ "type": "operation", "description": "Get token details", "token": "tokens.get.own", "method": "GET", "path": "/token/:id", "parameters": { "path": { "id": { "description": "The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 200, "type": "Token" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get token details", "token": "tokens.get.own", "method": "GET", "path": "/tokens/:id", "parameters": { "path": { "id": { "description": "The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 200, "type": "Token" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, /** * 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"}} @@ -364,11 +364,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ revoke: async (id) => { - return await this.#sendRequest({ "type": "operation", "description": "Revoke token", "token": "tokens.revoke.own", "method": "DELETE", "path": "/token/:id", "parameters": { "path": { "id": { "description": "The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 400, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Revoke token", "token": "tokens.revoke.own", "method": "DELETE", "path": "/tokens/:id", "parameters": { "path": { "id": { "description": "The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } } }, "returns": [{ "status": 204, "type": "void" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 423, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, /** * 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). @@ -381,15 +381,16 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ listRequests: async (id, limit = 10, page = 1) => { - return await this.#sendRequest({ "type": "operation", "description": "Get list of recent requests made with the token", "token": "tokens.get.own.requests", "method": "GET", "path": "/token/:id/requests", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } }, "query": { "limit": { "description": "The number of requests to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false } } }, "returns": [{ "status": 200, "type": "ShortRequest[]" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, { limit: `${limit}`, page: `${page}` }, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get list of recent requests made with the token", "token": "tokens.get.own.requests", "method": "GET", "path": "/tokens/:id/requests", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true } }, "query": { "limit": { "description": "The number of requests to return per page. No more than 50.", "default": "10", "type": "number", "required": false }, "page": { "description": "The page number. No more than 2³² (4294967296).", "default": "1", "type": "number", "required": false } } }, "returns": [{ "status": 200, "type": "ShortRequest[]" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, { limit: `${limit}`, page: `${page}` }, {}); }, /** * 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"}} @@ -397,13 +398,12 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ getRequest: async (id, request) => { - return await this.#sendRequest({ "type": "operation", "description": "Get a recent request by ID", "token": "tokens.get.own.requests", "method": "GET", "path": "/token/:id/requests/:request", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true }, "request": { "description": "The ID of the request.", "type": "string", "required": true } } }, "returns": [{ "status": 200, "type": "Request" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}`, request: `${request}` }, {}, {}); + return await this.#sendRequest({ "type": "operation", "description": "Get a recent request by ID", "token": "tokens.get.own.requests", "method": "GET", "path": "/tokens/:id/requests/:request", "parameters": { "path": { "id": { "description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.", "type": "string | \"current\"", "required": true }, "request": { "description": "The ID of the request.", "type": "string", "required": true } } }, "returns": [{ "status": 200, "type": "Request" }, { "status": 404, "type": "Error & {code: \"RESOURCE_NOT_FOUND\"}" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 423, "type": "Error & {code: \"MODIFICATION_NOT_ALLOWED\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}`, request: `${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"}} @@ -411,8 +411,8 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}} * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ - refresh: async () => { - return await this.#sendRequest({ "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": {}, "returns": [{ "status": 201, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, {}); + refresh: async (id) => { + return await this.#sendRequest({ "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": "/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": 200, "type": "Token" }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 401, "type": "Error & {code: \"UNAUTHORIZED\"}" }, { "status": 403, "type": "Error & {code: \"NO_PERMISSION\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, { id: `${id}` }, {}, {}); }, }; auth = { diff --git a/src/Cloudnode.ts b/src/Cloudnode.ts index 74f3ac1..09a6ad9 100644 --- a/src/Cloudnode.ts +++ b/src/Cloudnode.ts @@ -317,10 +317,10 @@ class Cloudnode { return await this.#sendRequest({"type":"operation","description":"Unsubscribe from newsletter","method":"DELETE","path":"/subscriptions/:id","parameters":{"path":{"id":{"description":"The ID of the subscription to revoke","type":"string","required":true}}},"returns":[{"status":204,"type":"void"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); }, } as const; - public token = { + public 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. @@ -331,11 +331,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ list: async (limit: number = 10, page: number = 1, internal?: any): Promise>> => { - return await this.#sendRequest>({"type":"operation","description":"List tokens of user","token":"tokens.list.own","method":"GET","path":"/token","parameters":{"query":{"limit":{"description":"The number of tokens to return per page. No more than 50.","default":"10","type":"number","required":false},"page":{"description":"The page number. No more than 2³² (4294967296).","default":"1","type":"number","required":false},"internal":{"description":"Internal tokens are returned as well if this parameter is present.","type":"any","required":false}}},"returns":[{"status":200,"type":"PartialToken[]"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {}, {limit: `${limit}`, page: `${page}`, internal: `${internal}`}, {}); + return await this.#sendRequest>({"type":"operation","description":"List tokens of user","token":"tokens.list.own","method":"GET","path":"/tokens","parameters":{"query":{"limit":{"description":"The number of tokens to return per page. No more than 50.","default":"10","type":"number","required":false},"page":{"description":"The page number. No more than 2³² (4294967296).","default":"1","type":"number","required":false},"internal":{"description":"Internal tokens are returned as well if this parameter is present.","type":"any","required":false}}},"returns":[{"status":200,"type":"PartialToken[]"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {}, {limit: `${limit}`, page: `${page}`, internal: `${internal}`}, {}); }, /** * 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. @@ -347,11 +347,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ create: async (permissions: string[], lifetime: number, note?: string): Promise> => { - return await this.#sendRequest({"type":"operation","description":"Create token","token":"tokens.create.own","method":"POST","path":"/token","parameters":{"body":{"permissions":{"description":"List of permissions to grant to the token. You must already have each of these permissions with your current token.","type":"string[]","required":true},"lifetime":{"description":"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).","type":"number","required":true},"note":{"description":"A user-specified note to label the token. Max length: 2⁸ (256) characters.","type":"string","required":false}}},"returns":[{"status":201,"type":"Token"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {}, {}, {permissions, lifetime, note}); + return await this.#sendRequest({"type":"operation","description":"Create token","token":"tokens.create.own","method":"POST","path":"/tokens","parameters":{"body":{"permissions":{"description":"List of permissions to grant to the token. You must already have each of these permissions with your current token.","type":"string[]","required":true},"lifetime":{"description":"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).","type":"number","required":true},"note":{"description":"A user-specified note to label the token. Max length: 2⁸ (256) characters.","type":"string","required":false}}},"returns":[{"status":201,"type":"Token"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {}, {}, {permissions, lifetime, note}); }, /** * 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"}} @@ -362,11 +362,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ get: async (id: string | "current"): Promise> => { - return await this.#sendRequest({"type":"operation","description":"Get token details","token":"tokens.get.own","method":"GET","path":"/token/:id","parameters":{"path":{"id":{"description":"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true}}},"returns":[{"status":200,"type":"Token"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); + return await this.#sendRequest({"type":"operation","description":"Get token details","token":"tokens.get.own","method":"GET","path":"/tokens/:id","parameters":{"path":{"id":{"description":"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true}}},"returns":[{"status":200,"type":"Token"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); }, /** * 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"}} @@ -378,11 +378,11 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ revoke: async (id: string | "current"): Promise> => { - return await this.#sendRequest({"type":"operation","description":"Revoke token","token":"tokens.revoke.own","method":"DELETE","path":"/token/:id","parameters":{"path":{"id":{"description":"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.","type":"string | \"current\"","required":true}}},"returns":[{"status":204,"type":"void"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":400,"type":"Error & {code: \"MODIFICATION_NOT_ALLOWED\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); + return await this.#sendRequest({"type":"operation","description":"Revoke token","token":"tokens.revoke.own","method":"DELETE","path":"/tokens/:id","parameters":{"path":{"id":{"description":"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.","type":"string | \"current\"","required":true}}},"returns":[{"status":204,"type":"void"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":423,"type":"Error & {code: \"MODIFICATION_NOT_ALLOWED\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); }, /** * 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). @@ -395,15 +395,16 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ listRequests: async (id: string | "current", limit: number = 10, page: number = 1): Promise>> => { - return await this.#sendRequest>({"type":"operation","description":"Get list of recent requests made with the token","token":"tokens.get.own.requests","method":"GET","path":"/token/:id/requests","parameters":{"path":{"id":{"description":"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true}},"query":{"limit":{"description":"The number of requests to return per page. No more than 50.","default":"10","type":"number","required":false},"page":{"description":"The page number. No more than 2³² (4294967296).","default":"1","type":"number","required":false}}},"returns":[{"status":200,"type":"ShortRequest[]"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {limit: `${limit}`, page: `${page}`}, {}); + return await this.#sendRequest>({"type":"operation","description":"Get list of recent requests made with the token","token":"tokens.get.own.requests","method":"GET","path":"/tokens/:id/requests","parameters":{"path":{"id":{"description":"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true}},"query":{"limit":{"description":"The number of requests to return per page. No more than 50.","default":"10","type":"number","required":false},"page":{"description":"The page number. No more than 2³² (4294967296).","default":"1","type":"number","required":false}}},"returns":[{"status":200,"type":"ShortRequest[]"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {limit: `${limit}`, page: `${page}`}, {}); }, /** * 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"}} @@ -411,13 +412,12 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ getRequest: async (id: string | "current", request: string): Promise> => { - return await this.#sendRequest({"type":"operation","description":"Get a recent request by ID","token":"tokens.get.own.requests","method":"GET","path":"/token/:id/requests/:request","parameters":{"path":{"id":{"description":"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true},"request":{"description":"The ID of the request.","type":"string","required":true}}},"returns":[{"status":200,"type":"Request"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`, request: `${request}`}, {}, {}); + return await this.#sendRequest({"type":"operation","description":"Get a recent request by ID","token":"tokens.get.own.requests","method":"GET","path":"/tokens/:id/requests/:request","parameters":{"path":{"id":{"description":"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.","type":"string | \"current\"","required":true},"request":{"description":"The ID of the request.","type":"string","required":true}}},"returns":[{"status":200,"type":"Request"},{"status":404,"type":"Error & {code: \"RESOURCE_NOT_FOUND\"}"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":423,"type":"Error & {code: \"MODIFICATION_NOT_ALLOWED\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`, request: `${request}`}, {}, {}); }, - } as const; - public 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"}} @@ -425,8 +425,8 @@ class Cloudnode { * @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}} * @throws {Cloudnode.Error & {code: "MAINTENANCE"}} */ - refresh: async (): Promise> => { - return await this.#sendRequest({"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":{},"returns":[{"status":201,"type":"Token"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {}, {}, {}); + refresh: async (id: string | "current"): Promise> => { + return await this.#sendRequest({"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":"/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":200,"type":"Token"},{"status":422,"type":"Error & {code: \"INVALID_DATA\"}"},{"status":401,"type":"Error & {code: \"UNAUTHORIZED\"}"},{"status":403,"type":"Error & {code: \"NO_PERMISSION\"}"},{"status":429,"type":"Error & {code: \"RATE_LIMITED\"}"},{"status":500,"type":"Error & {code: \"INTERNAL_SERVER_ERROR\"}"},{"status":503,"type":"Error & {code: \"MAINTENANCE\"}"}]}, {id: `${id}`}, {}, {}); }, } as const; public auth = {