Comparing version 1.0.6 to 1.0.7
23
index.js
@@ -12,6 +12,10 @@ const fs = require('fs'); | ||
path: '/tmp', | ||
xml: 'sdn.xml' | ||
xml: 'sdn.xml', | ||
fetch: (url, opts) => fetch(url.opts) | ||
}, | ||
config: (opts) => { | ||
self.opts = Object.assign(self.opts, opts); | ||
}, | ||
init: async (opts = self.opts) => { | ||
self.opts = Object.assign(self.opts, opts); | ||
self.config(opts); | ||
var {force} = self.opts; | ||
@@ -29,3 +33,3 @@ | ||
return self; | ||
return self.db; | ||
}, | ||
@@ -36,3 +40,3 @@ fn: (url) => { | ||
fetch: (url = self.url) => { | ||
return fetch(url).then(res => { | ||
return self.opts.fetch(url).then(res => { | ||
var fn = self.fn(url); | ||
@@ -57,11 +61,10 @@ const dest = fs.createWriteStream(fn); | ||
}, | ||
search: (cust, fn = self.db) => { | ||
if (!fn) fn = self.db = self.fn(self.opts.xml); | ||
search: async (cust, fn = self.db) => { | ||
if (!fn) fn = await self.init(); | ||
if (!cust.search_type) cust.search_type = 'individual'; | ||
// input data clean | ||
// clean input data | ||
cust = lc(cust); | ||
// read database file line by line | ||
var lineReader = readline.createInterface({ | ||
@@ -73,3 +76,3 @@ input: fs.createReadStream(fn) | ||
return self.init().then(() => new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
lineReader.on('line', line => { | ||
@@ -81,3 +84,3 @@ try { collector(line) } | ||
.on('close', () => resolve(ret)); | ||
})); | ||
}); | ||
@@ -84,0 +87,0 @@ function collector(line) { |
{ | ||
"name": "ofac", | ||
"version": "1.0.6", | ||
"description": "A module to facilitate OFAC searches", | ||
"version": "1.0.7", | ||
"description": "A module to facilitate local OFAC searches", | ||
"main": "index.js", | ||
@@ -14,3 +14,5 @@ "scripts": { | ||
"keywords": [ | ||
"ofac", "kyc", "compliance" | ||
"ofac", | ||
"kyc", | ||
"compliance" | ||
], | ||
@@ -17,0 +19,0 @@ "author": "ekkis <e@arix.com>", |
@@ -127,3 +127,3 @@ [![npm version](https://badge.fury.io/js/ofac.svg)](https://badge.fury.io/js/ofac) | ||
## Example | ||
## Examples | ||
@@ -133,8 +133,5 @@ For more extensive examples please see the test suite | ||
const ofac = require('ofac'); | ||
ofac.init() | ||
.then(() => { | ||
var cust = {id: 'J287011', country: 'Colombia'}; | ||
return ofac.search(cust); | ||
}) | ||
.then(console.log); | ||
var cust = {id: 'J287011', country: 'Colombia'}; | ||
ofac.search(cust).then(console.log); | ||
``` | ||
@@ -167,1 +164,9 @@ will produce something like: | ||
}] | ||
``` | ||
## Licence | ||
MIT | ||
## Support | ||
For support post an issue on Github or reach out to me on Telegram. | ||
My username is [@ekkis](https://t.me/ekkis) |
@@ -32,3 +32,22 @@ var fs = require('fs'); | ||
describe('OFAC', () => { | ||
describe('Archive', () => { | ||
describe('Archive fetch', () => { | ||
var zip = '/tmp/sdn.xml.zip'; | ||
before(() => { | ||
function pipe(dest) { | ||
var rs = fs.createReadStream('t/sdn.xml.zip') | ||
rs.pipe(dest); | ||
} | ||
ofac.config({ | ||
fetch: () => Promise.resolve({body: {pipe}}) | ||
}) | ||
if (fs.existsSync(zip)) fs.unlinkSync(zip); | ||
}); | ||
it('File created', () => { | ||
return ofac.fetch('sdn.xml.zip').then(fn => { | ||
assert.ok(fn == zip, 'Incorrect file name') | ||
assert.ok(fs.existsSync(fn, 'File was not fetched')) | ||
}) | ||
}) | ||
}) | ||
describe('Archive extraction', () => { | ||
var zip = 't/sdn.xml.zip', fn = 'sdn.xml'; | ||
@@ -54,15 +73,10 @@ before(() => { | ||
describe('Search', () => { | ||
it('Uses internal path', async () => { | ||
it('Searched by id/country', async () => { | ||
var cust = {id: 'J287011', country: 'Colombia'}; | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected); | ||
}) | ||
it('Searched by id/country', async () => { | ||
var cust = {id: 'J287011', country: 'Colombia'}; | ||
var actual = await ofac.search(cust, fn); | ||
assert.deepEqual(actual, expected); | ||
}); | ||
it('Searched by id/country with type', async () => { | ||
var cust = {id: 'J287011', id_type: 'Passport', country: 'Colombia'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected); | ||
@@ -72,3 +86,3 @@ }); | ||
var cust = {id: 'J287011', id_type: 'Cedula No.', country: 'Colombia'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, []); | ||
@@ -78,3 +92,3 @@ }); | ||
var cust = {firstName: 'Helmer', lastName: 'HERRERA BUITRAGO'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected, 'Name search differs'); | ||
@@ -84,3 +98,3 @@ }); | ||
var cust = {firstName: 'Helmer', lastName: 'herrera buitrago'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected, 'Name search differs'); | ||
@@ -90,3 +104,3 @@ }); | ||
var cust = {firstName: 'Helmer', lastName: 'herrera-buitrago'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected, 'Name search differs'); | ||
@@ -96,5 +110,13 @@ }); | ||
var cust = {firstName: 'Helmer', lastName: 'pacho'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust); | ||
assert.deepEqual(actual, expected, 'Name search differs'); | ||
}); | ||
it('Uses external path', async () => { | ||
var moved = fn.replace(/xml$/, 'moved.xml') | ||
fs.renameSync(fn, moved) | ||
assert.ok(fs.existsSync(moved), 'File move failed') | ||
var cust = {id: 'J287011', country: 'Colombia'}; | ||
var actual = await ofac.search(cust, '/tmp/sdn.moved.xml'); | ||
assert.deepEqual(actual, expected); | ||
}) | ||
it('Bad XML produces exception', (done) => { | ||
@@ -109,3 +131,3 @@ var cust = {id: 'J287011', country: 'Colombia'}; | ||
var cust = {firstName: 'XX', lastName: 'XX'}; | ||
var actual = await ofac.search(cust, fn); | ||
var actual = await ofac.search(cust, '/tmp/sdn.moved.xml'); | ||
assert.deepEqual(actual, [], 'Empty array expected'); | ||
@@ -112,0 +134,0 @@ }); |
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
26101
8
260
170