@specdest/devkit 0.4.19 → 0.4.20
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 +105 -28
- package/dist/npm/cli.js +16 -26
- package/dist/npm/index.js +4 -1
- package/dist/npm/native/specdest-darwin-arm64 +0 -0
- package/dist/npm/native/specdest-darwin-x64 +0 -0
- package/dist/npm/native/specdest-linux-arm64 +0 -0
- package/dist/npm/native/specdest-linux-x64 +0 -0
- package/package.json +8 -5
- package/dist/npm/automation-policy.d.ts +0 -2
- package/dist/npm/automation-policy.js +0 -30
- package/dist/npm/canonical-project-operations.d.ts +0 -5
- package/dist/npm/canonical-project-operations.js +0 -5
- package/dist/npm/canonical-project.d.ts +0 -21
- package/dist/npm/canonical-project.js +0 -115
- package/dist/npm/catalog-snapshot.d.ts +0 -53
- package/dist/npm/catalog-snapshot.js +0 -35
- package/dist/npm/client-only-boundary.d.ts +0 -1
- package/dist/npm/client-only-boundary.js +0 -29
- package/dist/npm/commands.d.ts +0 -16
- package/dist/npm/commands.js +0 -194
- package/dist/npm/git-catalog.d.ts +0 -40
- package/dist/npm/git-catalog.js +0 -222
- package/dist/npm/github-doppler-secrets.d.ts +0 -8
- package/dist/npm/github-doppler-secrets.js +0 -156
- package/dist/npm/host-automation.d.ts +0 -9
- package/dist/npm/host-automation.js +0 -87
- package/dist/npm/installer-primitives.d.ts +0 -3
- package/dist/npm/installer-primitives.js +0 -50
- package/dist/npm/predefined-packages/abac.d.ts +0 -2
- package/dist/npm/predefined-packages/abac.js +0 -45
- package/dist/npm/predefined-packages/admin-ui-templates/AdminAccessAssignments.tsx.template +0 -67
- package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +0 -46
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +0 -49
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +0 -15
- package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +0 -17
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +0 -16
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminMembershipManager.tsx.template +0 -56
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPermissionMatrix.tsx.template +0 -54
- package/dist/npm/predefined-packages/admin-ui-templates/AdminRoleManager.tsx.template +0 -81
- package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +0 -18
- package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +0 -22
- package/dist/npm/predefined-packages/admin-ui.d.ts +0 -2
- package/dist/npm/predefined-packages/admin-ui.js +0 -83
- package/dist/npm/predefined-packages/auth-templates/README.md.template +0 -9
- package/dist/npm/predefined-packages/auth-templates/convex.ts.template +0 -18
- package/dist/npm/predefined-packages/auth-templates/identity.ts.template +0 -2
- package/dist/npm/predefined-packages/auth-templates/supabase.ts.template +0 -36
- package/dist/npm/predefined-packages/auth.d.ts +0 -2
- package/dist/npm/predefined-packages/auth.js +0 -36
- package/dist/npm/predefined-packages/convex.d.ts +0 -2
- package/dist/npm/predefined-packages/convex.js +0 -53
- package/dist/npm/predefined-packages/expo.d.ts +0 -2
- package/dist/npm/predefined-packages/expo.js +0 -88
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +0 -2
- package/dist/npm/predefined-packages/firebase-hosting.js +0 -24
- package/dist/npm/predefined-packages/health.d.ts +0 -10
- package/dist/npm/predefined-packages/health.js +0 -52
- package/dist/npm/predefined-packages/husky.d.ts +0 -2
- package/dist/npm/predefined-packages/husky.js +0 -57
- package/dist/npm/predefined-packages/index.d.ts +0 -12
- package/dist/npm/predefined-packages/index.js +0 -97
- package/dist/npm/predefined-packages/install.d.ts +0 -19
- package/dist/npm/predefined-packages/install.js +0 -86
- package/dist/npm/predefined-packages/local-logging.d.ts +0 -2
- package/dist/npm/predefined-packages/local-logging.js +0 -17
- package/dist/npm/predefined-packages/logging.d.ts +0 -2
- package/dist/npm/predefined-packages/logging.js +0 -21
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +0 -2
- package/dist/npm/predefined-packages/multi-tenancy.js +0 -37
- package/dist/npm/predefined-packages/nps.d.ts +0 -2
- package/dist/npm/predefined-packages/nps.js +0 -32
- package/dist/npm/predefined-packages/oxfmt.d.ts +0 -2
- package/dist/npm/predefined-packages/oxfmt.js +0 -22
- package/dist/npm/predefined-packages/oxlint.d.ts +0 -2
- package/dist/npm/predefined-packages/oxlint.js +0 -35
- package/dist/npm/predefined-packages/package-json.d.ts +0 -3
- package/dist/npm/predefined-packages/package-json.js +0 -61
- package/dist/npm/predefined-packages/payments.d.ts +0 -2
- package/dist/npm/predefined-packages/payments.js +0 -31
- package/dist/npm/predefined-packages/playwright.d.ts +0 -2
- package/dist/npm/predefined-packages/playwright.js +0 -35
- package/dist/npm/predefined-packages/project-signals.d.ts +0 -4
- package/dist/npm/predefined-packages/project-signals.js +0 -39
- package/dist/npm/predefined-packages/registry.d.ts +0 -3
- package/dist/npm/predefined-packages/registry.js +0 -65
- package/dist/npm/predefined-packages/resolver.d.ts +0 -8
- package/dist/npm/predefined-packages/resolver.js +0 -35
- package/dist/npm/predefined-packages/security-templates/README.md.template +0 -15
- package/dist/npm/predefined-packages/security-templates/convex-authorization.ts.template +0 -109
- package/dist/npm/predefined-packages/security-templates/permissions.ts.template +0 -40
- package/dist/npm/predefined-packages/security-templates/supabase-admin-rpc.sql.template +0 -54
- package/dist/npm/predefined-packages/security-templates/supabase-authorization.sql.template +0 -138
- package/dist/npm/predefined-packages/security-templates/supabase-posts-example.sql.template +0 -39
- package/dist/npm/predefined-packages/sentry.d.ts +0 -2
- package/dist/npm/predefined-packages/sentry.js +0 -29
- package/dist/npm/predefined-packages/shadcn.d.ts +0 -2
- package/dist/npm/predefined-packages/shadcn.js +0 -23
- package/dist/npm/predefined-packages/storybook.d.ts +0 -2
- package/dist/npm/predefined-packages/storybook.js +0 -25
- package/dist/npm/predefined-packages/stryker.d.ts +0 -2
- package/dist/npm/predefined-packages/stryker.js +0 -48
- package/dist/npm/predefined-packages/supabase.d.ts +0 -2
- package/dist/npm/predefined-packages/supabase.js +0 -355
- package/dist/npm/predefined-packages/tailwind.d.ts +0 -2
- package/dist/npm/predefined-packages/tailwind.js +0 -18
- package/dist/npm/predefined-packages/tanstack-form.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-form.js +0 -19
- package/dist/npm/predefined-packages/tanstack-query.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-query.js +0 -15
- package/dist/npm/predefined-packages/tanstack-router.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-router.js +0 -18
- package/dist/npm/predefined-packages/tenant-templates/README.md.template +0 -11
- package/dist/npm/predefined-packages/tenant-templates/tenant-context.ts.template +0 -22
- package/dist/npm/predefined-packages/types.d.ts +0 -38
- package/dist/npm/predefined-packages/types.js +0 -1
- package/dist/npm/predefined-packages/vite.d.ts +0 -2
- package/dist/npm/predefined-packages/vite.js +0 -127
- package/dist/npm/predefined-packages/vitest.d.ts +0 -2
- package/dist/npm/predefined-packages/vitest.js +0 -20
- package/dist/npm/predefined-packages/zod.d.ts +0 -2
- package/dist/npm/predefined-packages/zod.js +0 -18
- package/dist/npm/project-check.d.ts +0 -37
- package/dist/npm/project-check.js +0 -231
- package/dist/npm/project-context.d.ts +0 -52
- package/dist/npm/project-context.js +0 -211
- package/dist/npm/project-install-guard.d.ts +0 -2
- package/dist/npm/project-install-guard.js +0 -51
- package/dist/npm/project-rules.d.ts +0 -25
- package/dist/npm/project-rules.js +0 -106
- package/dist/npm/project-runtime.d.ts +0 -21
- package/dist/npm/project-runtime.js +0 -41
- package/dist/npm/project-status.d.ts +0 -32
- package/dist/npm/project-status.js +0 -70
- package/dist/npm/project-sync.d.ts +0 -7
- package/dist/npm/project-sync.js +0 -143
- package/dist/npm/remote-installer.d.ts +0 -35
- package/dist/npm/remote-installer.js +0 -351
- package/dist/npm/rule-id-migrations.d.ts +0 -6
- package/dist/npm/rule-id-migrations.js +0 -19
- package/dist/npm/slack.d.ts +0 -16
- package/dist/npm/slack.js +0 -135
- package/dist/npm/snapshot/config.d.ts +0 -10
- package/dist/npm/snapshot/config.js +0 -24
- package/dist/npm/snapshot/policy.d.ts +0 -1
- package/dist/npm/snapshot/policy.js +0 -64
- package/dist/npm/snapshot/restore.d.ts +0 -10
- package/dist/npm/snapshot/restore.js +0 -19
- package/dist/npm/snapshot/sql.d.ts +0 -2
- package/dist/npm/snapshot/sql.js +0 -113
- package/dist/npm/snapshot/storage.d.ts +0 -8
- package/dist/npm/snapshot/storage.js +0 -70
- package/dist/npm/snapshot/verify.d.ts +0 -11
- package/dist/npm/snapshot/verify.js +0 -13
- package/dist/npm/snapshot-cli.d.ts +0 -6
- package/dist/npm/snapshot-cli.js +0 -45
- package/dist/npm/state.d.ts +0 -14
- package/dist/npm/state.js +0 -269
- package/dist/npm/supabase-local.d.ts +0 -2
- package/dist/npm/supabase-local.js +0 -63
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { basename, resolve } from 'node:path';
|
|
4
|
-
import { projectFromCwd } from "./supabase-local.js";
|
|
5
|
-
const TOOLS = {
|
|
6
|
-
device: 'agent-device',
|
|
7
|
-
browser: 'agent-browser',
|
|
8
|
-
'jev-browser': 'jev-browser',
|
|
9
|
-
};
|
|
10
|
-
const NPS_BIN_ENV = {
|
|
11
|
-
device: 'SPECDEST_DEVKIT_AGENT_DEVICE_BIN',
|
|
12
|
-
browser: 'SPECDEST_DEVKIT_AGENT_BROWSER_BIN',
|
|
13
|
-
'jev-browser': 'SPECDEST_DEVKIT_JEV_BROWSER_BIN',
|
|
14
|
-
};
|
|
15
|
-
/** Forward unchanged arguments through Controller's queue, or its trusted NPS host context. */
|
|
16
|
-
export function runHostAutomation(command, args, cwd = process.cwd(), invoke = spawnSync, gatewayExists = existsSync, env = process.env) {
|
|
17
|
-
// Non-Supabase admin frontend: identity is used only to request access;
|
|
18
|
-
// Controller's root-owned allowlist still decides whether automation is authorized.
|
|
19
|
-
const adminManifest = resolve(cwd, 'package.json');
|
|
20
|
-
const isAdmin = basename(resolve(cwd)) === 'mycone-admin' &&
|
|
21
|
-
existsSync(adminManifest) &&
|
|
22
|
-
(() => {
|
|
23
|
-
try {
|
|
24
|
-
return JSON.parse(readFileSync(adminManifest, 'utf8')).name === 'mycone-admin';
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
})();
|
|
30
|
-
const agentManifest = resolve(cwd, 'agent/Cargo.toml');
|
|
31
|
-
const isWorkIntelligence = basename(resolve(cwd)) === 'work-intelligence-agent' &&
|
|
32
|
-
existsSync(agentManifest) &&
|
|
33
|
-
/^name\s*=\s*"work-intelligence-agent"\s*$/mu.test(readFileSync(agentManifest, 'utf8'));
|
|
34
|
-
const isCorporateSite = basename(resolve(cwd)) === 'specdest-lp' &&
|
|
35
|
-
existsSync(adminManifest) &&
|
|
36
|
-
(() => {
|
|
37
|
-
try {
|
|
38
|
-
return JSON.parse(readFileSync(adminManifest, 'utf8')).name === 'specdest-corporate-site';
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
const project = projectFromCwd(cwd) ??
|
|
45
|
-
(isAdmin
|
|
46
|
-
? 'mycone-admin'
|
|
47
|
-
: isWorkIntelligence
|
|
48
|
-
? 'work-intelligence-agent'
|
|
49
|
-
: isCorporateSite
|
|
50
|
-
? 'specdest-lp'
|
|
51
|
-
: undefined);
|
|
52
|
-
if (!project) {
|
|
53
|
-
process.stderr.write('Controller project registration required.\n');
|
|
54
|
-
return 2;
|
|
55
|
-
}
|
|
56
|
-
if (!args.length) {
|
|
57
|
-
process.stderr.write(`Usage: specdest ${command} <subcommand> [args...]\n`);
|
|
58
|
-
return 2;
|
|
59
|
-
}
|
|
60
|
-
// NPS executes inside the Mac gateway worker. Re-enqueuing to that worker
|
|
61
|
-
// would deadlock, so use the trusted host path injected by Controller.
|
|
62
|
-
if (env.SPECDEST_DEVKIT_GATEWAY_NPS === '1') {
|
|
63
|
-
const binary = env[NPS_BIN_ENV[command]];
|
|
64
|
-
if (!binary?.startsWith('/') || !gatewayExists(binary)) {
|
|
65
|
-
process.stderr.write('Controller did not authorize this host automation binary.\n');
|
|
66
|
-
return 1;
|
|
67
|
-
}
|
|
68
|
-
const result = invoke(binary, args, { stdio: 'inherit', shell: false });
|
|
69
|
-
if (result.error)
|
|
70
|
-
process.stderr.write(`${result.error.message}\n`);
|
|
71
|
-
return result.error ? 1 : (result.status ?? 1);
|
|
72
|
-
}
|
|
73
|
-
const client = '/usr/local/bin/host-cli';
|
|
74
|
-
if (!gatewayExists(client)) {
|
|
75
|
-
process.stderr.write('Controller gateway client unavailable.\n');
|
|
76
|
-
return 1;
|
|
77
|
-
}
|
|
78
|
-
const result = invoke(client, ['devkit-automation', project, TOOLS[command], ...args], {
|
|
79
|
-
stdio: 'inherit',
|
|
80
|
-
shell: false,
|
|
81
|
-
});
|
|
82
|
-
if (result.error) {
|
|
83
|
-
process.stderr.write(`${result.error.message}\n`);
|
|
84
|
-
return 1;
|
|
85
|
-
}
|
|
86
|
-
return result.status ?? 1;
|
|
87
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function resolveProjectPath(projectRoot: string, relativePath: string): string;
|
|
2
|
-
export declare function upsertMarkdownSection(existing: string, heading: string, body: string): string;
|
|
3
|
-
export declare function removeMarkdownSection(existing: string, heading: string): string;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, resolve, sep } from 'node:path';
|
|
2
|
-
export function resolveProjectPath(projectRoot, relativePath) {
|
|
3
|
-
if (!relativePath || isAbsolute(relativePath)) {
|
|
4
|
-
throw new Error(`Path must be project-relative: ${relativePath}`);
|
|
5
|
-
}
|
|
6
|
-
const root = resolve(projectRoot);
|
|
7
|
-
const target = resolve(root, relativePath);
|
|
8
|
-
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
9
|
-
throw new Error(`Path escapes project: ${relativePath}`);
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
}
|
|
13
|
-
function markdownSectionBounds(existing, heading) {
|
|
14
|
-
const trimmed = heading.trim();
|
|
15
|
-
const level = trimmed.match(/^(#{1,6})\s+/)?.[1].length ?? 2;
|
|
16
|
-
const lines = existing.split(/(?<=\n)/);
|
|
17
|
-
let offset = 0;
|
|
18
|
-
let start = -1;
|
|
19
|
-
let end = existing.length;
|
|
20
|
-
for (const line of lines) {
|
|
21
|
-
if (start < 0 && line.trim() === trimmed)
|
|
22
|
-
start = offset;
|
|
23
|
-
else if (start >= 0 && new RegExp(`^#{1,${level}}\\s+`).test(line.trim())) {
|
|
24
|
-
end = offset;
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
offset += line.length;
|
|
28
|
-
}
|
|
29
|
-
return start >= 0 ? [start, end] : null;
|
|
30
|
-
}
|
|
31
|
-
export function upsertMarkdownSection(existing, heading, body) {
|
|
32
|
-
const block = `${heading.trim()}\n\n${body.trim()}\n`;
|
|
33
|
-
const bounds = markdownSectionBounds(existing, heading);
|
|
34
|
-
if (!bounds)
|
|
35
|
-
return `${existing.trimEnd()}${existing.trim() ? '\n\n' : ''}${block}`;
|
|
36
|
-
const [start, end] = bounds;
|
|
37
|
-
const before = existing.slice(0, start).trimEnd();
|
|
38
|
-
const after = existing.slice(end).trim();
|
|
39
|
-
return `${[before, block.trimEnd(), after].filter(Boolean).join('\n\n')}\n`;
|
|
40
|
-
}
|
|
41
|
-
export function removeMarkdownSection(existing, heading) {
|
|
42
|
-
const bounds = markdownSectionBounds(existing, heading);
|
|
43
|
-
if (!bounds)
|
|
44
|
-
return existing;
|
|
45
|
-
const [start, end] = bounds;
|
|
46
|
-
const updated = `${existing.slice(0, start).trimEnd()}\n\n${existing.slice(end).trimStart()}`
|
|
47
|
-
.replace(/\n{3,}/g, '\n\n')
|
|
48
|
-
.trimEnd();
|
|
49
|
-
return updated ? `${updated}\n` : '';
|
|
50
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { writeProjectFileIfMissing } from "./install.js";
|
|
3
|
-
import { detectAnyPath } from "./project-signals.js";
|
|
4
|
-
export const abacRecipe = {
|
|
5
|
-
id: 'abac',
|
|
6
|
-
recipeVersion: '1.4.0',
|
|
7
|
-
role: 'feature',
|
|
8
|
-
requires: ['auth'],
|
|
9
|
-
variants: [
|
|
10
|
-
{ id: 'supabase', when: ['supabase'] },
|
|
11
|
-
{ id: 'convex', when: ['convex'] },
|
|
12
|
-
],
|
|
13
|
-
async detect(projectRoot) {
|
|
14
|
-
return await detectAnyPath(projectRoot, ['src/lib/permissions.ts', 'src/permissions', 'src/policies', 'src/features/permissions'], 'ABAC policy integration was not detected');
|
|
15
|
-
},
|
|
16
|
-
async apply(root, detection, resolution) {
|
|
17
|
-
if (detection.present) {
|
|
18
|
-
if (!detection.compatible)
|
|
19
|
-
throw new Error(detection.reason ?? 'Existing ABAC integration is not compatible.');
|
|
20
|
-
return { source: 'adopted' };
|
|
21
|
-
}
|
|
22
|
-
if (!resolution.variant)
|
|
23
|
-
throw new Error('ABAC requires an identified backend.');
|
|
24
|
-
const variantTemplate = resolution.variant === 'supabase'
|
|
25
|
-
? 'supabase-authorization.sql'
|
|
26
|
-
: 'convex-authorization.ts';
|
|
27
|
-
const files = [
|
|
28
|
-
{ source: 'permissions.ts', destination: 'src/lib/permissions.ts' },
|
|
29
|
-
{ source: variantTemplate, destination: resolution.variant === 'convex' ? 'convex/authorization.ts' : 'docs/security/' + variantTemplate },
|
|
30
|
-
...(resolution.variant === 'supabase' ? [
|
|
31
|
-
{ source: 'supabase-posts-example.sql', destination: 'docs/security/supabase-posts-example.sql' },
|
|
32
|
-
{ source: 'supabase-admin-rpc.sql', destination: 'docs/security/supabase-admin-rpc.sql' },
|
|
33
|
-
] : []),
|
|
34
|
-
{ source: 'README.md', destination: 'docs/security/README.md' },
|
|
35
|
-
];
|
|
36
|
-
// Templates are intentionally references until schema-specific backend enforcement is wired.
|
|
37
|
-
const content = await Promise.all(files.map(async (file) => ({
|
|
38
|
-
destination: file.destination,
|
|
39
|
-
text: await readFile(new URL('./security-templates/' + file.source + '.template', import.meta.url), 'utf8'),
|
|
40
|
-
})));
|
|
41
|
-
for (const file of content)
|
|
42
|
-
await writeProjectFileIfMissing(root, file.destination, file.text);
|
|
43
|
-
return { source: 'installed' };
|
|
44
|
-
},
|
|
45
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
|
|
3
|
-
export type AccessSubject = { id: string; label: string };
|
|
4
|
-
export type AccessAssignment = {
|
|
5
|
-
subjectType: 'user' | 'group';
|
|
6
|
-
subjectId: string;
|
|
7
|
-
roleId: string;
|
|
8
|
-
tenantId: string | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
users: readonly AccessSubject[];
|
|
13
|
-
groups: readonly AccessSubject[];
|
|
14
|
-
roles: readonly AccessSubject[];
|
|
15
|
-
assignments: readonly AccessAssignment[];
|
|
16
|
-
tenantId: string | null;
|
|
17
|
-
onAssign: (assignment: AccessAssignment) => void;
|
|
18
|
-
onRevoke: (assignment: AccessAssignment) => void;
|
|
19
|
-
disabled?: boolean;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/** Presentation-only role assignment editor. Authorization belongs in the mutation backend. */
|
|
23
|
-
export function AdminAccessAssignments({ users, groups, roles, assignments, tenantId, onAssign, onRevoke, disabled = false }: Props) {
|
|
24
|
-
const [subjectType, setSubjectType] = useState<'user' | 'group'>('user');
|
|
25
|
-
const [subjectId, setSubjectId] = useState('');
|
|
26
|
-
const [roleId, setRoleId] = useState('');
|
|
27
|
-
const [query, setQuery] = useState('');
|
|
28
|
-
const subjects = subjectType === 'user' ? users : groups;
|
|
29
|
-
const eligible = assignments.filter((entry) => entry.tenantId === tenantId);
|
|
30
|
-
const labelFor = (assignment: AccessAssignment) =>
|
|
31
|
-
(assignment.subjectType === 'user' ? users : groups).find((item) => item.id === assignment.subjectId)?.label ?? assignment.subjectId;
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<section aria-label="Role assignments" className="space-y-4">
|
|
35
|
-
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
36
|
-
event.preventDefault();
|
|
37
|
-
if (disabled || !subjectId || !roleId) return;
|
|
38
|
-
const assignment: AccessAssignment = { subjectType, subjectId, roleId, tenantId };
|
|
39
|
-
if (!eligible.some((entry) => entry.subjectType === subjectType && entry.subjectId === subjectId && entry.roleId === roleId)) onAssign(assignment);
|
|
40
|
-
}}>
|
|
41
|
-
<select aria-label="Subject type" className="rounded-md border p-2" value={subjectType}
|
|
42
|
-
onChange={(event) => { setSubjectType(event.target.value === 'group' ? 'group' : 'user'); setSubjectId(''); }} disabled={disabled}>
|
|
43
|
-
<option value="user">User</option><option value="group">Group</option>
|
|
44
|
-
</select>
|
|
45
|
-
<select aria-label="Subject" className="rounded-md border p-2" value={subjectId} required onChange={(event) => setSubjectId(event.target.value)} disabled={disabled}>
|
|
46
|
-
<option value="">Select subject</option>
|
|
47
|
-
{subjects.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
48
|
-
</select>
|
|
49
|
-
<select aria-label="Role" className="rounded-md border p-2" value={roleId} required onChange={(event) => setRoleId(event.target.value)} disabled={disabled}>
|
|
50
|
-
<option value="">Select role</option>
|
|
51
|
-
{roles.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
52
|
-
</select>
|
|
53
|
-
<button type="submit" className="rounded-md border px-3" disabled={disabled || !subjectId || !roleId}>Assign role</button>
|
|
54
|
-
</form>
|
|
55
|
-
<input aria-label="Filter assignments" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
56
|
-
<ul className="space-y-2">
|
|
57
|
-
{eligible.filter((entry) => `${labelFor(entry)} ${roles.find((role) => role.id === entry.roleId)?.label ?? entry.roleId}`.toLowerCase().includes(query.toLowerCase()))
|
|
58
|
-
.map((entry) => (
|
|
59
|
-
<li key={`${entry.subjectType}:${entry.subjectId}:${entry.roleId}`} className="flex flex-wrap items-center justify-between gap-2 rounded-md border p-2">
|
|
60
|
-
<span>{entry.subjectType}: {labelFor(entry)} — {roles.find((role) => role.id === entry.roleId)?.label ?? entry.roleId}</span>
|
|
61
|
-
<button type="button" className="rounded-md border px-3 py-1" disabled={disabled} onClick={() => onRevoke(entry)}>Revoke</button>
|
|
62
|
-
</li>
|
|
63
|
-
))}
|
|
64
|
-
</ul>
|
|
65
|
-
</section>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
AlertDialog,
|
|
4
|
-
AlertDialogAction,
|
|
5
|
-
AlertDialogCancel,
|
|
6
|
-
AlertDialogContent,
|
|
7
|
-
AlertDialogDescription,
|
|
8
|
-
AlertDialogFooter,
|
|
9
|
-
AlertDialogHeader,
|
|
10
|
-
AlertDialogTitle,
|
|
11
|
-
AlertDialogTrigger,
|
|
12
|
-
} from '@/components/ui/alert-dialog';
|
|
13
|
-
|
|
14
|
-
type AdminConfirmDialogProps = {
|
|
15
|
-
trigger: ReactNode;
|
|
16
|
-
title: ReactNode;
|
|
17
|
-
description: ReactNode;
|
|
18
|
-
onConfirm: () => void;
|
|
19
|
-
confirmLabel?: string;
|
|
20
|
-
cancelLabel?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export function AdminConfirmDialog({
|
|
24
|
-
trigger,
|
|
25
|
-
title,
|
|
26
|
-
description,
|
|
27
|
-
onConfirm,
|
|
28
|
-
confirmLabel = 'Confirm',
|
|
29
|
-
cancelLabel = 'Cancel',
|
|
30
|
-
}: AdminConfirmDialogProps) {
|
|
31
|
-
return (
|
|
32
|
-
<AlertDialog>
|
|
33
|
-
<AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>
|
|
34
|
-
<AlertDialogContent>
|
|
35
|
-
<AlertDialogHeader>
|
|
36
|
-
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
37
|
-
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
38
|
-
</AlertDialogHeader>
|
|
39
|
-
<AlertDialogFooter>
|
|
40
|
-
<AlertDialogCancel>{cancelLabel}</AlertDialogCancel>
|
|
41
|
-
<AlertDialogAction onClick={onConfirm}>{confirmLabel}</AlertDialogAction>
|
|
42
|
-
</AlertDialogFooter>
|
|
43
|
-
</AlertDialogContent>
|
|
44
|
-
</AlertDialog>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
|
3
|
-
|
|
4
|
-
export type AdminColumn<T> = {
|
|
5
|
-
id: string;
|
|
6
|
-
header: ReactNode;
|
|
7
|
-
cell: (row: T) => ReactNode;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type AdminDataTableProps<T> = {
|
|
11
|
-
columns: readonly AdminColumn<T>[];
|
|
12
|
-
rows: readonly T[];
|
|
13
|
-
getRowId: (row: T) => string;
|
|
14
|
-
empty?: ReactNode;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function AdminDataTable<T>({
|
|
18
|
-
columns,
|
|
19
|
-
rows,
|
|
20
|
-
getRowId,
|
|
21
|
-
empty = 'No results',
|
|
22
|
-
}: AdminDataTableProps<T>) {
|
|
23
|
-
return (
|
|
24
|
-
<div className="w-full min-w-0 overflow-x-auto rounded-lg border">
|
|
25
|
-
<Table>
|
|
26
|
-
<TableHeader>
|
|
27
|
-
<TableRow>
|
|
28
|
-
{columns.map((column) => <TableHead key={column.id}>{column.header}</TableHead>)}
|
|
29
|
-
</TableRow>
|
|
30
|
-
</TableHeader>
|
|
31
|
-
<TableBody>
|
|
32
|
-
{rows.length === 0 ? (
|
|
33
|
-
<TableRow>
|
|
34
|
-
<TableCell colSpan={columns.length} className="h-24 text-center text-muted-foreground">
|
|
35
|
-
{empty}
|
|
36
|
-
</TableCell>
|
|
37
|
-
</TableRow>
|
|
38
|
-
) : (
|
|
39
|
-
rows.map((row) => (
|
|
40
|
-
<TableRow key={getRowId(row)}>
|
|
41
|
-
{columns.map((column) => <TableCell key={column.id}>{column.cell(row)}</TableCell>)}
|
|
42
|
-
</TableRow>
|
|
43
|
-
))
|
|
44
|
-
)}
|
|
45
|
-
</TableBody>
|
|
46
|
-
</Table>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
type AdminDetailLayoutProps = {
|
|
4
|
-
main: ReactNode;
|
|
5
|
-
aside?: ReactNode;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export function AdminDetailLayout({ main, aside }: AdminDetailLayoutProps) {
|
|
9
|
-
return (
|
|
10
|
-
<div className={aside ? 'grid min-w-0 gap-6 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]' : 'min-w-0'}>
|
|
11
|
-
<div className="min-w-0 space-y-6">{main}</div>
|
|
12
|
-
{aside ? <aside className="min-w-0 space-y-6">{aside}</aside> : null}
|
|
13
|
-
</div>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
type AdminEmptyStateProps = {
|
|
4
|
-
title: ReactNode;
|
|
5
|
-
description?: ReactNode;
|
|
6
|
-
action?: ReactNode;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export function AdminEmptyState({ title, description, action }: AdminEmptyStateProps) {
|
|
10
|
-
return (
|
|
11
|
-
<div className="flex min-h-40 flex-col items-center justify-center gap-3 rounded-lg border p-6 text-center">
|
|
12
|
-
<p className="font-medium">{title}</p>
|
|
13
|
-
{description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
|
|
14
|
-
{action}
|
|
15
|
-
</div>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
type AdminFilterBarProps = {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
actions?: ReactNode;
|
|
6
|
-
label?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export function AdminFilterBar({ children, actions, label = 'Filters' }: AdminFilterBarProps) {
|
|
10
|
-
return (
|
|
11
|
-
<section aria-label={label} className="flex flex-wrap items-end gap-3 rounded-lg border bg-card p-4">
|
|
12
|
-
<div className="flex min-w-0 flex-1 flex-wrap items-end gap-3">{children}</div>
|
|
13
|
-
{actions ? <div className="flex shrink-0 items-end gap-2">{actions}</div> : null}
|
|
14
|
-
</section>
|
|
15
|
-
);
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
type AdminFormLayoutProps = {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
aside?: ReactNode;
|
|
6
|
-
actions?: ReactNode;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export function AdminFormLayout({ children, aside, actions }: AdminFormLayoutProps) {
|
|
10
|
-
return (
|
|
11
|
-
<div className="space-y-6">
|
|
12
|
-
<div className={aside ? 'grid min-w-0 gap-6 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]' : 'min-w-0'}>
|
|
13
|
-
<div className="min-w-0 space-y-6">{children}</div>
|
|
14
|
-
{aside ? <aside className="min-w-0 space-y-6">{aside}</aside> : null}
|
|
15
|
-
</div>
|
|
16
|
-
{actions ? <div className="flex flex-wrap justify-end gap-2">{actions}</div> : null}
|
|
17
|
-
</div>
|
|
18
|
-
);
|
|
19
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
}
|