Publish, edit, renew and delete listings from the web UI

- Form at #/mine/new and #/mine/<id>/edit: coordinates pasted and encoded
  to a precision-6 geohash in the browser (about 1 km, OSM link to check, no
  map tiles), euro price parsing, optional exact address saved on the node only
- Region guard: refuses places the node does not follow; region fixed on edit
- Owner view: days left with a warning under 5 days, manual Renew (30 days),
  Edit, Delete with confirmation
- Tests (jsdom and pure logic), docs, rebuilt web/dist

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:18:08 +01:00
co-authored by Claude Sonnet 5.5
parent 7348067350
commit d021989f09
16 changed files with 1846 additions and 87 deletions
+30 -1
View File
@@ -5,7 +5,9 @@
// in sessionStorage only, so closing the tab signs the owner out, and it is only
// ever sent to the node that served this page.
import { HttpError } from "./api.ts";
import { HttpError, getListing } from "./api.ts";
import { MAX_LIFETIME_DAYS, draftFromListing, type Draft } from "./draft.ts";
import type { Listing } from "./verify.ts";
const TOKEN_KEY = "allmende.owner.token";
let memory: string | null = null;
@@ -172,3 +174,30 @@ export async function putAddress(listing: string, a: Address): Promise<void> {
export async function deleteAddress(listing: string): Promise<void> {
await call("DELETE", `/api/v1/listings/${e(listing)}/address`);
}
/** Publishes a new listing. The node signs it and mines its proof-of-work, which takes a few seconds. */
export async function createListing(d: Draft): Promise<Listing> {
return (await call("POST", "/api/v1/listings", d)) as Listing;
}
/** Replaces one of your listings (a new version of it). The region cannot change. */
export async function updateListing(id: string, d: Draft): Promise<Listing> {
return (await call("PUT", `/api/v1/listings/${e(id)}`, d)) as Listing;
}
/** Withdraws a listing: publishes a deletion marker that outlives every older copy. */
export async function deleteListing(id: string): Promise<void> {
await call("DELETE", `/api/v1/listings/${e(id)}`);
}
/** Your own listing as the node has it, or null if it is gone. */
export async function getOwnListing(author: string, id: string): Promise<Listing | null> {
return (await getListing(author, id)) as Listing | null;
}
/** Publishes the listing again for a fresh term, otherwise unchanged. */
export async function renewListing(author: string, id: string, days = MAX_LIFETIME_DAYS): Promise<Listing> {
const l = await getOwnListing(author, id);
if (!l || l.tombstone) throw new HttpError(404, "no such listing of yours");
return updateListing(id, draftFromListing(l, days));
}