@squiz/dxp-cli-next 5.26.0-develop.4 → 5.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/lib/migration/create/{createMigration.js → create.js} +5 -5
  2. package/lib/migration/create/{createMigration.spec.js → create.spec.js} +44 -41
  3. package/lib/migration/get/{getMigration.js → get.js} +4 -6
  4. package/lib/migration/get/{getMigration.spec.js → get.spec.js} +39 -30
  5. package/lib/migration/index.js +9 -7
  6. package/lib/migration/next/next.d.ts +3 -0
  7. package/lib/migration/next/next.js +46 -0
  8. package/lib/migration/next/next.spec.js +186 -0
  9. package/lib/migration/revert/revert.js +5 -6
  10. package/lib/migration/revert/revert.spec.js +10 -7
  11. package/lib/migration/settings/{setMigrationSettings.js → settings.js} +7 -8
  12. package/lib/migration/settings/{setMigrationSettings.spec.js → settings.spec.js} +34 -26
  13. package/lib/migration/types/common.types.d.ts +19 -0
  14. package/lib/migration/types/createMigration.types.d.ts +7 -0
  15. package/lib/migration/types/createMigration.types.js +2 -0
  16. package/lib/migration/types/getMigration.types.d.ts +5 -0
  17. package/lib/migration/types/getMigration.types.js +2 -0
  18. package/lib/migration/types/index.d.ts +6 -0
  19. package/lib/migration/types/index.js +22 -0
  20. package/lib/migration/types/nextStage.types.d.ts +6 -0
  21. package/lib/migration/types/nextStage.types.js +2 -0
  22. package/lib/migration/types/revert.types.d.ts +6 -0
  23. package/lib/migration/types/revert.types.js +2 -0
  24. package/lib/migration/types/settings.types.d.ts +10 -0
  25. package/lib/migration/types/settings.types.js +2 -0
  26. package/lib/migration/utils/common.d.ts +32 -0
  27. package/lib/migration/utils/common.js +129 -0
  28. package/lib/migration/utils/common.spec.d.ts +1 -0
  29. package/lib/migration/utils/common.spec.js +196 -0
  30. package/lib/migration/utils/createMigration.d.ts +9 -0
  31. package/lib/migration/utils/createMigration.js +122 -0
  32. package/lib/migration/utils/createMigration.spec.d.ts +1 -0
  33. package/lib/migration/utils/createMigration.spec.js +276 -0
  34. package/lib/migration/utils/getMigration.d.ts +2 -0
  35. package/lib/migration/utils/getMigration.js +41 -0
  36. package/lib/migration/utils/getMigration.spec.d.ts +1 -0
  37. package/lib/migration/utils/getMigration.spec.js +156 -0
  38. package/lib/migration/utils/index.d.ts +7 -0
  39. package/lib/migration/utils/index.js +23 -0
  40. package/lib/migration/utils/nextStage.d.ts +2 -0
  41. package/lib/migration/utils/nextStage.js +44 -0
  42. package/lib/migration/utils/nextStage.spec.d.ts +1 -0
  43. package/lib/migration/utils/nextStage.spec.js +151 -0
  44. package/lib/migration/utils/options.d.ts +12 -0
  45. package/lib/migration/utils/options.js +82 -0
  46. package/lib/migration/utils/options.spec.d.ts +1 -0
  47. package/lib/migration/utils/options.spec.js +115 -0
  48. package/lib/migration/utils/revertMigration.d.ts +2 -0
  49. package/lib/migration/utils/revertMigration.js +38 -0
  50. package/lib/migration/utils/revertMigration.spec.d.ts +1 -0
  51. package/lib/migration/utils/revertMigration.spec.js +95 -0
  52. package/lib/migration/utils/setMigrationSettings.d.ts +2 -0
  53. package/lib/migration/utils/setMigrationSettings.js +53 -0
  54. package/lib/migration/utils/setMigrationSettings.spec.d.ts +1 -0
  55. package/lib/migration/utils/setMigrationSettings.spec.js +156 -0
  56. package/package.json +1 -1
  57. package/lib/migration/types.d.ts +0 -54
  58. package/lib/migration/utils.d.ts +0 -15
  59. package/lib/migration/utils.js +0 -298
  60. package/lib/migration/utils.spec.js +0 -617
  61. /package/lib/migration/create/{createMigration.d.ts → create.d.ts} +0 -0
  62. /package/lib/migration/create/{createMigration.spec.d.ts → create.spec.d.ts} +0 -0
  63. /package/lib/migration/get/{getMigration.d.ts → get.d.ts} +0 -0
  64. /package/lib/migration/get/{getMigration.spec.d.ts → get.spec.d.ts} +0 -0
  65. /package/lib/migration/{settings/setMigrationSettings.spec.d.ts → next/next.spec.d.ts} +0 -0
  66. /package/lib/migration/settings/{setMigrationSettings.d.ts → settings.d.ts} +0 -0
  67. /package/lib/migration/{utils.spec.d.ts → settings/settings.spec.d.ts} +0 -0
  68. /package/lib/migration/{types.js → types/common.types.js} +0 -0
@@ -0,0 +1,151 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const ApiService_1 = require("../../ApiService");
36
+ const nextStage_1 = require("./nextStage");
37
+ const utils = __importStar(require("."));
38
+ jest.mock('../../ApiService');
39
+ jest.mock('.');
40
+ const mockApiService = ApiService_1.ApiService;
41
+ const mockUtils = utils;
42
+ describe('nextStage', () => {
43
+ let mockApiServiceInstance;
44
+ let mockOptions;
45
+ beforeEach(() => {
46
+ mockApiServiceInstance = {
47
+ client: {
48
+ post: jest.fn(),
49
+ },
50
+ };
51
+ mockApiService.mockImplementation(() => mockApiServiceInstance);
52
+ mockOptions = {
53
+ migrationId: 'migration-123',
54
+ assetId: 'asset-456',
55
+ tenant: 'test-tenant',
56
+ };
57
+ mockUtils.buildMigrationUrl.mockResolvedValue('https://example.com/__dxp/service/aiapps/migration/migrations');
58
+ mockUtils.getMigrationHeaders.mockResolvedValue({
59
+ 'Content-Type': 'application/json',
60
+ 'x-dxp-tenant': 'test-tenant',
61
+ });
62
+ mockUtils.validateAxiosStatus.mockImplementation(status => status >= 200 && status < 300);
63
+ });
64
+ afterEach(() => {
65
+ jest.clearAllMocks();
66
+ });
67
+ it('triggers next stage successfully', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const mockResponse = {
69
+ status: 202,
70
+ data: {
71
+ message: 'Next stage triggered successfully',
72
+ },
73
+ };
74
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
75
+ const result = yield (0, nextStage_1.nextStage)(mockOptions);
76
+ expect(result).toEqual({
77
+ message: 'Next stage triggered successfully',
78
+ });
79
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://example.com/__dxp/service/aiapps/migration/migrations/migration-123/assets/asset-456/next', {}, {
80
+ headers: {
81
+ 'Content-Type': 'application/json',
82
+ 'x-dxp-tenant': 'test-tenant',
83
+ },
84
+ });
85
+ }));
86
+ it('handles non-202 status codes', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ const mockResponse = {
88
+ status: 400,
89
+ data: {},
90
+ };
91
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
92
+ yield expect((0, nextStage_1.nextStage)(mockOptions)).rejects.toThrow('Next stage failed with status: 400');
93
+ }));
94
+ it('handles missing message in response', () => __awaiter(void 0, void 0, void 0, function* () {
95
+ const mockResponse = {
96
+ status: 202,
97
+ data: {},
98
+ };
99
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
100
+ yield expect((0, nextStage_1.nextStage)(mockOptions)).rejects.toThrow('Invalid response format from next stage');
101
+ }));
102
+ it('handles API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
103
+ const error = new Error('Network error');
104
+ mockApiServiceInstance.client.post.mockRejectedValue(error);
105
+ yield expect((0, nextStage_1.nextStage)(mockOptions)).rejects.toThrow('Network error');
106
+ }));
107
+ it('handles unknown errors', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ mockApiServiceInstance.client.post.mockRejectedValue('Unknown error');
109
+ yield expect((0, nextStage_1.nextStage)(mockOptions)).rejects.toThrow('Failed to start next stage: Unknown error');
110
+ }));
111
+ it('uses override URL when provided', () => __awaiter(void 0, void 0, void 0, function* () {
112
+ const optionsWithOverride = Object.assign(Object.assign({}, mockOptions), { overrideUrl: 'https://custom.migration.url' });
113
+ mockUtils.buildMigrationUrl.mockResolvedValue('https://custom.migration.url/migrations');
114
+ const mockResponse = {
115
+ status: 202,
116
+ data: {
117
+ message: 'Next stage triggered successfully',
118
+ },
119
+ };
120
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
121
+ yield (0, nextStage_1.nextStage)(optionsWithOverride);
122
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://custom.migration.url/migrations/migration-123/assets/asset-456/next', expect.any(Object), expect.any(Object));
123
+ }));
124
+ it('constructs correct URL path', () => __awaiter(void 0, void 0, void 0, function* () {
125
+ const mockResponse = {
126
+ status: 202,
127
+ data: {
128
+ message: 'Next stage triggered successfully',
129
+ },
130
+ };
131
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
132
+ yield (0, nextStage_1.nextStage)(mockOptions);
133
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://example.com/__dxp/service/aiapps/migration/migrations/migration-123/assets/asset-456/next', expect.any(Object), expect.any(Object));
134
+ }));
135
+ it('uses correct headers', () => __awaiter(void 0, void 0, void 0, function* () {
136
+ const mockResponse = {
137
+ status: 202,
138
+ data: {
139
+ message: 'Next stage triggered successfully',
140
+ },
141
+ };
142
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
143
+ yield (0, nextStage_1.nextStage)(mockOptions);
144
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith(expect.any(String), expect.any(Object), {
145
+ headers: {
146
+ 'Content-Type': 'application/json',
147
+ 'x-dxp-tenant': 'test-tenant',
148
+ },
149
+ });
150
+ }));
151
+ });
@@ -0,0 +1,12 @@
1
+ import { Command, Option } from 'commander';
2
+ export declare enum OptionName {
3
+ ASSET_ID = "asset-id",
4
+ PREVIEW_ASSET_ID = "preview-asset-id",
5
+ MATRIX_URL = "matrix-url",
6
+ TENANT = "tenant",
7
+ MIGRATION_ID = "migration-id",
8
+ MATRIX_IDENTIFIER = "matrix-identifier",
9
+ MATRIX_KEY = "matrix-key"
10
+ }
11
+ export declare const getParamOption: (param: OptionName, makeOptionMandatory?: boolean) => Option;
12
+ export declare const addOverrideUrlOption: (command: Command) => void;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addOverrideUrlOption = exports.getParamOption = exports.OptionName = void 0;
4
+ const commander_1 = require("commander");
5
+ var OptionName;
6
+ (function (OptionName) {
7
+ OptionName["ASSET_ID"] = "asset-id";
8
+ OptionName["PREVIEW_ASSET_ID"] = "preview-asset-id";
9
+ OptionName["MATRIX_URL"] = "matrix-url";
10
+ OptionName["TENANT"] = "tenant";
11
+ OptionName["MIGRATION_ID"] = "migration-id";
12
+ OptionName["MATRIX_IDENTIFIER"] = "matrix-identifier";
13
+ OptionName["MATRIX_KEY"] = "matrix-key";
14
+ })(OptionName = exports.OptionName || (exports.OptionName = {}));
15
+ const params = new Map([
16
+ [
17
+ OptionName.ASSET_ID,
18
+ {
19
+ flags: '--asset-id <string>',
20
+ description: 'The ID of the asset to be migrated',
21
+ },
22
+ ],
23
+ [
24
+ OptionName.PREVIEW_ASSET_ID,
25
+ {
26
+ flags: '--preview-asset-id <string>',
27
+ description: 'The ID of the folder that will be used as the parent of the migrated asset generated during the Preview stage',
28
+ },
29
+ ],
30
+ [
31
+ OptionName.MATRIX_URL,
32
+ {
33
+ flags: '--matrix-url <string>',
34
+ description: 'Matrix URL for the migration',
35
+ },
36
+ ],
37
+ [
38
+ OptionName.TENANT,
39
+ {
40
+ flags: '--tenant <string>',
41
+ description: 'Tenant ID to run against. If not provided will use configured tenant from login',
42
+ },
43
+ ],
44
+ [
45
+ OptionName.MIGRATION_ID,
46
+ {
47
+ flags: '--migration-id <string>',
48
+ description: 'The ID of the migration created',
49
+ },
50
+ ],
51
+ [
52
+ OptionName.MATRIX_IDENTIFIER,
53
+ {
54
+ flags: '--matrix-identifier <string>',
55
+ description: 'The component service identifier used by the asset and components being migrated',
56
+ },
57
+ ],
58
+ [
59
+ OptionName.MATRIX_KEY,
60
+ {
61
+ flags: '--matrix-key <string>',
62
+ description: 'The Asset Management API key for the Migrator API to interact with Matrix API',
63
+ },
64
+ ],
65
+ ]);
66
+ const getParamOption = (param, makeOptionMandatory = true) => {
67
+ const paramInfo = params.get(param);
68
+ if (!paramInfo) {
69
+ throw new Error(`Param ${param} not found`);
70
+ }
71
+ return new commander_1.Option(paramInfo.flags, paramInfo.description).makeOptionMandatory(makeOptionMandatory);
72
+ };
73
+ exports.getParamOption = getParamOption;
74
+ const addOverrideUrlOption = (command) => {
75
+ if (!process.env.ENABLE_OVERRIDE_MIGRATION_URL ||
76
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL !== 'true') {
77
+ return;
78
+ }
79
+ const overrideUrlOption = new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value');
80
+ command.addOption(overrideUrlOption);
81
+ };
82
+ exports.addOverrideUrlOption = addOverrideUrlOption;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,115 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const commander_1 = require("commander");
13
+ const options_1 = require("./options");
14
+ describe('options', () => {
15
+ describe('getParamOption', () => {
16
+ it('should create a mandatory option with correct flags and description', () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const option = (0, options_1.getParamOption)(options_1.OptionName.ASSET_ID);
18
+ const command = new commander_1.Command().exitOverride().addOption(option);
19
+ expect(option.flags).toBe('--asset-id <string>');
20
+ expect(option.description).toBe('The ID of the asset to be migrated');
21
+ // Test that the option is mandatory by trying to parse without it
22
+ yield expect(command.parseAsync(['node', 'dxp-cli'])).rejects.toThrow();
23
+ }));
24
+ it('should create an optional option when makeOptionMandatory is false', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const option = (0, options_1.getParamOption)(options_1.OptionName.TENANT, false);
26
+ const command = new commander_1.Command().exitOverride().addOption(option);
27
+ expect(option.flags).toBe('--tenant <string>');
28
+ expect(option.description).toBe('Tenant ID to run against. If not provided will use configured tenant from login');
29
+ // Test that the option is optional by parsing without it
30
+ yield expect(command.parseAsync(['node', 'dxp-cli'])).resolves.not.toThrow();
31
+ }));
32
+ it('should throw error for invalid option name', () => {
33
+ expect(() => {
34
+ (0, options_1.getParamOption)('invalid-option');
35
+ }).toThrow('Param invalid-option not found');
36
+ });
37
+ it('should create all valid options with correct properties', () => {
38
+ const options = [
39
+ {
40
+ name: options_1.OptionName.ASSET_ID,
41
+ flags: '--asset-id <string>',
42
+ description: 'The ID of the asset to be migrated',
43
+ },
44
+ {
45
+ name: options_1.OptionName.PREVIEW_ASSET_ID,
46
+ flags: '--preview-asset-id <string>',
47
+ description: 'The ID of the folder that will be used as the parent of the migrated asset generated during the Preview stage',
48
+ },
49
+ {
50
+ name: options_1.OptionName.MATRIX_URL,
51
+ flags: '--matrix-url <string>',
52
+ description: 'Matrix URL for the migration',
53
+ },
54
+ {
55
+ name: options_1.OptionName.TENANT,
56
+ flags: '--tenant <string>',
57
+ description: 'Tenant ID to run against. If not provided will use configured tenant from login',
58
+ },
59
+ {
60
+ name: options_1.OptionName.MIGRATION_ID,
61
+ flags: '--migration-id <string>',
62
+ description: 'The ID of the migration created',
63
+ },
64
+ ];
65
+ options.forEach(({ name, flags, description }) => {
66
+ const option = (0, options_1.getParamOption)(name);
67
+ expect(option.flags).toBe(flags);
68
+ expect(option.description).toBe(description);
69
+ });
70
+ });
71
+ });
72
+ describe('addOverrideUrlOption', () => {
73
+ let command;
74
+ const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
75
+ beforeEach(() => {
76
+ command = new commander_1.Command().exitOverride();
77
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'false';
78
+ });
79
+ afterEach(() => {
80
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
81
+ });
82
+ it('should not add override URL option when environment variable is not set to true', () => {
83
+ (0, options_1.addOverrideUrlOption)(command);
84
+ expect(command.opts()).toEqual({});
85
+ });
86
+ it('should add override URL option to existing command options', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
88
+ command.addOption((0, options_1.getParamOption)(options_1.OptionName.ASSET_ID));
89
+ (0, options_1.addOverrideUrlOption)(command);
90
+ yield command.parseAsync([
91
+ 'node',
92
+ 'dxp-cli',
93
+ '--asset-id',
94
+ '123',
95
+ '--overrideUrl',
96
+ 'https://custom.url',
97
+ ]);
98
+ expect(command.opts()).toEqual({
99
+ assetId: '123',
100
+ overrideUrl: 'https://custom.url',
101
+ });
102
+ }));
103
+ it('should parse override URL option correctly', () => __awaiter(void 0, void 0, void 0, function* () {
104
+ process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
105
+ (0, options_1.addOverrideUrlOption)(command);
106
+ yield command.parseAsync([
107
+ 'node',
108
+ 'dxp-cli',
109
+ '--overrideUrl',
110
+ 'https://custom.url',
111
+ ]);
112
+ expect(command.opts()).toEqual({ overrideUrl: 'https://custom.url' });
113
+ }));
114
+ });
115
+ });
@@ -0,0 +1,2 @@
1
+ import { RevertMigrationOptions, RevertMigrationApiResponse } from '../types';
2
+ export declare function revertMigration(options: RevertMigrationOptions): Promise<RevertMigrationApiResponse>;
@@ -0,0 +1,38 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.revertMigration = void 0;
13
+ const ApiService_1 = require("../../ApiService");
14
+ const _1 = require(".");
15
+ function revertMigration(options) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const apiService = new ApiService_1.ApiService({
18
+ validateStatus: _1.validateAxiosStatus,
19
+ });
20
+ const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl);
21
+ try {
22
+ const response = yield apiService.client.post(`${migrationUrl}/${options.migrationId}/assets/${options.assetId}/rollback`, {}, {
23
+ headers: yield (0, _1.getMigrationHeaders)(options.tenant),
24
+ });
25
+ if (response.status !== 200) {
26
+ throw new Error(`Failed to revert migration: ${response.status}`);
27
+ }
28
+ return response.data;
29
+ }
30
+ catch (error) {
31
+ if (error instanceof Error) {
32
+ throw error;
33
+ }
34
+ throw new Error(`Failed to revert migration: ${error}`);
35
+ }
36
+ });
37
+ }
38
+ exports.revertMigration = revertMigration;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,95 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const ApiService_1 = require("../../ApiService");
13
+ const revertMigration_1 = require("./revertMigration");
14
+ const _1 = require(".");
15
+ // Mock dependencies
16
+ jest.mock('../../ApiService');
17
+ jest.mock('.', () => ({
18
+ buildMigrationUrl: jest.fn(),
19
+ getMigrationHeaders: jest.fn(),
20
+ }));
21
+ const mockApiService = ApiService_1.ApiService;
22
+ const mockBuildMigrationUrl = _1.buildMigrationUrl;
23
+ const mockGetMigrationHeaders = _1.getMigrationHeaders;
24
+ describe('revertMigration', () => {
25
+ const mockOptions = {
26
+ migrationId: 'migration-123',
27
+ assetId: 'asset-456',
28
+ tenant: 'test-tenant',
29
+ };
30
+ const mockApiServiceInstance = {
31
+ client: {
32
+ post: jest.fn(),
33
+ },
34
+ };
35
+ beforeEach(() => {
36
+ jest.clearAllMocks();
37
+ mockApiService.mockImplementation(() => mockApiServiceInstance);
38
+ mockBuildMigrationUrl.mockResolvedValue('https://migration.example.com');
39
+ mockGetMigrationHeaders.mockResolvedValue({
40
+ 'Content-Type': 'application/json',
41
+ 'x-dxp-tenant': 'test-tenant',
42
+ });
43
+ });
44
+ it('should revert migration successfully', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ const mockResponse = {
46
+ status: 200,
47
+ data: { message: 'Migration reverted successfully' },
48
+ };
49
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
50
+ const result = yield (0, revertMigration_1.revertMigration)(mockOptions);
51
+ expect(result).toEqual({ message: 'Migration reverted successfully' });
52
+ expect(mockBuildMigrationUrl).toHaveBeenCalledWith(mockOptions.tenant, undefined);
53
+ expect(mockGetMigrationHeaders).toHaveBeenCalledWith(mockOptions.tenant);
54
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://migration.example.com/migration-123/assets/asset-456/rollback', {}, {
55
+ headers: {
56
+ 'Content-Type': 'application/json',
57
+ 'x-dxp-tenant': 'test-tenant',
58
+ },
59
+ });
60
+ }));
61
+ it('should handle non-success status codes', () => __awaiter(void 0, void 0, void 0, function* () {
62
+ const mockResponse = {
63
+ status: 400,
64
+ data: {},
65
+ };
66
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
67
+ yield expect((0, revertMigration_1.revertMigration)(mockOptions)).rejects.toThrow('Failed to revert migration: 400');
68
+ }));
69
+ it('should handle API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
70
+ const error = new Error('Network error');
71
+ mockApiServiceInstance.client.post.mockRejectedValue(error);
72
+ yield expect((0, revertMigration_1.revertMigration)(mockOptions)).rejects.toThrow('Network error');
73
+ }));
74
+ it('should handle unknown errors', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ mockApiServiceInstance.client.post.mockRejectedValue('Unknown error');
76
+ yield expect((0, revertMigration_1.revertMigration)(mockOptions)).rejects.toThrow('Failed to revert migration: Unknown error');
77
+ }));
78
+ it('should use override URL when provided', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ const mockResponse = {
80
+ status: 200,
81
+ data: { message: 'Migration reverted successfully' },
82
+ };
83
+ mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
84
+ mockBuildMigrationUrl.mockResolvedValue('https://custom.migration.url');
85
+ const optionsWithOverride = Object.assign(Object.assign({}, mockOptions), { overrideUrl: 'https://custom.migration.url' });
86
+ yield (0, revertMigration_1.revertMigration)(optionsWithOverride);
87
+ expect(mockBuildMigrationUrl).toHaveBeenCalledWith(mockOptions.tenant, 'https://custom.migration.url');
88
+ expect(mockApiServiceInstance.client.post).toHaveBeenCalledWith('https://custom.migration.url/migration-123/assets/asset-456/rollback', {}, {
89
+ headers: {
90
+ 'Content-Type': 'application/json',
91
+ 'x-dxp-tenant': 'test-tenant',
92
+ },
93
+ });
94
+ }));
95
+ });
@@ -0,0 +1,2 @@
1
+ import { SetMigrationSettingOptions, SetMigrationSettingApiResponse } from '../types';
2
+ export declare function setMigrationSettings(options: SetMigrationSettingOptions): Promise<SetMigrationSettingApiResponse>;
@@ -0,0 +1,53 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.setMigrationSettings = void 0;
13
+ const ApiService_1 = require("../../ApiService");
14
+ const _1 = require(".");
15
+ function setMigrationSettings(options) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const apiService = new ApiService_1.ApiService({
18
+ validateStatus: _1.validateAxiosStatus,
19
+ });
20
+ const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl, 'settings');
21
+ try {
22
+ const payload = {
23
+ matrixUrl: options.matrixUrl,
24
+ matrixIdentifier: options.matrixIdentifier,
25
+ matrixKey: options.matrixKey,
26
+ };
27
+ const response = yield apiService.client.post(migrationUrl, payload, {
28
+ headers: yield (0, _1.getMigrationHeaders)(options.tenant),
29
+ });
30
+ if (response.status !== 200 && response.status !== 201) {
31
+ throw new Error(`Migration settings update failed with status: ${response.status}`);
32
+ }
33
+ if (!(response === null || response === void 0 ? void 0 : response.data)) {
34
+ throw new Error('No data returned from migration service');
35
+ }
36
+ const responseData = {
37
+ matrixUrl: response.data.matrixUrl,
38
+ matrixIdentifier: response.data.matrixIdentifier,
39
+ matrixKey: response.data.matrixKey
40
+ ? (0, _1.redactKey)(response.data.matrixKey, 3)
41
+ : '',
42
+ };
43
+ return responseData;
44
+ }
45
+ catch (error) {
46
+ if (error instanceof Error) {
47
+ throw error;
48
+ }
49
+ throw new Error(`Failed to set migration settings: ${error}`);
50
+ }
51
+ });
52
+ }
53
+ exports.setMigrationSettings = setMigrationSettings;
@@ -0,0 +1 @@
1
+ export {};