Skip to content

Commit d1169d8

Browse files
authored
Merge pull request #1 from 6RiverSystems/add_headers
Add headers to change stream
2 parents edd81d3 + b26d3ed commit d1169d8

18 files changed

+6886
-273
lines changed

.eslintrc

Lines changed: 0 additions & 21 deletions
This file was deleted.

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "6river/typescript"
3+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ npm-debug.log*
77
pids
88
*.pid
99
*.seed
10-
10+
dist
1111
# Directory for instrumented libs generated by jscoverage/JSCover
1212
lib-cov
1313

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Add the following configuration to component-config.json:
3434
"Foo",
3535
"Bar",
3636
"Baz"
37+
],
38+
"headers": [
39+
"x-auth-request-user"
3740
]
3841
},
3942
...
@@ -47,6 +50,7 @@ The configuration parameters:
4750
* reconnectTimeout - instruct Browser to reconnect after this timeout if connection is lost;
4851
* responseTimeout - the response socket will be closed after this timeout;
4952
* models - array of model names to observe.
53+
* headers - headers and values to embed in the stream metadata.
5054

5155
The component configuration above adds 3 middleware rules:
5256
* GET "/api/updates" to connect some SourceEvent listener;
@@ -61,4 +65,3 @@ The following snippet can be used on client side to connect:
6165
...
6266
});
6367
```
64-

circle.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ dependencies:
77
- node_modules
88
override:
99
- npm prune && npm install
10+
pre:
11+
- git clone --depth 1 git@github.com:6RiverSystems/infrastructure.git ~/infrastructure
12+
13+
test:
14+
post:
15+
- ~/infrastructure/ci_scripts/release.sh
16+
17+
deployment:
18+
npm-publish:
19+
branch: [master]
20+
commands:
21+
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
22+
- npm publish

dist/component.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

dist/middleware.js

Lines changed: 0 additions & 130 deletions
This file was deleted.

e2e/component-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"models": [
66
"Foo",
77
"Bar"
8+
],
9+
"headers": [
10+
"x-auth-request-user"
811
]
912
}
1013
}

e2e/component.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ describe('loopback-component-changestreamer', () => {
4242
.expect(200, done);
4343
});
4444

45+
it('set user headers', (done) => {
46+
const fooID = uuid.v4();
47+
let foo = {id: fooID, foo: 'habba'};
48+
http.get(changesUrl, (res) => {
49+
res.pipe(outStream);
50+
});
51+
request(app).post('/api/Foos')
52+
.set('X-Auth-Request-User','test@gmail.com')
53+
.send(foo)
54+
.expect(200)
55+
.then(response => {
56+
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","meta":{"headers":{"x-auth-request-user":"test@gmail.com"}},"data":{"id":"${fooID}","foo":"habba"}}\n\n`);
57+
done();
58+
});
59+
});
60+
4561
it('should write retry timout as first parameter', (done) => {
4662
http.get(changesUrl, (res) => {
4763
res.pipe(outStream);
@@ -55,7 +71,7 @@ describe('loopback-component-changestreamer', () => {
5571
});
5672

5773
context('on model create', () => {
58-
it('should write change event with kind kreate', (done) => {
74+
it('should write change event with kind create', (done) => {
5975
const fooID = uuid.v4();
6076
const barID = uuid.v4();
6177
http.get(changesUrl, (res) => {
@@ -68,8 +84,8 @@ describe('loopback-component-changestreamer', () => {
6884
});
6985
setTimeout(() => {
7086
messages.length.should.be.equal(3);
71-
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","data":{"id":"${fooID}","foo":"habba"}}\n\n`);
72-
messages[2].should.equal(`data: {"seqNo":1,"modelName":"Bar","kind":"create","target":"${barID}","data":{"id":"${barID}","bar":"bahha"}}\n\n`);
87+
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","meta":{"headers":[]},"data":{"id":"${fooID}","foo":"habba"}}\n\n`);
88+
messages[2].should.equal(`data: {"seqNo":1,"modelName":"Bar","kind":"create","target":"${barID}","meta":{"headers":[]},"data":{"id":"${barID}","bar":"bahha"}}\n\n`);
7389
done();
7490
}, 2000);
7591
});
@@ -114,7 +130,7 @@ describe('loopback-component-changestreamer', () => {
114130
});
115131
setTimeout(() => {
116132
messages.length.should.be.equal(2);
117-
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Foo","kind":"update","target":"${fooID}","data":{"id":"${fooID}","foo":"baz"}}\n\n`);
133+
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Foo","kind":"update","target":"${fooID}","meta":{"headers":[]},"data":{"id":"${fooID}","foo":"baz"}}\n\n`);
118134
done();
119135
}, 2000);
120136
});
@@ -128,7 +144,7 @@ describe('loopback-component-changestreamer', () => {
128144
});
129145
setTimeout(() => {
130146
messages.length.should.be.equal(2);
131-
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Bar","kind":"remove","target":"${barID}","where":{"id":"${barID}"},"data":{"id":"${barID}","bar":"bar"}}\n\n`);
147+
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Bar","kind":"remove","target":"${barID}","where":{"id":"${barID}"},"meta":{"headers":[]},"data":{"id":"${barID}","bar":"bar"}}\n\n`);
132148
done();
133149
}, 2000);
134150
});

e2e/config.json

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
{
2-
"restApiRoot": "/api",
3-
"host": "0.0.0.0",
4-
"port": 3333,
5-
"remoting": {
6-
"context": {
7-
"enableHttpContext": false
8-
},
9-
"rest": {
10-
"normalizeHttpPath": false,
11-
"xml": false
12-
},
13-
"json": {
14-
"strict": false,
15-
"limit": "100kb"
16-
},
17-
"urlencoded": {
18-
"extended": true,
19-
"limit": "100kb"
20-
},
21-
"cors": false,
22-
"errorHandler": {
23-
"disableStackTrace": false
24-
}
25-
},
26-
"legacyExplorer": false
2+
"restApiRoot": "/api",
3+
"host": "0.0.0.0",
4+
"port": 3333,
5+
"remoting": {
6+
"context": false,
7+
"rest": {
8+
"normalizeHttpPath": false,
9+
"xml": false
10+
},
11+
"json": {
12+
"strict": false,
13+
"limit": "100kb"
14+
},
15+
"urlencoded": {
16+
"extended": true,
17+
"limit": "100kb"
18+
},
19+
"cors": false,
20+
"errorHandler": {
21+
"disableStackTrace": false
22+
}
23+
},
24+
"legacyExplorer": false
2725
}
28-

0 commit comments

Comments
 (0)