11import { API_BASE_URL } from "@/config"
2+ import type { components , operations } from "./opencode-types"
23import { fetchWrapper , FetchError } from "./fetchWrapper"
34
4- export interface OAuthAuthorizeResponse {
5- url : string
6- method : "code"
7- instructions : string
8- }
5+ type OpenCodeAuthorizeRequest = NonNullable < operations [ "provider.oauth.authorize" ] [ "requestBody" ] > [ "content" ] [ "application/json" ]
96
10- export interface OAuthCallbackRequest {
11- method : number
12- code ?: string
13- }
7+ export type OAuthAuthorizeResponse = components [ "schemas" ] [ "ProviderAuthAuthorization" ]
148
15- export interface ProviderAuthMethod {
16- type : "oauth" | "api"
17- label : string
18- }
9+ export type OAuthCallbackRequest = NonNullable < operations [ "provider.oauth.callback" ] [ "requestBody" ] > [ "content" ] [ "application/json" ]
10+
11+ export type ProviderAuthMethod = components [ "schemas" ] [ "ProviderAuthMethod" ]
1912
2013export interface ProviderAuthMethods {
2114 [ providerId : string ] : ProviderAuthMethod [ ]
@@ -29,12 +22,12 @@ function handleApiError(error: unknown, context: string): never {
2922}
3023
3124export const oauthApi = {
32- authorize : async ( providerId : string , method : number ) : Promise < OAuthAuthorizeResponse > => {
25+ authorize : async ( providerId : string , method : number , inputs ?: OpenCodeAuthorizeRequest [ "inputs" ] ) : Promise < OAuthAuthorizeResponse > => {
3326 try {
3427 return await fetchWrapper ( `${ API_BASE_URL } /api/oauth/${ providerId } /oauth/authorize` , {
3528 method : 'POST' ,
3629 headers : { 'Content-Type' : 'application/json' } ,
37- body : JSON . stringify ( { method } ) ,
30+ body : JSON . stringify ( { method, inputs } ) ,
3831 } )
3932 } catch ( error ) {
4033 handleApiError ( error , "OAuth authorization failed" )
0 commit comments