@squiz/dxp-cli-next 5.23.0 → 5.23.1-develop.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ApiService.d.ts +7 -1
- package/lib/ApiService.js +15 -5
- package/lib/ApiService.spec.js +11 -0
- package/lib/auth/login/login.js +3 -3
- package/lib/cdp/schema/deploy/deploy.js +4 -2
- package/lib/cmp/deploy.js +22 -19
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -0
- package/lib/datastore/blueprint/add/add.js +3 -1
- package/lib/datastore/blueprint/list/list.js +3 -1
- package/lib/datastore/blueprint/rename/rename.js +3 -1
- package/lib/datastore/blueprint/update/update.js +3 -1
- package/lib/datastore/bundle/bundle.js +3 -1
- package/lib/datastore/simulator/upgrade/upgrade.js +1 -1
- package/lib/datastore/simulator/utils.js +3 -1
- package/lib/job-runner/job/listJobs/listJobs.js +3 -1
- package/lib/job-runner/job/listJobs/listJobs.spec.js +1 -2
- package/lib/job-runner/job/uploadJob/uploadJob.js +4 -1
- package/lib/job-runner/jobContext/listJobContexts.js +6 -11
- package/lib/job-runner/jobContext/listJobContexts.spec.js +1 -8
- package/lib/job-runner/jobExecution/beginJob/beginJob.js +3 -1
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.js +3 -1
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.js +1 -1
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.js +3 -1
- package/lib/job-runner/utils.js +11 -10
- package/lib/job-runner/utils.spec.js +2 -2
- package/lib/porter/port/abort/abort.js +4 -1
- package/lib/porter/port/get/get.js +4 -1
- package/lib/porter/port/start/start.js +4 -1
- package/lib/porter/project/add/add.js +4 -1
- package/lib/porter/project/get/get.js +4 -1
- package/lib/porter/project/remove/remove.js +4 -1
- package/package.json +3 -3
package/lib/ApiService.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
export declare const COOKIE_KEY = "dxp-sessionid";
|
|
3
|
+
interface ApiServiceParameters {
|
|
4
|
+
validateStatus?: (status: number) => boolean;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
tenantId?: string;
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* ApiService provides HTTP access to the DXP systems.
|
|
5
10
|
* This class wraps the authorization model within the DXP system by seamlessly
|
|
@@ -7,7 +12,7 @@ export declare const COOKIE_KEY = "dxp-sessionid";
|
|
|
7
12
|
*/
|
|
8
13
|
export declare class ApiService {
|
|
9
14
|
client: AxiosInstance;
|
|
10
|
-
constructor(validateStatus
|
|
15
|
+
constructor({ validateStatus, baseUrl, tenantId, }?: ApiServiceParameters);
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
18
|
* The API Service requestInterceptor will load the session cookie from
|
|
@@ -31,3 +36,4 @@ export declare class InvalidLoginSessionError extends Error {
|
|
|
31
36
|
export declare class InvalidTenantError extends Error {
|
|
32
37
|
constructor();
|
|
33
38
|
}
|
|
39
|
+
export {};
|
package/lib/ApiService.js
CHANGED
|
@@ -23,10 +23,13 @@ exports.COOKIE_KEY = 'dxp-sessionid';
|
|
|
23
23
|
* adding the session cookie to requests.
|
|
24
24
|
*/
|
|
25
25
|
class ApiService {
|
|
26
|
-
constructor(validateStatus, baseUrl) {
|
|
26
|
+
constructor({ validateStatus, baseUrl, tenantId = process.env.SQUIZ_DXP_TENANT_ID, } = {}) {
|
|
27
27
|
this.client = axios_1.default.create({
|
|
28
28
|
validateStatus: validateStatus,
|
|
29
29
|
baseURL: baseUrl,
|
|
30
|
+
headers: {
|
|
31
|
+
'x-dxp-tenant': tenantId,
|
|
32
|
+
},
|
|
30
33
|
});
|
|
31
34
|
this.client.interceptors.request.use(requestInterceptor);
|
|
32
35
|
this.client.interceptors.response.use(responseInterceptor);
|
|
@@ -42,10 +45,17 @@ function requestInterceptor(request) {
|
|
|
42
45
|
var _a;
|
|
43
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
47
|
const additionalHeaders = {};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// Support usage of API Keys generated from API Key Service
|
|
49
|
+
// @see - https://squizgroup.atlassian.net/wiki/spaces/PRODUCT/pages/2915959855/API+Key+Service+details
|
|
50
|
+
if (process.env.SQUIZ_DXP_API_TOKEN) {
|
|
51
|
+
additionalHeaders['x-api-key'] = process.env.SQUIZ_DXP_API_TOKEN;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const maybeSessionCookie = yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie);
|
|
55
|
+
if (maybeSessionCookie) {
|
|
56
|
+
additionalHeaders.cookie =
|
|
57
|
+
(_a = tough_cookie_1.Cookie.fromJSON(maybeSessionCookie)) === null || _a === void 0 ? void 0 : _a.cookieString();
|
|
58
|
+
}
|
|
49
59
|
}
|
|
50
60
|
if (process.env.DXP_JWT) {
|
|
51
61
|
additionalHeaders.authorization = `Bearer ${process.env.DXP_JWT}`;
|
package/lib/ApiService.spec.js
CHANGED
|
@@ -20,6 +20,8 @@ describe('ApiService', () => {
|
|
|
20
20
|
describe('requestInterceptor', () => {
|
|
21
21
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
delete process.env.DXP_JWT;
|
|
23
|
+
delete process.env.SQUIZ_DXP_API_TOKEN;
|
|
24
|
+
delete process.env.SQUIZ_DXP_TENANT_ID;
|
|
23
25
|
yield (0, ApplicationStore_1.deleteApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie);
|
|
24
26
|
}));
|
|
25
27
|
it('loads stored session cookie into request config', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -47,6 +49,15 @@ describe('ApiService', () => {
|
|
|
47
49
|
},
|
|
48
50
|
});
|
|
49
51
|
}));
|
|
52
|
+
it('uses the SQUIZ_DXP_API_TOKEN variable instead of session if provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
process.env.SQUIZ_DXP_API_TOKEN = '123';
|
|
54
|
+
yield (0, ApplicationStore_1.saveApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie, JSON.stringify(VALID_COOKIE.toJSON()));
|
|
55
|
+
yield expect((0, ApiService_1.requestInterceptor)({})).resolves.toMatchObject({
|
|
56
|
+
headers: {
|
|
57
|
+
'x-api-key': '123',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}));
|
|
50
61
|
});
|
|
51
62
|
describe('responseInterceptor', () => {
|
|
52
63
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
package/lib/auth/login/login.js
CHANGED
|
@@ -43,15 +43,15 @@ const ApplicationStore_1 = require("../../ApplicationStore");
|
|
|
43
43
|
const opener_1 = __importDefault(require("opener"));
|
|
44
44
|
const ora_1 = __importDefault(require("ora"));
|
|
45
45
|
const crypto_1 = require("crypto");
|
|
46
|
-
const
|
|
46
|
+
const constants_1 = require("../../constants");
|
|
47
47
|
const AUTH_TIMEOUT = 300000;
|
|
48
48
|
const createLoginCommand = () => {
|
|
49
49
|
const loginCommand = new commander_1.Command('login')
|
|
50
50
|
.name('login')
|
|
51
51
|
.description('Login to the DXP platform')
|
|
52
|
-
.addOption(new commander_1.Option('--dxp-base-url <baseURL>', '
|
|
52
|
+
.addOption(new commander_1.Option('--dxp-base-url <baseURL>', 'DXP Console URL')
|
|
53
53
|
.env('DXP_BASE_URL')
|
|
54
|
-
.default(PRODUCTION_URL))
|
|
54
|
+
.default(constants_1.PRODUCTION_URL))
|
|
55
55
|
.addOption(new commander_1.Option('--region <region>').choices(['au']).default('au'))
|
|
56
56
|
.addOption(new commander_1.Option('--override-session', 'Override the existing authorized session if it exists'))
|
|
57
57
|
.addOption(new commander_1.Option('--tenant <tenantID>'))
|
|
@@ -58,8 +58,10 @@ const createDeployCommand = () => {
|
|
|
58
58
|
console.log('');
|
|
59
59
|
const spinner = (0, ora_1.default)('Please wait a few minutes while our cloud builds this for you.').start();
|
|
60
60
|
try {
|
|
61
|
-
const apiService = new ApiService_1.ApiService(
|
|
62
|
-
|
|
61
|
+
const apiService = new ApiService_1.ApiService({
|
|
62
|
+
validateStatus: (status) => {
|
|
63
|
+
return status < 400;
|
|
64
|
+
},
|
|
63
65
|
});
|
|
64
66
|
const scvDeployBaseUrl = yield (0, utils_1.buildDXPUrl)(constants_1.SCV_DEPLOY_SERVICE_NAME, options.tenant, options.overrideUrl, options.region);
|
|
65
67
|
const schemaFilePath = path_1.default.resolve(process.cwd(), options.path);
|
package/lib/cmp/deploy.js
CHANGED
|
@@ -39,30 +39,33 @@ const commander_1 = require("commander");
|
|
|
39
39
|
const component_cli_lib_1 = require("@squiz/component-cli-lib");
|
|
40
40
|
const cli_color_1 = __importDefault(require("cli-color"));
|
|
41
41
|
const ApiService_1 = require("../ApiService");
|
|
42
|
-
const ApplicationStore_1 = require("../ApplicationStore");
|
|
43
42
|
const ApplicationConfig_1 = require("../ApplicationConfig");
|
|
44
43
|
const definitions_1 = require("./utils/definitions");
|
|
45
44
|
const fs = __importStar(require("node:fs/promises"));
|
|
46
45
|
const path = __importStar(require("node:path"));
|
|
46
|
+
const constants_1 = require("../constants");
|
|
47
47
|
const deployCommand = new commander_1.Command()
|
|
48
48
|
.name('deploy')
|
|
49
49
|
.argument('<source>', 'folder containing a manifest.json file')
|
|
50
|
-
.addOption(new commander_1.Option('-cu, --component-service-url <string>', 'Override the component service url from login')
|
|
51
|
-
.
|
|
50
|
+
.addOption(new commander_1.Option('-cu, --component-service-url <string>', 'Override the component service url from login')
|
|
51
|
+
.env('COMPONENT_SERVICE_URL')
|
|
52
|
+
.argParser(s => s.replace(/v1\/?$/, ''))
|
|
53
|
+
.hideHelp(true))
|
|
54
|
+
.addOption(new commander_1.Option('--dxp-base-url <baseURL>', 'DXP Console URL').env('DXP_BASE_URL'))
|
|
55
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to deploy to. If not provided will use configured tenant from login').env('SQUIZ_DXP_TENANT_ID'))
|
|
52
56
|
.addOption(new commander_1.Option('--dry-run', 'Run all pre-deployment processes without deploying').default(false))
|
|
53
57
|
.action((source, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
if (
|
|
56
|
-
console.log(`NOTICE: COMPONENT_SERVICE_URL is set and will deploy to ${
|
|
57
|
-
}
|
|
58
|
-
if (!options.componentServiceUrl &&
|
|
59
|
-
!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
|
|
60
|
-
deployCommand.error(cli_color_1.default.red('You must login to deploy components. See `dxp-next auth login`'));
|
|
61
|
-
}
|
|
62
|
-
const apiService = new ApiService_1.ApiService();
|
|
63
|
-
if ((_a = options.componentServiceUrl) === null || _a === void 0 ? void 0 : _a.match(/v1\/?$/)) {
|
|
64
|
-
console.warn(cli_color_1.default.yellow('WARN: Component service URL no longer requires /v1/ suffix'));
|
|
58
|
+
var _a, _b, _c, _d;
|
|
59
|
+
if (options.componentServiceUrl) {
|
|
60
|
+
console.log(`NOTICE: COMPONENT_SERVICE_URL is set and will deploy to ${options.componentServiceUrl}`);
|
|
65
61
|
}
|
|
62
|
+
const maybeConfig = yield maybeGetApplicationConfig();
|
|
63
|
+
const baseUrl = (_b = (_a = options.dxpBaseUrl) !== null && _a !== void 0 ? _a : maybeConfig === null || maybeConfig === void 0 ? void 0 : maybeConfig.baseUrl) !== null && _b !== void 0 ? _b : constants_1.PRODUCTION_URL;
|
|
64
|
+
const apiService = new ApiService_1.ApiService({
|
|
65
|
+
baseUrl,
|
|
66
|
+
tenantId: (_c = options.tenant) !== null && _c !== void 0 ? _c : maybeConfig === null || maybeConfig === void 0 ? void 0 : maybeConfig.tenant,
|
|
67
|
+
});
|
|
68
|
+
const componentServiceUrl = (_d = options.componentServiceUrl) !== null && _d !== void 0 ? _d : new URL('/__dxp/service/components-management', baseUrl).toString();
|
|
66
69
|
const dxpCacheDirPath = path.resolve(source, '../.dxp');
|
|
67
70
|
try {
|
|
68
71
|
yield fs.mkdir(dxpCacheDirPath, { recursive: true });
|
|
@@ -71,8 +74,6 @@ const deployCommand = new commander_1.Command()
|
|
|
71
74
|
if (!def) {
|
|
72
75
|
throw new Error('Failed to load component for deployment');
|
|
73
76
|
}
|
|
74
|
-
const componentServiceUrl = ((_b = options.componentServiceUrl) === null || _b === void 0 ? void 0 : _b.replace(/v1\/?$/, '')) ||
|
|
75
|
-
(yield buildComponentServiceUrl(options.tenant));
|
|
76
77
|
if (def.type === 'server') {
|
|
77
78
|
console.info(cli_color_1.default.yellow('INFO: Edge components are a new way to develop your component code offering a more stable runtime implementation of the DXP Component Service. Documentation outlining the benefits of Edge components along with Edge component development & migration guidelines can be found in DXP Component Service documentation: at https://docs.squiz.net/component-service/latest/tutorials/components-at-edge/index.html .'));
|
|
78
79
|
yield definitions_1.ComponentPreUpload.forServer(def, outputDir);
|
|
@@ -113,9 +114,11 @@ const deployCommand = new commander_1.Command()
|
|
|
113
114
|
return fs.rm(dxpCacheDirPath, { recursive: true });
|
|
114
115
|
}));
|
|
115
116
|
exports.default = deployCommand;
|
|
116
|
-
function
|
|
117
|
+
function maybeGetApplicationConfig() {
|
|
117
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
try {
|
|
120
|
+
return yield (0, ApplicationConfig_1.fetchApplicationConfig)();
|
|
121
|
+
}
|
|
122
|
+
catch (_a) { }
|
|
120
123
|
});
|
|
121
124
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PRODUCTION_URL = "https://dxp.squiz.cloud";
|
package/lib/constants.js
ADDED
|
@@ -46,7 +46,9 @@ const createAddCommand = () => {
|
|
|
46
46
|
const spinner = (0, ora_1.default)('Please wait (5 minutes) while our cloud builds this for you.').start();
|
|
47
47
|
let input;
|
|
48
48
|
try {
|
|
49
|
-
const apiService = new ApiService_1.ApiService(
|
|
49
|
+
const apiService = new ApiService_1.ApiService({
|
|
50
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
51
|
+
});
|
|
50
52
|
(0, utils_1.logDebug)('Checking blueprint limit');
|
|
51
53
|
// Check if we are at the blueprint limit.
|
|
52
54
|
const dxpTenantResp = yield apiService.client.get(yield (0, utils_1.buildOrganisationUrl)(options.tenant, options.overrideUrl));
|
|
@@ -33,7 +33,9 @@ const createListCommand = () => {
|
|
|
33
33
|
const spinner = (0, ora_1.default)('Gathering details for all cloud blueprints.').start();
|
|
34
34
|
let input;
|
|
35
35
|
try {
|
|
36
|
-
const apiService = new ApiService_1.ApiService(
|
|
36
|
+
const apiService = new ApiService_1.ApiService({
|
|
37
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
38
|
+
});
|
|
37
39
|
(0, utils_1.logDebug)('Checking blueprint limit');
|
|
38
40
|
const datastoreInstanceResp = yield apiService.client.get(yield (0, utils_1.buildDatastoreInstancesUrl)(options.tenant, options.overrideUrl));
|
|
39
41
|
(0, utils_1.logDebug)(`Listing blueprint instance: ${JSON.stringify(datastoreInstanceResp.data)}`);
|
|
@@ -44,7 +44,9 @@ const createRenameCommand = () => {
|
|
|
44
44
|
let input;
|
|
45
45
|
const organisationId = null;
|
|
46
46
|
try {
|
|
47
|
-
const apiService = new ApiService_1.ApiService(
|
|
47
|
+
const apiService = new ApiService_1.ApiService({
|
|
48
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
49
|
+
});
|
|
48
50
|
(0, utils_1.logDebug)('Checking current blueprints');
|
|
49
51
|
// Check if we are at the blueprint limit.
|
|
50
52
|
const datastoreInstancesResp = yield apiService.client.get(yield (0, utils_1.buildDatastoreInstancesUrl)(options.tenant, options.overrideUrl));
|
|
@@ -35,7 +35,9 @@ const createUpdateCommand = () => {
|
|
|
35
35
|
const spinner = (0, ora_1.default)('Please wait (5 minutes) while our cloud builds this for you.').start();
|
|
36
36
|
let input;
|
|
37
37
|
try {
|
|
38
|
-
const apiService = new ApiService_1.ApiService(
|
|
38
|
+
const apiService = new ApiService_1.ApiService({
|
|
39
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
40
|
+
});
|
|
39
41
|
(0, utils_1.logDebug)('Checking current blueprints');
|
|
40
42
|
// Check if we are at the blueprint limit.
|
|
41
43
|
const datastoreInstancesResp = yield apiService.client.get(yield (0, utils_1.buildDatastoreInstancesUrl)(options.tenant, options.overrideUrl));
|
|
@@ -85,7 +85,9 @@ const createBundleCommand = () => {
|
|
|
85
85
|
allowedExtensions.join(', ');
|
|
86
86
|
throw new Error(errorMsg);
|
|
87
87
|
}
|
|
88
|
-
const apiService = new ApiService_1.ApiService(
|
|
88
|
+
const apiService = new ApiService_1.ApiService({
|
|
89
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
90
|
+
});
|
|
89
91
|
let datastoreInstance;
|
|
90
92
|
if (options.name) {
|
|
91
93
|
(0, utils_1.logDebug)('Checking current blueprints');
|
|
@@ -23,7 +23,7 @@ const ApiService_1 = require("../../../ApiService");
|
|
|
23
23
|
function getCurrentLatest() {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
const dockerAPI = 'https://registry.hub.docker.com/v2/repositories/squizdxp/datastore/tags/latest';
|
|
26
|
-
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus);
|
|
26
|
+
const apiService = new ApiService_1.ApiService({ validateStatus: utils_1.validateAxiosStatus });
|
|
27
27
|
apiService.client.interceptors.request.clear();
|
|
28
28
|
apiService.client.interceptors.response.clear();
|
|
29
29
|
const dockerFetch = yield apiService.client.get(dockerAPI);
|
|
@@ -140,7 +140,9 @@ const checkUpdateAvailable = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
140
140
|
refreshVersionCache = true;
|
|
141
141
|
}
|
|
142
142
|
if (refreshVersionCache === true) {
|
|
143
|
-
const apiService = new ApiService_1.ApiService(
|
|
143
|
+
const apiService = new ApiService_1.ApiService({
|
|
144
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
145
|
+
});
|
|
144
146
|
apiService.client.interceptors.request.clear();
|
|
145
147
|
apiService.client.interceptors.response.clear();
|
|
146
148
|
const dockerFetch = yield apiService.client.get(dockerAPI);
|
|
@@ -34,7 +34,9 @@ const createListJobsCommand = () => {
|
|
|
34
34
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(listJobsCommand);
|
|
35
35
|
const spinner = (0, ora_1.default)('Retrieving jobs').start();
|
|
36
36
|
try {
|
|
37
|
-
const apiService = new ApiService_1.ApiService(
|
|
37
|
+
const apiService = new ApiService_1.ApiService({
|
|
38
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
39
|
+
});
|
|
38
40
|
let listJobsUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/job/latest?`;
|
|
39
41
|
listJobsUrl = (0, utils_1.addPaginationToUrl)(listJobsUrl, {
|
|
40
42
|
before: options.before,
|
|
@@ -14,12 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nock_1 = __importDefault(require("nock"));
|
|
16
16
|
const listJobs_1 = __importDefault(require("./listJobs"));
|
|
17
|
-
const logSpy = jest.spyOn(global.console, 'log');
|
|
18
17
|
describe('listJobs', () => {
|
|
19
18
|
it('correctly lists the job', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
19
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
20
|
(0, nock_1.default)('http://localhost:9999')
|
|
22
|
-
.get('/job/latest?&page
|
|
21
|
+
.get('/job/latest?&page%5Bsize%5D=5')
|
|
23
22
|
.reply(200, [{ name: 'simple-job', type: 'job', version: '1.0.0' }]);
|
|
24
23
|
const program = (0, listJobs_1.default)();
|
|
25
24
|
yield program.parseAsync([
|
|
@@ -33,7 +33,10 @@ const createUploadJobCommand = () => {
|
|
|
33
33
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(uploadJobCommand);
|
|
34
34
|
const spinner = (0, ora_1.default)('Uploading job ').start();
|
|
35
35
|
try {
|
|
36
|
-
const apiService = new ApiService_1.ApiService(
|
|
36
|
+
const apiService = new ApiService_1.ApiService({
|
|
37
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
38
|
+
baseUrl: yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl),
|
|
39
|
+
});
|
|
37
40
|
yield (0, component_cli_lib_1.uploadJobFolder)(apiService.client, inputSource);
|
|
38
41
|
spinner.succeed();
|
|
39
42
|
return;
|
|
@@ -34,7 +34,9 @@ const createListJobContextsCommand = () => {
|
|
|
34
34
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(listJobContextsCommand);
|
|
35
35
|
const spinner = (0, ora_1.default)('Retrieving job contexts\r\n').start();
|
|
36
36
|
try {
|
|
37
|
-
const apiService = new ApiService_1.ApiService(
|
|
37
|
+
const apiService = new ApiService_1.ApiService({
|
|
38
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
39
|
+
});
|
|
38
40
|
let listJobContextsUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/job-context?`;
|
|
39
41
|
listJobContextsUrl = (0, utils_1.addPaginationToUrl)(listJobContextsUrl, {
|
|
40
42
|
before: options.before,
|
|
@@ -42,16 +44,9 @@ const createListJobContextsCommand = () => {
|
|
|
42
44
|
size: options.size,
|
|
43
45
|
});
|
|
44
46
|
const res = yield apiService.client.get(listJobContextsUrl);
|
|
45
|
-
if (Array.isArray(res.data) && res.data.length > 0) {
|
|
46
|
-
spinner.succeed(
|
|
47
|
-
(0, utils_1.
|
|
48
|
-
res.data.forEach((context) => {
|
|
49
|
-
console.log(`${chalk_1.default.green(chalk_1.default.bold(context.contextName))}: ${chalk_1.default.green(context.description)}`);
|
|
50
|
-
for (const [key, value] of Object.entries(context.environment)) {
|
|
51
|
-
console.log(`${chalk_1.default.bold(key)}: ${JSON.stringify(value)}`);
|
|
52
|
-
}
|
|
53
|
-
(0, utils_1.writeLineSeparator)();
|
|
54
|
-
});
|
|
47
|
+
if (Array.isArray(res.data.data) && res.data.data.length > 0) {
|
|
48
|
+
spinner.succeed(`Retrieved ${res.data.data.length} job contexts`);
|
|
49
|
+
yield (0, utils_1.logArrayResults)(res.data.data, res.data.links);
|
|
55
50
|
}
|
|
56
51
|
else {
|
|
57
52
|
spinner.succeed('No job contexts found');
|
|
@@ -14,13 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nock_1 = __importDefault(require("nock"));
|
|
16
16
|
const listJobContexts_1 = __importDefault(require("./listJobContexts"));
|
|
17
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
17
|
describe('listJobContexts', () => {
|
|
20
18
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
19
|
it('correctly lists the job contexts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
20
|
(0, nock_1.default)('http://localhost:9999')
|
|
23
|
-
.get('/job-context?')
|
|
21
|
+
.get('/job-context?page%5Bsize%5D=20')
|
|
24
22
|
.reply(200, [
|
|
25
23
|
{
|
|
26
24
|
contextName: 'dev',
|
|
@@ -55,10 +53,5 @@ describe('listJobContexts', () => {
|
|
|
55
53
|
const opts = program.opts();
|
|
56
54
|
expect(opts.tenant).toEqual('myTenant');
|
|
57
55
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
58
|
-
expect(logSpy).toHaveBeenCalledTimes(9);
|
|
59
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.green(chalk_1.default.bold('dev'))}: ${chalk_1.default.green('dev context')}`);
|
|
60
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('something')}: ${JSON.stringify('cool')}`);
|
|
61
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: ${JSON.stringify('cooler')}`);
|
|
62
|
-
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
63
56
|
}));
|
|
64
57
|
});
|
|
@@ -39,7 +39,9 @@ const createBeginJobCommand = () => {
|
|
|
39
39
|
if (options.inputFile) {
|
|
40
40
|
input = yield (0, utils_1.readInputFile)(options.inputFile);
|
|
41
41
|
}
|
|
42
|
-
const apiService = new ApiService_1.ApiService(
|
|
42
|
+
const apiService = new ApiService_1.ApiService({
|
|
43
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
44
|
+
});
|
|
43
45
|
const beginJobUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/begin`;
|
|
44
46
|
const res = yield apiService.client.post(beginJobUrl, {
|
|
45
47
|
jobName: jobName,
|
|
@@ -35,7 +35,9 @@ const createListJobExecutionsCommand = () => {
|
|
|
35
35
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(listJobExecutionsCommand);
|
|
36
36
|
const spinner = (0, ora_1.default)('Retrieving job executions').start();
|
|
37
37
|
try {
|
|
38
|
-
const apiService = new ApiService_1.ApiService(
|
|
38
|
+
const apiService = new ApiService_1.ApiService({
|
|
39
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
40
|
+
});
|
|
39
41
|
let listExecutionsUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/jobName/${jobName}?`;
|
|
40
42
|
listExecutionsUrl = (0, utils_1.addPaginationToUrl)(listExecutionsUrl, {
|
|
41
43
|
before: options.before,
|
|
@@ -19,7 +19,7 @@ describe('listJobExecutions', () => {
|
|
|
19
19
|
it('correctly lists the job executions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
21
|
(0, nock_1.default)('http://localhost:9999')
|
|
22
|
-
.get('/executions/jobName/job-runner?&page
|
|
22
|
+
.get('/executions/jobName/job-runner?&page%5Bsize%5D=5')
|
|
23
23
|
.reply(200, [
|
|
24
24
|
{
|
|
25
25
|
context: 'dev',
|
|
@@ -36,7 +36,9 @@ const createTerminateJobCommand = () => {
|
|
|
36
36
|
const spinner = (0, ora_1.default)('Terminating job').start();
|
|
37
37
|
console.log('');
|
|
38
38
|
try {
|
|
39
|
-
const apiService = new ApiService_1.ApiService(
|
|
39
|
+
const apiService = new ApiService_1.ApiService({
|
|
40
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
41
|
+
});
|
|
40
42
|
const terminateJobUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/terminate`;
|
|
41
43
|
const res = yield apiService.client.post(terminateJobUrl, {
|
|
42
44
|
jobName: jobName,
|
package/lib/job-runner/utils.js
CHANGED
|
@@ -96,19 +96,20 @@ function addPaginationToUrl(url, opts) {
|
|
|
96
96
|
if (opts.before && opts.after) {
|
|
97
97
|
throw new Error('Only one of before and after can be set');
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const parsedUrl = new URL(url);
|
|
100
|
+
const params = parsedUrl.searchParams;
|
|
101
|
+
// Set page size
|
|
102
|
+
params.set('page[size]', opts.size
|
|
103
|
+
? `${PaginationPageLimit[opts.size]}`
|
|
104
|
+
: `${PaginationPageLimit.small}`);
|
|
105
|
+
// Set pagination parameters
|
|
105
106
|
if (opts.before) {
|
|
106
|
-
|
|
107
|
+
params.set('page[before]', opts.before);
|
|
107
108
|
}
|
|
108
|
-
if (opts.after) {
|
|
109
|
-
|
|
109
|
+
else if (opts.after) {
|
|
110
|
+
params.set('page[after]', opts.after);
|
|
110
111
|
}
|
|
111
|
-
return
|
|
112
|
+
return parsedUrl.toString();
|
|
112
113
|
}
|
|
113
114
|
exports.addPaginationToUrl = addPaginationToUrl;
|
|
114
115
|
function logArrayResults(results, links) {
|
|
@@ -93,11 +93,11 @@ describe('readInputFile', () => {
|
|
|
93
93
|
describe('addPaginationToUrl', () => {
|
|
94
94
|
it('correctly adds the pagination size param to the url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
95
|
const url = (0, utils_1.addPaginationToUrl)('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?', { size: 'tiny', before: '', after: '' });
|
|
96
|
-
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest
|
|
96
|
+
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?page%5Bsize%5D=5');
|
|
97
97
|
}));
|
|
98
98
|
it('correctly adds the pagination params to the url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
99
|
const url = (0, utils_1.addPaginationToUrl)('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?', { size: 'tiny', before: '12345', after: '' });
|
|
100
|
-
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest
|
|
100
|
+
expect(url).toBe('http://localhost:9999//__dxp/au/job-runner/someTenant/job/latest?page%5Bsize%5D=5&page%5Bbefore%5D=12345');
|
|
101
101
|
}));
|
|
102
102
|
it('correctly throws error for before and after params', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
103
|
expect(() => {
|
|
@@ -43,7 +43,10 @@ const createAbortPortCommand = () => {
|
|
|
43
43
|
try {
|
|
44
44
|
projectName = yield (0, utils_1.getProjectName)();
|
|
45
45
|
spinner.start('Aborting port..');
|
|
46
|
-
const apiService = new ApiService_1.ApiService(
|
|
46
|
+
const apiService = new ApiService_1.ApiService({
|
|
47
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
48
|
+
baseUrl,
|
|
49
|
+
});
|
|
47
50
|
const abortRequest = {
|
|
48
51
|
status: 'abort',
|
|
49
52
|
};
|
|
@@ -44,7 +44,10 @@ const createGetPortCommand = () => {
|
|
|
44
44
|
try {
|
|
45
45
|
projectName = yield (0, utils_1.getProjectName)();
|
|
46
46
|
spinner.start('Retrieving port..');
|
|
47
|
-
const apiService = new ApiService_1.ApiService(
|
|
47
|
+
const apiService = new ApiService_1.ApiService({
|
|
48
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
49
|
+
baseUrl,
|
|
50
|
+
});
|
|
48
51
|
const response = yield apiService.client.get(`/projects/${projectName}/ports/${portId}`);
|
|
49
52
|
const jsonResponse = response.data;
|
|
50
53
|
(0, utils_1.logDebug)(JSON.stringify(jsonResponse));
|
|
@@ -35,7 +35,10 @@ const createStartPortCommand = () => {
|
|
|
35
35
|
try {
|
|
36
36
|
projectName = yield (0, utils_1.getProjectName)();
|
|
37
37
|
spinner.start('Starting port..');
|
|
38
|
-
const apiService = new ApiService_1.ApiService(
|
|
38
|
+
const apiService = new ApiService_1.ApiService({
|
|
39
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
40
|
+
baseUrl,
|
|
41
|
+
});
|
|
39
42
|
// Read the stage directories for project configuration
|
|
40
43
|
const stageConfigDir = path_1.default.resolve('stage-configs');
|
|
41
44
|
const stageDirs = yield promises_1.default.readdir(stageConfigDir);
|
|
@@ -70,7 +70,10 @@ const createAddProjectCommand = () => {
|
|
|
70
70
|
throw new Error(`Project parent directory "${parentDir}" does not exist`);
|
|
71
71
|
}
|
|
72
72
|
spinner.start('Creating a new project..');
|
|
73
|
-
const apiService = new ApiService_1.ApiService(
|
|
73
|
+
const apiService = new ApiService_1.ApiService({
|
|
74
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
75
|
+
baseUrl,
|
|
76
|
+
});
|
|
74
77
|
const requestBody = { 'new-project': true };
|
|
75
78
|
const response = yield apiService.client.put(`/projects/${projectName}`, requestBody);
|
|
76
79
|
(0, utils_1.logDebug)(response.data);
|
|
@@ -34,7 +34,10 @@ const createGetProjectCommand = () => {
|
|
|
34
34
|
try {
|
|
35
35
|
projectName = yield (0, utils_1.getProjectName)();
|
|
36
36
|
spinner.start('Retrieving project..');
|
|
37
|
-
const apiService = new ApiService_1.ApiService(
|
|
37
|
+
const apiService = new ApiService_1.ApiService({
|
|
38
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
39
|
+
baseUrl,
|
|
40
|
+
});
|
|
38
41
|
const response = yield apiService.client.get(`/projects/${projectName}`);
|
|
39
42
|
const jsonResponse = response.data;
|
|
40
43
|
(0, utils_1.logDebug)(JSON.stringify(jsonResponse));
|
|
@@ -43,7 +43,10 @@ const createRemoveProjectCommand = () => {
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
spinner.start('Deleting project..');
|
|
46
|
-
const apiService = new ApiService_1.ApiService(
|
|
46
|
+
const apiService = new ApiService_1.ApiService({
|
|
47
|
+
validateStatus: utils_1.validateAxiosStatus,
|
|
48
|
+
baseUrl,
|
|
49
|
+
});
|
|
47
50
|
const response = yield apiService.client.delete(`/projects/${projectName}`);
|
|
48
51
|
(0, utils_1.logDebug)(response.data);
|
|
49
52
|
spinner.succeed('Project has been deleted from the cloud');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/dxp-cli-next",
|
|
3
|
-
"version": "5.23.
|
|
3
|
+
"version": "5.23.1-develop.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
|
|
6
6
|
},
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@apidevtools/swagger-parser": "10.1.0",
|
|
44
|
-
"@squiz/component-cli-lib": "1.71.
|
|
44
|
+
"@squiz/component-cli-lib": "1.71.12",
|
|
45
45
|
"@squiz/dxp-porter-shared": "0.4.0",
|
|
46
|
-
"@squiz/local-component-dev-ui": "0.6.
|
|
46
|
+
"@squiz/local-component-dev-ui": "0.6.18",
|
|
47
47
|
"axios": "1.1.3",
|
|
48
48
|
"cli-color": "2.0.3",
|
|
49
49
|
"commander": "9.4.0",
|