@squiz/dxp-cli-next 5.26.0-develop.1 → 5.26.0-develop.3

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.
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const getMigrationCommand: () => Command;
3
+ export default getMigrationCommand;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const chalk_1 = __importDefault(require("chalk"));
16
+ const commander_1 = require("commander");
17
+ const utils_1 = require("../utils");
18
+ const ora_1 = __importDefault(require("ora"));
19
+ const getMigrationCommand = () => {
20
+ const getCommand = new commander_1.Command('get')
21
+ .name('get')
22
+ .description('Get a migration using the AI Page migration service')
23
+ .addOption(new commander_1.Option('--migration-id <string>', 'The ID of the migration to get').makeOptionMandatory())
24
+ .addOption(new commander_1.Option('--asset-id <string>', 'The ID of the asset to get the migration for'))
25
+ .addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
26
+ .configureOutput({
27
+ outputError(str, write) {
28
+ write(chalk_1.default.red(str));
29
+ },
30
+ })
31
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const spinner = (0, ora_1.default)('Getting migration').start();
33
+ yield (0, utils_1.throwErrorIfNotLoggedIn)(getCommand);
34
+ try {
35
+ const response = yield (0, utils_1.getMigration)(options);
36
+ spinner.succeed(`Migration details: ${JSON.stringify(response, null, 2)}`);
37
+ }
38
+ catch (error) {
39
+ spinner.fail();
40
+ (0, utils_1.handleCommandError)(getCommand, error);
41
+ }
42
+ }));
43
+ if (process.env.ENABLE_OVERRIDE_MIGRATION_URL === 'true') {
44
+ getCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value'));
45
+ }
46
+ return getCommand;
47
+ };
48
+ exports.default = getMigrationCommand;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const nock_1 = __importDefault(require("nock"));
39
+ const getMigration_1 = __importDefault(require("./getMigration"));
40
+ const utils = __importStar(require("../utils"));
41
+ const ApplicationStore = __importStar(require("../../ApplicationStore"));
42
+ jest.mock('../utils');
43
+ jest.mock('../../ApplicationStore');
44
+ const mockUtils = utils;
45
+ const mockApplicationStore = ApplicationStore;
46
+ describe('getMigrationCommand', () => {
47
+ let logSpy;
48
+ let mockGetMigrationResponse;
49
+ beforeEach(() => {
50
+ nock_1.default.cleanAll();
51
+ jest.clearAllMocks();
52
+ jest.resetAllMocks();
53
+ logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
54
+ mockApplicationStore.getApplicationFile.mockResolvedValue('session-cookie');
55
+ mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue(undefined);
56
+ mockGetMigrationResponse = {
57
+ migrationId: 'migration-123',
58
+ assetId: 'asset-456',
59
+ stage: 'completed',
60
+ status: 'success',
61
+ stageDetail: 'Migration completed successfully',
62
+ previewPageAssetId: 'preview-789',
63
+ componentDownloadUrl: 'https://download.example.com/components.zip',
64
+ };
65
+ mockUtils.getMigration.mockResolvedValue(mockGetMigrationResponse);
66
+ });
67
+ afterEach(() => {
68
+ logSpy.mockRestore();
69
+ });
70
+ describe('successful migration retrieval', () => {
71
+ it('should get migration successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const program = (0, getMigration_1.default)();
73
+ yield program.parseAsync([
74
+ 'node',
75
+ 'dxp-cli',
76
+ '--migration-id',
77
+ 'migration-123',
78
+ '--asset-id',
79
+ 'asset-456',
80
+ ]);
81
+ expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
82
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
83
+ migrationId: 'migration-123',
84
+ assetId: 'asset-456',
85
+ });
86
+ expect(mockUtils.getMigration).toHaveBeenCalledTimes(1);
87
+ expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
88
+ }));
89
+ it('should get migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
90
+ const program = (0, getMigration_1.default)();
91
+ yield program.parseAsync([
92
+ 'node',
93
+ 'dxp-cli',
94
+ '--migration-id',
95
+ 'migration-123',
96
+ '--asset-id',
97
+ 'asset-456',
98
+ '--tenant',
99
+ 'test-tenant',
100
+ ]);
101
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
102
+ migrationId: 'migration-123',
103
+ assetId: 'asset-456',
104
+ tenant: 'test-tenant',
105
+ });
106
+ }));
107
+ it('should get migration with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
109
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
110
+ const program = (0, getMigration_1.default)();
111
+ yield program.parseAsync([
112
+ 'node',
113
+ 'dxp-cli',
114
+ '--migration-id',
115
+ 'migration-123',
116
+ '--asset-id',
117
+ 'asset-456',
118
+ '--overrideUrl',
119
+ 'https://custom.migration.url',
120
+ ]);
121
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
122
+ migrationId: 'migration-123',
123
+ assetId: 'asset-456',
124
+ overrideUrl: 'https://custom.migration.url',
125
+ });
126
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
127
+ }));
128
+ it('should get migration without asset-id option', () => __awaiter(void 0, void 0, void 0, function* () {
129
+ const program = (0, getMigration_1.default)();
130
+ yield program.parseAsync([
131
+ 'node',
132
+ 'dxp-cli',
133
+ '--migration-id',
134
+ 'migration-123',
135
+ ]);
136
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
137
+ migrationId: 'migration-123',
138
+ });
139
+ }));
140
+ });
141
+ describe('error scenarios', () => {
142
+ it('should handle getMigration API error', () => __awaiter(void 0, void 0, void 0, function* () {
143
+ const apiError = new Error('Migration not found');
144
+ mockUtils.getMigration.mockRejectedValue(apiError);
145
+ mockUtils.handleCommandError.mockImplementation(() => { });
146
+ const program = (0, getMigration_1.default)();
147
+ yield program.parseAsync([
148
+ 'node',
149
+ 'dxp-cli',
150
+ '--migration-id',
151
+ 'migration-123',
152
+ '--asset-id',
153
+ 'asset-456',
154
+ ]);
155
+ expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, apiError);
156
+ }));
157
+ it('should handle network error', () => __awaiter(void 0, void 0, void 0, function* () {
158
+ const networkError = new Error('Network connection failed');
159
+ mockUtils.getMigration.mockRejectedValue(networkError);
160
+ mockUtils.handleCommandError.mockImplementation(() => { });
161
+ const program = (0, getMigration_1.default)();
162
+ yield program.parseAsync([
163
+ 'node',
164
+ 'dxp-cli',
165
+ '--migration-id',
166
+ 'migration-123',
167
+ '--asset-id',
168
+ 'asset-456',
169
+ ]);
170
+ expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, networkError);
171
+ }));
172
+ });
173
+ describe('required options validation', () => {
174
+ it('should require migration-id option', () => {
175
+ const program = (0, getMigration_1.default)().exitOverride();
176
+ expect(() => {
177
+ program.parse(['node', 'dxp-cli', '--asset-id', 'asset-456']);
178
+ }).toThrow();
179
+ });
180
+ it('should not require asset-id option', () => {
181
+ const program = (0, getMigration_1.default)().exitOverride();
182
+ expect(() => {
183
+ program.parse(['node', 'dxp-cli', '--migration-id', 'migration-123']);
184
+ }).not.toThrow();
185
+ });
186
+ });
187
+ describe('command configuration', () => {
188
+ it('should have correct command name and description', () => {
189
+ const program = (0, getMigration_1.default)();
190
+ expect(program.name()).toBe('get');
191
+ expect(program.description()).toBe('Get a migration using the AI Page migration service');
192
+ });
193
+ it('should parse options correctly', () => {
194
+ const program = (0, getMigration_1.default)();
195
+ program.parse([
196
+ 'node',
197
+ 'dxp-cli',
198
+ '--migration-id',
199
+ 'migration-123',
200
+ '--asset-id',
201
+ 'asset-456',
202
+ '--tenant',
203
+ 'test-tenant',
204
+ ]);
205
+ const opts = program.opts();
206
+ expect(opts.migrationId).toBe('migration-123');
207
+ expect(opts.assetId).toBe('asset-456');
208
+ expect(opts.tenant).toBe('test-tenant');
209
+ });
210
+ it('should parse options with kebab-case to camelCase conversion', () => {
211
+ const program = (0, getMigration_1.default)();
212
+ program.parse([
213
+ 'node',
214
+ 'dxp-cli',
215
+ '--migration-id',
216
+ 'migration-123',
217
+ '--asset-id',
218
+ 'asset-456',
219
+ ]);
220
+ const opts = program.opts();
221
+ expect(opts.migrationId).toBe('migration-123');
222
+ expect(opts.assetId).toBe('asset-456');
223
+ });
224
+ });
225
+ describe('spinner and output behavior', () => {
226
+ it('should display appropriate spinner messages during execution', () => __awaiter(void 0, void 0, void 0, function* () {
227
+ const program = (0, getMigration_1.default)();
228
+ yield program.parseAsync([
229
+ 'node',
230
+ 'dxp-cli',
231
+ '--migration-id',
232
+ 'migration-123',
233
+ '--asset-id',
234
+ 'asset-456',
235
+ ]);
236
+ expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
237
+ expect(mockUtils.getMigration).toHaveBeenCalled();
238
+ }));
239
+ it('should format output correctly', () => __awaiter(void 0, void 0, void 0, function* () {
240
+ const program = (0, getMigration_1.default)();
241
+ yield program.parseAsync([
242
+ 'node',
243
+ 'dxp-cli',
244
+ '--migration-id',
245
+ 'migration-123',
246
+ '--asset-id',
247
+ 'asset-456',
248
+ ]);
249
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
250
+ migrationId: 'migration-123',
251
+ assetId: 'asset-456',
252
+ });
253
+ }));
254
+ });
255
+ describe('override URL configuration', () => {
256
+ it('should work with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
257
+ const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
258
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
259
+ const program = (0, getMigration_1.default)();
260
+ yield program.parseAsync([
261
+ 'node',
262
+ 'dxp-cli',
263
+ '--migration-id',
264
+ 'migration-123',
265
+ '--asset-id',
266
+ 'asset-456',
267
+ '--overrideUrl',
268
+ 'https://custom.migration.url',
269
+ ]);
270
+ expect(mockUtils.getMigration).toHaveBeenCalledWith({
271
+ migrationId: 'migration-123',
272
+ assetId: 'asset-456',
273
+ overrideUrl: 'https://custom.migration.url',
274
+ });
275
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
276
+ }));
277
+ });
278
+ });
@@ -5,8 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = require("commander");
7
7
  const createMigration_1 = __importDefault(require("./create/createMigration"));
8
+ const getMigration_1 = __importDefault(require("./get/getMigration"));
9
+ const setMigrationSettings_1 = __importDefault(require("./settings/setMigrationSettings"));
8
10
  const migrationCommand = new commander_1.Command('migration');
9
11
  migrationCommand
10
12
  .description('AI Page Migration Service Commands')
11
- .addCommand((0, createMigration_1.default)());
13
+ .addCommand((0, createMigration_1.default)())
14
+ .addCommand((0, getMigration_1.default)())
15
+ .addCommand((0, setMigrationSettings_1.default)());
12
16
  exports.default = migrationCommand;
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const setMigrationSettingsCommand: () => Command;
3
+ export default setMigrationSettingsCommand;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const chalk_1 = __importDefault(require("chalk"));
16
+ const commander_1 = require("commander");
17
+ const utils_1 = require("../utils");
18
+ const ora_1 = __importDefault(require("ora"));
19
+ const setMigrationSettingsCommand = () => {
20
+ const settingsCommand = new commander_1.Command('settings')
21
+ .name('settings')
22
+ .description('Set settings for the migration service')
23
+ .addOption(new commander_1.Option('--matrix-url <string>', 'The URL of the Matrix instance').makeOptionMandatory())
24
+ .addOption(new commander_1.Option('--matrix-identifier <string>', 'The component service identifier used by the asset and components being migrated').makeOptionMandatory())
25
+ .addOption(new commander_1.Option('--matrix-key <string>', 'The Asset Management API key for the Migrator API to interact with Matrix API').makeOptionMandatory())
26
+ .addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
27
+ .configureOutput({
28
+ outputError(str, write) {
29
+ write(chalk_1.default.red(str));
30
+ },
31
+ })
32
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const spinner = (0, ora_1.default)('Setting migration configuration...').start();
34
+ yield (0, utils_1.throwErrorIfNotLoggedIn)(settingsCommand);
35
+ try {
36
+ const response = yield (0, utils_1.setMigrationSetting)(options);
37
+ spinner.succeed(`Migration settings updated: ${JSON.stringify(response, null, 2)}`);
38
+ }
39
+ catch (error) {
40
+ spinner.fail();
41
+ (0, utils_1.handleCommandError)(settingsCommand, error);
42
+ }
43
+ }));
44
+ if (process.env.ENABLE_OVERRIDE_MIGRATION_URL === 'true') {
45
+ settingsCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value'));
46
+ }
47
+ return settingsCommand;
48
+ };
49
+ exports.default = setMigrationSettingsCommand;
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const nock_1 = __importDefault(require("nock"));
39
+ const setMigrationSettings_1 = __importDefault(require("./setMigrationSettings"));
40
+ const utils = __importStar(require("../utils"));
41
+ const ApplicationStore = __importStar(require("../../ApplicationStore"));
42
+ jest.mock('../utils');
43
+ jest.mock('../../ApplicationStore');
44
+ const mockUtils = utils;
45
+ const mockApplicationStore = ApplicationStore;
46
+ describe('setMigrationSettingsCommand', () => {
47
+ let logSpy;
48
+ let mockSetMigrationSettingResponse;
49
+ beforeEach(() => {
50
+ nock_1.default.cleanAll();
51
+ jest.clearAllMocks();
52
+ jest.resetAllMocks();
53
+ logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
54
+ mockApplicationStore.getApplicationFile.mockResolvedValue('session-cookie');
55
+ mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue(undefined);
56
+ mockSetMigrationSettingResponse = {
57
+ matrixUrl: 'https://matrix.example.com',
58
+ matrixIdentifier: '@user:matrix.example.com',
59
+ matrixKey: '***********123',
60
+ };
61
+ mockUtils.setMigrationSetting.mockResolvedValue(mockSetMigrationSettingResponse);
62
+ });
63
+ afterEach(() => {
64
+ logSpy.mockRestore();
65
+ });
66
+ describe('successful migration setting update', () => {
67
+ it('should set migration settings successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const program = (0, setMigrationSettings_1.default)();
69
+ yield program.parseAsync([
70
+ 'node',
71
+ 'dxp-cli',
72
+ 'migration',
73
+ 'settings',
74
+ '--matrix-url',
75
+ 'https://matrix.example.com',
76
+ '--matrix-identifier',
77
+ '@user:matrix.example.com',
78
+ '--matrix-key',
79
+ 'secret-key-123',
80
+ ]);
81
+ expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
82
+ expect(mockUtils.setMigrationSetting).toHaveBeenCalledWith({
83
+ matrixUrl: 'https://matrix.example.com',
84
+ matrixIdentifier: '@user:matrix.example.com',
85
+ matrixKey: 'secret-key-123',
86
+ });
87
+ expect(mockUtils.setMigrationSetting).toHaveBeenCalledTimes(1);
88
+ expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
89
+ }));
90
+ it('should set migration settings with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
91
+ const program = (0, setMigrationSettings_1.default)();
92
+ yield program.parseAsync([
93
+ 'node',
94
+ 'dxp-cli',
95
+ 'migration',
96
+ 'settings',
97
+ '--matrix-url',
98
+ 'https://matrix.example.com',
99
+ '--matrix-identifier',
100
+ '@user:matrix.example.com',
101
+ '--matrix-key',
102
+ 'secret-key-123',
103
+ '--tenant',
104
+ 'test-tenant',
105
+ ]);
106
+ expect(mockUtils.setMigrationSetting).toHaveBeenCalledWith({
107
+ matrixUrl: 'https://matrix.example.com',
108
+ matrixIdentifier: '@user:matrix.example.com',
109
+ matrixKey: 'secret-key-123',
110
+ tenant: 'test-tenant',
111
+ });
112
+ }));
113
+ it('should set migration settings with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
114
+ const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
115
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
116
+ const program = (0, setMigrationSettings_1.default)();
117
+ yield program.parseAsync([
118
+ 'node',
119
+ 'dxp-cli',
120
+ 'migration',
121
+ 'settings',
122
+ '--matrix-url',
123
+ 'https://matrix.example.com',
124
+ '--matrix-identifier',
125
+ '@user:matrix.example.com',
126
+ '--matrix-key',
127
+ 'secret-key-123',
128
+ '--overrideUrl',
129
+ 'https://custom.migration.url',
130
+ ]);
131
+ expect(mockUtils.setMigrationSetting).toHaveBeenCalledWith({
132
+ matrixUrl: 'https://matrix.example.com',
133
+ matrixIdentifier: '@user:matrix.example.com',
134
+ matrixKey: 'secret-key-123',
135
+ overrideUrl: 'https://custom.migration.url',
136
+ });
137
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
138
+ }));
139
+ });
140
+ describe('error scenarios', () => {
141
+ it('should handle setMigrationSetting API error', () => __awaiter(void 0, void 0, void 0, function* () {
142
+ const apiError = new Error('Settings update failed');
143
+ mockUtils.setMigrationSetting.mockRejectedValue(apiError);
144
+ mockUtils.handleCommandError.mockImplementation(() => { });
145
+ const program = (0, setMigrationSettings_1.default)();
146
+ yield program.parseAsync([
147
+ 'node',
148
+ 'dxp-cli',
149
+ 'migration',
150
+ 'settings',
151
+ '--matrix-url',
152
+ 'https://matrix.example.com',
153
+ '--matrix-identifier',
154
+ '@user:matrix.example.com',
155
+ '--matrix-key',
156
+ 'secret-key-123',
157
+ ]);
158
+ expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, apiError);
159
+ }));
160
+ it('should handle network error', () => __awaiter(void 0, void 0, void 0, function* () {
161
+ const networkError = new Error('Network connection failed');
162
+ mockUtils.setMigrationSetting.mockRejectedValue(networkError);
163
+ mockUtils.handleCommandError.mockImplementation(() => { });
164
+ const program = (0, setMigrationSettings_1.default)();
165
+ yield program.parseAsync([
166
+ 'node',
167
+ 'dxp-cli',
168
+ 'migration',
169
+ 'settings',
170
+ '--matrix-url',
171
+ 'https://matrix.example.com',
172
+ '--matrix-identifier',
173
+ '@user:matrix.example.com',
174
+ '--matrix-key',
175
+ 'secret-key-123',
176
+ ]);
177
+ expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, networkError);
178
+ }));
179
+ });
180
+ describe('required options validation', () => {
181
+ it('should require matrixUrl option', () => {
182
+ const program = (0, setMigrationSettings_1.default)().exitOverride();
183
+ expect(() => {
184
+ program.parse([
185
+ 'node',
186
+ 'dxp-cli',
187
+ 'migration',
188
+ 'settings',
189
+ '--matrix-identifier',
190
+ '@user:matrix.example.com',
191
+ '--matrix-key',
192
+ 'secret-key-123',
193
+ ]);
194
+ }).toThrow();
195
+ });
196
+ it('should require matrixIdentifier option', () => {
197
+ const program = (0, setMigrationSettings_1.default)().exitOverride();
198
+ expect(() => {
199
+ program.parse([
200
+ 'node',
201
+ 'dxp-cli',
202
+ 'migration',
203
+ 'settings',
204
+ '--matrix-url',
205
+ 'https://matrix.example.com',
206
+ '--matrix-key',
207
+ 'secret-key-123',
208
+ ]);
209
+ }).toThrow();
210
+ });
211
+ it('should require matrixKey option', () => {
212
+ const program = (0, setMigrationSettings_1.default)().exitOverride();
213
+ expect(() => {
214
+ program.parse([
215
+ 'node',
216
+ 'dxp-cli',
217
+ 'migration',
218
+ 'settings',
219
+ '--matrix-url',
220
+ 'https://matrix.example.com',
221
+ '--matrix-identifier',
222
+ '@user:matrix.example.com',
223
+ ]);
224
+ }).toThrow();
225
+ });
226
+ });
227
+ describe('command configuration', () => {
228
+ it('should have correct command name and description', () => {
229
+ const program = (0, setMigrationSettings_1.default)();
230
+ expect(program.name()).toBe('settings');
231
+ expect(program.description()).toBe('Set settings for the migration service');
232
+ });
233
+ it('should parse options correctly', () => {
234
+ const program = (0, setMigrationSettings_1.default)();
235
+ program.parse([
236
+ 'node',
237
+ 'dxp-cli',
238
+ 'migration',
239
+ 'settings',
240
+ '--matrix-url',
241
+ 'https://matrix.example.com',
242
+ '--matrix-identifier',
243
+ '@user:matrix.example.com',
244
+ '--matrix-key',
245
+ 'secret-key-123',
246
+ '--tenant',
247
+ 'test-tenant',
248
+ ]);
249
+ const opts = program.opts();
250
+ expect(opts.matrixUrl).toBe('https://matrix.example.com');
251
+ expect(opts.matrixIdentifier).toBe('@user:matrix.example.com');
252
+ expect(opts.matrixKey).toBe('secret-key-123');
253
+ expect(opts.tenant).toBe('test-tenant');
254
+ });
255
+ it('should parse options with kebab-case to camelCase conversion', () => {
256
+ const program = (0, setMigrationSettings_1.default)();
257
+ program.parse([
258
+ 'node',
259
+ 'dxp-cli',
260
+ 'migration',
261
+ 'settings',
262
+ '--matrix-url',
263
+ 'https://matrix.example.com',
264
+ '--matrix-identifier',
265
+ '@user:matrix.example.com',
266
+ '--matrix-key',
267
+ 'secret-key-123',
268
+ ]);
269
+ const opts = program.opts();
270
+ expect(opts.matrixUrl).toBe('https://matrix.example.com');
271
+ expect(opts.matrixIdentifier).toBe('@user:matrix.example.com');
272
+ expect(opts.matrixKey).toBe('secret-key-123');
273
+ });
274
+ });
275
+ });
@@ -0,0 +1,49 @@
1
+ export interface CreateMigrationOptions {
2
+ assetId: string;
3
+ previewAssetId: string;
4
+ matrixUrl: string;
5
+ tenant?: string;
6
+ overrideUrl?: string;
7
+ }
8
+ export interface CreateMigrationAPIResponse {
9
+ assetMigration: {
10
+ migrationId: string;
11
+ assetId: string;
12
+ xmlFilePath: string;
13
+ matrixUrl: string;
14
+ previewAssetId: string;
15
+ stage: string;
16
+ status: string;
17
+ created: number;
18
+ updated: number;
19
+ migrationIdAssetId: string;
20
+ };
21
+ uploadUrl: string;
22
+ }
23
+ export interface GetMigrationOptions {
24
+ migrationId: string;
25
+ assetId: string;
26
+ tenant?: string;
27
+ overrideUrl?: string;
28
+ }
29
+ export interface GetMigrationAPIResponse {
30
+ migrationId: string;
31
+ assetId: string;
32
+ stage: string;
33
+ status: string;
34
+ stageDetails?: string;
35
+ previewPageAssetId?: string;
36
+ componentsTarDownloadUrl?: string;
37
+ }
38
+ export interface SetMigrationSettingOptions {
39
+ matrixUrl: string;
40
+ matrixIdentifier: string;
41
+ matrixKey: string;
42
+ tenant?: string;
43
+ overrideUrl?: string;
44
+ }
45
+ export interface SetMigrationSettingAPIResponse {
46
+ matrixUrl: string;
47
+ matrixIdentifier: string;
48
+ matrixKey: string;
49
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,32 +1,14 @@
1
1
  import { Command } from 'commander';
2
- export interface CreateMigrationOptions {
3
- assetId: string;
4
- previewAssetId: string;
5
- matrixUrl: string;
6
- tenant?: string;
7
- overrideUrl?: string;
8
- }
9
- export interface CreateMigrationAPIResponse {
10
- assetMigration: {
11
- migrationId: string;
12
- assetId: string;
13
- xmlFilePath: string;
14
- matrixUrl: string;
15
- previewAssetId: string;
16
- stage: string;
17
- status: string;
18
- created: number;
19
- updated: number;
20
- migrationIdAssetId: string;
21
- };
22
- uploadUrl: string;
23
- }
2
+ import { CreateMigrationOptions, CreateMigrationAPIResponse, GetMigrationOptions, GetMigrationAPIResponse, SetMigrationSettingOptions, SetMigrationSettingAPIResponse } from './types';
24
3
  export declare function handleCommandError(command: Command, error: Error): void;
25
4
  export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
26
5
  export declare function buildMigrationUrl(tenantID?: string, overrideUrl?: string): Promise<string>;
27
6
  export declare function validateAxiosStatus(status: number): boolean;
7
+ export declare function redactKey(key: string, visibleChars?: number): string;
28
8
  export declare function validateExportFolder(exportPath: string): void;
29
9
  export declare function createTarFile(exportPath: string): Promise<string>;
30
10
  export declare function getMigrationHeaders(tenantID?: string): Promise<Record<string, string>>;
31
11
  export declare function uploadFileToS3(uploadUrl: string, filePath: string, tenantID?: string): Promise<string>;
32
12
  export declare function createMigration(options: CreateMigrationOptions): Promise<CreateMigrationAPIResponse>;
13
+ export declare function getMigration(options: GetMigrationOptions): Promise<GetMigrationAPIResponse>;
14
+ export declare function setMigrationSetting(options: SetMigrationSettingOptions): Promise<SetMigrationSettingAPIResponse>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createMigration = exports.uploadFileToS3 = exports.getMigrationHeaders = exports.createTarFile = exports.validateExportFolder = exports.validateAxiosStatus = exports.buildMigrationUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
15
+ exports.setMigrationSetting = exports.getMigration = exports.createMigration = exports.uploadFileToS3 = exports.getMigrationHeaders = exports.createTarFile = exports.validateExportFolder = exports.redactKey = exports.validateAxiosStatus = exports.buildMigrationUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
16
16
  const fs_1 = __importDefault(require("fs"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const chalk_1 = __importDefault(require("chalk"));
@@ -70,6 +70,16 @@ function validateAxiosStatus(status) {
70
70
  return status < 400;
71
71
  }
72
72
  exports.validateAxiosStatus = validateAxiosStatus;
73
+ function redactKey(key, visibleChars = 3) {
74
+ if (!key)
75
+ return '';
76
+ const len = key.length;
77
+ if (len <= visibleChars)
78
+ return '*'.repeat(len);
79
+ const masked = '*'.repeat(len - visibleChars);
80
+ return masked + key.slice(-visibleChars);
81
+ }
82
+ exports.redactKey = redactKey;
73
83
  function validateExportFolder(exportPath) {
74
84
  // Check if the export folder exists
75
85
  if (!fs_1.default.existsSync(exportPath)) {
@@ -188,3 +198,77 @@ function createMigration(options) {
188
198
  });
189
199
  }
190
200
  exports.createMigration = createMigration;
201
+ function getMigration(options) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ const apiService = new ApiService_1.ApiService({
204
+ validateStatus: validateAxiosStatus,
205
+ });
206
+ const migrationUrl = yield buildMigrationUrl(options.tenant, options.overrideUrl);
207
+ try {
208
+ const response = yield apiService.client.get(`${migrationUrl}/migrations/${options.migrationId}/assets/${options.assetId}`, {
209
+ headers: Object.assign({ 'Content-Type': 'application/json' }, (yield getMigrationHeaders(options.tenant))),
210
+ });
211
+ if (response.status !== 200) {
212
+ throw new Error(`Failed to get migration: ${response.status}`);
213
+ }
214
+ if (!(response === null || response === void 0 ? void 0 : response.data)) {
215
+ throw new Error('No data returned from migration service');
216
+ }
217
+ return {
218
+ migrationId: response.data.migrationId,
219
+ assetId: response.data.assetId,
220
+ stage: response.data.stage,
221
+ status: response.data.status,
222
+ stageDetails: response.data.stageDetails,
223
+ previewPageAssetId: response.data.previewPageAssetId,
224
+ componentsTarDownloadUrl: response.data.componentsTarDownloadUrl,
225
+ };
226
+ }
227
+ catch (error) {
228
+ if (error instanceof Error) {
229
+ throw error;
230
+ }
231
+ throw new Error(`Failed to get migration: ${error}`);
232
+ }
233
+ });
234
+ }
235
+ exports.getMigration = getMigration;
236
+ function setMigrationSetting(options) {
237
+ return __awaiter(this, void 0, void 0, function* () {
238
+ const apiService = new ApiService_1.ApiService({
239
+ validateStatus: validateAxiosStatus,
240
+ });
241
+ const migrationUrl = yield buildMigrationUrl(options.tenant, options.overrideUrl);
242
+ try {
243
+ const payload = {
244
+ matrixUrl: options.matrixUrl,
245
+ matrixIdentifier: options.matrixIdentifier,
246
+ matrixKey: options.matrixKey,
247
+ };
248
+ const response = yield apiService.client.post(`${migrationUrl}/settings`, payload, {
249
+ headers: Object.assign({ 'Content-Type': 'application/json' }, (yield getMigrationHeaders(options.tenant))),
250
+ });
251
+ if (response.status !== 200 && response.status !== 201) {
252
+ throw new Error(`Migration settings update failed with status: ${response.status}`);
253
+ }
254
+ if (!(response === null || response === void 0 ? void 0 : response.data)) {
255
+ throw new Error('No data returned from migration service');
256
+ }
257
+ const responseData = {
258
+ matrixUrl: response.data.matrixUrl,
259
+ matrixIdentifier: response.data.matrixIdentifier,
260
+ matrixKey: response.data.matrixKey
261
+ ? redactKey(response.data.matrixKey, 3)
262
+ : '',
263
+ };
264
+ return responseData;
265
+ }
266
+ catch (error) {
267
+ if (error instanceof Error) {
268
+ throw error;
269
+ }
270
+ throw new Error(`Failed to set migration settings: ${error}`);
271
+ }
272
+ });
273
+ }
274
+ exports.setMigrationSetting = setMigrationSetting;
@@ -145,6 +145,13 @@ describe('Migration Utils', () => {
145
145
  expect((0, utils_1.validateAxiosStatus)(500)).toBe(false);
146
146
  });
147
147
  });
148
+ describe('redactKey', () => {
149
+ it('redacts key correctly', () => {
150
+ expect((0, utils_1.redactKey)('1234567890', 3)).toBe('*******890');
151
+ expect((0, utils_1.redactKey)('1234567890', 1)).toBe('*********0');
152
+ expect((0, utils_1.redactKey)('1234567890', 10)).toBe('**********');
153
+ });
154
+ });
148
155
  describe('validateExportFolder', () => {
149
156
  beforeEach(() => {
150
157
  mockPath.join.mockImplementation((...paths) => paths.join('/'));
@@ -408,4 +415,136 @@ describe('Migration Utils', () => {
408
415
  yield expect((0, utils_1.createMigration)(mockOptions)).rejects.toThrow('Failed to create migration: Unknown error');
409
416
  }));
410
417
  });
418
+ describe('getMigration', () => {
419
+ let mockApiServiceInstance;
420
+ let mockOptions;
421
+ beforeEach(() => {
422
+ mockApiServiceInstance = {
423
+ client: {
424
+ get: jest.fn(),
425
+ },
426
+ };
427
+ mockApiService.mockImplementation(() => mockApiServiceInstance);
428
+ mockOptions = {
429
+ migrationId: 'migration-123',
430
+ assetId: 'asset-456',
431
+ tenant: 'test-tenant',
432
+ };
433
+ mockFetchApplicationConfig.mockResolvedValue({
434
+ tenant: 'test-tenant',
435
+ baseUrl: 'https://example.com',
436
+ region: 'au',
437
+ });
438
+ });
439
+ it('gets migration successfully', () => __awaiter(void 0, void 0, void 0, function* () {
440
+ const mockResponse = {
441
+ status: 200,
442
+ data: {
443
+ migrationId: 'migration-123',
444
+ assetId: 'asset-456',
445
+ stage: 'completed',
446
+ status: 'success',
447
+ stageDetails: 'Migration completed successfully',
448
+ previewPageAssetId: 'preview-789',
449
+ componentsTarDownloadUrl: 'https://download.example.com/components.zip',
450
+ },
451
+ };
452
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
453
+ const result = yield (0, utils_1.getMigration)(mockOptions);
454
+ expect(result).toEqual({
455
+ migrationId: 'migration-123',
456
+ assetId: 'asset-456',
457
+ stage: 'completed',
458
+ status: 'success',
459
+ stageDetails: 'Migration completed successfully',
460
+ previewPageAssetId: 'preview-789',
461
+ componentsTarDownloadUrl: 'https://download.example.com/components.zip',
462
+ });
463
+ expect(mockApiServiceInstance.client.get).toHaveBeenCalledWith('https://example.com/__dxp/service/aiapps/migration/migrations/migration-123/assets/asset-456', {
464
+ headers: {
465
+ 'Content-Type': 'application/json',
466
+ 'x-dxp-tenant': 'test-tenant',
467
+ },
468
+ });
469
+ }));
470
+ it('gets migration with override URL', () => __awaiter(void 0, void 0, void 0, function* () {
471
+ const optionsWithOverride = Object.assign(Object.assign({}, mockOptions), { overrideUrl: 'https://custom.migration.url' });
472
+ const mockResponse = {
473
+ status: 200,
474
+ data: {
475
+ migrationId: 'migration-123',
476
+ assetId: 'asset-456',
477
+ stage: 'pending',
478
+ status: 'processing',
479
+ },
480
+ };
481
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
482
+ const result = yield (0, utils_1.getMigration)(optionsWithOverride);
483
+ expect(result.migrationId).toBe('migration-123');
484
+ expect(result.assetId).toBe('asset-456');
485
+ expect(mockApiServiceInstance.client.get).toHaveBeenCalledWith('https://custom.migration.url/migrations/migration-123/assets/asset-456', expect.any(Object));
486
+ }));
487
+ it('handles non-success status codes', () => __awaiter(void 0, void 0, void 0, function* () {
488
+ const mockResponse = {
489
+ status: 404,
490
+ data: {},
491
+ };
492
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
493
+ yield expect((0, utils_1.getMigration)(mockOptions)).rejects.toThrow('Failed to get migration: 404');
494
+ }));
495
+ it('handles missing response data', () => __awaiter(void 0, void 0, void 0, function* () {
496
+ const mockResponse = {
497
+ status: 200,
498
+ data: null,
499
+ };
500
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
501
+ yield expect((0, utils_1.getMigration)(mockOptions)).rejects.toThrow('No data returned from migration service');
502
+ }));
503
+ it('handles API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
504
+ const error = new Error('Network error');
505
+ mockApiServiceInstance.client.get.mockRejectedValue(error);
506
+ yield expect((0, utils_1.getMigration)(mockOptions)).rejects.toThrow('Network error');
507
+ }));
508
+ it('handles unknown errors', () => __awaiter(void 0, void 0, void 0, function* () {
509
+ mockApiServiceInstance.client.get.mockRejectedValue('Unknown error');
510
+ yield expect((0, utils_1.getMigration)(mockOptions)).rejects.toThrow('Failed to get migration: Unknown error');
511
+ }));
512
+ it('works without optional fields in response', () => __awaiter(void 0, void 0, void 0, function* () {
513
+ const mockResponse = {
514
+ status: 200,
515
+ data: {
516
+ migrationId: 'migration-123',
517
+ assetId: 'asset-456',
518
+ stage: 'pending',
519
+ status: 'processing',
520
+ // No optional fields: stageDetails, previewPageAssetId, componentsTarDownloadUrl
521
+ },
522
+ };
523
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
524
+ const result = yield (0, utils_1.getMigration)(mockOptions);
525
+ expect(result).toEqual({
526
+ migrationId: 'migration-123',
527
+ assetId: 'asset-456',
528
+ stage: 'pending',
529
+ status: 'processing',
530
+ stageDetails: undefined,
531
+ previewPageAssetId: undefined,
532
+ componentsTarDownloadUrl: undefined,
533
+ });
534
+ }));
535
+ it('constructs correct URL path', () => __awaiter(void 0, void 0, void 0, function* () {
536
+ const mockResponse = {
537
+ status: 200,
538
+ data: {
539
+ migrationId: 'migration-123',
540
+ assetId: 'asset-456',
541
+ stage: 'completed',
542
+ status: 'success',
543
+ },
544
+ };
545
+ mockApiServiceInstance.client.get.mockResolvedValue(mockResponse);
546
+ yield (0, utils_1.getMigration)(mockOptions);
547
+ expect(mockApiServiceInstance.client.get).toHaveBeenCalledWith('https://example.com/__dxp/service/aiapps/migration/migrations/migration-123/assets/asset-456', expect.any(Object));
548
+ }));
549
+ });
411
550
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.26.0-develop.1",
3
+ "version": "5.26.0-develop.3",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },