From 538d7450233bbb9506524bc52c049484329d0952 Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:06:56 +0200 Subject: [PATCH] chore: format --- .../tm-core/src/auth/auth-manager.test.ts | 2 +- .../tm-core/src/auth/credential-store.test.ts | 75 ++++++++++++++----- packages/tm-core/src/auth/credential-store.ts | 16 ++-- packages/tm-core/src/config/config-manager.ts | 10 +-- .../src/interfaces/configuration.interface.ts | 4 +- 5 files changed, 73 insertions(+), 34 deletions(-) diff --git a/packages/tm-core/src/auth/auth-manager.test.ts b/packages/tm-core/src/auth/auth-manager.test.ts index 04178764..10ef85ef 100644 --- a/packages/tm-core/src/auth/auth-manager.test.ts +++ b/packages/tm-core/src/auth/auth-manager.test.ts @@ -40,7 +40,7 @@ describe('AuthManager Singleton', () => { const instance = AuthManager.getInstance(config); expect(instance).toBeDefined(); - + // Verify the config is passed to internal components // This would be observable when attempting operations that use the config // For example, getCredentials would look in the configured file path diff --git a/packages/tm-core/src/auth/credential-store.test.ts b/packages/tm-core/src/auth/credential-store.test.ts index 93330521..db044287 100644 --- a/packages/tm-core/src/auth/credential-store.test.ts +++ b/packages/tm-core/src/auth/credential-store.test.ts @@ -56,7 +56,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -79,7 +81,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -100,7 +104,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -120,7 +126,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -140,7 +148,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -160,7 +170,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -181,7 +193,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials(); @@ -203,7 +217,9 @@ describe('CredentialStore', () => { }; vi.mocked(fs.existsSync).mockReturnValue(true); - vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockCredentials)); + vi.mocked(fs.readFileSync).mockReturnValue( + JSON.stringify(mockCredentials) + ); const result = store.getCredentials({ allowExpired: true }); @@ -239,7 +255,8 @@ describe('CredentialStore', () => { ); // Check that the written data contains a valid ISO string - const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string; + const writtenData = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; const parsed = JSON.parse(writtenData); expect(typeof parsed.expiresAt).toBe('string'); expect(new Date(parsed.expiresAt).toISOString()).toBe(parsed.expiresAt); @@ -257,7 +274,8 @@ describe('CredentialStore', () => { store.saveCredentials(credentials); - const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string; + const writtenData = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; const parsed = JSON.parse(writtenData); expect(typeof parsed.expiresAt).toBe('string'); expect(new Date(parsed.expiresAt).getTime()).toBe(futureTimestamp); @@ -272,8 +290,12 @@ describe('CredentialStore', () => { savedAt: new Date().toISOString() }; - expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError); - expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format'); + expect(() => store.saveCredentials(credentials)).toThrow( + AuthenticationError + ); + expect(() => store.saveCredentials(credentials)).toThrow( + 'Invalid expiresAt format' + ); }); it('should reject NaN timestamp when saving', () => { @@ -285,8 +307,12 @@ describe('CredentialStore', () => { savedAt: new Date().toISOString() }; - expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError); - expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format'); + expect(() => store.saveCredentials(credentials)).toThrow( + AuthenticationError + ); + expect(() => store.saveCredentials(credentials)).toThrow( + 'Invalid expiresAt format' + ); }); it('should reject Infinity timestamp when saving', () => { @@ -298,8 +324,12 @@ describe('CredentialStore', () => { savedAt: new Date().toISOString() }; - expect(() => store.saveCredentials(credentials)).toThrow(AuthenticationError); - expect(() => store.saveCredentials(credentials)).toThrow('Invalid expiresAt format'); + expect(() => store.saveCredentials(credentials)).toThrow( + AuthenticationError + ); + expect(() => store.saveCredentials(credentials)).toThrow( + 'Invalid expiresAt format' + ); }); it('should handle missing expiresAt when saving', () => { @@ -313,7 +343,8 @@ describe('CredentialStore', () => { store.saveCredentials(credentials); - const writtenData = vi.mocked(fs.writeFileSync).mock.calls[0][1] as string; + const writtenData = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; const parsed = JSON.parse(writtenData); expect(parsed.expiresAt).toBeUndefined(); }); @@ -394,8 +425,12 @@ describe('CredentialStore', () => { store.cleanupCorruptFiles(); - expect(fs.unlinkSync).toHaveBeenCalledWith(expect.stringContaining(oldFile)); - expect(fs.unlinkSync).not.toHaveBeenCalledWith(expect.stringContaining(newFile)); + expect(fs.unlinkSync).toHaveBeenCalledWith( + expect.stringContaining(oldFile) + ); + expect(fs.unlinkSync).not.toHaveBeenCalledWith( + expect.stringContaining(newFile) + ); }); it('should handle cleanup errors gracefully', () => { @@ -411,4 +446,4 @@ describe('CredentialStore', () => { ); }); }); -}); \ No newline at end of file +}); diff --git a/packages/tm-core/src/auth/credential-store.ts b/packages/tm-core/src/auth/credential-store.ts index bb8fd015..024f0f37 100644 --- a/packages/tm-core/src/auth/credential-store.ts +++ b/packages/tm-core/src/auth/credential-store.ts @@ -32,7 +32,9 @@ export class CredentialStore { // Normalize/migrate timestamps to numeric (handles both number and ISO string) let expiresAtMs: number | undefined; if (typeof authData.expiresAt === 'number') { - expiresAtMs = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined; + expiresAtMs = Number.isFinite(authData.expiresAt) + ? authData.expiresAt + : undefined; } else if (typeof authData.expiresAt === 'string') { const parsed = Date.parse(authData.expiresAt); expiresAtMs = Number.isNaN(parsed) ? undefined : parsed; @@ -97,25 +99,27 @@ export class CredentialStore { // Add timestamp without mutating caller's object authData = { ...authData, savedAt: new Date().toISOString() }; - + // Validate and normalize expiresAt timestamp if (authData.expiresAt !== undefined) { let validTimestamp: number | undefined; - + if (typeof authData.expiresAt === 'number') { - validTimestamp = Number.isFinite(authData.expiresAt) ? authData.expiresAt : undefined; + validTimestamp = Number.isFinite(authData.expiresAt) + ? authData.expiresAt + : undefined; } else if (typeof authData.expiresAt === 'string') { const parsed = Date.parse(authData.expiresAt); validTimestamp = Number.isNaN(parsed) ? undefined : parsed; } - + if (validTimestamp === undefined) { throw new AuthenticationError( `Invalid expiresAt format: ${authData.expiresAt}`, 'SAVE_FAILED' ); } - + // Store as ISO string for consistency authData.expiresAt = new Date(validTimestamp).toISOString(); } diff --git a/packages/tm-core/src/config/config-manager.ts b/packages/tm-core/src/config/config-manager.ts index 5ef5003a..03bf41a1 100644 --- a/packages/tm-core/src/config/config-manager.ts +++ b/packages/tm-core/src/config/config-manager.ts @@ -154,10 +154,10 @@ export class ConfigManager { }; } - return { - type: storageType, - basePath, - apiConfigured: false + return { + type: storageType, + basePath, + apiConfigured: false }; } @@ -190,7 +190,7 @@ export class ConfigManager { /** * Check if explicitly configured to use API storage - * Excludes 'auto' type + * Excludes 'auto' type */ isApiExplicitlyConfigured(): boolean { return this.getStorageConfig().type === 'api'; diff --git a/packages/tm-core/src/interfaces/configuration.interface.ts b/packages/tm-core/src/interfaces/configuration.interface.ts index eecad240..f03c55db 100644 --- a/packages/tm-core/src/interfaces/configuration.interface.ts +++ b/packages/tm-core/src/interfaces/configuration.interface.ts @@ -112,8 +112,8 @@ export interface StorageSettings type: StorageType; /** Base path for file storage */ basePath?: string; - /** - * Indicates whether API is configured + /** + * Indicates whether API is configured * @computed Derived automatically from presence of apiEndpoint or apiAccessToken * @internal Should not be set manually in user config - computed by ConfigManager */