Skip to content

Commit b663619

Browse files
committed
fix login
1 parent 7b61bdb commit b663619

6 files changed

Lines changed: 99 additions & 69 deletions

File tree

.env.production

Lines changed: 0 additions & 3 deletions
This file was deleted.

bun.lockb

5.36 KB
Binary file not shown.

package.json

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
{
2-
"dependencies": {
3-
"@inquirer/prompts": "^5.1.2",
4-
"chalk": "^5.3.0",
5-
"chrono-node": "^2.7.6",
6-
"commander": "^12.1.0",
7-
"dayjs": "^1.11.11",
8-
"dotenv": "^16.4.5",
9-
"ora": "^8.0.1",
10-
"parse-duration": "^1.1.0"
11-
},
12-
"name": "@sfc/cli",
13-
"bin": {
14-
"sfc": "dist/cli.js"
15-
},
16-
"type": "module",
17-
"module": "src/index.ts",
18-
"scripts": {
19-
"format": "biome format --write ./src",
20-
"lint": "biome lint --write ./src",
21-
"check": "biome check ./src",
22-
"dev": "IS_DEVELOPMENT_CLI_ENV=true bun run src/index.ts",
23-
"pack": "bun build src/index.ts --outfile dist/cli.js",
24-
"release": "bun run src/scripts/release.ts"
25-
},
26-
"devDependencies": {
27-
"@biomejs/biome": "^1.8.2",
28-
"@types/bun": "latest"
29-
},
30-
"peerDependencies": {
31-
"typescript": "^5.0.0"
32-
},
33-
"version": "0.0.0-pre.1720203472273"
2+
"dependencies": {
3+
"@inquirer/prompts": "^5.1.2",
4+
"axios": "^1.7.2",
5+
"chalk": "^5.3.0",
6+
"chrono-node": "^2.7.6",
7+
"commander": "^12.1.0",
8+
"dayjs": "^1.11.11",
9+
"dotenv": "^16.4.5",
10+
"node-fetch": "^3.3.2",
11+
"ora": "^8.0.1",
12+
"parse-duration": "^1.1.0"
13+
},
14+
"name": "@sfc/cli",
15+
"bin": {
16+
"sfc": "dist/cli.js"
17+
},
18+
"type": "module",
19+
"module": "src/index.ts",
20+
"scripts": {
21+
"format": "biome format --write ./src",
22+
"lint": "biome lint --write ./src",
23+
"check": "biome check ./src",
24+
"dev": "IS_DEVELOPMENT_CLI_ENV=true bun run src/index.ts",
25+
"pack": "bun build src/index.ts --outfile dist/cli.js",
26+
"release": "bun run src/scripts/release.ts",
27+
"prod": "bun run src/index.ts"
28+
},
29+
"devDependencies": {
30+
"@biomejs/biome": "^1.8.2",
31+
"@types/bun": "latest"
32+
},
33+
"peerDependencies": {
34+
"typescript": "^5.0.0"
35+
},
36+
"version": "0.0.0-pre.1720203472273"
3437
}

src/helpers/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export interface Config {
99
}
1010

1111
const ProductionConfigDefaults = {
12-
api_url: "https://api.sfcompute.com",
13-
webapp_url: "https://sfcompute.com",
12+
api_url: "https://api.sfcompute.dev",
13+
webapp_url: "https://sfcompute.dev",
1414
};
1515

1616
const DevelopmentConfigDefaults = {

src/lib/login.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { saveConfig } from "../helpers/config";
55
import { getWebAppUrl } from "../helpers/urls";
66
import { clearScreen } from "../helpers/prompt";
77

8+
// We're using Axios here because there's a bug
9+
// where the fetch API in Bun isn't passing the body
10+
// through redirects correctly
11+
import axios from "axios";
12+
813
export function registerLogin(program: Command) {
914
program
1015
.command("login")
@@ -47,53 +52,52 @@ async function createSession({
4752
}: {
4853
validation: string;
4954
}) {
50-
const response = await fetch(await getWebAppUrl("cli_session_create"), {
51-
method: "POST",
52-
headers: {
53-
"Content-Type": "application/json",
54-
},
55-
body: JSON.stringify({ validation }),
56-
});
57-
if (!response.ok) {
58-
console.error("Response not ok", response.status, response.statusText);
59-
return null;
60-
}
55+
const url = await getWebAppUrl("cli_session_create");
6156

62-
const body = (await response.json()) as {
63-
url: string;
64-
token: string;
65-
};
57+
try {
58+
const response = await axios.post(
59+
url,
60+
{ validation },
61+
{
62+
headers: {
63+
"Content-Type": "application/json",
64+
},
65+
maxRedirects: 5,
66+
},
67+
);
6668

67-
return body;
69+
return response.data as {
70+
url: string;
71+
token: string;
72+
};
73+
} catch (error) {
74+
console.error("Error creating session:", error);
75+
return null;
76+
}
6877
}
6978

7079
async function getSession({
7180
token,
7281
}: {
7382
token: string;
7483
}) {
75-
const response = await fetch(
76-
await getWebAppUrl("cli_session_get", {
77-
token,
78-
}),
79-
{
80-
method: "GET",
84+
try {
85+
const url = await getWebAppUrl("cli_session_get", { token });
86+
const response = await axios.get(url, {
8187
headers: {
8288
"Content-Type": "application/json",
8389
},
84-
},
85-
);
86-
if (!response.ok) {
87-
console.error("Response not ok", response.status, response.statusText);
90+
});
91+
92+
return response.data as {
93+
validation?: string;
94+
token?: string;
95+
};
96+
} catch (error) {
97+
console.error("Error getting session:", error);
8898
process.exit(1);
8999
return null;
90100
}
91-
92-
const body = (await response.json()) as {
93-
validation?: string;
94-
token?: string;
95-
};
96-
return body;
97101
}
98102

99103
function generateValidationString() {

src/lib/sell.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Command } from "commander";
2+
3+
export function registerSell(program: Command) {
4+
program
5+
.command("sell")
6+
.description("Place a sell order")
7+
.requiredOption("-p, --price <price>", "Specify the price in centicents")
8+
.requiredOption("-c, --contract-id <id>", "Specify the contract ID")
9+
.requiredOption("-q, --quantity <quantity>", "Specify the quantity")
10+
.requiredOption(
11+
"-s, --start <start>",
12+
"Specify the start time (ISO 8601 format)",
13+
)
14+
.requiredOption(
15+
"-d, --duration <duration>",
16+
"Specify the duration in seconds",
17+
)
18+
.option(
19+
"-f, --flags <flags>",
20+
"Specify additional flags as JSON",
21+
JSON.parse,
22+
)
23+
.action(async (options) => {
24+
await placeSellOrder(options);
25+
});
26+
}

0 commit comments

Comments
 (0)