@checkstack/common 0.0.2 → 0.1.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,79 @@
1
1
  # @checkstack/common
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8e43507: # Teams and Resource-Level Access Control
8
+
9
+ This release introduces a comprehensive Teams system for organizing users and controlling access to resources at a granular level.
10
+
11
+ ## Features
12
+
13
+ ### Team Management
14
+
15
+ - Create, update, and delete teams with name and description
16
+ - Add/remove users from teams
17
+ - Designate team managers with elevated privileges
18
+ - View team membership and manager status
19
+
20
+ ### Resource-Level Access Control
21
+
22
+ - Grant teams access to specific resources (systems, health checks, incidents, maintenances)
23
+ - Configure read-only or manage permissions per team
24
+ - Resource-level "Team Only" mode that restricts access exclusively to team members
25
+ - Separate `resourceAccessSettings` table for resource-level settings (not per-grant)
26
+ - Automatic cleanup of grants when teams are deleted (database cascade)
27
+
28
+ ### Middleware Integration
29
+
30
+ - Extended `autoAuthMiddleware` to support resource access checks
31
+ - Single-resource pre-handler validation for detail endpoints
32
+ - Automatic list filtering for collection endpoints
33
+ - S2S endpoints for access verification
34
+
35
+ ### Frontend Components
36
+
37
+ - `TeamsTab` component for managing teams in Auth Settings
38
+ - `TeamAccessEditor` component for assigning team access to resources
39
+ - Resource-level "Team Only" toggle in `TeamAccessEditor`
40
+ - Integration into System, Health Check, Incident, and Maintenance editors
41
+
42
+ ## Breaking Changes
43
+
44
+ ### API Response Format Changes
45
+
46
+ List endpoints now return objects with named keys instead of arrays directly:
47
+
48
+ ```typescript
49
+ // Before
50
+ const systems = await catalogApi.getSystems();
51
+
52
+ // After
53
+ const { systems } = await catalogApi.getSystems();
54
+ ```
55
+
56
+ Affected endpoints:
57
+
58
+ - `catalog.getSystems` → `{ systems: [...] }`
59
+ - `healthcheck.getConfigurations` → `{ configurations: [...] }`
60
+ - `incident.listIncidents` → `{ incidents: [...] }`
61
+ - `maintenance.listMaintenances` → `{ maintenances: [...] }`
62
+
63
+ ### User Identity Enrichment
64
+
65
+ `RealUser` and `ApplicationUser` types now include `teamIds: string[]` field with team memberships.
66
+
67
+ ## Documentation
68
+
69
+ See `docs/backend/teams.md` for complete API reference and integration guide.
70
+
71
+ ## 0.0.3
72
+
73
+ ### Patch Changes
74
+
75
+ - f5b1f49: Added generic `TransportClient` interface for health check strategy transport abstraction.
76
+
3
77
  ## 0.0.2
4
78
 
5
79
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/common",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -5,3 +5,5 @@ export * from "./plugin-metadata";
5
5
  export * from "./client-definition";
6
6
  export * from "./permission-utils";
7
7
  export * from "./icons";
8
+ export * from "./transport-client";
9
+ export * from "./json-schema";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Generic base JSON Schema property type.
3
+ * Uses a generic Self parameter for recursive properties to allow proper extension.
4
+ */
5
+ export interface JsonSchemaPropertyCore<
6
+ Self = JsonSchemaPropertyCore<unknown>
7
+ > {
8
+ type?: string;
9
+ description?: string;
10
+ enum?: string[];
11
+ const?: string | number | boolean;
12
+ properties?: Record<string, Self>;
13
+ items?: Self;
14
+ required?: string[];
15
+ additionalProperties?: boolean | Self;
16
+ format?: string;
17
+ default?: unknown;
18
+ oneOf?: Self[];
19
+ anyOf?: Self[];
20
+ }
21
+
22
+ /**
23
+ * Concrete base JSON Schema property type without extensions.
24
+ */
25
+ export type JsonSchemaPropertyBase =
26
+ JsonSchemaPropertyCore<JsonSchemaPropertyBase>;
27
+
28
+ /**
29
+ * Base JSON Schema type for object schemas.
30
+ */
31
+ export interface JsonSchemaBase<TProp = JsonSchemaPropertyBase> {
32
+ type?: string;
33
+ properties?: Record<string, TProp>;
34
+ required?: string[];
35
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generic transport client interface for remote command execution.
3
+ *
4
+ * Transport strategies (SSH, SNMP, WinRM) implement this interface to provide
5
+ * a consistent abstraction for collectors.
6
+ *
7
+ * @template TCommand - Command type (e.g., string for SSH, OidRequest for SNMP)
8
+ * @template TResult - Result type (e.g., { stdout, stderr, exitCode } for SSH)
9
+ */
10
+ export interface TransportClient<TCommand, TResult> {
11
+ /**
12
+ * Execute a command on the remote host.
13
+ * The command and result types are defined by the transport implementation.
14
+ */
15
+ exec(command: TCommand): Promise<TResult>;
16
+ }
package/src/types.ts CHANGED
@@ -2,6 +2,80 @@
2
2
  // RPC PROCEDURE METADATA
3
3
  // =============================================================================
4
4
 
5
+ /**
6
+ * Configuration for resource-level access control.
7
+ * Used to enforce fine-grained permissions based on team grants.
8
+ */
9
+ export interface ResourceAccessConfig {
10
+ /**
11
+ * The resource type identifier (e.g., "system", "healthcheck").
12
+ * Will be auto-prefixed with pluginId in middleware (e.g., "catalog.system").
13
+ */
14
+ resourceType: string;
15
+
16
+ /**
17
+ * Parameter name in request input to extract resource ID from.
18
+ * Uses dot notation for nested params (e.g., "params.id").
19
+ * Required for single-resource access checks.
20
+ */
21
+ idParam?: string;
22
+
23
+ /**
24
+ * Filter mode for list endpoints.
25
+ * - "single": Check access to a single resource (default)
26
+ * - "list": Post-filter result array based on team access
27
+ */
28
+ filterMode?: "single" | "list";
29
+
30
+ /**
31
+ * Key in response object containing the array to filter.
32
+ * Required when filterMode is "list".
33
+ * Example: "systems" for response { systems: [...] }
34
+ */
35
+ outputKey?: string;
36
+ }
37
+
38
+ /**
39
+ * Creates a ResourceAccessConfig for single-resource access checks.
40
+ *
41
+ * @param resourceType - The resource type (auto-prefixed with pluginId)
42
+ * @param idParam - Parameter path in input to extract resource ID from
43
+ */
44
+ export function createResourceAccess(
45
+ resourceType: string,
46
+ idParam: string
47
+ ): ResourceAccessConfig {
48
+ return { resourceType, idParam, filterMode: "single" };
49
+ }
50
+
51
+ /**
52
+ * Creates a ResourceAccessConfig for list filtering.
53
+ *
54
+ * @param resourceType - The resource type (auto-prefixed with pluginId)
55
+ * @param outputKey - Key in response object containing the array to filter
56
+ */
57
+ export function createResourceAccessList(
58
+ resourceType: string,
59
+ outputKey: string
60
+ ): ResourceAccessConfig {
61
+ return { resourceType, filterMode: "list", outputKey };
62
+ }
63
+
64
+ /**
65
+ * Qualifies a resource type with the plugin namespace.
66
+ * @param pluginId - The plugin identifier
67
+ * @param resourceType - The unqualified resource type
68
+ * @returns Qualified resource type (e.g., "catalog.system")
69
+ */
70
+ export function qualifyResourceType(
71
+ pluginId: string,
72
+ resourceType: string
73
+ ): string {
74
+ // If already qualified (contains a dot), return as-is
75
+ if (resourceType.includes(".")) return resourceType;
76
+ return `${pluginId}.${resourceType}`;
77
+ }
78
+
5
79
  /**
6
80
  * Metadata interface for RPC procedures.
7
81
  * Used by contracts to define auth requirements and by backend middleware to enforce them.
@@ -34,4 +108,10 @@ export interface ProcedureMetadata {
34
108
  * User must have at least one of the listed permissions, or "*" (wildcard).
35
109
  */
36
110
  permissions?: string[];
111
+
112
+ /**
113
+ * Resource-level access control configurations.
114
+ * When specified, middleware checks team-based grants for the resources.
115
+ */
116
+ resourceAccess?: ResourceAccessConfig[];
37
117
  }