create-signet-app 0.5.0 → 0.7.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 (39) hide show
  1. package/README.md +31 -8
  2. package/base/api/api/app.ts +57 -8
  3. package/base/api/api/db/schema.ts +16 -4
  4. package/base/api/api/env.ts +8 -0
  5. package/base/api/api/server.ts +6 -0
  6. package/base/api/api/services.ts +43 -3
  7. package/base/api/drizzle/0002_ai_paywalls_workflows.sql +77 -0
  8. package/base/api/drizzle/meta/0002_snapshot.json +1759 -0
  9. package/base/api/drizzle/meta/_journal.json +7 -0
  10. package/base/shared/README.md +87 -0
  11. package/base/web/index.html +5 -0
  12. package/base/web/src/main.tsx +2 -0
  13. package/base/web/src/routeTree.gen.ts +25 -0
  14. package/base/web/src/router.test.ts +1 -0
  15. package/base/web/src/routes/_app/index.tsx +7 -0
  16. package/base/web/src/routes/_app.tsx +96 -49
  17. package/package.json +5 -2
  18. package/parts/ai/api/api/routes/ai.ts +28 -0
  19. package/parts/ai/api/test/ai.test.ts +52 -0
  20. package/parts/ai/part.ts +16 -0
  21. package/parts/dashboard/part.ts +6 -0
  22. package/parts/dashboard/web/src/components/overview.test.tsx +16 -0
  23. package/parts/dashboard/web/src/components/overview.tsx +175 -0
  24. package/parts/paywalls/api/api/routes/paywall.ts +126 -0
  25. package/parts/paywalls/api/test/paywalls.test.ts +71 -0
  26. package/parts/paywalls/part.ts +8 -0
  27. package/parts/pwa/part.ts +6 -0
  28. package/parts/pwa/web/public/icon.svg +6 -0
  29. package/parts/pwa/web/public/manifest.webmanifest +10 -0
  30. package/parts/pwa/web/public/sw.js +69 -0
  31. package/parts/pwa/web/src/components/install-button.tsx +14 -0
  32. package/parts/pwa/web/src/lib/pwa.ts +39 -0
  33. package/parts/workflows/api/api/workflows.ts +33 -0
  34. package/parts/workflows/api/test/workflows.test.ts +44 -0
  35. package/parts/workflows/part.ts +7 -0
  36. package/parts/workflows/web/src/routes/_app/approvals.tsx +34 -0
  37. package/src/compose.ts +107 -30
  38. package/src/desktop.ts +1 -1
  39. package/src/index.ts +49 -8
package/src/compose.ts CHANGED
@@ -16,13 +16,18 @@ import { cp, readdir, readFile, rm, writeFile } from "node:fs/promises"
16
16
  import { join, resolve } from "node:path"
17
17
  import account from "../parts/account/part.js"
18
18
  import admin from "../parts/admin/part.js"
19
+ import ai from "../parts/ai/part.js"
19
20
  import auth from "../parts/auth/part.js"
21
+ import dashboard from "../parts/dashboard/part.js"
20
22
  import growth from "../parts/growth/part.js"
21
23
  import mcp from "../parts/mcp/part.js"
22
24
  import notifications from "../parts/notifications/part.js"
23
25
  import orgs from "../parts/orgs/part.js"
24
26
  import payments from "../parts/payments/part.js"
27
+ import paywalls from "../parts/paywalls/part.js"
25
28
  import privacy from "../parts/privacy/part.js"
29
+ import pwa from "../parts/pwa/part.js"
30
+ import workflows from "../parts/workflows/part.js"
26
31
 
27
32
  type Deps = Record<string, string>
28
33
 
@@ -34,13 +39,18 @@ export type Part = {
34
39
  needs?: PartName[]
35
40
  /** Needs the API surface (it has no web half). */
36
41
  apiOnly?: boolean
42
+ /** Needs the web surface (it has no API half). */
43
+ webOnly?: boolean
37
44
  web?: { deps?: Deps }
38
45
  api?: { deps?: Deps }
39
46
  /** With both surfaces: dev deps and scripts (the browser test). */
40
47
  both?: { devDeps?: Deps; scripts?: Record<string, string> }
41
48
  /** Lines for the generated env file. A function, so secrets are fresh per app. */
42
49
  env?: () => string[]
43
- /** SQL tables its schema adds: the migrations keep only the chosen parts' tables. */
50
+ /**
51
+ * SQL tables its schema adds: the migrations keep only the chosen parts'
52
+ * tables. Two parts may list one table; it stays when either is chosen.
53
+ */
44
54
  tables?: string[]
45
55
  /** API files the web half also reads; a UI-only app gets a copy at the mapped path. */
46
56
  uiCopies?: Record<string, string>
@@ -55,7 +65,12 @@ export const PART_NAMES = [
55
65
  "notifications",
56
66
  "privacy",
57
67
  "payments",
68
+ "paywalls",
58
69
  "growth",
70
+ "ai",
71
+ "workflows",
72
+ "dashboard",
73
+ "pwa",
59
74
  "mcp",
60
75
  ] as const
61
76
  export type PartName = (typeof PART_NAMES)[number]
@@ -67,19 +82,68 @@ export const PARTS: Record<PartName, Part> = {
67
82
  notifications,
68
83
  privacy,
69
84
  payments,
85
+ paywalls,
70
86
  growth,
87
+ ai,
88
+ workflows,
89
+ dashboard,
90
+ pwa,
71
91
  mcp,
72
92
  }
73
93
 
74
94
  /**
75
- * A named mix of parts. `full` is everything the full template had; `blank`
76
- * is the base alone (the shell, the API, the database), for parts of your own.
95
+ * A named mix of parts, by the shape of app, never its domain. `full` is
96
+ * everything the full template had (not dashboard or pwa, which reshape the
97
+ * web half); `blank` is the base alone (the shell, the
98
+ * API, the database), for parts of your own. Needs are added for you (admin
99
+ * brings orgs, everything brings auth). `surface: "api"` is the API half only.
77
100
  * MCP is not listed: it is asked for (or --mcp / --no-mcp), as it always was.
101
+ * Each description is one line, quoted, first: signet-mcp's index reads it.
78
102
  */
79
103
  export const STARTERS = {
80
- full: { parts: PART_NAMES.filter((p) => p !== "mcp") },
81
- blank: { parts: [] },
82
- } satisfies Record<string, { parts: PartName[] }>
104
+ full: {
105
+ description: "every part, web + API",
106
+ parts: PART_NAMES.filter((p) => !["mcp", "dashboard", "pwa"].includes(p)),
107
+ },
108
+ blank: { description: "no parts: the shell, the API and the database", parts: [] },
109
+ saas: {
110
+ description: "a paid team product: orgs, admin, billing, inbox, account, privacy",
111
+ parts: ["account", "orgs", "admin", "notifications", "privacy", "payments"],
112
+ },
113
+ launch: {
114
+ description: "before launch: sign-in, waitlist, invites, referrals, feedback, privacy",
115
+ parts: ["account", "privacy", "growth"],
116
+ },
117
+ "internal-tool": {
118
+ description: "for your own team: orgs and roles, the admin panel, approval workflows",
119
+ parts: ["account", "orgs", "admin", "workflows"],
120
+ },
121
+ api: {
122
+ description: "the API half only: sign-in, API keys, billing webhooks",
123
+ parts: ["account", "payments"],
124
+ surface: "api",
125
+ },
126
+ "ai-app": {
127
+ description: "an AI product: spend caps per user, billing, account, privacy",
128
+ parts: ["account", "privacy", "payments", "ai"],
129
+ },
130
+ paywall: {
131
+ description: "sell access: plans, entitlements, billing, remote paywalls",
132
+ parts: ["account", "payments", "paywalls"],
133
+ },
134
+ automation: {
135
+ description: "durable workflows with approvals, and an inbox to tell people",
136
+ parts: ["account", "notifications", "workflows"],
137
+ },
138
+ dashboard: {
139
+ description: "a sidebar shell and an overview: stat tiles, a chart, a table",
140
+ parts: ["account", "dashboard"],
141
+ },
142
+ pwa: {
143
+ description: "installable and offline: web manifest, service worker, install prompt",
144
+ parts: ["account", "pwa"],
145
+ },
146
+ } satisfies Record<string, { description: string; parts: PartName[]; surface?: "api" }>
83
147
  export type StarterName = keyof typeof STARTERS
84
148
 
85
149
  /**
@@ -190,45 +254,66 @@ async function walk(dir: string, base = dir): Promise<string[]> {
190
254
  return out
191
255
  }
192
256
 
257
+ /** The tables a left-out part lists, less any a chosen part also lists (usage_counters: payments and ai). */
258
+ export function droppedTables(parts: readonly PartName[]): Set<string> {
259
+ const kept = new Set(parts.flatMap((p) => (PARTS[p] as Part).tables ?? []))
260
+ return new Set(
261
+ PART_NAMES.filter((p) => !parts.includes(p))
262
+ .flatMap((p) => (PARTS[p] as Part).tables ?? [])
263
+ .filter((t) => !kept.has(t)),
264
+ )
265
+ }
266
+
193
267
  /**
194
268
  * Keep the chosen parts' tables in drizzle/: drop each statement on a table
195
269
  * of a part left out, and the table from the snapshot. A migration left with
196
- * no statements goes, with its snapshot and journal entry.
197
- * ponytail: drops only trailing migrations cleanly (prevId is not relinked);
198
- * the base has two, and only the last can empty out.
270
+ * no statements goes, with its snapshot and journal entry; the ones after it
271
+ * move up a number and link to the snapshot before, so the next `db:generate`
272
+ * neither reuses a number nor finds a broken chain.
199
273
  */
200
- async function filterMigrations(dir: string, dropTables: Set<string>) {
274
+ export async function filterMigrations(dir: string, dropTables: Set<string>) {
201
275
  if (!dropTables.size) return
202
276
  const journalPath = join(dir, "meta/_journal.json")
203
277
  const journal = JSON.parse(await readFile(journalPath, "utf8")) as {
204
278
  entries: { idx: number; tag: string }[]
205
279
  }
206
280
  const keep: typeof journal.entries = []
281
+ let prevId: string | undefined
207
282
  for (const entry of journal.entries) {
208
283
  const sqlPath = join(dir, `${entry.tag}.sql`)
209
284
  const snapPath = join(dir, `meta/${entry.tag.slice(0, 4)}_snapshot.json`)
210
- const statements = (await readFile(sqlPath, "utf8")).split("--> statement-breakpoint")
285
+ const text = await readFile(sqlPath, "utf8")
286
+ const statements = text.split("--> statement-breakpoint")
211
287
  const kept = statements.filter((s) => {
212
288
  const table = /CREATE TABLE `(\w+)`/.exec(s)?.[1] ?? / ON `(\w+)`/.exec(s)?.[1]
213
289
  return !table || !dropTables.has(table)
214
290
  })
291
+ await rm(sqlPath)
215
292
  if (!kept.some((s) => s.trim())) {
216
- await rm(sqlPath)
217
293
  await rm(snapPath)
218
294
  continue
219
295
  }
220
- keep.push(entry)
221
- if (kept.length !== statements.length)
222
- await writeFile(sqlPath, kept.join("--> statement-breakpoint").trim())
223
296
  // Snapshots are cumulative: a later one still lists an earlier one's tables.
224
- const snap = JSON.parse(await readFile(snapPath, "utf8")) as { tables: Record<string, unknown> }
297
+ const snap = JSON.parse(await readFile(snapPath, "utf8")) as {
298
+ id: string
299
+ prevId: string
300
+ tables: Record<string, unknown>
301
+ }
302
+ await rm(snapPath)
225
303
  for (const t of dropTables) delete snap.tables[t]
226
- await writeFile(snapPath, JSON.stringify(snap, null, 2))
227
- }
228
- if (keep.length !== journal.entries.length) {
229
- journal.entries = keep
230
- await writeFile(journalPath, JSON.stringify(journal, null, 2))
304
+ if (prevId !== undefined) snap.prevId = prevId
305
+ prevId = snap.id
306
+ const n = String(keep.length).padStart(4, "0")
307
+ const tag = `${n}${entry.tag.slice(4)}`
308
+ await writeFile(
309
+ join(dir, `${tag}.sql`),
310
+ kept.length === statements.length ? text : kept.join("--> statement-breakpoint").trim(),
311
+ )
312
+ await writeFile(join(dir, `meta/${n}_snapshot.json`), JSON.stringify(snap, null, 2))
313
+ keep.push({ ...entry, idx: keep.length, tag })
231
314
  }
315
+ journal.entries = keep
316
+ await writeFile(journalPath, JSON.stringify(journal, null, 2))
232
317
  }
233
318
 
234
319
  export type ComposeOptions = {
@@ -281,15 +366,7 @@ export async function compose(
281
366
  await writeFile(path, out.replace(/^\n+/, "").replace(/\n{3,}/g, "\n\n"))
282
367
  }
283
368
 
284
- if (api)
285
- await filterMigrations(
286
- join(dest, "drizzle"),
287
- new Set(
288
- PART_NAMES.filter((p) => !parts.includes(p)).flatMap(
289
- (p) => (PARTS[p] as Part).tables ?? [],
290
- ),
291
- ),
292
- )
369
+ if (api) await filterMigrations(join(dest, "drizzle"), droppedTables(parts))
293
370
 
294
371
  const refs = [...(web ? ["app", "node", "test"] : []), ...(api ? ["api"] : [])]
295
372
  const ref = (r: string) => `{ "path": "./tsconfig.${r}.json" }`
package/src/desktop.ts CHANGED
@@ -23,7 +23,7 @@ export const DESKTOP_PKG = {
23
23
  dependencies: {
24
24
  "@dapplelight/signet-lib": "^0.4.1",
25
25
  "@dapplelight/signet-tokens": "^0.4.0",
26
- "@dapplelight/signet-ui": "^0.4.0",
26
+ "@dapplelight/signet-ui": "^0.5.0",
27
27
  "@tauri-apps/api": "^2.0.0",
28
28
  "@tauri-apps/plugin-opener": "^2.0.0",
29
29
  "@tauri-apps/plugin-store": "^2.0.0",
package/src/index.ts CHANGED
@@ -235,7 +235,7 @@ const DEPS = {
235
235
  "@dapplelight/signet-lib": "^0.4.0",
236
236
  "@dapplelight/signet-tokens": "^0.4.0",
237
237
  // LabelsProvider (src/components/signet-labels.tsx) since 0.3.2.
238
- "@dapplelight/signet-ui": "^0.4.0",
238
+ "@dapplelight/signet-ui": "^0.5.0",
239
239
  "@tanstack/react-query": "^5.108.0",
240
240
  "@tanstack/react-router": "^1.170.39",
241
241
  "class-variance-authority": "^0.7.1",
@@ -422,10 +422,9 @@ Platforms (one app each):
422
422
  --template <name> the old name for --platform; --template full is --starter full
423
423
 
424
424
  Composed apps (a web app and its API from parts; any of these flags):
425
- --starter <name> ${STARTER_NAMES.join(" | ")}
426
- full: every part below, web + API in one project, typed
427
- client between them, SQLite with migrations
428
- blank: the same project with no parts: shell, API, database
425
+ --starter <name> a named mix of parts, web + API in one project, typed
426
+ client between them, SQLite with migrations:
427
+ ${STARTER_NAMES.map((s) => ` ${s.padEnd(14)}${STARTERS[s].description}`).join("\n")}
429
428
  --with <parts> comma-separated parts to add; the parts they need come too
430
429
  --without <parts> parts to leave out (alone: the full starter without them)
431
430
  --ui the web half only; it calls an API elsewhere (VITE_API_URL)
@@ -518,6 +517,8 @@ Examples:
518
517
  mcp,
519
518
  pm: pm ?? detectPm(),
520
519
  composeFlags,
520
+ // Nothing said what to build: asked on a terminal, else the web platform.
521
+ pick: !templateGiven && !composing,
521
522
  }
522
523
  }
523
524
 
@@ -572,6 +573,34 @@ async function substitute(dir: string, vars: Record<string, string>) {
572
573
  }
573
574
  }
574
575
 
576
+ /** "What are you building?": a platform or a starter, by number or name; default web. */
577
+ async function askWhat(): Promise<Platform | StarterName> {
578
+ const choices = [...PLATFORMS, ...STARTER_NAMES.map((s) => `starter ${s}`)]
579
+ const lines = [
580
+ ...PLATFORMS.map((p) => p),
581
+ ...STARTER_NAMES.map((s) => `${s.padEnd(14)}${STARTERS[s].description}`),
582
+ ]
583
+ console.log(
584
+ `\n What are you building?\n${lines.map((l, i) => ` ${String(i + 1).padStart(3)}. ${l}`).join("\n")}`,
585
+ )
586
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
587
+ try {
588
+ for (;;) {
589
+ const a = (await rl.question(" Number or name (web): ")).trim().toLowerCase()
590
+ if (a === "") return "web"
591
+ const n = Number(a)
592
+ const pick =
593
+ Number.isInteger(n) && n >= 1
594
+ ? choices[n - 1]
595
+ : choices.find((c) => c === a || c === `starter ${a}`)
596
+ if (pick) return pick.replace(/^starter /, "") as Platform | StarterName
597
+ console.log(` Not one of these: ${a}`)
598
+ }
599
+ } finally {
600
+ rl.close()
601
+ }
602
+ }
603
+
575
604
  /** "Add MCP for agents?", default yes; only asked on a terminal. */
576
605
  async function askMcp(): Promise<boolean> {
577
606
  if (!process.stdin.isTTY) return true
@@ -611,11 +640,13 @@ async function copyPlatform(platform: Platform, dest: string, target: Target, mc
611
640
  * when nothing said, as it always was.
612
641
  */
613
642
  async function pickParts(c: ComposeFlags, mcpFlag: boolean | undefined) {
614
- const web = !c.api
615
- const api = !c.ui
616
643
  const flagged = c.ui || c.api || c.with.length > 0 || c.without.length > 0
617
644
  const starter =
618
645
  c.starter ?? (!flagged || (!c.with.length && c.without.length) ? "full" : undefined)
646
+ const apiStarter = starter !== undefined && "surface" in STARTERS[starter]
647
+ if (apiStarter && c.ui) throw new Error(`--starter ${starter} is the API only: drop --ui.`)
648
+ const web = !c.api && !apiStarter
649
+ const api = !c.ui
619
650
  // A UI-only app takes the starter's parts that have a web half.
620
651
  const base = starter ? STARTERS[starter].parts.filter((p) => api || !PARTS[p].apiOnly) : []
621
652
  const mcp = c.with.includes("mcp")
@@ -625,8 +656,10 @@ async function pickParts(c: ComposeFlags, mcpFlag: boolean | undefined) {
625
656
  : api && (mcpFlag ?? (await askMcp()))
626
657
  const chosen = [...base.filter((p) => !c.without.includes(p)), ...c.with, ...(mcp ? ["mcp"] : [])]
627
658
  const { parts, added } = resolveParts([...new Set(chosen)], c.without)
628
- for (const p of parts)
659
+ for (const p of parts) {
629
660
  if (PARTS[p].apiOnly && !api) throw new Error(`${p} needs the API: drop --ui, or ${p}.`)
661
+ if (PARTS[p].webOnly && !web) throw new Error(`${p} is web only: drop --api, or ${p}.`)
662
+ }
630
663
  return { parts, added, web, api, starter }
631
664
  }
632
665
 
@@ -684,6 +717,14 @@ async function main() {
684
717
  ;({ theme, template } = described)
685
718
  checkCombo(template, theme, parsed.targetGiven, flags.mcp)
686
719
  }
720
+ if (parsed.pick && process.stdin.isTTY) {
721
+ const what = await askWhat()
722
+ if ((PLATFORMS as readonly string[]).includes(what)) template = what as Platform
723
+ else {
724
+ template = "full"
725
+ parsed.composeFlags.starter = what as StarterName
726
+ }
727
+ }
687
728
  if (parsed.pm === "deno" && template === "cli")
688
729
  throw new Error(
689
730
  "--platform cli compiles one binary with `bun build --compile`; use --pm bun, npm, pnpm or yarn.",