diff --git a/src/cli/cmds/sumsub-cmds/applicant-details.ts b/src/cli/cmds/sumsub-cmds/applicant-details.ts index 945e717..6fc3bf4 100644 --- a/src/cli/cmds/sumsub-cmds/applicant-details.ts +++ b/src/cli/cmds/sumsub-cmds/applicant-details.ts @@ -8,22 +8,23 @@ dotenv.config(); const SUMSUB_BASE_URL = 'https://api.sumsub.com'; 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) => { - return yargs.positional('applicantId', { - describe: 'The applicant ID to query', + return yargs.positional('userId', { + describe: 'The user ID to query', 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}; var method = 'GET'; - var url = `/resources/applicants/${applicantId}/one` + var url = `/resources/applicants/-;externalUserId=${userId}/one` var headers = { 'Accept': 'application/json', @@ -39,20 +40,20 @@ function getApplicantDetails (applicantId: string | number) { } export const handler = async (argv: Arguments) => { - const applicantId = argv.applicantId as string; + const userId = argv.userId as string; - if (!applicantId) { - console.error('Applicant ID is required'); + if (!userId) { + throw new Error('User ID is required') } 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 delete response.data.requiredIdDocs; console.log('Applicant Data:', JSON.stringify(response.data, null, 2)); } 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)}`) } } diff --git a/src/index.ts b/src/index.ts index 923129d..88c7ca1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; // 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}; var method = 'post'; @@ -43,7 +43,7 @@ app.post('/generate-token', async (req, res) => { } try { - const response = await sumsubAxios(createAccessToken(userId, levelName, ttlInSecs)); + const response = await sumsubAxios(createAccessTokenRequest(userId, levelName, ttlInSecs)); console.log("Created token:\n", response.data); const { token } = response.data;