Affinidi UAF Service Lib [ Backend Integration ]
Affinidi UAF Service library helps to validate and sent the data to affinidi UAF application.
Installation
npm i @affinidi/affinidi-uaf-service-lib --save
import the file into the application where the data sent to affinidi applcation.
Example for typescript for importing the library.
import { UafServiceIntegration } from '@affinidi/affinidi-uaf-service-lib/dist'
const uafService = new UafServiceIntegration()
You should have 2 environemnt variables before proceeding further. it has to be added in the env file
AFFINIDI_UAF_BASEURL=<base url given by affinidi>
AFFINIDI_UAF_PREFILL_ENDPOINT=<API end point given by affinidi>
Example for javascript for importing the library.
var uafLib = require('@affinidi/affinidi-uaf-service-lib/dist')
const uafService = new uafLib.UafServiceIntegration()
There is 3 functionalites/steps to helps to sent the data to UAF applcation.
1. validateLoanDataSchemaFormat -> validate the data schema provided by vendor.
2. validatePublicKeyExistOnPath -> validate the public key exist on the abosolute path provided by developer.
3. prefillUserData -> It will sent the data to the affinidi.
UserData Object format should be like below.
{
uuid?: string
affinidiPartnerId?: string
userContactInformation?: {
name?: string
personalEmailAddress?: string
mobile?: string
}
userProfileInformation: {
dob?: string
gender?: string
panNumber?: string
nameAsInPan?: string
pfUAN?: string
aadharNumber?: string
nameAsInAadhar?: string
mothersName?: string
fatherOrSpouseName?: string
relationshipStatus?: string
education?: { fileInput?: string; qualification?: string; filePassword?: string }
currentAddress?: {
addressLine1?: string
addressLine2?: string
pincode?: string
city?: string
state?: string
country?: string
permanentAddress?: boolean
fileInput?: string
filePassword?: string
}
permanentAddress?: {
addressLine1?: string
addressLine2?: string
pincode?: string
city?: string
state?: string
country?: string
fileInput?: string
filePassword?: string
}
bankAccounts?: {
ifsc?: string
accountNumber?: string
}
cibilScore?: number
}
employment: {
employmentType?: string
workStatus?: string
employerName?: string
employerType?: string
employeeId?: string
currentExperience?: string
noticePeriod?: string
totalEmiAmount?: string
currentlyWorking?: string
designation?: string
joiningDate?: string
industry?: string
jobSector?: string
supervisorDetails?: {
name?: string
phoneNumber?: string
emailId?: string
}
epfo?: string
monthlySalary?: string
salaryDocuments?: { files?: SalaryFiles[] }
salaryMode?: string
salarySlipDocumentUri?: string
servingNoticePeriod?: string
lastWorkingDate?: string
tenureInMonths?: number
totalWorkExperienceInMonths?: string
workEmailAddress?: string
workAddress?: {
addressLine1?: string
addressLine2?: string
pincode?: string
city?: string
state?: string
country?: string
}
}
}
Salary File Object Format
SalaryFiles {
fileType?: string
fileInput?: string
filePassword?: string
}
Success and Error Response for the each functionality.
-
validateLoanDataSchemaFormat
{ success: true, DataValidationErros: [] }
[
{ key: 'Joining Date', error: 'please enter date in DD/MM/YYYY format' },
{ key: 'Pincode', error: 'please give valid 6 digit pincode' },
{ key: 'Salary mode', error: 'salary mode should be cash or bank' },
{ key: 'Monthly salary', error: 'please give valid salary in integer' },
]
-
validatePublicKeyExistOnPath
Response: {
success: true
}
Error: {
error: 'File not found / Directory does not exists'
}
-
prefillUserData
{ success: true, DataValidationErros: [] }
{
success: false,
DataValidationErros: [
{ key: 'Joining Date', error: 'please enter date in DD/MM/YYYY format' },
{ key: 'Pincode', error: 'please give valid 6 digit pincode' },
{ key: 'Salary mode', error: 'salary mode should be cash or bank' },
{ key: 'Monthly salary', error: 'please give valid salary in integer' },
]
}
Example [typescript]
const uafService = new UafServiceIntegration()
const validateUserData = await uafService.validateLoanDataSchemaFormat(usersData)
if (validateUserData && validateUserData.success === false) {
throw new OperationError('UBSB-2', { message: 'user data validation error' })
}
const pathArray = __dirname.split('/')
pathArray.splice(-2)
const currentPath = pathArray.join('/')
const publicKeyAbsolutePath = `${currentPath}/secrets/affinidi.public.txt`
await uafService.validatePublicKeyExistOnPath(publicKeyAbsolutePath)
const prefillData = await uafService.prefillUserData({
endUserSessionToken: sessiontoken,
issuerApiKey: apiKey,
usersData: usersData,
publicKeyPath: publicKeyAbsolutePath,
})
Frameworks and tools
- Typescript
- Express for REST APIs
tsoa for OpenAPI spec generation
dotenv for .env file configuration
pino for logging
ESLint for code analysis
husky for git hooks
jest for testing