@concordiq/error-sdk 1.0.0 → 1.0.1

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,10 +1,31 @@
1
1
  {
2
2
  "name": "@concordiq/error-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
+ "private": false,
4
5
  "description": "Error monitoring SDK",
5
- "main": "src/index.js",
6
6
  "type": "module",
7
- "keywords": ["errors", "monitoring", "logging"],
7
+ "main": "./src/index.js",
8
+ "types": "./src/index.d.ts",
9
+ "keywords": [
10
+ "errors",
11
+ "monitoring",
12
+ "logging"
13
+ ],
8
14
  "author": "Arowolo",
9
- "license": "MIT"
15
+ "license": "MIT",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./src/index.js",
19
+ "types": "./src/index.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "src"
24
+ ],
25
+ "dependencies": {
26
+ "node-fetch": "^3.3.2"
27
+ },
28
+ "peerDependencies": {
29
+ "express": "^4 || ^5"
30
+ }
10
31
  }
package/readMe.md CHANGED
@@ -1,13 +1,27 @@
1
+ # @concordiq/error-sdk
2
+
3
+ Official ConcordIQ Error Tracking SDK for Node.js and Express.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
1
10
  npm install @concordiq/error-sdk
2
11
 
12
+ ```
13
+ ## Initialization
14
+
15
+ ```javascript and typescript
16
+ Initialize once when your app starts:
17
+ ```
3
18
 
4
- `Controller`
5
- import ErrorSDK from "@arosebine/error-sdk";
19
+ import ErrorSDK from "@concordiq/error-sdk";
6
20
 
7
21
  ErrorSDK.init({
8
- Authorization: "Bearer coiq-6ddfeede1d57a268f7131ef0597624200a8a02b7",
22
+ apiKey: "PROJECT_API_KEY",
9
23
 
10
- endpoint: "https://concordiq.onrender.com/api/v1/ingest/events",
24
+ endpoint: "https://api.mysaas.com/ingest",
11
25
 
12
26
  env: "production",
13
27
 
@@ -15,51 +29,51 @@ ErrorSDK.init({
15
29
  });
16
30
 
17
31
 
18
- `
32
+
33
+ ## Manual Error Capture
34
+
35
+ Use inside controllers or services:
36
+
37
+ ---
19
38
  try {
20
39
  processPayment();
21
40
  } catch (err) {
22
41
  ErrorSDK.capture(err, {
23
- message: err.message,
24
- stack: err.stack,
25
- type: "crash"
42
+ userId: 22,
43
+ orderId: 991
26
44
  });
27
45
  }
28
- `
29
-
30
-
31
- `Express.Js `
32
- export function expressHandler() {
33
- return (err, req, res, next) => {
34
- import("./index.js").then(sdk => {
35
- sdk.default.capture(err, {
36
- url: req.originalUrl,
37
- method: req.method,
38
- user: req.user?.id
39
- });
40
- });
41
-
42
- next(err);
43
- };
44
- }
45
46
 
46
- app.use(ErrorSDK.expressMiddleware());
47
47
 
48
48
 
49
49
 
50
- `To publish it`
51
- npm login
52
- npm publish --access public
50
+ ## Express.js Integration
53
51
 
52
+ Automatically capture all server errors.
53
+ import express from "express";
54
+ import ErrorSDK from "@concordiq/error-sdk";
55
+ ----
56
+ const app = express();
54
57
 
58
+ app.use("/pay", (req, res) => {
59
+ throw new Error("Payment failed");
60
+ });
55
61
 
56
- `To Test it Locally`
57
- import ErrorSDK from "./src/index.js";
62
+ /**
63
+ * Must be last middleware
64
+ */
65
+ app.use(ErrorSDK.expressMiddleware());
58
66
 
59
- ErrorSDK.init({
60
- apiKey: "test123",
61
- endpoint: "http://localhost:4000/ingest"
62
- });
63
67
 
64
- throw new Error("Test Crash");
65
68
 
69
+ ## Features:
70
+
71
+ 1. Manual error tracking
72
+
73
+ 2. Express middleware
74
+
75
+ 3. Global crash handling
76
+
77
+ 4. TypeScript support
78
+
79
+ 5. Lightweight
package/src/client.js CHANGED
@@ -1,19 +1,22 @@
1
1
  import fetch from "node-fetch";
2
2
 
3
- export async function sendError(apiKey, url, payload) {
3
+ /**
4
+ * Send error to ConcordIQ API
5
+ */
6
+ export async function sendError(apiKey, endpoint, payload) {
4
7
  try {
5
- await fetch(url, {
8
+ await fetch(endpoint, {
6
9
  method: "POST",
7
10
 
8
11
  headers: {
9
12
  "Content-Type": "application/json",
10
- "x-api-key": apiKey
13
+ Authorization: apiKey
11
14
  },
12
15
 
13
16
  body: JSON.stringify(payload)
14
17
  });
15
18
  } catch (err) {
16
- // Never crash client app
17
- console.error("SDK Send Failed:", err.message);
19
+ // Avoid crashing user app
20
+ console.error("[ErrorSDK] Failed to send error:", err);
18
21
  }
19
- }
22
+ }
package/src/handlers.js CHANGED
@@ -1,32 +1,14 @@
1
- import { sendError } from "./client.js";
2
-
3
- export function attachHandlers(config) {
4
- // Promise errors
5
- process.on("unhandledRejection", err => {
6
- report(err, config);
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);
7
9
  });
8
10
 
9
- // Crash errors
10
- process.on("uncaughtException", err => {
11
- report(err, config);
11
+ process.on("unhandledRejection", (err) => {
12
+ capture(err);
12
13
  });
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
- }
14
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+
3
+ export interface ErrorSDKOptions {
4
+ apiKey: string;
5
+ endpoint?: string;
6
+ env?: string;
7
+ service?: string;
8
+ }
9
+
10
+ export function init(options: ErrorSDKOptions): void;
11
+
12
+ export function capture(
13
+ error: any,
14
+ extra?: Record<string, any>
15
+ ): Promise<void>;
16
+
17
+ export function expressMiddleware(): (
18
+ err: any,
19
+ req: Request,
20
+ res: Response,
21
+ next: NextFunction
22
+ ) => void;
23
+
24
+ declare const ErrorSDK: {
25
+ init: typeof init;
26
+ capture: typeof capture;
27
+ expressMiddleware: typeof expressMiddleware;
28
+ };
29
+
30
+ export default ErrorSDK;
package/src/index.js CHANGED
@@ -1,12 +1,16 @@
1
- import { attachHandlers } from "./handlers.js";
1
+ import { expressMiddleware } from "./middleware.js";
2
2
  import { sendError } from "./client.js";
3
+ import { attachHandlers } from "./handlers.js";
3
4
  import { getMeta } from "./utils.js";
4
5
 
5
6
  let config = null;
6
7
 
8
+ /**
9
+ * Initialize SDK
10
+ */
7
11
  function init(options) {
8
- if (!options.apiKey) {
9
- throw new Error("apiKey required");
12
+ if (!options?.apiKey) {
13
+ throw new Error("apiKey is required");
10
14
  }
11
15
 
12
16
  config = {
@@ -14,7 +18,7 @@ function init(options) {
14
18
 
15
19
  endpoint:
16
20
  options.endpoint ||
17
- "https://api.yoursaas.com/ingest",
21
+ "https://concordiq.onrender.com/api/v1/ingest/events",
18
22
 
19
23
  env: options.env || "production",
20
24
 
@@ -24,12 +28,16 @@ function init(options) {
24
28
  attachHandlers(config);
25
29
  }
26
30
 
31
+ /**
32
+ * Capture error manually
33
+ */
27
34
  async function capture(error, extra = {}) {
28
35
  if (!config) return;
29
36
 
30
37
  const payload = {
31
- message: error.message || error,
32
- stack: error.stack,
38
+ message: error?.message || String(error),
39
+
40
+ stack: error?.stack,
33
41
 
34
42
  type: "manual",
35
43
 
@@ -41,7 +49,7 @@ async function capture(error, extra = {}) {
41
49
  ...extra
42
50
  },
43
51
 
44
- timestamp: new Date()
52
+ timestamp: new Date().toISOString()
45
53
  };
46
54
 
47
55
  await sendError(
@@ -51,7 +59,14 @@ async function capture(error, extra = {}) {
51
59
  );
52
60
  }
53
61
 
54
- export default {
62
+ export {
55
63
  init,
56
- capture
64
+ capture,
65
+ expressMiddleware
57
66
  };
67
+
68
+ export default {
69
+ init,
70
+ capture,
71
+ expressMiddleware
72
+ };
@@ -0,0 +1,16 @@
1
+ import { capture } from "./index.js";
2
+
3
+ /**
4
+ * Express error middleware
5
+ */
6
+ export function expressMiddleware() {
7
+ return function (err, req, res, next) {
8
+ capture(err, {
9
+ url: req.originalUrl,
10
+ method: req.method,
11
+ ip: req.ip
12
+ });
13
+
14
+ next(err);
15
+ };
16
+ }
package/src/utils.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import os from "os";
2
2
 
3
+ /**
4
+ * Collect runtime metadata
5
+ */
3
6
  export function getMeta() {
4
7
  return {
5
- host: os.hostname(),
6
- platform: process.platform,
8
+ platform: os.platform() || process.platform,
9
+ arch: os.arch(),
10
+ nodeVersion: process.version,
11
+ hostname: os.hostname(),
7
12
  memory: process.memoryUsage().rss
8
13
  };
9
- }
14
+ }