@affinidi/affinidi-uaf-service-lib
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

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'
// SDK initialization
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')
// SDK initialization
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 // should have the value, we will be checking the value is there or not.
  // UUID can be unique indetifier for the third party.
  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.

  1. validateLoanDataSchemaFormat

    // Success
    { success: true, DataValidationErros: [] }
    // Error
    [
      { 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' },
    ]
  2. validatePublicKeyExistOnPath

    // In case the file exists at the given path
    Response: {
      success: true
    }
    // or, else
    Error: {
      error: 'File not found / Directory does not exists'
    }
  3. prefillUserData

    // in case we get success
    { success: true, DataValidationErros: [] }
    
    // in case of error
    {
     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]

/*
 * usersData -> user data from thrid party vendor and it must be the format which is given by affinidi.
 * sessiontoken -> session token would be the end user token which is generated by UAF while end user joureny.
 * apiKey -> issuer API key which is given by affinidi.
 * store the affinidi public key in any of the folder and get the absolute path.
 */

// SDK initialization
const uafService = new UafServiceIntegration()

// step 1:  needed to check the user date schema format by using SDK
const validateUserData = await uafService.validateLoanDataSchemaFormat(usersData)
if (validateUserData && validateUserData.success === false) {
  throw new OperationError('UBSB-2', { message: 'user data validation error' })
}

// step 2: needed to check the public key path exist by using SDK
const pathArray = __dirname.split('/')
pathArray.splice(-2)
const currentPath = pathArray.join('/')
const publicKeyAbsolutePath = `${currentPath}/secrets/affinidi.public.txt`
await uafService.validatePublicKeyExistOnPath(publicKeyAbsolutePath)

// step 3: sent the data to affinidi by using SDK
const prefillData = await uafService.prefillUserData({
  endUserSessionToken: sessiontoken,
  issuerApiKey: apiKey,
  usersData: usersData,
  publicKeyPath: publicKeyAbsolutePath,
})

Frameworks and tools

  1. Typescript
  2. Express for REST APIs
  3. tsoa for OpenAPI spec generation
  4. dotenv for .env file configuration
  5. pino for logging
  6. ESLint for code analysis
  7. husky for git hooks
  8. jest for testing

Readme

Keywords

Package Sidebar

Install

npm i @affinidi/affinidi-uaf-service-lib

Weekly Downloads

0

Version

1.6.0

License

ISC

Unpacked Size

42.5 kB

Total Files

23

Last publish

Collaborators

  • rohitjjw
  • maratsh-affinidi
  • robert-affinidi
  • standemchuk