@dnax/core 0.5.8 → 0.6.1
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/app/hono.ts +10 -3
- package/package.json +1 -1
- package/utils/index.ts +28 -0
package/app/hono.ts
CHANGED
|
@@ -62,6 +62,12 @@ function HonoInstance(): typeof app {
|
|
|
62
62
|
}
|
|
63
63
|
if (typeof Cfg?.server?.logger == "boolean" && Cfg?.server?.logger) {
|
|
64
64
|
app.use(async (c, next) => {
|
|
65
|
+
let ip =
|
|
66
|
+
c.req.raw.headers?.get("CF-Connecting-IP") ||
|
|
67
|
+
c.req.raw.headers?.get("x-forwarded-for") ||
|
|
68
|
+
c.req.raw.headers?.get("x-real-ip");
|
|
69
|
+
const origin =
|
|
70
|
+
c.req?.header("Origin") || c.req.raw?.headers?.get("Origin") || "";
|
|
65
71
|
const info = getConnInfo(c);
|
|
66
72
|
if (c.req.method == "OPTIONS") return await next();
|
|
67
73
|
const start = Date.now();
|
|
@@ -69,7 +75,7 @@ function HonoInstance(): typeof app {
|
|
|
69
75
|
c.req.query() as Q;
|
|
70
76
|
// Log the incoming request
|
|
71
77
|
console.log(
|
|
72
|
-
`<-- ${info.remote.address} | ${c.req.method.gray} ${
|
|
78
|
+
`<-- ${ip || info.remote.address} ${origin} | ${c.req.method.gray} ${
|
|
73
79
|
c.req.path?.gray
|
|
74
80
|
} -C ${colors.blue(`${collection || ""}`)} -A ${
|
|
75
81
|
action?.gray || ""
|
|
@@ -82,11 +88,11 @@ function HonoInstance(): typeof app {
|
|
|
82
88
|
// Calculate the duration of the request processing
|
|
83
89
|
const duration = Date.now() - start;
|
|
84
90
|
console.log(
|
|
85
|
-
`--> ${info.remote.address} | ${c.req.method.gray} ${
|
|
91
|
+
`--> ${ip || info.remote.address} ${origin} | ${c.req.method.gray} ${
|
|
86
92
|
c.req.path?.gray
|
|
87
93
|
} -C ${colors.blue(`${collection || ""}`)} -A ${
|
|
88
94
|
action?.gray || ""
|
|
89
|
-
} -Sn ${name?.gray || ""}
|
|
95
|
+
} -Sn ${name?.gray || ""} -s ${c.res.status} -d ${colors.green(
|
|
90
96
|
`(${duration}ms)`
|
|
91
97
|
)} -t ${moment().format("YYYY-DD-MM:HH:mm:ss").gray} \n`
|
|
92
98
|
);
|
|
@@ -121,6 +127,7 @@ function HonoInstance(): typeof app {
|
|
|
121
127
|
c.set("_STUDIO_SECRET_KEY_", secretKeyStudio);
|
|
122
128
|
c.set("isStudio", isStudio(secretKeyStudio));
|
|
123
129
|
}
|
|
130
|
+
|
|
124
131
|
let _v = {
|
|
125
132
|
token: token || null,
|
|
126
133
|
ip:
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -232,6 +232,33 @@ function omit(data: object[] | object, keysToRemove: string[]) {
|
|
|
232
232
|
});
|
|
233
233
|
return json;
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
* @param {object|object[]} data - data
|
|
238
|
+
* @param {string[]} keys - keys to pick
|
|
239
|
+
* @returns {object|object[]} - data with the keys
|
|
240
|
+
|
|
241
|
+
*/
|
|
242
|
+
function pick(data: object | object[], keys: string[]): object {
|
|
243
|
+
const extractValues = (item) => {
|
|
244
|
+
return keys.reduce((result, keyPath) => {
|
|
245
|
+
const keys = keyPath.split(".");
|
|
246
|
+
const value = keys.reduce((acc, key) => acc && acc[key], item);
|
|
247
|
+
if (value !== undefined) {
|
|
248
|
+
result[keyPath] = value;
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}, {});
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
if (Array.isArray(data)) {
|
|
255
|
+
return data.map((item) => extractValues(item));
|
|
256
|
+
} else if (typeof data === "object" && data !== null) {
|
|
257
|
+
return extractValues(data);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
235
262
|
|
|
236
263
|
class contextError extends Error {
|
|
237
264
|
constructor(message: string, code: number) {
|
|
@@ -253,6 +280,7 @@ const password = {
|
|
|
253
280
|
};
|
|
254
281
|
|
|
255
282
|
export {
|
|
283
|
+
pick,
|
|
256
284
|
password, // Hash and verify Password utils
|
|
257
285
|
email, // smtp utils
|
|
258
286
|
moment,
|