lamassu-server/lib/compliance-external.js
Sérgio Salgado 6ba0632067 feat: implement sumsub API module
feat: add 3rd party services splash screen
feat: add sumsub as a configurable 3rd party service
feat: sumsub config loader
fix: small fixes

feat: add external validation as a compliance trigger
feat: add external validation route in l-s
feat: add external validation graphql module
feat: integrate sumsub SDK

feat: improve sumsub form to allow adding multiple applicant levels with enhanced UX
feat: added support for array fields in FormRenderer
feat: allow external validation triggers to dynamically use levels setup in the services page
fix: multiple small fixes

feat: get external compliance customer info
fix: small fixes

feat: add informational card in customer profile regarding external service info

feat: send external customer data for machine trigger verification

feat: restrictions to the creation of custom info requests and external validation triggers
fix: allow for a single applicant level to be setup

fix: account instance access

fix: small fixes

fix: development-only log
2024-06-11 11:25:58 +01:00

55 lines
1.8 KiB
JavaScript

const _ = require('lodash/fp')
const configManager = require('./new-config-manager')
const ph = require('./plugin-helper')
const getPlugin = settings => {
const pluginCodes = ['sumsub']
const enabledAccounts = _.filter(_plugin => _plugin.enabled, _.map(code => ph.getAccountInstance(settings.accounts[code], code), pluginCodes))
if (_.isEmpty(enabledAccounts)) {
throw new Error('No external compliance services are active. Please check your 3rd party service configuration')
}
if (_.size(enabledAccounts) > 1) {
throw new Error('Multiple external compliance services are active. Please check your 3rd party service configuration')
}
const account = _.head(enabledAccounts)
const plugin = ph.load(ph.COMPLIANCE, account.code, account.enabled)
return ({ plugin, account })
}
const createApplicant = (settings, customer, applicantLevel) => {
const { plugin } = getPlugin(settings)
const { id } = customer
return plugin.createApplicant({ levelName: applicantLevel, externalUserId: id })
}
const getApplicant = (settings, customer) => {
try {
const { plugin } = getPlugin(settings)
const { id } = customer
return plugin.getApplicant({ externalUserId: id }, false)
.then(res => ({
provider: plugin.CODE,
...res.data
}))
.catch(() => ({}))
} catch (e) {
return {}
}
}
const createApplicantAccessToken = (settings, customerId, triggerId) => {
const triggers = configManager.getTriggers(settings.config)
const trigger = _.find(it => it.id === triggerId)(triggers)
const { plugin } = getPlugin(settings)
return plugin.createApplicantAccessToken({ levelName: trigger.externalServiceApplicantLevel, userId: customerId })
.then(r => r.data.token)
}
module.exports = {
createApplicant,
getApplicant,
createApplicantAccessToken
}