Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nordnet-next-api

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nordnet-next-api - npm Package Compare versions

Comparing version 2.3.2 to 2.3.3

16

lib/__tests__/expectations/get-accounts.js

@@ -1,6 +0,16 @@

import api from '../../index';
'use strict';
export default {
Object.defineProperty(exports, "__esModule", {
value: true
});
var _index = require('../../index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
conditions: {
request: [api.get, ['/api/2/accounts']],
request: [_index2.default.get, ['/api/2/accounts']],
response: ['GET', '/api/2/accounts', [401, { 'Content-Type': 'application/json; charset=UTF-8' }, JSON.stringify({ code: 'NEXT_INVALID_SESSION' })]]

@@ -7,0 +17,0 @@ },

22

lib/__tests__/expectations/get-instrument.js

@@ -1,13 +0,23 @@

import api from '../../index';
'use strict';
const params = { instrument_id: 123, positions: [456, 789], accno: 987 };
const headers = { 'Accept-Language': 'sv' };
Object.defineProperty(exports, "__esModule", {
value: true
});
export default {
var _index = require('../../index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var params = { instrument_id: 123, positions: [456, 789], accno: 987 };
var headers = { 'Accept-Language': 'sv' };
exports.default = {
conditions: {
request: [api.get, ['/api/2/instruments/{instrument_id}?positions={positions}', params, headers]],
request: [_index2.default.get, ['/api/2/instruments/{instrument_id}?positions={positions}', params, headers]],
response: ['GET', '/api/2/instruments/123?positions=456%2C789&accno=987', [200, { 'Content-Type': 'application/json; charset=UTF-8' }, JSON.stringify({ instrument_id: 123 })]]
},
expected: {
url: `/api/2/instruments/123?positions=${ encodeURIComponent('456,789') }&accno=987`,
url: '/api/2/instruments/123?positions=' + encodeURIComponent('456,789') + '&accno=987',
headers: { 'accept-language': 'sv', accept: 'application/json', ntag: 'NO_NTAG_RECEIVED_YET' },

@@ -14,0 +24,0 @@ method: 'get',

@@ -1,13 +0,35 @@

import getInstrument from './get-instrument';
import getAccounts from './get-accounts';
import postUserSettings from './post-user-settings';
import postUserLists from './post-user-lists';
import ping from './ping';
'use strict';
export default {
getInstrument,
getAccounts,
postUserSettings,
postUserLists,
ping
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getInstrument = require('./get-instrument');
var _getInstrument2 = _interopRequireDefault(_getInstrument);
var _getAccounts = require('./get-accounts');
var _getAccounts2 = _interopRequireDefault(_getAccounts);
var _postUserSettings = require('./post-user-settings');
var _postUserSettings2 = _interopRequireDefault(_postUserSettings);
var _postUserLists = require('./post-user-lists');
var _postUserLists2 = _interopRequireDefault(_postUserLists);
var _ping = require('./ping');
var _ping2 = _interopRequireDefault(_ping);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
getInstrument: _getInstrument2.default,
getAccounts: _getAccounts2.default,
postUserSettings: _postUserSettings2.default,
postUserLists: _postUserLists2.default,
ping: _ping2.default
};

@@ -1,6 +0,16 @@

import api from '../../index';
'use strict';
export default {
Object.defineProperty(exports, "__esModule", {
value: true
});
var _index = require('../../index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
conditions: {
request: [api.get, ['/api/2/ping']],
request: [_index2.default.get, ['/api/2/ping']],
response: ['GET', '/api/2/ping', [200, {}, 'pong']]

@@ -7,0 +17,0 @@ },

@@ -1,10 +0,20 @@

import api from '../../index';
'use strict';
const name = 'abc';
const params = { name };
const response = { id: 1, name };
Object.defineProperty(exports, "__esModule", {
value: true
});
export default {
var _index = require('../../index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var name = 'abc';
var params = { name: name };
var response = { id: 1, name: name };
exports.default = {
conditions: {
request: [api.post, ['/api/2/user/lists', params]],
request: [_index2.default.post, ['/api/2/user/lists', params]],
response: ['POST', '/api/2/user/lists', [201, { 'Content-type': 'application/json; charset=UTF-8' }, JSON.stringify(response)]]

@@ -17,3 +27,3 @@ },

credentials: true,
body: `name=${ name }`,
body: 'name=' + name,
status: 201,

@@ -20,0 +30,0 @@ data: response,

@@ -1,9 +0,19 @@

import api from '../../index';
'use strict';
const params = { key: 1, settings: { widgets: [{ id: 1, name: 'winners/losers' }] } };
const headers = { 'content-type': 'application/json' };
Object.defineProperty(exports, "__esModule", {
value: true
});
export default {
var _index = require('../../index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var params = { key: 1, settings: { widgets: [{ id: 1, name: 'winners/losers' }] } };
var headers = { 'content-type': 'application/json' };
exports.default = {
conditions: {
request: [api.post, ['/api/2/user/settings/{key}', params, headers]],
request: [_index2.default.post, ['/api/2/user/settings/{key}', params, headers]],
response: ['POST', '/api/2/user/settings/1', [201, { 'Content-type': 'application/json; charset=UTF-8' }, JSON.stringify(params)]]

@@ -10,0 +20,0 @@ },

@@ -1,19 +0,48 @@

import { initSandBox, respondWith, execute, expectations } from 'test-helper';
import tests from './expectations';
import api from '../index';
import { expect } from 'chai';
'use strict';
function init(done, { request, response }) {
initSandBox.apply(this);
respondWith.call(this, response);
execute.apply(null, request).then(res => this.response = res, res => this.response = res).then(() => done()).catch(() => done());
var _testHelper = require('test-helper');
var _expectations = require('./expectations');
var _expectations2 = _interopRequireDefault(_expectations);
var _index = require('../index');
var _index2 = _interopRequireDefault(_index);
var _chai = require('chai');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function init(done, _ref) {
var _this = this;
var request = _ref.request;
var response = _ref.response;
_testHelper.initSandBox.apply(this);
_testHelper.respondWith.call(this, response);
_testHelper.execute.apply(null, request).then(function (res) {
return _this.response = res;
}, function (res) {
return _this.response = res;
}).then(function () {
return done();
}).catch(function () {
return done();
});
}
function verifyExpectations(expected) {
Object.keys(expected).forEach(key => it(`should have expected ${ key }`, function () {
expectations[key].call(this, expected[key]);
}));
Object.keys(expected).forEach(function (key) {
return it('should have expected ' + key, function () {
_testHelper.expectations[key].call(this, expected[key]);
});
});
}
function test({ conditions, expected }) {
function test(_ref2) {
var conditions = _ref2.conditions;
var expected = _ref2.expected;
return function () {

@@ -34,3 +63,5 @@ beforeEach(function (done) {

return function () {
conditions.forEach(condition => Object.keys(api).forEach(testMethodThrows(condition)));
conditions.forEach(function (condition) {
return Object.keys(_index2.default).forEach(testMethodThrows(condition));
});
};

@@ -40,3 +71,9 @@ }

function testMethodThrows(condition) {
return method => it(`should throw an error with ${ method } and url '${ condition }'`, () => expect(() => api[method](condition)).to.throw(Error));
return function (method) {
return it('should throw an error with ' + method + ' and url \'' + condition + '\'', function () {
return (0, _chai.expect)(function () {
return _index2.default[method](condition);
}).to.throw(Error);
});
};
}

@@ -46,7 +83,7 @@

describe('when url is invalid', testThrows([undefined, '', '/api/2/accounts/{accno}']));
describe('when request succeeded', test(tests.getInstrument));
describe('when request failed', test(tests.getAccounts));
describe('when response is not JSON', test(tests.ping));
describe('when making POST request', test(tests.postUserLists));
describe('when making POST request with JSON payload', test(tests.postUserSettings));
describe('when request succeeded', test(_expectations2.default.getInstrument));
describe('when request failed', test(_expectations2.default.getAccounts));
describe('when response is not JSON', test(_expectations2.default.ping));
describe('when making POST request', test(_expectations2.default.postUserLists));
describe('when making POST request with JSON payload', test(_expectations2.default.postUserSettings));
});

@@ -1,30 +0,51 @@

import 'babel-polyfill';
import es6Promise from 'es6-promise';
'use strict';
es6Promise.polyfill();
Object.defineProperty(exports, "__esModule", {
value: true
});
import 'isomorphic-fetch';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
const HTTP_NO_CONTENT = 204;
const HTTP_BAD_REQUEST = 400;
exports.get = get;
exports.post = post;
exports.put = put;
exports.del = del;
const defaultHeaders = {
require('babel-polyfill');
var _es6Promise = require('es6-promise');
var _es6Promise2 = _interopRequireDefault(_es6Promise);
require('isomorphic-fetch');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_es6Promise2.default.polyfill();
var HTTP_NO_CONTENT = 204;
var HTTP_BAD_REQUEST = 400;
var defaultHeaders = {
accept: 'application/json'
};
const postDefaultHeaders = Object.assign({
var postDefaultHeaders = Object.assign({
'content-type': 'application/x-www-form-urlencoded'
}, defaultHeaders);
const state = {
var state = {
nTag: 'NO_NTAG_RECEIVED_YET'
};
const credentials = 'include';
var credentials = 'include';
export function get(url, params = {}, headers = {}) {
const options = {
url,
params,
headers,
function get(url) {
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var headers = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = {
url: url,
params: params,
headers: headers,
method: 'get'

@@ -36,7 +57,10 @@ };

export function post(url, params = {}, headers = {}) {
const options = {
url,
params,
headers,
function post(url) {
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var headers = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = {
url: url,
params: params,
headers: headers,
method: 'post'

@@ -48,7 +72,10 @@ };

export function put(url, params = {}, headers = {}) {
const options = {
url,
params,
headers,
function put(url) {
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var headers = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = {
url: url,
params: params,
headers: headers,
method: 'put'

@@ -60,7 +87,10 @@ };

export function del(url, params = {}, headers = {}) {
const options = {
url,
params,
headers,
function del(url) {
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var headers = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = {
url: url,
params: params,
headers: headers,
method: 'delete'

@@ -72,25 +102,26 @@ };

export default {
get,
post,
put,
del
exports.default = {
get: get,
post: post,
put: put,
del: del
};
function httpFetch(options) {
validateUrl(options.url);
const path = buildPath(options.url, options.params);
const params = omit(options.params, getPathParams(options.url));
var path = buildPath(options.url, options.params);
var params = omit(options.params, getPathParams(options.url));
const query = hasQuery(options.method) ? buildParams(params) : undefined;
const headers = buildHeaders(options.method, options.headers);
const body = buildBody(options.method, params, headers);
var query = hasQuery(options.method) ? buildParams(params) : undefined;
var headers = buildHeaders(options.method, options.headers);
var body = buildBody(options.method, params, headers);
const fetchUrl = buildUrl(path, query);
var fetchUrl = buildUrl(path, query);
const fetchParams = {
headers,
credentials,
body,
var fetchParams = {
headers: headers,
credentials: credentials,
body: body,
method: options.method

@@ -111,3 +142,5 @@ };

function toErrorResponse(response) {
return parseContent(response).then(res => Promise.reject(res));
return parseContent(response).then(function (res) {
return Promise.reject(res);
});
}

@@ -122,3 +155,3 @@

if (response.status === HTTP_NO_CONTENT) {
return { response, status: response.status };
return { response: response, status: response.status };
}

@@ -130,6 +163,8 @@

function parseContent(response) {
const contentType = response.headers.get('Content-type');
const method = isJSON(contentType) ? 'json' : 'text';
var contentType = response.headers.get('Content-type');
var method = isJSON(contentType) ? 'json' : 'text';
return response[method]().then(data => ({ response, data, status: response.status }));
return response[method]().then(function (data) {
return { response: response, data: data, status: response.status };
});
}

@@ -148,11 +183,15 @@

function getPathParams(url) {
const keys = url.match(/{([\s\S]+?)}/g) || [];
return keys.map(key => key.replace(/({|})/g, ''));
var keys = url.match(/{([\s\S]+?)}/g) || [];
return keys.map(function (key) {
return key.replace(/({|})/g, '');
});
}
function buildUrl(path, query = '') {
const queryParams = query.length ? query.join('&') : '';
const pathContainsQuery = path.indexOf('?') !== -1;
function buildUrl(path) {
var query = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
let delimiter = '';
var queryParams = query.length ? query.join('&') : '';
var pathContainsQuery = path.indexOf('?') !== -1;
var delimiter = '';
if (pathContainsQuery && queryParams) {

@@ -164,3 +203,3 @@ delimiter = '&';

return `${ path }${ delimiter }${ queryParams }`;
return '' + path + delimiter + queryParams;
}

@@ -175,3 +214,3 @@

if (params[key] === undefined) {
throw new Error(`unknown parameter ${ key }`);
throw new Error('unknown parameter ' + key);
}

@@ -183,4 +222,8 @@

function buildParams(params = {}) {
return Object.keys(params).map(key => encodeURIComponent(key) + '=' + uriEncode(params[key]));
function buildParams() {
var params = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
return Object.keys(params).map(function (key) {
return encodeURIComponent(key) + '=' + uriEncode(params[key]);
});
}

@@ -201,3 +244,3 @@

function keyToLowerCase(obj) {
return (accumulator, key) => {
return function (accumulator, key) {
accumulator[key.toLowerCase()] = obj[key];

@@ -217,3 +260,3 @@ return accumulator;

function isJsonContentType(headers) {
const contentType = Object.keys(headers).find(contains('content-type'));
var contentType = Object.keys(headers).find(contains('content-type'));
return isJSON(headers[contentType]);

@@ -223,3 +266,3 @@ }

function uriEncode(value) {
let encoded;
var encoded = void 0;
if (Array.isArray(value)) {

@@ -255,3 +298,3 @@ encoded = value.join(',');

function omitKey(source, props) {
return (accumulator, key) => {
return function (accumulator, key) {
if (props.indexOf(key) === -1) {

@@ -266,3 +309,3 @@ accumulator[key] = source[key];

function isPlainObject(obj) {
return obj !== null && typeof obj === 'object';
return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
}
{
"name": "nordnet-next-api",
"version": "2.3.2",
"version": "2.3.3",
"description": "Nordnet nExt API Javascript client",

@@ -8,3 +8,3 @@ "main": "lib/index.js",

"clean": "rimraf lib dist",
"build": "babel src --out-dir lib",
"build": "babel --presets es2015 --plugin add-module-exports src --out-dir lib",
"build:umd": "webpack --config ./webpack/webpack.config src/index.js dist/nordnet-next-api.js && NODE_ENV=production webpack --config ./webpack/webpack.config src/index.js dist/nordnet-next-api.min.js",

@@ -11,0 +11,0 @@ "eslint": "eslint src || echo \"Linting failed...\"",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc