@alertsamurai/sdk-js 0.0.2 → 0.0.5
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 +1 -1
- package/dist/index.d.mts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +60 -15
- package/dist/index.mjs +60 -15
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,12 @@ interface AlertSamuraiConfig {
|
|
|
10
10
|
timeout?: number;
|
|
11
11
|
/** Number of retries on network failure (optional) - defaults to 3 */
|
|
12
12
|
retries?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Silent mode (optional) - defaults to true
|
|
15
|
+
* When true, errors are swallowed silently
|
|
16
|
+
* When false, warnings/errors are logged to console
|
|
17
|
+
*/
|
|
18
|
+
silent?: boolean;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Options for sending a metric
|
|
@@ -32,12 +38,16 @@ interface SendMetricOptions {
|
|
|
32
38
|
* Response from sending a metric
|
|
33
39
|
*/
|
|
34
40
|
interface SendMetricResponse {
|
|
35
|
-
/** ID of the created metric record */
|
|
36
|
-
id
|
|
41
|
+
/** ID of the created metric record (present on success) */
|
|
42
|
+
id?: string;
|
|
37
43
|
/** Whether the metric was successfully processed */
|
|
38
44
|
success: boolean;
|
|
39
45
|
/** Whether any threshold-based alerts were triggered */
|
|
40
46
|
alertTriggered?: boolean;
|
|
47
|
+
/** True if client is disabled (no DSN configured) */
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
/** Error message if the request failed */
|
|
50
|
+
error?: string;
|
|
41
51
|
}
|
|
42
52
|
/**
|
|
43
53
|
* Alert priority levels
|
|
@@ -60,15 +70,23 @@ interface SendAlertOptions {
|
|
|
60
70
|
* Response from sending an alert
|
|
61
71
|
*/
|
|
62
72
|
interface SendAlertResponse {
|
|
63
|
-
/** ID of the created alert record */
|
|
64
|
-
id
|
|
73
|
+
/** ID of the created alert record (present on success) */
|
|
74
|
+
id?: string;
|
|
65
75
|
/** Whether the alert was successfully processed */
|
|
66
76
|
success: boolean;
|
|
77
|
+
/** True if client is disabled (no DSN configured) */
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/** Error message if the request failed */
|
|
80
|
+
error?: string;
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
/**
|
|
70
84
|
* AlertSamurai SDK client for sending metrics and alerts
|
|
71
85
|
*
|
|
86
|
+
* The client is designed to be fault-tolerant and will never throw errors
|
|
87
|
+
* that could crash your application. If misconfigured, it operates in
|
|
88
|
+
* "disabled" mode and silently returns empty responses.
|
|
89
|
+
*
|
|
72
90
|
* @example
|
|
73
91
|
* ```typescript
|
|
74
92
|
* const client = new AlertSamuraiClient({
|
|
@@ -91,7 +109,13 @@ declare class AlertSamuraiClient {
|
|
|
91
109
|
private baseUrl;
|
|
92
110
|
private timeout;
|
|
93
111
|
private retries;
|
|
94
|
-
|
|
112
|
+
private enabled;
|
|
113
|
+
private silent;
|
|
114
|
+
constructor(config?: AlertSamuraiConfig | null);
|
|
115
|
+
/**
|
|
116
|
+
* Check if the client is enabled and configured properly
|
|
117
|
+
*/
|
|
118
|
+
isEnabled(): boolean;
|
|
95
119
|
/**
|
|
96
120
|
* Send a custom metric for tracking and threshold-based alerting
|
|
97
121
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ interface AlertSamuraiConfig {
|
|
|
10
10
|
timeout?: number;
|
|
11
11
|
/** Number of retries on network failure (optional) - defaults to 3 */
|
|
12
12
|
retries?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Silent mode (optional) - defaults to true
|
|
15
|
+
* When true, errors are swallowed silently
|
|
16
|
+
* When false, warnings/errors are logged to console
|
|
17
|
+
*/
|
|
18
|
+
silent?: boolean;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Options for sending a metric
|
|
@@ -32,12 +38,16 @@ interface SendMetricOptions {
|
|
|
32
38
|
* Response from sending a metric
|
|
33
39
|
*/
|
|
34
40
|
interface SendMetricResponse {
|
|
35
|
-
/** ID of the created metric record */
|
|
36
|
-
id
|
|
41
|
+
/** ID of the created metric record (present on success) */
|
|
42
|
+
id?: string;
|
|
37
43
|
/** Whether the metric was successfully processed */
|
|
38
44
|
success: boolean;
|
|
39
45
|
/** Whether any threshold-based alerts were triggered */
|
|
40
46
|
alertTriggered?: boolean;
|
|
47
|
+
/** True if client is disabled (no DSN configured) */
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
/** Error message if the request failed */
|
|
50
|
+
error?: string;
|
|
41
51
|
}
|
|
42
52
|
/**
|
|
43
53
|
* Alert priority levels
|
|
@@ -60,15 +70,23 @@ interface SendAlertOptions {
|
|
|
60
70
|
* Response from sending an alert
|
|
61
71
|
*/
|
|
62
72
|
interface SendAlertResponse {
|
|
63
|
-
/** ID of the created alert record */
|
|
64
|
-
id
|
|
73
|
+
/** ID of the created alert record (present on success) */
|
|
74
|
+
id?: string;
|
|
65
75
|
/** Whether the alert was successfully processed */
|
|
66
76
|
success: boolean;
|
|
77
|
+
/** True if client is disabled (no DSN configured) */
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/** Error message if the request failed */
|
|
80
|
+
error?: string;
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
/**
|
|
70
84
|
* AlertSamurai SDK client for sending metrics and alerts
|
|
71
85
|
*
|
|
86
|
+
* The client is designed to be fault-tolerant and will never throw errors
|
|
87
|
+
* that could crash your application. If misconfigured, it operates in
|
|
88
|
+
* "disabled" mode and silently returns empty responses.
|
|
89
|
+
*
|
|
72
90
|
* @example
|
|
73
91
|
* ```typescript
|
|
74
92
|
* const client = new AlertSamuraiClient({
|
|
@@ -91,7 +109,13 @@ declare class AlertSamuraiClient {
|
|
|
91
109
|
private baseUrl;
|
|
92
110
|
private timeout;
|
|
93
111
|
private retries;
|
|
94
|
-
|
|
112
|
+
private enabled;
|
|
113
|
+
private silent;
|
|
114
|
+
constructor(config?: AlertSamuraiConfig | null);
|
|
115
|
+
/**
|
|
116
|
+
* Check if the client is enabled and configured properly
|
|
117
|
+
*/
|
|
118
|
+
isEnabled(): boolean;
|
|
95
119
|
/**
|
|
96
120
|
* Send a custom metric for tracking and threshold-based alerting
|
|
97
121
|
*
|
package/dist/index.js
CHANGED
|
@@ -83,18 +83,37 @@ function sleep(ms) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// src/client.ts
|
|
86
|
-
var DEFAULT_BASE_URL = "https://
|
|
86
|
+
var DEFAULT_BASE_URL = "https://monitor.alertsamurai.com";
|
|
87
87
|
var DEFAULT_TIMEOUT = 3e4;
|
|
88
88
|
var DEFAULT_RETRIES = 3;
|
|
89
89
|
var AlertSamuraiClient = class {
|
|
90
90
|
constructor(config) {
|
|
91
|
-
if (!config.dsn) {
|
|
92
|
-
|
|
91
|
+
if (!config || !config.dsn) {
|
|
92
|
+
this.enabled = false;
|
|
93
|
+
this.dsn = "";
|
|
94
|
+
this.baseUrl = DEFAULT_BASE_URL;
|
|
95
|
+
this.timeout = DEFAULT_TIMEOUT;
|
|
96
|
+
this.retries = DEFAULT_RETRIES;
|
|
97
|
+
this.silent = config?.silent ?? true;
|
|
98
|
+
if (!this.silent) {
|
|
99
|
+
console.warn(
|
|
100
|
+
"[AlertSamurai] Client disabled: DSN is required. Calls will be no-ops."
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
93
104
|
}
|
|
105
|
+
this.enabled = true;
|
|
94
106
|
this.dsn = config.dsn;
|
|
95
107
|
this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
96
108
|
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
97
109
|
this.retries = config.retries ?? DEFAULT_RETRIES;
|
|
110
|
+
this.silent = config.silent ?? true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if the client is enabled and configured properly
|
|
114
|
+
*/
|
|
115
|
+
isEnabled() {
|
|
116
|
+
return this.enabled;
|
|
98
117
|
}
|
|
99
118
|
/**
|
|
100
119
|
* Send a custom metric for tracking and threshold-based alerting
|
|
@@ -114,16 +133,29 @@ var AlertSamuraiClient = class {
|
|
|
114
133
|
* ```
|
|
115
134
|
*/
|
|
116
135
|
async sendMetric(options) {
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
if (!this.enabled) {
|
|
137
|
+
return { success: false, disabled: true };
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
this.validateMetric(options);
|
|
141
|
+
const body = {
|
|
142
|
+
metricType: options.metricType,
|
|
143
|
+
value: options.value,
|
|
144
|
+
unit: options.unit,
|
|
145
|
+
environment: options.environment,
|
|
146
|
+
metadata: options.metadata,
|
|
147
|
+
timestamp: this.normalizeTimestamp(options.timestamp)
|
|
148
|
+
};
|
|
149
|
+
return this.request("/api/metrics", body);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (!this.silent) {
|
|
152
|
+
console.error("[AlertSamurai] sendMetric failed:", error);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
127
159
|
}
|
|
128
160
|
/**
|
|
129
161
|
* Send an application alert with priority level
|
|
@@ -142,8 +174,21 @@ var AlertSamuraiClient = class {
|
|
|
142
174
|
* ```
|
|
143
175
|
*/
|
|
144
176
|
async sendAlert(options) {
|
|
145
|
-
this.
|
|
146
|
-
|
|
177
|
+
if (!this.enabled) {
|
|
178
|
+
return { success: false, disabled: true };
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
this.validateAlert(options);
|
|
182
|
+
return this.request("/api/alerts", options);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (!this.silent) {
|
|
185
|
+
console.error("[AlertSamurai] sendAlert failed:", error);
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
190
|
+
};
|
|
191
|
+
}
|
|
147
192
|
}
|
|
148
193
|
/**
|
|
149
194
|
* Send a critical priority alert
|
package/dist/index.mjs
CHANGED
|
@@ -53,18 +53,37 @@ function sleep(ms) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// src/client.ts
|
|
56
|
-
var DEFAULT_BASE_URL = "https://
|
|
56
|
+
var DEFAULT_BASE_URL = "https://monitor.alertsamurai.com";
|
|
57
57
|
var DEFAULT_TIMEOUT = 3e4;
|
|
58
58
|
var DEFAULT_RETRIES = 3;
|
|
59
59
|
var AlertSamuraiClient = class {
|
|
60
60
|
constructor(config) {
|
|
61
|
-
if (!config.dsn) {
|
|
62
|
-
|
|
61
|
+
if (!config || !config.dsn) {
|
|
62
|
+
this.enabled = false;
|
|
63
|
+
this.dsn = "";
|
|
64
|
+
this.baseUrl = DEFAULT_BASE_URL;
|
|
65
|
+
this.timeout = DEFAULT_TIMEOUT;
|
|
66
|
+
this.retries = DEFAULT_RETRIES;
|
|
67
|
+
this.silent = config?.silent ?? true;
|
|
68
|
+
if (!this.silent) {
|
|
69
|
+
console.warn(
|
|
70
|
+
"[AlertSamurai] Client disabled: DSN is required. Calls will be no-ops."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
63
74
|
}
|
|
75
|
+
this.enabled = true;
|
|
64
76
|
this.dsn = config.dsn;
|
|
65
77
|
this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
66
78
|
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
67
79
|
this.retries = config.retries ?? DEFAULT_RETRIES;
|
|
80
|
+
this.silent = config.silent ?? true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if the client is enabled and configured properly
|
|
84
|
+
*/
|
|
85
|
+
isEnabled() {
|
|
86
|
+
return this.enabled;
|
|
68
87
|
}
|
|
69
88
|
/**
|
|
70
89
|
* Send a custom metric for tracking and threshold-based alerting
|
|
@@ -84,16 +103,29 @@ var AlertSamuraiClient = class {
|
|
|
84
103
|
* ```
|
|
85
104
|
*/
|
|
86
105
|
async sendMetric(options) {
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
if (!this.enabled) {
|
|
107
|
+
return { success: false, disabled: true };
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
this.validateMetric(options);
|
|
111
|
+
const body = {
|
|
112
|
+
metricType: options.metricType,
|
|
113
|
+
value: options.value,
|
|
114
|
+
unit: options.unit,
|
|
115
|
+
environment: options.environment,
|
|
116
|
+
metadata: options.metadata,
|
|
117
|
+
timestamp: this.normalizeTimestamp(options.timestamp)
|
|
118
|
+
};
|
|
119
|
+
return this.request("/api/metrics", body);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (!this.silent) {
|
|
122
|
+
console.error("[AlertSamurai] sendMetric failed:", error);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
success: false,
|
|
126
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
127
|
+
};
|
|
128
|
+
}
|
|
97
129
|
}
|
|
98
130
|
/**
|
|
99
131
|
* Send an application alert with priority level
|
|
@@ -112,8 +144,21 @@ var AlertSamuraiClient = class {
|
|
|
112
144
|
* ```
|
|
113
145
|
*/
|
|
114
146
|
async sendAlert(options) {
|
|
115
|
-
this.
|
|
116
|
-
|
|
147
|
+
if (!this.enabled) {
|
|
148
|
+
return { success: false, disabled: true };
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
this.validateAlert(options);
|
|
152
|
+
return this.request("/api/alerts", options);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!this.silent) {
|
|
155
|
+
console.error("[AlertSamurai] sendAlert failed:", error);
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
117
162
|
}
|
|
118
163
|
/**
|
|
119
164
|
* Send a critical priority alert
|