-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathsetup.ts
More file actions
66 lines (58 loc) · 2.63 KB
/
setup.ts
File metadata and controls
66 lines (58 loc) · 2.63 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { existsSync, realpathSync } from 'fs'
import prompts from 'prompts'
import { TellerConfig, defaultTellerConfig } from '../../types/integrations/teller'
import { updateConfig } from '../../common/config'
import { IntegrationId } from '../../types/integrations'
import { logInfo, logError } from '../../common/logging'
export default async () => {
try {
console.log('\nThis script will walk you through setting up the Teller integration. Follow these steps:')
console.log('\n\t1. Visit https://teller.io')
console.log('\t2. Click \'Get Started\'')
console.log('\t3. Fill out the form')
console.log('\t4. Find the application ID, and download the certificate and private key')
console.log('\t5. Answer the following questions:\n')
const credentials = await prompts([
{
type: 'text',
name: 'name',
message: 'What would you like to call this integration?',
initial: 'Teller',
validate: (s: string) =>
1 < s.length && s.length <= 64 ? true : 'Must be between 2 and 64 characters in length.'
},
{
type: 'text',
name: 'pathCertificate',
message: 'Path to Certificate',
validate: (s: string) => s.length && existsSync(s) ? true : 'Must enter path to certificate file.'
},
{
type: 'text',
name: 'pathPrivateKey',
message: 'Path to Private Key',
validate: (s: string) => s.length && existsSync(s) ? true : 'Must enter path to private key file.'
},
{
type: 'text',
name: 'appId',
message: 'Application ID',
validate: (s: string) => s.length && s.startsWith('app_') ? true : 'Must enter Application ID from Teller.'
}
])
updateConfig(config => {
const tellerConfig = (config.integrations[IntegrationId.Teller] as TellerConfig) || defaultTellerConfig
tellerConfig.name = credentials.name
tellerConfig.pathCertificate = realpathSync(credentials.pathCertificate)
tellerConfig.pathPrivateKey = realpathSync(credentials.pathPrivateKey)
tellerConfig.appId = credentials.appId
config.integrations[IntegrationId.Teller] = tellerConfig
return config
})
logInfo('Successfully set up Teller Integration.')
return true
} catch (e) {
logError('Unable to set up Teller Integration.', e)
return false
}
}