From ebadebbd11a78b60e7f29ea75834b183ed6f3b5c Mon Sep 17 00:00:00 2001 From: Sander Grootendorst Date: Thu, 3 Dec 2026 12:09:17 +0100 Subject: [PATCH] Support shared bid history and custom project opening --- README.md | 5 ++-- src/components/ProjectHeader.svelte | 4 ++-- src/components/ProjectPicker.svelte | 4 ++-- src/components/ProjectWorkspace.svelte | 4 ++-- src/dom.d.ts | 3 ++- src/dom.js | 4 ++-- src/overview.js | 5 ++-- src/shared-folder.d.ts | 13 +++++++---- src/shared-folder.js | 32 +++++++++++++++++++++++++- 9 files changed, 56 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4aa9ced..eaa5f73 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,15 @@ For directory-backed collections, initialize the empty collection in the selecte ## Specialist viewers for shared data -The dashboard exposes two versioned datasets through ordinary workspace files. Each extension obtains its own launch-scoped grant through `openWorkspaceAsset`. A group supplies the requesting user's access context. The workspace owns the data and its checkpoints. +The dashboard exposes versioned datasets through ordinary workspace files. Each extension obtains its own launch-scoped grant through `openWorkspaceAsset`. A group supplies the requesting user's access context. The workspace owns the data and its checkpoints. | Asset | Canonical store | Contents | | --- | --- | --- | | `suppliers` | `/shared/suppliers/catalog.kv` | Stable supplier IDs, profiles, overrides, import history and enrichments. `catalog/meta.active` selects the generation. | | `prices` | `/shared/prices/prices.kv` | Comparable price observations, keyed by stable observation ID in the list `observations/v1`. | +| `bid_history` | `/shared/bid_history/inschrijfhistorie.json` | Historical bids by ID and lot, with criterion scores and feedback. | -Declare `workspace_asset_suppliers_read` or `workspace_asset_prices_read`, plus `filesystem_read` and `kv_store_read`. Editors also need the corresponding asset write permission, `filesystem_write`, `kv_store_write` and effective write access to the folder. Store a supplier ID on a project line. Resolve the ID against the supplier asset when displaying current details. Keep original offers, recipients and sent messages in the project. +Declare the asset’s `workspace_asset__read` permission and `filesystem_read`. Editors also need its write permission, `filesystem_write` and effective write access to the folder. KV datasets additionally require `kv_store_read` and, for editing, `kv_store_write`. For JSON datasets, pass the snapshot from `createSharedFolderReader(...).readJson(relative)` to `writeWorkspaceAssetJson(context, relative, value, snapshot)` with a writable asset grant in `context.folder`. Store a supplier ID on a project line. Resolve the ID against the supplier asset when displaying current details. Keep original offers, recipients and sent messages in the project. ```js import { openWorkspaceAsset } from '@isa-warden/isa-project-format/shared-folder'; diff --git a/src/components/ProjectHeader.svelte b/src/components/ProjectHeader.svelte index b7ad4e8..2891242 100644 --- a/src/components/ProjectHeader.svelte +++ b/src/components/ProjectHeader.svelte @@ -1,5 +1,5 @@ - + diff --git a/src/components/ProjectPicker.svelte b/src/components/ProjectPicker.svelte index 3d61633..5025a6e 100644 --- a/src/components/ProjectPicker.svelte +++ b/src/components/ProjectPicker.svelte @@ -1,5 +1,5 @@ - + diff --git a/src/components/ProjectWorkspace.svelte b/src/components/ProjectWorkspace.svelte index 23a0bfe..39fb8d0 100644 --- a/src/components/ProjectWorkspace.svelte +++ b/src/components/ProjectWorkspace.svelte @@ -1,8 +1,8 @@
diff --git a/src/dom.d.ts b/src/dom.d.ts index cceb5cf..f3b3d06 100644 --- a/src/dom.d.ts +++ b/src/dom.d.ts @@ -1,8 +1,9 @@ -import type { ProjectClient, ProjectBridge, ProjectSession } from './index.js'; +import type { ProjectClient, ProjectBridge, ProjectReference, ProjectSession } from './index.js'; export interface ProjectMountOptions { extensionName?: string; client: ProjectClient; bridge?: ProjectBridge; locale?: 'en' | 'nl'; showEmptyProjectMessage?: boolean; onOverview?: (actions: {refresh(): Promise} | null) => void; + onOpen?: (project: ProjectReference) => Promise; onImport?: () => Promise; onExport?: (session: ProjectSession) => Promise; beforeExport?: (session: ProjectSession) => void | Promise; diff --git a/src/dom.js b/src/dom.js index 0837a3f..a0a89fd 100644 --- a/src/dom.js +++ b/src/dom.js @@ -5,7 +5,7 @@ import { labels } from './labels.js'; import { exportProjectToDialog, importProjectFromDialog } from './transfer.js'; import { styles } from './styles.js'; -export function mountProjectWorkspace(target, {client,bridge,locale='en',extensionName,mode='workspace',beforeExport,onOverview,onImport,onExport,showEmptyProjectMessage} = {}) { +export function mountProjectWorkspace(target, {client,bridge,locale='en',extensionName,mode='workspace',beforeExport,onOverview,onOpen,onImport,onExport,showEmptyProjectMessage} = {}) { if (!target?.ownerDocument || !client) throw new TypeError('Mount target and project client required'); const document = target.ownerDocument; const text = labels[locale] ?? labels.en; @@ -124,7 +124,7 @@ export function mountProjectWorkspace(target, {client,bridge,locale='en',extensi activeView ??= mountActive(active); if (activeView.title.textContent !== active.manifest.name) activeView.title.textContent = active.manifest.name; } else if (!removeOverview) { - removeOverview = mountOverview(content, {client, extensionName, text, locale, onOverview, showEmptyProjectMessage, + removeOverview = mountOverview(content, {client, extensionName, text, locale, onOverview, onOpen, showEmptyProjectMessage, onImport: onImport ?? (bridge && (() => importProjectFromDialog(client, {bridge})))}); } } diff --git a/src/overview.js b/src/overview.js index 5057287..018c237 100644 --- a/src/overview.js +++ b/src/overview.js @@ -2,7 +2,7 @@ import { workspaceElements } from './workspace-elements.js'; // A row identifies a folder accessible through the current launch's grants. Private // recents supply the activity order only, never the inventory or a grant. -export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview, showEmptyProjectMessage = true}) { +export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview, onOpen, showEmptyProjectMessage = true}) { const document = target.ownerDocument; const {icon} = workspaceElements(document); function element(tag, label, className) { @@ -172,7 +172,8 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm const row = container.querySelector('[data-project-id="' + CSS.escape(project.id) + '"]'); row?.setAttribute('aria-busy', 'true'); } - void run(() => client.openListed(project), alert, text.opening + ' ' + project.name); + if (onOpen) void run(() => onOpen(project), alert, ''); + else void run(() => client.openListed(project), alert, text.opening + ' ' + project.name); } function refresh() { if (pendingRefresh) return pendingRefresh; diff --git a/src/shared-folder.d.ts b/src/shared-folder.d.ts index e765c5e..f0326ff 100644 --- a/src/shared-folder.d.ts +++ b/src/shared-folder.d.ts @@ -1,11 +1,16 @@ import type { ProjectBridge, ProjectScope, ProjectRead } from './index.js'; -export type WorkspaceAsset = 'suppliers' | 'prices'; +export type WorkspaceAsset = 'suppliers' | 'prices' | 'bid_history'; +export interface WorkspaceAssetGrant { + readonly asset: WorkspaceAsset; readonly workspaceId: string; readonly groupId: string; + readonly folderId: string; readonly path: string; readonly canWrite: boolean; +} export function openWorkspaceAsset(options: { bridge: ProjectBridge; scope: ProjectScope; asset: WorkspaceAsset; access?: 'read' | 'read_write'; assertCurrent?: () => void; -}): Promise>; +}): Promise; +export function writeWorkspaceAssetJson(options: { + bridge: ProjectBridge; scope: ProjectScope; folder: WorkspaceAssetGrant; assertCurrent?: () => void; +}, relative: string, value: unknown, base: ProjectRead): Promise<{fileId: string; path: string; [key: string]: unknown}>; export function createSharedFolderReader(options: { bridge: ProjectBridge; scope: ProjectScope; diff --git a/src/shared-folder.js b/src/shared-folder.js index 55fc55d..92a512f 100644 --- a/src/shared-folder.js +++ b/src/shared-folder.js @@ -1,13 +1,16 @@ import { validateArchivePath } from './format.js'; import { readAuthoritativeFile } from './shared-read.js'; import { readKvSnapshot } from './kv-snapshot.js'; +import { confirmedWrite } from './proofs.js'; + +const workspaceAssets = ['suppliers', 'prices', 'bid_history']; /** Obtain the calling extension's grant to a workspace-owned dataset. */ export async function openWorkspaceAsset({bridge, scope, asset, access, assertCurrent = () => {}}) { if (typeof bridge?.invoke !== 'function' || !scope?.workspaceId || !scope?.groupId) { throw new TypeError('Host bridge and launch scope required'); } - if (!['suppliers', 'prices'].includes(asset) || (access !== undefined && !['read', 'read_write'].includes(access))) { + if (!workspaceAssets.includes(asset) || (access !== undefined && !['read', 'read_write'].includes(access))) { throw new TypeError('Invalid workspace asset or access mode'); } const {workspaceId, groupId} = scope; @@ -23,6 +26,33 @@ export async function openWorkspaceAsset({bridge, scope, asset, access, assertCu return Object.freeze({asset, workspaceId, groupId, path: folder.path, folderId: folder.folderId, canWrite: folder.canWrite}); } +/** Conditionally create or replace one JSON file under an opened workspace asset. */ +export async function writeWorkspaceAssetJson({bridge, scope, folder, assertCurrent = () => {}}, relative, value, base) { + if (folder?.canWrite !== true || !workspaceAssets.includes(folder.asset) || + folder.path !== '/shared/' + folder.asset || !folder.folderId || !scope?.workspaceId || !scope.groupId || + folder.workspaceId !== scope.workspaceId || folder.groupId !== scope.groupId) { + throw new Error('A writable workspace asset grant for this launch is required'); + } + const path = folder.path + '/' + validateArchivePath(relative); + const replace = base?.status === 'found'; + if (base?.path !== path || (!replace && base.status !== 'absent') || + (replace && (!base.fileId || base.authoritative !== true || !Number.isSafeInteger(base.syncRevision) || base.syncRevision < 0))) { + throw new TypeError('An authoritative read of the target file is required'); + } + const file = {path, text:JSON.stringify(value), contentType:'application/json', replaceExisting:replace}; + if (replace) { + file.expectedSyncRevision = base.syncRevision; + const hash = base.serverContentHash || (base.contentHashVerified && base.contentHash); + if (hash) file.expectedContentHash = hash; + } + assertCurrent(); + const reply = await bridge.invoke('filesystem_upload_files', { + workspaceId:scope.workspaceId, groupId:scope.groupId, files:[file] + }); + assertCurrent(); + return confirmedWrite(reply, path); +} + /** Reads through the calling extension's own host grant. The folder can also * be the root of an open project session. No source is opened for writing. */ export function createSharedFolderReader({bridge,scope,folder,assertCurrent = () => {}}) {