-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathregister.ts
More file actions
33 lines (28 loc) · 1.17 KB
/
register.ts
File metadata and controls
33 lines (28 loc) · 1.17 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
import { AppType, PagedApp } from '@smartthings/core-sdk'
import { APICommand, selectFromList, SelectFromListConfig } from '@smartthings/cli-lib'
import { inspect } from 'util'
export default class AppRegisterCommand extends APICommand<typeof AppRegisterCommand.flags> {
static description = 'send request to app target URL to confirm existence and authorize lifecycle events'
static flags = APICommand.flags
static args = [{
name: 'id',
description: 'the app id',
}]
async run(): Promise<void> {
const config: SelectFromListConfig<PagedApp> = {
primaryKeyName: 'appId',
sortKeyName: 'displayName',
listTableFieldDefinitions: ['displayName', 'appType', 'appId'],
}
const id = await selectFromList<PagedApp>(this, config, {
preselectedId: this.args.id,
listItems: async () => (await Promise.all([
this.client.apps.list({ appType: AppType.WEBHOOK_SMART_APP }),
this.client.apps.list({ appType: AppType.API_ONLY }),
])).flat(),
promptMessage: 'Select an app to register.',
})
const result = await this.client.apps.register(id)
this.log(`Registration request sent to app ${id}. Check server log for confirmation URL: ${inspect(result)}`)
}
}