baseflow-client
Version:
Official TypeScript/JavaScript client for BaseFlow - a powerful BaaS with OAuth authentication, RPC functions, database indexes, real-time features, and Supabase-compatible API
179 lines (178 loc) • 5.18 kB
TypeScript
export interface BaseFlowConfig {
url: string;
apiKey?: string;
serviceRoleKey?: string;
mode?: 'local' | 'cloud';
}
export interface AuthUser {
id: string;
email: string;
name?: string;
created_at: string;
updated_at: string;
last_sign_in?: string;
email_confirmed?: boolean;
user_metadata?: Record<string, any>;
}
export interface AuthSession {
access_token: string;
user: AuthUser;
}
export interface QueryOptions {
select?: string;
where?: string;
order?: string;
limit?: number;
offset?: number;
}
export interface StorageFile {
name: string;
path: string;
size: number;
type: 'file' | 'folder';
modified: string;
}
/**
* BaseFlow Client - Universal client for local and cloud BaseFlow
*/
export declare class BaseFlowClient {
private config;
private authToken;
constructor(config: BaseFlowConfig);
/**
* Make authenticated API request
*/
private request;
/**
* Get API base path based on mode
*/
private getApiPath;
auth: {
/**
* Sign up new user
*/
signUp: (email: string, password: string, options?: {
name?: string;
data?: Record<string, any>;
}) => Promise<AuthSession>;
/**
* Sign in user
*/
signIn: (email: string, password: string) => Promise<AuthSession>;
/**
* Sign out user
*/
signOut: () => Promise<void>;
/**
* Get current user
*/
getUser: () => Promise<AuthUser>;
/**
* Set auth token manually
*/
setToken: (token: string) => void;
/**
* Get current auth token
*/
getToken: () => string | null;
};
database: {
/**
* Query table data
*/
from: (table: string) => {
select: (columns?: string) => {
eq: (column: string, value: any) => Promise<any[]>;
neq: (column: string, value: any) => Promise<any[]>;
gt: (column: string, value: any) => Promise<any[]>;
gte: (column: string, value: any) => Promise<any[]>;
lt: (column: string, value: any) => Promise<any[]>;
lte: (column: string, value: any) => Promise<any[]>;
like: (column: string, pattern: string) => Promise<any[]>;
in: (column: string, values: any[]) => Promise<any[]>;
order: (column: string, ascending?: boolean) => Promise<any[]>;
limit: (count: number) => Promise<any[]>;
offset: (count: number) => Promise<any[]>;
execute: () => Promise<any[]>;
};
insert: (data: Record<string, any> | Record<string, any>[]) => Promise<any>;
update: (data: Record<string, any>) => {
eq: (column: string, value: any) => Promise<any>;
neq: (column: string, value: any) => Promise<any>;
gt: (column: string, value: any) => Promise<any>;
gte: (column: string, value: any) => Promise<any>;
lt: (column: string, value: any) => Promise<any>;
lte: (column: string, value: any) => Promise<any>;
};
delete: () => {
eq: (column: string, value: any) => Promise<any>;
neq: (column: string, value: any) => Promise<any>;
gt: (column: string, value: any) => Promise<any>;
gte: (column: string, value: any) => Promise<any>;
lt: (column: string, value: any) => Promise<any>;
lte: (column: string, value: any) => Promise<any>;
};
};
};
/**
* Execute query
*/
private query;
/**
* Insert data
*/
private insert;
/**
* Update data
*/
private update;
/**
* Delete data
*/
private delete;
storage: {
/**
* Upload file
*/
upload: (path: string, file: File | Blob) => Promise<any>;
/**
* List files
*/
list: (path?: string) => Promise<StorageFile[]>;
/**
* Get file URL
*/
getUrl: (path: string) => Promise<string>;
/**
* Delete file
*/
delete: (path: string) => Promise<void>;
/**
* Create folder
*/
createFolder: (path: string) => Promise<void>;
};
rpc: {
/**
* Call remote procedure
*/
call: (functionName: string, params?: Record<string, any>) => Promise<any>;
};
}
/**
* Create BaseFlow client for local development
*/
export declare function createLocalClient(url?: string): BaseFlowClient;
/**
* Create BaseFlow client for cloud projects
*/
export declare function createCloudClient(config: {
url: string;
apiKey?: string;
serviceRoleKey?: string;
}): BaseFlowClient;
/**
* Auto-detect client type based on deployment info
*/
export declare function createClient(): Promise<BaseFlowClient>;
export default BaseFlowClient;