@checkstack/ui 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,80 @@
1
1
  # @checkstack/ui
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9faec1f: # Unified AccessRule Terminology Refactoring
8
+
9
+ This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
10
+
11
+ ## Changes
12
+
13
+ ### Core Infrastructure (`@checkstack/common`)
14
+
15
+ - Introduced `AccessRule` interface as the primary access control type
16
+ - Added `accessPair()` helper for creating read/manage access rule pairs
17
+ - Added `access()` builder for individual access rules
18
+ - Replaced `Permission` type with `AccessRule` throughout
19
+
20
+ ### API Changes
21
+
22
+ - `env.registerPermissions()` → `env.registerAccessRules()`
23
+ - `meta.permissions` → `meta.access` in RPC contracts
24
+ - `usePermission()` → `useAccess()` in frontend hooks
25
+ - Route `permission:` field → `accessRule:` field
26
+
27
+ ### UI Changes
28
+
29
+ - "Roles & Permissions" tab → "Roles & Access Rules"
30
+ - "You don't have permission..." → "You don't have access..."
31
+ - All permission-related UI text updated
32
+
33
+ ### Documentation & Templates
34
+
35
+ - Updated 18 documentation files with AccessRule terminology
36
+ - Updated 7 scaffolding templates with `accessPair()` pattern
37
+ - All code examples use new AccessRule API
38
+
39
+ ## Migration Guide
40
+
41
+ ### Backend Plugins
42
+
43
+ ```diff
44
+ - import { permissionList } from "./permissions";
45
+ - env.registerPermissions(permissionList);
46
+ + import { accessRules } from "./access";
47
+ + env.registerAccessRules(accessRules);
48
+ ```
49
+
50
+ ### RPC Contracts
51
+
52
+ ```diff
53
+ - .meta({ userType: "user", permissions: [permissions.read.id] })
54
+ + .meta({ userType: "user", access: [access.read] })
55
+ ```
56
+
57
+ ### Frontend Hooks
58
+
59
+ ```diff
60
+ - const canRead = accessApi.usePermission(permissions.read.id);
61
+ + const canRead = accessApi.useAccess(access.read);
62
+ ```
63
+
64
+ ### Routes
65
+
66
+ ```diff
67
+ - permission: permissions.entityRead.id,
68
+ + accessRule: access.read,
69
+ ```
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [9faec1f]
74
+ - Updated dependencies [f533141]
75
+ - @checkstack/common@0.2.0
76
+ - @checkstack/frontend-api@0.1.0
77
+
3
78
  ## 0.1.0
4
79
 
5
80
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "dependencies": {
@@ -3,13 +3,10 @@ import { ShieldAlert } from "lucide-react";
3
3
  import { Card, CardHeader, CardTitle, CardContent } from "./Card";
4
4
  import { cn } from "../utils";
5
5
 
6
- export const PermissionDenied: React.FC<{
6
+ export const AccessDenied: React.FC<{
7
7
  message?: string;
8
8
  className?: string;
9
- }> = ({
10
- message = "You do not have permission to view this page.",
11
- className,
12
- }) => {
9
+ }> = ({ message = "You do not have access to this page.", className }) => {
13
10
  return (
14
11
  <div
15
12
  className={cn(
@@ -0,0 +1,97 @@
1
+ import React from "react";
2
+ import { AccessDenied } from "./AccessDenied";
3
+ import { LoadingSpinner } from "./LoadingSpinner";
4
+
5
+ /**
6
+ * Props for the AccessGate component.
7
+ */
8
+ export interface AccessGateProps {
9
+ /**
10
+ * The access rule ID to check for access.
11
+ */
12
+ accessRuleId: string;
13
+ /**
14
+ * Content to render when access is granted.
15
+ */
16
+ children: React.ReactNode;
17
+ /**
18
+ * Custom fallback to render when access is denied.
19
+ * If not provided and showDenied is false, renders nothing.
20
+ */
21
+ fallback?: React.ReactNode;
22
+ /**
23
+ * If true, shows a AccessDenied component when access is denied.
24
+ * Useful for entire page sections. Overridden by fallback if provided.
25
+ */
26
+ showDenied?: boolean;
27
+ /**
28
+ * Custom message to show in the AccessDenied component.
29
+ */
30
+ deniedMessage?: string;
31
+ /**
32
+ * Hook to check access. Must be provided by the consumer.
33
+ * This allows the component to be used without depending on auth-frontend directly.
34
+ */
35
+ useAccess: (accessRuleId: string) => { loading: boolean; allowed: boolean };
36
+ }
37
+
38
+ /**
39
+ * Conditionally renders children based on whether the user has a required access rule.
40
+ *
41
+ * @example
42
+ * // Hide content if access denied
43
+ * <AccessGate accessRuleId="catalog.manage" useAccess={accessApi.useAccess}>
44
+ * <ManageButton />
45
+ * </AccessGate>
46
+ *
47
+ * @example
48
+ * // Show access denied message
49
+ * <AccessGate
50
+ * accessRuleId="catalog.read"
51
+ * useAccess={accessApi.useAccess}
52
+ * showDenied
53
+ * deniedMessage="You don't have access to view the catalog."
54
+ * >
55
+ * <CatalogList />
56
+ * </AccessGate>
57
+ *
58
+ * @example
59
+ * // Custom fallback
60
+ * <AccessGate
61
+ * accessRuleId="admin.manage"
62
+ * useAccess={accessApi.useAccess}
63
+ * fallback={<p>Admin access required</p>}
64
+ * >
65
+ * <AdminPanel />
66
+ * </AccessGate>
67
+ */
68
+ export const AccessGate: React.FC<AccessGateProps> = ({
69
+ accessRuleId,
70
+ children,
71
+ fallback,
72
+ showDenied = false,
73
+ deniedMessage,
74
+ useAccess,
75
+ }) => {
76
+ const { loading, allowed } = useAccess(accessRuleId);
77
+
78
+ if (loading) {
79
+ return <LoadingSpinner size="sm" />;
80
+ }
81
+
82
+ if (!allowed) {
83
+ if (fallback) {
84
+ return <>{fallback}</>;
85
+ }
86
+ if (showDenied) {
87
+ return (
88
+ <AccessDenied
89
+ message={deniedMessage ?? `You don't have access: ${accessRuleId}`}
90
+ />
91
+ );
92
+ }
93
+ return <></>;
94
+ }
95
+
96
+ return <>{children}</>;
97
+ };
@@ -2,13 +2,15 @@ import React, { useState, useRef, useEffect } from "react";
2
2
  import { NavLink } from "react-router-dom";
3
3
  import { ChevronDown } from "lucide-react";
4
4
  import { cn } from "../utils";
5
- import { useApi, permissionApiRef } from "@checkstack/frontend-api";
5
+ import { useApi, accessApiRef } from "@checkstack/frontend-api";
6
+ import type { AccessRule } from "@checkstack/common";
6
7
 
7
8
  export interface NavItemProps {
8
9
  to?: string;
9
10
  label: string;
10
11
  icon?: React.ReactNode;
11
- permission?: string;
12
+ /** Access rule to check - if not provided, always shows */
13
+ accessRule?: AccessRule;
12
14
  children?: React.ReactNode;
13
15
  className?: string;
14
16
  }
@@ -17,7 +19,7 @@ export const NavItem: React.FC<NavItemProps> = ({
17
19
  to,
18
20
  label,
19
21
  icon,
20
- permission,
22
+ accessRule,
21
23
  children,
22
24
  className,
23
25
  }) => {
@@ -25,11 +27,17 @@ export const NavItem: React.FC<NavItemProps> = ({
25
27
  const containerRef = useRef<HTMLDivElement>(null);
26
28
 
27
29
  // Always call hooks at top level
28
- // We assume permissionApi is available if we use it. Safe fallback?
29
- // ApiProvider guarantees it if registered. App.tsx registers a default.
30
- const permissionApi = useApi(permissionApiRef);
31
- const { allowed, loading } = permissionApi.usePermission(permission || "");
32
- const hasAccess = permission ? allowed : true;
30
+ const accessApi = useApi(accessApiRef);
31
+
32
+ // Create a dummy access rule for when accessRule is undefined
33
+ const dummyRule: AccessRule = {
34
+ id: "",
35
+ resource: "",
36
+ level: "read",
37
+ description: "",
38
+ };
39
+ const { allowed, loading } = accessApi.useAccess(accessRule ?? dummyRule);
40
+ const hasAccess = accessRule ? allowed : true;
33
41
 
34
42
  // Handle click outside for dropdown
35
43
  useEffect(() => {
@@ -4,7 +4,7 @@ import {
4
4
  PageHeader,
5
5
  PageContent,
6
6
  LoadingSpinner,
7
- PermissionDenied,
7
+ AccessDenied,
8
8
  } from "..";
9
9
 
10
10
  interface PageLayoutProps {
@@ -39,7 +39,7 @@ export const PageLayout: React.FC<PageLayoutProps> = ({
39
39
  }) => {
40
40
  // If loading is explicitly true, show loading state
41
41
  // If loading is undefined and allowed is false, also show loading state
42
- // (this prevents "Access Denied" flash when permissions are still being fetched)
42
+ // (this prevents "Access Denied" flash when access rules are still being fetched)
43
43
  const isLoading =
44
44
  loading === true || (loading === undefined && allowed === false);
45
45
 
@@ -56,13 +56,13 @@ export const PageLayout: React.FC<PageLayoutProps> = ({
56
56
  );
57
57
  }
58
58
 
59
- // Only show permission denied when loading is explicitly false and allowed is false
59
+ // Only show access denied when loading is explicitly false and allowed is false
60
60
  if (allowed === false) {
61
61
  return (
62
62
  <Page>
63
63
  <PageHeader title={title} subtitle={subtitle} actions={actions} />
64
64
  <PageContent>
65
- <PermissionDenied />
65
+ <AccessDenied />
66
66
  </PageContent>
67
67
  </Page>
68
68
  );
package/src/index.ts CHANGED
@@ -3,8 +3,8 @@ export * from "./components/Input";
3
3
  export * from "./components/Card";
4
4
  export * from "./components/Label";
5
5
  export * from "./components/NavItem";
6
- export * from "./components/PermissionDenied";
7
- export * from "./components/PermissionGate";
6
+ export * from "./components/AccessDenied";
7
+ export * from "./components/AccessGate";
8
8
  export * from "./components/SectionHeader";
9
9
  export * from "./components/StatusCard";
10
10
  export * from "./components/EmptyState";
@@ -1,97 +0,0 @@
1
- import React from "react";
2
- import { PermissionDenied } from "./PermissionDenied";
3
- import { LoadingSpinner } from "./LoadingSpinner";
4
-
5
- /**
6
- * Props for the PermissionGate component.
7
- */
8
- export interface PermissionGateProps {
9
- /**
10
- * The permission ID to check for access.
11
- */
12
- permission: string;
13
- /**
14
- * Content to render when permission is granted.
15
- */
16
- children: React.ReactNode;
17
- /**
18
- * Custom fallback to render when permission is denied.
19
- * If not provided and showDenied is false, renders nothing.
20
- */
21
- fallback?: React.ReactNode;
22
- /**
23
- * If true, shows a PermissionDenied component when access is denied.
24
- * Useful for entire page sections. Overridden by fallback if provided.
25
- */
26
- showDenied?: boolean;
27
- /**
28
- * Custom message to show in the PermissionDenied component.
29
- */
30
- deniedMessage?: string;
31
- /**
32
- * Hook to check permissions. Must be provided by the consumer.
33
- * This allows the component to be used without depending on auth-frontend directly.
34
- */
35
- usePermission: (permission: string) => { loading: boolean; allowed: boolean };
36
- }
37
-
38
- /**
39
- * Conditionally renders children based on whether the user has a required permission.
40
- *
41
- * @example
42
- * // Hide content if permission denied
43
- * <PermissionGate permission="catalog.manage" usePermission={permissionApi.usePermission}>
44
- * <ManageButton />
45
- * </PermissionGate>
46
- *
47
- * @example
48
- * // Show permission denied message
49
- * <PermissionGate
50
- * permission="catalog.read"
51
- * usePermission={permissionApi.usePermission}
52
- * showDenied
53
- * deniedMessage="You don't have access to view the catalog."
54
- * >
55
- * <CatalogList />
56
- * </PermissionGate>
57
- *
58
- * @example
59
- * // Custom fallback
60
- * <PermissionGate
61
- * permission="admin.manage"
62
- * usePermission={permissionApi.usePermission}
63
- * fallback={<p>Admin access required</p>}
64
- * >
65
- * <AdminPanel />
66
- * </PermissionGate>
67
- */
68
- export const PermissionGate: React.FC<PermissionGateProps> = ({
69
- permission,
70
- children,
71
- fallback,
72
- showDenied = false,
73
- deniedMessage,
74
- usePermission,
75
- }) => {
76
- const { loading, allowed } = usePermission(permission);
77
-
78
- if (loading) {
79
- return <LoadingSpinner size="sm" />;
80
- }
81
-
82
- if (!allowed) {
83
- if (fallback) {
84
- return <>{fallback}</>;
85
- }
86
- if (showDenied) {
87
- return (
88
- <PermissionDenied
89
- message={deniedMessage ?? `You don't have permission: ${permission}`}
90
- />
91
- );
92
- }
93
- return <></>;
94
- }
95
-
96
- return <>{children}</>;
97
- };