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:
shumeiko.it
2026-10-24 16:34:20 +02:00
parent 23431550ae
commit 3528a242f6
60 changed files with 602 additions and 606 deletions

View File

@@ -1,7 +1,10 @@
import type { FastifyInstance } from 'fastify';
import type { ConnectorHealth } from '@waggle/shared';
import type { RecordAuditInput } from '@waggle/core';
import { JiraConnector, SalesforceConnector } from '@waggle/agent';
import {
JiraConnector, SalesforceConnector,
getConnectorCredential, setConnectorCredential, setConnectorCredentialBundle,
} from '@waggle/agent';
/** Vault sub-key holding the C16 manual-sync stamp. Matches the
* `connector:{id}:*` prefix so disconnect/revoke auto-clean it. */
@@ -80,7 +83,7 @@ export async function connectorRoutes(fastify: FastifyInstance) {
}
// Fallback: basic health without registry
const cred = fastify.vault?.getConnectorCredential(id);
const cred = fastify.vault ? getConnectorCredential(fastify.vault, id) : null;
const lastSyncAt = fastify.vault?.get(lastSyncKey(id))?.value;
const health: ConnectorHealth = {
id,
@@ -161,12 +164,12 @@ export async function connectorRoutes(fastify: FastifyInstance) {
};
if (jiraEmail && jiraBaseUrl) {
fastify.vault.setConnectorCredentialBundle(id, credential, {
setConnectorCredentialBundle(fastify.vault, id, credential, {
email: jiraEmail,
base_url: jiraBaseUrl,
});
} else {
fastify.vault.setConnectorCredential(id, credential);
setConnectorCredential(fastify.vault, id, credential);
}
if (salesforceInstanceUrl) {