@checkstack/command-common 0.0.4 → 0.1.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 +74 -0
- package/package.json +1 -1
- package/src/index.ts +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
# @checkstack/command-common
|
|
2
2
|
|
|
3
|
+
## 0.1.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
|
+
|
|
3
77
|
## 0.0.4
|
|
4
78
|
|
|
5
79
|
### Patch Changes
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -33,8 +33,8 @@ export const SearchResultSchema = z.object({
|
|
|
33
33
|
route: z.string().optional(),
|
|
34
34
|
/** For commands: keyboard shortcuts */
|
|
35
35
|
shortcuts: z.array(z.string()).optional(),
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/** Access rule IDs required to see this result */
|
|
37
|
+
requiredAccessRules: z.array(z.string()).optional(),
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
export type SearchResult = z.infer<typeof SearchResultSchema>;
|
|
@@ -54,8 +54,8 @@ export const CommandSchema = z.object({
|
|
|
54
54
|
iconName: z.string().optional(),
|
|
55
55
|
/** Route to navigate to when the command is executed */
|
|
56
56
|
route: z.string(),
|
|
57
|
-
/**
|
|
58
|
-
|
|
57
|
+
/** Access rule IDs required to see/execute this command */
|
|
58
|
+
requiredAccessRules: z.array(z.string()).optional(),
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
export type Command = z.infer<typeof CommandSchema>;
|
|
@@ -73,7 +73,7 @@ const _base = oc.$meta<ProcedureMetadata>({});
|
|
|
73
73
|
export const commandContract = {
|
|
74
74
|
/**
|
|
75
75
|
* Search across all registered search providers.
|
|
76
|
-
* Returns results filtered by user
|
|
76
|
+
* Returns results filtered by user access rules.
|
|
77
77
|
*/
|
|
78
78
|
search: _base
|
|
79
79
|
.meta({ userType: "public" })
|
|
@@ -82,7 +82,7 @@ export const commandContract = {
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Get all registered commands (for browsing without a query).
|
|
85
|
-
* Returns commands filtered by user
|
|
85
|
+
* Returns commands filtered by user access rules.
|
|
86
86
|
*/
|
|
87
87
|
getCommands: _base
|
|
88
88
|
.meta({ userType: "public" })
|
|
@@ -101,32 +101,32 @@ export const CommandApi = createClientDefinition(
|
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
// =============================================================================
|
|
104
|
-
//
|
|
104
|
+
// ACCESS RULE UTILITIES (shared between frontend and backend)
|
|
105
105
|
// =============================================================================
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
* Filter items by user
|
|
109
|
-
* Items without
|
|
110
|
-
* Users with the wildcard "*"
|
|
108
|
+
* Filter items by user access rules.
|
|
109
|
+
* Items without requiredAccessRules are always included.
|
|
110
|
+
* Users with the wildcard "*" access rule can see all items.
|
|
111
111
|
*/
|
|
112
|
-
export function
|
|
113
|
-
T extends {
|
|
114
|
-
>(items: T[],
|
|
115
|
-
// Wildcard
|
|
116
|
-
const hasWildcard =
|
|
112
|
+
export function filterByAccessRules<
|
|
113
|
+
T extends { requiredAccessRules?: string[] }
|
|
114
|
+
>(items: T[], userAccessRules: string[]): T[] {
|
|
115
|
+
// Wildcard access rule means access to everything
|
|
116
|
+
const hasWildcard = userAccessRules.includes("*");
|
|
117
117
|
|
|
118
118
|
return items.filter((item) => {
|
|
119
|
-
// No
|
|
120
|
-
if (!item.
|
|
119
|
+
// No access rules required - always visible
|
|
120
|
+
if (!item.requiredAccessRules || item.requiredAccessRules.length === 0) {
|
|
121
121
|
return true;
|
|
122
122
|
}
|
|
123
123
|
// Wildcard user can see everything
|
|
124
124
|
if (hasWildcard) {
|
|
125
125
|
return true;
|
|
126
126
|
}
|
|
127
|
-
// Check if user has all required
|
|
128
|
-
return item.
|
|
129
|
-
|
|
127
|
+
// Check if user has all required access rules
|
|
128
|
+
return item.requiredAccessRules.every((rule) =>
|
|
129
|
+
userAccessRules.includes(rule)
|
|
130
130
|
);
|
|
131
131
|
});
|
|
132
132
|
}
|