UNPKG

pocketbase-tools

Version:

237 lines (190 loc) 6.61 kB
import { CollectionModel } from 'pocketbase'; import { default as default_2 } from 'pocketbase'; import { RecordAuthResponse } from 'pocketbase'; import { RecordModel } from 'pocketbase'; import { RecordService } from 'pocketbase'; export declare function addCompanyProfile(companyNameOrProfile: string | ProfileCollection, contactEmail?: string, contactPhone?: string, companyAddress?: string, allowRegistration?: boolean): Promise<RecordModel | null>; /** * 添加产品 */ export declare function addProduct(titleOrProduct: string | Partial<Product>, desc?: string, img?: string, video?: string): Promise<Product | null>; /** * 添加用户 */ export declare function addUser(user: Partial<UserCreate>): Promise<User | null>; export declare interface ApiError { code: string; message: string; details?: Record<string, any>; } export declare interface AuthActions { login: (role: Role, account: UserLogin, clientOptions?: { url?: string; instance?: default_2; }) => PromiseAuth; logout: () => void; refresh: (role: Role) => PromiseAuth; verify: (email: string) => Promise<boolean>; } declare type AuthType = RecordAuthResponse<RecordModel>; export declare function checkProfileCollectionExists(): Promise<boolean | null>; /** * 创建 products 表结构 */ export declare function createProductsCollection(): Promise<CollectionModel | null>; export declare function createProfileCollection(): Promise<CollectionModel | null>; declare const _default: default_2; export default _default; export declare function deleteCompanyProfile(recordId: string): Promise<boolean | null>; /** * 删除产品 */ export declare function deleteProduct(id: string): Promise<boolean | null>; /** * 删除用户 */ export declare function deleteUser(id: string): Promise<boolean | null>; export declare class ErrorHandler { handle(error: any): void; private parseError; } export declare const filesCollect: RecordService<RecordModel>; /** * 获取所有产品 */ export declare function getAllProducts(options?: { filter?: string; sort?: string; expand?: string[]; }): Promise<Product[] | null>; /** * 获取所有用户列表 * @param options 可选过滤 */ export declare function getAllUsers(options?: { filter?: string; sort?: string; expand?: string[]; }): Promise<User[] | null>; export declare const getCollect: (name: string) => RecordService<RecordModel>; /** * 安全获取环境变量 * @param key 环境变量键名 * @param defaultValue 可选默认值 * @returns 环境变量值或默认值 * @throws 当没有默认值且变量未设置时抛出错误 */ export declare function getEnvVar(key: string, defaultValue?: string): string; /** * 获取单个产品 by ID */ export declare function getProductById(id: string): Promise<Product | null>; declare interface IFilesAPI { /** * 获取文件访问令牌 * @returns Promise<string> 返回文件访问令牌 */ getTokenPayload(): Promise<string>; /** * 获取指定 record 下文件的下载 URL * @param record RecordModel 记录 * @param fileFiled 需要下载的文件字段 * @returns url 文件下载 URL */ getAbsoluteURL(record: RecordModel, fileFiled: string): string; } export declare function listAllCompanyProfiles(): Promise<RecordModel[] | null>; export declare class Logger { private enableConsole; constructor(enableConsole?: boolean); success(message: string, data?: any): void; error(message: string, error?: any): void; warn(message: string, data?: any): void; info(message: string, data?: any): void; } export declare const logger: Logger; export declare interface Product { id: string; title: string; desc?: string; img?: string; video?: string; addtime?: string; created: string; updated: string; } export declare const productCollect: RecordService<RecordModel>; export declare const profileCollect: RecordService<RecordModel>; export declare interface ProfileCollection { companyName: string; contactEmail: string; contactPhone: string; companyAddress: string; allowRegistration: boolean; } declare type PromiseAuth = Promise<AuthType>; export declare function resetPBInstances(): void; export declare type Role = "admin" | "user"; export declare const superusersCollect: RecordService<RecordModel>; export declare function updateCompanyProfile(recordId: string, updatedFields: Partial<ProfileCollection>): Promise<RecordModel | null>; /** * 更新产品 */ export declare function updateProduct(id: string, updatedFields: Partial<Product>): Promise<Product | null>; /** * 更新用户 */ export declare function updateUser(id: string, updatedFields: Partial<UserUpdate>): Promise<User | null>; export declare const useAuth: AuthActions; export declare const useFiles: IFilesAPI; /** * 获取或创建 PocketBase 客户端 * @param options 配置选项 * - url: 指定服务地址创建新实例 * - instance: 直接注入实例 * - override: 是否强制覆盖现有实例 (默认false) */ export declare function usePBClient(options?: { url?: string; instance?: default_2; override?: boolean; }): default_2; export declare interface User { collectionId?: string; collectionName?: string; id?: string; email: string; name?: string; emailVisibility?: boolean; avatar?: string; verified?: boolean; created?: string; updated?: string; } export declare const userCollect: RecordService<RecordModel>; export declare type UserCreate = User & { password: string; passwordConfirm: string; }; export declare interface UserLogin { email?: string; username?: string; password?: string; } export declare type UserUpdate = Partial<User> & { oldPassword?: string; password?: string; passwordConfirm?: string; }; /** * 验证必需环境变量 */ export declare function validateEnvVars(requiredVars: string[]): void; /** * 封装错误处理逻辑 * @param action 当前执行的动作描述,用于日志输出 * @param callback 要执行的操作 * @returns 成功返回结果,失败返回 null */ export declare const withErrorHandling: <T>(action: string, callback: () => Promise<T>) => Promise<T | null>; export { }