@squiz/dxp-cli-next 5.13.1-develop.1 → 5.14.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/README.md +1 -0
- package/lib/__tests__/integration/main.spec.js +1 -0
- package/lib/cdp/constants.d.ts +1 -0
- package/lib/cdp/constants.js +4 -0
- package/lib/cdp/index.d.ts +3 -0
- package/lib/cdp/index.js +10 -0
- package/lib/cdp/schema/deploy/deploy.const.d.ts +5 -0
- package/lib/cdp/schema/deploy/deploy.const.js +8 -0
- package/lib/cdp/schema/deploy/deploy.d.ts +4 -0
- package/lib/cdp/schema/deploy/deploy.js +105 -0
- package/lib/cdp/schema/deploy/deploy.spec.d.ts +1 -0
- package/lib/cdp/schema/deploy/deploy.spec.js +139 -0
- package/lib/cdp/schema/schemaCommand.d.ts +3 -0
- package/lib/cdp/schema/schemaCommand.js +15 -0
- package/lib/cdp/utils.d.ts +20 -0
- package/lib/cdp/utils.js +123 -0
- package/lib/dxp.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SCV_DEPLOY_SERVICE_NAME = "scv-deploy";
|
package/lib/cdp/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
|
+
const schemaCommand_1 = __importDefault(require("./schema/schemaCommand"));
|
|
8
|
+
const cdpCommand = new commander_1.Command('cdp');
|
|
9
|
+
cdpCommand.description('CDP Commands').addCommand((0, schemaCommand_1.default)());
|
|
10
|
+
exports.default = cdpCommand;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CDP_DEPLOY_STATUS_ERROR = "error";
|
|
2
|
+
export declare const CDP_DEPLOY_STATUS_DEPLOYED = "deployed";
|
|
3
|
+
export declare const CDP_DEPLOY_STATUS_DELETED = "deleted";
|
|
4
|
+
export declare const CDP_DEPLOY_STATUS_DELETING = "deleting";
|
|
5
|
+
export declare const CDP_DEPLOY_STATUS_DEPLOYING = "deploying";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CDP_DEPLOY_STATUS_DEPLOYING = exports.CDP_DEPLOY_STATUS_DELETING = exports.CDP_DEPLOY_STATUS_DELETED = exports.CDP_DEPLOY_STATUS_DEPLOYED = exports.CDP_DEPLOY_STATUS_ERROR = void 0;
|
|
4
|
+
exports.CDP_DEPLOY_STATUS_ERROR = 'error';
|
|
5
|
+
exports.CDP_DEPLOY_STATUS_DEPLOYED = 'deployed';
|
|
6
|
+
exports.CDP_DEPLOY_STATUS_DELETED = 'deleted';
|
|
7
|
+
exports.CDP_DEPLOY_STATUS_DELETING = 'deleting';
|
|
8
|
+
exports.CDP_DEPLOY_STATUS_DEPLOYING = 'deploying';
|
|
@@ -0,0 +1,105 @@
|
|
|
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.handleDeployError = void 0;
|
|
16
|
+
const commander_1 = require("commander");
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
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 fs_1 = require("fs");
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const handleDeployError = (status, body) => {
|
|
25
|
+
let message = '';
|
|
26
|
+
if (body.title === 'Invalid schema') {
|
|
27
|
+
message += `${body.title}\n`;
|
|
28
|
+
message += body['invalid-params']
|
|
29
|
+
// @ts-ignore.
|
|
30
|
+
.map(({ name, reason }) => {
|
|
31
|
+
return `${name} - ${reason}`;
|
|
32
|
+
})
|
|
33
|
+
.join('\n');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Catch all error message.
|
|
37
|
+
message = `Status code: ${status}\n${JSON.stringify(body, null, ' ')}`;
|
|
38
|
+
}
|
|
39
|
+
throw new Error(message);
|
|
40
|
+
};
|
|
41
|
+
exports.handleDeployError = handleDeployError;
|
|
42
|
+
const createDeployCommand = () => {
|
|
43
|
+
const deployCommand = new commander_1.Command('deploy')
|
|
44
|
+
.name('deploy')
|
|
45
|
+
.description('Deploy an SCV schema')
|
|
46
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
|
|
47
|
+
.addOption(new commander_1.Option('-p, --path <string>', 'Path to your schema json file e.g. templates/scv.json').makeOptionMandatory())
|
|
48
|
+
.addOption(new commander_1.Option('-r, --region <string>', 'Region for your schema to be deployed e.g. au')
|
|
49
|
+
.choices(['au', 'uk', 'us'])
|
|
50
|
+
.makeOptionMandatory())
|
|
51
|
+
.configureOutput({
|
|
52
|
+
outputError(str, write) {
|
|
53
|
+
write(chalk_1.default.red(str));
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(deployCommand);
|
|
58
|
+
console.log('');
|
|
59
|
+
const spinner = (0, ora_1.default)('Please wait a few minutes while our cloud builds this for you.').start();
|
|
60
|
+
try {
|
|
61
|
+
const apiService = new ApiService_1.ApiService((status) => {
|
|
62
|
+
return status < 400;
|
|
63
|
+
});
|
|
64
|
+
const scvDeployBaseUrl = yield (0, utils_1.buildDXPUrl)(constants_1.SCV_DEPLOY_SERVICE_NAME, options.tenant, options.overrideUrl, options.region);
|
|
65
|
+
const schemaFilePath = path_1.default.resolve(process.cwd(), options.path);
|
|
66
|
+
if (!(0, fs_1.existsSync)(schemaFilePath)) {
|
|
67
|
+
throw new Error('Schema file not found.');
|
|
68
|
+
}
|
|
69
|
+
// Pre-parse the schema.
|
|
70
|
+
const schema = JSON.parse((0, fs_1.readFileSync)(schemaFilePath).toString('utf-8'));
|
|
71
|
+
const apiUrl = `${scvDeployBaseUrl.dxpUrl}/${scvDeployBaseUrl.tenant}`;
|
|
72
|
+
(0, utils_1.logDebug)(`PUT ${apiUrl}`);
|
|
73
|
+
const deploySchemaResponse = (yield apiService.client
|
|
74
|
+
.put(apiUrl, JSON.stringify(schema), {
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
.catch(err => {
|
|
80
|
+
(0, utils_1.logDebug)(`RAW ERROR: ${JSON.stringify(err)}`);
|
|
81
|
+
(0, exports.handleDeployError)(err.response.status, err.response.data);
|
|
82
|
+
}));
|
|
83
|
+
(0, utils_1.logDebug)(`Deploy schema response: ${JSON.stringify(deploySchemaResponse.data)}`);
|
|
84
|
+
if (deploySchemaResponse.status === 409) {
|
|
85
|
+
throw new Error('Schema is currently deploying. Please try again later.');
|
|
86
|
+
}
|
|
87
|
+
yield (0, utils_1.pollForDeployedSchema)(apiUrl, apiService);
|
|
88
|
+
spinner.succeed('Done!');
|
|
89
|
+
console.log('');
|
|
90
|
+
console.log('Your Schema has been deployed.');
|
|
91
|
+
console.log('');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
(0, utils_1.logDebug)(`ERROR: ${JSON.stringify(error)}`);
|
|
96
|
+
spinner.fail();
|
|
97
|
+
(0, utils_1.handleCommandError)(error);
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
if (process.env.ENABLE_OVERRIDE_CDP_SCHEMA_URL === 'true') {
|
|
101
|
+
deployCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire DXP url with a custom value'));
|
|
102
|
+
}
|
|
103
|
+
return deployCommand;
|
|
104
|
+
};
|
|
105
|
+
exports.default = createDeployCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
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 nock_1 = __importDefault(require("nock"));
|
|
16
|
+
const deploy_1 = __importDefault(require("./deploy"));
|
|
17
|
+
const deploy_const_1 = require("./deploy.const");
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
function createMockUrl(region, path) {
|
|
20
|
+
return `/__dxp/${region}/scv-deploy/${path}`;
|
|
21
|
+
}
|
|
22
|
+
function createMockArgs(region, tenantID, filePath, mockDomain) {
|
|
23
|
+
return [
|
|
24
|
+
'node',
|
|
25
|
+
'dxp-cli',
|
|
26
|
+
'cdp',
|
|
27
|
+
'schema',
|
|
28
|
+
'deploy',
|
|
29
|
+
'-t',
|
|
30
|
+
tenantID,
|
|
31
|
+
'-p',
|
|
32
|
+
filePath,
|
|
33
|
+
'-r',
|
|
34
|
+
region,
|
|
35
|
+
'-ou',
|
|
36
|
+
'http://localhost:9999',
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
describe('cdpSchemaCommand', () => {
|
|
40
|
+
let mockTenant;
|
|
41
|
+
let mockRegion;
|
|
42
|
+
let mockFilePath;
|
|
43
|
+
let mockDomain;
|
|
44
|
+
let logSpy;
|
|
45
|
+
let errorSpy;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
mockTenant = 'myTenant';
|
|
48
|
+
mockRegion = 'us';
|
|
49
|
+
mockFilePath = './src/__tests__/cdp/scv/schema.json';
|
|
50
|
+
mockDomain = 'http://localhost:9999';
|
|
51
|
+
process.env.ENABLE_OVERRIDE_CDP_SCHEMA_URL = 'true';
|
|
52
|
+
logSpy = jest.spyOn(console, 'log');
|
|
53
|
+
errorSpy = jest.spyOn(console, 'error');
|
|
54
|
+
if (!nock_1.default.isActive()) {
|
|
55
|
+
nock_1.default.activate();
|
|
56
|
+
}
|
|
57
|
+
// Removes mocks between unit tests so they run in isolation.
|
|
58
|
+
// Note: this does not currently work.
|
|
59
|
+
nock_1.default.cleanAll();
|
|
60
|
+
});
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
jest.clearAllMocks(); // Clear all spies
|
|
63
|
+
});
|
|
64
|
+
it('correctly handles command arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const mockPath = createMockUrl(mockRegion, mockTenant);
|
|
66
|
+
(0, nock_1.default)(mockDomain)
|
|
67
|
+
.put(mockPath, require(path_1.default.resolve(process.cwd(), './src/__tests__/cdp/scv/schema.json')))
|
|
68
|
+
.reply(200, {
|
|
69
|
+
tenantid: 'myTenant',
|
|
70
|
+
version: 'unknown',
|
|
71
|
+
stack: 'stackName',
|
|
72
|
+
status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYING,
|
|
73
|
+
})
|
|
74
|
+
.get(mockPath)
|
|
75
|
+
.reply(200, {
|
|
76
|
+
status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYED,
|
|
77
|
+
});
|
|
78
|
+
const program = (0, deploy_1.default)();
|
|
79
|
+
yield program.parseAsync(createMockArgs(mockRegion, mockTenant, mockFilePath, mockDomain));
|
|
80
|
+
const opts = program.opts();
|
|
81
|
+
expect(opts.tenant).toEqual(mockTenant);
|
|
82
|
+
expect(opts.overrideUrl).toEqual(mockDomain);
|
|
83
|
+
}));
|
|
84
|
+
it('presents a formatted invalid schema message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const schemaFileContent = require(path_1.default.resolve(process.cwd(), mockFilePath));
|
|
86
|
+
const mockPath = createMockUrl(mockRegion, mockTenant);
|
|
87
|
+
expect(`${mockDomain}${mockPath}`).toEqual('http://localhost:9999/__dxp/us/scv-deploy/myTenant');
|
|
88
|
+
(0, nock_1.default)(mockDomain)
|
|
89
|
+
.get(mockPath)
|
|
90
|
+
.reply(200, {
|
|
91
|
+
status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYED,
|
|
92
|
+
})
|
|
93
|
+
.put(mockPath, schemaFileContent)
|
|
94
|
+
.reply(400, {
|
|
95
|
+
title: 'Invalid schema',
|
|
96
|
+
'invalid-params': [
|
|
97
|
+
{
|
|
98
|
+
name: 'Name 1',
|
|
99
|
+
reason: 'Reason 1',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'Name 2',
|
|
103
|
+
reason: 'Reason 2',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
const program = (0, deploy_1.default)();
|
|
108
|
+
yield program.parseAsync(createMockArgs(mockRegion, mockTenant, mockFilePath, mockDomain));
|
|
109
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Invalid schema'));
|
|
110
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Name 1 - Reason 1'));
|
|
111
|
+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Name 2 - Reason 2'));
|
|
112
|
+
}));
|
|
113
|
+
it('deploys a schema', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
const schemaFileContent = require(path_1.default.resolve(process.cwd(), mockFilePath));
|
|
115
|
+
const mockPath = createMockUrl(mockRegion, mockTenant);
|
|
116
|
+
expect(`${mockDomain}${mockPath}`).toEqual('http://localhost:9999/__dxp/us/scv-deploy/myTenant');
|
|
117
|
+
(0, nock_1.default)(mockDomain)
|
|
118
|
+
.get(mockPath)
|
|
119
|
+
.reply(200, {
|
|
120
|
+
status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYED,
|
|
121
|
+
})
|
|
122
|
+
.put(mockPath, schemaFileContent)
|
|
123
|
+
.reply(200, {
|
|
124
|
+
tenantid: 'myTenant',
|
|
125
|
+
version: 'unknown',
|
|
126
|
+
stack: 'stackName',
|
|
127
|
+
status: deploy_const_1.CDP_DEPLOY_STATUS_DEPLOYING,
|
|
128
|
+
});
|
|
129
|
+
const program = (0, deploy_1.default)();
|
|
130
|
+
yield program.parseAsync(createMockArgs(mockRegion, mockTenant, mockFilePath, mockDomain));
|
|
131
|
+
// Note the output from the spinner doesn't seem to appear here but this still tests that it
|
|
132
|
+
// ran without displaying an error.
|
|
133
|
+
expect(logSpy).toHaveBeenNthCalledWith(1, '');
|
|
134
|
+
expect(logSpy).toHaveBeenNthCalledWith(2, '');
|
|
135
|
+
expect(logSpy).toHaveBeenNthCalledWith(3, 'Your Schema has been deployed.');
|
|
136
|
+
expect(logSpy).toHaveBeenNthCalledWith(4, '');
|
|
137
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
|
+
const deploy_1 = __importDefault(require("./deploy/deploy"));
|
|
8
|
+
const schemaCommand = () => {
|
|
9
|
+
const cdpSchemaCommands = new commander_1.Command('schema');
|
|
10
|
+
cdpSchemaCommands
|
|
11
|
+
.description('CDP Schema Commands')
|
|
12
|
+
.addCommand((0, deploy_1.default)());
|
|
13
|
+
return cdpSchemaCommands;
|
|
14
|
+
};
|
|
15
|
+
exports.default = schemaCommand;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ApiService } from '../ApiService';
|
|
3
|
+
export interface tenantDetails {
|
|
4
|
+
tenantid: string;
|
|
5
|
+
version: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
status: string;
|
|
8
|
+
tags?: any;
|
|
9
|
+
}
|
|
10
|
+
export declare function logDebug(message: string): void;
|
|
11
|
+
export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
|
|
12
|
+
export declare function buildDXPUrl(serviceName: string, tenantID?: string, override?: string, region?: string): Promise<{
|
|
13
|
+
dxpUrl: string;
|
|
14
|
+
tenant: string | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function handleCommandError(error: Error): void;
|
|
17
|
+
/**
|
|
18
|
+
* Poll the schema to be deployed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function pollForDeployedSchema(endpointUrl: string, apiService: ApiService): Promise<unknown>;
|
package/lib/cdp/utils.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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.pollForDeployedSchema = exports.handleCommandError = exports.buildDXPUrl = exports.throwErrorIfNotLoggedIn = exports.logDebug = void 0;
|
|
16
|
+
const ApplicationStore_1 = require("../ApplicationStore");
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const ApplicationConfig_1 = require("../ApplicationConfig");
|
|
19
|
+
const axios_1 = __importDefault(require("axios"));
|
|
20
|
+
const API_TIMEOUT = 300000;
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
const sleep = (ms) => {
|
|
23
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
24
|
+
};
|
|
25
|
+
/* istanbul ignore next */
|
|
26
|
+
function logDebug(message) {
|
|
27
|
+
if (!!process.env.DEBUG) {
|
|
28
|
+
console.log(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.logDebug = logDebug;
|
|
32
|
+
function throwErrorIfNotLoggedIn(command) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
|
|
35
|
+
command.error(chalk_1.default.red('You must login to interact with this command. See `dxp-next auth login`'));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.throwErrorIfNotLoggedIn = throwErrorIfNotLoggedIn;
|
|
40
|
+
function buildDXPUrl(serviceName, tenantID, override, region) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (!override) {
|
|
43
|
+
const existingConfig = yield (0, ApplicationConfig_1.fetchApplicationConfig)(tenantID);
|
|
44
|
+
logDebug(`existingConfig: ${JSON.stringify(existingConfig)}`);
|
|
45
|
+
return {
|
|
46
|
+
dxpUrl: `${existingConfig.baseUrl}/__dxp/${region || existingConfig.region}/${serviceName}`,
|
|
47
|
+
tenant: existingConfig.tenant,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
logDebug(`Using override URL: ${override}`);
|
|
52
|
+
return {
|
|
53
|
+
dxpUrl: `${override}/__dxp/${region || 'au'}/${serviceName}`,
|
|
54
|
+
tenant: tenantID,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.buildDXPUrl = buildDXPUrl;
|
|
60
|
+
function handleCommandError(error) {
|
|
61
|
+
var _a, _b, _c, _d;
|
|
62
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
63
|
+
let message = `${error.message}`;
|
|
64
|
+
if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
|
|
65
|
+
message += `: ${error.response.data.message}`;
|
|
66
|
+
}
|
|
67
|
+
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.details) {
|
|
68
|
+
message += ` - ${error.response.data.details}`;
|
|
69
|
+
}
|
|
70
|
+
console.error(chalk_1.default.red(message));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if (!!process.env.DEBUG && error.stack) {
|
|
74
|
+
console.error(error.stack);
|
|
75
|
+
}
|
|
76
|
+
if (error.message) {
|
|
77
|
+
console.error(chalk_1.default.red(error.message));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.error(chalk_1.default.red('An unknown error occurred'));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.handleCommandError = handleCommandError;
|
|
85
|
+
/**
|
|
86
|
+
* Poll the schema to be deployed.
|
|
87
|
+
*/
|
|
88
|
+
function pollForDeployedSchema(endpointUrl, apiService) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const errHandler = (err) => {
|
|
92
|
+
reject(err);
|
|
93
|
+
};
|
|
94
|
+
const checkSessionTimeout = setTimeout(() => {
|
|
95
|
+
reject('Timed out waiting for api, please try again.');
|
|
96
|
+
}, API_TIMEOUT);
|
|
97
|
+
const poll = () => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
logDebug(`GET ${endpointUrl}`);
|
|
99
|
+
const { data, status } = yield apiService.client.get(endpointUrl);
|
|
100
|
+
logDebug(`Response: ${JSON.stringify(data)}`);
|
|
101
|
+
if (status !== 200) {
|
|
102
|
+
return reject(`Unexpected poll request status: ${status}`);
|
|
103
|
+
}
|
|
104
|
+
if (data.status === 'deploying') {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
poll().catch(errHandler);
|
|
107
|
+
}, 2000);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
else if (data.status === 'deployed') {
|
|
111
|
+
clearTimeout(checkSessionTimeout);
|
|
112
|
+
resolve(true);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
clearTimeout(checkSessionTimeout);
|
|
116
|
+
reject(`Unexpected deployment status code: "${data.status}"`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
poll().catch(errHandler);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.pollForDeployedSchema = pollForDeployedSchema;
|
package/lib/dxp.js
CHANGED
|
@@ -15,6 +15,7 @@ const auth_1 = __importDefault(require("./auth"));
|
|
|
15
15
|
const cmp_1 = __importDefault(require("./cmp"));
|
|
16
16
|
const job_runner_1 = __importDefault(require("./job-runner"));
|
|
17
17
|
const datastore_1 = __importDefault(require("./datastore"));
|
|
18
|
+
const cdp_1 = __importDefault(require("./cdp"));
|
|
18
19
|
const program = new commander_1.default.Command();
|
|
19
20
|
const packageJson = require('../package.json');
|
|
20
21
|
const version = packageJson.version;
|
|
@@ -26,6 +27,7 @@ program
|
|
|
26
27
|
.addCommand(cmp_1.default)
|
|
27
28
|
.addCommand(job_runner_1.default)
|
|
28
29
|
.addCommand(datastore_1.default)
|
|
30
|
+
.addCommand(cdp_1.default)
|
|
29
31
|
.action(() => {
|
|
30
32
|
program.help();
|
|
31
33
|
})
|