Commit 241f4753 authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v.1.0.1

parent 0c82b8b2
{
"extends": ["google"],
"extends": [
"google"
],
"rules": {
"max-len": [2, 120, 2],
"indent": [2, "tab",{
"SwitchCase": 1
}],
"camelcase": [2, {
"properties": "never"
}],
"max-len": [
2,
120,
2
],
"indent": [
2,
"tab",
{
"SwitchCase": 1
}
],
"camelcase": [
2,
{
"properties": "never"
}
],
"require-jsdoc": 0,
"no-debugger": 1
"no-debugger": 1,
"no-invalid-this": 0
},
"env": {
"es6": true,
......
......@@ -45,7 +45,9 @@ class SDK {
this.server.context.db = mysql.createConnection(this.config.mySql);
this.server.context.logger = this.logger;
this.server.context.config = this.config;
this.server.context.throwResponseErrorIfNeed = throwResponseErrorIfNeed.bind(this.server.context);
this.server.context.throwResponseErrorIfNeed = throwResponseErrorIfNeed.bind(
this.server.context
);
Promise.promisifyAll(this.server.context.db);
}
......@@ -61,53 +63,92 @@ class SDK {
}
fetchPrivateLatestResultsByEventFeedUUID(feedEndpoint, eventFeedUUID) {
this.logger.log(__filename, 'fetch private latest result by event feed uuid', feedEndpoint, eventFeedUUID);
this.logger.log(
__filename,
'fetch private latest result by event feed uuid',
feedEndpoint,
eventFeedUUID
);
return this._fetchPrivateFeed('privateLatestResults', feedEndpoint, eventFeedUUID);
}
fetchPrivateAllPublishedElementsByEventFeedUUID(feedEndpoint, eventFeedUUID) {
this.logger.log(__filename, 'fetch private all publish elements by event feed uuid', feedEndpoint, eventFeedUUID);
this.logger.log(
__filename,
'fetch private all publish elements by event feed uuid',
feedEndpoint,
eventFeedUUID
);
return this._fetchPrivateFeed('privateAllPublishedElements', feedEndpoint, eventFeedUUID);
}
fetchPrivateAllElementsByEventFeedUUID(feedEndpoint, eventFeedUUID) {
this.logger.log(__filename, 'fetch private all elements by event feed uuid', feedEndpoint, eventFeedUUID);
this.logger.log(
__filename,
'fetch private all elements by event feed uuid',
feedEndpoint,
eventFeedUUID
);
return this._fetchPrivateFeed('privateAllElements', feedEndpoint, eventFeedUUID);
}
fetchPrivateLatestResultsByEventId(feedEndpoint, projectFeedUUID, eventId) {
this.logger.log(__filename, 'fetch private latest result by event uuid',
feedEndpoint, projectFeedUUID, eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(feedEndpoint, projectFeedUUID, eventId)
.then(eventFeedUUID => this.fetchPrivateLatestResultsByEventFeedUUID(feedEndpoint, eventFeedUUID));
this.logger.log(
__filename,
'fetch private latest result by event uuid',
feedEndpoint,
projectFeedUUID,
eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(
feedEndpoint,
projectFeedUUID,
eventId
).then((eventFeedUUID) =>
this.fetchPrivateLatestResultsByEventFeedUUID(feedEndpoint, eventFeedUUID));
}
fetchPrivateAllPublishedElementsByEventId(feedEndpoint, projectFeedUUID, eventId) {
this.logger.log(__filename, 'fetch private all publish elements by event uuid',
feedEndpoint, projectFeedUUID, eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(feedEndpoint, projectFeedUUID, eventId)
.then(eventFeedUUID => this.fetchPrivateAllPublishedElementsByEventFeedUUID(feedEndpoint, eventFeedUUID));
this.logger.log(
__filename,
'fetch private all publish elements by event uuid',
feedEndpoint,
projectFeedUUID,
eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(
feedEndpoint,
projectFeedUUID,
eventId
).then((eventFeedUUID) =>
this.fetchPrivateAllPublishedElementsByEventFeedUUID(feedEndpoint, eventFeedUUID));
}
fetchPrivateAllElementsByEventId(feedEndpoint, projectFeedUUID, eventId) {
this.logger.log(__filename, 'fetch private all elements by event uuid',
feedEndpoint, projectFeedUUID, eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(feedEndpoint, projectFeedUUID, eventId)
.then(eventFeedUUID => this.fetchPrivateAllElementsByEventFeedUUID(feedEndpoint, eventFeedUUID));
this.logger.log(
__filename,
'fetch private all elements by event uuid',
feedEndpoint,
projectFeedUUID,
eventId
);
return this._fetchPrivateListingsAndGetEventFeedUUID(
feedEndpoint,
projectFeedUUID,
eventId
).then((eventFeedUUID) =>
this.fetchPrivateAllElementsByEventFeedUUID(feedEndpoint, eventFeedUUID));
}
* _run() {
yield * connectToMySql.call(this.server.context);
yield * createTables.call(this.server.context);
yield* connectToMySql.call(this.server.context);
yield* createTables.call(this.server.context);
this._createHttp();
this._createHttps();
......@@ -116,7 +157,10 @@ class SDK {
_createHttp() {
http.createServer(this.server.callback()).listen(this.config.httpPort);
this.server.context.logger.log(__filename, `HTTP is listening on port: ${this.config.httpPort}`);
this.server.context.logger.log(
__filename,
`HTTP is listening on port: ${this.config.httpPort}`
);
}
_createHttps() {
......@@ -126,12 +170,15 @@ class SDK {
const options = {
key: fs.readFileSync(this.config.ssl.keyFileName),
cert: fs.readFileSync(this.config.ssl.certFileName)
cert: fs.readFileSync(this.config.ssl.certFileName),
};
https.createServer(options, this.server.callback()).listen(this.config.httpsPort);
this.server.context.logger.log(__filename, `HTTPS is listening on port: ${this.config.httpsPort}`);
this.server.context.logger.log(
__filename,
`HTTPS is listening on port: ${this.config.httpsPort}`
);
}
_fetchPrivateFeed(feedName, feedEndpoint, feedUUID) {
......@@ -139,16 +186,16 @@ class SDK {
this.logger.log(__filename, 'fetch private feed', url);
return fetch(url).then(res => res.json());
return fetch(url).then((res) => res.json());
}
_fetchPrivateListingsAndGetEventFeedUUID(feedEndpoint, projectFeedUUID, eventId) {
return this.fetchPrivateListings(feedEndpoint, projectFeedUUID)
.then(listings => SDK._getEventFeedUUIDFromListings(listings, eventId));
return this.fetchPrivateListings(feedEndpoint, projectFeedUUID).then((listings) =>
SDK._getEventFeedUUIDFromListings(listings, eventId));
}
static _getEventFeedUUIDFromListings(listings, eventId) {
const event = listings.events.find(event => event.id === eventId);
const event = listings.events.find((event) => event.id === eventId);
if (!event) {
throw new Error('event is no found in listings');
......
module.exports = {
INSTANCES: 'instances',
PROJECTS: 'projects'
PROJECTS: 'projects',
};
'use strict';
function * connectToMySql() {
function* connectToMySql() {
try {
yield this.db.connectAsync();
......
'use strict';
function * createTables() {
function* createTables() {
try {
yield this.db.queryAsync(`
yield this.db.queryAsync(
`
CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.INSTANCES}\` (
\`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL,
......@@ -11,9 +12,11 @@ function * createTables() {
PRIMARY KEY (\`id\`),
UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC)
)
`);
`
);
yield this.db.queryAsync(`
yield this.db.queryAsync(
`
CREATE TABLE IF NOT EXISTS \`${this.config.mySql.database}\`.\`${this.tablesNames.PROJECTS}\` (
\`id\` CHAR(36) NOT NULL,
\`name\` CHAR(255) NOT NULL,
......@@ -22,7 +25,8 @@ function * createTables() {
PRIMARY KEY (\`id\`),
UNIQUE INDEX \`id_UNIQUE\` (\`id\` ASC)
)
`);
`
);
this.logger.log(__filename, 'tables created successfully');
} catch (err) {
......
......@@ -5,11 +5,4 @@ const debug = require('debug');
const log = debug('service-sdk:log');
const error = debug('service-sdk:error');
module.exports = {
log() {
log.apply(null, arguments);
},
error() {
error.apply(null, arguments);
}
};
module.exports = {log, error};
......@@ -2,12 +2,13 @@
const urlJoin = require('url-join');
const privateFeed = name =>
(feedEndpoint, version, feedUUID) => urlJoin(feedEndpoint, 'feeds', name, version, `${feedUUID}.json`);
const privateFeed = (name) =>
(feedEndpoint, version, feedUUID) =>
urlJoin(feedEndpoint, 'feeds', name, version, `${feedUUID}.json`);
module.exports = {
privateListings: privateFeed('listings'),
privateLatestResults: privateFeed('latest_results'),
privateAllPublishedElements: privateFeed('all_published'),
privateAllElements: privateFeed('all')
privateAllElements: privateFeed('all'),
};
......@@ -16,7 +16,7 @@ function serialize(obj, prefix) {
}
}
return res.join("&");
return res.join('&');
}
module.exports = serialize;
const parse = require('co-body');
function * bodyParser(next) {
function* bodyParser(next) {
this.request.bodyRow = yield parse.text(this.request);
try {
......@@ -13,4 +13,3 @@ function * bodyParser(next) {
}
module.exports = bodyParser;
function * checkEventId(next) {
function* checkEventId(next) {
const eventId = this.checkParams('eventId').isUUID().value;
this.logger.log(__filename, 'GET', 'event id:', eventId);
......
function * checkInstanceId(next) {
function* checkInstanceId(next) {
const instanceId = this.checkParams('instanceId').isUUID().value;
this.logger.log(__filename, 'instance id:', instanceId);
......
function * checkInstanceId(next) {
function* checkInstanceId(next) {
const projectId = this.checkParams('projectId').isUUID().value;
this.logger.log(__filename, 'project id:', projectId);
......
......@@ -4,7 +4,7 @@ const sha1 = require('sha1');
const urlJoin = require('url-join');
const fetch = require('node-fetch');
function * checkSessionToken(next) {
function* checkSessionToken(next) {
const sessionToken = this.checkQuery('lvis_at').notEmpty().value;
this.logger.log(__filename, 'session token', sessionToken);
......@@ -36,7 +36,7 @@ function fetchUser(sessionToken) {
this.logger.log(__filename, 'fetch user url:', url, 'headers:', headers);
return fetch(url, {headers: headers}).then(res => res.json());
return fetch(url, {headers: headers}).then((res) => res.json());
}
module.exports = checkSessionToken;
const sha1 = require('sha1');
function * checkToken(next) {
function* checkToken(next) {
const salt = this.checkHeader('x-lvis-salt').notBlank().value;
const signature = this.checkHeader('x-lvis-signature').notBlank().value;
const querystring = this.request.querystring ? '?' + this.request.querystring : '';
......
function * checkTabId(next) {
function* checkTabId(next) {
const tabId = this.checkParams('tabId').notEmpty().value;
this.logger.log(__filename, 'GET', 'tab id:', tabId);
......
......@@ -2,7 +2,7 @@
const ResponseError = require('../lib/ResponseError');
function * errors(next) {
function* errors(next) {
try {
yield next;
} catch (err) {
......@@ -10,7 +10,7 @@ function * errors(next) {
if (err instanceof Error) {
this.body = {
message: err.message
message: err.message,
};
this.logger.error(err);
......
function * protocol(next) {
function* protocol(next) {
this.state.protocol = this.config.forceHttps ? 'https' : this.protocol;
this.logger.log(__filename, 'protocol:', this.state.protocol);
......@@ -7,4 +7,3 @@ function * protocol(next) {
}
module.exports = protocol;
{
"name": "service-sdk",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"description": "Service SDK for LViS",
"keywords": [],
......@@ -26,7 +26,7 @@
},
"scripts": {
"start": "node app.js",
"lint": "eslint ./**/*.js",
"lint": "eslint ./**/*.js ./*.js",
"copy-to-releases": "cpy constants/* ../service-sdk-releases/constants && cpy lib/* ../service-sdk-releases/lib && cpy middlewares/* ../service-sdk-releases/middlewares && cpy router/* ../service-sdk-releases/router && cpy .editorconfig .eslintignore .eslintrc .gitignore app.js package.json ../service-sdk-releases"
},
"devDependencies": {
......
'use strict';
function * get() {
this.body = yield this.config.analyticsCallback(this.state.instance, this.state.project, this.state.eventId);
function* get() {
this.body = yield this.config.analyticsCallback(
this.state.instance,
this.state.project,
this.state.eventId
);
}
module.exports = {get: get};
'use strict';
function* get() {
const getAssets = this.config.assetsCallback;
const assets = {
endpoint: this.config.wsEndpoint,
};
if (getAssets) {
const customAssets = yield getAssets(
this.state.instance,
this.state.project,
this.state.eventId
);
Object.assign({}, customAssets, assets);
}
this.body = assets;
}
module.exports = {get: get};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment