@tokenoftrust/storefront-runner 1.4.1 → 1.4.2-rc.0

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.
Files changed (166) hide show
  1. package/apps/storefront/astro.config.mjs +17 -1
  2. package/apps/storefront/integrations/materialize-guard.mjs +56 -0
  3. package/apps/storefront/migrations-apps/0002_good_switch.sql +26 -0
  4. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +12 -0
  5. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +1160 -0
  6. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +1235 -0
  7. package/apps/storefront/migrations-apps/meta/_journal.json +14 -0
  8. package/apps/storefront/public/js/dashboard-team.js +38 -2
  9. package/apps/storefront/src/components/Seo.astro +65 -1
  10. package/apps/storefront/src/components/admin/AdminBlogDetailRail.astro +878 -0
  11. package/apps/storefront/src/components/admin/AdminBlogTab.astro +1432 -0
  12. package/apps/storefront/src/components/admin/AdminCustomersTab.astro +3 -7
  13. package/apps/storefront/src/components/admin/AdminPublishTab.astro +1105 -2334
  14. package/apps/storefront/src/components/admin/AdminSubscriptionsTab.astro +1 -3
  15. package/apps/storefront/src/components/blog/BlogPaywall.astro +87 -0
  16. package/apps/storefront/src/components/blog/PostAccessBadge.astro +43 -0
  17. package/apps/storefront/src/components/blog/PostGrid.astro +57 -0
  18. package/apps/storefront/src/components/blog/ReactionBar.astro +214 -0
  19. package/apps/storefront/src/layouts/Layout.astro +48 -3
  20. package/apps/storefront/src/lib/activity/alerts.ts +17 -19
  21. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +3 -3
  22. package/apps/storefront/src/lib/activity/deployVersion.ts +19 -26
  23. package/apps/storefront/src/lib/activity/ingest.ts +8 -8
  24. package/apps/storefront/src/lib/activity/ingestAuth.ts +1 -1
  25. package/apps/storefront/src/lib/activity/killSwitch.ts +6 -6
  26. package/apps/storefront/src/lib/activity/query.ts +9 -9
  27. package/apps/storefront/src/lib/activity/recordActivity.ts +11 -15
  28. package/apps/storefront/src/lib/activity/store.ts +4 -6
  29. package/apps/storefront/src/lib/activity/uiActor.ts +12 -12
  30. package/apps/storefront/src/lib/activity/workerCommit.ts +6 -6
  31. package/apps/storefront/src/lib/admin/adminShell.ts +290 -0
  32. package/apps/storefront/src/lib/admin/ai/approvalMode.ts +2 -3
  33. package/apps/storefront/src/lib/admin/ai/audit.ts +3 -5
  34. package/apps/storefront/src/lib/admin/checkoutStyleInput.ts +7 -7
  35. package/apps/storefront/src/lib/admin/checkoutStyleTarget.ts +3 -3
  36. package/apps/storefront/src/lib/admin/orderClient.ts +3 -5
  37. package/apps/storefront/src/lib/admin/services/orders.ts +17 -19
  38. package/apps/storefront/src/lib/admin/viewmodels/aiWorkflows.ts +4 -6
  39. package/apps/storefront/src/lib/admin/viewmodels/settings.ts +1 -1
  40. package/apps/storefront/src/lib/apps/adminService.ts +4 -4
  41. package/apps/storefront/src/lib/apps/adminSession.ts +53 -44
  42. package/apps/storefront/src/lib/apps/apiAuth.ts +2 -2
  43. package/apps/storefront/src/lib/apps/apiRoute.ts +2 -2
  44. package/apps/storefront/src/lib/apps/catalogMapper.ts +1 -1
  45. package/apps/storefront/src/lib/apps/credentials.ts +2 -2
  46. package/apps/storefront/src/lib/apps/gatewayKeys.ts +4 -4
  47. package/apps/storefront/src/lib/apps/healthAggregate.ts +5 -5
  48. package/apps/storefront/src/lib/apps/orders/attributionService.ts +2 -2
  49. package/apps/storefront/src/lib/apps/orders/customerHash.ts +1 -1
  50. package/apps/storefront/src/lib/apps/orders/foxyOrderClient.ts +12 -12
  51. package/apps/storefront/src/lib/apps/orders/idempotency.ts +7 -7
  52. package/apps/storefront/src/lib/apps/orders/orderForwardReceiver.ts +1 -1
  53. package/apps/storefront/src/lib/apps/orders/orderMapper.ts +2 -2
  54. package/apps/storefront/src/lib/apps/orders/ordersStore.ts +6 -6
  55. package/apps/storefront/src/lib/apps/registryService.ts +6 -6
  56. package/apps/storefront/src/lib/apps/scopes.ts +2 -2
  57. package/apps/storefront/src/lib/apps/tokenIssuer.ts +4 -4
  58. package/apps/storefront/src/lib/apps/tokenVerifier.ts +6 -6
  59. package/apps/storefront/src/lib/apps/widgets/eligibility.ts +2 -2
  60. package/apps/storefront/src/lib/apps/widgets/frameProps.ts +3 -3
  61. package/apps/storefront/src/lib/apps/widgets/launchToken.ts +4 -4
  62. package/apps/storefront/src/lib/apps/widgets/placements.ts +2 -2
  63. package/apps/storefront/src/lib/apps/widgets/renderSlot.ts +1 -1
  64. package/apps/storefront/src/lib/auth/adminEntry.ts +9 -9
  65. package/apps/storefront/src/lib/auth/identityToken.ts +6 -14
  66. package/apps/storefront/src/lib/auth/loginGate.ts +75 -13
  67. package/apps/storefront/src/lib/auth/mcpClientAssertion.ts +2 -4
  68. package/apps/storefront/src/lib/auth/operatorSession.ts +113 -0
  69. package/apps/storefront/src/lib/auth/session.ts +7 -8
  70. package/apps/storefront/src/lib/auth/totAccessClient.ts +8 -18
  71. package/apps/storefront/src/lib/basePath.ts +9 -2
  72. package/apps/storefront/src/lib/blog/access.ts +29 -0
  73. package/apps/storefront/src/lib/blog/collection.ts +313 -0
  74. package/apps/storefront/src/lib/blog/markdown.ts +174 -0
  75. package/apps/storefront/src/lib/blog/provider.ts +5 -0
  76. package/apps/storefront/src/lib/blog/reactions.ts +87 -0
  77. package/apps/storefront/src/lib/blog/rss.ts +92 -0
  78. package/apps/storefront/src/lib/blog/teaser.ts +83 -0
  79. package/apps/storefront/src/lib/blog/types.ts +34 -0
  80. package/apps/storefront/src/lib/blog/viewCounts.ts +243 -0
  81. package/apps/storefront/src/lib/d1/catalog.ts +2 -2
  82. package/apps/storefront/src/lib/d1/schema-apps.ts +96 -17
  83. package/apps/storefront/src/lib/dev/activityIngestToken.ts +2 -4
  84. package/apps/storefront/src/lib/dev/activityStore.ts +3 -5
  85. package/apps/storefront/src/lib/dev/apiBase.ts +1 -4
  86. package/apps/storefront/src/lib/dev/cockpitStore.ts +1 -9
  87. package/apps/storefront/src/lib/dev/devDraft.ts +1 -1
  88. package/apps/storefront/src/lib/dev/previewStatus.ts +9 -21
  89. package/apps/storefront/src/lib/dev/rendezvousBroker.ts +9 -24
  90. package/apps/storefront/src/lib/edgeCache.ts +17 -0
  91. package/apps/storefront/src/lib/http/fetchTransport.ts +63 -0
  92. package/apps/storefront/src/lib/i18n.ts +25 -0
  93. package/apps/storefront/src/lib/jsonld.ts +118 -0
  94. package/apps/storefront/src/lib/monitoring/manifest.ts +11 -11
  95. package/apps/storefront/src/lib/newsletter/confirmationEmail.ts +30 -0
  96. package/apps/storefront/src/lib/newsletter/consent.ts +23 -0
  97. package/apps/storefront/src/lib/newsletter/digest.ts +117 -0
  98. package/apps/storefront/src/lib/newsletter/resendClient.ts +79 -0
  99. package/apps/storefront/src/lib/newsletter/send.ts +265 -0
  100. package/apps/storefront/src/lib/newsletter/subscribers.ts +156 -0
  101. package/apps/storefront/src/lib/publish/adminPublishTab.ts +3519 -0
  102. package/apps/storefront/src/lib/publish/apex-readiness.ts +41 -18
  103. package/apps/storefront/src/lib/publish/dispatchHealth.ts +5 -7
  104. package/apps/storefront/src/lib/publish/domainState.ts +22 -13
  105. package/apps/storefront/src/lib/publish/panelPolling.ts +78 -0
  106. package/apps/storefront/src/lib/publish/shipWorkspace.ts +100 -49
  107. package/apps/storefront/src/lib/publish/stageBundleUpload.ts +215 -0
  108. package/apps/storefront/src/lib/rate/kvWindow.ts +53 -0
  109. package/apps/storefront/src/lib/search/index.ts +2 -2
  110. package/apps/storefront/src/lib/seo/alternates.ts +42 -0
  111. package/apps/storefront/src/lib/seo/meta.ts +65 -0
  112. package/apps/storefront/src/lib/social/golive.ts +212 -0
  113. package/apps/storefront/src/lib/social/notify.ts +32 -0
  114. package/apps/storefront/src/lib/social/tokenStore.ts +171 -0
  115. package/apps/storefront/src/lib/the-build/provider.ts +27 -0
  116. package/apps/storefront/src/lib/the-build/readingTime.ts +35 -0
  117. package/apps/storefront/src/lib/the-build/toc.ts +95 -0
  118. package/apps/storefront/src/lib/tot/ToTClient.ts +1 -1
  119. package/apps/storefront/src/lib/tot/d1Client.ts +2 -2
  120. package/apps/storefront/src/lib/tot/totClientInterface.ts +3 -4
  121. package/apps/storefront/src/lib/webhooks/deliveryStore.ts +16 -17
  122. package/apps/storefront/src/middleware/index.ts +113 -2
  123. package/apps/storefront/src/pages/admin.astro +10 -1312
  124. package/apps/storefront/src/pages/api/blog/[collection]/[slug]/react.ts +104 -0
  125. package/apps/storefront/src/pages/api/newsletter/[collection]/subscribe.ts +146 -0
  126. package/apps/storefront/src/pages/api/newsletter/confirm.ts +75 -0
  127. package/apps/storefront/src/pages/api/newsletter/unsubscribe.ts +90 -0
  128. package/apps/storefront/src/pages/api/publish/stage-bundle.ts +70 -0
  129. package/apps/storefront/src/pages/api/rum/vitals.ts +21 -2
  130. package/apps/storefront/src/pages/blog/[slug].astro +96 -16
  131. package/apps/storefront/src/pages/blog/author/[author].astro +140 -0
  132. package/apps/storefront/src/pages/blog/category/[category].astro +67 -0
  133. package/apps/storefront/src/pages/blog/index.astro +2 -0
  134. package/apps/storefront/src/pages/blog/tag/[tag].astro +65 -0
  135. package/apps/storefront/src/pages/cockpit.astro +37 -12
  136. package/apps/storefront/src/pages/dashboard/[appDomain]/team.astro +15 -11
  137. package/apps/storefront/src/pages/search.astro +1 -1
  138. package/apps/storefront/src/pages/sitemap.xml.ts +20 -0
  139. package/apps/storefront/src/pages/the-build/[slug].astro +129 -0
  140. package/apps/storefront/src/pages/the-build/index.astro +146 -0
  141. package/apps/storefront/src/pages/the-build/rss.xml.ts +33 -0
  142. package/apps/storefront/src/styles/admin.css +1080 -0
  143. package/apps/storefront/tsconfig.json +5 -0
  144. package/package.json +1 -1
  145. package/packages/public-runtime/package.json +1 -0
  146. package/packages/public-runtime/src/activity/catalog.ts +52 -0
  147. package/packages/public-runtime/src/catalog-d1.ts +1 -1
  148. package/packages/public-runtime/src/customization-preview.ts +25 -2
  149. package/packages/public-runtime/src/customization-runtime.ts +125 -3
  150. package/packages/public-runtime/src/customization-versioning.ts +10 -0
  151. package/packages/public-runtime/src/index.ts +1 -0
  152. package/packages/public-runtime/src/static-bundle.ts +357 -0
  153. package/packages/public-runtime/src/tenant.ts +36 -8
  154. package/scripts/build/copy-tenant-assets.mjs +14 -4
  155. package/scripts/dev/ai-edit.mjs +1 -1
  156. package/scripts/dev/checkout-watch.mjs +2 -2
  157. package/scripts/dev/file-browser.mjs +2 -4
  158. package/scripts/dev/file-writer.mjs +1 -1
  159. package/scripts/dev/git-status.mjs +2 -2
  160. package/scripts/dev/locate-handler.mjs +3 -3
  161. package/scripts/dev/port-check.mjs +3 -3
  162. package/scripts/dev/publish.mjs +5 -9
  163. package/scripts/dev/shot.mjs +1 -1
  164. package/scripts/dev/unified-diff.mjs +8 -3
  165. package/scripts/tot-dev.mjs +6 -9
  166. package/apps/storefront/src/lib/dev/vcBinding.ts +0 -80
@@ -31,7 +31,7 @@
31
31
  * Vite trusts) and run a recursive `fs.watch` on the checkout that re-syncs each
32
32
  * changed file back into the in-tree copy on save — which is what fires Vite HMR.
33
33
  *
34
- * Two things learned the hard way (see the two-liners below):
34
+ * Two things to know (see the two-liners below):
35
35
  * - Tenant is selected by the URL path-prefix (`/<appDomain>/`), NOT by
36
36
  * DEFAULT_TENANT_ID — the @astrojs/cloudflare dev runtime (workerd) reads env
37
37
  * from .dev.vars/bindings, so a spawned process.env var never reaches it, and
@@ -76,9 +76,8 @@ const flag = (name, def) => {
76
76
 
77
77
  // `--version` / `-v` / `version` → print the runner's PUBLISHED version and exit.
78
78
  // Reads the emitted root package.json (build-runner.mjs stamps RUNNER_VERSION in
79
- // PUBLISH mode). This is the version the 2026-07-14 cache-staleness bug hid — the
80
- // runner kept being served from a stale public-0.1.0 dir with no way to see it —
81
- // so making it directly checkable (npm bin `storefront-runner`) is part of the fix.
79
+ // PUBLISH mode), so the runner's version is directly checkable (npm bin
80
+ // `storefront-runner`).
82
81
  if (argv[0] === "--version" || argv[0] === "-v" || argv[0] === "version") {
83
82
  let v = "0.0.0";
84
83
  try {
@@ -165,7 +164,7 @@ if (!domain) {
165
164
  // Records let us undo everything on exit (leave the tree exactly as found).
166
165
  /** @type {{ target: string, backup: string|null }[]} */
167
166
  const grafts = [];
168
- /** @type {import("node:fs").FSWatcher[]} */
167
+ /** @type {Array<{ close: () => void }>} */
169
168
  const watchers = [];
170
169
  let cleanedUp = false;
171
170
 
@@ -295,8 +294,7 @@ if (workspacePath) {
295
294
 
296
295
  // Resolve the port BEFORE printing a URL or booting astro. Vite's `strictPort`
297
296
  // defaults off, so a taken port makes astro SILENTLY drift to the next free one —
298
- // which then mismatches the URL we (and the CLI's liveness poll) advertise, and a
299
- // stale server on the original port produced a false "You're live" (2026-07-14).
297
+ // which then mismatches the URL we (and the CLI's liveness poll) advertise.
300
298
  // Instead we pick the first free port ourselves and PRINT it, so a busy default
301
299
  // port "just works" (better UX than failing). See port-check.mjs.
302
300
  const requestedPort = Number(flag("port", "4321"));
@@ -362,8 +360,7 @@ const spawnEnv = workspacePath
362
360
  // require pnpm at RUNTIME), so resolve astro's real entry through Node's own
363
361
  // resolver from the app package and exec it with our Node. No package-manager
364
362
  // binary, no .bin shims, and no coupling to the package's name (the build
365
- // renames @tot/storefront → @tot/storefront-runner in the shipped tree, which
366
- // the old `pnpm --filter <name> exec` had to track).
363
+ // renames @tot/storefront → @tot/storefront-runner in the shipped tree).
367
364
  const appDir = resolve(repoRoot, "apps/storefront");
368
365
  const astroEntry = resolve(
369
366
  dirname(createRequire(join(appDir, "package.json")).resolve("astro/package.json")),
@@ -1,80 +0,0 @@
1
- /**
2
- * Cockpit safety-net for the 08-18 vc-app-binding gap (§5): ensure the signed-in
3
- * developer is bound to storefront's version-control app so their `tot start`
4
- * checkout (`tenant_checkout`) and the repo tools stop 403-ing "No version-control
5
- * app is bound to your session."
6
- *
7
- * WHY a net at all: the ROOT fix binds every entitled human at the authority seams
8
- * the MCP owns — grant issuance, rendezvous `/approve`, native OAuth token issuance
9
- * — plus a one-shot backfill. Those cover the terminal path. This net covers the
10
- * BROWSER-FIRST developer who reached /cockpit via the storefront's own tot20
11
- * sign-in (a `tot_session` cookie) WITHOUT ever crossing an MCP binding seam, so
12
- * they'd otherwise land at cockpit with a `tot start` command that 403s.
13
- *
14
- * HOW (mirrors cli-signin-approve): there is NO per-human MCP session server-side —
15
- * the cockpit reaches the MCP only as the APP (private_key_jwt). So we re-issue a
16
- * FRESH tot20-signed id_token for the VERIFIED session email (via the storefront's
17
- * core credential — {@link reissueSubjectToken}, the same proof `/approve` sends)
18
- * and pass it as the `subject_token` the MCP binds the enrollment to. The app can't
19
- * assert an arbitrary subject; the MCP verifies the proof + the subject's LIVE
20
- * entitlement and authors the binding under its own forge authority (ADR-0001).
21
- *
22
- * ALWAYS FAIL-OPEN: any gap (proof re-issue failed, MCP cold/unreachable, the
23
- * endpoint not yet deployed) returns a typed `{ ok:false }` and NEVER throws — the
24
- * cockpit must render regardless, and the authority-seam binding + backfill are the
25
- * real guarantees. This is strictly a best-effort accelerator.
26
- */
27
- import { createForgeClient } from "@/lib/forge";
28
- import { reissueSubjectToken } from "@/lib/dev/subjectReissue";
29
-
30
- export type EnsureCockpitBindingResult =
31
- | { ok: true; bound: boolean; created: boolean }
32
- | { ok: false; reason: string };
33
-
34
- export interface EnsureCockpitBindingDeps {
35
- /** Override the subject-proof minter (tests). */
36
- reissue?: typeof reissueSubjectToken;
37
- /** Override the forge-client factory (tests) — returns something with ensureVcAppBinding. */
38
- makeForgeClient?: () => Promise<{
39
- ensureVcAppBinding(opts: {
40
- subjectToken?: string;
41
- }): Promise<{ bound: boolean; created: boolean }>;
42
- }>;
43
- }
44
-
45
- /**
46
- * Ensure the developer identified by their VERIFIED session `email` is bound to the
47
- * storefront VC app. Best-effort + fail-closed-to-typed-error: never throws.
48
- */
49
- export async function ensureCockpitVcBinding(
50
- email: string,
51
- deps: EnsureCockpitBindingDeps = {},
52
- ): Promise<EnsureCockpitBindingResult> {
53
- if (!email) return { ok: false, reason: "missing-identity" };
54
-
55
- const reissue = deps.reissue ?? reissueSubjectToken;
56
- let subjectToken: string;
57
- try {
58
- const proof = await reissue(email);
59
- if (!proof.ok) return { ok: false, reason: `reissue-${proof.reason}` };
60
- subjectToken = proof.idToken;
61
- } catch {
62
- // A re-issue fault must not surface as a cockpit 500.
63
- return { ok: false, reason: "reissue-threw" };
64
- }
65
-
66
- try {
67
- const client = deps.makeForgeClient
68
- ? await deps.makeForgeClient()
69
- : await createForgeClient();
70
- const res = await client.ensureVcAppBinding({ subjectToken });
71
- return { ok: true, bound: res.bound, created: res.created };
72
- } catch (cause) {
73
- // Fail-open: the ensure endpoint may not be deployed yet, or the MCP may be
74
- // cold/unreachable. The proof itself is never logged; the reason is a terse code.
75
- return {
76
- ok: false,
77
- reason: "mcp-" + (cause instanceof Error ? cause.name : "error"),
78
- };
79
- }
80
- }