@squiz/dxp-cli-next 5.25.3 → 5.26.0-develop.2

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,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
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const migrationCommand: Command;
3
+ export default migrationCommand;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const createMigration_1 = __importDefault(require("./create/createMigration"));
8
+ const getMigration_1 = __importDefault(require("./get/getMigration"));
9
+ const migrationCommand = new commander_1.Command('migration');
10
+ migrationCommand
11
+ .description('AI Page Migration Service Commands')
12
+ .addCommand((0, createMigration_1.default)())
13
+ .addCommand((0, getMigration_1.default)());
14
+ exports.default = migrationCommand;
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { Command } from 'commander';
2
+ import { CreateMigrationOptions, CreateMigrationAPIResponse, GetMigrationOptions, GetMigrationAPIResponse } from './types';
3
+ export declare function handleCommandError(command: Command, error: Error): void;
4
+ export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
5
+ export declare function buildMigrationUrl(tenantID?: string, overrideUrl?: string): Promise<string>;
6
+ export declare function validateAxiosStatus(status: number): boolean;
7
+ export declare function validateExportFolder(exportPath: string): void;
8
+ export declare function createTarFile(exportPath: string): Promise<string>;
9
+ export declare function getMigrationHeaders(tenantID?: string): Promise<Record<string, string>>;
10
+ export declare function uploadFileToS3(uploadUrl: string, filePath: string, tenantID?: string): Promise<string>;
11
+ export declare function createMigration(options: CreateMigrationOptions): Promise<CreateMigrationAPIResponse>;
12
+ export declare function getMigration(options: GetMigrationOptions): Promise<GetMigrationAPIResponse>;
@@ -0,0 +1,225 @@
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
+ exports.getMigration = exports.createMigration = exports.uploadFileToS3 = exports.getMigrationHeaders = exports.createTarFile = exports.validateExportFolder = exports.validateAxiosStatus = exports.buildMigrationUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const chalk_1 = __importDefault(require("chalk"));
19
+ const ApplicationConfig_1 = require("../ApplicationConfig");
20
+ const axios_1 = __importDefault(require("axios"));
21
+ const ApplicationStore_1 = require("../ApplicationStore");
22
+ const child_process_1 = require("child_process");
23
+ const ApiService_1 = require("../ApiService");
24
+ function handleCommandError(command, error) {
25
+ var _a, _b, _c, _d;
26
+ if (axios_1.default.isAxiosError(error)) {
27
+ let message = `${error.message}`;
28
+ if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
29
+ message += `: ${error.response.data.message}`;
30
+ }
31
+ if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.details) {
32
+ message += ` - ${error.response.data.details}`;
33
+ }
34
+ command.error(chalk_1.default.red(message));
35
+ }
36
+ else {
37
+ if (!!process.env.DEBUG && error.stack) {
38
+ command.error(error.stack);
39
+ }
40
+ if (error.message) {
41
+ command.error(chalk_1.default.red(error.message));
42
+ }
43
+ else {
44
+ command.error(chalk_1.default.red('An unknown error occurred'));
45
+ }
46
+ }
47
+ }
48
+ exports.handleCommandError = handleCommandError;
49
+ function throwErrorIfNotLoggedIn(command) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
52
+ command.error(chalk_1.default.red('You must login to interact with the migration service. See `dxp-next auth login`'));
53
+ }
54
+ });
55
+ }
56
+ exports.throwErrorIfNotLoggedIn = throwErrorIfNotLoggedIn;
57
+ function buildMigrationUrl(tenantID, overrideUrl) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!overrideUrl) {
60
+ const existingConfig = yield (0, ApplicationConfig_1.fetchApplicationConfig)(tenantID);
61
+ return `${existingConfig.baseUrl}/__dxp/service/aiapps/migration`;
62
+ }
63
+ else {
64
+ return overrideUrl;
65
+ }
66
+ });
67
+ }
68
+ exports.buildMigrationUrl = buildMigrationUrl;
69
+ function validateAxiosStatus(status) {
70
+ return status < 400;
71
+ }
72
+ exports.validateAxiosStatus = validateAxiosStatus;
73
+ function validateExportFolder(exportPath) {
74
+ // Check if the export folder exists
75
+ if (!fs_1.default.existsSync(exportPath)) {
76
+ throw new Error(`Export folder does not exist: ${exportPath}`);
77
+ }
78
+ // Check if it's a directory
79
+ if (!fs_1.default.statSync(exportPath).isDirectory()) {
80
+ throw new Error(`Export path is not a directory: ${exportPath}`);
81
+ }
82
+ // Check for nested export folder structure (e.g., ./export/export/...)
83
+ const nestedExportPath = path_1.default.join(exportPath, 'export');
84
+ if (!fs_1.default.existsSync(nestedExportPath)) {
85
+ throw new Error(`Nested export folder does not exist: ${nestedExportPath}`);
86
+ }
87
+ if (!fs_1.default.statSync(nestedExportPath).isDirectory()) {
88
+ throw new Error(`Nested export path is not a directory: ${nestedExportPath}`);
89
+ }
90
+ // Check for export.xml file in the nested export directory
91
+ const exportXmlPath = path_1.default.join(nestedExportPath, 'export.xml');
92
+ if (!fs_1.default.existsSync(exportXmlPath)) {
93
+ throw new Error(`export.xml file does not exist in: ${nestedExportPath}`);
94
+ }
95
+ if (!fs_1.default.statSync(exportXmlPath).isFile()) {
96
+ throw new Error(`export.xml is not a valid file: ${exportXmlPath}`);
97
+ }
98
+ }
99
+ exports.validateExportFolder = validateExportFolder;
100
+ function createTarFile(exportPath) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const tarFileName = `export_${Date.now()}.tar.gz`;
103
+ const tarFilePath = path_1.default.join(process.cwd(), tarFileName);
104
+ return new Promise((resolve, reject) => {
105
+ const tar = (0, child_process_1.spawn)('tar', [
106
+ '-czf',
107
+ tarFilePath,
108
+ '-C',
109
+ path_1.default.dirname(exportPath),
110
+ path_1.default.basename(exportPath),
111
+ ]);
112
+ tar.on('close', code => {
113
+ if (code === 0) {
114
+ resolve(tarFilePath);
115
+ }
116
+ else {
117
+ reject(new Error(`tar command failed with exit code ${code}`));
118
+ }
119
+ });
120
+ tar.on('error', error => {
121
+ reject(new Error(`Failed to create tar file: ${error.message}`));
122
+ });
123
+ });
124
+ });
125
+ }
126
+ exports.createTarFile = createTarFile;
127
+ function getMigrationHeaders(tenantID) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const existingConfig = yield (0, ApplicationConfig_1.fetchApplicationConfig)(tenantID);
130
+ return {
131
+ 'x-dxp-tenant': existingConfig.tenant,
132
+ };
133
+ });
134
+ }
135
+ exports.getMigrationHeaders = getMigrationHeaders;
136
+ function uploadFileToS3(uploadUrl, filePath, tenantID) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const fileBuffer = fs_1.default.readFileSync(filePath);
139
+ const response = yield fetch(uploadUrl, {
140
+ method: 'PUT',
141
+ body: fileBuffer,
142
+ headers: Object.assign({}, (yield getMigrationHeaders(tenantID))),
143
+ });
144
+ return response.url;
145
+ });
146
+ }
147
+ exports.uploadFileToS3 = uploadFileToS3;
148
+ function createMigration(options) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const apiService = new ApiService_1.ApiService({
151
+ validateStatus: validateAxiosStatus,
152
+ });
153
+ const migrationUrl = yield buildMigrationUrl(options.tenant, options.overrideUrl);
154
+ try {
155
+ const payload = {
156
+ assetId: options.assetId,
157
+ previewAssetId: options.previewAssetId,
158
+ matrixUrl: options.matrixUrl,
159
+ };
160
+ const response = yield apiService.client.post(`${migrationUrl}/migrations`, payload, {
161
+ headers: Object.assign({ 'Content-Type': 'application/json' }, (yield getMigrationHeaders(options.tenant))),
162
+ });
163
+ if (response.status !== 200 && response.status !== 201) {
164
+ throw new Error(`Migration creation failed with status: ${response.status}`);
165
+ }
166
+ // Validate response structure
167
+ const { assetMigration, uploadUrl } = response.data || {};
168
+ if (!(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.migrationId) ||
169
+ !(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.assetId) ||
170
+ !(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.stage) ||
171
+ !(assetMigration === null || assetMigration === void 0 ? void 0 : assetMigration.status)) {
172
+ throw new Error('Invalid response format from migration service');
173
+ }
174
+ if (!uploadUrl) {
175
+ throw new Error('Upload URL not found in response');
176
+ }
177
+ return {
178
+ assetMigration,
179
+ uploadUrl,
180
+ };
181
+ }
182
+ catch (error) {
183
+ if (error instanceof Error) {
184
+ throw error;
185
+ }
186
+ throw new Error(`Failed to create migration: ${error}`);
187
+ }
188
+ });
189
+ }
190
+ exports.createMigration = createMigration;
191
+ function getMigration(options) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ const apiService = new ApiService_1.ApiService({
194
+ validateStatus: validateAxiosStatus,
195
+ });
196
+ const migrationUrl = yield buildMigrationUrl(options.tenant, options.overrideUrl);
197
+ try {
198
+ const response = yield apiService.client.get(`${migrationUrl}/migrations/${options.migrationId}/assets/${options.assetId}`, {
199
+ headers: Object.assign({ 'Content-Type': 'application/json' }, (yield getMigrationHeaders(options.tenant))),
200
+ });
201
+ if (response.status !== 200) {
202
+ throw new Error(`Failed to get migration: ${response.status}`);
203
+ }
204
+ if (!(response === null || response === void 0 ? void 0 : response.data)) {
205
+ throw new Error('No data returned from migration service');
206
+ }
207
+ return {
208
+ migrationId: response.data.migrationId,
209
+ assetId: response.data.assetId,
210
+ stage: response.data.stage,
211
+ status: response.data.status,
212
+ stageDetails: response.data.stageDetails,
213
+ previewPageAssetId: response.data.previewPageAssetId,
214
+ componentsTarDownloadUrl: response.data.componentsTarDownloadUrl,
215
+ };
216
+ }
217
+ catch (error) {
218
+ if (error instanceof Error) {
219
+ throw error;
220
+ }
221
+ throw new Error(`Failed to get migration: ${error}`);
222
+ }
223
+ });
224
+ }
225
+ exports.getMigration = getMigration;
@@ -0,0 +1 @@
1
+ export {};