astroidjs 0.7.2 → 0.8.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.
package/dist/config.d.ts CHANGED
@@ -288,6 +288,23 @@ export interface TenancyConfig {
288
288
  * makes local dev work, since `wrangler dev` cannot serve subdomains.
289
289
  */
290
290
  apps?: Record<string, string>;
291
+ /**
292
+ * What a syntactically-valid tenant host whose label resolves to NOTHING
293
+ * (`resolveTenant` returned `null`) should get.
294
+ *
295
+ * `"fallthrough"` (the default) renders the ordinary site — which means a
296
+ * stranger who points a CNAME at your zone gets your homepage. `"404"` emits
297
+ * a guard that refuses the request instead, which is the right answer the
298
+ * moment tenant hosts are commercial surfaces: an unknown storefront must be
299
+ * unambiguously *not a page*, not a copy of the marketing site under someone
300
+ * else's name.
301
+ *
302
+ * Either way the decision stays visible in config rather than buried in the
303
+ * seam: `resolveTenant` decides *what exists*; this decides what not-existing
304
+ * means. Reserved labels, app labels, the apex, and off-pattern hosts are
305
+ * never affected — they aren't tenant candidates at all.
306
+ */
307
+ unknown?: "fallthrough" | "404";
291
308
  }
292
309
  export interface AstroidCron {
293
310
  /** Standard 5-field cron, UTC — e.g. `"*&#47;15 * * * *"`. */
@@ -115,8 +115,8 @@ export function generateAstroidTenancy(config) {
115
115
  " *",
116
116
  " * `null` falls through to the ordinary site — which is a real choice, not a",
117
117
  " * default: a stranger's subdomain then renders your homepage. If that is wrong",
118
- " * for this project, return null here and refuse it in the middleware's `guard`",
119
- " * with a 404, so an unknown host is unambiguously not a page.",
118
+ ' * for this project, set `tenancy.unknown: "404"` in astroid.config.ts and the',
119
+ " * generated middleware refuses the host instead — unambiguously not a page.",
120
120
  " *",
121
121
  " * This runs on EVERY request to a tenant host, so a database lookup here is a",
122
122
  " * query per request. Cache it — a module-scope Map is enough within an isolate,",
@@ -475,12 +475,11 @@ export function generateAstroidMiddleware(config) {
475
475
  // two import statements for the same module is legal and reads as an
476
476
  // oversight in a file nobody is supposed to hand-edit.
477
477
  `import { ${[
478
+ ...(tenancy && Object.keys(tenancy.apps ?? {}).length ? ["appPrefix"] : []),
478
479
  ...(portal ? ["astroidPortalGuardConfig"] : []),
479
480
  "astroidRateRules",
480
481
  ...(portal ? ["guardResponse", "portalGuard", "resolvePortalSession"] : []),
481
- ...(tenancy
482
- ? [...(Object.keys(tenancy.apps ?? {}).length ? ["appPrefix"] : []), "tenantLabel"]
483
- : []),
482
+ ...(tenancy ? ["tenantLabel"] : []),
484
483
  ].join(", ")} } from "astroidjs";`,
485
484
  'import astroidConfig from "../astroid.config.js";',
486
485
  ...(tenancy
@@ -548,20 +547,36 @@ export function generateAstroidMiddleware(config) {
548
547
  " },",
549
548
  ]
550
549
  : []),
551
- ...(portal
550
+ ...(portal || tenancy?.unknown === "404"
552
551
  ? [
553
- " // Route guard: the declarative prefix→roles table from your config.",
554
- " // An /api/* route always answers in JSON — redirecting fetch() to an",
555
- " // HTML login page returns 200 and markup, which reads as success.",
556
552
  " guard: (context) => {",
557
- " const decision = portalGuard(",
558
- " context.url.pathname,",
559
- " context.locals.portalUser,",
560
- " PORTAL_GUARD,",
561
- " );",
562
- " if (!decision) return undefined;",
563
- ' if (decision.kind === "redirect") return context.redirect(decision.location);',
564
- " return guardResponse(decision) ?? undefined;",
553
+ ...(tenancy?.unknown === "404"
554
+ ? [
555
+ " // A syntactically-valid tenant host whose label resolved to nothing is",
556
+ ' // NOT a page (config `tenancy.unknown: "404"`). Falling through would',
557
+ " // render the marketing homepage on a stranger's subdomain. Reserved",
558
+ " // labels, app labels, and the apex never reach here — tenantLabel",
559
+ " // returns null for all of them, so they are not tenant candidates.",
560
+ " if (tenantLabel(context.url.hostname, TENANCY) && !context.locals.tenant) {",
561
+ ' return new Response("Not found", { status: 404 });',
562
+ " }",
563
+ ]
564
+ : []),
565
+ ...(portal
566
+ ? [
567
+ " // Route guard: the declarative prefix→roles table from your config.",
568
+ " // An /api/* route always answers in JSON — redirecting fetch() to an",
569
+ " // HTML login page returns 200 and markup, which reads as success.",
570
+ " const decision = portalGuard(",
571
+ " context.url.pathname,",
572
+ " context.locals.portalUser,",
573
+ " PORTAL_GUARD,",
574
+ " );",
575
+ " if (!decision) return undefined;",
576
+ ' if (decision.kind === "redirect") return context.redirect(decision.location);',
577
+ " return guardResponse(decision) ?? undefined;",
578
+ ]
579
+ : [" return undefined;"]),
565
580
  " },",
566
581
  ]
567
582
  : []),
@@ -573,8 +588,8 @@ export function generateAstroidMiddleware(config) {
573
588
  " // redirect — so links built from Astro.url stay correct.",
574
589
  " //",
575
590
  " // An unknown subdomain is YOUR decision: `resolveTenant` returning null",
576
- " // falls through to the ordinary site below. Return a 404 from `guard`",
577
- " // instead if a stranger's subdomain should not render your homepage.",
591
+ " // falls through to the ordinary site below — or 404s first, when the",
592
+ ' // config sets `tenancy.unknown: "404"` (see the guard above).',
578
593
  " rewrite: (context) => {",
579
594
  ...(Object.keys(tenancy.apps ?? {}).length
580
595
  ? [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astroidjs",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Astroid — an opinionated meta-framework over Louise Toolkit and Astro for building editable, multi-editor sites on Cloudflare Workers.",
5
5
  "keywords": [
6
6
  "astro",
@@ -60,7 +60,7 @@
60
60
  "access": "public"
61
61
  },
62
62
  "dependencies": {
63
- "louise-toolkit": "0.25.0"
63
+ "louise-toolkit": "0.25.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "^24.13.3",