PolyWood Price Builder

Widget Catalog

Component Scope

src/lib/s3-widgets.ts manages widget manifests in S3. src/app/widgets/page.tsx is the read-only UI viewer.

Storage Keys

Under <rulesPrefix>/widgets:

  • index.json tracks widget IDs and update timestamp.
  • <widgetId>.json stores each widget manifest.

Runtime Behavior

  • On read, ensureDefaultWidgetsInS3 guarantees all DEFAULT_WIDGETS exist in storage and in index.json.
  • ensureDefaultWidgetsInS3 also removes deprecated defaults (price.roundUpMultiple, price.roundDownMultiple) from S3 and from index metadata.
  • listWidgetsFromS3 reads index, loads manifests, validates them, sorts by category/title, and caches results for ~10 seconds.
  • saveWidgetToS3 validates and persists a widget, then updates index if needed.

Validation Highlights

  • Widget ID format: ^[A-Za-z0-9][A-Za-z0-9._-]{1,80}$.
  • Fields must be valid number or select descriptors.
  • Engine kinds supported:
    • multiply
    • percentAdjust
    • marginFromCost
    • roundNearest9
    • roundNearest5
  • Widget field keys must be unique within a widget.

API Exposure

Current route surface only exposes read:

  • GET /api/widgets -> listWidgetsFromS3

saveWidgetToS3 exists in library code but is not currently wired to a route.