miqro 6.1.4 → 6.2.0
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/editor.bundle.js +10 -2
- package/build/esm/editor/components/editor.js +8 -0
- package/build/esm/editor/components/file-editor.js +1 -1
- package/build/esm/editor/components/highlight-text-area.js +2 -1
- package/build/esm/src/common/jwt.d.ts +49 -0
- package/build/esm/src/common/jwt.js +76 -0
- package/build/esm/src/inflate/inflate-sea.js +9 -8
- package/build/esm/src/inflate/setup-http.d.ts +1 -0
- package/build/esm/src/inflate/setup-http.js +8 -0
- package/build/esm/src/lib.d.ts +1 -1
- package/build/esm/src/lib.js +2 -2
- package/build/esm/src/services/app.js +5 -4
- package/build/esm/src/services/globals.js +45 -1
- package/build/esm/src/services/utils/cluster-ws.d.ts +4 -2
- package/build/esm/src/services/utils/cluster-ws.js +10 -1
- package/build/esm/src/services/utils/server-interface.d.ts +4 -30
- package/build/esm/src/services/utils/server-interface.js +44 -64
- package/build/esm/src/services/utils/websocketmanager.d.ts +3 -0
- package/build/esm/src/services/utils/websocketmanager.js +8 -2
- package/build/esm/src/types.d.ts +76 -5
- package/build/lib.cjs +2983 -362
- package/editor/components/editor.tsx +8 -0
- package/editor/components/file-editor.tsx +1 -1
- package/editor/components/highlight-text-area.tsx +2 -1
- package/package.json +4 -3
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/sea/types.json +1 -1
- package/src/common/jwt.ts +85 -0
- package/src/inflate/inflate-sea.ts +9 -8
- package/src/inflate/setup-http.ts +9 -0
- package/src/lib.ts +2 -2
- package/src/services/app.ts +6 -4
- package/src/services/globals.ts +45 -2
- package/src/services/utils/cluster-ws.ts +6 -1
- package/src/services/utils/server-interface.ts +44 -140
- package/src/services/utils/websocketmanager.ts +10 -2
- package/src/types/cookie.d.ts +2 -0
- package/src/types/jose.d.ts +2 -0
- package/src/types/miqro.d.ts +92 -2
- package/src/types/server.globals.d.ts +4 -29
- package/src/types.ts +78 -5
|
@@ -1,49 +1,19 @@
|
|
|
1
|
-
import cluster from "node:cluster";
|
|
2
1
|
import { execSync } from "node:child_process";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.cache = options.cache;
|
|
14
|
-
this.localCache = options.localCache;
|
|
15
|
-
this.logger = options.logger ? options.logger : options.loggerProvider ? options.loggerProvider.getLogger("server") : undefined;
|
|
16
|
-
this.port = options.port;
|
|
17
|
-
const dbManager = options.dbManager;
|
|
18
|
-
const wsManager = options.wsManager;
|
|
19
|
-
this.loggerProvider = options.loggerProvider;
|
|
20
|
-
const app = options.app;
|
|
21
|
-
this.openBrowser = (path) => {
|
|
22
|
-
const PORT = this.port;
|
|
23
|
-
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
24
|
-
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
25
|
-
const OPEN = app.options.browser !== undefined && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ?
|
|
26
|
-
String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ?
|
|
27
|
-
app.options.browser : false :
|
|
28
|
-
process.env["BROWSER"] ?
|
|
29
|
-
process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
30
|
-
if (OPEN) {
|
|
31
|
-
const openCMD = `${OPEN} "${URL}"`;
|
|
32
|
-
this.logger?.info("opening browser with [%s]", openCMD);
|
|
33
|
-
execSync(openCMD);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.logger?.warn("ignoring browser [%s]", OPEN);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
this.db = Object.freeze({
|
|
40
|
-
get: (name) => {
|
|
41
|
-
return dbManager.getDB(name);
|
|
2
|
+
import { initGlobals } from "../globals.js";
|
|
3
|
+
export function createServerInterface(options) {
|
|
4
|
+
initGlobals();
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
cache: options.cache,
|
|
7
|
+
localCache: options.localCache,
|
|
8
|
+
logger: options.logger,
|
|
9
|
+
db: {
|
|
10
|
+
get(name) {
|
|
11
|
+
return options.dbManager.getDB(name);
|
|
42
12
|
},
|
|
43
|
-
getMigrations
|
|
44
|
-
if (app?.inflated) {
|
|
13
|
+
getMigrations() {
|
|
14
|
+
if (options.app?.inflated) {
|
|
45
15
|
const ret = [];
|
|
46
|
-
for (const d of app?.inflated.dbList) {
|
|
16
|
+
for (const d of options.app?.inflated.dbList) {
|
|
47
17
|
ret.push(...(d.migrations.map(m => {
|
|
48
18
|
return {
|
|
49
19
|
name: m.name,
|
|
@@ -56,29 +26,39 @@ export class ServerInterfaceImpl {
|
|
|
56
26
|
}
|
|
57
27
|
return [];
|
|
58
28
|
},
|
|
59
|
-
migrate
|
|
60
|
-
return app?.migrate(
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
29
|
+
migrate(migrateOptions) {
|
|
30
|
+
return options?.app?.migrate(migrateOptions);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
ws: {
|
|
64
34
|
get: (name) => {
|
|
65
|
-
return
|
|
35
|
+
return options?.webSocketManager?.getWS(name);
|
|
66
36
|
},
|
|
67
37
|
disconnectAll: (path) => {
|
|
68
|
-
return
|
|
38
|
+
return options?.webSocketManager?.disconnectAllButLOGSocket();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
openBrowser(path) {
|
|
42
|
+
const PORT = options.port;
|
|
43
|
+
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
44
|
+
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
45
|
+
const OPEN = options?.app?.options.browser !== undefined && String(options?.app?.options.browser).toUpperCase() !== "TRUE" && String(options?.app?.options.browser).toUpperCase() !== "1" ?
|
|
46
|
+
String(options?.app.options.browser).toUpperCase() !== "0" && String(options?.app?.options.browser).toUpperCase() !== "FALSE" && String(options?.app?.options.browser).toUpperCase() !== "NONE" && options?.app?.options.browser ?
|
|
47
|
+
options?.app.options.browser : false :
|
|
48
|
+
process.env["BROWSER"] ?
|
|
49
|
+
process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
50
|
+
if (OPEN) {
|
|
51
|
+
const openCMD = `${OPEN} "${URL}"`;
|
|
52
|
+
options?.logger?.info("opening browser with [%s]", openCMD);
|
|
53
|
+
execSync(openCMD);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
options?.logger?.warn("ignoring browser [%s]", OPEN);
|
|
69
57
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined || process.env["CLUSTER_COUNT"] === undefined ? 1 : parseInt(process.env["CLUSTER_COUNT"], 10);
|
|
77
|
-
}
|
|
78
|
-
isPrimaryWorker() {
|
|
79
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
80
|
-
}
|
|
81
|
-
getLogger(identifier, options) {
|
|
82
|
-
return this.loggerProvider?.getLogger(identifier, options);
|
|
83
|
-
}
|
|
58
|
+
},
|
|
59
|
+
getLogger(identifier, loggerOptions) {
|
|
60
|
+
return options?.loggerProvider?.getLogger(identifier, loggerOptions);
|
|
61
|
+
},
|
|
62
|
+
...server
|
|
63
|
+
});
|
|
84
64
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Logger } from "@miqro/core";
|
|
2
2
|
import { ClusterWebSocketServer2 } from "./cluster-ws.js";
|
|
3
3
|
import { WSConfig } from "../../types.js";
|
|
4
|
+
import { LogProvider } from "./log.js";
|
|
4
5
|
export interface WebSocketManagerOptions {
|
|
5
6
|
logger?: Logger | Console;
|
|
7
|
+
loggerProvider?: LogProvider;
|
|
6
8
|
name?: string;
|
|
7
9
|
avoidLogSocket?: boolean;
|
|
8
10
|
}
|
|
@@ -11,6 +13,7 @@ export declare class WebSocketManager {
|
|
|
11
13
|
logger?: Logger | Console | null;
|
|
12
14
|
name: string;
|
|
13
15
|
avoidLogSocket: boolean;
|
|
16
|
+
loggerProvider: LogProvider;
|
|
14
17
|
constructor(options?: WebSocketManagerOptions);
|
|
15
18
|
deleteWS(path: string): void;
|
|
16
19
|
deleteAllWS(): void;
|
|
@@ -5,10 +5,12 @@ export class WebSocketManager {
|
|
|
5
5
|
logger = null;
|
|
6
6
|
name;
|
|
7
7
|
avoidLogSocket;
|
|
8
|
+
loggerProvider;
|
|
8
9
|
constructor(options) {
|
|
9
10
|
this.onUpgrade = this.onUpgrade.bind(this);
|
|
10
11
|
this.logger = options && options.logger ? options.logger : null;
|
|
11
12
|
this.name = options && options.name ? options.name : "WebSocketManager";
|
|
13
|
+
this.loggerProvider = options.loggerProvider;
|
|
12
14
|
this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
|
|
13
15
|
}
|
|
14
16
|
deleteWS(path) {
|
|
@@ -33,7 +35,9 @@ export class WebSocketManager {
|
|
|
33
35
|
throw new Error(`ws on path ${wsConfig.path} already setup!`);
|
|
34
36
|
}
|
|
35
37
|
this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
|
|
36
|
-
const
|
|
38
|
+
const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
|
|
39
|
+
const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
|
|
40
|
+
const server = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
|
|
37
41
|
this.runningGlobalWSMap.set(wsConfig.path, server);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
@@ -51,7 +55,9 @@ export class WebSocketManager {
|
|
|
51
55
|
throw new Error(`ws on path ${wsConfig.path} already setup!`);
|
|
52
56
|
}
|
|
53
57
|
this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
|
|
54
|
-
const
|
|
58
|
+
const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
|
|
59
|
+
const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
|
|
60
|
+
const server = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
|
|
55
61
|
this.runningGlobalWSMap.set(wsConfig.path, server);
|
|
56
62
|
}
|
|
57
63
|
}
|
package/build/esm/src/types.d.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { Database } from "@miqro/query";
|
|
2
2
|
import { WebSocketServerOptions, SessionHandlerOptions, Logger, WebSocketServer, ReadBuffer, URLEncodedParser, JSONParser, TextParser, CORS, SessionHandler, RouteOptions, Handler, Request, Response, LogLevel, LoggerTransportWriteArgs, CORSOptions, HandlerWithOptions, ErrorHandler } from "@miqro/core";
|
|
3
3
|
import { request } from "@miqro/request";
|
|
4
|
-
import { ParserInterface } from "@miqro/parser";
|
|
4
|
+
import { Parser, ParserInterface } from "@miqro/parser";
|
|
5
5
|
import { RuntimeHTMLElement, Runtime, RuntimeContainer, RuntimeURL, RuntimeOptions, RuntimeShadowRootInit } from "@miqro/jsx";
|
|
6
6
|
import { RuntimeElementDefinitionOptions, Component, createElement, Fragment, enableDebugLog } from "@miqro/jsx";
|
|
7
7
|
import * as jsxLib from "@miqro/jsx";
|
|
8
|
+
import { EncryptOptions, JWTDecryptOptions, JWTDecryptResult, JWTPayload, JWTVerifyOptions, JWTVerifyResult, ProtectedHeaderParameters, SignOptions } from "jose";
|
|
9
|
+
import { KeyObject } from "node:crypto";
|
|
10
|
+
export interface EncryptJWTOptions {
|
|
11
|
+
alg?: string;
|
|
12
|
+
enc?: string;
|
|
13
|
+
iat?: number | string | Date;
|
|
14
|
+
iss?: string;
|
|
15
|
+
aud?: string;
|
|
16
|
+
exp?: number | string | Date;
|
|
17
|
+
options?: EncryptOptions;
|
|
18
|
+
}
|
|
19
|
+
export interface JWTSignOptions {
|
|
20
|
+
alg?: string;
|
|
21
|
+
iat?: number | string | Date;
|
|
22
|
+
iss?: string;
|
|
23
|
+
aud?: string;
|
|
24
|
+
exp?: number | string | Date;
|
|
25
|
+
options?: SignOptions;
|
|
26
|
+
}
|
|
8
27
|
declare global {
|
|
9
28
|
var JSX: {
|
|
10
29
|
createElement: typeof createElement;
|
|
@@ -42,6 +61,61 @@ export interface ServerGlobal {
|
|
|
42
61
|
cors: typeof CORS;
|
|
43
62
|
session: typeof SessionHandler;
|
|
44
63
|
};
|
|
64
|
+
newParser(): Parser;
|
|
65
|
+
newClusterCache: (name: string, logger?: Logger) => CacheInterface;
|
|
66
|
+
newLocalCache: (name: string, logger?: Logger) => CacheInterface;
|
|
67
|
+
createSecretKey: (key: string, encoding: BufferEncoding) => KeyObject;
|
|
68
|
+
getWorkerCount: () => number;
|
|
69
|
+
getWorkerNumber: () => number;
|
|
70
|
+
isPrimaryWorker: () => boolean;
|
|
71
|
+
jwt: {
|
|
72
|
+
/**
|
|
73
|
+
* creates a JWT encrypted token with jose
|
|
74
|
+
*
|
|
75
|
+
* @param payload the payload to encrypt
|
|
76
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
77
|
+
* @param options options like expiratation date, issuer and audience
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
encrypt: (payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>) => Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* decrypts a JWT token with jose
|
|
83
|
+
* @param jwt the JWT token
|
|
84
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
85
|
+
* @param options options like issuer and audience
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
decrypt: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>) => Promise<JWTDecryptResult<PayloadType>>;
|
|
89
|
+
/**
|
|
90
|
+
* verify a JWT token with jose
|
|
91
|
+
* @param jwt the JWT token
|
|
92
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
93
|
+
* @param options options like issuer and audience
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
verify: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>) => Promise<JWTVerifyResult<PayloadType>>;
|
|
97
|
+
/**
|
|
98
|
+
* creates a signed JWT with jose
|
|
99
|
+
*
|
|
100
|
+
* @param payload the payload to encrypt
|
|
101
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
102
|
+
* @param options options like expiratation date, issuer and audience
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
sign: (payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>) => Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* decodes a protected header with jose
|
|
108
|
+
* @param token
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
decodeProtectedHeader: (token: string | object) => ProtectedHeaderParameters;
|
|
112
|
+
/**
|
|
113
|
+
* decodes a jwt token
|
|
114
|
+
* @param jwt
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
decode: <PayloadType = JWTPayload>(jwt: string) => PayloadType & JWTPayload;
|
|
118
|
+
};
|
|
45
119
|
}
|
|
46
120
|
export interface CacheInterface {
|
|
47
121
|
get<T = any>(key: string): T | undefined;
|
|
@@ -72,7 +146,7 @@ export interface LogConfig {
|
|
|
72
146
|
replaceFileTransport?: boolean;
|
|
73
147
|
write: (args: LoggerTransportWriteArgs) => Promise<void> | void;
|
|
74
148
|
}
|
|
75
|
-
export interface ServerInterface {
|
|
149
|
+
export interface ServerInterface extends ServerGlobal {
|
|
76
150
|
db: {
|
|
77
151
|
get(name: string): Database | null;
|
|
78
152
|
getMigrations(): NamedMigration[];
|
|
@@ -85,9 +159,6 @@ export interface ServerInterface {
|
|
|
85
159
|
cache: CacheInterface;
|
|
86
160
|
localCache: CacheInterface;
|
|
87
161
|
logger?: Logger;
|
|
88
|
-
isPrimaryWorker: () => boolean;
|
|
89
|
-
getWorkerNumber: () => number;
|
|
90
|
-
getWorkerCount: () => number;
|
|
91
162
|
openBrowser: (path: string) => void;
|
|
92
163
|
getLogger: (identifier: string, options?: {
|
|
93
164
|
level?: any;
|