@sixb/cli 0.1.6 → 0.1.7
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 +125 -18
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/logout.d.ts +6 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/profile.d.ts +7 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/service-account.d.ts +1 -0
- package/dist/commands/service-account.d.ts.map +1 -1
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/token.d.ts +1 -0
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/lib/api-client.d.ts +0 -11
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +176 -0
- package/dist/lib/command-line.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +6 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/instance-command.d.ts +3 -0
- package/dist/lib/instance-command.d.ts.map +1 -0
- package/dist/lib/loadSixb.d.ts.map +1 -1
- package/dist/lib/profile-api-client.d.ts +6 -0
- package/dist/lib/profile-api-client.d.ts.map +1 -0
- package/dist/lib/profiles.d.ts +34 -0
- package/dist/lib/profiles.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/index.d.ts +5 -5
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +14 -13
- package/src/commands/init.tsx +1 -13
- package/src/commands/login.tsx +196 -0
- package/src/commands/logout.tsx +36 -0
- package/src/commands/profile.tsx +101 -0
- package/src/commands/service-account.tsx +18 -15
- package/src/commands/status.tsx +93 -0
- package/src/commands/token.tsx +11 -8
- package/src/index.tsx +134 -156
- package/src/lib/api-client.ts +4 -65
- package/src/lib/command-line.ts +743 -0
- package/src/lib/errors.ts +13 -0
- package/src/lib/instance-command.ts +80 -0
- package/src/lib/loadSixb.ts +0 -2
- package/src/lib/profile-api-client.ts +38 -0
- package/src/lib/profiles.ts +262 -0
- package/src/lib/runtime.ts +7 -1
- package/src/lib/worker-registry.ts +7 -1
- package/src/ui/index.tsx +39 -140
- package/dist/commands/auth.d.ts +0 -8
- package/dist/commands/auth.d.ts.map +0 -1
- package/src/commands/auth.tsx +0 -96
package/src/commands/auth.tsx
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { getProjectInfo } from "@sixb/client"
|
|
2
|
-
import {
|
|
3
|
-
createCliSixbClient,
|
|
4
|
-
resolveApiClientConfig,
|
|
5
|
-
SixbApiError,
|
|
6
|
-
unwrapSixbApiResult,
|
|
7
|
-
} from "../lib/api-client"
|
|
8
|
-
import { KeyValueResultView, renderStatic } from "../ui"
|
|
9
|
-
|
|
10
|
-
export interface AuthCommandOptions {
|
|
11
|
-
readonly action?: string
|
|
12
|
-
readonly apiUrl?: string
|
|
13
|
-
readonly token?: string
|
|
14
|
-
readonly json?: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function runAuth(options: AuthCommandOptions = {}) {
|
|
18
|
-
const action = options.action ?? "status"
|
|
19
|
-
if (action !== "status") {
|
|
20
|
-
throw new Error("Usage: sixb auth status")
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const config = resolveApiClientConfig(options)
|
|
24
|
-
if (!config.token) {
|
|
25
|
-
await renderStatus({
|
|
26
|
-
authenticated: false,
|
|
27
|
-
apiUrl: config.apiUrl,
|
|
28
|
-
apiUrlSource: config.apiUrlSource,
|
|
29
|
-
message: "No API token found. Set SIXB_API_TOKEN or pass --token.",
|
|
30
|
-
json: options.json,
|
|
31
|
-
})
|
|
32
|
-
process.exitCode = 1
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const client = createCliSixbClient(config)
|
|
37
|
-
try {
|
|
38
|
-
const project = unwrapSixbApiResult(await getProjectInfo({ client }))
|
|
39
|
-
await renderStatus({
|
|
40
|
-
authenticated: true,
|
|
41
|
-
apiUrl: config.apiUrl,
|
|
42
|
-
apiUrlSource: config.apiUrlSource,
|
|
43
|
-
tokenSource: config.tokenSource,
|
|
44
|
-
projectId: project.id,
|
|
45
|
-
json: options.json,
|
|
46
|
-
})
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (error instanceof SixbApiError && (error.status === 401 || error.status === 403)) {
|
|
49
|
-
await renderStatus({
|
|
50
|
-
authenticated: false,
|
|
51
|
-
apiUrl: config.apiUrl,
|
|
52
|
-
apiUrlSource: config.apiUrlSource,
|
|
53
|
-
tokenSource: config.tokenSource,
|
|
54
|
-
message: error.message,
|
|
55
|
-
json: options.json,
|
|
56
|
-
})
|
|
57
|
-
process.exitCode = 1
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
throw error
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function renderStatus(input: {
|
|
66
|
-
readonly authenticated: boolean
|
|
67
|
-
readonly apiUrl: string
|
|
68
|
-
readonly apiUrlSource: string
|
|
69
|
-
readonly tokenSource?: string
|
|
70
|
-
readonly projectId?: string
|
|
71
|
-
readonly message?: string
|
|
72
|
-
readonly json?: boolean
|
|
73
|
-
}) {
|
|
74
|
-
if (input.json) {
|
|
75
|
-
const { json: _json, ...payload } = input
|
|
76
|
-
console.log(JSON.stringify(payload, null, 2))
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const items = [{ label: "API", value: `${input.apiUrl} (${input.apiUrlSource})` }]
|
|
81
|
-
if (input.projectId) {
|
|
82
|
-
items.push({ label: "Project", value: input.projectId })
|
|
83
|
-
}
|
|
84
|
-
if (input.tokenSource) {
|
|
85
|
-
items.push({ label: "Token", value: input.tokenSource })
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
await renderStatic(
|
|
89
|
-
<KeyValueResultView
|
|
90
|
-
title={input.authenticated ? "Authenticated" : "Not authenticated"}
|
|
91
|
-
titleColor={input.authenticated ? "green" : "red"}
|
|
92
|
-
items={items}
|
|
93
|
-
message={input.message}
|
|
94
|
-
/>
|
|
95
|
-
)
|
|
96
|
-
}
|