@lensjs/express 1.4.1 → 1.4.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/dist/adapter.cjs +22 -1
- package/dist/adapter.d.cts +2 -0
- package/dist/adapter.d.ts +2 -0
- package/dist/adapter.js +22 -1
- package/dist/index.cjs +22 -1
- package/dist/index.js +22 -1
- package/dist/types/index.d.cts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +4 -4
package/dist/adapter.cjs
CHANGED
|
@@ -188,7 +188,7 @@ var ExpressAdapter = class extends import_core.LensAdapter {
|
|
|
188
188
|
headers: req.headers,
|
|
189
189
|
body: req.body ?? {},
|
|
190
190
|
status: res.statusCode,
|
|
191
|
-
ip:
|
|
191
|
+
ip: this.config.getRequestIp?.(req) ?? this.getIp(req),
|
|
192
192
|
createdAt: (0, import_date.nowISO)()
|
|
193
193
|
},
|
|
194
194
|
response: {
|
|
@@ -215,6 +215,27 @@ var ExpressAdapter = class extends import_core.LensAdapter {
|
|
|
215
215
|
return body;
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
+
getIp(req) {
|
|
219
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
220
|
+
const xff = req.headers["x-forwarded-for"];
|
|
221
|
+
if (typeof xff === "string") {
|
|
222
|
+
const [ip] = xff.split(",");
|
|
223
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
224
|
+
}
|
|
225
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
226
|
+
const ips = xff[0]?.split(",");
|
|
227
|
+
if (ips && ips.length > 0) {
|
|
228
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
232
|
+
}
|
|
233
|
+
normalizeIp(ip) {
|
|
234
|
+
if (ip.startsWith("::ffff:")) {
|
|
235
|
+
return ip.replace("::ffff:", "");
|
|
236
|
+
}
|
|
237
|
+
return ip;
|
|
238
|
+
}
|
|
218
239
|
};
|
|
219
240
|
// Annotate the CommonJS export names for ESM import in node:
|
|
220
241
|
0 && (module.exports = {
|
package/dist/adapter.d.cts
CHANGED
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.js
CHANGED
|
@@ -160,7 +160,7 @@ var ExpressAdapter = class extends LensAdapter {
|
|
|
160
160
|
headers: req.headers,
|
|
161
161
|
body: req.body ?? {},
|
|
162
162
|
status: res.statusCode,
|
|
163
|
-
ip:
|
|
163
|
+
ip: this.config.getRequestIp?.(req) ?? this.getIp(req),
|
|
164
164
|
createdAt: nowISO()
|
|
165
165
|
},
|
|
166
166
|
response: {
|
|
@@ -187,6 +187,27 @@ var ExpressAdapter = class extends LensAdapter {
|
|
|
187
187
|
return body;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
getIp(req) {
|
|
191
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
192
|
+
const xff = req.headers["x-forwarded-for"];
|
|
193
|
+
if (typeof xff === "string") {
|
|
194
|
+
const [ip] = xff.split(",");
|
|
195
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
196
|
+
}
|
|
197
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
198
|
+
const ips = xff[0]?.split(",");
|
|
199
|
+
if (ips && ips.length > 0) {
|
|
200
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
204
|
+
}
|
|
205
|
+
normalizeIp(ip) {
|
|
206
|
+
if (ip.startsWith("::ffff:")) {
|
|
207
|
+
return ip.replace("::ffff:", "");
|
|
208
|
+
}
|
|
209
|
+
return ip;
|
|
210
|
+
}
|
|
190
211
|
};
|
|
191
212
|
export {
|
|
192
213
|
ExpressAdapter
|
package/dist/index.cjs
CHANGED
|
@@ -193,7 +193,7 @@ var ExpressAdapter = class extends import_core.LensAdapter {
|
|
|
193
193
|
headers: req.headers,
|
|
194
194
|
body: req.body ?? {},
|
|
195
195
|
status: res.statusCode,
|
|
196
|
-
ip:
|
|
196
|
+
ip: this.config.getRequestIp?.(req) ?? this.getIp(req),
|
|
197
197
|
createdAt: (0, import_date.nowISO)()
|
|
198
198
|
},
|
|
199
199
|
response: {
|
|
@@ -220,6 +220,27 @@ var ExpressAdapter = class extends import_core.LensAdapter {
|
|
|
220
220
|
return body;
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
+
getIp(req) {
|
|
224
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
225
|
+
const xff = req.headers["x-forwarded-for"];
|
|
226
|
+
if (typeof xff === "string") {
|
|
227
|
+
const [ip] = xff.split(",");
|
|
228
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
229
|
+
}
|
|
230
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
231
|
+
const ips = xff[0]?.split(",");
|
|
232
|
+
if (ips && ips.length > 0) {
|
|
233
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
237
|
+
}
|
|
238
|
+
normalizeIp(ip) {
|
|
239
|
+
if (ip.startsWith("::ffff:")) {
|
|
240
|
+
return ip.replace("::ffff:", "");
|
|
241
|
+
}
|
|
242
|
+
return ip;
|
|
243
|
+
}
|
|
223
244
|
};
|
|
224
245
|
|
|
225
246
|
// src/index.ts
|
package/dist/index.js
CHANGED
|
@@ -170,7 +170,7 @@ var ExpressAdapter = class extends LensAdapter {
|
|
|
170
170
|
headers: req.headers,
|
|
171
171
|
body: req.body ?? {},
|
|
172
172
|
status: res.statusCode,
|
|
173
|
-
ip:
|
|
173
|
+
ip: this.config.getRequestIp?.(req) ?? this.getIp(req),
|
|
174
174
|
createdAt: nowISO()
|
|
175
175
|
},
|
|
176
176
|
response: {
|
|
@@ -197,6 +197,27 @@ var ExpressAdapter = class extends LensAdapter {
|
|
|
197
197
|
return body;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
+
getIp(req) {
|
|
201
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
202
|
+
const xff = req.headers["x-forwarded-for"];
|
|
203
|
+
if (typeof xff === "string") {
|
|
204
|
+
const [ip] = xff.split(",");
|
|
205
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
208
|
+
const ips = xff[0]?.split(",");
|
|
209
|
+
if (ips && ips.length > 0) {
|
|
210
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
214
|
+
}
|
|
215
|
+
normalizeIp(ip) {
|
|
216
|
+
if (ip.startsWith("::ffff:")) {
|
|
217
|
+
return ip.replace("::ffff:", "");
|
|
218
|
+
}
|
|
219
|
+
return ip;
|
|
220
|
+
}
|
|
200
221
|
};
|
|
201
222
|
|
|
202
223
|
// src/index.ts
|
package/dist/types/index.d.cts
CHANGED
|
@@ -15,11 +15,13 @@ type ExpressAdapterConfig = {
|
|
|
15
15
|
};
|
|
16
16
|
isAuthenticated?: (request: Request) => Promise<boolean>;
|
|
17
17
|
getUser?: (request: Request) => Promise<UserEntry>;
|
|
18
|
+
getRequestIp?: (request: Request) => string;
|
|
18
19
|
} & Partial<LensConfig>;
|
|
19
20
|
type RequiredExpressAdapterConfig = Required<ExpressAdapterConfig> & {
|
|
20
21
|
queryWatcher?: ExpressAdapterConfig["queryWatcher"];
|
|
21
22
|
isAuthenticated?: ExpressAdapterConfig["isAuthenticated"];
|
|
22
23
|
getUser?: ExpressAdapterConfig["getUser"];
|
|
24
|
+
getRequestIp?: (request: Request) => string;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type { ExpressAdapterConfig, RequiredExpressAdapterConfig };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,11 +15,13 @@ type ExpressAdapterConfig = {
|
|
|
15
15
|
};
|
|
16
16
|
isAuthenticated?: (request: Request) => Promise<boolean>;
|
|
17
17
|
getUser?: (request: Request) => Promise<UserEntry>;
|
|
18
|
+
getRequestIp?: (request: Request) => string;
|
|
18
19
|
} & Partial<LensConfig>;
|
|
19
20
|
type RequiredExpressAdapterConfig = Required<ExpressAdapterConfig> & {
|
|
20
21
|
queryWatcher?: ExpressAdapterConfig["queryWatcher"];
|
|
21
22
|
isAuthenticated?: ExpressAdapterConfig["isAuthenticated"];
|
|
22
23
|
getUser?: ExpressAdapterConfig["getUser"];
|
|
24
|
+
getRequestIp?: (request: Request) => string;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type { ExpressAdapterConfig, RequiredExpressAdapterConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensjs/express",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Express adapter for LensJs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"express": "^5.1.0",
|
|
42
|
-
"@lensjs/core": "2.3.
|
|
42
|
+
"@lensjs/core": "2.3.2",
|
|
43
43
|
"@lensjs/typescript-config": "1.0.12",
|
|
44
|
-
"@lensjs/
|
|
45
|
-
"@lensjs/
|
|
44
|
+
"@lensjs/date": "1.0.12",
|
|
45
|
+
"@lensjs/watchers": "1.1.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/express": "^5.0.3",
|