File tree Expand file tree Collapse file tree 6 files changed +419
-129
lines changed Expand file tree Collapse file tree 6 files changed +419
-129
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import { createCli , trpcServer , zod as z } from "trpc-cli" ;
4
4
import { createAlchemy } from "./commands/create.ts" ;
5
+ import { runLogin , type LoginInput } from "./commands/login.ts" ;
5
6
import { getPackageVersion } from "./services/get-package-version.ts" ;
6
7
import {
7
8
EditorSchema ,
@@ -59,6 +60,32 @@ const router = t.router({
59
60
} ;
60
61
await createAlchemy ( combinedInput ) ;
61
62
} ) ,
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
+ } ) ,
62
89
} ) ;
63
90
64
91
export type AppRouter = typeof router ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 144
144
"jszip" : " ^3.0.0" ,
145
145
"kleur" : " ^4.1.5" ,
146
146
"libsodium-wrappers" : " ^0.7.15" ,
147
+ "open" : " ^10.1.2" ,
147
148
"turndown" : " ^7.0.0" ,
148
149
"unenv" : " 2.0.0-rc.15" ,
149
150
"yaml" : " ^2.0.0"
You can’t perform that action at this time.
0 commit comments