@placeos/ts-client 4.3.1 → 4.4.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.3.1",
2
+ "version": "4.4.0",
3
3
  "license": "MIT",
4
4
  "name": "@placeos/ts-client",
5
5
  "author": "Alex Sorafumo <alex@place.tech>",
@@ -0,0 +1,44 @@
1
+ import { PlaceResource } from '../resources/resource';
2
+ import { TriggerConditions } from '../triggers/interfaces';
3
+ import { PlaceAlertDashboard } from './dashboard';
4
+
5
+ export type AlertSeverity = 'low' | 'medium' | 'high' | 'critical';
6
+ export type AlertType = 'threshold' | 'status' | 'custom';
7
+
8
+ export class PlaceAlert extends PlaceResource {
9
+ // Dashboard to show this alert on
10
+ public readonly alert_dashboard_id: string;
11
+ // Details of the dashboard assigned
12
+ public readonly alert_dashboard_details: PlaceAlertDashboard | undefined;
13
+ // Domain authority that the dashboard exists under
14
+ public readonly authority_id: string;
15
+ // Description of the dashboard's purpose
16
+ public readonly description: string;
17
+ // Whether the dashboard is enabled or not
18
+ public readonly enabled: boolean;
19
+ // Conditions for triggering the alert
20
+ public readonly conditions: TriggerConditions;
21
+ // Severity of the alert
22
+ public readonly severity: AlertSeverity;
23
+ // Type of the alert
24
+ public readonly alert_type: AlertType;
25
+ // How often should this alert should be raised when triggered
26
+ public readonly debounce_period: number;
27
+
28
+ constructor(data: Partial<PlaceAlert>) {
29
+ super(data);
30
+ this.authority_id = data.authority_id || '';
31
+ this.description = data.description || '';
32
+ this.enabled = data.enabled || false;
33
+ this.conditions = data.conditions || {
34
+ time_dependents: [],
35
+ comparisons: [],
36
+ };
37
+ this.severity = data.severity || 'low';
38
+ this.alert_type = data.alert_type || 'threshold';
39
+ this.debounce_period = data.debounce_period || 0;
40
+ this.alert_dashboard_id = data.alert_dashboard_id || '';
41
+ this.alert_dashboard_details =
42
+ data.alert_dashboard_details || undefined;
43
+ }
44
+ }
@@ -0,0 +1,17 @@
1
+ import { PlaceResource } from '../resources/resource';
2
+
3
+ export class PlaceAlertDashboard extends PlaceResource {
4
+ // Domain authority that the dashboard exists under
5
+ public readonly authority_id: string;
6
+ // Description of the dashboard's purpose
7
+ public readonly description: string;
8
+ // Whether the dashboard is enabled or not
9
+ public readonly enabled: boolean;
10
+
11
+ constructor(data: Partial<PlaceAlertDashboard>) {
12
+ super(data);
13
+ this.authority_id = data.authority_id || '';
14
+ this.description = data.description || '';
15
+ this.enabled = data.enabled || false;
16
+ }
17
+ }
@@ -0,0 +1,197 @@
1
+ import { create, query, remove, show, update } from '../api';
2
+ import { PlaceResourceQueryOptions } from '../resources/interface';
3
+ import { PlaceAlert } from './alert';
4
+ import { PlaceAlertDashboard } from './dashboard';
5
+
6
+ ///////////////////////////////////////////////////////////////
7
+ ///////////////////// Alert Dashboards ////////////////////
8
+ ///////////////////////////////////////////////////////////////
9
+
10
+ /**
11
+ * @private
12
+ */
13
+ const DASHBOARD_PATH = 'alert_dashboards';
14
+
15
+ /** Convert raw server data to an alert dashboard object */
16
+ function processDashboard(item: Partial<PlaceAlertDashboard>) {
17
+ return new PlaceAlertDashboard(item);
18
+ }
19
+
20
+ /**
21
+ * Query the available alert dashboards
22
+ * @param query_params Query parameters to add the to request URL
23
+ */
24
+ export function queryAlertDashboards(
25
+ query_params: PlaceResourceQueryOptions = {},
26
+ ) {
27
+ return query({
28
+ query_params,
29
+ fn: processDashboard,
30
+ path: DASHBOARD_PATH,
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Get the data for an alert dashboard
36
+ * @param id ID of the alert dashboard to retrieve
37
+ * @param query_params Query parameters to add the to request URL
38
+ */
39
+ export function showAlertDashboard(
40
+ id: string,
41
+ query_params: Record<string, any> = {},
42
+ ) {
43
+ return show({
44
+ id,
45
+ query_params,
46
+ fn: processDashboard,
47
+ path: DASHBOARD_PATH,
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Update the alert dashboard in the database
53
+ * @param id ID of the alert dashboard
54
+ * @param form_data New values for the alert dashboard
55
+ * @param query_params Query parameters to add the to request URL
56
+ * @param method HTTP verb to use on request. Defaults to `patch`
57
+ */
58
+ export function updateAlertDashboard(
59
+ id: string,
60
+ form_data: Partial<PlaceAlertDashboard>,
61
+ method: 'put' | 'patch' = 'patch',
62
+ ) {
63
+ return update({
64
+ id,
65
+ form_data,
66
+ query_params: {},
67
+ method,
68
+ fn: processDashboard,
69
+ path: DASHBOARD_PATH,
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Add a new alert dashboard to the database
75
+ * @param form_data Application data
76
+ * @param query_params Query parameters to add the to request URL
77
+ */
78
+ export function addAlertDashboard(form_data: Partial<PlaceAlertDashboard>) {
79
+ return create({
80
+ form_data,
81
+ query_params: {},
82
+ fn: processDashboard,
83
+ path: DASHBOARD_PATH,
84
+ });
85
+ }
86
+
87
+ /**
88
+ * Remove an alert dashboard from the database
89
+ * @param id ID of the alert dashboard
90
+ * @param query_params Query parameters to add the to request URL
91
+ */
92
+ export function removeAlertDashboard(
93
+ id: string,
94
+ query_params: Record<string, any> = {},
95
+ ) {
96
+ return remove({ id, query_params, path: DASHBOARD_PATH });
97
+ }
98
+
99
+ /**
100
+ * Get list of alerts for dashbaord
101
+ * @param id Alert dashboard ID
102
+ */
103
+ export function listDashboardAlerts(id: string) {
104
+ return query({
105
+ query_params: {},
106
+ fn: processAlert,
107
+ path: `${DASHBOARD_PATH}/${id}/alerts`,
108
+ });
109
+ }
110
+
111
+ ///////////////////////////////////////////////////////////////
112
+ ////////////////////////// Alerts /////////////////////////
113
+ ///////////////////////////////////////////////////////////////
114
+
115
+ /**
116
+ * @private
117
+ */
118
+ const ALERT_PATH = 'alerts';
119
+
120
+ /** Convert raw server data to an alert object */
121
+ function processAlert(item: Partial<PlaceAlert>) {
122
+ return new PlaceAlert(item);
123
+ }
124
+
125
+ /**
126
+ * Query the available alerts
127
+ * @param query_params Query parameters to add the to request URL
128
+ */
129
+ export function queryAlerts(query_params: PlaceResourceQueryOptions = {}) {
130
+ return query({
131
+ query_params,
132
+ fn: processAlert,
133
+ path: ALERT_PATH,
134
+ });
135
+ }
136
+
137
+ /**
138
+ * Get the data for an alert
139
+ * @param id ID of the alert to retrieve
140
+ * @param query_params Query parameters to add the to request URL
141
+ */
142
+ export function showAlert(id: string, query_params: Record<string, any> = {}) {
143
+ return show({
144
+ id,
145
+ query_params,
146
+ fn: processAlert,
147
+ path: ALERT_PATH,
148
+ });
149
+ }
150
+
151
+ /**
152
+ * Update the alert in the database
153
+ * @param id ID of the alert
154
+ * @param form_data New values for the alert
155
+ * @param query_params Query parameters to add the to request URL
156
+ * @param method HTTP verb to use on request. Defaults to `patch`
157
+ */
158
+ export function updateAlert(
159
+ id: string,
160
+ form_data: Partial<PlaceAlert>,
161
+ method: 'put' | 'patch' = 'patch',
162
+ ) {
163
+ return update({
164
+ id,
165
+ form_data,
166
+ query_params: {},
167
+ method,
168
+ fn: processAlert,
169
+ path: ALERT_PATH,
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Add a new alert to the database
175
+ * @param form_data Application data
176
+ * @param query_params Query parameters to add the to request URL
177
+ */
178
+ export function addAlert(form_data: Partial<PlaceAlert>) {
179
+ return create({
180
+ form_data,
181
+ query_params: {},
182
+ fn: processAlert,
183
+ path: ALERT_PATH,
184
+ });
185
+ }
186
+
187
+ /**
188
+ * Remove an alert from the database
189
+ * @param id ID of the alert
190
+ * @param query_params Query parameters to add the to request URL
191
+ */
192
+ export function removeAlert(
193
+ id: string,
194
+ query_params: Record<string, any> = {},
195
+ ) {
196
+ return remove({ id, query_params, path: ALERT_PATH });
197
+ }
package/src/api.ts CHANGED
@@ -17,6 +17,22 @@ export {
17
17
  setMockNotFoundHandler,
18
18
  } from './http/mock';
19
19
 
20
+ export { PlaceAlert } from './alerts/alert';
21
+ export { PlaceAlertDashboard } from './alerts/dashboard';
22
+ export {
23
+ addAlert,
24
+ addAlertDashboard,
25
+ listDashboardAlerts,
26
+ queryAlertDashboards,
27
+ queryAlerts,
28
+ removeAlert,
29
+ removeAlertDashboard,
30
+ showAlert,
31
+ showAlertDashboard,
32
+ updateAlert,
33
+ updateAlertDashboard,
34
+ } from './alerts/functions';
35
+
20
36
  export { PlaceApplication } from './applications/application';
21
37
  export {
22
38
  addApplication,
@@ -248,7 +264,6 @@ export type {
248
264
  TriggerComparison,
249
265
  TriggerConditionConstant,
250
266
  TriggerConditionValue,
251
- TriggerConditions,
252
267
  TriggerCronTimeCondition,
253
268
  TriggerFunction,
254
269
  TriggerMailer,
@@ -256,6 +271,7 @@ export type {
256
271
  TriggerTimeCondition,
257
272
  TriggerWebhook,
258
273
  } from './triggers/interfaces';
274
+ export type { TriggerConditions } from './triggers/interfaces';
259
275
  export { PlaceTrigger } from './triggers/trigger';
260
276
 
261
277
  export {