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
package/src/types/miqro.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "./globals.js";
|
|
2
2
|
import { Database, Migration } from "@miqro/query/lib.js";
|
|
3
|
+
import { ReadBuffer, URLEncodedParser, JSONParser, TextParser, CORS, SessionHandler } from "@miqro/core/lib.js";
|
|
3
4
|
import { ErrorHandler, HandlerWithOptions, CORSOptions, LogLevel, LoggerTransportWriteArgs, Request, Response, WebSocketServer, Logger, WebSocketServerOptions, SessionHandlerOptions, RouteOptions, Handler } from "@miqro/core/lib.js";
|
|
4
|
-
import { ParserInterface } from "@miqro/parser/lib.js";
|
|
5
|
+
import { Parser, ParserInterface } from "@miqro/parser/lib.js";
|
|
6
|
+
import { ProtectedHeaderParameters, EncryptOptions, SignOptions, JWTPayload, JWTDecryptOptions, JWTDecryptResult, JWTVerifyResult, JWTVerifyOptions } from "jose/types/index.js";
|
|
7
|
+
import { KeyObject } from "node:crypto";
|
|
5
8
|
|
|
6
9
|
/*export * from "@miqro/core/lib.js";
|
|
7
10
|
export * from "@miqro/query/lib.js";*/
|
|
@@ -10,6 +13,93 @@ export interface AuthConfig extends SessionHandlerOptions {
|
|
|
10
13
|
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
export interface EncryptJWTOptions {
|
|
17
|
+
alg?: string;
|
|
18
|
+
enc?: string;
|
|
19
|
+
iat?: number | string | Date;
|
|
20
|
+
iss?: string;
|
|
21
|
+
aud?: string;
|
|
22
|
+
exp?: number | string | Date;
|
|
23
|
+
options?: EncryptOptions;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface JWTSignOptions {
|
|
27
|
+
alg?: string;
|
|
28
|
+
iat?: number | string | Date;
|
|
29
|
+
iss?: string;
|
|
30
|
+
aud?: string;
|
|
31
|
+
exp?: number | string | Date;
|
|
32
|
+
options?: SignOptions;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ServerGlobal {
|
|
36
|
+
encodeHTML: (str: string) => string;
|
|
37
|
+
inflateMDtoHTML: (str: string) => string;
|
|
38
|
+
middleware: {
|
|
39
|
+
buffer: typeof ReadBuffer;
|
|
40
|
+
url: typeof URLEncodedParser;
|
|
41
|
+
json: typeof JSONParser;
|
|
42
|
+
text: typeof TextParser;
|
|
43
|
+
cors: typeof CORS;
|
|
44
|
+
session: typeof SessionHandler;
|
|
45
|
+
};
|
|
46
|
+
newParser(): Parser;
|
|
47
|
+
newClusterCache: (name: string, logger?: Logger) => CacheInterface;
|
|
48
|
+
newLocalCache: (name: string, logger?: Logger) => CacheInterface;
|
|
49
|
+
createSecretKey: (key: string, encoding: BufferEncoding) => KeyObject;
|
|
50
|
+
getWorkerCount: () => number;
|
|
51
|
+
getWorkerNumber: () => number;
|
|
52
|
+
isPrimaryWorker: () => boolean;
|
|
53
|
+
jwt: {
|
|
54
|
+
/**
|
|
55
|
+
* creates a JWT encrypted token with jose
|
|
56
|
+
*
|
|
57
|
+
* @param payload the payload to encrypt
|
|
58
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
59
|
+
* @param options options like expiratation date, issuer and audience
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
encrypt: (payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>) => Promise<string>
|
|
63
|
+
/**
|
|
64
|
+
* decrypts a JWT token with jose
|
|
65
|
+
* @param jwt the JWT token
|
|
66
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
67
|
+
* @param options options like issuer and audience
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
decrypt: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>) => Promise<JWTDecryptResult<PayloadType>>;
|
|
71
|
+
/**
|
|
72
|
+
* verify a JWT token with jose
|
|
73
|
+
* @param jwt the JWT token
|
|
74
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
75
|
+
* @param options options like issuer and audience
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
verify: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>) => Promise<JWTVerifyResult<PayloadType>>;
|
|
79
|
+
/**
|
|
80
|
+
* creates a signed JWT with jose
|
|
81
|
+
*
|
|
82
|
+
* @param payload the payload to encrypt
|
|
83
|
+
* @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
|
|
84
|
+
* @param options options like expiratation date, issuer and audience
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
sign: (payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>) => Promise<string>;
|
|
88
|
+
/**
|
|
89
|
+
* decodes a protected header with jose
|
|
90
|
+
* @param token
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
decodeProtectedHeader: (token: string | object) => ProtectedHeaderParameters;
|
|
94
|
+
/**
|
|
95
|
+
* decodes a jwt token
|
|
96
|
+
* @param jwt
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
decode: <PayloadType = JWTPayload>(jwt: string) => PayloadType & JWTPayload;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
13
103
|
export interface MiddlewareConfig {
|
|
14
104
|
middleware?: Array<HandlerWithOptions | Handler>;
|
|
15
105
|
post?: Array<HandlerWithOptions | Handler>;
|
|
@@ -97,7 +187,7 @@ export interface MigrateOptions {
|
|
|
97
187
|
name?: string;
|
|
98
188
|
}
|
|
99
189
|
|
|
100
|
-
export interface ServerInterface {
|
|
190
|
+
export interface ServerInterface extends ServerGlobal{
|
|
101
191
|
// null values are if the feature has been disabled
|
|
102
192
|
db: {
|
|
103
193
|
get(name: string): Database | null;
|
|
@@ -1,38 +1,13 @@
|
|
|
1
1
|
import "./jsx.globals.js";
|
|
2
2
|
|
|
3
|
-
import { Logger
|
|
4
|
-
import { request } from "./@miqro/request.js";
|
|
3
|
+
import { Logger } from "./@miqro/core/lib.js";
|
|
4
|
+
import { request } from "./@miqro/request/lib.js";
|
|
5
5
|
import { RuntimeHTMLElement, Runtime, RuntimeContainer, RuntimeURL, RuntimeOptions, RuntimeShadowRootInit } from "./@miqro/jsx.js";
|
|
6
|
+
import { ServerGlobal } from "./miqro.js";
|
|
6
7
|
|
|
7
8
|
declare global {
|
|
8
9
|
// only available server side
|
|
9
|
-
var server:
|
|
10
|
-
/*// null values are if the feature has been disabled
|
|
11
|
-
db: {
|
|
12
|
-
get(name: string): Database | null;
|
|
13
|
-
},
|
|
14
|
-
ws: {
|
|
15
|
-
get(path: string): WebSocketServer | undefined;
|
|
16
|
-
disconnectAll(path: string): void;
|
|
17
|
-
};
|
|
18
|
-
cache: {
|
|
19
|
-
get: (key: string) => any;
|
|
20
|
-
set: (key: string, value: unknown) => void;
|
|
21
|
-
delete: (key: string) => void;
|
|
22
|
-
has: (key: string) => boolean;
|
|
23
|
-
};
|
|
24
|
-
logger: Logger;*/
|
|
25
|
-
middleware: {
|
|
26
|
-
buffer: typeof ReadBuffer;
|
|
27
|
-
url: typeof URLEncodedParser;
|
|
28
|
-
json: typeof JSONParser;
|
|
29
|
-
text: typeof TextParser;
|
|
30
|
-
cors: typeof CORS;
|
|
31
|
-
session: typeof SessionHandler;
|
|
32
|
-
}
|
|
33
|
-
encodeHTML: (str: string) => string;
|
|
34
|
-
inflateMDtoHTML: (str: string) => string;
|
|
35
|
-
}
|
|
10
|
+
var server: ServerGlobal;
|
|
36
11
|
|
|
37
12
|
var test: {
|
|
38
13
|
PORT: string;
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
7
7
|
RuntimeElementDefinitionOptions,
|
|
@@ -11,6 +11,27 @@ import {
|
|
|
11
11
|
enableDebugLog
|
|
12
12
|
} from "@miqro/jsx";
|
|
13
13
|
import * as jsxLib from "@miqro/jsx";
|
|
14
|
+
import { EncryptOptions, JWTDecryptOptions, JWTDecryptResult, JWTPayload, JWTVerifyOptions, JWTVerifyResult, ProtectedHeaderParameters, SignOptions } from "jose";
|
|
15
|
+
import { KeyObject } from "node:crypto";
|
|
16
|
+
|
|
17
|
+
export interface EncryptJWTOptions {
|
|
18
|
+
alg?: string;
|
|
19
|
+
enc?: string;
|
|
20
|
+
iat?: number | string | Date;
|
|
21
|
+
iss?: string;
|
|
22
|
+
aud?: string;
|
|
23
|
+
exp?: number | string | Date;
|
|
24
|
+
options?: EncryptOptions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface JWTSignOptions {
|
|
28
|
+
alg?: string;
|
|
29
|
+
iat?: number | string | Date;
|
|
30
|
+
iss?: string;
|
|
31
|
+
aud?: string;
|
|
32
|
+
exp?: number | string | Date;
|
|
33
|
+
options?: SignOptions;
|
|
34
|
+
}
|
|
14
35
|
|
|
15
36
|
declare global {
|
|
16
37
|
// jsx only for the default value of tsconfig.json
|
|
@@ -55,6 +76,61 @@ export interface ServerGlobal {
|
|
|
55
76
|
cors: typeof CORS;
|
|
56
77
|
session: typeof SessionHandler;
|
|
57
78
|
};
|
|
79
|
+
newParser(): Parser;
|
|
80
|
+
newClusterCache: (name: string, logger?: Logger) => CacheInterface;
|
|
81
|
+
newLocalCache: (name: string, logger?: Logger) => CacheInterface;
|
|
82
|
+
createSecretKey: (key: string, encoding: BufferEncoding) => KeyObject;
|
|
83
|
+
getWorkerCount: () => number;
|
|
84
|
+
getWorkerNumber: () => number;
|
|
85
|
+
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
|
+
}
|
|
58
134
|
}
|
|
59
135
|
|
|
60
136
|
export interface CacheInterface {
|
|
@@ -92,7 +168,7 @@ export interface LogConfig {
|
|
|
92
168
|
write: (args: LoggerTransportWriteArgs) => Promise<void> | void;
|
|
93
169
|
}
|
|
94
170
|
|
|
95
|
-
export interface ServerInterface {
|
|
171
|
+
export interface ServerInterface extends ServerGlobal {
|
|
96
172
|
// null values are if the feature has been disabled
|
|
97
173
|
db: {
|
|
98
174
|
get(name: string): Database | null;
|
|
@@ -106,9 +182,6 @@ export interface ServerInterface {
|
|
|
106
182
|
cache: CacheInterface;
|
|
107
183
|
localCache: CacheInterface;
|
|
108
184
|
logger?: Logger;
|
|
109
|
-
isPrimaryWorker: () => boolean;
|
|
110
|
-
getWorkerNumber: () => number;
|
|
111
|
-
getWorkerCount: () => number;
|
|
112
185
|
openBrowser: (path: string) => void;
|
|
113
186
|
getLogger: (identifier: string, options?: { level?: any; transports?: any[]; formatter?: any; }) => Logger;
|
|
114
187
|
}
|