Skip to content

Commit

Permalink
Merge pull request #21 from OpenSTFoundation/develop
Browse files Browse the repository at this point in the history
Preparing for release 2.0.0
  • Loading branch information
mayurpatil888 authored Dec 5, 2018
2 parents 6e82276 + ace6088 commit a34e121
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 59 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dist: trusty
language: node_js
sudo: required
branches:
only:
- master
- develop
notifications:
email:
recipients:
- ci.report@ost.com
on_success: always
on_failure: always
node_js:
- "9"
- "8"
- "7"
before_install:
- sudo apt-get update
- sudo apt-get install nodejs
- sudo apt-get install npm
install:
- npm install
- npm install -g mocha
before_script:
script:
- mocha --timeout 120000 test.js --exit
after_script:
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2018 OST.com Ltd.

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## KYC Javascript SDK

The official [KYC JavaScript SDK](https://dev.ost.com/docs/kyc/index.html).
The official [OST KYC JavaScript SDK](https://dev.ost.com/docs/kyc/index.html).

## Requirements


To use this node module, developers will need to:
1. Be a client of OST KYC
2. Obtain an API Key and API Secret from OST KYC.
1. Login on [https://kyc.ost.com/admin/login](https://kyc.ost.com/admin/login).
2. Obtain an API Key and API Secret from [https://kyc.ost.com/admin/settings/developer-integrations](https://kyc.ost.com/admin/settings/developer-integrations).

## Documentation

Expand All @@ -17,22 +18,24 @@ To use this node module, developers will need to:
Install OST KYC JavaScript SDK

```bash
> npm install @ostdotcom/kyc-sdk-js
> npm install @ostdotcom/ost-kyc-sdk-js
```

## Example Usage

Require the SDK:

```node.js
const KYCSDK = require('@ostdotcom/kyc-sdk-js');
const KYCSDK = require('@ostdotcom/ost-kyc-sdk-js');
```

Initialize the SDK object:

```node.js
// the latest valid API endpoint is "https://kyc.sandboxost.com", this may change in the future
const kycObj = new KYCSDK({apiKey: <api_key>, apiSecret: <api_secret>, apiEndpoint: <api_endpoint>});
// timeout can be passed in config object. This is http request timeout.(In seconds)
const kycObj = new KYCSDK({apiKey: <api_key>, apiSecret: <api_secret>, apiEndpoint: <api_endpoint>,
config: {timeout: <timeout>}});
```

### Users Module
Expand Down Expand Up @@ -63,13 +66,13 @@ userService.list({}).then(function(res) { console.log(JSON.stringify(res)); }).c
### Users KYC module

```node.js
const usersKYCService = kycSdk.services.usersKyc;
const usersKYCService = kycObj.services.usersKyc;
```

Submit KYC:

```node.js
usersKYCService.submitKyc({user_id:11003, first_name:'YOGESH', last_name:'SAWANT', birthdate:'29/07/1992', country:'INDIA', nationality:'INDIAN', document_id_number:'DMDPS9634C', document_id_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd1', selfie_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd2', ethereum_address:'0x04d39e0b112c20917868ffd5c42372ecc5df577b',estimated_participation_amount:'1.2',residence_proof_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd3',investor_proof_files_path: ['10/i/4ae058629d4b384edcda8decdfbf0da1', '10/i/4ae058629d4b384edcda8decdfbf0da2'], city:'pune',street_address:'hadapsar',postal_code:'411028',state:'maharashtra'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
usersKYCService.submitKyc({user_id:11003, first_name:'RAJESH', last_name:'KUMAR', birthdate:'29/07/1992', country:'INDIA', nationality:'INDIAN', document_id_number:'ADDHBDHBSH', document_id_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd1', selfie_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd2', ethereum_address:'0x04d39e0b112c20917868ffd5c42372ecc5df577b',estimated_participation_amount:'1.2',residence_proof_file_path:'10/i/4ae058629d4b384edcda8decdfbf0dd3',investor_proof_files_path: ['10/i/4ae058629d4b384edcda8decdfbf0da1', '10/i/4ae058629d4b384edcda8decdfbf0da2'], city:'pune',street_address:'hadapsar',postal_code:'411028',state:'maharashtra'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

List Users KYC:
Expand All @@ -81,7 +84,7 @@ usersKYCService.list().then(function(res) { console.log(JSON.stringify(res)); })
Get Users KYC

```node.js
usersKYCService.get({id:11003}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
usersKYCService.get({user_id:11003}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```


Expand Down Expand Up @@ -123,7 +126,7 @@ usersKYCService.getPresignedUrlPost({
### Users KYC details Module

```node.js
const usersKYCDetailsService = kycSdk.services.usersKycDetails,
const usersKYCDetailsService = kycObj.services.usersKycDetails;
```

Get user's kyc details
Expand All @@ -136,7 +139,7 @@ usersKYCDetailsService.get({user_id:11003}).then(function(res) { console.log(JSO


```node.js
const validatorService = kycSdk.services.validators;
const validatorService = kycObj.services.validators;
```

Verify ethereum address
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
12 changes: 11 additions & 1 deletion configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
"email": "mayur+67@ost.com"
},
"testResource": "/api/v2/users",
"signatureExpected": "c42188c53bfdf84e542a0a9c0a78d19c9f497c61e816f169e1907bc98477eb82"
"signatureExpected": "c42188c53bfdf84e542a0a9c0a78d19c9f497c61e816f169e1907bc98477eb82",
"getPreSignedUrlObj": {"files": {
"residence_proof": "application/pdf",
"investor_proof_file1": "application/pdf",
"investor_proof_file2": "application/pdf",
"document_id": "image/jpeg",
"selfie": "image/jpeg"
}},
"api_secret_for_testing_signature":"35f346e5ef825ed4499da98a6ac6b401"




}
25 changes: 16 additions & 9 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const queryString = require('qs')
const rootPrefix = ".."
, validate = require(rootPrefix + '/lib/validate')
, version = require(rootPrefix + '/package.json').version
, httpUserAgent = "ost-sdk-js " + version
, httpUserAgent = "ost-kyc-sdk-js " + version
;

let DEBUG = ( "true" === process.env.OST_SDK_DEBUG );
let DEBUG = ( "true" === process.env.OST_KYC_SDK_DEBUG );

/**
* Generate query signature
Expand Down Expand Up @@ -48,6 +48,7 @@ function alphabeticalSort(a, b) {
* @param {string} params.apiKey - api key
* @param {string} params.apiSecret - api secret
* @param {string} params.apiEndpoint - version specific api endpoint
* @param {obj} params.config - configularions like timeout
*
* @constructor
*/
Expand All @@ -71,6 +72,8 @@ const RequestKlass = function(params) {
}

oThis.apiEndpoint = params.apiEndpoint.replace(/\/$/, "");
var config = params.config || {};
oThis.timeOut = config.timeout * 1000 || 15000;

oThis._formatQueryParams = function (resource, queryParams) {
const oThis = this;
Expand Down Expand Up @@ -206,9 +209,16 @@ RequestKlass.prototype = {

});

request.on('socket', function (socket) {
socket.setTimeout(oThis.timeOut);
socket.on('timeout', function(e) {
onReject({"success":false,"err":{"code":"GATEWAY_TIMEOUT","internal_id":"TIMEOUT_ERROR","msg":"","error_data":[]}});
});
});

request.on('error', function (e) {

console.error('OST-SDK: Request error');
console.error('KYC-SDK: Request error');
console.error(e);
var parsedResponse = oThis._parseResponse(e);
if (parsedResponse.success) {
Expand All @@ -231,17 +241,14 @@ RequestKlass.prototype = {
* Parse response
*
* @param {string} responseData - Response data
* @param {object} response - Response object
* @param { object} response - Response object
*
* @private
*/
_parseResponse: function(responseData, response) {
var statusesHandledAtServers = [200, 400, 422, 500];
var statusesHandledAtServers = [200, 400, 401, 403, 404, 422, 429, 500];
if (!validate.isPresent(responseData) || statusesHandledAtServers.indexOf((response || {}).statusCode) < 0 ) {
switch ((response || {}).statusCode) {
case 429:
responseData = responseData || '{"success": false, "err": {"code": "TOO_MANY_REQUESTS", "internal_id": "SDK(TOO_MANY_REQUESTS)", "msg": "", "error_data":[]}}';
break;
case 502:
responseData = responseData || '{"success": false, "err": {"code": "BAD_GATEWAY", "internal_id": "SDK(BAD_GATEWAY)", "msg": "", "error_data":[]}}';
break;
Expand All @@ -259,7 +266,7 @@ RequestKlass.prototype = {
try {
var parsedResponse = JSON.parse(responseData);
} catch(e) {
//console.error('OST-SDK: Response parsing error');
//console.error('KYC-SDK: Response parsing error');
//console.error(e);
var parsedResponse = {"success": false, "err": {"code": "SOMETHING_WENT_WRONG", "internal_id": "SDK(SOMETHING_WENT_WRONG)", "msg": "Response parsing error", "error_data":[]}};
}
Expand Down
12 changes: 7 additions & 5 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const ValidateKlass = function() {};

ValidateKlass.prototype = {

pattern: /^[a-z\d\-\.]+$/i,

/**
* Check if parameter is present
*
Expand All @@ -25,7 +27,7 @@ ValidateKlass.prototype = {
* @public
*/
isPresent: function (param) {
return (typeof param !== 'undefined' && param !== null);
return (typeof param !== 'undefined' && param !== null && String(param).trim() !== '');
},

/**
Expand All @@ -35,10 +37,10 @@ ValidateKlass.prototype = {
*/
getId: function (params) {
const oThis = this;
if (oThis.isPresent(params.id)) {
if (oThis.isPresent(params.id) && oThis.pattern.test(params.id)) {
return params.id;
} else {
throw new Error('id missing in request params');
throw new Error('missing or invalid id in request params');
}
},

Expand All @@ -49,10 +51,10 @@ ValidateKlass.prototype = {
*/
getUserId: function (params) {
const oThis = this;
if(oThis.isPresent(params.user_id)){
if(oThis.isPresent(params.user_id)&& oThis.pattern.test(params.user_id)){
return params.user_id
} else{
throw new Error('user id missing in request params');
throw new Error('missing or invalid user id in request params');
}
}

Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
{
"name": "@ostdotcom/ost-kyc-sdk-js",
"version": "1.0.0",
"description": "KYC sdk",
"version": "2.0.0",
"description": "OST KYC sdk",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"OST",
"KYC",
"Javascript",
"Node.js",
"SDK"
],
"dependencies": {
"qs": "^6.5.2",
"query-string": "6.0.0"
"qs": "^6.5.2"
},
"devDependencies": {
"chai": "4.1.2",
"mocha": "5.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/OpenSTFoundation/kyc-sdk-js.git"
"url": "git+https://github.com/OpenSTFoundation/ost-kyc-sdk-js.git"
},
"author": "",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenSTFoundation/kyc-sdk-js/issues"
"url": "https://github.com/OpenSTFoundation/ost-kyc-sdk-js/issues"
},
"homepage": "https://github.com/OpenSTFoundation/kyc-sdk-js#readme"
"homepage": "https://github.com/OpenSTFoundation/ost-kyc-sdk-js#readme"
}
Loading

0 comments on commit a34e121

Please sign in to comment.