← back to Designer Wallcoverings
Add activated-items viewer: live Shopify pull, grouped by activation date with image+SKU, sort+density (shopify/activated-viewer :9846)
afcf25ff21eced830f957e43b69116af5d82b0f9 · 2026-06-20 09:45:45 -0700 · Steve
Files touched
A shopify/activated-viewer/.gitignoreA shopify/activated-viewer/public/index.htmlA shopify/activated-viewer/server.js
Diff
commit afcf25ff21eced830f957e43b69116af5d82b0f9
Author: Steve <steve@designerwallcoverings.com>
Date: Sat Jun 20 09:45:45 2026 -0700
Add activated-items viewer: live Shopify pull, grouped by activation date with image+SKU, sort+density (shopify/activated-viewer :9846)
---
shopify/activated-viewer/.gitignore | 3 +
shopify/activated-viewer/public/index.html | 136 +++++++++++++++++++++++++++++
shopify/activated-viewer/server.js | 71 +++++++++++++++
3 files changed, 210 insertions(+)
diff --git a/shopify/activated-viewer/.gitignore b/shopify/activated-viewer/.gitignore
new file mode 100644
index 00000000..2e8157a9
--- /dev/null
+++ b/shopify/activated-viewer/.gitignore
@@ -0,0 +1,3 @@
+node_modules/
+.env
+*.log
diff --git a/shopify/activated-viewer/public/index.html b/shopify/activated-viewer/public/index.html
new file mode 100644
index 00000000..2b69053a
--- /dev/null
+++ b/shopify/activated-viewer/public/index.html
@@ -0,0 +1,136 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+<title>DW — Activated Items by Date</title>
+<style>
+ :root{ --ink:#1b1b1b; --muted:#6b6b6b; --line:#e6e6e6; --bg:#f5f4f1; --card:#fff; --accent:#1f6f54; --cols:260px; }
+ *{box-sizing:border-box}
+ body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:var(--ink)}
+ header{position:sticky;top:0;z-index:10;background:#fff;border-bottom:1px solid var(--line);padding:12px 20px;display:flex;align-items:center;gap:16px;flex-wrap:wrap}
+ header h1{font-size:18px;margin:0;font-weight:800;letter-spacing:-.3px}
+ header .meta{font-size:12.5px;color:var(--muted)}
+ .controls{margin-left:auto;display:flex;align-items:center;gap:18px;flex-wrap:wrap}
+ .controls label{font-size:12px;color:var(--muted);font-weight:700;display:flex;align-items:center;gap:7px}
+ select,button{font-family:inherit;font-size:13px;border:1px solid var(--line);border-radius:8px;padding:7px 11px;background:#fff;cursor:pointer}
+ button:hover{background:#f0f0ee}
+ input[type=range]{accent-color:var(--accent)}
+ .wrap{padding:18px 20px 60px;max-width:1500px;margin:0 auto}
+ .daygroup{margin-bottom:26px}
+ .dayhd{display:flex;align-items:baseline;gap:10px;margin:0 2px 12px;padding-bottom:7px;border-bottom:2px solid var(--line)}
+ .dayhd b{font-size:16px}
+ .dayhd span{font-size:12.5px;color:var(--muted);font-weight:700}
+ .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(var(--cols),1fr));gap:14px}
+ .card{background:var(--card);border:1px solid var(--line);border-radius:12px;overflow:hidden;display:flex;flex-direction:column;transition:box-shadow .15s}
+ .card:hover{box-shadow:0 4px 16px rgba(0,0,0,.10)}
+ .thumb{aspect-ratio:1/1;background:#eee center/cover no-repeat;position:relative}
+ .thumb.none{display:grid;place-items:center;color:#bbb;font-size:12px}
+ .body{padding:10px 12px 12px;display:flex;flex-direction:column;gap:6px;flex:1}
+ .title{font-size:13.5px;font-weight:600;line-height:1.3;color:#222;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
+ .sku{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--accent);font-weight:700;word-break:break-all}
+ .when{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:5px;margin-top:auto}
+ .links{display:flex;gap:8px;margin-top:4px}
+ .links a{font-size:11.5px;font-weight:700;color:var(--accent);text-decoration:none}
+ .links a:hover{text-decoration:underline}
+ .empty,.loading{padding:60px;text-align:center;color:var(--muted)}
+ .pill{background:#eef3f0;color:var(--accent);font-size:11px;font-weight:700;border-radius:10px;padding:2px 8px}
+</style>
+</head>
+<body>
+<header>
+ <h1>🟢 Activated Items</h1>
+ <div class="meta" id="meta">loading…</div>
+ <div class="controls">
+ <label>Sort
+ <select id="sort">
+ <option value="newest">Newest activated</option>
+ <option value="oldest">Oldest activated</option>
+ <option value="title">Title A→Z</option>
+ <option value="sku">SKU A→Z</option>
+ </select>
+ </label>
+ <label>Density <input type="range" id="density" min="160" max="360" step="20" /></label>
+ <button id="refresh">↻ Refresh</button>
+ </div>
+</header>
+<div class="wrap"><div id="out" class="loading">Loading activated items from the live store…</div></div>
+
+<script>
+let ITEMS = [], STORE = '';
+const $ = s => document.querySelector(s);
+const sortSel = $('#sort'), density = $('#density');
+
+// persisted controls (standing rule)
+sortSel.value = localStorage.getItem('av-sort') || 'newest';
+density.value = localStorage.getItem('av-density') || '260';
+applyDensity();
+sortSel.onchange = () => { localStorage.setItem('av-sort', sortSel.value); render(); };
+density.oninput = () => { localStorage.setItem('av-density', density.value); applyDensity(); };
+function applyDensity(){ document.documentElement.style.setProperty('--cols', density.value + 'px'); }
+
+$('#refresh').onclick = () => load(true);
+
+function fmtDate(iso){
+ if(!iso) return '—';
+ return new Date(iso).toLocaleString(undefined, { year:'numeric', month:'short', day:'numeric', hour:'numeric', minute:'2-digit' });
+}
+function dayKey(iso){ return iso ? new Date(iso).toLocaleDateString(undefined,{year:'numeric',month:'long',day:'numeric',weekday:'short'}) : 'Unknown date'; }
+
+function card(it){
+ const adminUrl = `https://${STORE}/admin/products/${it.id}`;
+ const pdp = `https://designerwallcoverings.com/products/${it.handle}`;
+ const thumb = it.image
+ ? `<div class="thumb" style="background-image:url('${it.image}&width=400')"></div>`
+ : `<div class="thumb none">no image</div>`;
+ return `<div class="card">
+ ${thumb}
+ <div class="body">
+ <div class="sku">${it.sku || it.handle || '—'}</div>
+ <div class="title">${it.title}</div>
+ <div class="when" title="${it.activated || ''}">🕓 ${fmtDate(it.activated)}</div>
+ <div class="links"><a href="${pdp}" target="_blank">Store ↗</a><a href="${adminUrl}" target="_blank">Admin ↗</a></div>
+ </div>
+ </div>`;
+}
+
+function render(){
+ const mode = sortSel.value;
+ let items = ITEMS.slice();
+ if(mode==='title') items.sort((a,b)=> (a.title||'').localeCompare(b.title||''));
+ else if(mode==='sku') items.sort((a,b)=> (a.sku||a.handle||'').localeCompare(b.sku||b.handle||''));
+ else items.sort((a,b)=> mode==='oldest' ? new Date(a.activated)-new Date(b.activated) : new Date(b.activated)-new Date(a.activated));
+
+ const out = $('#out');
+ if(!items.length){ out.className='empty'; out.textContent='No activated items found.'; return; }
+ out.className='';
+
+ if(mode==='newest' || mode==='oldest'){
+ // group by activation date
+ const groups = [];
+ let cur = null;
+ for(const it of items){ const k = dayKey(it.activated); if(!cur || cur.k!==k){ cur={k, items:[]}; groups.push(cur);} cur.items.push(it); }
+ out.innerHTML = groups.map(g=>`<div class="daygroup">
+ <div class="dayhd"><b>${g.k}</b><span class="pill">${g.items.length} activated</span></div>
+ <div class="grid">${g.items.map(card).join('')}</div>
+ </div>`).join('');
+ } else {
+ out.innerHTML = `<div class="grid">${items.map(card).join('')}</div>`;
+ }
+}
+
+async function load(refresh){
+ $('#out').className='loading'; $('#out').textContent='Loading…';
+ const r = await fetch('/api/activated' + (refresh?'?refresh=1':''));
+ const j = await r.json();
+ ITEMS = j.items || []; STORE = j.store || '';
+ const days = new Set(ITEMS.map(i=>dayKey(i.activated))).size;
+ $('#meta').innerHTML = j.error
+ ? `<span style="color:#b00">⚠ ${j.error}</span>`
+ : `${j.count} active items · ${days} days · ${j.store} · fetched ${fmtDate(new Date(j.fetchedAt).toISOString())}`;
+ render();
+}
+load(false);
+</script>
+</body>
+</html>
diff --git a/shopify/activated-viewer/server.js b/shopify/activated-viewer/server.js
new file mode 100644
index 00000000..4f7cccb3
--- /dev/null
+++ b/shopify/activated-viewer/server.js
@@ -0,0 +1,71 @@
+'use strict';
+// Activated-items viewer — pulls recently-ACTIVATED products from the LIVE DW Shopify
+// store (published_at = activation date) and serves a date-grouped grid with image + SKU.
+// Read-only: only GETs from Shopify. Token read from ../.env (never logged).
+const http = require('http');
+const fs = require('fs');
+const path = require('path');
+
+// load ../.env (the shopify project env) without a dep
+for (const envPath of [path.join(__dirname, '..', '.env'), path.join(__dirname, '.env')]) {
+ if (fs.existsSync(envPath)) for (const line of fs.readFileSync(envPath, 'utf8').split('\n')) {
+ const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/); if (m && !process.env[m[1]]) process.env[m[1]] = m[2].replace(/^["']|["']$/g, '');
+ }
+}
+const STORE = process.env.SHOPIFY_STORE || 'designer-laboratory-sandbox.myshopify.com';
+const TOKEN = process.env.SHOPIFY_ADMIN_TOKEN;
+const VER = process.env.SHOPIFY_API_VERSION || '2024-10';
+const PORT = process.env.PORT || 9846;
+const MAX_PAGES = Number(process.env.MAX_PAGES || 4); // 4×250 = up to 1000 most-recent active
+
+let cache = { at: 0, data: null, err: null };
+const TTL = 5 * 60 * 1000;
+
+async function fetchActivated() {
+ if (!TOKEN) throw new Error('SHOPIFY_ADMIN_TOKEN not set');
+ const out = [];
+ let url = `https://${STORE}/admin/api/${VER}/products.json?status=active&limit=250&order=created_at+desc&fields=id,title,handle,status,created_at,published_at,variants,image`;
+ for (let p = 0; p < MAX_PAGES && url; p++) {
+ const r = await fetch(url, { headers: { 'X-Shopify-Access-Token': TOKEN } });
+ if (!r.ok) throw new Error('shopify ' + r.status + ' ' + (await r.text()).slice(0, 120));
+ const j = await r.json();
+ for (const pr of j.products || []) {
+ const v = (pr.variants && pr.variants[0]) || {};
+ out.push({
+ id: pr.id, title: pr.title, handle: pr.handle,
+ sku: v.sku || '', price: v.price || '',
+ image: (pr.image && pr.image.src) || '',
+ published_at: pr.published_at, created_at: pr.created_at,
+ activated: pr.published_at || pr.created_at
+ });
+ }
+ const link = r.headers.get('link') || '';
+ const m = link.match(/<([^>]+)>;\s*rel="next"/);
+ url = m ? m[1] : null;
+ }
+ out.sort((a, b) => new Date(b.activated) - new Date(a.activated));
+ return out;
+}
+
+async function getData(force) {
+ if (!force && cache.data && Date.now() - cache.at < TTL) return cache;
+ try { cache = { at: Date.now(), data: await fetchActivated(), err: null }; }
+ catch (e) { cache = { at: Date.now(), data: cache.data, err: e.message }; }
+ return cache;
+}
+
+http.createServer(async (req, res) => {
+ const u = new URL(req.url, 'http://localhost');
+ if (u.pathname === '/api/activated') {
+ const c = await getData(u.searchParams.get('refresh') === '1');
+ res.writeHead(c.data ? 200 : 502, { 'Content-Type': 'application/json' });
+ return res.end(JSON.stringify({ store: STORE, fetchedAt: c.at, error: c.err, count: c.data ? c.data.length : 0, items: c.data || [] }));
+ }
+ if (u.pathname === '/' || u.pathname === '/index.html') {
+ return fs.readFile(path.join(__dirname, 'public', 'index.html'), (e, b) => {
+ if (e) { res.writeHead(500); return res.end('missing index.html'); }
+ res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(b);
+ });
+ }
+ res.writeHead(404); res.end('not found');
+}).listen(PORT, () => console.log(`Activated viewer → http://localhost:${PORT} (store ${STORE}, v${VER})`));
← 8d58a8d4 cadence wrapper: refund unused upload grant on 429/exit-3 +
·
back to Designer Wallcoverings
·
Activated viewer: GraphQL feed with essentials audit (priced c14beea5 →