@checkstack/command-common 0.0.4 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/package.json +1 -1
  3. package/src/index.ts +31 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,138 @@
1
1
  # @checkstack/command-common
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7a23261: ## TanStack Query Integration
8
+
9
+ Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
10
+
11
+ ### New Features
12
+
13
+ - **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
14
+ - **Automatic request deduplication**: Multiple components requesting the same data share a single network request
15
+ - **Built-in caching**: Configurable stale time and cache duration per query
16
+ - **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
17
+ - **Background refetching**: Stale data is automatically refreshed when components mount
18
+
19
+ ### Contract Changes
20
+
21
+ All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
22
+
23
+ ```typescript
24
+ const getItems = proc()
25
+ .meta({ operationType: "query", access: [access.read] })
26
+ .output(z.array(itemSchema))
27
+ .query();
28
+
29
+ const createItem = proc()
30
+ .meta({ operationType: "mutation", access: [access.manage] })
31
+ .input(createItemSchema)
32
+ .output(itemSchema)
33
+ .mutation();
34
+ ```
35
+
36
+ ### Migration
37
+
38
+ ```typescript
39
+ // Before (forPlugin pattern)
40
+ const api = useApi(myPluginApiRef);
41
+ const [items, setItems] = useState<Item[]>([]);
42
+ useEffect(() => {
43
+ api.getItems().then(setItems);
44
+ }, [api]);
45
+
46
+ // After (usePluginClient pattern)
47
+ const client = usePluginClient(MyPluginApi);
48
+ const { data: items, isLoading } = client.getItems.useQuery({});
49
+ ```
50
+
51
+ ### Bug Fixes
52
+
53
+ - Fixed `rpc.test.ts` test setup for middleware type inference
54
+ - Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
55
+ - Fixed null→undefined warnings in notification and queue frontends
56
+
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies [7a23261]
60
+ - @checkstack/common@0.3.0
61
+
62
+ ## 0.1.0
63
+
64
+ ### Minor Changes
65
+
66
+ - 9faec1f: # Unified AccessRule Terminology Refactoring
67
+
68
+ This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
69
+
70
+ ## Changes
71
+
72
+ ### Core Infrastructure (`@checkstack/common`)
73
+
74
+ - Introduced `AccessRule` interface as the primary access control type
75
+ - Added `accessPair()` helper for creating read/manage access rule pairs
76
+ - Added `access()` builder for individual access rules
77
+ - Replaced `Permission` type with `AccessRule` throughout
78
+
79
+ ### API Changes
80
+
81
+ - `env.registerPermissions()` → `env.registerAccessRules()`
82
+ - `meta.permissions` → `meta.access` in RPC contracts
83
+ - `usePermission()` → `useAccess()` in frontend hooks
84
+ - Route `permission:` field → `accessRule:` field
85
+
86
+ ### UI Changes
87
+
88
+ - "Roles & Permissions" tab → "Roles & Access Rules"
89
+ - "You don't have permission..." → "You don't have access..."
90
+ - All permission-related UI text updated
91
+
92
+ ### Documentation & Templates
93
+
94
+ - Updated 18 documentation files with AccessRule terminology
95
+ - Updated 7 scaffolding templates with `accessPair()` pattern
96
+ - All code examples use new AccessRule API
97
+
98
+ ## Migration Guide
99
+
100
+ ### Backend Plugins
101
+
102
+ ```diff
103
+ - import { permissionList } from "./permissions";
104
+ - env.registerPermissions(permissionList);
105
+ + import { accessRules } from "./access";
106
+ + env.registerAccessRules(accessRules);
107
+ ```
108
+
109
+ ### RPC Contracts
110
+
111
+ ```diff
112
+ - .meta({ userType: "user", permissions: [permissions.read.id] })
113
+ + .meta({ userType: "user", access: [access.read] })
114
+ ```
115
+
116
+ ### Frontend Hooks
117
+
118
+ ```diff
119
+ - const canRead = accessApi.usePermission(permissions.read.id);
120
+ + const canRead = accessApi.useAccess(access.read);
121
+ ```
122
+
123
+ ### Routes
124
+
125
+ ```diff
126
+ - permission: permissions.entityRead.id,
127
+ + accessRule: access.read,
128
+ ```
129
+
130
+ ### Patch Changes
131
+
132
+ - Updated dependencies [9faec1f]
133
+ - Updated dependencies [f533141]
134
+ - @checkstack/common@0.2.0
135
+
3
136
  ## 0.0.4
4
137
 
5
138
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/command-common",
3
- "version": "0.0.4",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { oc } from "@orpc/contract";
2
1
  import { z } from "zod";
3
2
  import {
4
3
  createClientDefinition,
5
4
  definePluginMetadata,
6
- type ProcedureMetadata,
5
+ proc,
7
6
  } from "@checkstack/common";
8
7
 
9
8
  // =============================================================================
@@ -33,8 +32,8 @@ export const SearchResultSchema = z.object({
33
32
  route: z.string().optional(),
34
33
  /** For commands: keyboard shortcuts */
35
34
  shortcuts: z.array(z.string()).optional(),
36
- /** Permission IDs required to see this result */
37
- requiredPermissions: z.array(z.string()).optional(),
35
+ /** Access rule IDs required to see this result */
36
+ requiredAccessRules: z.array(z.string()).optional(),
38
37
  });
39
38
 
40
39
  export type SearchResult = z.infer<typeof SearchResultSchema>;
@@ -54,8 +53,8 @@ export const CommandSchema = z.object({
54
53
  iconName: z.string().optional(),
55
54
  /** Route to navigate to when the command is executed */
56
55
  route: z.string(),
57
- /** Permission IDs required to see/execute this command */
58
- requiredPermissions: z.array(z.string()).optional(),
56
+ /** Access rule IDs required to see/execute this command */
57
+ requiredAccessRules: z.array(z.string()).optional(),
59
58
  });
60
59
 
61
60
  export type Command = z.infer<typeof CommandSchema>;
@@ -64,8 +63,6 @@ export type Command = z.infer<typeof CommandSchema>;
64
63
  // RPC CONTRACT
65
64
  // =============================================================================
66
65
 
67
- const _base = oc.$meta<ProcedureMetadata>({});
68
-
69
66
  /**
70
67
  * Command palette RPC contract.
71
68
  * Provides search functionality across all registered providers.
@@ -73,20 +70,25 @@ const _base = oc.$meta<ProcedureMetadata>({});
73
70
  export const commandContract = {
74
71
  /**
75
72
  * Search across all registered search providers.
76
- * Returns results filtered by user permissions.
73
+ * Returns results filtered by user access rules.
77
74
  */
78
- search: _base
79
- .meta({ userType: "public" })
75
+ search: proc({
76
+ operationType: "query",
77
+ userType: "public",
78
+ access: [],
79
+ })
80
80
  .input(z.object({ query: z.string() }))
81
81
  .output(z.array(SearchResultSchema)),
82
82
 
83
83
  /**
84
84
  * Get all registered commands (for browsing without a query).
85
- * Returns commands filtered by user permissions.
85
+ * Returns commands filtered by user access rules.
86
86
  */
87
- getCommands: _base
88
- .meta({ userType: "public" })
89
- .output(z.array(SearchResultSchema)),
87
+ getCommands: proc({
88
+ operationType: "query",
89
+ userType: "public",
90
+ access: [],
91
+ }).output(z.array(SearchResultSchema)),
90
92
  };
91
93
 
92
94
  export type CommandContract = typeof commandContract;
@@ -101,32 +103,32 @@ export const CommandApi = createClientDefinition(
101
103
  );
102
104
 
103
105
  // =============================================================================
104
- // PERMISSION UTILITIES (shared between frontend and backend)
106
+ // ACCESS RULE UTILITIES (shared between frontend and backend)
105
107
  // =============================================================================
106
108
 
107
109
  /**
108
- * Filter items by user permissions.
109
- * Items without requiredPermissions are always included.
110
- * Users with the wildcard "*" permission can see all items.
110
+ * Filter items by user access rules.
111
+ * Items without requiredAccessRules are always included.
112
+ * Users with the wildcard "*" access rule can see all items.
111
113
  */
112
- export function filterByPermissions<
113
- T extends { requiredPermissions?: string[] }
114
- >(items: T[], userPermissions: string[]): T[] {
115
- // Wildcard permission means access to everything
116
- const hasWildcard = userPermissions.includes("*");
114
+ export function filterByAccessRules<
115
+ T extends { requiredAccessRules?: string[] }
116
+ >(items: T[], userAccessRules: string[]): T[] {
117
+ // Wildcard access rule means access to everything
118
+ const hasWildcard = userAccessRules.includes("*");
117
119
 
118
120
  return items.filter((item) => {
119
- // No permissions required - always visible
120
- if (!item.requiredPermissions || item.requiredPermissions.length === 0) {
121
+ // No access rules required - always visible
122
+ if (!item.requiredAccessRules || item.requiredAccessRules.length === 0) {
121
123
  return true;
122
124
  }
123
125
  // Wildcard user can see everything
124
126
  if (hasWildcard) {
125
127
  return true;
126
128
  }
127
- // Check if user has all required permissions
128
- return item.requiredPermissions.every((perm) =>
129
- userPermissions.includes(perm)
129
+ // Check if user has all required access rules
130
+ return item.requiredAccessRules.every((rule) =>
131
+ userAccessRules.includes(rule)
130
132
  );
131
133
  });
132
134
  }