@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.
Files changed (54) hide show
  1. package/README.md +125 -18
  2. package/dist/commands/init.d.ts +0 -1
  3. package/dist/commands/init.d.ts.map +1 -1
  4. package/dist/commands/login.d.ts +8 -0
  5. package/dist/commands/login.d.ts.map +1 -0
  6. package/dist/commands/logout.d.ts +6 -0
  7. package/dist/commands/logout.d.ts.map +1 -0
  8. package/dist/commands/profile.d.ts +7 -0
  9. package/dist/commands/profile.d.ts.map +1 -0
  10. package/dist/commands/service-account.d.ts +1 -0
  11. package/dist/commands/service-account.d.ts.map +1 -1
  12. package/dist/commands/status.d.ts +8 -0
  13. package/dist/commands/status.d.ts.map +1 -0
  14. package/dist/commands/token.d.ts +1 -0
  15. package/dist/commands/token.d.ts.map +1 -1
  16. package/dist/lib/api-client.d.ts +0 -11
  17. package/dist/lib/api-client.d.ts.map +1 -1
  18. package/dist/lib/command-line.d.ts +176 -0
  19. package/dist/lib/command-line.d.ts.map +1 -0
  20. package/dist/lib/errors.d.ts +6 -0
  21. package/dist/lib/errors.d.ts.map +1 -1
  22. package/dist/lib/instance-command.d.ts +3 -0
  23. package/dist/lib/instance-command.d.ts.map +1 -0
  24. package/dist/lib/loadSixb.d.ts.map +1 -1
  25. package/dist/lib/profile-api-client.d.ts +6 -0
  26. package/dist/lib/profile-api-client.d.ts.map +1 -0
  27. package/dist/lib/profiles.d.ts +34 -0
  28. package/dist/lib/profiles.d.ts.map +1 -0
  29. package/dist/lib/runtime.d.ts.map +1 -1
  30. package/dist/lib/worker-registry.d.ts.map +1 -1
  31. package/dist/ui/index.d.ts +5 -5
  32. package/dist/ui/index.d.ts.map +1 -1
  33. package/package.json +14 -13
  34. package/src/commands/init.tsx +1 -13
  35. package/src/commands/login.tsx +196 -0
  36. package/src/commands/logout.tsx +36 -0
  37. package/src/commands/profile.tsx +101 -0
  38. package/src/commands/service-account.tsx +18 -15
  39. package/src/commands/status.tsx +93 -0
  40. package/src/commands/token.tsx +11 -8
  41. package/src/index.tsx +134 -156
  42. package/src/lib/api-client.ts +4 -65
  43. package/src/lib/command-line.ts +743 -0
  44. package/src/lib/errors.ts +13 -0
  45. package/src/lib/instance-command.ts +80 -0
  46. package/src/lib/loadSixb.ts +0 -2
  47. package/src/lib/profile-api-client.ts +38 -0
  48. package/src/lib/profiles.ts +262 -0
  49. package/src/lib/runtime.ts +7 -1
  50. package/src/lib/worker-registry.ts +7 -1
  51. package/src/ui/index.tsx +39 -140
  52. package/dist/commands/auth.d.ts +0 -8
  53. package/dist/commands/auth.d.ts.map +0 -1
  54. package/src/commands/auth.tsx +0 -96
@@ -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
- }