@blamejs/blamejs-shop 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
8
8
 
9
9
  ## v0.1.x
10
10
 
11
+ - v0.1.7 (2026-05-25) — **Admin console — persistent navigation and a products screen.** The admin is now a cohesive, navigable web console rather than a set of disconnected pages. A persistent nav (Home, Dashboard, Products, Integrations, Setup) runs across every signed-in page, and Products is the first full management screen: browse the catalog, create a product, and archive or restore one — all from the browser. The JSON API is unchanged: an endpoint serves the HTML console to a signed-in browser and JSON to a bearer-token client, so tooling keeps working exactly as before. **Added:** *Console navigation* — Every signed-in admin page shares a top nav with the current section highlighted, so the dashboard, products, integrations, and setup wizard are one console. The shell is the same brand-matched layout as the dashboard. · *Products management screen* — `/admin/products` renders the catalog as a table (title, slug, status) with Archive / Restore actions and a New-product form, when opened in a signed-in browser. The same path returns the existing JSON list to a bearer-token client; create, archive, and restore content-negotiate the same way (browser form → redirect; bad input re-renders with a notice, never a 500). The product create / archive / restore JSON API is unchanged.
12
+
11
13
  - v0.1.6 (2026-05-25) — **Claim past guest orders when a shopper signs in.** A shopper who checked out as a guest and later signs in with a provider-verified email now finds those past orders attached to their account. Checkout records a hash of the buyer's email on the order; on Google sign-in, orders placed under that same email — and not yet owned by anyone — are claimed into the account. Linking happens only on an email the identity provider verified, never on an unverified one, so it can't be used to steal another shopper's order history. **Added:** *Guest-order reconciliation on sign-in* — Orders now carry a `customer_email_hash` (migration 0206), written at checkout from the buyer's email with the same key the customers table uses. On a verified Google sign-in, `order.linkGuestOrdersByEmailHash` claims every ownerless order under that email into the account — so prior guest purchases appear in /account and satisfy customer-scoped checks (e.g. verified-buyer reviews). Only ownerless orders are touched (an order already attached to a customer is never reassigned), and only a provider-verified email triggers a link.
12
14
 
13
15
  - v0.1.5 (2026-05-25) — **Tell operators how to turn each integration on.** Every third-party integration (Stripe card checkout, Apple/Google Pay, Sign in with Google) is off by default and only activates when you supply its credentials. This release documents exactly what to set for each — in the README, in a new .env.example, and in the admin console itself. A signed-in operator opens /admin/integrations to see, at a glance, which integrations are live and the precise environment variables (or one-time action) needed to enable the rest. Nothing is enabled without your keys. **Added:** *Admin integrations status page* — `/admin/integrations` lists each integration with a live Enabled / Not configured status and the exact variables or action to turn it on — Stripe keys, the payment-method-domain registration for wallets, the Google OAuth client + redirect URI. Read-only; secrets are never rendered. Linked from the admin landing. · *Operator setup docs* — A README "Optional integrations" section and a top-level `.env.example` enumerate every environment variable, what capability it unlocks, and the external setup (e.g. the Google OAuth redirect URI, the Stripe webhook path). Both note that Apple sign-in + PayPal are planned and that Shop Pay / "Sign in with Shop" isn't available to a self-hosted store.
package/lib/admin.js CHANGED
@@ -235,6 +235,24 @@ function mount(router, deps) {
235
235
  return _wrap(h, { expectedToken: expectedToken });
236
236
  };
237
237
 
238
+ // Content-negotiate one endpoint between the JSON API and the HTML
239
+ // console: a bearer token routes to `apiHandler` (the JSON contract,
240
+ // unchanged for tooling); a browser admin-cookie session routes to
241
+ // `htmlHandler` (the rendered console page). Unauthenticated GETs show
242
+ // the sign-in form; other methods bounce to /admin.
243
+ function _pageOrApi(isGet, apiHandler, htmlHandler) {
244
+ return async function (req, res) {
245
+ if (_authOk(_readBearer(req), expectedToken)) return apiHandler(req, res);
246
+ // Mirror _htmlAuthed: a missing vault makes the cookie check throw;
247
+ // treat that as "not authed" rather than 500-ing the route.
248
+ var cookieOk = false;
249
+ try { cookieOk = _adminCookieValid(req); } catch (_e) { cookieOk = false; }
250
+ if (cookieOk) return htmlHandler(req, res);
251
+ if (isGet) return _sendHtml(res, 200, renderAdminLogin({ shop_name: deps.shop_name }));
252
+ return _redirect(res, "/admin");
253
+ };
254
+ }
255
+
238
256
  function _json(res, status, obj) {
239
257
  res.status(status);
240
258
  if (res.setHeader) res.setHeader("content-type", "application/json; charset=utf-8");
@@ -244,11 +262,31 @@ function mount(router, deps) {
244
262
 
245
263
  // ---- products -------------------------------------------------------
246
264
 
247
- router.post("/admin/products", W("product.create", async function (req, res) {
248
- var p = await catalog.products.create(req.body || {});
249
- _json(res, 201, p);
250
- return p;
251
- }));
265
+ router.post("/admin/products", _pageOrApi(false,
266
+ W("product.create", async function (req, res) {
267
+ var p = await catalog.products.create(req.body || {});
268
+ _json(res, 201, p);
269
+ return p;
270
+ }),
271
+ async function (req, res) {
272
+ // Browser form submit — create, then redirect (PRG). Bad input
273
+ // re-renders the products page with a notice, never a 500.
274
+ try {
275
+ await catalog.products.create(req.body || {});
276
+ } catch (e) {
277
+ if (e instanceof TypeError || e.code === "CATALOG_DUPLICATE" || /slug|exists|duplicate/i.test(e.message || "")) {
278
+ var page = await catalog.products.list({ limit: 100 });
279
+ return _sendHtml(res, 400, renderAdminProducts({
280
+ shop_name: deps.shop_name, products: page.rows || [],
281
+ notice: (e && e.message) || "Couldn't create that product.",
282
+ }));
283
+ }
284
+ throw e;
285
+ }
286
+ _b().audit.safeEmit({ action: AUDIT_NAMESPACE + ".product.create", outcome: "success", metadata: {} });
287
+ _redirect(res, "/admin/products?created=1");
288
+ },
289
+ ));
252
290
 
253
291
  router.get("/admin/products/search", R(async function (req, res) {
254
292
  var url = req.url ? new URL(req.url, "http://localhost") : null;
@@ -269,15 +307,23 @@ function mount(router, deps) {
269
307
  _json(res, 200, page);
270
308
  }));
271
309
 
272
- router.get("/admin/products", R(async function (req, res) {
273
- var url = req.url ? new URL(req.url, "http://localhost") : null;
274
- var status = url && url.searchParams.get("status");
275
- var cursor = url && url.searchParams.get("cursor");
276
- var limitS = url && url.searchParams.get("limit");
277
- var limit = limitS == null ? 50 : parseInt(limitS, 10);
278
- var page = await catalog.products.list({ status: status || undefined, cursor: cursor || undefined, limit: limit });
279
- _json(res, 200, page);
280
- }));
310
+ router.get("/admin/products", _pageOrApi(true,
311
+ R(async function (req, res) {
312
+ var url = req.url ? new URL(req.url, "http://localhost") : null;
313
+ var status = url && url.searchParams.get("status");
314
+ var cursor = url && url.searchParams.get("cursor");
315
+ var limitS = url && url.searchParams.get("limit");
316
+ var limit = limitS == null ? 50 : parseInt(limitS, 10);
317
+ var page = await catalog.products.list({ status: status || undefined, cursor: cursor || undefined, limit: limit });
318
+ _json(res, 200, page);
319
+ }),
320
+ async function (req, res) {
321
+ var url = req.url ? new URL(req.url, "http://localhost") : null;
322
+ var created = !!(url && url.searchParams.get("created"));
323
+ var page = await catalog.products.list({ limit: 100 });
324
+ _sendHtml(res, 200, renderAdminProducts({ shop_name: deps.shop_name, products: page.rows || [], created: created }));
325
+ },
326
+ ));
281
327
 
282
328
  router.get("/admin/products/:id", R(async function (req, res) {
283
329
  var p = await catalog.products.get(req.params.id);
@@ -292,19 +338,26 @@ function mount(router, deps) {
292
338
  return p;
293
339
  }));
294
340
 
295
- router.post("/admin/products/:id/archive", W("product.archive", async function (req, res) {
296
- var p = await catalog.products.archive(req.params.id);
297
- if (!p) return _problem(res, 404, "product-not-found");
298
- _json(res, 200, p);
299
- return p;
300
- }));
301
-
302
- router.post("/admin/products/:id/restore", W("product.restore", async function (req, res) {
303
- var p = await catalog.products.restore(req.params.id);
304
- if (!p) return _problem(res, 404, "product-not-found");
305
- _json(res, 200, p);
306
- return p;
307
- }));
341
+ function _productStateAction(verb, op, audit) {
342
+ return _pageOrApi(false,
343
+ W(audit, async function (req, res) {
344
+ var p = await op(req.params.id);
345
+ if (!p) return _problem(res, 404, "product-not-found");
346
+ _json(res, 200, p);
347
+ return p;
348
+ }),
349
+ async function (req, res) {
350
+ // A bad/missing id is a no-op (fall through to the list); a real
351
+ // failure must NOT be reported as success — let it surface.
352
+ try { await op(req.params.id); }
353
+ catch (e) { if (!(e instanceof TypeError)) throw e; }
354
+ _b().audit.safeEmit({ action: AUDIT_NAMESPACE + "." + audit, outcome: "success", metadata: { id: req.params.id } });
355
+ _redirect(res, "/admin/products");
356
+ },
357
+ );
358
+ }
359
+ router.post("/admin/products/:id/archive", _productStateAction("archive", function (id) { return catalog.products.archive(id); }, "product.archive"));
360
+ router.post("/admin/products/:id/restore", _productStateAction("restore", function (id) { return catalog.products.restore(id); }, "product.restore"));
308
361
 
309
362
  // ---- variants -------------------------------------------------------
310
363
 
@@ -1189,6 +1242,11 @@ var DASHBOARD_LAYOUT =
1189
1242
  " .banner--ok { background:#e9f5ec; border:1px solid #bfe1c9; color:#1f6b3a; }\n" +
1190
1243
  " .banner--err { background:#fff1eb; border:1px solid #f6c5af; color:var(--accent-d); }\n" +
1191
1244
  " .actions-row { display:flex; gap:.75rem; flex-wrap:wrap; align-items:center; margin-top:1.5rem; }\n" +
1245
+ " .admin-nav { background:var(--paper); border-bottom:1px solid var(--hair); }\n" +
1246
+ " .admin-nav__inner { max-width:80rem; margin:0 auto; padding:0 1.5rem; display:flex; gap:.1rem; flex-wrap:wrap; }\n" +
1247
+ " .admin-nav a { display:inline-block; padding:.85rem .9rem; color:var(--ink-2); text-decoration:none; font-size:.84rem; font-weight:600; border-bottom:2px solid transparent; }\n" +
1248
+ " .admin-nav a:hover { color:var(--ink); }\n" +
1249
+ " .admin-nav a.active { color:var(--accent); border-bottom-color:var(--accent); }\n" +
1192
1250
  " </style>\n" +
1193
1251
  "</head>\n" +
1194
1252
  "<body>\n" +
@@ -1198,6 +1256,7 @@ var DASHBOARD_LAYOUT =
1198
1256
  " <span style=\"font-size:.8rem; color:var(--mute);\">{{window_label}}</span>\n" +
1199
1257
  " </div>\n" +
1200
1258
  " </header>\n" +
1259
+ " {{nav}}\n" +
1201
1260
  " <main>{{body}}</main>\n" +
1202
1261
  "</body>\n" +
1203
1262
  "</html>\n";
@@ -1326,12 +1385,12 @@ function renderDashboard(opts) {
1326
1385
 
1327
1386
  var body = statsBlock + otherCurrencies + spark + twoCol;
1328
1387
 
1329
- var html = _renderTemplate(DASHBOARD_LAYOUT, {
1330
- shop_name: opts.shop_name || "blamejs.shop",
1331
- window_label: "Window: last 30 days (operator-tunable via ?since=&until=)",
1332
- body: "RAW_BODY",
1333
- }).replace("RAW_BODY", body);
1334
- return html;
1388
+ return _renderAdminShell(
1389
+ opts.shop_name,
1390
+ "Window: last 30 days (operator-tunable via ?since=&until=)",
1391
+ body,
1392
+ "dashboard",
1393
+ );
1335
1394
  }
1336
1395
 
1337
1396
  function _statCard(label, value, accent) {
@@ -1341,12 +1400,32 @@ function _statCard(label, value, accent) {
1341
1400
 
1342
1401
  // ---- admin web pages (login / landing / setup wizard) -------------------
1343
1402
 
1344
- function _renderAdminShell(shopName, subtitle, bodyHtml) {
1403
+ // Console nav one entry per HTML console screen. `active` highlights
1404
+ // the current page; `null`/`false` (unauthenticated pages like the
1405
+ // sign-in form) renders no nav at all.
1406
+ var ADMIN_NAV_ITEMS = [
1407
+ { key: "home", href: "/admin", label: "Home" },
1408
+ { key: "dashboard", href: "/admin/dashboard", label: "Dashboard" },
1409
+ { key: "products", href: "/admin/products", label: "Products" },
1410
+ { key: "integrations", href: "/admin/integrations", label: "Integrations" },
1411
+ { key: "setup", href: "/admin/setup", label: "Setup" },
1412
+ ];
1413
+ function _adminNav(active) {
1414
+ if (active === null || active === undefined || active === false) return "";
1415
+ var links = ADMIN_NAV_ITEMS.map(function (it) {
1416
+ return "<a href=\"" + it.href + "\"" + (it.key === active ? " class=\"active\"" : "") + ">" +
1417
+ _htmlEscape(it.label) + "</a>";
1418
+ }).join("");
1419
+ return "<nav class=\"admin-nav\"><div class=\"admin-nav__inner\">" + links + "</div></nav>";
1420
+ }
1421
+
1422
+ function _renderAdminShell(shopName, subtitle, bodyHtml, active) {
1345
1423
  return _renderTemplate(DASHBOARD_LAYOUT, {
1346
1424
  shop_name: shopName || "blamejs.shop",
1347
1425
  window_label: subtitle || "",
1426
+ nav: "RAW_NAV",
1348
1427
  body: "RAW_BODY",
1349
- }).replace("RAW_BODY", bodyHtml);
1428
+ }).replace("RAW_NAV", _adminNav(active)).replace("RAW_BODY", bodyHtml);
1350
1429
  }
1351
1430
 
1352
1431
  function renderAdminLogin(opts) {
@@ -1365,7 +1444,7 @@ function renderAdminLogin(opts) {
1365
1444
  "<button type=\"submit\" class=\"btn\">Sign in</button>" +
1366
1445
  "</form>" +
1367
1446
  "</section>";
1368
- return _renderAdminShell(opts.shop_name, "Sign in", body);
1447
+ return _renderAdminShell(opts.shop_name, "Sign in", body, null);
1369
1448
  }
1370
1449
 
1371
1450
  function renderAdminLanding(opts) {
@@ -1383,7 +1462,7 @@ function renderAdminLanding(opts) {
1383
1462
  "</div>" +
1384
1463
  "<div class=\"actions-row\"><form method=\"post\" action=\"/admin/logout\"><button type=\"submit\" class=\"btn btn--ghost\">Sign out</button></form></div>" +
1385
1464
  "</section>";
1386
- return _renderAdminShell(opts.shop_name, "", body);
1465
+ return _renderAdminShell(opts.shop_name, "", body, "home");
1387
1466
  }
1388
1467
 
1389
1468
  function _setupField(label, name, value, type, hint, extra) {
@@ -1412,7 +1491,7 @@ function renderAdminSetup(opts) {
1412
1491
  "<a class=\"btn btn--ghost\" href=\"/admin\">Back</a></div>" +
1413
1492
  "</form>" +
1414
1493
  "</section>";
1415
- return _renderAdminShell(opts.shop_name, "Setup", body);
1494
+ return _renderAdminShell(opts.shop_name, "Setup", body, "setup");
1416
1495
  }
1417
1496
 
1418
1497
  // Each integration is off until the operator supplies its credentials.
@@ -1464,7 +1543,41 @@ function renderAdminIntegrations(opts) {
1464
1543
  "<p class=\"meta\" style=\"margin-top:1.25rem;\">Sign in with Apple and PayPal are planned. “Sign in with Shop” / Shop Pay isn't available to a self-hosted store. See the README “Optional integrations” section for full setup steps.</p>" +
1465
1544
  "<div class=\"actions-row\"><a class=\"btn btn--ghost\" href=\"/admin\">Back</a></div>" +
1466
1545
  "</section>";
1467
- return _renderAdminShell(opts.shop_name, "Integrations", body);
1546
+ return _renderAdminShell(opts.shop_name, "Integrations", body, "integrations");
1547
+ }
1548
+
1549
+ function renderAdminProducts(opts) {
1550
+ opts = opts || {};
1551
+ var products = opts.products || [];
1552
+ var created = opts.created ? "<div class=\"banner banner--ok\">Product created.</div>" : "";
1553
+ var notice = opts.notice ? "<div class=\"banner banner--err\">" + _htmlEscape(opts.notice) + "</div>" : "";
1554
+ var rows = products.map(function (p) {
1555
+ var cls = p.status === "active" ? "paid" : (p.status === "archived" ? "refunded" : "pending");
1556
+ var action = p.status === "archived"
1557
+ ? "<form method=\"post\" action=\"/admin/products/" + _htmlEscape(p.id) + "/restore\"><button class=\"btn btn--ghost\" type=\"submit\">Restore</button></form>"
1558
+ : "<form method=\"post\" action=\"/admin/products/" + _htmlEscape(p.id) + "/archive\"><button class=\"btn btn--ghost\" type=\"submit\">Archive</button></form>";
1559
+ return "<tr><td><strong>" + _htmlEscape(p.title) + "</strong></td>" +
1560
+ "<td><code class=\"order-id\">" + _htmlEscape(p.slug) + "</code></td>" +
1561
+ "<td><span class=\"status-pill " + cls + "\">" + _htmlEscape(p.status) + "</span></td>" +
1562
+ "<td>" + action + "</td></tr>";
1563
+ }).join("");
1564
+ var table = products.length
1565
+ ? "<div class=\"panel\"><table><thead><tr><th>Title</th><th>Slug</th><th>Status</th><th>Action</th></tr></thead><tbody>" + rows + "</tbody></table></div>"
1566
+ : "<p class=\"empty\">No products yet — create your first one below.</p>";
1567
+ var body =
1568
+ "<section><h2>Products</h2>" + created + notice + table +
1569
+ "<div class=\"panel\" style=\"margin-top:1.5rem; max-width:34rem;\">" +
1570
+ "<h3 style=\"font-size:.95rem; margin-bottom:.75rem;\">New product</h3>" +
1571
+ "<form method=\"post\" action=\"/admin/products\">" +
1572
+ _setupField("Title", "title", "", "text", "", " maxlength=\"200\" required") +
1573
+ _setupField("Slug", "slug", "", "text", "Lowercase, hyphenated — the storefront URL.", " maxlength=\"200\" required") +
1574
+ "<label class=\"form-field\"><span>Status</span><select name=\"status\"><option value=\"draft\">Draft</option><option value=\"active\">Active</option></select></label>" +
1575
+ _setupField("Description", "description", "", "text", "", " maxlength=\"2000\"") +
1576
+ "<div class=\"actions-row\"><button class=\"btn\" type=\"submit\">Create product</button></div>" +
1577
+ "</form>" +
1578
+ "</div>" +
1579
+ "</section>";
1580
+ return _renderAdminShell(opts.shop_name, "Products", body, "products");
1468
1581
  }
1469
1582
 
1470
1583
  module.exports = {
@@ -1475,4 +1588,5 @@ module.exports = {
1475
1588
  renderAdminLanding: renderAdminLanding,
1476
1589
  renderAdminSetup: renderAdminSetup,
1477
1590
  renderAdminIntegrations: renderAdminIntegrations,
1591
+ renderAdminProducts: renderAdminProducts,
1478
1592
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/blamejs-shop",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Open-source framework built on blamejs. Vendored stack, zero npm runtime deps, PQC-first crypto, security-on by default.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {