Skip to content

Commit d101494

Browse files
authored
Merge pull request #70 from Luidog/session-handling
Session handling
2 parents eaa8b92 + 996f78c commit d101494

File tree

10 files changed

+382
-229
lines changed

10 files changed

+382
-229
lines changed

.prettierrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
22
singleQuote: true,
3-
tabWidth: 2
3+
tabWidth: 2,
4+
arrowParens: 'avoid',
5+
trailingComma: 'none'
46
};

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- node
4+
services: mongodb
45
install:
56
- npm install
67
- npm install marpat

package-lock.json

Lines changed: 289 additions & 205 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A FileMaker Data API client designed to allow easier interaction with a FileMaker database from a web environment.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "snyk test && nyc _mocha --recursive ./test --timeout=15000 --exit",
7+
"test": "nyc _mocha --recursive ./test/*.test.js --timeout=15000 --exit",
88
"coverage": "nyc report --reporter=text-lcov | coveralls",
99
"report": "nyc report --reporter=html",
1010
"examples": "node examples/index.js",
@@ -47,31 +47,31 @@
4747
"marpat": "^3.0.2",
4848
"mime-types": "^2.1.26",
4949
"moment": "^2.24.0",
50-
"object-sizeof": "^1.5.2",
50+
"object-sizeof": "^1.5.3",
5151
"prettysize": "^2.0.0",
52-
"snyk": "^1.290.2",
52+
"snyk": "^1.303.0",
5353
"stream-to-array": "^2.3.0",
54-
"tough-cookie": "^3.0.1",
55-
"uuid": "^3.4.0"
54+
"tough-cookie": "^4.0.0",
55+
"uuid": "^7.0.2"
5656
},
5757
"devDependencies": {
5858
"chai": "^4.2.0",
5959
"chai-as-promised": "^7.1.1",
60-
"coveralls": "^3.0.9",
60+
"coveralls": "^3.0.11",
6161
"deep-map": "^2.0.0",
6262
"dotenv": "^8.2.0",
6363
"es6-weak-map": "^2.0.3",
6464
"eslint": "^6.8.0",
6565
"eslint-config-google": "^0.14.0",
66-
"eslint-config-prettier": "^6.10.0",
66+
"eslint-config-prettier": "^6.10.1",
6767
"eslint-plugin-prettier": "^3.1.2",
68-
"fs-extra": "^8.1.0",
68+
"fs-extra": "^9.0.0",
6969
"handlebars": "^4.7.3",
7070
"http-proxy": "^1.18.0",
7171
"jsdoc": "^3.6.3",
7272
"jsdoc-to-markdown": "^5.0.3",
7373
"minami": "^1.2.3",
74-
"mocha": "^7.0.1",
74+
"mocha": "^7.1.1",
7575
"mocha-lcov-reporter": "^1.3.0",
7676
"mos": "^1.3.1",
7777
"mos-plugin-dependencies": "^2.2.2",
@@ -80,9 +80,9 @@
8080
"mos-plugin-license": "^1.2.2",
8181
"mos-plugin-snippet": "^2.1.3",
8282
"nyc": "^15.0.0",
83-
"prettier": "^1.19.1",
84-
"sinon": "^8.1.1",
83+
"prettier": "^2.0.1",
84+
"sinon": "^9.0.1",
8585
"varium": "^2.0.6"
8686
},
8787
"snyk": true
88-
}
88+
}

src/models/agent.model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const https = require('https');
44
const http = require('http');
5-
const uuidv4 = require('uuid/v4');
5+
const { v4: uuidv4 } = require('uuid');
66
const { EmbeddedDocument } = require('marpat');
77
const _ = require('lodash');
88
const { deepMapKeys } = require('../utilities');

src/models/client.model.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class Client extends Document {
137137
return new Promise((resolve, reject) =>
138138
this.agent.connection
139139
.start(!_.isEmpty(this.agent.agent) ? this.agent.localize() : false)
140-
.then(response => resolve(response))
140+
.then(body => this.data.outgoing(body))
141+
.then(body => this._save(resolve(body)))
141142
.catch(error => this._save(reject(error)))
142143
);
143144
}

src/models/session.model.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const moment = require('moment');
44
const { EmbeddedDocument } = require('marpat');
5-
const uuidv4 = require('uuid/v4');
5+
const { v4: uuidv4 } = require('uuid');
66
/**
77
* @class Session
88
* @classdesc The class used to save FileMaker Data API Session information
@@ -34,10 +34,7 @@ class Session extends EmbeddedDocument {
3434
*/
3535
expires: {
3636
type: String,
37-
default: () =>
38-
moment()
39-
.add(15, 'minutes')
40-
.format()
37+
default: () => moment().add(15, 'minutes').format()
4138
},
4239
/* A string containing the last time the token was used.
4340
* @member Session#used
@@ -103,9 +100,7 @@ class Session extends EmbeddedDocument {
103100
*/
104101
extend() {
105102
this.active = false;
106-
this.expires = moment()
107-
.add(15, 'minutes')
108-
.format();
103+
this.expires = moment().add(15, 'minutes').format();
109104
}
110105
}
111106

src/services/container.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require('path');
77
const toArray = require('stream-to-array');
88
const { CookieJar } = require('tough-cookie');
99
const mime = require('mime-types');
10-
const uuidv4 = require('uuid/v4');
10+
const { v4: uuidv4 } = require('uuid');
1111
const _ = require('lodash');
1212
const { interceptResponse } = require('./request.service')
1313

test/admin/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const axios = require('axios');
2+
const path = require('path');
3+
const environment = require('dotenv');
4+
const varium = require('varium');
5+
const manifestPath = path.join(__dirname, '../env.manifest');
6+
7+
environment.config({ path: './test/.env' });
8+
varium({ manifestPath });
9+
10+
const instance = axios.create({
11+
baseURL: process.env.SERVER
12+
});
13+
14+
let adminToken = false;
15+
16+
const login = () =>
17+
instance
18+
.post(
19+
'/fmi/admin/api/v2/user/auth',
20+
{},
21+
{
22+
auth: {
23+
username: process.env.ADMIN_USER,
24+
password: process.env.ADMIN_PASSWORD
25+
}
26+
}
27+
)
28+
.then(response => {
29+
adminToken = response.data.response.token;
30+
return response.data.response.token;
31+
});
32+
33+
const logout = (token = adminToken) => instance
34+
.delete(`/fmi/admin/api/v2/user/auth/${token}`, {})
35+
36+
const remove = ({ id }, token = adminToken) =>
37+
instance
38+
.delete(`/fmi/admin/api/v2/clients/${id}`, {
39+
params: {
40+
graceTime: 0
41+
},
42+
headers: { Authorization: `Bearer ${token}` }
43+
})
44+
.then(response => response.data)
45+
.catch(error => console.log(error.response.data));
46+
47+
const drop = account =>
48+
find(account).then(sessions => {
49+
const removals = [];
50+
sessions.forEach(session => removals.push(remove(session)));
51+
return Promise.all(removals);
52+
});
53+
54+
const find = ({ userName }, token = adminToken) =>
55+
instance
56+
.get('/fmi/admin/api/v2/clients', {
57+
headers: { Authorization: `Bearer ${token}` }
58+
})
59+
.then(response =>
60+
response.data.response.clients.filter(
61+
client => client.userName === userName
62+
)
63+
);
64+
65+
module.exports = { admin: { login, logout, sessions: { find, drop } } };

test/env.manifest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ PASSWORD : String
77
LAYOUT : String
88
CONTAINER_LAYOUT : String
99

10+
# FileMaker Server Configuration
11+
12+
ADMIN_USER: String
13+
ADMIN_PASSWORD: String
14+
1015
# Client Configuration
1116

1217
CLIENT_NAME: String | star-wars-fan

0 commit comments

Comments
 (0)