v12.0.0 - initial commit
This commit is contained in:
commit
e2c49ea43c
1145 changed files with 97211 additions and 0 deletions
58
packages/server/lib/sanctions.js
Normal file
58
packages/server/lib/sanctions.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
const _ = require('lodash/fp')
|
||||
const ofac = require('./ofac')
|
||||
const T = require('./time')
|
||||
const logger = require('./logger')
|
||||
const customers = require('./customers')
|
||||
|
||||
const sanctionStatus = {
|
||||
loaded: false,
|
||||
timestamp: null,
|
||||
}
|
||||
|
||||
const loadOrUpdateSanctions = () => {
|
||||
if (
|
||||
!sanctionStatus.loaded ||
|
||||
(sanctionStatus.timestamp && Date.now() > sanctionStatus.timestamp + T.day)
|
||||
) {
|
||||
logger.info('No sanction lists loaded. Loading sanctions...')
|
||||
return ofac
|
||||
.load()
|
||||
.then(() => {
|
||||
logger.info('OFAC sanction list loaded!')
|
||||
sanctionStatus.loaded = true
|
||||
sanctionStatus.timestamp = Date.now()
|
||||
})
|
||||
.catch(e => {
|
||||
logger.error("Couldn't load OFAC sanction list!", e)
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const checkByUser = (customerId, userToken) => {
|
||||
return Promise.all([
|
||||
loadOrUpdateSanctions(),
|
||||
customers.getCustomerById(customerId),
|
||||
]).then(([, customer]) => {
|
||||
const { firstName, lastName, dateOfBirth } = customer.idCardData
|
||||
const birthdate = _.replace(/-/g, '')(dateOfBirth)
|
||||
const ofacMatches = ofac.match({ firstName, lastName }, birthdate, {
|
||||
threshold: 0.85,
|
||||
fullNameThreshold: 0.95,
|
||||
debug: false,
|
||||
})
|
||||
const isOfacSanctioned = _.size(ofacMatches) > 0
|
||||
customers.updateCustomer(
|
||||
customerId,
|
||||
{ sanctions: !isOfacSanctioned },
|
||||
userToken,
|
||||
)
|
||||
|
||||
return { ofacSanctioned: isOfacSanctioned }
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkByUser,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue