@lensjs/express 1.0.7 → 1.0.8
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/adapter.cjs +28 -5
- package/dist/adapter.js +28 -5
- package/package.json +10 -12
package/dist/adapter.cjs
CHANGED
|
@@ -32,8 +32,10 @@ __export(adapter_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(adapter_exports);
|
|
34
34
|
var import_core = require("@lensjs/core");
|
|
35
|
-
var path = __toESM(require("path"), 1);
|
|
35
|
+
var path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
37
|
var import_express2 = __toESM(require("express"), 1);
|
|
38
|
+
var import_date = require("@repo/date");
|
|
37
39
|
class ExpressAdapter extends import_core.LensAdapter {
|
|
38
40
|
app;
|
|
39
41
|
config;
|
|
@@ -94,7 +96,7 @@ class ExpressAdapter extends import_core.LensAdapter {
|
|
|
94
96
|
const queryPayload = {
|
|
95
97
|
query: query.query,
|
|
96
98
|
duration: query.duration || "0 ms",
|
|
97
|
-
createdAt: query.createdAt ||
|
|
99
|
+
createdAt: query.createdAt || (0, import_date.sqlDateTime)(),
|
|
98
100
|
type: query.type
|
|
99
101
|
};
|
|
100
102
|
await watcher?.log({
|
|
@@ -124,8 +126,29 @@ class ExpressAdapter extends import_core.LensAdapter {
|
|
|
124
126
|
return originalJson(body);
|
|
125
127
|
};
|
|
126
128
|
res.send = function(body) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
let safeBody;
|
|
130
|
+
try {
|
|
131
|
+
if (!body) {
|
|
132
|
+
safeBody = "Purged By Lens";
|
|
133
|
+
} else if (typeof body === "object" && !Buffer.isBuffer(body)) {
|
|
134
|
+
safeBody = body;
|
|
135
|
+
} else if (typeof body === "string") {
|
|
136
|
+
const filePath = path.resolve(body);
|
|
137
|
+
if (import_node_fs.default.existsSync(filePath)) {
|
|
138
|
+
safeBody = "Purged By Lens";
|
|
139
|
+
} else {
|
|
140
|
+
safeBody = body;
|
|
141
|
+
}
|
|
142
|
+
} else if (Buffer.isBuffer(body)) {
|
|
143
|
+
safeBody = "Purged By Lens";
|
|
144
|
+
} else {
|
|
145
|
+
safeBody = "Purged By Lens";
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
safeBody = "Purged By Lens";
|
|
149
|
+
}
|
|
150
|
+
res._body = safeBody;
|
|
151
|
+
return originalSend(safeBody);
|
|
129
152
|
};
|
|
130
153
|
}
|
|
131
154
|
async finalizeRequestLog(req, res, requestWatcher, start) {
|
|
@@ -141,7 +164,7 @@ class ExpressAdapter extends import_core.LensAdapter {
|
|
|
141
164
|
body: req.body ?? {},
|
|
142
165
|
status: res.statusCode,
|
|
143
166
|
ip: req.socket?.remoteAddress ?? "",
|
|
144
|
-
createdAt:
|
|
167
|
+
createdAt: (0, import_date.nowISO)()
|
|
145
168
|
},
|
|
146
169
|
response: {
|
|
147
170
|
json: res._body ?? null,
|
package/dist/adapter.js
CHANGED
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
lensUtils,
|
|
4
4
|
WatcherTypeEnum
|
|
5
5
|
} from "@lensjs/core";
|
|
6
|
-
import * as path from "path";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import fs from "node:fs";
|
|
7
8
|
import express from "express";
|
|
9
|
+
import { nowISO, sqlDateTime } from "@repo/date";
|
|
8
10
|
class ExpressAdapter extends LensAdapter {
|
|
9
11
|
app;
|
|
10
12
|
config;
|
|
@@ -65,7 +67,7 @@ class ExpressAdapter extends LensAdapter {
|
|
|
65
67
|
const queryPayload = {
|
|
66
68
|
query: query.query,
|
|
67
69
|
duration: query.duration || "0 ms",
|
|
68
|
-
createdAt: query.createdAt ||
|
|
70
|
+
createdAt: query.createdAt || sqlDateTime(),
|
|
69
71
|
type: query.type
|
|
70
72
|
};
|
|
71
73
|
await watcher?.log({
|
|
@@ -95,8 +97,29 @@ class ExpressAdapter extends LensAdapter {
|
|
|
95
97
|
return originalJson(body);
|
|
96
98
|
};
|
|
97
99
|
res.send = function(body) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
let safeBody;
|
|
101
|
+
try {
|
|
102
|
+
if (!body) {
|
|
103
|
+
safeBody = "Purged By Lens";
|
|
104
|
+
} else if (typeof body === "object" && !Buffer.isBuffer(body)) {
|
|
105
|
+
safeBody = body;
|
|
106
|
+
} else if (typeof body === "string") {
|
|
107
|
+
const filePath = path.resolve(body);
|
|
108
|
+
if (fs.existsSync(filePath)) {
|
|
109
|
+
safeBody = "Purged By Lens";
|
|
110
|
+
} else {
|
|
111
|
+
safeBody = body;
|
|
112
|
+
}
|
|
113
|
+
} else if (Buffer.isBuffer(body)) {
|
|
114
|
+
safeBody = "Purged By Lens";
|
|
115
|
+
} else {
|
|
116
|
+
safeBody = "Purged By Lens";
|
|
117
|
+
}
|
|
118
|
+
} catch {
|
|
119
|
+
safeBody = "Purged By Lens";
|
|
120
|
+
}
|
|
121
|
+
res._body = safeBody;
|
|
122
|
+
return originalSend(safeBody);
|
|
100
123
|
};
|
|
101
124
|
}
|
|
102
125
|
async finalizeRequestLog(req, res, requestWatcher, start) {
|
|
@@ -112,7 +135,7 @@ class ExpressAdapter extends LensAdapter {
|
|
|
112
135
|
body: req.body ?? {},
|
|
113
136
|
status: res.statusCode,
|
|
114
137
|
ip: req.socket?.remoteAddress ?? "",
|
|
115
|
-
createdAt:
|
|
138
|
+
createdAt: nowISO()
|
|
116
139
|
},
|
|
117
140
|
response: {
|
|
118
141
|
json: res._body ?? null,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensjs/express",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Express adapter for
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Express adapter for LensJs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -17,19 +17,17 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "tsup --clean"
|
|
22
|
-
},
|
|
23
20
|
"dependencies": {
|
|
24
21
|
"express": "^5.1.0",
|
|
25
|
-
"
|
|
22
|
+
"@repo/date": "0.0.1",
|
|
23
|
+
"@repo/typescript-config": "0.0.1",
|
|
24
|
+
"@lensjs/core": "1.0.8",
|
|
25
|
+
"@lensjs/watchers": "1.0.8"
|
|
26
26
|
},
|
|
27
|
-
"trustedDependencies": [
|
|
28
|
-
"utf-8-validate"
|
|
29
|
-
],
|
|
30
27
|
"devDependencies": {
|
|
31
|
-
"@lensjs/core": "1.0.4",
|
|
32
28
|
"@types/express": "^5.0.3"
|
|
33
29
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup --clean"
|
|
32
|
+
}
|
|
33
|
+
}
|