@tokenoftrust/storefront-runner 1.4.0 → 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 (193) 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/0001_woozy_lyja.sql +22 -0
  4. package/apps/storefront/migrations-apps/0002_good_switch.sql +26 -0
  5. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +12 -0
  6. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +990 -0
  7. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +1160 -0
  8. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +1235 -0
  9. package/apps/storefront/migrations-apps/meta/_journal.json +21 -0
  10. package/apps/storefront/package.json +0 -1
  11. package/apps/storefront/public/js/dashboard-team.js +38 -2
  12. package/apps/storefront/src/components/Seo.astro +65 -1
  13. package/apps/storefront/src/components/admin/AdminBlogDetailRail.astro +878 -0
  14. package/apps/storefront/src/components/admin/AdminBlogTab.astro +1432 -0
  15. package/apps/storefront/src/components/admin/AdminCustomersTab.astro +3 -7
  16. package/apps/storefront/src/components/admin/AdminPublishTab.astro +1756 -1382
  17. package/apps/storefront/src/components/admin/AdminSubscriptionsTab.astro +1 -3
  18. package/apps/storefront/src/components/blog/BlogPaywall.astro +87 -0
  19. package/apps/storefront/src/components/blog/PostAccessBadge.astro +43 -0
  20. package/apps/storefront/src/components/blog/PostGrid.astro +57 -0
  21. package/apps/storefront/src/components/blog/ReactionBar.astro +214 -0
  22. package/apps/storefront/src/layouts/Layout.astro +48 -3
  23. package/apps/storefront/src/lib/activity/alerts.ts +426 -0
  24. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +85 -0
  25. package/apps/storefront/src/lib/activity/deployVersion.ts +120 -0
  26. package/apps/storefront/src/lib/activity/ingest.ts +188 -0
  27. package/apps/storefront/src/lib/activity/ingestAuth.ts +105 -0
  28. package/apps/storefront/src/lib/activity/killSwitch.ts +80 -0
  29. package/apps/storefront/src/lib/activity/query.ts +403 -0
  30. package/apps/storefront/src/lib/activity/recordActivity.ts +101 -0
  31. package/apps/storefront/src/lib/activity/store.ts +120 -0
  32. package/apps/storefront/src/lib/activity/uiActor.ts +150 -0
  33. package/apps/storefront/src/lib/activity/workerCommit.ts +70 -0
  34. package/apps/storefront/src/lib/admin/adminShell.ts +290 -0
  35. package/apps/storefront/src/lib/admin/ai/approvalMode.ts +2 -3
  36. package/apps/storefront/src/lib/admin/ai/audit.ts +3 -5
  37. package/apps/storefront/src/lib/admin/checkoutStyleInput.ts +7 -7
  38. package/apps/storefront/src/lib/admin/checkoutStyleTarget.ts +3 -3
  39. package/apps/storefront/src/lib/admin/orderClient.ts +3 -5
  40. package/apps/storefront/src/lib/admin/services/orders.ts +17 -19
  41. package/apps/storefront/src/lib/admin/viewmodels/aiWorkflows.ts +4 -6
  42. package/apps/storefront/src/lib/admin/viewmodels/settings.ts +1 -1
  43. package/apps/storefront/src/lib/apps/adminService.ts +4 -4
  44. package/apps/storefront/src/lib/apps/adminSession.ts +53 -44
  45. package/apps/storefront/src/lib/apps/apiAuth.ts +2 -2
  46. package/apps/storefront/src/lib/apps/apiRoute.ts +2 -2
  47. package/apps/storefront/src/lib/apps/catalogMapper.ts +1 -1
  48. package/apps/storefront/src/lib/apps/credentials.ts +2 -2
  49. package/apps/storefront/src/lib/apps/gatewayKeys.ts +4 -4
  50. package/apps/storefront/src/lib/apps/healthAggregate.ts +5 -5
  51. package/apps/storefront/src/lib/apps/orders/attributionService.ts +2 -2
  52. package/apps/storefront/src/lib/apps/orders/customerHash.ts +1 -1
  53. package/apps/storefront/src/lib/apps/orders/foxyOrderClient.ts +12 -12
  54. package/apps/storefront/src/lib/apps/orders/idempotency.ts +7 -7
  55. package/apps/storefront/src/lib/apps/orders/orderForwardReceiver.ts +1 -1
  56. package/apps/storefront/src/lib/apps/orders/orderMapper.ts +2 -2
  57. package/apps/storefront/src/lib/apps/orders/ordersStore.ts +6 -6
  58. package/apps/storefront/src/lib/apps/registryService.ts +6 -6
  59. package/apps/storefront/src/lib/apps/scopes.ts +2 -2
  60. package/apps/storefront/src/lib/apps/tokenIssuer.ts +4 -4
  61. package/apps/storefront/src/lib/apps/tokenVerifier.ts +6 -6
  62. package/apps/storefront/src/lib/apps/widgets/eligibility.ts +2 -2
  63. package/apps/storefront/src/lib/apps/widgets/frameProps.ts +3 -3
  64. package/apps/storefront/src/lib/apps/widgets/launchToken.ts +4 -4
  65. package/apps/storefront/src/lib/apps/widgets/placements.ts +2 -2
  66. package/apps/storefront/src/lib/apps/widgets/renderSlot.ts +1 -1
  67. package/apps/storefront/src/lib/auth/adminEntry.ts +9 -9
  68. package/apps/storefront/src/lib/auth/identityToken.ts +6 -14
  69. package/apps/storefront/src/lib/auth/loginGate.ts +75 -13
  70. package/apps/storefront/src/lib/auth/mcpClientAssertion.ts +6 -4
  71. package/apps/storefront/src/lib/auth/operatorSession.ts +113 -0
  72. package/apps/storefront/src/lib/auth/route.ts +44 -4
  73. package/apps/storefront/src/lib/auth/session.ts +7 -8
  74. package/apps/storefront/src/lib/auth/totAccessClient.ts +8 -18
  75. package/apps/storefront/src/lib/basePath.ts +9 -2
  76. package/apps/storefront/src/lib/blog/access.ts +29 -0
  77. package/apps/storefront/src/lib/blog/collection.ts +313 -0
  78. package/apps/storefront/src/lib/blog/markdown.ts +174 -0
  79. package/apps/storefront/src/lib/blog/provider.ts +5 -0
  80. package/apps/storefront/src/lib/blog/reactions.ts +87 -0
  81. package/apps/storefront/src/lib/blog/rss.ts +92 -0
  82. package/apps/storefront/src/lib/blog/teaser.ts +83 -0
  83. package/apps/storefront/src/lib/blog/types.ts +34 -0
  84. package/apps/storefront/src/lib/blog/viewCounts.ts +243 -0
  85. package/apps/storefront/src/lib/d1/catalog.ts +2 -2
  86. package/apps/storefront/src/lib/d1/schema-apps.ts +147 -14
  87. package/apps/storefront/src/lib/dev/activityIngestToken.ts +2 -4
  88. package/apps/storefront/src/lib/dev/activityStore.ts +3 -5
  89. package/apps/storefront/src/lib/dev/apiBase.ts +1 -4
  90. package/apps/storefront/src/lib/dev/cockpitStore.ts +1 -9
  91. package/apps/storefront/src/lib/dev/devDraft.ts +1 -1
  92. package/apps/storefront/src/lib/dev/previewStatus.ts +9 -21
  93. package/apps/storefront/src/lib/dev/rendezvousBroker.ts +9 -24
  94. package/apps/storefront/src/lib/edgeCache.ts +17 -0
  95. package/apps/storefront/src/lib/env.ts +51 -0
  96. package/apps/storefront/src/lib/http/fetchTransport.ts +63 -0
  97. package/apps/storefront/src/lib/i18n.ts +25 -0
  98. package/apps/storefront/src/lib/jsonld.ts +118 -0
  99. package/apps/storefront/src/lib/monitoring/manifest.ts +11 -11
  100. package/apps/storefront/src/lib/newsletter/confirmationEmail.ts +30 -0
  101. package/apps/storefront/src/lib/newsletter/consent.ts +23 -0
  102. package/apps/storefront/src/lib/newsletter/digest.ts +117 -0
  103. package/apps/storefront/src/lib/newsletter/resendClient.ts +79 -0
  104. package/apps/storefront/src/lib/newsletter/send.ts +265 -0
  105. package/apps/storefront/src/lib/newsletter/subscribers.ts +156 -0
  106. package/apps/storefront/src/lib/publish/adminPublishTab.ts +3519 -0
  107. package/apps/storefront/src/lib/publish/apex-readiness.ts +41 -18
  108. package/apps/storefront/src/lib/publish/dispatchHealth.ts +5 -7
  109. package/apps/storefront/src/lib/publish/domainState.ts +22 -13
  110. package/apps/storefront/src/lib/publish/panelPolling.ts +78 -0
  111. package/apps/storefront/src/lib/publish/shipWorkspace.ts +100 -42
  112. package/apps/storefront/src/lib/publish/stageBundleUpload.ts +215 -0
  113. package/apps/storefront/src/lib/rate/kvWindow.ts +53 -0
  114. package/apps/storefront/src/lib/search/index.ts +2 -2
  115. package/apps/storefront/src/lib/seo/alternates.ts +42 -0
  116. package/apps/storefront/src/lib/seo/meta.ts +65 -0
  117. package/apps/storefront/src/lib/social/golive.ts +212 -0
  118. package/apps/storefront/src/lib/social/notify.ts +32 -0
  119. package/apps/storefront/src/lib/social/tokenStore.ts +171 -0
  120. package/apps/storefront/src/lib/the-build/provider.ts +27 -0
  121. package/apps/storefront/src/lib/the-build/readingTime.ts +35 -0
  122. package/apps/storefront/src/lib/the-build/toc.ts +95 -0
  123. package/apps/storefront/src/lib/tot/ToTClient.ts +1 -1
  124. package/apps/storefront/src/lib/tot/d1Client.ts +2 -2
  125. package/apps/storefront/src/lib/tot/totClientInterface.ts +3 -4
  126. package/apps/storefront/src/lib/webhooks/deliveryStore.ts +16 -17
  127. package/apps/storefront/src/middleware/index.ts +130 -2
  128. package/apps/storefront/src/pages/admin/ops-timeline.astro +420 -0
  129. package/apps/storefront/src/pages/admin.astro +52 -1206
  130. package/apps/storefront/src/pages/api/activity.ts +137 -0
  131. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +73 -0
  132. package/apps/storefront/src/pages/api/apps/admin/credentials/rotate.ts +27 -1
  133. package/apps/storefront/src/pages/api/apps/admin/install.ts +26 -1
  134. package/apps/storefront/src/pages/api/apps/admin/resume.ts +24 -1
  135. package/apps/storefront/src/pages/api/apps/admin/suspend.ts +24 -1
  136. package/apps/storefront/src/pages/api/apps/admin/uninstall.ts +25 -1
  137. package/apps/storefront/src/pages/api/apps/admin/update.ts +24 -1
  138. package/apps/storefront/src/pages/api/apps/admin/webhooks/deliveries/[deliveryId]/replay.ts +11 -0
  139. package/apps/storefront/src/pages/api/apps/internal/order-forward.ts +11 -0
  140. package/apps/storefront/src/pages/api/apps/v1/attribution.ts +20 -0
  141. package/apps/storefront/src/pages/api/apps/v1/webhooks/deliveries/[deliveryId]/replay.ts +12 -0
  142. package/apps/storefront/src/pages/api/blog/[collection]/[slug]/react.ts +104 -0
  143. package/apps/storefront/src/pages/api/cache-purge.ts +11 -0
  144. package/apps/storefront/src/pages/api/dashboard/enter-vendor.ts +30 -0
  145. package/apps/storefront/src/pages/api/newsletter/[collection]/subscribe.ts +146 -0
  146. package/apps/storefront/src/pages/api/newsletter/confirm.ts +75 -0
  147. package/apps/storefront/src/pages/api/newsletter/unsubscribe.ts +90 -0
  148. package/apps/storefront/src/pages/api/publish/stage-bundle.ts +70 -0
  149. package/apps/storefront/src/pages/api/rum/vitals.ts +21 -2
  150. package/apps/storefront/src/pages/auth/login.astro +5 -4
  151. package/apps/storefront/src/pages/blog/[slug].astro +96 -16
  152. package/apps/storefront/src/pages/blog/author/[author].astro +140 -0
  153. package/apps/storefront/src/pages/blog/category/[category].astro +67 -0
  154. package/apps/storefront/src/pages/blog/index.astro +2 -0
  155. package/apps/storefront/src/pages/blog/tag/[tag].astro +65 -0
  156. package/apps/storefront/src/pages/cockpit.astro +74 -12
  157. package/apps/storefront/src/pages/dashboard/[appDomain]/team.astro +15 -11
  158. package/apps/storefront/src/pages/search.astro +1 -1
  159. package/apps/storefront/src/pages/sitemap.xml.ts +20 -0
  160. package/apps/storefront/src/pages/the-build/[slug].astro +129 -0
  161. package/apps/storefront/src/pages/the-build/index.astro +146 -0
  162. package/apps/storefront/src/pages/the-build/rss.xml.ts +33 -0
  163. package/apps/storefront/src/styles/admin.css +1080 -0
  164. package/apps/storefront/tsconfig.json +5 -0
  165. package/package.json +1 -1
  166. package/packages/public-runtime/package.json +1 -0
  167. package/packages/public-runtime/src/activity/README.md +146 -0
  168. package/packages/public-runtime/src/activity/catalog.ts +553 -0
  169. package/packages/public-runtime/src/activity/event.ts +168 -0
  170. package/packages/public-runtime/src/activity/index.ts +16 -0
  171. package/packages/public-runtime/src/activity/redaction.ts +263 -0
  172. package/packages/public-runtime/src/candidate-index.ts +13 -0
  173. package/packages/public-runtime/src/catalog-d1.ts +1 -1
  174. package/packages/public-runtime/src/customization-preview.ts +25 -2
  175. package/packages/public-runtime/src/customization-runtime.ts +125 -3
  176. package/packages/public-runtime/src/customization-versioning.ts +10 -0
  177. package/packages/public-runtime/src/index.ts +7 -0
  178. package/packages/public-runtime/src/static-bundle.ts +357 -0
  179. package/packages/public-runtime/src/tenant.ts +36 -8
  180. package/scripts/build/copy-tenant-assets.mjs +14 -4
  181. package/scripts/dev/ai-edit.mjs +1 -1
  182. package/scripts/dev/checkout-watch.mjs +2 -2
  183. package/scripts/dev/file-browser.mjs +2 -4
  184. package/scripts/dev/file-writer.mjs +1 -1
  185. package/scripts/dev/git-status.mjs +2 -2
  186. package/scripts/dev/locate-handler.mjs +3 -3
  187. package/scripts/dev/port-check.mjs +3 -3
  188. package/scripts/dev/publish.mjs +5 -9
  189. package/scripts/dev/shot.mjs +1 -1
  190. package/scripts/dev/unified-diff.mjs +8 -3
  191. package/scripts/tot-dev.mjs +6 -9
  192. package/apps/storefront/src/lib/webhooks/signing.ts +0 -29
  193. package/apps/storefront/src/lib/webhooks/webhookSigningKey.ts +0 -146
@@ -57,6 +57,7 @@ const gitSha = (() => {
57
57
  import preact from "@astrojs/preact";
58
58
  import tailwindcss from "@tailwindcss/vite";
59
59
  import { tenantHotReload } from "./dev-plugins/tenant-hot-reload.mjs";
60
+ import { materializeGuard } from "./integrations/materialize-guard.mjs";
60
61
 
61
62
  // SSR on Cloudflare Workers. `output: 'server'` because every response is
62
63
  // tenant-resolved at the edge from the Host header (see src/middleware).
@@ -88,7 +89,22 @@ export default defineConfig({
88
89
  // images get rehosted to R2 in Phase 1 ETL (see DECISIONS.md).
89
90
  imageService: "compile",
90
91
  }),
91
- integrations: [preact({ compat: true })],
92
+ integrations: [
93
+ // Refuse to build unless every Gitea-classified tenant is materialized from
94
+ // Gitea at a pinned ref — intrinsic to `astro build`, not just deploy.sh, so
95
+ // no build path can silently bake empty/stale real-tenant content.
96
+ materializeGuard(),
97
+ preact({ compat: true }),
98
+ // Astro's file-based router ignores ANY path segment starting with "_" (see
99
+ // `astro/dist/core/routing/create-manifest.js`), so a page literally named
100
+ // `pages/__evidence.astro` silently never becomes a route (confirmed by build:
101
+ // no "/__evidence" entry lands in the route manifest, and it 404s in dev — the
102
+ // SAME latent gap `pages/__preview/version.ts` has, pre-existing and out of
103
+ // scope here). `injectRoute` is the supported way to bind an arbitrary URL
104
+ // pattern to a component that lives OUTSIDE `src/pages` (so it never competes
105
+ // with file-based routing), which is how `/__evidence` — the diagnostic evidence
106
+ // instrument panel — is wired to a real route.
107
+ ],
92
108
  vite: {
93
109
  // Build-time constants: the CLI install spec the cockpit hands out (next vs latest),
94
110
  // and this build's commit SHA reported by /health.
@@ -0,0 +1,56 @@
1
+ import {
2
+ assertPinnedMaterialized,
3
+ checkPinned,
4
+ } from "../../../scripts/tenant/materialize-tenant-content.mjs";
5
+
6
+ /**
7
+ * Refuse `astro build` when any Gitea-classified tenant's content isn't
8
+ * materialized from Gitea at a pinned ref. Runs in `astro:build:start`, so the
9
+ * guard is INTRINSIC to the build — it fires for a bare `astro build`, `pnpm
10
+ * build`, or a deploy.sh build alike, never letting an unmaterialized real
11
+ * tenant bake empty content into the Worker.
12
+ *
13
+ * TOT_TENANT_REF also assert every stamp is EXACTLY this commit (off-ref → refuse)
14
+ * TOT_ALLOW_UNPINNED=1 tolerate a default-branch (unpinned) materialize
15
+ * TOT_FRAMEWORK_ONLY_BUILD=1 tolerate ABSENT tenant content (a credential-less
16
+ * compile check bakes nothing, so there is nothing stale to guard). Populated
17
+ * content without a pinned Gitea stamp still refuses — this never weakens the
18
+ * deploy path, which materializes first and never sets this.
19
+ * TOT_BUILD_TENANTS comma-separated tenant ids to scope the guard to. A per-tenant
20
+ * STATIC publish (materialize-tenant.mjs) sets this to the single tenant it renders,
21
+ * so a SIBLING Gitea tenant that isn't part of THIS publish can't block it. Unset ⇒
22
+ * guard every Gitea tenant — the Worker-deploy contract, where all tenants are
23
+ * served from one Worker at once and any unmaterialized tenant IS a real hazard.
24
+ */
25
+ export function materializeGuard() {
26
+ return {
27
+ name: "materialize-guard",
28
+ hooks: {
29
+ "astro:build:start": (ctx = {}) => {
30
+ const logger = ctx.logger;
31
+ const expectRef = process.env.TOT_TENANT_REF || null;
32
+ const allowUnpinned = process.env.TOT_ALLOW_UNPINNED === "1";
33
+ const scoped = (process.env.TOT_BUILD_TENANTS || "")
34
+ .split(",")
35
+ .map((t) => t.trim())
36
+ .filter(Boolean);
37
+ const onlyTenants = scoped.length > 0 ? scoped : null;
38
+ if (process.env.TOT_FRAMEWORK_ONLY_BUILD === "1") {
39
+ const { problems } = checkPinned(undefined, { expectRef, allowUnpinned, onlyTenants });
40
+ const absent = problems.filter((p) => p.reason === "absent");
41
+ const real = problems.filter((p) => p.reason !== "absent");
42
+ if (absent.length) {
43
+ const msg = `[materialize-guard] framework-only build: ${absent.length} tenant(s) absent (nothing baked): ${absent.map((p) => p.tenant).join(", ")}`;
44
+ if (logger && typeof logger.info === "function") logger.info(msg);
45
+ else console.log(msg);
46
+ }
47
+ if (real.length) {
48
+ assertPinnedMaterialized({ expectRef, allowUnpinned, onlyTenants });
49
+ }
50
+ return;
51
+ }
52
+ assertPinnedMaterialized({ expectRef, allowUnpinned, onlyTenants });
53
+ },
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,22 @@
1
+ CREATE TABLE `activity_events` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `tenant_id` text NOT NULL,
4
+ `action` text NOT NULL,
5
+ `actor_kind` text NOT NULL,
6
+ `actor_id` text NOT NULL,
7
+ `actor_ref` text,
8
+ `source` text NOT NULL,
9
+ `status` text NOT NULL,
10
+ `error_class` text,
11
+ `duration_ms` integer,
12
+ `change_id` text,
13
+ `trace_id` text,
14
+ `payload` text DEFAULT '{}' NOT NULL,
15
+ `schema_version` integer NOT NULL,
16
+ `at` text NOT NULL,
17
+ `ingested_at` text NOT NULL
18
+ );
19
+ --> statement-breakpoint
20
+ CREATE INDEX `idx_activity_tenant_at` ON `activity_events` (`tenant_id`,`at`);--> statement-breakpoint
21
+ CREATE INDEX `idx_activity_tenant_action` ON `activity_events` (`tenant_id`,`action`);--> statement-breakpoint
22
+ CREATE INDEX `idx_activity_change` ON `activity_events` (`change_id`);
@@ -0,0 +1,26 @@
1
+ CREATE TABLE `newsletter_sends` (
2
+ `tenant_id` text NOT NULL,
3
+ `collection` text NOT NULL,
4
+ `digest_id` text NOT NULL,
5
+ `post_slugs` text DEFAULT '[]' NOT NULL,
6
+ `recipient_count` integer DEFAULT 0 NOT NULL,
7
+ `sent_at` text NOT NULL,
8
+ PRIMARY KEY(`tenant_id`, `collection`, `digest_id`)
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE TABLE `newsletter_subscribers` (
12
+ `tenant_id` text NOT NULL,
13
+ `collection` text NOT NULL,
14
+ `email` text NOT NULL,
15
+ `status` text DEFAULT 'pending' NOT NULL,
16
+ `token` text NOT NULL,
17
+ `consent_source` text,
18
+ `consent_ip_hash` text,
19
+ `subscribed_at` text NOT NULL,
20
+ `confirmed_at` text,
21
+ `unsubscribed_at` text,
22
+ `last_sent_at` text,
23
+ PRIMARY KEY(`tenant_id`, `collection`, `email`)
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE INDEX `idx_newsletter_tenant_coll_status` ON `newsletter_subscribers` (`tenant_id`,`collection`,`status`);
@@ -0,0 +1,12 @@
1
+ CREATE TABLE `social_tokens` (
2
+ `tenant_id` text NOT NULL,
3
+ `network` text NOT NULL,
4
+ `ciphertext` text NOT NULL,
5
+ `iv` text NOT NULL,
6
+ `expires_at` text,
7
+ `created_at` text NOT NULL,
8
+ `updated_at` text NOT NULL,
9
+ PRIMARY KEY(`tenant_id`, `network`)
10
+ );
11
+ --> statement-breakpoint
12
+ CREATE INDEX `idx_social_tokens_tenant` ON `social_tokens` (`tenant_id`);