@squiz/dxp-cli-next 5.12.2-develop.1 → 5.13.0-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/auth/index.js +3 -4
- package/lib/auth/logout/logout.js +1 -1
- package/lib/datastore/blueprint/add/add.js +9 -1
- package/lib/datastore/blueprint/add/add.spec.js +52 -0
- package/lib/datastore/blueprint/rename/rename.js +9 -1
- package/lib/datastore/blueprint/rename/rename.spec.js +50 -0
- package/lib/datastore/utils.d.ts +2 -0
- package/lib/datastore/utils.js +13 -1
- package/lib/datastore/utils.spec.js +21 -0
- package/package.json +1 -1
package/lib/auth/index.js
CHANGED
|
@@ -5,11 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const login_1 = __importDefault(require("./login/login"));
|
|
8
|
+
const logout_1 = __importDefault(require("./logout/logout"));
|
|
8
9
|
const authCommand = new commander_1.Command('auth');
|
|
9
10
|
authCommand
|
|
10
11
|
.description('Authenticate into the DXP-Next CLI')
|
|
11
|
-
.addCommand((0, login_1.default)())
|
|
12
|
-
|
|
13
|
-
// getting fixed in PLATFORM-940
|
|
14
|
-
// .addCommand(createLogoutCommand());
|
|
12
|
+
.addCommand((0, login_1.default)())
|
|
13
|
+
.addCommand((0, logout_1.default)());
|
|
15
14
|
exports.default = authCommand;
|
|
@@ -43,7 +43,7 @@ const createLogoutCommand = () => {
|
|
|
43
43
|
const logoutCommand = new commander_1.Command('logout')
|
|
44
44
|
.name('logout')
|
|
45
45
|
.description('Log out of the current session')
|
|
46
|
-
.addOption(new commander_1.Option('-f, --force', '
|
|
46
|
+
.addOption(new commander_1.Option('-f, --force', 'skip confirmation prompt'))
|
|
47
47
|
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
48
|
try {
|
|
49
49
|
yield handleLogoutRequest(options);
|
|
@@ -23,7 +23,15 @@ const createAddCommand = () => {
|
|
|
23
23
|
.description('Adds a new blueprint')
|
|
24
24
|
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
|
|
25
25
|
.addOption(new commander_1.Option('-p, --path <string>', 'Path to your blueprint API yaml file e.g. documents/inputs/blueprint.yaml').makeOptionMandatory())
|
|
26
|
-
.addOption(new commander_1.Option('-n, --name <string>', 'Name for your blueprint e.g. MyFirstBlueprint')
|
|
26
|
+
.addOption(new commander_1.Option('-n, --name <string>', 'Name for your blueprint e.g. MyFirstBlueprint')
|
|
27
|
+
.makeOptionMandatory()
|
|
28
|
+
.argParser(v => {
|
|
29
|
+
const name = v;
|
|
30
|
+
if ((0, utils_1.dataServiceNameIsValid)(name) === false) {
|
|
31
|
+
throw new commander_1.InvalidArgumentError(utils_1.BLUEPRINT_ERROR);
|
|
32
|
+
}
|
|
33
|
+
return name;
|
|
34
|
+
}))
|
|
27
35
|
.addOption(new commander_1.Option('-r, --region <string>', 'Region for your blueprint to be deployed yo e.g. au')
|
|
28
36
|
.choices(['au', 'uk', 'us'])
|
|
29
37
|
.makeOptionMandatory())
|
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
38
|
const nock_1 = __importDefault(require("nock"));
|
|
16
39
|
const add_1 = __importDefault(require("./add"));
|
|
17
40
|
const utils_1 = require("../../utils");
|
|
41
|
+
const utils = __importStar(require("../../utils"));
|
|
18
42
|
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
43
|
describe('datastoreBlueprintAdd', () => {
|
|
20
44
|
process.env.ENABLE_OVERRIDE_DATASTORE_URL = 'true';
|
|
@@ -79,4 +103,32 @@ describe('datastoreBlueprintAdd', () => {
|
|
|
79
103
|
expect(logSpy).toHaveBeenCalledWith(' Region: au');
|
|
80
104
|
expect(logSpy).toHaveBeenCalledWith('');
|
|
81
105
|
}));
|
|
106
|
+
it('errors on bad blueprint name', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
const dataServiceNameIsValidSpy = jest
|
|
108
|
+
.spyOn(utils, 'dataServiceNameIsValid')
|
|
109
|
+
.mockReturnValue(false);
|
|
110
|
+
const program = (0, add_1.default)()
|
|
111
|
+
.exitOverride()
|
|
112
|
+
.action(() => { });
|
|
113
|
+
expect(() => {
|
|
114
|
+
program.parse([
|
|
115
|
+
'node',
|
|
116
|
+
'dxp-cli',
|
|
117
|
+
'datastore',
|
|
118
|
+
'blueprint',
|
|
119
|
+
'add',
|
|
120
|
+
'-t',
|
|
121
|
+
'myTenant',
|
|
122
|
+
'-p',
|
|
123
|
+
'./src/__tests__/datastore/blueprints/blueprint.yaml',
|
|
124
|
+
'-n',
|
|
125
|
+
'myBlueprint',
|
|
126
|
+
'-r',
|
|
127
|
+
'au',
|
|
128
|
+
'-ou',
|
|
129
|
+
'http://localhost:9999',
|
|
130
|
+
]);
|
|
131
|
+
}).toThrow("error: option '-n, --name <string>' argument 'myBlueprint' is invalid. Blueprint names can be a mix of letters, numbers, hyphen, underscore, brackets including square and up to 100 characters long");
|
|
132
|
+
expect(dataServiceNameIsValidSpy).toHaveBeenCalledTimes(1);
|
|
133
|
+
}));
|
|
82
134
|
});
|
|
@@ -23,7 +23,15 @@ const createRenameCommand = () => {
|
|
|
23
23
|
.description('Renames an existing blueprint')
|
|
24
24
|
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
|
|
25
25
|
.addOption(new commander_1.Option('-on, --oldName <string>', 'Old Name for your blueprint e.g. MyFirstBlueprint').makeOptionMandatory())
|
|
26
|
-
.addOption(new commander_1.Option('-nn, --newName <string>', 'New Name for your blueprint e.g. MyFirstBlueprint')
|
|
26
|
+
.addOption(new commander_1.Option('-nn, --newName <string>', 'New Name for your blueprint e.g. MyFirstBlueprint')
|
|
27
|
+
.makeOptionMandatory()
|
|
28
|
+
.argParser(v => {
|
|
29
|
+
const name = v;
|
|
30
|
+
if ((0, utils_1.dataServiceNameIsValid)(name) === false) {
|
|
31
|
+
throw new commander_1.InvalidArgumentError(utils_1.BLUEPRINT_ERROR);
|
|
32
|
+
}
|
|
33
|
+
return name;
|
|
34
|
+
}))
|
|
27
35
|
.configureOutput({
|
|
28
36
|
outputError(str, write) {
|
|
29
37
|
write(chalk_1.default.red(str));
|
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
38
|
const nock_1 = __importDefault(require("nock"));
|
|
16
39
|
const rename_1 = __importDefault(require("./rename"));
|
|
17
40
|
const utils_1 = require("../../utils");
|
|
41
|
+
const utils = __importStar(require("../../utils"));
|
|
18
42
|
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
43
|
describe('datastoreBlueprintRename', () => {
|
|
20
44
|
process.env.ENABLE_OVERRIDE_DATASTORE_URL = 'true';
|
|
@@ -89,4 +113,30 @@ describe('datastoreBlueprintRename', () => {
|
|
|
89
113
|
expect(logSpy).toHaveBeenCalledWith('');
|
|
90
114
|
expect(logSpy).toHaveBeenCalledWith('');
|
|
91
115
|
}));
|
|
116
|
+
it('errors on bad blueprint rename', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const dataServiceNameIsValidSpy = jest
|
|
118
|
+
.spyOn(utils, 'dataServiceNameIsValid')
|
|
119
|
+
.mockReturnValue(false);
|
|
120
|
+
const program = (0, rename_1.default)()
|
|
121
|
+
.exitOverride()
|
|
122
|
+
.action(() => { });
|
|
123
|
+
expect(() => {
|
|
124
|
+
program.parse([
|
|
125
|
+
'node',
|
|
126
|
+
'dxp-cli',
|
|
127
|
+
'datastore',
|
|
128
|
+
'blueprint',
|
|
129
|
+
'rename',
|
|
130
|
+
'-t',
|
|
131
|
+
'myTenant',
|
|
132
|
+
'-on',
|
|
133
|
+
'myBlueprint',
|
|
134
|
+
'-nn',
|
|
135
|
+
'myRenamedBlueprint',
|
|
136
|
+
'-ou',
|
|
137
|
+
'http://localhost:9999',
|
|
138
|
+
]);
|
|
139
|
+
}).toThrow("error: option '-nn, --newName <string>' argument 'myRenamedBlueprint' is invalid. Blueprint names can be a mix of letters, numbers, hyphen, underscore, brackets including square and up to 100 characters long");
|
|
140
|
+
expect(dataServiceNameIsValidSpy).toHaveBeenCalledTimes(1);
|
|
141
|
+
}));
|
|
92
142
|
});
|
package/lib/datastore/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { ApiService } from '../ApiService';
|
|
3
3
|
export declare const CONSOLE_STATUS_CODE_LIVE = "Live";
|
|
4
4
|
export declare const CONSOLE_STATUS_CODE_ERROR = "Error";
|
|
5
|
+
export declare const BLUEPRINT_ERROR = "Blueprint names can be a mix of letters, numbers, hyphen, underscore, brackets including square and up to 100 characters long";
|
|
5
6
|
export declare function logDebug(message: string): void;
|
|
6
7
|
export declare function bundleBlueprint(filePath: string, asYaml?: boolean): Promise<string>;
|
|
7
8
|
export declare function handleCommandError(command: Command, error: Error): void;
|
|
@@ -16,3 +17,4 @@ export declare function buildOrganisationUrl(tenantID?: string, override?: strin
|
|
|
16
17
|
export declare function buildInstanceUrl(tenantID?: string, instanceID?: string, override?: string, isDeploy?: boolean): Promise<string>;
|
|
17
18
|
export declare function buildDatastoreInstancesUrl(tenantID?: string, override?: string): Promise<string>;
|
|
18
19
|
export declare function checkDeploymentStatus(apiService: ApiService, tenantID?: string, instanceID?: string, override?: string): Promise<any>;
|
|
20
|
+
export declare function dataServiceNameIsValid(name: string): boolean;
|
package/lib/datastore/utils.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.checkDeploymentStatus = exports.buildDatastoreInstancesUrl = exports.buildInstanceUrl = exports.buildOrganisationUrl = exports.buildDXPUrl = exports.validateAxiosStatus = exports.writeLineSeparator = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = exports.bundleBlueprint = exports.logDebug = exports.CONSOLE_STATUS_CODE_ERROR = exports.CONSOLE_STATUS_CODE_LIVE = void 0;
|
|
38
|
+
exports.dataServiceNameIsValid = exports.checkDeploymentStatus = exports.buildDatastoreInstancesUrl = exports.buildInstanceUrl = exports.buildOrganisationUrl = exports.buildDXPUrl = exports.validateAxiosStatus = exports.writeLineSeparator = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = exports.bundleBlueprint = exports.logDebug = exports.BLUEPRINT_ERROR = exports.CONSOLE_STATUS_CODE_ERROR = exports.CONSOLE_STATUS_CODE_LIVE = void 0;
|
|
39
39
|
const path_1 = __importDefault(require("path"));
|
|
40
40
|
const fs_1 = __importDefault(require("fs"));
|
|
41
41
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -46,6 +46,7 @@ const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"))
|
|
|
46
46
|
const YAML = __importStar(require("yaml"));
|
|
47
47
|
exports.CONSOLE_STATUS_CODE_LIVE = 'Live';
|
|
48
48
|
exports.CONSOLE_STATUS_CODE_ERROR = 'Error';
|
|
49
|
+
exports.BLUEPRINT_ERROR = 'Blueprint names can be a mix of letters, numbers, hyphen, underscore, brackets including square and up to 100 characters long';
|
|
49
50
|
/* istanbul ignore next */
|
|
50
51
|
const sleep = (ms) => {
|
|
51
52
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -227,3 +228,14 @@ function checkDeploymentStatus(apiService, tenantID, instanceID, override) {
|
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
230
|
exports.checkDeploymentStatus = checkDeploymentStatus;
|
|
231
|
+
function dataServiceNameIsValid(name) {
|
|
232
|
+
const regex = /^[A-Za-z0-9\-\_\(\)\[\]:]+$/;
|
|
233
|
+
const found = name.match(regex);
|
|
234
|
+
if (found == null || name.length >= 100) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.dataServiceNameIsValid = dataServiceNameIsValid;
|
|
@@ -89,4 +89,25 @@ paths:
|
|
|
89
89
|
const res = yield (0, utils_1.bundleBlueprint)(path_1.default.join('./src/__tests__/datastore/blueprints/blueprint.json'), false);
|
|
90
90
|
expect(res).toStrictEqual('{"openapi":"3.0.2","info":{"description":"A Sample Test API","version":"1.0.0","title":"Unit Test"},"paths":{"/acl-dxp-authentication-1":{"get":{"x-datastore-acl":"public","responses":{"200":{"description":"OK"}}}}}}');
|
|
91
91
|
}));
|
|
92
|
+
describe('dataServiceNameIsValid', () => {
|
|
93
|
+
it.each([
|
|
94
|
+
'blueprint',
|
|
95
|
+
'abcdefghijklmnopqrstuvwxyz',
|
|
96
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
97
|
+
'1234567890',
|
|
98
|
+
'-_():[]',
|
|
99
|
+
])('validates blueprint name as valid (%s)', name => {
|
|
100
|
+
const result = (0, utils_1.dataServiceNameIsValid)(name);
|
|
101
|
+
expect(result).toStrictEqual(true);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it.each([
|
|
105
|
+
'',
|
|
106
|
+
'blue!',
|
|
107
|
+
'/print',
|
|
108
|
+
'reallylongoverlimitnamesssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss',
|
|
109
|
+
])('validates blueprint name as invalid (%s)', name => {
|
|
110
|
+
const result = (0, utils_1.dataServiceNameIsValid)(name);
|
|
111
|
+
expect(result).toStrictEqual(false);
|
|
112
|
+
});
|
|
92
113
|
});
|