@checkstack/maintenance-common 0.1.0 → 0.3.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 +137 -0
- package/package.json +1 -1
- package/src/access.ts +48 -0
- package/src/index.ts +1 -1
- package/src/rpc-contract.ts +60 -56
- package/src/permissions.ts +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,142 @@
|
|
|
1
1
|
# @checkstack/maintenance-common
|
|
2
2
|
|
|
3
|
+
## 0.3.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/frontend-api@0.2.0
|
|
61
|
+
- @checkstack/common@0.3.0
|
|
62
|
+
- @checkstack/signal-common@0.1.1
|
|
63
|
+
|
|
64
|
+
## 0.2.0
|
|
65
|
+
|
|
66
|
+
### Minor Changes
|
|
67
|
+
|
|
68
|
+
- 9faec1f: # Unified AccessRule Terminology Refactoring
|
|
69
|
+
|
|
70
|
+
This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
|
|
71
|
+
|
|
72
|
+
## Changes
|
|
73
|
+
|
|
74
|
+
### Core Infrastructure (`@checkstack/common`)
|
|
75
|
+
|
|
76
|
+
- Introduced `AccessRule` interface as the primary access control type
|
|
77
|
+
- Added `accessPair()` helper for creating read/manage access rule pairs
|
|
78
|
+
- Added `access()` builder for individual access rules
|
|
79
|
+
- Replaced `Permission` type with `AccessRule` throughout
|
|
80
|
+
|
|
81
|
+
### API Changes
|
|
82
|
+
|
|
83
|
+
- `env.registerPermissions()` → `env.registerAccessRules()`
|
|
84
|
+
- `meta.permissions` → `meta.access` in RPC contracts
|
|
85
|
+
- `usePermission()` → `useAccess()` in frontend hooks
|
|
86
|
+
- Route `permission:` field → `accessRule:` field
|
|
87
|
+
|
|
88
|
+
### UI Changes
|
|
89
|
+
|
|
90
|
+
- "Roles & Permissions" tab → "Roles & Access Rules"
|
|
91
|
+
- "You don't have permission..." → "You don't have access..."
|
|
92
|
+
- All permission-related UI text updated
|
|
93
|
+
|
|
94
|
+
### Documentation & Templates
|
|
95
|
+
|
|
96
|
+
- Updated 18 documentation files with AccessRule terminology
|
|
97
|
+
- Updated 7 scaffolding templates with `accessPair()` pattern
|
|
98
|
+
- All code examples use new AccessRule API
|
|
99
|
+
|
|
100
|
+
## Migration Guide
|
|
101
|
+
|
|
102
|
+
### Backend Plugins
|
|
103
|
+
|
|
104
|
+
```diff
|
|
105
|
+
- import { permissionList } from "./permissions";
|
|
106
|
+
- env.registerPermissions(permissionList);
|
|
107
|
+
+ import { accessRules } from "./access";
|
|
108
|
+
+ env.registerAccessRules(accessRules);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### RPC Contracts
|
|
112
|
+
|
|
113
|
+
```diff
|
|
114
|
+
- .meta({ userType: "user", permissions: [permissions.read.id] })
|
|
115
|
+
+ .meta({ userType: "user", access: [access.read] })
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Frontend Hooks
|
|
119
|
+
|
|
120
|
+
```diff
|
|
121
|
+
- const canRead = accessApi.usePermission(permissions.read.id);
|
|
122
|
+
+ const canRead = accessApi.useAccess(access.read);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Routes
|
|
126
|
+
|
|
127
|
+
```diff
|
|
128
|
+
- permission: permissions.entityRead.id,
|
|
129
|
+
+ accessRule: access.read,
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [9faec1f]
|
|
135
|
+
- Updated dependencies [f533141]
|
|
136
|
+
- @checkstack/common@0.2.0
|
|
137
|
+
- @checkstack/frontend-api@0.1.0
|
|
138
|
+
- @checkstack/signal-common@0.1.0
|
|
139
|
+
|
|
3
140
|
## 0.1.0
|
|
4
141
|
|
|
5
142
|
### Minor Changes
|
package/package.json
CHANGED
package/src/access.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { access, accessPair } from "@checkstack/common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Access rules for the Maintenance plugin.
|
|
5
|
+
*/
|
|
6
|
+
export const maintenanceAccess = {
|
|
7
|
+
/**
|
|
8
|
+
* Maintenance access with both read and manage levels.
|
|
9
|
+
* Read is public by default.
|
|
10
|
+
* Uses system-level instance access for team-based filtering.
|
|
11
|
+
*/
|
|
12
|
+
maintenance: accessPair(
|
|
13
|
+
"maintenance",
|
|
14
|
+
{
|
|
15
|
+
read: "View planned maintenances",
|
|
16
|
+
manage:
|
|
17
|
+
"Manage planned maintenances - create, edit, delete, and add updates",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
idParam: "systemId",
|
|
21
|
+
readIsDefault: true,
|
|
22
|
+
readIsPublic: true,
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Bulk maintenance access for viewing maintenances for multiple systems.
|
|
28
|
+
* Uses recordKey for filtering the output record by accessible system IDs.
|
|
29
|
+
*/
|
|
30
|
+
bulkMaintenance: access(
|
|
31
|
+
"maintenance.maintenance",
|
|
32
|
+
"read",
|
|
33
|
+
"View planned maintenances",
|
|
34
|
+
{
|
|
35
|
+
recordKey: "maintenances",
|
|
36
|
+
isDefault: true,
|
|
37
|
+
isPublic: true,
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* All access rules for registration with the plugin system.
|
|
44
|
+
*/
|
|
45
|
+
export const maintenanceAccessRules = [
|
|
46
|
+
maintenanceAccess.maintenance.read,
|
|
47
|
+
maintenanceAccess.maintenance.manage,
|
|
48
|
+
];
|
package/src/index.ts
CHANGED
package/src/rpc-contract.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { oc } from "@orpc/contract";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
createResourceAccessList,
|
|
6
|
-
type ProcedureMetadata,
|
|
7
|
-
} from "@checkstack/common";
|
|
8
|
-
import { permissions } from "./permissions";
|
|
2
|
+
import { createClientDefinition, proc } from "@checkstack/common";
|
|
3
|
+
import { maintenanceAccess } from "./access";
|
|
9
4
|
import { pluginMetadata } from "./plugin-metadata";
|
|
10
5
|
import {
|
|
11
6
|
MaintenanceWithSystemsSchema,
|
|
@@ -17,22 +12,13 @@ import {
|
|
|
17
12
|
MaintenanceStatusEnum,
|
|
18
13
|
} from "./schemas";
|
|
19
14
|
|
|
20
|
-
const _base = oc.$meta<ProcedureMetadata>({});
|
|
21
|
-
|
|
22
|
-
// Resource access configurations for team-based access control
|
|
23
|
-
const maintenanceListAccess = createResourceAccessList(
|
|
24
|
-
"maintenance",
|
|
25
|
-
"maintenances"
|
|
26
|
-
);
|
|
27
|
-
|
|
28
15
|
export const maintenanceContract = {
|
|
29
16
|
/** List all maintenances with optional status filter */
|
|
30
|
-
listMaintenances:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
17
|
+
listMaintenances: proc({
|
|
18
|
+
operationType: "query",
|
|
19
|
+
userType: "public",
|
|
20
|
+
access: [maintenanceAccess.maintenance.read],
|
|
21
|
+
})
|
|
36
22
|
.input(
|
|
37
23
|
z
|
|
38
24
|
.object({
|
|
@@ -44,65 +30,83 @@ export const maintenanceContract = {
|
|
|
44
30
|
.output(z.object({ maintenances: z.array(MaintenanceWithSystemsSchema) })),
|
|
45
31
|
|
|
46
32
|
/** Get a single maintenance with all details */
|
|
47
|
-
getMaintenance:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
getMaintenance: proc({
|
|
34
|
+
operationType: "query",
|
|
35
|
+
userType: "public",
|
|
36
|
+
access: [maintenanceAccess.maintenance.read],
|
|
37
|
+
})
|
|
52
38
|
.input(z.object({ id: z.string() }))
|
|
53
39
|
.output(MaintenanceDetailSchema.nullable()),
|
|
54
40
|
|
|
55
41
|
/** Get active or upcoming maintenances for a specific system */
|
|
56
|
-
getMaintenancesForSystem:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
getMaintenancesForSystem: proc({
|
|
43
|
+
operationType: "query",
|
|
44
|
+
userType: "public",
|
|
45
|
+
access: [maintenanceAccess.maintenance.read],
|
|
46
|
+
})
|
|
61
47
|
.input(z.object({ systemId: z.string() }))
|
|
62
48
|
.output(z.array(MaintenanceWithSystemsSchema)),
|
|
63
49
|
|
|
50
|
+
/** Get active maintenances for multiple systems in a single request.
|
|
51
|
+
* Used for efficient dashboard rendering to avoid N+1 queries.
|
|
52
|
+
*/
|
|
53
|
+
getBulkMaintenancesForSystems: proc({
|
|
54
|
+
operationType: "query",
|
|
55
|
+
userType: "public",
|
|
56
|
+
access: [maintenanceAccess.bulkMaintenance],
|
|
57
|
+
})
|
|
58
|
+
.input(z.object({ systemIds: z.array(z.string()) }))
|
|
59
|
+
.output(
|
|
60
|
+
z.object({
|
|
61
|
+
maintenances: z.record(
|
|
62
|
+
z.string(),
|
|
63
|
+
z.array(MaintenanceWithSystemsSchema)
|
|
64
|
+
),
|
|
65
|
+
})
|
|
66
|
+
),
|
|
67
|
+
|
|
64
68
|
/** Create a new maintenance */
|
|
65
|
-
createMaintenance:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
createMaintenance: proc({
|
|
70
|
+
operationType: "mutation",
|
|
71
|
+
userType: "authenticated",
|
|
72
|
+
access: [maintenanceAccess.maintenance.manage],
|
|
73
|
+
})
|
|
70
74
|
.input(CreateMaintenanceInputSchema)
|
|
71
75
|
.output(MaintenanceWithSystemsSchema),
|
|
72
76
|
|
|
73
77
|
/** Update an existing maintenance */
|
|
74
|
-
updateMaintenance:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
updateMaintenance: proc({
|
|
79
|
+
operationType: "mutation",
|
|
80
|
+
userType: "authenticated",
|
|
81
|
+
access: [maintenanceAccess.maintenance.manage],
|
|
82
|
+
})
|
|
79
83
|
.input(UpdateMaintenanceInputSchema)
|
|
80
84
|
.output(MaintenanceWithSystemsSchema),
|
|
81
85
|
|
|
82
86
|
/** Add a status update to a maintenance */
|
|
83
|
-
addUpdate:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
addUpdate: proc({
|
|
88
|
+
operationType: "mutation",
|
|
89
|
+
userType: "authenticated",
|
|
90
|
+
access: [maintenanceAccess.maintenance.manage],
|
|
91
|
+
})
|
|
88
92
|
.input(AddMaintenanceUpdateInputSchema)
|
|
89
93
|
.output(MaintenanceUpdateSchema),
|
|
90
94
|
|
|
91
95
|
/** Close a maintenance early (sets status to completed) */
|
|
92
|
-
closeMaintenance:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
closeMaintenance: proc({
|
|
97
|
+
operationType: "mutation",
|
|
98
|
+
userType: "authenticated",
|
|
99
|
+
access: [maintenanceAccess.maintenance.manage],
|
|
100
|
+
})
|
|
97
101
|
.input(z.object({ id: z.string(), message: z.string().optional() }))
|
|
98
102
|
.output(MaintenanceWithSystemsSchema),
|
|
99
103
|
|
|
100
104
|
/** Delete a maintenance */
|
|
101
|
-
deleteMaintenance:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
deleteMaintenance: proc({
|
|
106
|
+
operationType: "mutation",
|
|
107
|
+
userType: "authenticated",
|
|
108
|
+
access: [maintenanceAccess.maintenance.manage],
|
|
109
|
+
})
|
|
106
110
|
.input(z.object({ id: z.string() }))
|
|
107
111
|
.output(z.object({ success: z.boolean() })),
|
|
108
112
|
};
|
package/src/permissions.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createPermission, type Permission } from "@checkstack/common";
|
|
2
|
-
|
|
3
|
-
export const permissions = {
|
|
4
|
-
/** Read access to maintenances - granted to all authenticated users by default */
|
|
5
|
-
maintenanceRead: createPermission(
|
|
6
|
-
"maintenance",
|
|
7
|
-
"read",
|
|
8
|
-
"View planned maintenances",
|
|
9
|
-
{ isAuthenticatedDefault: true, isPublicDefault: true }
|
|
10
|
-
),
|
|
11
|
-
/** Manage maintenances - create, edit, delete, and add updates */
|
|
12
|
-
maintenanceManage: createPermission(
|
|
13
|
-
"maintenance",
|
|
14
|
-
"manage",
|
|
15
|
-
"Manage planned maintenances"
|
|
16
|
-
),
|
|
17
|
-
} as const satisfies Record<string, Permission>;
|
|
18
|
-
|
|
19
|
-
export const permissionList = Object.values(permissions);
|