@cloudbase/js-sdk 4.0.0 → 4.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +398 -0
- package/ai/dist/index.esm.js +2 -3
- package/ai/dist/index.esm.js.map +1 -0
- package/ai/dist/index.js +2 -21
- package/ai/dist/index.js.map +1 -0
- package/apis/dist/index.d.ts +1 -0
- package/apis/dist/index.esm.js +2 -0
- package/apis/dist/index.esm.js.map +1 -0
- package/apis/dist/index.js +2 -0
- package/apis/dist/index.js.map +1 -0
- package/{analytics → apis}/package.json +1 -1
- package/app/dist/index.esm.js +2 -11
- package/app/dist/index.esm.js.map +1 -0
- package/app/dist/index.js +2 -18
- package/app/dist/index.js.map +1 -0
- package/app/dist/index.node.esm.js +3 -0
- package/app/dist/index.node.esm.js.LICENSE.txt +13 -0
- package/app/dist/index.node.esm.js.map +1 -0
- package/app/dist/index.node.js +3 -0
- package/app/dist/index.node.js.LICENSE.txt +13 -0
- package/app/dist/index.node.js.map +1 -0
- package/app/package.json +12 -1
- package/auth/dist/index.d.ts +2 -2
- package/auth/dist/index.esm.js +3 -4
- package/auth/dist/index.esm.js.LICENSE.txt +12 -0
- package/auth/dist/index.esm.js.map +1 -0
- package/auth/dist/index.js +3 -9
- package/auth/dist/index.js.LICENSE.txt +12 -0
- package/auth/dist/index.js.map +1 -0
- package/cloudrun/dist/index.esm.js +2 -3
- package/cloudrun/dist/index.esm.js.map +1 -0
- package/cloudrun/dist/index.js +2 -21
- package/cloudrun/dist/index.js.map +1 -0
- package/container/dist/index.d.ts +2 -2
- package/container/dist/index.esm.js +2 -4
- package/container/dist/index.esm.js.map +1 -0
- package/container/dist/index.js +2 -9
- package/container/dist/index.js.map +1 -0
- package/core.d.ts +4331 -0
- package/core.node.d.ts +294 -0
- package/database/dist/index.esm.js +2 -47
- package/database/dist/index.esm.js.map +1 -0
- package/database/dist/index.js +2 -53
- package/database/dist/index.js.map +1 -0
- package/database/package.json +34 -4
- package/dist/index.cjs.js +3 -37
- package/dist/index.cjs.js.LICENSE.txt +12 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +3 -32
- package/dist/index.esm.js.LICENSE.txt +12 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.node.cjs.js +3 -0
- package/dist/index.node.cjs.js.LICENSE.txt +26 -0
- package/dist/index.node.cjs.js.map +1 -0
- package/dist/index.node.esm.js +3 -0
- package/dist/index.node.esm.js.LICENSE.txt +26 -0
- package/dist/index.node.esm.js.map +1 -0
- package/functions/dist/index.d.ts +2 -2
- package/functions/dist/index.esm.js +2 -4
- package/functions/dist/index.esm.js.map +1 -0
- package/functions/dist/index.js +2 -9
- package/functions/dist/index.js.map +1 -0
- package/index.d.ts +7 -1785
- package/index.node.d.ts +13 -0
- package/miniprogram_dist/ai/index.d.ts +42 -0
- package/miniprogram_dist/ai/index.js +2 -0
- package/miniprogram_dist/apis/index.d.ts +5 -0
- package/miniprogram_dist/apis/index.js +1 -0
- package/miniprogram_dist/app/index.d.ts +67 -0
- package/miniprogram_dist/app/index.js +2 -0
- package/miniprogram_dist/auth/index.d.ts +269 -0
- package/miniprogram_dist/auth/index.js +2 -0
- package/miniprogram_dist/cloudrun/index.d.ts +4 -0
- package/miniprogram_dist/cloudrun/index.js +1 -0
- package/miniprogram_dist/container/index.d.ts +13 -0
- package/miniprogram_dist/container/index.js +1 -0
- package/miniprogram_dist/database/index.d.ts +3 -0
- package/miniprogram_dist/database/index.js +1 -0
- package/miniprogram_dist/functions/index.d.ts +2 -0
- package/miniprogram_dist/functions/index.js +1 -0
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/model/index.d.ts +5 -0
- package/miniprogram_dist/model/index.js +1 -0
- package/miniprogram_dist/mysql/index.d.ts +3 -0
- package/miniprogram_dist/mysql/index.js +1 -0
- package/miniprogram_dist/oauth/index.d.ts +22 -0
- package/miniprogram_dist/oauth/index.js +2 -0
- package/miniprogram_dist/realtime/index.d.ts +2 -0
- package/miniprogram_dist/realtime/index.js +1 -0
- package/miniprogram_dist/storage/index.d.ts +13 -0
- package/miniprogram_dist/storage/index.js +1 -0
- package/model/dist/index.esm.js +2 -3
- package/model/dist/index.esm.js.map +1 -0
- package/model/dist/index.js +2 -21
- package/model/dist/index.js.map +1 -0
- package/mysql/dist/index.d.ts +1 -0
- package/mysql/dist/index.esm.js +2 -0
- package/mysql/dist/index.esm.js.map +1 -0
- package/mysql/dist/index.js +2 -0
- package/mysql/dist/index.js.map +1 -0
- package/mysql/package.json +6 -0
- package/oauth/dist/index.esm.js +3 -3
- package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
- package/oauth/dist/index.esm.js.map +1 -0
- package/oauth/dist/index.js +3 -21
- package/oauth/dist/index.js.LICENSE.txt +12 -0
- package/oauth/dist/index.js.map +1 -0
- package/package.json +144 -18
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.esm.js +2 -4
- package/realtime/dist/index.esm.js.map +1 -0
- package/realtime/dist/index.js +2 -9
- package/realtime/dist/index.js.map +1 -0
- package/storage/dist/index.d.ts +2 -2
- package/storage/dist/index.esm.js +2 -4
- package/storage/dist/index.esm.js.map +1 -0
- package/storage/dist/index.js +2 -9
- package/storage/dist/index.js.map +1 -0
- package/types/analytics.d.ts +51 -0
- package/types/auth.d.ts +166 -0
- package/types/cache.d.ts +26 -0
- package/types/cloudrun.d.ts +9 -0
- package/types/component.d.ts +17 -0
- package/types/container.d.ts +93 -0
- package/types/database.d.ts +31 -0
- package/types/error.d.ts +40 -0
- package/types/events.d.ts +13 -0
- package/types/functions.d.ts +49 -0
- package/types/index.d.ts +269 -0
- package/types/package.json +47 -0
- package/types/realtime.d.ts +350 -0
- package/types/request.d.ts +30 -0
- package/types/result.d.ts +48 -0
- package/types/storage.d.ts +144 -0
- package/utilities/dist/cjs/adapters/index.d.ts +45 -0
- package/utilities/dist/cjs/adapters/index.js +68 -0
- package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
- package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
- package/utilities/dist/cjs/constants/common.d.ts +6 -0
- package/utilities/dist/cjs/constants/common.js +24 -0
- package/utilities/dist/cjs/constants/errors.d.ts +8 -0
- package/utilities/dist/cjs/constants/errors.js +12 -0
- package/utilities/dist/cjs/constants/index.d.ts +3 -0
- package/utilities/dist/cjs/constants/index.js +21 -0
- package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
- package/utilities/dist/cjs/helpers/decorators.js +238 -0
- package/utilities/dist/cjs/helpers/index.d.ts +1 -0
- package/utilities/dist/cjs/helpers/index.js +18 -0
- package/utilities/dist/cjs/index.d.ts +13 -0
- package/utilities/dist/cjs/index.js +51 -0
- package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
- package/utilities/dist/cjs/libs/abortController.js +25 -0
- package/utilities/dist/cjs/libs/cache.d.ts +17 -0
- package/utilities/dist/cjs/libs/cache.js +261 -0
- package/utilities/dist/cjs/libs/events.d.ts +27 -0
- package/utilities/dist/cjs/libs/events.js +108 -0
- package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
- package/utilities/dist/cjs/libs/langEvent.js +7 -0
- package/utilities/dist/cjs/libs/util.d.ts +49 -0
- package/utilities/dist/cjs/libs/util.js +282 -0
- package/utilities/dist/esm/adapters/index.d.ts +45 -0
- package/utilities/dist/esm/adapters/index.js +40 -0
- package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
- package/utilities/dist/esm/adapters/platforms/web.js +282 -0
- package/utilities/dist/esm/constants/common.d.ts +6 -0
- package/utilities/dist/esm/constants/common.js +17 -0
- package/utilities/dist/esm/constants/errors.d.ts +8 -0
- package/utilities/dist/esm/constants/errors.js +9 -0
- package/utilities/dist/esm/constants/index.d.ts +3 -0
- package/utilities/dist/esm/constants/index.js +4 -0
- package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
- package/utilities/dist/esm/helpers/decorators.js +234 -0
- package/utilities/dist/esm/helpers/index.d.ts +1 -0
- package/utilities/dist/esm/helpers/index.js +2 -0
- package/utilities/dist/esm/index.d.ts +13 -0
- package/utilities/dist/esm/index.js +14 -0
- package/utilities/dist/esm/libs/abortController.d.ts +9 -0
- package/utilities/dist/esm/libs/abortController.js +23 -0
- package/utilities/dist/esm/libs/cache.d.ts +17 -0
- package/utilities/dist/esm/libs/cache.js +258 -0
- package/utilities/dist/esm/libs/events.d.ts +27 -0
- package/utilities/dist/esm/libs/events.js +102 -0
- package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
- package/utilities/dist/esm/libs/langEvent.js +4 -0
- package/utilities/dist/esm/libs/util.d.ts +49 -0
- package/utilities/dist/esm/libs/util.js +254 -0
- package/utilities/dist/miniprogram/index.js +1 -0
- package/utilities/package.json +26 -0
- package/analytics/dist/index.d.ts +0 -2
- package/analytics/dist/index.esm.js +0 -4
- package/analytics/dist/index.js +0 -9
- package/miniprogram_dist/ai.js +0 -2
- package/miniprogram_dist/analytics.js +0 -1
- package/miniprogram_dist/app.js +0 -2
- package/miniprogram_dist/auth.js +0 -2
- package/miniprogram_dist/cloudrun.js +0 -1
- package/miniprogram_dist/container.js +0 -1
- package/miniprogram_dist/database.js +0 -2
- package/miniprogram_dist/functions.js +0 -1
- package/miniprogram_dist/model.js +0 -1
- package/miniprogram_dist/oauth.js +0 -1
- package/miniprogram_dist/realtime.js +0 -1
- package/miniprogram_dist/storage.js +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// report 接口传参结构
|
|
2
|
+
export interface IReportData {
|
|
3
|
+
report_type: string, // 上报场景 如电商 mall,游戏 game
|
|
4
|
+
report_data: {
|
|
5
|
+
action_time?: number, // 非必填 行为发生时,客户端的时间点,单位s
|
|
6
|
+
action_type: string, // 必填 行为类型 如 访问 visit_store,分享 share,加入购物车 add_to_cart等
|
|
7
|
+
click_id?: string, // 非必填 广告平台会在URL增加click_id
|
|
8
|
+
action_param?: { // 非必填
|
|
9
|
+
value?: number, // 非必填 行为所带的参数,转化行为价值(例如金额)
|
|
10
|
+
leads_type?: string // 非必填 行为来源,目前支持PHONE(电话直呼),RESERVE(表单预约)
|
|
11
|
+
},
|
|
12
|
+
product_param?: { // 非必填
|
|
13
|
+
product_yun_type?: string, // 非必填 商品 goods ,优惠券 coupon, 搜索词 search_term
|
|
14
|
+
product_yun_id?: string, // 非必填 商品id
|
|
15
|
+
product_yun_category?: string, // 非必填 商品类目 自定义
|
|
16
|
+
product_yun_keywords?: string, // 非必填 商品关键词
|
|
17
|
+
product_yun_price?: number, // 非必填 商品原价
|
|
18
|
+
product_yun_value?: number, // 非必填 商品成交价
|
|
19
|
+
product_yun_name?: string, // 非必填 商品名
|
|
20
|
+
product_yun_id_ad?: string, // 非必填 广告商品库中商品id
|
|
21
|
+
product_yun_category_ad?: string // 非必填 广告商品库中商品类目
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 上报数据结构
|
|
27
|
+
export interface IAnalyticsDataItem {
|
|
28
|
+
analytics_scene: string, // 上报场景 如电商 mall,游戏 game
|
|
29
|
+
analytics_data: { // 场景模板内容,以电商模板举例
|
|
30
|
+
openid?: string, // 必填 用户openid
|
|
31
|
+
wechat_mini_program_appid?: string, // 必填小程序appid
|
|
32
|
+
action_time: number, // 必填 行为发生时,客户端的时间点,单位s
|
|
33
|
+
action_type: string, // 必填 行为类型 如 访问 visit_store,分享 share,加入购物车 add_to_cart等
|
|
34
|
+
click_id?: string, // 非必填 广告平台会在URL增加click_id
|
|
35
|
+
action_param?: { // 非必填
|
|
36
|
+
value?: number, // 非必填 行为所带的参数,转化行为价值(例如金额)
|
|
37
|
+
leads_type?: string // 非必填 行为来源,目前支持PHONE(电话直呼),RESERVE(表单预约)
|
|
38
|
+
},
|
|
39
|
+
product_param?: { // 非必填
|
|
40
|
+
product_yun_type?: string, // 非必填 商品 goods ,优惠券 coupon, 搜索词 search_term
|
|
41
|
+
product_yun_id?: string, // 非必填 商品id
|
|
42
|
+
product_yun_category?: string, // 非必填 商品类目 自定义
|
|
43
|
+
product_yun_keywords?: string, // 非必填 商品关键词
|
|
44
|
+
product_yun_price?: number, // 非必填 商品原价
|
|
45
|
+
product_yun_value?: number, // 非必填 商品成交价
|
|
46
|
+
product_yun_name?: string, // 非必填 商品名
|
|
47
|
+
product_yun_id_ad?: string, // 非必填 广告商品库中商品id
|
|
48
|
+
product_yun_category_ad?: string // 非必填 广告商品库中商品类目
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/types/auth.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { ICloudbaseConfig, KV, ICloudbase } from '.'
|
|
2
|
+
import { authModels, UserInfo } from '@cloudbase/oauth'
|
|
3
|
+
import { ICloudbaseEventEmitter } from './events'
|
|
4
|
+
|
|
5
|
+
export type ICloudbaseAuthConfig = Pick<
|
|
6
|
+
ICloudbaseConfig,
|
|
7
|
+
| 'env'
|
|
8
|
+
| 'clientId'
|
|
9
|
+
| 'region'
|
|
10
|
+
| 'persistence'
|
|
11
|
+
| 'debug'
|
|
12
|
+
| '_fromApp'
|
|
13
|
+
| 'oauthInstance'
|
|
14
|
+
| 'wxCloud'
|
|
15
|
+
| 'i18n'
|
|
16
|
+
| 'accessKey'
|
|
17
|
+
| 'useWxCloud'
|
|
18
|
+
| 'auth'
|
|
19
|
+
> &
|
|
20
|
+
ICloudbaseConfig['auth']
|
|
21
|
+
& {eventBus?: ICloudbaseEventEmitter}
|
|
22
|
+
|
|
23
|
+
export interface IAccessTokenInfo {
|
|
24
|
+
accessToken: string
|
|
25
|
+
env: string
|
|
26
|
+
}
|
|
27
|
+
export interface ICredential {
|
|
28
|
+
// refreshToken: string;
|
|
29
|
+
accessToken?: string
|
|
30
|
+
accessTokenExpire?: string
|
|
31
|
+
}
|
|
32
|
+
export interface IAuthProvider {
|
|
33
|
+
signInWithRedirect: () => any
|
|
34
|
+
}
|
|
35
|
+
export interface IUserInfo {
|
|
36
|
+
uid?: string
|
|
37
|
+
loginType?: string
|
|
38
|
+
openid?: string
|
|
39
|
+
wxOpenId?: string
|
|
40
|
+
wxPublicId?: string
|
|
41
|
+
unionId?: string
|
|
42
|
+
qqMiniOpenId?: string
|
|
43
|
+
customUserId?: string
|
|
44
|
+
name?: string
|
|
45
|
+
displayName?: string
|
|
46
|
+
gender?: string
|
|
47
|
+
email?: string
|
|
48
|
+
username?: string
|
|
49
|
+
hasPassword?: boolean
|
|
50
|
+
location?: {
|
|
51
|
+
country?: string
|
|
52
|
+
province?: string
|
|
53
|
+
city?: string
|
|
54
|
+
}
|
|
55
|
+
country?: string
|
|
56
|
+
province?: string
|
|
57
|
+
city?: string
|
|
58
|
+
}
|
|
59
|
+
export interface IUser extends IUserInfo {
|
|
60
|
+
checkLocalInfo: () => void
|
|
61
|
+
checkLocalInfoAsync: () => Promise<void>
|
|
62
|
+
linkWithTicket?: (ticket: string) => Promise<void>
|
|
63
|
+
linkWithRedirect?: (provider: IAuthProvider) => void
|
|
64
|
+
getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean; users: IUserInfo[] }>
|
|
65
|
+
setPrimaryUid?: (uid: string) => Promise<void>
|
|
66
|
+
unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>
|
|
67
|
+
update: (userinfo: authModels.UserProfile) => Promise<void>
|
|
68
|
+
refresh: (params?: { version?: string }) => Promise<authModels.UserInfo>
|
|
69
|
+
}
|
|
70
|
+
export interface ILoginState {
|
|
71
|
+
user: IUser
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* v1 兼容事件回调收到的载荷。
|
|
76
|
+
*
|
|
77
|
+
* 运行时实际传入的是 `ILoginState` 与事件元数据(`eventType` 等)的混合对象;
|
|
78
|
+
* 在某些时机(如未登录、首次立即回调)可能为 `null`。这里用一个开放的载荷类型
|
|
79
|
+
* 精确表达其形态,取代原先的裸 `Function`,同时保持对既有回调写法的非破坏。
|
|
80
|
+
*/
|
|
81
|
+
export type IAuthEventPayload =
|
|
82
|
+
| (Partial<ILoginState> & {
|
|
83
|
+
/** 事件类型标识(如 `SIGN_IN` / `SIGN_OUT` / `CREDENTIALS_ERROR` 等)。 */
|
|
84
|
+
eventType?: string
|
|
85
|
+
/** 事件携带的原始数据。 */
|
|
86
|
+
data?: KV<any>
|
|
87
|
+
[key: string]: any
|
|
88
|
+
})
|
|
89
|
+
| null
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* v1 兼容事件回调签名。
|
|
93
|
+
*
|
|
94
|
+
* @deprecated 推荐改用 `onAuthStateChange((event, session, info) => {})` 监听,
|
|
95
|
+
* 该回调仅为兼容旧代码保留。
|
|
96
|
+
*/
|
|
97
|
+
export type IAuthEventCallback = (payload: IAuthEventPayload) => void
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 认证核心能力:状态字段与核心方法,均为**非可选**(与 `ICloudbase` 拆分同款)。
|
|
101
|
+
*/
|
|
102
|
+
export interface AuthCore {
|
|
103
|
+
config: ICloudbaseConfig
|
|
104
|
+
loginType: string
|
|
105
|
+
getAccessToken: () => IAccessTokenInfo
|
|
106
|
+
getLoginState: () => Promise<ILoginState | null>
|
|
107
|
+
hasLoginState: () => Promise<ILoginState | null>
|
|
108
|
+
getUserInfo: () => Promise<UserInfo & IUser>
|
|
109
|
+
getAuthHeader: () => Promise<KV<string>>
|
|
110
|
+
/** 当前登录用户,未登录时为 null */
|
|
111
|
+
currentUser: IUser | null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 认证事件监听能力(v1 兼容)。
|
|
116
|
+
*
|
|
117
|
+
* @deprecated 这些监听器均为兼容旧代码保留,推荐统一改用
|
|
118
|
+
* `onAuthStateChange((event, session, info) => {})`。回调签名已从裸 `Function`
|
|
119
|
+
* 收紧为精确类型 {@link IAuthEventCallback},对既有 `(state) => {}` 写法非破坏。
|
|
120
|
+
*/
|
|
121
|
+
export interface AuthEventCapability {
|
|
122
|
+
onLoginStateChanged: (callback: IAuthEventCallback) => void
|
|
123
|
+
onLoginStateExpired: (callback: IAuthEventCallback) => void
|
|
124
|
+
onAccessTokenRefreshed: (callback: IAuthEventCallback) => void
|
|
125
|
+
onAnonymousConverted: (callback: IAuthEventCallback) => void
|
|
126
|
+
onLoginTypeChanged: (callback: IAuthEventCallback) => void
|
|
127
|
+
/** 决定是否刷新 accessToken 的钩子,返回 `true` 表示需要刷新。 */
|
|
128
|
+
shouldRefreshAccessToken: (hook: () => boolean) => void
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 认证身份源提供方能力。三个 provider 由 `registerProvider` 动态注册,
|
|
133
|
+
* 类型收敛为 {@link IAuthProvider}(取代原先的 `any`)。
|
|
134
|
+
*/
|
|
135
|
+
export interface AuthProviderCapability {
|
|
136
|
+
weixinAuthProvider: IAuthProvider
|
|
137
|
+
anonymousAuthProvider: IAuthProvider
|
|
138
|
+
customAuthProvider: IAuthProvider
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 认证客户端总类型。
|
|
143
|
+
*
|
|
144
|
+
* 由 {@link AuthCore} + {@link AuthEventCapability} + {@link AuthProviderCapability}
|
|
145
|
+
* 交叉组合而成,与原先的单一大接口**结构等价**(字段无增删,仅按能力分层 +
|
|
146
|
+
* 收紧回调/provider 类型),因此对既有代码非破坏。
|
|
147
|
+
*/
|
|
148
|
+
export type ICloudbaseAuth = AuthCore & AuthEventCapability & AuthProviderCapability
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 按需组合的认证客户端泛型。
|
|
152
|
+
*
|
|
153
|
+
* 默认等价于完整的 {@link ICloudbaseAuth};也可只声明需要的能力,例如
|
|
154
|
+
* `CloudbaseAuthClient<AuthEventCapability>` 只暴露事件监听,为 tree-shaking
|
|
155
|
+
* 与精确 API 面铺路。
|
|
156
|
+
*/
|
|
157
|
+
export type CloudbaseAuthClient<
|
|
158
|
+
Caps = AuthEventCapability & AuthProviderCapability,
|
|
159
|
+
> = AuthCore & Caps
|
|
160
|
+
|
|
161
|
+
type IProvider = new (...args: any[]) => any
|
|
162
|
+
|
|
163
|
+
export interface ICloudbaseAuthModule {
|
|
164
|
+
registerAuth: (app: ICloudbase) => void
|
|
165
|
+
registerProvider: (name: string, provider: IProvider) => void
|
|
166
|
+
}
|
package/types/cache.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ICloudbasePlatformInfo, KV, ICloudbaseConfig } from '.'
|
|
2
|
+
|
|
3
|
+
export type ICacheConfig = Pick < ICloudbaseConfig, 'debug' | 'persistence' > & {
|
|
4
|
+
platformInfo?: ICloudbasePlatformInfo;
|
|
5
|
+
keys?: KV<string>;
|
|
6
|
+
alwaysLocalKeys?: string[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export interface ICloudbaseCache {
|
|
10
|
+
keys: KV<string>;
|
|
11
|
+
mode: 'async' | 'sync';
|
|
12
|
+
|
|
13
|
+
setStore: (key: string, value: any, version?: string) => void;
|
|
14
|
+
setStoreAsync: (key: string, value: any, version?: string) => Promise<void>;
|
|
15
|
+
|
|
16
|
+
getStore: (key: string, version?: string) => any;
|
|
17
|
+
getStoreAsync: (key: string, version?: string) => Promise<any>;
|
|
18
|
+
|
|
19
|
+
removeStore: (key: string) => void;
|
|
20
|
+
removeStoreAsync: (key: string) => Promise<void>;
|
|
21
|
+
|
|
22
|
+
updatePersistence?: (persistence: string) => void;
|
|
23
|
+
updatePersistenceAsync?: (persistence: string) => Promise<void>;
|
|
24
|
+
|
|
25
|
+
clear?: () => void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ICloudbaseEventEmitter } from './events'
|
|
2
|
+
|
|
3
|
+
export interface ICloudbaseComponent {
|
|
4
|
+
name: string;
|
|
5
|
+
entity: any;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
injectEvents?: {
|
|
8
|
+
bus: ICloudbaseEventEmitter,
|
|
9
|
+
events: string[];
|
|
10
|
+
};
|
|
11
|
+
IIFE?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ICloudbaseHook {
|
|
15
|
+
entity: any;
|
|
16
|
+
target: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ICloudbaseConfig } from '.'
|
|
2
|
+
|
|
3
|
+
export interface IContianerConfig {
|
|
4
|
+
/**
|
|
5
|
+
* wasm sdk 地址
|
|
6
|
+
*/
|
|
7
|
+
wasmUrl?: string;
|
|
8
|
+
/**
|
|
9
|
+
* js sdk 地址
|
|
10
|
+
*/
|
|
11
|
+
jsUrl?:
|
|
12
|
+
| string
|
|
13
|
+
| {
|
|
14
|
+
vender?: string;
|
|
15
|
+
vm?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 账号ID
|
|
19
|
+
*/
|
|
20
|
+
uin: string;
|
|
21
|
+
/**
|
|
22
|
+
* 网关id
|
|
23
|
+
*/
|
|
24
|
+
gatewayId: string;
|
|
25
|
+
/**
|
|
26
|
+
* 网关请求 host port
|
|
27
|
+
*/
|
|
28
|
+
host: string;
|
|
29
|
+
port: string;
|
|
30
|
+
/**
|
|
31
|
+
* 是否上报数据
|
|
32
|
+
*/
|
|
33
|
+
report?: boolean | object;
|
|
34
|
+
/**
|
|
35
|
+
* public key
|
|
36
|
+
*/
|
|
37
|
+
publicKey?: string;
|
|
38
|
+
i18n?: ICloudbaseConfig['i18n'];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ICallContainerOptions {
|
|
42
|
+
/**
|
|
43
|
+
* 填入业务自定义url和参数
|
|
44
|
+
* 根目录,就是 /
|
|
45
|
+
*/
|
|
46
|
+
url: string;
|
|
47
|
+
/**
|
|
48
|
+
* 请求网关api子路由
|
|
49
|
+
*/
|
|
50
|
+
pathname?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 按照自己的业务开发,选择对应的方法
|
|
53
|
+
* @default GET
|
|
54
|
+
*/
|
|
55
|
+
method?: string;
|
|
56
|
+
/**
|
|
57
|
+
* 设置请求的 header,header 中不能设置 Referer
|
|
58
|
+
*/
|
|
59
|
+
header?: Record<string, string>;
|
|
60
|
+
/**
|
|
61
|
+
* 请求参数
|
|
62
|
+
*/
|
|
63
|
+
data?: Object;
|
|
64
|
+
/**
|
|
65
|
+
* 超时时间,单位毫秒,默认60000
|
|
66
|
+
*/
|
|
67
|
+
timeout?: number;
|
|
68
|
+
/**
|
|
69
|
+
* 超时提示细腻系
|
|
70
|
+
*/
|
|
71
|
+
timeoutMsg?: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 响应 parse 类型
|
|
75
|
+
*/
|
|
76
|
+
dataType?: 'json' | string;
|
|
77
|
+
/**
|
|
78
|
+
* 响应类型
|
|
79
|
+
*/
|
|
80
|
+
responseType?: 'text' | 'arrayBuffer';
|
|
81
|
+
/**
|
|
82
|
+
* 是否上报数据
|
|
83
|
+
*/
|
|
84
|
+
report?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* 请求 withCredentials
|
|
87
|
+
*/
|
|
88
|
+
withCredentials?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* 请求是否为透明模式
|
|
91
|
+
*/
|
|
92
|
+
transparent?: boolean;
|
|
93
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit'
|
|
2
|
+
export type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
|
|
3
|
+
|
|
4
|
+
export interface ISingleDBEvent {
|
|
5
|
+
id: number
|
|
6
|
+
dataType: DataType
|
|
7
|
+
queueType: QueueType
|
|
8
|
+
docId: string
|
|
9
|
+
doc: Record<string, any>
|
|
10
|
+
updatedFields?: any
|
|
11
|
+
removedFields?: any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IDatabaseServiceContext extends IServiceContext {
|
|
15
|
+
appConfig: IAppConfig
|
|
16
|
+
ws?: any
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IAppConfig {
|
|
20
|
+
docSizeLimit: number
|
|
21
|
+
realtimePingInterval: number
|
|
22
|
+
realtimePongWaitTimeout: number
|
|
23
|
+
request: any
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IServiceContext {
|
|
27
|
+
// name: string
|
|
28
|
+
// identifiers: IRuntimeIdentifiers
|
|
29
|
+
// debug: boolean
|
|
30
|
+
env?: string
|
|
31
|
+
}
|
package/types/error.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudbase 统一错误结构契约。
|
|
3
|
+
*
|
|
4
|
+
* 这是一个**结构化契约**(structural contract),而非要求所有错误都继承同一个 class。
|
|
5
|
+
* 各模块的具体错误类(如 auth 的 `AuthError`、storage 的 `StorageError`)只要满足此结构,
|
|
6
|
+
* 即可作为 `Result<T, E>` / `SafeResult<T, E>` 的错误分支类型 `E`。
|
|
7
|
+
*
|
|
8
|
+
* 运行时判别推荐使用各模块的类型守卫(如 `isStorageError`),
|
|
9
|
+
* 或检查隐藏标记字段(如 `__isStorageError`),而非 `instanceof`
|
|
10
|
+
* (`instanceof` 在跨 bundle / 跨 realm 场景会失效)。
|
|
11
|
+
*/
|
|
12
|
+
export interface ICloudbaseError extends Error {
|
|
13
|
+
/** 错误名称,用于二级判别(如 `'StorageApiError'`)。 */
|
|
14
|
+
name: string
|
|
15
|
+
/** 人类可读的错误描述。 */
|
|
16
|
+
message: string
|
|
17
|
+
/** 便于 `JSON.stringify` 时不丢失关键字段(原生 Error 序列化会丢 name/message)。 */
|
|
18
|
+
toJSON?: () => Record<string, unknown>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Cloudbase 体系内错误的隐藏标记字段集合。
|
|
23
|
+
*
|
|
24
|
+
* 各模块的错误类都携带其中之一(在其构造函数中设为 `true`):
|
|
25
|
+
* - `__isAuthError` —— {@link !AuthError}(`@cloudbase/oauth`)
|
|
26
|
+
* - `__isStorageError` —— `StorageError`(`@cloudbase/storage`)
|
|
27
|
+
*
|
|
28
|
+
* 之所以用隐藏标记而非 `instanceof`,是因为多个 SDK 副本共存(跨 bundle / 跨 realm)
|
|
29
|
+
* 时 `instanceof` 会失效,而标记字段始终可靠。
|
|
30
|
+
*/
|
|
31
|
+
export type CloudbaseErrorBrand = '__isAuthError' | '__isStorageError'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 统一的跨模块错误判别类型。
|
|
35
|
+
*
|
|
36
|
+
* 任何携带 {@link CloudbaseErrorBrand} 标记之一的对象,都被视为 Cloudbase 体系内的错误,
|
|
37
|
+
* 满足 {@link ICloudbaseError} 契约。各模块另提供具体的运行时守卫(`isAuthError` /
|
|
38
|
+
* `isStorageError`),本类型用于在类型层统一表达「这是一个 Cloudbase 错误」。
|
|
39
|
+
*/
|
|
40
|
+
export type CloudbaseErrorLike = ICloudbaseError & Partial<Record<CloudbaseErrorBrand, boolean>>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface Listeners {
|
|
2
|
+
[key: string]: Function[];
|
|
3
|
+
}
|
|
4
|
+
export interface ICloudbaseEvent {
|
|
5
|
+
name: string;
|
|
6
|
+
target: any;
|
|
7
|
+
data: any;
|
|
8
|
+
}
|
|
9
|
+
export interface ICloudbaseEventEmitter {
|
|
10
|
+
on(name: string, listener: Function): this;
|
|
11
|
+
off(name: string, listener: Function): this;
|
|
12
|
+
fire(event: string | ICloudbaseEvent, data?: any): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { KV } from '.'
|
|
2
|
+
|
|
3
|
+
export interface ICallFunctionOptions {
|
|
4
|
+
name: string
|
|
5
|
+
data?: KV<any>
|
|
6
|
+
query?: KV<any>
|
|
7
|
+
search?: string
|
|
8
|
+
parse?: boolean
|
|
9
|
+
// Used for 云函数2.0 CallContainer
|
|
10
|
+
type?: string
|
|
11
|
+
method?: string
|
|
12
|
+
path?: string
|
|
13
|
+
header?: KV<any>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ICallFunctionResponse<T = any> {
|
|
17
|
+
requestId: string
|
|
18
|
+
/**
|
|
19
|
+
* 云函数返回值。
|
|
20
|
+
*
|
|
21
|
+
* 默认 `any` 以保持对既有调用方(直接访问 `res.result.xxx`)的**非破坏**兼容;
|
|
22
|
+
* 推荐通过泛型参数指定精确类型以获得类型安全:`callFunction<{ n: number }>(...)`。
|
|
23
|
+
*/
|
|
24
|
+
result: T
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ICallFunction = <T = any>(
|
|
28
|
+
options: ICallFunctionOptions,
|
|
29
|
+
callback?: (err: Error | null, res: ICallFunctionResponse<T> | null) => void,
|
|
30
|
+
) => Promise<ICallFunctionResponse<T>>
|
|
31
|
+
|
|
32
|
+
export interface IRetryOptions {
|
|
33
|
+
retries?: number
|
|
34
|
+
factor?: number
|
|
35
|
+
minTimeout?: number
|
|
36
|
+
maxTimeout?: number
|
|
37
|
+
randomize?: boolean
|
|
38
|
+
timeouts?: number[]
|
|
39
|
+
timeoutOps?: {
|
|
40
|
+
timeout: number
|
|
41
|
+
cb: (...args: any[]) => void
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ICustomReqOpts {
|
|
46
|
+
timeout?: number
|
|
47
|
+
retryOptions?: IRetryOptions
|
|
48
|
+
from?: 'node-sdk'
|
|
49
|
+
}
|