@omujs/omu 0.9.31 → 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 +19 -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 +17 -4
- 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/api/registry/registry.d.ts +13 -0
- package/dist/dts/api/server/extension.d.ts +9 -1
- 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 +23 -13
- package/dist/esm/api/dashboard/index.js +23 -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 +47 -3
- package/dist/esm/api/i18n/index.js +47 -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 +47 -3
- package/dist/esm/api/registry/index.js +47 -3
- package/dist/esm/api/registry/registry.js +1 -1
- package/dist/esm/api/server/extension.js +51 -5
- package/dist/esm/api/server/index.js +51 -5
- package/dist/esm/api/session/extension.js +47 -3
- package/dist/esm/api/session/index.js +47 -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 +369 -189
- package/dist/esm/network/index.js +3 -3
- package/dist/esm/network/network.js +3 -3
- package/dist/esm/omu.js +368 -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 +40 -14
- 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/api/registry/extension.ts +46 -1
- package/src/api/registry/registry.ts +23 -0
- package/src/api/server/extension.ts +10 -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
|
@@ -8,6 +8,7 @@ import { ExtensionType } from '../extension.js';
|
|
|
8
8
|
import { PermissionTypeJson } from '../permission/permission.js';
|
|
9
9
|
import { PackageInfo } from '../plugin/package-info.js';
|
|
10
10
|
import { Registry, RegistryType } from '../registry/registry.js';
|
|
11
|
+
import { AppIndexRegistryMeta } from '../server/extension.js';
|
|
11
12
|
import type { Table } from '../table/table.js';
|
|
12
13
|
import { TableType } from '../table/table.js';
|
|
13
14
|
|
|
@@ -201,15 +202,14 @@ const DASHBOARD_WEBVIEW_EVENT_PACKET = PacketType.createJson<WebviewEventPacket>
|
|
|
201
202
|
});
|
|
202
203
|
|
|
203
204
|
type AllowedHost = {
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
id: string;
|
|
206
|
+
hosts: string[];
|
|
206
207
|
};
|
|
207
208
|
|
|
208
|
-
const
|
|
209
|
-
name: '
|
|
210
|
-
key: (entry) => entry.
|
|
211
|
-
|
|
212
|
-
.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 },
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
const DASHBOARD_HOST_REQUEST = EndpointType.createJson<{
|
|
@@ -285,10 +285,23 @@ export interface PromptRequestAppInstall extends PromptRequestBase<'app/install'
|
|
|
285
285
|
export interface PromptRequestAppUpdate extends PromptRequestBase<'app/update'> {
|
|
286
286
|
old_app: AppJson;
|
|
287
287
|
new_app: AppJson;
|
|
288
|
+
dependencies: Record<string, AppJson>;
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
export interface PromptRequestIndexInstall extends PromptRequestBase<'index/install'> {
|
|
291
292
|
index_url: string;
|
|
293
|
+
meta?: AppIndexRegistryMeta;
|
|
294
|
+
}
|
|
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[];
|
|
292
305
|
}
|
|
293
306
|
|
|
294
307
|
export type PromptRequest = (
|
|
@@ -297,13 +310,14 @@ export type PromptRequest = (
|
|
|
297
310
|
| PromptRequestAppInstall
|
|
298
311
|
| PromptRequestAppUpdate
|
|
299
312
|
| PromptRequestIndexInstall
|
|
313
|
+
| PromptRequestHttpPort
|
|
300
314
|
);
|
|
301
315
|
|
|
302
316
|
const DASHBOARD_PROMPT_REQUEST = PacketType.createJson<PromptRequest>(DASHBOARD_EXTENSION_TYPE, {
|
|
303
317
|
name: 'prompt_request',
|
|
304
318
|
});
|
|
305
319
|
|
|
306
|
-
export type PromptResult = 'accept' | 'deny';
|
|
320
|
+
export type PromptResult = 'accept' | 'deny' | 'block';
|
|
307
321
|
|
|
308
322
|
interface PromptResponse {
|
|
309
323
|
id: string;
|
|
@@ -315,6 +329,10 @@ const DASHBOARD_PROMPT_RESPONSE = PacketType.createJson<PromptResponse>(DASHBOAR
|
|
|
315
329
|
name: 'prompt_response',
|
|
316
330
|
});
|
|
317
331
|
|
|
332
|
+
const DASHBOARD_PROMPT_CLEAR_BLOCKED = EndpointType.createJson<null, null>(DASHBOARD_EXTENSION_TYPE, {
|
|
333
|
+
name: 'prompt_clear_blocked',
|
|
334
|
+
});
|
|
335
|
+
|
|
318
336
|
export class DashboardExtension {
|
|
319
337
|
public readonly type: ExtensionType<DashboardExtension> = DASHBOARD_EXTENSION_TYPE;
|
|
320
338
|
private dashboard: DashboardHandler | null = null;
|
|
@@ -378,7 +396,7 @@ export class DashboardExtension {
|
|
|
378
396
|
if (!handle) return;
|
|
379
397
|
handle.emit(packet.event);
|
|
380
398
|
});
|
|
381
|
-
this.allowedHosts = omu.tables.get(
|
|
399
|
+
this.allowedHosts = omu.tables.get(DASHBOARD_ALLOWED_WEBVIEW_HOSTS);
|
|
382
400
|
this.speechRecognition = omu.registries.get(DASHBOARD_SPEECH_RECOGNITION);
|
|
383
401
|
}
|
|
384
402
|
|
|
@@ -395,6 +413,8 @@ export class DashboardExtension {
|
|
|
395
413
|
return await dashboard.handleUpdateApp(request);
|
|
396
414
|
case 'index/install':
|
|
397
415
|
return await dashboard.handleIndexInstall(request);
|
|
416
|
+
case 'http/port':
|
|
417
|
+
return await dashboard.handleHttpPortRequest(request);
|
|
398
418
|
default:
|
|
399
419
|
throw new Error(`Unknown prompt requested: ${JSON.stringify(request)}`);
|
|
400
420
|
}
|
|
@@ -445,8 +465,9 @@ export class DashboardExtension {
|
|
|
445
465
|
this.omu.endpoints.bind(DASHBOARD_COOKIES_GET, async (request, params): Promise<UserResponse<Cookie[]>> => {
|
|
446
466
|
const { url } = request;
|
|
447
467
|
const { hostname } = new URL(url);
|
|
448
|
-
const
|
|
449
|
-
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);
|
|
450
471
|
if (!allowed) {
|
|
451
472
|
return {
|
|
452
473
|
type: 'cancelled',
|
|
@@ -456,8 +477,9 @@ export class DashboardExtension {
|
|
|
456
477
|
});
|
|
457
478
|
this.omu.endpoints.bind(DASHBOARD_HOST_REQUEST, async (request, params): Promise<UserResponse> => {
|
|
458
479
|
const { host } = request;
|
|
459
|
-
const
|
|
460
|
-
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);
|
|
461
483
|
if (allowed) {
|
|
462
484
|
return {
|
|
463
485
|
type: 'ok',
|
|
@@ -466,7 +488,7 @@ export class DashboardExtension {
|
|
|
466
488
|
}
|
|
467
489
|
const result = await dashboard.hostRequested(request, params);
|
|
468
490
|
if (result.type === 'ok') {
|
|
469
|
-
hostEntry.
|
|
491
|
+
hostEntry.hosts.push(host);
|
|
470
492
|
await this.allowedHosts.update(hostEntry);
|
|
471
493
|
}
|
|
472
494
|
return result;
|
|
@@ -590,6 +612,10 @@ export class DashboardExtension {
|
|
|
590
612
|
return await this.omu.endpoints.call(DASHBOARD_APP_INSTALL_ENDPOINT, app);
|
|
591
613
|
}
|
|
592
614
|
|
|
615
|
+
public async clearBlockedPrompts(): Promise<null> {
|
|
616
|
+
return await this.omu.endpoints.call(DASHBOARD_PROMPT_CLEAR_BLOCKED, null);
|
|
617
|
+
}
|
|
618
|
+
|
|
593
619
|
public async requireDragDrop(): Promise<DragDropHandler> {
|
|
594
620
|
await this.omu.endpoints.call(DASHBOARD_DRAG_DROP_REQUEST_ENDPOINT, {});
|
|
595
621
|
const listeners = this.dragDropListeners;
|
|
@@ -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,
|