@dnax/core 0.4.9 → 0.5.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 +31 -7
- package/lib/orama/index.ts +7 -0
- package/package.json +2 -2
- package/types/index.ts +6 -0
package/app/hono.ts
CHANGED
|
@@ -20,16 +20,35 @@ import { pick } from "radash";
|
|
|
20
20
|
import { secureHeaders } from "hono/secure-headers";
|
|
21
21
|
import { getTenant } from "../lib/tenant";
|
|
22
22
|
import { checkPermission, getPermission } from "../lib/permissions";
|
|
23
|
+
import { ipRestriction } from "hono/ip-restriction";
|
|
24
|
+
import { logger } from "hono/logger";
|
|
23
25
|
const app = new Hono();
|
|
24
26
|
|
|
25
27
|
const API_PATH = "/api";
|
|
26
28
|
function HonoInstance(): typeof app {
|
|
29
|
+
if (Cfg?.server?.logger) {
|
|
30
|
+
if (typeof Cfg?.server?.logger == "function") {
|
|
31
|
+
app.use(async (c, next) => {
|
|
32
|
+
Cfg?.server?.logger(c);
|
|
33
|
+
return await next();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (typeof Cfg?.server?.logger == "boolean") {
|
|
37
|
+
app.use(logger());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
app.use(
|
|
41
|
+
ipRestriction(getConnInfo, {
|
|
42
|
+
allowList: Cfg?.server?.whiteListIps || [],
|
|
43
|
+
denyList: Cfg?.server?.blackListIps || [],
|
|
44
|
+
// blackList: Cfg.server?.ipBlackList || [],
|
|
45
|
+
})
|
|
46
|
+
);
|
|
27
47
|
app.use(secureHeaders());
|
|
28
|
-
|
|
29
48
|
app.use(
|
|
30
49
|
cors({
|
|
31
50
|
origin: Cfg.server?.cors?.origin || [],
|
|
32
|
-
credentials: true,
|
|
51
|
+
credentials: Cfg.server?.cors?.credentials || true,
|
|
33
52
|
})
|
|
34
53
|
);
|
|
35
54
|
//eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoibm9tIiwiaWF0IjoxNzE3Nzc0MDQzLCJleHAiOjE3MTc3NzQxMDN9.Ud4-0y8pa4SMIcSn8PU1A-sjC-hT4ZVe_u3AdChyIJU
|
|
@@ -41,8 +60,11 @@ function HonoInstance(): typeof app {
|
|
|
41
60
|
let session = sessionStorage();
|
|
42
61
|
var token = jwt.getToken("Bearer", c.req.header()["authorization"]) || "";
|
|
43
62
|
var { decode, valid, error } = jwt.verify(token);
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
if (valid && decode?.studio) {
|
|
64
|
+
// FIX STUDIO INFO
|
|
65
|
+
c.set("_STUDIO_SECRET_KEY_", secretKeyStudio);
|
|
66
|
+
c.set("isStudio", isStudio(secretKeyStudio));
|
|
67
|
+
}
|
|
46
68
|
let _v = {
|
|
47
69
|
token: token || null,
|
|
48
70
|
ip:
|
|
@@ -379,7 +401,7 @@ function HonoInstance(): typeof app {
|
|
|
379
401
|
|
|
380
402
|
return c.json(response);
|
|
381
403
|
} catch (err: any) {
|
|
382
|
-
|
|
404
|
+
if (Cfg?.debug) console.log(err?.message | err);
|
|
383
405
|
if (err?.code && (err?.code < 200 || err?.code > 599)) {
|
|
384
406
|
err.code = 409;
|
|
385
407
|
}
|
|
@@ -390,9 +412,10 @@ function HonoInstance(): typeof app {
|
|
|
390
412
|
}
|
|
391
413
|
});
|
|
392
414
|
|
|
393
|
-
app.post("/api/studio", (c, next) => {
|
|
415
|
+
app.post("/api/studio", async (c, next) => {
|
|
394
416
|
let cookie = getCookie(c);
|
|
395
|
-
let
|
|
417
|
+
let body = await c?.req?.json();
|
|
418
|
+
let secretKeyStudio = body?.secret || cookie["_STUDIO_SECRET_KEY_"];
|
|
396
419
|
let canPerform = isStudio(secretKeyStudio);
|
|
397
420
|
let cf = {
|
|
398
421
|
collections: Cfg.collections?.map((c) =>
|
|
@@ -405,6 +428,7 @@ function HonoInstance(): typeof app {
|
|
|
405
428
|
return c.json({
|
|
406
429
|
auth: true,
|
|
407
430
|
data: cf,
|
|
431
|
+
token: jwt.sign({ studio: true }),
|
|
408
432
|
});
|
|
409
433
|
} else {
|
|
410
434
|
c.status(403);
|
package/lib/orama/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"find-open-port": "^2.0.3",
|
|
30
30
|
"fs-extra": "^11.2.0",
|
|
31
31
|
"generate-unique-id": "^2.0.3",
|
|
32
|
-
"hono": "^4.5.
|
|
32
|
+
"hono": "^4.5.9",
|
|
33
33
|
"joi": "^17.13.3",
|
|
34
34
|
"json-joy": "^16.8.0",
|
|
35
35
|
"jsonwebtoken": "^9.0.2",
|
package/types/index.ts
CHANGED
|
@@ -294,6 +294,8 @@ export type Collection = {
|
|
|
294
294
|
}>;
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
+
export type loggerFunction = (c: Context) => void;
|
|
298
|
+
|
|
297
299
|
export type Config = {
|
|
298
300
|
email?: {
|
|
299
301
|
provider: "smtp";
|
|
@@ -335,8 +337,12 @@ export type Config = {
|
|
|
335
337
|
};
|
|
336
338
|
|
|
337
339
|
server: {
|
|
340
|
+
logger?: Boolean | loggerFunction;
|
|
341
|
+
whiteListIps?: Array<string>;
|
|
342
|
+
blackListIps?: Array<string>;
|
|
338
343
|
cors?: {
|
|
339
344
|
origin: string[];
|
|
345
|
+
credentials?: boolean;
|
|
340
346
|
};
|
|
341
347
|
socket?: {
|
|
342
348
|
/**
|