Skip to content

Commit 88dc401

Browse files
authored
Merge pull request #75 from hull/hotfix/v0.13.16
Handle entity too large and devMode
2 parents 9891bcb + 4e5fdb1 commit 88dc401

File tree

8 files changed

+134
-12
lines changed

8 files changed

+134
-12
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"plugins": ["transform-flow-comments"]
2+
"plugins": ["transform-flow-comments", "transform-object-rest-spread"]
33
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.13.16
2+
* Explicitly handle too large kraken notification payloads
3+
* Adds devMode utility
4+
* Turn on flow in index.js files
5+
16
# 0.13.15
27
* Bump hull-client version to 1.2.2
38
* Adds support for Account anonymous_id claim

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hull",
3-
"version": "0.13.15",
3+
"version": "0.13.16",
44
"description": "A Node.js client for hull.io",
55
"main": "lib",
66
"repository": {
@@ -35,6 +35,7 @@
3535
"dependencies": {
3636
"JSONStream": "^1.1.2",
3737
"aws-sdk": "^2.81.0",
38+
"babel-polyfill": "^6.26.0",
3839
"basic-auth": "^1.1.0",
3940
"batch-stream": "^0.1.3",
4041
"bluebird": "^3.4.7",
@@ -54,26 +55,32 @@
5455
"kue": "^0.11.5",
5556
"kue-ui": "^0.1.0",
5657
"lodash": "^4.17.5",
57-
"newrelic": "^2.4.1",
58+
"newrelic": "^4.1.4",
5859
"passport": "^0.3.2",
60+
"progress-bar-webpack-plugin": "^1.11.0",
5961
"promise-streams": "^1.0.1",
6062
"raven": "^2.4.2",
6163
"raw-body": "^2.1.7",
64+
"react-hot-loader": "^4.2.0",
6265
"request": "^2.72.0",
6366
"sns-validator": "^0.3.0",
6467
"sqs-consumer": "^3.6.1",
6568
"supply": "0.0.4",
66-
"urijs": "^1.18.7"
69+
"urijs": "^1.18.7",
70+
"webpack": "^3.12.0",
71+
"webpack-dev-middleware": "^2.0.6",
72+
"webpack-hot-middleware": "^2.22.2"
6773
},
6874
"peerDependencies": {
69-
"express": "^4.16.2",
70-
"newrelic": "^2.4.1"
75+
"express": "^4.16.3",
76+
"newrelic": "^4.1.4"
7177
},
7278
"devDependencies": {
7379
"babel": "^6.5.2",
7480
"babel-cli": "^6.24.1",
7581
"babel-eslint": "^7.1.1",
7682
"babel-plugin-transform-flow-comments": "^6.22.0",
83+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
7784
"babel-register": "^6.9.0",
7885
"chai": "^3.5.0",
7986
"chai-http": "^3.0.0",
@@ -90,12 +97,13 @@
9097
"mkdirp": "^0.5.1",
9198
"mocha": "^3.0.0",
9299
"nock": "^9.2.3",
93-
"node-mocks-http": "^1.6.1",
100+
"node-mocks-http": "^1.7.0",
94101
"nyc": "^11.0.3",
95102
"rimraf": "^2.6.0",
96103
"sinon": "^2.2.0",
97104
"sinon-chai": "^2.10.0",
98105
"superagent": "^3.8.2",
106+
"supertest": "^3.1.0",
99107
"updtr": "^1.0.0"
100108
},
101109
"nodeBoilerplateOptions": {

src/errors/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
/* eslint-disable global-require */
23

34
/**

src/utils/dev-mode.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @flow
2+
import type { $Application } from "express";
3+
4+
const _ = require("lodash");
5+
const webpack = require("webpack");
6+
const webpackDevMiddleware = require("webpack-dev-middleware");
7+
const webpackHotMiddleware = require("webpack-hot-middleware");
8+
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
9+
10+
function devMode(app: $Application, config: Object) {
11+
const entry = _.reduce(
12+
config.entry,
13+
(m: Object, v, k: string) => {
14+
m[k] = [
15+
require.resolve("babel-polyfill"),
16+
require.resolve("react-hot-loader/patch"),
17+
require.resolve("webpack-hot-middleware/client"),
18+
v
19+
];
20+
return m;
21+
},
22+
{}
23+
);
24+
25+
const plugins = [
26+
new webpack.HotModuleReplacementPlugin(),
27+
...config.plugins,
28+
new webpack.NamedModulesPlugin(),
29+
new ProgressBarPlugin({ clear: false }),
30+
new webpack.NoEmitOnErrorsPlugin()
31+
];
32+
33+
const compiler = webpack({ ...config, entry, plugins });
34+
35+
app.use(
36+
webpackDevMiddleware(compiler, {
37+
hot: true,
38+
quiet: false,
39+
overlay: false,
40+
noInfo: false,
41+
lazy: false,
42+
clientLogLevel: "none",
43+
watchContentBase: true,
44+
stats: { colors: true },
45+
watchOptions: {
46+
ignored: /node_modules/
47+
},
48+
historyApiFallback: {
49+
disableDotRule: true
50+
},
51+
52+
headers: { "Access-Control-Allow-Origin": "http://localhost" },
53+
publicPath: config.output.publicPath
54+
})
55+
);
56+
app.use(webpackHotMiddleware(compiler));
57+
}
58+
59+
module.exports = devMode;

src/utils/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
/**
23
* General utilities
34
* @namespace Utils
@@ -24,5 +25,7 @@ module.exports.SmartNotifierResponse = require("./smart-notifier-response");
2425
module.exports.PromiseReuser = require("./promise-reuser");
2526

2627
module.exports.superagentUrlTemplatePlugin = require("./superagent-url-template-plugin");
27-
module.exports.superagentInstrumentationPlugin = require("././superagent-intrumentation-plugin.js");
28-
module.exports.superagentErrorPlugin = require("././superagent-error-plugin.js");
28+
module.exports.superagentInstrumentationPlugin = require("./superagent-intrumentation-plugin.js");
29+
module.exports.superagentErrorPlugin = require("./superagent-error-plugin.js");
30+
31+
module.exports.devMode = require("./dev-mode");

src/utils/smart-notifier-middleware.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ module.exports = function smartNotifierMiddlewareFactory({ skipSignatureValidati
3737
}
3838
}
3939

40-
return bodyParser.json({ limit: "10mb" })(req, res, () => {
40+
return bodyParser.json({ limit: "10mb" })(req, res, (err) => {
41+
if (err !== undefined && err.type === "entity.too.large") {
42+
Client.logger.error("connector.smartNotifierHandler.error", { error: err.toString() });
43+
return next(new SmartNotifierError("ENTITY_TOO_LARGE", "Payload size bigger than 10mb", err.statusCode, {
44+
type: "retry",
45+
size: 1
46+
}));
47+
}
48+
4149
Client.logger.debug("connector.smartNotifierHandler", _.pick(req.body, "channel", "notification_id"));
4250

4351
if (!smartNotifierValidator.validatePayload()) {
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global describe, it */
2-
const { expect, should } = require("chai");
3-
const sinon = require("sinon");
2+
const { expect } = require("chai");
3+
const http = require("http");
4+
const request = require("supertest");
45

56
const smartNotifierMiddleware = require("../../../src/utils/smart-notifier-middleware");
67

@@ -10,4 +11,41 @@ describe("SmartNotifierMiddleware", () => {
1011
const testInstance = new smartNotifierMiddleware({});
1112
expect(typeof testInstance).to.equal("function");
1213
});
14+
15+
it("should handle notifications exceeding the json size limit", (done) => {
16+
const testInstance = new smartNotifierMiddleware({ skipSignatureValidation: true });
17+
const server = http.createServer((req) => {
18+
testInstance(req, {}, (err) => {
19+
expect(err.code).to.equal("ENTITY_TOO_LARGE");
20+
expect(err.statusCode).to.equal(413);
21+
expect(err.flowControl).to.eql({
22+
type: "retry",
23+
size: 1
24+
});
25+
done();
26+
});
27+
});
28+
request(server)
29+
.post("/")
30+
.set("Content-Type", "application/json")
31+
.set({
32+
"content-type": "application/json",
33+
"x-hull-smart-notifier": "yes",
34+
"x-hull-smart-notifier-signature": "singature",
35+
"x-hull-smart-notifier-signature-version": "v1",
36+
"x-hull-smart-notifier-signature-public-key-url": "url"
37+
})
38+
.send({
39+
configuration: {
40+
id: "12312312312"
41+
},
42+
connector: {},
43+
messages: [{
44+
user: {
45+
super_long_trait: String(".").repeat(10485760) // 10mb string
46+
}
47+
}]
48+
})
49+
.end(() => {});
50+
});
1351
});

0 commit comments

Comments
 (0)