sa-kws-node-sdk
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,14 +9,20 @@ var BPromise = require('bluebird'); | ||
/* | ||
* Mandatory opts: * | ||
* - kwsApiHost: KWS Host (https://kwsapi.superawesome.tv for example) * | ||
* - apiKey: Api Key of the app * | ||
* - clientId: Name of the app * | ||
* * | ||
* Optional opts: * | ||
* - scope: special scope requested for the token * | ||
* - endpoints: list of additional endpoints to use (for specific clients) * | ||
* - cookieNameUser: Name of the user token cookie * | ||
* - cookieNameApp: Name of the app token cookie * | ||
* - headerNameUser: Name of the user header * | ||
* - headerNameApp: Name of the app header * | ||
* Mandatory opts: * | ||
* - kwsApiHost: KWS Host (https://kwsapi.superawesome.tv for example) * | ||
* - apiKey: Api Key of the app * | ||
* - clientId: Name of the app * | ||
* * | ||
* Optional opts: * | ||
* - scope: special scope requested for the token * | ||
* - endpoints: list of additional endpoints to use (for specific clients) * | ||
* - singularList: list of word that are always singular (related to endpoints)* | ||
* - cookieNameUser: Name of the user token cookie * | ||
* - cookieNameApp: Name of the app token cookie * | ||
* - headerNameUser: Name of the user header * | ||
* - headerNameApp: Name of the app header * | ||
* - loginRedirectUrl: if the login url is different than the current host * | ||
* - logoutRedirectUrl: if the logout url is different than the current host * | ||
* - allowedDomains: In case of cross domain login array of allowed domains * | ||
* - debug: add logs if set to true * | ||
* - logger: loger function, by default console.log * | ||
*/ | ||
@@ -34,3 +40,7 @@ | ||
var singularList = []; | ||
this.opts = opts || {}; | ||
this.opts.logger = opts.logger || console.log; | ||
this.opts.allowedDomains = opts.allowedDomains || []; | ||
@@ -42,3 +52,4 @@ this.bearerToken = null; | ||
var endpointList = endpoints.concat(this.opts.endpoints || []); | ||
this.apiFunctionFactory(endpointList); | ||
singularList = singularList.concat(this.opts.singularList || []); | ||
this.apiFunctionFactory(endpointList, singularList); | ||
} | ||
@@ -48,3 +59,3 @@ | ||
//********************************************************************************* | ||
KwsSdk.prototype.createApiFunction = function (endpoint) { | ||
KwsSdk.prototype.createApiFunction = function (endpoint, singularList) { | ||
var self = this; | ||
@@ -68,3 +79,3 @@ | ||
.then(function (token) { | ||
var url = self.opts.kwsApiHost + utils.createPathFromEndpoint(endpoint, params, token); | ||
var url = self.opts.kwsApiHost + utils.createPathFromEndpoint(endpoint, singularList, params, token); | ||
@@ -81,7 +92,7 @@ var opts = { | ||
KwsSdk.prototype.apiFunctionFactory = function (endpointList) { | ||
KwsSdk.prototype.apiFunctionFactory = function (endpointList, singularList) { | ||
var self = this; | ||
endpointList.forEach(function (endpoint) { | ||
self.createApiFunction(endpoint); | ||
self.createApiFunction(endpoint, singularList); | ||
}); | ||
@@ -88,0 +99,0 @@ }; |
@@ -57,2 +57,6 @@ var express = require('express'); | ||
.catch(function (resp) { | ||
if (sdkOptions.debug) { | ||
sdkOptions.logger('Error in: /sa/oauth/callback'); | ||
sdkOptions.logger(resp); | ||
} | ||
res.redirect(sdkOptions.logoutRedirectUrl || '/'); | ||
@@ -118,3 +122,8 @@ }); | ||
}) | ||
.catch(function () { | ||
.catch(function (resp) { | ||
if (sdkOptions.debug) { | ||
sdkOptions.logger('Error in: /sa/authentication/frontend-app-token'); | ||
sdkOptions.logger(resp); | ||
} | ||
return res.status(400).json({message:'Authentication failed'}); | ||
@@ -121,0 +130,0 @@ }); |
@@ -36,9 +36,15 @@ var BPromise = require('bluebird'); | ||
'app.game.score', | ||
'app.competition.submitDrawing' | ||
'app.competition.submitDrawing', | ||
'app.user.appData.list', | ||
'app.user.appData.set', | ||
'app.user.appData.deleteByName' | ||
]; | ||
var singularList = ['appData']; | ||
this.opts = opts || {}; | ||
this.bearerToken = this.opts.userToken || this.opts.appToken; | ||
singularList = singularList.concat(this.opts.singularList || []); | ||
this.apiFunctionFactory(endpoints); | ||
this.apiFunctionFactory(endpoints, singularList); | ||
} | ||
@@ -59,3 +65,3 @@ | ||
//********************************************************************************* | ||
UserSdk.prototype.createApiFunction = function (endpoint) { | ||
UserSdk.prototype.createApiFunction = function (endpoint, singularList) { | ||
var self = this; | ||
@@ -78,3 +84,3 @@ | ||
var url = self.opts.kwsApiHost + utils.createPathFromEndpoint(endpoint, params, self.bearerToken); | ||
var url = self.opts.kwsApiHost + utils.createPathFromEndpoint(endpoint, singularList, params, self.bearerToken); | ||
@@ -91,7 +97,7 @@ var opts = { | ||
UserSdk.prototype.apiFunctionFactory = function (endpointList) { | ||
UserSdk.prototype.apiFunctionFactory = function (endpointList, singularList) { | ||
var self = this; | ||
endpointList.forEach(function (endpoint) { | ||
self.createApiFunction(endpoint); | ||
self.createApiFunction(endpoint, singularList); | ||
}); | ||
@@ -98,0 +104,0 @@ }; |
@@ -94,3 +94,7 @@ 'use strict'; | ||
for (var i = 0; i < parts.length - 1; i++) { | ||
path += '/' + decamelize(parts[i], '-') + 's'; | ||
var plural = 's'; | ||
if (singularList.indexOf(parts[i]) !== -1) { | ||
plural = ''; | ||
} | ||
path += '/' + KwsSdk.decamelize(parts[i], '-') + plural; | ||
@@ -97,0 +101,0 @@ // Add id to the path if existing in params or tokenData |
{ | ||
"name": "sa-kws-node-sdk", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "KWS Node App SDK", | ||
@@ -5,0 +5,0 @@ "main": "./lib/kwsSdk.js", |
36157
918