@shiv-kush/pulse-monitor-plugin-express 0.1.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.
@@ -0,0 +1,7 @@
1
+ import type { Application } from "express";
2
+ import type { PulseInstance } from "@shiv-kush/pulse-monitor-sdk";
3
+ export interface PulseExpressOptions {
4
+ exportPath?: string;
5
+ }
6
+ export declare function pulseExpress(app: Application, instance: PulseInstance, options?: PulseExpressOptions): void;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAmC,MAAM,SAAS,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,mBAAwB,GAChC,IAAI,CA+BN"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pulseExpress = pulseExpress;
4
+ function pulseExpress(app, instance, options = {}) {
5
+ const exportPath = options.exportPath ?? "/_pulse/export";
6
+ app.use((req, res, next) => {
7
+ const start = process.hrtime.bigint();
8
+ res.on("finish", () => {
9
+ const durationMs = Number(process.hrtime.bigint() - start) / 1_000_000;
10
+ instance.record({
11
+ kind: "http_request",
12
+ data: {
13
+ method: req.method,
14
+ route: req.route?.path ?? req.path,
15
+ statusCode: res.statusCode,
16
+ durationMs,
17
+ userId: req.user?.id ?? null,
18
+ },
19
+ });
20
+ });
21
+ next();
22
+ });
23
+ app.get(exportPath, async (req, res) => {
24
+ const sinceTs = Number(req.query.since ?? 0);
25
+ const limit = req.query.limit ? Number(req.query.limit) : undefined;
26
+ const result = await instance.exportHandler({
27
+ authorizationHeader: req.header("authorization"),
28
+ sinceTs: Number.isFinite(sinceTs) ? sinceTs : 0,
29
+ limit,
30
+ });
31
+ res.status(result.status).json(result.body);
32
+ });
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,oCAmCC;AAnCD,SAAgB,YAAY,CAC1B,GAAgB,EAChB,QAAuB,EACvB,UAA+B,EAAE;IAEjC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,gBAAgB,CAAC;IAE1D,GAAG,CAAC,GAAG,CAAC,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACpB,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;YACvE,QAAQ,CAAC,MAAM,CAAC;gBACd,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE;oBACJ,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI;oBAClC,UAAU,EAAE,GAAG,CAAC,UAAU;oBAC1B,UAAU;oBACV,MAAM,EAAG,GAA6C,CAAC,IAAI,EAAE,EAAE,IAAI,IAAI;iBACxE;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC;YAC1C,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC;YAChD,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/C,KAAK;SACN,CAAC,CAAC;QACH,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@shiv-kush/pulse-monitor-plugin-express",
3
+ "version": "0.1.0",
4
+ "description": "Express integration for @shiv-kush/pulse-monitor-sdk: request timing middleware + /_pulse/export route.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "peerDependencies": {
14
+ "express": ">=4",
15
+ "@shiv-kush/pulse-monitor-sdk": "0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/express": "^4.17.21",
19
+ "express": "^4.19.2",
20
+ "typescript": "^5.5.0",
21
+ "@shiv-kush/pulse-monitor-sdk": "0.1.0"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.json"
25
+ }
26
+ }