-
Notifications
You must be signed in to change notification settings - Fork 0
/
Onfido.ts
51 lines (40 loc) · 1.23 KB
/
Onfido.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require('fs')
const { Onfido, Region } = require('@onfido/api')
const { config: configDotenv } = require('dotenv')
configDotenv()
const onfido = new Onfido({
apiToken: process.env.API_TOKEN,
region: Region.EU,
})
async function generateApplicantId() {
const applicant = await onfido.applicant.create({
firstName: 'Web',
lastName: 'SDK',
})
return applicant.id
}
async function generateSdkToken(applicantId: string) {
return await onfido.sdkToken.generate({
applicantId: `${applicantId}`,
})
}
async function createWorkflowRun(applicantId: string) {
const workflowRun = await onfido.workflowRun.create({
applicantId: `${applicantId}`,
workflowId: `${process.env.WORKFLOW_ID}`,
})
return workflowRun.id
}
async function writeEnvFile(sdkToken: string, workflowRunId: string) {
const envContent = `SDK_TOKEN=${sdkToken}\nWORKFLOW_RUN_ID=${workflowRunId}`
fs.appendFileSync('.env', envContent, 'utf-8')
}
generateApplicantId().then(async (applicantId) => {
const sdkToken = await generateSdkToken(applicantId)
const workflowRunId = await createWorkflowRun(applicantId)
await writeEnvFile(sdkToken, workflowRunId)
console.log({
sdkToken: sdkToken,
workflowRunId: workflowRunId,
})
})