@checkstack/incident-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 +42 -0
- package/src/index.ts +1 -1
- package/src/rpc-contract.ts +57 -53
- package/src/permissions.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,142 @@
|
|
|
1
1
|
# @checkstack/incident-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,42 @@
|
|
|
1
|
+
import { access, accessPair } from "@checkstack/common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Access rules for the Incident plugin.
|
|
5
|
+
*/
|
|
6
|
+
export const incidentAccess = {
|
|
7
|
+
/**
|
|
8
|
+
* Incident 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
|
+
incident: accessPair(
|
|
13
|
+
"incident",
|
|
14
|
+
{
|
|
15
|
+
read: "View incidents",
|
|
16
|
+
manage: "Manage incidents - create, edit, resolve, and delete",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
idParam: "systemId",
|
|
20
|
+
readIsDefault: true,
|
|
21
|
+
readIsPublic: true,
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Bulk incident access for viewing incidents for multiple systems.
|
|
27
|
+
* Uses recordKey for filtering the output record by accessible system IDs.
|
|
28
|
+
*/
|
|
29
|
+
bulkIncident: access("incident.incident", "read", "View incidents", {
|
|
30
|
+
recordKey: "incidents",
|
|
31
|
+
isDefault: true,
|
|
32
|
+
isPublic: true,
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* All access rules for registration with the plugin system.
|
|
38
|
+
*/
|
|
39
|
+
export const incidentAccessRules = [
|
|
40
|
+
incidentAccess.incident.read,
|
|
41
|
+
incidentAccess.incident.manage,
|
|
42
|
+
];
|
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 { incidentAccess } from "./access";
|
|
9
4
|
import { pluginMetadata } from "./plugin-metadata";
|
|
10
5
|
import {
|
|
11
6
|
IncidentWithSystemsSchema,
|
|
@@ -17,19 +12,13 @@ import {
|
|
|
17
12
|
IncidentStatusEnum,
|
|
18
13
|
} from "./schemas";
|
|
19
14
|
|
|
20
|
-
const _base = oc.$meta<ProcedureMetadata>({});
|
|
21
|
-
|
|
22
|
-
// Resource access configurations for team-based access control
|
|
23
|
-
const incidentListAccess = createResourceAccessList("incident", "incidents");
|
|
24
|
-
|
|
25
15
|
export const incidentContract = {
|
|
26
16
|
/** List all incidents with optional filters */
|
|
27
|
-
listIncidents:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
17
|
+
listIncidents: proc({
|
|
18
|
+
operationType: "query",
|
|
19
|
+
userType: "public",
|
|
20
|
+
access: [incidentAccess.incident.read],
|
|
21
|
+
})
|
|
33
22
|
.input(
|
|
34
23
|
z
|
|
35
24
|
.object({
|
|
@@ -42,65 +31,80 @@ export const incidentContract = {
|
|
|
42
31
|
.output(z.object({ incidents: z.array(IncidentWithSystemsSchema) })),
|
|
43
32
|
|
|
44
33
|
/** Get a single incident with all details */
|
|
45
|
-
getIncident:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
getIncident: proc({
|
|
35
|
+
operationType: "query",
|
|
36
|
+
userType: "public",
|
|
37
|
+
access: [incidentAccess.incident.read],
|
|
38
|
+
})
|
|
50
39
|
.input(z.object({ id: z.string() }))
|
|
51
40
|
.output(IncidentDetailSchema.nullable()),
|
|
52
41
|
|
|
53
42
|
/** Get active incidents for a specific system */
|
|
54
|
-
getIncidentsForSystem:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
getIncidentsForSystem: proc({
|
|
44
|
+
operationType: "query",
|
|
45
|
+
userType: "public",
|
|
46
|
+
access: [incidentAccess.incident.read],
|
|
47
|
+
})
|
|
59
48
|
.input(z.object({ systemId: z.string() }))
|
|
60
49
|
.output(z.array(IncidentWithSystemsSchema)),
|
|
61
50
|
|
|
51
|
+
/** Get active incidents for multiple systems in a single request.
|
|
52
|
+
* Used for efficient dashboard rendering to avoid N+1 queries.
|
|
53
|
+
*/
|
|
54
|
+
getBulkIncidentsForSystems: proc({
|
|
55
|
+
operationType: "query",
|
|
56
|
+
userType: "public",
|
|
57
|
+
access: [incidentAccess.bulkIncident],
|
|
58
|
+
})
|
|
59
|
+
.input(z.object({ systemIds: z.array(z.string()) }))
|
|
60
|
+
.output(
|
|
61
|
+
z.object({
|
|
62
|
+
incidents: z.record(z.string(), z.array(IncidentWithSystemsSchema)),
|
|
63
|
+
})
|
|
64
|
+
),
|
|
65
|
+
|
|
62
66
|
/** Create a new incident */
|
|
63
|
-
createIncident:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
createIncident: proc({
|
|
68
|
+
operationType: "mutation",
|
|
69
|
+
userType: "authenticated",
|
|
70
|
+
access: [incidentAccess.incident.manage],
|
|
71
|
+
})
|
|
68
72
|
.input(CreateIncidentInputSchema)
|
|
69
73
|
.output(IncidentWithSystemsSchema),
|
|
70
74
|
|
|
71
75
|
/** Update an existing incident */
|
|
72
|
-
updateIncident:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
updateIncident: proc({
|
|
77
|
+
operationType: "mutation",
|
|
78
|
+
userType: "authenticated",
|
|
79
|
+
access: [incidentAccess.incident.manage],
|
|
80
|
+
})
|
|
77
81
|
.input(UpdateIncidentInputSchema)
|
|
78
82
|
.output(IncidentWithSystemsSchema),
|
|
79
83
|
|
|
80
84
|
/** Add a status update to an incident */
|
|
81
|
-
addUpdate:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
addUpdate: proc({
|
|
86
|
+
operationType: "mutation",
|
|
87
|
+
userType: "authenticated",
|
|
88
|
+
access: [incidentAccess.incident.manage],
|
|
89
|
+
})
|
|
86
90
|
.input(AddIncidentUpdateInputSchema)
|
|
87
91
|
.output(IncidentUpdateSchema),
|
|
88
92
|
|
|
89
93
|
/** Resolve an incident (sets status to resolved) */
|
|
90
|
-
resolveIncident:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
resolveIncident: proc({
|
|
95
|
+
operationType: "mutation",
|
|
96
|
+
userType: "authenticated",
|
|
97
|
+
access: [incidentAccess.incident.manage],
|
|
98
|
+
})
|
|
95
99
|
.input(z.object({ id: z.string(), message: z.string().optional() }))
|
|
96
100
|
.output(IncidentWithSystemsSchema),
|
|
97
101
|
|
|
98
102
|
/** Delete an incident */
|
|
99
|
-
deleteIncident:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
deleteIncident: proc({
|
|
104
|
+
operationType: "mutation",
|
|
105
|
+
userType: "authenticated",
|
|
106
|
+
access: [incidentAccess.incident.manage],
|
|
107
|
+
})
|
|
104
108
|
.input(z.object({ id: z.string() }))
|
|
105
109
|
.output(z.object({ success: z.boolean() })),
|
|
106
110
|
};
|
package/src/permissions.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createPermission, type Permission } from "@checkstack/common";
|
|
2
|
-
|
|
3
|
-
export const permissions = {
|
|
4
|
-
/** Read access to incidents - granted to all users by default */
|
|
5
|
-
incidentRead: createPermission("incident", "read", "View incidents", {
|
|
6
|
-
isAuthenticatedDefault: true,
|
|
7
|
-
isPublicDefault: true,
|
|
8
|
-
}),
|
|
9
|
-
/** Manage incidents - create, edit, resolve, and delete */
|
|
10
|
-
incidentManage: createPermission("incident", "manage", "Manage incidents"),
|
|
11
|
-
} as const satisfies Record<string, Permission>;
|
|
12
|
-
|
|
13
|
-
export const permissionList = Object.values(permissions);
|