@checkstack/incident-common 0.2.0 → 0.3.1
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 +68 -0
- package/package.json +1 -1
- package/src/access.ts +13 -1
- package/src/rpc-contract.ts +56 -47
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# @checkstack/incident-common
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4eed42d]
|
|
8
|
+
- @checkstack/frontend-api@0.3.0
|
|
9
|
+
|
|
10
|
+
## 0.3.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 7a23261: ## TanStack Query Integration
|
|
15
|
+
|
|
16
|
+
Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
|
|
17
|
+
|
|
18
|
+
### New Features
|
|
19
|
+
|
|
20
|
+
- **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
|
|
21
|
+
- **Automatic request deduplication**: Multiple components requesting the same data share a single network request
|
|
22
|
+
- **Built-in caching**: Configurable stale time and cache duration per query
|
|
23
|
+
- **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
|
|
24
|
+
- **Background refetching**: Stale data is automatically refreshed when components mount
|
|
25
|
+
|
|
26
|
+
### Contract Changes
|
|
27
|
+
|
|
28
|
+
All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const getItems = proc()
|
|
32
|
+
.meta({ operationType: "query", access: [access.read] })
|
|
33
|
+
.output(z.array(itemSchema))
|
|
34
|
+
.query();
|
|
35
|
+
|
|
36
|
+
const createItem = proc()
|
|
37
|
+
.meta({ operationType: "mutation", access: [access.manage] })
|
|
38
|
+
.input(createItemSchema)
|
|
39
|
+
.output(itemSchema)
|
|
40
|
+
.mutation();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Migration
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// Before (forPlugin pattern)
|
|
47
|
+
const api = useApi(myPluginApiRef);
|
|
48
|
+
const [items, setItems] = useState<Item[]>([]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
api.getItems().then(setItems);
|
|
51
|
+
}, [api]);
|
|
52
|
+
|
|
53
|
+
// After (usePluginClient pattern)
|
|
54
|
+
const client = usePluginClient(MyPluginApi);
|
|
55
|
+
const { data: items, isLoading } = client.getItems.useQuery({});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
- Fixed `rpc.test.ts` test setup for middleware type inference
|
|
61
|
+
- Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
|
|
62
|
+
- Fixed null→undefined warnings in notification and queue frontends
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- Updated dependencies [7a23261]
|
|
67
|
+
- @checkstack/frontend-api@0.2.0
|
|
68
|
+
- @checkstack/common@0.3.0
|
|
69
|
+
- @checkstack/signal-common@0.1.1
|
|
70
|
+
|
|
3
71
|
## 0.2.0
|
|
4
72
|
|
|
5
73
|
### Minor Changes
|
package/package.json
CHANGED
package/src/access.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { accessPair } from "@checkstack/common";
|
|
1
|
+
import { access, accessPair } from "@checkstack/common";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Access rules for the Incident plugin.
|
|
@@ -7,6 +7,7 @@ export const incidentAccess = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Incident access with both read and manage levels.
|
|
9
9
|
* Read is public by default.
|
|
10
|
+
* Uses system-level instance access for team-based filtering.
|
|
10
11
|
*/
|
|
11
12
|
incident: accessPair(
|
|
12
13
|
"incident",
|
|
@@ -15,10 +16,21 @@ export const incidentAccess = {
|
|
|
15
16
|
manage: "Manage incidents - create, edit, resolve, and delete",
|
|
16
17
|
},
|
|
17
18
|
{
|
|
19
|
+
idParam: "systemId",
|
|
18
20
|
readIsDefault: true,
|
|
19
21
|
readIsPublic: true,
|
|
20
22
|
}
|
|
21
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
|
+
}),
|
|
22
34
|
};
|
|
23
35
|
|
|
24
36
|
/**
|
package/src/rpc-contract.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { oc } from "@orpc/contract";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
createClientDefinition,
|
|
5
|
-
type ProcedureMetadata,
|
|
6
|
-
} from "@checkstack/common";
|
|
2
|
+
import { createClientDefinition, proc } from "@checkstack/common";
|
|
7
3
|
import { incidentAccess } from "./access";
|
|
8
4
|
import { pluginMetadata } from "./plugin-metadata";
|
|
9
5
|
import {
|
|
@@ -16,15 +12,13 @@ import {
|
|
|
16
12
|
IncidentStatusEnum,
|
|
17
13
|
} from "./schemas";
|
|
18
14
|
|
|
19
|
-
const _base = oc.$meta<ProcedureMetadata>({});
|
|
20
|
-
|
|
21
15
|
export const incidentContract = {
|
|
22
16
|
/** List all incidents with optional filters */
|
|
23
|
-
listIncidents:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
listIncidents: proc({
|
|
18
|
+
operationType: "query",
|
|
19
|
+
userType: "public",
|
|
20
|
+
access: [incidentAccess.incident.read],
|
|
21
|
+
})
|
|
28
22
|
.input(
|
|
29
23
|
z
|
|
30
24
|
.object({
|
|
@@ -37,65 +31,80 @@ export const incidentContract = {
|
|
|
37
31
|
.output(z.object({ incidents: z.array(IncidentWithSystemsSchema) })),
|
|
38
32
|
|
|
39
33
|
/** Get a single incident with all details */
|
|
40
|
-
getIncident:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
getIncident: proc({
|
|
35
|
+
operationType: "query",
|
|
36
|
+
userType: "public",
|
|
37
|
+
access: [incidentAccess.incident.read],
|
|
38
|
+
})
|
|
45
39
|
.input(z.object({ id: z.string() }))
|
|
46
40
|
.output(IncidentDetailSchema.nullable()),
|
|
47
41
|
|
|
48
42
|
/** Get active incidents for a specific system */
|
|
49
|
-
getIncidentsForSystem:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
getIncidentsForSystem: proc({
|
|
44
|
+
operationType: "query",
|
|
45
|
+
userType: "public",
|
|
46
|
+
access: [incidentAccess.incident.read],
|
|
47
|
+
})
|
|
54
48
|
.input(z.object({ systemId: z.string() }))
|
|
55
49
|
.output(z.array(IncidentWithSystemsSchema)),
|
|
56
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
|
+
|
|
57
66
|
/** Create a new incident */
|
|
58
|
-
createIncident:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
createIncident: proc({
|
|
68
|
+
operationType: "mutation",
|
|
69
|
+
userType: "authenticated",
|
|
70
|
+
access: [incidentAccess.incident.manage],
|
|
71
|
+
})
|
|
63
72
|
.input(CreateIncidentInputSchema)
|
|
64
73
|
.output(IncidentWithSystemsSchema),
|
|
65
74
|
|
|
66
75
|
/** Update an existing incident */
|
|
67
|
-
updateIncident:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
updateIncident: proc({
|
|
77
|
+
operationType: "mutation",
|
|
78
|
+
userType: "authenticated",
|
|
79
|
+
access: [incidentAccess.incident.manage],
|
|
80
|
+
})
|
|
72
81
|
.input(UpdateIncidentInputSchema)
|
|
73
82
|
.output(IncidentWithSystemsSchema),
|
|
74
83
|
|
|
75
84
|
/** Add a status update to an incident */
|
|
76
|
-
addUpdate:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
addUpdate: proc({
|
|
86
|
+
operationType: "mutation",
|
|
87
|
+
userType: "authenticated",
|
|
88
|
+
access: [incidentAccess.incident.manage],
|
|
89
|
+
})
|
|
81
90
|
.input(AddIncidentUpdateInputSchema)
|
|
82
91
|
.output(IncidentUpdateSchema),
|
|
83
92
|
|
|
84
93
|
/** Resolve an incident (sets status to resolved) */
|
|
85
|
-
resolveIncident:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
resolveIncident: proc({
|
|
95
|
+
operationType: "mutation",
|
|
96
|
+
userType: "authenticated",
|
|
97
|
+
access: [incidentAccess.incident.manage],
|
|
98
|
+
})
|
|
90
99
|
.input(z.object({ id: z.string(), message: z.string().optional() }))
|
|
91
100
|
.output(IncidentWithSystemsSchema),
|
|
92
101
|
|
|
93
102
|
/** Delete an incident */
|
|
94
|
-
deleteIncident:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
deleteIncident: proc({
|
|
104
|
+
operationType: "mutation",
|
|
105
|
+
userType: "authenticated",
|
|
106
|
+
access: [incidentAccess.incident.manage],
|
|
107
|
+
})
|
|
99
108
|
.input(z.object({ id: z.string() }))
|
|
100
109
|
.output(z.object({ success: z.boolean() })),
|
|
101
110
|
};
|