@checkstack/maintenance-common 0.2.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 CHANGED
@@ -1,5 +1,66 @@
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
+
3
64
  ## 0.2.0
4
65
 
5
66
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/maintenance-common",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
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 Maintenance plugin.
@@ -7,6 +7,7 @@ export const maintenanceAccess = {
7
7
  /**
8
8
  * Maintenance 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
  maintenance: accessPair(
12
13
  "maintenance",
@@ -16,10 +17,26 @@ export const maintenanceAccess = {
16
17
  "Manage planned maintenances - create, edit, delete, and add updates",
17
18
  },
18
19
  {
20
+ idParam: "systemId",
19
21
  readIsDefault: true,
20
22
  readIsPublic: true,
21
23
  }
22
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
+ ),
23
40
  };
24
41
 
25
42
  /**
@@ -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 { maintenanceAccess } from "./access";
8
4
  import { pluginMetadata } from "./plugin-metadata";
9
5
  import {
@@ -16,15 +12,13 @@ import {
16
12
  MaintenanceStatusEnum,
17
13
  } from "./schemas";
18
14
 
19
- const _base = oc.$meta<ProcedureMetadata>({});
20
-
21
15
  export const maintenanceContract = {
22
16
  /** List all maintenances with optional status filter */
23
- listMaintenances: _base
24
- .meta({
25
- userType: "public",
26
- access: [maintenanceAccess.maintenance.read],
27
- })
17
+ listMaintenances: proc({
18
+ operationType: "query",
19
+ userType: "public",
20
+ access: [maintenanceAccess.maintenance.read],
21
+ })
28
22
  .input(
29
23
  z
30
24
  .object({
@@ -36,65 +30,83 @@ export const maintenanceContract = {
36
30
  .output(z.object({ maintenances: z.array(MaintenanceWithSystemsSchema) })),
37
31
 
38
32
  /** Get a single maintenance with all details */
39
- getMaintenance: _base
40
- .meta({
41
- userType: "public",
42
- access: [maintenanceAccess.maintenance.read],
43
- })
33
+ getMaintenance: proc({
34
+ operationType: "query",
35
+ userType: "public",
36
+ access: [maintenanceAccess.maintenance.read],
37
+ })
44
38
  .input(z.object({ id: z.string() }))
45
39
  .output(MaintenanceDetailSchema.nullable()),
46
40
 
47
41
  /** Get active or upcoming maintenances for a specific system */
48
- getMaintenancesForSystem: _base
49
- .meta({
50
- userType: "public",
51
- access: [maintenanceAccess.maintenance.read],
52
- })
42
+ getMaintenancesForSystem: proc({
43
+ operationType: "query",
44
+ userType: "public",
45
+ access: [maintenanceAccess.maintenance.read],
46
+ })
53
47
  .input(z.object({ systemId: z.string() }))
54
48
  .output(z.array(MaintenanceWithSystemsSchema)),
55
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
+
56
68
  /** Create a new maintenance */
57
- createMaintenance: _base
58
- .meta({
59
- userType: "authenticated",
60
- access: [maintenanceAccess.maintenance.manage],
61
- })
69
+ createMaintenance: proc({
70
+ operationType: "mutation",
71
+ userType: "authenticated",
72
+ access: [maintenanceAccess.maintenance.manage],
73
+ })
62
74
  .input(CreateMaintenanceInputSchema)
63
75
  .output(MaintenanceWithSystemsSchema),
64
76
 
65
77
  /** Update an existing maintenance */
66
- updateMaintenance: _base
67
- .meta({
68
- userType: "authenticated",
69
- access: [maintenanceAccess.maintenance.manage],
70
- })
78
+ updateMaintenance: proc({
79
+ operationType: "mutation",
80
+ userType: "authenticated",
81
+ access: [maintenanceAccess.maintenance.manage],
82
+ })
71
83
  .input(UpdateMaintenanceInputSchema)
72
84
  .output(MaintenanceWithSystemsSchema),
73
85
 
74
86
  /** Add a status update to a maintenance */
75
- addUpdate: _base
76
- .meta({
77
- userType: "authenticated",
78
- access: [maintenanceAccess.maintenance.manage],
79
- })
87
+ addUpdate: proc({
88
+ operationType: "mutation",
89
+ userType: "authenticated",
90
+ access: [maintenanceAccess.maintenance.manage],
91
+ })
80
92
  .input(AddMaintenanceUpdateInputSchema)
81
93
  .output(MaintenanceUpdateSchema),
82
94
 
83
95
  /** Close a maintenance early (sets status to completed) */
84
- closeMaintenance: _base
85
- .meta({
86
- userType: "authenticated",
87
- access: [maintenanceAccess.maintenance.manage],
88
- })
96
+ closeMaintenance: proc({
97
+ operationType: "mutation",
98
+ userType: "authenticated",
99
+ access: [maintenanceAccess.maintenance.manage],
100
+ })
89
101
  .input(z.object({ id: z.string(), message: z.string().optional() }))
90
102
  .output(MaintenanceWithSystemsSchema),
91
103
 
92
104
  /** Delete a maintenance */
93
- deleteMaintenance: _base
94
- .meta({
95
- userType: "authenticated",
96
- access: [maintenanceAccess.maintenance.manage],
97
- })
105
+ deleteMaintenance: proc({
106
+ operationType: "mutation",
107
+ userType: "authenticated",
108
+ access: [maintenanceAccess.maintenance.manage],
109
+ })
98
110
  .input(z.object({ id: z.string() }))
99
111
  .output(z.object({ success: z.boolean() })),
100
112
  };