miqro 6.3.0 → 7.0.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/README.md +9 -17
- package/build/editor.bundle.js +11601 -10129
- package/build/esm/editor/common/log-socket.js +1 -0
- package/build/esm/editor/common/templates.js +90 -90
- package/build/esm/editor/components/api-preview.js +2 -0
- package/build/esm/editor/components/editor.js +2 -0
- package/build/esm/editor/components/file-browser.js +1 -0
- package/build/esm/editor/components/file-editor-toolbar.js +2 -0
- package/build/esm/editor/components/file-editor.js +2 -0
- package/build/esm/editor/components/filter-query.js +1 -0
- package/build/esm/editor/components/highlight-text-area.js +2 -0
- package/build/esm/editor/components/log-viewer.js +2 -0
- package/build/esm/editor/components/new-file.js +2 -0
- package/build/esm/editor/components/scroll-query.js +1 -0
- package/build/esm/editor/components/start-page.js +2 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +2 -1
- package/build/esm/editor/http/admin/editor/editor.js +2 -1
- package/build/esm/editor/http/admin/editor/index.api.js +1 -0
- package/build/esm/src/bin/types.js +10 -5
- package/build/esm/src/cluster.js +1 -1
- package/build/esm/src/common/arguments.d.ts +1 -1
- package/build/esm/src/common/arguments.js +28 -14
- package/build/esm/src/common/assets.d.ts +1 -1
- package/build/esm/src/common/assets.js +34 -13
- package/build/esm/src/common/esbuild.d.ts +4 -1
- package/build/esm/src/common/esbuild.js +31 -26
- package/build/esm/src/common/exit.js +4 -4
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +0 -1
- package/build/esm/src/common/jsx.d.ts +2 -3
- package/build/esm/src/common/jsx.js +70 -75
- package/build/esm/src/common/paths.d.ts +0 -1
- package/build/esm/src/common/paths.js +3 -3
- package/build/esm/src/common/watch.d.ts +0 -1
- package/build/esm/src/common/watch.js +1 -1
- package/build/esm/src/inflate/inflate-sea.js +35 -24
- package/build/esm/src/inflate/inflate.js +4 -4
- package/build/esm/src/inflate/setup-auth.js +1 -1
- package/build/esm/src/inflate/setup-cors.js +1 -1
- package/build/esm/src/inflate/setup-db.js +2 -2
- package/build/esm/src/inflate/setup-error.js +1 -1
- package/build/esm/src/inflate/setup-http.js +16 -16
- package/build/esm/src/inflate/setup-log.js +1 -1
- package/build/esm/src/inflate/setup-middleware.js +1 -1
- package/build/esm/src/inflate/setup-server-config.js +1 -1
- package/build/esm/src/inflate/setup-ws.js +1 -1
- package/build/esm/src/inflate/setup.doc.d.ts +2 -2
- package/build/esm/src/inflate/setup.doc.js +23 -2
- package/build/esm/src/inflate/utils/sea-utils.js +2 -2
- package/build/esm/src/lib.d.ts +10 -1
- package/build/esm/src/lib.js +16 -1
- package/build/esm/src/main.js +1 -1
- package/build/esm/src/services/app.js +3 -4
- package/build/esm/src/services/migrations.js +2 -2
- package/build/esm/src/services/utils/jwt.d.ts +2 -0
- package/build/esm/src/services/utils/jwt.js +23 -0
- package/build/esm/src/services/utils/middleware.d.ts +9 -0
- package/build/esm/src/services/utils/middleware.js +9 -0
- package/build/esm/src/services/utils/server-interface.js +33 -4
- package/build/esm/src/types.d.ts +50 -83
- package/build/lib.cjs +15684 -15612
- package/editor/common/log-socket.tsx +2 -0
- package/editor/common/templates.ts +12 -12
- package/editor/components/api-preview.tsx +2 -0
- package/editor/components/editor.tsx +2 -0
- package/editor/components/file-browser.tsx +3 -0
- package/editor/components/file-editor-toolbar.tsx +3 -0
- package/editor/components/file-editor.tsx +3 -0
- package/editor/components/filter-query.tsx +4 -0
- package/editor/components/highlight-text-area.tsx +3 -0
- package/editor/components/log-viewer.tsx +3 -0
- package/editor/components/new-file.tsx +3 -0
- package/editor/components/scroll-query.tsx +3 -0
- package/editor/components/start-page.tsx +3 -0
- package/editor/http/admin/editor/api/fs/delete.api.tsx +2 -2
- package/editor/http/admin/editor/api/fs/read.api.tsx +2 -2
- package/editor/http/admin/editor/api/fs/rename.api.tsx +2 -2
- package/editor/http/admin/editor/api/fs/scan.api.tsx +2 -2
- package/editor/http/admin/editor/api/fs/write.api.tsx +2 -2
- package/editor/http/admin/editor/api/server/restart.api.tsx +2 -2
- package/editor/http/admin/editor/editor.tsx +3 -1
- package/editor/http/admin/editor/index.api.tsx +3 -0
- package/package.json +6 -8
- package/sea/basic-compile.base64.sh +1 -1
- package/sea/basic-compile.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/src/bin/types.ts +7 -2
- package/src/cluster.ts +1 -1
- package/src/common/arguments.ts +27 -10
- package/src/common/assets.ts +32 -12
- package/src/common/esbuild.ts +11 -3
- package/src/common/exit.ts +3 -3
- package/src/common/help.ts +0 -1
- package/src/common/jsx.ts +50 -35
- package/src/common/paths.ts +2 -2
- package/src/common/watch.ts +1 -1
- package/src/inflate/inflate-sea.ts +35 -24
- package/src/inflate/inflate.ts +4 -4
- package/src/inflate/setup-auth.ts +1 -1
- package/src/inflate/setup-cors.ts +1 -1
- package/src/inflate/setup-db.ts +2 -2
- package/src/inflate/setup-error.ts +1 -1
- package/src/inflate/setup-http.ts +16 -16
- package/src/inflate/setup-log.ts +1 -1
- package/src/inflate/setup-middleware.ts +1 -1
- package/src/inflate/setup-server-config.ts +1 -1
- package/src/inflate/setup-ws.ts +1 -1
- package/src/inflate/setup.doc.ts +27 -3
- package/src/inflate/utils/sea-utils.ts +2 -2
- package/src/lib.ts +17 -2
- package/src/main.ts +1 -1
- package/src/services/app.ts +4 -4
- package/src/services/migrations.ts +2 -2
- package/src/services/utils/jwt.ts +25 -0
- package/src/services/utils/middleware.ts +10 -0
- package/src/services/utils/server-interface.ts +37 -7
- package/src/types.ts +56 -53
- package/.eslintrc +0 -15
- package/build/esm/src/services/globals.d.ts +0 -3
- package/build/esm/src/services/globals.js +0 -182
- package/build/jsx.dom.js +0 -1587
- package/build/postject.base64.cjs +0 -1
- package/sea/types.json +0 -1
- package/src/types/@esbuild.d.ts +0 -1
- package/src/types/@miqro/core.d.ts +0 -2
- package/src/types/@miqro/jsx.d.ts +0 -2
- package/src/types/@miqro/parser.d.ts +0 -2
- package/src/types/@miqro/query.d.ts +0 -2
- package/src/types/@miqro/request.d.ts +0 -2
- package/src/types/@miqro/test.d.ts +0 -2
- package/src/types/@miqro.d.ts +0 -1
- package/src/types/@types.d.ts +0 -1
- package/src/types/browser.globals.d.ts +0 -1
- package/src/types/cookie.d.ts +0 -2
- package/src/types/globals.d.ts +0 -2
- package/src/types/jose.d.ts +0 -2
- package/src/types/jsx.globals.d.ts +0 -38
- package/src/types/miqro.d.ts +0 -228
- package/src/types/postject.d.ts +0 -1
- package/src/types/server.globals.d.ts +0 -47
- package/tsconfig.json +0 -35
- /package/src/services/{globals.ts → globals.ts.ignore} +0 -0
package/src/inflate/setup-log.ts
CHANGED
|
@@ -26,7 +26,7 @@ export async function setupLogConfig(logger: Logger, servicePath: string, servic
|
|
|
26
26
|
});
|
|
27
27
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
28
28
|
writeFileSync(inflatePath, await inflateJSX(logPath, {
|
|
29
|
-
embemedJSX: false,
|
|
29
|
+
// embemedJSX: false,
|
|
30
30
|
minify: false,
|
|
31
31
|
useExport: true,
|
|
32
32
|
platform: "node",
|
|
@@ -25,7 +25,7 @@ export async function setupMiddleware(logger: Logger, servicePath: string, servi
|
|
|
25
25
|
});
|
|
26
26
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
27
27
|
writeFileSync(inflatePath, await inflateJSX(middlewarePath, {
|
|
28
|
-
embemedJSX: false,
|
|
28
|
+
// embemedJSX: false,
|
|
29
29
|
minify: false,
|
|
30
30
|
platform: "node",
|
|
31
31
|
useExport: true,
|
|
@@ -29,7 +29,7 @@ export async function setupServerConfig(logger: Logger, servicePath: string, ser
|
|
|
29
29
|
});
|
|
30
30
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
31
31
|
writeFileSync(inflatePath, await inflateJSX(serverPath, {
|
|
32
|
-
embemedJSX: false,
|
|
32
|
+
// embemedJSX: false,
|
|
33
33
|
minify: false,
|
|
34
34
|
platform: "node",
|
|
35
35
|
useExport: true,
|
package/src/inflate/setup-ws.ts
CHANGED
|
@@ -29,7 +29,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
|
|
|
29
29
|
});
|
|
30
30
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
31
31
|
writeFileSync(inflatePath, await inflateJSX(wsPath, {
|
|
32
|
-
embemedJSX: false,
|
|
32
|
+
// embemedJSX: false,
|
|
33
33
|
minify: false,
|
|
34
34
|
platform: "node",
|
|
35
35
|
useExport: true,
|
package/src/inflate/setup.doc.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { basename, dirname, join, relative, resolve } from "node:path";
|
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { cwd } from "node:process";
|
|
7
7
|
import { getDocOutput } from "../bin/generate-doc.js";
|
|
8
|
-
import { RouteFileMap } from "./setup-http.js";
|
|
8
|
+
import { RouteFileMap, StaticFileMap } from "./setup-http.js";
|
|
9
9
|
import { CONTENT_TYPE_MAP } from "../common/content-type.js";
|
|
10
10
|
|
|
11
|
-
export async function setupDoc(logger: Logger, servicePath: string, service: string, mainRouter: Router, fileMap: RouteFileMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
11
|
+
export async function setupDoc(logger: Logger, servicePath: string, service: string, mainRouter: Router, fileMap: RouteFileMap, staticFileMap: StaticFileMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
12
12
|
const docPath = getDocConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
13
13
|
|
|
14
14
|
if (docPath) {
|
|
@@ -20,11 +20,13 @@ export async function setupDoc(logger: Logger, servicePath: string, service: str
|
|
|
20
20
|
for (const path of paths) {
|
|
21
21
|
const config = docModule.publish[path];
|
|
22
22
|
|
|
23
|
+
const contentType = config.type === "MD" ? CONTENT_TYPE_MAP[".md"] :
|
|
24
|
+
config.type === "JSON" ? CONTENT_TYPE_MAP[".json"] : CONTENT_TYPE_MAP[".html"];
|
|
25
|
+
|
|
23
26
|
const body = await getDocOutput(mainRouter, fileMap, config.all, config.type);
|
|
24
27
|
mainRouter.get(path, async (_, res) => {
|
|
25
28
|
switch (config.type) {
|
|
26
29
|
case "MD": {
|
|
27
|
-
const contentType = CONTENT_TYPE_MAP[".md"];
|
|
28
30
|
return await res.asyncEnd({
|
|
29
31
|
headers: {
|
|
30
32
|
"content-type": contentType
|
|
@@ -51,6 +53,28 @@ export async function setupDoc(logger: Logger, servicePath: string, service: str
|
|
|
51
53
|
});
|
|
52
54
|
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
53
55
|
writeFileSync(inflatePath, body);
|
|
56
|
+
|
|
57
|
+
fileMap[docPath + path] = {
|
|
58
|
+
routes: [{
|
|
59
|
+
method: "GET",
|
|
60
|
+
path
|
|
61
|
+
}],
|
|
62
|
+
service,
|
|
63
|
+
filePath: docPath,
|
|
64
|
+
previewMethod: "html"
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (staticFileMap) {
|
|
68
|
+
staticFileMap[docPath + path] = {
|
|
69
|
+
contentType,
|
|
70
|
+
filePath: docPath,
|
|
71
|
+
previewMethod: "html",
|
|
72
|
+
method: "GET",
|
|
73
|
+
path,
|
|
74
|
+
body: Buffer.from(body),
|
|
75
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
54
78
|
}
|
|
55
79
|
}
|
|
56
80
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Router } from "@miqro/core";
|
|
2
2
|
import { describeFilePath } from "../../common/fs.js";
|
|
3
3
|
import { getRoutes } from "../../services/utils/get-route.js";
|
|
4
|
-
import { assertGlobalTampered } from "../../services/globals.js";
|
|
4
|
+
// import { assertGlobalTampered } from "../../services/globals.js";
|
|
5
5
|
import { dirname, join, relative } from "node:path";
|
|
6
6
|
|
|
7
7
|
export async function appendAPIModule(router: Router, dir: string, filePath: string, module: any) {
|
|
8
8
|
const file = describeFilePath(filePath);
|
|
9
9
|
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
|
|
10
10
|
for (const r of routes) {
|
|
11
|
-
router.use(assertGlobalTampered);
|
|
11
|
+
// router.use(assertGlobalTampered);
|
|
12
12
|
router.use(module.handler, r.path, r.method as any, r.options);
|
|
13
13
|
}
|
|
14
14
|
}
|
package/src/lib.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Component, enableDebugLog, Fragment, Props, createElement as realCreateElement } from "@miqro/jsx";
|
|
2
|
+
import { jsx2HTML } from "./common/jsx.js";
|
|
3
|
+
|
|
1
4
|
/*export * from "@miqro/core";
|
|
2
5
|
export * from "@miqro/query";*/
|
|
3
6
|
export * from "./types.js";
|
|
@@ -9,11 +12,23 @@ export { WebSocketManager, WebSocketManagerOptions } from "./services/utils/webs
|
|
|
9
12
|
export { DBManager } from "./services/utils/db-manager.js";
|
|
10
13
|
export { LogProvider, LogProviderOptions } from "./services/utils/log.js";
|
|
11
14
|
export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
|
|
12
|
-
export { initGlobals, assertGlobalTampered } from "./services/globals.js";
|
|
15
|
+
// export { initGlobals, assertGlobalTampered } from "./services/globals.js";
|
|
16
|
+
export { jsx2HTML } from "./common/jsx.js";
|
|
13
17
|
|
|
14
18
|
//exported for --inflate-sea
|
|
15
19
|
export { appendAPIModule } from "./inflate/utils/sea-utils.js";
|
|
16
20
|
export { createServerInterface, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
|
|
17
21
|
export { App, LoggerHandler, Router } from "@miqro/core";
|
|
18
22
|
export { migration } from "@miqro/query";
|
|
19
|
-
|
|
23
|
+
export { middleware } from "./services/utils/middleware.js";
|
|
24
|
+
export { jwt } from "./services/utils/jwt.js";
|
|
25
|
+
export const JSX = {
|
|
26
|
+
createElement: (...args: [tag: string | Component | typeof Fragment, attributes: Props | null | undefined, ...children: Array<any>]) => {
|
|
27
|
+
const ret = realCreateElement(...args);
|
|
28
|
+
ret.toString = () => jsx2HTML(ret)
|
|
29
|
+
return ret;
|
|
30
|
+
},
|
|
31
|
+
Fragment,
|
|
32
|
+
enableDebugLog
|
|
33
|
+
}
|
|
34
|
+
export * as jsx from "@miqro/jsx";
|
package/src/main.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { TEST_SOCKET } from "./common/paths.js";
|
|
|
11
11
|
import { Logger } from "@miqro/core";
|
|
12
12
|
|
|
13
13
|
async function main(args: Arguments) {
|
|
14
|
-
if (args.
|
|
14
|
+
if (args.install || args.installTSConfig || args.installMiqroJSON) {
|
|
15
15
|
await installTypings(args, new Logger(""));
|
|
16
16
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
17
17
|
} else {
|
package/src/services/app.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { createEditorRouter } from "./editor.js";
|
|
|
17
17
|
import { EDITOR_CONFIG_KEY, HOT_RELOAD_PATH } from "../common/constants.js";
|
|
18
18
|
import { watchAndServer } from "../common/watch.js";
|
|
19
19
|
import { LocalCache } from "./utils/cache.js";
|
|
20
|
-
import { initGlobals } from "./globals.js";
|
|
20
|
+
// import { initGlobals } from "./globals.js";
|
|
21
21
|
import { EditorAdminInterface } from "../../editor/common/admin-interface.js";
|
|
22
22
|
import { LogProvider, LogProviderOptions } from "./utils/log.js";
|
|
23
23
|
import { initAssets } from "../common/assets.js";
|
|
@@ -219,7 +219,7 @@ export class Miqro {
|
|
|
219
219
|
if (this.inflated !== null) {
|
|
220
220
|
throw new Error("already inflated! call deflate()");
|
|
221
221
|
}
|
|
222
|
-
initGlobals();
|
|
222
|
+
// initGlobals();
|
|
223
223
|
// block others from inflating while inflateApp is running
|
|
224
224
|
this.inflated = undefined;
|
|
225
225
|
this.inflated = {
|
|
@@ -280,7 +280,7 @@ export class Miqro {
|
|
|
280
280
|
// init assets only once for all ApplicationServer's
|
|
281
281
|
if (Miqro.initAssetsPromise === null) {
|
|
282
282
|
// init globals only once for all inflations
|
|
283
|
-
initGlobals();
|
|
283
|
+
// initGlobals();
|
|
284
284
|
Miqro.initAssetsPromise = initAssets(this.logger);
|
|
285
285
|
}
|
|
286
286
|
await Miqro.initAssetsPromise;
|
|
@@ -328,7 +328,7 @@ export class Miqro {
|
|
|
328
328
|
// init assets only once for all ApplicationServer's
|
|
329
329
|
if (Miqro.initAssetsPromise === null) {
|
|
330
330
|
// init globals only once for all inflations
|
|
331
|
-
initGlobals();
|
|
331
|
+
// initGlobals();
|
|
332
332
|
Miqro.initAssetsPromise = initAssets(this.logger);
|
|
333
333
|
}
|
|
334
334
|
await Miqro.initAssetsPromise;
|
|
@@ -25,7 +25,7 @@ export async function runMigrations(logger: Logger | undefined, db: Database | n
|
|
|
25
25
|
});
|
|
26
26
|
logger?.log("writing [%s]", relative(cwd(), inflatePath));
|
|
27
27
|
writeFileSync(inflatePath, await inflateJSX(resolve(migrationsFolderPath, migration), {
|
|
28
|
-
embemedJSX: false,
|
|
28
|
+
// embemedJSX: false,
|
|
29
29
|
minify: false,
|
|
30
30
|
useExport: true,
|
|
31
31
|
platform: "node",
|
|
@@ -55,7 +55,7 @@ export async function runMigrationsDown(logger: Logger | Console | undefined, db
|
|
|
55
55
|
});
|
|
56
56
|
logger?.log("writing [%s]", relative(cwd(), inflatePath));
|
|
57
57
|
writeFileSync(inflatePath, await inflateJSX(resolve(migrationsFolderPath, migration), {
|
|
58
|
-
embemedJSX: false,
|
|
58
|
+
// embemedJSX: false,
|
|
59
59
|
platform: "node",
|
|
60
60
|
minify: false,
|
|
61
61
|
useExport: true,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { decodeJWT, decodeProtectedHeaderJWT, decryptJWT, encryptJWT, signJWT, verifyJWT } from "../../common/jwt.js";
|
|
2
|
+
import { JWTInterface } from "../../types.js";
|
|
3
|
+
import { createSecretKey } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
export const jwt: JWTInterface = {
|
|
6
|
+
createSecretKey,
|
|
7
|
+
decode(jwt) {
|
|
8
|
+
return decodeJWT(jwt);
|
|
9
|
+
},
|
|
10
|
+
decodeProtectedHeader(token) {
|
|
11
|
+
return decodeProtectedHeaderJWT(token);
|
|
12
|
+
},
|
|
13
|
+
decrypt(jwt, secret, options) {
|
|
14
|
+
return decryptJWT(jwt, secret, options);
|
|
15
|
+
},
|
|
16
|
+
encrypt(payload, secret, options) {
|
|
17
|
+
return encryptJWT(payload, secret, options);
|
|
18
|
+
},
|
|
19
|
+
sign(payload, secret, options) {
|
|
20
|
+
return signJWT(payload, secret, options);
|
|
21
|
+
},
|
|
22
|
+
verify(jwt, secret, options) {
|
|
23
|
+
return verifyJWT(jwt, secret, options);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CORS, JSONParser, ReadBuffer, SessionHandler, TextParser, URLEncodedParser } from "@miqro/core";
|
|
2
|
+
|
|
3
|
+
export const middleware = Object.freeze({
|
|
4
|
+
buffer: ReadBuffer,
|
|
5
|
+
url: URLEncodedParser,
|
|
6
|
+
json: JSONParser,
|
|
7
|
+
text: TextParser,
|
|
8
|
+
cors: CORS,
|
|
9
|
+
session: SessionHandler
|
|
10
|
+
});
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Database } from "@miqro/query";
|
|
1
|
+
import { Logger } from "@miqro/core";
|
|
3
2
|
import cluster from "node:cluster";
|
|
4
|
-
import { CacheInterface,
|
|
3
|
+
import { CacheInterface, NamedMigration, ServerInterface } from "../../types.js";
|
|
5
4
|
import { DBManager } from "./db-manager.js";
|
|
6
5
|
import { Miqro } from "../app.js";
|
|
7
6
|
import { WebSocketManager } from "./websocketmanager.js";
|
|
8
7
|
import { execSync } from "node:child_process";
|
|
9
8
|
import { LogProvider } from "./log.js";
|
|
10
|
-
import {
|
|
9
|
+
import { HTMLEncode } from "../../../editor/common/html-encode.js";
|
|
10
|
+
import { inflateMD2HTML } from "../../inflate/md.js";
|
|
11
|
+
|
|
12
|
+
import { Parser } from "@miqro/parser";
|
|
13
|
+
import { ClusterCache } from "./cluster-cache.js";
|
|
14
|
+
import { LocalCache } from "./cache.js";
|
|
15
|
+
import { middleware } from "./middleware.js";
|
|
16
|
+
import { jwt } from "./jwt.js";
|
|
17
|
+
|
|
18
|
+
// import { initGlobals } from "../globals.js";
|
|
11
19
|
|
|
12
20
|
export interface ServerInterfaceImplOptions {
|
|
13
21
|
cache: CacheInterface;
|
|
@@ -21,8 +29,30 @@ export interface ServerInterfaceImplOptions {
|
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
export function createServerInterface(options: ServerInterfaceImplOptions): ServerInterface {
|
|
24
|
-
initGlobals();
|
|
32
|
+
// initGlobals();
|
|
25
33
|
return Object.freeze<ServerInterface>({
|
|
34
|
+
middleware,
|
|
35
|
+
encodeHTML: HTMLEncode,
|
|
36
|
+
inflateMDtoHTML: inflateMD2HTML,
|
|
37
|
+
newParser() {
|
|
38
|
+
return new Parser();
|
|
39
|
+
},
|
|
40
|
+
newClusterCache(name, logger) {
|
|
41
|
+
return new ClusterCache(name, logger);
|
|
42
|
+
},
|
|
43
|
+
newLocalCache(name, logger) {
|
|
44
|
+
return new LocalCache(name, logger);
|
|
45
|
+
},
|
|
46
|
+
getWorkerNumber(): number {
|
|
47
|
+
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined ? 0 : parseInt(process.env["CLUSTER_NODE_NUMBER"], 10);
|
|
48
|
+
},
|
|
49
|
+
getWorkerCount(): number {
|
|
50
|
+
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined || process.env["CLUSTER_COUNT"] === undefined ? 1 : parseInt(process.env["CLUSTER_COUNT"], 10);
|
|
51
|
+
},
|
|
52
|
+
isPrimaryWorker(): boolean {
|
|
53
|
+
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
54
|
+
},
|
|
55
|
+
jwt,
|
|
26
56
|
cache: options.cache,
|
|
27
57
|
localCache: options.localCache,
|
|
28
58
|
logger: options.logger,
|
|
@@ -86,7 +116,7 @@ export function createServerInterface(options: ServerInterfaceImplOptions): Serv
|
|
|
86
116
|
},
|
|
87
117
|
getLogger(identifier, loggerOptions) {
|
|
88
118
|
return options?.loggerProvider?.getLogger(identifier, loggerOptions);
|
|
89
|
-
}
|
|
90
|
-
...server
|
|
119
|
+
}
|
|
120
|
+
// ...server
|
|
91
121
|
});
|
|
92
122
|
}
|
package/src/types.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface JWTSignOptions {
|
|
|
33
33
|
options?: SignOptions;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
declare global {
|
|
36
|
+
/*declare global {
|
|
37
37
|
// jsx only for the default value of tsconfig.json
|
|
38
38
|
//var React: {};
|
|
39
39
|
var JSX: {
|
|
@@ -60,11 +60,61 @@ declare global {
|
|
|
60
60
|
useElement: typeof jsxLib.useElement;
|
|
61
61
|
useRefresh: typeof jsxLib.useRefresh;
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}*/
|
|
64
64
|
|
|
65
65
|
export { APIRoute } from "@miqro/core";
|
|
66
66
|
export { Migration } from "@miqro/query";
|
|
67
67
|
|
|
68
|
+
export interface JWTInterface {
|
|
69
|
+
createSecretKey: (key: string, encoding: BufferEncoding) => KeyObject;
|
|
70
|
+
/**
|
|
71
|
+
* creates a JWT encrypted token with jose
|
|
72
|
+
*
|
|
73
|
+
* @param payload the payload to encrypt
|
|
74
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
75
|
+
* @param options options like expiratation date, issuer and audience
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
encrypt: (payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>) => Promise<string>
|
|
79
|
+
/**
|
|
80
|
+
* decrypts a JWT token with jose
|
|
81
|
+
* @param jwt the JWT token
|
|
82
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
83
|
+
* @param options options like issuer and audience
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
decrypt: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>) => Promise<JWTDecryptResult<PayloadType>>;
|
|
87
|
+
/**
|
|
88
|
+
* verify a JWT token with jose
|
|
89
|
+
* @param jwt the JWT token
|
|
90
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
91
|
+
* @param options options like issuer and audience
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
verify: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>) => Promise<JWTVerifyResult<PayloadType>>;
|
|
95
|
+
/**
|
|
96
|
+
* creates a signed JWT with jose
|
|
97
|
+
*
|
|
98
|
+
* @param payload the payload to encrypt
|
|
99
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
100
|
+
* @param options options like expiratation date, issuer and audience
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
sign: (payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>) => Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* decodes a protected header with jose
|
|
106
|
+
* @param token
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
decodeProtectedHeader: (token: string | object) => ProtectedHeaderParameters;
|
|
110
|
+
/**
|
|
111
|
+
* decodes a jwt token
|
|
112
|
+
* @param jwt
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
decode: <PayloadType = JWTPayload>(jwt: string) => PayloadType & JWTPayload;
|
|
116
|
+
}
|
|
117
|
+
|
|
68
118
|
export interface ServerGlobal {
|
|
69
119
|
encodeHTML: (str: string) => string;
|
|
70
120
|
inflateMDtoHTML: (str: string) => string;
|
|
@@ -79,58 +129,11 @@ export interface ServerGlobal {
|
|
|
79
129
|
newParser(): Parser;
|
|
80
130
|
newClusterCache: (name: string, logger?: Logger) => CacheInterface;
|
|
81
131
|
newLocalCache: (name: string, logger?: Logger) => CacheInterface;
|
|
82
|
-
|
|
132
|
+
|
|
83
133
|
getWorkerCount: () => number;
|
|
84
134
|
getWorkerNumber: () => number;
|
|
85
135
|
isPrimaryWorker: () => boolean;
|
|
86
|
-
jwt:
|
|
87
|
-
/**
|
|
88
|
-
* creates a JWT encrypted token with jose
|
|
89
|
-
*
|
|
90
|
-
* @param payload the payload to encrypt
|
|
91
|
-
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
92
|
-
* @param options options like expiratation date, issuer and audience
|
|
93
|
-
* @returns
|
|
94
|
-
*/
|
|
95
|
-
encrypt: (payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>) => Promise<string>
|
|
96
|
-
/**
|
|
97
|
-
* decrypts a JWT token with jose
|
|
98
|
-
* @param jwt the JWT token
|
|
99
|
-
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
100
|
-
* @param options options like issuer and audience
|
|
101
|
-
* @returns
|
|
102
|
-
*/
|
|
103
|
-
decrypt: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>) => Promise<JWTDecryptResult<PayloadType>>;
|
|
104
|
-
/**
|
|
105
|
-
* verify a JWT token with jose
|
|
106
|
-
* @param jwt the JWT token
|
|
107
|
-
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
108
|
-
* @param options options like issuer and audience
|
|
109
|
-
* @returns
|
|
110
|
-
*/
|
|
111
|
-
verify: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>) => Promise<JWTVerifyResult<PayloadType>>;
|
|
112
|
-
/**
|
|
113
|
-
* creates a signed JWT with jose
|
|
114
|
-
*
|
|
115
|
-
* @param payload the payload to encrypt
|
|
116
|
-
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
117
|
-
* @param options options like expiratation date, issuer and audience
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
sign: (payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>) => Promise<string>;
|
|
121
|
-
/**
|
|
122
|
-
* decodes a protected header with jose
|
|
123
|
-
* @param token
|
|
124
|
-
* @returns
|
|
125
|
-
*/
|
|
126
|
-
decodeProtectedHeader: (token: string | object) => ProtectedHeaderParameters;
|
|
127
|
-
/**
|
|
128
|
-
* decodes a jwt token
|
|
129
|
-
* @param jwt
|
|
130
|
-
* @returns
|
|
131
|
-
*/
|
|
132
|
-
decode: <PayloadType = JWTPayload>(jwt: string) => PayloadType & JWTPayload;
|
|
133
|
-
}
|
|
136
|
+
jwt: JWTInterface;
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
export interface CacheInterface {
|
|
@@ -233,7 +236,7 @@ export interface TestHelperGlobal {
|
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
|
|
236
|
-
declare global {
|
|
239
|
+
/*declare global {
|
|
237
240
|
// only available server side
|
|
238
241
|
var server: ServerGlobal;
|
|
239
242
|
|
|
@@ -245,7 +248,7 @@ declare global {
|
|
|
245
248
|
var describe: Function;
|
|
246
249
|
var before: Function;
|
|
247
250
|
var after: Function;
|
|
248
|
-
}
|
|
251
|
+
}*/
|
|
249
252
|
|
|
250
253
|
export interface AuthConfig extends SessionHandlerOptions {
|
|
251
254
|
|
package/.eslintrc
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "@typescript-eslint/parser",
|
|
3
|
-
"extends": [
|
|
4
|
-
"plugin:@typescript-eslint/recommended"
|
|
5
|
-
],
|
|
6
|
-
"parserOptions": {
|
|
7
|
-
"ecmaVersion": 2018,
|
|
8
|
-
"sourceType": "module"
|
|
9
|
-
},
|
|
10
|
-
"rules": {
|
|
11
|
-
// Aca puedes modificar alguna regla específica, por ejemplo:
|
|
12
|
-
// "@typescript-eslint/explicit-function-return-type": "off",
|
|
13
|
-
"@typescript-eslint/no-explicit-any": "off"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
//@ts-ignore
|
|
2
|
-
import { ReadBuffer, URLEncodedParser, JSONParser, TextParser, CORS, SessionHandler } from "@miqro/core";
|
|
3
|
-
import cluster from "node:cluster";
|
|
4
|
-
import { strictEqual } from "node:assert";
|
|
5
|
-
import { HTMLEncode } from "@miqro/jsx-node";
|
|
6
|
-
import { createElement as realCreateElement, enableDebugLog, useRuntime, Link, Router, usePathname, Fragment, useEffect, useRef, useState, useQuery, useRefresh, useElement, createContext, useContext } from "@miqro/jsx";
|
|
7
|
-
import { jsx2HTML } from "../common/jsx.js";
|
|
8
|
-
import { inflateMD2HTML } from "../inflate/md.js";
|
|
9
|
-
import { EXIT_CODES } from "../common/constants.js";
|
|
10
|
-
import { ClusterCache, LocalCache } from "../lib.js";
|
|
11
|
-
import { decodeJWT, decodeProtectedHeaderJWT, decryptJWT, encryptJWT, signJWT, verifyJWT } from "../common/jwt.js";
|
|
12
|
-
import { createSecretKey } from "node:crypto";
|
|
13
|
-
import { Parser } from "@miqro/parser";
|
|
14
|
-
/*const globaljsx: any = Object.freeze({
|
|
15
|
-
useContext,
|
|
16
|
-
useRuntime,
|
|
17
|
-
createContext,
|
|
18
|
-
useState,
|
|
19
|
-
useEffect,
|
|
20
|
-
useQuery,
|
|
21
|
-
useRef,
|
|
22
|
-
useElement,
|
|
23
|
-
useRefresh,
|
|
24
|
-
Link,
|
|
25
|
-
Router,
|
|
26
|
-
usePathname
|
|
27
|
-
});*/
|
|
28
|
-
const globalJSX = Object.freeze({
|
|
29
|
-
createElement: (...args) => {
|
|
30
|
-
const ret = realCreateElement(...args);
|
|
31
|
-
ret.toString = () => jsx2HTML(ret);
|
|
32
|
-
return ret;
|
|
33
|
-
},
|
|
34
|
-
Fragment,
|
|
35
|
-
enableDebugLog
|
|
36
|
-
});
|
|
37
|
-
const globaljsx = Object.freeze({
|
|
38
|
-
useContext,
|
|
39
|
-
useRuntime,
|
|
40
|
-
createContext,
|
|
41
|
-
useState,
|
|
42
|
-
useEffect,
|
|
43
|
-
useQuery,
|
|
44
|
-
useRef,
|
|
45
|
-
useElement,
|
|
46
|
-
useRefresh,
|
|
47
|
-
Link,
|
|
48
|
-
Router,
|
|
49
|
-
usePathname,
|
|
50
|
-
define: function define() {
|
|
51
|
-
/*const callSites = getCallSite();
|
|
52
|
-
const caller = callSites[2];
|
|
53
|
-
if (CLEAR_JSX_CACHE) {
|
|
54
|
-
const scriptName = basename(caller.scriptName);
|
|
55
|
-
const originalName = scriptName.substring(0, scriptName.length - ".mjs".length);
|
|
56
|
-
//server.logger.debug("browser.define not available server side!");
|
|
57
|
-
//server.logger.trace("browser.define not available server side! %s", originalName);
|
|
58
|
-
} else {
|
|
59
|
-
//server.logger.debug("browser.define not available server side!");
|
|
60
|
-
//server.logger.trace("browser.define not available server side! %s:%s:%s", caller.scriptName, caller.lineNumber, caller.column);
|
|
61
|
-
}*/
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const globalWindow = Object.freeze({
|
|
65
|
-
addEventListener: function define() {
|
|
66
|
-
/*const callSites = getCallSite();
|
|
67
|
-
const caller = callSites[2];
|
|
68
|
-
if (CLEAR_JSX_CACHE) {
|
|
69
|
-
const scriptName = basename(caller.scriptName);
|
|
70
|
-
//server.logger.debug("window.addEventListener not available server side!");
|
|
71
|
-
server.logger.trace("window.addEventListener not available server side! %s", scriptName.substring(0, scriptName.length - ".mjs".length));
|
|
72
|
-
} else {
|
|
73
|
-
//server.logger.debug("window.addEventListener not available server side!");
|
|
74
|
-
server.logger.trace("window.addEventListener not available server side! %s:%s:%s", caller.scriptName, caller.lineNumber, caller.column);
|
|
75
|
-
}*/
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const globalServer = Object.freeze({
|
|
79
|
-
middleware: Object.freeze({
|
|
80
|
-
buffer: ReadBuffer,
|
|
81
|
-
url: URLEncodedParser,
|
|
82
|
-
json: JSONParser,
|
|
83
|
-
text: TextParser,
|
|
84
|
-
cors: CORS,
|
|
85
|
-
session: SessionHandler
|
|
86
|
-
}),
|
|
87
|
-
encodeHTML: HTMLEncode,
|
|
88
|
-
inflateMDtoHTML: inflateMD2HTML,
|
|
89
|
-
createSecretKey,
|
|
90
|
-
newParser() {
|
|
91
|
-
return new Parser();
|
|
92
|
-
},
|
|
93
|
-
newClusterCache(name, logger) {
|
|
94
|
-
return new ClusterCache(name, logger);
|
|
95
|
-
},
|
|
96
|
-
newLocalCache(name, logger) {
|
|
97
|
-
return new LocalCache(name, logger);
|
|
98
|
-
},
|
|
99
|
-
getWorkerNumber() {
|
|
100
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined ? 0 : parseInt(process.env["CLUSTER_NODE_NUMBER"], 10);
|
|
101
|
-
},
|
|
102
|
-
getWorkerCount() {
|
|
103
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined || process.env["CLUSTER_COUNT"] === undefined ? 1 : parseInt(process.env["CLUSTER_COUNT"], 10);
|
|
104
|
-
},
|
|
105
|
-
isPrimaryWorker() {
|
|
106
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
107
|
-
},
|
|
108
|
-
jwt: {
|
|
109
|
-
decode(jwt) {
|
|
110
|
-
return decodeJWT(jwt);
|
|
111
|
-
},
|
|
112
|
-
decodeProtectedHeader(token) {
|
|
113
|
-
return decodeProtectedHeaderJWT(token);
|
|
114
|
-
},
|
|
115
|
-
decrypt(jwt, secret, options) {
|
|
116
|
-
return decryptJWT(jwt, secret, options);
|
|
117
|
-
},
|
|
118
|
-
encrypt(payload, secret, options) {
|
|
119
|
-
return encryptJWT(payload, secret, options);
|
|
120
|
-
},
|
|
121
|
-
sign(payload, secret, options) {
|
|
122
|
-
return signJWT(payload, secret, options);
|
|
123
|
-
},
|
|
124
|
-
verify(jwt, secret, options) {
|
|
125
|
-
return verifyJWT(jwt, secret, options);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
export function browserJSXGlobals(inFile, jsxPath = false, useExport = true) {
|
|
130
|
-
const PRE = `import { enableDebugLog, useRuntime, Link, usePathname, createContext, useContext, useElement, useRefresh, useQuery, define, Router, useState, useEffect, useRef, createElement, Fragment } from "${jsxPath}";
|
|
131
|
-
globalThis.JSX = Object.freeze({
|
|
132
|
-
createElement,
|
|
133
|
-
Fragment,
|
|
134
|
-
enableDebugLog
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
globalThis.newParser = () => new Parser();
|
|
138
|
-
globalThis.jsx = Object.freeze({
|
|
139
|
-
define,
|
|
140
|
-
useRuntime,
|
|
141
|
-
createContext,
|
|
142
|
-
useContext,
|
|
143
|
-
useState,
|
|
144
|
-
useEffect,
|
|
145
|
-
useQuery,
|
|
146
|
-
useRef,
|
|
147
|
-
useElement,
|
|
148
|
-
useRefresh,
|
|
149
|
-
usePathname,
|
|
150
|
-
Link,
|
|
151
|
-
Router
|
|
152
|
-
});`;
|
|
153
|
-
return `${jsxPath ? PRE : ""}\n${useExport ? `export * from "${inFile}";import * as lib from "${inFile}";export default lib.default;` : `import * as lib from "${inFile}"`}`;
|
|
154
|
-
}
|
|
155
|
-
export function initGlobals() {
|
|
156
|
-
//const logger = getLogger(SERVER_IDENTIFIER);
|
|
157
|
-
globalThis.server = globalServer;
|
|
158
|
-
//globalThis.jsx = globaljsx;
|
|
159
|
-
/*for (const key of Object.keys(globaljsx)) {
|
|
160
|
-
globalThis[key] = globaljsx[key];
|
|
161
|
-
}*/
|
|
162
|
-
globalThis.JSX = globalJSX;
|
|
163
|
-
globalThis.jsx = globaljsx;
|
|
164
|
-
globalThis.window = globalWindow;
|
|
165
|
-
}
|
|
166
|
-
export function assertGlobalTampered() {
|
|
167
|
-
try {
|
|
168
|
-
//strictEqual(globalThis.utils, globalUtils, "globalThis.utils tamperered");
|
|
169
|
-
strictEqual(globalThis.JSX, globalJSX, "globalThis.JSX tamperered");
|
|
170
|
-
//strictEqual(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
171
|
-
/*for (const key of Object.keys(globaljsx)) {
|
|
172
|
-
strictEqual(globalThis[key], globaljsx[key], "globalThis.jsx tamperered");
|
|
173
|
-
}*/
|
|
174
|
-
strictEqual(globalThis.server, globalServer, "globalThis.server tamperered");
|
|
175
|
-
strictEqual(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
176
|
-
strictEqual(globalThis.window, globalWindow, "globalThis.window tamperered");
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
console.error(e);
|
|
180
|
-
process.exit(EXIT_CODES.GLOBALS_ALTERED);
|
|
181
|
-
}
|
|
182
|
-
}
|