Skip to content

Commit 807b7b6

Browse files
author
William Duncan
committed
get recent request by id
1 parent 2c3f128 commit 807b7b6

File tree

7 files changed

+339
-1
lines changed

7 files changed

+339
-1
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ console.log(newsletter._response.status); // 200
9595
- [`cloudnode.newsletters.unsubscribe(subscription)`](#cloudnodenewslettersunsubscribesubscription)
9696
- [`cloudnode.token.create(permissions, lifetime, [note])`](#cloudnodetokencreatepermissions-lifetime-note)
9797
- [`cloudnode.token.get(id)`](#cloudnodetokengetid)
98+
- [`cloudnode.token.getRequest(id, request)`](#cloudnodetokengetrequestid-request)
9899
- [`cloudnode.token.list([limit], [page], [internal])`](#cloudnodetokenlistlimit-page-internal)
99100
- [`cloudnode.token.listRequests(id, [limit], [page])`](#cloudnodetokenlistrequestsid-limit-page)
100101
- [`cloudnode.token.revoke(id)`](#cloudnodetokenrevokeid)
@@ -117,6 +118,7 @@ console.log(newsletter._response.status); // 200
117118
- [Interface: `Cloudnode.PartialToken`](#interface-cloudnodepartialtoken)
118119
- [Interface: `Cloudnode.Permission`](#interface-cloudnodepermission)
119120
- [Interface: `Cloudnode.PrimaryEmail`](#interface-cloudnodeprimaryemail)
121+
- [Interface: `Cloudnode.Request`](#interface-cloudnoderequest)
120122
- [Interface: `Cloudnode.ShortRequest`](#interface-cloudnodeshortrequest)
121123
- [Interface: `Cloudnode.Token`](#interface-cloudnodetoken)
122124
- [Interface: `Cloudnode.TokenMetadata`](#interface-cloudnodetokenmetadata)
@@ -462,6 +464,23 @@ Get token details
462464
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
463465
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>
464466

467+
<a name="cloudnodetokengetrequestid-request"></a>
468+
469+
### `cloudnode.token.getRequest(id, request)`
470+
471+
Get a recent request by ID
472+
473+
- `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.
474+
- `request` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The ID of the request.
475+
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.ApiResponse](#class-cloudnodeapiresponset)&lt;[Cloudnode.Request](#interface-cloudnoderequest)>></code>
476+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RESOURCE_NOT_FOUND"}</code>
477+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INVALID_DATA"}</code>
478+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "UNAUTHORIZED"}</code>
479+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "NO_PERMISSION"}</code>
480+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "RATE_LIMITED"}</code>
481+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "INTERNAL_SERVER_ERROR"}</code>
482+
- Throws: <code>[Cloudnode.Error](#interface-cloudnodeerror) & {code: "MAINTENANCE"}</code>
483+
465484
<a name="cloudnodetokenlistlimit-page-internal"></a>
466485

467486
### `cloudnode.token.list([limit], [page], [internal])`
@@ -712,6 +731,27 @@ Your current primary account e-mail address
712731
- `address` <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 primary e-mail address. May ben null if anonymised.
713732
- `verified` <code>[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)</code> Whether this e-mail address has been verified
714733

734+
<a name="interface-cloudnoderequest"></a>
735+
736+
### Interface: `Cloudnode.Request`
737+
738+
A request
739+
740+
- `id` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The ID of the request
741+
- `method` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The request method (e.g. GET, POST, HEAD, etc.
742+
- `scheme` <code>"http" | "https"</code> The URL scheme
743+
- `host` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The requested host name
744+
- `url` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The request URL path
745+
- `status` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The HTTP status code that was returned to this request
746+
- `ip` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The IP address of the client that made the request (can be both IPv4 and IPv6)
747+
- `date` <code>[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)</code> The time when the request was received
748+
- `responseTime` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The time in milliseconds that the request took to process
749+
- `hasEvents` <code>[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)</code> Whether any server-side error events occurred while processing this request
750+
- `requestHeaders` <code>[Record](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [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> The request headers that were received
751+
- `requestBody` <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> The request body that was received (likely parsed and formatted as JSON)
752+
- `responseHeaders` <code>[Record](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [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> The headers that were returned by the server
753+
- `responseBody` <code>{type: "Buffer", data: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)[]} | [null](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/null)</code> The response body that was returned by the server in response to this request
754+
715755
<a name="interface-cloudnodeshortrequest"></a>
716756

717757
### Interface: `Cloudnode.ShortRequest`

browser/Cloudnode.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,22 @@ class Cloudnode {
336336
listRequests: async (id, limit = 10, page = 1) => {
337337
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}` }, {});
338338
},
339+
/**
340+
* Get a recent request by ID
341+
* @GET /token/:id/requests/:request
342+
* @param id The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
343+
* @param request The ID of the request.
344+
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
345+
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
346+
* @throws {Cloudnode.Error & {code: "UNAUTHORIZED"}}
347+
* @throws {Cloudnode.Error & {code: "NO_PERMISSION"}}
348+
* @throws {Cloudnode.Error & {code: "RATE_LIMITED"}}
349+
* @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}}
350+
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
351+
*/
352+
getRequest: async (id, request) => {
353+
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}` }, {}, {});
354+
},
339355
};
340356
tokens = {
341357
/**

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.

schema.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,82 @@
404404
"type": "boolean"
405405
}
406406
]
407+
},
408+
{
409+
"name": "Request",
410+
"description": "A request",
411+
"fields": [
412+
{
413+
"name": "id",
414+
"description": "The ID of the request",
415+
"type": "string"
416+
},
417+
{
418+
"name": "method",
419+
"description": "The request method (e.g. GET, POST, HEAD, etc.",
420+
"type": "string"
421+
},
422+
{
423+
"name": "scheme",
424+
"description": "The URL scheme",
425+
"type": "\"http\" | \"https\""
426+
},
427+
{
428+
"name": "host",
429+
"description": "The requested host name",
430+
"type": "string"
431+
},
432+
{
433+
"name": "url",
434+
"description": "The request URL path",
435+
"type": "string"
436+
},
437+
{
438+
"name": "status",
439+
"description": "The HTTP status code that was returned to this request",
440+
"type": "number"
441+
},
442+
{
443+
"name": "ip",
444+
"description": "The IP address of the client that made the request (can be both IPv4 and IPv6)",
445+
"type": "string"
446+
},
447+
{
448+
"name": "date",
449+
"description": "The time when the request was received",
450+
"type": "Date"
451+
},
452+
{
453+
"name": "responseTime",
454+
"description": "The time in milliseconds that the request took to process",
455+
"type": "number"
456+
},
457+
{
458+
"name": "hasEvents",
459+
"description": "Whether any server-side error events occurred while processing this request",
460+
"type": "boolean"
461+
},
462+
{
463+
"name": "requestHeaders",
464+
"description": "The request headers that were received",
465+
"type": "Record<string, string> | null"
466+
},
467+
{
468+
"name": "requestBody",
469+
"description": "The request body that was received (likely parsed and formatted as JSON)",
470+
"type": "string | null"
471+
},
472+
{
473+
"name": "responseHeaders",
474+
"description": "The headers that were returned by the server",
475+
"type": "Record<string, string> | null"
476+
},
477+
{
478+
"name": "responseBody",
479+
"description": "The response body that was returned by the server in response to this request",
480+
"type": "{type: \"Buffer\", data: number[]} | null"
481+
}
482+
]
407483
}
408484
],
409485
"operations": {
@@ -753,6 +829,41 @@
753829
"type": "Error & {code: \"INVALID_DATA\"}"
754830
}
755831
]
832+
},
833+
"getRequest": {
834+
"type": "operation",
835+
"description": "Get a recent request by ID",
836+
"token": "tokens.get.own.requests",
837+
"method": "GET",
838+
"path": "/token/:id/requests/:request",
839+
"parameters": {
840+
"path": {
841+
"id": {
842+
"description": "The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",
843+
"type": "string | \"current\"",
844+
"required": true
845+
},
846+
"request": {
847+
"description": "The ID of the request.",
848+
"type": "string",
849+
"required": true
850+
}
851+
}
852+
},
853+
"returns": [
854+
{
855+
"status": 200,
856+
"type": "Request"
857+
},
858+
{
859+
"status": 404,
860+
"type": "Error & {code: \"RESOURCE_NOT_FOUND\"}"
861+
},
862+
{
863+
"status": 422,
864+
"type": "Error & {code: \"INVALID_DATA\"}"
865+
}
866+
]
756867
}
757868
}
758869
},

src/Cloudnode.d.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ declare class Cloudnode {
172172
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
173173
*/
174174
readonly listRequests: (id: string | "current", limit?: number, page?: number) => Promise<Cloudnode.ApiResponse<Cloudnode.PaginatedData<Cloudnode.ShortRequest[]>>>;
175+
/**
176+
* Get a recent request by ID
177+
* @GET /token/:id/requests/:request
178+
* @param id The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
179+
* @param request The ID of the request.
180+
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
181+
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
182+
* @throws {Cloudnode.Error & {code: "UNAUTHORIZED"}}
183+
* @throws {Cloudnode.Error & {code: "NO_PERMISSION"}}
184+
* @throws {Cloudnode.Error & {code: "RATE_LIMITED"}}
185+
* @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}}
186+
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
187+
*/
188+
readonly getRequest: (id: string | "current", request: string) => Promise<Cloudnode.ApiResponse<Cloudnode.Request>>;
175189
};
176190
tokens: {
177191
/**
@@ -662,6 +676,70 @@ declare namespace Cloudnode {
662676
*/
663677
hasEvents: boolean;
664678
}
679+
/**
680+
* A request
681+
*/
682+
interface Request {
683+
/**
684+
* The ID of the request
685+
*/
686+
id: string;
687+
/**
688+
* The request method (e.g. GET, POST, HEAD, etc.
689+
*/
690+
method: string;
691+
/**
692+
* The URL scheme
693+
*/
694+
scheme: "http" | "https";
695+
/**
696+
* The requested host name
697+
*/
698+
host: string;
699+
/**
700+
* The request URL path
701+
*/
702+
url: string;
703+
/**
704+
* The HTTP status code that was returned to this request
705+
*/
706+
status: number;
707+
/**
708+
* The IP address of the client that made the request (can be both IPv4 and IPv6)
709+
*/
710+
ip: string;
711+
/**
712+
* The time when the request was received
713+
*/
714+
date: Date;
715+
/**
716+
* The time in milliseconds that the request took to process
717+
*/
718+
responseTime: number;
719+
/**
720+
* Whether any server-side error events occurred while processing this request
721+
*/
722+
hasEvents: boolean;
723+
/**
724+
* The request headers that were received
725+
*/
726+
requestHeaders: Record<string, string> | null;
727+
/**
728+
* The request body that was received (likely parsed and formatted as JSON)
729+
*/
730+
requestBody: string | null;
731+
/**
732+
* The headers that were returned by the server
733+
*/
734+
responseHeaders: Record<string, string> | null;
735+
/**
736+
* The response body that was returned by the server in response to this request
737+
*/
738+
responseBody: {
739+
type: "Buffer";
740+
data: number[];
741+
} | null;
742+
}
665743
/**
666744
* Paginated response
667745
*/

src/Cloudnode.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,22 @@ class Cloudnode {
336336
listRequests: async (id, limit = 10, page = 1) => {
337337
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}` }, {});
338338
},
339+
/**
340+
* Get a recent request by ID
341+
* @GET /token/:id/requests/:request
342+
* @param id The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.
343+
* @param request The ID of the request.
344+
* @throws {Cloudnode.Error & {code: "RESOURCE_NOT_FOUND"}}
345+
* @throws {Cloudnode.Error & {code: "INVALID_DATA"}}
346+
* @throws {Cloudnode.Error & {code: "UNAUTHORIZED"}}
347+
* @throws {Cloudnode.Error & {code: "NO_PERMISSION"}}
348+
* @throws {Cloudnode.Error & {code: "RATE_LIMITED"}}
349+
* @throws {Cloudnode.Error & {code: "INTERNAL_SERVER_ERROR"}}
350+
* @throws {Cloudnode.Error & {code: "MAINTENANCE"}}
351+
*/
352+
getRequest: async (id, request) => {
353+
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}` }, {}, {});
354+
},
339355
};
340356
tokens = {
341357
/**

0 commit comments

Comments
 (0)