@agility/cli
Version:
Agility CLI for working with your content. (Public Beta)
164 lines (163 loc) • 4.58 kB
TypeScript
/**
* Centralized state management for Agility CLI
* Simple state object that gets populated from argv and referenced throughout the app
*/
import * as mgmtApi from '@agility/management-sdk';
import { Logs, OperationType, EntityType } from './logs';
export interface State {
dev: boolean;
local: boolean;
preprod: boolean;
headless: boolean;
verbose: boolean;
sourceGuid: string[];
targetGuid: string[];
locale: string[];
availableLocales: string[];
guidLocaleMap: Map<string, string[]>;
channel: string;
preview: boolean;
elements: string;
rootPath: string;
legacyFolders: boolean;
insecure: boolean;
baseUrl?: string;
test: boolean;
overwrite: boolean;
force: boolean;
reset: boolean;
update: boolean;
publish: boolean;
models: string;
modelsWithDeps: string;
contentItems?: string;
useHeadless?: boolean;
useVerbose?: boolean;
mgmtApiOptions?: any;
user?: any;
apiKeyForPull?: string;
previewKey?: string;
fetchKey?: string;
currentWebsite?: any;
apiKeys: Array<{
guid: string;
previewKey: string;
fetchKey: string;
}>;
cachedApiClient?: mgmtApi.ApiClient;
logger?: Logs;
loggerRegistry: Map<string, Logs>;
token: string | null;
localServer: string;
isAgilityDev: boolean;
forceNGROK: boolean;
isPush: boolean;
isPull: boolean;
isSync: boolean;
}
export declare const state: State;
/**
* Set state from command line arguments
*/
export declare function setState(argv: any): void;
/**
* Configure SSL verification based on CLI mode
*/
export declare function configureSSL(): void;
/**
* Prime state from .env file before setState() is called
* This allows .env values to be overridden by command line arguments
*/
export declare function primeFromEnv(): {
hasEnvFile: boolean;
primedValues: string[];
};
/**
* Reset state to default values (called at start of each command)
* Prevents contamination between command executions
*/
export declare function resetState(): void;
/**
* Get the current state
*/
export declare function getState(): State;
/**
* Get or create ApiClient - reuses cached instance to prevent connection pool exhaustion
* This ensures the client always uses current auth state while maintaining connection efficiency
*/
export declare function getApiClient(): mgmtApi.ApiClient;
/**
* @deprecated Use getApiClient() instead - this function is kept for backward compatibility
*/
export declare function createApiClient(): mgmtApi.ApiClient;
/**
* Clear the cached API client - forces creation of new instance on next getApiClient() call
*/
export declare function clearApiClient(): void;
/**
* Get computed UI mode based on state
*/
export declare function getUIMode(): {
useHeadless: boolean;
useVerbose: boolean;
};
/**
* Get API keys for a specific GUID
*/
export declare function getApiKeysForGuid(guid: string): {
previewKey: string;
fetchKey: string;
} | null;
/**
* Get all API keys
*/
export declare function getAllApiKeys(): Array<{
guid: string;
previewKey: string;
fetchKey: string;
}>;
/**
* Validate locale format (e.g., en-us, fr-ca, es-es)
*/
export declare function validateLocaleFormat(locale: string): boolean;
/**
* Validate array of locales and return valid/invalid splits
*/
export declare function validateLocales(locales: string[]): {
valid: string[];
invalid: string[];
};
/**
* Initialize centralized logger for the current operation
*/
export declare function initializeLogger(operationType: OperationType): Logs;
/**
* Initialize a per-GUID logger for parallel operations
*/
export declare function initializeGuidLogger(guid: string, operationType: OperationType, entityType?: EntityType): Logs;
/**
* Get logger for a specific GUID
*/
export declare function getLoggerForGuid(guid: string): Logs | null;
/**
* Get the current global logger instance
*/
export declare function getLogger(): Logs | null;
/**
* Save and clear a specific GUID logger
*/
export declare function finalizeGuidLogger(guid: string): string | null;
/**
* Save and clear all GUID loggers and merge into global log
*/
export declare function finalizeAllGuidLoggers(): string[];
/**
* Finalize and save the global logger
*/
export declare function finalizeLogger(): string | null;
export declare function startTimer(): void;
export declare function endTimer(): void;
/**
* Clear the current logger from state
*/
export declare function clearLogger(): void;