@squiz/dxp-cli-next 5.14.0-develop.2 → 5.15.0-develop.1
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/__tests__/integration/main.spec.js +3 -2
- package/lib/cdp/index.js +3 -1
- package/lib/cmp/deploy.js +49 -2
- package/lib/cmp/edge-components/compiler.d.ts +13 -0
- package/lib/cmp/edge-components/compiler.js +55 -0
- package/lib/cmp/utils/definitions.d.ts +12 -0
- package/lib/cmp/utils/definitions.js +76 -0
- package/lib/datastore/index.js +1 -1
- package/lib/dxp.js +2 -0
- package/lib/porter/constants.d.ts +6 -0
- package/lib/porter/constants.js +9 -0
- package/lib/porter/index.d.ts +3 -0
- package/lib/porter/index.js +12 -0
- package/lib/porter/project/add/add.d.ts +3 -0
- package/lib/porter/project/add/add.js +125 -0
- package/lib/porter/project/add/add.spec.d.ts +1 -0
- package/lib/porter/project/add/add.spec.js +323 -0
- package/lib/porter/project/get/get.d.ts +3 -0
- package/lib/porter/project/get/get.js +67 -0
- package/lib/porter/project/get/get.spec.d.ts +1 -0
- package/lib/porter/project/get/get.spec.js +221 -0
- package/lib/porter/project/projectCommand.d.ts +3 -0
- package/lib/porter/project/projectCommand.js +19 -0
- package/lib/porter/project/remove/remove.d.ts +3 -0
- package/lib/porter/project/remove/remove.js +71 -0
- package/lib/porter/project/remove/remove.spec.d.ts +1 -0
- package/lib/porter/project/remove/remove.spec.js +236 -0
- package/lib/porter/types.d.ts +5 -0
- package/lib/porter/types.js +2 -0
- package/lib/porter/utils/AuthUtils/CheckAuthorisation.d.ts +1 -0
- package/lib/porter/utils/AuthUtils/CheckAuthorisation.js +32 -0
- package/lib/porter/utils/AuthUtils/CheckAuthorisation.spec.d.ts +1 -0
- package/lib/porter/utils/AuthUtils/CheckAuthorisation.spec.js +77 -0
- package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.d.ts +1 -0
- package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.js +27 -0
- package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.spec.d.ts +1 -0
- package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.spec.js +59 -0
- package/lib/porter/utils/CoreUtils/CoreUtils.d.ts +2 -0
- package/lib/porter/utils/CoreUtils/CoreUtils.js +13 -0
- package/lib/porter/utils/CoreUtils/CoreUtils.spec.d.ts +1 -0
- package/lib/porter/utils/CoreUtils/CoreUtils.spec.js +36 -0
- package/lib/porter/utils/DoesPathExist/DoesPathExist.d.ts +1 -0
- package/lib/porter/utils/DoesPathExist/DoesPathExist.js +27 -0
- package/lib/porter/utils/DoesPathExist/DoesPathExist.spec.d.ts +1 -0
- package/lib/porter/utils/DoesPathExist/DoesPathExist.spec.js +40 -0
- package/lib/porter/utils/ErrorUtils/ErrorUtils.d.ts +4 -0
- package/lib/porter/utils/ErrorUtils/ErrorUtils.js +68 -0
- package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.d.ts +1 -0
- package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.js +175 -0
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.d.ts +2 -0
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.js +32 -0
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.d.ts +1 -0
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.js +49 -0
- package/lib/porter/utils/index.d.ts +6 -0
- package/lib/porter/utils/index.js +22 -0
- package/package.json +6 -3
|
@@ -0,0 +1,71 @@
|
|
|
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 commander_1 = require("commander");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const inquirer_1 = require("inquirer");
|
|
18
|
+
const ora_1 = __importDefault(require("ora"));
|
|
19
|
+
const ApiService_1 = require("../../../ApiService");
|
|
20
|
+
const utils_1 = require("../../utils");
|
|
21
|
+
const constants_1 = require("../../constants");
|
|
22
|
+
const createRemoveProjectCommand = () => {
|
|
23
|
+
const removeCommand = new commander_1.Command('removeProject')
|
|
24
|
+
.description('Deletes the project')
|
|
25
|
+
.configureOutput({
|
|
26
|
+
outputError(str, write) {
|
|
27
|
+
write(chalk_1.default.red(str));
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(removeCommand);
|
|
33
|
+
const baseUrl = yield (0, utils_1.buildPorterUrl)();
|
|
34
|
+
let projectName = '';
|
|
35
|
+
const spinner = (0, ora_1.default)();
|
|
36
|
+
try {
|
|
37
|
+
const projectConfig = yield (0, utils_1.getProjectConfig)();
|
|
38
|
+
projectName = projectConfig.projectName;
|
|
39
|
+
if (!projectName) {
|
|
40
|
+
throw new Error(constants_1.PORTER_ERRORS.projectNameMissing);
|
|
41
|
+
}
|
|
42
|
+
const confirmation = yield (0, inquirer_1.prompt)({
|
|
43
|
+
message: `Are you sure you wish to remove all data about the project "${projectName}" from the cloud permanently? [y/N]`,
|
|
44
|
+
name: 'answer',
|
|
45
|
+
});
|
|
46
|
+
if (confirmation.answer !== 'y') {
|
|
47
|
+
spinner.fail('Aborted');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
spinner.start('Deleting project..');
|
|
51
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
|
|
52
|
+
const response = yield apiService.client.delete(`/projects/${projectName}`);
|
|
53
|
+
(0, utils_1.logDebug)(response.data);
|
|
54
|
+
spinner.succeed('Project has been deleted from the cloud');
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
(0, utils_1.logDebug)(`ERROR: ${error instanceof Error ? `${error.message}` : JSON.stringify(error)}`);
|
|
58
|
+
if (spinner.isSpinning) {
|
|
59
|
+
spinner.fail();
|
|
60
|
+
}
|
|
61
|
+
if (((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.status) === 404) {
|
|
62
|
+
(0, utils_1.logDebug)(error.response.data);
|
|
63
|
+
const errorMessage = `Project "${projectName}" not found in DXP porter service`;
|
|
64
|
+
return (0, utils_1.handleError)(removeCommand, errorMessage);
|
|
65
|
+
}
|
|
66
|
+
(0, utils_1.handleCommandError)(removeCommand, error);
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
return removeCommand;
|
|
70
|
+
};
|
|
71
|
+
exports.default = createRemoveProjectCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
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 remove_1 = __importDefault(require("./remove"));
|
|
40
|
+
const axios_1 = require("axios");
|
|
41
|
+
const ApiService = __importStar(require("../../../ApiService"));
|
|
42
|
+
const Inquirer = __importStar(require("inquirer"));
|
|
43
|
+
const BuildPorterUrl = __importStar(require("../../utils/BuildPorterUrl/BuildPorterUrl"));
|
|
44
|
+
const ErrorUtils = __importStar(require("../../utils/ErrorUtils/ErrorUtils"));
|
|
45
|
+
const GetProjectConfig = __importStar(require("../../utils/GetProjectConfig/GetProjectConfig"));
|
|
46
|
+
jest.mock('inquirer', () => {
|
|
47
|
+
return {
|
|
48
|
+
prompt: jest.fn(),
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
describe('removeProject', () => {
|
|
52
|
+
let baseUrl;
|
|
53
|
+
let projectName;
|
|
54
|
+
let projectConfig;
|
|
55
|
+
let mockHandleCommandError;
|
|
56
|
+
let mockHandleError;
|
|
57
|
+
let mockBuildPorterUrl;
|
|
58
|
+
let mockResponse;
|
|
59
|
+
let mockClient;
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
jest.resetAllMocks();
|
|
62
|
+
jest.clearAllMocks();
|
|
63
|
+
nock_1.default.restore();
|
|
64
|
+
projectName = 'porter-project';
|
|
65
|
+
baseUrl = 'mock-url';
|
|
66
|
+
projectConfig = {
|
|
67
|
+
service: 'dxp-porter',
|
|
68
|
+
projectName,
|
|
69
|
+
version: '0.1.0',
|
|
70
|
+
};
|
|
71
|
+
mockHandleCommandError = jest.fn(() => Promise.resolve());
|
|
72
|
+
mockHandleError = jest.fn();
|
|
73
|
+
mockBuildPorterUrl = jest.fn(() => Promise.resolve(baseUrl));
|
|
74
|
+
mockResponse = {
|
|
75
|
+
data: {},
|
|
76
|
+
status: 204,
|
|
77
|
+
};
|
|
78
|
+
mockClient = {
|
|
79
|
+
delete: jest.fn().mockImplementationOnce(() => mockResponse),
|
|
80
|
+
};
|
|
81
|
+
jest
|
|
82
|
+
.spyOn(BuildPorterUrl, 'buildPorterUrl')
|
|
83
|
+
.mockImplementationOnce(mockBuildPorterUrl);
|
|
84
|
+
jest
|
|
85
|
+
.spyOn(ErrorUtils, 'handleCommandError')
|
|
86
|
+
.mockImplementationOnce(mockHandleCommandError);
|
|
87
|
+
jest
|
|
88
|
+
.spyOn(ErrorUtils, 'handleError')
|
|
89
|
+
.mockImplementationOnce(mockHandleError);
|
|
90
|
+
jest.spyOn(process, 'exit').mockImplementation();
|
|
91
|
+
jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
|
|
92
|
+
return {
|
|
93
|
+
client: mockClient,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it('should throw an error if not logged in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const mockError = new Error('Error not logged in');
|
|
99
|
+
jest
|
|
100
|
+
.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
|
|
101
|
+
.mockImplementationOnce(() => {
|
|
102
|
+
throw mockError;
|
|
103
|
+
});
|
|
104
|
+
(0, nock_1.default)('http://localhost:9999')
|
|
105
|
+
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
106
|
+
.reply(401);
|
|
107
|
+
const program = (0, remove_1.default)();
|
|
108
|
+
yield expect(() => program.parseAsync(['dxp-next', 'porter', 'project', 'removeProject'])).rejects.toThrow(mockError);
|
|
109
|
+
const opts = program.opts();
|
|
110
|
+
expect(opts).toStrictEqual({});
|
|
111
|
+
}));
|
|
112
|
+
it('should throw an error if not in a project directory', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
114
|
+
jest
|
|
115
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
116
|
+
.mockImplementationOnce(() => {
|
|
117
|
+
throw new Error('You must be within a porter project directory to use this command');
|
|
118
|
+
});
|
|
119
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
120
|
+
const program = createRemoveCommand();
|
|
121
|
+
yield program.parseAsync([
|
|
122
|
+
'dxp-next',
|
|
123
|
+
'porter',
|
|
124
|
+
'project',
|
|
125
|
+
'removeProject',
|
|
126
|
+
]);
|
|
127
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
128
|
+
expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
|
|
129
|
+
}));
|
|
130
|
+
it('should throw an error if project name is missing in the config.json file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
132
|
+
jest
|
|
133
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
134
|
+
.mockImplementationOnce(() => Promise.resolve(Object.assign(Object.assign({}, projectConfig), { projectName: '' })));
|
|
135
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
136
|
+
const program = createRemoveCommand();
|
|
137
|
+
yield program.parseAsync([
|
|
138
|
+
'dxp-next',
|
|
139
|
+
'porter',
|
|
140
|
+
'project',
|
|
141
|
+
'removeProject',
|
|
142
|
+
]);
|
|
143
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
144
|
+
expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
|
|
145
|
+
}));
|
|
146
|
+
it('should end the program if the prompt was input with anything other than "y"', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
148
|
+
jest
|
|
149
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
150
|
+
.mockImplementationOnce(() => Promise.resolve(projectConfig));
|
|
151
|
+
jest.spyOn(Inquirer, 'prompt').mockImplementationOnce(() => Promise.resolve({
|
|
152
|
+
answer: 'not-y',
|
|
153
|
+
}));
|
|
154
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
155
|
+
const program = createRemoveCommand();
|
|
156
|
+
yield program.parseAsync([
|
|
157
|
+
'dxp-next',
|
|
158
|
+
'porter',
|
|
159
|
+
'project',
|
|
160
|
+
'removeProject',
|
|
161
|
+
]);
|
|
162
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
163
|
+
expect(mockClient.delete).not.toHaveBeenCalled();
|
|
164
|
+
expect(ErrorUtils.handleCommandError).not.toHaveBeenCalled();
|
|
165
|
+
}));
|
|
166
|
+
it('should throw an error if the project does not exist in the cloud', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
168
|
+
jest
|
|
169
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
170
|
+
.mockImplementationOnce(() => Promise.resolve(projectConfig));
|
|
171
|
+
jest.spyOn(Inquirer, 'prompt').mockImplementationOnce(() => Promise.resolve({
|
|
172
|
+
answer: 'y',
|
|
173
|
+
}));
|
|
174
|
+
mockClient.delete = jest.fn(() => {
|
|
175
|
+
throw new axios_1.AxiosError('Project does not exist', '404', undefined, undefined, {
|
|
176
|
+
data: { status: 404 },
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
180
|
+
const program = createRemoveCommand();
|
|
181
|
+
yield program.parseAsync([
|
|
182
|
+
'dxp-next',
|
|
183
|
+
'porter',
|
|
184
|
+
'project',
|
|
185
|
+
'removeProject',
|
|
186
|
+
]);
|
|
187
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
188
|
+
expect(mockClient.delete).toHaveBeenCalled();
|
|
189
|
+
expect(ErrorUtils.handleError).toHaveBeenCalled();
|
|
190
|
+
}));
|
|
191
|
+
it('should successfully delete the project from the cloud', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
193
|
+
jest
|
|
194
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
195
|
+
.mockImplementationOnce(() => Promise.resolve(projectConfig));
|
|
196
|
+
jest.spyOn(Inquirer, 'prompt').mockImplementationOnce(() => Promise.resolve({
|
|
197
|
+
answer: 'y',
|
|
198
|
+
}));
|
|
199
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
200
|
+
const program = createRemoveCommand();
|
|
201
|
+
yield program.parseAsync([
|
|
202
|
+
'dxp-next',
|
|
203
|
+
'porter',
|
|
204
|
+
'project',
|
|
205
|
+
'removeProject',
|
|
206
|
+
]);
|
|
207
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
208
|
+
expect(mockClient.delete).toHaveBeenCalled();
|
|
209
|
+
expect(ErrorUtils.handleError).not.toHaveBeenCalled();
|
|
210
|
+
}));
|
|
211
|
+
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
212
|
+
jest.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
213
|
+
jest
|
|
214
|
+
.spyOn(GetProjectConfig, 'getProjectConfig')
|
|
215
|
+
.mockImplementationOnce(() => Promise.resolve(projectConfig));
|
|
216
|
+
jest.spyOn(Inquirer, 'prompt').mockImplementationOnce(() => Promise.resolve({
|
|
217
|
+
answer: 'y',
|
|
218
|
+
}));
|
|
219
|
+
mockClient.delete = jest.fn(() => {
|
|
220
|
+
throw new axios_1.AxiosError('Internal server error', '500', undefined, undefined, {
|
|
221
|
+
data: { status: 500 },
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
const { default: createRemoveCommand } = require('./remove');
|
|
225
|
+
const program = createRemoveCommand();
|
|
226
|
+
yield program.parseAsync([
|
|
227
|
+
'dxp-next',
|
|
228
|
+
'porter',
|
|
229
|
+
'project',
|
|
230
|
+
'removeProject',
|
|
231
|
+
]);
|
|
232
|
+
expect(BuildPorterUrl.buildPorterUrl).toHaveBeenCalled();
|
|
233
|
+
expect(mockClient.delete).toHaveBeenCalled();
|
|
234
|
+
expect(ErrorUtils.handleCommandError).toHaveBeenCalled();
|
|
235
|
+
}));
|
|
236
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkAuthorisation(): Promise<boolean>;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.checkAuthorisation = void 0;
|
|
13
|
+
const ApiService_1 = require("../../../ApiService");
|
|
14
|
+
const BuildPorterUrl_1 = require("../BuildPorterUrl/BuildPorterUrl");
|
|
15
|
+
const CoreUtils_1 = require("../CoreUtils/CoreUtils");
|
|
16
|
+
function checkAuthorisation() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
const baseUrl = yield (0, BuildPorterUrl_1.buildPorterUrl)();
|
|
20
|
+
const apiService = new ApiService_1.ApiService(CoreUtils_1.validateAxiosStatus, baseUrl);
|
|
21
|
+
const healthEndpoint = '/health';
|
|
22
|
+
const response = yield apiService.client.get(healthEndpoint);
|
|
23
|
+
return response.status === 200;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
(0, CoreUtils_1.logDebug)('Error while checking auth');
|
|
27
|
+
(0, CoreUtils_1.logDebug)(err);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.checkAuthorisation = checkAuthorisation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 = __importStar(require("../../../ApiService"));
|
|
36
|
+
const BuildPorterUrl = __importStar(require("../BuildPorterUrl/BuildPorterUrl"));
|
|
37
|
+
const CheckAuthorisation_1 = require("./CheckAuthorisation");
|
|
38
|
+
describe('checkAuthorisation', () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
jest.resetAllMocks();
|
|
41
|
+
});
|
|
42
|
+
it('should return false if failed to construct the porter url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
jest.spyOn(BuildPorterUrl, 'buildPorterUrl').mockImplementationOnce(() => {
|
|
44
|
+
throw new Error();
|
|
45
|
+
});
|
|
46
|
+
const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
|
|
47
|
+
expect(isAuthorised).toEqual(false);
|
|
48
|
+
}));
|
|
49
|
+
it('should return false if the health endpoint return with a non-200 status', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
jest
|
|
51
|
+
.spyOn(BuildPorterUrl, 'buildPorterUrl')
|
|
52
|
+
.mockReturnValue(Promise.resolve('1234'));
|
|
53
|
+
jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
|
|
54
|
+
return {
|
|
55
|
+
client: {
|
|
56
|
+
get: jest.fn(() => Promise.resolve({ status: 401 })),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
|
|
61
|
+
expect(isAuthorised).toEqual(false);
|
|
62
|
+
}));
|
|
63
|
+
it('should return true if the health endpoint returns with 200 status', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
jest
|
|
65
|
+
.spyOn(BuildPorterUrl, 'buildPorterUrl')
|
|
66
|
+
.mockImplementationOnce(() => Promise.resolve('1234'));
|
|
67
|
+
jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
|
|
68
|
+
return {
|
|
69
|
+
client: {
|
|
70
|
+
get: jest.fn(() => Promise.resolve({ status: 200 })),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
|
|
75
|
+
expect(isAuthorised).toEqual(true);
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildPorterUrl(override?: string): Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.buildPorterUrl = void 0;
|
|
13
|
+
const ApplicationConfig_1 = require("../../../ApplicationConfig");
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
15
|
+
const CoreUtils_1 = require("../CoreUtils/CoreUtils");
|
|
16
|
+
function buildPorterUrl(override) {
|
|
17
|
+
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}`;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.buildPorterUrl = buildPorterUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 FetchApplicationConfig = __importStar(require("../../../ApplicationConfig"));
|
|
36
|
+
const constants_1 = require("../../constants");
|
|
37
|
+
const BuildPorterUrl_1 = require("./BuildPorterUrl");
|
|
38
|
+
describe('buildPorterUrl', () => {
|
|
39
|
+
let fetchApplicationConfigSpy;
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
jest.resetAllMocks();
|
|
42
|
+
fetchApplicationConfigSpy = jest.spyOn(FetchApplicationConfig, 'fetchApplicationConfig');
|
|
43
|
+
});
|
|
44
|
+
it('should construct the URL with details from the stored config file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
fetchApplicationConfigSpy.mockImplementationOnce(() => Promise.resolve({
|
|
46
|
+
baseUrl: 'base',
|
|
47
|
+
region: 'au',
|
|
48
|
+
tenant: 'tenant',
|
|
49
|
+
}));
|
|
50
|
+
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();
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAxiosStatus = exports.logDebug = void 0;
|
|
4
|
+
function logDebug(message) {
|
|
5
|
+
if (!!process.env.DEBUG) {
|
|
6
|
+
console.log(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.logDebug = logDebug;
|
|
10
|
+
function validateAxiosStatus(status) {
|
|
11
|
+
return status < 400;
|
|
12
|
+
}
|
|
13
|
+
exports.validateAxiosStatus = validateAxiosStatus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 CoreUtils_1 = require("./CoreUtils");
|
|
13
|
+
describe('logDebug', () => {
|
|
14
|
+
const consoleSpy = jest.spyOn(console, 'log');
|
|
15
|
+
const message = 'message';
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
it('should log the message if in debug mode', () => {
|
|
20
|
+
process.env.DEBUG = 'true';
|
|
21
|
+
(0, CoreUtils_1.logDebug)(message);
|
|
22
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
23
|
+
expect(consoleSpy).toHaveBeenCalledWith(message);
|
|
24
|
+
});
|
|
25
|
+
it('should log the message if in debug mode', () => {
|
|
26
|
+
delete process.env.DEBUG;
|
|
27
|
+
(0, CoreUtils_1.logDebug)(message);
|
|
28
|
+
expect(consoleSpy).not.toHaveBeenCalled();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('validateAxiosStatus', () => {
|
|
32
|
+
it('correctly validates the status', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
expect((0, CoreUtils_1.validateAxiosStatus)(200)).toBe(true);
|
|
34
|
+
expect((0, CoreUtils_1.validateAxiosStatus)(400)).toBe(false);
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const doesPathExist: (projectPath: string) => Promise<boolean>;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.doesPathExist = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
|
+
const doesPathExist = (projectPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
yield promises_1.default.readdir(path_1.default.resolve(projectPath));
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.doesPathExist = doesPathExist;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|