cronus-ui 0.6.3 → 0.6.5

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 CHANGED
@@ -49,7 +49,7 @@ Notes that match the commander surface:
49
49
  `packages/cli/scripts/build-registry.ts` — each item carries its source, its npm
50
50
  `dependencies`, and its `registryDependencies` (other components it imports),
51
51
  derived by parsing imports.
52
- - The default registry is pinned to the CLI package version (`v0.6.3` here), not
52
+ - The default registry is pinned to the CLI package version (`v0.6.5` here), not
53
53
  mutable `main`, so a published CLI reads the registry snapshot it was released
54
54
  with. Use `-r, --registry ./registry` when testing local registry changes before
55
55
  a release tag exists.
@@ -80,7 +80,7 @@ Notes that match the commander surface:
80
80
  "lib": "lib",
81
81
  "blocks": "components/blocks"
82
82
  },
83
- "registry": "https://raw.githubusercontent.com/pedrogbraz/cronus-ui/v0.6.3/registry"
83
+ "registry": "https://raw.githubusercontent.com/pedrogbraz/cronus-ui/v0.6.5/registry"
84
84
  }
85
85
  ```
86
86
 
@@ -37,10 +37,21 @@ export declare function goldPathLayout(config: CronusUIConfig): GoldPathLayout;
37
37
  export declare function patchChromeSource(source: string, workspaceImport: string, inviteImport: string, sessionImport?: string): string | undefined;
38
38
  /** Insert ItemsPanel into a generated home page. Returns undefined when there is no main. */
39
39
  export declare function patchHomePageSource(source: string, itemsImport: string): string | undefined;
40
+ /**
41
+ * Replace the catalog TeamBlock on a generated /team page with MembersPanel.
42
+ * Idempotent. Returns undefined when there is no TeamBlock and no MembersPanel.
43
+ */
44
+ export declare function patchTeamPageSource(source: string, membersImport: string): string | undefined;
45
+ /**
46
+ * Validate the session in the shell layout so a stale cookie cannot sit in the
47
+ * app chrome. Idempotent. Returns undefined when AppShellNav is missing.
48
+ */
49
+ export declare function patchShellLayoutSource(source: string, authImport: string): string | undefined;
40
50
  /**
41
51
  * Write sqlite + Drizzle + Better-Auth files into a composed saas/admin app.
42
- * Overwrites lib/auth-adapter.ts and lib/items.ts always. Patches the shell
43
- * home page only when compose wrote it this run.
52
+ * Overwrites lib/auth-adapter.ts, lib/items.ts, and lib/members.ts always.
53
+ * Patches the shell home, /team, and shell layout only when compose wrote them
54
+ * this run.
44
55
  */
45
56
  export declare function applyGoldPath(options: ApplyGoldPathOptions): Promise<ApplyGoldPathResult>;
46
57
  //# sourceMappingURL=gold-path.d.ts.map
@@ -82,6 +82,20 @@ function homePageRel(appDir, generatedFiles) {
82
82
  const any = generatedFiles.find((f) => /(^|\/)\(shell\)\/page\.tsx$/.test(posix(f)));
83
83
  return any !== undefined ? posix(any) : undefined;
84
84
  }
85
+ function teamPageRel(appDir, generatedFiles) {
86
+ const match = generatedFiles.find((f) => posix(f) === `${appDir}/(shell)/team/page.tsx`);
87
+ if (match !== undefined)
88
+ return posix(match);
89
+ const any = generatedFiles.find((f) => /(^|\/)\(shell\)\/team\/page\.tsx$/.test(posix(f)));
90
+ return any !== undefined ? posix(any) : undefined;
91
+ }
92
+ function shellLayoutRel(appDir, generatedFiles) {
93
+ const match = generatedFiles.find((f) => posix(f) === `${appDir}/(shell)/layout.tsx`);
94
+ if (match !== undefined)
95
+ return posix(match);
96
+ const any = generatedFiles.find((f) => /(^|\/)\(shell\)\/layout\.tsx$/.test(posix(f)));
97
+ return any !== undefined ? posix(any) : undefined;
98
+ }
85
99
  function drizzleConfigSource(dbDir) {
86
100
  return `import { mkdirSync } from "node:fs";
87
101
  import { dirname } from "node:path";
@@ -231,6 +245,19 @@ function newId(): string {
231
245
  return crypto.randomUUID().replaceAll("-", "");
232
246
  }
233
247
 
248
+ function authBaseURL() {
249
+ const env = process.env.BETTER_AUTH_URL;
250
+ const hosts = ["localhost:*", "127.0.0.1:*"];
251
+ if (env) {
252
+ try {
253
+ hosts.push(new URL(env).host);
254
+ } catch {
255
+ // ignore invalid BETTER_AUTH_URL
256
+ }
257
+ }
258
+ return { allowedHosts: hosts, fallback: env || "http://localhost:3000" };
259
+ }
260
+
234
261
  export const auth = betterAuth({
235
262
  database: drizzleAdapter(db, { provider: "sqlite", schema }),
236
263
  emailAndPassword: {
@@ -287,12 +314,11 @@ export const auth = betterAuth({
287
314
  },
288
315
  },
289
316
  secret: process.env.BETTER_AUTH_SECRET,
290
- baseURL: process.env.BETTER_AUTH_URL,
317
+ baseURL: authBaseURL(),
291
318
  plugins: [
292
319
  organization({
293
320
  sendInvitationEmail: async (data) => {
294
- const base = process.env.BETTER_AUTH_URL ?? "http://localhost:3000";
295
- console.info(\`Invite \${data.email}: \${base}/accept-invitation?id=\${data.id}\`);
321
+ console.info(\`Invite \${data.email}: /accept-invitation?id=\${data.id}\`);
296
322
  },
297
323
  }),
298
324
  nextCookies(),
@@ -415,13 +441,10 @@ export function middleware(request: NextRequest) {
415
441
  if (invitation) url.searchParams.set("invitation", invitation);
416
442
  return NextResponse.redirect(url);
417
443
  }
418
- if (sessionCookie && isAuthPage) {
419
- if (invitation) {
420
- return NextResponse.redirect(
421
- new URL(\`/accept-invitation?id=\${encodeURIComponent(invitation)}\`, request.url),
422
- );
423
- }
424
- return NextResponse.redirect(new URL("/", request.url));
444
+ if (sessionCookie && isAuthPage && invitation) {
445
+ return NextResponse.redirect(
446
+ new URL(\`/accept-invitation?id=\${encodeURIComponent(invitation)}\`, request.url),
447
+ );
425
448
  }
426
449
  return NextResponse.next();
427
450
  }
@@ -585,6 +608,156 @@ export function ItemsView({
585
608
  }
586
609
  `;
587
610
  }
611
+ function membersActionsSource(authImport) {
612
+ return `"use server";
613
+
614
+ import { and, asc, eq } from "drizzle-orm";
615
+ import { headers } from "next/headers";
616
+ import { db } from "@/db";
617
+ import { member, organization, user } from "@/db/schema";
618
+ import { auth } from ${JSON.stringify(authImport)};
619
+
620
+ async function activeWorkspaceId(): Promise<string | null> {
621
+ const session = await auth.api.getSession({ headers: await headers() });
622
+ const userId = session?.user?.id;
623
+ if (!userId) return null;
624
+ const hinted = session.session?.activeOrganizationId ?? null;
625
+ if (hinted) {
626
+ const [membership] = await db
627
+ .select({ organizationId: member.organizationId })
628
+ .from(member)
629
+ .where(and(eq(member.userId, userId), eq(member.organizationId, hinted)))
630
+ .limit(1);
631
+ if (membership?.organizationId) return membership.organizationId;
632
+ }
633
+ const [row] = await db
634
+ .select({ organizationId: member.organizationId })
635
+ .from(member)
636
+ .where(eq(member.userId, userId))
637
+ .limit(1);
638
+ return row?.organizationId ?? null;
639
+ }
640
+
641
+ export async function loadMembers(): Promise<{
642
+ workspace: string;
643
+ rows: { id: string; name: string; email: string; image: string | null; role: string }[];
644
+ }> {
645
+ const orgId = await activeWorkspaceId();
646
+ if (!orgId) return { workspace: "no workspace", rows: [] };
647
+ const [org] = await db.select().from(organization).where(eq(organization.id, orgId)).limit(1);
648
+ const rows = await db
649
+ .select({
650
+ id: member.id,
651
+ name: user.name,
652
+ email: user.email,
653
+ image: user.image,
654
+ role: member.role,
655
+ })
656
+ .from(member)
657
+ .innerJoin(user, eq(member.userId, user.id))
658
+ .where(eq(member.organizationId, orgId))
659
+ .orderBy(asc(member.createdAt));
660
+ return { workspace: org?.name ?? "no workspace", rows };
661
+ }
662
+ `;
663
+ }
664
+ function membersPanelSource(actionsImport, viewImport) {
665
+ return `import { loadMembers } from ${JSON.stringify(actionsImport)};
666
+ import { MembersView } from ${JSON.stringify(viewImport)};
667
+
668
+ export async function MembersPanel() {
669
+ const data = await loadMembers();
670
+ return <MembersView workspace={data.workspace} rows={data.rows} />;
671
+ }
672
+ `;
673
+ }
674
+ function membersViewSource(inviteImport) {
675
+ return `"use client";
676
+
677
+ import { Avatar, AvatarFallback, AvatarImage, Badge, Button } from "@cronus-ui/ui";
678
+ import { InviteMember } from ${JSON.stringify(inviteImport)};
679
+
680
+ function initialsOf(name: string, email: string): string {
681
+ const parts = name.trim().split(/\\s+/).filter(Boolean);
682
+ if (parts.length >= 2) {
683
+ return \`\${parts[0]?.[0] ?? ""}\${parts[1]?.[0] ?? ""}\`.toUpperCase();
684
+ }
685
+ if (parts[0]?.[0]) return parts[0][0].toUpperCase();
686
+ return email.slice(0, 2).toUpperCase();
687
+ }
688
+
689
+ function roleLabel(role: string): string {
690
+ if (role === "owner") return "Owner";
691
+ if (role === "admin") return "Admin";
692
+ if (role === "member") return "Member";
693
+ return role;
694
+ }
695
+
696
+ function roleVariant(role: string): "primary" | "info" | "secondary" {
697
+ if (role === "owner") return "primary";
698
+ if (role === "admin") return "info";
699
+ return "secondary";
700
+ }
701
+
702
+ export function MembersView({
703
+ workspace,
704
+ rows,
705
+ }: {
706
+ workspace: string;
707
+ rows: { id: string; name: string; email: string; image: string | null; role: string }[];
708
+ }) {
709
+ const count = String(rows.length);
710
+ return (
711
+ <section
712
+ data-slot="members-panel"
713
+ aria-labelledby="members-heading"
714
+ className="mx-auto w-full max-w-xl px-6 py-6"
715
+ >
716
+ <div className="flex items-end justify-between gap-3">
717
+ <div className="min-w-0">
718
+ <h1 id="members-heading" className="text-sm font-semibold text-fg">
719
+ Team
720
+ </h1>
721
+ <p className="mt-1 text-sm text-fg-tertiary">
722
+ {workspace} · {count} members
723
+ </p>
724
+ </div>
725
+ <InviteMember
726
+ trigger={
727
+ <Button type="button" size="sm">
728
+ Invite
729
+ </Button>
730
+ }
731
+ />
732
+ </div>
733
+ {rows.length === 0 ? (
734
+ <p className="mt-4 text-sm text-fg-tertiary">No members yet.</p>
735
+ ) : (
736
+ <ul className="mt-4">
737
+ {rows.map((row) => (
738
+ <li
739
+ key={row.id}
740
+ data-slot="member"
741
+ className="flex items-center gap-3 border-t border-border py-3"
742
+ >
743
+ <Avatar className="size-8">
744
+ {row.image ? <AvatarImage src={row.image} alt={row.name} /> : null}
745
+ <AvatarFallback>{initialsOf(row.name, row.email)}</AvatarFallback>
746
+ </Avatar>
747
+ <div className="flex min-w-0 flex-1 flex-col">
748
+ <span className="truncate text-sm text-fg">{row.name}</span>
749
+ <span className="truncate text-sm text-fg-tertiary">{row.email}</span>
750
+ </div>
751
+ <Badge variant={roleVariant(row.role)}>{roleLabel(row.role)}</Badge>
752
+ </li>
753
+ ))}
754
+ </ul>
755
+ )}
756
+ </section>
757
+ );
758
+ }
759
+ `;
760
+ }
588
761
  function workspaceMenuSource(authClientImport) {
589
762
  return `"use client";
590
763
 
@@ -846,6 +1019,48 @@ export function patchHomePageSource(source, itemsImport) {
846
1019
  }
847
1020
  return out;
848
1021
  }
1022
+ /**
1023
+ * Replace the catalog TeamBlock on a generated /team page with MembersPanel.
1024
+ * Idempotent. Returns undefined when there is no TeamBlock and no MembersPanel.
1025
+ */
1026
+ export function patchTeamPageSource(source, membersImport) {
1027
+ const hasPanel = /<MembersPanel\s*\/>/.test(source);
1028
+ const hasTeam = /<TeamBlock\s*\/>/.test(source);
1029
+ if (!hasPanel && !hasTeam)
1030
+ return undefined;
1031
+ if (hasPanel)
1032
+ return source;
1033
+ let out = source;
1034
+ const importLine = `import { MembersPanel } from ${JSON.stringify(membersImport)};`;
1035
+ out = insertImport(out, importLine);
1036
+ out = out.replace(/import \{ TeamBlock \} from "[^"]+";\n/, "");
1037
+ out = out.replace(/export default(?! async) function/, "export default async function");
1038
+ out = out.replace(/<TeamBlock\s*\/>/, "<MembersPanel />");
1039
+ return out;
1040
+ }
1041
+ /**
1042
+ * Validate the session in the shell layout so a stale cookie cannot sit in the
1043
+ * app chrome. Idempotent. Returns undefined when AppShellNav is missing.
1044
+ */
1045
+ export function patchShellLayoutSource(source, authImport) {
1046
+ if (source.includes("auth.api.getSession") && source.includes('redirect("/login")')) {
1047
+ return source;
1048
+ }
1049
+ if (!source.includes("AppShellNav") || !source.includes("{children}"))
1050
+ return undefined;
1051
+ let out = source;
1052
+ out = insertImport(out, `import { headers } from "next/headers";`);
1053
+ out = insertImport(out, `import { redirect } from "next/navigation";`);
1054
+ out = insertImport(out, `import { auth } from ${JSON.stringify(authImport)};`);
1055
+ out = out.replace(/export default(?! async) function/, "export default async function");
1056
+ if (!out.includes("auth.api.getSession")) {
1057
+ out = out.replace(/(\{ children \}: \{ children: ReactNode \}\) \{)\n/, `$1
1058
+ const session = await auth.api.getSession({ headers: await headers() });
1059
+ if (!session) redirect("/login");
1060
+ `);
1061
+ }
1062
+ return out;
1063
+ }
849
1064
  function mergePackageJson(raw) {
850
1065
  const pkg = JSON.parse(raw);
851
1066
  const dependencies = { ...(pkg.dependencies ?? {}) };
@@ -915,8 +1130,9 @@ async function writeRel(targetDir, rel, content, overwrite, always, written, ski
915
1130
  }
916
1131
  /**
917
1132
  * Write sqlite + Drizzle + Better-Auth files into a composed saas/admin app.
918
- * Overwrites lib/auth-adapter.ts and lib/items.ts always. Patches the shell
919
- * home page only when compose wrote it this run.
1133
+ * Overwrites lib/auth-adapter.ts, lib/items.ts, and lib/members.ts always.
1134
+ * Patches the shell home, /team, and shell layout only when compose wrote them
1135
+ * this run.
920
1136
  */
921
1137
  export async function applyGoldPath(options) {
922
1138
  const { targetDir, config, generatedFiles, overwrite } = options;
@@ -932,6 +1148,9 @@ export async function applyGoldPath(options) {
932
1148
  const itemsActionsImport = `${config.aliases.lib}/items`;
933
1149
  const itemsViewImport = "@/components/items-view";
934
1150
  const itemsImport = "@/components/items-panel";
1151
+ const membersActionsImport = `${config.aliases.lib}/members`;
1152
+ const membersViewImport = "@/components/members-view";
1153
+ const membersImport = "@/components/members-panel";
935
1154
  const workspaceImport = "@/components/workspace-menu";
936
1155
  const inviteImport = "@/components/invite-member";
937
1156
  const sessionImport = "@/components/session-user";
@@ -965,6 +1184,21 @@ export async function applyGoldPath(options) {
965
1184
  content: itemsViewSource(itemsActionsImport),
966
1185
  always: true,
967
1186
  },
1187
+ {
1188
+ rel: `${layout.libDir}/members.ts`,
1189
+ content: membersActionsSource(authImport),
1190
+ always: true,
1191
+ },
1192
+ {
1193
+ rel: `${layout.componentsDir}/members-panel.tsx`,
1194
+ content: membersPanelSource(membersActionsImport, membersViewImport),
1195
+ always: true,
1196
+ },
1197
+ {
1198
+ rel: `${layout.componentsDir}/members-view.tsx`,
1199
+ content: membersViewSource(inviteImport),
1200
+ always: true,
1201
+ },
968
1202
  {
969
1203
  rel: `${layout.componentsDir}/workspace-menu.tsx`,
970
1204
  content: workspaceMenuSource(authClientImport),
@@ -1004,6 +1238,38 @@ export async function applyGoldPath(options) {
1004
1238
  }
1005
1239
  }
1006
1240
  }
1241
+ const layoutRel = shellLayoutRel(appDir, generatedFiles);
1242
+ if (layoutRel !== undefined) {
1243
+ const dest = resolveSafeDest(targetDir, ".", layoutRel);
1244
+ if (existsSync(dest)) {
1245
+ const current = await readFile(dest, "utf8");
1246
+ const patched = patchShellLayoutSource(current, authImport);
1247
+ if (patched !== undefined && patched !== current) {
1248
+ await writeFileEnsured(dest, patched);
1249
+ const templateName = options.templateName;
1250
+ if (templateName !== undefined) {
1251
+ const snapDest = resolveSafeDest(targetDir, baseSnapshotDir(templateName), layoutRel);
1252
+ await writeFileEnsured(snapDest, patched);
1253
+ }
1254
+ }
1255
+ }
1256
+ }
1257
+ const teamRel = teamPageRel(appDir, generatedFiles);
1258
+ if (teamRel !== undefined) {
1259
+ const dest = resolveSafeDest(targetDir, ".", teamRel);
1260
+ if (existsSync(dest)) {
1261
+ const current = await readFile(dest, "utf8");
1262
+ const patched = patchTeamPageSource(current, membersImport);
1263
+ if (patched !== undefined && patched !== current) {
1264
+ await writeFileEnsured(dest, patched);
1265
+ const templateName = options.templateName;
1266
+ if (templateName !== undefined) {
1267
+ const snapDest = resolveSafeDest(targetDir, baseSnapshotDir(templateName), teamRel);
1268
+ await writeFileEnsured(snapDest, patched);
1269
+ }
1270
+ }
1271
+ }
1272
+ }
1007
1273
  const homeRel = homePageRel(appDir, generatedFiles);
1008
1274
  if (homeRel !== undefined) {
1009
1275
  const dest = resolveSafeDest(targetDir, ".", homeRel);
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare const CONFIG_FILE = "cronus-ui.json";
2
- export declare const CLI_VERSION = "0.6.3";
3
- export declare const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/pedrogbraz/cronus-ui/v0.6.3/registry";
2
+ export declare const CLI_VERSION = "0.6.5";
3
+ export declare const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/pedrogbraz/cronus-ui/v0.6.5/registry";
4
4
  /** Manifest entry `add`/`upgrade` record per installed registry item. */
5
5
  export interface InstalledRecord {
6
6
  /** Registry release the files came from (git tag without the leading "v"). */
package/dist/config.js CHANGED
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { readFile, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  export const CONFIG_FILE = "cronus-ui.json";
5
- export const CLI_VERSION = "0.6.3";
5
+ export const CLI_VERSION = "0.6.5";
6
6
  export const DEFAULT_REGISTRY = `https://raw.githubusercontent.com/pedrogbraz/cronus-ui/v${CLI_VERSION}/registry`;
7
7
  export const DEFAULT_CONFIG = {
8
8
  aliases: { ui: "@/components/ui", lib: "@/lib", blocks: "@/components/blocks" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronus-ui",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "cronus-ui — add Cronus UI components to your project, shadcn-style (copy-paste registry).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "registry:check": "bun run scripts/check-registry.ts"
55
55
  },
56
56
  "dependencies": {
57
- "@cronus-ui/ai-kit": "0.6.3",
57
+ "@cronus-ui/ai-kit": "0.6.5",
58
58
  "commander": "^15.0.0",
59
59
  "picocolors": "^1.1.1"
60
60
  },