@signalgrid/signalgrid 1.0.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.
Files changed (3) hide show
  1. package/README.md +79 -0
  2. package/index.js +39 -0
  3. package/package.json +19 -0
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Signalgrid Node.js SDK
2
+
3
+ Official Node.js client for the `@signalgrid/signalgrid` package.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @signalgrid/signalgrid
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import Signalgrid from '@signalgrid/signalgrid';
15
+
16
+ const sg = new Signalgrid('your_client_key');
17
+
18
+ const result = await sg.send({
19
+ channel: 'your_channel_token',
20
+ title: 'Server Alert',
21
+ body: 'High CPU usage detected on web-01',
22
+ type: 'warning',
23
+ critical: false
24
+ });
25
+
26
+ console.log(result);
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### `new Signalgrid(clientKey)`
32
+
33
+ Creates a Signalgrid client instance.
34
+
35
+ #### Arguments
36
+
37
+ - `clientKey` (`string`) - Your Signalgrid client key.
38
+
39
+ ### `sg.send(payload)`
40
+
41
+ Sends a notification.
42
+
43
+ #### Payload
44
+
45
+ - `channel` (`string`) - Your channel token.
46
+ - `title` (`string`) - Notification title.
47
+ - `body` (`string`) - Notification body.
48
+ - `type` (`string`, optional) - Notification type such as `info`, `success`, `warning`, or `error`.
49
+ - `critical` (`boolean`, optional) - Critical flag. If set to true, notification will bypass DND / Focus modes.
50
+
51
+ #### Returns
52
+
53
+ Returns a promise that resolves with the Signalgrid API response.
54
+
55
+ ## Example with error handling
56
+
57
+ ```js
58
+ import Signalgrid from '@signalgrid/signalgrid';
59
+
60
+ async function main() {
61
+ try {
62
+ const sg = new Signalgrid('your_client_key');
63
+
64
+ const result = await sg.send({
65
+ channel: 'your_channel_token',
66
+ title: 'Server Alert',
67
+ body: 'High CPU usage detected on web-01',
68
+ type: 'warning',
69
+ critical: false
70
+ });
71
+
72
+ console.log(result);
73
+ } catch (error) {
74
+ console.error('Failed to send notification:', error);
75
+ }
76
+ }
77
+
78
+ main();
79
+ ```
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ class Signalgrid {
2
+ constructor(clientKey) {
3
+ if (!clientKey) {
4
+ throw new Error('Signalgrid: clientKey is required.');
5
+ }
6
+ this.clientKey = clientKey;
7
+ this.url = 'https://api.signalgrid.co/v1/push';
8
+ }
9
+
10
+ async send({ channel, type = 'info', title = '', body = '', critical = false }) {
11
+ if (!channel) throw new Error('Signalgrid: channel is required.');
12
+
13
+ const params = new URLSearchParams();
14
+ params.append('client_key', this.clientKey);
15
+ params.append('channel', channel);
16
+ params.append('type', type);
17
+ params.append('title', title);
18
+ params.append('body', body);
19
+ params.append('critical', String(critical));
20
+
21
+ const response = await fetch(this.url, {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/x-www-form-urlencoded',
25
+ 'User-Agent': 'signalgrid-node-client/1.0.0'
26
+ },
27
+ body: params.toString()
28
+ });
29
+
30
+ if (!response.ok) {
31
+ const errorText = await response.text();
32
+ throw new Error(`Signalgrid HTTP Error ${response.status}: ${errorText}`);
33
+ }
34
+
35
+ return await response.text();
36
+ }
37
+ }
38
+
39
+ export default Signalgrid;
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@signalgrid/signalgrid",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js client for Signalgrid push notifications",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "engines": {
8
+ "node": ">=18.0.0"
9
+ },
10
+ "keywords": [
11
+ "signalgrid",
12
+ "push",
13
+ "notifications",
14
+ "zabbix",
15
+ "alerts"
16
+ ],
17
+ "author": "Signalgrid",
18
+ "license": "MIT"
19
+ }