@lensjs/fastify 1.1.1 → 1.1.3
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.d.cts +2 -0
- package/dist/types.d.ts +2 -0
- package/package.json +10 -9
package/dist/adapter.cjs
CHANGED
|
@@ -176,7 +176,7 @@ var FastifyAdapter = class extends import_core.LensAdapter {
|
|
|
176
176
|
headers: request.headers,
|
|
177
177
|
body: request.body ?? {},
|
|
178
178
|
status: reply.statusCode,
|
|
179
|
-
ip: request
|
|
179
|
+
ip: this.config.getRequestIp?.(request) ?? this.getIp(request),
|
|
180
180
|
createdAt: (0, import_date.nowISO)()
|
|
181
181
|
},
|
|
182
182
|
response: {
|
|
@@ -229,6 +229,27 @@ var FastifyAdapter = class extends import_core.LensAdapter {
|
|
|
229
229
|
return body;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
+
getIp(req) {
|
|
233
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
234
|
+
const xff = req.headers["x-forwarded-for"];
|
|
235
|
+
if (typeof xff === "string") {
|
|
236
|
+
const [ip] = xff.split(",");
|
|
237
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
238
|
+
}
|
|
239
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
240
|
+
const ips = xff[0]?.split(",");
|
|
241
|
+
if (ips && ips.length > 0) {
|
|
242
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
246
|
+
}
|
|
247
|
+
normalizeIp(ip) {
|
|
248
|
+
if (ip.startsWith("::ffff:")) {
|
|
249
|
+
return ip.replace("::ffff:", "");
|
|
250
|
+
}
|
|
251
|
+
return ip;
|
|
252
|
+
}
|
|
232
253
|
};
|
|
233
254
|
// Annotate the CommonJS export names for ESM import in node:
|
|
234
255
|
0 && (module.exports = {
|
package/dist/adapter.d.cts
CHANGED
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.js
CHANGED
|
@@ -148,7 +148,7 @@ var FastifyAdapter = class extends LensAdapter {
|
|
|
148
148
|
headers: request.headers,
|
|
149
149
|
body: request.body ?? {},
|
|
150
150
|
status: reply.statusCode,
|
|
151
|
-
ip: request
|
|
151
|
+
ip: this.config.getRequestIp?.(request) ?? this.getIp(request),
|
|
152
152
|
createdAt: nowISO()
|
|
153
153
|
},
|
|
154
154
|
response: {
|
|
@@ -201,6 +201,27 @@ var FastifyAdapter = class extends LensAdapter {
|
|
|
201
201
|
return body;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
+
getIp(req) {
|
|
205
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
206
|
+
const xff = req.headers["x-forwarded-for"];
|
|
207
|
+
if (typeof xff === "string") {
|
|
208
|
+
const [ip] = xff.split(",");
|
|
209
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
212
|
+
const ips = xff[0]?.split(",");
|
|
213
|
+
if (ips && ips.length > 0) {
|
|
214
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
218
|
+
}
|
|
219
|
+
normalizeIp(ip) {
|
|
220
|
+
if (ip.startsWith("::ffff:")) {
|
|
221
|
+
return ip.replace("::ffff:", "");
|
|
222
|
+
}
|
|
223
|
+
return ip;
|
|
224
|
+
}
|
|
204
225
|
};
|
|
205
226
|
export {
|
|
206
227
|
FastifyAdapter
|
package/dist/index.cjs
CHANGED
|
@@ -180,7 +180,7 @@ var FastifyAdapter = class extends import_core.LensAdapter {
|
|
|
180
180
|
headers: request.headers,
|
|
181
181
|
body: request.body ?? {},
|
|
182
182
|
status: reply.statusCode,
|
|
183
|
-
ip: request
|
|
183
|
+
ip: this.config.getRequestIp?.(request) ?? this.getIp(request),
|
|
184
184
|
createdAt: (0, import_date.nowISO)()
|
|
185
185
|
},
|
|
186
186
|
response: {
|
|
@@ -233,6 +233,27 @@ var FastifyAdapter = class extends import_core.LensAdapter {
|
|
|
233
233
|
return body;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
+
getIp(req) {
|
|
237
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
238
|
+
const xff = req.headers["x-forwarded-for"];
|
|
239
|
+
if (typeof xff === "string") {
|
|
240
|
+
const [ip] = xff.split(",");
|
|
241
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
242
|
+
}
|
|
243
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
244
|
+
const ips = xff[0]?.split(",");
|
|
245
|
+
if (ips && ips.length > 0) {
|
|
246
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
250
|
+
}
|
|
251
|
+
normalizeIp(ip) {
|
|
252
|
+
if (ip.startsWith("::ffff:")) {
|
|
253
|
+
return ip.replace("::ffff:", "");
|
|
254
|
+
}
|
|
255
|
+
return ip;
|
|
256
|
+
}
|
|
236
257
|
};
|
|
237
258
|
|
|
238
259
|
// src/index.ts
|
package/dist/index.js
CHANGED
|
@@ -159,7 +159,7 @@ var FastifyAdapter = class extends LensAdapter {
|
|
|
159
159
|
headers: request.headers,
|
|
160
160
|
body: request.body ?? {},
|
|
161
161
|
status: reply.statusCode,
|
|
162
|
-
ip: request
|
|
162
|
+
ip: this.config.getRequestIp?.(request) ?? this.getIp(request),
|
|
163
163
|
createdAt: nowISO()
|
|
164
164
|
},
|
|
165
165
|
response: {
|
|
@@ -212,6 +212,27 @@ var FastifyAdapter = class extends LensAdapter {
|
|
|
212
212
|
return body;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
+
getIp(req) {
|
|
216
|
+
if (req.ip) return this.normalizeIp(req.ip);
|
|
217
|
+
const xff = req.headers["x-forwarded-for"];
|
|
218
|
+
if (typeof xff === "string") {
|
|
219
|
+
const [ip] = xff.split(",");
|
|
220
|
+
return this.normalizeIp(ip?.trim() ?? "");
|
|
221
|
+
}
|
|
222
|
+
if (Array.isArray(xff) && xff.length > 0) {
|
|
223
|
+
const ips = xff[0]?.split(",");
|
|
224
|
+
if (ips && ips.length > 0) {
|
|
225
|
+
return this.normalizeIp(ips[0]?.trim() ?? "");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return this.normalizeIp(req.socket?.remoteAddress ?? "");
|
|
229
|
+
}
|
|
230
|
+
normalizeIp(ip) {
|
|
231
|
+
if (ip.startsWith("::ffff:")) {
|
|
232
|
+
return ip.replace("::ffff:", "");
|
|
233
|
+
}
|
|
234
|
+
return ip;
|
|
235
|
+
}
|
|
215
236
|
};
|
|
216
237
|
|
|
217
238
|
// src/index.ts
|
package/dist/types.d.cts
CHANGED
|
@@ -17,11 +17,13 @@ type FastifyAdapterConfig = {
|
|
|
17
17
|
};
|
|
18
18
|
isAuthenticated?: (request: FastifyRequest) => Promise<boolean>;
|
|
19
19
|
getUser?: (request: FastifyRequest) => Promise<UserEntry>;
|
|
20
|
+
getRequestIp?: (request: FastifyRequest) => string;
|
|
20
21
|
} & Partial<LensConfig>;
|
|
21
22
|
type RequiredFastifyAdapterConfig = Required<FastifyAdapterConfig> & {
|
|
22
23
|
queryWatcher?: FastifyAdapterConfig["queryWatcher"];
|
|
23
24
|
isAuthenticated?: FastifyAdapterConfig["isAuthenticated"];
|
|
24
25
|
getUser?: FastifyAdapterConfig["getUser"];
|
|
26
|
+
getRequestIp?: (request: FastifyRequest) => string;
|
|
25
27
|
};
|
|
26
28
|
declare module "fastify" {
|
|
27
29
|
interface FastifyReply {
|
package/dist/types.d.ts
CHANGED
|
@@ -17,11 +17,13 @@ type FastifyAdapterConfig = {
|
|
|
17
17
|
};
|
|
18
18
|
isAuthenticated?: (request: FastifyRequest) => Promise<boolean>;
|
|
19
19
|
getUser?: (request: FastifyRequest) => Promise<UserEntry>;
|
|
20
|
+
getRequestIp?: (request: FastifyRequest) => string;
|
|
20
21
|
} & Partial<LensConfig>;
|
|
21
22
|
type RequiredFastifyAdapterConfig = Required<FastifyAdapterConfig> & {
|
|
22
23
|
queryWatcher?: FastifyAdapterConfig["queryWatcher"];
|
|
23
24
|
isAuthenticated?: FastifyAdapterConfig["isAuthenticated"];
|
|
24
25
|
getUser?: FastifyAdapterConfig["getUser"];
|
|
26
|
+
getRequestIp?: (request: FastifyRequest) => string;
|
|
25
27
|
};
|
|
26
28
|
declare module "fastify" {
|
|
27
29
|
interface FastifyReply {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensjs/fastify",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Fastify adapter for LensJs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,19 +18,20 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@lensjs/core": "2.3.1",
|
|
23
|
-
"@lensjs/typescript-config": "1.0.12",
|
|
21
|
+
"@lensjs/core": "2.4.0",
|
|
24
22
|
"@lensjs/date": "1.0.12",
|
|
25
|
-
"@lensjs/
|
|
23
|
+
"@lensjs/typescript-config": "1.0.12",
|
|
24
|
+
"@lensjs/watchers": "1.1.3"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"fastify": "^5.2.1",
|
|
28
|
+
"@fastify/static": "^8.2.0"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"fastify": "^5.
|
|
31
|
+
"fastify": "^5.7.4",
|
|
32
|
+
"@fastify/static": "^8.2.0",
|
|
29
33
|
"vitest": "^3.2.4"
|
|
30
34
|
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"fastify": "^5.2.1"
|
|
33
|
-
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "tsup --clean",
|
|
36
37
|
"test": "vitest run"
|