@seamapi/cli 0.0.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -3
- package/bin/cli.d.ts +2 -0
- package/bin/cli.js +233 -0
- package/bin/cli.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/lib/blueprint.d.ts +6 -0
- package/lib/blueprint.js +37 -0
- package/lib/blueprint.js.map +1 -0
- package/lib/get-api-blueprint.d.ts +3 -0
- package/lib/get-api-blueprint.js +19 -0
- package/lib/get-api-blueprint.js.map +1 -0
- package/lib/get-command-blueprint-def.d.ts +2 -0
- package/lib/get-command-blueprint-def.js +11 -0
- package/lib/get-command-blueprint-def.js.map +1 -0
- package/lib/get-config-store.d.ts +2 -0
- package/lib/get-config-store.js +5 -0
- package/lib/get-config-store.js.map +1 -0
- package/lib/get-current-workspace-id.d.ts +1 -0
- package/lib/get-current-workspace-id.js +10 -0
- package/lib/get-current-workspace-id.js.map +1 -0
- package/lib/get-seam.d.ts +3 -0
- package/lib/get-seam.js +26 -0
- package/lib/get-seam.js.map +1 -0
- package/lib/get-server.d.ts +1 -0
- package/lib/get-server.js +7 -0
- package/lib/get-server.js.map +1 -0
- package/lib/interact-for-access-code.d.ts +3 -0
- package/lib/interact-for-access-code.js +19 -0
- package/lib/interact-for-access-code.js.map +1 -0
- package/lib/interact-for-acs-entrance.d.ts +1 -0
- package/lib/interact-for-acs-entrance.js +15 -0
- package/lib/interact-for-acs-entrance.js.map +1 -0
- package/lib/interact-for-acs-system.d.ts +1 -0
- package/lib/interact-for-acs-system.js +16 -0
- package/lib/interact-for-acs-system.js.map +1 -0
- package/lib/interact-for-acs-user.d.ts +1 -0
- package/lib/interact-for-acs-user.js +17 -0
- package/lib/interact-for-acs-user.js.map +1 -0
- package/lib/interact-for-action-attempt-poll.d.ts +2 -0
- package/lib/interact-for-action-attempt-poll.js +22 -0
- package/lib/interact-for-action-attempt-poll.js.map +1 -0
- package/lib/interact-for-array.d.ts +1 -0
- package/lib/interact-for-array.js +53 -0
- package/lib/interact-for-array.js.map +1 -0
- package/lib/interact-for-blueprint-object.d.ts +9 -0
- package/lib/interact-for-blueprint-object.js +235 -0
- package/lib/interact-for-blueprint-object.js.map +1 -0
- package/lib/interact-for-command-params.d.ts +5 -0
- package/lib/interact-for-command-params.js +11 -0
- package/lib/interact-for-command-params.js.map +1 -0
- package/lib/interact-for-command-selection.d.ts +2 -0
- package/lib/interact-for-command-selection.js +76 -0
- package/lib/interact-for-command-selection.js.map +1 -0
- package/lib/interact-for-connected-account.d.ts +1 -0
- package/lib/interact-for-connected-account.js +20 -0
- package/lib/interact-for-connected-account.js.map +1 -0
- package/lib/interact-for-custom-metadata.d.ts +6 -0
- package/lib/interact-for-custom-metadata.js +71 -0
- package/lib/interact-for-custom-metadata.js.map +1 -0
- package/lib/interact-for-device.d.ts +1 -0
- package/lib/interact-for-device.js +15 -0
- package/lib/interact-for-device.js.map +1 -0
- package/lib/interact-for-login.d.ts +1 -0
- package/lib/interact-for-login.js +39 -0
- package/lib/interact-for-login.js.map +1 -0
- package/lib/interact-for-resource.d.ts +11 -0
- package/lib/interact-for-resource.js +13 -0
- package/lib/interact-for-resource.js.map +1 -0
- package/lib/interact-for-server-selection.d.ts +1 -0
- package/lib/interact-for-server-selection.js +41 -0
- package/lib/interact-for-server-selection.js.map +1 -0
- package/lib/interact-for-timestamp.d.ts +1 -0
- package/lib/interact-for-timestamp.js +10 -0
- package/lib/interact-for-timestamp.js.map +1 -0
- package/lib/interact-for-use-remote-api-defs.d.ts +1 -0
- package/lib/interact-for-use-remote-api-defs.js +25 -0
- package/lib/interact-for-use-remote-api-defs.js.map +1 -0
- package/lib/interact-for-user-identity.d.ts +1 -0
- package/lib/interact-for-user-identity.js +15 -0
- package/lib/interact-for-user-identity.js.map +1 -0
- package/lib/interact-for-workspace-id.d.ts +1 -0
- package/lib/interact-for-workspace-id.js +31 -0
- package/lib/interact-for-workspace-id.js.map +1 -0
- package/lib/types.d.ts +5 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/util/ellipsis.d.ts +1 -0
- package/lib/util/ellipsis.js +6 -0
- package/lib/util/ellipsis.js.map +1 -0
- package/lib/util/request-seam-api.d.ts +4 -0
- package/lib/util/request-seam-api.js +28 -0
- package/lib/util/request-seam-api.js.map +1 -0
- package/lib/util/with-loading.d.ts +1 -0
- package/lib/util/with-loading.js +14 -0
- package/lib/util/with-loading.js.map +1 -0
- package/lib/validate-token.d.ts +1 -0
- package/lib/validate-token.js +19 -0
- package/lib/validate-token.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.js +3 -0
- package/lib/version.js.map +1 -0
- package/package.json +44 -18
- package/src/bin/cli.ts +265 -0
- package/src/index.ts +4 -1
- package/src/lib/blueprint.ts +53 -0
- package/src/lib/get-api-blueprint.ts +27 -0
- package/src/lib/get-command-blueprint-def.ts +15 -0
- package/src/lib/get-config-store.ts +5 -0
- package/src/lib/get-current-workspace-id.ts +11 -0
- package/src/lib/get-seam.ts +43 -0
- package/src/lib/get-server.ts +9 -0
- package/src/lib/interact-for-access-code.ts +25 -0
- package/src/lib/interact-for-acs-entrance.ts +16 -0
- package/src/lib/interact-for-acs-system.ts +17 -0
- package/src/lib/interact-for-acs-user.ts +21 -0
- package/src/lib/interact-for-action-attempt-poll.ts +35 -0
- package/src/lib/interact-for-array.ts +61 -0
- package/src/lib/interact-for-blueprint-object.ts +274 -0
- package/src/lib/interact-for-command-params.ts +22 -0
- package/src/lib/interact-for-command-selection.ts +107 -0
- package/src/lib/interact-for-connected-account.ts +24 -0
- package/src/lib/interact-for-custom-metadata.ts +89 -0
- package/src/lib/interact-for-device.ts +15 -0
- package/src/lib/interact-for-login.ts +53 -0
- package/src/lib/interact-for-resource.ts +34 -0
- package/src/lib/interact-for-server-selection.ts +46 -0
- package/src/lib/interact-for-timestamp.ts +10 -0
- package/src/lib/interact-for-use-remote-api-defs.ts +27 -0
- package/src/lib/interact-for-user-identity.ts +16 -0
- package/src/lib/interact-for-workspace-id.ts +37 -0
- package/src/lib/types.ts +6 -0
- package/src/lib/util/ellipsis.ts +4 -0
- package/src/lib/util/request-seam-api.ts +43 -0
- package/src/lib/util/with-loading.ts +16 -0
- package/src/lib/validate-token.ts +28 -0
- package/src/lib/version.ts +3 -0
- package/src/lib/index.ts +0 -1
- package/src/lib/todo.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seamapi/cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A command line interface (CLI) for interacting with the Seam API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"module": "index.js",
|
|
17
|
-
"
|
|
17
|
+
"bin": {
|
|
18
|
+
"seam": "./bin/cli.js"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"./bin/cli.js",
|
|
22
|
+
"./src/bin/cli.ts"
|
|
23
|
+
],
|
|
18
24
|
"keywords": [
|
|
19
|
-
"
|
|
25
|
+
"cli",
|
|
26
|
+
"node",
|
|
27
|
+
"seam"
|
|
20
28
|
],
|
|
21
29
|
"homepage": "https://github.com/seamapi/cli",
|
|
22
30
|
"bugs": "https://github.com/seamapi/cli/issues",
|
|
@@ -30,6 +38,7 @@
|
|
|
30
38
|
"index.js",
|
|
31
39
|
"index.js.map",
|
|
32
40
|
"index.d.ts",
|
|
41
|
+
"bin",
|
|
33
42
|
"lib",
|
|
34
43
|
"src",
|
|
35
44
|
"!test",
|
|
@@ -38,29 +47,30 @@
|
|
|
38
47
|
"scripts": {
|
|
39
48
|
"build": "npm run build:entrypoints",
|
|
40
49
|
"prebuild": "tsx src/index.ts",
|
|
41
|
-
"postbuild": "node ./index.js",
|
|
50
|
+
"postbuild": "concurrently --raw --group 'node ./index.js' 'node ./bin/cli.js --version'",
|
|
42
51
|
"build:entrypoints": "npm run build:ts",
|
|
43
52
|
"build:ts": "tsc --project tsconfig.build.json",
|
|
44
|
-
"prebuild:ts": "del 'index.*' lib",
|
|
53
|
+
"prebuild:ts": "del 'index.*' bin lib",
|
|
45
54
|
"postbuild:ts": "tsc-alias --project tsconfig.build.json",
|
|
46
55
|
"typecheck": "tsc",
|
|
47
|
-
"test": "
|
|
56
|
+
"test": "vitest run --coverage",
|
|
48
57
|
"pretest": "tsx src/index.ts",
|
|
49
|
-
"test:update": "
|
|
50
|
-
"test:watch": "
|
|
51
|
-
"test:debug": "
|
|
58
|
+
"test:update": "vitest run --update",
|
|
59
|
+
"test:watch": "vitest",
|
|
60
|
+
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
52
61
|
"lint": "eslint .",
|
|
53
62
|
"postlint": "prettier --check --ignore-path .gitignore .",
|
|
63
|
+
"prepack": "tsx ./prepack.ts",
|
|
54
64
|
"postversion": "git push --follow-tags",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
65
|
+
"seam": "tsx src/bin/cli.ts",
|
|
66
|
+
"inspect": "tsx --inspect src/bin/cli.ts",
|
|
57
67
|
"format": "prettier --write --ignore-path .gitignore .",
|
|
58
68
|
"preformat": "eslint --fix .",
|
|
59
|
-
"report": "
|
|
69
|
+
"report": "vitest run --coverage"
|
|
60
70
|
},
|
|
61
71
|
"engines": {
|
|
62
72
|
"node": ">=22.11.0",
|
|
63
|
-
"npm": ">=10.
|
|
73
|
+
"npm": ">=10.0.0"
|
|
64
74
|
},
|
|
65
75
|
"devEngines": {
|
|
66
76
|
"runtime": {
|
|
@@ -69,24 +79,40 @@
|
|
|
69
79
|
},
|
|
70
80
|
"packageManager": {
|
|
71
81
|
"name": "npm",
|
|
72
|
-
"version": "^11.
|
|
82
|
+
"version": "^11.0.0 || ^10.0.0"
|
|
73
83
|
}
|
|
74
84
|
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@seamapi/blueprint": "^1.1.0",
|
|
87
|
+
"@seamapi/http": "^2.2.0",
|
|
88
|
+
"chalk": "^6.0.0",
|
|
89
|
+
"command-line-usage": "^7.0.4",
|
|
90
|
+
"configstore": "^8.0.0",
|
|
91
|
+
"minimist": "^1.2.8",
|
|
92
|
+
"nanospinner": "^1.2.2",
|
|
93
|
+
"open": "^11.0.0",
|
|
94
|
+
"prompts": "^2.4.2"
|
|
95
|
+
},
|
|
75
96
|
"devDependencies": {
|
|
97
|
+
"@seamapi/types": "^1.983.0",
|
|
98
|
+
"@types/command-line-usage": "^5.0.4",
|
|
99
|
+
"@types/minimist": "^1.2.5",
|
|
76
100
|
"@types/node": "^24.10.9",
|
|
77
|
-
"
|
|
78
|
-
"
|
|
101
|
+
"@types/prompts": "^2.4.9",
|
|
102
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
103
|
+
"concurrently": "^10.0.4",
|
|
79
104
|
"del-cli": "^7.0.0",
|
|
80
105
|
"eslint": "^9.31.0",
|
|
81
106
|
"eslint-plugin-import": "^2.32.0",
|
|
82
107
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
83
108
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
109
|
+
"execa": "^10.0.0",
|
|
84
110
|
"jiti": "^2.4.2",
|
|
85
|
-
"landlubber": "^2.0.0",
|
|
86
111
|
"neostandard": "^0.13.0",
|
|
87
112
|
"prettier": "^3.0.0",
|
|
88
113
|
"tsc-alias": "^1.8.2",
|
|
89
114
|
"tsx": "^4.6.2",
|
|
90
|
-
"typescript": "^6.0.3"
|
|
115
|
+
"typescript": "^6.0.3",
|
|
116
|
+
"vitest": "^4.1.10"
|
|
91
117
|
}
|
|
92
118
|
}
|
package/src/bin/cli.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { randomBytes } from 'node:crypto'
|
|
3
|
+
import { isDeepStrictEqual as isEqual } from 'node:util'
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import commandLineUsage from 'command-line-usage'
|
|
7
|
+
import parseArgs, { type ParsedArgs } from 'minimist'
|
|
8
|
+
import prompts from 'prompts'
|
|
9
|
+
|
|
10
|
+
import { getApiBlueprint } from 'lib/get-api-blueprint.js'
|
|
11
|
+
import { getConfigStore } from 'lib/get-config-store.js'
|
|
12
|
+
import { getServer } from 'lib/get-server.js'
|
|
13
|
+
import { interactForActionAttemptPoll } from 'lib/interact-for-action-attempt-poll.js'
|
|
14
|
+
import { interactForCommandParams } from 'lib/interact-for-command-params.js'
|
|
15
|
+
import { interactForCommandSelection } from 'lib/interact-for-command-selection.js'
|
|
16
|
+
import { interactForLogin } from 'lib/interact-for-login.js'
|
|
17
|
+
import { interactForServerSelection } from 'lib/interact-for-server-selection.js'
|
|
18
|
+
import { interactForUseRemoteApiDefs } from 'lib/interact-for-use-remote-api-defs.js'
|
|
19
|
+
import { interactForWorkspaceId } from 'lib/interact-for-workspace-id.js'
|
|
20
|
+
import type { ContextHelpers } from 'lib/types.js'
|
|
21
|
+
import { RequestSeamApi } from 'lib/util/request-seam-api.js'
|
|
22
|
+
import { validateToken } from 'lib/validate-token.js'
|
|
23
|
+
import seamapiCliVersion from 'lib/version.js'
|
|
24
|
+
|
|
25
|
+
const sections = [
|
|
26
|
+
{
|
|
27
|
+
header: 'Seam CLI',
|
|
28
|
+
content:
|
|
29
|
+
'Every seam command is interactive and will prompt you for any missing required properties with helpful suggestions. To avoid automatic behavior, pass -y ',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
header: 'Options',
|
|
33
|
+
optionList: [
|
|
34
|
+
{
|
|
35
|
+
name: 'help',
|
|
36
|
+
description: 'Display this help guide.',
|
|
37
|
+
alias: 'h',
|
|
38
|
+
type: Boolean,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
header: 'Command List Examples',
|
|
44
|
+
content: [
|
|
45
|
+
{ name: 'seam', summary: 'Interactively select commands to execute.' },
|
|
46
|
+
{ name: 'seam login', summary: 'Login to Seam.' },
|
|
47
|
+
{ name: 'seam select workspace', summary: 'Select your workspace.' },
|
|
48
|
+
{
|
|
49
|
+
name: 'seam connect-webviews create',
|
|
50
|
+
summary: 'Create a connect webview to connect devices.',
|
|
51
|
+
},
|
|
52
|
+
{ name: 'seam devices list', summary: 'List devices in your workspace.' },
|
|
53
|
+
{
|
|
54
|
+
name: 'seam locks unlock-door {bold --device-id} $MY_DOOR',
|
|
55
|
+
summary: 'Unlock a lock.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "seam access-codes create {bold --code} '1234' {bold --name} 'My Code'",
|
|
59
|
+
summary: 'Create an access code.',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'seam access-codes list {bold --device-id} $MY_DOOR',
|
|
63
|
+
summary: 'List you access codes.',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
async function cli(args: ParsedArgs) {
|
|
70
|
+
const config = getConfigStore()
|
|
71
|
+
|
|
72
|
+
if (args['help'] || args['h']) {
|
|
73
|
+
const usage = commandLineUsage(sections)
|
|
74
|
+
console.log(usage)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (args['version']) {
|
|
79
|
+
console.log(seamapiCliVersion)
|
|
80
|
+
process.exit(0)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
args._[0] === 'config' &&
|
|
85
|
+
args._[1] === 'set' &&
|
|
86
|
+
args._[2] === 'fake-server'
|
|
87
|
+
) {
|
|
88
|
+
const randomstring = randomBytes(5).toString('hex')
|
|
89
|
+
const fakeApiUrl = `https://${randomstring}.fakeseamconnect.seam.vc`
|
|
90
|
+
|
|
91
|
+
config.set('server', fakeApiUrl)
|
|
92
|
+
console.log(`Server URL set to ${fakeApiUrl}`)
|
|
93
|
+
|
|
94
|
+
config.set(`${getServer()}.pat`, `seam_apikey1_token`)
|
|
95
|
+
console.log(`PAT set to use fakeseamconnect with "seam_apikey1_token"`)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
!config.get(`${getServer()}.pat`) &&
|
|
101
|
+
args._[0] !== 'login' &&
|
|
102
|
+
!isEqual(args._, ['select', 'server'])
|
|
103
|
+
) {
|
|
104
|
+
console.log(`Not logged in. Please run "seam login"`)
|
|
105
|
+
process.exit(1)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
args._ = args._.map((arg) => arg.toLowerCase().replace(/_/g, '-'))
|
|
109
|
+
for (const k in args) {
|
|
110
|
+
args[k.toLowerCase().replace(/-/g, '_')] = args[k]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const use_remote_api_defs =
|
|
114
|
+
args['remote_api_defs'] ?? config.get('use_remote_api_defs')
|
|
115
|
+
|
|
116
|
+
const blueprint = await getApiBlueprint(use_remote_api_defs ?? false)
|
|
117
|
+
|
|
118
|
+
const commandParams: Record<string, any> = {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether or not to auto-select first option
|
|
122
|
+
*/
|
|
123
|
+
const is_interactive = args['y'] !== true
|
|
124
|
+
|
|
125
|
+
const ctx: ContextHelpers = {
|
|
126
|
+
blueprint,
|
|
127
|
+
is_interactive,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const k in args) {
|
|
131
|
+
if (k === '_') continue
|
|
132
|
+
const v = args[k]
|
|
133
|
+
delete args[k]
|
|
134
|
+
args[k.replace(/-/g, '_')] = v
|
|
135
|
+
commandParams[k.replace(/-/g, '_')] = v
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const selectedCommand = await interactForCommandSelection(args._, ctx)
|
|
139
|
+
if (isEqual(selectedCommand, ['login'])) {
|
|
140
|
+
if (args['server']) {
|
|
141
|
+
config.set('server', args['server'])
|
|
142
|
+
config.delete('current_workspace_id')
|
|
143
|
+
}
|
|
144
|
+
if (args['token']) {
|
|
145
|
+
const token = String(args['token']).trim()
|
|
146
|
+
await validateToken(token, args['workspace_id'])
|
|
147
|
+
config.set(`${getServer()}.pat`, token)
|
|
148
|
+
config.delete('current_workspace_id')
|
|
149
|
+
}
|
|
150
|
+
if (args['workspace_id']) {
|
|
151
|
+
config.set(`current_workspace_id`, args['workspace_id'])
|
|
152
|
+
}
|
|
153
|
+
if (args['token'] || args['workspace_id'] || args['server']) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
await interactForLogin()
|
|
157
|
+
return
|
|
158
|
+
} else if (isEqual(selectedCommand, ['logout'])) {
|
|
159
|
+
config.delete('pat')
|
|
160
|
+
console.log('Logged out!')
|
|
161
|
+
return
|
|
162
|
+
} else if (isEqual(selectedCommand, ['config', 'reveal-location'])) {
|
|
163
|
+
console.log(config.path)
|
|
164
|
+
return
|
|
165
|
+
} else if (isEqual(selectedCommand, ['config', 'use-remote-api-defs'])) {
|
|
166
|
+
await interactForUseRemoteApiDefs()
|
|
167
|
+
return
|
|
168
|
+
} else if (isEqual(selectedCommand, ['select', 'workspace'])) {
|
|
169
|
+
await interactForWorkspaceId()
|
|
170
|
+
return
|
|
171
|
+
} else if (isEqual(selectedCommand, ['events', 'list'])) {
|
|
172
|
+
if (!commandParams['since']) {
|
|
173
|
+
const date = new Date()
|
|
174
|
+
date.setMonth(date.getMonth() - 1)
|
|
175
|
+
commandParams['since'] = date.toISOString()
|
|
176
|
+
}
|
|
177
|
+
} else if (isEqual(selectedCommand, ['select', 'server'])) {
|
|
178
|
+
if (args['server']) {
|
|
179
|
+
config.set('server', args['server'])
|
|
180
|
+
config.delete('current_workspace_id')
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
await interactForServerSelection()
|
|
184
|
+
return
|
|
185
|
+
} else if (isEqual(selectedCommand, ['health', 'get-health'])) {
|
|
186
|
+
await RequestSeamApi({
|
|
187
|
+
path: '/health/get_health',
|
|
188
|
+
params: {},
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
// TODO - do this using the OpenAPI spec for the command rather than
|
|
194
|
+
// explicitly encoding the property names
|
|
195
|
+
if (commandParams['accepted_providers']) {
|
|
196
|
+
commandParams['accepted_providers'] =
|
|
197
|
+
commandParams['accepted_providers'].split(',')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Hit 'back' on a top-level command path, so we start again
|
|
201
|
+
const lastCommandPath = selectedCommand.slice(-1)[0]
|
|
202
|
+
if (lastCommandPath === '[Back]') {
|
|
203
|
+
return await cli({
|
|
204
|
+
...args,
|
|
205
|
+
_: [],
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const params = await interactForCommandParams(
|
|
210
|
+
{ command: selectedCommand, params: commandParams },
|
|
211
|
+
ctx,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if (params === '[Back]') {
|
|
215
|
+
const previousCommands = [...selectedCommand]
|
|
216
|
+
previousCommands.pop()
|
|
217
|
+
return await cli({
|
|
218
|
+
...args,
|
|
219
|
+
_: previousCommands,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const apiPath = `/${selectedCommand.join('/').replace(/-/g, '_')}`
|
|
224
|
+
|
|
225
|
+
if (apiPath.includes('/events/list') && params.between) {
|
|
226
|
+
delete params.since
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const response = await RequestSeamApi({
|
|
230
|
+
path: apiPath,
|
|
231
|
+
params,
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
if (response.data?.connect_webview) {
|
|
235
|
+
await handleConnectWebviewResponse(response.data.connect_webview)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (response.data?.action_attempt) {
|
|
239
|
+
interactForActionAttemptPoll(response.data.action_attempt)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const handleConnectWebviewResponse = async (connect_webview: any) => {
|
|
244
|
+
const url = connect_webview.url
|
|
245
|
+
|
|
246
|
+
if (process.env['INSIDE_WEB_BROWSER'] !== '1') {
|
|
247
|
+
const { action } = await prompts({
|
|
248
|
+
type: 'confirm',
|
|
249
|
+
name: 'action',
|
|
250
|
+
message: 'Would you like to open the webview in your browser?',
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
if (action) {
|
|
254
|
+
const { default: open } = await import('open')
|
|
255
|
+
await open(url)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
cli(parseArgs(process.argv.slice(2), { string: ['code'] })).catch((e) => {
|
|
261
|
+
console.log(chalk.red(`CLI Error: ${e.toString()}\n${e.stack}`))
|
|
262
|
+
if (e.toString().includes('object Object')) {
|
|
263
|
+
console.log(e)
|
|
264
|
+
}
|
|
265
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// This package is a CLI, not a library: nothing here is part of a public API.
|
|
2
|
+
// The entrypoint exists so that importing the package resolves to a module
|
|
3
|
+
// instead of failing, for consumers that depend on it to get the bin.
|
|
4
|
+
export default null
|