@squiz/dxp-cli-next 5.15.0-develop.4 → 5.15.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.
@@ -138,7 +138,7 @@ exports.handleCommandError = handleCommandError;
138
138
  function throwErrorIfNotLoggedIn(command) {
139
139
  return __awaiter(this, void 0, void 0, function* () {
140
140
  if (!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
141
- command.error(chalk_1.default.red('You must login to interact with the job runner. See `dxp-next auth login`'));
141
+ command.error(chalk_1.default.red('You must login to interact with the datastore service. See `dxp-next auth login`'));
142
142
  }
143
143
  });
144
144
  }
@@ -1,8 +1,10 @@
1
1
  export declare const SQUIZ_ROOT_TENANT = "SquizRoot-0000";
2
2
  export declare const PORTER_REGION = "au";
3
+ export declare const PORTER_SERVICE_NAME = "porter";
3
4
  export declare const PORTER_ERRORS: {
4
5
  projectAlreadyExists: string;
5
6
  projectNameMissing: string;
6
7
  projectDirectoryInvalid: string;
7
8
  portIdBlankError: string;
9
+ loginError: string;
8
10
  };
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PORTER_ERRORS = exports.PORTER_REGION = exports.SQUIZ_ROOT_TENANT = void 0;
3
+ exports.PORTER_ERRORS = exports.PORTER_SERVICE_NAME = exports.PORTER_REGION = exports.SQUIZ_ROOT_TENANT = void 0;
4
4
  exports.SQUIZ_ROOT_TENANT = 'SquizRoot-0000';
5
5
  exports.PORTER_REGION = 'au';
6
+ exports.PORTER_SERVICE_NAME = 'porter';
6
7
  exports.PORTER_ERRORS = {
7
8
  projectAlreadyExists: 'Project directory already exists. Please choose a project directory that does not exist',
8
9
  projectNameMissing: 'Project name is missing from the config.json file',
9
10
  projectDirectoryInvalid: 'You must be within a porter project directory to use this command',
10
11
  portIdBlankError: 'Cannot be blank.',
12
+ loginError: 'To use this service you must be logged in as a DXP super admin, Squiz support staff or be assigned the Migration Agent secondary role for the selected tenant',
11
13
  };
@@ -0,0 +1,4 @@
1
+ export declare function buildDXPUrl(serviceName: string, tenantID?: string, override?: string, region?: string): Promise<{
2
+ dxpUrl: string;
3
+ tenant: string | undefined;
4
+ }>;
@@ -0,0 +1,34 @@
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.buildDXPUrl = void 0;
13
+ const ApplicationConfig_1 = require("../../../ApplicationConfig");
14
+ const CoreUtils_1 = require("../CoreUtils/CoreUtils");
15
+ function buildDXPUrl(serviceName, tenantID, override, region) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!override) {
18
+ const existingConfig = yield (0, ApplicationConfig_1.fetchApplicationConfig)(tenantID);
19
+ (0, CoreUtils_1.logDebug)(`existingConfig: ${JSON.stringify(existingConfig)}`);
20
+ return {
21
+ dxpUrl: `${existingConfig.baseUrl}/__dxp/${region || existingConfig.region}/${serviceName}`,
22
+ tenant: existingConfig.tenant,
23
+ };
24
+ }
25
+ else {
26
+ (0, CoreUtils_1.logDebug)(`Using override URL: ${override}`);
27
+ return {
28
+ dxpUrl: `${override}/__dxp/${region || 'au'}/${serviceName}`,
29
+ tenant: tenantID,
30
+ };
31
+ }
32
+ });
33
+ }
34
+ exports.buildDXPUrl = buildDXPUrl;
@@ -1 +1 @@
1
- export declare function buildPorterUrl(override?: string): Promise<string>;
1
+ export declare function buildPorterUrl(): Promise<string>;
@@ -10,18 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.buildPorterUrl = void 0;
13
- const ApplicationConfig_1 = require("../../../ApplicationConfig");
14
13
  const constants_1 = require("../../constants");
15
- const CoreUtils_1 = require("../CoreUtils/CoreUtils");
16
- function buildPorterUrl(override) {
14
+ const BuildDXPUrl_1 = require("../BuildDXPUrl/BuildDXPUrl");
15
+ function buildPorterUrl() {
17
16
  return __awaiter(this, void 0, void 0, function* () {
18
- if (!override) {
19
- const existingConfig = yield (0, ApplicationConfig_1.fetchApplicationConfig)();
20
- (0, CoreUtils_1.logDebug)(`existingConfig: ${JSON.stringify(existingConfig)}`);
21
- return `${existingConfig.baseUrl}/__dxp/${constants_1.PORTER_REGION}/porter/${constants_1.SQUIZ_ROOT_TENANT}`;
22
- }
23
- (0, CoreUtils_1.logDebug)(`Using override URL: ${override}`);
24
- return `${override}/__dxp/${constants_1.PORTER_REGION}/porter/${constants_1.SQUIZ_ROOT_TENANT}`;
17
+ const { dxpUrl, tenant } = yield (0, BuildDXPUrl_1.buildDXPUrl)(constants_1.PORTER_SERVICE_NAME, undefined, undefined, 'au');
18
+ return `${dxpUrl}/${tenant}`;
25
19
  });
26
20
  }
27
21
  exports.buildPorterUrl = buildPorterUrl;
@@ -33,7 +33,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const FetchApplicationConfig = __importStar(require("../../../ApplicationConfig"));
36
- const constants_1 = require("../../constants");
37
36
  const BuildPorterUrl_1 = require("./BuildPorterUrl");
38
37
  describe('buildPorterUrl', () => {
39
38
  let fetchApplicationConfigSpy;
@@ -48,12 +47,6 @@ describe('buildPorterUrl', () => {
48
47
  tenant: 'tenant',
49
48
  }));
50
49
  const porterUrl = yield (0, BuildPorterUrl_1.buildPorterUrl)();
51
- expect(porterUrl).toBe(`base/__dxp/${constants_1.PORTER_REGION}/porter/${constants_1.SQUIZ_ROOT_TENANT}`);
52
- }));
53
- it('should construct the URL using the provided override base URL', () => __awaiter(void 0, void 0, void 0, function* () {
54
- const overrideBaseUrl = 'override';
55
- const porterUrl = yield (0, BuildPorterUrl_1.buildPorterUrl)(overrideBaseUrl);
56
- expect(porterUrl).toBe(`${overrideBaseUrl}/__dxp/${constants_1.PORTER_REGION}/porter/${constants_1.SQUIZ_ROOT_TENANT}`);
57
- expect(fetchApplicationConfigSpy).not.toHaveBeenCalled();
50
+ expect(porterUrl).toEqual('base/__dxp/au/porter/tenant');
58
51
  }));
59
52
  });
@@ -17,6 +17,7 @@ const axios_1 = __importDefault(require("axios"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const ApplicationStore_1 = require("../../../ApplicationStore");
19
19
  const CheckAuthorisation_1 = require("../AuthUtils/CheckAuthorisation");
20
+ const constants_1 = require("../../constants");
20
21
  function handleCommandError(command, error) {
21
22
  if (!axios_1.default.isAxiosError(error)) {
22
23
  if (!!process.env.DEBUG && error.stack) {
@@ -31,8 +32,7 @@ function handleCommandError(command, error) {
31
32
  return command.error(chalk_1.default.red(error.message));
32
33
  }
33
34
  if (error.response.status === 401 || error.response.status === 403) {
34
- const errorMessage = 'You must be logged in as a DXP super admin or Squiz support staff to use this service';
35
- return command.error(chalk_1.default.red(errorMessage));
35
+ return command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginError));
36
36
  }
37
37
  if (error.response.status >= 500) {
38
38
  const errorMessage = `Action failed. Service responded with "${error.response.status}" response code`;
@@ -64,7 +64,7 @@ function throwErrorIfNotLoggedIn(command) {
64
64
  }
65
65
  const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
66
66
  if (!isAuthorised) {
67
- command.error(chalk_1.default.red('You must login to interact with the porter service. See `dxp-next auth login`'));
67
+ command.error(chalk_1.default.red(constants_1.PORTER_ERRORS.loginError));
68
68
  }
69
69
  });
70
70
  }
@@ -37,6 +37,7 @@ const commander_1 = require("commander");
37
37
  const GetApplicationFile = __importStar(require("../../../ApplicationStore"));
38
38
  const CheckAuthorisation = __importStar(require("../AuthUtils/CheckAuthorisation"));
39
39
  const ErrorUtils_1 = require("./ErrorUtils");
40
+ const constants_1 = require("../../constants");
40
41
  describe('handleCommandError', () => {
41
42
  let stderrSpy;
42
43
  beforeEach(() => {
@@ -95,7 +96,7 @@ describe('handleCommandError', () => {
95
96
  }));
96
97
  expect(stderrSpy).toHaveBeenCalledTimes(1);
97
98
  // read the mock call strings directly otherwise colours cause test failures with .toEqual()
98
- expect(stderrSpy.mock.calls[0][0]).toContain('You must be logged in as a DXP super admin or Squiz support staff to use this service');
99
+ expect(stderrSpy.mock.calls[0][0]).toContain(constants_1.PORTER_ERRORS.loginError);
99
100
  }));
100
101
  it('correctly displays the console logs for invalid-params errors from the porter service', () => __awaiter(void 0, void 0, void 0, function* () {
101
102
  const command = new commander_1.Command();
@@ -173,7 +174,7 @@ describe('throwErrorIfNotLoggedIn', () => {
173
174
  .spyOn(CheckAuthorisation, 'checkAuthorisation')
174
175
  .mockImplementationOnce(() => Promise.resolve(false));
175
176
  yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
176
- expect(stderrSpy.mock.calls[0][0]).toContain('You must login to interact with the porter service. See `dxp-next auth login');
177
+ expect(stderrSpy.mock.calls[0][0]).toContain(constants_1.PORTER_ERRORS.loginError);
177
178
  expect(process.exit).toHaveBeenCalled();
178
179
  }));
179
180
  it('should not call the command error if logged in', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,5 +1,6 @@
1
1
  export * from './AuthUtils/CheckAuthorisation';
2
2
  export * from './BuildPorterUrl/BuildPorterUrl';
3
+ export * from './BuildDXPUrl/BuildDXPUrl';
3
4
  export * from './CoreUtils/CoreUtils';
4
5
  export * from './DoesPathExist/DoesPathExist';
5
6
  export * from './ErrorUtils/ErrorUtils';
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AuthUtils/CheckAuthorisation"), exports);
18
18
  __exportStar(require("./BuildPorterUrl/BuildPorterUrl"), exports);
19
+ __exportStar(require("./BuildDXPUrl/BuildDXPUrl"), exports);
19
20
  __exportStar(require("./CoreUtils/CoreUtils"), exports);
20
21
  __exportStar(require("./DoesPathExist/DoesPathExist"), exports);
21
22
  __exportStar(require("./ErrorUtils/ErrorUtils"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.15.0-develop.4",
3
+ "version": "5.15.0",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },