miqro 7.2.7 → 7.2.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/build/esm/editor/auth.d.ts +6 -0
- package/build/esm/editor/auth.js +42 -0
- package/build/esm/editor/common/constants.d.ts +4 -0
- package/build/esm/editor/common/constants.js +20 -0
- package/build/esm/editor/common/constants.server.d.ts +2 -0
- package/build/esm/editor/common/constants.server.js +4 -0
- package/build/esm/editor/common/editor-index.d.ts +2 -0
- package/build/esm/editor/common/editor-index.js +14 -0
- package/build/esm/editor/common/html-encode.d.ts +1 -0
- package/build/esm/editor/common/html-encode.js +14 -0
- package/build/esm/editor/common/log-socket.d.ts +15 -0
- package/build/esm/editor/common/log-socket.js +71 -0
- package/build/esm/editor/common/templates.d.ts +11 -0
- package/build/esm/editor/common/templates.js +477 -0
- package/build/esm/editor/components/api-preview.d.ts +11 -0
- package/build/esm/editor/components/api-preview.js +92 -0
- package/build/esm/editor/components/editor.d.ts +16 -0
- package/build/esm/editor/components/editor.js +367 -0
- package/build/esm/editor/components/file-browser.d.ts +37 -0
- package/build/esm/editor/components/file-browser.js +127 -0
- package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
- package/build/esm/editor/components/file-editor-toolbar.js +95 -0
- package/build/esm/editor/components/file-editor.d.ts +32 -0
- package/build/esm/editor/components/file-editor.js +61 -0
- package/build/esm/editor/components/filter-query.d.ts +1 -0
- package/build/esm/editor/components/filter-query.js +23 -0
- package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
- package/build/esm/editor/components/highlight-text-area.js +127 -0
- package/build/esm/editor/components/log-viewer.d.ts +6 -0
- package/build/esm/editor/components/log-viewer.js +71 -0
- package/build/esm/editor/components/new-file.d.ts +10 -0
- package/build/esm/editor/components/new-file.js +119 -0
- package/build/esm/editor/components/scroll-query.d.ts +7 -0
- package/build/esm/editor/components/scroll-query.js +22 -0
- package/build/esm/editor/components/start-page.d.ts +13 -0
- package/build/esm/editor/components/start-page.js +32 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +4 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +7 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +7 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
- package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +8 -0
- package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/index.api.js +23 -0
- package/build/esm/editor/server.d.ts +3 -0
- package/build/esm/editor/server.js +49 -0
- package/build/esm/editor/ws.d.ts +3 -0
- package/build/esm/editor/ws.js +12 -0
- package/build/esm/src/common/admin-interface.d.ts +36 -0
- package/build/esm/src/common/admin-interface.js +44 -0
- package/build/esm/src/services/app.d.ts +1 -1
- package/build/esm/src/services/editor.d.ts +1 -1
- package/build/esm/src/services/utils/admin-interface.d.ts +1 -1
- package/build/esm/src/services/utils/websocketmanager.d.ts +1 -1
- package/editor/auth.ts +52 -0
- package/editor/common/constants.server.ts +5 -0
- package/editor/common/constants.ts +21 -0
- package/editor/common/editor-index.tsx +17 -0
- package/editor/common/html-encode.ts +14 -0
- package/editor/common/log-socket.tsx +87 -0
- package/editor/common/templates.ts +481 -0
- package/editor/components/api-preview.tsx +118 -0
- package/editor/components/editor.tsx +496 -0
- package/editor/components/file-browser.tsx +311 -0
- package/editor/components/file-editor-toolbar.tsx +194 -0
- package/editor/components/file-editor.tsx +125 -0
- package/editor/components/filter-query.tsx +26 -0
- package/editor/components/highlight-text-area.tsx +148 -0
- package/editor/components/log-viewer.tsx +113 -0
- package/editor/components/new-file.tsx +172 -0
- package/editor/components/scroll-query.tsx +25 -0
- package/editor/components/start-page.tsx +52 -0
- package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
- package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
- package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
- package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
- package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
- package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
- package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
- package/editor/http/admin/editor/editor.tsx +10 -0
- package/editor/http/admin/editor/index.api.tsx +43 -0
- package/editor/server.ts +57 -0
- package/editor/ws.ts +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuthConfig } from "../src/types.js";
|
|
2
|
+
export declare const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
|
|
3
|
+
export declare const ADMIN_EDITOR_AUTH_QUERY = "key";
|
|
4
|
+
export declare const ADMIN_EDITOR_AUTH_COOKIE = "$$ADMIN_EDITOR_AUTH_KEY$$";
|
|
5
|
+
declare const _default: AuthConfig;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
export const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
|
|
3
|
+
export const ADMIN_EDITOR_AUTH_QUERY = "key";
|
|
4
|
+
export const ADMIN_EDITOR_AUTH_COOKIE = ADMIN_EDITOR_AUTH_KEY;
|
|
5
|
+
export default {
|
|
6
|
+
authService: {
|
|
7
|
+
verify: async (args) => {
|
|
8
|
+
const adminInterface = args.req.editor;
|
|
9
|
+
const serverInterface = args.req.server;
|
|
10
|
+
const KEY = (adminInterface ? adminInterface.getCache() : serverInterface.cache).get(ADMIN_EDITOR_AUTH_KEY);
|
|
11
|
+
const validSesson = {
|
|
12
|
+
username: "username",
|
|
13
|
+
account: "account",
|
|
14
|
+
groups: [],
|
|
15
|
+
token: args.token
|
|
16
|
+
};
|
|
17
|
+
const queryToken = args.req.query[ADMIN_EDITOR_AUTH_QUERY];
|
|
18
|
+
const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
|
|
19
|
+
//console.log("\n\nqueryToken[%s] cookieToken[%s] KEY[%s]\n\n", queryToken, cookieToken, KEY);
|
|
20
|
+
if (queryToken) {
|
|
21
|
+
if (typeof queryToken === "string" && timingSafeEqual(Buffer.from(queryToken), Buffer.from(KEY))) {
|
|
22
|
+
args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
|
|
23
|
+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 31 * 12 * 500),
|
|
24
|
+
httpOnly: true,
|
|
25
|
+
//secure: true,
|
|
26
|
+
path: "/",
|
|
27
|
+
//sameSite: "strict"
|
|
28
|
+
});
|
|
29
|
+
args.req.searchParams.delete(ADMIN_EDITOR_AUTH_QUERY);
|
|
30
|
+
const queryString = args.req.searchParams.toString();
|
|
31
|
+
const redirect = args.req.path + (queryString ? "?" + queryString : "");
|
|
32
|
+
await args.res.redirect(redirect);
|
|
33
|
+
return validSesson;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (cookieToken) {
|
|
37
|
+
return cookieToken === KEY ? validSesson : null;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const BASEEDITOR_PATH = "/admin/editor";
|
|
2
|
+
export const LOG_SOCKET_PATH = "/admin/socket";
|
|
3
|
+
export const LOG_WRITE_EVENT = "LogWrite";
|
|
4
|
+
export const SUPPORTED_LANGUAGES = [
|
|
5
|
+
"text",
|
|
6
|
+
"json",
|
|
7
|
+
"javascript",
|
|
8
|
+
"typescript",
|
|
9
|
+
"dockerfile",
|
|
10
|
+
"yaml",
|
|
11
|
+
"xml",
|
|
12
|
+
"html",
|
|
13
|
+
"css",
|
|
14
|
+
"scss",
|
|
15
|
+
"markdown",
|
|
16
|
+
"c",
|
|
17
|
+
"cpp",
|
|
18
|
+
"bash",
|
|
19
|
+
"python"
|
|
20
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { scanDir } from "../http/admin/editor/api/fs/scan.api.js";
|
|
2
|
+
import { parseInflateErrors } from "../http/admin/editor/api/server/restart.api.js";
|
|
3
|
+
import { HTMLEncode } from "./html-encode.js";
|
|
4
|
+
export function EditorIndex(editorCSS, editorJS, enableHotReload) {
|
|
5
|
+
return async function editorIndex(req, res) {
|
|
6
|
+
const admin = req.editor;
|
|
7
|
+
const errors = parseInflateErrors(admin ? admin.getInflateErrors() : []);
|
|
8
|
+
const files = scanDir(req);
|
|
9
|
+
const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
|
|
10
|
+
const services = admin ? admin.getServices() : ["."];
|
|
11
|
+
const hotReload = enableHotReload ? (admin ? admin.getHotReloadHTML() : "") : "";
|
|
12
|
+
res.html(`<!DOCTYPE html><html><body><style>${editorCSS}</style><script type="module">${editorJS}</script><editor-component class="main-container" reloadstring="${req.uuid}" migrations="${HTMLEncode(JSON.stringify(migrations))}" services="${HTMLEncode(JSON.stringify(services))}" errors="${HTMLEncode(JSON.stringify(errors))}" files="${HTMLEncode(JSON.stringify(files))}"><noscript>Enable JavaScript</noscript></editor-component>${hotReload}</body></html>`);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function HTMLEncode(str: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function HTMLEncode(str) {
|
|
2
|
+
let i = str.length;
|
|
3
|
+
const aRet = [];
|
|
4
|
+
while (i--) {
|
|
5
|
+
const iC = str[i].charCodeAt(0);
|
|
6
|
+
if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
|
|
7
|
+
aRet[i] = '&#' + iC + ';';
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
aRet[i] = str[i];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return aRet.join('');
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface LogLine {
|
|
2
|
+
out: string;
|
|
3
|
+
identifier: string;
|
|
4
|
+
level: "error" | "warn" | "debug" | "trace" | "info";
|
|
5
|
+
}
|
|
6
|
+
export interface LogSocket {
|
|
7
|
+
lines: LogLine[];
|
|
8
|
+
clearLog: () => void;
|
|
9
|
+
getMaxlogsize: () => number | "unlimited";
|
|
10
|
+
setMaxLogSize: (val: number | "unlimited") => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useLogSocket(options: {
|
|
13
|
+
disableLog?: boolean;
|
|
14
|
+
}): LogSocket;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as jsx from "@miqro/jsx";
|
|
2
|
+
export function useLogSocket(options) {
|
|
3
|
+
const [_, setmaxLogSize, getMaxlogsize] = jsx.useState(1000000);
|
|
4
|
+
const [__, setlines, getLines] = jsx.useState([]);
|
|
5
|
+
const refresh = jsx.useRefresh();
|
|
6
|
+
jsx.useEffect(() => {
|
|
7
|
+
let timeout;
|
|
8
|
+
function setupSocket() {
|
|
9
|
+
try {
|
|
10
|
+
if (options.disableLog) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.log("setting up log socket");
|
|
14
|
+
const socket = new WebSocket("/admin/socket");
|
|
15
|
+
socket.addEventListener("error", (err) => {
|
|
16
|
+
console.error(err);
|
|
17
|
+
clearTimeout(timeout);
|
|
18
|
+
timeout = setTimeout(() => {
|
|
19
|
+
setupSocket();
|
|
20
|
+
}, 1000);
|
|
21
|
+
});
|
|
22
|
+
socket.addEventListener("open", () => {
|
|
23
|
+
console.log("log socket open");
|
|
24
|
+
clearTimeout(timeout);
|
|
25
|
+
socket.addEventListener("message", (msg) => {
|
|
26
|
+
const lines = getLines();
|
|
27
|
+
const data = JSON.parse(msg.data);
|
|
28
|
+
//console.log(data.out);
|
|
29
|
+
const maxLogSize = getMaxlogsize();
|
|
30
|
+
if (maxLogSize !== "unlimited" && lines.length >= maxLogSize) {
|
|
31
|
+
lines.splice(0, (lines.length - maxLogSize) + 1);
|
|
32
|
+
}
|
|
33
|
+
lines.push(data);
|
|
34
|
+
setlines(lines);
|
|
35
|
+
refresh();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
socket.addEventListener("close", () => {
|
|
39
|
+
console.log("log socket close");
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
timeout = setTimeout(() => {
|
|
42
|
+
setupSocket();
|
|
43
|
+
}, 1000);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
timeout = setTimeout(() => {
|
|
50
|
+
setupSocket();
|
|
51
|
+
}, 1000);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setupSocket();
|
|
55
|
+
}, []);
|
|
56
|
+
return {
|
|
57
|
+
lines: getLines(),
|
|
58
|
+
clearLog: () => {
|
|
59
|
+
setlines([]);
|
|
60
|
+
},
|
|
61
|
+
getMaxlogsize,
|
|
62
|
+
setMaxLogSize: (newValue) => {
|
|
63
|
+
if (newValue === "unlimited") {
|
|
64
|
+
setmaxLogSize(newValue);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
setmaxLogSize(newValue);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|