@checkstack/queue-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.
- package/CHANGELOG.md +152 -0
- package/package.json +2 -1
- package/src/access.ts +22 -0
- package/src/index.ts +3 -7
- package/src/rpc-contract.ts +46 -22
- package/src/schemas.ts +47 -0
- package/src/signals.ts +15 -0
- package/src/permissions.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,157 @@
|
|
|
1
1
|
# @checkstack/queue-common
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 180be38: # Queue Lag Warning
|
|
8
|
+
|
|
9
|
+
Added a queue lag warning system that displays alerts when pending jobs exceed configurable thresholds.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Backend Stats API**: New `getStats`, `getLagStatus`, and `updateLagThresholds` RPC endpoints
|
|
14
|
+
- **Signal-based Updates**: `QUEUE_LAG_CHANGED` signal for real-time frontend updates
|
|
15
|
+
- **Aggregated Stats**: `QueueManager.getAggregatedStats()` sums stats across all queues
|
|
16
|
+
- **Configurable Thresholds**: Warning (default 100) and Critical (default 500) thresholds stored in config
|
|
17
|
+
- **Dashboard Integration**: Queue lag alert displayed on main Dashboard (access-gated)
|
|
18
|
+
- **Queue Settings Page**: Lag alert and Performance Tuning guidance card with concurrency tips
|
|
19
|
+
|
|
20
|
+
## UI Changes
|
|
21
|
+
|
|
22
|
+
- Queue lag alert banner appears on Dashboard and Queue Settings when pending jobs exceed thresholds
|
|
23
|
+
- New "Performance Tuning" card with concurrency settings guidance and bottleneck indicators
|
|
24
|
+
|
|
25
|
+
- 7a23261: ## TanStack Query Integration
|
|
26
|
+
|
|
27
|
+
Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
|
|
28
|
+
|
|
29
|
+
### New Features
|
|
30
|
+
|
|
31
|
+
- **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
|
|
32
|
+
- **Automatic request deduplication**: Multiple components requesting the same data share a single network request
|
|
33
|
+
- **Built-in caching**: Configurable stale time and cache duration per query
|
|
34
|
+
- **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
|
|
35
|
+
- **Background refetching**: Stale data is automatically refreshed when components mount
|
|
36
|
+
|
|
37
|
+
### Contract Changes
|
|
38
|
+
|
|
39
|
+
All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const getItems = proc()
|
|
43
|
+
.meta({ operationType: "query", access: [access.read] })
|
|
44
|
+
.output(z.array(itemSchema))
|
|
45
|
+
.query();
|
|
46
|
+
|
|
47
|
+
const createItem = proc()
|
|
48
|
+
.meta({ operationType: "mutation", access: [access.manage] })
|
|
49
|
+
.input(createItemSchema)
|
|
50
|
+
.output(itemSchema)
|
|
51
|
+
.mutation();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Migration
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Before (forPlugin pattern)
|
|
58
|
+
const api = useApi(myPluginApiRef);
|
|
59
|
+
const [items, setItems] = useState<Item[]>([]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
api.getItems().then(setItems);
|
|
62
|
+
}, [api]);
|
|
63
|
+
|
|
64
|
+
// After (usePluginClient pattern)
|
|
65
|
+
const client = usePluginClient(MyPluginApi);
|
|
66
|
+
const { data: items, isLoading } = client.getItems.useQuery({});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Bug Fixes
|
|
70
|
+
|
|
71
|
+
- Fixed `rpc.test.ts` test setup for middleware type inference
|
|
72
|
+
- Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
|
|
73
|
+
- Fixed null→undefined warnings in notification and queue frontends
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [7a23261]
|
|
78
|
+
- @checkstack/common@0.3.0
|
|
79
|
+
- @checkstack/signal-common@0.1.1
|
|
80
|
+
|
|
81
|
+
## 0.1.0
|
|
82
|
+
|
|
83
|
+
### Minor Changes
|
|
84
|
+
|
|
85
|
+
- 9faec1f: # Unified AccessRule Terminology Refactoring
|
|
86
|
+
|
|
87
|
+
This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
|
|
88
|
+
|
|
89
|
+
## Changes
|
|
90
|
+
|
|
91
|
+
### Core Infrastructure (`@checkstack/common`)
|
|
92
|
+
|
|
93
|
+
- Introduced `AccessRule` interface as the primary access control type
|
|
94
|
+
- Added `accessPair()` helper for creating read/manage access rule pairs
|
|
95
|
+
- Added `access()` builder for individual access rules
|
|
96
|
+
- Replaced `Permission` type with `AccessRule` throughout
|
|
97
|
+
|
|
98
|
+
### API Changes
|
|
99
|
+
|
|
100
|
+
- `env.registerPermissions()` → `env.registerAccessRules()`
|
|
101
|
+
- `meta.permissions` → `meta.access` in RPC contracts
|
|
102
|
+
- `usePermission()` → `useAccess()` in frontend hooks
|
|
103
|
+
- Route `permission:` field → `accessRule:` field
|
|
104
|
+
|
|
105
|
+
### UI Changes
|
|
106
|
+
|
|
107
|
+
- "Roles & Permissions" tab → "Roles & Access Rules"
|
|
108
|
+
- "You don't have permission..." → "You don't have access..."
|
|
109
|
+
- All permission-related UI text updated
|
|
110
|
+
|
|
111
|
+
### Documentation & Templates
|
|
112
|
+
|
|
113
|
+
- Updated 18 documentation files with AccessRule terminology
|
|
114
|
+
- Updated 7 scaffolding templates with `accessPair()` pattern
|
|
115
|
+
- All code examples use new AccessRule API
|
|
116
|
+
|
|
117
|
+
## Migration Guide
|
|
118
|
+
|
|
119
|
+
### Backend Plugins
|
|
120
|
+
|
|
121
|
+
```diff
|
|
122
|
+
- import { permissionList } from "./permissions";
|
|
123
|
+
- env.registerPermissions(permissionList);
|
|
124
|
+
+ import { accessRules } from "./access";
|
|
125
|
+
+ env.registerAccessRules(accessRules);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### RPC Contracts
|
|
129
|
+
|
|
130
|
+
```diff
|
|
131
|
+
- .meta({ userType: "user", permissions: [permissions.read.id] })
|
|
132
|
+
+ .meta({ userType: "user", access: [access.read] })
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Frontend Hooks
|
|
136
|
+
|
|
137
|
+
```diff
|
|
138
|
+
- const canRead = accessApi.usePermission(permissions.read.id);
|
|
139
|
+
+ const canRead = accessApi.useAccess(access.read);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Routes
|
|
143
|
+
|
|
144
|
+
```diff
|
|
145
|
+
- permission: permissions.entityRead.id,
|
|
146
|
+
+ accessRule: access.read,
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- Updated dependencies [9faec1f]
|
|
152
|
+
- Updated dependencies [f533141]
|
|
153
|
+
- @checkstack/common@0.2.0
|
|
154
|
+
|
|
3
155
|
## 0.0.4
|
|
4
156
|
|
|
5
157
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/queue-common",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@checkstack/common": "workspace:*",
|
|
17
|
+
"@checkstack/signal-common": "workspace:*",
|
|
17
18
|
"@orpc/contract": "^1.13.2",
|
|
18
19
|
"zod": "^4.0.0"
|
|
19
20
|
},
|
package/src/access.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { accessPair } from "@checkstack/common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Access rules for the Queue plugin.
|
|
5
|
+
*/
|
|
6
|
+
export const queueAccess = {
|
|
7
|
+
/**
|
|
8
|
+
* Queue settings access.
|
|
9
|
+
*/
|
|
10
|
+
settings: accessPair("queue", {
|
|
11
|
+
read: "Read Queue Settings",
|
|
12
|
+
manage: "Update Queue Settings",
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* All access rules for registration with the plugin system.
|
|
18
|
+
*/
|
|
19
|
+
export const queueAccessRules = [
|
|
20
|
+
queueAccess.settings.read,
|
|
21
|
+
queueAccess.settings.manage,
|
|
22
|
+
];
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export * from "./schemas";
|
|
2
|
-
export * from "./
|
|
3
|
-
export {
|
|
4
|
-
queueContract,
|
|
5
|
-
QueueApi,
|
|
6
|
-
type QueueContract,
|
|
7
|
-
type QueueMetadata,
|
|
8
|
-
} from "./rpc-contract";
|
|
2
|
+
export * from "./access";
|
|
3
|
+
export { queueContract, QueueApi, type QueueContract } from "./rpc-contract";
|
|
9
4
|
export * from "./plugin-metadata";
|
|
10
5
|
export { queueRoutes } from "./routes";
|
|
6
|
+
export * from "./signals";
|
package/src/rpc-contract.ts
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createClientDefinition } from "@checkstack/common";
|
|
1
|
+
import { createClientDefinition, proc } from "@checkstack/common";
|
|
3
2
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
3
|
+
import { queueAccess } from "./access";
|
|
5
4
|
import { pluginMetadata } from "./plugin-metadata";
|
|
6
5
|
import {
|
|
7
6
|
QueuePluginDtoSchema,
|
|
8
7
|
QueueConfigurationDtoSchema,
|
|
9
8
|
UpdateQueueConfigurationSchema,
|
|
9
|
+
QueueStatsDtoSchema,
|
|
10
|
+
QueueLagStatusSchema,
|
|
11
|
+
QueueLagThresholdsSchema,
|
|
10
12
|
} from "./schemas";
|
|
11
13
|
|
|
12
|
-
//
|
|
13
|
-
export interface QueueMetadata {
|
|
14
|
-
permissions?: string[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Base builder with metadata support
|
|
18
|
-
const _base = oc.$meta<QueueMetadata>({});
|
|
19
|
-
|
|
20
|
-
// Queue RPC Contract with permission metadata
|
|
14
|
+
// Queue RPC Contract with access metadata
|
|
21
15
|
export const queueContract = {
|
|
22
|
-
// Queue plugin queries - Read
|
|
23
|
-
getPlugins:
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
// Queue plugin queries - Read access
|
|
17
|
+
getPlugins: proc({
|
|
18
|
+
operationType: "query",
|
|
19
|
+
userType: "authenticated",
|
|
20
|
+
access: [queueAccess.settings.read],
|
|
21
|
+
}).output(z.array(QueuePluginDtoSchema)),
|
|
26
22
|
|
|
27
|
-
getConfiguration:
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
getConfiguration: proc({
|
|
24
|
+
operationType: "query",
|
|
25
|
+
userType: "authenticated",
|
|
26
|
+
access: [queueAccess.settings.read],
|
|
27
|
+
}).output(QueueConfigurationDtoSchema),
|
|
30
28
|
|
|
31
|
-
// Queue configuration updates - Manage
|
|
32
|
-
updateConfiguration:
|
|
33
|
-
|
|
29
|
+
// Queue configuration updates - Manage access
|
|
30
|
+
updateConfiguration: proc({
|
|
31
|
+
operationType: "mutation",
|
|
32
|
+
userType: "authenticated",
|
|
33
|
+
access: [queueAccess.settings.manage],
|
|
34
|
+
})
|
|
34
35
|
.input(UpdateQueueConfigurationSchema)
|
|
35
36
|
.output(QueueConfigurationDtoSchema),
|
|
37
|
+
|
|
38
|
+
// Queue statistics - Read access
|
|
39
|
+
getStats: proc({
|
|
40
|
+
operationType: "query",
|
|
41
|
+
userType: "authenticated",
|
|
42
|
+
access: [queueAccess.settings.read],
|
|
43
|
+
}).output(QueueStatsDtoSchema),
|
|
44
|
+
|
|
45
|
+
// Queue lag status (includes thresholds) - Read access
|
|
46
|
+
getLagStatus: proc({
|
|
47
|
+
operationType: "query",
|
|
48
|
+
userType: "authenticated",
|
|
49
|
+
access: [queueAccess.settings.read],
|
|
50
|
+
}).output(QueueLagStatusSchema),
|
|
51
|
+
|
|
52
|
+
// Update lag thresholds - Manage access
|
|
53
|
+
updateLagThresholds: proc({
|
|
54
|
+
operationType: "mutation",
|
|
55
|
+
userType: "authenticated",
|
|
56
|
+
access: [queueAccess.settings.manage],
|
|
57
|
+
})
|
|
58
|
+
.input(QueueLagThresholdsSchema)
|
|
59
|
+
.output(QueueLagThresholdsSchema),
|
|
36
60
|
};
|
|
37
61
|
|
|
38
62
|
// Export contract type
|
package/src/schemas.ts
CHANGED
|
@@ -36,3 +36,50 @@ export const UpdateQueueConfigurationSchema = z.object({
|
|
|
36
36
|
export type UpdateQueueConfiguration = z.infer<
|
|
37
37
|
typeof UpdateQueueConfigurationSchema
|
|
38
38
|
>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Queue statistics DTO
|
|
42
|
+
*/
|
|
43
|
+
export const QueueStatsDtoSchema = z.object({
|
|
44
|
+
pending: z.number(),
|
|
45
|
+
processing: z.number(),
|
|
46
|
+
completed: z.number(),
|
|
47
|
+
failed: z.number(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export type QueueStatsDto = z.infer<typeof QueueStatsDtoSchema>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Lag severity levels
|
|
54
|
+
*/
|
|
55
|
+
export const LagSeveritySchema = z.enum(["none", "warning", "critical"]);
|
|
56
|
+
export type LagSeverity = z.infer<typeof LagSeveritySchema>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Queue lag thresholds configuration
|
|
60
|
+
*/
|
|
61
|
+
export const QueueLagThresholdsSchema = z.object({
|
|
62
|
+
warningThreshold: z
|
|
63
|
+
.number()
|
|
64
|
+
.min(1)
|
|
65
|
+
.default(100)
|
|
66
|
+
.describe("Pending job count to trigger warning"),
|
|
67
|
+
criticalThreshold: z
|
|
68
|
+
.number()
|
|
69
|
+
.min(1)
|
|
70
|
+
.default(500)
|
|
71
|
+
.describe("Pending job count to trigger critical alert"),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export type QueueLagThresholds = z.infer<typeof QueueLagThresholdsSchema>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Queue lag status response
|
|
78
|
+
*/
|
|
79
|
+
export const QueueLagStatusSchema = z.object({
|
|
80
|
+
pending: z.number(),
|
|
81
|
+
severity: LagSeveritySchema,
|
|
82
|
+
thresholds: QueueLagThresholdsSchema,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type QueueLagStatus = z.infer<typeof QueueLagStatusSchema>;
|
package/src/signals.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createSignal } from "@checkstack/signal-common";
|
|
3
|
+
import { LagSeveritySchema } from "./schemas";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Signal broadcast when queue lag status changes.
|
|
7
|
+
* Frontend listens to update lag warning UI in real-time.
|
|
8
|
+
*/
|
|
9
|
+
export const QUEUE_LAG_CHANGED = createSignal(
|
|
10
|
+
"queue.lag.changed",
|
|
11
|
+
z.object({
|
|
12
|
+
pending: z.number(),
|
|
13
|
+
severity: LagSeveritySchema,
|
|
14
|
+
})
|
|
15
|
+
);
|
package/src/permissions.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createPermission } from "@checkstack/common";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Permissions for queue settings
|
|
5
|
-
*/
|
|
6
|
-
export const permissions = {
|
|
7
|
-
queueRead: createPermission("queue", "read", "Read Queue Settings"),
|
|
8
|
-
queueManage: createPermission("queue", "manage", "Update Queue Settings"),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const permissionList = Object.values(permissions);
|