Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
publics
service-sdk-releases
Commits
241f4753
Commit
241f4753
authored
May 10, 2017
by
Evgeniy Zaitsev
Browse files
v.1.0.1
parent
0c82b8b2
Changes
25
Show whitespace changes
Inline
Side-by-side
.eslintrc
View file @
241f4753
{
"extends": ["google"],
"extends": [
"google"
],
"rules": {
"max-len": [2, 120, 2],
"indent": [2, "tab",{
"max-len": [
2,
120,
2
],
"indent": [
2,
"tab",
{
"SwitchCase": 1
}],
"camelcase": [2, {
}
],
"camelcase": [
2,
{
"properties": "never"
}],
}
],
"require-jsdoc": 0,
"no-debugger": 1
"no-debugger": 1,
"no-invalid-this": 0
},
"env": {
"es6": true,
...
...
app.js
View file @
241f4753
...
...
@@ -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
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
));
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
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
));
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
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
));
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
'
);
...
...
constants/tablesNames.js
View file @
241f4753
module
.
exports
=
{
INSTANCES
:
'
instances
'
,
PROJECTS
:
'
projects
'
PROJECTS
:
'
projects
'
,
};
lib/connectToMySql.js
View file @
241f4753
'
use strict
'
;
function
*
connectToMySql
()
{
function
*
connectToMySql
()
{
try
{
yield
this
.
db
.
connectAsync
();
...
...
lib/createTables.js
View file @
241f4753
'
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
)
{
...
...
lib/logger.js
View file @
241f4753
...
...
@@ -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
};
lib/lvisEndpoints.js
View file @
241f4753
...
...
@@ -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
'
)
,
};
lib/serialize.js
View file @
241f4753
...
...
@@ -16,7 +16,7 @@ function serialize(obj, prefix) {
}
}
return
res
.
join
(
"
&
"
);
return
res
.
join
(
'
&
'
);
}
module
.
exports
=
serialize
;
middlewares/bodyParser.js
View file @
241f4753
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
;
middlewares/checkEventId.js
View file @
241f4753
function
*
checkEventId
(
next
)
{
function
*
checkEventId
(
next
)
{
const
eventId
=
this
.
checkParams
(
'
eventId
'
).
isUUID
().
value
;
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
event id:
'
,
eventId
);
...
...
middlewares/checkInstanceId.js
View file @
241f4753
function
*
checkInstanceId
(
next
)
{
function
*
checkInstanceId
(
next
)
{
const
instanceId
=
this
.
checkParams
(
'
instanceId
'
).
isUUID
().
value
;
this
.
logger
.
log
(
__filename
,
'
instance id:
'
,
instanceId
);
...
...
middlewares/checkProjectId.js
View file @
241f4753
function
*
checkInstanceId
(
next
)
{
function
*
checkInstanceId
(
next
)
{
const
projectId
=
this
.
checkParams
(
'
projectId
'
).
isUUID
().
value
;
this
.
logger
.
log
(
__filename
,
'
project id:
'
,
projectId
);
...
...
middlewares/checkSessionToken.js
View file @
241f4753
...
...
@@ -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
;
middlewares/checkSignature.js
View file @
241f4753
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
:
''
;
...
...
middlewares/checkTabId.js
View file @
241f4753
function
*
checkTabId
(
next
)
{
function
*
checkTabId
(
next
)
{
const
tabId
=
this
.
checkParams
(
'
tabId
'
).
notEmpty
().
value
;
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
tab id:
'
,
tabId
);
...
...
middlewares/errors.js
View file @
241f4753
...
...
@@ -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
);
...
...
middlewares/protocol.js
View file @
241f4753
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
;
package.json
View file @
241f4753
{
"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"
:
{
...
...
router/analytics.js
View file @
241f4753
'
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
};
router/assets.js
0 → 100644
View file @
241f4753
'
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
};
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment