import { SimpleStorage } from './interface' import { ErrorType } from './consts' import { AuthOptions } from '../auth/apis' import { ICloudbaseConfig } from '@cloudbase/types' /** Credentials **/ export interface Credentials { token_type?: string | null; access_token?: string | null; refresh_token?: string | null; scope?: string | null; expires_in?: number | null; expires_at?: Date | null; sub?: string | null; groups?: string[] | null; version?: string; } /** An Error For all concern **/ export interface ResponseError { error: ErrorType; error_description?: string | null; error_uri?: string | null; details?: any | null; } export interface RequestOptions { body?: any | null; headers?: any | null; method?: string; [key: string]: any; } export type RequestFunction = ( url: string, options?: RequestOptions, ) => Promise; export interface AuthClientRequestOptions extends RequestOptions { headers?: { 'x-request-id'?: string; [key: string]: any; } | null; withCredentials?: boolean; withBasicAuth?: boolean; retry?: number; useWxCloud?: boolean; /** * Custom getCredentials function for this request. * When provided, uses this function instead of the default getCredentials() call * to avoid potential deadlocks during initialization. */ getCredentials?: () => Credentials | Promise | null; [key: string]: any; } export interface OAuth2ClientOptions { devMode?: boolean; apiOrigin: string; apiPath?: string; clientId: string; env: string; // default value is 1,min value is 0, max value is 5 retry?: number; baseRequest?: (url: string, options?: RequestOptions) => Promise; // Storage, default is localStorage, setItem(k, v), getItem(k),removeItem(k) storage?: SimpleStorage; clientSecret?: string; refreshTokenFunc?: (refreshToken?: string) => Promise; // set the token in url query instead of header tokenInURL?: boolean; headers?: { [key: string]: string }; // hook anonymousSignInFunc?: (Credentials) => Promise wxCloud?: any; onCredentialsError?: AuthOptions['onCredentialsError'] i18n?: ICloudbaseConfig['i18n'] useWxCloud?: boolean eventBus?: any /** * Enable debug logging */ debug?: boolean /** * Callback function to get initial session (e.g., from OAuth callback in URL). * Called by OAuth2Client.initialize() if set. * The callback should handle URL detection, OAuth verification, and return credentials. * Returns { data: { session: Credentials, user?: any }, error: null } on success, * or { data: null, error: Error } on failure. */ getInitialSession?: () => Promise<{ data: { session: Credentials; user?: any } | null error: Error | null }> /** * Callback invoked after initial session is obtained and stored. * Used to let upper layer (e.g., packages/auth) handle user info storage. * Called with session and user data. */ onInitialSessionObtained?: (data: { session: Credentials; user?: any }) => void | Promise }