@squiz/dxp-cli-next 5.26.0-develop.2 → 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.
- package/lib/migration/get/getMigration.js +1 -0
- package/lib/migration/index.js +3 -1
- package/lib/migration/settings/setMigrationSettings.d.ts +3 -0
- package/lib/migration/settings/setMigrationSettings.js +49 -0
- package/lib/migration/settings/setMigrationSettings.spec.d.ts +1 -0
- package/lib/migration/settings/setMigrationSettings.spec.js +275 -0
- package/lib/migration/types.d.ts +12 -0
- package/lib/migration/utils.d.ts +3 -1
- package/lib/migration/utils.js +50 -1
- package/lib/migration/utils.spec.js +7 -0
- package/package.json +1 -1
package/lib/migration/index.js
CHANGED
|
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const createMigration_1 = __importDefault(require("./create/createMigration"));
|
|
8
8
|
const getMigration_1 = __importDefault(require("./get/getMigration"));
|
|
9
|
+
const setMigrationSettings_1 = __importDefault(require("./settings/setMigrationSettings"));
|
|
9
10
|
const migrationCommand = new commander_1.Command('migration');
|
|
10
11
|
migrationCommand
|
|
11
12
|
.description('AI Page Migration Service Commands')
|
|
12
13
|
.addCommand((0, createMigration_1.default)())
|
|
13
|
-
.addCommand((0, getMigration_1.default)())
|
|
14
|
+
.addCommand((0, getMigration_1.default)())
|
|
15
|
+
.addCommand((0, setMigrationSettings_1.default)());
|
|
14
16
|
exports.default = migrationCommand;
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|
package/lib/migration/types.d.ts
CHANGED
|
@@ -35,3 +35,15 @@ export interface GetMigrationAPIResponse {
|
|
|
35
35
|
previewPageAssetId?: string;
|
|
36
36
|
componentsTarDownloadUrl?: string;
|
|
37
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
|
+
}
|
package/lib/migration/utils.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { CreateMigrationOptions, CreateMigrationAPIResponse, GetMigrationOptions, GetMigrationAPIResponse } from './types';
|
|
2
|
+
import { CreateMigrationOptions, CreateMigrationAPIResponse, GetMigrationOptions, GetMigrationAPIResponse, SetMigrationSettingOptions, SetMigrationSettingAPIResponse } from './types';
|
|
3
3
|
export declare function handleCommandError(command: Command, error: Error): void;
|
|
4
4
|
export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
|
|
5
5
|
export declare function buildMigrationUrl(tenantID?: string, overrideUrl?: string): Promise<string>;
|
|
6
6
|
export declare function validateAxiosStatus(status: number): boolean;
|
|
7
|
+
export declare function redactKey(key: string, visibleChars?: number): string;
|
|
7
8
|
export declare function validateExportFolder(exportPath: string): void;
|
|
8
9
|
export declare function createTarFile(exportPath: string): Promise<string>;
|
|
9
10
|
export declare function getMigrationHeaders(tenantID?: string): Promise<Record<string, string>>;
|
|
10
11
|
export declare function uploadFileToS3(uploadUrl: string, filePath: string, tenantID?: string): Promise<string>;
|
|
11
12
|
export declare function createMigration(options: CreateMigrationOptions): Promise<CreateMigrationAPIResponse>;
|
|
12
13
|
export declare function getMigration(options: GetMigrationOptions): Promise<GetMigrationAPIResponse>;
|
|
14
|
+
export declare function setMigrationSetting(options: SetMigrationSettingOptions): Promise<SetMigrationSettingAPIResponse>;
|
package/lib/migration/utils.js
CHANGED
|
@@ -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.getMigration = 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)) {
|
|
@@ -223,3 +233,42 @@ function getMigration(options) {
|
|
|
223
233
|
});
|
|
224
234
|
}
|
|
225
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('/'));
|