@specdest/devkit 0.4.17 → 0.4.19
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 +5 -2
- package/dist/npm/cli.js +2 -0
- package/dist/npm/commands.d.ts +1 -0
- package/dist/npm/commands.js +15 -9
- package/dist/npm/github-doppler-secrets.d.ts +8 -0
- package/dist/npm/github-doppler-secrets.js +156 -0
- package/dist/npm/host-automation.js +22 -1
- package/dist/npm/index.js +2 -1
- package/dist/npm/predefined-packages/abac.js +30 -7
- package/dist/npm/predefined-packages/admin-ui-templates/AdminAccessAssignments.tsx.template +67 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +46 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +49 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +15 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +17 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +16 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +19 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminMembershipManager.tsx.template +56 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +19 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +19 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +20 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPermissionMatrix.tsx.template +54 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminRoleManager.tsx.template +81 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +20 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +18 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +22 -0
- package/dist/npm/predefined-packages/admin-ui.d.ts +2 -0
- package/dist/npm/predefined-packages/admin-ui.js +83 -0
- package/dist/npm/predefined-packages/auth-templates/README.md.template +9 -0
- package/dist/npm/predefined-packages/auth-templates/convex.ts.template +18 -0
- package/dist/npm/predefined-packages/auth-templates/identity.ts.template +2 -0
- package/dist/npm/predefined-packages/auth-templates/supabase.ts.template +36 -0
- package/dist/npm/predefined-packages/auth.js +22 -7
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -5
- package/dist/npm/predefined-packages/registry.js +2 -0
- package/dist/npm/predefined-packages/security-templates/README.md.template +15 -0
- package/dist/npm/predefined-packages/security-templates/convex-authorization.ts.template +109 -0
- package/dist/npm/predefined-packages/security-templates/permissions.ts.template +40 -0
- package/dist/npm/predefined-packages/security-templates/supabase-admin-rpc.sql.template +54 -0
- package/dist/npm/predefined-packages/security-templates/supabase-authorization.sql.template +138 -0
- package/dist/npm/predefined-packages/security-templates/supabase-posts-example.sql.template +39 -0
- package/dist/npm/predefined-packages/tenant-templates/README.md.template +11 -0
- package/dist/npm/predefined-packages/tenant-templates/tenant-context.ts.template +22 -0
- package/dist/npm/project-check.d.ts +12 -0
- package/dist/npm/project-check.js +54 -1
- package/dist/npm/supabase-local.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type MembershipSubject = { id: string; label: string };
|
|
4
|
+
export type ManagedMembership = { userId: string; containerId: string };
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
kind: 'tenant' | 'group';
|
|
8
|
+
users: readonly MembershipSubject[];
|
|
9
|
+
containers: readonly MembershipSubject[];
|
|
10
|
+
memberships: readonly ManagedMembership[];
|
|
11
|
+
onAdd: (membership: ManagedMembership) => void;
|
|
12
|
+
onRemove: (membership: ManagedMembership) => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Only use with backend-authorized mutations and server-sourced memberships. */
|
|
17
|
+
export function AdminMembershipManager({ kind, users, containers, memberships, onAdd, onRemove, disabled = false }: Props) {
|
|
18
|
+
const [userId, setUserId] = useState('');
|
|
19
|
+
const [containerId, setContainerId] = useState('');
|
|
20
|
+
const [query, setQuery] = useState('');
|
|
21
|
+
const subjectName = (id: string) => users.find((user) => user.id === id)?.label ?? id;
|
|
22
|
+
const containerName = (id: string) => containers.find((item) => item.id === id)?.label ?? id;
|
|
23
|
+
const eligible = memberships.filter((item) =>
|
|
24
|
+
`${subjectName(item.userId)} ${containerName(item.containerId)}`.toLowerCase().includes(query.toLowerCase()));
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<section aria-label={`${kind} memberships`} className="space-y-4">
|
|
28
|
+
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
if (disabled || !userId || !containerId) return;
|
|
31
|
+
if (!memberships.some((item) => item.userId === userId && item.containerId === containerId)) {
|
|
32
|
+
onAdd({ userId, containerId });
|
|
33
|
+
}
|
|
34
|
+
}}>
|
|
35
|
+
<select className="rounded-md border p-2" aria-label="User" value={userId} disabled={disabled} required onChange={(event) => setUserId(event.target.value)}>
|
|
36
|
+
<option value="">Select user</option>
|
|
37
|
+
{users.map((user) => <option key={user.id} value={user.id}>{user.label}</option>)}
|
|
38
|
+
</select>
|
|
39
|
+
<select className="rounded-md border p-2" aria-label={kind === 'tenant' ? 'Tenant' : 'Group'} value={containerId} disabled={disabled} required onChange={(event) => setContainerId(event.target.value)}>
|
|
40
|
+
<option value="">Select {kind}</option>
|
|
41
|
+
{containers.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
42
|
+
</select>
|
|
43
|
+
<button type="submit" className="rounded-md border px-3" disabled={disabled || !userId || !containerId}>Add membership</button>
|
|
44
|
+
</form>
|
|
45
|
+
<input aria-label="Search memberships" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
46
|
+
<ul className="space-y-2">
|
|
47
|
+
{eligible.map((item) => (
|
|
48
|
+
<li key={`${item.containerId}:${item.userId}`} className="flex flex-wrap items-center justify-between gap-2 rounded-md border p-2">
|
|
49
|
+
<span>{subjectName(item.userId)} — {containerName(item.containerId)}</span>
|
|
50
|
+
<button type="button" className="rounded-md border px-3 py-1" disabled={disabled} onClick={() => onRemove(item)}>Remove</button>
|
|
51
|
+
</li>
|
|
52
|
+
))}
|
|
53
|
+
</ul>
|
|
54
|
+
</section>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type AdminPageVariant = 'list' | 'detail' | 'form' | 'dashboard';
|
|
4
|
+
|
|
5
|
+
type AdminPageProps = {
|
|
6
|
+
variant: AdminPageVariant;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widths: Record<AdminPageVariant, string> = {
|
|
11
|
+
list: 'w-full',
|
|
12
|
+
detail: 'max-w-6xl',
|
|
13
|
+
form: 'max-w-3xl',
|
|
14
|
+
dashboard: 'w-full',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function AdminPage({ variant, children }: AdminPageProps) {
|
|
18
|
+
return <div className={'mx-auto min-w-0 space-y-6 p-4 md:p-6 ' + widths[variant]}>{children}</div>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type AdminPageHeaderProps = {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
actions?: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function AdminPageHeader({ title, description, actions }: AdminPageHeaderProps) {
|
|
10
|
+
return (
|
|
11
|
+
<header className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
|
12
|
+
<div className="min-w-0 space-y-1">
|
|
13
|
+
<h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
|
|
14
|
+
{description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
|
|
15
|
+
</div>
|
|
16
|
+
{actions ? <div className="flex shrink-0 flex-wrap gap-2">{actions}</div> : null}
|
|
17
|
+
</header>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type AdminPaginationProps = {
|
|
4
|
+
page: number;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
previous?: ReactNode;
|
|
7
|
+
next?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function AdminPagination({ page, totalPages, previous, next }: AdminPaginationProps) {
|
|
11
|
+
return (
|
|
12
|
+
<nav aria-label="Pagination" className="flex flex-wrap items-center justify-between gap-3 rounded-lg border p-3">
|
|
13
|
+
<div className="min-w-0">{previous}</div>
|
|
14
|
+
<span className="text-sm text-muted-foreground" aria-live="polite">
|
|
15
|
+
Page {page} of {totalPages}
|
|
16
|
+
</span>
|
|
17
|
+
<div className="min-w-0">{next}</div>
|
|
18
|
+
</nav>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
|
2
|
+
|
|
3
|
+
export type PermissionCell = { resource: string; action: string; scope: 'any' | 'own' };
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
resources: readonly string[];
|
|
7
|
+
actions: readonly string[];
|
|
8
|
+
value: readonly PermissionCell[];
|
|
9
|
+
onChange: (next: PermissionCell[]) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Presentation only. Saving grants must be authorized and validated server-side. */
|
|
14
|
+
export function AdminPermissionMatrix({ resources, actions, value, onChange, disabled = false }: Props) {
|
|
15
|
+
return (
|
|
16
|
+
<div className="w-full min-w-0 overflow-x-auto rounded-lg border">
|
|
17
|
+
<Table>
|
|
18
|
+
<TableHeader>
|
|
19
|
+
<TableRow>
|
|
20
|
+
<TableHead>Resource</TableHead>
|
|
21
|
+
{actions.flatMap((action) => [
|
|
22
|
+
<TableHead key={`${action}:any`}>{action}</TableHead>,
|
|
23
|
+
<TableHead key={`${action}:own`}>{action} own</TableHead>,
|
|
24
|
+
])}
|
|
25
|
+
</TableRow>
|
|
26
|
+
</TableHeader>
|
|
27
|
+
<TableBody>
|
|
28
|
+
{resources.map((resource) => (
|
|
29
|
+
<TableRow key={resource}>
|
|
30
|
+
<TableCell className="font-medium">{resource}</TableCell>
|
|
31
|
+
{actions.flatMap((action) => (['any', 'own'] as const).map((scope) => {
|
|
32
|
+
const selected = value.some((item) => item.resource === resource && item.action === action && item.scope === scope);
|
|
33
|
+
return (
|
|
34
|
+
<TableCell key={`${action}:${scope}`}>
|
|
35
|
+
<input
|
|
36
|
+
type="checkbox"
|
|
37
|
+
aria-label={`${resource} ${action} ${scope}`}
|
|
38
|
+
checked={selected}
|
|
39
|
+
disabled={disabled}
|
|
40
|
+
onChange={(event) => {
|
|
41
|
+
const next = value.filter((item) => !(item.resource === resource && item.action === action && item.scope === scope));
|
|
42
|
+
onChange(event.target.checked ? [...next, { resource, action, scope }] : next);
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</TableCell>
|
|
46
|
+
);
|
|
47
|
+
}))}
|
|
48
|
+
</TableRow>
|
|
49
|
+
))}
|
|
50
|
+
</TableBody>
|
|
51
|
+
</Table>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { AdminPermissionMatrix, type PermissionCell } from './AdminPermissionMatrix';
|
|
3
|
+
import { AdminConfirmDialog } from './AdminConfirmDialog';
|
|
4
|
+
|
|
5
|
+
export type ManagedRole = {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
tenantId: string | null;
|
|
9
|
+
permissions: readonly PermissionCell[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
roles: readonly ManagedRole[];
|
|
14
|
+
tenantId: string | null;
|
|
15
|
+
resources: readonly string[];
|
|
16
|
+
actions: readonly string[];
|
|
17
|
+
onCreate: (name: string, tenantId: string | null) => void;
|
|
18
|
+
onRename: (roleId: string, name: string) => void;
|
|
19
|
+
onDelete: (roleId: string) => void;
|
|
20
|
+
onPermissionsChange: (roleId: string, permissions: PermissionCell[]) => void;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** All callbacks must call trusted, admin-authorized server handlers. */
|
|
25
|
+
export function AdminRoleManager({
|
|
26
|
+
roles, tenantId, resources, actions, onCreate, onRename, onDelete, onPermissionsChange,
|
|
27
|
+
disabled = false,
|
|
28
|
+
}: Props) {
|
|
29
|
+
const [query, setQuery] = useState('');
|
|
30
|
+
const [name, setName] = useState('');
|
|
31
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
32
|
+
const visible = roles.filter((role) => role.tenantId === tenantId && role.name.toLowerCase().includes(query.toLowerCase()));
|
|
33
|
+
const selected = roles.find((role) => role.id === selectedId && role.tenantId === tenantId);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<section aria-label="Role management" className="space-y-4">
|
|
37
|
+
<header className="flex flex-wrap items-center gap-3">
|
|
38
|
+
<input aria-label="Search roles" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
39
|
+
<form onSubmit={(event) => {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
if (!disabled && name.trim()) {
|
|
42
|
+
onCreate(name.trim(), tenantId);
|
|
43
|
+
setName('');
|
|
44
|
+
}
|
|
45
|
+
}} className="flex gap-2">
|
|
46
|
+
<input aria-label="New role name" className="rounded-md border p-2" required value={name} onChange={(event) => setName(event.target.value)} disabled={disabled} />
|
|
47
|
+
<button className="rounded-md border px-3" type="submit" disabled={disabled || !name.trim()}>Create role</button>
|
|
48
|
+
</form>
|
|
49
|
+
</header>
|
|
50
|
+
<div className="flex flex-wrap gap-2">
|
|
51
|
+
{visible.map((role) => (
|
|
52
|
+
<button key={role.id} type="button" aria-pressed={selected?.id === role.id}
|
|
53
|
+
className="rounded-md border px-3 py-2 aria-pressed:bg-muted"
|
|
54
|
+
onClick={() => setSelectedId(role.id)}>{role.name}</button>
|
|
55
|
+
))}
|
|
56
|
+
{visible.length === 0 ? <p>No roles found</p> : null}
|
|
57
|
+
</div>
|
|
58
|
+
{selected ? (
|
|
59
|
+
<div className="space-y-4 rounded-lg border p-4" key={selected.id}>
|
|
60
|
+
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const data = new FormData(event.currentTarget);
|
|
63
|
+
const nextName = data.get('roleName');
|
|
64
|
+
if (!disabled && typeof nextName === 'string' && nextName.trim()) onRename(selected.id, nextName.trim());
|
|
65
|
+
}}>
|
|
66
|
+
<input name="roleName" aria-label="Role name" defaultValue={selected.name} required className="rounded-md border p-2" disabled={disabled} />
|
|
67
|
+
<button type="submit" className="rounded-md border px-3" disabled={disabled}>Rename</button>
|
|
68
|
+
{!disabled ? <AdminConfirmDialog
|
|
69
|
+
trigger={<button type="button" className="rounded-md border px-3">Delete role</button>}
|
|
70
|
+
title="Delete role"
|
|
71
|
+
description={`Delete ${selected.name}? This may revoke user and group permissions.`}
|
|
72
|
+
onConfirm={() => { onDelete(selected.id); setSelectedId(null); }}
|
|
73
|
+
/> : null}
|
|
74
|
+
</form>
|
|
75
|
+
<AdminPermissionMatrix resources={resources} actions={actions} value={selected.permissions}
|
|
76
|
+
onChange={(permissions) => onPermissionsChange(selected.id, permissions)} disabled={disabled} />
|
|
77
|
+
</div>
|
|
78
|
+
) : null}
|
|
79
|
+
</section>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar';
|
|
3
|
+
|
|
4
|
+
type AdminShellProps = {
|
|
5
|
+
sidebar: ReactNode;
|
|
6
|
+
header?: ReactNode;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function AdminShell({ sidebar, header, children }: AdminShellProps) {
|
|
11
|
+
return (
|
|
12
|
+
<SidebarProvider>
|
|
13
|
+
{sidebar}
|
|
14
|
+
<SidebarInset className="min-w-0">
|
|
15
|
+
{header}
|
|
16
|
+
<main className="min-w-0 flex-1">{children}</main>
|
|
17
|
+
</SidebarInset>
|
|
18
|
+
</SidebarProvider>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader } from '@/components/ui/sidebar';
|
|
3
|
+
|
|
4
|
+
type AdminSidebarProps = {
|
|
5
|
+
navigation: ReactNode;
|
|
6
|
+
header?: ReactNode;
|
|
7
|
+
footer?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function AdminSidebar({ navigation, header, footer }: AdminSidebarProps) {
|
|
11
|
+
return (
|
|
12
|
+
<Sidebar>
|
|
13
|
+
{header ? <SidebarHeader>{header}</SidebarHeader> : null}
|
|
14
|
+
<SidebarContent>{navigation}</SidebarContent>
|
|
15
|
+
{footer ? <SidebarFooter>{footer}</SidebarFooter> : null}
|
|
16
|
+
</Sidebar>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
3
|
+
|
|
4
|
+
type AdminStatCardProps = {
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
value: ReactNode;
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function AdminStatCard({ label, value, description }: AdminStatCardProps) {
|
|
11
|
+
return (
|
|
12
|
+
<Card>
|
|
13
|
+
<CardHeader>
|
|
14
|
+
<CardTitle className="text-sm font-medium text-muted-foreground">{label}</CardTitle>
|
|
15
|
+
</CardHeader>
|
|
16
|
+
<CardContent className="space-y-1">
|
|
17
|
+
<div className="text-2xl font-semibold tabular-nums">{value}</div>
|
|
18
|
+
{description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
|
|
19
|
+
</CardContent>
|
|
20
|
+
</Card>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { writeProjectFileIfMissing } from "./install.js";
|
|
4
|
+
import { pathExists } from "./project-signals.js";
|
|
5
|
+
const components = [
|
|
6
|
+
'AdminShell',
|
|
7
|
+
'AdminSidebar',
|
|
8
|
+
'AdminPage',
|
|
9
|
+
'AdminPageHeader',
|
|
10
|
+
'AdminFilterBar',
|
|
11
|
+
'AdminDataTable',
|
|
12
|
+
'AdminPagination',
|
|
13
|
+
'AdminFormLayout',
|
|
14
|
+
'AdminDetailLayout',
|
|
15
|
+
'AdminStatCard',
|
|
16
|
+
'AdminEmptyState',
|
|
17
|
+
'AdminConfirmDialog',
|
|
18
|
+
'AdminPermissionMatrix',
|
|
19
|
+
'AdminRoleManager',
|
|
20
|
+
'AdminAccessAssignments',
|
|
21
|
+
'AdminMembershipManager',
|
|
22
|
+
];
|
|
23
|
+
const primitives = ['alert-dialog', 'card', 'sidebar', 'table'];
|
|
24
|
+
async function hasExistingAdminUi(root) {
|
|
25
|
+
// Existing project-owned shared admin page systems are adopted, not replaced.
|
|
26
|
+
return ((await pathExists(root, 'src/components/extra/admin-list-layout.tsx')) &&
|
|
27
|
+
(await pathExists(root, 'src/components/extra/admin-list-states.tsx')));
|
|
28
|
+
}
|
|
29
|
+
async function templateCount(root) {
|
|
30
|
+
const files = await Promise.all(components.map((name) => pathExists(root, 'src/components/admin/' + name + '.tsx')));
|
|
31
|
+
return files.filter(Boolean).length;
|
|
32
|
+
}
|
|
33
|
+
export const adminUiRecipe = {
|
|
34
|
+
id: 'admin-ui',
|
|
35
|
+
recipeVersion: '1.3.0',
|
|
36
|
+
role: 'feature',
|
|
37
|
+
requires: ['shadcn'],
|
|
38
|
+
async detect(root) {
|
|
39
|
+
if (await hasExistingAdminUi(root)) {
|
|
40
|
+
return { present: true, compatible: true, detectedVersion: null };
|
|
41
|
+
}
|
|
42
|
+
const count = await templateCount(root);
|
|
43
|
+
return {
|
|
44
|
+
present: count > 0,
|
|
45
|
+
compatible: count === components.length,
|
|
46
|
+
detectedVersion: null,
|
|
47
|
+
...(count > 0 && count < components.length
|
|
48
|
+
? {
|
|
49
|
+
reason: 'Admin UI has only ' + count + ' of ' + components.length + ' source components',
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
async apply(root) {
|
|
55
|
+
if (await hasExistingAdminUi(root))
|
|
56
|
+
return { source: 'adopted' };
|
|
57
|
+
const rawConfig = JSON.parse(await readFile(join(root, 'components.json'), 'utf8'));
|
|
58
|
+
const aliases = rawConfig !== null && typeof rawConfig === 'object' && 'aliases' in rawConfig
|
|
59
|
+
? rawConfig.aliases
|
|
60
|
+
: null;
|
|
61
|
+
if (aliases === null ||
|
|
62
|
+
typeof aliases !== 'object' ||
|
|
63
|
+
!('ui' in aliases) ||
|
|
64
|
+
aliases.ui !== '@/components/ui' ||
|
|
65
|
+
!('components' in aliases) ||
|
|
66
|
+
aliases.components !== '@/components') {
|
|
67
|
+
throw new Error('admin-ui requires shadcn aliases for @/components and @/components/ui');
|
|
68
|
+
}
|
|
69
|
+
const missing = (await Promise.all(primitives.map(async (name) => (await pathExists(root, 'src/components/ui/' + name + '.tsx')) ? null : name))).filter((name) => name !== null);
|
|
70
|
+
if (missing.length) {
|
|
71
|
+
throw new Error('admin-ui requires shadcn components: ' + missing.join(', ') + '. Add them first.');
|
|
72
|
+
}
|
|
73
|
+
// Read all inputs before changing the project; generated files become project-owned.
|
|
74
|
+
const templates = await Promise.all(components.map(async (name) => ({
|
|
75
|
+
name,
|
|
76
|
+
content: await readFile(new URL('./admin-ui-templates/' + name + '.tsx.template', import.meta.url), 'utf8'),
|
|
77
|
+
})));
|
|
78
|
+
for (const { name, content } of templates) {
|
|
79
|
+
await writeProjectFileIfMissing(root, 'src/components/admin/' + name + '.tsx', content);
|
|
80
|
+
}
|
|
81
|
+
return { source: 'installed' };
|
|
82
|
+
},
|
|
83
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Authentication integration
|
|
2
|
+
|
|
3
|
+
These are project-owned integration helpers, **not a configured login flow**.
|
|
4
|
+
|
|
5
|
+
- Supabase variant requires an initialized Supabase client. `getIdentity` validates the user through Supabase Auth; authorization still belongs in database RLS.
|
|
6
|
+
- For Expo iOS, use `expo-apple-authentication` native Apple Sign-In, obtain a native ID token and pass the correct original nonce to `signInWithNativeAppleToken`. The app owns the nonce generation and lifecycle; this template does not implement it.
|
|
7
|
+
- Convex variant requires a working compatible identity provider configured in `convex/auth.config.ts`. The helper uses Convex's verified server context; the application owns web/Expo login and session state. Convex authorization belongs in protected server queries/mutations.
|
|
8
|
+
- Neither variant stores passwords, creates identity servers, or installs Clerk.
|
|
9
|
+
- Provider credentials, redirect URLs, client wiring, social providers, token lifetimes and Expo platform integration must be configured and tested per application before release.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Identity } from './identity';
|
|
2
|
+
|
|
3
|
+
/** For Convex queries/mutations only: ctx.auth is verified by configured identity provider. */
|
|
4
|
+
export async function getIdentity(ctx: { auth: { getUserIdentity(): Promise<{
|
|
5
|
+
subject: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
} | null> } }): Promise<Identity | null> {
|
|
9
|
+
const user = await ctx.auth.getUserIdentity();
|
|
10
|
+
if (!user?.subject) return null;
|
|
11
|
+
return { id: user.subject, email: user.email ?? null, name: user.name ?? null };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function requireIdentity(ctx: Parameters<typeof getIdentity>[0]): Promise<Identity> {
|
|
15
|
+
const identity = await getIdentity(ctx);
|
|
16
|
+
if (!identity) throw new Error('Unauthorized');
|
|
17
|
+
return identity;
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
import type { Identity } from './identity';
|
|
3
|
+
|
|
4
|
+
/** Always fetch a verified user. Do not trust the locally cached session user for authorization. */
|
|
5
|
+
export async function getIdentity(client: SupabaseClient): Promise<Identity | null> {
|
|
6
|
+
const { data, error } = await client.auth.getUser();
|
|
7
|
+
if (error || !data.user) return null;
|
|
8
|
+
return {
|
|
9
|
+
id: data.user.id,
|
|
10
|
+
email: data.user.email ?? null,
|
|
11
|
+
name: typeof data.user.user_metadata?.full_name === 'string' ? data.user.user_metadata.full_name : null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function signInWithPassword(client: SupabaseClient, email: string, password: string) {
|
|
16
|
+
const { error } = await client.auth.signInWithPassword({ email, password });
|
|
17
|
+
if (error) throw error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function signInWithOAuth(client: SupabaseClient, provider: 'google' | 'github' | 'apple', redirectTo: string) {
|
|
21
|
+
const { data, error } = await client.auth.signInWithOAuth({ provider, options: { redirectTo } });
|
|
22
|
+
if (error) throw error;
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Native Apple ID token from expo-apple-authentication, with validated nonce flow. */
|
|
27
|
+
export async function signInWithNativeAppleToken(client: SupabaseClient, idToken: string, nonce: string) {
|
|
28
|
+
if (!idToken || !nonce) throw new Error('Apple credential and nonce required');
|
|
29
|
+
const { error } = await client.auth.signInWithIdToken({ provider: 'apple', token: idToken, nonce });
|
|
30
|
+
if (error) throw error;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function signOut(client: SupabaseClient) {
|
|
34
|
+
const { error } = await client.auth.signOut();
|
|
35
|
+
if (error) throw error;
|
|
36
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { writeProjectFileIfMissing } from "./install.js";
|
|
1
3
|
import { detectAnyPath } from "./project-signals.js";
|
|
2
4
|
export const authRecipe = {
|
|
3
5
|
id: 'auth',
|
|
4
|
-
recipeVersion: '1.
|
|
6
|
+
recipeVersion: '1.1.0',
|
|
5
7
|
role: 'feature',
|
|
6
8
|
variants: [
|
|
7
9
|
{ id: 'supabase', when: ['supabase'] },
|
|
@@ -10,12 +12,25 @@ export const authRecipe = {
|
|
|
10
12
|
async detect(projectRoot) {
|
|
11
13
|
return await detectAnyPath(projectRoot, ['src/application/auth', 'src/auth', 'app/auth', 'convex/auth.ts', 'convex/auth.config.ts'], 'authentication integration was not detected');
|
|
12
14
|
},
|
|
13
|
-
async apply(
|
|
14
|
-
if (
|
|
15
|
-
|
|
15
|
+
async apply(root, detection, resolution) {
|
|
16
|
+
if (detection.present) {
|
|
17
|
+
if (!detection.compatible)
|
|
18
|
+
throw new Error(detection.reason ?? 'Existing auth integration is not compatible.');
|
|
19
|
+
return { source: 'adopted' };
|
|
16
20
|
}
|
|
17
|
-
if (!
|
|
18
|
-
throw new Error(
|
|
19
|
-
|
|
21
|
+
if (!resolution.variant)
|
|
22
|
+
throw new Error('Auth requires a resolved backend.');
|
|
23
|
+
const filenames = ['identity.ts', resolution.variant + '.ts'];
|
|
24
|
+
const files = await Promise.all(filenames.map(async (name) => ({
|
|
25
|
+
destination: 'src/application/auth/' + name,
|
|
26
|
+
content: await readFile(new URL('./auth-templates/' + name + '.template', import.meta.url), 'utf8'),
|
|
27
|
+
})));
|
|
28
|
+
files.push({
|
|
29
|
+
destination: 'docs/security/auth.md',
|
|
30
|
+
content: await readFile(new URL('./auth-templates/README.md.template', import.meta.url), 'utf8'),
|
|
31
|
+
});
|
|
32
|
+
for (const file of files)
|
|
33
|
+
await writeProjectFileIfMissing(root, file.destination, file.content);
|
|
34
|
+
return { source: 'installed' };
|
|
20
35
|
},
|
|
21
36
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { writeProjectFileIfMissing } from "./install.js";
|
|
3
|
+
import { detectCapability, pathExists } from "./project-signals.js";
|
|
2
4
|
export const multiTenancyRecipe = {
|
|
3
5
|
id: 'multi-tenancy',
|
|
4
|
-
recipeVersion: '1.
|
|
6
|
+
recipeVersion: '1.1.0',
|
|
5
7
|
role: 'feature',
|
|
6
8
|
variants: [
|
|
7
9
|
{ id: 'supabase', when: ['supabase'] },
|
|
@@ -10,12 +12,26 @@ export const multiTenancyRecipe = {
|
|
|
10
12
|
async detect(projectRoot) {
|
|
11
13
|
return await detectCapability(projectRoot, 'multi-tenant');
|
|
12
14
|
},
|
|
13
|
-
async apply(
|
|
15
|
+
async apply(root, detection) {
|
|
14
16
|
if (!detection.present) {
|
|
15
|
-
throw new Error('Multi-tenancy
|
|
17
|
+
throw new Error('Multi-tenancy requires the multi-tenant capability in .spd/rules.json.');
|
|
16
18
|
}
|
|
17
19
|
if (!detection.compatible)
|
|
18
20
|
throw new Error(detection.reason ?? 'Existing multi-tenancy integration is not compatible.');
|
|
19
|
-
|
|
21
|
+
// Do not compete with an existing project-specific tenant implementation.
|
|
22
|
+
if ((await pathExists(root, 'src/lib/tenant-context.ts')) ||
|
|
23
|
+
(await pathExists(root, 'src/features/tenants')) ||
|
|
24
|
+
(await pathExists(root, 'src/application/tenants'))) {
|
|
25
|
+
return { source: 'adopted' };
|
|
26
|
+
}
|
|
27
|
+
const files = [
|
|
28
|
+
{ source: 'tenant-context.ts', destination: 'src/lib/tenant-context.ts' },
|
|
29
|
+
{ source: 'README.md', destination: 'docs/security/tenancy.md' },
|
|
30
|
+
];
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
const content = await readFile(new URL('./tenant-templates/' + file.source + '.template', import.meta.url), 'utf8');
|
|
33
|
+
await writeProjectFileIfMissing(root, file.destination, content);
|
|
34
|
+
}
|
|
35
|
+
return { source: 'installed' };
|
|
20
36
|
},
|
|
21
37
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { abacRecipe } from "./abac.js";
|
|
2
|
+
import { adminUiRecipe } from "./admin-ui.js";
|
|
2
3
|
import { authRecipe } from "./auth.js";
|
|
3
4
|
import { convexRecipe } from "./convex.js";
|
|
4
5
|
import { expoRecipe } from "./expo.js";
|
|
@@ -32,6 +33,7 @@ const RECIPES = new Map([
|
|
|
32
33
|
[authRecipe.id, authRecipe],
|
|
33
34
|
[multiTenancyRecipe.id, multiTenancyRecipe],
|
|
34
35
|
[abacRecipe.id, abacRecipe],
|
|
36
|
+
[adminUiRecipe.id, adminUiRecipe],
|
|
35
37
|
[sentryRecipe.id, sentryRecipe],
|
|
36
38
|
[loggingRecipe.id, loggingRecipe],
|
|
37
39
|
[paymentsRecipe.id, paymentsRecipe],
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Authorization integration checklist
|
|
2
|
+
|
|
3
|
+
These are project-owned **reference templates, NOT an activated security implementation**.
|
|
4
|
+
Do not deploy application features until enforcement is mapped and tested.
|
|
5
|
+
|
|
6
|
+
1. Authenticate via the existing Supabase Auth or configured Convex-compatible provider. Verify the identity server-side. Do not trust client-supplied role/tenant/owner fields.
|
|
7
|
+
2. Persist roles, group memberships, tenant memberships and assignments in trusted backend storage. Restrict all writes to privileged server operations; administrative mutations must authorize the acting administrator.
|
|
8
|
+
3. Supabase: inspect `supabase-posts-example.sql` for complete SELECT/INSERT/UPDATE/DELETE and trigger wiring; adapt `supabase-authorization.sql` to existing declarative schema and real table identifiers. Enforce SELECT/INSERT/UPDATE/DELETE and attach the included tenant/owner immutability trigger to each real resource table. Validate external provider subject-to-UUID mapping. Apply and test RLS; do not use frontend checks in place of RLS.
|
|
9
|
+
4. For limited Supabase user-role assignment, review `supabase-admin-rpc.sql`. It checks the real caller and rejects role grants outside their permissions; it is not a general-purpose admin API.
|
|
10
|
+
5. Convex: adapt `convex/authorization.ts` to the actual schema and load actor/roles/assignments/resource from server-owned tables. Call `authorizedMutation` for writes, `authorizedRows` for list queries, and `authorizedRoleAssignment` for tenant user-to-role changes (using trusted role/member loaders); `authorize` protects individual reads. Never invoke loaders with client-supplied owner IDs, roles or grants. Individual resource reads/writes deny missing resources. Only create checks accept `requireResource: false`; `authorizedMutation` additionally requires `newResource` with the authenticated owner and requested tenant. Persist precisely these server-validated scope fields; never trust client-provided ownership. Lists must filter server-loaded rows *before pagination*.
|
|
11
|
+
6. Test anonymous, missing grants, any/own grants, ownership transfers, cross-tenant access, revoked roles and unauthorized administrative edits.
|
|
12
|
+
|
|
13
|
+
Permission semantics: `feature:action` with `any` or `own` scope. `own` requires a resource loaded from the backend and an exact trusted owner match. Global grants do not authorize tenant resources. Missing identity or membership denies.
|
|
14
|
+
|
|
15
|
+
Security note: Convex mutation loaders and writes must execute in the same Convex transaction. Do not call an external service or an action to perform the write after authorization. Role creation, permission editing, user invitations, and group membership changes require independently authorized server mutations.
|