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
6066db22
Commit
6066db22
authored
Oct 17, 2016
by
Evgeniy Zaitsev
Browse files
v0.0.9
parent
4a0e9952
Changes
9
Hide whitespace changes
Inline
Side-by-side
middlewares/checkEventId.js
0 → 100644
View file @
6066db22
function
*
checkEventId
(
next
)
{
const
eventId
=
this
.
checkParams
(
'
eventId
'
).
isUUID
().
value
;
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
event id:
'
,
eventId
);
this
.
throwResponseErrorIfNeed
(
this
.
errors
);
this
.
state
.
eventId
=
eventId
;
yield
next
;
}
module
.
exports
=
checkEventId
;
middlewares/checkSessionToken.js
0 → 100644
View file @
6066db22
function
*
checkSessionToken
(
next
)
{
const
sessionToken
=
this
.
checkQuery
(
'
lvis_at
'
).
notEmpty
().
value
;
this
.
logger
.
log
(
__filename
,
'
session token
'
,
sessionToken
);
this
.
throwResponseErrorIfNeed
(
this
.
errors
);
this
.
state
.
sessionToken
=
sessionToken
;
yield
next
;
}
module
.
exports
=
checkSessionToken
;
middlewares/checkSignature.js
0 → 100644
View file @
6066db22
const
sha1
=
require
(
'
sha1
'
);
const
serialize
=
require
(
'
../lib/serialize
'
);
function
*
checkToken
(
next
)
{
const
salt
=
this
.
checkHeader
(
'
x-lvis-salt
'
).
notBlank
().
value
;
const
signature
=
this
.
checkHeader
(
'
x-lvis-signature
'
).
notBlank
().
value
;
this
.
logger
.
log
(
__filename
,
'
headers:
'
,
JSON
.
stringify
({
salt
,
signature
}));
this
.
throwResponseErrorIfNeed
(
this
.
errors
);
const
reqBody
=
serialize
(
this
.
request
.
body
);
const
querystring
=
this
.
request
.
querystring
?
'
?
'
+
this
.
request
.
querystring
:
''
;
this
.
logger
.
log
(
__filename
,
'
\n
'
,
this
.
request
.
path
,
'
\n
'
,
this
.
request
.
querystring
,
'
\n
'
,
reqBody
);
const
signeableContent
=
this
.
request
.
path
+
querystring
+
reqBody
;
const
privateSignature
=
sha1
(
this
.
config
.
accessToken
+
signeableContent
+
salt
);
this
.
logger
.
log
(
__filename
,
'
private signature:
'
,
privateSignature
);
this
.
throwResponseErrorIfNeed
(
privateSignature
!==
signature
,
'
Invalid access token
'
);
yield
next
;
}
module
.
exports
=
checkToken
;
middlewares/checkTabId.js
0 → 100644
View file @
6066db22
function
*
checkTabId
(
next
)
{
const
tabId
=
this
.
checkParams
(
'
tabId
'
).
notEmpty
().
value
;
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
tab id:
'
,
tabId
);
this
.
throwResponseErrorIfNeed
(
this
.
errors
);
this
.
state
.
tabId
=
tabId
;
yield
next
;
}
module
.
exports
=
checkTabId
;
package.json
View file @
6066db22
{
"name"
:
"service-sdk"
,
"version"
:
"0.0.
8
"
,
"version"
:
"0.0.
9
"
,
"private"
:
true
,
"description"
:
"Service SDK for LViS"
,
"keywords"
:
[],
...
...
router/analytics.js
View file @
6066db22
'
use strict
'
;
function
*
get
()
{
const
eventId
=
this
.
checkParams
(
'
eventId
'
).
isUUID
().
value
;
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
event id:
'
,
eventId
);
this
.
throwResponseErrorIfNeed
(
this
.
errors
);
this
.
body
=
yield
this
.
config
.
analyticsCallback
(
this
.
state
.
instance
,
this
.
state
.
project
,
eventId
);
this
.
body
=
yield
this
.
config
.
analyticsCallback
(
this
.
state
.
instance
,
this
.
state
.
project
,
this
.
state
.
eventId
);
}
module
.
exports
=
{
get
:
get
};
router/index.js
View file @
6066db22
const
router
=
require
(
'
koa-router
'
)();
const
checkToken
=
require
(
'
../middlewares/checkToken
'
);
const
check
Session
Token
=
require
(
'
../middlewares/check
Session
Token
'
);
const
checkInstanceId
=
require
(
'
../middlewares/checkInstanceId
'
);
const
checkSignature
=
require
(
'
../middlewares/checkSignature
'
);
const
checkProjectId
=
require
(
'
../middlewares/checkProjectId
'
);
const
checkEventId
=
require
(
'
../middlewares/checkEventId
'
);
const
checkTabId
=
require
(
'
../middlewares/checkTabId
'
);
const
lvis
=
require
(
'
./lvis
'
);
const
project
=
require
(
'
./project
'
);
const
analytics
=
require
(
'
./analytics
'
);
const
tabs
=
require
(
'
./tabs
'
);
const
tab
=
require
(
'
./tab
'
);
router
.
post
(
'
/lvis
'
,
check
Token
,
lvis
.
post
)
.
post
(
'
/lvis
'
,
check
Signature
,
lvis
.
post
)
.
post
(
'
/lvis/:instanceId/project
'
,
check
Token
,
checkInstanceId
,
project
.
post
)
.
put
(
'
/lvis/:instanceId/project/:projectId
'
,
check
Token
,
checkInstanceId
,
checkProjectId
,
project
.
put
)
.
del
(
'
/lvis/:instanceId/project/:projectId
'
,
check
Token
,
checkInstanceId
,
checkProjectId
,
project
.
del
)
.
post
(
'
/lvis/:instanceId/project
'
,
check
Signature
,
checkInstanceId
,
project
.
post
)
.
put
(
'
/lvis/:instanceId/project/:projectId
'
,
check
Signature
,
checkInstanceId
,
checkProjectId
,
project
.
put
)
.
del
(
'
/lvis/:instanceId/project/:projectId
'
,
check
Signature
,
checkInstanceId
,
checkProjectId
,
project
.
del
)
.
get
(
'
/lvis/:instanceId/project/:projectId/events/:eventId/analytics_tab
'
,
check
Token
,
checkInstanceId
,
checkProjectId
,
analytics
.
get
check
Signature
,
checkInstanceId
,
checkProjectId
,
checkEventId
,
analytics
.
get
)
.
get
(
'
/lvis/:instanceId/project/:projectId/tabs
'
,
checkSignature
,
checkInstanceId
,
checkProjectId
,
tabs
.
getProject
)
.
get
(
'
/lvis/:instanceId/project/:projectId/events/:eventId/tabs
'
,
checkToken
,
checkInstanceId
,
checkProjectId
,
tabs
.
get
checkSignature
,
checkInstanceId
,
checkProjectId
,
checkEventId
,
tabs
.
getEvent
)
.
get
(
'
/lvis/:instanceId/project/:projectId/tabs/:tabId
'
,
checkInstanceId
,
checkProjectId
,
checkTabId
,
checkSessionToken
,
tab
.
getEvent
)
.
get
(
'
/lvis/:instanceId/project/:projectId/events/:eventId/tabs/:tabId
'
,
checkInstanceId
,
checkProjectId
,
checkEventId
,
checkTabId
,
checkSessionToken
,
tab
.
getEvent
)
;
...
...
router/tab.js
0 → 100644
View file @
6066db22
'
use strict
'
;
const
urlJoin
=
require
(
'
url-join
'
);
const
fetch
=
require
(
'
node-fetch
'
);
function
*
getProject
()
{
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
project
'
);
if
(
!
this
.
config
.
projectTabCallback
)
{
return
;
}
const
user
=
yield
*
fetchUser
.
apply
(
this
);
this
.
logger
.
log
(
__filename
,
'
user
'
,
user
);
this
.
body
=
yield
this
.
config
.
projectTabCallback
(
this
.
state
.
instance
,
this
.
state
.
project
,
this
.
state
.
tabId
,
user
);
}
function
*
getEvent
()
{
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
event
'
);
if
(
!
this
.
config
.
eventTabCallback
)
{
return
;
}
const
user
=
yield
*
fetchUser
.
apply
(
this
);
this
.
logger
.
log
(
__filename
,
'
user
'
,
user
);
this
.
body
=
yield
this
.
config
.
projectTabCallback
(
this
.
state
.
instance
,
this
.
state
.
project
,
this
.
state
.
eventId
,
this
.
state
.
tabId
,
user
);
}
module
.
exports
=
{
getProject
,
getEvent
};
function
*
fetchUser
()
{
const
url
=
urlJoin
(
this
.
state
.
instance
.
auth_endpoint
,
'
p
'
,
this
.
state
.
project
.
id
,
'
sessions
'
,
`
${
this
.
config
.
service
.
id
}
?service_id=
${
this
.
state
.
sessionToken
}
`
);
this
.
logger
.
log
(
__filename
,
'
fetch user url:
'
,
url
);
yield
fetch
(
url
).
then
(
res
=>
res
.
json
());
}
router/tabs.js
View file @
6066db22
'
use strict
'
;
const
urlJoin
=
require
(
'
url-join
'
);
function
*
get
()
{
this
.
logger
.
log
(
__filename
,
'
GET
'
);
function
*
get
Project
()
{
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
project
'
);
if
(
this
.
config
.
t
absCallback
)
{
this
.
body
=
yield
this
.
config
.
tabsCallback
(
this
.
state
.
instance
,
this
.
state
.
project
)
;
if
(
!
this
.
config
.
projectT
absCallback
)
{
return
;
}
const
tabs
=
yield
this
.
config
.
projectTabsCallback
(
this
.
state
.
instance
,
this
.
state
.
project
);
tabs
.
forEach
(
tab
=>
Object
.
assign
(
tab
,
{
level
:
'
p
'
,
url
:
this
.
protocol
+
'
://
'
+
urlJoin
(
this
.
host
,
'
lvis
'
,
this
.
state
.
instance
.
id
,
'
project
'
,
this
.
state
.
project
.
id
,
'
tabs
'
,
tab
.
id
)
}));
this
.
body
=
tabs
;
}
function
*
getEvent
()
{
this
.
logger
.
log
(
__filename
,
'
GET
'
,
'
event
'
);
if
(
!
this
.
config
.
eventTabsCallback
)
{
return
;
}
const
tabs
=
yield
this
.
config
.
eventTabsCallback
(
this
.
state
.
instance
,
this
.
state
.
project
,
this
.
state
.
eventId
);
tabs
.
forEach
(
tab
=>
Object
.
assign
(
tab
,
{
level
:
'
e
'
,
url
:
this
.
protocol
+
'
://
'
+
urlJoin
(
this
.
host
,
'
lvis
'
,
this
.
state
.
instance
.
id
,
'
project
'
,
this
.
state
.
project
.
id
,
'
events
'
,
this
.
state
.
eventId
,
'
tabs
'
,
tab
.
id
)
}));
this
.
body
=
tabs
;
}
module
.
exports
=
{
get
:
ge
t
};
module
.
exports
=
{
get
Project
,
getEven
t
};
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