create-signet-app 0.5.0 → 0.6.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.
@@ -0,0 +1,34 @@
1
+ import { ApprovalInboxCard } from "@dapplelight/signet-ui/screens/workflow-screens"
2
+ import { useQuery, useQueryClient } from "@tanstack/react-query"
3
+ import { createFileRoute } from "@tanstack/react-router"
4
+ import { api } from "../../lib/api"
5
+
6
+ export const Route = createFileRoute("/_app/approvals")({
7
+ component: Approvals,
8
+ })
9
+
10
+ // Workflow approval steps waiting on you (signet-db workflows, /api/workflows),
11
+ // each with Approve and Reject. The run carries on at the runner's next tick.
12
+ function Approvals() {
13
+ const qc = useQueryClient()
14
+ const approvals = useQuery({
15
+ queryKey: ["approvals"],
16
+ queryFn: async () => (await api.workflows.approvals.$get()).json(),
17
+ }).data
18
+ if (!approvals) return null
19
+ const decide = (verb: "approve" | "reject") => async (a: { runId: string; stepId: string }) => {
20
+ await api.workflows.runs[":id"].steps[":step"][verb].$post({
21
+ param: { id: a.runId, step: a.stepId },
22
+ })
23
+ await qc.invalidateQueries({ queryKey: ["approvals"] })
24
+ }
25
+
26
+ return (
27
+ <ApprovalInboxCard
28
+ approvals={approvals}
29
+ withReason={false}
30
+ onApprove={decide("approve")}
31
+ onReject={decide("reject")}
32
+ />
33
+ )
34
+ }
package/src/compose.ts CHANGED
@@ -16,13 +16,16 @@ 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"
20
21
  import growth from "../parts/growth/part.js"
21
22
  import mcp from "../parts/mcp/part.js"
22
23
  import notifications from "../parts/notifications/part.js"
23
24
  import orgs from "../parts/orgs/part.js"
24
25
  import payments from "../parts/payments/part.js"
26
+ import paywalls from "../parts/paywalls/part.js"
25
27
  import privacy from "../parts/privacy/part.js"
28
+ import workflows from "../parts/workflows/part.js"
26
29
 
27
30
  type Deps = Record<string, string>
28
31
 
@@ -40,7 +43,10 @@ export type Part = {
40
43
  both?: { devDeps?: Deps; scripts?: Record<string, string> }
41
44
  /** Lines for the generated env file. A function, so secrets are fresh per app. */
42
45
  env?: () => string[]
43
- /** SQL tables its schema adds: the migrations keep only the chosen parts' tables. */
46
+ /**
47
+ * SQL tables its schema adds: the migrations keep only the chosen parts'
48
+ * tables. Two parts may list one table; it stays when either is chosen.
49
+ */
44
50
  tables?: string[]
45
51
  /** API files the web half also reads; a UI-only app gets a copy at the mapped path. */
46
52
  uiCopies?: Record<string, string>
@@ -55,7 +61,10 @@ export const PART_NAMES = [
55
61
  "notifications",
56
62
  "privacy",
57
63
  "payments",
64
+ "paywalls",
58
65
  "growth",
66
+ "ai",
67
+ "workflows",
59
68
  "mcp",
60
69
  ] as const
61
70
  export type PartName = (typeof PART_NAMES)[number]
@@ -67,19 +76,54 @@ export const PARTS: Record<PartName, Part> = {
67
76
  notifications,
68
77
  privacy,
69
78
  payments,
79
+ paywalls,
70
80
  growth,
81
+ ai,
82
+ workflows,
71
83
  mcp,
72
84
  }
73
85
 
74
86
  /**
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.
87
+ * A named mix of parts, by the shape of app, never its domain. `full` is
88
+ * everything the full template had; `blank` is the base alone (the shell, the
89
+ * API, the database), for parts of your own. Needs are added for you (admin
90
+ * brings orgs, everything brings auth). `surface: "api"` is the API half only.
77
91
  * MCP is not listed: it is asked for (or --mcp / --no-mcp), as it always was.
92
+ * Each description is one line, quoted, first: signet-mcp's index reads it.
78
93
  */
79
94
  export const STARTERS = {
80
- full: { parts: PART_NAMES.filter((p) => p !== "mcp") },
81
- blank: { parts: [] },
82
- } satisfies Record<string, { parts: PartName[] }>
95
+ full: { description: "every part, web + API", parts: PART_NAMES.filter((p) => p !== "mcp") },
96
+ blank: { description: "no parts: the shell, the API and the database", parts: [] },
97
+ saas: {
98
+ description: "a paid team product: orgs, admin, billing, inbox, account, privacy",
99
+ parts: ["account", "orgs", "admin", "notifications", "privacy", "payments"],
100
+ },
101
+ launch: {
102
+ description: "before launch: sign-in, waitlist, invites, referrals, feedback, privacy",
103
+ parts: ["account", "privacy", "growth"],
104
+ },
105
+ "internal-tool": {
106
+ description: "for your own team: orgs and roles, the admin panel, approval workflows",
107
+ parts: ["account", "orgs", "admin", "workflows"],
108
+ },
109
+ api: {
110
+ description: "the API half only: sign-in, API keys, billing webhooks",
111
+ parts: ["account", "payments"],
112
+ surface: "api",
113
+ },
114
+ "ai-app": {
115
+ description: "an AI product: spend caps per user, billing, account, privacy",
116
+ parts: ["account", "privacy", "payments", "ai"],
117
+ },
118
+ paywall: {
119
+ description: "sell access: plans, entitlements, billing, remote paywalls",
120
+ parts: ["account", "payments", "paywalls"],
121
+ },
122
+ automation: {
123
+ description: "durable workflows with approvals, and an inbox to tell people",
124
+ parts: ["account", "notifications", "workflows"],
125
+ },
126
+ } satisfies Record<string, { description: string; parts: PartName[]; surface?: "api" }>
83
127
  export type StarterName = keyof typeof STARTERS
84
128
 
85
129
  /**
@@ -190,45 +234,66 @@ async function walk(dir: string, base = dir): Promise<string[]> {
190
234
  return out
191
235
  }
192
236
 
237
+ /** The tables a left-out part lists, less any a chosen part also lists (usage_counters: payments and ai). */
238
+ export function droppedTables(parts: readonly PartName[]): Set<string> {
239
+ const kept = new Set(parts.flatMap((p) => (PARTS[p] as Part).tables ?? []))
240
+ return new Set(
241
+ PART_NAMES.filter((p) => !parts.includes(p))
242
+ .flatMap((p) => (PARTS[p] as Part).tables ?? [])
243
+ .filter((t) => !kept.has(t)),
244
+ )
245
+ }
246
+
193
247
  /**
194
248
  * Keep the chosen parts' tables in drizzle/: drop each statement on a table
195
249
  * 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.
250
+ * no statements goes, with its snapshot and journal entry; the ones after it
251
+ * move up a number and link to the snapshot before, so the next `db:generate`
252
+ * neither reuses a number nor finds a broken chain.
199
253
  */
200
- async function filterMigrations(dir: string, dropTables: Set<string>) {
254
+ export async function filterMigrations(dir: string, dropTables: Set<string>) {
201
255
  if (!dropTables.size) return
202
256
  const journalPath = join(dir, "meta/_journal.json")
203
257
  const journal = JSON.parse(await readFile(journalPath, "utf8")) as {
204
258
  entries: { idx: number; tag: string }[]
205
259
  }
206
260
  const keep: typeof journal.entries = []
261
+ let prevId: string | undefined
207
262
  for (const entry of journal.entries) {
208
263
  const sqlPath = join(dir, `${entry.tag}.sql`)
209
264
  const snapPath = join(dir, `meta/${entry.tag.slice(0, 4)}_snapshot.json`)
210
- const statements = (await readFile(sqlPath, "utf8")).split("--> statement-breakpoint")
265
+ const text = await readFile(sqlPath, "utf8")
266
+ const statements = text.split("--> statement-breakpoint")
211
267
  const kept = statements.filter((s) => {
212
268
  const table = /CREATE TABLE `(\w+)`/.exec(s)?.[1] ?? / ON `(\w+)`/.exec(s)?.[1]
213
269
  return !table || !dropTables.has(table)
214
270
  })
271
+ await rm(sqlPath)
215
272
  if (!kept.some((s) => s.trim())) {
216
- await rm(sqlPath)
217
273
  await rm(snapPath)
218
274
  continue
219
275
  }
220
- keep.push(entry)
221
- if (kept.length !== statements.length)
222
- await writeFile(sqlPath, kept.join("--> statement-breakpoint").trim())
223
276
  // 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> }
277
+ const snap = JSON.parse(await readFile(snapPath, "utf8")) as {
278
+ id: string
279
+ prevId: string
280
+ tables: Record<string, unknown>
281
+ }
282
+ await rm(snapPath)
225
283
  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))
284
+ if (prevId !== undefined) snap.prevId = prevId
285
+ prevId = snap.id
286
+ const n = String(keep.length).padStart(4, "0")
287
+ const tag = `${n}${entry.tag.slice(4)}`
288
+ await writeFile(
289
+ join(dir, `${tag}.sql`),
290
+ kept.length === statements.length ? text : kept.join("--> statement-breakpoint").trim(),
291
+ )
292
+ await writeFile(join(dir, `meta/${n}_snapshot.json`), JSON.stringify(snap, null, 2))
293
+ keep.push({ ...entry, idx: keep.length, tag })
231
294
  }
295
+ journal.entries = keep
296
+ await writeFile(journalPath, JSON.stringify(journal, null, 2))
232
297
  }
233
298
 
234
299
  export type ComposeOptions = {
@@ -281,15 +346,7 @@ export async function compose(
281
346
  await writeFile(path, out.replace(/^\n+/, "").replace(/\n{3,}/g, "\n\n"))
282
347
  }
283
348
 
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
- )
349
+ if (api) await filterMigrations(join(dest, "drizzle"), droppedTables(parts))
293
350
 
294
351
  const refs = [...(web ? ["app", "node", "test"] : []), ...(api ? ["api"] : [])]
295
352
  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")
@@ -684,6 +715,14 @@ async function main() {
684
715
  ;({ theme, template } = described)
685
716
  checkCombo(template, theme, parsed.targetGiven, flags.mcp)
686
717
  }
718
+ if (parsed.pick && process.stdin.isTTY) {
719
+ const what = await askWhat()
720
+ if ((PLATFORMS as readonly string[]).includes(what)) template = what as Platform
721
+ else {
722
+ template = "full"
723
+ parsed.composeFlags.starter = what as StarterName
724
+ }
725
+ }
687
726
  if (parsed.pm === "deno" && template === "cli")
688
727
  throw new Error(
689
728
  "--platform cli compiles one binary with `bun build --compile`; use --pm bun, npm, pnpm or yarn.",