@cloudbase/js-sdk
Version:
cloudbase javascript sdk
1,690 lines (1,637 loc) • 134 kB
TypeScript
/**
* 共享类型定义(Web + Node.js 通用),以 ambient 形式声明。
*
* 说明:本文件不能出现顶层 `import` / `export` 语句,否则会变成模块而无法作为
* 全局 ambient 命名空间被 `index.d.ts` / `index.node.d.ts` 通过三斜线引用聚合。
* 因此所有外部依赖类型均以内联 `import('...')` 类型别名的形式声明在命名空间内部,
* 既避免污染全局作用域,又不会让本文件变成模块。
*/
declare namespace cloudbase {
type KV<T> = {
[key: string]: T
}
type ExcludeOf<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type MethodType = 'request' | 'post' | 'get' | 'head' | 'patch' | 'delete' | 'put'
interface ICallApiOptions {
/** 请求的path */
path?: string
/** 请求方法 */
method?: MethodType
/** 请求头 */
headers?: KV<any>
/** 请求体,根据content-type可以是不同类型 */
body?: KV<any> | string
/** 可传token,如果没有传值,则默认用当前登录的token */
token?: string
}
interface ICloudbaseApis {
[apiName: string]: {
[method in MethodType]: (callApiOptions: ICallApiOptions, opts?: KV<any>) => Promise<ResponseObject['data']>
}
}
// ===== 外部依赖类型别名(内联 import 类型,避免顶层 import 使本文件成为模块)=====
type OrmClient = import('@cloudbase/model').OrmClient
type OrmRawQueryClient = import('@cloudbase/model').OrmRawQueryClient
type IMySqlClient = import('@cloudbase/mysql').IMySqlClient
type AI = import('@cloudbase/ai').AI
type CloudbaseAdapter = import('@cloudbase/adapter-interface').CloudbaseAdapter
type ResponseObject = import('@cloudbase/adapter-interface').ResponseObject
type ICloudbaseUpgradedConfig = import('@cloudbase/types').ICloudbaseUpgradedConfig
type ICloudbase = import('@cloudbase/types').ICloudbase
type Persistence = import('@cloudbase/types').Persistence
type LANGS = import('@cloudbase/types').LANGS
type ICustomReqOpts = import('@cloudbase/types/functions').ICustomReqOpts
// ===== @cloudbase/auth 相关类型别名 =====
type SignInRes = import('@cloudbase/auth').SignInRes
type GetUserRes = import('@cloudbase/auth').GetUserRes
type CommonRes = import('@cloudbase/auth').CommonRes
type SignInWithOtpRes = import('@cloudbase/auth').SignInWithOtpRes
type SignInOAuthRes = import('@cloudbase/auth').SignInOAuthRes
type GetClaimsRes = import('@cloudbase/auth').GetClaimsRes
type ResetPasswordForEmailRes = import('@cloudbase/auth').ResetPasswordForEmailRes
type GetUserIdentitiesRes = import('@cloudbase/auth').GetUserIdentitiesRes
type LinkIdentityRes = import('@cloudbase/auth').LinkIdentityRes
type ReauthenticateRes = import('@cloudbase/auth').ReauthenticateRes
type ResendRes = import('@cloudbase/auth').ResendRes
type UpdateUserWithVerificationRes = import('@cloudbase/auth').UpdateUserWithVerificationRes
type OnAuthStateChangeCallback = import('@cloudbase/auth').OnAuthStateChangeCallback
type SignInWithPasswordReq = import('@cloudbase/auth').SignInWithPasswordReq
type SignInWithIdTokenReq = import('@cloudbase/auth').SignInWithIdTokenReq
type SignInWithOAuthReq = import('@cloudbase/auth').SignInWithOAuthReq
type VerifyOAuthReq = import('@cloudbase/auth').VerifyOAuthReq
type VerifyOtpReq = import('@cloudbase/auth').VerifyOtpReq
type LinkIdentityReq = import('@cloudbase/auth').LinkIdentityReq
type UnlinkIdentityReq = import('@cloudbase/auth').UnlinkIdentityReq
type UpdateUserReq = import('@cloudbase/auth').UpdateUserReq
type SignInWithOtpReq = import('@cloudbase/auth').SignInWithOtpReq
type ResetPasswordForOldReq = import('@cloudbase/auth').ResetPasswordForOldReq
type ResendReq = import('@cloudbase/auth').ResendReq
type SetSessionReq = import('@cloudbase/auth').SetSessionReq
type DeleteMeReq = import('@cloudbase/auth').DeleteMeReq
type SignUpRes = import('@cloudbase/auth').SignUpRes
// ===== @cloudbase/oauth authModels 命名空间别名 =====
namespace authModels {
type BindPhoneRequest = import('@cloudbase/oauth').authModels.BindPhoneRequest
type BindEmailRequest = import('@cloudbase/oauth').authModels.BindEmailRequest
type UnbindProviderRequest = import('@cloudbase/oauth').authModels.UnbindProviderRequest
type VerifyRequest = import('@cloudbase/oauth').authModels.VerifyRequest
type VerifyResponse = import('@cloudbase/oauth').authModels.VerifyResponse
type GetVerificationRequest = import('@cloudbase/oauth').authModels.GetVerificationRequest
type GetVerificationResponse = import('@cloudbase/oauth').authModels.GetVerificationResponse
type GetCustomSignTicketFn = import('@cloudbase/oauth').authModels.GetCustomSignTicketFn
type SetPasswordRequest = import('@cloudbase/oauth').authModels.SetPasswordRequest
type ModifyUserBasicInfoRequest = import('@cloudbase/oauth').authModels.ModifyUserBasicInfoRequest
type BindWithProviderRequest = import('@cloudbase/oauth').authModels.BindWithProviderRequest
type QueryUserProfileRequest = import('@cloudbase/oauth').authModels.QueryUserProfileRequest
type QueryUserProfileResponse = import('@cloudbase/oauth').authModels.QueryUserProfileResponse
type GrantProviderTokenRequest = import('@cloudbase/oauth').authModels.GrantProviderTokenRequest
type GrantProviderTokenResponse = import('@cloudbase/oauth').authModels.GrantProviderTokenResponse
type PatchProviderTokenRequest = import('@cloudbase/oauth').authModels.PatchProviderTokenRequest
type PatchProviderTokenResponse = import('@cloudbase/oauth').authModels.PatchProviderTokenResponse
type SignInWithProviderRequest = import('@cloudbase/oauth').authModels.SignInWithProviderRequest
type GrantTokenRequest = import('@cloudbase/oauth').authModels.GrantTokenRequest
type GenProviderRedirectUriRequest = import('@cloudbase/oauth').authModels.GenProviderRedirectUriRequest
type GenProviderRedirectUriResponse = import('@cloudbase/oauth').authModels.GenProviderRedirectUriResponse
type ResetPasswordRequest = import('@cloudbase/oauth').authModels.ResetPasswordRequest
type DeviceAuthorizeRequest = import('@cloudbase/oauth').authModels.DeviceAuthorizeRequest
type DeviceAuthorizeResponse = import('@cloudbase/oauth').authModels.DeviceAuthorizeResponse
type SudoRequest = import('@cloudbase/oauth').authModels.SudoRequest
type SudoResponse = import('@cloudbase/oauth').authModels.SudoResponse
type WithSudoRequest = import('@cloudbase/oauth').authModels.WithSudoRequest
type UserProfile = import('@cloudbase/oauth').authModels.UserProfile
type UserProfileProvider = import('@cloudbase/oauth').authModels.UserProfileProvider
type Credentials = import('@cloudbase/oauth').authModels.Credentials
type ProviderSubType = import('@cloudbase/oauth').authModels.ProviderSubType
type ModifyPasswordWithoutLoginRequest = import('@cloudbase/oauth').authModels.ModifyPasswordWithoutLoginRequest
type GetUserBehaviorLog = import('@cloudbase/oauth').authModels.GetUserBehaviorLog
type GetUserBehaviorLogRes = import('@cloudbase/oauth').authModels.GetUserBehaviorLogRes
type GetMiniProgramQrCodeRequest = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeRequest
type GetMiniProgramQrCodeResponse = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeResponse
type GetMiniProgramQrCodeStatusRequest = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeStatusRequest
type GetMiniProgramQrCodeStatusResponse = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeStatusResponse
type ToDefaultLoginPage = import('@cloudbase/oauth').authModels.ToDefaultLoginPage
type SignoutRequest = import('@cloudbase/oauth').authModels.SignoutRequest
type SignoutResponse = import('@cloudbase/oauth').authModels.SignoutResponse
type SignInRequest = import('@cloudbase/oauth').authModels.SignInRequest
type SignUpRequest = import('@cloudbase/oauth').authModels.SignUpRequest
}
interface SimpleStorage {
getItem: (key: string) => Promise<string | null>
removeItem: (key: string) => Promise<void>
setItem: (key: string, value: string) => Promise<void>
getItemSync: (key: string) => string | null
removeItemSync: (key: string) => void
setItemSync: (key: string, value: string) => void
}
interface ICloudbaseConfig {
/** 是否国际站标记 */
intl?: boolean
/** 环境 ID,在腾讯云开发控制台 → 环境 → 环境总览中获取 */
env?: string
/**
* 地域信息
* @example 'ap-shanghai'
*/
region?: string
/** 网络请求超时上限,单位 ms,默认 15000 */
timeout?: number
/** 本地登录态保留期限 */
persistence?: Persistence
oauthClient?: any
/** 是否开启调试模式 */
debug?: boolean
_fromApp?: ICloudbase
clientId?: string
oauthInstance?: any
wxCloud?: any
i18n?: {
t: (text: string) => string
LANG_HEADER_KEY: string
lang: LANGS
}
accessKey?: string
endPointMode?: EndPointKey
lang?: LANGS
/**
* 认证相关配置
* @example
* ```typescript
* cloudbase.init({
* env: 'your-env-id',
* auth: {
* detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
* }
* })
* ```
*/
auth?: ICloudbaseAuthConfig
}
/**
* 认证相关配置(Web 通用部分)。
* Node.js 专属字段(secretId / secretKey / sessionToken / secretType)
* 通过 core.node.d.ts 的声明合并追加,仅在 Node.js 入口可见。
*/
interface ICloudbaseAuthConfig {
/** 是否自动检测 URL 中的 OAuth 回调参数,默认 false */
detectSessionInUrl?: boolean
}
interface ICloudbaseExtension {
name: string
invoke(opts: any, app: ICloudbase): Promise<any>
}
interface Listeners {
[key: string]: Function[]
}
interface ICloudbaseEvent {
name: string
target: any
data: any
}
interface ICloudbaseEventEmitter {
on(name: string, listener: Function): this
off(name: string, listener: Function): this
fire(event: string | ICloudbaseEvent, data?: any): this
}
interface ICloudbaseComponent {
name: string
entity: any
namespace?: string
injectEvents?: {
bus: ICloudbaseEventEmitter
events: string[]
}
IIFE?: boolean
}
interface ICloudbaseHook {
entity: any
target: string
}
type EndPointKey = 'CLOUD_API' | 'GATEWAY'
interface ISetEndPointWithKey {
key: EndPointKey
url?: string
protocol?: 'http' | 'https'
}
/**
* 初始化Cloudbase
*
* @example
* ```javascript
* // 基本用法
* const app = cloudbase.init({
* env: 'your-envid',
* timeout: 15000
* });
*
* // 推荐:从环境变量读取环境 ID
* const app = cloudbase.init({
* env: process.env.CLOUDBASE_ENV || import.meta.env.VITE_CLOUDBASE_ENV || 'your-envid'
* });
*
* // 使用认证配置
* const app = cloudbase.init({
* env: 'your-envid',
* auth: {
* detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
* }
* });
* ```
*
* @param config 初始化配置
* @param config.env 环境ID,在腾讯云开发控制台 → 环境 → 环境总览中获取
* @param config.timeout 【可选】网络请求超时上限,单位`ms`,默认值`15000`
* @param config.auth 【可选】认证相关配置
*
* @return {!cloudbase.app.App} 初始化成功的Cloudbase实例
*/
function init(config?: ICloudbaseConfig): cloudbase.app.App
/**
* 检查 Cloudbase 实例是否已完成初始化
*
* @example
* ```javascript
* if (!cloudbase.isInitialized()) {
* cloudbase.init({ env: 'your-envid' });
* }
* ```
*
* @returns 是否已初始化
*/
function isInitialized(): boolean
function updateConfig(config: ICloudbaseUpgradedConfig): void
function updateLang(lang: LANGS): void
/**
* 使用适配器,使用方式参考 {@link https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-1-%E6%AD%A5%E5%AE%89%E8%A3%85%E5%B9%B6%E5%BC%95%E5%85%A5%E9%80%82%E9%85%8D%E5%99%A8}
*
* @example
* ```javascript
* cloudbase.useAdapters(adapter); // 使用单个适配器
* cloudbase.useAdapters([ // 使用多个适配器
* adapterA,
* adapterB
* ]);
* ```
*
* @param adapters 适配器对象,入参可以为单个适配器对象,也可以是多个适配器对象的数组
* @param options 适配器参数,可以在genAdapter中获取到该参数
*/
function useAdapters(adapters: CloudbaseAdapter | CloudbaseAdapter[], options?: any): void
/**
* 注册扩展能力插件,使用方式参考 {@link https://docs.cloudbase.net/extension/abilities/image-examination.html#shi-yong-kuo-zhan}
*
* @example
* ```javascript
* cloudbase.registerExtension(ext);
* ```
*
* @param ext 扩展能力插件对象
*/
function registerExtension(ext: ICloudbaseExtension): void
/**
* 【谨慎操作】注册SDK的版本
*
* @example
* ```javascript
* cloudbase.registerVersion('1.2.1');
* ```
*
* @param version SDK版本
*/
function registerVersion(version: string): void
/**
* 【谨慎操作】注册SDK的名称
*
* @example
* ```javascript
* cloudbase.registerSdkName('cloudbase-js-sdk');
* ```
*
* @param name SDK名称
*/
function registerSdkName(name: string): void
/**
* 【谨慎操作】修改SDK请求的云开发服务地址
*
* @example
* ```javascript
* cloudbase.registerEndPoint('url','https');
* ```
*
* @param url 服务地址
* @param protocol 【可选】强制使用某种协议,默认与主站协议一致
*/
function registerEndPoint(url: string, protocol?: 'http' | 'https'): void
/**
* 【谨慎操作】修改SDK请求的「云开发/网关」服务地址
*
* @example
* ```javascript
* cloudbase.registerEndPointWithKey({
* key: "GATEWAY",
* url: "",
* protocol: ""
* });
* ```
*
*/
function registerEndPointWithKey(props: ISetEndPointWithKey): void
/**
* 一次性设置所有端点,只需传入 host 地址,自动拼接路径
* @param host - 主机地址,如 "43.144.98.4" 或 "//43.144.98.4"
* @param protocol - 协议,默认 "http"
*/
function registerHost(host: string, protocol?: 'http' | 'https'): void
/**
* 【谨慎操作】注册功能模块
*
* @example
* ```javascript
* cloudbase.registerComponent({});
* ```
*
* @param component 功能模块对象
*/
function registerComponent(component: ICloudbaseComponent): void
/**
* 【谨慎操作】注册hook
*
* @example
* ```javascript
* cloudbase.registerHook({});
* ```
*
* @param hook hook对象
*/
function registerHook(hook: ICloudbaseHook): void
export interface models extends OrmClient, OrmRawQueryClient {}
}
/**
* instance
*/
declare namespace cloudbase.app {
interface App {
/**
* 创建Auth对象
*
* {@link https://docs.cloudbase.net/api-reference/webv3/authentication#appauth}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* const auth = app.auth({
* persistence: 'local'
* });
* ```
*
* @param options Auth初始化配置
* @param options.persistence 本地登录态保留期限
*
* @return {!cloudbase.auth.App} Auth实例
*/
auth: ((options?: { persistence: cloudbase.auth.Persistence }) => cloudbase.auth.App) & cloudbase.auth.App
/**
* 调用云函数
*
* {@link https://docs.cloudbase.net/api-reference/webv3/functions#callfunction}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.callFunction({
* name: 'function-name'
* data: {
* a: 1,
* b: 2
* }
* }).then(res=>{
* console.log(res.result);
* }});
* ```
*
* @param options 被调用的云函数信息
* @param options.name 云函数的名称
* @param options.data 【可选】云函数的参数,默认为空
* @param options.parse 【可选】设置为 `true` 时,当函数返回值为对象时,API 请求会返回解析对象,而不是 JSON 字符串,默认为`false`
*
* @return Promise-函数执行结果
*/
callFunction(
options: cloudbase.functions.ICallFunctionOptions,
callback?: Function,
customReqOpts?: ICustomReqOpts,
): Promise<cloudbase.functions.ICallFunctionResponse>
/**
* 调用云托管
*
* {@link https://docs.cloudbase.net/api-reference/webv3/cloudrun}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app
* .callContainer({
* name: 'helloworld',
* method: 'POST',
* path: '/abc',
* header:{
* 'Content-Type': 'application/json; charset=utf-8'
* },
* data: {
* key1: 'test value 1',
* key2: 'test value 2'
* },
* })
* .then((res) => {
* console.log(res)
* });
* ```
*
* @param options 被调用的云托管信息
* @param options.name 云托管的名称
* @param options.data 【可选】云托管的参数,默认为空
*
* @return Promise-云托管执行结果
*/
callContainer(
options: cloudbase.functions.ICallFunctionOptions,
customReqOpts?: ICustomReqOpts,
): Promise<ResponseObject>
/**
* 云存储-上传文件
*
* {@link https://docs.cloudbase.net/api-reference/webv3/storage#uploadfile}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.uploadFile({
* cloudPath: 'cloudPath',
* filePath: 'filePath',
* method: 'put',
* headers: {
* 'Content-MD5': 'xxxxxx'
* }
* onUploadProgress: function(event){}
* });
* ```
*
* @param params
* @param params.cloudPath 文件上传到云端后的绝对路径,包含文件名
* @param params.filePath 被上传的文件对象
* @param params.method 上传方法,默认为 put
* @param params.headers 自定义头部字段
* @param params.onUploadProgress 【可选】上传进度回调函数
*
* @return Promise-上传结果
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().upload()`。
*/
uploadFile(
params: cloudbase.storage.ICloudbaseUploadFileParams,
callback?: Function,
): Promise<cloudbase.storage.ICloudbaseUploadFileResult>
/**
* 云存储-下载文件
*
* {@link https://docs.cloudbase.net/api-reference/webv3/storage#downloadfile}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.downloadFile({
* fileID: 'cloudPath'
* });
* ```
*
* @param params
* @param params.fileID 要下载的文件的 `id`,在控制台云存储中查看
*
* @return Promise-下载结果
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().download()`。
*/
downloadFile(
params: cloudbase.storage.ICloudbaseDownloadFileParams,
callback?: Function,
): Promise<cloudbase.storage.ICloudbaseDownloadFileResult>
/**
* 云存储-批量复制文件
*
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.copyFile({
* fileList: [
* {
* srcPath: '源文件的绝对路径,包含文件名。例如 foo/bar.jpg、foo/bar/baz.jpg 等,不能包含除[0-9 , a-z , A-Z]、/、!、-、_、.、、*和中文以外的字符,使用 / 字符来实现类似传统文件系统的层级结构',
* dstPath: '目标文件的绝对路径,包含文件名。例如 foo/bar.jpg、foo/bar/baz.jpg 等,不能包含除[0-9 , a-z , A-Z]、/、!、-、_、.、、*和中文以外的字符,使用 / 字符来实现类似传统文件系统的层级结构',
* overwrite: '当目标文件已经存在时,是否允许覆盖已有文件,默认 true',
* removeOriginal: '复制文件后是否删除源文件,默认 false'
* }
* ]
* });
* ```
*
* @param params
* @param params.fileList 要复制的文件信息组成的数组
*
* @return Promise-复制结果
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().copy()`。
*/
copyFile(
params: cloudbase.storage.ICloudbaseCopyFileParams,
callback?: Function,
): Promise<cloudbase.storage.ICloudbaseCopyFileResult>
/**
* 云存储-获取文件的下载链接
*
* {@link https://docs.cloudbase.net/api-reference/webv3/storage#gettempfileurl}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.getTempFileURL({
* fileList: [
* '文件A的fileID',
* {
* fileID: '文件B的fileID',
* maxAge: 600 // 文件B的链接有效期,单位`ms`
* }
* ]
* });
* ```
*
* @param params
* @param params.fileList 要下载的文件数组,数组元素可以是`string`或`Object`,如果是`string`代表文件ID,如果是`Object`可配置以下信息
* @param params.fileList[].fileID 要下载的文件ID
* @param params.fileList[].maxAge 下载链接的有效期,单位`ms`
*
* @return Promise-文件下载链接
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUrl()`。
*/
getTempFileURL(
params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
callback?: Function,
): Promise<cloudbase.storage.ICloudbaseGetTempFileURLResult>
/**
* 云存储-删除文件
*
* {@link https://docs.cloudbase.net/api-reference/webv3/storage#deletefile}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* app.deleteFile({
* fileList: [
* '文件A的fileID',
* '文件B的fileID'
* ]
* });
* ```
*
* @param params
* @param params.fileList 要删除的文件ID数组
*
* @return Promise-删除结果
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().remove()`。
*/
deleteFile(
params: cloudbase.storage.ICloudbaseDeleteFileParams,
callback?: Function,
): Promise<cloudbase.storage.ICloudbaseDeleteFileResult>
/**
* 云存储-获取文件信息
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().info()`。
*/
getFileInfo(
params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
): Promise<cloudbase.storage.ICloudbaseGetFileInfoResult>
/**
* 云存储-获取上传元信息
*
*
* @param params
* @param callback
*
* @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUploadUrl()`。
*/
getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>
/**
* Supabase 风格的文件存储 API
*
* @example
* ```typescript
* const bucket = app.storage.from('my-bucket')
* const { data, error } = await bucket.upload('path/to/file.jpg', file)
* ```
*/
storage: cloudbase.storage.StorageClient
/**
* 获取数据库实例
*
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* const db = app.database();
* ```
*
* @return 数据库实例
*/
database(dbConfig?: { instance?: string; database?: string }): cloudbase.database.App
/**
* 调用扩展能力插件功能
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: 'your-envid'
* });
* // 调用前需要先注册
* app.registerExtension(ext);
*
* app.invokeExtension('扩展能力插件名称',{
* // ...扩展能力插件的入参
* });
* ```
*
* @param name 扩展能力插件的名称
* @param opts 【可选】扩展能力插件的参数,根据插件具体需求而定
*
* @return Promise-扩展能力插件执行结果
*/
invokeExtension(name: string, opts: any): Promise<any>
eventBus: any
/**
* 调用 数据模型 SDK
*
* {@link https://docs.cloudbase.net/model/sdk-reference/model}
* @example
* ```javascript
models.<model_name>.create() // 创建单条数据
models.<model_name>.createMany() // 创建多条数据
models.<model_name>.update() // 更新单条数据
models.<model_name>.updateMany() // 更新多条数据
models.<model_name>.delete() // 删除单条数据
models.<model_name>.deleteMany() // 删除多条数据
models.<model_name>.get() // 查询单条数据
models.<model_name>.list() // 查询多条数据
models.$runSQL() // 执行原生 SQL 语句
* ```
*/
models: OrmClient & OrmRawQueryClient
/**
* MySQL 数据库
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
*
* app.mysql().from('todos').select().then((res) => {
* console.log(res.data);
* });
* ```
*/
mysql: IMySqlClient
rdb: IMySqlClient
ai(options?: { baseUrl?: string }): AI
apis: ICloudbaseApis
/**
* 一次性设置所有端点,只需传入 host 地址,自动拼接路径
* @param host - 主机地址,如 "43.144.98.4" 或 "//43.144.98.4"
* @param protocol - 协议,默认 "http"
*/
registerHost(host: string, protocol?: 'http' | 'https'): void
/**
* 获取指定类型的端点信息
* @param key - 端点类型
*/
getEndPointWithKey(key: cloudbase.EndPointKey): { BASE_URL: string; PROTOCOL: string }
/**
* 修改SDK请求的云开发服务地址
* @param url 服务地址
* @param protocol 【可选】强制使用某种协议,默认与主站协议一致
*/
registerEndPoint(url: string, protocol?: 'http' | 'https'): void
/**
* 修改SDK请求的「云开发/网关」服务地址,通过 key 指定
*/
registerEndPointWithKey(props: cloudbase.ISetEndPointWithKey): void
/**
* 解析验证码 URL 参数
*/
parseCaptcha(url: string): any
}
}
/**
* auth
*/
declare namespace cloudbase.auth {
type Persistence = 'local' | 'session' | 'none'
interface IAccessTokenInfo {
accessToken: string
env: string
}
interface ILoginState {
/**
* 当前登录用户的信息
*/
user: IUser
}
interface ICredential {
accessToken?: string
accessTokenExpire?: string
}
interface IAuthProvider {
signInWithRedirect: () => any
}
/**
* 用户信息
*/
interface IUserInfo {
uid?: string
loginType?: string
openid?: string
wxOpenId?: string
wxPublicId?: string
unionId?: string
qqMiniOpenId?: string
customUserId?: string
name?: string
displayName?: string
gender?: string
email?: string
username?: string
hasPassword?: boolean
location?: {
country?: string
province?: string
city?: string
}
country?: string
province?: string
city?: string
}
interface IUser extends IUserInfo {
/**
* 更新用户信息
*
* {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userupdate}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* const auth = app.auth();
* const user = auth.currentUser;
* user.update({
* nickName: '新昵称'
* }).then(()=>{});
* ```
*
* @param userinfo 用户信息
*
* @return Promise
*
*/
update(userinfo: IUserInfo): Promise<void>
/**
* 刷新本地用户信息
*
* {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userrefresh}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* const auth = app.auth();
* const user = auth.currentUser;
* user.refresh().then(()=>{});
* ```
*
* @return Promise-刷新后的用户信息
*
*/
refresh(): Promise<IUserInfo>
/**
* 同步获取本地用户信息
*/
checkLocalInfo: () => void
/**
* 异步获取本地用户信息
*/
checkLocalInfoAsync: () => Promise<void>
linkWithTicket?: (ticket: string) => Promise<void>
linkWithRedirect?: (provider: IAuthProvider) => void
getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean; users: IUserInfo[] }>
setPrimaryUid?: (uid: string) => Promise<void>
unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>
}
interface App {
/**
* 获取当前登录的用户信息-同步操作
*
* {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authhasloginstate}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* const userInfo = app.auth().currentUser;
* ```
*
* @return 用户信息,如果未登录返回`null`
*/
currentUser: IUser | null
/**
* 获取当前登录的用户信息-异步操作,文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetcurrentuser}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* app.auth().getCurrentUser().then(userInfo=>{
* // ...
* });
* ```
*
* @return Promise-用户信息,如果未登录返回`null`
*/
getCurrentUser(): Promise<IUser | null>
/**
* 绑定手机号码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindphonenumber}
*
* @param params
*/
bindPhoneNumber(params: authModels.BindPhoneRequest): Promise<void>
/**
* 绑定邮箱
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindemail}
*
* @param params
*/
bindEmail(params: authModels.BindEmailRequest): Promise<void>
/**
* 解除三方绑定
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authunbindprovider}
*
* @param params
*/
unbindProvider(params: authModels.UnbindProviderRequest): Promise<void>
/**
* 验证码验证
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authverify}
*
* @param params
*/
verify(params: authModels.VerifyRequest): Promise<authModels.VerifyResponse>
/**
* 获取验证码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetverification}
*
* @param params
* @param options
*/
getVerification(
params: authModels.GetVerificationRequest,
options?: { withCaptcha: boolean },
): Promise<authModels.GetVerificationResponse>
/**
* 匿名登录。无需用户注册即可使用应用功能,适合游客模式、临时体验等场景。
*
* **前置条件**:需要在云开发控制台(环境 → 登录授权 → 身份源列表)开启「匿名登录」。
*
* **重要**:匿名登录必须在使用 `watch()` 等实时数据库功能**之前**完成,
* 否则 WebSocket 连接会因缺少认证信息而失败。
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninanonymously}
*
* @example
* ```typescript
* import Cloudbase from '@cloudbase/js-sdk';
*
* const app = Cloudbase.init({
* env: 'your-env-id',
* region: 'ap-shanghai'
* });
* const auth = app.auth();
*
* // 匿名登录
* const { data, error } = await auth.signInAnonymously();
* if (error) {
* console.error('匿名登录失败:', error.message);
* return;
* }
* console.log('匿名登录成功, 用户ID:', data.user.id);
* console.log('是否匿名用户:', data.user.is_anonymous); // true
*
* // 登录成功后,即可使用 watch() 等实时功能
* const db = app.database();
* const listener = db.collection('rooms').where({ status: 'active' }).watch({
* onChange: (snapshot) => {
* console.log('数据变化:', snapshot.docs);
* },
* onError: (err) => {
* console.error('监听错误:', err);
* }
* });
*
* // 不再需要时关闭监听
* listener.close();
* ```
*
* @param data 可选参数
* @param data.provider_token 提供令牌(通常不需要手动传入)
* @returns 登录结果,包含 `data.user`(用户信息)和 `data.session`(会话信息),
* 或 `error`(登录失败时的错误信息)
*/
signInAnonymously(data?: { provider_token?: string }): Promise<SignInRes>
/**
* 小程序匿名登录
*
* @param params
*/
signInAnonymouslyInWx(params?: { useWxCloud?: boolean }): Promise<ILoginState>
/**
* 小程序绑定OpenID
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindopenid}
*
*/
bindOpenId(): Promise<void>
/**
* 小程序unionId静默登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithunionid}
*
*/
signInWithUnionId(): Promise<ILoginState>
/**
* 短信验证码登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithsms}
*
* @param params
*/
signInWithSms(params: {
verificationInfo?: { verification_id: string; is_user: boolean }
verificationCode?: string
phoneNum?: string
bindInfo?: any
}): Promise<ILoginState>
/**
* 邮箱验证码登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithemail}
*
* @param params
*/
signInWithEmail(params: {
verificationInfo?: { verification_id: string; is_user: boolean }
verificationCode?: string
email?: string
bindInfo?: any
}): Promise<ILoginState>
/**
* 设置获取自定义登录 ticket 的函数
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsetcustomsignfunc}
*
*
* @param getTickFn
*/
setCustomSignFunc(getTickFn: authModels.GetCustomSignTicketFn): void
/**
* 设置密码(已登录状态下,更新用户密码)
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsetpassword}
*
*/
setPassword(params: authModels.SetPasswordRequest): Promise<void>
/**
* 获取用户信息
* @deprecated 请使用 getCurrentUser 代替
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetuserinfo}
*/
getUserInfo(): Promise<IUserInfo>
/**
* 获取微搭插件用户信息
*
*/
getWedaUserInfo(): Promise<any>
/**
* 更新用户基本信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authupdateuserbasicinfo}
*
* @param params
*/
updateUserBasicInfo(params: authModels.ModifyUserBasicInfoRequest): Promise<void>
/**
* 获取本地登录态-同步操作
*
* {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authhasloginstate}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* const loginState = app.auth().hasLoginState();
* ```
*
* @return 登录态信息,如果未登录返回`null`
*/
hasLoginState(): ILoginState | null
/**
* 获取本地登录态-异步操作
*
* {@link https://docs.cloudbase.net/api-reference/webv2/authentication.html#auth-getloginstate}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* app.auth().getLoginState().then(loginState=>{
* // ...
* });
* ```
*
* @return Promise-登录态信息,如果未登录返回`null`
*/
getLoginState(): Promise<ILoginState | null>
/**
* @deprecated
*/
getAuthHeader(): {}
/**
* 为已有账户绑定第三方账户
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindwithprovider}
*/
bindWithProvider(params: authModels.BindWithProviderRequest): Promise<void>
/**
* 查询用户(自定义登录场景和匿名登录场景,不支持使用该接口查询用户信息)
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authqueryuser}
*
*/
queryUser(queryObj: authModels.QueryUserProfileRequest): Promise<authModels.QueryUserProfileResponse>
/**
* 获取当前登录用户的访问凭证
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetaccesstoken}
*/
getAccessToken(): Promise<{ accessToken: string; env: string }>
/**
* 提供第三方平台登录 token
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgrantprovidertoken}
*/
grantProviderToken(params: authModels.GrantProviderTokenRequest): Promise<authModels.GrantProviderTokenResponse>
patchProviderToken(params: authModels.PatchProviderTokenRequest): Promise<authModels.PatchProviderTokenResponse>
/**
* 第三方平台登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithprovider}
*/
signInWithProvider(params: authModels.SignInWithProviderRequest): Promise<ILoginState>
/**
* 微信登录
*/
signInWithWechat(params?: any): Promise<ILoginState>
grantToken(params: authModels.GrantTokenRequest): Promise<ILoginState>
/**
* 生成第三方平台授权 Uri (如微信二维码扫码授权网页)
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgenproviderredirecturi}
*/
genProviderRedirectUri(
params: authModels.GenProviderRedirectUriRequest,
): Promise<authModels.GenProviderRedirectUriResponse>
/**
* 重置密码(用户忘记密码无法登录时,可使用该接口强制设置密码)
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authresetpassword}
*/
resetPassword(params: authModels.ResetPasswordRequest): Promise<void>
deviceAuthorize(params: authModels.DeviceAuthorizeRequest): Promise<authModels.DeviceAuthorizeResponse>
/**
* 通过 sudo 接口获取高级操作权限,如修改用户密码,修改手机号,邮箱等操作
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsudo}
*/
sudo(params: authModels.SudoRequest): Promise<authModels.SudoResponse>
/**
* 删除用户
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authdeleteme}
*/
deleteMe(params: authModels.WithSudoRequest): Promise<authModels.UserProfile>
/**
* 获取第三方绑定列表
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetproviders}
*/
getProviders(): Promise<authModels.UserProfileProvider>
/**
* 用于查询用户是否为匿名登录状态
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authloginscope}
*/
loginScope(): Promise<string>
loginGroups(): Promise<string[]>
onLoginStateChanged(callback: Function)
createLoginState(
params?: { version?: string; query?: any },
options?: { asyncRefreshUser?: boolean; userInfo?: any },
): Promise<ILoginState>
/**
* 强制刷新token
*
* @param params
*/
refreshTokenForce(params: { version?: string }): Promise<authModels.Credentials>
/**
* 获取身份信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetcredentials}
*/
getCredentials(): Promise<authModels.Credentials>
/**
* 写入身份信息
*
* @param credentials
*/
setCredentials(credentials: authModels.Credentials): Promise<void>
/**
* 获取身份源类型
*
*/
getProviderSubType(): Promise<authModels.ProviderSubType>
/**
* 创建验证码数据
*
* @param params
*/
createCaptchaData(params: { state: string; redirect_uri?: string }): Promise<any>
/**
* 验证验证码数据
*
* @param params
*/
verifyCaptchaData(params: { token: string; key: string }): Promise<any>
/**
* 修改密码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authmodifypassword}
*
* @param params
*/
modifyPassword(params: authModels.ModifyUserBasicInfoRequest): Promise<void>
/**
* 未登录状态修改密码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authmodifypasswordwithoutlogin}
*
* @param params
*/
modifyPasswordWithoutLogin(params: authModels.ModifyPasswordWithoutLoginRequest): Promise<void>
/**
* 获取用户行为日志
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetuserbehaviorlog}
*
* @param params
*/
getUserBehaviorLog(params: authModels.GetUserBehaviorLog): Promise<authModels.GetUserBehaviorLogRes>
/**
* 检查用户名是否被绑定过
*
* {@link https://docs.cloudbase.net/api-reference/webv2/authentication.html#authisusernameregistered}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* const auth = app.auth();
* const username = "your_awesome_username";
* auth.isUsernameRegistered(username).then(registered=>{
* // ...
* });
* ```
*
* @param username 用户名
*
* @return Promise-用户是否被绑定
*/
isUsernameRegistered(username: string): Promise<boolean>
getMiniProgramQrCode(
params: authModels.GetMiniProgramQrCodeRequest,
): Promise<authModels.GetMiniProgramQrCodeResponse>
getMiniProgramQrCodeStatus(
params: authModels.GetMiniProgramQrCodeStatusRequest,
): Promise<authModels.GetMiniProgramQrCodeStatusResponse>
/**
* 跳转到默认登录页
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authtodefaultloginpage}
* @param params
*/
toDefaultLoginPage(params?: authModels.ToDefaultLoginPage): Promise<CommonRes>
/**
* 退出登录
*
* {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signout}
*
* @example
* ```javascript
* const app = cloudbase.init({
* env: "xxxx-yyy"
* });
* app.auth.signOut().then(()=>{});
* ```
*
* @return Promise
*/
signOut(params?: authModels.SignoutRequest): Promise<void | authModels.SignoutResponse>
/**
* 使用自定义登录 ticket 登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithcustomticket}
*
* @param getTickFn
*/
signInWithCustomTicket(getTickFn?: authModels.GetCustomSignTicketFn): Promise<ILoginState>
/**
* 用户登录,目前支持手机号,邮箱,用户名密码登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signin}
*/
signIn(params: authModels.SignInRequest): Promise<ILoginState>
/**
* 用户注册,目前支持手机号验证码注册,邮箱验证码注册
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signup}
*/
signUp(params: authModels.SignUpRequest): Promise<SignUpRes>
/**
* 监听认证状态变化
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#onauthstatechange}
*
* @param callback
*/
onAuthStateChange(callback: OnAuthStateChangeCallback): {
data: { subscription: { id: string; callback: Function; unsubscribe: () => void } }
}
/**
* 使用用户名和密码登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithpassword}
*
* @param params
*/
signInWithPassword(params: SignInWithPasswordReq): Promise<SignInRes>
/**
* 使用第三方平台 ID Token 登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithidtoken}
*
* @param params
*/
signInWithIdToken(params: SignInWithIdTokenReq): Promise<SignInRes>
/**
* 使用一次性密码(OTP)登录,支持手机号和邮箱两种方式。
*
* **注意**:手机号验证码登录需要在初始化时设置 `region: 'ap-shanghai'`。
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithotp}
*
* @example
* ```typescript
* // 完整的手机号验证码登录流程
* import Cloudbase from '@cloudbase/js-sdk';
*
* // 第一步:初始化(region 必须为 ap-shanghai)
* const app = Cloudbase.init({
* env: 'your-env-id',
* region: 'ap-shanghai'
* });
* const auth = app.auth();
*
* // 第二步:发送验证码
* const { data, error } = await auth.signInWithOtp({ phone: '+8613800138000' });
* if (error) {
* console.error('发送验证码失败:', error.message);
* return;
* }
*
* // 第三步:用户输入验证码后,调用 verifyOtp 完成登录
* const { data: loginData, error: loginError } = await data.verifyOtp({
* token: userInputCode // 用户输入的验证码
* });
* if (loginError) {
* console.error('验证失败:', loginError.message);
* return;
* }
* console.log('登录成功:', loginData.user);
* ```
*
* @param params 登录参数,包含 email 或 phone(二选一)
*/
signInWithOtp(params: SignInWithOtpReq): Promise<SignInWithOtpRes>
/**
* 校验第三方平台授权登录回调
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#verifyoauth}
*
* @param params
*/
verifyOAuth(params?: VerifyOAuthReq): Promise<SignInRes>
/**
* 生成第三方平台授权 Uri
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithoauth}
*
* @param params
*/
signInWithOAuth(params: SignInWithOAuthReq): Promise<SignInOAuthRes>
/**
* 获取当前访问令牌中的声明信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getclaims}
*/
getClaims(): Promise<GetClaimsRes>
/**
* 通过邮箱重置密码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resetpasswordforemail}
*
* @param emailOrPhone
* @param options
*/
resetPasswordForEmail(emailOrPhone: string, options?: { redirectTo?: string }): Promise<ResetPasswordForEmailRes>
/**
* 通过旧密码重置密码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resetpasswordforold}
*
* @param params
*/
resetPasswordForOld(params: ResetPasswordForOldReq): Promise<SignInRes>
/**
* 验证一次性密码(OTP)
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#verifyotp}
*
* @param params
*/
verifyOtp(params: VerifyOtpReq): Promise<SignInRes>
/**
* 获取当前会话
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getsession}
*/
getSession(): Promise<SignInRes>
/**
* 刷新会话
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#refreshsession}
*
* @param refresh_token
*/
refreshSession(refresh_token?: string): Promise<SignInRes>
/**
* 获取当前用户详细信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getuser}
*/
getUser(): Promise<GetUserRes>
/**
* 刷新用户信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#refreshuser}
*/
refreshUser(): Promise<CommonRes>
/**
* 更新用户信息
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#updateuser}
*
* @param params
*/
updateUser(params: UpdateUserReq): Promise<GetUserRes | UpdateUserWithVerificationRes>
/**
* 获取已绑定的身份源
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getuseridentities}
*/
getUserIdentities(): Promise<GetUserIdentitiesRes>
/**
* 绑定身份源到当前用户
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#linkidentity}
*
* @param params
*/
linkIdentity(params: LinkIdentityReq): Promise<LinkIdentityRes>
/**
* 解绑身份源
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#unlinkidentity}
*
* @param params
*/
unlinkIdentity(params: UnlinkIdentityReq): Promise<CommonRes>
/**
* 重新认证
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#reauthenticate}
*/
reauthenticate(): Promise<ReauthenticateRes>
/**
* 重新发送验证码
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resend}
*
* @param params
*/
resend(params: ResendReq): Promise<ResendRes>
/**
* 使用 access_token 和 refresh_token 设置会话
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#setsession}
*
* @param params
*/
setSession(params: SetSessionReq): Promise<SignInRes>
/**
* 删除当前用户
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#deleteuser}
*
* @param params
*/
deleteUser(params: DeleteMeReq): Promise<CommonRes>
/**
* 小程序 openId 静默登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithopenid}
*
* @param params
*/
signInWithOpenId(params?: { useWxCloud?: boolean }): Promise<SignInRes>
/**
* 小程序手机号授权登录
*
* 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithphoneauth}
*
* @param params
*/
signInWithPhoneAuth(params: { phoneCode: string }): Promise<SignInRes>
// ========== v1 兼容 API ==========
/**
* v1 API: 获取用于微信登录的 WeixinAuthProvider
*
* @deprecated 建议使用 auth.signInWithOAuth({ provider: appid }) 替代。
*
* @example
* ```javascript
* const provider = auth.weixinAuthProvider({ appid: 'wx-appid', scope: 'snsapi_login' });
* provider.signInWithRedirect();
* ```
*
* @param options
* @param options.appid 微信 AppID
* @param options.scope 微信授权范围
*/
weixinAuthProvider(options: { appid: string; scope: string }): cloudbase.auth.WeixinAuthProvider
/**
* v1 API: 获取用于自定义登录的 CustomAuthProvider
*
* @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
*
* @example
* ```javascript
* const provider = auth.customAuthProvider();
* await provider.signIn(ticket);
* ```
*/
customAuthProvider(): cloudbase.auth.CustomAuthProvider
/**
* v1 API: 获取用于匿名登录的 AnonymousAuthProvider
*
* @deprecated 建议使用 auth.signInAnonymously({}) 替代。
*
* @example
* ```javascript
* const provider = auth.anonymousAuthProvider();
* await provider.signIn();
* ```
*/
anonymousAuthProvider(): cloudbase.auth.AnonymousAuthProvider
/**
* v1 API: 使用邮箱和密码注册云开发账户
*
* @deprecated 建议使用 auth.signUp({ email, password }) 替代。
*
* @example
* ```javascript
* await auth.signUpWithEmailAndPassword('user@example.com', 'password123');
* ```
*
* @param email 邮箱
* @param password 密码
*/
signUpWithEmailAndPassword(email: string, password: string): Promise<SignUpRes>
/**
* v1 API: 使用邮箱和密码登录云开发(支持两种调用方式)
*
* @deprecated 建议使用 auth.signInWithPassword({ email, password }) 替代。
*
* @example
* ```javascript
* // 方式一(v1 风格):
* await auth.signInWithEmailAndPassword('user@example.com', 'password123');
*
* // 方式二(v3 风格):
* const { data, error } = await auth.signInWithEmailAndPassword({
* email: 'user@example.com',
* password: 'password123'
* });
* ```
*
* @param emailOrParams - 邮箱字符串(v1)或包含 email 和 password 的对象(v3)
* @param password - 密码(仅 v1 风格时使用)
*/
signInWithEmailAndPassword(emailOrParams: string | { email: string; password: string; is_encrypt?: boolean }, password?: string): Promise<SignInRes | ILoginState>
/**
* v1 API: 发送重置密码的邮件
*
* @deprecated 建议使用 auth.resetPasswordForEmail(email) 替代。
*
* @example
* ```javascript
* await auth.sendPasswordResetEmail('user@example.com');
* ```
*
* @param email 邮箱
*/
sendPasswordResetEmail(email: string): Promise<void>
/**
* v1 API: 使用用户名和密码登录云开发
*
* @deprecated 建议使用 auth.signInWithPassword({ username, password }) 替代。
*
* @example
* ```javascript
* const loginState = await auth.signInWithUsernameAndPassword('username', 'password123');
* ```
*
* @param username 用户名
* @param password 密码
*/
signInWithUsernameAndPassword(username: string, password: string): Promise<ILoginState>
/**
* v1 API: 发送手机验证码
*
* @deprecated 此方法仅发送验证码并返回布尔值,不返回 verifyOtp 回调。