@concordiq/error-sdk 1.0.3 → 1.0.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@concordiq/error-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "description": "Error monitoring SDK",
6
6
  "type": "module",
package/readMe.md CHANGED
@@ -54,14 +54,17 @@ import express from "express";
54
54
  import ErrorSDK from "@concordiq/error-sdk";
55
55
  ----
56
56
  const app = express();
57
-
57
+ ``
58
58
  app.use("/pay", (req, res) => {
59
59
  throw new Error("Payment failed");
60
60
  });
61
+ ``
61
62
 
62
63
  /**
63
64
  * Must be last middleware
64
65
  */
66
+
67
+ ``
65
68
  app.use(ErrorSDK.expressMiddleware());
66
69
 
67
70
 
package/src/client.js CHANGED
@@ -1,3 +1,24 @@
1
+ // import fetch from "node-fetch";
2
+
3
+ // export async function sendError(apiKey, url, payload) {
4
+ // try {
5
+ // await fetch(url, {
6
+ // method: "POST",
7
+
8
+ // headers: {
9
+ // "Content-Type": "application/json",
10
+ // "x-api-key": apiKey
11
+ // },
12
+
13
+ // body: JSON.stringify(payload)
14
+ // });
15
+ // } catch (err) {
16
+ // // Never crash client app
17
+ // console.error("SDK Send Failed:", err.message);
18
+ // }
19
+ // }
20
+
21
+
1
22
  import fetch from "node-fetch";
2
23
 
3
24
  /**
@@ -10,7 +31,8 @@ export async function sendError(apiKey, endpoint, payload) {
10
31
 
11
32
  headers: {
12
33
  "Content-Type": "application/json",
13
- Authorization: apiKey
34
+ "Authorization": apiKey,
35
+ "x-api-key": apiKey
14
36
  },
15
37
 
16
38
  body: JSON.stringify(payload)
package/src/handlers.js CHANGED
@@ -1,14 +1,48 @@
1
- import { capture } from "./index.js";
2
-
3
- /**
4
- * Attach process-level handlers
5
- */
6
- export function attachHandlers() {
7
- process.on("uncaughtException", (err) => {
8
- capture(err);
1
+ import { sendError } from "./client.js";
2
+
3
+ export function attachHandlers(config) {
4
+ // Promise errors
5
+ process.on("unhandledRejection", err => {
6
+ report(err, config);
9
7
  });
10
8
 
11
- process.on("unhandledRejection", (err) => {
12
- capture(err);
9
+ // Crash errors
10
+ process.on("uncaughtException", err => {
11
+ report(err, config);
13
12
  });
14
- }
13
+ }
14
+
15
+ function report(err, config) {
16
+ const payload = {
17
+ message: err.message,
18
+ stack: err.stack,
19
+ type: "system",
20
+
21
+ service: config.service,
22
+ env: config.env,
23
+
24
+ timestamp: new Date()
25
+ };
26
+
27
+ sendError(
28
+ config.apiKey,
29
+ config.endpoint,
30
+ payload
31
+ );
32
+ }
33
+
34
+
35
+ // import { capture } from "./index.js";
36
+
37
+ // /**
38
+ // * Attach process-level handlers
39
+ // */
40
+ // export function attachHandlers() {
41
+ // process.on("uncaughtException", (err) => {
42
+ // capture(err);
43
+ // });
44
+
45
+ // process.on("unhandledRejection", (err) => {
46
+ // capture(err);
47
+ // });
48
+ // }
package/src/index.js CHANGED
@@ -1,16 +1,13 @@
1
1
  import { expressMiddleware } from "./middleware.js";
2
- import { sendError } from "./client.js";
3
2
  import { attachHandlers } from "./handlers.js";
3
+ import { sendError } from "./client.js";
4
4
  import { getMeta } from "./utils.js";
5
5
 
6
6
  let config = null;
7
7
 
8
- /**
9
- * Initialize SDK
10
- */
11
8
  function init(options) {
12
- if (!options?.apiKey) {
13
- throw new Error("apiKey is required");
9
+ if (!options.apiKey) {
10
+ throw new Error("apiKey required");
14
11
  }
15
12
 
16
13
  config = {
@@ -28,16 +25,12 @@ function init(options) {
28
25
  attachHandlers(config);
29
26
  }
30
27
 
31
- /**
32
- * Capture error manually
33
- */
34
28
  async function capture(error, extra = {}) {
35
29
  if (!config) return;
36
30
 
37
31
  const payload = {
38
- message: error?.message || String(error),
39
-
40
- stack: error?.stack,
32
+ message: error.message || error,
33
+ stack: error.stack,
41
34
 
42
35
  type: "manual",
43
36
 
@@ -49,7 +42,7 @@ async function capture(error, extra = {}) {
49
42
  ...extra
50
43
  },
51
44
 
52
- timestamp: new Date().toISOString()
45
+ timestamp: new Date()
53
46
  };
54
47
 
55
48
  await sendError(
@@ -65,8 +58,84 @@ export {
65
58
  expressMiddleware
66
59
  };
67
60
 
61
+
68
62
  export default {
69
63
  init,
70
64
  capture,
71
65
  expressMiddleware
72
- };
66
+ };
67
+
68
+
69
+
70
+ // import { expressMiddleware } from "./middleware.js";
71
+ // import { sendError } from "./client.js";
72
+ // import { attachHandlers } from "./handlers.js";
73
+ // import { getMeta } from "./utils.js";
74
+
75
+ // let config = null;
76
+
77
+ // /**
78
+ // * Initialize SDK
79
+ // */
80
+ // function init(options) {
81
+ // if (!options?.apiKey) {
82
+ // throw new Error("apiKey is required");
83
+ // }
84
+
85
+ // config = {
86
+ // apiKey: options.apiKey,
87
+
88
+ // endpoint:
89
+ // options.endpoint ||
90
+ // "https://concordiq.onrender.com/api/v1/ingest/events",
91
+
92
+ // env: options.env || "production",
93
+
94
+ // service: options.service || "app"
95
+ // };
96
+
97
+ // attachHandlers(config);
98
+ // }
99
+
100
+ // /**
101
+ // * Capture error manually
102
+ // */
103
+ // async function capture(error, extra = {}) {
104
+ // if (!config) return;
105
+
106
+ // const payload = {
107
+ // message: error?.message || String(error),
108
+
109
+ // stack: error?.stack,
110
+
111
+ // type: "manual",
112
+
113
+ // env: config.env,
114
+ // service: config.service,
115
+
116
+ // meta: {
117
+ // ...getMeta(),
118
+ // ...extra
119
+ // },
120
+
121
+ // timestamp: new Date().toISOString()
122
+ // };
123
+
124
+ // await sendError(
125
+ // config.apiKey,
126
+ // config.endpoint,
127
+ // payload
128
+ // );
129
+ // }
130
+
131
+ // export {
132
+ // init,
133
+ // capture,
134
+ // expressMiddleware
135
+ // };
136
+
137
+ // export default {
138
+ // init,
139
+ // capture,
140
+ // expressMiddleware
141
+ // };