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 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ The build:

## Selling

Products come straight from your Square catalog. Add items in Square Dashboard > Items & services, with a price and a photo. They appear on the shop within a minute. Shop prices and tax are always calculated by Square on the server.
Products come straight from your Square catalog. Every product upload—in Square Dashboard > Items & services or via `scripts/load-items.mjs`—must include:
- **Price** and **photo(s)** (first photo upright/vertical as the primary thumbnail)
- **Category** (e.g. `Bowls`, `Plates & dishes`, `Vases`, `Mugs`, `Sets`; `/p/<id>` maps this automatically to both your shop `product_type` and Google's official `CategoryCode` taxonomy)
- **Dimensions on line 1 of Description** (`size` in batch JSON, e.g. `"9½″ × 3¾″"` for round pieces or `"14″ × 9″ × 1½″"` for oblong slabs; parsed into `depth` / `width` / `height` in inches for Google Merchant Center)
- **Item weight (lb)** custom attribute (`item_lb` in Square, `itemLb` or `itemOz` in batch JSON): the unpacked scale weight of the piece itself, emitted as `Product.weight` (`product_weight` in Google)
- **Ship weight (lb)** custom attribute (`ship_lb` in Square, `shipLb` in batch JSON): the billed weight of the packed double-boxed parcel, used by checkout and emitted as `OfferShippingDetails.weight` (`shipping_weight` in Google)

**Naming & descriptions for search:** Square item names become `/p/<id>` `<h1>` headings and `<title>` tags, and the first line of the Square description becomes the spec line and search snippet. Favor specific, plain-language names (e.g. `"Celadon porcelain mug, 12 oz"` or `"Soda-fired stoneware vase"`) and put clay body, glaze, and dimensions on line 1 (`"Cone 10 stoneware · Tacoma crackle 26 · 9½″ × 3¾″"`). Batch files for `scripts/load-items.mjs` accept optional `clay`, `glaze`, and `description` fields at both the batch and item level.
Items appear on the shop within a minute. Shop prices and tax are always calculated by Square on the server.

**Shipping** is priced per piece, from the delivery ZIP: one double-boxed parcel per piece, at the published label price for its billed weight and zone from Tacoma, rounded up to whole dollars (`backend/src/shipping.mjs`). UPS Ground carries everything it can; USPS Ground Advantage takes PO boxes, military addresses, Alaska, Hawaii and the territories. Each item needs a **Ship weight (lb)** custom attribute in Square: the billed weight of the packed box (the larger of actual and dimensional weight, from the pack-and-ship planner). An item without one can be picked up but not shipped. Rates and zones live in `backend/src/shipping-rates.json`; update it when UPS or USPS change prices (USPS holiday prices end 2027-01-17; the UPS fuel surcharge changes weekly).
**Naming & descriptions for search:** Square item names become `/p/<id>` `<h1>` headings and `<title>` tags, and the first line of the Square description becomes the spec line and search snippet. Favor specific, plain-language names (e.g. `"Celadon porcelain mug, 12 oz"` or `"Soda-fired stoneware vase"`) and put clay body, glaze, and dimensions on line 1 (`"Cone 10 stoneware · Tacoma crackle 26 · 9½″ × 3¾″"`). Batch files for `scripts/load-items.mjs` and `scripts/update-items.mjs` accept `clay`, `glaze`, `size`, `description`, `category`, `itemLb` (or `itemOz`), and `shipLb`.

**Shipping (both item weight and shipping weight required on every upload):** Shipping is priced per piece from the delivery ZIP: one double-boxed parcel per piece, at the published label price for its **Ship weight (lb)** and zone from Tacoma, rounded up to whole dollars (`backend/src/shipping.mjs`). Both shop checkout and Google Merchant Center's weight-based shipping table require **Ship weight (lb)** (`ship_lb`), while Google Merchant Center's product spec separately uses **Item weight (lb)** (`item_lb`); an item without `Ship weight (lb)` is pickup only. Run `node scripts/ship-weight-attribute.mjs` (or `load-items.mjs` / `update-items.mjs`) once per Square account to create both custom attributes. UPS Ground carries everything it can; USPS Ground Advantage takes PO boxes, military addresses, Alaska, Hawaii and the territories. Rates and zones live in `backend/src/shipping-rates.json`; update it when UPS or USPS change prices (USPS holiday prices end 2027-01-17; the UPS fuel surcharge changes weekly).

## Email signup

Expand Down
14 changes: 9 additions & 5 deletions backend/src/catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import { SQUARE_LOCATION_ID, square, onSquareReset } from "./config.mjs";
import { applyRecentSales, stockOf, soldLines } from "./stock.mjs";

// Billed shipping weight in lb of one packed piece: a catalog custom attribute on the item, set when
// the piece is listed (see README.md, "Selling"). A piece without one can't be shipped, only picked up.
// Packed shipping weight (ship_lb) and unpacked item scale weight (item_lb), stored as Square
// custom attributes on each item (see scripts/ship-weight-attribute.mjs and README.md, "Selling").
// A piece without ship_lb can't be shipped, only picked up; item_lb feeds Product.weight for Google.
export const SHIP_LB_KEY = "ship_lb";
const shipLbOf = (item) => {
const v = Object.values(item.customAttributeValues ?? {}).find((x) => x?.key === SHIP_LB_KEY);
export const ITEM_LB_KEY = "item_lb";
const numberAttr = (item, key) => {
const v = Object.values(item.customAttributeValues ?? {}).find((x) => x?.key === key);
const lb = Number(v?.numberValue);
return lb > 0 ? lb : null;
};
Expand Down Expand Up @@ -48,7 +50,8 @@ export async function loadCatalog() {
.filter((o) => o.type === "ITEM" && !o.isDeleted && o.itemData?.productType !== "APPOINTMENTS_SERVICE")
.filter((o) => !o.itemData.isArchived)
.map((o) => {
const shipLb = shipLbOf(o);
const shipLb = numberAttr(o, SHIP_LB_KEY);
const itemLb = numberAttr(o, ITEM_LB_KEY);
return {
id: o.id,
name: o.itemData.name,
Expand All @@ -57,6 +60,7 @@ export async function loadCatalog() {
images: (o.itemData.imageIds ?? []).map((id) => images.get(id)).filter(Boolean), // in the order set in Square
category: categoryOf(o.itemData),
...(shipLb ? { shipLb } : {}),
...(itemLb ? { itemLb } : {}),
updatedAt: o.updatedAt ?? null, // the pieces' sitemap (piece-page.mjs)
variations: (o.itemData.variations ?? [])
.filter((v) => v.itemVariationData?.priceMoney)
Expand Down
161 changes: 133 additions & 28 deletions backend/src/piece-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,41 +82,135 @@ function picture(url, { alt, sizes, widths, eager }) {
const FRACTIONS = { "¼": 0.25, "½": 0.5, "¾": 0.75, "⅛": 0.125, "⅜": 0.375, "⅝": 0.625, "⅞": 0.875 };
const toInches = (whole, dec, frac) => (dec ? Number(`${whole}.${dec}`) : Number(whole) + (FRACTIONS[frac] ?? 0));
const qvIn = (n) => ({ "@type": "QuantitativeValue", value: +n.toFixed(3), unitCode: "INH" });
const qvLb = (n) => ({ "@type": "QuantitativeValue", value: +Number(n).toFixed(2), unitCode: "LBR" });

/** Parses dimensions (e.g. "9½″ × 3¾″" or "5½″ wide × 3″ tall") from a piece's spec line, in inches. */
export const GOOGLE_TAXONOMY = "https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt";

/** Maps a studio piece to Google's official Product Taxonomy (ID + full path) for Merchant Center. */
export function googleCategoryFor(item) {
if (item.googleCategory?.codeValue && item.googleCategory?.name) return item.googleCategory;
const cat = String(item.category ?? "").trim();
const name = String(item.name ?? "").trim();
const desc = String(item.description ?? "");
if (/\bcoasters?\b/i.test(name) || /^coasters$/i.test(cat))
return { codeValue: "2363", name: "Home & Garden > Kitchen & Dining > Barware > Coasters" };
if (/^vases$/i.test(cat) || /\bvases?\b/i.test(name)) return { codeValue: "602", name: "Home & Garden > Decor > Vases" };
if (/^planters$/i.test(cat) || /\b(planters?|flower\s*pots?)\b/i.test(name))
return { codeValue: "721", name: "Home & Garden > Lawn & Garden > Gardening > Pots & Planters" };
if (/^(mugs|cups|drinkware)$/i.test(cat) || /\b(mugs?|cups?|tumblers?|yunomi|chawan)\b/i.test(name))
return { codeValue: "2169", name: "Home & Garden > Kitchen & Dining > Tableware > Drinkware > Mugs" };
if (/\b(pitchers?|creamers?|carafes?|ewers?)\b/i.test(name) || /^pitchers$/i.test(cat))
return { codeValue: "3330", name: "Home & Garden > Kitchen & Dining > Tableware > Serveware > Serving Pitchers & Carafes" };
if (/\b(platters?|trays?)\b/i.test(name) || /^platters$/i.test(cat))
return { codeValue: "3802", name: "Home & Garden > Kitchen & Dining > Tableware > Serveware > Serving Platters" };
if (/^plates/i.test(cat) || /\b(plates?|dishes?|saucers?)\b/i.test(name))
return { codeValue: "3553", name: "Home & Garden > Kitchen & Dining > Tableware > Dinnerware > Plates" };
if (/^bowls$/i.test(cat) || /\bbowls?\b/i.test(name)) {
return /\b(raku|decorative\s+only|not\s+food\s+safe)\b/i.test(desc)
? { codeValue: "6457", name: "Home & Garden > Decor > Decorative Bowls" }
: { codeValue: "3498", name: "Home & Garden > Kitchen & Dining > Tableware > Dinnerware > Bowls" };
}
if (/^sets$/i.test(cat))
return { codeValue: "5537", name: "Home & Garden > Kitchen & Dining > Tableware > Dinnerware > Dinnerware Sets" };
return { codeValue: "11", name: "Home & Garden > Decor > Artwork > Sculptures & Statues" };
}

function parseInchToken(raw) {
const s = raw.trim();
if (!s || s.length > 32) return null;
const m = s.match(
/^(\d{1,2})(?:\.(\d{1,2})|\s*([¼½¾⅛⅜⅝⅞]))?\s*(?:[″"]|\bin(?:ches)?\b)?\s*(long|length|deep|depth|wide|width|across|diameter|tall|high|height)?$/i,
);
if (!m) return null;
const n = toInches(m[1], m[2], m[3]);
return n > 0 ? { n, label: (m[4] ?? "").toLowerCase() } : null;
}

const axisOf = (label) => {
if (label === "long" || label === "length" || label === "deep" || label === "depth") return "depth";
if (label === "wide" || label === "width" || label === "across" || label === "diameter") return "width";
if (label === "tall" || label === "high" || label === "height") return "height";
return "";
};

/**
* Parses 3D product dimensions ({ depth, width, height } in inches; Schema.org depth = Google product_length)
* from explicit item.dimensions or the piece's spec line (e.g. "9½″ × 3¾″", "14″ × 9″ × 1½″",
* "7¼″, 7¾″ and 8″ × 4½″, set of 3", or "5½″ across, set of 3").
*/
export function parseDimensions(item) {
const explicit = item.dimensions;
const base = {};
if (explicit && typeof explicit === "object") {
const d = Number(explicit.depth ?? explicit.length);
const w = Number(explicit.width);
const h = Number(explicit.height);
if (d > 0) base.depth = d;
if (w > 0) base.width = w;
if (h > 0) base.height = h;
if (base.depth && base.width && base.height) return base;
}
const spec = specLine(item.description);
if (!spec) return {};
if (!spec) return base;
for (const raw of spec.split("·")) {
const seg = raw.trim();
if (!seg || seg.length > 60 || /,|\band\b|\bset\b/i.test(seg)) continue;
const pair = seg.match(
/^(\d{1,2})(?:\.(\d{1,2})|([¼½¾⅛⅜⅝⅞]))?\s*[″"]\s*(wide|across|tall|high)?\s*[×x]\s*(\d{1,2})(?:\.(\d{1,2})|([¼½¾⅛⅜⅝⅞]))?\s*[″"]\s*(wide|across|tall|high)?$/i,
);
if (pair) {
const a = toInches(pair[1], pair[2], pair[3]);
const la = (pair[4] ?? "").toLowerCase();
const b = toInches(pair[5], pair[6], pair[7]);
const lb = (pair[8] ?? "").toLowerCase();
if (!(a > 0 && b > 0)) return {};
const tallFirst =
la === "tall" ||
la === "high" ||
lb === "wide" ||
lb === "across" ||
(!la && !lb && (item.category === "Vases" || /\b(vase|bottle|pitcher|ewer|cylinder|tower)\b/i.test(item.name ?? "")));
return tallFirst ? { height: a, width: b } : { width: a, height: b };
const seg = raw
.trim()
.replace(/(?:,|\s)\s*\(?set of \d+\)?$/i, "")
.trim();
if (!seg || seg.length > 80 || !/[″"]|\bin(?:ches)?\b/i.test(seg) || /\b(oz|ml|lb|kg|cone)\b/i.test(seg)) continue;
const parts = seg.split(/\s*[×x]\s*/);
if (parts.length === 3) {
const toks = parts.map(parseInchToken);
if (toks.every(Boolean)) {
/** @type {{ depth?: number, width?: number, height?: number }} */
const out = {};
const rest = [];
for (const t of toks) {
const ax = axisOf(t.label);
if (ax === "depth" && !out.depth) out.depth = t.n;
else if (ax === "width" && !out.width) out.width = t.n;
else if (ax === "height" && !out.height) out.height = t.n;
else rest.push(t.n);
}
if (!out.depth && rest.length) out.depth = rest.shift();
if (!out.width && rest.length) out.width = rest.shift();
if (!out.height && rest.length) out.height = rest.shift();
return { ...out, ...base };
}
}
if (parts.length === 2) {
const a = parseInchToken(parts[0]);
const b = parseInchToken(parts[1]);
if (a && b) {
const axA = axisOf(a.label);
const axB = axisOf(b.label);
if (axA === "depth" && axB === "width") return { depth: a.n, width: b.n, ...base };
if (axA === "width" && axB === "depth") return { width: a.n, depth: b.n, ...base };
const tallFirst =
axA === "height" ||
axB === "width" ||
(!axA && !axB && (item.category === "Vases" || /\b(vase|bottle|pitcher|ewer|cylinder|tower)\b/i.test(item.name ?? "")));
const [diam, height] = tallFirst ? [b.n, a.n] : [a.n, b.n];
return { depth: diam, width: diam, height, ...base };
}
// Nested / multi-piece sets such as "7¼″, 7¾″ and 8″ × 4½″": largest outer diameter × height.
const list = parts[0].split(/\s*,\s*|\s+and\s+/i).map(parseInchToken);
if (list.length > 1 && list.every(Boolean) && b) {
const diam = Math.max(...list.map((t) => t.n));
return { depth: diam, width: diam, height: b.n, ...base };
}
}
const single = seg.match(/^(\d{1,2})(?:\.(\d{1,2})|([¼½¾⅛⅜⅝⅞]))?\s*[″"]\s*(wide|across)$/i);
if (single) {
const w = toInches(single[1], single[2], single[3]);
return w > 0 ? { width: w } : {};
if (parts.length === 1) {
const single = parseInchToken(parts[0]);
if (single && (!single.label || axisOf(single.label) === "width")) {
return { depth: single.n, width: single.n, ...base };
}
}
}
return {};
return base;
}

/** OfferShippingDetails for one parcel (WA Zone 3 + US Zone 8 ceiling), or doesNotShip when pickup-only. */
/** OfferShippingDetails for one parcel (WA Zone 3 + US Zone 8 ceiling + packed weight), or doesNotShip when pickup-only. */
function shippingDetailsFor(shipLb) {
if (!(shipLb > 0)) {
return {
Expand All @@ -134,9 +228,11 @@ function shippingDetailsFor(shipLb) {
const us = maxForZone(8);
if (wa === null || us === null) return null;
const handlingTime = { "@type": "QuantitativeValue", minValue: 1, maxValue: 2, unitCode: "DAY" };
const weight = qvLb(shipLb);
return [
{
"@type": "OfferShippingDetails",
weight,
shippingRate: { "@type": "MonetaryAmount", value: wa.toFixed(2), currency: "USD" },
shippingDestination: { "@type": "DefinedRegion", addressCountry: "US", addressRegion: "WA" },
deliveryTime: {
Expand All @@ -147,6 +243,7 @@ function shippingDetailsFor(shipLb) {
},
{
"@type": "OfferShippingDetails",
weight,
shippingRate: { "@type": "MonetaryAmount", value: us.toFixed(2), currency: "USD" },
shippingDestination: { "@type": "DefinedRegion", addressCountry: "US" },
deliveryTime: {
Expand All @@ -163,6 +260,13 @@ export function structuredData(item, site) {
const url = `${site}/p/${item.id}`;
const many = item.variations.length > 1;
const dims = parseDimensions(item);
const gpc = googleCategoryFor(item);
const categoryCode = {
"@type": "CategoryCode",
name: gpc.name,
codeValue: gpc.codeValue,
inCodeSet: GOOGLE_TAXONOMY,
};
const delivery =
item.shipLb > 0 ? ["https://schema.org/OnSitePickup", "https://schema.org/ParcelService"] : ["https://schema.org/OnSitePickup"];
const shippingDetails = shippingDetailsFor(item.shipLb);
Expand All @@ -183,12 +287,13 @@ export function structuredData(item, site) {
url,
sku: item.id,
image: photosOf(item).map((p) => site + sized(p, 1200, "jpeg")),
...(item.category ? { category: item.category } : {}),
category: item.category ? [item.category, categoryCode] : categoryCode,
material: materialOf(item),
countryOfOrigin: "US",
...(dims.depth ? { depth: qvIn(dims.depth) } : {}),
...(dims.width ? { width: qvIn(dims.width) } : {}),
...(dims.height ? { height: qvIn(dims.height) } : {}),
...(item.shipLb > 0 ? { weight: { "@type": "QuantitativeValue", value: item.shipLb, unitCode: "LBR" } } : {}),
...(item.itemLb > 0 ? { weight: qvLb(item.itemLb) } : {}),
creator: { "@type": "Person", "@id": `${site}/about.html#aaron`, name: "Aaron Filson" },
brand: { "@type": "Brand", name: SITE_NAME },
offers: item.variations.map((v) => ({
Expand Down
Loading
Loading