From f56fb31bfae29f077eeebbb0d9d7dfd30962b229 Mon Sep 17 00:00:00 2001 From: Jan Leon Date: Mon, 29 Jun 2026 17:05:32 +0200 Subject: [PATCH] chore: remove unused api key format helpers (#5359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integrated into release/v3.8.41 — dead-code removal (typecheck:core EXIT 0, 102 affected tests green, fabricated-docs clean). Thanks @JxnLexn. --- src/shared/utils/apiKey.ts | 26 ----------------- .../unit/api-key-utils-public-surface.test.ts | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 tests/unit/api-key-utils-public-surface.test.ts diff --git a/src/shared/utils/apiKey.ts b/src/shared/utils/apiKey.ts index 1b60814bb4..c339af0480 100644 --- a/src/shared/utils/apiKey.ts +++ b/src/shared/utils/apiKey.ts @@ -90,29 +90,3 @@ export function parseApiKey( return null; } - -/** - * Verify API key CRC (only for new format) - * @param {string} apiKey - * @returns {boolean} - */ -export function verifyApiKeyCrc(apiKey: string): boolean { - const parsed = parseApiKey(apiKey); - if (!parsed) return false; - - // Old format doesn't have CRC, always valid if parsed - if (!parsed.isNewFormat) return true; - - // New format already verified in parseApiKey - return true; -} - -/** - * Check if API key is new format (contains machineId) - * @param {string} apiKey - * @returns {boolean} - */ -export function isNewFormatKey(apiKey: string): boolean { - const parsed = parseApiKey(apiKey); - return parsed?.isNewFormat === true; -} diff --git a/tests/unit/api-key-utils-public-surface.test.ts b/tests/unit/api-key-utils-public-surface.test.ts new file mode 100644 index 0000000000..509ac0ad0e --- /dev/null +++ b/tests/unit/api-key-utils-public-surface.test.ts @@ -0,0 +1,29 @@ +import test from "node:test"; +import assert from "node:assert/strict"; + +process.env.API_KEY_SECRET = "test-api-key-utils-secret"; + +const apiKeyUtils = await import("../../src/shared/utils/apiKey.ts"); + +test("api key utility public surface keeps generation and parsing only", () => { + const machineId = "testmachine"; + const { key, keyId } = apiKeyUtils.generateApiKeyWithMachine(machineId); + + assert.equal(typeof key, "string"); + assert.equal(typeof keyId, "string"); + assert.match(key, new RegExp(`^sk-${machineId}-${keyId}-[a-f0-9]{8}$`)); + assert.deepEqual(apiKeyUtils.parseApiKey(key), { + machineId, + keyId, + isNewFormat: true, + }); + assert.deepEqual(apiKeyUtils.parseApiKey("sk-legacykey"), { + machineId: null, + keyId: "legacykey", + isNewFormat: false, + }); + assert.equal(apiKeyUtils.parseApiKey("not-a-key"), null); + + assert.equal("verifyApiKeyCrc" in apiKeyUtils, false); + assert.equal("isNewFormatKey" in apiKeyUtils, false); +});