@contentstack/cli-cm-clone 1.20.0 → 1.21.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
16
16
  $ csdx COMMAND
17
17
  running command...
18
18
  $ csdx (--version)
19
- @contentstack/cli-cm-clone/1.20.0 darwin-arm64 node-v24.13.0
19
+ @contentstack/cli-cm-clone/1.21.0-beta.0 linux-x64 node-v22.22.0
20
20
  $ csdx --help [COMMAND]
21
21
  USAGE
22
22
  $ csdx COMMAND
@@ -0,0 +1,21 @@
1
+ import { Command } from '@contentstack/cli-command';
2
+ import { CloneContext } from '../../../types/clone-context';
3
+ export default class StackCloneCommand extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static aliases: string[];
7
+ static flags: any;
8
+ static usage: string;
9
+ /**
10
+ * Determine authentication method based on user preference
11
+ */
12
+ determineAuthenticationMethod(sourceManagementTokenAlias?: string, destinationManagementTokenAlias?: string): string;
13
+ /**
14
+ * Create clone context object for logging
15
+ */
16
+ createCloneContext(authenticationMethod: string): CloneContext;
17
+ run(): Promise<void>;
18
+ removeContentDirIfNotEmptyBeforeClone(dir: string, cloneContext: CloneContext): Promise<void>;
19
+ cleanUp(pathDir: string, message: string | null, cloneContext: CloneContext): Promise<void>;
20
+ registerCleanupOnInterrupt(pathDir: string, cloneContext: CloneContext): void;
21
+ }
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const cli_command_1 = require("@contentstack/cli-command");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const clone_handler_1 = require("../../../core/util/clone-handler");
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const rimraf_1 = require("rimraf");
9
+ const merge_1 = tslib_1.__importDefault(require("merge"));
10
+ const fs_1 = require("fs");
11
+ // Resolve path to package root (works in both src and lib contexts)
12
+ const packageRoot = __dirname.includes('/src/') ? __dirname.split('/src/')[0] : __dirname.split('/lib/')[0];
13
+ const pathdir = path.join(packageRoot, 'contents');
14
+ let config = {};
15
+ class StackCloneCommand extends cli_command_1.Command {
16
+ /**
17
+ * Determine authentication method based on user preference
18
+ */
19
+ determineAuthenticationMethod(sourceManagementTokenAlias, destinationManagementTokenAlias) {
20
+ // Track authentication method
21
+ let authenticationMethod = 'unknown';
22
+ // Determine authentication method based on user preference
23
+ if (sourceManagementTokenAlias || destinationManagementTokenAlias) {
24
+ authenticationMethod = 'Management Token';
25
+ }
26
+ else if ((0, cli_utilities_1.isAuthenticated)()) {
27
+ // Check if user is authenticated via OAuth
28
+ const isOAuthUser = cli_utilities_1.configHandler.get('authorisationType') === 'OAUTH' || false;
29
+ if (isOAuthUser) {
30
+ authenticationMethod = 'OAuth';
31
+ }
32
+ else {
33
+ authenticationMethod = 'Basic Auth';
34
+ }
35
+ }
36
+ else {
37
+ authenticationMethod = 'Basic Auth';
38
+ }
39
+ return authenticationMethod;
40
+ }
41
+ /**
42
+ * Create clone context object for logging
43
+ */
44
+ createCloneContext(authenticationMethod) {
45
+ var _a, _b, _c;
46
+ return {
47
+ command: ((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'cm:stacks:clone',
48
+ module: 'clone',
49
+ email: cli_utilities_1.configHandler.get('email') || '',
50
+ sessionId: ((_c = this.context) === null || _c === void 0 ? void 0 : _c.sessionId) || '',
51
+ authenticationMethod: authenticationMethod || 'Basic Auth',
52
+ };
53
+ }
54
+ async run() {
55
+ try {
56
+ const self = this;
57
+ const { flags: cloneCommandFlags } = await self.parse(StackCloneCommand);
58
+ const { yes, type: cloneType, 'stack-name': stackName, 'source-branch': sourceStackBranch, 'source-branch-alias': sourceStackBranchAlias, 'target-branch': targetStackBranch, 'target-branch-alias': targetStackBranchAlias, 'source-stack-api-key': sourceStackApiKey, 'destination-stack-api-key': destinationStackApiKey, 'source-management-token-alias': sourceManagementTokenAlias, 'destination-management-token-alias': destinationManagementTokenAlias, 'import-webhook-status': importWebhookStatus, config: externalConfigPath, } = cloneCommandFlags;
59
+ const handleClone = async () => {
60
+ const listOfTokens = cli_utilities_1.configHandler.get('tokens');
61
+ const authenticationMethod = this.determineAuthenticationMethod(sourceManagementTokenAlias, destinationManagementTokenAlias);
62
+ const cloneContext = this.createCloneContext(authenticationMethod);
63
+ cli_utilities_1.log.debug('Starting clone operation setup', cloneContext);
64
+ if (externalConfigPath) {
65
+ cli_utilities_1.log.debug(`Loading external configuration from: ${externalConfigPath}`, cloneContext);
66
+ let externalConfig = (0, fs_1.readFileSync)(externalConfigPath, 'utf-8');
67
+ externalConfig = JSON.parse(externalConfig);
68
+ config = merge_1.default.recursive(config, externalConfig);
69
+ }
70
+ config.forceStopMarketplaceAppsPrompt = yes;
71
+ config.skipAudit = cloneCommandFlags['skip-audit'];
72
+ cli_utilities_1.log.debug('Clone configuration prepared', Object.assign(Object.assign({}, cloneContext), { cloneType: config.cloneType, skipAudit: config.skipAudit, forceStopMarketplaceAppsPrompt: config.forceStopMarketplaceAppsPrompt }));
73
+ if (cloneType) {
74
+ config.cloneType = cloneType;
75
+ }
76
+ if (stackName) {
77
+ config.stackName = stackName;
78
+ }
79
+ if (sourceStackBranch) {
80
+ config.sourceStackBranch = sourceStackBranch;
81
+ }
82
+ if (sourceStackBranchAlias) {
83
+ config.sourceStackBranchAlias = sourceStackBranchAlias;
84
+ }
85
+ if (targetStackBranch) {
86
+ config.targetStackBranch = targetStackBranch;
87
+ }
88
+ if (targetStackBranchAlias) {
89
+ config.targetStackBranchAlias = targetStackBranchAlias;
90
+ }
91
+ if (sourceStackApiKey) {
92
+ config.source_stack = sourceStackApiKey;
93
+ }
94
+ if (destinationStackApiKey) {
95
+ config.target_stack = destinationStackApiKey;
96
+ }
97
+ if (sourceManagementTokenAlias && (listOfTokens === null || listOfTokens === void 0 ? void 0 : listOfTokens[sourceManagementTokenAlias])) {
98
+ config.source_alias = sourceManagementTokenAlias;
99
+ config.source_stack = listOfTokens[sourceManagementTokenAlias].apiKey;
100
+ cli_utilities_1.log.debug(`Using source token alias: ${sourceManagementTokenAlias}`, cloneContext);
101
+ }
102
+ else if (sourceManagementTokenAlias) {
103
+ cli_utilities_1.log.warn(`Provided source token alias (${sourceManagementTokenAlias}) not found in your config.!`, cloneContext);
104
+ }
105
+ if (destinationManagementTokenAlias && (listOfTokens === null || listOfTokens === void 0 ? void 0 : listOfTokens[destinationManagementTokenAlias])) {
106
+ config.destination_alias = destinationManagementTokenAlias;
107
+ config.target_stack = listOfTokens[destinationManagementTokenAlias].apiKey;
108
+ cli_utilities_1.log.debug(`Using destination token alias: ${destinationManagementTokenAlias}`, cloneContext);
109
+ }
110
+ else if (destinationManagementTokenAlias) {
111
+ cli_utilities_1.log.warn(`Provided destination token alias (${destinationManagementTokenAlias}) not found in your config.!`, cloneContext);
112
+ }
113
+ if (importWebhookStatus) {
114
+ config.importWebhookStatus = importWebhookStatus;
115
+ }
116
+ cli_utilities_1.log.debug('Management API client initialized successfully', cloneContext);
117
+ cli_utilities_1.log.debug(`Content directory path: ${pathdir}`, cloneContext);
118
+ await this.removeContentDirIfNotEmptyBeforeClone(pathdir, cloneContext); // NOTE remove if folder not empty before clone
119
+ this.registerCleanupOnInterrupt(pathdir, cloneContext);
120
+ config.auth_token = cli_utilities_1.configHandler.get('authtoken');
121
+ config.host = this.cmaHost;
122
+ config.cdn = this.cdaHost;
123
+ config.pathDir = pathdir;
124
+ config.cloneContext = cloneContext;
125
+ cli_utilities_1.log.debug('Clone configuration finalized', cloneContext);
126
+ const cloneHandler = new clone_handler_1.CloneHandler(config);
127
+ const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(config);
128
+ cloneHandler.setClient(managementAPIClient);
129
+ cli_utilities_1.log.debug('Starting clone operation', cloneContext);
130
+ cloneHandler.execute().catch((error) => {
131
+ (0, cli_utilities_1.handleAndLogError)(error, cloneContext);
132
+ });
133
+ };
134
+ if (sourceManagementTokenAlias && destinationManagementTokenAlias) {
135
+ if (sourceStackBranch || targetStackBranch) {
136
+ if ((0, cli_utilities_1.isAuthenticated)()) {
137
+ handleClone();
138
+ }
139
+ else {
140
+ cli_utilities_1.log.error('Log in to execute this command,csdx auth:login', this.createCloneContext('unknown'));
141
+ this.exit(1);
142
+ }
143
+ }
144
+ else {
145
+ handleClone();
146
+ }
147
+ }
148
+ else if ((0, cli_utilities_1.isAuthenticated)()) {
149
+ handleClone();
150
+ }
151
+ else {
152
+ cli_utilities_1.log.error('Please login to execute this command, csdx auth:login', this.createCloneContext('unknown'));
153
+ this.exit(1);
154
+ }
155
+ }
156
+ catch (error) {
157
+ if (error) {
158
+ await this.cleanUp(pathdir, null, this.createCloneContext('unknown'));
159
+ cli_utilities_1.log.error('Stack clone command failed', Object.assign(Object.assign({}, this.createCloneContext('unknown')), { error: (error === null || error === void 0 ? void 0 : error.message) || error }));
160
+ }
161
+ }
162
+ }
163
+ async removeContentDirIfNotEmptyBeforeClone(dir, cloneContext) {
164
+ try {
165
+ cli_utilities_1.log.debug('Checking if content directory is empty', Object.assign(Object.assign({}, cloneContext), { dir }));
166
+ const files = await fs_1.promises.readdir(dir);
167
+ if (files.length) {
168
+ cli_utilities_1.log.debug('Content directory is not empty, cleaning up', Object.assign(Object.assign({}, cloneContext), { dir }));
169
+ await this.cleanUp(dir, null, cloneContext);
170
+ }
171
+ }
172
+ catch (error) {
173
+ const omit = ['ENOENT']; // NOTE add emittable error codes in the array
174
+ if (!omit.includes(error.code)) {
175
+ cli_utilities_1.log.error('Error checking content directory', Object.assign(Object.assign({}, cloneContext), { error: error === null || error === void 0 ? void 0 : error.message, code: error.code }));
176
+ }
177
+ }
178
+ }
179
+ async cleanUp(pathDir, message, cloneContext) {
180
+ try {
181
+ cli_utilities_1.log.debug('Starting cleanup', Object.assign(Object.assign({}, cloneContext), { pathDir }));
182
+ await (0, rimraf_1.rimraf)(pathDir);
183
+ if (message) {
184
+ cli_utilities_1.log.info(message, cloneContext);
185
+ }
186
+ cli_utilities_1.log.debug('Cleanup completed', Object.assign(Object.assign({}, cloneContext), { pathDir }));
187
+ }
188
+ catch (err) {
189
+ if (err) {
190
+ cli_utilities_1.log.debug('Cleaning up', cloneContext);
191
+ const skipCodeArr = ['ENOENT', 'EBUSY', 'EPERM', 'EMFILE', 'ENOTEMPTY'];
192
+ if (skipCodeArr.includes(err.code)) {
193
+ cli_utilities_1.log.debug('Cleanup error code is in skip list, exiting', Object.assign(Object.assign({}, cloneContext), { code: err === null || err === void 0 ? void 0 : err.code }));
194
+ process.exit();
195
+ }
196
+ }
197
+ }
198
+ }
199
+ registerCleanupOnInterrupt(pathDir, cloneContext) {
200
+ const interrupt = ['SIGINT', 'SIGQUIT', 'SIGTERM'];
201
+ const exceptions = ['unhandledRejection', 'uncaughtException'];
202
+ const cleanUp = async (exitOrError) => {
203
+ if (exitOrError) {
204
+ cli_utilities_1.log.debug('Cleaning up on interrupt', cloneContext);
205
+ await this.cleanUp(pathDir, null, cloneContext);
206
+ cli_utilities_1.log.info('Cleanup done', cloneContext);
207
+ if (exitOrError instanceof Promise) {
208
+ exitOrError.catch((error) => {
209
+ cli_utilities_1.log.error('Error during cleanup', Object.assign(Object.assign({}, cloneContext), { error: (error && (error === null || error === void 0 ? void 0 : error.message)) || '' }));
210
+ });
211
+ }
212
+ else if (exitOrError.message) {
213
+ cli_utilities_1.log.error('Cleanup error', Object.assign(Object.assign({}, cloneContext), { error: exitOrError === null || exitOrError === void 0 ? void 0 : exitOrError.message }));
214
+ }
215
+ else if (exitOrError.errorMessage) {
216
+ cli_utilities_1.log.error('Cleanup error', Object.assign(Object.assign({}, cloneContext), { error: exitOrError === null || exitOrError === void 0 ? void 0 : exitOrError.errorMessage }));
217
+ }
218
+ if (exitOrError === true)
219
+ process.exit();
220
+ }
221
+ };
222
+ exceptions.forEach((event) => process.on(event, cleanUp));
223
+ interrupt.forEach((signal) => process.on(signal, () => cleanUp(true)));
224
+ }
225
+ }
226
+ exports.default = StackCloneCommand;
227
+ StackCloneCommand.description = `Clone data (structure/content or both) of a stack into another stack
228
+ Use this plugin to automate the process of cloning a stack in few steps.
229
+ `;
230
+ StackCloneCommand.examples = [
231
+ 'csdx cm:stacks:clone',
232
+ 'csdx cm:stacks:clone --source-branch <source-branch-name> --target-branch <target-branch-name> --yes',
233
+ 'csdx cm:stacks:clone --source-stack-api-key <apiKey> --destination-stack-api-key <apiKey>',
234
+ 'csdx cm:stacks:clone --source-management-token-alias <management token alias> --destination-management-token-alias <management token alias>',
235
+ 'csdx cm:stacks:clone --source-branch --target-branch --source-management-token-alias <management token alias> --destination-management-token-alias <management token alias>',
236
+ 'csdx cm:stacks:clone --source-branch --target-branch --source-management-token-alias <management token alias> --destination-management-token-alias <management token alias> --type <value a or b>',
237
+ ];
238
+ StackCloneCommand.aliases = ['cm:stack-clone'];
239
+ StackCloneCommand.flags = {
240
+ 'source-branch': cli_utilities_1.flags.string({
241
+ required: false,
242
+ multiple: false,
243
+ description: 'Branch of the source stack.',
244
+ exclusive: ['source-branch-alias'],
245
+ }),
246
+ 'source-branch-alias': cli_utilities_1.flags.string({
247
+ required: false,
248
+ multiple: false,
249
+ description: 'Alias of Branch of the source stack.',
250
+ exclusive: ['source-branch'],
251
+ }),
252
+ 'target-branch': cli_utilities_1.flags.string({
253
+ required: false,
254
+ multiple: false,
255
+ description: 'Branch of the target stack.',
256
+ exclusive: ['target-branch-alias'],
257
+ }),
258
+ 'target-branch-alias': cli_utilities_1.flags.string({
259
+ required: false,
260
+ multiple: false,
261
+ description: 'Alias of Branch of the target stack.',
262
+ exclusive: ['target-branch'],
263
+ }),
264
+ 'source-management-token-alias': cli_utilities_1.flags.string({
265
+ required: false,
266
+ multiple: false,
267
+ description: 'Source management token alias.',
268
+ }),
269
+ 'destination-management-token-alias': cli_utilities_1.flags.string({
270
+ required: false,
271
+ multiple: false,
272
+ description: 'Destination management token alias.',
273
+ }),
274
+ 'stack-name': cli_utilities_1.flags.string({
275
+ char: 'n',
276
+ required: false,
277
+ multiple: false,
278
+ description: 'Provide a name for the new stack to store the cloned content.',
279
+ }),
280
+ type: cli_utilities_1.flags.string({
281
+ required: false,
282
+ multiple: false,
283
+ options: ['a', 'b'],
284
+ description: ` Type of data to clone. You can select option a or b.
285
+ a) Structure (all modules except entries & assets).
286
+ b) Structure with content (all modules including entries & assets).
287
+ `,
288
+ }),
289
+ 'source-stack-api-key': cli_utilities_1.flags.string({
290
+ description: 'Source stack API key',
291
+ }),
292
+ 'destination-stack-api-key': cli_utilities_1.flags.string({
293
+ description: 'Destination stack API key',
294
+ }),
295
+ 'import-webhook-status': cli_utilities_1.flags.string({
296
+ description: '[default: disable] (optional) The status of the import webhook. <options: disable|current>',
297
+ options: ['disable', 'current'],
298
+ required: false,
299
+ default: 'disable',
300
+ }),
301
+ yes: cli_utilities_1.flags.boolean({
302
+ char: 'y',
303
+ required: false,
304
+ description: 'Force override all Marketplace prompts.',
305
+ }),
306
+ 'skip-audit': cli_utilities_1.flags.boolean({
307
+ description: ' (optional) Skips the audit fix that occurs during an import operation.',
308
+ }),
309
+ config: cli_utilities_1.flags.string({
310
+ char: 'c',
311
+ required: false,
312
+ description: 'Path for the external configuration',
313
+ }),
314
+ };
315
+ StackCloneCommand.usage = 'cm:stacks:clone [--source-branch <value>] [--target-branch <value>] [--source-management-token-alias <value>] [--destination-management-token-alias <value>] [-n <value>] [--type a|b] [--source-stack-api-key <value>] [--destination-stack-api-key <value>] [--import-webhook-status disable|current]';
@@ -0,0 +1,31 @@
1
+ import { ICommand, OrgCommandParams, StackCommandParams, BranchCommandParams, CreateStackCommandParams } from '../../types/command-types';
2
+ /**
3
+ * Base command class implementing the command pattern
4
+ */
5
+ export declare class BaseCommand implements ICommand {
6
+ private executeFn;
7
+ private undoFn?;
8
+ params?: any;
9
+ constructor(executeFn: (params?: any) => Promise<any>, undoFn?: (params?: any) => Promise<void>, params?: any);
10
+ execute(params?: any): Promise<any>;
11
+ undo(params?: any): Promise<void>;
12
+ }
13
+ /**
14
+ * Command factory functions
15
+ */
16
+ export declare function HandleOrgCommand(params: OrgCommandParams, parentContext: any): ICommand;
17
+ export declare function HandleStackCommand(params: StackCommandParams, parentContext: any): ICommand;
18
+ export declare function HandleBranchCommand(params: BranchCommandParams, parentContext: any, backStepHandler?: (params?: any) => Promise<void>): ICommand;
19
+ export declare function HandleDestinationStackCommand(params: StackCommandParams, parentContext: any): ICommand;
20
+ export declare function HandleExportCommand(params: any, parentContext: any): ICommand;
21
+ export declare function SetBranchCommand(params: any, parentContext: any): ICommand;
22
+ export declare function CreateNewStackCommand(params: CreateStackCommandParams, parentContext: any): ICommand;
23
+ export declare function CloneTypeSelectionCommand(params: any, parentContext: any): ICommand;
24
+ /**
25
+ * Clone command executor class
26
+ */
27
+ export declare class Clone {
28
+ private commands;
29
+ execute(command: ICommand): Promise<any>;
30
+ undo(): Promise<void>;
31
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Clone = exports.CloneTypeSelectionCommand = exports.CreateNewStackCommand = exports.SetBranchCommand = exports.HandleExportCommand = exports.HandleDestinationStackCommand = exports.HandleBranchCommand = exports.HandleStackCommand = exports.HandleOrgCommand = exports.BaseCommand = void 0;
4
+ /**
5
+ * Base command class implementing the command pattern
6
+ */
7
+ class BaseCommand {
8
+ constructor(executeFn, undoFn, params) {
9
+ this.executeFn = executeFn;
10
+ this.undoFn = undoFn;
11
+ this.params = params;
12
+ }
13
+ async execute(params) {
14
+ return this.executeFn(params || this.params);
15
+ }
16
+ async undo(params) {
17
+ if (this.undoFn) {
18
+ await this.undoFn(params || this.params);
19
+ }
20
+ }
21
+ }
22
+ exports.BaseCommand = BaseCommand;
23
+ /**
24
+ * Command factory functions
25
+ */
26
+ function HandleOrgCommand(params, parentContext) {
27
+ return new BaseCommand(parentContext.handleOrgSelection.bind(parentContext), undefined, params);
28
+ }
29
+ exports.HandleOrgCommand = HandleOrgCommand;
30
+ function HandleStackCommand(params, parentContext) {
31
+ return new BaseCommand(parentContext.handleStackSelection.bind(parentContext), parentContext.execute.bind(parentContext), params);
32
+ }
33
+ exports.HandleStackCommand = HandleStackCommand;
34
+ function HandleBranchCommand(params, parentContext, backStepHandler) {
35
+ return new BaseCommand(parentContext.handleBranchSelection.bind(parentContext), backStepHandler, params);
36
+ }
37
+ exports.HandleBranchCommand = HandleBranchCommand;
38
+ function HandleDestinationStackCommand(params, parentContext) {
39
+ return new BaseCommand(parentContext.handleStackSelection.bind(parentContext), parentContext.executeDestination.bind(parentContext), params);
40
+ }
41
+ exports.HandleDestinationStackCommand = HandleDestinationStackCommand;
42
+ function HandleExportCommand(params, parentContext) {
43
+ return new BaseCommand(parentContext.cmdExport.bind(parentContext), undefined, params);
44
+ }
45
+ exports.HandleExportCommand = HandleExportCommand;
46
+ function SetBranchCommand(params, parentContext) {
47
+ return new BaseCommand(parentContext.setBranch.bind(parentContext), undefined, params);
48
+ }
49
+ exports.SetBranchCommand = SetBranchCommand;
50
+ function CreateNewStackCommand(params, parentContext) {
51
+ return new BaseCommand(parentContext.createNewStack.bind(parentContext), parentContext.executeDestination.bind(parentContext), params);
52
+ }
53
+ exports.CreateNewStackCommand = CreateNewStackCommand;
54
+ function CloneTypeSelectionCommand(params, parentContext) {
55
+ return new BaseCommand(parentContext.cloneTypeSelection.bind(parentContext), undefined, params);
56
+ }
57
+ exports.CloneTypeSelectionCommand = CloneTypeSelectionCommand;
58
+ /**
59
+ * Clone command executor class
60
+ */
61
+ class Clone {
62
+ constructor() {
63
+ this.commands = [];
64
+ }
65
+ async execute(command) {
66
+ this.commands.push(command);
67
+ const result = await command.execute(command.params);
68
+ return result;
69
+ }
70
+ async undo() {
71
+ if (this.commands.length) {
72
+ const command = this.commands.pop();
73
+ if (command && command.undo) {
74
+ await command.undo(command.params);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ exports.Clone = Clone;
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ /**
4
+ * Custom AbortSignal implementation
5
+ */
6
+ declare class CustomAbortSignal {
7
+ eventEmitter: EventEmitter;
8
+ onabort: ((event: {
9
+ type: string;
10
+ target: CustomAbortSignal;
11
+ }) => void) | null;
12
+ aborted: boolean;
13
+ constructor();
14
+ toString(): string;
15
+ get [Symbol.toStringTag](): string;
16
+ removeEventListener(name: string, handler: (...args: any[]) => void): void;
17
+ addEventListener(name: string, handler: (...args: any[]) => void): void;
18
+ dispatchEvent(type: string): void;
19
+ }
20
+ /**
21
+ * Custom AbortController implementation
22
+ */
23
+ declare class CustomAbortController {
24
+ signal: CustomAbortSignal;
25
+ constructor();
26
+ abort(): void;
27
+ toString(): string;
28
+ get [Symbol.toStringTag](): string;
29
+ }
30
+ export { CustomAbortController, CustomAbortSignal };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomAbortSignal = exports.CustomAbortController = void 0;
4
+ const events_1 = require("events");
5
+ /**
6
+ * Custom AbortSignal implementation
7
+ */
8
+ class CustomAbortSignal {
9
+ constructor() {
10
+ this.eventEmitter = new events_1.EventEmitter();
11
+ this.onabort = null;
12
+ this.aborted = false;
13
+ }
14
+ toString() {
15
+ return '[object CustomAbortSignal]';
16
+ }
17
+ get [Symbol.toStringTag]() {
18
+ return 'CustomAbortSignal';
19
+ }
20
+ removeEventListener(name, handler) {
21
+ this.eventEmitter.removeListener(name, handler);
22
+ }
23
+ addEventListener(name, handler) {
24
+ this.eventEmitter.on(name, handler);
25
+ }
26
+ dispatchEvent(type) {
27
+ const event = { type, target: this };
28
+ const handlerName = `on${type}`;
29
+ // Emit event to EventEmitter listeners (for addEventListener)
30
+ this.eventEmitter.emit(type, event);
31
+ // Call onabort handler if it exists (for onabort property)
32
+ if (typeof this[handlerName] === 'function') {
33
+ this[handlerName](event);
34
+ }
35
+ }
36
+ }
37
+ exports.CustomAbortSignal = CustomAbortSignal;
38
+ /**
39
+ * Custom AbortController implementation
40
+ */
41
+ class CustomAbortController {
42
+ constructor() {
43
+ this.signal = new CustomAbortSignal();
44
+ }
45
+ abort() {
46
+ if (this.signal.aborted)
47
+ return;
48
+ this.signal.aborted = true;
49
+ this.signal.dispatchEvent('abort');
50
+ }
51
+ toString() {
52
+ return '[object CustomAbortController]';
53
+ }
54
+ get [Symbol.toStringTag]() {
55
+ return 'CustomAbortController';
56
+ }
57
+ }
58
+ exports.CustomAbortController = CustomAbortController;
@@ -0,0 +1,55 @@
1
+ import { CloneConfig } from '../../types/clone-config';
2
+ export declare class CloneHandler {
3
+ private config;
4
+ private client;
5
+ private cloneCommand;
6
+ pathDir: string;
7
+ private orgUidList;
8
+ private stackUidList;
9
+ private masterLocaleList;
10
+ private master_locale?;
11
+ private executingCommand?;
12
+ private backKeyPressHandler?;
13
+ private createNewStackPrompt?;
14
+ private stackNamePrompt;
15
+ constructor(opt: CloneConfig);
16
+ setClient(managementSDKClient: any): void;
17
+ getOrganizationChoices(orgMessage?: string): Promise<any>;
18
+ handleOrgSelection(options?: {
19
+ msg?: string;
20
+ isSource?: boolean;
21
+ }): Promise<any>;
22
+ getStack(answer: any, stkMessage?: string, isSource?: boolean): Promise<any>;
23
+ displayBackOptionMessage(): void;
24
+ setBackKeyPressHandler(backKeyPressHandler: (...args: any[]) => void): void;
25
+ removeBackKeyPressHandler(): void;
26
+ setExectingCommand(command: number): void;
27
+ handleStackSelection(options?: {
28
+ org?: any;
29
+ msg?: string;
30
+ isSource?: boolean;
31
+ }): Promise<any>;
32
+ validateIfBranchExist(stackAPIClient: any, isSource: boolean): Promise<void>;
33
+ resolveBranchAliases(isSource?: boolean): Promise<void>;
34
+ handleBranchSelection(options?: {
35
+ api_key?: string;
36
+ isSource?: boolean;
37
+ returnBranch?: boolean;
38
+ }): Promise<any>;
39
+ executeStackPrompt(params?: any): Promise<void>;
40
+ executeBranchPrompt(parentParams: any): Promise<void>;
41
+ executeExport(): Promise<void>;
42
+ execute(): Promise<void>;
43
+ executeDestination(): Promise<void>;
44
+ executeStackDestinationPrompt(params: any): Promise<void>;
45
+ executeBranchDestinationPrompt(parentParams: any): Promise<void>;
46
+ cmdExport(): Promise<boolean>;
47
+ cmdImport(): Promise<void>;
48
+ setCreateNewStackPrompt(createNewStackPrompt: any): void;
49
+ setBranch(): Promise<void>;
50
+ getNewStackPromptResult(): Promise<any>;
51
+ createNewStack(options: {
52
+ orgUid: string;
53
+ }): Promise<any>;
54
+ cloneTypeSelection(): Promise<any>;
55
+ }