devinsight-sdk 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.
- package/index.js +32 -0
- package/package.json +18 -0
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// sdk/index.js
|
|
2
|
+
const DEFAULT_BASE_URL = 'https://devinsight-api.onrender.com';
|
|
3
|
+
|
|
4
|
+
class DevInsight {
|
|
5
|
+
constructor({ apiKey, baseUrl } = {}) {
|
|
6
|
+
if (!apiKey) throw new Error('DevInsight: apiKey é obrigatória');
|
|
7
|
+
this.apiKey = apiKey;
|
|
8
|
+
this.baseUrl = baseUrl || DEFAULT_BASE_URL;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async report({ tipo, mensagem, contexto, dados } = {}) {
|
|
12
|
+
if (!tipo) throw new Error("DevInsight: campo 'tipo' é obrigatório");
|
|
13
|
+
|
|
14
|
+
const response = await fetch(`${this.baseUrl}/v1/diagnosticos`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({ tipo, mensagem, contexto, dados }),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const err = await response.json().catch(() => ({}));
|
|
25
|
+
throw new Error(`DevInsight API error ${response.status}: ${err.erro || 'desconhecido'}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return response.json();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = DevInsight;
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "devinsight-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK oficial da DevInsight API — diagnósticos inteligentes para aplicações",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": ["index.js"],
|
|
7
|
+
"keywords": ["diagnostics", "debug", "api", "devinsight", "monitoring"],
|
|
8
|
+
"author": "DevInsight",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/mirutee/devinsight-api"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/mirutee/devinsight-api",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|