Update applicant-details CLI to use user ID
This commit is contained in:
parent
a1a0f8e3ba
commit
650e7f4b6a
@ -8,22 +8,22 @@ 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) {
|
function getApplicantDetails (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,14 +39,15 @@ 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');
|
console.error('User ID is required');
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await sumsubAxios(getApplicantDetails(applicantId));
|
const response = await sumsubAxios(getApplicantDetails(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;
|
||||||
@ -54,5 +55,6 @@ export const handler = async (argv: Arguments) => {
|
|||||||
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);
|
console.error('Failed to fetch applicant data:', error.response ? error.response.data : error.message);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user