Update applicant-details CLI to use user ID (#4)

Part of [Sumsub KYC integration in onboarding app](https://www.notion.so/Sumsub-KYC-integration-in-onboarding-app-607b598c9c1d4d12adc71725e2ab5e7e)

Reviewed-on: #4
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-07-31 08:14:51 +00:00 committed by nabarun
parent a1a0f8e3ba
commit a349c4622d
2 changed files with 14 additions and 13 deletions

View File

@ -8,22 +8,23 @@ dotenv.config();
const SUMSUB_BASE_URL = 'https://api.sumsub.com'; const SUMSUB_BASE_URL = 'https://api.sumsub.com';
const SUMSUB_APP_TOKEN = process.env.SUMSUB_APP_TOKEN || ''; const SUMSUB_APP_TOKEN = process.env.SUMSUB_APP_TOKEN || '';
export const command = 'applicant-details [applicantId]'; export const command = 'applicant-details [userId]';
export const desc = 'Get applicant details.'; export const desc = 'Get applicant details by user ID.';
export const builder = (yargs: any) => { export const builder = (yargs: any) => {
return yargs.positional('applicantId', { return yargs.positional('userId', {
describe: 'The applicant ID to query', describe: 'The user ID to query',
type: 'string', type: 'string',
}); });
}; };
function getApplicantDetails (applicantId: string | number) { // https://docs.sumsub.com/reference/get-applicant-data-via-externaluserid
function getApplicantDetailsRequest (userId: string) {
const config: any = { baseURL: SUMSUB_BASE_URL}; const config: any = { baseURL: SUMSUB_BASE_URL};
var method = 'GET'; var method = 'GET';
var url = `/resources/applicants/${applicantId}/one` var url = `/resources/applicants/-;externalUserId=${userId}/one`
var headers = { var headers = {
'Accept': 'application/json', 'Accept': 'application/json',
@ -39,20 +40,20 @@ function getApplicantDetails (applicantId: string | number) {
} }
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const applicantId = argv.applicantId as string; const userId = argv.userId as string;
if (!applicantId) { if (!userId) {
console.error('Applicant ID is required'); throw new Error('User ID is required')
} }
try { try {
const response = await sumsubAxios(getApplicantDetails(applicantId)); const response = await sumsubAxios(getApplicantDetailsRequest(userId));
// Exclude this key because the includedCountries and docSets data is not required // Exclude this key because the includedCountries and docSets data is not required
delete response.data.requiredIdDocs; delete response.data.requiredIdDocs;
console.log('Applicant Data:', JSON.stringify(response.data, null, 2)); console.log('Applicant Data:', JSON.stringify(response.data, null, 2));
} catch (error: any) { } catch (error: any) {
console.error('Failed to fetch applicant data:', error.response ? error.response.data : error.message); throw new Error(`Failed to fetch applicant data: ${JSON.stringify(error.response ? error.response.data : error.message)}`)
} }
} }

View File

@ -11,7 +11,7 @@ const DEFAULT_KYC_LEVEL = process.env.KYC_LEVEL || 'basic-kyc-level';
const DEFAULT_TOKEN_TTL_IN_SECS = process.env.TTL_IN_SECS || 600; const DEFAULT_TOKEN_TTL_IN_SECS = process.env.TTL_IN_SECS || 600;
// https://developers.sumsub.com/api-reference/#access-tokens-for-sdks // https://developers.sumsub.com/api-reference/#access-tokens-for-sdks
function createAccessToken (externalUserId: string, levelName: string, ttlInSecs: number) { function createAccessTokenRequest (externalUserId: string, levelName: string, ttlInSecs: number) {
const config: any = { baseURL: SUMSUB_BASE_URL}; const config: any = { baseURL: SUMSUB_BASE_URL};
var method = 'post'; var method = 'post';
@ -43,7 +43,7 @@ app.post('/generate-token', async (req, res) => {
} }
try { try {
const response = await sumsubAxios(createAccessToken(userId, levelName, ttlInSecs)); const response = await sumsubAxios(createAccessTokenRequest(userId, levelName, ttlInSecs));
console.log("Created token:\n", response.data); console.log("Created token:\n", response.data);
const { token } = response.data; const { token } = response.data;