@checkstack/infrastructure-common 0.2.3 → 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 CHANGED
@@ -1,5 +1,139 @@
1
1
  # @checkstack/infrastructure-common
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [9016526]
8
+ - @checkstack/common@0.10.0
9
+ - @checkstack/frontend-api@0.5.1
10
+
11
+ ## 0.3.0
12
+
13
+ ### Minor Changes
14
+
15
+ - aa89bc5: Replace the bespoke `registerInfrastructureTab()` registry with a standard
16
+ slot-extension contract (`InfrastructureTabsSlot` from
17
+ `@checkstack/infrastructure-common`). Plugins now contribute infrastructure
18
+ tabs via `createSlotExtension`, depending only on the slot owner.
19
+
20
+ The slot system in `@checkstack/frontend-api` gains a second type parameter
21
+ on `createSlot<TContext, TMetadata>` so extensions can declare typed static
22
+ metadata at registration time (label, icon, access rules, ordering for the
23
+ infrastructure tab bar). A new `useSlotExtensions(slot)` hook returns typed
24
+ extensions and subscribes to plugin lifecycle changes.
25
+
26
+ Each tab body now stacks a **Runtime** sub-section (live state, read-only)
27
+ on top of a **Configuration** sub-section (settings, gated by `canUpdate`).
28
+
29
+ **Queue runtime panel.** Surfaces aggregated counts (pending / processing /
30
+ completed / failed) plus three sub-tabs of recent jobs: **Active**, **Recent
31
+ failed** (with the failure message), and **Recent completed** (with
32
+ duration). Job payloads are deliberately not surfaced — they may carry
33
+ secrets and need a separate manage-access gate to be shown.
34
+
35
+ To support this, `Queue<T>` gains a required `listJobs(opts)` method
36
+ returning `JobSummary[]` (no payloads), and `QueueStats` gains a
37
+ `scope: "instance" | "cluster"` field. The in-memory queue keeps rolling
38
+ ring buffers (200 entries) for completed/failed history and tracks active
39
+ jobs by id; BullMQ uses native `getJobs`. `QueueManager.listJobs` aggregates
40
+ across queues and sorts (most-recent-first for terminal states, FIFO for
41
+ active/waiting/delayed).
42
+
43
+ **Cache runtime panel.** Lists the top N entries by size (or by recency) so
44
+ operators can debug a cache filling up. Values are deliberately omitted —
45
+ PII / secret risk. Backends opt in via an optional `listEntries?` method on
46
+ `CacheProvider`; non-supporting backends return `{ supported: false }` and
47
+ the UI renders a "not supported by this backend" hint. The in-memory cache
48
+ implements it using its existing per-entry byte tracking.
49
+
50
+ `CacheStats` also gains `scope: "instance" | "cluster"`.
51
+
52
+ **Multi-instance scope warning.** A new `<InstanceScopeBanner>` component in
53
+ `@checkstack/ui` renders a yellow banner above any runtime panel whose
54
+ backend reports `scope: "instance"` — i.e. in-memory queue or cache running
55
+ in a horizontally scaled deployment. The banner explains the metrics are
56
+ local to the responding replica and recommends switching to a clustered
57
+ backend (Redis-backed queue / cache) for cluster-wide visibility.
58
+
59
+ **Bug fix — stable cache provider proxy.** `CacheManagerImpl.getProvider()`
60
+ now returns a single stable proxy that delegates to whatever provider is
61
+ currently active. Previously, consumers of `createCachedScope` (and any
62
+ direct `cacheManager.getProvider()` caller) captured the active provider
63
+ reference at plugin-init time. After any `setActiveBackend` call — including
64
+ saving the same memory config in the new Cache tab, which reconstructs the
65
+ in-memory cache — those scopes wrote to an orphaned old provider while the
66
+ runtime panel read stats from the new (empty) one, making the runtime panel
67
+ appear to report 0 keys. With the proxy, all consumers share a single stable
68
+ identity and writes always land in the active provider.
69
+
70
+ **Bytes tracking on the in-memory cache.** `InMemoryCache.getStats().sizeBytes`
71
+ now returns a running approximation (UTF-8 bytes of the key plus
72
+ `v8.serialize(value).byteLength`, with a JSON fallback) that's kept in sync
73
+ across all eviction paths. Treat the number as a sanity gauge; it doesn't
74
+ include `Map` per-entry overhead.
75
+
76
+ **Pagination.** Both `Queue<T>.listJobs` and `CacheProvider.listEntries?`
77
+ are offset-paginated. Inputs gain an `offset: number`; outputs change to
78
+ `{ items, total: number | null, hasMore: boolean }`. `total` is nullable
79
+ so backends that can't compute it cheaply still paginate via `hasMore`.
80
+ The UI uses the existing `<Pagination>` component with a 25-row default
81
+ page size. `QueueManager.listJobs` aggregates by over-fetching
82
+ `[0, offset+limit)` per queue, merge-sorting, then slicing the window —
83
+ optimal for the single-queue case, acceptable for the multi-queue case
84
+ within the UI's reasonable page-depth bounds. BullMQ uses native offset
85
+ ranges via `getJobs(types, start, end)` plus `getJobCounts` for `total`.
86
+
87
+ **Pending tab.** The Queue runtime panel exposes a virtual `"pending"`
88
+ state (waiting ∪ delayed, FIFO). It's now the default sub-tab, since
89
+ "what's queued up?" is the most common question. Per-row state is shown
90
+ when viewing the combined list.
91
+
92
+ **Recurring schedules visible under Pending.** Cron- and interval-based
93
+ recurring jobs (e.g. healthchecks) are surfaced under Pending/Delayed
94
+ between fires, with a `nextRunAt` countdown column and a "(recurring)"
95
+ label. `JobSummary` gains optional `nextRunAt: Date` and `recurring:
96
+ boolean` fields. The in-memory queue synthesises these rows from its
97
+ `recurringJobs` registry; BullMQ already materialises the next fire of
98
+ each scheduler as a delayed job and we now surface its trigger time and
99
+ the `repeatJobKey`-derived `recurring` flag.
100
+
101
+ **Bug fix — drop hook emits with no listeners.** `EventBus.emit` no
102
+ longer enqueues a job when zero listeners (distributed or instance-local)
103
+ are registered for the hook. Previously, hooks like
104
+ `core.plugin.initialized` — emitted on every plugin init but subscribed
105
+ to by nothing in the core repo — accumulated one waiting job per emit
106
+ forever. The in-memory queue's `processNext` short-circuits when there
107
+ are zero consumer groups, so its post-loop cleanup never ran for these
108
+ orphaned jobs. The fix drops the emit at the source and logs a debug
109
+ line. Note: in distributed deployments using a Redis-backed queue, this
110
+ means a subscriber on another replica won't receive an event if no
111
+ replica that emits it has a local listener. Plugins needing cross-process
112
+ delivery must register their listener on every replica that should
113
+ receive the hook.
114
+
115
+ **Breaking notes (treated as minor under beta semantics)**:
116
+
117
+ - `@checkstack/infrastructure-common` removes `registerInfrastructureTab`
118
+ and `getInfrastructureTabs`; former callers must register an extension
119
+ into `InfrastructureTabsSlot`.
120
+ - `@checkstack/queue-api`'s `Queue<T>` interface requires the new
121
+ `listJobs(opts)` method returning `ListJobsResult` (paginated). Both
122
+ bundled queue backends (memory, BullMQ) are updated; out-of-tree
123
+ implementations will need to add it.
124
+ - `QueueStats` and `CacheStats` add a required `scope` field.
125
+ - `CacheProvider.listEntries?` (when implemented) now returns
126
+ `ListEntriesResult` instead of `CacheEntrySummary[]`.
127
+ - `JobState` adds a `"pending"` variant.
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [42abfff]
132
+ - Updated dependencies [aa89bc5]
133
+ - Updated dependencies [950d6ec]
134
+ - @checkstack/common@0.9.0
135
+ - @checkstack/frontend-api@0.5.0
136
+
3
137
  ## 0.2.3
4
138
 
5
139
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/infrastructure-common",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,13 +14,13 @@
14
14
  "lint:code": "eslint . --max-warnings 0"
15
15
  },
16
16
  "dependencies": {
17
- "@checkstack/common": "0.7.0",
18
- "@checkstack/frontend-api": "0.4.1"
17
+ "@checkstack/common": "0.9.0",
18
+ "@checkstack/frontend-api": "0.5.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "typescript": "^5.7.2",
22
- "@checkstack/tsconfig": "0.0.6",
23
- "@checkstack/scripts": "0.1.2",
22
+ "@checkstack/tsconfig": "0.0.7",
23
+ "@checkstack/scripts": "0.3.1",
24
24
  "@types/react": "^18.3.18",
25
25
  "react": "^18.3.1"
26
26
  },
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { pluginMetadata } from "./plugin-metadata";
2
2
  export { infrastructureRoutes } from "./routes";
3
3
  export {
4
- registerInfrastructureTab,
5
- getInfrastructureTabs,
6
- type InfrastructureTab,
7
- } from "./tabs";
4
+ InfrastructureTabsSlot,
5
+ type InfrastructureTabContext,
6
+ type InfrastructureTabMetadata,
7
+ } from "./slots";
package/src/slots.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type React from "react";
2
+ import type { AccessRule } from "@checkstack/common";
3
+ import { createSlot } from "@checkstack/frontend-api";
4
+
5
+ /**
6
+ * Render-time props for an Infrastructure tab body component.
7
+ *
8
+ * The shell page resolves the user's manage-access permission for the tab
9
+ * (declared in the extension's metadata) and passes it down so the tab body
10
+ * can disable update affordances accordingly.
11
+ */
12
+ export interface InfrastructureTabContext {
13
+ canUpdate: boolean;
14
+ }
15
+
16
+ /**
17
+ * Static descriptor each tab declares at extension-registration time.
18
+ *
19
+ * The shell page reads these to render the vertical tab bar (label + icon),
20
+ * to determine which tabs the current user can see (`readAccess`) and to
21
+ * order tabs (`order`). Whether the tab body is interactive is decided by
22
+ * `manageAccess`, evaluated by the page and forwarded as `canUpdate`.
23
+ */
24
+ export interface InfrastructureTabMetadata {
25
+ label: string;
26
+ icon: React.ComponentType<{ className?: string }>;
27
+ readAccess: AccessRule;
28
+ manageAccess: AccessRule;
29
+ order?: number;
30
+ }
31
+
32
+ /**
33
+ * Slot for the Infrastructure Settings page tab bar.
34
+ *
35
+ * Plugins that own an infrastructure concern (queue, cache, …) register an
36
+ * extension into this slot via `createSlotExtension` from
37
+ * `@checkstack/frontend-api`. The shell page in `@checkstack/infrastructure-frontend`
38
+ * is the only consumer.
39
+ *
40
+ * Dependency direction: `queue-frontend` → `infrastructure-common` (the slot
41
+ * owner). `infrastructure-frontend` does NOT depend on the contributing
42
+ * plugins.
43
+ */
44
+ export const InfrastructureTabsSlot = createSlot<
45
+ InfrastructureTabContext,
46
+ InfrastructureTabMetadata
47
+ >("infrastructure.tabs");
package/src/tabs.ts DELETED
@@ -1,62 +0,0 @@
1
- import type React from "react";
2
- import type { AccessRule } from "@checkstack/common";
3
-
4
- /**
5
- * Tab registration for the Infrastructure Configuration page.
6
- *
7
- * Each infrastructure concern (Queue, Cache, etc.) registers a tab
8
- * with its own access rules, icon, and component.
9
- *
10
- * The shell page evaluates user access per tab and only shows
11
- * tabs the user can read. If no tabs are visible, it shows "not authorized".
12
- */
13
- export interface InfrastructureTab {
14
- /** Unique tab ID (e.g., "queue", "cache") */
15
- id: string;
16
-
17
- /** Plugin ID that registers this tab (e.g., "queue", "cache") */
18
- pluginId: string;
19
-
20
- /** Tab display label */
21
- label: string;
22
-
23
- /** Tab icon component */
24
- icon: React.ComponentType<{ className?: string }>;
25
-
26
- /** The tab content component */
27
- component: React.ComponentType<{ canUpdate: boolean }>;
28
-
29
- /** Access rule required to view this tab */
30
- readAccess: AccessRule;
31
-
32
- /** Access rule required to modify settings in this tab */
33
- manageAccess: AccessRule;
34
-
35
- /** Sort order — lower numbers appear first */
36
- order?: number;
37
- }
38
-
39
- /**
40
- * Global tab registry for Infrastructure Configuration.
41
- *
42
- * Plugins register their tabs here during frontend plugin initialization.
43
- * The infrastructure page reads from this registry to build its tab bar.
44
- *
45
- * This is a simple module-level registry — no React context needed
46
- * since tabs are registered at module load time (during eager plugin loading).
47
- */
48
- const tabs: InfrastructureTab[] = [];
49
-
50
- export function registerInfrastructureTab(tab: InfrastructureTab): void {
51
- // Prevent duplicate registration
52
- if (tabs.some((t) => t.id === tab.id)) {
53
- return;
54
- }
55
- tabs.push(tab);
56
- // Keep sorted by order
57
- tabs.sort((a, b) => (a.order ?? 100) - (b.order ?? 100));
58
- }
59
-
60
- export function getInfrastructureTabs(): readonly InfrastructureTab[] {
61
- return tabs;
62
- }