abs-client
Advanced tools
Comparing version 0.0.2-alpha to 0.0.3-alpha
221
lib/index.js
@@ -1,35 +0,208 @@ | ||
const fetch = require('node-fetch') | ||
const rp = require('request-promise-native') | ||
const defaultConfig = { | ||
apiServerAddress: 'http://localhost:9443', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
const URL = require('url').URL | ||
const fetchJson = async (uri, options) => await (await fetch(uri, options)).json() | ||
function init(receivedConfig) { | ||
const config = { | ||
...defaultConfig, | ||
...receivedConfig | ||
} | ||
const balances = async (basepath, customerId) => ( | ||
await fetchJson( | ||
basepath + '/account', | ||
{ | ||
async function doGet(route, query = {}, additionalHeaders = {}) { | ||
let uri = new URL(config.apiServerAddress + route) | ||
if (query !== {}) { | ||
for (let key in query) { | ||
uri.searchParams.append(key, query[key]) | ||
} | ||
} | ||
const options = { | ||
method: 'GET', | ||
uri: uri.href, | ||
json: true, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
'X-USERID': customerId | ||
...config.headers, | ||
...additionalHeaders | ||
} | ||
} | ||
) | ||
).items | ||
const balance = async (basepath, customerId, accountId) => ( | ||
await fetchJson( | ||
basepath + '/account/' + accountId, | ||
{ | ||
method: 'GET', | ||
try { | ||
return await rp(options) | ||
} catch (err) { | ||
return { result: false, route, err } | ||
} | ||
} | ||
async function doPost(route, body = {}, additionalHeaders = {}) { | ||
const options = { | ||
method: 'POST', | ||
uri: config.apiServerAddress + route, | ||
json: true, | ||
body, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
'X-USERID': customerId | ||
...config.headers, | ||
...additionalHeaders | ||
} | ||
} | ||
) | ||
) | ||
try { | ||
return await rp(options) | ||
} catch (err) { | ||
return { result: false, route, err } | ||
} | ||
} | ||
module.exports = { | ||
balances, | ||
balance, | ||
async function doPut(route, body = {}, additionalHeaders = {}) { | ||
const options = { | ||
method: 'PUT', | ||
uri: config.apiServerAddress + route, | ||
json: true, | ||
body, | ||
headers: { | ||
...config.headers, | ||
...additionalHeaders | ||
} | ||
} | ||
try { | ||
return await rp(options) | ||
} catch (err) { | ||
return { result: false, route, err } | ||
} | ||
} | ||
// {"originAccount":"OCBC002","description":"TTT","value":"1000","currency":"SGD"}" | ||
async function transferToOmnibus(originAccount, description, value, currency) { | ||
return await doPost('/transfers:toOmnibus', { originAccount, description, value, currency }) | ||
} | ||
// {"remoteAccount":"OCBC002","description":"aaaaaaa","value":"1000","currency":"SGD"}" | ||
async function transferFromOmnibus(remoteAccount, description, value, currency) { | ||
return await doPost('/transfers:fromOmnibus', { remoteAccount, description, value, currency }) | ||
} | ||
// {"description":"aaaaaaa","value":"1000","currency":"SGD"}" | ||
async function addBalanceToOmnibus(description, value, currency) { | ||
return await doPost('/omnibus:addBalance', description, value, currency) | ||
} | ||
async function balances(customerID) { | ||
return await doGet('/account', {}, { 'X-USERID': customerID }) | ||
} | ||
async function balance(customerID, accountID) { | ||
return await doGet(`/account/${accountID}`, {}, { 'X-USERID': customerID }) | ||
} | ||
async function setBankInfo(name, branch, BIC, address, countryCode, defaultCurrency, description) { | ||
return await doPost(`/bankInfo`, { name, branch, BIC, address, countryCode, defaultCurrency, description }) | ||
} | ||
async function getBankInfo() { | ||
return await doGet(`/bankInfo`) | ||
} | ||
async function createCustomer({ | ||
firstName, | ||
lastName, | ||
companyName, | ||
customerId, | ||
customerType, | ||
description, | ||
countryCode, | ||
natLegalIdentifier, | ||
intlLegalIdentifier, | ||
}) { | ||
return await doPost(`/customer`, { | ||
firstName, | ||
lastName, | ||
companyName, | ||
customerId, | ||
customerType, | ||
description, | ||
countryCode, | ||
natLegalIdentifier, | ||
intlLegalIdentifier, | ||
}, { 'X-USERID': customerId }) | ||
} | ||
async function createCustomer({ | ||
firstName, | ||
lastName, | ||
companyName, | ||
customerId, | ||
customerType, | ||
description, | ||
countryCode, | ||
natLegalIdentifier, | ||
intlLegalIdentifier, | ||
}) { | ||
return await doPost(`/customer`, { | ||
firstName, | ||
lastName, | ||
companyName, | ||
customerId, | ||
customerType, | ||
description, | ||
countryCode, | ||
natLegalIdentifier, | ||
intlLegalIdentifier, | ||
}, { 'X-USERID': customerId }) | ||
} | ||
async function getCustomer(queryObj, customerID) { | ||
return await doGet(`/customer`, queryObj, { 'X-USERID': customerID }) | ||
} | ||
async function createAccount({ | ||
customerID, | ||
accountID, | ||
accountNumber, | ||
balance, | ||
currency, | ||
description, | ||
// type, | ||
}) { | ||
return await doPost(`/account`, { | ||
customerID, | ||
accountID, | ||
accountNumber, | ||
balance, | ||
currency, | ||
description, | ||
// type, | ||
}) | ||
} | ||
async function linkAccount({ | ||
customerID, | ||
accountID, | ||
}) { | ||
console.log({ | ||
customerID, | ||
accountID, | ||
}) | ||
return await doPost(`/account:link`, { | ||
customerID, | ||
accountID, | ||
// customerID: accountID, | ||
// accountID: customerID, | ||
}) | ||
} | ||
return { | ||
transferToOmnibus, | ||
transferFromOmnibus, | ||
addBalanceToOmnibus, | ||
balances, | ||
balance, | ||
setBankInfo, | ||
getBankInfo, | ||
createCustomer, | ||
getCustomer, | ||
createAccount, | ||
linkAccount, | ||
} | ||
} | ||
module.exports = init |
{ | ||
"name": "abs-client", | ||
"version": "0.0.2-alpha", | ||
"version": "0.0.3-alpha", | ||
"description": "Client that interacts functions for the abs.", | ||
@@ -10,4 +10,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"node-fetch": "^2.1.2" | ||
"request": "^2.88.0", | ||
"request-promise-native": "^1.0.7" | ||
} | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
6421
192
2
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedrequest-promise-native@1.0.9(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
- Removednode-fetch@^2.1.2
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)