commit d2657a801556df07e16b046142a0dc7a42f8d6aa
parent 1ab9bbebf2bcb0fa3c9f921e067cdb3079d42567
Author: triesap <tyson@radroots.org>
Date: Sat, 10 Oct 2026 12:54:16 +0000
web: build exact public review and edit-details navigation (HCP-117)
Diffstat:
9 files changed, 1288 insertions(+), 130 deletions(-)
diff --git a/web/src/lib/components/ListingEditor.svelte b/web/src/lib/components/ListingEditor.svelte
@@ -1,5 +1,28 @@
<script lang="ts">
- import { getContext, onMount } from 'svelte';
+ /* global document */
+ import { getContext, onMount, tick } from 'svelte';
+ import ListingReview from './ListingReview.svelte';
+ import InboxSetup from './InboxSetup.svelte';
+ import {
+ PUBLIC_RUNTIME_CONTEXT,
+ publicRuntimeReady,
+ type PublicRuntimeContext,
+ type PublicRuntime
+ } from '../runtime/public-runtime.ts';
+ import {
+ createRuntimeInboxSetupView,
+ inboxSetupViewSnapshot,
+ subscribeInboxSetupView,
+ closeInboxSetupView,
+ type InboxSetupView
+ } from '../messaging/inbox-setup-view.ts';
+ import {
+ openEditorReview,
+ editorReviewSnapshot,
+ closeEditorReview,
+ type EditorReview,
+ type EditorFormError
+ } from '../publishing/editor-workflow.ts';
import CapabilityGate from './CapabilityGate.svelte';
import Notice from './Notice.svelte';
import OperationStatus from './OperationStatus.svelte';
@@ -28,13 +51,25 @@
let {
route,
onfirstsave,
- onsavedclose
+ onsavedclose,
+ inboxController
}: {
route: ListingEditorRoute;
onfirstsave?: (draftId: string, current: () => boolean) => Promise<void>;
onsavedclose?: () => Promise<void>;
+ inboxController?: InboxSetupView;
} = $props();
const context = getContext<IdentityViewContext>(IDENTITY_VIEW_CONTEXT);
+ const publicContext = getContext<PublicRuntimeContext>(
+ PUBLIC_RUNTIME_CONTEXT
+ );
+ let runtime = $state.raw<PublicRuntime | undefined>(),
+ setup = $state.raw<InboxSetupView | undefined>();
+ let setupState = $state(inboxSetupViewSnapshot(undefined));
+ let review = $state.raw<EditorReview | undefined>(),
+ reviewBusy = $state(false);
+ let errors = $state<readonly EditorFormError[]>([]),
+ reviewMessage = $state('');
let identity = $state(identityViewSnapshot(context)),
mounted = $state(false),
editor = $state.raw<Editor | undefined>(),
@@ -79,12 +114,47 @@
const off = subscribeIdentityView(context, (next) => {
identity = next;
});
+ if (publicContext)
+ void publicRuntimeReady(publicContext)
+ .then((value) => {
+ if (mounted) runtime = value;
+ })
+ .catch(() => {
+ /* Draft saving does not depend on inbox setup. */
+ });
return () => {
mounted = false;
off();
};
});
$effect(() => {
+ const author = admittedAuthor,
+ available = active,
+ source = runtime,
+ supplied = inboxController;
+ if (!available || !author) {
+ setup = undefined;
+ setupState = inboxSetupViewSnapshot(undefined);
+ return;
+ }
+ const owned =
+ supplied ?? (source && createRuntimeInboxSetupView(context, source));
+ setup = owned;
+ const off = owned
+ ? subscribeInboxSetupView(owned, (next) => {
+ setupState = next;
+ })
+ : () => {};
+ return () => {
+ off();
+ if (owned) closeInboxSetupView(owned);
+ };
+ });
+ const visibleReview = $derived.by(() => {
+ if (!setupState.owner || !snapshot || !visible || !review) return;
+ return editorReviewSnapshot(review) ? review : undefined;
+ });
+ $effect(() => {
const resource = route,
author = admittedAuthor;
if (!active || !author) {
@@ -100,6 +170,9 @@
off = () => {};
editor = undefined;
snapshot = undefined;
+ review = undefined;
+ errors = [];
+ reviewMessage = '';
form = blankForm();
unavailable = false;
void openListingEditor(context, resource, cancellation.signal).then(
@@ -163,8 +236,75 @@
function changed() {
const original = editor;
if (!original || !listingEditorSnapshot(original)?.editable) return;
+ if (review) closeEditorReview(review);
+ review = undefined;
+ errors = [];
void editListingEditor(original, { ...form });
}
+ async function showReview() {
+ const original = editor,
+ resource = route,
+ author = admittedAuthor;
+ if (
+ reviewBusy ||
+ closeBusy ||
+ !original ||
+ !listingEditorSnapshot(original)?.editable
+ )
+ return;
+ reviewBusy = true;
+ try {
+ const result = await openEditorReview(original, setup, { ...form });
+ if (
+ !mounted ||
+ editor !== original ||
+ route !== resource ||
+ admittedAuthor !== author ||
+ !listingEditorSnapshot(original)
+ ) {
+ if (result.status === 'review') closeEditorReview(result.review);
+ return;
+ }
+ if (result.status === 'blocked') {
+ errors = result.errors;
+ reviewMessage = result.message;
+ await tick();
+ document.querySelector<HTMLElement>('#listing-review-errors')?.focus();
+ return;
+ }
+ if (review) closeEditorReview(review);
+ review = result.review;
+ errors = [];
+ reviewMessage = '';
+ await tick();
+ if (mounted && editor === original && editorReviewSnapshot(result.review))
+ document.querySelector<HTMLElement>('#listing-review-heading')?.focus();
+ } finally {
+ reviewBusy = false;
+ }
+ }
+ async function editDetails() {
+ if (review) closeEditorReview(review);
+ review = undefined;
+ errors = [];
+ reviewMessage = '';
+ await tick();
+ if (mounted && editor && listingEditorSnapshot(editor)?.editable)
+ document.querySelector<HTMLInputElement>('#listing-title')?.focus();
+ }
+ function fieldError(field: keyof PublicDraftForm) {
+ return errors.find((value) => value.field === field);
+ }
+ function fieldId(field: keyof PublicDraftForm) {
+ return (
+ 'listing-' +
+ (field === 'contactType'
+ ? 'contact-type'
+ : field === 'contactValue'
+ ? 'contact-value'
+ : field)
+ );
+ }
function connect() {
return connectIdentityView(context);
}
@@ -248,164 +388,261 @@
/>{:else}<p>
Changes are saved in this browser. Browser storage is not a backup.
</p>{/if}
- <form class="stack" onsubmit={(event) => event.preventDefault()} novalidate>
- <div class="field">
- <label class="label" for="listing-title">Product name</label><input
- id="listing-title"
- type="text"
- value={form.title}
- oninput={(event) => {
- form = { ...form, title: event.currentTarget.value };
- changed();
- }}
- readonly={!visible.editable}
- />
- </div>
- <div class="field">
- <label class="label" for="listing-description">Description</label
- ><textarea
- id="listing-description"
- rows="6"
- value={form.description}
- oninput={(event) => {
- form = { ...form, description: event.currentTarget.value };
- changed();
- }}
- readonly={!visible.editable}></textarea>
- </div>
- <div class="field">
- <label class="label" for="listing-location">Public area</label>
- <p id="listing-location-hint" class="text-small">
- A town or collection area is enough.
- </p>
- <input
- id="listing-location"
- type="text"
- aria-describedby="listing-location-hint"
- value={form.location}
- oninput={(event) => {
- form = { ...form, location: event.currentTarget.value };
- changed();
- }}
- readonly={!visible.editable}
- />
- </div>
- <div class="cluster">
+ {#if visibleReview}<ListingReview
+ review={visibleReview}
+ onedit={editDetails}
+ />{:else}
+ {#if reviewMessage}<Notice tone="warning" text={reviewMessage} />{/if}
+ {#if errors.length}<div
+ id="listing-review-errors"
+ tabindex="-1"
+ role="alert"
+ >
+ <p>Check these listing fields. Your input remains here.</p>
+ <ul>
+ {#each errors as error (error.field)}<li>
+ <a href={internalHref('#' + fieldId(error.field))}
+ >{error.message}</a
+ >
+ </li>{/each}
+ </ul>
+ </div>{/if}
+ <form
+ class="stack"
+ onsubmit={(event) => event.preventDefault()}
+ novalidate
+ >
<div class="field">
- <label class="label" for="listing-amount">Price</label><input
- id="listing-amount"
+ <label class="label" for="listing-title">Product name</label><input
+ id="listing-title"
+ aria-invalid={fieldError('title') ? 'true' : undefined}
+ aria-errormessage={fieldError('title')
+ ? 'listing-title-error'
+ : undefined}
type="text"
- inputmode="decimal"
- value={form.amount}
+ value={form.title}
oninput={(event) => {
- form = { ...form, amount: event.currentTarget.value };
+ form = { ...form, title: event.currentTarget.value };
changed();
}}
readonly={!visible.editable}
/>
+ {#if fieldError('title')}<p id="listing-title-error">
+ {fieldError('title')?.message}
+ </p>{/if}
</div>
<div class="field">
- <label class="label" for="listing-currency">Currency</label><input
- id="listing-currency"
- type="text"
- maxlength="3"
- value={form.currency}
+ <label class="label" for="listing-description">Description</label
+ ><textarea
+ id="listing-description"
+ aria-invalid={fieldError('description') ? 'true' : undefined}
+ aria-errormessage={fieldError('description')
+ ? 'listing-description-error'
+ : undefined}
+ rows="6"
+ value={form.description}
oninput={(event) => {
- form = { ...form, currency: event.currentTarget.value };
+ form = { ...form, description: event.currentTarget.value };
changed();
}}
- readonly={!visible.editable}
- />
+ readonly={!visible.editable}></textarea>
+ {#if fieldError('description')}<p id="listing-description-error">
+ {fieldError('description')?.message}
+ </p>{/if}
</div>
<div class="field">
- <label class="label" for="listing-unit">Per</label><select
- id="listing-unit"
- value={form.unit}
- onchange={(event) => {
- form = { ...form, unit: event.currentTarget.value };
+ <label class="label" for="listing-location">Public area</label>
+ <p id="listing-location-hint" class="text-small">
+ A town or collection area is enough.
+ </p>
+ <input
+ id="listing-location"
+ aria-invalid={fieldError('location') ? 'true' : undefined}
+ aria-errormessage={fieldError('location')
+ ? 'listing-location-error'
+ : undefined}
+ type="text"
+ aria-describedby="listing-location-hint"
+ value={form.location}
+ oninput={(event) => {
+ form = { ...form, location: event.currentTarget.value };
changed();
}}
- disabled={!visible.editable}
- ><option value="">Choose a unit</option
- >{#each foodUnits as unit (unit)}<option value={unit}>{unit}</option
- >{/each}</select
- >
+ readonly={!visible.editable}
+ />
+ {#if fieldError('location')}<p id="listing-location-error">
+ {fieldError('location')?.message}
+ </p>{/if}
</div>
- </div>
- <div class="field">
- <label class="label" for="listing-quantity"
- >Advertised quantity (optional)</label
- >
- <p id="listing-quantity-unit">
- {form.unit || 'Uses the selected price unit'}
- </p>
- <input
- id="listing-quantity"
- type="text"
- inputmode="decimal"
- aria-describedby="listing-quantity-unit"
- value={form.quantity}
- oninput={(event) => {
- form = { ...form, quantity: event.currentTarget.value };
- changed();
- }}
- readonly={!visible.editable}
- />
- </div>
- <details>
- <summary>Add public contact details (optional)</summary>
- <div class="stack">
- <p>Only add contact details you want to include publicly.</p>
+ <div class="cluster">
<div class="field">
- <label class="label" for="listing-contact-type"
- >Public contact type</label
- ><select
- id="listing-contact-type"
- value={form.contactType}
- onchange={(event) => {
- const value = event.currentTarget.value;
- if (
- value === '' ||
- value === 'email' ||
- value === 'phone' ||
- value === 'https'
- ) {
- form = { ...form, contactType: value };
- changed();
- }
+ <label class="label" for="listing-amount">Price</label><input
+ id="listing-amount"
+ aria-invalid={fieldError('amount') ? 'true' : undefined}
+ aria-errormessage={fieldError('amount')
+ ? 'listing-amount-error'
+ : undefined}
+ type="text"
+ inputmode="decimal"
+ value={form.amount}
+ oninput={(event) => {
+ form = { ...form, amount: event.currentTarget.value };
+ changed();
}}
- disabled={!visible.editable}
- ><option value="">No public contact</option><option value="email"
- >Email</option
- ><option value="phone">Phone</option><option value="https"
- >Website</option
- ></select
- >
+ readonly={!visible.editable}
+ />
+ {#if fieldError('amount')}<p id="listing-amount-error">
+ {fieldError('amount')?.message}
+ </p>{/if}
</div>
<div class="field">
- <label class="label" for="listing-contact-value"
- >Public contact details</label
- ><input
- id="listing-contact-value"
+ <label class="label" for="listing-currency">Currency</label><input
+ id="listing-currency"
+ aria-invalid={fieldError('currency') ? 'true' : undefined}
+ aria-errormessage={fieldError('currency')
+ ? 'listing-currency-error'
+ : undefined}
type="text"
- value={form.contactValue}
+ maxlength="3"
+ value={form.currency}
oninput={(event) => {
- form = { ...form, contactValue: event.currentTarget.value };
+ form = { ...form, currency: event.currentTarget.value };
changed();
}}
readonly={!visible.editable}
/>
+ {#if fieldError('currency')}<p id="listing-currency-error">
+ {fieldError('currency')?.message}
+ </p>{/if}
+ </div>
+ <div class="field">
+ <label class="label" for="listing-unit">Per</label><select
+ id="listing-unit"
+ aria-invalid={fieldError('unit') ? 'true' : undefined}
+ aria-errormessage={fieldError('unit')
+ ? 'listing-unit-error'
+ : undefined}
+ value={form.unit}
+ onchange={(event) => {
+ form = { ...form, unit: event.currentTarget.value };
+ changed();
+ }}
+ disabled={!visible.editable}
+ ><option value="">Choose a unit</option
+ >{#each foodUnits as unit (unit)}<option value={unit}
+ >{unit}</option
+ >{/each}</select
+ >
+ {#if fieldError('unit')}<p id="listing-unit-error">
+ {fieldError('unit')?.message}
+ </p>{/if}
</div>
</div>
- </details>
- </form>
+ <div class="field">
+ <label class="label" for="listing-quantity"
+ >Advertised quantity (optional)</label
+ >
+ <p id="listing-quantity-unit">
+ {form.unit || 'Uses the selected price unit'}
+ </p>
+ <input
+ id="listing-quantity"
+ aria-invalid={fieldError('quantity') ? 'true' : undefined}
+ aria-errormessage={fieldError('quantity')
+ ? 'listing-quantity-error'
+ : undefined}
+ type="text"
+ inputmode="decimal"
+ aria-describedby="listing-quantity-unit"
+ value={form.quantity}
+ oninput={(event) => {
+ form = { ...form, quantity: event.currentTarget.value };
+ changed();
+ }}
+ readonly={!visible.editable}
+ />
+ {#if fieldError('quantity')}<p id="listing-quantity-error">
+ {fieldError('quantity')?.message}
+ </p>{/if}
+ </div>
+ <details>
+ <summary>Add public contact details (optional)</summary>
+ <div class="stack">
+ <p>Only add contact details you want to include publicly.</p>
+ <div class="field">
+ <label class="label" for="listing-contact-type"
+ >Public contact type</label
+ ><select
+ id="listing-contact-type"
+ aria-invalid={fieldError('contactType') ? 'true' : undefined}
+ aria-errormessage={fieldError('contactType')
+ ? 'listing-contact-type-error'
+ : undefined}
+ value={form.contactType}
+ onchange={(event) => {
+ const value = event.currentTarget.value;
+ if (
+ value === '' ||
+ value === 'email' ||
+ value === 'phone' ||
+ value === 'https'
+ ) {
+ form = { ...form, contactType: value };
+ changed();
+ }
+ }}
+ disabled={!visible.editable}
+ ><option value="">No public contact</option><option
+ value="email">Email</option
+ ><option value="phone">Phone</option><option value="https"
+ >Website</option
+ ></select
+ >
+ {#if fieldError('contactType')}<p id="listing-contact-type-error">
+ {fieldError('contactType')?.message}
+ </p>{/if}
+ </div>
+ <div class="field">
+ <label class="label" for="listing-contact-value"
+ >Public contact details</label
+ ><input
+ id="listing-contact-value"
+ aria-invalid={fieldError('contactValue') ? 'true' : undefined}
+ aria-errormessage={fieldError('contactValue')
+ ? 'listing-contact-value-error'
+ : undefined}
+ type="text"
+ value={form.contactValue}
+ oninput={(event) => {
+ form = { ...form, contactValue: event.currentTarget.value };
+ changed();
+ }}
+ readonly={!visible.editable}
+ />
+ {#if fieldError('contactValue')}<p
+ id="listing-contact-value-error"
+ >
+ {fieldError('contactValue')?.message}
+ </p>{/if}
+ </div>
+ </div>
+ </details>
+ </form>
+ {#if visible.editable}<button
+ type="button"
+ onclick={showReview}
+ disabled={reviewBusy || closeBusy}
+ >{reviewBusy ? 'Preparing review' : 'Review listing'}</button
+ >{/if}
+ {/if}
+ {#if visible.editable && setup}<InboxSetup controller={setup} inline />{/if}
{#each visible.operations as operation (operation)}<OperationStatus
publicOperation={operation}
/>{/each}
{#if visible.editable}<button
type="button"
onclick={saveClose}
- disabled={closeBusy}>Save and close</button
+ disabled={closeBusy || reviewBusy}>Save and close</button
>{/if}
{#if navigationFailed}<Notice
tone="warning"
diff --git a/web/src/lib/components/ListingReview.svelte b/web/src/lib/components/ListingReview.svelte
@@ -0,0 +1,56 @@
+<script lang="ts">
+ import Notice from './Notice.svelte';
+ import {
+ editorReviewSnapshot,
+ type EditorReview
+ } from '../publishing/editor-workflow.ts';
+ let { review, onedit }: { review: EditorReview; onedit: () => void } =
+ $props();
+ const preview = $derived(editorReviewSnapshot(review));
+ function tag(name: string) {
+ return (
+ preview?.tags
+ .find((value) => value[0] === name)
+ ?.slice(1)
+ .join(' ') ?? ''
+ );
+ }
+</script>
+
+{#if preview}
+ <section class="stack" aria-label="Public listing review">
+ <h2 id="listing-review-heading" tabindex="-1">Public review</h2>
+ <p>Check the complete public listing before any signing or publication.</p>
+ <h3>{tag('title')}</h3>
+ <p class="description" id="listing-review-content">{preview.content}</p>
+ <dl>
+ <dt>Derived summary</dt>
+ <dd>{preview.summary}</dd>
+ <dt>Public area</dt>
+ <dd>{tag('location')}</dd>
+ <dt>Price</dt>
+ <dd>{tag('price')} per {tag('radroots:price_unit')}</dd>
+ {#if tag('radroots:quantity')}<dt>Advertised quantity</dt>
+ <dd>{tag('radroots:quantity')}</dd>{/if}
+ <dt>Publisher</dt>
+ <dd class="key">{preview.owner}</dd>
+ <dt>Public destinations</dt>
+ <dd>
+ <ul>
+ {#each preview.targets as target (target)}<li class="key">
+ {target}
+ </li>{/each}
+ </ul>
+ </dd>
+ </dl>
+ <p>Messages: ready to receive replies</p>
+ <p>This review has not requested a signature or published the listing.</p>
+ <button type="button" onclick={onedit}>Edit details</button>
+ </section>
+{:else}
+ <Notice
+ tone="warning"
+ text="This review is no longer current. Return to the current listing values."
+ />
+ <button type="button" onclick={onedit}>Edit details</button>
+{/if}
diff --git a/web/src/lib/publishing/editor-workflow.ts b/web/src/lib/publishing/editor-workflow.ts
@@ -0,0 +1,179 @@
+import {
+ exactLocalFields,
+ type PublicDraftForm
+} from '../contracts/local-records.ts';
+import {
+ buildFoodTemplate,
+ type FoodDraftErrorCode
+} from '../contracts/food-availability-v1/write.ts';
+import type { InboxSetupView } from '../messaging/inbox-setup-view.ts';
+import {
+ reviewListingEditor,
+ listingEditorReviewCurrent,
+ type ListingEditor
+} from './listing-editor.ts';
+import {
+ listingReviewSnapshot,
+ type ListingReview,
+ type ListingPreview
+} from './prepare-listing.ts';
+
+export type EditorFormError = Readonly<{
+ field: keyof PublicDraftForm;
+ message: string;
+}>;
+const fields = [
+ 'title',
+ 'description',
+ 'location',
+ 'amount',
+ 'currency',
+ 'unit',
+ 'quantity',
+ 'contactType',
+ 'contactValue'
+] as const;
+export function validateEditorForm(
+ input: PublicDraftForm
+): readonly EditorFormError[] {
+ try {
+ if (
+ !exactLocalFields(input, fields) ||
+ fields.some((field) => typeof input[field] !== 'string')
+ )
+ return [{ field: 'title', message: 'Keep all listing fields as text.' }];
+ if (input.contactType === '' && input.contactValue !== '')
+ return [
+ {
+ field: 'contactValue',
+ message: 'Choose a public contact type or remove the contact details.'
+ }
+ ];
+ const built = buildFoodTemplate({
+ identifier: '00000000-0000-4000-8000-000000000001',
+ created_at: 1,
+ published_at: 1,
+ status: 'active',
+ title: input.title,
+ description: input.description,
+ location: input.location,
+ amount: input.amount,
+ currency: input.currency,
+ unit: input.unit,
+ ...(input.quantity === '' ? {} : { quantity: input.quantity }),
+ ...(input.contactType === ''
+ ? {}
+ : {
+ contact: {
+ type: input.contactType,
+ value: input.contactValue,
+ public: true as const
+ }
+ })
+ });
+ if (built.ok) return [];
+ const messages: Partial<Record<FoodDraftErrorCode, EditorFormError>> = {
+ title_invalid: {
+ field: 'title',
+ message: 'Use a product name within the public text limit.'
+ },
+ location_invalid: {
+ field: 'location',
+ message: 'Use a public area within the text limit.'
+ },
+ description_invalid: {
+ field: 'description',
+ message: 'Add a complete description within the public text limit.'
+ },
+ summary_invalid: {
+ field: 'description',
+ message: 'Use supported public text in the description.'
+ },
+ price_invalid: {
+ field: 'amount',
+ message: 'Use a supported price, currency and price unit.'
+ },
+ quantity_invalid: {
+ field: 'quantity',
+ message: 'Use a supported advertised quantity in the selected unit.'
+ },
+ contact_invalid: {
+ field: 'contactValue',
+ message: 'Use supported public contact details for the selected type.'
+ }
+ };
+ return [
+ messages[built.error.code] ?? {
+ field: 'description',
+ message: 'The public listing exceeds its supported limits.'
+ }
+ ];
+ } catch {
+ return [
+ {
+ field: 'title',
+ message:
+ 'The listing fields could not be read. Keep your current input.'
+ }
+ ];
+ }
+}
+declare const reviewBrand: unique symbol;
+export type EditorReview = Readonly<{ [reviewBrand]: true }>;
+type Owned = Readonly<{ editor: ListingEditor; original: ListingReview }>;
+const reviews = new WeakMap<EditorReview, Owned>();
+export type EditorReviewSnapshot = ListingPreview &
+ Readonly<{ content: string; tags: readonly (readonly string[])[] }>;
+export async function openEditorReview(
+ editor: ListingEditor,
+ setup: InboxSetupView | undefined,
+ form: PublicDraftForm
+): Promise<
+ | Readonly<{ status: 'review'; review: EditorReview }>
+ | Readonly<{
+ status: 'blocked';
+ errors: readonly EditorFormError[];
+ message: string;
+ }>
+> {
+ const errors = validateEditorForm(form);
+ if (errors.length)
+ return {
+ status: 'blocked',
+ errors,
+ message: 'Check the linked fields. Your input remains here.'
+ };
+ const result = await reviewListingEditor(editor, setup, form);
+ if (
+ result.status !== 'review' ||
+ !listingEditorReviewCurrent(editor, result.review)
+ )
+ return {
+ status: 'blocked',
+ errors: [],
+ message:
+ result.status === 'blocked' && result.reason === 'unavailable'
+ ? 'Enable messages before reviewing this listing. Your draft remains in this browser.'
+ : 'The saved listing or account changed. Keep your input and review the current values again.'
+ };
+ const review = Object.freeze({}) as EditorReview;
+ reviews.set(review, { editor, original: result.review });
+ return { status: 'review', review };
+}
+export function editorReviewSnapshot(
+ review: EditorReview
+): EditorReviewSnapshot | undefined {
+ const owned = reviews.get(review);
+ if (!owned || !listingEditorReviewCurrent(owned.editor, owned.original))
+ return;
+ const preview = listingReviewSnapshot(owned.original);
+ if (!preview) return;
+ const wire = JSON.parse(preview.templateWire) as {
+ content: string;
+ tags: string[][];
+ };
+ return { ...preview, content: wire.content, tags: wire.tags };
+}
+export function closeEditorReview(review: EditorReview): void {
+ reviews.delete(review);
+}
diff --git a/web/src/lib/publishing/listing-editor.ts b/web/src/lib/publishing/listing-editor.ts
@@ -2,7 +2,20 @@ import {
exactLocalFields,
type PublicDraftForm
} from '../contracts/local-records.ts';
-import { canonicalLocalId } from '../private-handles.ts';
+import { canonicalLocalId, newLocalId } from '../private-handles.ts';
+import type { InboxSetupView } from '../messaging/inbox-setup-view.ts';
+import {
+ captureNewListingReadiness,
+ closeNewListingReadiness,
+ type NewListingReadiness
+} from './new-listing-readiness.ts';
+import {
+ reviewNewListing,
+ listingReviewSnapshot,
+ listingReviewOwnership,
+ type ListingReview,
+ type ListingReviewResult
+} from './prepare-listing.ts';
import { decodeProductReference } from '../nostr/references.ts';
import { inspectLocalTemplate } from '../nostr/local-template.ts';
import { projectFoodParts } from '../contracts/food-availability-v1/read.ts';
@@ -78,6 +91,11 @@ type Editor = Readonly<{
edit(form: unknown): Promise<boolean>;
flush(): Promise<boolean>;
saveClose(): Promise<boolean>;
+ review(
+ setup: InboxSetupView | undefined,
+ form: PublicDraftForm
+ ): Promise<ListingReviewResult>;
+ reviewCurrent(review: ListingReview): boolean;
subscribe(listener: () => void): () => void;
}>;
const editors = new WeakMap<ListingEditor, Editor>();
@@ -155,6 +173,20 @@ export async function openListingEditor(
repository: PublicDraftRepository | undefined,
controller: PublicDraftController | undefined;
const operations = new Map<string, ListingOperationView>();
+ let reviewed:
+ | {
+ setup: InboxSetupView | undefined;
+ proof: NewListingReadiness;
+ review: ListingReview;
+ }
+ | undefined;
+ let reviewing: Promise<ListingReviewResult> | undefined;
+ let reviewingForm: string | undefined;
+ let reviewingSetup: InboxSetupView | undefined;
+ function clearReview() {
+ if (reviewed) closeNewListingReadiness(reviewed.proof);
+ reviewed = undefined;
+ }
function current() {
return (
alive &&
@@ -187,6 +219,7 @@ export async function openListingEditor(
unsubscribe();
signal?.removeEventListener('abort', retire);
cancellation.abort();
+ clearReview();
if (controller) closePublicDraftController(controller);
for (const operation of operations.values())
closeListingOperationView(operation);
@@ -346,6 +379,26 @@ export async function openListingEditor(
}
}
if (!current()) return unavailable('source');
+ function reviewCurrent(review: ListingReview) {
+ const preview = listingReviewSnapshot(review),
+ local = controller && publicDraftControllerSnapshot(controller);
+ return !!(
+ current() &&
+ !closing &&
+ !operations.size &&
+ route &&
+ route.mode !== 'edit' &&
+ reviewed?.review === review &&
+ listingReviewOwnership(review)?.current() &&
+ preview &&
+ local?.state === 'saved' &&
+ local.draft &&
+ preview.owner === owner &&
+ preview.draftId === local.draft.id &&
+ preview.draftRevision === local.draft.revision &&
+ JSON.stringify(preview.form) === JSON.stringify(local.form)
+ );
+ }
const value: Editor = {
current,
retire,
@@ -381,6 +434,7 @@ export async function openListingEditor(
if (!controller || route.mode === 'edit' || operations.size)
return false;
if (!editPublicDraft(controller, input)) return false;
+ clearReview();
notify();
const pending = flushPublicDraft(controller);
await Promise.resolve();
@@ -454,6 +508,86 @@ export async function openListingEditor(
closing = false;
}
},
+ review(setup, input) {
+ const local = controller && publicDraftControllerSnapshot(controller);
+ if (
+ !current() ||
+ closing ||
+ !controller ||
+ !local ||
+ route.mode === 'edit' ||
+ operations.size ||
+ !exactLocalFields(input, Object.keys(emptyForm)) ||
+ JSON.stringify(input) !== JSON.stringify(local.form)
+ )
+ return Promise.resolve({
+ status: 'blocked',
+ reason: 'invalid_scope'
+ });
+ if (
+ reviewed &&
+ reviewed.setup === setup &&
+ reviewCurrent(reviewed.review)
+ )
+ return Promise.resolve({ status: 'review', review: reviewed.review });
+ const formWire = JSON.stringify(local.form);
+ if (reviewing)
+ return reviewingForm === formWire && reviewingSetup === setup
+ ? reviewing
+ : Promise.resolve({ status: 'blocked', reason: 'conflict' });
+ clearReview();
+ const proof = captureNewListingReadiness(
+ session,
+ setup,
+ 'reviewed_new_listing_inbox'
+ ),
+ command = newLocalId();
+ if (!proof || !command) {
+ if (proof) closeNewListingReadiness(proof);
+ return Promise.resolve({ status: 'blocked', reason: 'unavailable' });
+ }
+ const original = controller;
+ reviewingForm = formWire;
+ reviewingSetup = setup;
+ const pending = reviewNewListing(
+ publications,
+ original,
+ proof,
+ command,
+ 'reviewed_new_listing'
+ )
+ .then((result): ListingReviewResult => {
+ const actual = publicDraftControllerSnapshot(original);
+ if (
+ !current() ||
+ closing ||
+ !actual ||
+ JSON.stringify(actual.form) !== formWire ||
+ result.status !== 'review'
+ ) {
+ closeNewListingReadiness(proof);
+ return result.status === 'blocked'
+ ? result
+ : { status: 'blocked', reason: 'conflict' };
+ }
+ reviewed = { setup, proof, review: result.review };
+ if (!reviewCurrent(result.review)) {
+ clearReview();
+ return { status: 'blocked', reason: 'conflict' };
+ }
+ return result;
+ })
+ .finally(() => {
+ if (reviewing === pending) {
+ reviewing = undefined;
+ reviewingForm = undefined;
+ reviewingSetup = undefined;
+ }
+ });
+ reviewing = pending;
+ return pending;
+ },
+ reviewCurrent,
subscribe(listener) {
if (!current()) return () => {};
const key = Symbol();
@@ -498,3 +632,20 @@ export function subscribeListingEditor(
): () => void {
return editors.get(editor)?.subscribe(listener) ?? (() => {});
}
+// Original editor custody remains private. Review never reserves or signs.
+export function reviewListingEditor(
+ editor: ListingEditor,
+ setup: InboxSetupView | undefined,
+ form: PublicDraftForm
+): Promise<ListingReviewResult> {
+ return (
+ editors.get(editor)?.review(setup, form) ??
+ Promise.resolve({ status: 'blocked', reason: 'invalid_scope' })
+ );
+}
+export function listingEditorReviewCurrent(
+ editor: ListingEditor,
+ review: ListingReview
+): boolean {
+ return editors.get(editor)?.reviewCurrent(review) ?? false;
+}
diff --git a/web/tests/e2e/editor-workflow.spec.ts b/web/tests/e2e/editor-workflow.spec.ts
@@ -0,0 +1,295 @@
+import { expect, test } from '@playwright/test';
+import { build } from 'vite';
+import { svelte } from '@sveltejs/vite-plugin-svelte';
+import { fileURLToPath } from 'node:url';
+import { createStaticHarness } from '../integration/harness/static.ts';
+import type * as Fixture from './harness/editor-workflow.ts';
+import type { PublicDraftForm } from '../../src/lib/contracts/local-records.ts';
+declare global {
+ interface Window {
+ hcp117: typeof Fixture;
+ hcp117Fixture: Awaited<ReturnType<typeof Fixture.createFixture>>;
+ }
+}
+let server: Awaited<ReturnType<typeof createStaticHarness>>, bundle: string;
+const form: PublicDraftForm = {
+ title: 'Exact 菜 listing',
+ description:
+ ' ' + 'Complete public description 菜\r\n'.repeat(40) + ' final line ',
+ location: 'Town',
+ amount: '2.5',
+ currency: 'GBP',
+ unit: 'kg',
+ quantity: '3',
+ contactType: 'email',
+ contactValue: 'public@example.org'
+};
+test.beforeAll(async () => {
+ server = await createStaticHarness();
+ const built = await build({
+ configFile: false,
+ plugins: [svelte({ configFile: false })],
+ resolve: { conditions: ['browser'] },
+ logLevel: 'silent',
+ build: {
+ write: false,
+ minify: false,
+ lib: {
+ entry: fileURLToPath(
+ new URL('./harness/editor-workflow.ts', import.meta.url)
+ ),
+ name: 'hcp117',
+ formats: ['iife']
+ }
+ }
+ });
+ const result = Array.isArray(built) ? built[0] : built;
+ if (!('output' in result)) throw Error('actual review bundle missing');
+ const chunks = result.output.filter((row) => row.type === 'chunk');
+ expect(chunks).toHaveLength(1);
+ bundle = chunks[0].code;
+});
+test.afterAll(async () => {
+ await server?.close();
+});
+test.beforeEach(async ({ page }) => {
+ await page.addInitScript(() => {
+ window.WebSocket = class extends WebSocket {
+ constructor() {
+ super(
+ (() => {
+ throw Error('HCP117 no live relay permission');
+ })()
+ );
+ }
+ };
+ });
+ await page.goto(server.url + '/search');
+ await page.addScriptTag({ content: bundle });
+});
+test.afterEach(async ({ page }) => {
+ await page.evaluate(async () => {
+ await window.hcp117Fixture?.close();
+ });
+});
+test('HCP117 exact immutable full outgoing template and destinations review does not publish', async ({
+ page
+}) => {
+ const result = await page.evaluate(async (form) => {
+ const f = (window.hcp117Fixture = await window.hcp117.createFixture());
+ await f.open();
+ await f.edit(form);
+ const before = f.counts(),
+ a = await f.review(form),
+ b = await f.review(form);
+ return {
+ a,
+ b,
+ before,
+ after: f.counts(),
+ rows: await f.inspect(),
+ copied: f.snapshot(true)
+ };
+ }, form);
+ expect(result.a.status).toBe('review');
+ expect(result.b).toEqual(result.a);
+ if (result.a.status !== 'review' || !result.a.snapshot)
+ throw Error('genuine exact preview missing');
+ const wire = JSON.parse(result.a.snapshot.templateWire) as {
+ content: string;
+ tags: string[][];
+ pubkey: string;
+ };
+ expect(wire.content).toBe(
+ form.description.replaceAll('\r\n', '\n').trim() +
+ '\n\nPublic contact: mailto:public@example.org'
+ );
+ expect(result.a.snapshot.content).toBe(wire.content);
+ expect(result.a.snapshot.summary.length).toBeLessThanOrEqual(240);
+ expect(result.a.snapshot.content.length).toBeGreaterThan(1000);
+ expect(result.a.snapshot.owner).toBe(wire.pubkey);
+ expect(result.a.snapshot.targets).toEqual(['wss://discovery.example.org']);
+ expect(wire.tags.find((tag) => tag[0] === 'summary')?.[1]).toBe(
+ result.a.snapshot.summary
+ );
+ expect(result.rows.operations).toHaveLength(0);
+ expect(result.rows.drafts).toHaveLength(1);
+ expect(result.after.signs).toBe(result.before.signs);
+ expect(result.copied).toBeUndefined();
+});
+test('HCP117 copy stale form changed draft and revoked readiness never retain review custody', async ({
+ page
+}) => {
+ const result = await page.evaluate(async (form) => {
+ const f = (window.hcp117Fixture = await window.hcp117.createFixture());
+ await f.open();
+ await f.edit(form);
+ const copied = await f.review(form, true),
+ stale = await f.review({ ...form, title: 'not saved' });
+ const original = await f.review(form);
+ await f.edit({ ...form, title: 'new saved values' });
+ const afterEdit = f.snapshot();
+ const next = await f.review({ ...form, title: 'new saved values' });
+ f.stop();
+ return {
+ copied,
+ stale,
+ original,
+ afterEdit,
+ next,
+ afterStop: f.snapshot(),
+ rows: await f.inspect()
+ };
+ }, form);
+ expect(result.copied.status).toBe('blocked');
+ expect(result.stale.status).toBe('blocked');
+ expect(result.original.status).toBe('review');
+ expect(result.next.status).toBe('review');
+ expect(result.afterEdit).toBeUndefined();
+ expect(result.afterStop).toBeUndefined();
+ expect(result.rows.operations).toHaveLength(0);
+});
+test('HCP117 unqualified inbox blocks disclosure while saving the complete draft remains available', async ({
+ page
+}) => {
+ const result = await page.evaluate(async (form) => {
+ const f = (window.hcp117Fixture = await window.hcp117.createFixture(false));
+ await f.open();
+ const saved = await f.edit(form),
+ reviewed = await f.review(form);
+ return {
+ saved,
+ reviewed,
+ rows: await f.inspect(),
+ signs: f.counts().signs
+ };
+ }, form);
+ expect(result.saved).toBe(true);
+ expect(result.reviewed.status).toBe('blocked');
+ expect(result.rows.drafts).toHaveLength(1);
+ expect(result.rows.operations).toHaveLength(0);
+ expect(result.signs).toBe(0);
+});
+for (const width of [320, 1024]) {
+ test(`HCP117 ${width}px same-route full review and Edit details preserve exact raw values and focus`, async ({
+ page
+ }) => {
+ await page.setViewportSize({ width, height: 900 });
+ await page.evaluate(async () => {
+ window.hcp117Fixture = await window.hcp117.createFixture();
+ window.hcp117Fixture.render();
+ });
+ await expect(page.locator('#listing-title')).toBeVisible();
+ for (const [field, value] of Object.entries(form)) {
+ const id =
+ '#listing-' +
+ (
+ {
+ contactType: 'contact-type',
+ contactValue: 'contact-value'
+ } as Record<string, string>
+ )[field];
+ const selector = field.startsWith('contact') ? id : '#listing-' + field;
+ if (field === 'contactType') {
+ await page
+ .getByText('Add public contact details (optional)', { exact: true })
+ .click();
+ await page.locator(selector).selectOption(value);
+ } else if (field === 'contactValue')
+ await page.locator(selector).fill(value);
+ else if (field === 'unit')
+ await page.locator(selector).selectOption(value);
+ else await page.locator(selector).fill(value);
+ }
+ const originalURL = page.url();
+ await page
+ .getByRole('button', { name: 'Review listing', exact: true })
+ .click();
+ await expect(
+ page.getByRole('heading', { name: 'Public review', exact: true })
+ ).toBeVisible();
+ await expect(page.locator('#listing-review-content')).toHaveText(
+ form.description.replaceAll('\r\n', '\n').trim() +
+ '\n\nPublic contact: mailto:public@example.org',
+ { useInnerText: false }
+ );
+ expect(await page.locator('#listing-review-content').textContent()).toBe(
+ form.description.replaceAll('\r\n', '\n').trim() +
+ '\n\nPublic contact: mailto:public@example.org'
+ );
+ await expect(page.locator('#listing-title')).toHaveCount(0);
+ expect(page.url()).toBe(originalURL);
+ await expect(
+ page.getByRole('button', { name: 'Publish', exact: true })
+ ).toHaveCount(0);
+ await page
+ .getByRole('button', { name: 'Edit details', exact: true })
+ .click();
+ await expect(page.locator('#listing-title')).toBeFocused();
+ await expect(page.locator('#listing-title')).toHaveValue(form.title);
+ await expect(page.locator('#listing-description')).toHaveValue(
+ form.description.replaceAll('\r\n', '\n')
+ );
+ await expect(page.locator('#listing-amount')).toHaveValue(form.amount);
+ await expect(page.locator('#listing-contact-value')).toHaveValue(
+ form.contactValue
+ );
+ for (const [field, value] of Object.entries(form)) {
+ const id =
+ { contactType: 'contact-type', contactValue: 'contact-value' }[
+ field as 'contactType' | 'contactValue'
+ ] ?? field;
+ await expect(page.locator('#listing-' + id)).toHaveValue(
+ value.replaceAll('\r\n', '\n')
+ );
+ }
+ expect(
+ (await page.evaluate(() => window.hcp117Fixture.inspect())).operations
+ ).toHaveLength(0);
+ expect(
+ await page.evaluate(
+ () => document.documentElement.scrollWidth <= innerWidth
+ )
+ ).toBe(true);
+ });
+ test(`HCP117 ${width}px linked inline errors preserve input and refuse stale saved content`, async ({
+ page
+ }) => {
+ await page.setViewportSize({ width, height: 900 });
+ await page.evaluate(async () => {
+ window.hcp117Fixture = await window.hcp117.createFixture();
+ window.hcp117Fixture.render();
+ });
+ const title = page.locator('#listing-title');
+ await expect(title).toBeVisible();
+ await title.fill('raw retained title');
+ await page.locator('#listing-description').fill(' raw\n菜 description ');
+ await page.locator('#listing-location').fill(form.location);
+ await page.locator('#listing-currency').fill(form.currency);
+ await page.locator('#listing-unit').selectOption(form.unit);
+ await page.locator('#listing-amount').fill('2,50');
+ await page
+ .getByRole('button', { name: 'Review listing', exact: true })
+ .click();
+ await expect(page.locator('#listing-review-errors')).toBeVisible();
+ await expect(page.locator('#listing-amount')).toHaveAttribute(
+ 'aria-invalid',
+ 'true'
+ );
+ await expect(page.locator('#listing-review-errors a')).toHaveAttribute(
+ 'href',
+ '#listing-amount'
+ );
+ await expect(title).toHaveValue('raw retained title');
+ await expect(page.locator('#listing-description')).toHaveValue(
+ ' raw\n菜 description '
+ );
+ await expect(page.locator('#listing-amount')).toHaveValue('2,50');
+ await expect(
+ page.getByRole('heading', { name: 'Public review', exact: true })
+ ).toHaveCount(0);
+ expect(
+ (await page.evaluate(() => window.hcp117Fixture.inspect())).operations
+ ).toHaveLength(0);
+ });
+}
diff --git a/web/tests/e2e/harness/editor-workflow.ts b/web/tests/e2e/harness/editor-workflow.ts
@@ -0,0 +1,121 @@
+// HC_TEST_ONLY_QUALIFICATION_PORT: genuine production owners/native IndexedDB
+// with controlled exercised inbox observations, never live extension/relay Q.
+import { mount, unmount } from 'svelte';
+import ListingEditor from '../../../src/lib/components/ListingEditor.svelte';
+import { makeSetupFixture, fixturePolicy, inbox } from './inbox-setup.ts';
+import { inspectNative } from './listing-editor.ts';
+import {
+ createIdentityViewContext,
+ mountIdentityView,
+ connectIdentityView,
+ probeIdentityViewMessaging,
+ identityViewSession,
+ closeIdentityView,
+ disconnectIdentityView,
+ IDENTITY_VIEW_CONTEXT
+} from '../../../src/lib/runtime/view-context.ts';
+import {
+ createInboxSetupView,
+ checkInboxSetupView,
+ unlockInboxSetupView,
+ stopInboxSetupView,
+ closeInboxSetupView
+} from '../../../src/lib/messaging/inbox-setup-view.ts';
+import {
+ openListingEditor,
+ editListingEditor,
+ listingEditorSnapshot,
+ closeListingEditor,
+ type ListingEditor as Editor
+} from '../../../src/lib/publishing/listing-editor.ts';
+import {
+ openEditorReview,
+ editorReviewSnapshot,
+ closeEditorReview,
+ type EditorReview
+} from '../../../src/lib/publishing/editor-workflow.ts';
+import type { PublicDraftForm } from '../../../src/lib/contracts/local-records.ts';
+export async function createFixture(qualified = true) {
+ const f = await makeSetupFixture([['relay', inbox]]),
+ context = createIdentityViewContext();
+ mountIdentityView(context);
+ await connectIdentityView(context);
+ await probeIdentityViewMessaging(context, 'reviewed_self_copy');
+ const identity = identityViewSession(context);
+ if (!identity) throw Error('original editor session unavailable');
+ const setup = createInboxSetupView({
+ identity,
+ policy: fixturePolicy(),
+ lookup: () => Promise.resolve(f.resolve().resolver),
+ ...(qualified
+ ? {
+ observeAccess: (
+ value: import('../../../src/lib/messaging/readiness.ts').OwnInboxAccessContext
+ ) => ({
+ ...value,
+ readTargets: value.readTargets.slice(),
+ archiveTargets: value.archiveTargets.slice(),
+ receive: 'qualified_exercised' as const,
+ archive: 'qualified_exercised' as const,
+ current: () => true
+ })
+ }
+ : {})
+ });
+ if (!setup) throw Error('original inbox setup unavailable');
+ await checkInboxSetupView(setup);
+ await unlockInboxSetupView(setup);
+ let editor: Editor | undefined, review: EditorReview | undefined;
+ let mounted: ReturnType<typeof mount> | undefined,
+ target: HTMLElement | undefined;
+ return {
+ owner: f.owner,
+ counts: f.counts,
+ inspect: inspectNative,
+ async open() {
+ const result = await openListingEditor(context, { mode: 'new' });
+ if (result.status !== 'ready') throw Error(result.reason);
+ editor = result.editor;
+ return listingEditorSnapshot(editor);
+ },
+ edit: (form: PublicDraftForm) =>
+ editor ? editListingEditor(editor, form) : Promise.resolve(false),
+ async review(form: PublicDraftForm, copied = false) {
+ if (!editor) throw Error('original editor unavailable');
+ const result = await openEditorReview(
+ copied ? { ...editor } : editor,
+ setup,
+ form
+ );
+ if (result.status === 'review') review = result.review;
+ return result.status === 'review'
+ ? {
+ status: result.status,
+ snapshot: editorReviewSnapshot(result.review)
+ }
+ : result;
+ },
+ snapshot: (copied = false) =>
+ review && editorReviewSnapshot(copied ? { ...review } : review),
+ stop: () => stopInboxSetupView(setup),
+ disconnect: () => disconnectIdentityView(context),
+ render() {
+ target = document.createElement('div');
+ document.body.append(target);
+ mounted = mount(ListingEditor, {
+ target,
+ props: { route: { mode: 'new' }, inboxController: setup },
+ context: new Map([[IDENTITY_VIEW_CONTEXT, context]])
+ });
+ },
+ async close() {
+ if (mounted) await unmount(mounted);
+ target?.remove();
+ if (review) closeEditorReview(review);
+ if (editor) closeListingEditor(editor);
+ closeInboxSetupView(setup);
+ closeIdentityView(context);
+ f.close();
+ }
+ };
+}
diff --git a/web/tests/provenance/output.test.mjs b/web/tests/provenance/output.test.mjs
@@ -1298,7 +1298,9 @@ import { auditOutput } from '../../tools/check-output.mjs';
'src/routes/selling/drafts/[draftId=local_id]/+page.svelte',
'src/routes/products/[naddr=naddr]/edit/+page.svelte',
'src/lib/components/ListingEditor.svelte',
- 'src/lib/publishing/listing-editor.ts'
+ 'src/lib/publishing/listing-editor.ts',
+ 'src/lib/components/ListingReview.svelte',
+ 'src/lib/publishing/editor-workflow.ts'
]) {
await check(
'listing editor rejects changed owned producer ' + producer,
diff --git a/web/tests/unit/editor-workflow.test.ts b/web/tests/unit/editor-workflow.test.ts
@@ -0,0 +1,67 @@
+import { expect, it } from 'vitest';
+import { render } from 'svelte/server';
+import ListingEditor from '../../src/lib/components/ListingEditor.svelte';
+import ListingReview from '../../src/lib/components/ListingReview.svelte';
+import {
+ validateEditorForm,
+ editorReviewSnapshot,
+ closeEditorReview,
+ type EditorReview
+} from '../../src/lib/publishing/editor-workflow.ts';
+
+const form = {
+ title: '菜',
+ description: ' Complete\r\npublic description 菜 ',
+ location: 'Town',
+ amount: '2.5',
+ currency: 'GBP',
+ unit: 'kg',
+ quantity: '3',
+ contactType: '' as const,
+ contactValue: ''
+};
+it('HCP117 validation preserves raw values and uses the exact Food writer bounds', () => {
+ const before = JSON.stringify(form);
+ expect(validateEditorForm(form)).toEqual([]);
+ expect(JSON.stringify(form)).toBe(before);
+ for (const [change, field] of [
+ [{ title: 'x'.repeat(161) }, 'title'],
+ [{ description: ' ' }, 'description'],
+ [{ description: '菜'.repeat(6000) }, 'description'],
+ [{ amount: '2,50' }, 'amount'],
+ [{ amount: '2.50' }, 'amount'],
+ [{ quantity: '03' }, 'quantity'],
+ [{ contactValue: 'unapproved private contact' }, 'contactValue'],
+ [
+ { contactType: 'https', contactValue: 'javascript:alert(1)' },
+ 'contactValue'
+ ]
+ ] as const) {
+ const input = { ...form, ...change };
+ const original = JSON.stringify(input);
+ expect(validateEditorForm(input)[0]?.field).toBe(field);
+ expect(JSON.stringify(input)).toBe(original);
+ }
+});
+it('HCP117 copied display values cannot mint a review or disclose a fabricated template', () => {
+ const fake = {
+ owner: 'a'.repeat(64),
+ content: 'FABRICATED_PUBLIC_REVIEW'
+ } as unknown as EditorReview;
+ expect(editorReviewSnapshot(fake)).toBeUndefined();
+ closeEditorReview(fake);
+ const html = render(ListingReview, {
+ props: { review: fake, onedit: () => {} }
+ }).body;
+ expect(html).not.toContain('FABRICATED_PUBLIC_REVIEW');
+ expect(html).not.toMatch(/Publish|<form|<input|<textarea/);
+});
+it('HCP117 SSR connection gate exposes no protected review or inbox effects', () => {
+ const html = render(ListingEditor, {
+ props: { route: { mode: 'new' } }
+ }).body;
+ expect(html).toContain('Connect to continue');
+ expect(html).not.toMatch(
+ /Review listing|Public review|Inbox setup|<form|<textarea|<input/
+ );
+});
diff --git a/web/tools/check-output.mjs b/web/tools/check-output.mjs
@@ -622,17 +622,50 @@ async function listingEditorAdmission(web) {
'src/lib/publishing/listing-editor.ts':
'9d7ea3f905188ab807b1779c2c0856e39a82cfe598bd071da33fabad66796012'
};
+ /** @type {Record<string,string>} */
+ const reviewProducers = {
+ 'src/routes/sell/+page.svelte':
+ '97f22f9a0309621e9acb5f1b328d3376bc9c5affbe5a7ea1b85ece76097b9c08',
+ 'src/routes/selling/drafts/[draftId=local_id]/+page.svelte':
+ '1df59a753fbef2bc2ebf77890a79cbd3d7a5bb0dcef34c219df1b5e8043cf787',
+ 'src/routes/products/[naddr=naddr]/edit/+page.svelte':
+ '09c3a6bde766045319cd36a00a82ca565f9f3b5cd5322982be9482836f312998',
+ 'src/lib/components/ListingEditor.svelte':
+ '8be89452b0bfd50ff907efcf38873ef1b4007440464836db8b1ff2bc552b97ff',
+ 'src/lib/publishing/listing-editor.ts':
+ 'f781a9b028f4f441514bfb8622767c365b0425e7083acfd8deaaba57dc0b7dab',
+ 'src/lib/components/ListingReview.svelte':
+ 'bf4e6bf0fc76fa12672fabc441e1058d73c1f281a0a560aeafbdaa2aa36f6f90',
+ 'src/lib/publishing/editor-workflow.ts':
+ '5bc8827c5ff167e0974f03a87e4e9db350e42f30c511f199b785c30ad365d838'
+ };
let historical = true,
- current = true;
+ current = true,
+ reviewed = true;
for (const [name, pin] of Object.entries(producers)) {
const bytes = await readOwned(web, name);
publicText(bytes);
const actual = createHash('sha256').update(bytes).digest('hex');
historical = historical && actual === pin;
current = current && actual === continuity[name];
+ reviewed = reviewed && actual === reviewProducers[name];
}
- if (!historical && !current)
+ if (reviewed) {
+ for (const name of [
+ 'src/lib/components/ListingReview.svelte',
+ 'src/lib/publishing/editor-workflow.ts'
+ ]) {
+ const bytes = await readOwned(web, name);
+ publicText(bytes);
+ reviewed =
+ reviewed &&
+ createHash('sha256').update(bytes).digest('hex') ===
+ reviewProducers[name];
+ }
+ }
+ if (!historical && !current && !reviewed)
throw new Error('Invalid owned listing editor source');
+ if (reviewed) return 'review';
if (current) return 'continuity';
return true;
}
@@ -829,7 +862,9 @@ export async function auditOutput(webDirectory) {
const hasListingEditor = hasFullRoutes && (await listingEditorAdmission(web));
if (hasListingEditor && !(hasListingPublication && hasInboxSetup))
throw new Error('Invalid owned listing editor runtime authority');
- const hasListingContinuity = hasListingEditor === 'continuity';
+ const hasListingReview = hasListingEditor === 'review';
+ const hasListingContinuity =
+ hasListingEditor === 'continuity' || hasListingReview;
const identityCompilerModule = hasListingEditor
? 'view-context'
: hasInboxSetup
@@ -2596,6 +2631,21 @@ export async function auditOutput(webDirectory) {
imports: ['view-context', 'public-runtime']
}
};
+ if (hasListingReview)
+ expected.ListingEditor = {
+ file: '_app/immutable/chunks/HASH.js',
+ name: 'ListingEditor',
+ imports: [
+ 'public-key',
+ 'public-runtime',
+ 'references',
+ 'client',
+ 'Button',
+ 'CapabilityGate',
+ 'InboxSetup',
+ 'read'
+ ]
+ };
for (const record of Object.values(manifest)) {
const actual = { ...record };
actual.file = actual.file.includes('/chunks/')