anbaric-cloud-hosting 1.6.0 → 1.8.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/package.json +7 -5
- package/src/app-management/FargateBuildLayer.ts +4 -0
- package/src/auditing/AuditRecordStore.ts +4 -3
- package/src/auditing/InMemoryAuditRecordStore.ts +3 -2
- package/src/data-store/PostgresAuditRecordStore.ts +40 -14
- package/src/data-store/PostgresJobPersistence.ts +15 -24
- package/src/data-store/PostgresJsonStore.ts +9 -7
- package/src/data-store/Schema.ts +46 -17
- package/src/data-store/SecretsManagerSecretStore.ts +10 -7
- package/src/hosting/HostingServer.ts +11 -1
- package/src/hosting/Request.ts +5 -0
- package/src/hosting/handlers/AuditsHandler.ts +12 -9
- package/src/hosting/handlers/DocumentsHandler.ts +5 -5
- package/src/hosting/handlers/JobsHandler.ts +8 -25
- package/src/hosting/handlers/PluginsHandler.ts +52 -0
- package/src/hosting/handlers/SecretsHandler.ts +5 -5
- package/src/hosting/pages/platform-ui.html +4 -4
- package/src/index.ts +5 -0
- package/src/main.ts +6 -1
- package/src/plugins/PageDirectory.ts +35 -0
- package/src/plugins/Plugin.ts +39 -0
- package/src/plugins/PluginBundler.ts +75 -0
- package/src/plugins/PluginLoader.ts +72 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {LoadedPlugin} from "../../plugins/Plugin";
|
|
2
|
+
import {Request} from "../Request";
|
|
3
|
+
import {RequestHandler} from "../RequestHandler";
|
|
4
|
+
|
|
5
|
+
class PluginsHandler implements RequestHandler {
|
|
6
|
+
|
|
7
|
+
constructor(private plugins : Array<LoadedPlugin>) {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async handle(request : Request) : Promise<void> {
|
|
11
|
+
if (request.method !== "GET") return request.notFound();
|
|
12
|
+
if (!request.id) return this.manifest(request);
|
|
13
|
+
if (request.id === "data") return this.data(request);
|
|
14
|
+
if (request.id.endsWith(".js")) return this.bundle(request);
|
|
15
|
+
request.notFound();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private manifest(request : Request) : void {
|
|
19
|
+
request.reply(200, this.plugins.map(({ name, plugin }) => ({
|
|
20
|
+
name,
|
|
21
|
+
bundle: `/plugins/${name}.js`,
|
|
22
|
+
pages: plugin.pages,
|
|
23
|
+
widgets: plugin.widgets.map(({ page, id, title, position, data }) =>
|
|
24
|
+
({ page, id, title, position, hasData: data !== undefined })),
|
|
25
|
+
})));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private bundle(request : Request) : void {
|
|
29
|
+
const name = request.id!.slice(0, -".js".length);
|
|
30
|
+
const found = this.plugins.find(plugin => plugin.name === name);
|
|
31
|
+
if (!found) return request.notFound();
|
|
32
|
+
request.replyJavaScript(found.bundle);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private async data(request : Request) : Promise<void> {
|
|
36
|
+
const pluginName = request.query("plugin");
|
|
37
|
+
const widgetId = request.query("widget");
|
|
38
|
+
const found = this.plugins.find(plugin => plugin.name === pluginName);
|
|
39
|
+
const widget = found?.plugin.widgets.find(candidate => candidate.id === widgetId);
|
|
40
|
+
if (!widget?.data) {
|
|
41
|
+
return request.reply(404, { error: `No data function found for widget "${widgetId}" of plugin "${pluginName}"` });
|
|
42
|
+
}
|
|
43
|
+
const parameters : Record<string, string> = {};
|
|
44
|
+
for (const [key, value] of request.url.searchParams) {
|
|
45
|
+
if (key !== "plugin" && key !== "widget") parameters[key] = value;
|
|
46
|
+
}
|
|
47
|
+
request.reply(200, (await widget.data(parameters)) ?? null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { PluginsHandler }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {SecretStore} from "anbaric-tsapi";
|
|
1
|
+
import {SecretStore, SystemActor} from "anbaric-tsapi";
|
|
2
2
|
import {Request} from "../Request";
|
|
3
3
|
import {RequestHandler} from "../RequestHandler";
|
|
4
4
|
|
|
@@ -17,13 +17,13 @@ class SecretsHandler implements RequestHandler {
|
|
|
17
17
|
case "PUT": {
|
|
18
18
|
const { value } = await request.body();
|
|
19
19
|
if (typeof value !== "string") return request.reply(400, { error: "Expected a body of { value : string }" });
|
|
20
|
-
await this.secretStore.
|
|
20
|
+
await this.secretStore.create(SystemActor.actor, name, value);
|
|
21
21
|
return request.reply(204);
|
|
22
22
|
}
|
|
23
23
|
case "GET":
|
|
24
|
-
return request.reply(200, { value: await this.secretStore.retrieve(name) });
|
|
24
|
+
return request.reply(200, { value: await this.secretStore.retrieve(name, SystemActor.actor) });
|
|
25
25
|
case "DELETE":
|
|
26
|
-
await this.secretStore.delete(name);
|
|
26
|
+
await this.secretStore.delete(name, SystemActor.actor);
|
|
27
27
|
return request.reply(204);
|
|
28
28
|
}
|
|
29
29
|
request.notFound();
|
|
@@ -32,7 +32,7 @@ class SecretsHandler implements RequestHandler {
|
|
|
32
32
|
private async handleCollection(request : Request) : Promise<void> {
|
|
33
33
|
switch (request.method) {
|
|
34
34
|
case "GET":
|
|
35
|
-
return request.reply(200, await this.secretStore.list());
|
|
35
|
+
return request.reply(200, await this.secretStore.list(SystemActor.actor));
|
|
36
36
|
}
|
|
37
37
|
request.notFound();
|
|
38
38
|
}
|