refactor(agent): move the connector credential helpers out of VaultStore (P1.2)
getConnectorCredential, setConnectorCredential and setConnectorCredentialBundle are now plain functions over a SecretStore in packages/agent/src/connectors/connector-credentials.ts. The secret names, metadata layout and the rule that tokens never go into plaintext metadata are unchanged, so existing vault files keep working. A bundle still lands as one update: SecretStore gains writeBatch, which VaultStore applies with a single vault-file replacement. Connector tests seed a Map-backed SecretStore instead of mocking VaultStore methods; the helper tests from core and server moved to the agent package.
This commit is contained in:
@@ -8,7 +8,7 @@ import { BitbucketConnector } from '../../src/connectors/bitbucket-connector.js'
|
||||
import { DropboxConnector } from '../../src/connectors/dropbox-connector.js';
|
||||
import { PostgresConnector } from '../../src/connectors/postgres-connector.js';
|
||||
import { safeFetch } from '../../src/url-egress-guard.js';
|
||||
import type { VaultStore } from '@waggle/core';
|
||||
import { createMemorySecretStore, seedCredential, type MockSecretStore } from '../helpers/memory-secret-store.js';
|
||||
|
||||
vi.mock('../../src/url-egress-guard.js', () => ({
|
||||
safeFetch: vi.fn((url: string, init?: RequestInit) => globalThis.fetch(url, {
|
||||
@@ -17,23 +17,11 @@ vi.mock('../../src/url-egress-guard.js', () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
function createMockVault(connectorId: string, cred?: { value: string; isExpired: boolean }, extras?: Record<string, string>): VaultStore {
|
||||
return {
|
||||
getConnectorCredential: vi.fn((id: string) => {
|
||||
if (id === connectorId && cred) return { ...cred, type: 'bearer' };
|
||||
return null;
|
||||
}),
|
||||
get: vi.fn((key: string) => {
|
||||
if (extras && extras[key]) return { value: extras[key] };
|
||||
return null;
|
||||
}),
|
||||
set: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
list: vi.fn(() => []),
|
||||
has: vi.fn(() => false),
|
||||
setConnectorCredential: vi.fn(),
|
||||
migrateFromConfig: vi.fn(() => 0),
|
||||
} as unknown as VaultStore;
|
||||
function createMockVault(connectorId: string, cred?: { value: string; isExpired: boolean }, extras?: Record<string, string>): MockSecretStore {
|
||||
return createMemorySecretStore({
|
||||
connectors: cred ? { [connectorId]: seedCredential(cred) } : {},
|
||||
secrets: extras,
|
||||
});
|
||||
}
|
||||
|
||||
// ── CRM Connectors ──────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user