@suluk/platform 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suluk/platform",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "The platform generator (C051): write one `definePlatform` manifest → it plans the shadcn-registry adds, generates the wired Hono entry, and merges each module's provision fragment into a single provision.config. The manifest compiles to a shadcn-add list + a C047 provision.config; the generator runs the adds + `@suluk/provision`. Turns the Suluk backend registry into a one-command platform. CANDIDATE tooling.",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/catalog.ts CHANGED
@@ -27,6 +27,10 @@ export const CATALOG: Record<string, CatalogEntry> = {
27
27
  cost: { mount: { kind: "route", path: "/cost", symbol: "costRoutes", from: "./routes/cost" }, provision: { symbol: "costProvision", from: "./src/provision/cost" } },
28
28
  erasure: { mount: { kind: "route", path: "/erasure", symbol: "erasureRoutes", from: "./routes/erasure" }, provision: { symbol: "erasureProvision", from: "./src/provision/erasure" } },
29
29
  email: { mount: { kind: "route", path: "/email", symbol: "emailRoutes", from: "./routes/email" } }, // stateless binding — no provision fragment (C052)
30
+ webhooks: { mount: { kind: "route", path: "/webhooks", symbol: "webhooksRoutes", from: "./routes/webhooks" }, provision: { symbol: "webhooksProvision", from: "./src/provision/webhooks" } },
31
+ // cross-cutting MIDDLEWARE (apply globally via app.use, emitted before any route) — not routed resources.
32
+ "rate-limit": { mount: { kind: "middleware", symbol: "mountRateLimit", from: "./services/rate-limit" } },
33
+ i18n: { mount: { kind: "middleware", symbol: "mountI18n", from: "./services/i18n" } },
30
34
  logs: { mount: { kind: "route", path: "/logs", symbol: "logsRoutes", from: "./routes/logs" }, provision: { symbol: "logsProvision", from: "./src/provision/logs" } },
31
35
  // dev/CI tooling — pulled in as files, no runtime mount, no provision fragment.
32
36
  journeys: { mount: { kind: "dev" } },
package/src/plan.ts CHANGED
@@ -30,17 +30,21 @@ export function planPlatform(manifest: PlatformManifest): PlatformPlan {
30
30
 
31
31
  function buildEntry(services: string[]): string {
32
32
  const imports = ['import { createApp } from "./app";'];
33
- const body: string[] = ["const app = createApp();"];
33
+ const middleware: string[] = [];
34
+ const routes: string[] = [];
35
+ // TWO passes: ALL middleware mounts (app.use / handler) emit BEFORE any route mount, so a cross-cutting concern
36
+ // (auth, rate-limit, i18n) applies to every route regardless of where it sits in the manifest.
34
37
  for (const s of services) {
35
38
  const m = CATALOG[s].mount;
36
39
  if (m.kind === "middleware") {
37
40
  imports.push(`import { ${m.symbol} } from "${m.from}";`);
38
- body.push(`${m.symbol}(app);`);
41
+ middleware.push(`${m.symbol}(app);`);
39
42
  } else if (m.kind === "route") {
40
43
  imports.push(`import { ${m.symbol} } from "${m.from}";`);
41
- body.push(`app.route("${m.path}", ${m.symbol}());`);
44
+ routes.push(`app.route("${m.path}", ${m.symbol}());`);
42
45
  }
43
46
  }
47
+ const body = ["const app = createApp();", ...middleware, ...routes];
44
48
  return `// AUTO-GENERATED by @suluk/platform from platform.config.ts — the wired Hono entry. Edit freely.\n${imports.join("\n")}\n\n${body.join("\n")}\n\nexport default app;\n`;
45
49
  }
46
50
 
package/test/plan.test.ts CHANGED
@@ -64,6 +64,25 @@ describe("cost (route + provision) + dev modules (journeys/audit — files only)
64
64
  expect(p.provisionConfig).toContain("mergeProvision([authProvision, creditsProvision])");
65
65
  });
66
66
 
67
+ test("webhooks mounts a /webhooks route and contributes a provision fragment", () => {
68
+ const p = planPlatform(definePlatform({ name: "w", registry: "acme/reg", services: ["auth", "webhooks"] }));
69
+ expect(p.entry).toContain('import { webhooksRoutes } from "./routes/webhooks";');
70
+ expect(p.entry).toContain('app.route("/webhooks", webhooksRoutes());');
71
+ expect(p.provisionConfig).toContain("mergeProvision([authProvision, webhooksProvision])");
72
+ });
73
+
74
+ test("rate-limit + i18n are MIDDLEWARE mounts (app.use, no route, no provision) emitted BEFORE routes", () => {
75
+ const p = planPlatform(definePlatform({ name: "mw", registry: "acme/reg", services: ["auth", "credits", "rate-limit", "i18n"] }));
76
+ expect(p.entry).toContain("mountRateLimit(app);");
77
+ expect(p.entry).toContain("mountI18n(app);");
78
+ // no route, no provision for either.
79
+ expect(p.entry).not.toContain('app.route("/rate-limit"');
80
+ expect(p.provisionConfig).toContain("mergeProvision([authProvision, creditsProvision])");
81
+ // two-pass ordering: every middleware mount precedes every route mount, so global middleware applies to all routes.
82
+ const lastMw = Math.max(p.entry.indexOf("mountRateLimit(app);"), p.entry.indexOf("mountI18n(app);"), p.entry.indexOf("mountAuthRoutes(app);"));
83
+ expect(lastMw).toBeLessThan(p.entry.indexOf('app.route("/credits"'));
84
+ });
85
+
67
86
  test("dev modules add shadcn refs but NO entry mount and NO provision fragment", () => {
68
87
  expect(plan.adds).toContain("acme/reg/journeys");
69
88
  expect(plan.adds).toContain("acme/reg/audit");