@cloudbase/js-sdk 4.0.0 → 4.0.1-alpha.1

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +398 -0
  2. package/ai/dist/index.esm.js +2 -3
  3. package/ai/dist/index.esm.js.map +1 -0
  4. package/ai/dist/index.js +2 -21
  5. package/ai/dist/index.js.map +1 -0
  6. package/apis/dist/index.d.ts +1 -0
  7. package/apis/dist/index.esm.js +2 -0
  8. package/apis/dist/index.esm.js.map +1 -0
  9. package/apis/dist/index.js +2 -0
  10. package/apis/dist/index.js.map +1 -0
  11. package/{analytics → apis}/package.json +1 -1
  12. package/app/dist/index.esm.js +2 -11
  13. package/app/dist/index.esm.js.map +1 -0
  14. package/app/dist/index.js +2 -18
  15. package/app/dist/index.js.map +1 -0
  16. package/app/dist/index.node.esm.js +3 -0
  17. package/app/dist/index.node.esm.js.LICENSE.txt +13 -0
  18. package/app/dist/index.node.esm.js.map +1 -0
  19. package/app/dist/index.node.js +3 -0
  20. package/app/dist/index.node.js.LICENSE.txt +13 -0
  21. package/app/dist/index.node.js.map +1 -0
  22. package/app/package.json +12 -1
  23. package/auth/dist/index.d.ts +2 -2
  24. package/auth/dist/index.esm.js +3 -4
  25. package/auth/dist/index.esm.js.LICENSE.txt +12 -0
  26. package/auth/dist/index.esm.js.map +1 -0
  27. package/auth/dist/index.js +3 -9
  28. package/auth/dist/index.js.LICENSE.txt +12 -0
  29. package/auth/dist/index.js.map +1 -0
  30. package/cloudrun/dist/index.esm.js +2 -3
  31. package/cloudrun/dist/index.esm.js.map +1 -0
  32. package/cloudrun/dist/index.js +2 -21
  33. package/cloudrun/dist/index.js.map +1 -0
  34. package/container/dist/index.d.ts +2 -2
  35. package/container/dist/index.esm.js +2 -4
  36. package/container/dist/index.esm.js.map +1 -0
  37. package/container/dist/index.js +2 -9
  38. package/container/dist/index.js.map +1 -0
  39. package/core.d.ts +4331 -0
  40. package/core.node.d.ts +294 -0
  41. package/database/dist/index.esm.js +2 -47
  42. package/database/dist/index.esm.js.map +1 -0
  43. package/database/dist/index.js +2 -53
  44. package/database/dist/index.js.map +1 -0
  45. package/database/package.json +34 -4
  46. package/dist/index.cjs.js +3 -37
  47. package/dist/index.cjs.js.LICENSE.txt +12 -0
  48. package/dist/index.cjs.js.map +1 -0
  49. package/dist/index.esm.js +3 -32
  50. package/dist/index.esm.js.LICENSE.txt +12 -0
  51. package/dist/index.esm.js.map +1 -0
  52. package/dist/index.node.cjs.js +3 -0
  53. package/dist/index.node.cjs.js.LICENSE.txt +26 -0
  54. package/dist/index.node.cjs.js.map +1 -0
  55. package/dist/index.node.esm.js +3 -0
  56. package/dist/index.node.esm.js.LICENSE.txt +26 -0
  57. package/dist/index.node.esm.js.map +1 -0
  58. package/functions/dist/index.d.ts +2 -2
  59. package/functions/dist/index.esm.js +2 -4
  60. package/functions/dist/index.esm.js.map +1 -0
  61. package/functions/dist/index.js +2 -9
  62. package/functions/dist/index.js.map +1 -0
  63. package/index.d.ts +7 -1785
  64. package/index.node.d.ts +13 -0
  65. package/miniprogram_dist/ai/index.d.ts +42 -0
  66. package/miniprogram_dist/ai/index.js +2 -0
  67. package/miniprogram_dist/apis/index.d.ts +5 -0
  68. package/miniprogram_dist/apis/index.js +1 -0
  69. package/miniprogram_dist/app/index.d.ts +67 -0
  70. package/miniprogram_dist/app/index.js +2 -0
  71. package/miniprogram_dist/auth/index.d.ts +269 -0
  72. package/miniprogram_dist/auth/index.js +2 -0
  73. package/miniprogram_dist/cloudrun/index.d.ts +4 -0
  74. package/miniprogram_dist/cloudrun/index.js +1 -0
  75. package/miniprogram_dist/container/index.d.ts +13 -0
  76. package/miniprogram_dist/container/index.js +1 -0
  77. package/miniprogram_dist/database/index.d.ts +3 -0
  78. package/miniprogram_dist/database/index.js +1 -0
  79. package/miniprogram_dist/functions/index.d.ts +2 -0
  80. package/miniprogram_dist/functions/index.js +1 -0
  81. package/miniprogram_dist/index.js +1 -1
  82. package/miniprogram_dist/model/index.d.ts +5 -0
  83. package/miniprogram_dist/model/index.js +1 -0
  84. package/miniprogram_dist/mysql/index.d.ts +3 -0
  85. package/miniprogram_dist/mysql/index.js +1 -0
  86. package/miniprogram_dist/oauth/index.d.ts +22 -0
  87. package/miniprogram_dist/oauth/index.js +2 -0
  88. package/miniprogram_dist/realtime/index.d.ts +2 -0
  89. package/miniprogram_dist/realtime/index.js +1 -0
  90. package/miniprogram_dist/storage/index.d.ts +13 -0
  91. package/miniprogram_dist/storage/index.js +1 -0
  92. package/model/dist/index.esm.js +2 -3
  93. package/model/dist/index.esm.js.map +1 -0
  94. package/model/dist/index.js +2 -21
  95. package/model/dist/index.js.map +1 -0
  96. package/mysql/dist/index.d.ts +1 -0
  97. package/mysql/dist/index.esm.js +2 -0
  98. package/mysql/dist/index.esm.js.map +1 -0
  99. package/mysql/dist/index.js +2 -0
  100. package/mysql/dist/index.js.map +1 -0
  101. package/mysql/package.json +6 -0
  102. package/oauth/dist/index.esm.js +3 -3
  103. package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
  104. package/oauth/dist/index.esm.js.map +1 -0
  105. package/oauth/dist/index.js +3 -21
  106. package/oauth/dist/index.js.LICENSE.txt +12 -0
  107. package/oauth/dist/index.js.map +1 -0
  108. package/package.json +144 -18
  109. package/realtime/dist/index.d.ts +2 -2
  110. package/realtime/dist/index.esm.js +2 -4
  111. package/realtime/dist/index.esm.js.map +1 -0
  112. package/realtime/dist/index.js +2 -9
  113. package/realtime/dist/index.js.map +1 -0
  114. package/storage/dist/index.d.ts +2 -2
  115. package/storage/dist/index.esm.js +2 -4
  116. package/storage/dist/index.esm.js.map +1 -0
  117. package/storage/dist/index.js +2 -9
  118. package/storage/dist/index.js.map +1 -0
  119. package/types/analytics.d.ts +51 -0
  120. package/types/auth.d.ts +166 -0
  121. package/types/cache.d.ts +26 -0
  122. package/types/cloudrun.d.ts +9 -0
  123. package/types/component.d.ts +17 -0
  124. package/types/container.d.ts +93 -0
  125. package/types/database.d.ts +31 -0
  126. package/types/error.d.ts +40 -0
  127. package/types/events.d.ts +13 -0
  128. package/types/functions.d.ts +49 -0
  129. package/types/index.d.ts +269 -0
  130. package/types/package.json +47 -0
  131. package/types/realtime.d.ts +350 -0
  132. package/types/request.d.ts +30 -0
  133. package/types/result.d.ts +48 -0
  134. package/types/storage.d.ts +144 -0
  135. package/utilities/dist/cjs/adapters/index.d.ts +45 -0
  136. package/utilities/dist/cjs/adapters/index.js +68 -0
  137. package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
  138. package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
  139. package/utilities/dist/cjs/constants/common.d.ts +6 -0
  140. package/utilities/dist/cjs/constants/common.js +24 -0
  141. package/utilities/dist/cjs/constants/errors.d.ts +8 -0
  142. package/utilities/dist/cjs/constants/errors.js +12 -0
  143. package/utilities/dist/cjs/constants/index.d.ts +3 -0
  144. package/utilities/dist/cjs/constants/index.js +21 -0
  145. package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
  146. package/utilities/dist/cjs/helpers/decorators.js +238 -0
  147. package/utilities/dist/cjs/helpers/index.d.ts +1 -0
  148. package/utilities/dist/cjs/helpers/index.js +18 -0
  149. package/utilities/dist/cjs/index.d.ts +13 -0
  150. package/utilities/dist/cjs/index.js +51 -0
  151. package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
  152. package/utilities/dist/cjs/libs/abortController.js +25 -0
  153. package/utilities/dist/cjs/libs/cache.d.ts +17 -0
  154. package/utilities/dist/cjs/libs/cache.js +261 -0
  155. package/utilities/dist/cjs/libs/events.d.ts +27 -0
  156. package/utilities/dist/cjs/libs/events.js +108 -0
  157. package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
  158. package/utilities/dist/cjs/libs/langEvent.js +7 -0
  159. package/utilities/dist/cjs/libs/util.d.ts +49 -0
  160. package/utilities/dist/cjs/libs/util.js +282 -0
  161. package/utilities/dist/esm/adapters/index.d.ts +45 -0
  162. package/utilities/dist/esm/adapters/index.js +40 -0
  163. package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
  164. package/utilities/dist/esm/adapters/platforms/web.js +282 -0
  165. package/utilities/dist/esm/constants/common.d.ts +6 -0
  166. package/utilities/dist/esm/constants/common.js +17 -0
  167. package/utilities/dist/esm/constants/errors.d.ts +8 -0
  168. package/utilities/dist/esm/constants/errors.js +9 -0
  169. package/utilities/dist/esm/constants/index.d.ts +3 -0
  170. package/utilities/dist/esm/constants/index.js +4 -0
  171. package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
  172. package/utilities/dist/esm/helpers/decorators.js +234 -0
  173. package/utilities/dist/esm/helpers/index.d.ts +1 -0
  174. package/utilities/dist/esm/helpers/index.js +2 -0
  175. package/utilities/dist/esm/index.d.ts +13 -0
  176. package/utilities/dist/esm/index.js +14 -0
  177. package/utilities/dist/esm/libs/abortController.d.ts +9 -0
  178. package/utilities/dist/esm/libs/abortController.js +23 -0
  179. package/utilities/dist/esm/libs/cache.d.ts +17 -0
  180. package/utilities/dist/esm/libs/cache.js +258 -0
  181. package/utilities/dist/esm/libs/events.d.ts +27 -0
  182. package/utilities/dist/esm/libs/events.js +102 -0
  183. package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
  184. package/utilities/dist/esm/libs/langEvent.js +4 -0
  185. package/utilities/dist/esm/libs/util.d.ts +49 -0
  186. package/utilities/dist/esm/libs/util.js +254 -0
  187. package/utilities/dist/miniprogram/index.js +1 -0
  188. package/utilities/package.json +26 -0
  189. package/analytics/dist/index.d.ts +0 -2
  190. package/analytics/dist/index.esm.js +0 -4
  191. package/analytics/dist/index.js +0 -9
  192. package/miniprogram_dist/ai.js +0 -2
  193. package/miniprogram_dist/analytics.js +0 -1
  194. package/miniprogram_dist/app.js +0 -2
  195. package/miniprogram_dist/auth.js +0 -2
  196. package/miniprogram_dist/cloudrun.js +0 -1
  197. package/miniprogram_dist/container.js +0 -1
  198. package/miniprogram_dist/database.js +0 -2
  199. package/miniprogram_dist/functions.js +0 -1
  200. package/miniprogram_dist/model.js +0 -1
  201. package/miniprogram_dist/oauth.js +0 -1
  202. package/miniprogram_dist/realtime.js +0 -1
  203. 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
+ }
@@ -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
+ }
@@ -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,9 @@
1
+ import { KV } from '.'
2
+
3
+ export interface ICallContainerOptions {
4
+ name: string
5
+ data?: KV<any>
6
+ method?: string
7
+ path?: string
8
+ header?: KV<any>
9
+ }
@@ -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
+ }
@@ -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
+ }