Skip to content

Commit a489d66

Browse files
sigmachiralityindentclaude
authored
refactor: bump nodes-sdk-alpha and refactor image commands (#262)
Co-authored-by: Indent <noreply@indent.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 633588c commit a489d66

21 files changed

Lines changed: 11630 additions & 6903 deletions

bun.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@formatjs/intl-segmenter": "^12.1.0",
2424
"@inkjs/ui": "^1.0.0",
2525
"@inquirer/prompts": "^8.2.0",
26-
"@sfcompute/nodes-sdk-alpha": "0.1.0-alpha.27",
26+
"@sfcompute/nodes-sdk-alpha": "0.1.0-alpha.31",
2727
"@types/ms": "^0.7.34",
2828
"async-retry": "^1.3.3",
2929
"axios": "^1.8.4",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function main() {
8989

9090
if (!exchangeAccountId) {
9191
const client = await apiClient(config.auth_token);
92-
const { data } = await client.GET("/v0/me");
92+
const { data } = await client.GET("/v1/account/me", {});
9393
if (data?.id) {
9494
exchangeAccountId = data.id;
9595
saveConfig({ ...config, account_id: data.id });

src/lib/contracts/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function listContracts(
7878
if (!response.ok) {
7979
switch (response.status) {
8080
case 400:
81-
return logAndQuit(`Bad Request: ${error?.message}`);
81+
return logAndQuit(`Bad Request: ${error?.error?.message}`);
8282
case 401:
8383
return await logSessionTokenExpiredAndQuit();
8484
default:

src/lib/images/get.tsx

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@ import Link from "ink-link";
1010
import { apiClient } from "../../apiClient.ts";
1111
import { logAndQuit } from "../../helpers/errors.ts";
1212
import { formatDate } from "../../helpers/format-time.ts";
13+
import type { components } from "../../schema.ts";
1314
import { Row } from "../Row.tsx";
1415

1516
dayjs.extend(utc);
1617
dayjs.extend(advanced);
1718
dayjs.extend(timezone);
1819

20+
type Image = components["schemas"]["sfc-api_ImageListEntry"];
21+
type Download = components["schemas"]["sfc-api_ImageDownloadResponse"];
22+
1923
function ImageDisplay({
2024
image,
2125
download,
2226
}: {
23-
image: {
24-
name: string;
25-
id: string;
26-
upload_status: string;
27-
sha256_hash: string | null;
28-
};
29-
download: { url: string; expires_at: number } | null;
27+
image: Image;
28+
download: Download | null;
3029
}) {
31-
const expiresAt = download?.expires_at
32-
? new Date(download.expires_at * 1000)
33-
: null;
30+
const expiresAt = download ? new Date(download.expires_at * 1000) : null;
3431
const isExpired = expiresAt ? expiresAt < new Date() : false;
3532

3633
return (
@@ -43,7 +40,7 @@ function ImageDisplay({
4340

4441
<Box paddingX={1} flexDirection="column">
4542
<Row head="Status: " value={formatStatusInk(image.upload_status)} />
46-
{image.sha256_hash && <Row head="SHA256: " value={image.sha256_hash} />}
43+
{image.sha256 && <Row head="SHA256: " value={image.sha256} />}
4744
{download && (
4845
<>
4946
<Row
@@ -92,50 +89,48 @@ function formatStatusInk(status: string): React.ReactElement {
9289
return <Text color="cyan">Completed</Text>;
9390
case "failed":
9491
return <Text color="red">Failed</Text>;
92+
case "revoked":
93+
return <Text color="red">Revoked</Text>;
9594
default:
9695
return <Text dimColor>Unknown</Text>;
9796
}
9897
}
9998

100-
const get = new Command("get")
101-
.description("Get image details and download URL")
102-
.argument("<id>", "Image ID or name")
103-
.option("--json", "Output JSON")
104-
.action(async (id, opts) => {
105-
const client = await apiClient();
99+
export function createGet() {
100+
return new Command("get")
101+
.alias("show")
102+
.description("Get image details and download URL")
103+
.argument("<id>", "Image ID or name")
104+
.option("--json", "Output JSON")
105+
.action(async (id, opts) => {
106+
const client = await apiClient();
106107

107-
const { data: image, response } = await client.GET("/v2/images/{id}", {
108-
params: { path: { id } },
109-
});
110-
if (!response.ok || !image) {
111-
logAndQuit(
112-
`Failed to get image: ${response.status} ${response.statusText}`,
108+
const { data: image, response } = await client.GET(
109+
"/preview/v2/images/{id}",
110+
{ params: { path: { id } } },
113111
);
114-
}
115-
116-
// Fetch download URL if image is completed
117-
let download = null;
118-
if (image.upload_status === "completed") {
119-
const { data: downloadData, response: downloadResponse } =
120-
await client.GET("/v2/images/{id}/download", {
121-
params: { path: { id } },
122-
});
123-
if (downloadResponse.ok && downloadData) {
124-
download = downloadData;
112+
if (!response.ok || !image) {
113+
logAndQuit(
114+
`Failed to get image: ${response.status} ${response.statusText}`,
115+
);
125116
}
126-
}
127117

128-
if (opts.json) {
129-
console.log(JSON.stringify({ ...image, download }, null, 2));
130-
return;
131-
}
118+
let download: Download | null = null;
119+
if (image.upload_status === "completed") {
120+
const { data: downloadData } = await client.GET(
121+
"/preview/v2/images/{id}/download",
122+
{ params: { path: { id } } },
123+
);
124+
if (downloadData) {
125+
download = downloadData;
126+
}
127+
}
132128

133-
render(
134-
<ImageDisplay
135-
image={{ ...image, sha256_hash: image.sha256_hash ?? null }}
136-
download={download}
137-
/>,
138-
);
139-
});
129+
if (opts.json) {
130+
console.log(JSON.stringify({ ...image, download }, null, 2));
131+
return;
132+
}
140133

141-
export default get;
134+
render(<ImageDisplay image={image} download={download} />);
135+
});
136+
}

src/lib/images/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { Command } from "@commander-js/extra-typings";
2-
import get from "./get.tsx";
3-
import list from "./list.ts";
4-
import upload from "./upload.ts";
1+
import { Command } from "@commander-js/extra-typings";
2+
import { createGet } from "./get.tsx";
3+
import { createList } from "./list.ts";
4+
import { createUpload } from "./upload.ts";
55

6-
export function registerImages(program: Command) {
7-
const images = program
8-
.command("images")
6+
export function createImagesCommand() {
7+
const images = new Command("images")
98
.alias("image")
9+
.alias("os")
1010
.description("Manage images")
1111
.showHelpAfterError()
1212
.addHelpText(
@@ -23,10 +23,15 @@ Examples:\n
2323
$ sf images get <image-id>
2424
`,
2525
)
26-
.addCommand(list)
27-
.addCommand(upload)
28-
.addCommand(get)
26+
.addCommand(createList())
27+
.addCommand(createUpload())
28+
.addCommand(createGet())
2929
.action(() => {
3030
images.help();
3131
});
32+
return images;
33+
}
34+
35+
export function registerImages(program: Command) {
36+
program.addCommand(createImagesCommand());
3237
}

0 commit comments

Comments
 (0)