nordnet-next-api
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -20,3 +20,3 @@ 'use strict'; | ||
url: '/api/2/accounts', | ||
headers: { 'Accept': 'application/json' }, | ||
headers: { 'accept': 'application/json' }, | ||
method: 'get', | ||
@@ -26,5 +26,6 @@ credentials: true, | ||
status: 401, | ||
data: { code: 'NEXT_INVALID_SESSION' } | ||
data: { code: 'NEXT_INVALID_SESSION' }, | ||
response: true | ||
} | ||
}; | ||
module.exports = exports['default']; |
@@ -23,3 +23,3 @@ 'use strict'; | ||
url: '/api/2/instruments/123?positions=' + encodeURIComponent('456,789') + '&accno=987', | ||
headers: { 'Accept-Language': 'sv', 'Accept': 'application/json' }, | ||
headers: { 'accept-language': 'sv', 'accept': 'application/json' }, | ||
method: 'get', | ||
@@ -29,5 +29,6 @@ credentials: true, | ||
status: 200, | ||
data: { instrument_id: 123 } | ||
data: { instrument_id: 123 }, | ||
response: true | ||
} | ||
}; | ||
module.exports = exports['default']; |
@@ -21,5 +21,6 @@ 'use strict'; | ||
status: 200, | ||
data: 'pong' | ||
data: 'pong', | ||
response: true | ||
} | ||
}; | ||
module.exports = exports['default']; |
@@ -24,3 +24,3 @@ 'use strict'; | ||
url: '/api/2/user/lists', | ||
headers: { 'Content-type': 'application/x-www-form-urlencoded', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
headers: { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
method: 'post', | ||
@@ -30,5 +30,6 @@ credentials: true, | ||
status: 201, | ||
data: response | ||
data: response, | ||
response: true | ||
} | ||
}; | ||
module.exports = exports['default']; |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var params = { key: 1, settings: { widgets: [{ id: 1, name: 'winners/losers' }] } }; | ||
var headers = { 'Content-type': 'application/json' }; | ||
var headers = { 'content-type': 'application/json' }; | ||
@@ -24,3 +24,3 @@ exports['default'] = { | ||
url: '/api/2/user/settings/1', | ||
headers: { 'Content-type': 'application/json', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
headers: { 'content-type': 'application/json', accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
method: 'post', | ||
@@ -30,5 +30,6 @@ credentials: true, | ||
status: 201, | ||
data: params | ||
data: params, | ||
response: true | ||
} | ||
}; | ||
module.exports = exports['default']; |
@@ -38,3 +38,3 @@ 'use strict'; | ||
Object.keys(expected).forEach(function (key) { | ||
return it('should fetch with expected ' + key, function () { | ||
return it('should have expected ' + key, function () { | ||
_testHelper.expectations[key].call(this, expected[key]); | ||
@@ -41,0 +41,0 @@ }); |
@@ -46,7 +46,7 @@ 'use strict'; | ||
var defaultHeaders = { | ||
Accept: 'application/json' | ||
accept: 'application/json' | ||
}; | ||
var postDefaultHeaders = (0, _lodashObjectMerge2['default'])({ | ||
'Content-type': 'application/x-www-form-urlencoded' | ||
'content-type': 'application/x-www-form-urlencoded' | ||
}, defaultHeaders); | ||
@@ -166,3 +166,3 @@ | ||
if (response.status === HTTP_NO_CONTENT) { | ||
return { status: response.status }; | ||
return { response: response, status: response.status }; | ||
} | ||
@@ -178,3 +178,3 @@ | ||
return response[method]().then(function (data) { | ||
return { data: data, status: response.status }; | ||
return { response: response, data: data, status: response.status }; | ||
}); | ||
@@ -239,11 +239,24 @@ } | ||
function buildHeaders(method, headers) { | ||
var sanitisedHeaders = convertKeysToLowerCase(headers); | ||
if (method === 'post' || method === 'put') { | ||
return (0, _lodashObjectMerge2['default'])({ ntag: state.nTag }, postDefaultHeaders, headers); | ||
return (0, _lodashObjectMerge2['default'])({ ntag: state.nTag }, postDefaultHeaders, sanitisedHeaders); | ||
} else if (method === 'delete') { | ||
return (0, _lodashObjectMerge2['default'])({ ntag: state.nTag }, defaultHeaders, headers); | ||
return (0, _lodashObjectMerge2['default'])({ ntag: state.nTag }, defaultHeaders, sanitisedHeaders); | ||
} | ||
return (0, _lodashObjectMerge2['default'])({}, headers, defaultHeaders); | ||
return (0, _lodashObjectMerge2['default'])({}, sanitisedHeaders, defaultHeaders); | ||
} | ||
function convertKeysToLowerCase(obj) { | ||
return Object.keys(obj).reduce(keyToLowerCase(obj), {}); | ||
} | ||
function keyToLowerCase(obj) { | ||
return function (accumulator, key) { | ||
accumulator[key.toLowerCase()] = obj[key]; | ||
return accumulator; | ||
}; | ||
} | ||
function buildBody(method, params, headers) { | ||
@@ -250,0 +263,0 @@ if (!hasBody(method)) { |
{ | ||
"name": "nordnet-next-api", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Nordnet nExt API Javascript client", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -17,3 +17,3 @@ import api from '../../index'; | ||
url: '/api/2/accounts', | ||
headers: { 'Accept': 'application/json' }, | ||
headers: { 'accept': 'application/json' }, | ||
method: 'get', | ||
@@ -24,3 +24,4 @@ credentials: true, | ||
data: { code: 'NEXT_INVALID_SESSION' }, | ||
response: true, | ||
}, | ||
}; |
@@ -20,3 +20,3 @@ import api from '../../index'; | ||
url: `/api/2/instruments/123?positions=${encodeURIComponent('456,789')}&accno=987`, | ||
headers: { 'Accept-Language': 'sv', 'Accept': 'application/json' }, | ||
headers: { 'accept-language': 'sv', 'accept': 'application/json' }, | ||
method: 'get', | ||
@@ -27,3 +27,4 @@ credentials: true, | ||
data: { instrument_id: 123 }, | ||
response: true, | ||
}, | ||
}; |
@@ -19,3 +19,4 @@ import api from '../../index'; | ||
data: 'pong', | ||
response: true, | ||
}, | ||
}; |
@@ -21,3 +21,3 @@ import api from '../../index'; | ||
url: '/api/2/user/lists', | ||
headers: { 'Content-type': 'application/x-www-form-urlencoded', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
headers: { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
method: 'post', | ||
@@ -28,3 +28,4 @@ credentials: true, | ||
data: response, | ||
response: true, | ||
}, | ||
}; |
import api from '../../index'; | ||
const params = { key: 1, settings: { widgets: [{ id: 1, name: 'winners/losers' }] }}; | ||
const headers = { 'Content-type': 'application/json' }; | ||
const headers = { 'content-type': 'application/json' }; | ||
@@ -20,3 +20,3 @@ export default { | ||
url: '/api/2/user/settings/1', | ||
headers: { 'Content-type': 'application/json', Accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
headers: { 'content-type': 'application/json', accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' }, | ||
method: 'post', | ||
@@ -27,3 +27,4 @@ credentials: true, | ||
data: params, | ||
response: true, | ||
}, | ||
}; |
@@ -17,3 +17,3 @@ import { initSandBox, respondWith, execute, expectations } from 'test-helper'; | ||
Object.keys(expected) | ||
.forEach(key => it(`should fetch with expected ${key}`, function() { | ||
.forEach(key => it(`should have expected ${key}`, function() { | ||
expectations[key].call(this, expected[key]); | ||
@@ -20,0 +20,0 @@ })); |
@@ -18,7 +18,7 @@ import es6Promise from 'es6-promise'; | ||
const defaultHeaders = { | ||
Accept: 'application/json', | ||
accept: 'application/json', | ||
}; | ||
const postDefaultHeaders = merge({ | ||
'Content-type': 'application/x-www-form-urlencoded', | ||
'content-type': 'application/x-www-form-urlencoded', | ||
}, defaultHeaders); | ||
@@ -127,3 +127,3 @@ | ||
if (response.status === HTTP_NO_CONTENT) { | ||
return { status: response.status }; | ||
return { response, status: response.status }; | ||
} | ||
@@ -138,3 +138,3 @@ | ||
return response[method]().then(data => ({ data, status: response.status })); | ||
return response[method]().then(data => ({ response, data, status: response.status })); | ||
} | ||
@@ -190,11 +190,24 @@ | ||
function buildHeaders(method, headers) { | ||
const sanitisedHeaders = convertKeysToLowerCase(headers); | ||
if (method === 'post' || method === 'put') { | ||
return merge({ ntag: state.nTag }, postDefaultHeaders, headers); | ||
return merge({ ntag: state.nTag }, postDefaultHeaders, sanitisedHeaders); | ||
} else if (method === 'delete') { | ||
return merge({ ntag: state.nTag }, defaultHeaders, headers); | ||
return merge({ ntag: state.nTag }, defaultHeaders, sanitisedHeaders); | ||
} | ||
return merge({}, headers, defaultHeaders); | ||
return merge({}, sanitisedHeaders, defaultHeaders); | ||
} | ||
function convertKeysToLowerCase(obj) { | ||
return Object.keys(obj).reduce(keyToLowerCase(obj), {}); | ||
} | ||
function keyToLowerCase(obj) { | ||
return (accumulator, key) => { | ||
accumulator[key.toLowerCase()] = obj[key]; | ||
return accumulator; | ||
} | ||
} | ||
function buildBody(method, params, headers) { | ||
@@ -201,0 +214,0 @@ if (!hasBody(method)) { |
@@ -26,2 +26,3 @@ import { expect } from 'chai'; | ||
data: expectData, | ||
response: expectResponse, | ||
}; | ||
@@ -57,2 +58,6 @@ | ||
function expectResponse() { | ||
expect(this.response.response).to.not.be.undefined; | ||
} | ||
function expectEqual(expected, actual) { | ||
@@ -59,0 +64,0 @@ expect(actual).to.equal(expected); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3
42639
36
1110