-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
61 lines (53 loc) · 1.75 KB
/
Copy pathutils.ts
File metadata and controls
61 lines (53 loc) · 1.75 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
import { user } from '@roll-network/api'
import { ClientPool } from '@roll-network/api-client'
import { InteractionType, SDKPool } from '@roll-network/auth-sdk'
import inquirer from 'inquirer'
import config, { platformUserConfig } from './config.js'
export const generateClientPool = async (config_: typeof config) => {
const sdkPool = new SDKPool(config_)
await sdkPool.getSDK(InteractionType.ClientCredentials).generateToken()
const clientPool = new ClientPool(
{ baseUrl: process.env.API_URL, redactErrorData: false },
sdkPool,
)
return { sdkPool, clientPool }
}
export const generateMasqueradeTokenClient = async () => {
const { clientPool, sdkPool } = await generateClientPool(platformUserConfig)
const answers = await inquirer.prompt([
{
type: 'input',
name: 'userType',
message: 'User Type (discord, telegram)',
},
{
type: 'input',
name: 'platformUserId',
message: 'User ID from the external platform',
},
])
const userResp = await user.createPlatformUser(
clientPool.getClient(InteractionType.ClientCredentials).call,
{
userType: answers.userType,
platformUserId: answers.platformUserId,
},
)
const masqueradeToken = await user.getUserMasqueradeToken(
clientPool.getClient(InteractionType.ClientCredentials).call,
{
userId: userResp.userID,
},
)
const clientToken = await sdkPool
.getSDK(InteractionType.ClientCredentials)
.getToken()
if (!clientToken) {
throw new Error('Client token is undefined.')
}
await sdkPool.getSDK(InteractionType.MasqueradeToken).generateToken({
clientToken: clientToken.access_token,
masqueradeToken: masqueradeToken.token,
})
return clientPool.getClient(InteractionType.MasqueradeToken)
}