-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: route wrappers * chore: updated package name
- Loading branch information
1 parent
ae4d179
commit 1dd2175
Showing
18 changed files
with
14,423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
jobs: | ||
release: | ||
docker: | ||
- image: node:11 | ||
steps: | ||
- checkout | ||
- run: npm i -g semantic-release@15 | ||
- run: semantic-release | ||
test: | ||
docker: | ||
- image: node:11 | ||
working_directory: ~/repo | ||
steps: | ||
- checkout | ||
- run: | ||
name: Add token | ||
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v2-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v2-dependencies- | ||
|
||
- run: npm i | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v2-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: | ||
name: testing | ||
command: npm run test | ||
|
||
- run: | ||
name: Coverage | ||
command: npm run send-coverage | ||
|
||
# run lint | ||
- run: | ||
name: lint | ||
command: npm run lint | ||
workflows: | ||
version: 2 | ||
test-and-build: | ||
jobs: | ||
- test | ||
- release: | ||
requires: | ||
- test | ||
filters: | ||
branches: | ||
only: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[vcbuild.bat] | ||
end_of_line = crlf | ||
|
||
[Makefile] | ||
indent_size = 8 | ||
indent_style = tab | ||
|
||
[{deps}/**] | ||
charset = ignore | ||
end_of_line = ignore | ||
indent_size = ignore | ||
indent_style = ignore | ||
trim_trailing_whitespace = ignore | ||
|
||
[{test/fixtures,deps,tools/node_modules,tools/gyp,tools/icu,tools/msvs}/**] | ||
insert_final_newline = false | ||
|
||
[*.js] | ||
trim_trailing_whitespace = false | ||
max_line_length = 150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/coverage | ||
/.nyc_output | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
extends: '@voiceflow/eslint-config', | ||
rules: { | ||
'no-continue': 'off', | ||
'quotes': ['error', 'single', 'avoid-escape'], | ||
'sonarjs/cognitive-complexity': 'warn', | ||
'promise/always-return': 'off', | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
coverage | ||
.idea | ||
.nyc_output | ||
scratch.js | ||
/scripts | ||
/.ebextensions/ | ||
/app/ | ||
/log/ | ||
/routes/multimodal/apl_authoring_tool | ||
/database | ||
/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = { extends: ['@commitlint/config-conventional'] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
/* eslint global-require: "off" */ | ||
module.exports = require('./lib'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const VError = require('@voiceflow/verror'); | ||
|
||
const log = require('../logger'); | ||
|
||
/** | ||
* @class | ||
*/ | ||
class ExceptionHandler { | ||
/** | ||
* @param {ResponseBuilder} responseBuilder | ||
*/ | ||
constructor(responseBuilder) { | ||
if (!_.isObject(responseBuilder)) { | ||
throw new VError('responseBuilder must be an object'); | ||
} | ||
this.responseBuilder = responseBuilder; | ||
} | ||
|
||
/** | ||
* Express middleware for json body parser errors. | ||
* From here: {@link https://github.com/expressjs/body-parser/issues/122#issuecomment-328190379} | ||
* @param {Error|VError|object} err unhandled error | ||
* @param {Request} req express request | ||
* @param {Response} res express response | ||
* @param {Function} next | ||
* @return {Promise<void>} | ||
*/ | ||
async handleJsonParseError(err, req, res, next) { | ||
if (err.type && err.type === 'entity.parse.failed') { | ||
await this.responseBuilder.route(new VError('Could not parse JSON input', VError.HTTP_STATUS.BAD_REQUEST, err.body))(req, res); | ||
return null; | ||
} | ||
|
||
next(err); | ||
return null; | ||
} | ||
|
||
/** | ||
* Express middleware for catching unhandled errors and returning a 500 | ||
* @param {Error|VError|object} err unhandled error | ||
* @param {Request} req express request | ||
* @param {Response} res express response | ||
* @param {Function} next | ||
* @return {Promise<void>} | ||
*/ | ||
async handleError(err, req, res, next) { | ||
// If the error object doesn't exist | ||
if (!err) return next(); | ||
|
||
if (err.stack) { | ||
log.error(`Unhandled error: ${err.stack}`); | ||
} else { | ||
log.error(`Unhandled error without stack: ${JSON.stringify(err)}`); | ||
} | ||
|
||
await this.responseBuilder.route(new VError('Unhandled error occurred'))(req, res); | ||
return null; | ||
} | ||
|
||
/** | ||
* Express middleware for catching all unhandled requests and returning 404 | ||
* @param {Request} req express request | ||
* @param {Response} res express response | ||
* @return {Promise<void>} | ||
*/ | ||
async handleNotFound(req, res) { | ||
const url = req.originalUrl; | ||
const { method } = req; | ||
|
||
await this.responseBuilder.route(new VError(`URL: ${url} with method: ${method} is not a valid path`, VError.HTTP_STATUS.NOT_FOUND))(req, res); | ||
} | ||
} | ||
|
||
module.exports = ExceptionHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
/* eslint global-require: "off" */ | ||
module.exports = { | ||
ExceptionHandler: require('./exceptionHandler'), | ||
ResponseBuilder: require('./responseBuilder'), | ||
}; |
Oops, something went wrong.