Repository: n8n-io/n8n
File: packages/cli/src/modules/external-secrets.ee/secrets-providers-connections.service.ee.ts (TypeScript)

Code before:

	async getProjectCompletions(projectId: string): Promise<SecretsProviderConnection[]> {
		return await this.repository.findByProjectId(projectId);
	}

	async listConnectionsForProject(projectId: string): Promise<SecretsProviderConnection[]> {
		return await this.repository.findAllAccessibleByProjectWithProjectAccess(projectId);
	}

	toSecretCompletionsResponse(connections: SecretsProviderConnection[]): SecretCompletionsResponse {
		return Object.fromEntries(
			connections.map((connection) => [
				connection.providerKey,
				this.externalSecretsManager.getSecretNames(connection.providerKey),
			]),
		);
	}

	toPublicConnectionListItem(
		connection: SecretsProviderConnection,
	): SecretsProvidersResponses.ConnectionListItem {
		return {
			id: String(connection.id),
			name: connection.providerKey,
			type: connection.type as SecretsProviderType,
			secretsCount: this.externalSecretsManager.getSecretNames(connection.providerKey).length,
			projects: connection.projectAccess.map((access) => ({
				id: access.project.id,
				name: access.project.name,
			})),
			createdAt: connection.createdAt.toISOString(),
			updatedAt: connection.updatedAt.toISOString(),
		};
	}

	toPublicConnection(connection: SecretsProviderConnection): SecretsProvidersResponses.Connection {
		const decryptedSettings = this.decryptConnectionSettings(connection.encryptedSettings);
		const { provider } = this.externalSecretsManager.getProviderWithSettings(connection.type);
		const redactedSettings = this.redactionService.redact(decryptedSettings, provider.properties);
		const secretNames = this.externalSecretsManager.getSecretNames(connection.providerKey);

		return {
			id: String(connection.id),
			name: connection.providerKey,
			type: connection.type as SecretsProviderType,
			secretsCount: secretNames.length,
			secrets: secretNames.map((name) => ({ name })),
			projects: connection.projectAccess.map((access) => ({
				id: access.project.id,
				name: access.project.name,
			})),

Review comment (security):
Nit: `secretsCount: secretNames.length` having a `secretNames` const like below would make it more readable imo

Code after:

	async getProjectCompletions(projectId: string): Promise<SecretsProviderConnection[]> {
		return await this.repository.findByProjectId(projectId);
	}

	async listConnectionsForProject(projectId: string): Promise<SecretsProviderConnection[]> {
		return await this.repository.findAllAccessibleByProjectWithProjectAccess(projectId);
	}

	toSecretCompletionsResponse(connections: SecretsProviderConnection[]): SecretCompletionsResponse {
		return Object.fromEntries(
			connections.map((connection) => [
				connection.providerKey,
				this.externalSecretsManager.getSecretNames(connection.providerKey),
			]),
		);
	}

	toPublicConnectionListItem(
		connection: SecretsProviderConnection,
	): SecretsProvidersResponses.ConnectionListItem {
		const secretNames = this.externalSecretsManager.getSecretNames(connection.providerKey);

		return {
			id: String(connection.id),
			name: connection.providerKey,
			type: connection.type as SecretsProviderType,
			secretsCount: secretNames.length,
			projects: connection.projectAccess.map((access) => ({
				id: access.project.id,
				name: access.project.name,
			})),
			createdAt: connection.createdAt.toISOString(),
			updatedAt: connection.updatedAt.toISOString(),
		};
	}

	toPublicConnection(connection: SecretsProviderConnection): SecretsProvidersResponses.Connection {
		const decryptedSettings = this.decryptConnectionSettings(connection.encryptedSettings);
		const { provider } = this.externalSecretsManager.getProviderWithSettings(connection.type);
		const redactedSettings = this.redactionService.redact(decryptedSettings, provider.properties);
		const secretNames = this.externalSecretsManager.getSecretNames(connection.providerKey);

		return {
			id: String(connection.id),
			name: connection.providerKey,
			type: connection.type as SecretsProviderType,
			secretsCount: secretNames.length,
			secrets: secretNames.map((name) => ({ name })),
			projects: connection.projectAccess.map((access) => ({
				id: access.project.id,