@concordiq/error-sdk 1.0.0 → 1.0.2

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