Project format updates
This commit is contained in:
@@ -55,34 +55,37 @@ For directory-backed collections, initialize the empty collection in the selecte
|
|||||||
|
|
||||||
## Specialist viewers for shared data
|
## Specialist viewers for shared data
|
||||||
|
|
||||||
A supplier viewer and a price-book viewer can each open on their own dataset. ISA Match and other authorised extensions can display that same data. All readers use the existing file or KV store and its schema. The viewer’s extension ID does not determine ownership of the 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.
|
||||||
|
|
||||||
Use `@isa-warden/isa-project-format/shared-folder` with a folder already authorised for the current launch. For data inside an open project, pass `scope: session.scope`, `folder: session.project` and `assertCurrent: session.assertCurrent`. For a separately shared register, use the host-authorised workspace folder and the immutable launch scope. Host grants are per package. Reopening a linked folder uses its valid grant. A new reader needs its own host authorisation for a folder outside the project.
|
| 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`. |
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { createSharedFolderReader } from '@isa-warden/isa-project-format/shared-folder';
|
import { openWorkspaceAsset } from '@isa-warden/isa-project-format/shared-folder';
|
||||||
|
import { openPriceAsset } from '@isa-warden/isa-project-format/prices';
|
||||||
|
|
||||||
const reader = createSharedFolderReader({ bridge, scope, folder, assertCurrent });
|
const folder = await openWorkspaceAsset({ bridge, scope, asset: 'suppliers', access: 'read' });
|
||||||
const index = await reader.readJson('isa-match-suppliers.json');
|
const path = folder.path + '/catalog.kv';
|
||||||
if (index.status === 'found') {
|
const subscription = await bridge.invoke('kv_store_subscribe', { path, keys: ['catalog/meta'] });
|
||||||
const register = index.value;
|
try {
|
||||||
if (register.format !== 'isa-match-workspace-suppliers-v1' ||
|
const active = subscription.entries.find(entry => entry.key === 'catalog/meta')?.value?.active;
|
||||||
register.workspaceId !== scope.workspaceId ||
|
// Subscribe to catalog/<active>/supplier/<id>/profile for the linked IDs in batches.
|
||||||
typeof register.id !== 'string' || !register.id || !Array.isArray(register.suppliers)) {
|
// Follow mergedInto on old profiles. Rebind the profile subscription when active changes.
|
||||||
throw new Error('Unexpected supplier register');
|
} finally {
|
||||||
}
|
await bridge.invoke('kv_store_unsubscribe', { path, subscriptionId: subscription.subscriptionId });
|
||||||
const id = encodeURIComponent(register.id);
|
|
||||||
// The supplier directory contains stable supplier IDs and public identities.
|
|
||||||
const suppliers = register.suppliers;
|
|
||||||
// The price-book viewer reads the published price rows from the same folder.
|
|
||||||
const snapshot = await reader.readKv('isa-match-prices-' + id + '.kv');
|
|
||||||
const prices = snapshot.entries.filter(entry => entry.key.startsWith('price/'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prices = await openPriceAsset({ bridge, scope, access: 'read' });
|
||||||
|
const page = await prices.query({ search: 'asfalt', limit: 30 });
|
||||||
```
|
```
|
||||||
|
|
||||||
For supplier details, read `isa-match-catalog-<encoded register ID>.kv` and the active generation in `catalog/meta`. Profiles use `catalog/<active>/supplier/<supplier ID>/profile`. Use the active generation to exclude retired and staged records. The prices KV contains the shared price book. The separate ISA Prijzenregister searches published records across the workspace. A viewer that only needs suppliers can skip the prices read entirely.
|
Price values contain `supplier`, `description`, `specItem`, numeric `unitPrice` (including zero), `unit`, `currency` and `receivedAt` (ISO date or empty). Optional `supplierId` links to the shared supplier and `validUntil` holds an ISO date. A writer assigns one stable observation ID per source observation or quotation version. New writers can use a persisted UUID. Project paths, quotations, review notes and commercial terms belong in the project.
|
||||||
|
|
||||||
`listFiles()` lists the authorised directory. `readFile` and `readJson` distinguish authoritative absence from a failed read. `readKv` pages a consistent snapshot and checks store identity and revision across pages. These operations use the host’s filesystem or KV read access without creating files, modifying records or granting another extension access.
|
To add price observations, open the price asset with `access: 'read_write'` and call `importRows([{ id, value }])`. Keep the same ID on retries. Re-imports preserve edited values and can attach a supplier ID to an existing observation. Queries accept date ranges, exact field filters, facets and revision-checked paging. Follow the supplier schema's publication rules to update profiles and indexes together. A read-only viewer should handle a missing dataset as a distinct state and surface authorization or transport errors. For arbitrary files in an authorised project or workspace folder, `createSharedFolderReader` supports relative file reads and consistent KV snapshots.
|
||||||
|
|
||||||
## ZIP transfer
|
## ZIP transfer
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
},
|
},
|
||||||
"./svelte": {
|
"./svelte": {
|
||||||
"import": "./src/components/index.js"
|
"import": "./src/components/index.js"
|
||||||
|
},
|
||||||
|
"./prices": {
|
||||||
|
"types": "./src/prices.d.ts",
|
||||||
|
"import": "./src/prices.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ function reference(value) {
|
|||||||
if (typeof id !== 'string' || !id || typeof path !== 'string' || !path.startsWith('/') || !path.endsWith('.isap')) throw new TypeError('Invalid project folder');
|
if (typeof id !== 'string' || !id || typeof path !== 'string' || !path.startsWith('/') || !path.endsWith('.isap')) throw new TypeError('Invalid project folder');
|
||||||
validateArchivePath(path.slice(1));
|
validateArchivePath(path.slice(1));
|
||||||
return { id, folderId: id, path, name: String(value.name ?? ''),
|
return { id, folderId: id, path, name: String(value.name ?? ''),
|
||||||
archived: Boolean(value.archived), updatedAt: value.updatedAt, canWrite: value.canWrite,
|
instanceCreatorId: value.instanceCreatorId, instanceCreatedAt: value.instanceCreatedAt, archived: Boolean(value.archived), updatedAt: value.updatedAt, canWrite: value.canWrite,
|
||||||
...(typeof value.hasInstance === 'boolean' && { hasInstance: value.hasInstance }),
|
...(typeof value.hasInstance === 'boolean' && { hasInstance: value.hasInstance }),
|
||||||
projectIdentity: String(value.projectIdentity ?? id), manifestPath: `${path}/project.json`, formatVersion: 1 };
|
projectIdentity: String(value.projectIdentity ?? id), manifestPath: `${path}/project.json`, formatVersion: 1 };
|
||||||
}
|
}
|
||||||
|
|||||||
+110
-87
@@ -1,3 +1,5 @@
|
|||||||
|
import { mountFileBrowser } from './file-browser.js';
|
||||||
|
import { workspaceElements } from './workspace-elements.js';
|
||||||
import { mountOverview } from './overview.js';
|
import { mountOverview } from './overview.js';
|
||||||
import { labels } from './labels.js';
|
import { labels } from './labels.js';
|
||||||
import { exportProjectToDialog, importProjectFromDialog } from './transfer.js';
|
import { exportProjectToDialog, importProjectFromDialog } from './transfer.js';
|
||||||
@@ -10,27 +12,12 @@ export function mountProjectWorkspace(target, {client,bridge,locale='en',extensi
|
|||||||
const shell = document.createElement('section'); shell.className='isa-project-ui';
|
const shell = document.createElement('section'); shell.className='isa-project-ui';
|
||||||
const style = document.createElement('style'); style.textContent=styles;
|
const style = document.createElement('style'); style.textContent=styles;
|
||||||
const content = document.createElement('div');
|
const content = document.createElement('div');
|
||||||
const preview = document.createElement('div'); preview.className='isa-project-preview';
|
shell.append(style, content);
|
||||||
shell.append(style,content,preview);target.append(shell);
|
target.append(shell);
|
||||||
let mounted=true,busy=false,error='',files=[],directory='',fileLoading=false,loadGeneration=0,shownSession=null;
|
const elements = workspaceElements(document);
|
||||||
let removeOverview;
|
const {make, icon, button} = elements;
|
||||||
|
let activeView, removeOverview;
|
||||||
const dialogs = new Set();
|
const dialogs = new Set();
|
||||||
const make = (tag,textContent,className) => {
|
|
||||||
const element=document.createElement(tag);
|
|
||||||
if (textContent != null) element.textContent=textContent;
|
|
||||||
if (className) element.className=className;
|
|
||||||
return element;
|
|
||||||
};
|
|
||||||
function button(label,action) {
|
|
||||||
const element=make('button',label,'isa-extension-button isa-extension-button--secondary');element.type='button';element.disabled=busy;
|
|
||||||
element.addEventListener('click',()=>perform(action));return element;
|
|
||||||
}
|
|
||||||
async function perform(action) {
|
|
||||||
if (busy || !mounted) return;
|
|
||||||
busy=true;error='';render();
|
|
||||||
try {await action();} catch(failure) {if (failure?.name!=='AbortError') error=String(failure.message ?? failure);}
|
|
||||||
finally {if(mounted){busy=false;render();}}
|
|
||||||
}
|
|
||||||
function confirmDiscard() {
|
function confirmDiscard() {
|
||||||
return new Promise(resolve=>{
|
return new Promise(resolve=>{
|
||||||
const dialog=make('dialog');
|
const dialog=make('dialog');
|
||||||
@@ -45,81 +32,117 @@ export function mountProjectWorkspace(target, {client,bridge,locale='en',extensi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const removeConfirmation = client.provideSwitchConfirmation(confirmDiscard);
|
const removeConfirmation = client.provideSwitchConfirmation(confirmDiscard);
|
||||||
async function loadFiles(session,relative='') {
|
function mountActive(session) {
|
||||||
const ticket=++loadGeneration;
|
const card = make('section', null, 'isa-project-active');
|
||||||
directory=relative;files=[];fileLoading=true;render();
|
const header = make('header', null, 'isa-project-header');
|
||||||
try {
|
const identity = make('div', null, 'isa-project-identity');
|
||||||
const result=await session.listFiles(relative,false);
|
const mark = make('span', null, 'isa-project-mark');
|
||||||
if (!mounted || ticket!==loadGeneration || client.active!==session) return;
|
mark.append(icon('folder'));
|
||||||
files=result.filter(file=>file.path !== (relative?session.path(relative):session.project.path));
|
const heading = make('div');
|
||||||
} catch(failure) {if(mounted&&ticket===loadGeneration&&failure?.name!=='AbortError') error=String(failure.message ?? failure);}
|
const title = make('h1', session.manifest.name, 'isa-project-title');
|
||||||
finally {if(mounted&&ticket===loadGeneration){fileLoading=false;render();}}
|
heading.append(make('p', extensionName || text.project, 'isa-project-context'), title);
|
||||||
}
|
identity.append(mark, heading);
|
||||||
async function showFile(session,file) {
|
const controls = make('div', null, 'isa-project-controls');
|
||||||
const relative=file.path.slice(session.project.path.length+1);
|
const notice = make('p', null, 'isa-extension-notice isa-extension-notice--error');
|
||||||
const mime=file.contentType ?? '';
|
notice.setAttribute('role', 'alert');
|
||||||
let element;
|
|
||||||
if (/^(audio|video|image)\//.test(mime)) {
|
const menu = make('details', null, 'isa-project-actions');
|
||||||
if(!bridge) throw new Error('Media bridge unavailable');
|
const trigger = make('summary', text.actions, 'isa-extension-button isa-extension-button--ghost');
|
||||||
const reply=await bridge.invoke('filesystem_get_download_link_file',{...session.scope,path:session.path(relative)});
|
trigger.prepend(icon('more'));
|
||||||
session.assertCurrent();
|
const choices = make('div', null, 'isa-project-choices');
|
||||||
const url=new URL(reply.downloadUrl);
|
function setBusy(busy) {
|
||||||
if(!['http:','https:'].includes(url.protocol)) throw new Error('Unsupported project media URL');
|
card.setAttribute('aria-busy', String(busy));
|
||||||
element=make(mime.startsWith('audio/')?'audio':mime.startsWith('video/')?'video':'img');
|
for (const choice of choices.children) choice.disabled = busy;
|
||||||
element.src=url.toString();
|
|
||||||
if(element.tagName==='IMG') element.alt=file.name; else element.controls=true;
|
|
||||||
} else {
|
|
||||||
const reply=await session.readFile(relative);
|
|
||||||
session.assertCurrent();
|
|
||||||
if(reply.status!=='found'||typeof reply.text!=='string') throw new Error('File preview unavailable');
|
|
||||||
element=make('pre',reply.text);
|
|
||||||
}
|
}
|
||||||
if(mounted&&client.active===session) {clearPreview();preview.append(element);}
|
function addAction(label, symbol, action) {
|
||||||
}
|
choices.append(button(label, async () => {
|
||||||
function clearPreview() {
|
menu.open = false;
|
||||||
for(const media of preview.querySelectorAll('audio,video')) {media.pause();media.removeAttribute('src');media.load();}
|
trigger.focus();
|
||||||
preview.replaceChildren();
|
setBusy(true);
|
||||||
}
|
notice.textContent = '';
|
||||||
function render() {
|
try {
|
||||||
if(!mounted)return;
|
await action();
|
||||||
const session=client.active;
|
} catch (error) {
|
||||||
if (!session) {
|
if (error?.name !== 'AbortError') notice.textContent = String(error.message ?? error);
|
||||||
if (!removeOverview) {
|
} finally {
|
||||||
content.replaceChildren();
|
setBusy(false);
|
||||||
removeOverview = mountOverview(content,{client,extensionName,text,locale,onOverview,
|
}
|
||||||
onImport:onImport ?? (bridge && (() => importProjectFromDialog(client,{bridge})))});
|
}, symbol));
|
||||||
|
}
|
||||||
|
if (bridge && client.supports('create')) {
|
||||||
|
addAction(text.import, 'import', onImport ?? (() => importProjectFromDialog(client, {bridge})));
|
||||||
|
}
|
||||||
|
if (bridge) {
|
||||||
|
addAction(text.export, 'export', () => onExport ? onExport(session) : exportProjectToDialog(session, {bridge, beforeExport}));
|
||||||
|
}
|
||||||
|
addAction(text.close, 'leave', () => client.leave());
|
||||||
|
menu.append(trigger, choices);
|
||||||
|
const dismissOutside = event => {
|
||||||
|
if (menu.open && !menu.contains(event.target)) menu.open = false;
|
||||||
|
};
|
||||||
|
document.addEventListener('pointerdown', dismissOutside);
|
||||||
|
document.addEventListener('focusin', dismissOutside);
|
||||||
|
menu.onkeydown = event => {
|
||||||
|
if (event.key === 'Escape' && menu.open) {
|
||||||
|
event.preventDefault();
|
||||||
|
menu.open = false;
|
||||||
|
trigger.focus();
|
||||||
}
|
}
|
||||||
return;
|
};
|
||||||
|
header.append(identity, controls);
|
||||||
|
card.append(header, notice);
|
||||||
|
let closeBrowser;
|
||||||
|
if (mode === 'workspace') {
|
||||||
|
const toggle = button(text.projectFiles, null, 'files', 'secondary');
|
||||||
|
const panel = make('div', null, 'isa-project-browser');
|
||||||
|
closeBrowser = mountFileBrowser(panel, toggle, {session, bridge, text, locale, elements});
|
||||||
|
controls.append(toggle);
|
||||||
|
card.append(panel);
|
||||||
}
|
}
|
||||||
removeOverview?.(); removeOverview = null;
|
controls.append(menu);
|
||||||
content.replaceChildren();shell.setAttribute('aria-busy',String(busy));
|
content.append(card);
|
||||||
const toolbar=make('div',null,'isa-project-toolbar');
|
|
||||||
if(session) toolbar.append(make('h2',session.manifest.name,'isa-extension-heading isa-extension-heading--section isa-project-title'));
|
return {
|
||||||
if(bridge && client.supports('create'))toolbar.append(button(text.import,onImport ?? (()=>importProjectFromDialog(client,{bridge}))));
|
session, notice, title,
|
||||||
if(bridge&&session)toolbar.append(button(text.export,()=>onExport ? onExport(session) : exportProjectToDialog(session,{bridge,beforeExport})));
|
destroy() {
|
||||||
if(session) toolbar.append(button(text.close,()=>client.leave()));
|
document.removeEventListener('pointerdown', dismissOutside);
|
||||||
content.append(toolbar);
|
document.removeEventListener('focusin', dismissOutside);
|
||||||
if(error){const notice=make('p',error,'isa-extension-notice isa-extension-notice--error');notice.setAttribute('role','alert');content.append(notice);}
|
closeBrowser?.();
|
||||||
if(session&&mode==='workspace') {
|
card.remove();
|
||||||
const navigation=make('div',null,'isa-project-toolbar');navigation.append(button(text.files,()=>loadFiles(session)));
|
|
||||||
if(directory)navigation.append(button(text.back,()=>loadFiles(session,directory.split('/').slice(0,-1).join('/'))));
|
|
||||||
content.append(navigation);
|
|
||||||
if(fileLoading){const status=make('p',text.loading);status.setAttribute('role','status');content.append(status);}
|
|
||||||
else if(files.length===0)content.append(make('p',text.empty));
|
|
||||||
const list=make('div',null,'isa-project-list');
|
|
||||||
for(const file of [...files].sort((a,b)=>Number(b.kind==='folder')-Number(a.kind==='folder')||a.name.localeCompare(b.name))) {
|
|
||||||
list.append(button(file.name,()=>file.kind==='folder'?loadFiles(session,file.path.slice(session.project.path.length+1)):showFile(session,file)));
|
|
||||||
}
|
}
|
||||||
content.append(list);
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function render({active}) {
|
||||||
|
if (activeView && activeView.session !== active) {
|
||||||
|
activeView.destroy();
|
||||||
|
activeView = null;
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
removeOverview?.();
|
||||||
|
removeOverview = null;
|
||||||
|
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,
|
||||||
|
onImport: onImport ?? (bridge && (() => importProjectFromDialog(client, {bridge})))});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const unsubscribe=client.subscribe(({active})=>{
|
|
||||||
if(active!==shownSession){shownSession=active;directory='';files=[];clearPreview();loadGeneration++;if(active&&mode==='workspace')void loadFiles(active);}
|
const unsubscribe = client.subscribe(render);
|
||||||
render();
|
client.recent().catch(error => {
|
||||||
|
if (activeView && error?.name !== 'AbortError') activeView.notice.textContent = String(error.message ?? error);
|
||||||
});
|
});
|
||||||
client.recent().catch(failure=>{if(mounted&&failure?.name!=='AbortError'){error=String(failure.message ?? failure);render();}});
|
|
||||||
return {
|
return {
|
||||||
destroy(){if(!mounted)return;mounted=false;removeOverview?.();loadGeneration++;unsubscribe();removeConfirmation();for(const dialog of dialogs)dialog.close('cancel');clearPreview();shell.remove();}
|
destroy() {
|
||||||
|
unsubscribe();
|
||||||
|
removeConfirmation();
|
||||||
|
removeOverview?.();
|
||||||
|
activeView?.destroy();
|
||||||
|
activeView = null;
|
||||||
|
for (const dialog of dialogs) dialog.close('cancel');
|
||||||
|
shell.remove();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import { PROJECT_MANIFEST } from './format.js';
|
||||||
|
import { manifestFromSnapshot } from './project-filesystem.js';
|
||||||
|
|
||||||
|
export function mountFileBrowser(panel, toggle, {session, bridge, text, locale, elements}) {
|
||||||
|
const {make, icon, button} = elements;
|
||||||
|
const nav = make('nav', null, 'isa-project-path');
|
||||||
|
nav.setAttribute('aria-label', text.fileLocation);
|
||||||
|
const body = make('div', null, 'isa-project-browser-body');
|
||||||
|
panel.append(nav, body);
|
||||||
|
panel.id = 'isa-project-files-' + crypto.randomUUID();
|
||||||
|
panel.hidden = true;
|
||||||
|
toggle.setAttribute('aria-controls', panel.id);
|
||||||
|
toggle.setAttribute('aria-expanded', 'false');
|
||||||
|
let generation = 0;
|
||||||
|
|
||||||
|
function displayName(path) {
|
||||||
|
if (!path) return text.projectFiles;
|
||||||
|
if (path === PROJECT_MANIFEST) return text.projectDetails;
|
||||||
|
if (path === 'extensions') return text.extensionData;
|
||||||
|
if (path === 'assets') return text.assets;
|
||||||
|
return path.split('/').at(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPath(path, focus) {
|
||||||
|
const segments = path ? path.split('/') : [];
|
||||||
|
nav.replaceChildren();
|
||||||
|
for (let index = 0; index <= segments.length; index++) {
|
||||||
|
const current = segments.slice(0, index).join('/');
|
||||||
|
if (index) nav.append(icon('chevron'));
|
||||||
|
if (index < segments.length) {
|
||||||
|
nav.append(button(displayName(current), () => open(current)));
|
||||||
|
} else {
|
||||||
|
const name = make('span', displayName(current));
|
||||||
|
name.setAttribute('aria-current', 'location');
|
||||||
|
name.tabIndex = -1;
|
||||||
|
nav.append(name);
|
||||||
|
if (focus) name.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearBody() {
|
||||||
|
for (const media of body.querySelectorAll('audio, video')) {
|
||||||
|
media.pause();
|
||||||
|
media.removeAttribute('src');
|
||||||
|
media.load();
|
||||||
|
}
|
||||||
|
body.replaceChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
function list(directory, entries) {
|
||||||
|
const parent = directory ? session.path(directory) : session.project.path;
|
||||||
|
const files = entries.filter(entry => entry.path !== parent)
|
||||||
|
.sort((a, b) => Number(b.kind === 'folder') - Number(a.kind === 'folder') || a.name.localeCompare(b.name, locale));
|
||||||
|
if (!files.length) return make('p', text.empty, 'isa-project-message');
|
||||||
|
const rows = make('ul', null, 'isa-project-file-list');
|
||||||
|
for (const file of files) {
|
||||||
|
const path = file.path.slice(session.project.path.length + 1);
|
||||||
|
const folder = file.kind === 'folder';
|
||||||
|
const row = button(null, () => open(path, folder ? null : file), folder ? 'folder' : 'file');
|
||||||
|
row.append(make('span', displayName(path)), icon('chevron'));
|
||||||
|
row.title = file.name;
|
||||||
|
const item = make('li');
|
||||||
|
item.append(row);
|
||||||
|
rows.append(item);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function manifestPreview(snapshot) {
|
||||||
|
let manifest;
|
||||||
|
try {
|
||||||
|
manifest = manifestFromSnapshot(snapshot);
|
||||||
|
} catch (error) {
|
||||||
|
if (typeof snapshot.text === 'string') return make('pre', snapshot.text);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
const format = new Intl.DateTimeFormat(locale, {dateStyle: 'medium', timeStyle: 'short'});
|
||||||
|
const result = make('div', null, 'isa-project-metadata');
|
||||||
|
const fields = make('dl');
|
||||||
|
for (const [label, value] of [
|
||||||
|
[text.name, manifest.name], [text.created, format.format(new Date(manifest.createdAt))],
|
||||||
|
[text.updated, format.format(new Date(manifest.updatedAt))], [text.projectId, manifest.id],
|
||||||
|
[text.formatVersion, manifest.formatVersion]
|
||||||
|
]) {
|
||||||
|
const field = make('div');
|
||||||
|
field.append(make('dt', label), make('dd', value));
|
||||||
|
fields.append(field);
|
||||||
|
}
|
||||||
|
const source = make('details');
|
||||||
|
source.append(make('summary', PROJECT_MANIFEST), make('pre', snapshot.text ?? JSON.stringify(manifest, null, 2)));
|
||||||
|
result.append(fields, source);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function preview(path, file, ticket) {
|
||||||
|
const mime = file.contentType ?? '';
|
||||||
|
if (/^(audio|video|image)\//.test(mime)) {
|
||||||
|
if (!bridge) throw new Error(text.previewUnavailable);
|
||||||
|
const reply = await bridge.invoke('filesystem_get_download_link_file', {...session.scope, path: session.path(path)});
|
||||||
|
session.assertCurrent();
|
||||||
|
if (ticket !== generation) return;
|
||||||
|
const url = new URL(reply.downloadUrl);
|
||||||
|
if (!['http:', 'https:'].includes(url.protocol)) throw new Error(text.previewUnavailable);
|
||||||
|
const media = make(mime.startsWith('image/') ? 'img' : mime.startsWith('audio/') ? 'audio' : 'video');
|
||||||
|
if (media.tagName === 'IMG') media.alt = file.name;
|
||||||
|
else media.controls = true;
|
||||||
|
media.src = url.toString();
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
const reply = await session.readFile(path);
|
||||||
|
session.assertCurrent();
|
||||||
|
if (ticket !== generation) return;
|
||||||
|
if (reply.status !== 'found') throw new Error(text.previewUnavailable);
|
||||||
|
if (path === PROJECT_MANIFEST) return manifestPreview(reply);
|
||||||
|
if (typeof reply.text !== 'string') throw new Error(text.previewUnavailable);
|
||||||
|
return make('pre', reply.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function open(path, file = null, focus = true) {
|
||||||
|
const ticket = ++generation;
|
||||||
|
clearBody();
|
||||||
|
showPath(path, focus);
|
||||||
|
body.setAttribute('aria-busy', 'true');
|
||||||
|
try {
|
||||||
|
if (file) {
|
||||||
|
const node = await preview(path, file, ticket);
|
||||||
|
if (ticket === generation) body.replaceChildren(node);
|
||||||
|
} else {
|
||||||
|
const entries = await session.listFiles(path, false);
|
||||||
|
if (ticket === generation) body.replaceChildren(list(path, entries));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (ticket !== generation || error?.name === 'AbortError') return;
|
||||||
|
const notice = make('p', String(error.message ?? error), 'isa-extension-notice isa-extension-notice--error');
|
||||||
|
notice.setAttribute('role', 'alert');
|
||||||
|
body.replaceChildren(notice, button(text.retry, () => open(path, file)));
|
||||||
|
} finally {
|
||||||
|
if (ticket === generation) body.removeAttribute('aria-busy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
generation++;
|
||||||
|
clearBody();
|
||||||
|
body.removeAttribute('aria-busy');
|
||||||
|
panel.hidden = true;
|
||||||
|
toggle.setAttribute('aria-expanded', 'false');
|
||||||
|
}
|
||||||
|
toggle.onclick = () => {
|
||||||
|
if (!panel.hidden) return close();
|
||||||
|
panel.hidden = false;
|
||||||
|
toggle.setAttribute('aria-expanded', 'true');
|
||||||
|
void open('', null, false);
|
||||||
|
};
|
||||||
|
return close;
|
||||||
|
}
|
||||||
Vendored
+1
-1
@@ -17,7 +17,7 @@ export function extensionDataPath(extensionId: string, relativePath: string): st
|
|||||||
|
|
||||||
export interface ProjectReference {
|
export interface ProjectReference {
|
||||||
id: string; folderId: string; path: string; name: string;
|
id: string; folderId: string; path: string; name: string;
|
||||||
archived?: boolean; updatedAt?: string; canWrite?: boolean; hasInstance?: boolean;
|
instanceCreatorId?: string; instanceCreatedAt?: string; archived?: boolean; updatedAt?: string; canWrite?: boolean; hasInstance?: boolean;
|
||||||
projectIdentity: string; manifestPath: string; formatVersion: 1;
|
projectIdentity: string; manifestPath: string; formatVersion: 1;
|
||||||
}
|
}
|
||||||
export interface ProjectScope { workspaceId: string; groupId: string; }
|
export interface ProjectScope { workspaceId: string; groupId: string; }
|
||||||
|
|||||||
+6
-2
@@ -1,4 +1,8 @@
|
|||||||
export const labels = {
|
export const labels = {
|
||||||
en: {createInstance:'Create instance',creating:'Creating project…',newProject:'New project',createTitle:'Create new project',saveProject:'Save project',projects:'Projects',search:'Search projects',updated:'Last modified',sort:'Sort projects',activity:'Recent activity',noActivity:'No projects opened yet.',noProjects:'No projects yet.',noMatches:'No matching projects.',refresh:'Refresh',pickFolder:'Add project folder',updateHost:'Update ISA Warden to use shared group projects.',create:'Create project',name:'Project name',recent:'Recent projects',files:'Files',back:'Back',close:'Close project',empty:'No files',loading:'Loading…',cancel:'Cancel',discard:'Discard changes',dirty:'Discard unsaved project changes?',retry:'Retry',export:'Export project',import:'Import project'},
|
en: {noInstance:'No instance yet',owner:'Owner (creator)',creationDate:'Creation date',createInstance:'Create instance',creating:'Creating project…',newProject:'New project',createTitle:'Create new project',saveProject:'Save project',projects:'Projects',search:'Search projects',updated:'Last modified',sort:'Sort projects',activity:'Recent activity',noActivity:'No projects opened yet.',noProjects:'No projects yet.',noMatches:'No matching projects.',refresh:'Refresh',pickFolder:'Add project folder',updateHost:'Update ISA Warden to use shared group projects.',create:'Create project',name:'Project name',recent:'Recent projects',files:'Files',back:'Back',close:'Close project',empty:'No files',loading:'Loading…',cancel:'Cancel',discard:'Discard changes',dirty:'Discard unsaved project changes?',retry:'Retry',export:'Export project',import:'Import project',
|
||||||
nl: {createInstance:'Instance aanmaken',creating:'Project wordt aangemaakt…',newProject:'Nieuw project',createTitle:'Nieuw project aanmaken',saveProject:'Bewaar project',projects:'Projecten',search:'Zoek op projectnaam',updated:'Laatst gewijzigd',sort:'Projecten sorteren',activity:'Recente activiteit',noActivity:'Nog geen projecten geopend.',noProjects:'Nog geen projecten.',noMatches:'Geen overeenkomende projecten.',refresh:'Vernieuwen',pickFolder:'Projectmap toevoegen',updateHost:'Werk ISA Warden bij om gedeelde groepsprojecten te gebruiken.',create:'Project maken',name:'Projectnaam',recent:'Recente projecten',files:'Bestanden',back:'Terug',close:'Project sluiten',empty:'Geen bestanden',loading:'Laden…',cancel:'Annuleren',discard:'Wijzigingen weggooien',dirty:'Niet-opgeslagen projectwijzigingen weggooien?',retry:'Opnieuw proberen',export:'Project exporteren',import:'Project importeren'}
|
project:'Project',actions:'Project actions',projectFiles:'Project files',fileLocation:'File location',projectDetails:'Project details',extensionData:'Extension data',assets:'Assets',created:'Created',projectId:'Project ID',formatVersion:'Format version',previewUnavailable:'File preview unavailable.'
|
||||||
|
},
|
||||||
|
nl: {noInstance:'Nog geen instance',owner:'Eigenaar (aanmaker)',creationDate:'Aanmaakdatum',createInstance:'Instance aanmaken',creating:'Project wordt aangemaakt…',newProject:'Nieuw project',createTitle:'Nieuw project aanmaken',saveProject:'Bewaar project',projects:'Projecten',search:'Zoek op projectnaam',updated:'Laatst gewijzigd',sort:'Projecten sorteren',activity:'Recente activiteit',noActivity:'Nog geen projecten geopend.',noProjects:'Nog geen projecten.',noMatches:'Geen overeenkomende projecten.',refresh:'Vernieuwen',pickFolder:'Projectmap toevoegen',updateHost:'Werk ISA Warden bij om gedeelde groepsprojecten te gebruiken.',create:'Project maken',name:'Projectnaam',recent:'Recente projecten',files:'Bestanden',back:'Terug',close:'Project sluiten',empty:'Geen bestanden',loading:'Laden…',cancel:'Annuleren',discard:'Wijzigingen weggooien',dirty:'Niet-opgeslagen projectwijzigingen weggooien?',retry:'Opnieuw proberen',export:'Project exporteren',import:'Project importeren',
|
||||||
|
project:'Project',actions:'Projectacties',projectFiles:'Projectbestanden',fileLocation:'Bestandslocatie',projectDetails:'Projectgegevens',extensionData:'Extensiegegevens',assets:'Bronbestanden',created:'Aangemaakt',projectId:'Project-ID',formatVersion:'Formaatversie',previewUnavailable:'Bestandsvoorbeeld niet beschikbaar.'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+19
-12
@@ -57,9 +57,11 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
|||||||
const alert = element('p');
|
const alert = element('p');
|
||||||
alert.setAttribute('role','alert');
|
alert.setAttribute('role','alert');
|
||||||
const list = element('div', '', 'isa-group-rows');
|
const list = element('div', '', 'isa-group-rows');
|
||||||
|
const columns = element('div', '', 'isa-project-columns');
|
||||||
|
columns.append(element('span', text.name), element('span', text.owner), element('span', text.creationDate));
|
||||||
const status = element('p');
|
const status = element('p');
|
||||||
status.setAttribute('role','status');
|
status.setAttribute('role','status');
|
||||||
panel.append(heading,controls,alert,status,list);
|
panel.append(heading,controls,alert,status,columns,list);
|
||||||
grid.append(activity,panel);
|
grid.append(activity,panel);
|
||||||
const dialog = element('dialog', '', 'isa-project-create-dialog');
|
const dialog = element('dialog', '', 'isa-project-create-dialog');
|
||||||
const title = element('h2', text.createTitle);
|
const title = element('h2', text.createTitle);
|
||||||
@@ -86,7 +88,7 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
|||||||
root.append(grid,dialog);
|
root.append(grid,dialog);
|
||||||
target.append(root);
|
target.append(root);
|
||||||
|
|
||||||
let projects = [], recents = [], loading = true, failed = false, busy = false, alive = true, generation = 0;
|
let projects = [], recents = [], loading = true, hasInventory = false, busy = false, alive = true, generation = 0;
|
||||||
const date = new Intl.DateTimeFormat(locale,{dateStyle:'medium'});
|
const date = new Intl.DateTimeFormat(locale,{dateStyle:'medium'});
|
||||||
// The host focuses an extension iframe on pointer-down. Preserve matching
|
// The host focuses an extension iframe on pointer-down. Preserve matching
|
||||||
// buttons through that refresh so the subsequent click reaches the same row.
|
// buttons through that refresh so the subsequent click reaches the same row.
|
||||||
@@ -98,9 +100,7 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
|||||||
row = button();
|
row = button();
|
||||||
row.dataset.projectId = project.id;
|
row.dataset.projectId = project.id;
|
||||||
if (detailed) {
|
if (detailed) {
|
||||||
const info = element('span');
|
row.append(element('strong'), element('small'), element('time'));
|
||||||
info.append(element('strong'), element('small'));
|
|
||||||
row.append(info, element('time'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
existing.delete(project.id);
|
existing.delete(project.id);
|
||||||
@@ -109,8 +109,9 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
|||||||
const firstUse = project.hasInstance === false && project.canWrite && !project.archived;
|
const firstUse = project.hasInstance === false && project.canWrite && !project.archived;
|
||||||
if (detailed) {
|
if (detailed) {
|
||||||
row.querySelector('strong').textContent = project.name;
|
row.querySelector('strong').textContent = project.name;
|
||||||
row.querySelector('small').textContent = firstUse ? text.createInstance : project.path;
|
row.querySelector('small').textContent = project.hasInstance === false ? text.noInstance : project.instanceCreatorId || '—';
|
||||||
row.querySelector('time').textContent = Number.isFinite(Date.parse(project.updatedAt)) ? date.format(new Date(project.updatedAt)) : '';
|
row.title = firstUse ? text.createInstance : '';
|
||||||
|
row.querySelector('time').textContent = Number.isFinite(Date.parse(project.instanceCreatedAt)) ? date.format(new Date(project.instanceCreatedAt)) : '—';
|
||||||
} else row.textContent = firstUse ? `${project.name} · ${text.createInstance}` : project.name;
|
} else row.textContent = firstUse ? `${project.name} · ${text.createInstance}` : project.name;
|
||||||
if (container.children[index] !== row) container.insertBefore(row, container.children[index] ?? null);
|
if (container.children[index] !== row) container.insertBefore(row, container.children[index] ?? null);
|
||||||
});
|
});
|
||||||
@@ -120,22 +121,28 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
|||||||
const needle = search.value.trim().toLocaleLowerCase(locale);
|
const needle = search.value.trim().toLocaleLowerCase(locale);
|
||||||
const visible = projects.filter(p => p.name.toLocaleLowerCase(locale).includes(needle));
|
const visible = projects.filter(p => p.name.toLocaleLowerCase(locale).includes(needle));
|
||||||
visible.sort((a,b) => (sort.value === 'updated' && (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0)) || a.name.localeCompare(b.name,locale));
|
visible.sort((a,b) => (sort.value === 'updated' && (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0)) || a.name.localeCompare(b.name,locale));
|
||||||
|
list.setAttribute('aria-busy', String(loading));
|
||||||
|
columns.hidden = !visible.length;
|
||||||
updateRows(list, visible, true);
|
updateRows(list, visible, true);
|
||||||
status.textContent = loading ? text.loading : visible.length || failed ? '' : needle ? text.noMatches : text.noProjects;
|
status.textContent = hasInventory && !visible.length ? (needle ? text.noMatches : text.noProjects) : '';
|
||||||
updateRows(recent, recents.map(item => projects.find(project => project.id === item.id)).filter(Boolean), false);
|
updateRows(recent, recents.map(item => projects.find(project => project.id === item.id)).filter(Boolean), false);
|
||||||
if (!recent.childElementCount && !loading && !failed) recent.append(element('p',text.noActivity));
|
if (!recent.childElementCount && hasInventory) recent.append(element('p',text.noActivity));
|
||||||
pickFolder.disabled = busy; create.disabled = busy; importButton.disabled = busy; refreshButton.disabled = busy || loading;
|
pickFolder.disabled = busy; create.disabled = busy; importButton.disabled = busy; refreshButton.disabled = busy || loading;
|
||||||
}
|
}
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
const ticket = ++generation;
|
const ticket = ++generation;
|
||||||
loading = true; failed = false; alert.textContent = ''; draw();
|
loading = true; alert.textContent = ''; draw();
|
||||||
try {
|
try {
|
||||||
const inventory = await client.list();
|
const inventory = await client.list();
|
||||||
if (alive && ticket === generation) projects = inventory.filter(p => !p.archived);
|
if (alive && ticket === generation) {
|
||||||
|
projects = inventory.filter(p => !p.archived);
|
||||||
|
hasInventory = true;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (alive && ticket === generation) {
|
if (alive && ticket === generation) {
|
||||||
if (client.sharedProjectsFolder) projects = [];
|
if (client.sharedProjectsFolder) projects = [];
|
||||||
failed = true; alert.textContent = error.code === 'SHARED_GROUP_PROJECTS_UNAVAILABLE' ? text.updateHost : String(error.message ?? error);
|
hasInventory = false;
|
||||||
|
alert.textContent = error.code === 'SHARED_GROUP_PROJECTS_UNAVAILABLE' ? text.updateHost : String(error.message ?? error);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (alive && ticket === generation) { loading = false; draw(); }
|
if (alive && ticket === generation) { loading = false; draw(); }
|
||||||
|
|||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
import type {ProjectBridge, ProjectScope} from './index.js';
|
||||||
|
export const priceListKey: 'observations/v1';
|
||||||
|
export type PriceObservation = {supplierId?:string; supplier:string; description:string; specItem:string; unitPrice:number; unit:string; currency:string; receivedAt:string; validUntil?:string};
|
||||||
|
export type PriceItem = {id:string;value:PriceObservation};
|
||||||
|
export interface PriceQuery {
|
||||||
|
search?:string; equals?:Record<string,string>; from?:string; to?:string; facet?:string; prefix?:string;
|
||||||
|
offset?:number; version?:number; limit?:number; signal?:AbortSignal;
|
||||||
|
}
|
||||||
|
export function openPriceAsset(options:{bridge:ProjectBridge;scope:ProjectScope;access?:'read'|'read_write'}):Promise<{
|
||||||
|
folder: Readonly<{asset:'suppliers'|'prices';workspaceId:string;groupId:string;folderId:string;path:string;canWrite:boolean}>;
|
||||||
|
query(options?:PriceQuery):Promise<{items?:PriceItem[];choices?:string[];version:number;nextOffset:number|null}>;
|
||||||
|
existingIds(ids:string[], options?:{signal?:AbortSignal}):Promise<Set<string>>;
|
||||||
|
sourceVersion(id:string, options?:{signal?:AbortSignal}):Promise<number|null>;
|
||||||
|
markSourceVersion(id:string, version:number, options?:{signal?:AbortSignal}):Promise<void>;
|
||||||
|
importRows(records:PriceItem[], options?:{signal?:AbortSignal}):Promise<void>;
|
||||||
|
}>;
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
import {createSharedFolderReader, openWorkspaceAsset} from './shared-folder.js';
|
||||||
|
|
||||||
|
export const priceListKey = 'observations/v1';
|
||||||
|
const fields = ['description', 'specItem', 'supplier', 'supplierId', 'unitPrice', 'currency', 'unit', 'receivedAt', 'validUntil'];
|
||||||
|
const sort = {path: ['receivedAt'], kind: 'text', direction: 'desc'};
|
||||||
|
|
||||||
|
function publicObservation({id, value}) {
|
||||||
|
if (typeof id !== 'string' || !id.trim() || id.length > 256 || !value || !Number.isFinite(value.unitPrice)) throw new TypeError('Invalid price observation');
|
||||||
|
for (const [field, cell] of Object.entries(value)) {
|
||||||
|
if (!fields.includes(field) || (field !== 'unitPrice' && typeof cell !== 'string')) throw new TypeError('Invalid public price field: ' + field);
|
||||||
|
}
|
||||||
|
return {id, value};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readReply(bridge, path, value, signal) {
|
||||||
|
if (!value?.transferId) return value;
|
||||||
|
if (!Number.isSafeInteger(value.byteSize) || value.byteSize <= 0 || value.byteSize > 64 * 1024 * 1024) throw new Error('Invalid price query response size');
|
||||||
|
const bytes = new Uint8Array(value.byteSize);
|
||||||
|
for (let offset = 0; offset < bytes.length;) {
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
const chunk = await bridge.invoke('kv_store_read_chunk', {path, transferId: value.transferId, offset});
|
||||||
|
const part = Uint8Array.from(atob(chunk.bytesBase64), c => c.charCodeAt(0));
|
||||||
|
if (chunk.offset !== offset || !part.length || part.length > bytes.length - offset) throw new Error('Incomplete price query response');
|
||||||
|
bytes.set(part, offset);
|
||||||
|
offset += part.length;
|
||||||
|
}
|
||||||
|
return JSON.parse(new TextDecoder('utf-8', {fatal:true}).decode(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function openPriceAsset({bridge, scope, access}) {
|
||||||
|
const folder = await openWorkspaceAsset({bridge, scope, asset: 'prices', access});
|
||||||
|
const path = folder.path + '/prices.kv';
|
||||||
|
const scoped = {invoke:(command,args) => bridge.invoke(command, {...args,workspaceId:folder.workspaceId,groupId:folder.groupId})};
|
||||||
|
const reader = createSharedFolderReader({bridge, scope, folder});
|
||||||
|
const clientId = crypto.randomUUID();
|
||||||
|
let sequence = 0;
|
||||||
|
let identity;
|
||||||
|
|
||||||
|
async function open(create) {
|
||||||
|
if (identity) return identity;
|
||||||
|
if (!create && !(await reader.listFiles()).some(f => f.path === path && f.kind === 'file')) return null;
|
||||||
|
const opened = await scoped.invoke('kv_store_open', {path, syncable:false});
|
||||||
|
if (!opened?.storeId || !opened.incarnation) throw new Error('Price store identity unavailable');
|
||||||
|
if (identity && (opened.storeId !== identity.storeId || opened.incarnation !== identity.incarnation)) throw new Error('Price store changed');
|
||||||
|
identity = {storeId: opened.storeId, incarnation: opened.incarnation};
|
||||||
|
return identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request(args, signal) {
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
const reply = await readReply(scoped, path, await scoped.invoke('kv_store_query_list', {path, ...identity, key:priceListKey, ...args}), signal);
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
if (!identity || reply?.storeId !== identity.storeId || reply.incarnation !== identity.incarnation || !Number.isSafeInteger(reply.revision)) throw new Error('Price store changed');
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function lookup(key, ids, signal) {
|
||||||
|
const reply = await request({key, ids}, signal);
|
||||||
|
if (!Array.isArray(reply.page?.items)) throw new Error('Unable to verify saved prices');
|
||||||
|
return {reply, saved:new Map(reply.page.items.map(row => [row.id, row.value]))};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function update(key, ids, changes, signal) {
|
||||||
|
const store = await open(true);
|
||||||
|
for (let attempt = 0;; attempt++) {
|
||||||
|
const {reply, saved} = await lookup(key, ids, signal);
|
||||||
|
if (reply.supportsExpectedRevision !== true) throw new Error('Host does not support conditional price updates');
|
||||||
|
const operations = changes(saved);
|
||||||
|
if (!operations.length) return;
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
try {
|
||||||
|
const ack = await scoped.invoke('kv_store_apply', {path, ...store, expectedRevision:reply.revision, clientId, sequence:++sequence, operations});
|
||||||
|
if (ack?.storeId !== store.storeId || ack.incarnation !== store.incarnation || !Number.isSafeInteger(ack.acceptedRevision) || ack.pending === true) throw new Error('Workspace price publication unconfirmed');
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
if (attempt >= 5 || !/revision_conflict/.test(error?.message ?? String(error))) throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
folder,
|
||||||
|
async query({search = '', equals = {}, from, to, facet, prefix, offset = 0, version, limit = 30, signal} = {}) {
|
||||||
|
if (!(await open(false))) {
|
||||||
|
if (offset > 0) throw new Error('cursor_stale');
|
||||||
|
return {items:[],choices:[],version:0,nextOffset:null};
|
||||||
|
}
|
||||||
|
const query = {fields,search,equals,offset,version,facet,prefix,...((from || to) && {range:{field:'receivedAt',from:from || undefined,to:to || undefined}})};
|
||||||
|
for (let attempt = 0;; attempt++) {
|
||||||
|
const {page} = await request({query,sort,limit}, signal);
|
||||||
|
if (page?.status !== 'indexing') {
|
||||||
|
if (!Number.isSafeInteger(page?.version) || !Array.isArray(facet ? page.choices : page.items)
|
||||||
|
|| (page.nextOffset != null && (!Number.isSafeInteger(page.nextOffset) || page.nextOffset <= offset))) throw new Error('Invalid price page');
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
if (attempt === 120) throw new Error('The price index is still being prepared');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, Math.min(1000, 100 + attempt * 100)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Historical observations are immutable. Replays may add a previously unknown supplier link.
|
||||||
|
async importRows(records, {signal} = {}) {
|
||||||
|
if (!folder.canWrite) throw new Error('Price asset is read-only');
|
||||||
|
if (!records.length) return;
|
||||||
|
for (let i = 0; i < records.length; i += 50) {
|
||||||
|
const batch = records.slice(i, i + 50).map(publicObservation);
|
||||||
|
await update(priceListKey, batch.map(row => row.id), saved => {
|
||||||
|
const operations = [];
|
||||||
|
for (const {id, value} of batch) {
|
||||||
|
const previous = saved.get(id);
|
||||||
|
if (previous && (previous.supplierId || !value.supplierId)) continue;
|
||||||
|
const observation = previous ? {...previous, supplierId:value.supplierId} : value;
|
||||||
|
operations.push({kind:'list_put',key:priceListKey,id,value:observation});
|
||||||
|
}
|
||||||
|
return operations;
|
||||||
|
}, signal);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async existingIds(ids, {signal} = {}) {
|
||||||
|
if (!(await open(false))) return new Set();
|
||||||
|
return new Set((await lookup(priceListKey, ids, signal)).saved.keys());
|
||||||
|
},
|
||||||
|
// The source fingerprint includes its incarnation. Record only a fully acknowledged
|
||||||
|
// scan, so interruption and concurrent imports always converge on the same IDs.
|
||||||
|
async sourceVersion(id, {signal} = {}) {
|
||||||
|
if (!(await open(false))) return null;
|
||||||
|
return (await lookup('imports/v1', [id], signal)).saved.get(id)?.version ?? null;
|
||||||
|
},
|
||||||
|
async markSourceVersion(id, version, {signal} = {}) {
|
||||||
|
if (!folder.canWrite) throw new Error('Price asset is read-only');
|
||||||
|
if (!Number.isSafeInteger(version) || version < 1) throw new Error('Invalid source version');
|
||||||
|
const key = 'imports/v1';
|
||||||
|
await update(key, [id], saved => (saved.get(id)?.version ?? 0) >= version
|
||||||
|
? [] : [{kind:'list_put',key,id,value:{version}}], signal);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ function folderReference(value) {
|
|||||||
throw new ProjectUnavailableError('Invalid project folder reference');
|
throw new ProjectUnavailableError('Invalid project folder reference');
|
||||||
}
|
}
|
||||||
validateArchivePath(path.slice(1));
|
validateArchivePath(path.slice(1));
|
||||||
return { path, fileId, canWrite: access ? access === 'read_write' : canWrite === true, archivedAt,
|
return { path, fileId, instanceCreatorId: value.instanceCreatorId, instanceCreatedAt: value.instanceCreatedAt, canWrite: access ? access === 'read_write' : canWrite === true, archivedAt,
|
||||||
...(typeof hasInstance === 'boolean' && { hasInstance }) };
|
...(typeof hasInstance === 'boolean' && { hasInstance }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ export function createProjectFilesystem({ invoke, invokePrivateStorage, read, ca
|
|||||||
function projectFrom(folder, manifest) {
|
function projectFrom(folder, manifest) {
|
||||||
return {
|
return {
|
||||||
id: folder.fileId, folderId: folder.fileId, path: folder.path,
|
id: folder.fileId, folderId: folder.fileId, path: folder.path,
|
||||||
name: manifest.name, projectIdentity: manifest.id,
|
name: manifest.name, instanceCreatorId: folder.instanceCreatorId, instanceCreatedAt: folder.instanceCreatedAt, projectIdentity: manifest.id,
|
||||||
canWrite: canWrite && folder.canWrite, updatedAt: manifest.updatedAt, hasInstance: folder.hasInstance,
|
canWrite: canWrite && folder.canWrite, updatedAt: manifest.updatedAt, hasInstance: folder.hasInstance,
|
||||||
archived: manifest.archived ?? Boolean(folder.archivedAt)
|
archived: manifest.archived ?? Boolean(folder.archivedAt)
|
||||||
};
|
};
|
||||||
@@ -168,7 +168,8 @@ export function createProjectFilesystem({ invoke, invokePrivateStorage, read, ca
|
|||||||
throw new ProjectUnavailableError('Project folder identity changed');
|
throw new ProjectUnavailableError('Project folder identity changed');
|
||||||
}
|
}
|
||||||
return { ...project, id: current.fileId, folderId: current.fileId,
|
return { ...project, id: current.fileId, folderId: current.fileId,
|
||||||
canWrite: current.canWrite, archived: Boolean(current.archivedAt), hasInstance: current.hasInstance };
|
canWrite: current.canWrite, archived: Boolean(current.archivedAt), hasInstance: current.hasInstance,
|
||||||
|
instanceCreatorId: current.instanceCreatorId, instanceCreatedAt: current.instanceCreatedAt };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function list(includeArchived) {
|
async function list(includeArchived) {
|
||||||
|
|||||||
Vendored
+7
@@ -1,4 +1,11 @@
|
|||||||
import type { ProjectBridge, ProjectScope, ProjectRead } from './index.js';
|
import type { ProjectBridge, ProjectScope, ProjectRead } from './index.js';
|
||||||
|
export type WorkspaceAsset = 'suppliers' | 'prices';
|
||||||
|
export function openWorkspaceAsset(options: {
|
||||||
|
bridge: ProjectBridge; scope: ProjectScope; asset: WorkspaceAsset; access?: 'read' | 'read_write';
|
||||||
|
assertCurrent?: () => void;
|
||||||
|
}): Promise<Readonly<{
|
||||||
|
asset: WorkspaceAsset; workspaceId: string; groupId: string; folderId: string; path: string; canWrite: boolean;
|
||||||
|
}>>;
|
||||||
export function createSharedFolderReader(options: {
|
export function createSharedFolderReader(options: {
|
||||||
bridge: ProjectBridge;
|
bridge: ProjectBridge;
|
||||||
scope: ProjectScope;
|
scope: ProjectScope;
|
||||||
|
|||||||
@@ -2,6 +2,27 @@ import { validateArchivePath } from './format.js';
|
|||||||
import { readAuthoritativeFile } from './shared-read.js';
|
import { readAuthoritativeFile } from './shared-read.js';
|
||||||
import { readKvSnapshot } from './kv-snapshot.js';
|
import { readKvSnapshot } from './kv-snapshot.js';
|
||||||
|
|
||||||
|
/** 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))) {
|
||||||
|
throw new TypeError('Invalid workspace asset or access mode');
|
||||||
|
}
|
||||||
|
const {workspaceId, groupId} = scope;
|
||||||
|
assertCurrent();
|
||||||
|
const folder = await bridge.invoke('filesystem_open_workspace_asset', {asset, ...(access && {access})});
|
||||||
|
assertCurrent();
|
||||||
|
if (folder?.asset !== asset || folder.workspaceId !== workspaceId || folder.groupId !== groupId ||
|
||||||
|
typeof folder.folderId !== 'string' || !folder.folderId || folder.path !== '/shared/' + asset ||
|
||||||
|
typeof folder.canWrite !== 'boolean' || (access === 'read_write' && !folder.canWrite) ||
|
||||||
|
(access === 'read' && folder.canWrite)) {
|
||||||
|
throw new Error('Invalid workspace asset grant for this launch');
|
||||||
|
}
|
||||||
|
return Object.freeze({asset, workspaceId, groupId, path: folder.path, folderId: folder.folderId, canWrite: folder.canWrite});
|
||||||
|
}
|
||||||
|
|
||||||
/** Reads through the calling extension's own host grant. The folder can also
|
/** 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. */
|
* be the root of an open project session. No source is opened for writing. */
|
||||||
export function createSharedFolderReader({bridge,scope,folder,assertCurrent = () => {}}) {
|
export function createSharedFolderReader({bridge,scope,folder,assertCurrent = () => {}}) {
|
||||||
|
|||||||
+99
-7
@@ -1,8 +1,6 @@
|
|||||||
export const styles = `
|
export const styles = `
|
||||||
.isa-project-ui {color:var(--isa-extension-panel-text,CanvasText);font-family:var(--isa-extension-font-family,system-ui);display:flex;flex-direction:column;gap:var(--isa-extension-space-3,.75rem)}
|
.isa-project-ui {color:var(--isa-extension-panel-text,CanvasText);font-family:var(--isa-extension-font-family,system-ui);display:flex;flex-direction:column;gap:var(--isa-extension-space-3,.75rem)}
|
||||||
.isa-project-ui .isa-project-toolbar,.isa-project-ui form {display:flex;align-items:center;gap:var(--isa-extension-space-2,.5rem);flex-wrap:wrap}
|
.isa-project-ui .isa-project-toolbar,.isa-project-ui form {display:flex;align-items:center;gap:var(--isa-extension-space-2,.5rem);flex-wrap:wrap}
|
||||||
.isa-project-ui .isa-project-title {margin:0 auto 0 0;font-size:var(--isa-extension-font-size-lg,1.125rem);overflow-wrap:anywhere}
|
|
||||||
.isa-project-ui .isa-project-list {display:flex;flex-direction:column;gap:var(--isa-extension-space-1,.25rem);margin-block:var(--isa-extension-space-2,.5rem)}
|
|
||||||
:where(.isa-project-ui button),.isa-project-ui input {font:inherit;min-height:var(--isa-extension-control-height,2.25rem);box-sizing:border-box;border:1px solid var(--isa-extension-border,ButtonBorder);border-radius:var(--isa-extension-radius-control,.75rem);padding:.375rem .75rem;color:inherit;background:var(--isa-extension-control-bg,Canvas)}
|
:where(.isa-project-ui button),.isa-project-ui input {font:inherit;min-height:var(--isa-extension-control-height,2.25rem);box-sizing:border-box;border:1px solid var(--isa-extension-border,ButtonBorder);border-radius:var(--isa-extension-radius-control,.75rem);padding:.375rem .75rem;color:inherit;background:var(--isa-extension-control-bg,Canvas)}
|
||||||
.isa-project-ui input {flex:1;min-width:8rem}
|
.isa-project-ui input {flex:1;min-width:8rem}
|
||||||
:where(.isa-project-ui button) {cursor:pointer;text-align:start}
|
:where(.isa-project-ui button) {cursor:pointer;text-align:start}
|
||||||
@@ -10,12 +8,102 @@ export const styles = `
|
|||||||
:where(.isa-project-ui button:focus-visible),.isa-project-ui input:focus-visible {outline:2px solid var(--isa-extension-focus-outline,Highlight);outline-offset:2px}
|
:where(.isa-project-ui button:focus-visible),.isa-project-ui input:focus-visible {outline:2px solid var(--isa-extension-focus-outline,Highlight);outline-offset:2px}
|
||||||
:where(.isa-project-ui button:disabled) {opacity:.55;cursor:default}
|
:where(.isa-project-ui button:disabled) {opacity:.55;cursor:default}
|
||||||
:where(.isa-project-ui [role=alert]) {color:var(--isa-extension-danger,CanvasText);overflow-wrap:anywhere}
|
:where(.isa-project-ui [role=alert]) {color:var(--isa-extension-danger,CanvasText);overflow-wrap:anywhere}
|
||||||
.isa-project-ui .isa-project-heading {font-size:1rem;font-weight:600;margin:.75rem 0 .375rem}
|
|
||||||
.isa-project-ui .isa-project-preview audio,.isa-project-ui .isa-project-preview video,.isa-project-ui .isa-project-preview img {display:block;max-width:100%}
|
|
||||||
.isa-project-ui .isa-project-preview pre {white-space:pre-wrap;overflow-wrap:anywhere}
|
|
||||||
.isa-project-ui dialog {color:inherit;background:var(--isa-extension-panel-bg,Canvas);border:1px solid var(--isa-extension-border,ButtonBorder);border-radius:var(--isa-extension-radius-panel,1rem);max-width:28rem;padding:var(--isa-extension-space-4,1rem);box-shadow:var(--isa-extension-modal-shadow,none)}
|
.isa-project-ui dialog {color:inherit;background:var(--isa-extension-panel-bg,Canvas);border:1px solid var(--isa-extension-border,ButtonBorder);border-radius:var(--isa-extension-radius-panel,1rem);max-width:28rem;padding:var(--isa-extension-space-4,1rem);box-shadow:var(--isa-extension-modal-shadow,none)}
|
||||||
.isa-project-ui dialog::backdrop {background:var(--isa-extension-modal-backdrop,rgb(0 0 0/.4))}
|
.isa-project-ui dialog::backdrop {background:var(--isa-extension-modal-backdrop,rgb(0 0 0/.4))}
|
||||||
|
|
||||||
|
.isa-project-active {
|
||||||
|
margin:var(--isa-extension-shell-gutter,1rem) var(--isa-extension-shell-gutter,1rem) 0;
|
||||||
|
background:var(--isa-extension-panel-bg,Canvas);
|
||||||
|
border:1px solid var(--isa-extension-border-subtle,ButtonBorder);
|
||||||
|
border-radius:var(--isa-extension-radius-panel,1rem);
|
||||||
|
}
|
||||||
|
.isa-project-header {
|
||||||
|
display:flex;
|
||||||
|
align-items:center;
|
||||||
|
justify-content:space-between;
|
||||||
|
flex-wrap:wrap;
|
||||||
|
gap:.75rem 1.5rem;
|
||||||
|
padding:1rem 1.25rem;
|
||||||
|
}
|
||||||
|
.isa-project-identity {display:flex;align-items:center;gap:.875rem;flex:1 1 24rem;min-width:0}
|
||||||
|
.isa-project-identity > div {min-width:0}
|
||||||
|
.isa-project-identity .isa-project-context {
|
||||||
|
margin:0 0 .18rem;
|
||||||
|
color:var(--isa-extension-panel-muted,CanvasText);
|
||||||
|
font-size:var(--isa-extension-font-size-xs,.8125rem);
|
||||||
|
font-weight:600;
|
||||||
|
line-height:1.35;
|
||||||
|
}
|
||||||
|
.isa-project-identity .isa-project-title {
|
||||||
|
margin:0;
|
||||||
|
color:var(--isa-extension-panel-heading,CanvasText);
|
||||||
|
font-size:var(--isa-extension-font-size-xl,1.25rem);
|
||||||
|
font-weight:650;
|
||||||
|
line-height:1.25;
|
||||||
|
overflow-wrap:anywhere;
|
||||||
|
}
|
||||||
|
.isa-project-mark {
|
||||||
|
display:grid;
|
||||||
|
place-items:center;
|
||||||
|
flex:none;
|
||||||
|
width:2.75rem;
|
||||||
|
height:2.75rem;
|
||||||
|
border-radius:var(--isa-extension-radius-control,.75rem);
|
||||||
|
color:var(--isa-extension-primary-strong,CanvasText);
|
||||||
|
background:var(--isa-extension-primary-soft,ButtonFace);
|
||||||
|
}
|
||||||
|
.isa-project-icon {display:block;width:1rem;height:1rem;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
||||||
|
.isa-project-mark svg {width:1.35rem;height:1.35rem}
|
||||||
|
.isa-project-controls,.isa-project-path {display:flex;align-items:center;gap:.5rem;flex-wrap:wrap}
|
||||||
|
.isa-project-active :is(button,summary) {cursor:pointer}
|
||||||
|
.isa-project-active :is(button,summary):focus-visible,.isa-project-path [aria-current]:focus-visible {outline:2px solid var(--isa-extension-focus-outline,Highlight);outline-offset:2px}
|
||||||
|
.isa-project-controls :is(button,summary),.isa-project-file-list button {
|
||||||
|
display:inline-flex;align-items:center;gap:.5rem;min-height:var(--isa-extension-control-height,2.25rem);
|
||||||
|
font-family:inherit;font-size:var(--isa-extension-font-size-sm,.875rem);
|
||||||
|
}
|
||||||
|
.isa-project-controls > button[aria-expanded=true] {background:var(--isa-extension-primary-soft,ButtonFace);border-color:var(--isa-extension-primary-strong,ButtonBorder)}
|
||||||
|
.isa-project-actions {position:relative;margin-inline-start:auto}
|
||||||
|
.isa-project-actions > summary {list-style:none;padding:.35rem .75rem;border-radius:var(--isa-extension-radius-control,.75rem)}
|
||||||
|
.isa-project-actions > summary::-webkit-details-marker {display:none}
|
||||||
|
.isa-project-actions[open] > summary,.isa-project-actions > summary:hover {background:var(--isa-extension-control-active-bg,ButtonFace)}
|
||||||
|
.isa-project-choices {
|
||||||
|
position:absolute;z-index:5;inset-inline-end:0;top:calc(100% + .375rem);
|
||||||
|
width:max-content;max-width:calc(100vw - 2rem);padding:.25rem;
|
||||||
|
background:var(--isa-extension-elevated-bg,Canvas);border:1px solid var(--isa-extension-border,ButtonBorder);
|
||||||
|
border-radius:var(--isa-extension-radius-control,.75rem);box-shadow:var(--isa-extension-elevated-shadow,none);
|
||||||
|
}
|
||||||
|
.isa-project-choices button {display:flex;justify-content:flex-start;width:100%;padding-inline:.75rem}
|
||||||
|
.isa-project-choices button:last-child:not(:first-child) {margin-top:.25rem;border-top:1px solid var(--isa-extension-divider,ButtonBorder);border-top-left-radius:0;border-top-right-radius:0}
|
||||||
|
.isa-project-active > [role=alert] {margin:0 1rem 1rem}
|
||||||
|
.isa-project-active > [role=alert]:empty,.isa-project-browser[hidden] {display:none}
|
||||||
|
.isa-project-browser {min-width:0;padding:.75rem 1.25rem 1rem;border-top:1px solid var(--isa-extension-divider,ButtonBorder)}
|
||||||
|
.isa-project-path {gap:.125rem .375rem;font-size:var(--isa-extension-font-size-sm,.875rem);color:var(--isa-extension-panel-muted,CanvasText)}
|
||||||
|
.isa-project-path > svg {width:.75rem;height:.75rem}
|
||||||
|
.isa-project-path > button {min-width:0;max-width:100%;padding:.25rem .375rem;overflow-wrap:anywhere;color:inherit}
|
||||||
|
.isa-project-path > [aria-current] {padding-block:.4rem;font-weight:600;color:var(--isa-extension-panel-heading,CanvasText);overflow-wrap:anywhere}
|
||||||
|
.isa-project-browser-body {margin-top:.5rem;overflow-wrap:anywhere}
|
||||||
|
.isa-project-file-list {display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,15rem),1fr));gap:.5rem;list-style:none;margin:0;padding:0}
|
||||||
|
.isa-project-file-list button {
|
||||||
|
box-sizing:border-box;width:100%;justify-content:flex-start;padding:.5rem .75rem;text-align:start;
|
||||||
|
border:1px solid var(--isa-extension-border-subtle,ButtonBorder);border-radius:var(--isa-extension-radius-detail,.5rem);
|
||||||
|
}
|
||||||
|
.isa-project-file-list button:hover {background:var(--isa-extension-control-hover-bg,ButtonFace);border-color:var(--isa-extension-control-border,ButtonBorder)}
|
||||||
|
.isa-project-file-list button > span {min-width:0;overflow-wrap:anywhere}
|
||||||
|
.isa-project-file-list svg {color:var(--isa-extension-panel-muted,CanvasText)}
|
||||||
|
.isa-project-file-list svg:last-child {width:.8rem;margin-inline-start:auto}
|
||||||
|
.isa-project-message {margin:0;color:var(--isa-extension-panel-muted,CanvasText);font-size:var(--isa-extension-font-size-sm,.875rem)}
|
||||||
|
.isa-project-browser-body :is(img,video,audio) {display:block;max-width:100%;max-height:55vh}
|
||||||
|
.isa-project-browser-body pre {margin:.5rem 0 0;max-height:45vh;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere}
|
||||||
|
.isa-project-metadata dl {display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr));gap:1rem;margin:0;padding:1rem;background:var(--isa-extension-panel-bg-muted,ButtonFace);border-radius:var(--isa-extension-radius-detail,.5rem)}
|
||||||
|
.isa-project-metadata dt,.isa-project-metadata summary {color:var(--isa-extension-panel-muted,CanvasText);font-size:var(--isa-extension-font-size-xs,.8125rem)}
|
||||||
|
.isa-project-metadata dd {margin:.25rem 0 0;font-size:var(--isa-extension-font-size-sm,.875rem)}
|
||||||
|
.isa-project-metadata details {margin-top:.5rem}
|
||||||
|
.isa-project-metadata summary {width:fit-content;padding:.375rem}
|
||||||
|
@media (max-width:680px) {
|
||||||
|
.isa-project-header,.isa-project-browser {padding:.875rem}
|
||||||
|
.isa-project-controls {width:100%}
|
||||||
|
}
|
||||||
|
|
||||||
.isa-group-home {display:grid;gap:9px;padding:10px;min-height:75vh;grid-template-rows:auto 1fr;background:var(--isa-extension-app-bg,var(--isa-extension-panel-bg,Canvas))}
|
.isa-group-home {display:grid;gap:9px;padding:10px;min-height:75vh;grid-template-rows:auto 1fr;background:var(--isa-extension-app-bg,var(--isa-extension-panel-bg,Canvas))}
|
||||||
.isa-group-home > header,.isa-group-projects {background:var(--isa-extension-card-bg,Canvas);border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:14px;padding:14px 18px}
|
.isa-group-home > header,.isa-group-projects {background:var(--isa-extension-card-bg,Canvas);border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:14px;padding:14px 18px}
|
||||||
.isa-group-home header {display:flex;gap:12px;align-items:center;justify-content:space-between;flex-wrap:wrap}
|
.isa-group-home header {display:flex;gap:12px;align-items:center;justify-content:space-between;flex-wrap:wrap}
|
||||||
@@ -31,8 +119,12 @@ export const styles = `
|
|||||||
.isa-group-projects select {font:inherit;color:inherit;background:var(--isa-extension-control-bg,Canvas);border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:.5rem;padding:.5rem;max-width:100%}
|
.isa-group-projects select {font:inherit;color:inherit;background:var(--isa-extension-control-bg,Canvas);border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:.5rem;padding:.5rem;max-width:100%}
|
||||||
.isa-group-home.isa-group-home-embedded {min-height:0;grid-template-rows:auto;padding:0;background:transparent}
|
.isa-group-home.isa-group-home-embedded {min-height:0;grid-template-rows:auto;padding:0;background:transparent}
|
||||||
.isa-group-home-embedded .isa-group-projects,.isa-group-home-embedded aside {border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:var(--isa-extension-radius-md,.625rem);background:var(--isa-extension-card-bg,Canvas)}
|
.isa-group-home-embedded .isa-group-projects,.isa-group-home-embedded aside {border:1px solid var(--isa-extension-border-subtle,GrayText);border-radius:var(--isa-extension-radius-md,.625rem);background:var(--isa-extension-card-bg,Canvas)}
|
||||||
.isa-group-rows {display:grid;gap:8px}
|
.isa-group-rows {display:grid;gap:3px}
|
||||||
.isa-group-rows button {display:flex;justify-content:space-between;align-items:center;gap:10px;width:100%;padding:12px;border-radius:10px;border-color:var(--isa-extension-border-subtle,GrayText);background:var(--isa-extension-card-bg,Canvas)}
|
.isa-project-columns,.isa-group-rows button {box-sizing:border-box;display:grid;grid-template-columns:minmax(0,2fr) minmax(0,1fr) minmax(0,.8fr);align-items:center;gap:8px;text-align:start;padding:6px 10px}
|
||||||
|
.isa-project-columns {font-size:.8em;font-weight:600;overflow-wrap:anywhere;border:1px solid transparent}
|
||||||
|
.isa-project-columns[hidden] {display:none}
|
||||||
|
.isa-project-columns span:last-child,.isa-group-rows time {text-align:end}
|
||||||
|
.isa-group-rows button {width:100%;border-radius:6px;border-color:var(--isa-extension-border-subtle,GrayText);background:var(--isa-extension-card-bg,Canvas)}
|
||||||
.isa-group-rows strong,.isa-group-rows small {display:block;overflow-wrap:anywhere}
|
.isa-group-rows strong,.isa-group-rows small {display:block;overflow-wrap:anywhere}
|
||||||
.isa-group-rows small,.isa-group-rows time {color:var(--isa-extension-panel-muted,GrayText);font-size:.8em}
|
.isa-group-rows small,.isa-group-rows time {color:var(--isa-extension-panel-muted,GrayText);font-size:.8em}
|
||||||
.isa-group-home p:empty {display:none}
|
.isa-group-home p:empty {display:none}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
const paths = {
|
||||||
|
folder: 'M3 7V5a1 1 0 0 1 1-1h5l2 3h9a1 1 0 0 1 1 1v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z',
|
||||||
|
files: 'M7 3h9l4 4v11H7z M15 3v5h5 M4 7v14h12',
|
||||||
|
file: 'M5 3h9l5 5v13H5z M14 3v6h5 M9 13h6 M9 17h4',
|
||||||
|
more: 'M4 12h.01 M12 12h.01 M20 12h.01',
|
||||||
|
chevron: 'm9 6 6 6-6 6',
|
||||||
|
import: 'M12 3v12m-5-5 5 5 5-5 M4 16v4h16v-4',
|
||||||
|
export: 'M12 15V3m-5 5 5-5 5 5 M4 16v4h16v-4',
|
||||||
|
leave: 'M9 4H4v16h5 M9 12h12m-5-5 5 5-5 5'
|
||||||
|
};
|
||||||
|
|
||||||
|
export function workspaceElements(document) {
|
||||||
|
function make(tag, label, className) {
|
||||||
|
const node = document.createElement(tag);
|
||||||
|
if (label != null) node.textContent = label;
|
||||||
|
if (className) node.className = className;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
function icon(name) {
|
||||||
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||||
|
const path = document.createElementNS(svg.namespaceURI, 'path');
|
||||||
|
svg.setAttribute('viewBox', '0 0 24 24');
|
||||||
|
svg.setAttribute('class', 'isa-project-icon');
|
||||||
|
svg.setAttribute('aria-hidden', 'true');
|
||||||
|
svg.setAttribute('focusable', 'false');
|
||||||
|
path.setAttribute('d', paths[name]);
|
||||||
|
if (name === 'more') path.setAttribute('stroke-width', '3.5');
|
||||||
|
svg.append(path);
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
|
function button(label, action, symbol, variant = 'ghost') {
|
||||||
|
const node = make('button', label, 'isa-extension-button isa-extension-button--' + variant);
|
||||||
|
node.type = 'button';
|
||||||
|
node.onclick = action;
|
||||||
|
if (symbol) node.prepend(icon(symbol));
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return {make, icon, button};
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import test from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import {openPriceAsset} from '../src/prices.js';
|
||||||
|
|
||||||
|
test('workspace writers can backfill the same observation concurrently without replacing edits or creating duplicates',async () => {
|
||||||
|
let revision = 0, conflict = true;
|
||||||
|
const records = new Map(), writes = [];
|
||||||
|
const identity = {storeId:'s',incarnation:'i',supportsExpectedRevision:true};
|
||||||
|
const scope = {workspaceId:'w',groupId:'g'};
|
||||||
|
const bridge = {async invoke(command,args) {
|
||||||
|
if(command === 'filesystem_open_workspace_asset') return {...scope,asset:'prices',folderId:'f',path:'/shared/prices',canWrite:true};
|
||||||
|
if(command === 'kv_store_open') return {...identity,revision};
|
||||||
|
if(command === 'kv_store_query_list') return {...identity,revision,page:{items:args.ids.filter(id=>records.has(id)).map(id=>({id,value:records.get(id)}))}};
|
||||||
|
if(command === 'kv_store_apply') {
|
||||||
|
if(conflict) {
|
||||||
|
records.set('a',{description:'Manual correction',supplier:'A',unitPrice:0});
|
||||||
|
revision++; conflict = false; throw Error('revision_conflict');
|
||||||
|
}
|
||||||
|
assert.equal(args.expectedRevision,revision);
|
||||||
|
for(const row of args.operations) records.set(row.id,row.value);
|
||||||
|
writes.push(args.operations.length);
|
||||||
|
return {...identity,pending:false,acceptedRevision:++revision};
|
||||||
|
}
|
||||||
|
assert.fail(command);
|
||||||
|
}};
|
||||||
|
const asset = await openPriceAsset({bridge,scope});
|
||||||
|
const rows = [{id:'a',value:{description:'old',supplierId:'supplier-a',unitPrice:0}}];
|
||||||
|
await asset.importRows(rows); await asset.importRows(rows);
|
||||||
|
assert.deepEqual(records.get('a'), {description:'Manual correction',supplier:'A',unitPrice:0,supplierId:'supplier-a'});
|
||||||
|
assert.deepEqual(writes,[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a read-only open distinguishes a genuinely empty asset from an inaccessible inventory and creates no KV file', async () => {
|
||||||
|
const scope = {workspaceId:'w',groupId:'g'}; let denied = false;
|
||||||
|
const bridge = {async invoke(command) {
|
||||||
|
if(command === 'filesystem_open_workspace_asset') return {...scope,asset:'prices',folderId:'f',path:'/shared/prices',canWrite:false};
|
||||||
|
if(command === 'filesystem_list_dir') {
|
||||||
|
if(denied) throw Error('access revoked');
|
||||||
|
return {authoritative:true,files:[]};
|
||||||
|
}
|
||||||
|
assert.fail(command);
|
||||||
|
}};
|
||||||
|
const asset = await openPriceAsset({bridge,scope,access:'read'});
|
||||||
|
assert.deepEqual((await asset.query()).items,[]);
|
||||||
|
denied = true;
|
||||||
|
await assert.rejects(asset.query(), /access revoked/);
|
||||||
|
});
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import {createSharedFolderReader} from '../src/shared-folder.js';
|
import {createSharedFolderReader, openWorkspaceAsset} from '../src/shared-folder.js';
|
||||||
|
|
||||||
|
test('opening a workspace asset rejects cross-group, cross-asset and overprivileged replies', async () => {
|
||||||
|
const scope = {workspaceId: 'company', groupId: 'estimators'};
|
||||||
|
const grant = {...scope, asset: 'suppliers', folderId: 'folder-1', path: '/shared/suppliers', canWrite: false};
|
||||||
|
const open = reply => openWorkspaceAsset({scope, asset: 'suppliers', access: 'read', bridge: {
|
||||||
|
async invoke(command, args) {
|
||||||
|
assert.equal(command, 'filesystem_open_workspace_asset');
|
||||||
|
assert.deepEqual(args, {asset: 'suppliers', access: 'read'});
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
assert.deepEqual(await open(grant), grant);
|
||||||
|
for (const patch of [{groupId:'other'}, {asset:'prices'}, {path:'/shared'}, {canWrite:true}]) {
|
||||||
|
await assert.rejects(open({...grant, ...patch}), /Invalid workspace asset grant/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('specialist and other viewers read the same existing supplier register and price book', async () => {
|
test('specialist and other viewers read the same existing supplier register and price book', async () => {
|
||||||
const root='/Shared/Registers';
|
const root='/Shared/Registers';
|
||||||
|
|||||||
Reference in New Issue
Block a user