Skip to content

Commit

Permalink
fix: improve user experiences by updating the post-lwa response webpa…
Browse files Browse the repository at this point in the history
…ge (#108)

Also fix the NPE when developers want to self-host and no deployer is selected in new command
  • Loading branch information
RonWang authored Apr 8, 2020
1 parent 57d8b24 commit 41c17a6
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ coverage

# MAC OS
.DS_Store

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1 align="center">Alexa Skills Kit Command Line interface</h1>
<p align="center">
<a href="https://www.npmjs.com/package/ask-cli-x"><img src="https://badge.fury.io/js/ask-cli-x.svg"></a>
<a href="https://travis-ci.org/alexa-labs/ask-cli"><img src="https://travis-ci.org/alexa-labs/ask-cli.svg?branch=master"></a>
<a href="https://travis-ci.org/alexa/ask-cli"><img src="https://travis-ci.org/alexa/ask-cli.svg?branch=master"></a>
</p>
<p align="center">
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg"></a>
Expand Down
8 changes: 7 additions & 1 deletion lib/commands/init/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CliWarn = require('@src/exceptions/cli-warn');
const AskResources = require('@src/model/resources-config/ask-resources');
const AskStates = require('@src/model/resources-config/ask-states');
const ResourcesConfig = require('@src/model/resources-config');
const stringUtils = require('@src/utils/string-utils');
const CONSTANTS = require('@src/utils/constants');
const Messenger = require('@src/view/messenger');

Expand Down Expand Up @@ -177,8 +178,13 @@ function _assembleAskResources(userInput, profile) {
function bootstrapSkillInfra(rootPath, profile, doDebug, callback) {
const askResourcesFilePath = path.join(rootPath, CONSTANTS.FILE_PATH.ASK_RESOURCES_JSON_CONFIG);
new ResourcesConfig(askResourcesFilePath);
// bootstrap after deployer gets selected
const deployerType = ResourcesConfig.getInstance().getSkillInfraType(profile);
if (!stringUtils.isNonBlankString(deployerType)) {
return process.nextTick(() => {
callback();
});
}
// bootstrap after deployer gets selected
const ddFolderPath = deployerType.startsWith('@ask-cli/') ? deployerType.replace('@ask-cli/', '') : deployerType;
const deployerPath = path.join(rootPath, CONSTANTS.FILE_PATH.SKILL_INFRASTRUCTURE.INFRASTRUCTURE, ddFolderPath);
fs.ensureDirSync(deployerPath);
Expand Down
5 changes: 3 additions & 2 deletions lib/controllers/authorization-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ module.exports = class AuthorizationController {
}
if (requestUrl.startsWith('/cb?error')) {
response.statusCode = 403;
response.end(`Error: ${requestQuery.error}\nError description: ${requestQuery.error_description}`);
callback(messages.ASK_SIGN_IN_FAILURE_MESSAGE);
const errorMessage = `Error: ${requestQuery.error}\nReason: ${requestQuery.error_description}`;
response.end(messages.ASK_SIGN_IN_FAILURE_MESSAGE(errorMessage));
callback(errorMessage);
}
}
}
Expand Down
48 changes: 47 additions & 1 deletion lib/controllers/authorization-controller/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,52 @@ module.exports.PORT_OCCUPIED_WARN_MESSAGE = '[Warn]: 9090 port on localhost has
+ 'ask-cli cannot start a local server for receiving authorization code.\nPlease either abort any processes running on port 9090\n'
+ 'or add `--no-browser` flag to the command as an alternative approach.';

module.exports.ASK_SIGN_IN_SUCCESS_MESSAGE = 'Sign in was successful. Close browser and return to the command line interface.';
module.exports.ASK_SIGN_IN_SUCCESS_MESSAGE = `
<html>
<head>
<title>ask-cli Login with Amazon</title>
<style>
body {
text-align: center;
}
.heading {
background-color: #162A38;
}
</style>
</head>
<body>
<p class="heading">
<img src="https://m.media-amazon.com/images/G/01/mobile-apps/dex/avs/docs/ux/branding/mark1._TTH_.png"/>
</p>
<p style="text-align:center; background-color: rgb(167, 234, 255); line-height: 28px;">
Sign in was successful. Close browser and return to the command line interface to continue the configure process.
</p>
</body>
</html>
`;

module.exports.ASK_SIGN_IN_FAILURE_MESSAGE = (error) => `
<html>
<head>
<title>ask-cli Login with Amazon</title>
<style>
body {
text-align: center;
}
.heading {
background-color: #162A38;
}
</style>
</head>
<body>
<p class="heading">
<img src="https://m.media-amazon.com/images/G/01/mobile-apps/dex/avs/docs/ux/branding/mark1._TTH_.png"/>
</p>
<p style="text-align:center; background-color: rgb(167, 234, 255); line-height: 28px;">
${error}
</p>
</body>
</html>
`;

module.exports.ASK_ENV_VARIABLES_ERROR_MESSAGE = 'Could not find either of the environment variables: ASK_ACCESS_TOKEN, ASK_REFRESH_TOKEN';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.20.1",
"gulp": "^3.9.1",
"husky": "^4.2.1",
"husky": "^4.2.3",
"mocha": "^3.2.0",
"nyc": "^13.3.0",
"proxyquire": "^1.7.11",
Expand Down
5 changes: 3 additions & 2 deletions test/unit/controller/authorization-controller/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,12 @@ describe('Controller test - Authorization controller test', () => {
// call
authorizationController._listenResponseFromLWA(TEST_PORT, (err) => {
// verify
const EXPECTED_ERR_MESSAGE = `Error: ${requestQuery.query.error}\nReason: ${requestQuery.query.error_description}`;
expect(spinnerTerminateStub.callCount).eq(1);
expect(serverDestroyStub.callCount).eq(1);
expect(endStub.callCount).eq(1);
expect(endStub.args[0][0]).eq(`Error: ${requestQuery.query.error}\nError description: ${requestQuery.query.error_description}`);
expect(err).eq(messages.ASK_SIGN_IN_FAILURE_MESSAGE);
expect(endStub.args[0][0].includes(EXPECTED_ERR_MESSAGE)).equal(true);
expect(err).eq(EXPECTED_ERR_MESSAGE);
done();
});
});
Expand Down

0 comments on commit 41c17a6

Please sign in to comment.