Skip to content

Commit d6d05d6

Browse files
authored
Merge 96f1a5f into c55d351
2 parents c55d351 + 96f1a5f commit d6d05d6

File tree

6 files changed

+419
-129
lines changed

6 files changed

+419
-129
lines changed

alchemy/bin/alchemy.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { createCli, trpcServer, zod as z } from "trpc-cli";
44
import { createAlchemy } from "./commands/create.ts";
5+
import { runLogin, type LoginInput } from "./commands/login.ts";
56
import { getPackageVersion } from "./services/get-package-version.ts";
67
import {
78
EditorSchema,
@@ -59,6 +60,32 @@ const router = t.router({
5960
};
6061
await createAlchemy(combinedInput);
6162
}),
63+
login: t.procedure
64+
.meta({
65+
description: "Login to Cloudflare using OAuth",
66+
})
67+
.input(
68+
z.tuple([
69+
z
70+
.object({
71+
scopes: z
72+
.array(z.string())
73+
.optional()
74+
.describe(
75+
"Cloudflare OAuth scopes to request (defaults to all available scopes)",
76+
),
77+
})
78+
.optional()
79+
.default({}),
80+
]),
81+
)
82+
.mutation(async ({ input }) => {
83+
const [options] = input;
84+
const loginInput: LoginInput = {
85+
scopes: options.scopes,
86+
};
87+
await runLogin(loginInput);
88+
}),
6289
});
6390

6491
export type AppRouter = typeof router;

alchemy/bin/commands/login.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { intro, log, outro } from "@clack/prompts";
2+
import pc from "picocolors";
3+
import { DefaultScopes, loginToCloudflare } from "../../src/cloudflare/auth.ts";
4+
5+
export interface LoginInput {
6+
scopes?: string[];
7+
}
8+
9+
export async function runLogin(input: LoginInput): Promise<void> {
10+
try {
11+
intro(pc.cyan("🔐 Cloudflare Login"));
12+
13+
const scopesToUse =
14+
input.scopes && input.scopes.length > 0
15+
? input.scopes
16+
: Object.keys(DefaultScopes);
17+
18+
log.info(
19+
`Requesting the following scopes:\n${scopesToUse.map((scope) => ` • ${scope}`).join("\n")}`,
20+
);
21+
22+
await loginToCloudflare(scopesToUse);
23+
24+
outro(pc.green("✅ Login successful!"));
25+
} catch (error) {
26+
log.error("Login failed:");
27+
if (error instanceof Error) {
28+
log.error(`${pc.red("Error:")} ${error.message}`);
29+
if (error.stack && process.env.DEBUG) {
30+
log.error(`${pc.gray("Stack trace:")}\n${error.stack}`);
31+
}
32+
} else {
33+
log.error(pc.red(String(error)));
34+
}
35+
process.exit(1);
36+
}
37+
}

alchemy/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"jszip": "^3.0.0",
145145
"kleur": "^4.1.5",
146146
"libsodium-wrappers": "^0.7.15",
147+
"open": "^10.1.2",
147148
"turndown": "^7.0.0",
148149
"unenv": "2.0.0-rc.15",
149150
"yaml": "^2.0.0"

0 commit comments

Comments
 (0)