Skip to content

Commit b2f2cad

Browse files
author
williamd5
authored
Merge pull request #72 from cloudnode-pro/token-info
Token info in docs and credentials: include fix on login & register
2 parents 9409953 + 23c7b5f commit b2f2cad

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Check compatibility with the API
199199

200200
### `cloudnode.account.changePassword(currentPassword, newPassword)`
201201

202-
Change account password
202+
Change account password. Requires token with scope `account.details.password.update`.
203203

204204
- `currentPassword` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your current password.
205205
- `newPassword` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The new password. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.
@@ -215,7 +215,7 @@ Change account password
215215

216216
### `cloudnode.account.get()`
217217

218-
Get account details
218+
Get account details. Requires token with scope `account.details`.
219219

220220

221221
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.AccountDetails](#interface-cloudnodeaccountdetails)>></code>
@@ -229,7 +229,7 @@ Get account details
229229

230230
### `cloudnode.account.getEmail()`
231231

232-
Get your primary e-mail address
232+
Get your primary e-mail address. Requires token with scope `account.details.email`.
233233

234234

235235
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.DatedPrimaryEmail](#interface-cloudnodedatedprimaryemail)>></code>
@@ -244,7 +244,7 @@ Get your primary e-mail address
244244

245245
### `cloudnode.account.getIdentity()`
246246

247-
Get account identity
247+
Get account identity. Requires token with scope `account.details.identity`.
248248

249249

250250
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.AccountIdentity](#interface-cloudnodeaccountidentity)>></code>
@@ -259,7 +259,7 @@ Get account identity
259259

260260
### `cloudnode.account.listEmails()`
261261

262-
List account e-mail addresses
262+
List account e-mail addresses. Requires token with scope `account.details.email.list`.
263263

264264

265265
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.PaginatedData](#interface-cloudnodepaginateddatat)&lt;[Cloudnode.AccountEmail[]](#interface-cloudnodeaccountemail)>>></code>
@@ -273,7 +273,7 @@ List account e-mail addresses
273273

274274
### `cloudnode.account.listPermissions()`
275275

276-
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.
276+
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. Requires token with scope `account.details`.
277277

278278

279279
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.PaginatedData](#interface-cloudnodepaginateddatat)&lt;[Cloudnode.Permission[]](#interface-cloudnodepermission)>>></code>
@@ -287,7 +287,7 @@ List account permissions with user-friendly descriptions. Some permissions (such
287287

288288
### `cloudnode.account.replaceIdentity(username, name)`
289289

290-
Replace account identity
290+
Replace account identity. Requires token with scope `account.details.identity.update`.
291291

292292
- `username` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.
293293
- `name` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [null](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/null)</code> Your full name. Set to `null` to remove.
@@ -305,7 +305,7 @@ Replace account identity
305305

306306
### `cloudnode.account.setEmail(email)`
307307

308-
Set your primary e-mail address
308+
Set your primary e-mail address. Requires token with scope `account.details.email.update`.
309309

310310
- `email` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> E-mail address to set as primary.
311311
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>></code>
@@ -321,7 +321,7 @@ Set your primary e-mail address
321321

322322
### `cloudnode.account.updateIdentity(username, [name])`
323323

324-
Update account identity
324+
Update account identity. Requires token with scope `account.details.identity.update`.
325325

326326
- `username` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.
327327
- `name` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [null](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/null)</code> Your full name. Set to `null` to remove.
@@ -417,7 +417,7 @@ Subscribe to newsletter
417417

418418
### `cloudnode.newsletters.listSubscriptions([limit], [page])`
419419

420-
List subscriptions of the authenticated user
420+
List subscriptions of the authenticated user. Requires token with scope `newsletter.subscriptions.list.own`.
421421

422422
- `limit` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The number of subscriptions to return per page. No more than 50. Default: `10`
423423
- `page` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The page number. No more than 2³² (4294967296). Default: `1`
@@ -446,7 +446,7 @@ Revoke a subscription (unsubscribe)
446446

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

449-
Create token
449+
Create token. Requires token with scope `tokens.create.own`.
450450

451451
- `permissions` <code>[string[]](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> List of permissions to grant to the token. You must already have each of these permissions with your current token.
452452
- `lifetime` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).
@@ -463,7 +463,7 @@ Create token
463463

464464
### `cloudnode.token.get(id)`
465465

466-
Get token details
466+
Get token details. Requires token with scope `tokens.get.own`.
467467

468468
- `id` <code>string | "current"</code> The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.
469469
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Token](#interface-cloudnodetoken)>></code>
@@ -479,7 +479,7 @@ Get token details
479479

480480
### `cloudnode.token.getRequest(id, request)`
481481

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

484484
- `id` <code>string | "current"</code> The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
485485
- `request` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The ID of the request.
@@ -496,7 +496,7 @@ Get a recent request by ID
496496

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

499-
List tokens of user
499+
List tokens of user. Requires token with scope `tokens.list.own`.
500500

501501
- `limit` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The number of tokens to return per page. No more than 50. Default: `10`
502502
- `page` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The page number. No more than 2³² (4294967296). Default: `1`
@@ -512,7 +512,7 @@ List tokens of user
512512

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

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

517517
- `id` <code>string | "current"</code> The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
518518
- `limit` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The number of requests to return per page. No more than 50. Default: `10`
@@ -530,7 +530,7 @@ Get list of recent requests made with the token
530530

531531
### `cloudnode.token.revoke(id)`
532532

533-
Revoke token
533+
Revoke token. Requires token with scope `tokens.revoke.own`.
534534

535535
- `id` <code>string | "current"</code> The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.
536536
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[void](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)>></code>
@@ -547,7 +547,7 @@ Revoke token
547547

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

550-
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.
550+
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`.
551551

552552

553553
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Token](#interface-cloudnodetoken)>></code>

browser/Cloudnode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class Cloudnode {
422422
* @returns Session token. Also returned in `Set-Cookie` header.
423423
*/
424424
register: async (username, email, password) => {
425-
return await this.#sendRequest({ "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", "parameters": { "body": { "username": { "description": "The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "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": true } } }, "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, email, password });
425+
return await this.#sendRequest({ "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 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "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": true } } }, "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, email, password });
426426
},
427427
/**
428428
* Create a session using user ID/username/e-mail and password.
@@ -439,7 +439,7 @@ class Cloudnode {
439439
* @returns Session token. Also returned in `Set-Cookie` header.
440440
*/
441441
login: async (user, password) => {
442-
return await this.#sendRequest({ "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", "parameters": { "body": { "user": { "description": "User ID (starts with `user_`), username or e-mail address.", "type": "string", "required": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "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, password });
442+
return await this.#sendRequest({ "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": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "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, password });
443443
},
444444
};
445445
account = {

browser/Cloudnode.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/docs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
6969
const queryParams = Object.entries(operation.parameters.query ?? {}).map(([name, parameter]) => new DocSchema.Parameter(name, parameter.type, parameter.description, parameter.required, parameter.default));
7070
const bodyParams = Object.entries(operation.parameters.body ?? {}).map(([name, parameter]) => new DocSchema.Parameter(name, parameter.type, parameter.description, parameter.required, parameter.default));
7171
const params: DocSchema.Parameter[] = [...pathParams, ...queryParams, ...bodyParams];
72-
return new DocSchema.Method(config.instanceName + "." + operation.name, operation.description, params, returns, throws, undefined, config.name, true);
72+
const description = typeof operation.token === "string" ? `${operation.description}${[".", "?", "!"].includes(operation.description.slice(-1)) ? "" : "."} Requires token with scope \`${operation.token}\`.` : operation.description;
73+
return new DocSchema.Method(config.instanceName + "." + operation.name, description, params, returns, throws, undefined, config.name, true);
7374
});
7475
mainClass.properties.push(...operationMethods);
7576
mainClass.properties.sort((a, b) => a.displayName.localeCompare(b.displayName));

gen/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function addExtraReturns(schema: Schema): Schema {
5656
* @returns The modified operation
5757
*/
5858
function addExtraReturnsToOperation(operation: Schema.Operation): Schema.Operation {
59-
if (operation.token !== undefined)
59+
if (typeof operation.token === "string")
6060
operation.returns.push({
6161
status: 401,
6262
type: 'Error & {code: "UNAUTHORIZED"}'

schema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@
898898
"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.",
899899
"method": "POST",
900900
"path": "/auth/register",
901+
"token": null,
901902
"parameters": {
902903
"body": {
903904
"username": {
@@ -938,6 +939,7 @@
938939
"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.",
939940
"method": "POST",
940941
"path": "/auth/login",
942+
"token": null,
941943
"parameters": {
942944
"body": {
943945
"user": {

0 commit comments

Comments
 (0)