@a-company/sentinel 0.2.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/dist/adapters/express.d.ts +44 -0
- package/dist/adapters/express.js +30 -0
- package/dist/adapters/fastify.d.ts +23 -0
- package/dist/adapters/fastify.js +18 -0
- package/dist/adapters/hono.d.ts +23 -0
- package/dist/adapters/hono.js +26 -0
- package/dist/chunk-KPMG4XED.js +1249 -0
- package/dist/cli.js +32 -0
- package/dist/commands-KIMGFR2I.js +3278 -0
- package/dist/dist-2F7NO4H4.js +6851 -0
- package/dist/dist-BPWLYV4U.js +6853 -0
- package/dist/index.d.ts +434 -0
- package/dist/index.js +2270 -0
- package/dist/mcp.js +2767 -0
- package/dist/sdk-B27_vK1g.d.ts +644 -0
- package/dist/server/index.d.ts +82 -0
- package/dist/server/index.js +854 -0
- package/package.json +98 -0
- package/src/seeds/loader.ts +45 -0
- package/src/seeds/paradigm-patterns.json +195 -0
- package/src/seeds/universal-patterns.json +292 -0
- package/ui/dist/assets/index-BNgsn_C8.js +62 -0
- package/ui/dist/assets/index-BNgsn_C8.js.map +1 -0
- package/ui/dist/assets/index-DPxatSdT.css +1 -0
- package/ui/dist/index.html +17 -0
- package/ui/dist/sentinel.svg +19 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { X as Sentinel } from '../sdk-B27_vK1g.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sentinel Express Adapter
|
|
5
|
+
*
|
|
6
|
+
* Express error-handling middleware that auto-captures errors
|
|
7
|
+
* with route-derived symbolic context.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import { Sentinel } from '@a-company/sentinel';
|
|
11
|
+
* import { createExpressErrorHandler } from '@a-company/sentinel/express';
|
|
12
|
+
*
|
|
13
|
+
* const sentinel = new Sentinel({ project: 'my-app' });
|
|
14
|
+
* app.use(createExpressErrorHandler(sentinel));
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type ErrorRequestHandler = (err: Error, req: any, res: any, next: (err?: any) => void) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Route-to-symbol mapping configuration.
|
|
20
|
+
* Maps route prefixes to component symbols.
|
|
21
|
+
*
|
|
22
|
+
* Example:
|
|
23
|
+
* { '/api/checkout': '#checkout', '/api/auth': '#auth-service' }
|
|
24
|
+
*/
|
|
25
|
+
type RouteSymbolMap = Record<string, string>;
|
|
26
|
+
interface ExpressAdapterOptions {
|
|
27
|
+
/** Map route prefixes to component symbols */
|
|
28
|
+
routeMap?: RouteSymbolMap;
|
|
29
|
+
/** Whether to set X-Sentinel-Incident response header (default: true) */
|
|
30
|
+
setHeader?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create Express error-handling middleware.
|
|
34
|
+
*
|
|
35
|
+
* Automatically captures unhandled errors with:
|
|
36
|
+
* - Route-derived component symbol (auto-detected or from routeMap)
|
|
37
|
+
* - Request metadata (method, path)
|
|
38
|
+
*
|
|
39
|
+
* @param sentinel - Sentinel SDK instance
|
|
40
|
+
* @param options - Adapter options
|
|
41
|
+
*/
|
|
42
|
+
declare function createExpressErrorHandler(sentinel: Sentinel, options?: ExpressAdapterOptions): ErrorRequestHandler;
|
|
43
|
+
|
|
44
|
+
export { type ExpressAdapterOptions, type RouteSymbolMap, createExpressErrorHandler };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/adapters/express.ts
|
|
2
|
+
function createExpressErrorHandler(sentinel, options = {}) {
|
|
3
|
+
const { routeMap = {}, setHeader = true } = options;
|
|
4
|
+
return (err, req, res, next) => {
|
|
5
|
+
const context = {};
|
|
6
|
+
const path = req.path || req.url || "";
|
|
7
|
+
let matched = false;
|
|
8
|
+
for (const [prefix, symbol] of Object.entries(routeMap)) {
|
|
9
|
+
if (path.startsWith(prefix)) {
|
|
10
|
+
context.component = symbol;
|
|
11
|
+
matched = true;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (!matched) {
|
|
16
|
+
const routeParts = path.split("/").filter(Boolean);
|
|
17
|
+
if (routeParts.length >= 2) {
|
|
18
|
+
context.component = `#${routeParts[1]}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const incidentId = sentinel.capture(err, context);
|
|
22
|
+
if (setHeader && res.setHeader && !res.headersSent) {
|
|
23
|
+
res.setHeader("X-Sentinel-Incident", incidentId);
|
|
24
|
+
}
|
|
25
|
+
next(err);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
createExpressErrorHandler
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { X as Sentinel } from '../sdk-B27_vK1g.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sentinel Fastify Adapter
|
|
5
|
+
*
|
|
6
|
+
* Fastify plugin that auto-captures errors with symbolic context.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { Sentinel } from '@a-company/sentinel';
|
|
10
|
+
* import { createFastifyPlugin } from '@a-company/sentinel/fastify';
|
|
11
|
+
*
|
|
12
|
+
* const sentinel = new Sentinel({ project: 'my-app' });
|
|
13
|
+
* fastify.register(createFastifyPlugin(sentinel));
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a Fastify plugin that captures errors with symbolic context.
|
|
18
|
+
*
|
|
19
|
+
* @param sentinel - Sentinel SDK instance
|
|
20
|
+
*/
|
|
21
|
+
declare function createFastifyPlugin(sentinel: Sentinel): (fastify: any) => Promise<void>;
|
|
22
|
+
|
|
23
|
+
export { createFastifyPlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/adapters/fastify.ts
|
|
2
|
+
function createFastifyPlugin(sentinel) {
|
|
3
|
+
return async function sentinelPlugin(fastify) {
|
|
4
|
+
fastify.setErrorHandler(async (error, request, reply) => {
|
|
5
|
+
const context = {};
|
|
6
|
+
const url = request.url || "";
|
|
7
|
+
const routeParts = url.split("?")[0].split("/").filter(Boolean);
|
|
8
|
+
if (routeParts.length >= 2) {
|
|
9
|
+
context.component = `#${routeParts[1]}`;
|
|
10
|
+
}
|
|
11
|
+
sentinel.capture(error, context);
|
|
12
|
+
reply.status(500).send({ error: "Internal Server Error" });
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
createFastifyPlugin
|
|
18
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { X as Sentinel } from '../sdk-B27_vK1g.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sentinel Hono Adapter
|
|
5
|
+
*
|
|
6
|
+
* Hono middleware that auto-captures errors with symbolic context.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { Sentinel } from '@a-company/sentinel';
|
|
10
|
+
* import { createHonoMiddleware } from '@a-company/sentinel/hono';
|
|
11
|
+
*
|
|
12
|
+
* const sentinel = new Sentinel({ project: 'my-app' });
|
|
13
|
+
* app.use('*', createHonoMiddleware(sentinel));
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create Hono middleware that captures errors with symbolic context.
|
|
18
|
+
*
|
|
19
|
+
* @param sentinel - Sentinel SDK instance
|
|
20
|
+
*/
|
|
21
|
+
declare function createHonoMiddleware(sentinel: Sentinel): (c: any, next: () => Promise<void>) => Promise<void>;
|
|
22
|
+
|
|
23
|
+
export { createHonoMiddleware };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/adapters/hono.ts
|
|
2
|
+
function createHonoMiddleware(sentinel) {
|
|
3
|
+
return async (c, next) => {
|
|
4
|
+
try {
|
|
5
|
+
await next();
|
|
6
|
+
} catch (error) {
|
|
7
|
+
if (error instanceof Error) {
|
|
8
|
+
const context = {};
|
|
9
|
+
const url = c.req?.url || "";
|
|
10
|
+
try {
|
|
11
|
+
const pathname = new URL(url, "http://localhost").pathname;
|
|
12
|
+
const routeParts = pathname.split("/").filter(Boolean);
|
|
13
|
+
if (routeParts.length >= 2) {
|
|
14
|
+
context.component = `#${routeParts[1]}`;
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
sentinel.capture(error, context);
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
createHonoMiddleware
|
|
26
|
+
};
|