@squiz/dxp-cli-next 5.33.0-develop.2 → 5.33.0-develop.4
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 +1 -0
- package/lib/migration/batch-get/batch-get.d.ts +3 -0
- package/lib/migration/batch-get/batch-get.js +45 -0
- package/lib/migration/batch-get/batch-get.spec.js +182 -0
- package/lib/migration/batch-next/batch-next.d.ts +3 -0
- package/lib/migration/batch-next/batch-next.js +60 -0
- package/lib/migration/batch-next/batch-next.spec.d.ts +1 -0
- package/lib/migration/batch-next/batch-next.spec.js +251 -0
- package/lib/migration/batch-revert/batch-revert.d.ts +3 -0
- package/lib/migration/batch-revert/batch-revert.js +45 -0
- package/lib/migration/batch-revert/batch-revert.spec.d.ts +1 -0
- package/lib/migration/batch-revert/batch-revert.spec.js +197 -0
- package/lib/migration/create/create.js +27 -7
- package/lib/migration/create/create.spec.js +48 -20
- package/lib/migration/get/get.js +3 -3
- package/lib/migration/get/get.spec.js +8 -19
- package/lib/migration/index.js +9 -1
- package/lib/migration/list/list.spec.js +7 -6
- package/lib/migration/mark-deployed/mark-deployed.d.ts +3 -0
- package/lib/migration/mark-deployed/mark-deployed.js +55 -0
- package/lib/migration/mark-deployed/mark-deployed.spec.d.ts +1 -0
- package/lib/migration/mark-deployed/mark-deployed.spec.js +217 -0
- package/lib/migration/next/next.spec.js +6 -5
- package/lib/migration/pre/pre.js +3 -3
- package/lib/migration/pre/pre.spec.js +8 -8
- package/lib/migration/revert/revert.js +1 -1
- package/lib/migration/revert/revert.spec.js +1 -1
- package/lib/migration/settings/settings.spec.js +2 -2
- package/lib/migration/types/common.types.d.ts +33 -2
- package/lib/migration/types/common.types.js +17 -0
- package/lib/migration/types/createMigration.types.d.ts +41 -3
- package/lib/migration/types/getMigration.types.d.ts +5 -1
- package/lib/migration/types/index.d.ts +1 -0
- package/lib/migration/types/index.js +1 -0
- package/lib/migration/types/markDeployed.types.d.ts +20 -0
- package/lib/migration/types/markDeployed.types.js +2 -0
- package/lib/migration/types/nextStage.types.d.ts +22 -1
- package/lib/migration/types/revert.types.d.ts +12 -0
- package/lib/migration/utils/common.d.ts +17 -3
- package/lib/migration/utils/common.js +56 -24
- package/lib/migration/utils/common.spec.js +73 -2
- package/lib/migration/utils/createMigration.d.ts +4 -21
- package/lib/migration/utils/createMigration.js +23 -32
- package/lib/migration/utils/createMigration.spec.js +19 -18
- package/lib/migration/utils/getMigration.d.ts +2 -1
- package/lib/migration/utils/getMigration.js +23 -18
- package/lib/migration/utils/getMigration.spec.js +146 -7
- package/lib/migration/utils/index.d.ts +1 -0
- package/lib/migration/utils/index.js +1 -0
- package/lib/migration/utils/listMigrations.spec.js +7 -6
- package/lib/migration/utils/loadAssetIdsFromFile.d.ts +9 -0
- package/lib/migration/utils/loadAssetIdsFromFile.js +40 -0
- package/lib/migration/utils/loadAssetIdsFromFile.spec.d.ts +1 -0
- package/lib/migration/utils/{loadCctIdsFromFile.spec.js → loadAssetIdsFromFile.spec.js} +13 -13
- package/lib/migration/utils/loadStageOptionsFromFile.d.ts +2 -1
- package/lib/migration/utils/markComponentsDeployed.d.ts +2 -0
- package/lib/migration/utils/markComponentsDeployed.js +37 -0
- package/lib/migration/utils/markComponentsDeployed.spec.d.ts +1 -0
- package/lib/migration/utils/markComponentsDeployed.spec.js +222 -0
- package/lib/migration/utils/nextStage.d.ts +2 -1
- package/lib/migration/utils/nextStage.js +32 -22
- package/lib/migration/utils/nextStage.spec.js +179 -7
- package/lib/migration/utils/options.d.ts +4 -1
- package/lib/migration/utils/options.js +32 -2
- package/lib/migration/utils/revertMigration.d.ts +2 -1
- package/lib/migration/utils/revertMigration.js +21 -1
- package/lib/migration/utils/revertMigration.spec.js +115 -0
- package/lib/page/utils/definitions.js +1 -1
- package/lib/page/utils/definitions.spec.js +19 -8
- package/package.json +1 -1
- package/lib/migration/utils/loadCctIdsFromFile.d.ts +0 -1
- package/lib/migration/utils/loadCctIdsFromFile.js +0 -32
- /package/lib/migration/{utils/loadCctIdsFromFile.spec.d.ts → batch-get/batch-get.spec.d.ts} +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
2
|
+
import { CreateMigrationApiResponse } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* The purpose of this file is to provide utilities in common
|
|
5
5
|
* such as functions that can be reused across the migration service.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Handles errors from the migration service.
|
|
9
|
+
* Formats and displays the error message, then terminates the process.
|
|
9
10
|
* @param command - The command that is being executed.
|
|
10
11
|
* @param error - The error that occurred.
|
|
11
12
|
*/
|
|
12
|
-
export declare function handleCommandError(command: Command, error:
|
|
13
|
+
export declare function handleCommandError(command: Command, error: unknown): never;
|
|
13
14
|
/**
|
|
14
15
|
* Throws an error if the user is not logged in.
|
|
15
16
|
* @param command - The command that is being executed.
|
|
@@ -30,10 +31,23 @@ export declare function buildMigrationUrl(tenantID?: string, overrideUrl?: strin
|
|
|
30
31
|
export declare function validateAxiosStatus(status: number): boolean;
|
|
31
32
|
export declare function getMigrationHeaders(tenantID?: string, isJson?: boolean): Promise<Record<string, string>>;
|
|
32
33
|
export declare function redactKey(key: string, visibleChars?: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Formats batch operation results (batch-next, batch-revert) into a human-readable string.
|
|
36
|
+
* @param success - Array of successful operations with asset IDs and messages.
|
|
37
|
+
* @param failed - Array of failed operations with asset IDs and error messages.
|
|
38
|
+
* @returns Formatted string with colored output.
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatBatchOperationResult(success: {
|
|
41
|
+
assetIds: string[];
|
|
42
|
+
message: string;
|
|
43
|
+
}[], failed: {
|
|
44
|
+
assetIds: string[];
|
|
45
|
+
error: string;
|
|
46
|
+
}[]): string;
|
|
33
47
|
/**
|
|
34
48
|
* Builds a success message for migration creation.
|
|
35
49
|
* @param label - The label for the migration type (e.g., "migration" or "pre-migration").
|
|
36
50
|
* @param assetMigration - The asset migration response.
|
|
37
51
|
* @returns The formatted success message.
|
|
38
52
|
*/
|
|
39
|
-
export declare function buildMigrationSuccessMessage(label: string,
|
|
53
|
+
export declare function buildMigrationSuccessMessage(label: string, response: CreateMigrationApiResponse): string;
|
|
@@ -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.buildMigrationSuccessMessage = exports.redactKey = exports.getMigrationHeaders = exports.validateAxiosStatus = exports.buildMigrationUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
|
|
15
|
+
exports.buildMigrationSuccessMessage = exports.formatBatchOperationResult = exports.redactKey = exports.getMigrationHeaders = exports.validateAxiosStatus = exports.buildMigrationUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const ApplicationConfig_1 = require("../../ApplicationConfig");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -23,31 +23,41 @@ const ApplicationStore_1 = require("../../ApplicationStore");
|
|
|
23
23
|
*/
|
|
24
24
|
/**
|
|
25
25
|
* Handles errors from the migration service.
|
|
26
|
+
* Formats and displays the error message, then terminates the process.
|
|
26
27
|
* @param command - The command that is being executed.
|
|
27
28
|
* @param error - The error that occurred.
|
|
28
29
|
*/
|
|
29
30
|
function handleCommandError(command, error) {
|
|
30
31
|
var _a, _b, _c, _d;
|
|
32
|
+
let message;
|
|
31
33
|
if (axios_1.default.isAxiosError(error)) {
|
|
32
|
-
|
|
34
|
+
// Build message from AxiosError components
|
|
35
|
+
const parts = [error.message];
|
|
33
36
|
if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
|
|
34
|
-
|
|
37
|
+
parts.push(error.response.data.message);
|
|
35
38
|
}
|
|
36
39
|
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.details) {
|
|
37
|
-
|
|
40
|
+
const details = error.response.data.details;
|
|
41
|
+
parts.push(typeof details === 'string' ? details : JSON.stringify(details, null, 2));
|
|
38
42
|
}
|
|
39
|
-
|
|
43
|
+
// Handle network errors (no response received from server)
|
|
44
|
+
if (!error.response && error.request) {
|
|
45
|
+
parts.push('No response received from server');
|
|
46
|
+
}
|
|
47
|
+
message = parts.join(': ');
|
|
48
|
+
}
|
|
49
|
+
else if (error instanceof Error) {
|
|
50
|
+
message = error.message || 'An unknown error occurred';
|
|
40
51
|
}
|
|
41
52
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
53
|
+
message = 'An unknown error occurred';
|
|
54
|
+
}
|
|
55
|
+
// Show stack trace in DEBUG mode, otherwise just the message
|
|
56
|
+
if (process.env.DEBUG && error instanceof Error && error.stack) {
|
|
57
|
+
command.error(chalk_1.default.red(`${message}\n\nStack trace:\n${error.stack}`));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
command.error(chalk_1.default.red(message));
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
exports.handleCommandError = handleCommandError;
|
|
@@ -114,21 +124,43 @@ function redactKey(key, visibleChars = 3) {
|
|
|
114
124
|
return masked + key.slice(-visibleChars);
|
|
115
125
|
}
|
|
116
126
|
exports.redactKey = redactKey;
|
|
127
|
+
/**
|
|
128
|
+
* Formats batch operation results (batch-next, batch-revert) into a human-readable string.
|
|
129
|
+
* @param success - Array of successful operations with asset IDs and messages.
|
|
130
|
+
* @param failed - Array of failed operations with asset IDs and error messages.
|
|
131
|
+
* @returns Formatted string with colored output.
|
|
132
|
+
*/
|
|
133
|
+
function formatBatchOperationResult(success, failed) {
|
|
134
|
+
const lines = [];
|
|
135
|
+
if (success.length > 0) {
|
|
136
|
+
lines.push(chalk_1.default.green('Successful:'));
|
|
137
|
+
success.forEach(({ assetIds, message }) => {
|
|
138
|
+
const idsStr = chalk_1.default.cyan(assetIds.join(', '));
|
|
139
|
+
lines.push(message ? ` ${idsStr}: ${message}` : ` ${idsStr}`);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (failed.length > 0) {
|
|
143
|
+
if (lines.length > 0)
|
|
144
|
+
lines.push('');
|
|
145
|
+
lines.push(chalk_1.default.red('Failed:'));
|
|
146
|
+
failed.forEach(({ assetIds, error }) => {
|
|
147
|
+
lines.push(` ${chalk_1.default.cyan(assetIds.join(', '))}: ${error}`);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (lines.length === 0) {
|
|
151
|
+
return 'No assets were processed';
|
|
152
|
+
}
|
|
153
|
+
return lines.join('\n');
|
|
154
|
+
}
|
|
155
|
+
exports.formatBatchOperationResult = formatBatchOperationResult;
|
|
117
156
|
/**
|
|
118
157
|
* Builds a success message for migration creation.
|
|
119
158
|
* @param label - The label for the migration type (e.g., "migration" or "pre-migration").
|
|
120
159
|
* @param assetMigration - The asset migration response.
|
|
121
160
|
* @returns The formatted success message.
|
|
122
161
|
*/
|
|
123
|
-
function buildMigrationSuccessMessage(label,
|
|
124
|
-
const
|
|
125
|
-
return `Successfully created ${label}
|
|
126
|
-
isPreMigration,
|
|
127
|
-
migrationId,
|
|
128
|
-
assetId,
|
|
129
|
-
stage,
|
|
130
|
-
status,
|
|
131
|
-
cctIds: (cctIds === null || cctIds === void 0 ? void 0 : cctIds.length) ? JSON.stringify(cctIds).substring(0, 100) : '[]',
|
|
132
|
-
})}`;
|
|
162
|
+
function buildMigrationSuccessMessage(label, response) {
|
|
163
|
+
const formattedResponse = JSON.stringify(response, null, 2);
|
|
164
|
+
return `Successfully created ${label}:\n${formattedResponse}`;
|
|
133
165
|
}
|
|
134
166
|
exports.buildMigrationSuccessMessage = buildMigrationSuccessMessage;
|
|
@@ -56,7 +56,7 @@ describe('Migration Utils', () => {
|
|
|
56
56
|
};
|
|
57
57
|
mockAxios.isAxiosError.mockReturnValue(true);
|
|
58
58
|
(0, _1.handleCommandError)(mockCommand, axiosError);
|
|
59
|
-
expect(mockCommand.error).toHaveBeenCalledWith(expect.stringContaining('Network Error: Server Error
|
|
59
|
+
expect(mockCommand.error).toHaveBeenCalledWith(expect.stringContaining('Network Error: Server Error: Additional details'));
|
|
60
60
|
});
|
|
61
61
|
it('handles axios errors without response data', () => {
|
|
62
62
|
const axiosError = {
|
|
@@ -86,7 +86,9 @@ describe('Migration Utils', () => {
|
|
|
86
86
|
error.stack = 'Error stack trace';
|
|
87
87
|
mockAxios.isAxiosError.mockReturnValue(false);
|
|
88
88
|
(0, _1.handleCommandError)(mockCommand, error);
|
|
89
|
-
expect(mockCommand.error).toHaveBeenCalledWith('
|
|
89
|
+
expect(mockCommand.error).toHaveBeenCalledWith(expect.stringContaining('Test error'));
|
|
90
|
+
expect(mockCommand.error).toHaveBeenCalledWith(expect.stringContaining('Stack trace:'));
|
|
91
|
+
expect(mockCommand.error).toHaveBeenCalledWith(expect.stringContaining('Error stack trace'));
|
|
90
92
|
process.env.DEBUG = originalDebug;
|
|
91
93
|
});
|
|
92
94
|
});
|
|
@@ -162,4 +164,73 @@ describe('Migration Utils', () => {
|
|
|
162
164
|
expect((0, _1.redactKey)('1234567890', 10)).toBe('**********');
|
|
163
165
|
});
|
|
164
166
|
});
|
|
167
|
+
describe('formatBatchOperationResult', () => {
|
|
168
|
+
it('formats successful results correctly', () => {
|
|
169
|
+
const success = [
|
|
170
|
+
{ assetIds: ['asset-1', 'asset-2'], message: 'Stage completed' },
|
|
171
|
+
];
|
|
172
|
+
const failed = [];
|
|
173
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
174
|
+
expect(result).toContain('Successful:');
|
|
175
|
+
expect(result).toContain('asset-1, asset-2');
|
|
176
|
+
expect(result).toContain('Stage completed');
|
|
177
|
+
});
|
|
178
|
+
it('formats failed results correctly', () => {
|
|
179
|
+
const success = [];
|
|
180
|
+
const failed = [{ assetIds: ['asset-3'], error: 'Migration failed' }];
|
|
181
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
182
|
+
expect(result).toContain('Failed:');
|
|
183
|
+
expect(result).toContain('asset-3');
|
|
184
|
+
expect(result).toContain('Migration failed');
|
|
185
|
+
});
|
|
186
|
+
it('formats mixed success and failed results correctly', () => {
|
|
187
|
+
const success = [{ assetIds: ['asset-1'], message: 'Completed' }];
|
|
188
|
+
const failed = [{ assetIds: ['asset-2'], error: 'Failed to process' }];
|
|
189
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
190
|
+
expect(result).toContain('Successful:');
|
|
191
|
+
expect(result).toContain('asset-1');
|
|
192
|
+
expect(result).toContain('Completed');
|
|
193
|
+
expect(result).toContain('Failed:');
|
|
194
|
+
expect(result).toContain('asset-2');
|
|
195
|
+
expect(result).toContain('Failed to process');
|
|
196
|
+
});
|
|
197
|
+
it('returns empty message when no results', () => {
|
|
198
|
+
const success = [];
|
|
199
|
+
const failed = [];
|
|
200
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
201
|
+
expect(result).toBe('No assets were processed');
|
|
202
|
+
});
|
|
203
|
+
it('handles multiple asset IDs in a single result', () => {
|
|
204
|
+
const success = [
|
|
205
|
+
{
|
|
206
|
+
assetIds: ['asset-1', 'asset-2', 'asset-3'],
|
|
207
|
+
message: 'All processed',
|
|
208
|
+
},
|
|
209
|
+
];
|
|
210
|
+
const failed = [];
|
|
211
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
212
|
+
expect(result).toContain('asset-1, asset-2, asset-3');
|
|
213
|
+
});
|
|
214
|
+
it('handles multiple success entries', () => {
|
|
215
|
+
const success = [
|
|
216
|
+
{ assetIds: ['asset-1'], message: 'First batch' },
|
|
217
|
+
{ assetIds: ['asset-2'], message: 'Second batch' },
|
|
218
|
+
];
|
|
219
|
+
const failed = [];
|
|
220
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
221
|
+
expect(result).toContain('asset-1');
|
|
222
|
+
expect(result).toContain('First batch');
|
|
223
|
+
expect(result).toContain('asset-2');
|
|
224
|
+
expect(result).toContain('Second batch');
|
|
225
|
+
});
|
|
226
|
+
it('handles empty message gracefully', () => {
|
|
227
|
+
const success = [{ assetIds: ['asset-1'], message: '' }];
|
|
228
|
+
const failed = [];
|
|
229
|
+
const result = (0, _1.formatBatchOperationResult)(success, failed);
|
|
230
|
+
expect(result).toContain('Successful:');
|
|
231
|
+
expect(result).toContain('asset-1');
|
|
232
|
+
// Should not have a trailing colon when message is empty
|
|
233
|
+
expect(result).not.toContain('asset-1:');
|
|
234
|
+
});
|
|
235
|
+
});
|
|
165
236
|
});
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface CreateMigrationInput extends CommonCommandOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Optional for pre-migrations, required for migrations.
|
|
5
|
-
*/
|
|
6
|
-
assetId?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Optional for pre-migrations, required for migrations.
|
|
9
|
-
*/
|
|
10
|
-
previewAssetId?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Required for both migrations and pre-migrations.
|
|
13
|
-
*/
|
|
14
|
-
matrixUrl: string;
|
|
15
|
-
/**
|
|
16
|
-
* Optional for migrations, required for pre-migrations.
|
|
17
|
-
*/
|
|
18
|
-
cctIds?: string[];
|
|
19
|
-
}
|
|
1
|
+
import { CreateMigrationInput, CreateMigrationApiResponse } from '../types';
|
|
20
2
|
/**
|
|
21
|
-
* Creates a new migration or pre-migration using the AI Page Migration service.
|
|
3
|
+
* Creates a new single asset migration, bulk migration, or pre-migration using the AI Page Migration service.
|
|
22
4
|
* Pre-migrations are used to generate specs for CCTs so they can be converted and deployed in advance.
|
|
5
|
+
* Bulk migrations are used to migrate multiple assets at once, and they all share the same migration ID.
|
|
23
6
|
* @param {CreateMigrationInput} input - The input parameters for the migration/pre-migration creation.
|
|
24
7
|
* @returns {Promise<CreateMigrationApiResponse>}
|
|
25
8
|
*/
|
|
26
|
-
export declare function createMigration({ tenant, overrideUrl,
|
|
9
|
+
export declare function createMigration({ tenant, overrideUrl, assetIds, previewAssetId, matrixUrl, cctIds, stageOptions, triggerNextStage, }: CreateMigrationInput): Promise<CreateMigrationApiResponse>;
|
|
27
10
|
export declare function validateExportFolder(exportPath: string): void;
|
|
28
11
|
/**
|
|
29
12
|
* Creates a tar file from the export path.
|
|
@@ -19,48 +19,39 @@ const ApiService_1 = require("../../ApiService");
|
|
|
19
19
|
const _1 = require(".");
|
|
20
20
|
const child_process_1 = require("child_process");
|
|
21
21
|
/**
|
|
22
|
-
* Creates a new migration or pre-migration using the AI Page Migration service.
|
|
22
|
+
* Creates a new single asset migration, bulk migration, or pre-migration using the AI Page Migration service.
|
|
23
23
|
* Pre-migrations are used to generate specs for CCTs so they can be converted and deployed in advance.
|
|
24
|
+
* Bulk migrations are used to migrate multiple assets at once, and they all share the same migration ID.
|
|
24
25
|
* @param {CreateMigrationInput} input - The input parameters for the migration/pre-migration creation.
|
|
25
26
|
* @returns {Promise<CreateMigrationApiResponse>}
|
|
26
27
|
*/
|
|
27
|
-
function createMigration({ tenant, overrideUrl,
|
|
28
|
+
function createMigration({ tenant, overrideUrl, assetIds, previewAssetId, matrixUrl, cctIds, stageOptions, triggerNextStage, }) {
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
const apiService = new ApiService_1.ApiService({
|
|
30
31
|
validateStatus: _1.validateAxiosStatus,
|
|
31
32
|
});
|
|
32
33
|
const migrationUrl = yield (0, _1.buildMigrationUrl)(tenant, overrideUrl);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.migrationId) ||
|
|
49
|
-
!(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.assetId) ||
|
|
50
|
-
!(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.stage) ||
|
|
51
|
-
!(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.status)) {
|
|
52
|
-
throw new Error('Invalid response format from migration service');
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
assetMigration,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (error instanceof Error) {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Failed to create migration: ${error}`);
|
|
34
|
+
const payload = {
|
|
35
|
+
assetIds,
|
|
36
|
+
previewAssetId,
|
|
37
|
+
matrixUrl,
|
|
38
|
+
cctIds,
|
|
39
|
+
stageOptions,
|
|
40
|
+
triggerNextStage,
|
|
41
|
+
};
|
|
42
|
+
const response = yield apiService.client.post(`${migrationUrl}`, payload, {
|
|
43
|
+
headers: yield (0, _1.getMigrationHeaders)(tenant),
|
|
44
|
+
});
|
|
45
|
+
// Validate response structure
|
|
46
|
+
const { assetMigration, summary, nextStageResults } = response.data || {};
|
|
47
|
+
if (!assetMigration && !summary && !nextStageResults) {
|
|
48
|
+
throw new Error('Invalid response format from migration service.');
|
|
63
49
|
}
|
|
50
|
+
return {
|
|
51
|
+
assetMigration,
|
|
52
|
+
summary,
|
|
53
|
+
nextStageResults,
|
|
54
|
+
};
|
|
64
55
|
});
|
|
65
56
|
}
|
|
66
57
|
exports.createMigration = createMigration;
|
|
@@ -134,7 +134,7 @@ describe('createMigration', () => {
|
|
|
134
134
|
};
|
|
135
135
|
mockApiService.mockImplementation(() => mockApiServiceInstance);
|
|
136
136
|
mockOptions = {
|
|
137
|
-
|
|
137
|
+
assetIds: ['asset-123'],
|
|
138
138
|
previewAssetId: 'preview-456',
|
|
139
139
|
matrixUrl: 'https://matrix.example.com',
|
|
140
140
|
tenant: 'test-tenant',
|
|
@@ -167,9 +167,12 @@ describe('createMigration', () => {
|
|
|
167
167
|
const result = yield (0, _1.createMigration)(mockOptions);
|
|
168
168
|
expect(result).toEqual(mockResponse.data);
|
|
169
169
|
expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://example.com/__dxp/service/aiapps/migration/migrations', {
|
|
170
|
-
|
|
170
|
+
assetIds: ['asset-123'],
|
|
171
171
|
previewAssetId: 'preview-456',
|
|
172
172
|
matrixUrl: 'https://matrix.example.com',
|
|
173
|
+
cctIds: undefined,
|
|
174
|
+
stageOptions: undefined,
|
|
175
|
+
triggerNextStage: undefined,
|
|
173
176
|
}, {
|
|
174
177
|
headers: {
|
|
175
178
|
'Content-Type': 'application/json',
|
|
@@ -177,36 +180,34 @@ describe('createMigration', () => {
|
|
|
177
180
|
},
|
|
178
181
|
});
|
|
179
182
|
}));
|
|
180
|
-
it('handles
|
|
181
|
-
|
|
183
|
+
it('handles API errors (4xx/5xx status codes)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
// In production, Axios throws AxiosError for 4xx/5xx status codes
|
|
185
|
+
const axiosError = new Error('Request failed with status code 400');
|
|
186
|
+
axiosError.isAxiosError = true;
|
|
187
|
+
axiosError.response = {
|
|
182
188
|
status: 400,
|
|
183
|
-
data: {},
|
|
189
|
+
data: { message: 'Bad Request' },
|
|
184
190
|
};
|
|
185
|
-
mockApiServiceInstance.client.post.
|
|
186
|
-
yield expect((0, _1.createMigration)(mockOptions)).rejects.toThrow('
|
|
191
|
+
mockApiServiceInstance.client.post.mockRejectedValue(axiosError);
|
|
192
|
+
yield expect((0, _1.createMigration)(mockOptions)).rejects.toThrow('Request failed with status code 400');
|
|
187
193
|
}));
|
|
188
|
-
it('handles invalid response format - missing
|
|
194
|
+
it('handles invalid response format - missing required fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
195
|
const mockResponse = {
|
|
190
196
|
status: 200,
|
|
191
|
-
data: {
|
|
192
|
-
assetMigration: {
|
|
193
|
-
assetId: 'asset-123',
|
|
194
|
-
stage: 'pending',
|
|
195
|
-
status: 'created',
|
|
196
|
-
},
|
|
197
|
-
},
|
|
197
|
+
data: {},
|
|
198
198
|
};
|
|
199
199
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
200
|
-
yield expect((0, _1.createMigration)(mockOptions)).rejects.toThrow('Invalid response format from migration service');
|
|
200
|
+
yield expect((0, _1.createMigration)(mockOptions)).rejects.toThrow('Invalid response format from migration service.');
|
|
201
201
|
}));
|
|
202
202
|
it('handles API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
203
|
const error = new Error('Network error');
|
|
204
204
|
mockApiServiceInstance.client.post.mockRejectedValue(error);
|
|
205
205
|
yield expect((0, _1.createMigration)(mockOptions)).rejects.toThrow('Network error');
|
|
206
206
|
}));
|
|
207
|
-
it('
|
|
207
|
+
it('propagates rejected values as-is', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
// Non-Error values are propagated without wrapping
|
|
208
209
|
mockApiServiceInstance.client.post.mockRejectedValue('Unknown error');
|
|
209
|
-
yield expect((0, _1.createMigration)(mockOptions)).rejects.
|
|
210
|
+
yield expect((0, _1.createMigration)(mockOptions)).rejects.toBe('Unknown error');
|
|
210
211
|
}));
|
|
211
212
|
});
|
|
212
213
|
describe('createTarFile', () => {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { GetMigrationOptions, GetMigrationApiResponse } from '../types';
|
|
1
|
+
import { GetMigrationOptions, GetMigrationApiResponse, BatchGetMigrationOptions, BatchGetMigrationApiResponse } from '../types';
|
|
2
2
|
export declare function getMigration(options: GetMigrationOptions): Promise<GetMigrationApiResponse>;
|
|
3
|
+
export declare function batchGetMigration(options: BatchGetMigrationOptions): Promise<BatchGetMigrationApiResponse>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getMigration = void 0;
|
|
12
|
+
exports.batchGetMigration = exports.getMigration = void 0;
|
|
13
13
|
const ApiService_1 = require("../../ApiService");
|
|
14
14
|
const _1 = require(".");
|
|
15
15
|
function getMigration(options) {
|
|
@@ -18,24 +18,29 @@ function getMigration(options) {
|
|
|
18
18
|
validateStatus: _1.validateAxiosStatus,
|
|
19
19
|
});
|
|
20
20
|
const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new Error(`Failed to get migration: ${response.status}`);
|
|
27
|
-
}
|
|
28
|
-
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
29
|
-
throw new Error('No data returned from migration service');
|
|
30
|
-
}
|
|
31
|
-
return response.data;
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
if (error instanceof Error) {
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Failed to get migration: ${error}`);
|
|
21
|
+
const response = yield apiService.client.get(`${migrationUrl}/${options.migrationId}/assets/${options.assetId}`, {
|
|
22
|
+
headers: yield (0, _1.getMigrationHeaders)(options.tenant),
|
|
23
|
+
});
|
|
24
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
25
|
+
throw new Error('No data returned from migration service');
|
|
38
26
|
}
|
|
27
|
+
return response.data;
|
|
39
28
|
});
|
|
40
29
|
}
|
|
41
30
|
exports.getMigration = getMigration;
|
|
31
|
+
function batchGetMigration(options) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const apiService = new ApiService_1.ApiService({
|
|
34
|
+
validateStatus: _1.validateAxiosStatus,
|
|
35
|
+
});
|
|
36
|
+
const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl);
|
|
37
|
+
const response = yield apiService.client.get(`${migrationUrl}/${options.migrationId}`, {
|
|
38
|
+
headers: yield (0, _1.getMigrationHeaders)(options.tenant),
|
|
39
|
+
});
|
|
40
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
41
|
+
throw new Error('No data returned from migration service');
|
|
42
|
+
}
|
|
43
|
+
return response.data;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.batchGetMigration = batchGetMigration;
|