astroidjs 0.18.0 → 0.20.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/README.md +6 -7
- package/bin/astroid.mjs +51 -11
- package/dist/commerce/adapters.js +3 -3
- package/dist/commerce/checkout.js +1 -1
- package/dist/commerce/mirror.js +5 -4
- package/dist/commerce/roles.js +3 -3
- package/dist/commerce/secrets.d.ts +7 -0
- package/dist/commerce/secrets.js +12 -3
- package/dist/config.d.ts +85 -16
- package/dist/config.js +111 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/portal/guard.js +1 -1
- package/dist/project/generate.js +96 -52
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +1 -0
- package/dist/project/migrations.d.ts +26 -0
- package/dist/project/migrations.js +78 -0
- package/dist/project/scaffold.d.ts +6 -0
- package/dist/project/scaffold.js +33 -11
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/messages.d.ts +6 -0
- package/dist/queues/messages.js +17 -2
- package/dist/queues/scaffold.js +5 -1
- package/dist/schema/collections.d.ts +6 -0
- package/dist/schema/collections.js +14 -2
- package/dist/schema/framework.js +1 -1
- package/dist/schema/generate.js +48 -4
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/rate-rules.d.ts +9 -2
- package/dist/security/rate-rules.js +46 -22
- package/dist/seo/routes.js +3 -2
- package/dist/shape.d.ts +6 -0
- package/dist/shape.js +14 -0
- package/dist/status.js +22 -10
- package/dist/worker/generate.js +142 -10
- package/dist/workflow/advance.js +1 -1
- package/dist/workflow/config.js +1 -1
- package/package.json +3 -3
- package/src/components/Credit.astro +70 -0
- package/src/components/StageBar.astro +1 -1
- package/src/components/media-meta.ts +1 -1
package/dist/schema/framework.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* (the worker route plan). */
|
|
11
11
|
export function capturesInquiries(config) {
|
|
12
12
|
// Explicit override wins—a site whose inquiry surface is a bespoke section
|
|
13
|
-
// (
|
|
13
|
+
// (a custom `contactForm`, say) can't be detected from the built-in
|
|
14
14
|
// vocabulary, so it says so directly.
|
|
15
15
|
if (typeof config.inquiries === "boolean")
|
|
16
16
|
return config.inquiries;
|
package/dist/schema/generate.js
CHANGED
|
@@ -11,7 +11,51 @@
|
|
|
11
11
|
// result to disk and formats it. Import ordering matches the site's schema.ts so
|
|
12
12
|
// a formatter never re-flags the generated file.
|
|
13
13
|
import { generateCatalogTable } from "../commerce/mirror.js";
|
|
14
|
+
import { astroidHasEditor } from "../shape.js";
|
|
14
15
|
import { astroidFrameworkTables } from "./framework.js";
|
|
16
|
+
/** The Drizzle column builders a catalog table's source uses. */
|
|
17
|
+
function catalogBuilders(catalog) {
|
|
18
|
+
const builders = ["integer", "sqliteTable", "text"];
|
|
19
|
+
if (catalog?.includes("real("))
|
|
20
|
+
builders.push("real");
|
|
21
|
+
return builders.sort();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The schema of an app with no editor (`editor: false`): no `pages`, no
|
|
25
|
+
* versions, and no framework tables, because nothing here edits them. What's
|
|
26
|
+
* left is what the config itself implies, the commerce catalog, and the site's
|
|
27
|
+
* own tables.
|
|
28
|
+
*
|
|
29
|
+
* A framework table the app only READS, such as `siteSettings` in a database
|
|
30
|
+
* another app owns, is imported straight from `louise-toolkit/db` where it's
|
|
31
|
+
* queried. Re-exporting it here would put it in front of drizzle-kit, which
|
|
32
|
+
* would then write migrations for a table this app doesn't own.
|
|
33
|
+
*/
|
|
34
|
+
function generateAppSchema(config) {
|
|
35
|
+
const catalog = generateCatalogTable(config);
|
|
36
|
+
return [
|
|
37
|
+
"// Generated by astroidjs—do not hand-edit.",
|
|
38
|
+
"// Source: your defineAstroid config. This app has no editor (`editor: false`),",
|
|
39
|
+
"// so it owns no content tables. To read one that another app owns, such as",
|
|
40
|
+
'// `siteSettings`, import it from "louise-toolkit/db" where you query it.',
|
|
41
|
+
...(catalog
|
|
42
|
+
? [
|
|
43
|
+
`import { ${catalogBuilders(catalog).join(", ")} } from "drizzle-orm/sqlite-core";`,
|
|
44
|
+
// The catalog's JSON columns are typed with it; the editor schema
|
|
45
|
+
// imports it for `pages.sections` anyway.
|
|
46
|
+
...(catalog.includes("JsonValue")
|
|
47
|
+
? ['import type { JsonValue } from "louise-toolkit/content";']
|
|
48
|
+
: []),
|
|
49
|
+
"",
|
|
50
|
+
catalog,
|
|
51
|
+
]
|
|
52
|
+
: [""]),
|
|
53
|
+
"// Site-owned tables, declared in src/schema.site.ts and re-exported here so",
|
|
54
|
+
"// drizzle-kit and the worker see them. Empty until the app adds one.",
|
|
55
|
+
'export * from "./schema.site.js";',
|
|
56
|
+
"",
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
15
59
|
/**
|
|
16
60
|
* Generate the TypeScript source of a site's Drizzle schema from an Astroid
|
|
17
61
|
* config. The output is a drop-in replacement for the hand-written `schema.ts`:
|
|
@@ -19,6 +63,8 @@ import { astroidFrameworkTables } from "./framework.js";
|
|
|
19
63
|
* table, and the re-exported framework tables the config selects.
|
|
20
64
|
*/
|
|
21
65
|
export function generateAstroidSchema(config) {
|
|
66
|
+
if (!astroidHasEditor(config))
|
|
67
|
+
return generateAppSchema(config);
|
|
22
68
|
const framework = astroidFrameworkTables(config); // sorted
|
|
23
69
|
// pagesColumns is spread into `pages`; the framework tables are re-exported.
|
|
24
70
|
// One import brings them all in (matching the site) so nothing is unused.
|
|
@@ -27,13 +73,11 @@ export function generateAstroidSchema(config) {
|
|
|
27
73
|
// Only import the column builders the emitted source actually uses—an
|
|
28
74
|
// unused import is a lint error in the project we're generating into, and a
|
|
29
75
|
// missing one (`real`, from the catalog's price/sortOrder) is a type error.
|
|
30
|
-
const drizzleImports =
|
|
31
|
-
if (catalog?.includes("real("))
|
|
32
|
-
drizzleImports.push("real");
|
|
76
|
+
const drizzleImports = catalogBuilders(catalog);
|
|
33
77
|
return [
|
|
34
78
|
"// Generated by astroidjs—do not hand-edit.",
|
|
35
79
|
"// Source: your defineAstroid config.",
|
|
36
|
-
`import { ${drizzleImports.
|
|
80
|
+
`import { ${drizzleImports.join(", ")} } from "drizzle-orm/sqlite-core";`,
|
|
37
81
|
'import { collectionVersionsTable, type JsonValue } from "louise-toolkit/content";',
|
|
38
82
|
`import { ${dbImports.join(", ")} } from "louise-toolkit/db";`,
|
|
39
83
|
"",
|
package/dist/security/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ASTROID_CHECKOUT_PATH, ASTROID_PORTAL_BASE_PATH, astroidRateRules, type RateRule, } from "./rate-rules.js";
|
|
1
|
+
export { ASTROID_API_PREFIX, ASTROID_CHECKOUT_PATH, ASTROID_PORTAL_BASE_PATH, astroidRateRules, type RateRule, } from "./rate-rules.js";
|
package/dist/security/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Copyright (c) 2026 BowenLabs. Astroid is MIT licensed.
|
|
2
|
-
export { ASTROID_CHECKOUT_PATH, ASTROID_PORTAL_BASE_PATH, astroidRateRules, } from "./rate-rules.js";
|
|
2
|
+
export { ASTROID_API_PREFIX, ASTROID_CHECKOUT_PATH, ASTROID_PORTAL_BASE_PATH, astroidRateRules, } from "./rate-rules.js";
|
|
@@ -9,10 +9,17 @@ export type { RateRule };
|
|
|
9
9
|
export declare const ASTROID_PORTAL_BASE_PATH = "/api/portal-auth";
|
|
10
10
|
/** Path the commerce module's checkout POSTs to. */
|
|
11
11
|
export declare const ASTROID_CHECKOUT_PATH = "/api/checkout";
|
|
12
|
+
/**
|
|
13
|
+
* Where an app with no editor (`editor: false`) serves its versioned JSON API.
|
|
14
|
+
* A web client and a later native client call the same routes, so a new
|
|
15
|
+
* version is a new prefix rather than a change to the one clients already use.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ASTROID_API_PREFIX = "/api/v1";
|
|
12
18
|
/**
|
|
13
19
|
* The rule set for a project, derived from its config: the editor sign-in
|
|
14
|
-
* surface
|
|
15
|
-
* checkout when commerce is configured
|
|
20
|
+
* surface unless the project has no editor, the portal's credential surfaces
|
|
21
|
+
* when a portal is enabled, checkout when commerce is configured, and the
|
|
22
|
+
* versioned API for an app with no editor.
|
|
16
23
|
*
|
|
17
24
|
* Rules are matched first-wins, and `security.rateRules` from the config are
|
|
18
25
|
* placed FIRST—so a site tightens or loosens any default by declaring its own
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// The contact form is also absent by design: it's a worker route with its own
|
|
17
17
|
// per-form limiter, and worker routes are matched before Astro's middleware ever
|
|
18
18
|
// runs, so a rule here would never fire.
|
|
19
|
+
import { astroidHasEditor } from "../shape.js";
|
|
19
20
|
/**
|
|
20
21
|
* Base path the customer/portal Better Auth instance mounts at—its own
|
|
21
22
|
* handler, separate from the editor's `/api/auth`. Fixed by Astroid so the rate
|
|
@@ -24,14 +25,21 @@
|
|
|
24
25
|
export const ASTROID_PORTAL_BASE_PATH = "/api/portal-auth";
|
|
25
26
|
/** Path the commerce module's checkout POSTs to. */
|
|
26
27
|
export const ASTROID_CHECKOUT_PATH = "/api/checkout";
|
|
28
|
+
/**
|
|
29
|
+
* Where an app with no editor (`editor: false`) serves its versioned JSON API.
|
|
30
|
+
* A web client and a later native client call the same routes, so a new
|
|
31
|
+
* version is a new prefix rather than a change to the one clients already use.
|
|
32
|
+
*/
|
|
33
|
+
export const ASTROID_API_PREFIX = "/api/v1";
|
|
27
34
|
/** Ten minutes. Every default budget uses this window—long enough that a
|
|
28
35
|
* burst can't wait it out, short enough that a false positive self-heals. */
|
|
29
36
|
const WINDOW = 600;
|
|
30
37
|
const exact = (path) => (p) => p === path;
|
|
31
38
|
/**
|
|
32
39
|
* The rule set for a project, derived from its config: the editor sign-in
|
|
33
|
-
* surface
|
|
34
|
-
* checkout when commerce is configured
|
|
40
|
+
* surface unless the project has no editor, the portal's credential surfaces
|
|
41
|
+
* when a portal is enabled, checkout when commerce is configured, and the
|
|
42
|
+
* versioned API for an app with no editor.
|
|
35
43
|
*
|
|
36
44
|
* Rules are matched first-wins, and `security.rateRules` from the config are
|
|
37
45
|
* placed FIRST—so a site tightens or loosens any default by declaring its own
|
|
@@ -39,26 +47,29 @@ const exact = (path) => (p) => p === path;
|
|
|
39
47
|
*/
|
|
40
48
|
export function astroidRateRules(config) {
|
|
41
49
|
const rules = [...(config.security?.rateRules ?? [])];
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
// The editor's sign-in, which an app with no editor doesn't serve.
|
|
51
|
+
if (astroidHasEditor(config)) {
|
|
52
|
+
// Magic-link sign-in is the email-bombing target: without a cap, anyone who
|
|
53
|
+
// knows an editor's address can trigger unbounded sign-in mail (their inbox,
|
|
54
|
+
// your Email + Worker spend). Tightest budget in the set.
|
|
55
|
+
rules.push({
|
|
56
|
+
name: "magic-link",
|
|
57
|
+
method: "POST",
|
|
58
|
+
match: exact("/api/auth/sign-in/magic-link"),
|
|
59
|
+
limit: 5,
|
|
60
|
+
windowSec: WINDOW,
|
|
61
|
+
});
|
|
62
|
+
// Everything else Better Auth serves (passkey challenges, sign-out, callbacks)
|
|
63
|
+
// behind a looser catch-all. Ordered after the specific rule above, which
|
|
64
|
+
// matters: `matchRateRule` takes the first match.
|
|
65
|
+
rules.push({
|
|
66
|
+
name: "auth",
|
|
67
|
+
method: "POST",
|
|
68
|
+
match: (p) => p.startsWith("/api/auth/"),
|
|
69
|
+
limit: 30,
|
|
70
|
+
windowSec: WINDOW,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
62
73
|
if (config.portal?.enabled) {
|
|
63
74
|
// The portal's mount is configurable (a site may already ship a second
|
|
64
75
|
// instance at its own path), so the credential-surface rules must track the
|
|
@@ -106,5 +117,18 @@ export function astroidRateRules(config) {
|
|
|
106
117
|
windowSec: WINDOW,
|
|
107
118
|
});
|
|
108
119
|
}
|
|
120
|
+
if (!astroidHasEditor(config)) {
|
|
121
|
+
// An app's own JSON API: quotes, orders, account changes. Looser than
|
|
122
|
+
// checkout because a client posts here as a cart changes, not once per
|
|
123
|
+
// purchase, so this is abuse control rather than flow control. After the
|
|
124
|
+
// specific rules, so a tighter budget for one route wins.
|
|
125
|
+
rules.push({
|
|
126
|
+
name: "api",
|
|
127
|
+
method: "POST",
|
|
128
|
+
match: (p) => p.startsWith(`${ASTROID_API_PREFIX}/`),
|
|
129
|
+
limit: 120,
|
|
130
|
+
windowSec: WINDOW,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
109
133
|
return rules;
|
|
110
134
|
}
|
package/dist/seo/routes.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// rules are: which routes exist is a function of which modules are enabled, and
|
|
14
14
|
// a hand-maintained list drifts the moment someone turns a portal on.
|
|
15
15
|
import { ASTROID_PORTAL_BASE_PATH } from "../security/rate-rules.js";
|
|
16
|
+
import { astroidHasEditor } from "../shape.js";
|
|
16
17
|
/**
|
|
17
18
|
* Paths that must never be indexed, derived from the config: the editor and its
|
|
18
19
|
* API always, plus the portal's account + auth surfaces and checkout when those
|
|
@@ -25,8 +26,8 @@ export function astroidNoindexPaths(config) {
|
|
|
25
26
|
const paths = [
|
|
26
27
|
// Every worker route (editor CRUD, media, forms) and Better Auth.
|
|
27
28
|
"/api/",
|
|
28
|
-
// The editor entry point.
|
|
29
|
-
"/louise",
|
|
29
|
+
// The editor entry point, when there is an editor.
|
|
30
|
+
...(astroidHasEditor(config) ? ["/louise"] : []),
|
|
30
31
|
];
|
|
31
32
|
if (config.portal?.enabled) {
|
|
32
33
|
paths.push(ASTROID_PORTAL_BASE_PATH, "/account", "/login", "/register", "/reset-password");
|
package/dist/shape.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AstroidConfig } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether the project has a Louise editor: its routes, its sign-in, and the
|
|
4
|
+
* content tables it edits. True unless the config sets `editor: false`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function astroidHasEditor(config: AstroidConfig): boolean;
|
package/dist/shape.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) 2026 BowenLabs. Astroid is MIT licensed.
|
|
2
|
+
//
|
|
3
|
+
// The project's shape: a Louise-edited site, or an app with no pages to edit.
|
|
4
|
+
//
|
|
5
|
+
// Its own module, and dependency-free, because nearly every generator asks the
|
|
6
|
+
// question and `config.ts` imports some of them at runtime. A type-only import
|
|
7
|
+
// of the config keeps that from becoming a cycle.
|
|
8
|
+
/**
|
|
9
|
+
* Whether the project has a Louise editor: its routes, its sign-in, and the
|
|
10
|
+
* content tables it edits. True unless the config sets `editor: false`.
|
|
11
|
+
*/
|
|
12
|
+
export function astroidHasEditor(config) {
|
|
13
|
+
return config.editor !== false;
|
|
14
|
+
}
|
package/dist/status.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { commerceSecretNames, resolveCommerceStatus } from "./commerce/secrets.js";
|
|
20
20
|
import { ASTROID_VITALS_SECRET_NAMES } from "./analytics/index.js";
|
|
21
21
|
import { EMAIL_SECRET_NAMES, resolveMailerStatus } from "./email/send.js";
|
|
22
|
+
import { astroidHasEditor } from "./shape.js";
|
|
22
23
|
/**
|
|
23
24
|
* Secrets every Astroid site has, independent of which modules are on.
|
|
24
25
|
*
|
|
@@ -40,17 +41,25 @@ export const ASTROID_CORE_SECRET_NAMES = [
|
|
|
40
41
|
* and a marketing site shouldn't be told to provision a Square token.
|
|
41
42
|
*/
|
|
42
43
|
export function astroidSecretNames(config) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
// An app with no editor signs nobody in unless it has a portal, which needs
|
|
45
|
+
// the session secret and mail, not the editor's Turnstile pair.
|
|
46
|
+
const editor = astroidHasEditor(config);
|
|
47
|
+
const portal = Boolean(config.portal?.enabled);
|
|
48
|
+
const groups = {};
|
|
49
|
+
if (editor)
|
|
50
|
+
groups.core = [...ASTROID_CORE_SECRET_NAMES];
|
|
51
|
+
else if (portal)
|
|
52
|
+
groups.core = ["SESSION_SECRET"];
|
|
53
|
+
if (editor || portal)
|
|
54
|
+
groups.email = [...EMAIL_SECRET_NAMES];
|
|
47
55
|
const commerce = commerceSecretNames(config.commerce);
|
|
48
56
|
if (commerce.length > 0)
|
|
49
57
|
groups.commerce = commerce;
|
|
50
58
|
// The CWV read-back's API credentials. Collection needs none of this—only
|
|
51
59
|
// querying the p75 back out does, because the Analytics Engine SQL API is
|
|
52
|
-
// account-scoped and has no binding.
|
|
53
|
-
|
|
60
|
+
// account-scoped and has no binding. The editor's Health panel reads it.
|
|
61
|
+
if (editor)
|
|
62
|
+
groups.vitals = [...ASTROID_VITALS_SECRET_NAMES];
|
|
54
63
|
return groups;
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
@@ -68,8 +77,11 @@ export async function astroidModuleStatus(config, env) {
|
|
|
68
77
|
resolveCommerceStatus(config.commerce, secretEnv),
|
|
69
78
|
resolveMailerStatus(env),
|
|
70
79
|
]);
|
|
71
|
-
const reports = [
|
|
72
|
-
|
|
80
|
+
const reports = [];
|
|
81
|
+
// Mail is for signing in: the editor's magic link, or a portal's password
|
|
82
|
+
// reset. An app with neither sends none, so there's nothing to report.
|
|
83
|
+
if (astroidHasEditor(config) || config.portal?.enabled) {
|
|
84
|
+
reports.push({
|
|
73
85
|
module: "email",
|
|
74
86
|
enabled: true,
|
|
75
87
|
configured: mailer.configured,
|
|
@@ -79,8 +91,8 @@ export async function astroidModuleStatus(config, env) {
|
|
|
79
91
|
: // Naming the log is the useful part: the magic link IS in the console,
|
|
80
92
|
// and someone who doesn't know that concludes sign-in is broken.
|
|
81
93
|
"dormant — messages are logged to the console (the magic link is in the log), not sent",
|
|
82
|
-
}
|
|
83
|
-
|
|
94
|
+
});
|
|
95
|
+
}
|
|
84
96
|
if (commerce.enabled) {
|
|
85
97
|
reports.push({
|
|
86
98
|
module: "commerce",
|
package/dist/worker/generate.js
CHANGED
|
@@ -18,6 +18,7 @@ import { ASTROID_HEALTH_CRON, astroidCron, astroidUsesQueues } from "../queues/m
|
|
|
18
18
|
import { ASTROID_EDIT_SESSION_CLASS, ASTROID_REALTIME_BINDING, usesRealtime, } from "../realtime/scaffold.js";
|
|
19
19
|
import { capturesInquiries } from "../schema/framework.js";
|
|
20
20
|
import { astroidCspStyleSrc } from "../security/csp-origins.js";
|
|
21
|
+
import { astroidHasEditor } from "../shape.js";
|
|
21
22
|
import { ASTROID_REWRITE_EXCLUDE, ASTROID_TENANT_PREFIX } from "../tenancy/index.js";
|
|
22
23
|
import { astroidEditorRoutePlan } from "./routes.js";
|
|
23
24
|
// Astroid's default editable site_settings surface—the columns the Settings
|
|
@@ -52,6 +53,8 @@ export const ASTROID_SETTINGS_IMAGE_KEYS = ["logoUrl", "faviconUrl", "defaultOgI
|
|
|
52
53
|
* emitted only when a brand captures inquiries.
|
|
53
54
|
*/
|
|
54
55
|
export function generateAstroidWorker(config) {
|
|
56
|
+
if (!astroidHasEditor(config))
|
|
57
|
+
return generateAppWorker(config);
|
|
55
58
|
const inquiries = capturesInquiries(config);
|
|
56
59
|
const queues = astroidUsesQueues(config);
|
|
57
60
|
const cron = astroidCron(config);
|
|
@@ -564,6 +567,111 @@ export function generateAstroidWorker(config) {
|
|
|
564
567
|
}
|
|
565
568
|
return lines.join("\n");
|
|
566
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* The worker of an app with no editor (`editor: false`): the public status
|
|
572
|
+
* route, the SSR fallback, and whatever the config's modules add (a queue
|
|
573
|
+
* consumer, the crons), with no editor route and no auth seam.
|
|
574
|
+
*
|
|
575
|
+
* The gate stays, with a resolver that never finds an editor. Nothing under
|
|
576
|
+
* `/api/louise` belongs to one here, so it refuses everything there except the
|
|
577
|
+
* public status probe, and it gives route responses the security headers the
|
|
578
|
+
* middleware never sees.
|
|
579
|
+
*/
|
|
580
|
+
function generateAppWorker(config) {
|
|
581
|
+
const queues = astroidUsesQueues(config);
|
|
582
|
+
const cron = astroidCron(config);
|
|
583
|
+
const customCrons = config.crons ?? [];
|
|
584
|
+
const scheduled = cron !== null || customCrons.length > 0;
|
|
585
|
+
const lines = [];
|
|
586
|
+
const p = (s = "") => lines.push(s);
|
|
587
|
+
p("// Generated by astroidjs—do not hand-edit.");
|
|
588
|
+
p("// Source: your defineAstroid config. This app has no editor (`editor: false`),");
|
|
589
|
+
p("// so it serves no editor routes and resolves no editor session.");
|
|
590
|
+
p('import { handle } from "@astrojs/cloudflare/handler";');
|
|
591
|
+
p('import { d1Check, statusRoute } from "louise-toolkit/editor";');
|
|
592
|
+
if (queues)
|
|
593
|
+
p('import { processBatch } from "louise-toolkit/queues";');
|
|
594
|
+
p('import { composeWorker, type WorkerRoute, withEdgeCache } from "louise-toolkit/worker";');
|
|
595
|
+
if (queues)
|
|
596
|
+
p('import type { AstroidQueueMessage } from "astroidjs";');
|
|
597
|
+
if (config.status?.checks) {
|
|
598
|
+
p("// Your STATUS seam: the app's own checks for the public status route.");
|
|
599
|
+
p("// Scaffolded once and yours to edit.");
|
|
600
|
+
p('import { statusChecks } from "./status-checks.js";');
|
|
601
|
+
}
|
|
602
|
+
if (queues) {
|
|
603
|
+
p("// Your QUEUE seam: what each message actually does. Scaffolded once and");
|
|
604
|
+
p("// yours to edit.");
|
|
605
|
+
p('import { handleQueueMessage } from "./queue.js";');
|
|
606
|
+
}
|
|
607
|
+
p();
|
|
608
|
+
p("// --- public status ---------------------------------------------------------");
|
|
609
|
+
p("// What statusRoute answers an outside probe with: 200 when every check");
|
|
610
|
+
p("// passes, 503 when any fails, throws, or takes over two seconds. Anyone can");
|
|
611
|
+
p("// make these run, so each is one cheap read, and a burst of probes reuses one");
|
|
612
|
+
p("// result per isolate for STATUS_REUSE_MS.");
|
|
613
|
+
p("const STATUS_REUSE_MS = 10_000;");
|
|
614
|
+
p("const STATUS_CHECKS = {");
|
|
615
|
+
p(" // D1 answers `SELECT 1`.");
|
|
616
|
+
p(" d1: d1Check((env: CloudflareEnv) => env.DB),");
|
|
617
|
+
if (config.status?.checks) {
|
|
618
|
+
p(" // The app's own, from src/status-checks.ts. Spread last, so a check with");
|
|
619
|
+
p(" // the same name replaces Astroid's on purpose.");
|
|
620
|
+
p(" ...statusChecks,");
|
|
621
|
+
}
|
|
622
|
+
p("};");
|
|
623
|
+
p();
|
|
624
|
+
p("const routes: WorkerRoute<CloudflareEnv>[] = [");
|
|
625
|
+
p(" // Public status for an outside probe (GET/HEAD /api/louise/status). A");
|
|
626
|
+
p(" // publicRoute, so the gate below lets an anonymous probe through.");
|
|
627
|
+
p(" statusRoute({ checks: STATUS_CHECKS, reuseMs: STATUS_REUSE_MS }),");
|
|
628
|
+
p("];");
|
|
629
|
+
p();
|
|
630
|
+
p(queues
|
|
631
|
+
? "export default composeWorker<CloudflareEnv, AstroidQueueMessage>({"
|
|
632
|
+
: "export default composeWorker<CloudflareEnv>({");
|
|
633
|
+
p(" routes,");
|
|
634
|
+
p(" // No editor, so no request under /api/louise resolves to one. The gate");
|
|
635
|
+
p(" // refuses everything there except the public status probe, and gives route");
|
|
636
|
+
p(" // responses the security headers the middleware never sees.");
|
|
637
|
+
p(" gate: { resolveEditor: () => null },");
|
|
638
|
+
p(" // The SSR fallback, in the Worker cache (ADR 0004). It stores only a");
|
|
639
|
+
p(" // response that opts in with `Astro.cache.set(...)`, and it strips the CDN");
|
|
640
|
+
p(" // directive from every other one, so Cloudflare's cookie-blind edge cache");
|
|
641
|
+
p(" // never stores a signed-in customer's page.");
|
|
642
|
+
p(" fetch: withEdgeCache((request, env, ctx) => handle(request, env, ctx)),");
|
|
643
|
+
if (queues) {
|
|
644
|
+
p(" // Queue consumer. `processBatch` acks or retries each message");
|
|
645
|
+
p(" // INDEPENDENTLY, so one poisoned message can't block the rest of the");
|
|
646
|
+
p(" // batch; Cloudflare routes it to the DLQ once it exceeds max_retries.");
|
|
647
|
+
p(" queue: (batch, env) => processBatch(batch, (message) => handleQueueMessage(env, message)),");
|
|
648
|
+
}
|
|
649
|
+
if (scheduled) {
|
|
650
|
+
p(" // Cron. Cloudflare fires this for EVERY trigger in wrangler.jsonc and");
|
|
651
|
+
p(" // identifies which by `controller.cron`, so dispatch on it.");
|
|
652
|
+
p(" scheduled: (controller, env, ctx) => {");
|
|
653
|
+
if (cron) {
|
|
654
|
+
p(` if (controller.cron === ${JSON.stringify(cron)}) {`);
|
|
655
|
+
p(" // Catalog safety net: a missed webhook leaves the catalog stale only");
|
|
656
|
+
p(" // until the next tick. Enqueued, so it takes the retry + DLQ path.");
|
|
657
|
+
p(' ctx.waitUntil(env.COMMERCE_QUEUE.send({ kind: "catalog_refresh" }));');
|
|
658
|
+
p(" return;");
|
|
659
|
+
p(" }");
|
|
660
|
+
}
|
|
661
|
+
for (const custom of customCrons) {
|
|
662
|
+
p(` if (controller.cron === ${JSON.stringify(custom.expression)}) {`);
|
|
663
|
+
p(" // Enqueued, not run inline: same retry + DLQ path as everything");
|
|
664
|
+
p(" // else, and a slow job can't hold the scheduled handler open.");
|
|
665
|
+
p(` ctx.waitUntil(env.COMMERCE_QUEUE.send(${JSON.stringify(custom.message)}));`);
|
|
666
|
+
p(" return;");
|
|
667
|
+
p(" }");
|
|
668
|
+
}
|
|
669
|
+
p(" },");
|
|
670
|
+
}
|
|
671
|
+
p("});");
|
|
672
|
+
p();
|
|
673
|
+
return lines.join("\n");
|
|
674
|
+
}
|
|
567
675
|
/**
|
|
568
676
|
* Generate the Astro middleware (`middleware.ts`) from an Astroid config: the
|
|
569
677
|
* shared Louise flow (rate-limit the unauthenticated POST surface → resolve editor
|
|
@@ -592,6 +700,8 @@ export function generateAstroidMiddleware(config) {
|
|
|
592
700
|
// origins (the Square SDK's stylesheet) are baked in here; `astroid build`
|
|
593
701
|
// regenerates this file, so a config change lands on the next deploy.
|
|
594
702
|
const cspStyleSrc = astroidCspStyleSrc(config);
|
|
703
|
+
// An app with no editor has no auth seam and no pages to redirect between.
|
|
704
|
+
const editor = astroidHasEditor(config);
|
|
595
705
|
const portal = astroidPortal(config);
|
|
596
706
|
const tenancy = config.tenancy;
|
|
597
707
|
const rewritePrefix = tenancy?.rewritePrefix ?? ASTROID_TENANT_PREFIX;
|
|
@@ -599,13 +709,17 @@ export function generateAstroidMiddleware(config) {
|
|
|
599
709
|
return [
|
|
600
710
|
"// Generated by astroidjs—do not hand-edit.",
|
|
601
711
|
"// The shared Louise middleware: rate-limit the unauthenticated POST surfaces,",
|
|
602
|
-
|
|
712
|
+
...(editor
|
|
713
|
+
? ["// then resolve the editor session + sticky ?louise edit mode, then apply"]
|
|
714
|
+
: ["// then (this app has no editor, so there's no session to resolve) apply"]),
|
|
603
715
|
"// content-freshness + transport-security headers, and rewrite the style-src of",
|
|
604
716
|
"// the CSP header Astro's security.csp emits so Louise's data-driven inline",
|
|
605
717
|
"// styles + inlined data: brand font are allowed.",
|
|
606
718
|
'import { env } from "cloudflare:workers";',
|
|
607
719
|
'import { createLouiseMiddleware } from "@louise-toolkit/astro";',
|
|
608
|
-
|
|
720
|
+
...(editor
|
|
721
|
+
? ['import { db, pageRedirects, resolvePageRedirect } from "louise-toolkit/db";']
|
|
722
|
+
: []),
|
|
609
723
|
// One `astroidjs` import, composed from what this config actually uses—two
|
|
610
724
|
// import statements for the same module is legal and reads as an
|
|
611
725
|
// oversight in a file nobody is supposed to hand-edit.
|
|
@@ -623,15 +737,21 @@ export function generateAstroidMiddleware(config) {
|
|
|
623
737
|
'import { resolveTenant } from "./tenancy.js";',
|
|
624
738
|
]
|
|
625
739
|
: []),
|
|
626
|
-
|
|
627
|
-
|
|
740
|
+
...(editor
|
|
741
|
+
? [
|
|
742
|
+
"// TODO(astroid): your AUTH seam—same resolveEditor as the generated worker.ts.",
|
|
743
|
+
'import { resolveEditor } from "./auth.js";',
|
|
744
|
+
]
|
|
745
|
+
: []),
|
|
628
746
|
// The portal's resolver lives in its OWN module, not the editor's auth
|
|
629
747
|
// seam—they're separate Better Auth instances and must not share a file.
|
|
630
748
|
...(portal ? ['import { resolvePortalUser } from "./portal-auth.js";'] : []),
|
|
631
749
|
"",
|
|
632
750
|
"// Rate-limit the public, unauthenticated POST surface, keyed by client IP",
|
|
633
751
|
"// (fixed-window KV counter that fails open). Derived from your config: the",
|
|
634
|
-
|
|
752
|
+
...(editor
|
|
753
|
+
? ["// editor magic-link always, plus the portal credential surfaces and checkout"]
|
|
754
|
+
: ["// versioned API under /api/v1, plus the portal credential surfaces and checkout"]),
|
|
635
755
|
"// when those are enabled. Add your own via `security.rateRules` in the config—",
|
|
636
756
|
"// they're matched first, so they can also override a default's budget.",
|
|
637
757
|
"// `env.RL` is read per request (a getter)—a KV binding is only valid in",
|
|
@@ -657,15 +777,27 @@ export function generateAstroidMiddleware(config) {
|
|
|
657
777
|
: []),
|
|
658
778
|
"",
|
|
659
779
|
"export const onRequest = createLouiseMiddleware({",
|
|
660
|
-
|
|
780
|
+
...(editor
|
|
781
|
+
? [" resolveEditor: (request) => resolveEditor(request),"]
|
|
782
|
+
: [
|
|
783
|
+
" // No editor (`editor: false`), so no request resolves to one and edit",
|
|
784
|
+
" // mode never turns on.",
|
|
785
|
+
" resolveEditor: () => null,",
|
|
786
|
+
]),
|
|
661
787
|
" rateLimit: { rules: RATE_RULES, kv: () => env.RL },",
|
|
662
788
|
" // The same deny-by-default gate for /api/louise routes that reach Astro—",
|
|
663
789
|
" // anything the worker's routes didn't answer. A second check behind the",
|
|
664
|
-
|
|
790
|
+
editor
|
|
791
|
+
? " // worker's gate, and free: the editor is resolved here on every request."
|
|
792
|
+
: " // worker's gate: with no editor, it refuses all but the public routes.",
|
|
665
793
|
" apiGate: true,",
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
794
|
+
...(editor
|
|
795
|
+
? [
|
|
796
|
+
" // A renamed page's old URL answers a 301 to the new one. It runs only after",
|
|
797
|
+
" // the page answered 404, so a page later created on the old path wins.",
|
|
798
|
+
" redirectFor: (path) => resolvePageRedirect(db(env.DB), pageRedirects, path),",
|
|
799
|
+
]
|
|
800
|
+
: []),
|
|
669
801
|
// `extend` runs once and may need to populate BOTH—a tenanted site with a
|
|
670
802
|
// portal resolves a tenant and a customer on the same request.
|
|
671
803
|
...(portal || tenancy
|
package/dist/workflow/advance.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// expected—`UPDATE … SET stage = ? WHERE id = ? AND stage = ?`—and treat "0 rows
|
|
11
11
|
// changed" as the conflict signal rather than checking first and hoping.
|
|
12
12
|
//
|
|
13
|
-
// ORDERING MATTERS, and the reference gets it wrong.
|
|
13
|
+
// ORDERING MATTERS, and the reference gets it wrong. Its floor route
|
|
14
14
|
// inserts the sign-off row and THEN runs the guarded update, so a double submit
|
|
15
15
|
// writes two audit rows even though only one advance lands. Here the guarded
|
|
16
16
|
// update goes first and the audit row is written only if it actually moved the
|
package/dist/workflow/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// `defineWorkflow`—staged, audited pipelines.
|
|
4
4
|
//
|
|
5
|
-
// The shape this generalizes is
|
|
5
|
+
// The shape this generalizes is a client site's production floor, and the
|
|
6
6
|
// framing correction in #256 is the important part: despite the name "order
|
|
7
7
|
// tracker", it is NOT queue- or Durable-Object-driven. It is a synchronous SSR
|
|
8
8
|
// + D1 state machine—an integer `stage` column advanced by sign-off rows,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astroidjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|
|
@@ -64,14 +64,14 @@
|
|
|
64
64
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
65
65
|
"@vitest/coverage-v8": "4.1.11",
|
|
66
66
|
"astro": "^7.2.9",
|
|
67
|
-
"louise-toolkit": "^0.
|
|
67
|
+
"louise-toolkit": "^0.37.0",
|
|
68
68
|
"solid-js": "^1.9.15",
|
|
69
69
|
"typescript": "^6.0.3",
|
|
70
70
|
"vitest": "^4.1.11"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"astro": "^7.0.9",
|
|
74
|
-
"louise-toolkit": "^0.
|
|
74
|
+
"louise-toolkit": "^0.37.0",
|
|
75
75
|
"solid-js": "^1.9.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependenciesMeta": {
|