feat(config): Restructure .taskmasterconfig and enhance gateway integration
Config Structure Changes and Gateway Integration ## Configuration Structure Changes - Restructured .taskmasterconfig to use 'account' section for user settings - Moved userId, userEmail, mode, telemetryEnabled from global to account section - API keys remain isolated in .env file (not accessible to AI) - Enhanced getUserId() to always return value, never null (sets default '1234567890') ## Gateway Integration Enhancements - Updated registerUserWithGateway() to accept both email and userId parameters - Enhanced /auth/init endpoint integration for existing user validation - API key updates automatically written to .env during registration process - Improved user identification and validation flow ## Code Updates for New Structure - Fixed config-manager.js getter functions for account section access - Updated user-management.js to use config.account.userId/mode - Modified telemetry-submission.js to read from account section - Added getTelemetryEnabled() function with proper account section access - Enhanced telemetry configuration reading with new structure ## Comprehensive Test Updates - Updated integration tests (init-config.test.js) for new config structure - Fixed unit tests (config-manager.test.js) with updated default config - Updated telemetry tests (telemetry-submission.test.js) for account structure - Added missing getTelemetryEnabled mock to ai-services-unified.test.js - Fixed all test expectations to use config.account.* instead of config.global.* - Removed references to deprecated config.subscription object ## Configuration Access Consistency - Standardized configuration access patterns across entire codebase - Clean separation: user settings in account, API keys in .env, models/global in respective sections - All tests passing with new configuration structure - Maintained backward compatibility during transition Changes support enhanced telemetry system with proper user management and gateway integration while maintaining security through API key isolation.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { z } from "zod";
|
||||
import { getConfig } from "./config-manager.js";
|
||||
import { getTelemetryEnabled } from "./config-manager.js";
|
||||
import { resolveEnvVariable } from "./utils.js";
|
||||
|
||||
// Telemetry data validation schema
|
||||
@@ -54,7 +55,7 @@ function getTelemetryConfig() {
|
||||
|
||||
return {
|
||||
apiKey: envApiKey || null, // API key should only come from environment
|
||||
userId: envUserId || config?.global?.userId || null,
|
||||
userId: envUserId || config?.account?.userId || null,
|
||||
email: envEmail || null,
|
||||
};
|
||||
}
|
||||
@@ -62,16 +63,21 @@ function getTelemetryConfig() {
|
||||
/**
|
||||
* Register or lookup user with the TaskMaster telemetry gateway using /auth/init
|
||||
* @param {string} email - User's email address
|
||||
* @param {string} userId - User's ID
|
||||
* @returns {Promise<{success: boolean, apiKey?: string, userId?: string, email?: string, isNewUser?: boolean, error?: string}>}
|
||||
*/
|
||||
export async function registerUserWithGateway(email) {
|
||||
export async function registerUserWithGateway(email = null, userId = null) {
|
||||
try {
|
||||
const requestBody = {};
|
||||
if (email) requestBody.email = email;
|
||||
if (userId) requestBody.userId = userId;
|
||||
|
||||
const response = await fetch(TASKMASTER_USER_REGISTRATION_ENDPOINT, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ email }),
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -114,8 +120,7 @@ export async function registerUserWithGateway(email) {
|
||||
export async function submitTelemetryData(telemetryData) {
|
||||
try {
|
||||
// Check user opt-out preferences first
|
||||
const config = getConfig();
|
||||
if (config && config.telemetryEnabled === false) {
|
||||
if (!getTelemetryEnabled()) {
|
||||
return {
|
||||
success: true,
|
||||
skipped: true,
|
||||
|
||||
Reference in New Issue
Block a user