betterstackmanager 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/docs/classes/IncidentComment.md +14 -0
- package/docs/classes/Incidents.md +25 -0
- package/docs/readme.md +1 -0
- package/docs/upstream/Pagination.md +12 -0
- package/examples/acknowledgeIncident.js +1 -1
- package/examples/createIncident.js +1 -1
- package/examples/createIncidentComment.js +1 -1
- package/examples/getSingleIncident.js +1 -1
- package/examples/readme.md +1 -0
- package/examples/resolveIncident.js +1 -1
- package/package.json +1 -1
- package/src/etc/Incident.js +46 -0
- package/src/etc/IncidentComment.js +18 -0
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ There is a required node version, and it is `>= 6.0.0`.
|
|
|
9
9
|
You must clone this repository (or, at least, the `src` directory) and require the Client object.
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
const BSM = require('
|
|
13
|
-
const client = new BSM();
|
|
12
|
+
const BSM = require('betterstackmanager');
|
|
13
|
+
const client = new BSM.Client();
|
|
14
14
|
const config = require('./config.json');
|
|
15
15
|
|
|
16
16
|
client.login(config.token);
|
|
@@ -31,10 +31,11 @@ The documentation for this project is contained within the `docs` directory.
|
|
|
31
31
|
## Links
|
|
32
32
|
|
|
33
33
|
- [Documentation](https://codeberg.org/Cyanic76/BSM.js/src/branch/main/docs)
|
|
34
|
+
- [NPM](https://www.npmjs.com/package/betterstackmanager)
|
|
34
35
|
- [Discord server](https://cyanic.me/next)
|
|
35
36
|
|
|
36
37
|
## Contributing & Help
|
|
37
38
|
|
|
38
39
|
As always, if you're in need of help, don't hesitate to create a new issue or to [join my Discord server](https://cyanic.me/discord).
|
|
39
40
|
|
|
40
|
-
This project abides by the CCoC.
|
|
41
|
+
This project abides by the [CCoC](https://codeberg.org/Cyanic76/pages/src/branch/pages/CODE_OF_CONDUCT.md).
|
|
@@ -6,6 +6,8 @@ This is the point from which all incident comments can be managed.
|
|
|
6
6
|
|
|
7
7
|
> **Markdown is supported within comments.**
|
|
8
8
|
|
|
9
|
+
Methods: `create`, `get`, `getAll`, `update`.
|
|
10
|
+
|
|
9
11
|
## create(incidentId, incidentCommentText)
|
|
10
12
|
|
|
11
13
|
Add a comment to an existing incident.
|
|
@@ -33,6 +35,18 @@ This can return:
|
|
|
33
35
|
- HTTP 200 with the comment object if it was successful.
|
|
34
36
|
- HTTP 404 if the given comment or incident doesn't exist.
|
|
35
37
|
|
|
38
|
+
## getAll(incidentId)
|
|
39
|
+
|
|
40
|
+
Fetch all comments from an incident.
|
|
41
|
+
|
|
42
|
+
| Value | Type | Required | About |
|
|
43
|
+
|-|-|-|-|
|
|
44
|
+
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
45
|
+
|
|
46
|
+
This can return:
|
|
47
|
+
- HTTP 200 with an array of incident comments if it was successful.
|
|
48
|
+
- HTTP 404 if the given incident doesn't exist.
|
|
49
|
+
|
|
36
50
|
## update(incidentId, incidentCommentId, incidentCommentText)
|
|
37
51
|
|
|
38
52
|
Edit an existing comment on an incident.
|
|
@@ -6,6 +6,8 @@ This is the point from which all incidents can be managed.
|
|
|
6
6
|
|
|
7
7
|
Status updates can't be managed from here.
|
|
8
8
|
|
|
9
|
+
Methods: `acknowledge`, `create`, `escalate`, `get`, `remove`, `resolve`.
|
|
10
|
+
|
|
9
11
|
## `acknowledge`
|
|
10
12
|
|
|
11
13
|
`acknowledge(incidentId)`
|
|
@@ -116,3 +118,26 @@ This can return:
|
|
|
116
118
|
|
|
117
119
|
- HTTP 200 if it was successful,
|
|
118
120
|
- HTTP 409 if that incident was already resolved.
|
|
121
|
+
|
|
122
|
+
## `search`
|
|
123
|
+
|
|
124
|
+
`search(perPage, page, from, to, monitorId, heartbeatId, resolved, acknowledged, metadata)`
|
|
125
|
+
|
|
126
|
+
> Each value must be set, either as the required corresponding type, as `null` or `undefined`.
|
|
127
|
+
|
|
128
|
+
> This method supports **pagination**!
|
|
129
|
+
|
|
130
|
+
| Value | Type | Required | About |
|
|
131
|
+
|-|-|-|-|
|
|
132
|
+
| `perPage` | Number | true | Number of results to show. Maximum is 250. |
|
|
133
|
+
| `page` | Number | true | Page of results to show. |
|
|
134
|
+
| `from` | String | false | Specify the start date. |
|
|
135
|
+
| `to` | String | false | Specify the end date. |
|
|
136
|
+
| `monitorId` | Number | false | Specify the monitor ID. |
|
|
137
|
+
| `heartbeatId` | Number | false | Specify the heartbeat ID. |
|
|
138
|
+
| `resolved` | Boolean | false | Whether to query only resolved or unresolved incidents. |
|
|
139
|
+
| `acknowledged` | Boolean | false | Whether to query only incidents that are acknowledged or not. |
|
|
140
|
+
|
|
141
|
+
This can return:
|
|
142
|
+
|
|
143
|
+
- HTTP 200 with a list of incidents.
|
package/docs/readme.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Pagination
|
|
2
|
+
|
|
3
|
+
When getting a result from an method that support pagination, you may check the following properties.
|
|
4
|
+
|
|
5
|
+
| Property | Type | Description |
|
|
6
|
+
|-|-|-|
|
|
7
|
+
| `pagination.first` | String | URL to the first page of results. |
|
|
8
|
+
| `pagination.last` | String | URL to the last page of results. |
|
|
9
|
+
| `pagination.prev` | String|null | URL to the previous page of results. If you're on the first page, you'll get `null`. |
|
|
10
|
+
| `pagination.next` | String|null | URL to the next page of results. If you're on the last page, you'll get `null`. |
|
|
11
|
+
|
|
12
|
+
See [upstream documentation](https://betterstack.com/docs/uptime/api/pagination).
|
package/examples/readme.md
CHANGED
package/package.json
CHANGED
package/src/etc/Incident.js
CHANGED
|
@@ -68,6 +68,52 @@ class Incidents {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Query bulk incidents.
|
|
73
|
+
* @param {Number} perPage
|
|
74
|
+
* @param {Number} page
|
|
75
|
+
* @param {String} from
|
|
76
|
+
* @param {String} to
|
|
77
|
+
* @param {Number} monitorId
|
|
78
|
+
* @param {Number} heartbeatId
|
|
79
|
+
* @param {Boolean} resolved
|
|
80
|
+
* @param {Boolean} acknowledged
|
|
81
|
+
* @param {Object} metadata
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
async search(perPage, page, from, to, monitorId, heartbeatId, resolved, acknowledged, metadata) {
|
|
85
|
+
|
|
86
|
+
// Test both timestamps against the YYYY-MM-DD format.
|
|
87
|
+
const dateRegEx = /(19[7-9]\d|20[0-3]\d)-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])/;
|
|
88
|
+
if(from != null && from != undefined && !from.match(dateRegEx) || to != null && to != undefined && !to.match(dateRegEx)) throw new Error("Incident search: Both timestamps must be formatted as YYYY-MM-DD.");
|
|
89
|
+
|
|
90
|
+
// Both following values are only boolean values.
|
|
91
|
+
if(monitorId != null && monitorId != undefined && isNaN(monitorId)) throw new Error("Incident search: Monitor ID must be a number.");
|
|
92
|
+
if(heartbeatId != null && heartbeatId != undefined && heartbeatId(monitorId)) throw new Error("Incident search: Monitor ID must be a number.");
|
|
93
|
+
|
|
94
|
+
// Both following values are only numbers.
|
|
95
|
+
if(perPage != null && perPage != undefined && isNaN(perPage) || page != null && page != null && isNaN(page)) throw new Error("Incident search: Page number and results must both be numbers.");
|
|
96
|
+
if(perPage != null && perPage != undefined && perPage < 1 || perPage != null && perPage != undefined && perPage > 250) throw new Error("Incident search: Can only get between 1 and 250 results.");
|
|
97
|
+
if(page != null && page != undefined && perPage < 1) throw new Error("Incident search: Page number must be a number.");
|
|
98
|
+
|
|
99
|
+
// Build our query with the params by only passing provided params.
|
|
100
|
+
const query = new URLSearchParams();
|
|
101
|
+
if(from != null && from != undefined) query.append('from', from);
|
|
102
|
+
if(to != null && to != undefined) query.append('to', to);
|
|
103
|
+
if(monitorId != null && monitorId != undefined) query.append('monitor_id', monitorId);
|
|
104
|
+
if(heartbeatId != null && heartbeatId != undefined) query.append('heartbeat_id', heartbeatId);
|
|
105
|
+
if(resolved == false || resolved == true) query.append('resolved', resolved);
|
|
106
|
+
if(acknowledged == false || acknowledged == true) query.append('acknowledged', acknowledged);
|
|
107
|
+
if(metadata != null && metadata != undefined) query.append('metadata', metadata);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
return await this.client.get(`/v3/incidents/?${query}`);
|
|
111
|
+
} catch(error) {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
71
117
|
/**
|
|
72
118
|
* Resolve an existing incident.
|
|
73
119
|
* @param {Number} incidentId
|
|
@@ -46,6 +46,24 @@ class IncidentComments {
|
|
|
46
46
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Get all comments on an incident.
|
|
51
|
+
* @param {Number} incidentId
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
async getAll(incidentId) {
|
|
55
|
+
|
|
56
|
+
if(!incidentId) throw new Error("Incident comment fetch: incidentId is a required options.");
|
|
57
|
+
if(isNaN(incidentId)) throw new Error("Incident comment fetch: incidentId must be a Number.");
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
return await this.client.get(`/v2/incidents/${incidentId}/comments`);
|
|
61
|
+
} catch(error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
49
67
|
/**
|
|
50
68
|
* Edit an existing incident comment.
|
|
51
69
|
* @param {Number} incidentId
|