Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,488 changes: 8,573 additions & 4,915 deletions api/openapi-v2.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions frontend/src/lib/api/boardPublications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { withCollectionInvalidation } from '../utils/collectionChanges.js';
import { fetchAPIV2, fetchV2Data } from './core.js';

export const boardPublications = {
/** @param {Record<string, unknown>} filters
* @param {{admin?: boolean, signal?: AbortSignal}} options */
list(filters = {}, { admin = false, ...options } = {}) {
const query = new URLSearchParams();
for (const [key, value] of Object.entries(filters)) {
if (value !== '' && value != null) query.set(key, String(value));
}
return fetchAPIV2(`${admin ? '/admin' : ''}/board-publications?${query}`, options);
},
get: (id, options = {}) => fetchV2Data(`/board-publications/${id}`, options),
history: (id, options = {}) => fetchV2Data(`/board-publications/${id}/history`, options),
save: (id, draft) =>
withCollectionInvalidation(
fetchV2Data(`/board-publications/${id}`, { method: 'PUT', body: JSON.stringify(draft) })
),
revoke: (id, revision, reason) =>
withCollectionInvalidation(
fetchV2Data(`/board-publications/${id}/revoke`, {
method: 'POST',
body: JSON.stringify({ revision, reason }),
})
),
allowRepublish: (id, revision) =>
withCollectionInvalidation(
fetchV2Data(`/board-publications/${id}/allow-republish`, {
method: 'POST',
body: JSON.stringify({ revision }),
})
),
};
28 changes: 28 additions & 0 deletions frontend/src/lib/api/portalBoards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { fetchAPIV2, fetchV2Data } from './core.js';

export const portalBoards = {
experience: (slug, options = {}) =>
fetchAPIV2(`/portal/${encodeURIComponent(slug)}/experience`, options),
list: (channelId) => fetchV2Data(`/channels/${channelId}/board-placements`),
save: (channelId, placement) =>
fetchV2Data(
`/channels/${channelId}/board-placements${placement.id ? `/${encodeURIComponent(placement.id)}` : ''}`,
{
method: placement.id ? 'PUT' : 'POST',
body: JSON.stringify(placement),
}
),
remove: (channelId, placement) =>
fetchV2Data(
`/channels/${channelId}/board-placements/${encodeURIComponent(placement.id)}?revision=${placement.revision}`,
{ method: 'DELETE' }
),
client(slug, placementId) {
const path = `/portal/${encodeURIComponent(slug)}/boards/${encodeURIComponent(placementId)}`;
return {
get: (_slug, options = {}) => fetchAPIV2(path, options),
getItem: (_slug, key, options = {}) =>
fetchAPIV2(`${path}/items/${encodeURIComponent(key)}`, options),
};
},
};
45 changes: 45 additions & 0 deletions frontend/src/lib/customer/CompactKnowledge.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script>
import { portalCustomizationStore as portalStore } from '../stores/portal.svelte.js';
import { portalSearchStore } from '../stores/portalSearch.svelte.js';
import SearchInput from '../components/SearchInput.svelte';
import Link from '../components/Link.svelte';
import Spinner from '../components/Spinner.svelte';
import AlertBox from '../components/AlertBox.svelte';
import EmptyState from '../components/EmptyState.svelte';
import PortalKBBrowse from '../portal/PortalKBBrowse.svelte';

const external = $derived(portalStore.parseDocmostShareLink(portalStore.knowledgeBaseShareLink));
function href(result) {
return result.source === 'workspace_page'
? `/portal/${portalStore.currentSlug}/kb/${result.page_id}?source=search`
: `${external.baseURL}/share/${external.shareID}/p/${result.slugId}`;
}
</script>

<div class="space-y-5" data-testid="compact-knowledge">
<SearchInput
bind:value={portalSearchStore.query}
dataTestid="compact-kb-search"
placeholder="Search the knowledge base"
on_input={() => portalSearchStore.searchDebounced()}
on_keydown={event => { if (event.key === 'Enter') portalSearchStore.search(); }}
/>
{#if portalSearchStore.visible}
{#if portalSearchStore.loading}<Spinner />
{:else if portalSearchStore.error}<AlertBox variant="error" message={portalSearchStore.error} />
{:else}
<div class="space-y-3">
{#each portalSearchStore.results?.data || [] as result}
<Link href={href(result)} target={result.source === 'workspace_page' ? undefined : '_blank'} rel="noopener" class="block rounded border border-ds-border p-4" data-testid="compact-kb-result">
<h3 class="font-medium">{result.title}</h3>
<p class="text-sm text-ds-text-subtle">{(result.highlight || result.excerpt || '').replace(/<[^>]*>/g, '')}</p>
</Link>
{:else}<EmptyState title="No matching articles" />{/each}
</div>
{/if}
{:else if portalStore.knowledgeBasePageSources.length}
<PortalKBBrowse />
{:else if external.shareID}
<Link href={portalStore.knowledgeBaseShareLink} target="_blank" rel="noopener">Open knowledge base</Link>
{:else}<EmptyState title="No articles available" />{/if}
</div>
74 changes: 74 additions & 0 deletions frontend/src/lib/customer/CompactPortal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script>
import { currentRoute, navigate } from '../router.js';
import { portalBoards } from '../api/portalBoards.js';
import { customerAccess } from '../api/customerAccess.js';
import CustomerHeader from './CustomerHeader.svelte';
import Button from '../components/Button.svelte';
import AlertBox from '../components/AlertBox.svelte';
import EmptyState from '../components/EmptyState.svelte';
import LazyRootView from '../components/LazyRootView.svelte';
import CustomerLogin from './CustomerLogin.svelte';
import { compactModules, compactTarget } from './compactNavigation.js';

let { experience } = $props();
let accessError = $state(null);
let showLogin = $state(false);
let loginStatus = $state(null);
let rejectedDefault = $state(null);
const loadBoard = () => import('../pages/PublicBoard.svelte');
const loadModule = () => import('./CompactPortalModule.svelte');
const slug = $derived(experience.slug);
const modules = $derived(compactModules(experience));
const target = $derived(compactTarget(rejectedDefault === experience.default_module ? { ...experience, default_module: '' } : experience, $currentRoute, modules));
const active = $derived(target.kind);
const placementId = $derived(active?.startsWith('board:') ? active.slice(6) : null);
const client = $derived(placementId ? portalBoards.client(slug, placementId) : null);
const navigation = $derived(modules.map(item => ({ ...item, active: item.id === active })));
const moduleEnabled = $derived(placementId ? experience.modules.includes('boards') : experience.modules.includes(active));

function selectItem(key) {
navigate(`/portal/${slug}/boards/${placementId}${key ? `/items/${encodeURIComponent(key)}` : ''}`, { replace: false });
}

async function signIn() {
try { loginStatus = await customerAccess.status('portal', slug); showLogin = true; }
catch (err) { accessError = err.status || 403; }
}

async function identityChanged() {
experience = await portalBoards.experience(slug);
accessError = null;
showLogin = false;
}
async function signOut() {
try { await customerAccess.login('portal', slug, 'logout'); window.location.reload(); }
catch (err) { accessError = err.status || 403; }
}
// Recheck identity/policy after another tab signs in/out; never keep stale customer modules.
function refreshIdentity() { void identityChanged().catch(() => { experience = { ...experience, authenticated: false, identity_key: 0, boards: [] }; }); }
</script>

<svelte:window onfocus={event => { if (event.target === window) refreshIdentity(); }} />

<div class="flex min-h-screen flex-col bg-ds-surface text-ds-text" data-testid="compact-portal">
<CustomerHeader title={experience.title} logo={experience.logo_url} {navigation}>
{#snippet actions()}
<!-- shortcut-guard-exempt: Customer navigation, not internal item creation; available by Tab and Enter without registering app-wide creation keys in a public shell. -->
{#if experience.modules.includes('forms') && active === 'requests'}<Button dataTestid="compact-new-request" onclick={() => navigate(`/portal/${slug}?module=forms`)}>New request</Button>{/if}
{#if experience.is_internal}<Button variant="ghost" href="/" dataTestid="compact-back-to-app">Back to app</Button>
{:else if !experience.authenticated}<Button variant="ghost" dataTestid="compact-sign-in" onclick={signIn}>Sign in</Button>
{:else}<Button variant="ghost" dataTestid="compact-sign-out" onclick={signOut}>Sign out</Button>{/if}
{/snippet}
</CustomerHeader>
{#if accessError}<AlertBox variant="warning" message={accessError === 401 ? 'Sign in to view this board.' : 'Your account does not have access to this board.'} />{/if}
{#if showLogin && loginStatus}<CustomerLogin kind="portal" {slug} status={loginStatus} onlogin={identityChanged} />{/if}
<main class="min-w-0 flex-1" data-testid="compact-portal-content">
{#if !active}<EmptyState title="No content available" description="There are no accessible modules in this portal." />
{:else if !moduleEnabled}<EmptyState title="Content unavailable" description="This module is not enabled for this portal." />
{:else if placementId}
{#key `${slug}:${placementId}:${experience.identity_key}:${experience.revision}`}<LazyRootView loader={loadBoard} label="Board" componentProps={{ slug, client, embedded: true, initialItemKey: $currentRoute.params?.itemKey || null, onitemchange: selectItem, onaccessdenied: status => { accessError = status; if (status === 401) void signIn(); } }} />{/key}
{:else}
{#key `${slug}:${active}:${target.formId || ''}:${target.articleId || ''}:${experience.identity_key}:${experience.revision}:${$currentRoute.path}:${$currentRoute.query?.id || ''}`}<LazyRootView loader={loadModule} label="Portal module" componentProps={{ slug, kind: active, formId: target.formId, articleId: target.articleId, draftsEnabled: experience.modules.includes('drafts'), onidentitychange: identityChanged, ondefaultunavailable: !$currentRoute.params?.pageId && !$currentRoute.params?.requestTypeId ? () => { rejectedDefault = experience.default_module; } : null }} />{/key}
{/if}
</main>
</div>
83 changes: 83 additions & 0 deletions frontend/src/lib/customer/CompactPortalModule.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<script>
import { onMount, onDestroy } from 'svelte';
import { currentRoute, navigate } from '../router.js';
import { portalCustomizationStore as portalStore, portalCatalogStore } from '../stores/portal.svelte.js';
import { portalAuthStore } from '../stores/portalAuth.svelte.js';
import { portalRequestsStore, portalApprovalsStore, portalDraftsStore } from '../stores/portalActivity.svelte.js';
import LazyRootView from '../components/LazyRootView.svelte';
import LazyRootDialog from '../components/LazyRootDialog.svelte';
import Button from '../components/Button.svelte';
import Spinner from '../components/Spinner.svelte';
import AlertBox from '../components/AlertBox.svelte';
import PortalLoginModal from '../portal/PortalLoginModal.svelte';
import GlobalConfirmDialog from '../dialogs/GlobalConfirmDialog.svelte';

let { slug, kind, formId = null, articleId = null, draftsEnabled = true, onidentitychange = null, ondefaultunavailable = null } = $props();
let ready = $state(false);
let error = $state('');
let selectedForm = $state(null);
let selectedReport = $state(null);
let prefill = $state({});
const loaders = {
requests: () => import('../portal/PortalMyRequests.svelte'),
drafts: () => import('../portal/PortalMyDrafts.svelte'),
approvals: () => import('../portal/PortalMyApprovals.svelte'),
profile: () => import('../portal/PortalProfile.svelte'),
'knowledge-base': () => import('./CompactKnowledge.svelte'),
article: () => import('../portal/PortalKBArticle.svelte'),
'asset-reports': () => import('../portal/PortalSections.svelte'),
};
const loadForm = () => import('../dialogs/RequestFormModal.svelte');
const loadReport = () => import('../dialogs/AssetReportFormModal.svelte');
let disposed = false;

async function load() {
try {
ready = false;
const [, bootstrap] = await Promise.all([portalStore.loadPortal(slug), portalAuthStore.checkAuth(slug)]);
if (disposed) return;
portalStore.hydrateUserBootstrap(bootstrap);
if (!bootstrap?.authenticated) { portalStore.showLoginDialog = true; ready = true; return; }
if (kind === 'requests') {
portalRequestsStore.setVisible(true);
if ($currentRoute.query?.id) await portalRequestsStore.loadAndView($currentRoute.query.id);
else await portalRequestsStore.load();
}
if (kind === 'approvals') { portalApprovalsStore.setVisible(true); if ($currentRoute.query?.id) await portalApprovalsStore.loadAndView($currentRoute.query.id); else await portalApprovalsStore.load(); }
if (kind === 'drafts') { portalDraftsStore.setVisible(true); await portalDraftsStore.load(); }
if (kind === 'forms') {
await portalCatalogStore.loadRequestTypes();
if (disposed) return;
const id = formId;
const forms = portalCatalogStore.requestTypes;
const target = id ? forms.find(form => form.id === id) : forms.length === 1 && !$currentRoute.query?.choose ? forms[0] : null;
if (id && !target) { if (ondefaultunavailable) { ondefaultunavailable(); return; } error = 'This request form is unavailable.'; }
if (target) selectedForm = target;
prefill = Object.fromEntries(Object.entries($currentRoute.query || {}).filter(([key]) => key.startsWith('prefill.') && !key.endsWith('.label')).map(([key, value]) => [key.slice(8), value]));
}
if (kind === 'asset-reports') await portalCatalogStore.loadAssetReports();
if (!disposed) ready = true;
} catch (err) { if (!disposed) { error = err.message; ready = true; } }
}

onMount(load);
onDestroy(() => { disposed = true; portalStore.reset(); portalAuthStore.reset(); });
</script>

<div class="mx-auto max-w-6xl p-4 sm:p-6" data-testid={`compact-module-${kind}`}>
{#if error}<AlertBox variant="error" message={error} />{/if}
{#if !ready}<Spinner />{:else if $portalAuthStore.isAuthenticated}
{#if kind === 'forms'}
<h2 class="mb-4 text-lg font-semibold">New request</h2>
<div class="flex flex-col items-start gap-2">{#each portalCatalogStore.requestTypes as form (form.id)}<Button dataTestid={`compact-request-type-${form.id}`} onclick={() => navigate(`/portal/${slug}/request/${form.id}`)}>{form.name}</Button>{/each}</div>
{:else if loaders[kind]}
<LazyRootView loader={kind === 'knowledge-base' && articleId ? loaders.article : loaders[kind]} label="Portal module" componentProps={kind === 'knowledge-base' && articleId ? { pageId: articleId, onunavailable: ondefaultunavailable } : kind === 'drafts' ? { onresume: ({ requestType }) => navigate(`/portal/${slug}/request/${requestType.id}`) } : kind === 'asset-reports' ? { onOpenAssetReportForm: report => selectedReport = report, onOpenRequestForm: form => navigate(`/portal/${slug}/request/${form.id}`) } : {}} />
{/if}
{/if}
<PortalLoginModal onloginsuccess={async () => { await onidentitychange?.(); if (!disposed) await load(); }} />
<GlobalConfirmDialog />
{#if selectedForm}
<LazyRootDialog loader={loadForm} isOpen={true} componentProps={{ requestType: selectedForm, portalSlug: slug, prefill, draftsEnabled, onsubmitted: id => navigate(`/portal/${slug}?view=requests&id=${id}`), onclose: () => { selectedForm = null; navigate(`/portal/${slug}?module=forms&choose=1`); } }} />
{/if}
{#if selectedReport}<LazyRootDialog loader={loadReport} isOpen={true} componentProps={{ report: selectedReport, portalSlug: slug, onclose: () => selectedReport = null }} />{/if}
</div>
7 changes: 6 additions & 1 deletion frontend/src/lib/customer/CustomerBoundary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import CustomerLogin from './CustomerLogin.svelte';
import Button from '../components/Button.svelte';
import AlertBox from '../components/AlertBox.svelte';
import { navigate } from '../router.js';
import { toLogical } from '../runtime/contextPath.js';
let { kind, slug, children } = $props();
let status = $state(null);
let loading = $state(true);
Expand Down Expand Up @@ -34,8 +36,11 @@
if (type === 'portal' && portalToken) {
const access = await customerAccess.status(type, key);
if (access.restricted && !access.allowed) {
const destination = new URLSearchParams(window.location.hash.slice(1)).get('next');
const next = destination ? toLogical(destination) : null;
await portalAuth.verifyMagicLink(key, portalToken);
history.replaceState(null, '', window.location.pathname);
const root = `/portal/${key}`;
navigate(next && (next === root || next.startsWith(`${root}/`) || next.startsWith(`${root}?`)) ? next : root, { replace: true });
}
}
const result = await customerAccess.status(type, key);
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/lib/customer/CustomerHeader.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
import { onMount } from 'svelte';
import Sun from '@lucide/svelte/icons/sun';
import Moon from '@lucide/svelte/icons/moon';
import Button from '../components/Button.svelte';
import Link from '../components/Link.svelte';
import { themeStore } from '../stores/theme.svelte.js';

let { title = '', description = '', logo = null, navigation = [], actions = null } = $props();
onMount(() => themeStore.init());
</script>

<header class="flex flex-wrap items-center justify-between gap-3 border-b border-ds-border bg-ds-surface-raised px-4 py-3 sm:px-6" data-testid="customer-header">
<div class="flex min-w-0 items-center gap-3">
{#if logo}<img src={logo} alt="" class="h-7 w-7 object-contain" />{/if}
<div class="min-w-0"><h1 class="truncate text-lg font-semibold">{title}</h1>{#if description}<p class="text-sm text-ds-text-subtle">{description}</p>{/if}</div>
</div>
{#if navigation.length > 1}
<nav class="order-last flex w-full gap-2 overflow-x-auto sm:order-none sm:w-auto" aria-label="Portal sections" data-testid="customer-module-navigation">
{#each navigation as item (item.id)}<Link href={item.href} active={item.active} data-testid={`customer-module-${item.id}`} class="shrink-0 rounded px-3 py-2 text-sm">{item.label}</Link>{/each}
</nav>
{/if}
<div class="flex items-center gap-2">
{#if actions}{@render actions()}{/if}
<Button variant="ghost" size="small" icon={themeStore.resolvedTheme === 'dark' ? Sun : Moon} ariaLabel="Toggle theme" dataTestid="public-board-theme-toggle" onclick={() => themeStore.setColorMode(themeStore.resolvedTheme === 'dark' ? 'light' : 'dark')} />
</div>
</header>
3 changes: 2 additions & 1 deletion frontend/src/lib/customer/CustomerLogin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Button from '../components/Button.svelte';
import Input from '../components/Input.svelte';
import AlertBox from '../components/AlertBox.svelte';
import { toLogical } from '../runtime/contextPath.js';
let { kind, slug, status, onlogin } = $props();
let email = $state('');
let busy = $state(false);
Expand All @@ -15,7 +16,7 @@
event.preventDefault();
busy = true;
error = '';
try { message = (await customerAccess.login(kind, slug, 'request', { email })).message; }
try { message = (await customerAccess.login(kind, slug, 'request', { email, ...(kind === 'portal' ? { next: toLogical(window.location.pathname + window.location.search) } : {}) })).message; }
catch (err) { error = err.message; }
finally { busy = false; }
}
Expand Down
Loading
Loading