Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions packages/contentstack-auth/src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
log.debug('LoginCommand run method started', this.contextDetails);

try {
log.debug('Initializing management API client', this.contextDetails);
log.debug('Initializing the Management API client.', this.contextDetails);
const managementAPIClient = await managementSDKClient({ host: this.cmaHost, skipTokenValidity: true });
log.debug('Management API client initialized successfully', this.contextDetails);
log.debug('Management API client initialized successfully.', this.contextDetails);

const { flags: loginFlags } = await this.parse(LoginCommand);
log.debug('Token add flags parsed', { ...this.contextDetails, flags: loginFlags });
log.debug('Token add flags parsed.', { ...this.contextDetails, flags: loginFlags });

authHandler.client = managementAPIClient;
log.debug('Auth handler client set', this.contextDetails);
Expand All @@ -86,7 +86,7 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
await this.login(username, password);
}
} catch (error) {
log.debug('Login command failed', {
log.debug('Login failed.', {
...this.contextDetails,
error,
});
Expand Down Expand Up @@ -116,26 +116,26 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
}

const user: User = await authHandler.login(username, password, tfaToken);
log.debug('Auth handler login completed', {
log.debug('Auth handler login completed.', {
...this.contextDetails,
hasUser: !!user,
hasAuthToken: !!user?.authtoken,
userEmail: user?.email,
});

if (typeof user !== 'object' || !user.authtoken || !user.email) {
log.debug('Login failed - invalid user response', { ...this.contextDetails, user });
throw new CLIError('Failed to login - invalid response');
log.debug('Login failed: Invalid user response', { ...this.contextDetails, user });
throw new CLIError('Login failed: Invalid response.');
}

log.debug('Setting config data for basic auth', this.contextDetails);
log.debug('Setting configuration data for basic authentication.', this.contextDetails);
await oauthHandler.setConfigData('basicAuth', user);
log.debug('Config data set successfully', this.contextDetails);
log.debug('Configuration data set successfully.', this.contextDetails);

log.success(messageHandler.parse('CLI_AUTH_LOGIN_SUCCESS'), this.contextDetails);
log.debug('Login process completed successfully', this.contextDetails);
log.debug('Login completed successfully.', this.contextDetails);
} catch (error) {
log.debug('Login process failed', { ...this.contextDetails, error });
log.debug('Login failed.', { ...this.contextDetails, error });
throw error;
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/contentstack-auth/src/commands/auth/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
}

try {
log.debug('Initializing management API client for logout', this.contextDetails);
log.debug('Initializing the Management API client for logout.', this.contextDetails);
const managementAPIClient = await managementSDKClient({ host: this.cmaHost, skipTokenValidity: true });
log.debug('Management API client initialized successfully', this.contextDetails);

Expand All @@ -75,9 +75,9 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
if (await oauthHandler.isAuthorisationTypeBasic()) {
log.debug('Using basic authentication for logout', this.contextDetails);
const authToken = configHandler.get('authtoken');
log.debug('Retrieved auth token for logout', { ...this.contextDetails, hasAuthToken: !!authToken });
log.debug('Authentication token retrieved for logout.', { ...this.contextDetails, hasAuthToken: !!authToken });
await authHandler.logout(authToken);
log.debug('Basic auth logout completed', this.contextDetails);
log.debug('Basic authentication logout completed.', this.contextDetails);
} else if (await oauthHandler.isAuthorisationTypeOAuth()) {
log.debug('Using OAuth authentication for logout', this.contextDetails);
await oauthHandler.oauthLogout();
Expand All @@ -86,7 +86,7 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {

cliux.loader('');
log.success(messageHandler.parse('CLI_AUTH_LOGOUT_SUCCESS'), this.contextDetails);
log.debug('Logout process completed successfully', this.contextDetails);
log.debug('Logout completed successfully.', this.contextDetails);
} else {
log.debug('User not confirmed or not authenticated, skipping logout', {
...this.contextDetails,
Expand All @@ -96,14 +96,14 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
log.success(messageHandler.parse('CLI_AUTH_LOGOUT_ALREADY'), this.contextDetails);
}
} catch (error) {
log.debug('Logout command failed', { ...this.contextDetails, error: error.message });
log.debug('Logout failed.', { ...this.contextDetails, error: error.message });
cliux.print('CLI_AUTH_LOGOUT_FAILED', { color: 'yellow' });
handleAndLogError(error, { ...this.contextDetails });
} finally {
if (confirm === true) {
log.debug('Setting config data for logout', this.contextDetails);
log.debug('Setting configuration data for logout.', this.contextDetails);
await oauthHandler.setConfigData('logout');
log.debug('Config data set for logout', this.contextDetails);
log.debug('Configuration data set for logout.', this.contextDetails);
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions packages/contentstack-auth/src/commands/auth/tokens/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
'auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]';

async run(): Promise<any> {
log.debug('TokensAddCommand run method started', this.contextDetails);
log.debug('TokensAddCommand run method started.', this.contextDetails);
this.contextDetails.module = 'tokens-add';

const { flags: addTokenFlags } = await this.parse(TokensAddCommand);
log.debug('Token add flags parsed', { ...this.contextDetails, flags: addTokenFlags });
log.debug('Token add flags parsed.', { ...this.contextDetails, flags: addTokenFlags });

let isAliasExist = false;
const skipAliasReplaceConfirmation = addTokenFlags.force || addTokenFlags.yes;
Expand Down Expand Up @@ -141,7 +141,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman

if (!shouldAliasReplace) {
log.debug('User declined alias replacement, exiting', this.contextDetails);
log.info('Exiting from the process of replacing the token', this.contextDetails);
log.info('Exiting the token replacement process.', this.contextDetails);
cliux.print('CLI_AUTH_EXIT_PROCESS');
return;
}
Expand All @@ -150,13 +150,13 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
if (!apiKey) {
log.debug('No API key provided, requesting user input', this.contextDetails);
apiKey = await cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_API_KEY', name: 'apiKey' });
log.debug('API key obtained', { ...this.contextDetails, hasApiKey: !!apiKey });
log.debug('API key obtained.', { ...this.contextDetails, hasApiKey: !!apiKey });
}

if (!token) {
log.debug('No token provided, requesting user input', this.contextDetails);
token = await cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_TOKEN', name: 'token' });
log.debug('Token obtained', { ...this.contextDetails, hasToken: !!token });
log.debug('Token obtained.', { ...this.contextDetails, hasToken: !!token });
}

if (isDelivery && !environment) {
Expand All @@ -183,12 +183,12 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
// FIXME - Once the SDK refresh token issue is resolved, need to revert this back to SDK call
const httpClient = new HttpClient({ headers: { api_key: apiKey, authorization: token } });

log.debug('Making management token validation API call', this.contextDetails);
log.debug('Making management token validation API call.', this.contextDetails);
const response = (await httpClient.get(`https://${this.cmaHost}/v3/environments?limit=1`)).data;
log.debug('Management token validation response received', { ...this.contextDetails, response });
log.debug('Management token validation response received.', { ...this.contextDetails, response });

if (response?.error_code === 105) {
log.debug('Management token validation failed - invalid token', this.contextDetails);
log.debug('Management token validation failed: invalid token.', this.contextDetails);
throw new Error(messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN'));
} else if (response?.error_message) {
log.debug('Management token validation failed with error message', {
Expand All @@ -197,7 +197,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
});
throw new Error(response.error_message);
}
log.debug('Management token validation successful', this.contextDetails);
log.debug('Management token validation successful.', this.contextDetails);
}

log.debug('Saving token to configuration', {
Expand All @@ -208,23 +208,23 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
});
if (isManagement) {
configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, type });
log.debug('Management token saved to configuration', this.contextDetails);
log.debug('Management token saved to configuration.', this.contextDetails);
} else {
configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, environment, type });
log.debug('Delivery token saved to configuration', this.contextDetails);
log.debug('Delivery token saved to configuration.', this.contextDetails);
}

if (isAliasExist) {
log.debug('Token replaced successfully', this.contextDetails);
log.debug('Token replaced successfully.', this.contextDetails);
cliux.success('CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS');
} else {
log.debug('Token added successfully', this.contextDetails);
log.debug('Token added successfully.', this.contextDetails);
cliux.success('CLI_AUTH_TOKENS_ADD_SUCCESS');
}

log.debug('Token add process completed successfully', this.contextDetails);
log.debug('Token addition process completed successfully.', this.contextDetails);
} catch (error) {
log.debug('Token add process failed', { ...this.contextDetails, error });
log.debug('Token addition process failed.', { ...this.contextDetails, error });
cliux.print('CLI_AUTH_TOKENS_ADD_FAILED', { color: 'yellow' });
handleAndLogError(error, { ...this.contextDetails });
}
Expand Down
20 changes: 10 additions & 10 deletions packages/contentstack-auth/src/commands/auth/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
]); // use the cli table flags as it displays tokens in table

async run(): Promise<any> {
log.debug('TokensListCommand run method started', this.contextDetails);
log.debug('TokensListCommand run method started.', this.contextDetails);
this.contextDetails.module = 'tokens-list';

try {
log.debug('Retrieving tokens from configuration', this.contextDetails);
log.debug('Retrieving tokens from configuration.', this.contextDetails);
const managementTokens = configHandler.get('tokens');
log.debug('Tokens retrieved from configuration', {...this.contextDetails, tokenCount: managementTokens ? Object.keys(managementTokens).length : 0 });
log.debug('Tokens retrieved from configuration.', {...this.contextDetails, tokenCount: managementTokens ? Object.keys(managementTokens).length : 0 });

const tokens: Record<string, unknown>[] = [];
if (managementTokens && Object.keys(managementTokens).length > 0) {
log.debug('Processing tokens for display', this.contextDetails);
log.debug('Processing tokens for display.', this.contextDetails);
Object.keys(managementTokens).forEach(function (item) {
tokens.push({
alias: item,
Expand All @@ -46,7 +46,7 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
});

const { flags } = await this.parse(TokensListCommand);
log.debug('Tokens list flags parsed', {...this.contextDetails, flags });
log.debug('Token list flags parsed.', {...this.contextDetails, flags });

const headers = [
{
Expand All @@ -66,17 +66,17 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
},
];

log.debug('Displaying tokens table', {...this.contextDetails, tokenCount: tokens.length });
log.debug('Displaying token table.', {...this.contextDetails, tokenCount: tokens.length });
cliux.table(headers, tokens, flags as TableFlags);
log.debug('Tokens table displayed successfully', this.contextDetails);
log.debug('Token table displayed successfully.', this.contextDetails);
} else {
log.debug('No tokens found in configuration', this.contextDetails);
log.debug('No tokens found in configuration.', this.contextDetails);
cliux.print('CLI_AUTH_TOKENS_LIST_NO_TOKENS');
}

log.debug('Tokens list command completed successfully', this.contextDetails);
log.debug('Token list command completed successfully.', this.contextDetails);
} catch (error) {
log.debug('Tokens list command failed', {...this.contextDetails, error });
log.debug('Token list command failed.', {...this.contextDetails, error });
cliux.print('CLI_AUTH_TOKENS_LIST_FAILED', { color: 'yellow' });
handleAndLogError(error, { ...this.contextDetails });
}
Expand Down
28 changes: 14 additions & 14 deletions packages/contentstack-auth/src/commands/auth/tokens/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
this.contextDetails.module = 'tokens-remove';

const { flags: removeTokenFlags } = await this.parse(TokensRemoveCommand);
log.debug('Token remove flags parsed', {...this.contextDetails, flags: removeTokenFlags });
log.debug('Token removal flags parsed.', {...this.contextDetails, flags: removeTokenFlags });

const alias = removeTokenFlags.alias;
const ignore = removeTokenFlags.ignore;
log.debug('Token removal parameters', {...this.contextDetails, alias, ignore });
log.debug('Token removal parameters set.', {...this.contextDetails, alias, ignore });

try {
log.debug('Retrieving token from configuration', {...this.contextDetails, alias });
log.debug('Retrieving token from configuration.', {...this.contextDetails, alias });
const token = configHandler.get(`tokens.${alias}`);
log.debug('Token retrieved from configuration', {...this.contextDetails, hasToken: !!token, tokenType: token?.type });
log.debug('Token retrieved from configuration.', {...this.contextDetails, hasToken: !!token, tokenType: token?.type });

const tokens = configHandler.get('tokens');
log.debug('All tokens retrieved from configuration', {...this.contextDetails, tokenCount: tokens ? Object.keys(tokens).length : 0 });
log.debug('All tokens retrieved from configuration.', {...this.contextDetails, tokenCount: tokens ? Object.keys(tokens).length : 0 });

const tokenOptions: Array<string> = [];

if (token || ignore) {
log.debug('Token found or ignore flag set, proceeding with removal', {...this.contextDetails, hasToken: !!token, ignore });
log.debug('Token found, or ignore flag set.', {...this.contextDetails, hasToken: !!token, ignore });
configHandler.delete(`tokens.${alias}`);
log.debug('Token removed from configuration', {...this.contextDetails, alias });
log.debug('Token removed from configuration.', {...this.contextDetails, alias });
return cliux.success(`CLI_AUTH_TOKENS_REMOVE_SUCCESS`);
}

if (tokens && Object.keys(tokens).length > 0) {
log.debug('Building token options for user selection', this.contextDetails);
log.debug('Building token options for user selection.', this.contextDetails);
Object.keys(tokens).forEach(function (item) {
const tokenOption = `${item}: ${tokens[item].token} : ${tokens[item].apiKey}${
tokens[item].environment ? ' : ' + tokens[item].environment + ' ' : ''
Expand All @@ -48,11 +48,11 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
});
log.debug(`Token options built: ${tokenOptions.length} options`, this.contextDetails);
} else {
log.debug('No tokens found in configuration', this.contextDetails);
log.debug('No tokens found in configuration.', this.contextDetails);
return cliux.print('CLI_AUTH_TOKENS_NOT_FOUND');
}

log.debug('Requesting user to select tokens for removal', this.contextDetails);
log.debug('Requesting user to select tokens for removal.', this.contextDetails);
const selectedTokens: Array<any> = await cliux.inquire({
name: 'selectedTokens',
message: 'CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN',
Expand All @@ -62,15 +62,15 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
log.debug(`User selected ${selectedTokens.length} tokens for removal`, {...this.contextDetails, selectedTokens });

if (selectedTokens.length === 0) {
log.debug('No tokens selected for removal, exiting', this.contextDetails);
log.debug('No tokens selected for removal.', this.contextDetails);
return;
}

selectedTokens.forEach((ele)=>{
log.info(`Selected token: ${ele}`, this.contextDetails);
})

log.debug('Removing selected tokens from configuration', this.contextDetails);
log.debug('Removing selected tokens from configuration.', this.contextDetails);
selectedTokens.forEach((element) => {
const selectedToken = element.split(':')[0];
log.debug(`Removing token: ${selectedToken}`, this.contextDetails);
Expand All @@ -79,9 +79,9 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
log.info(`Token removed: ${selectedToken}`, this.contextDetails);
});

log.debug('Token removal process completed successfully', this.contextDetails);
log.debug('Token removal completed successfully.', this.contextDetails);
} catch (error) {
log.debug('Token removal process failed', {...this.contextDetails, error });
log.debug('Token removal failed.', {...this.contextDetails, error });
cliux.print('CLI_AUTH_TOKENS_REMOVE_FAILED', { color: 'yellow' });
handleAndLogError(error, {...this.contextDetails} )
}
Expand Down
Loading
Loading