feat(storepkg): install packages from a signed default catalogue, listed on the Extensions page
This commit is contained in:
1 parent
8d73280633
commit
28bb4b4483
15 files changed
+1334
-570
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Plus } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
@@ -25,6 +25,8 @@ const KIND = "extension-settings";
|
||||
const store = useExtensionsStore();
|
||||
onMounted(store.load);
|
||||
|
||||
const available = computed(() => store.catalogue.filter((entry) => !entry.installed));
|
||||
|
||||
const name = ref("");
|
||||
const reference = ref("");
|
||||
const digest = ref("");
|
||||
@@ -59,12 +61,34 @@ const tones = {
|
||||
|
||||
<p v-if="store.error" role="alert" class="mb-4 text-sm text-danger">{{ store.error }}</p>
|
||||
|
||||
<form class="mb-6 flex flex-wrap gap-2" @submit.prevent="install">
|
||||
<Input v-model="name" class="max-w-40" placeholder="Name" aria-label="Name" required />
|
||||
<Input v-model="reference" class="max-w-80 font-mono" placeholder="registry/repo:tag" aria-label="Reference" required />
|
||||
<Input v-model="digest" class="max-w-96 font-mono" placeholder="sha256:…" aria-label="Digest" required />
|
||||
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" /> Install</Button>
|
||||
</form>
|
||||
<section class="mb-6" aria-label="Marketplace">
|
||||
<h2 class="mb-2 text-sm font-medium">Marketplace</h2>
|
||||
<p v-if="store.catalogueError" class="text-sm text-fg-muted">{{ store.catalogueError }}</p>
|
||||
<ul v-else class="divide-y divide-border rounded-lg border border-border bg-card">
|
||||
<li v-for="entry in available" :key="entry.name" class="flex flex-wrap items-center gap-3 px-4 py-3">
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate text-sm font-medium">
|
||||
{{ entry.name }}
|
||||
<span class="font-mono text-xs text-fg-subtle">{{ entry.surface }} {{ entry.version }}</span>
|
||||
</p>
|
||||
<p class="text-xs text-fg-subtle">{{ entry.description }}</p>
|
||||
</div>
|
||||
<Button size="sm" :disabled="!!store.busy" @click="store.installFromCatalogue(entry.name)">
|
||||
<Plus data-icon="inline-start" /> Install
|
||||
</Button>
|
||||
</li>
|
||||
<li v-if="!available.length" class="px-4 py-3 text-sm text-fg-muted">Everything listed is installed.</li>
|
||||
</ul>
|
||||
<details class="mt-3">
|
||||
<summary class="cursor-pointer text-xs text-fg-muted">Install by reference</summary>
|
||||
<form class="mt-2 flex flex-wrap gap-2" @submit.prevent="install">
|
||||
<Input v-model="name" class="max-w-40" placeholder="Name" aria-label="Name" required />
|
||||
<Input v-model="reference" class="max-w-80 font-mono" placeholder="registry/repo:tag" aria-label="Reference" required />
|
||||
<Input v-model="digest" class="max-w-96 font-mono" placeholder="sha256:…" aria-label="Digest" required />
|
||||
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" /> Install</Button>
|
||||
</form>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<ul class="divide-y divide-border rounded-lg border border-border bg-card" aria-label="Extensions">
|
||||
<li v-for="extension in store.extensions" :key="extension.name" class="flex flex-wrap items-center gap-3 px-4 py-3">
|
||||
|
||||
@@ -23,6 +23,17 @@ export interface Extension {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** A package the verified catalogue offers. */
|
||||
export interface CatalogueEntry {
|
||||
name: string;
|
||||
surface: string;
|
||||
version: string;
|
||||
description: string;
|
||||
reference: string;
|
||||
digest: string;
|
||||
installed: boolean;
|
||||
}
|
||||
|
||||
async function call<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch(path, {
|
||||
...init,
|
||||
@@ -59,6 +70,8 @@ export function stage(extension: Extension): "accept" | "disabled" | "enabled" |
|
||||
|
||||
export const useExtensionsStore = defineStore("extensions", () => {
|
||||
const extensions = ref<Extension[]>([]);
|
||||
const catalogue = ref<CatalogueEntry[]>([]);
|
||||
const catalogueError = ref("");
|
||||
const error = ref("");
|
||||
const busy = ref("");
|
||||
|
||||
@@ -69,6 +82,13 @@ export const useExtensionsStore = defineStore("extensions", () => {
|
||||
} catch (cause) {
|
||||
error.value = String((cause as Error).message || cause);
|
||||
}
|
||||
// The catalogue is remote; its failure leaves the installed list usable.
|
||||
try {
|
||||
catalogue.value = await call<CatalogueEntry[]>("/api/extensions/catalogue");
|
||||
catalogueError.value = "";
|
||||
} catch (cause) {
|
||||
catalogueError.value = String((cause as Error).message || cause);
|
||||
}
|
||||
}
|
||||
async function mutate(key: string, action: () => Promise<unknown>): Promise<boolean> {
|
||||
busy.value = key;
|
||||
@@ -86,11 +106,15 @@ export const useExtensionsStore = defineStore("extensions", () => {
|
||||
const path = (name: string) => `/api/extensions/${encodeURIComponent(name)}`;
|
||||
return {
|
||||
extensions,
|
||||
catalogue,
|
||||
catalogueError,
|
||||
error,
|
||||
busy,
|
||||
load,
|
||||
install: (name: string, reference: string, digest: string) =>
|
||||
mutate("install", () => call("/api/extensions", { method: "POST", body: JSON.stringify({ name, reference, digest }) })),
|
||||
installFromCatalogue: (name: string) =>
|
||||
mutate(name, () => call(`/api/extensions/catalogue/${encodeURIComponent(name)}/install`, { method: "POST" })),
|
||||
accept: (name: string) => mutate(name, () => call(`${path(name)}/accept`, { method: "POST" })),
|
||||
setEnabled: (name: string, enabled: boolean) =>
|
||||
mutate(name, () => call(`${path(name)}/enabled`, { method: "PUT", body: JSON.stringify({ enabled }) })),
|
||||
|
||||
Reference in new issue
Block a user