@omujs/omu 0.9.32 → 0.9.33
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/CHANGELOG.md +11 -0
- package/dist/dts/api/asset/extension.d.ts +3 -3
- package/dist/dts/api/asset/index.d.ts +1 -1
- package/dist/dts/api/dashboard/extension.d.ts +13 -3
- package/dist/dts/api/dashboard/handler.d.ts +2 -1
- package/dist/dts/api/dashboard/index.d.ts +1 -1
- package/dist/dts/api/http/extension.d.ts +2 -135
- package/dist/dts/api/http/http.d.ts +36 -0
- package/dist/dts/api/http/websocket.d.ts +123 -0
- package/dist/dts/api/permission/extension.d.ts +1 -0
- package/dist/dts/index.d.ts +1 -3
- package/dist/dts/version.d.ts +1 -1
- package/dist/esm/api/asset/extension.js +43 -18
- package/dist/esm/api/asset/index.js +42 -17
- package/dist/esm/api/dashboard/extension.js +17 -13
- package/dist/esm/api/dashboard/index.js +17 -13
- package/dist/esm/api/endpoint/extension.js +3 -3
- package/dist/esm/api/extension.js +3 -3
- package/dist/esm/api/http/extension.js +262 -277
- package/dist/esm/api/http/http.js +442 -0
- package/dist/esm/api/http/index.js +262 -165
- package/dist/esm/api/http/websocket.js +220 -0
- package/dist/esm/api/i18n/extension.js +3 -3
- package/dist/esm/api/i18n/index.js +3 -3
- package/dist/esm/api/index.js +3 -3
- package/dist/esm/api/logger/extension.js +3 -3
- package/dist/esm/api/logger/index.js +3 -3
- package/dist/esm/api/permission/extension.js +6 -3
- package/dist/esm/api/plugin/extension.js +3 -3
- package/dist/esm/api/plugin/index.js +3 -3
- package/dist/esm/api/registry/extension.js +3 -3
- package/dist/esm/api/registry/index.js +3 -3
- package/dist/esm/api/server/extension.js +3 -3
- package/dist/esm/api/server/index.js +3 -3
- package/dist/esm/api/session/extension.js +3 -3
- package/dist/esm/api/session/index.js +3 -3
- package/dist/esm/api/signal/extension.js +3 -3
- package/dist/esm/api/table/extension.js +3 -3
- package/dist/esm/api/table/index.js +3 -3
- package/dist/esm/index.js +319 -189
- package/dist/esm/network/index.js +3 -3
- package/dist/esm/network/network.js +3 -3
- package/dist/esm/omu.js +318 -186
- package/dist/esm/version.js +3 -3
- package/package.json +1 -1
- package/src/api/asset/extension.ts +46 -12
- package/src/api/asset/index.ts +1 -2
- package/src/api/dashboard/extension.ts +29 -13
- package/src/api/dashboard/handler.ts +2 -1
- package/src/api/dashboard/index.ts +2 -0
- package/src/api/extension.ts +1 -1
- package/src/api/http/extension.ts +13 -364
- package/src/api/http/http.ts +79 -0
- package/src/api/http/websocket.ts +283 -0
- package/src/api/permission/extension.ts +4 -0
- package/src/index.ts +3 -5
- package/src/version.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/esm/version.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/version.ts
|
|
3
|
-
var VERSION = "0.9.
|
|
3
|
+
var VERSION = "0.9.32";
|
|
4
4
|
export {
|
|
5
5
|
VERSION
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
9
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
8
|
+
//# debugId=DEEFD25FE9A5D95764756E2164756E21
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL3ZlcnNpb24udHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbCiAgICAiZXhwb3J0IGNvbnN0IFZFUlNJT04gPSAnMC45LjMyJztcbiIKICBdLAogICJtYXBwaW5ncyI6ICI7O0FBQU8sSUFBTSxVQUFVOyIsCiAgImRlYnVnSWQiOiAiREVFRkQyNUZFOUE1RDk1NzY0NzU2RTIxNjQ3NTZFMjEiLAogICJuYW1lcyI6IFtdCn0=
|
package/package.json
CHANGED
|
@@ -53,14 +53,15 @@ const FILE_ARRAY_SERIALIZER = new Serializer<Asset[], Uint8Array>(
|
|
|
53
53
|
},
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
export const
|
|
56
|
+
export const ASSET_PERMISSION_ID: Identifier = ASSET_EXTENSION_TYPE;
|
|
57
|
+
|
|
57
58
|
const ASSET_UPLOAD_ENDPOINT = EndpointType.createSerialized<Asset, Identifier>(
|
|
58
59
|
ASSET_EXTENSION_TYPE,
|
|
59
60
|
{
|
|
60
61
|
name: 'upload',
|
|
61
62
|
requestSerializer: FILE_SERIALIZER,
|
|
62
63
|
responseSerializer: Serializer.of(Identifier).toJson(),
|
|
63
|
-
permissionId:
|
|
64
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
64
65
|
},
|
|
65
66
|
);
|
|
66
67
|
const ASSET_UPLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Asset[], Identifier[]>(
|
|
@@ -69,17 +70,16 @@ const ASSET_UPLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Asset[], Identi
|
|
|
69
70
|
name: 'upload_many',
|
|
70
71
|
requestSerializer: FILE_ARRAY_SERIALIZER,
|
|
71
72
|
responseSerializer: Serializer.of(Identifier).toArray().pipe(Serializer.json()),
|
|
72
|
-
permissionId:
|
|
73
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
73
74
|
},
|
|
74
75
|
);
|
|
75
|
-
export const ASSET_DOWNLOAD_PERMISSION_ID: Identifier = ASSET_EXTENSION_TYPE.join('download');
|
|
76
76
|
const ASSET_DOWNLOAD_ENDPOINT = EndpointType.createSerialized<Identifier, Asset>(
|
|
77
77
|
ASSET_EXTENSION_TYPE,
|
|
78
78
|
{
|
|
79
79
|
name: 'download',
|
|
80
80
|
requestSerializer: Serializer.of(Identifier).pipe(Serializer.json()),
|
|
81
81
|
responseSerializer: FILE_SERIALIZER,
|
|
82
|
-
permissionId:
|
|
82
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
83
83
|
},
|
|
84
84
|
);
|
|
85
85
|
const ASSET_DOWNLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Identifier[], Asset[]>(
|
|
@@ -88,23 +88,40 @@ const ASSET_DOWNLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Identifier[],
|
|
|
88
88
|
name: 'download_many',
|
|
89
89
|
requestSerializer: Serializer.of(Identifier).toArray().pipe(Serializer.json()),
|
|
90
90
|
responseSerializer: FILE_ARRAY_SERIALIZER,
|
|
91
|
-
permissionId:
|
|
91
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
92
92
|
},
|
|
93
93
|
);
|
|
94
|
-
export const ASSET_DELETE_PERMISSION_ID: Identifier = ASSET_EXTENSION_TYPE.join('delete');
|
|
95
94
|
const ASSET_DELETE_ENDPOINT = EndpointType.createJson<Identifier, null>(
|
|
96
95
|
ASSET_EXTENSION_TYPE,
|
|
97
96
|
{
|
|
98
97
|
name: 'delete',
|
|
99
98
|
requestSerializer: Identifier,
|
|
100
|
-
permissionId:
|
|
99
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const ASSET_GENERATE_TOKEN_ENDPOINT = EndpointType.createJson<object, { token: string }>(
|
|
104
|
+
ASSET_EXTENSION_TYPE,
|
|
105
|
+
{
|
|
106
|
+
name: 'token_generate',
|
|
107
|
+
permissionId: ASSET_PERMISSION_ID,
|
|
101
108
|
},
|
|
102
109
|
);
|
|
103
110
|
|
|
104
111
|
export class AssetExtension {
|
|
105
112
|
public readonly type: ExtensionType<AssetExtension> = ASSET_EXTENSION_TYPE;
|
|
113
|
+
private assetToken: string | undefined = undefined;
|
|
106
114
|
|
|
107
|
-
constructor(private readonly omu: Omu) {
|
|
115
|
+
constructor(private readonly omu: Omu) {
|
|
116
|
+
omu.network.event.disconnected.listen(() => {
|
|
117
|
+
this.assetToken = undefined;
|
|
118
|
+
});
|
|
119
|
+
omu.network.addTask(async () => {
|
|
120
|
+
if (omu.permissions.required(ASSET_PERMISSION_ID)) {
|
|
121
|
+
this.requestGenerateAssetToken();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
108
125
|
|
|
109
126
|
public async upload(identifier: IntoId, buffer: Uint8Array): Promise<Identifier> {
|
|
110
127
|
const assetIdentifier = await this.omu.endpoints.call(ASSET_UPLOAD_ENDPOINT, {
|
|
@@ -138,22 +155,39 @@ export class AssetExtension {
|
|
|
138
155
|
await this.omu.endpoints.call(ASSET_DELETE_ENDPOINT, id);
|
|
139
156
|
}
|
|
140
157
|
|
|
158
|
+
private async requestGenerateAssetToken() {
|
|
159
|
+
const result = await this.omu.endpoints.call(ASSET_GENERATE_TOKEN_ENDPOINT, {});
|
|
160
|
+
this.assetToken = result.token;
|
|
161
|
+
}
|
|
162
|
+
|
|
141
163
|
public url(
|
|
142
164
|
id: IntoId,
|
|
143
165
|
options?: { cache?: 'no-cache' },
|
|
144
166
|
): string {
|
|
167
|
+
if (!this.assetToken) {
|
|
168
|
+
throw new Error('Asset token is not set');
|
|
169
|
+
}
|
|
145
170
|
const key = Identifier.from(id).key();
|
|
146
171
|
const address = this.omu.network.address;
|
|
147
172
|
const protocol = address.secure ? 'https' : 'http';
|
|
173
|
+
const url = new URL(`${protocol}://${address.host}:${address.port}/asset`);
|
|
174
|
+
url.searchParams.set('asset_token', this.assetToken);
|
|
175
|
+
url.searchParams.set('id', key);
|
|
148
176
|
if (options?.cache === 'no-cache') {
|
|
149
|
-
|
|
177
|
+
url.searchParams.set('t', Date.now().toString());
|
|
150
178
|
}
|
|
151
|
-
return
|
|
179
|
+
return url.toString();
|
|
152
180
|
}
|
|
153
181
|
|
|
154
182
|
public proxy(url: string): string {
|
|
183
|
+
if (!this.assetToken) {
|
|
184
|
+
throw new Error('Asset token is not set');
|
|
185
|
+
}
|
|
155
186
|
const address = this.omu.network.address;
|
|
156
187
|
const protocol = address.secure ? 'https' : 'http';
|
|
157
|
-
|
|
188
|
+
const proxyUrl = new URL(`${protocol}://${address.host}:${address.port}/proxy`);
|
|
189
|
+
proxyUrl.searchParams.set('asset_token', this.assetToken);
|
|
190
|
+
proxyUrl.searchParams.set('url', url);
|
|
191
|
+
return proxyUrl.toString();
|
|
158
192
|
}
|
|
159
193
|
}
|
package/src/api/asset/index.ts
CHANGED
|
@@ -202,15 +202,14 @@ const DASHBOARD_WEBVIEW_EVENT_PACKET = PacketType.createJson<WebviewEventPacket>
|
|
|
202
202
|
});
|
|
203
203
|
|
|
204
204
|
type AllowedHost = {
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
id: string;
|
|
206
|
+
hosts: string[];
|
|
207
207
|
};
|
|
208
208
|
|
|
209
|
-
const
|
|
210
|
-
name: '
|
|
211
|
-
key: (entry) => entry.
|
|
212
|
-
|
|
213
|
-
.field('apps', Serializer.of(Identifier).toArray()),
|
|
209
|
+
const DASHBOARD_ALLOWED_WEBVIEW_HOSTS = TableType.createJson<AllowedHost>(DASHBOARD_EXTENSION_TYPE, {
|
|
210
|
+
name: 'allowed_webview_hosts',
|
|
211
|
+
key: (entry) => entry.id,
|
|
212
|
+
permissions: { all: DASHBOARD_SET_PERMISSION_ID },
|
|
214
213
|
});
|
|
215
214
|
|
|
216
215
|
const DASHBOARD_HOST_REQUEST = EndpointType.createJson<{
|
|
@@ -286,6 +285,7 @@ export interface PromptRequestAppInstall extends PromptRequestBase<'app/install'
|
|
|
286
285
|
export interface PromptRequestAppUpdate extends PromptRequestBase<'app/update'> {
|
|
287
286
|
old_app: AppJson;
|
|
288
287
|
new_app: AppJson;
|
|
288
|
+
dependencies: Record<string, AppJson>;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
export interface PromptRequestIndexInstall extends PromptRequestBase<'index/install'> {
|
|
@@ -293,12 +293,24 @@ export interface PromptRequestIndexInstall extends PromptRequestBase<'index/inst
|
|
|
293
293
|
meta?: AppIndexRegistryMeta;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
export interface PortProcess {
|
|
297
|
+
port: number;
|
|
298
|
+
name: string;
|
|
299
|
+
exe: string;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface PromptRequestHttpPort extends PromptRequestBase<'http/port'> {
|
|
303
|
+
app: AppJson;
|
|
304
|
+
processes: PortProcess[];
|
|
305
|
+
}
|
|
306
|
+
|
|
296
307
|
export type PromptRequest = (
|
|
297
308
|
PromptRequestAppPermissions
|
|
298
309
|
| PromptRequestAppPlugins
|
|
299
310
|
| PromptRequestAppInstall
|
|
300
311
|
| PromptRequestAppUpdate
|
|
301
312
|
| PromptRequestIndexInstall
|
|
313
|
+
| PromptRequestHttpPort
|
|
302
314
|
);
|
|
303
315
|
|
|
304
316
|
const DASHBOARD_PROMPT_REQUEST = PacketType.createJson<PromptRequest>(DASHBOARD_EXTENSION_TYPE, {
|
|
@@ -384,7 +396,7 @@ export class DashboardExtension {
|
|
|
384
396
|
if (!handle) return;
|
|
385
397
|
handle.emit(packet.event);
|
|
386
398
|
});
|
|
387
|
-
this.allowedHosts = omu.tables.get(
|
|
399
|
+
this.allowedHosts = omu.tables.get(DASHBOARD_ALLOWED_WEBVIEW_HOSTS);
|
|
388
400
|
this.speechRecognition = omu.registries.get(DASHBOARD_SPEECH_RECOGNITION);
|
|
389
401
|
}
|
|
390
402
|
|
|
@@ -401,6 +413,8 @@ export class DashboardExtension {
|
|
|
401
413
|
return await dashboard.handleUpdateApp(request);
|
|
402
414
|
case 'index/install':
|
|
403
415
|
return await dashboard.handleIndexInstall(request);
|
|
416
|
+
case 'http/port':
|
|
417
|
+
return await dashboard.handleHttpPortRequest(request);
|
|
404
418
|
default:
|
|
405
419
|
throw new Error(`Unknown prompt requested: ${JSON.stringify(request)}`);
|
|
406
420
|
}
|
|
@@ -451,8 +465,9 @@ export class DashboardExtension {
|
|
|
451
465
|
this.omu.endpoints.bind(DASHBOARD_COOKIES_GET, async (request, params): Promise<UserResponse<Cookie[]>> => {
|
|
452
466
|
const { url } = request;
|
|
453
467
|
const { hostname } = new URL(url);
|
|
454
|
-
const
|
|
455
|
-
const
|
|
468
|
+
const id = params.caller.key();
|
|
469
|
+
const allowedHost: AllowedHost = await this.allowedHosts.get(id) ?? { id, hosts: [] };
|
|
470
|
+
const allowed = allowedHost.hosts.includes(hostname);
|
|
456
471
|
if (!allowed) {
|
|
457
472
|
return {
|
|
458
473
|
type: 'cancelled',
|
|
@@ -462,8 +477,9 @@ export class DashboardExtension {
|
|
|
462
477
|
});
|
|
463
478
|
this.omu.endpoints.bind(DASHBOARD_HOST_REQUEST, async (request, params): Promise<UserResponse> => {
|
|
464
479
|
const { host } = request;
|
|
465
|
-
const
|
|
466
|
-
const
|
|
480
|
+
const id = params.caller.key();
|
|
481
|
+
const hostEntry: AllowedHost = await this.allowedHosts.get(id) ?? { id, hosts: [] };
|
|
482
|
+
const allowed = hostEntry.hosts.includes(host);
|
|
467
483
|
if (allowed) {
|
|
468
484
|
return {
|
|
469
485
|
type: 'ok',
|
|
@@ -472,7 +488,7 @@ export class DashboardExtension {
|
|
|
472
488
|
}
|
|
473
489
|
const result = await dashboard.hostRequested(request, params);
|
|
474
490
|
if (result.type === 'ok') {
|
|
475
|
-
hostEntry.
|
|
491
|
+
hostEntry.hosts.push(host);
|
|
476
492
|
await this.allowedHosts.update(hostEntry);
|
|
477
493
|
}
|
|
478
494
|
return result;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { App } from '../../app.js';
|
|
2
2
|
import { Identifier } from '../../identifier';
|
|
3
3
|
import { InvokedParams } from '../endpoint/packets.js';
|
|
4
|
-
import { Cookie, GetCookiesRequest, HostRequest, PromptRequestAppInstall, PromptRequestAppPermissions, PromptRequestAppPlugins, PromptRequestAppUpdate, PromptRequestIndexInstall, PromptResult, SpeechRecognitionStart, UserResponse, WebviewEvent, WebviewPacket, WebviewRequest } from './extension.js';
|
|
4
|
+
import { Cookie, GetCookiesRequest, HostRequest, PromptRequestAppInstall, PromptRequestAppPermissions, PromptRequestAppPlugins, PromptRequestAppUpdate, PromptRequestHttpPort, PromptRequestIndexInstall, PromptResult, SpeechRecognitionStart, UserResponse, WebviewEvent, WebviewPacket, WebviewRequest } from './extension.js';
|
|
5
5
|
|
|
6
6
|
import type { DragDropReadRequestDashboard, DragDropReadResponse, DragDropRequestDashboard } from './packets.js';
|
|
7
7
|
|
|
@@ -11,6 +11,7 @@ export interface DashboardHandler {
|
|
|
11
11
|
handleInstallApp(request: PromptRequestAppInstall): Promise<PromptResult>;
|
|
12
12
|
handleUpdateApp(request: PromptRequestAppUpdate): Promise<PromptResult>;
|
|
13
13
|
handleIndexInstall(request: PromptRequestIndexInstall): Promise<PromptResult>;
|
|
14
|
+
handleHttpPortRequest(request: PromptRequestHttpPort): Promise<PromptResult>;
|
|
14
15
|
handleOpenApp(app: App): Promise<void>;
|
|
15
16
|
handleDragDropRequest(request: DragDropRequestDashboard): Promise<boolean>;
|
|
16
17
|
handleDragDropReadRequest(request: DragDropReadRequestDashboard): Promise<DragDropReadResponse>;
|
|
@@ -13,11 +13,13 @@ export {
|
|
|
13
13
|
UserResponse,
|
|
14
14
|
WebviewPacket,
|
|
15
15
|
WebviewRequest,
|
|
16
|
+
type PortProcess,
|
|
16
17
|
type PromptRequest,
|
|
17
18
|
type PromptRequestAppInstall,
|
|
18
19
|
type PromptRequestAppPermissions,
|
|
19
20
|
type PromptRequestAppPlugins,
|
|
20
21
|
type PromptRequestAppUpdate,
|
|
22
|
+
type PromptRequestHttpPort,
|
|
21
23
|
type PromptRequestIndexInstall,
|
|
22
24
|
type PromptResult,
|
|
23
25
|
type SpeechRecognitionStart,
|