@checkstack/backend 0.5.2 → 0.5.3

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,43 @@
1
1
  # @checkstack/backend
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - d1a2796: Enforce stricter code quality standards and eliminate AI slop anti-patterns.
8
+
9
+ **New utility**
10
+
11
+ - `extractErrorMessage(error, fallback?)` in `@checkstack/common` for consistent error extraction
12
+
13
+ **ESLint rules**
14
+
15
+ - `react-hooks/rules-of-hooks` and `exhaustive-deps` for hook correctness
16
+ - `no-console` in frontend packages — forces `toast` over silent `console.error`
17
+ - `no-restricted-syntax` banning `instanceof Error` — forces `extractErrorMessage`
18
+ - Custom `no-eslint-disable-any` rule preventing `@typescript-eslint/no-explicit-any` circumvention
19
+
20
+ **Refactoring**
21
+
22
+ - Replace 141 `instanceof Error` boilerplate patterns across the codebase
23
+ - Replace swallowed `console.error` with user-visible `toast.error()` feedback
24
+ - Remove 15 redundant `as` type casts in IntegrationsPage and ProviderConnectionsPage
25
+ - Consolidate 3 identical callback handlers into `handleDialogClose`
26
+ - Fix conditional React hook call in `FormField.tsx`
27
+ - Fix unstable useMemo deps in `Dashboard.tsx`
28
+ - Replace `useEffect`→`setState` with derived `useMemo` in `RegisterPage.tsx`
29
+ - Rewrite `keystore.test.ts` with typed `DrizzleMockChain` (eliminating 7 `any` suppressions)
30
+ - Delete obvious comments in `encryption.ts` and Teams `provider.ts`
31
+
32
+ - Updated dependencies [d1a2796]
33
+ - @checkstack/common@0.6.5
34
+ - @checkstack/backend-api@0.11.1
35
+ - @checkstack/api-docs-common@0.1.9
36
+ - @checkstack/auth-common@0.6.1
37
+ - @checkstack/signal-backend@0.1.18
38
+ - @checkstack/signal-common@0.1.9
39
+ - @checkstack/queue-api@0.2.12
40
+
3
41
  ## 0.5.2
4
42
 
5
43
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/backend",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "checkstack": {
5
5
  "type": "backend"
6
6
  },
@@ -15,11 +15,11 @@
15
15
  "dependencies": {
16
16
  "@checkstack/api-docs-common": "0.1.8",
17
17
  "@checkstack/auth-common": "0.6.0",
18
- "@checkstack/backend-api": "0.10.0",
18
+ "@checkstack/backend-api": "0.11.0",
19
19
  "@checkstack/common": "0.6.4",
20
20
  "@checkstack/drizzle-helper": "0.0.4",
21
- "@checkstack/queue-api": "0.2.9",
22
- "@checkstack/signal-backend": "0.1.15",
21
+ "@checkstack/queue-api": "0.2.11",
22
+ "@checkstack/signal-backend": "0.1.17",
23
23
  "@checkstack/signal-common": "0.1.8",
24
24
  "@hono/zod-validator": "^0.7.6",
25
25
  "@orpc/client": "^1.13.14",
@@ -38,8 +38,8 @@
38
38
  "devDependencies": {
39
39
  "@types/pg": "^8.11.0",
40
40
  "@types/bun": "latest",
41
- "@checkstack/tsconfig": "0.0.4",
41
+ "@checkstack/tsconfig": "0.0.5",
42
42
  "@checkstack/scripts": "0.1.2",
43
- "@checkstack/test-utils-backend": "0.1.15"
43
+ "@checkstack/test-utils-backend": "0.1.17"
44
44
  }
45
45
  }
@@ -68,11 +68,15 @@ export function createApiRouteHandler({
68
68
  return await next(rest);
69
69
  } catch (error) {
70
70
  if (logger) {
71
- (logger as Logger).error(
72
- `RPC procedure error: ${String(error)}`,
73
- );
74
- if (error instanceof Error && error.stack) {
75
- (logger as Logger).error(`Stack trace: ${error.stack}`);
71
+ logger.error(`RPC procedure error: ${String(error)}`);
72
+ const stack =
73
+ error !== null &&
74
+ typeof error === "object" &&
75
+ "stack" in error
76
+ ? (error as { stack: string }).stack
77
+ : undefined;
78
+ if (stack) {
79
+ logger.error(`Stack trace: ${stack}`);
76
80
  }
77
81
  }
78
82
  throw error;
@@ -1,76 +1,74 @@
1
1
  import { describe, it, expect, mock, beforeEach } from "bun:test";
2
2
  import { KeyStore } from "./keystore";
3
3
 
4
- // 1. Mock the DB module
5
- const mockDb = {
6
- insert: mock(() => ({
4
+ /**
5
+ * Drizzle fluent-chain mock factory.
6
+ *
7
+ * Drizzle's API returns `this` from every query-builder method (select, from,
8
+ * where, …). The final object is thenable — awaiting it resolves the query.
9
+ * This factory builds a single object that satisfies that pattern without
10
+ * resorting to `any`.
11
+ */
12
+ interface DrizzleMockChain {
13
+ insert: ReturnType<typeof mock>;
14
+ values: ReturnType<typeof mock>;
15
+ update: ReturnType<typeof mock>;
16
+ set: ReturnType<typeof mock>;
17
+ delete: ReturnType<typeof mock>;
18
+ select: ReturnType<typeof mock>;
19
+ from: ReturnType<typeof mock>;
20
+ where: ReturnType<typeof mock>;
21
+ orderBy: ReturnType<typeof mock>;
22
+ limit: ReturnType<typeof mock>;
23
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
24
+ then: (resolve: (rows: unknown[]) => void) => void;
25
+ }
26
+
27
+ function createDrizzleMockChain(): DrizzleMockChain {
28
+ const chain: DrizzleMockChain = {
29
+ insert: mock(() => chain),
7
30
  values: mock(() => Promise.resolve()),
8
- })),
9
- select: mock(() => mockDb),
10
- from: mock(() => mockDb),
11
- where: mock(() => mockDb),
12
- orderBy: mock(() => mockDb),
13
- limit: mock(() => mockDb),
14
- };
15
-
16
- // Return empty list by default for selects
17
- // We will override implementation per test if needed
18
- // But since the chain returns `mockDb` (itself), the final await needs to return data.
19
- // Wait, `await db.select()...` means the object must be thenable or the last method returns a Promise.
20
- // Drizzle: .execute() or await directly.
21
- // In the code: `const validKeys = await db.select()...`
22
- // So the object returned by `limit()` must be thenable.
23
-
24
- const mockChain = () => {
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- const chain: any = {};
27
- chain.insert = mock(() => chain);
28
- chain.values = mock(() => Promise.resolve());
29
- chain.update = mock(() => chain);
30
- chain.set = mock(() => chain);
31
- chain.delete = mock(() => chain);
32
-
33
- chain.select = mock(() => chain);
34
- chain.from = mock(() => chain);
35
- chain.where = mock(() => chain);
36
- chain.orderBy = mock(() => chain);
37
- chain.limit = mock(() => chain); // limit is the last one called in getSigningKey
38
-
39
- // Make it thenable to simulate 'await'
40
- // eslint-disable-next-line unicorn/no-thenable, @typescript-eslint/no-explicit-any
41
- chain.then = (resolve: any) => resolve([]); // Default empty array
31
+ update: mock(() => chain),
32
+ set: mock(() => chain),
33
+ delete: mock(() => chain),
34
+ select: mock(() => chain),
35
+ from: mock(() => chain),
36
+ where: mock(() => chain),
37
+ orderBy: mock(() => chain),
38
+ limit: mock(() => chain),
39
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
40
+ then: (resolve) => resolve([]),
41
+ };
42
42
 
43
43
  return chain;
44
- };
44
+ }
45
45
 
46
- const dbMockInstance = mockChain();
46
+ const dbMock = createDrizzleMockChain();
47
47
 
48
- mock.module("../db", () => {
49
- return {
50
- db: dbMockInstance,
51
- };
52
- });
48
+ mock.module("../db", () => ({
49
+ db: dbMock,
50
+ }));
53
51
 
54
52
  describe("KeyStore", () => {
55
53
  let store: KeyStore;
56
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
- let mockKeyForGeneration: any;
54
+ let mockKeyForGeneration: Record<string, unknown>;
58
55
 
59
56
  beforeEach(async () => {
60
57
  store = new KeyStore();
58
+
61
59
  // Reset mocks
62
- dbMockInstance.select.mockClear();
63
- dbMockInstance.insert.mockClear();
64
- dbMockInstance.update.mockClear();
65
- dbMockInstance.set.mockClear();
66
- dbMockInstance.delete.mockClear();
67
- dbMockInstance.where.mockClear();
68
-
69
- // Reset default behavior
70
- // eslint-disable-next-line unicorn/no-thenable, @typescript-eslint/no-explicit-any
71
- dbMockInstance.then = (resolve: any) => resolve([]);
72
-
73
- // Pre-generate a valid key for mocking responses
60
+ dbMock.select.mockClear();
61
+ dbMock.insert.mockClear();
62
+ dbMock.update.mockClear();
63
+ dbMock.set.mockClear();
64
+ dbMock.delete.mockClear();
65
+ dbMock.where.mockClear();
66
+
67
+ // Reset default behavior — empty result set
68
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
69
+ dbMock.then = (resolve) => resolve([]);
70
+
71
+ // Pre-generate a valid RSA keypair for mock responses
74
72
  const { generateKeyPair, exportJWK } = await import("jose");
75
73
  const { publicKey, privateKey } = await generateKeyPair("RS256", {
76
74
  extractable: true,
@@ -90,10 +88,9 @@ describe("KeyStore", () => {
90
88
  });
91
89
 
92
90
  it("should generate a new key if no active key exists", async () => {
93
- // Mock DB returning empty array for existing keys first, then the new key
94
91
  let callCount = 0;
95
- // eslint-disable-next-line unicorn/no-thenable, @typescript-eslint/no-explicit-any
96
- dbMockInstance.then = (resolve: any) => {
92
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
93
+ dbMock.then = (resolve) => {
97
94
  callCount++;
98
95
  if (callCount === 1) {
99
96
  return resolve([]); // First call: no active key
@@ -103,9 +100,9 @@ describe("KeyStore", () => {
103
100
 
104
101
  const result = await store.getSigningKey();
105
102
 
106
- expect(result.kid).toBe("generated-kid"); // The mock key ID
103
+ expect(result.kid).toBe("generated-kid");
107
104
  expect(result.key).toBeTruthy();
108
- expect(dbMockInstance.insert).toHaveBeenCalled();
105
+ expect(dbMock.insert).toHaveBeenCalled();
109
106
  });
110
107
 
111
108
  it("should return the existing key if it is valid", async () => {
@@ -122,24 +119,21 @@ describe("KeyStore", () => {
122
119
  publicKey: JSON.stringify(publicJwk),
123
120
  privateKey: JSON.stringify(privateJwk),
124
121
  algorithm: "RS256",
125
- createdAt: new Date().toISOString(), // Fresh
122
+ createdAt: new Date().toISOString(),
126
123
  expiresAt: undefined,
127
124
  revokedAt: undefined,
128
125
  };
129
126
 
130
- // Mock DB return
131
- // eslint-disable-next-line unicorn/no-thenable, @typescript-eslint/no-explicit-any
132
- dbMockInstance.then = (resolve: any) => resolve([mockKeyRow]);
127
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
128
+ dbMock.then = (resolve) => resolve([mockKeyRow]);
133
129
 
134
130
  const result = await store.getSigningKey();
135
131
 
136
132
  expect(result.kid).toBe(kid);
137
- // Should NOT have called insert (no rotation)
138
- expect(dbMockInstance.insert).not.toHaveBeenCalled();
133
+ expect(dbMock.insert).not.toHaveBeenCalled();
139
134
  });
140
135
 
141
136
  it("should rotate key if the existing one is too old", async () => {
142
- // Generate a real key
143
137
  const { generateKeyPair, exportJWK } = await import("jose");
144
138
  const { publicKey, privateKey } = await generateKeyPair("RS256", {
145
139
  extractable: true,
@@ -148,7 +142,6 @@ describe("KeyStore", () => {
148
142
  const privateJwk = await exportJWK(privateKey);
149
143
  const kid = "old-kid";
150
144
 
151
- // Create an OLD date > 1 hour ago
152
145
  const oldDate = new Date(Date.now() - 1000 * 60 * 60 * 2).toISOString();
153
146
 
154
147
  const mockKeyRow = {
@@ -162,14 +155,12 @@ describe("KeyStore", () => {
162
155
  };
163
156
 
164
157
  let callCount = 0;
165
- // eslint-disable-next-line unicorn/no-thenable, @typescript-eslint/no-explicit-any
166
- dbMockInstance.then = (resolve: any) => {
158
+ // eslint-disable-next-line unicorn/no-thenable -- Required: Drizzle chains are awaitable via a custom .then()
159
+ dbMock.then = (resolve) => {
167
160
  callCount++;
168
161
  if (callCount === 1) {
169
- return resolve([mockKeyRow]); // First call: check active
162
+ return resolve([mockKeyRow]);
170
163
  }
171
- // Second call: fetch new key (in rotate logic)
172
- // We need to return a valid new key so it doesn't crash
173
164
  return resolve([
174
165
  {
175
166
  ...mockKeyRow,
@@ -181,10 +172,10 @@ describe("KeyStore", () => {
181
172
 
182
173
  const result = await store.getSigningKey();
183
174
 
184
- expect(result.kid).toBe("new-kid"); // Should return the NEW key
185
- expect(dbMockInstance.insert).toHaveBeenCalled();
186
- expect(dbMockInstance.update).toHaveBeenCalled(); // Should set expiresAt on old key
187
- expect(dbMockInstance.set).toHaveBeenCalledWith(
175
+ expect(result.kid).toBe("new-kid");
176
+ expect(dbMock.insert).toHaveBeenCalled();
177
+ expect(dbMock.update).toHaveBeenCalled();
178
+ expect(dbMock.set).toHaveBeenCalledWith(
188
179
  expect.objectContaining({ expiresAt: expect.any(String) })
189
180
  );
190
181
  });
@@ -192,7 +183,7 @@ describe("KeyStore", () => {
192
183
  it("should delete expired keys in cleanupKeys", async () => {
193
184
  await store.cleanupKeys();
194
185
 
195
- expect(dbMockInstance.delete).toHaveBeenCalled();
196
- expect(dbMockInstance.where).toHaveBeenCalled();
186
+ expect(dbMock.delete).toHaveBeenCalled();
187
+ expect(dbMock.where).toHaveBeenCalled();
197
188
  });
198
189
  });
@@ -9,6 +9,7 @@ import type { QueuePluginRegistryImpl } from "./queue-plugin-registry";
9
9
  import type { Logger, ConfigService } from "@checkstack/backend-api";
10
10
  import { z } from "zod";
11
11
  import { QueueProxy } from "./queue-proxy";
12
+ import { extractErrorMessage } from "@checkstack/common";
12
13
 
13
14
  // Schema for active plugin pointer with version for multi-instance coordination
14
15
  const activePluginPointerSchema = z.object({
@@ -151,7 +152,7 @@ export class QueueManagerImpl implements QueueManager {
151
152
  await testQueue.stop();
152
153
  this.logger.info("✅ Connection test successful");
153
154
  } catch (error) {
154
- const message = error instanceof Error ? error.message : String(error);
155
+ const message = extractErrorMessage(error);
155
156
  this.logger.error(`❌ Connection test failed: ${message}`);
156
157
  throw new Error(`Failed to connect to queue: ${message}`);
157
158
  }