Comparing version 0.0.1 to 0.0.2
@@ -32,2 +32,5 @@ "use strict"; | ||
/** | ||
* Represent requests that returned status different than 2xx | ||
*/ | ||
var RequestError = /*#__PURE__*/function (_Error) { | ||
@@ -38,2 +41,8 @@ _inherits(RequestError, _Error); | ||
/** | ||
* Create a request error exception. | ||
* @param {number} statusCode - HTTP status code of the response. | ||
* @param {array|object} detail - List or single object describing the error. | ||
* @param {...any} params - Additional error parameters (used by parent class) | ||
*/ | ||
function RequestError(statusCode, detail) { | ||
@@ -40,0 +49,0 @@ var _this; |
100
lib/http.js
@@ -54,6 +54,15 @@ "use strict"; | ||
/** | ||
* Perform a request and raise error when status is not 2XX | ||
* @async | ||
* @param {function} fn - Function that will perform a request | ||
* @returns {object} Response | ||
* @throws {RequestError|Error} | ||
*/ | ||
function raiseForStatus(_x) { | ||
return _raiseForStatus.apply(this, arguments); | ||
} | ||
/** Class representing an active Belvo API session */ | ||
function _raiseForStatus() { | ||
@@ -79,5 +88,14 @@ _raiseForStatus = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(fn) { | ||
_context9.t0 = _context9["catch"](0); | ||
if (!_context9.t0.response) { | ||
_context9.next = 14; | ||
break; | ||
} | ||
throw new _exceptions["default"](_context9.t0.response.status, _context9.t0.response.data); | ||
case 11: | ||
case 14: | ||
throw _context9.t0; | ||
case 15: | ||
case "end": | ||
@@ -93,6 +111,10 @@ return _context9.stop(); | ||
var APISession = /*#__PURE__*/function () { | ||
/** | ||
* Create a session. | ||
* @param {string} url - Belvo API host URL. | ||
*/ | ||
function APISession(url) { | ||
_classCallCheck(this, APISession); | ||
var version = '0.0.1'; | ||
var version = '0.0.2'; | ||
this.session = _axios["default"].create({ | ||
@@ -106,3 +128,11 @@ baseURL: url, | ||
} | ||
/** | ||
* Login to Belvo API using secret key credentials. | ||
* @async | ||
* @param {string} secretKeyId - The Id of the key. | ||
* @param {string} secretKeyPassword - The password of the key. | ||
* @returns {boolean} true when login is sucessful else false. | ||
*/ | ||
_createClass(APISession, [{ | ||
@@ -128,3 +158,3 @@ key: "login", | ||
case 4: | ||
_context.next = 9; | ||
_context.next = 10; | ||
break; | ||
@@ -135,9 +165,10 @@ | ||
_context.t0 = _context["catch"](1); | ||
console.log(_context.t0); | ||
return _context.abrupt("return", false); | ||
case 9: | ||
case 10: | ||
this.session.defaults.auth = auth; | ||
return _context.abrupt("return", true); | ||
case 11: | ||
case 12: | ||
case "end": | ||
@@ -156,2 +187,9 @@ return _context.stop(); | ||
}() | ||
/** | ||
* Get all results from a paginated response | ||
* @async | ||
* @param {string} url - API endpoint | ||
* @yields {object} The next result in the response. | ||
*/ | ||
}, { | ||
@@ -230,2 +268,10 @@ key: "getAll", | ||
} | ||
/** | ||
* Get a list of resources. | ||
* @async | ||
* @param {string} url - API endpoint | ||
* @param {number} limit - Maximum number of results to get. | ||
* @returns {array} List of resources. | ||
*/ | ||
}, { | ||
@@ -298,2 +344,10 @@ key: "list", | ||
}() | ||
/** | ||
* Get details of a specific resource. | ||
* @async | ||
* @param {str} url - API endpoint | ||
* @param {string} id - UUID4 representing the resource id. | ||
* @returns {object} | ||
*/ | ||
}, { | ||
@@ -329,2 +383,11 @@ key: "get", | ||
}() | ||
/** | ||
* Do a POST request to the API. | ||
* @async | ||
* @param {string} url - API endpoint. | ||
* @param {object} payload - JSON request payload. | ||
* @returns {object} Response | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -360,2 +423,11 @@ key: "post", | ||
}() | ||
/** | ||
* Do a PATCH request to the API. | ||
* @async | ||
* @param {string} url - API endpoint. | ||
* @param {object} payload - Response | ||
* @returns {object} Response | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -391,2 +463,11 @@ key: "patch", | ||
}() | ||
/** | ||
* Do a PUT request to the API. | ||
* @async | ||
* @param {string} url - API endpoint. | ||
* @param {string} id - UUID4 representing the resource Id. | ||
* @param {object} payload - JSON request payload. | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -423,2 +504,11 @@ key: "put", | ||
}() | ||
/** | ||
* Do a DELETE request to the API. | ||
* @async | ||
* @param {stroing} url - API endpoint. | ||
* @param {string} id - UUID4 representing the resource Id. | ||
* @returns {boolean} | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -425,0 +515,0 @@ key: "delete", |
@@ -44,2 +44,6 @@ "use strict"; | ||
/** | ||
* A Link is a set of credentials associated to a end-user access to an Institution. | ||
* @extends Resource | ||
* */ | ||
var Link = /*#__PURE__*/function (_Resource) { | ||
@@ -68,18 +72,23 @@ _inherits(Link, _Resource); | ||
_createClass(Link, [{ | ||
key: "validateAccessMode", | ||
value: function validateAccessMode() { | ||
if (!(this.accessMode in [_classPrivateFieldLooseBase(Link, _SINGLE)[_SINGLE], _classPrivateFieldLooseBase(Link, _RECURRENT)[_RECURRENT]])) { | ||
throw Error('Invalid accessMode given.'); | ||
} | ||
} | ||
}, { | ||
key: "register", | ||
/** | ||
* Register a new link. | ||
* @async | ||
* @param {string} institution - Institution's code. | ||
* @param {string} username - Username used to sign in online by the end-user. | ||
* @param {string} password - Password used to sign in online by the end-user. | ||
* @param {object} options - Optional parameters | ||
* (token, encriptionKey, usernameType, password2, accessMode). | ||
* @returns {object} Newly created link. | ||
* @throws {RequestError} | ||
*/ | ||
value: function () { | ||
var _register = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(institution, username, password) { | ||
var password2, | ||
accessMode, | ||
options, | ||
var options, | ||
token, | ||
encryptionKey, | ||
usernameType, | ||
password2, | ||
accessMode, | ||
result, | ||
@@ -91,8 +100,5 @@ _args = arguments; | ||
case 0: | ||
password2 = _args.length > 3 && _args[3] !== undefined ? _args[3] : null; | ||
accessMode = _args.length > 4 && _args[4] !== undefined ? _args[4] : _classPrivateFieldLooseBase(Link, _SINGLE)[_SINGLE]; | ||
options = _args.length > 5 && _args[5] !== undefined ? _args[5] : {}; | ||
token = options.token, encryptionKey = options.encryptionKey, usernameType = options.usernameType; | ||
this.validateAccessMode(); | ||
_context.next = 7; | ||
options = _args.length > 3 && _args[3] !== undefined ? _args[3] : {}; | ||
token = options.token, encryptionKey = options.encryptionKey, usernameType = options.usernameType, password2 = options.password2, accessMode = options.accessMode; | ||
_context.next = 4; | ||
return this.session.post(_classPrivateFieldLooseBase(this, _endpoint)[_endpoint], { | ||
@@ -105,11 +111,11 @@ institution: institution, | ||
encryption_key: encryptionKey, | ||
accessMode: accessMode, | ||
usernameType: usernameType | ||
access_mode: accessMode !== null && accessMode !== void 0 ? accessMode : Link.SINGLE, | ||
username_type: usernameType | ||
}); | ||
case 7: | ||
case 4: | ||
result = _context.sent; | ||
return _context.abrupt("return", result); | ||
case 9: | ||
case 6: | ||
case "end": | ||
@@ -128,2 +134,14 @@ return _context.stop(); | ||
}() | ||
/** | ||
* Update link's password and password2. | ||
* Use this function when you want to update the link credentials. | ||
* Only updating passwords is available. | ||
* @async | ||
* @param {string} id - UUID4 representation of the link Id. | ||
* @param {string} password - New password. | ||
* @param {object} options - Optional parameters (token, encryptionKey, password2). | ||
* @returns {object} Response | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -133,6 +151,6 @@ key: "update", | ||
var _update = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(id, password) { | ||
var password2, | ||
options, | ||
var options, | ||
token, | ||
encryptionKey, | ||
password2, | ||
result, | ||
@@ -144,6 +162,5 @@ _args2 = arguments; | ||
case 0: | ||
password2 = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : null; | ||
options = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : {}; | ||
token = options.token, encryptionKey = options.encryptionKey; | ||
_context2.next = 5; | ||
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {}; | ||
token = options.token, encryptionKey = options.encryptionKey, password2 = options.password2; | ||
_context2.next = 4; | ||
return this.session.put(_classPrivateFieldLooseBase(this, _endpoint)[_endpoint], id, { | ||
@@ -156,7 +173,7 @@ password: password, | ||
case 5: | ||
case 4: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", result); | ||
case 7: | ||
case 6: | ||
case "end": | ||
@@ -182,15 +199,5 @@ return _context2.stop(); | ||
var _SINGLE = _classPrivateFieldLooseKey("SINGLE"); | ||
var _RECURRENT = _classPrivateFieldLooseKey("RECURRENT"); | ||
Object.defineProperty(Link, _SINGLE, { | ||
writable: true, | ||
value: 'single' | ||
}); | ||
Object.defineProperty(Link, _RECURRENT, { | ||
writable: true, | ||
value: 'recurrent' | ||
}); | ||
Link.SINGLE = 'single'; | ||
Link.RECURRENT = 'recurrent'; | ||
var _default = Link; | ||
exports["default"] = _default; |
@@ -24,3 +24,8 @@ "use strict"; | ||
/** Represents a Belvo API resource */ | ||
var Resource = /*#__PURE__*/function () { | ||
/** | ||
* Instantiate a resource. | ||
* @param {APISession} session - Belvo API session. | ||
*/ | ||
function Resource(session) { | ||
@@ -35,3 +40,11 @@ _classCallCheck(this, Resource); | ||
} | ||
/** | ||
* Get a list of resources. | ||
* @async | ||
* @param {number} limit - Maximum number of results. | ||
* @returns {array} List of results. | ||
* @throws {RequestError} | ||
*/ | ||
_createClass(Resource, [{ | ||
@@ -70,2 +83,10 @@ key: "list", | ||
}() | ||
/** | ||
* Get specific record details. | ||
* @async | ||
* @param {string} id - UUID4 representation of the resource Id. | ||
* @returns {object} | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -101,2 +122,9 @@ key: "detail", | ||
}() | ||
/** | ||
* Delete specific record. | ||
* @async | ||
* @param {string} id - UUID4 representation of the resource Id. | ||
* @returns {boolean} When the record is successfuly deleted returns true, otherwise false. | ||
*/ | ||
}, { | ||
@@ -132,2 +160,13 @@ key: "delete", | ||
}() | ||
/** | ||
* Resume a "pending" session that requires an OTP token. | ||
* Use this function to resume sessions that returned HTTP 428 status code. | ||
* @async | ||
* @param {string} session - UUID4 representation of a "pending" session. | ||
* @param {string} token - OTP token. | ||
* @param {string} link - UUID4 representation of the link being used. | ||
* @returns {object} Response. | ||
* @throws {RequestError} | ||
*/ | ||
}, { | ||
@@ -134,0 +173,0 @@ key: "resume", |
{ | ||
"name": "belvo", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "The node.js module for the Belvo API", | ||
"main": "index.js", | ||
"main": "belvo.js", | ||
"scripts": { | ||
"prepublish": "babel src -d lib", | ||
"lint": "eslint ./src", | ||
@@ -8,0 +9,0 @@ "build": "babel src -d lib", |
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
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
427
101037
16
1704
1