Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #50 from trustpilot/npm-vulnerabilities
Browse files Browse the repository at this point in the history
Npm vulnerabilities
  • Loading branch information
miklosaubert authored Jan 21, 2019
2 parents e53d709 + 2f6e145 commit d860070
Show file tree
Hide file tree
Showing 9 changed files with 4,267 additions and 4,217 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM mhart/alpine-node:8

WORKDIR /app

COPY package.json yarn.lock /app/
COPY package.json package-lock.json /app/

RUN yarn install --production
RUN npm ci --only=production

# Multi-stage build! We copy the modules over to this slimmer base image and install the app on top.
FROM mhart/alpine-node:base-8
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ You should now be able to authorize your app by visiting the login endpoint at `

If you don't want to deploy this app just yet, this repo comes with everything you need to run the code locally.

After running the obligatory `yarn install`, start the app with:
After running the obligatory `npm install`, start the app with:

```
yarn run local
npm run local
```

Wait for the localtunnel.me URL to appear in the log messages. This will allow Slack to bridge with your locally running app:
Expand Down
4 changes: 2 additions & 2 deletions app/trustpilot-api.js → app/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(client) {
return requestWrapper(options);
}

class ApiBridge {
class ApiClient {
async getLastUnansweredReview({ stars, businessUnitId }) {
const data = await privateRequest({
method: 'GET',
Expand All @@ -29,5 +29,5 @@ module.exports = function(client) {
}
}

return new ApiBridge();
return new ApiClient();
};
10 changes: 5 additions & 5 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Entry point of this app, sets us up and running from config and env variables
*/

const TrustpilotApi = require('./trustpilot-api');
const ApiClient = require('./api-client');
const StorageEngine = require('./storage-engine');
const SlackApp = require('./slackapp');

Expand All @@ -14,9 +14,9 @@ const run = (config, trustpilotClient, webserverExtensions) => {
process.exit(-1);
}

const trustpilotApi = TrustpilotApi(trustpilotClient);
const apiClient = ApiClient(trustpilotClient);
const storageEngine = StorageEngine(config.BOTKIT_STORAGE_TYPE);
const slackapp = SlackApp(config, trustpilotApi, storageEngine);
const slackapp = SlackApp(config, apiClient, storageEngine);

// Set up a web server to expose oauth and webhook endpoints
slackapp.setupWebserver(config.PORT, () => {
Expand All @@ -40,8 +40,8 @@ if (require.main !== module) {
console.error('Unhandled Rejection at:', p, 'reason:', reason);
});

const trustpilotClient = new Trustpilot({
apiKey: config.API_KEY,
const trustpilotClient = new Trustpilot.TrustpilotApi({
key: config.API_KEY,
secret: config.API_SECRET,
username: config.BUSINESS_USER_NAME,
password: config.BUSINESS_USER_PASS,
Expand Down
10 changes: 5 additions & 5 deletions app/slackapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { composeReviewMessage } = require('./lib/review-message');
const reviewReply = require('./review-reply');
const feedSettings = require('./feed-settings');

const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
const setupAppHandlers = (slackapp, apiClient, enableReviewQueries) => {
const slashCommandType = (text) => {
if (/^[1-5] stars?$/i.test(text) || /^la(te)?st$/i.test(text)) {
return 'review_query';
Expand All @@ -24,7 +24,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
const businessUnitId = team.businessUnitId;
const { canReply } = feedSettings.getChannelFeedSettingsOrDefault(team, sourceMessage.channel);

const lastReview = await trustpilotApi.getLastUnansweredReview({
const lastReview = await apiClient.getLastUnansweredReview({
stars,
businessUnitId,
});
Expand Down Expand Up @@ -130,7 +130,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
bot.dialogOk();
const { dialogType } = JSON.parse(message.callback_id);
const dialogHandlers = {
['review_reply']: reviewReply.handleReply(trustpilotApi),
['review_reply']: reviewReply.handleReply(apiClient),
['feed_settings']: feedSettings.handleDialogSubmission(slackapp),
};
await dialogHandlers[dialogType](bot, message);
Expand Down Expand Up @@ -174,7 +174,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
});
};

module.exports = (config, trustpilotApi, storage) => {
module.exports = (config, apiClient, storage) => {
// Fallback to jfs when no storage middleware provided
const slackapp = botkit.slackbot({
debug: false,
Expand All @@ -187,6 +187,6 @@ module.exports = (config, trustpilotApi, storage) => {
rtm_receive_messages: false, // eslint-disable-line camelcase
scopes: ['bot', 'incoming-webhook', 'commands'],
});
setupAppHandlers(slackapp, trustpilotApi, config.ENABLE_REVIEW_QUERIES);
setupAppHandlers(slackapp, apiClient, config.ENABLE_REVIEW_QUERIES);
return slackapp;
};
4 changes: 2 additions & 2 deletions app/slackapp/review-reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const confirmReply = async (bot, message, originalTs) => {
}
};

const handleReply = (trustpilotApi) => async (bot, message) => {
const handleReply = (apiClient) => async (bot, message) => {
const { originalTs, reviewId } = JSON.parse(message.callback_id);
try {
await trustpilotApi.replyToReview({
await apiClient.replyToReview({
reviewId,
message: message.submission.reply,
});
Expand Down
Loading

0 comments on commit d860070

Please sign in to comment.