chore: use monorepo organization
This commit is contained in:
parent
deaf7d6ecc
commit
a687827f7e
1099 changed files with 8184 additions and 11535 deletions
79
packages/server/lib/compliance.js
Normal file
79
packages/server/lib/compliance.js
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
const _ = require('lodash/fp')
|
||||
const uuid = require('uuid')
|
||||
|
||||
const logger = require('./logger')
|
||||
const db = require('./db')
|
||||
const ofac = require('./ofac/index')
|
||||
|
||||
function logSanctionsMatch (deviceId, customer, sanctionsId, alias) {
|
||||
const sql = `insert into sanctions_logs
|
||||
(id, device_id, sanctioned_id, sanctioned_alias_id, sanctioned_alias_full_name, customer_id)
|
||||
values
|
||||
($1, $2, $3, $4, $5, $6)`
|
||||
|
||||
return db.none(sql, [uuid.v4(), deviceId, sanctionsId, alias.id, alias.fullName, customer.id])
|
||||
}
|
||||
|
||||
function logSanctionsMatches (deviceId, customer, results) {
|
||||
const logAlias = resultId => alias => logSanctionsMatch(deviceId, customer, resultId, alias)
|
||||
const logResult = result => _.map(logAlias(result.id), result.aliases)
|
||||
|
||||
return Promise.all(_.flatMap(logResult, results))
|
||||
}
|
||||
|
||||
function matchOfac (deviceId, customer) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
// Probably because we haven't asked for ID yet
|
||||
if (!_.isPlainObject(customer.idCardData)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const nameParts = {
|
||||
firstName: customer.idCardData.firstName,
|
||||
lastName: customer.idCardData.lastName
|
||||
}
|
||||
|
||||
if (_.some(_.isNil, _.values(nameParts))) {
|
||||
logger.error(new Error(`Insufficient idCardData while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
|
||||
const birthDate = customer.idCardData.dateOfBirth
|
||||
|
||||
if (_.isNil(birthDate)) {
|
||||
logger.error(new Error(`No birth date while matching OFAC for: ${customer.id}`))
|
||||
return true
|
||||
}
|
||||
|
||||
const options = {
|
||||
threshold: 0.85,
|
||||
fullNameThreshold: 0.95,
|
||||
debug: false
|
||||
}
|
||||
|
||||
const results = ofac.match(nameParts, birthDate, options)
|
||||
|
||||
return logSanctionsMatches(deviceId, customer, results)
|
||||
.then(() => !_.isEmpty(results))
|
||||
})
|
||||
}
|
||||
|
||||
function validateOfac (deviceId, customer) {
|
||||
if (customer.sanctionsOverride === 'blocked') return Promise.resolve(false)
|
||||
if (customer.sanctionsOverride === 'verified') return Promise.resolve(true)
|
||||
|
||||
return matchOfac(deviceId, customer)
|
||||
.then(didMatch => !didMatch)
|
||||
}
|
||||
|
||||
function validationPatch (deviceId, customer) {
|
||||
return validateOfac(deviceId, customer)
|
||||
.then(sanctions =>
|
||||
_.isNil(customer.sanctions) || customer.sanctions !== sanctions ?
|
||||
{ sanctions } :
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {validationPatch}
|
||||
Loading…
Add table
Add a link
Reference in a new issue