Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fileignoreconfig:
- filename: packages/contentstack-audit/src/modules/content-types.ts
checksum: ddf7b08e6a80af09c6a7019a637c26089fb76572c7c3d079a8af244b02985f16
- filename: packages/contentstack-import/test/unit/commands/cm/stacks/import.test.ts
checksum: b11e57f1b824d405f86438e9e7c59183f8c59b66b42d8d16dbeaf76195a30548
checksum: ead3c34bad34f912d8663599273d26a95bb48220e16d9e9e3d33f5c064a487a5
- filename: packages/contentstack-import/test/unit/utils/asset-helper.test.ts
checksum: 8e83200ac8028f9289ff1bd3a50d191b35c8e28f1854141c90fa1b0134d6bf8a
- filename: packages/contentstack-import/test/unit/import/modules/marketplace-apps.test.ts
Expand Down Expand Up @@ -212,7 +212,7 @@ fileignoreconfig:
- filename: packages/contentstack-export/test/unit/export/modules/personalize.test.ts
checksum: 83cf034fabee00b42b4243a8c0b8ba280ab7c1e68ffd741c49c31aaee8ca0315
- filename: packages/contentstack-utilities/test/unit/logger.test.ts
checksum: 11778d0252202c18a1ca6a38883d6e12fc324ff86ad0fe058bc2505f9cd66ba3
checksum: a1939dea16166b1893a248179524a76f2ed20b04b99c83bd1a5a13fcf6f0dadc
- filename: packages/contentstack-audit/test/unit/audit-base-command.test.ts
checksum: 17a16b4457c820494442f335d94d0949961e68e8ca72ca0f1fa9d4d0eeb0c17a
- filename: packages/contentstack-import/src/import/modules/taxonomies.ts
Expand All @@ -227,4 +227,8 @@ fileignoreconfig:
checksum: 86b11c2a2dd8c0b14aa558e4e52d6d721cd7707422c26a68e96cc5b55b9fefd8
- filename: packages/contentstack-import-setup/src/utils/login-handler.ts
checksum: 3860c96e31677356963e67049762f944aef7c7b22fabb75a70ff5c64cf1ac274
- filename: packages/contentstack-utilities/src/helpers.ts
checksum: 9d7df9d79cec75f238a0072bf79c4934b4724bf1466451ea6f923adfd5c0b75b
- filename: packages/contentstack-utilities/src/logger/session-path.ts
checksum: 4c66980a857bc12012a45e50790c0eaab06883db5e1476d84fb142a08b70b2e7
version: "1.0"
20 changes: 5 additions & 15 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid';
import isEmpty from 'lodash/isEmpty';
import { join, resolve } from 'path';
import cloneDeep from 'lodash/cloneDeep';
import { cliux, sanitizePath, TableFlags, TableHeader, log, configHandler } from '@contentstack/cli-utilities';
import { cliux, sanitizePath, TableFlags, TableHeader, log, configHandler, createLogContext } from '@contentstack/cli-utilities';
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';
import config from './config';
import { print } from './util/log';
Expand Down Expand Up @@ -50,18 +50,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
};
}

/**
* Create audit context object similar to export command
*/
private createAuditContext(moduleName?: string): AuditContext {
return {
command: this.context?.info?.command || 'cm:stacks:audit',
module: moduleName || 'audit',
email: configHandler.get('email') || '',
sessionId: this.context?.sessionId || '',
authenticationMethod: configHandler.get('authenticationMethod') || '',
};
}

/**
* The `start` function performs an audit on content types, global fields, entries, and workflows and displays
Expand All @@ -72,7 +60,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
async start(command: CommandNames): Promise<boolean> {
this.currentCommand = command;
// Initialize audit context
this.auditContext = this.createAuditContext();
createLogContext(this.context?.info?.command,'', configHandler.get('authenticationMethod'));
this.auditContext = { module: 'audit' };
log.debug(`Starting audit command: ${command}`, this.auditContext);
log.info(`Starting audit command: ${command}`, this.auditContext);

Expand Down Expand Up @@ -224,7 +213,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
log.debug(`Data module wise: ${JSON.stringify(dataModuleWise)}`, this.auditContext);
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
// Update audit context with current module
this.auditContext = this.createAuditContext(module);
createLogContext(this.context?.info?.command, '', configHandler.get('authenticationMethod'));
this.auditContext = { module: module };
log.debug(`Starting audit for module: ${module}`, this.auditContext);
log.info(`Starting audit for module: ${module}`, this.auditContext);

Expand Down
5 changes: 0 additions & 5 deletions packages/contentstack-audit/src/types/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export interface AuditContext {
command: string;
module: string;
email: string | undefined;
sessionId: string | undefined;
clientId?: string;
authenticationMethod?: string;
}
6 changes: 4 additions & 2 deletions packages/contentstack-auth/src/base-command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from '@contentstack/cli-command';
import { configHandler, Flags, Interfaces, log } from '@contentstack/cli-utilities';
import { configHandler, createLogContext, Flags, getAuthenticationMethod, Interfaces, log } from '@contentstack/cli-utilities';
import { Context } from './interfaces';

export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
Expand All @@ -16,7 +16,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
*/
public async init(): Promise<void> {
await super.init();
this.contextDetails = { ...this.createExportContext() };
// this.contextDetails = { ...this.createExportContext() };
this.contextDetails = { ...createLogContext(this.context?.info?.command || 'auth', '',) };

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ class StackCloneCommand extends Command {
sourceManagementTokenAlias,
destinationManagementTokenAlias,
);
const cloneContext = this.createCloneContext(authenticationMethod);
createLogContext(
this.context?.info?.command || 'cm:stacks:clone',
sourceStackApiKey,
authenticationMethod
);
cloneContext = { module: 'clone' };
log.debug('Starting clone operation setup', cloneContext);

if (externalConfigPath) {
Expand Down
34 changes: 14 additions & 20 deletions packages/contentstack-export/src/commands/cm/stacks/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
log,
handleAndLogError,
getLogPath,
createLogContext,
} from '@contentstack/cli-utilities';

import { ModuleExporter } from '../../../export';
import { Context, ExportConfig } from '../../../types';
import { ExportConfig } from '../../../types';
import { setupExportConfig, writeExportMetaFile } from '../../../utils';

export default class ExportCommand extends Command {
Expand Down Expand Up @@ -120,9 +121,16 @@ export default class ExportCommand extends Command {
try {
const { flags } = await this.parse(ExportCommand);
const exportConfig = await setupExportConfig(flags);
// Prepare the context object
const context = this.createExportContext(exportConfig.apiKey, exportConfig.authenticationMethod);
exportConfig.context = { ...context };

// Store apiKey in configHandler for session.json (return value not needed)
createLogContext(
this.context?.info?.command || 'cm:stacks:export',
exportConfig.apiKey,
exportConfig.authenticationMethod
);

// For log entries, only pass module (other fields are in session.json)
exportConfig.context = { module: '' };
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);

// Assign exportConfig variables
Expand All @@ -137,29 +145,15 @@ export default class ExportCommand extends Command {
}
log.success(
`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,
exportConfig.context,
);
log.info(`The exported content has been stored at '${exportDir}'`, exportConfig.context);
log.success(`The log has been stored at '${getLogPath()}'`, exportConfig.context);
log.info(`The exported content has been stored at '${exportDir}'`);
log.success(`The log has been stored at '${getLogPath()}'`);
} catch (error) {
handleAndLogError(error);
log.info(`The log has been stored at '${getLogPath()}'`);
}
}

// Create export context object
private createExportContext(apiKey: string, authenticationMethod?: string): Context {
return {
command: this.context?.info?.command || 'cm:stacks:export',
module: '',
userId: configHandler.get('userUid') || '',
email: configHandler.get('email') || '',
sessionId: this.context?.sessionId || '',
apiKey: apiKey || '',
orgId: configHandler.get('oauthOrgUid') || '',
authenticationMethod: authenticationMethod || 'Basic Auth',
};
}

// Assign values to exportConfig
private assignExportConfig(exportConfig: ExportConfig): void {
Expand Down
8 changes: 0 additions & 8 deletions packages/contentstack-export/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,7 @@ export interface StackConfig {
limit?: number;
}
export interface Context {
command: string;
module: string;
userId: string | undefined;
email: string | undefined;
sessionId: string | undefined;
clientId?: string | undefined;
apiKey: string;
orgId: string;
authenticationMethod?: string;
}

export { default as DefaultConfig } from './default-config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
log,
handleAndLogError,
configHandler,
createLogContext,
} from '@contentstack/cli-utilities';

import { ImportConfig, Context } from '../../../types';
Expand Down Expand Up @@ -71,8 +72,13 @@ export default class ImportSetupCommand extends Command {
const { flags } = await this.parse(ImportSetupCommand);
let importSetupConfig = await setupImportConfig(flags);
// Prepare the context object
const context = this.createImportSetupContext(importSetupConfig.apiKey, (importSetupConfig as any).authenticationMethod);
importSetupConfig.context = { ...context };
createLogContext(
this.context?.info?.command || 'cm:stacks:import-setup',
importSetupConfig.apiKey,
configHandler.get('authenticationMethod')
);

importSetupConfig.context = { module: '' };

// Note setting host to create cma client
importSetupConfig.host = this.cmaHost;
Expand All @@ -94,17 +100,4 @@ export default class ImportSetupCommand extends Command {
}
}

// Create import setup context object
private createImportSetupContext(apiKey: string, authenticationMethod?: string, module?: string): Context {
return {
command: this.context?.info?.command || 'cm:stacks:import-setup',
module: module || '',
userId: configHandler.get('userUid') || undefined,
email: configHandler.get('email') || undefined,
sessionId: this.context?.sessionId,
apiKey: apiKey || '',
orgId: configHandler.get('oauthOrgUid') || '',
authenticationMethod: authenticationMethod || 'Basic Auth',
};
}
}
7 changes: 0 additions & 7 deletions packages/contentstack-import-setup/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,5 @@ export type TaxonomyQueryParams = {
};

export interface Context {
command: string;
module: string;
userId: string | undefined;
email: string | undefined;
sessionId: string | undefined;
apiKey: string;
orgId: string;
authenticationMethod?: string;
}
24 changes: 8 additions & 16 deletions packages/contentstack-import/src/commands/cm/stacks/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
handleAndLogError,
configHandler,
getLogPath,
createLogContext,
} from '@contentstack/cli-utilities';

import { Context, ImportConfig } from '../../../types';
Expand Down Expand Up @@ -155,8 +156,13 @@ export default class ImportCommand extends Command {
const { flags } = await this.parse(ImportCommand);
importConfig = await setupImportConfig(flags);
// Prepare the context object
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
importConfig.context = { ...context };
createLogContext(
this.context?.info?.command || 'cm:stacks:export',
importConfig.apiKey,
importConfig.authenticationMethod
);

importConfig.context = { module: '' };
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);

// Note setting host to create cma client
Expand Down Expand Up @@ -190,18 +196,4 @@ export default class ImportCommand extends Command {
}
}
}

// Create export context object
private createImportContext(apiKey: string, authenticationMethod?: string): Context {
return {
command: this.context?.info?.command || 'cm:stacks:import',
module: '',
userId: configHandler.get('userUid') || '',
email: configHandler.get('email') || '',
sessionId: this.context?.sessionId,
apiKey: apiKey || '',
orgId: configHandler.get('oauthOrgUid') || '',
authenticationMethod: authenticationMethod || 'Basic Auth',
};
}
}
22 changes: 1 addition & 21 deletions packages/contentstack-import/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,7 @@ export interface TaxonomiesConfig {
}

export interface Context {
command: string;
module: string;
userId: string | undefined;
email: string | undefined;
sessionId: string | undefined;
clientId?: string | undefined;
apiKey: string;
orgId: string;
authenticationMethod?: string;
}

export { default as DefaultConfig } from './default-config';
Expand All @@ -127,16 +119,4 @@ export type ExtensionType = {
uid: string;
scope: Record<string, unknown>;
title: string;
};

export interface Context {
command: string;
module: string;
userId: string | undefined;
email: string | undefined;
sessionId: string | undefined;
clientId?: string | undefined;
apiKey: string;
orgId: string;
authenticationMethod?: string;
}
};
Loading
Loading