@cloudbase/types 3.0.0 → 3.0.2
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/auth.d.ts +72 -55
- package/functions.d.ts +18 -0
- package/index.d.ts +30 -8
- package/package.json +2 -2
- package/request.d.ts +1 -1
- package/storage.d.ts +33 -4
package/auth.d.ts
CHANGED
|
@@ -1,78 +1,95 @@
|
|
|
1
1
|
import { ICloudbaseConfig, KV, ICloudbase } from '.'
|
|
2
|
+
import { authModels, UserInfo } from '@cloudbase/oauth'
|
|
3
|
+
import { ICloudbaseEventEmitter } from './events'
|
|
2
4
|
|
|
3
|
-
export type ICloudbaseAuthConfig = Pick<
|
|
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
|
+
> &
|
|
19
|
+
ICloudbaseConfig['auth']
|
|
20
|
+
& {eventBus?: ICloudbaseEventEmitter}
|
|
4
21
|
|
|
5
22
|
export interface IAccessTokenInfo {
|
|
6
|
-
accessToken: string
|
|
7
|
-
env: string
|
|
23
|
+
accessToken: string
|
|
24
|
+
env: string
|
|
8
25
|
}
|
|
9
26
|
export interface ICredential {
|
|
10
27
|
// refreshToken: string;
|
|
11
|
-
accessToken?: string
|
|
12
|
-
accessTokenExpire?: string
|
|
28
|
+
accessToken?: string
|
|
29
|
+
accessTokenExpire?: string
|
|
13
30
|
}
|
|
14
31
|
export interface IAuthProvider {
|
|
15
|
-
signInWithRedirect: () => any
|
|
32
|
+
signInWithRedirect: () => any
|
|
16
33
|
}
|
|
17
34
|
export interface IUserInfo {
|
|
18
|
-
uid?: string
|
|
19
|
-
loginType?: string
|
|
20
|
-
openid?: string
|
|
21
|
-
wxOpenId?: string
|
|
22
|
-
wxPublicId?: string
|
|
23
|
-
unionId?: string
|
|
24
|
-
qqMiniOpenId?: string
|
|
25
|
-
customUserId?: string
|
|
26
|
-
name?: string
|
|
27
|
-
gender?: string
|
|
28
|
-
email?: string
|
|
29
|
-
username?: string
|
|
30
|
-
hasPassword?: boolean
|
|
35
|
+
uid?: string
|
|
36
|
+
loginType?: string
|
|
37
|
+
openid?: string
|
|
38
|
+
wxOpenId?: string
|
|
39
|
+
wxPublicId?: string
|
|
40
|
+
unionId?: string
|
|
41
|
+
qqMiniOpenId?: string
|
|
42
|
+
customUserId?: string
|
|
43
|
+
name?: string
|
|
44
|
+
gender?: string
|
|
45
|
+
email?: string
|
|
46
|
+
username?: string
|
|
47
|
+
hasPassword?: boolean
|
|
31
48
|
location?: {
|
|
32
|
-
country?: string
|
|
33
|
-
province?: string
|
|
34
|
-
city?: string
|
|
35
|
-
}
|
|
36
|
-
country?: string
|
|
37
|
-
province?: string
|
|
38
|
-
city?: string
|
|
49
|
+
country?: string
|
|
50
|
+
province?: string
|
|
51
|
+
city?: string
|
|
52
|
+
}
|
|
53
|
+
country?: string
|
|
54
|
+
province?: string
|
|
55
|
+
city?: string
|
|
39
56
|
}
|
|
40
57
|
export interface IUser extends IUserInfo {
|
|
41
|
-
checkLocalInfo: () => void
|
|
42
|
-
checkLocalInfoAsync: () => Promise<void
|
|
43
|
-
linkWithTicket?: (ticket: string) => Promise<void
|
|
44
|
-
linkWithRedirect?: (provider: IAuthProvider) => void
|
|
45
|
-
getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean
|
|
46
|
-
setPrimaryUid?: (uid: string) => Promise<void
|
|
47
|
-
unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void
|
|
48
|
-
update: (userinfo:
|
|
49
|
-
refresh: (params?: {version?: string
|
|
58
|
+
checkLocalInfo: () => void
|
|
59
|
+
checkLocalInfoAsync: () => Promise<void>
|
|
60
|
+
linkWithTicket?: (ticket: string) => Promise<void>
|
|
61
|
+
linkWithRedirect?: (provider: IAuthProvider) => void
|
|
62
|
+
getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean; users: IUserInfo[] }>
|
|
63
|
+
setPrimaryUid?: (uid: string) => Promise<void>
|
|
64
|
+
unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>
|
|
65
|
+
update: (userinfo: authModels.UserProfile) => Promise<void>
|
|
66
|
+
refresh: (params?: { version?: string }) => Promise<authModels.UserInfo>
|
|
50
67
|
}
|
|
51
68
|
export interface ILoginState {
|
|
52
|
-
user: IUser
|
|
69
|
+
user: IUser
|
|
53
70
|
}
|
|
54
71
|
export interface ICloudbaseAuth {
|
|
55
|
-
config: ICloudbaseConfig
|
|
56
|
-
loginType: string
|
|
57
|
-
weixinAuthProvider: any
|
|
58
|
-
anonymousAuthProvider: any
|
|
59
|
-
customAuthProvider: any
|
|
60
|
-
getAccessToken: () => IAccessTokenInfo
|
|
61
|
-
getLoginState: () => Promise<ILoginState | null
|
|
62
|
-
hasLoginState: () => Promise<ILoginState | null
|
|
63
|
-
getUserInfo: () => Promise<
|
|
64
|
-
getAuthHeader: () => Promise<KV<string
|
|
65
|
-
onLoginStateChanged: (callback: Function) => void
|
|
66
|
-
onLoginStateExpired: (callback: Function) => void
|
|
67
|
-
onAccessTokenRefreshed: (callback: Function) => void
|
|
68
|
-
onAnonymousConverted: (callback: Function) => void
|
|
69
|
-
onLoginTypeChanged: (callback: Function) => void
|
|
70
|
-
shouldRefreshAccessToken: (hook: Function) => void
|
|
72
|
+
config: ICloudbaseConfig
|
|
73
|
+
loginType: string
|
|
74
|
+
weixinAuthProvider: any
|
|
75
|
+
anonymousAuthProvider: any
|
|
76
|
+
customAuthProvider: any
|
|
77
|
+
getAccessToken: () => IAccessTokenInfo
|
|
78
|
+
getLoginState: () => Promise<ILoginState | null>
|
|
79
|
+
hasLoginState: () => Promise<ILoginState | null>
|
|
80
|
+
getUserInfo: () => Promise<UserInfo & IUser>
|
|
81
|
+
getAuthHeader: () => Promise<KV<string>>
|
|
82
|
+
onLoginStateChanged: (callback: Function) => void
|
|
83
|
+
onLoginStateExpired: (callback: Function) => void
|
|
84
|
+
onAccessTokenRefreshed: (callback: Function) => void
|
|
85
|
+
onAnonymousConverted: (callback: Function) => void
|
|
86
|
+
onLoginTypeChanged: (callback: Function) => void
|
|
87
|
+
shouldRefreshAccessToken: (hook: Function) => void
|
|
71
88
|
}
|
|
72
89
|
|
|
73
|
-
type IProvider = new (...args: any[]) => any
|
|
90
|
+
type IProvider = new (...args: any[]) => any
|
|
74
91
|
|
|
75
92
|
export interface ICloudbaseAuthModule {
|
|
76
|
-
registerAuth: (app: ICloudbase) => void
|
|
77
|
-
registerProvider: (name: string, provider: IProvider) => void
|
|
93
|
+
registerAuth: (app: ICloudbase) => void
|
|
94
|
+
registerProvider: (name: string, provider: IProvider) => void
|
|
78
95
|
}
|
package/functions.d.ts
CHANGED
|
@@ -20,3 +20,21 @@ export interface ICallFunctionResponse {
|
|
|
20
20
|
|
|
21
21
|
export type ICallFunction = (options: ICallFunctionOptions, callback?: Function) => Promise<ICallFunctionResponse>
|
|
22
22
|
|
|
23
|
+
export interface IRetryOptions {
|
|
24
|
+
retries?: number
|
|
25
|
+
factor?: number
|
|
26
|
+
minTimeout?: number
|
|
27
|
+
maxTimeout?: number
|
|
28
|
+
randomize?: boolean
|
|
29
|
+
timeouts?: number[]
|
|
30
|
+
timeoutOps?: {
|
|
31
|
+
timeout: number
|
|
32
|
+
cb: function
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ICustomReqOpts {
|
|
37
|
+
timeout?: number
|
|
38
|
+
retryOptions?: IRetryOptions
|
|
39
|
+
from?: 'node-sdk'
|
|
40
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CloudbaseAdapter, SDKAdapterInterface } from '@cloudbase/adapter-interface'
|
|
1
|
+
import { CloudbaseAdapter, SDKAdapterInterface, ResponseObject } from '@cloudbase/adapter-interface'
|
|
2
2
|
import { ICloudbaseComponent, ICloudbaseHook } from './component'
|
|
3
3
|
import { ICloudbaseRequest } from './request'
|
|
4
4
|
import { ICloudbaseCache } from './cache'
|
|
5
5
|
import { ICloudbaseAuth } from './auth'
|
|
6
|
+
import { cloudbase } from '../cloudbase/index'
|
|
6
7
|
|
|
7
8
|
export enum LANGS {
|
|
8
9
|
ZH = 'zh-CN',
|
|
@@ -19,6 +20,8 @@ export interface KVstring {
|
|
|
19
20
|
[key: string]: string
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export type EndPointKey = 'CLOUD_API' | 'GATEWAY'
|
|
24
|
+
|
|
22
25
|
export interface ICloudbaseConfig {
|
|
23
26
|
env: string
|
|
24
27
|
region?: string
|
|
@@ -31,11 +34,16 @@ export interface ICloudbaseConfig {
|
|
|
31
34
|
oauthInstance?: any
|
|
32
35
|
wxCloud?: any
|
|
33
36
|
i18n?: {
|
|
34
|
-
t: (text: string) => string
|
|
35
|
-
LANG_HEADER_KEY: string
|
|
36
|
-
lang: LANGS
|
|
37
|
+
t: (text: string) => string
|
|
38
|
+
LANG_HEADER_KEY: string
|
|
39
|
+
lang: LANGS
|
|
40
|
+
}
|
|
41
|
+
accessKey?: string
|
|
42
|
+
endPointMode?: EndPointKey // auth请求域名模式,默认CLOUD_API
|
|
43
|
+
useWxCloud?: boolean // 是否使用微信云开发链路
|
|
44
|
+
auth?: {
|
|
45
|
+
detectSessionInUrl?: boolean
|
|
37
46
|
}
|
|
38
|
-
publishable_key?: string
|
|
39
47
|
}
|
|
40
48
|
// 可更新的配置字段
|
|
41
49
|
export type ICloudbaseUpgradedConfig = Pick<ICloudbaseConfig, 'persistence' | 'region' | 'debug'>
|
|
@@ -45,6 +53,13 @@ export interface ICloudbaseExtension {
|
|
|
45
53
|
invoke: (opts: any, app: ICloudbase) => Promise<any>
|
|
46
54
|
}
|
|
47
55
|
|
|
56
|
+
declare type MethodType = 'request' | 'post' | 'get' | 'head' | 'patch' | 'delete' | 'put'
|
|
57
|
+
export interface ICloudbaseApis {
|
|
58
|
+
[apiName: string]: {
|
|
59
|
+
[method in MethodType]: (callApiOptions: ICallApiOptions, opts?: KV<any>) => Promise<ResponseObject['data']>
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
export interface ICloudbase {
|
|
49
64
|
config: ICloudbaseConfig
|
|
50
65
|
platform: ICloudbasePlatformInfo
|
|
@@ -54,7 +69,8 @@ export interface ICloudbase {
|
|
|
54
69
|
localCache: ICloudbaseCache
|
|
55
70
|
authInstance?: ICloudbaseAuth
|
|
56
71
|
oauthInstance?: any
|
|
57
|
-
|
|
72
|
+
apis: ICloudbaseApis
|
|
73
|
+
init: (config: ICloudbaseConfig & { lang?: LANGS }) => cloudbase.app
|
|
58
74
|
updateConfig: (config: ICloudbaseUpgradedConfig) => void
|
|
59
75
|
registerExtension: (ext: ICloudbaseExtension) => void
|
|
60
76
|
invokeExtension: (name: string, opts: any) => Promise<any>
|
|
@@ -63,6 +79,12 @@ export interface ICloudbase {
|
|
|
63
79
|
registerHook: (hook: ICloudbaseHook) => void
|
|
64
80
|
registerVersion: (version: string) => void
|
|
65
81
|
fire?: (...args: any[]) => void
|
|
82
|
+
updateLang?: (lang: LANGS) => void
|
|
83
|
+
getEndPointWithKey?: (key: EndPointKey) => {
|
|
84
|
+
BASE_URL: string
|
|
85
|
+
PROTOCOL: string
|
|
86
|
+
}
|
|
87
|
+
auth?: (options?: { persistence: cloudbase.auth.Persistence }) => cloudbase.auth.App
|
|
66
88
|
}
|
|
67
89
|
export interface ICloudbasePlatformInfo {
|
|
68
90
|
adapter?: SDKAdapterInterface
|
|
@@ -77,12 +99,12 @@ export interface IGenericError<T extends string, P = any> extends Error {
|
|
|
77
99
|
|
|
78
100
|
export interface ICallApiOptions {
|
|
79
101
|
/** api标识 */
|
|
80
|
-
name
|
|
102
|
+
name?: string
|
|
81
103
|
/** 请求的path */
|
|
82
104
|
path?: string
|
|
83
105
|
method?: string
|
|
84
106
|
headers?: KV<any>
|
|
85
107
|
/** 请求体,根据content-type可以是不同类型 */
|
|
86
108
|
body?: KV<any> | string
|
|
87
|
-
token?: string
|
|
109
|
+
token?: string
|
|
88
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/types",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "cloudbase javascript sdk types",
|
|
5
5
|
"files": [
|
|
6
6
|
"index.js",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"lint": "eslint --fix \"./**/*.ts\"",
|
|
44
44
|
"precommit": "npm run lint"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "56b879a3e173e64e44ca36c1260b3fc66d0e822a"
|
|
47
47
|
}
|
package/request.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface IGetAccessTokenResult {
|
|
|
10
10
|
accessTokenExpire: number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export type ICloudbaseRequestConfig = Pick<ICloudbaseConfig, 'env' | 'region' | 'timeout' | 'oauthClient' | '_fromApp' | 'i18n' | '
|
|
13
|
+
export type ICloudbaseRequestConfig = Pick<ICloudbaseConfig, 'env' | 'region' | 'timeout' | 'oauthClient' | '_fromApp' | 'i18n' | 'endPointMode'>;
|
|
14
14
|
|
|
15
15
|
export interface IAppendedRequestInfo {
|
|
16
16
|
data: KV<any>;
|
package/storage.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { KVstring } from '.'
|
|
2
|
+
import { ICustomReqOpts } from './functions'
|
|
2
3
|
|
|
3
4
|
export interface ICloudbaseUploadFileParams {
|
|
4
5
|
cloudPath: string;
|
|
5
6
|
filePath: string;
|
|
6
7
|
method?: 'post' | 'put';
|
|
7
|
-
headers?: KVstring
|
|
8
|
+
headers?: KVstring;
|
|
8
9
|
onUploadProgress?: Function;
|
|
10
|
+
// 文件内容 Buffer 或 文件可读流, node端使用
|
|
11
|
+
fileContent?: any;
|
|
12
|
+
customReqOpts?: ICustomReqOpts;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
export interface ICloudbaseUploadFileByPutParams {
|
|
12
16
|
cloudPath: string;
|
|
13
17
|
filePath: string;
|
|
14
|
-
headers?: KVstring
|
|
18
|
+
headers?: KVstring;
|
|
15
19
|
onUploadProgress?: Function;
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -24,12 +28,14 @@ export type ICloudbaseUploadFile = (params: ICloudbaseUploadFileParams, callback
|
|
|
24
28
|
|
|
25
29
|
export interface ICloudbaseGetUploadMetadataParams {
|
|
26
30
|
cloudPath: string;
|
|
31
|
+
customReqOpts?: ICustomReqOpts;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
export type ICloudbaseGetUploadMetadata = (params: ICloudbaseGetUploadMetadataParams, callback?: Function) => Promise<any>;
|
|
30
35
|
|
|
31
36
|
export interface ICloudbaseDeleteFileParams {
|
|
32
37
|
fileList: string[];
|
|
38
|
+
customReqOpts?: ICustomReqOpts;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
export type ICloudbaseDeleteFile = (params: ICloudbaseDeleteFileParams, callback?: Function) => Promise<ICloudbaseDeleteFileResult>;
|
|
@@ -51,8 +57,8 @@ export interface ICloudbaseFileInfo {
|
|
|
51
57
|
|
|
52
58
|
export interface ICloudbaseGetTempFileURLParams {
|
|
53
59
|
fileList: string[] | ICloudbaseFileInfo[];
|
|
60
|
+
customReqOpts?: ICustomReqOpts;
|
|
54
61
|
}
|
|
55
|
-
|
|
56
62
|
export interface ICloudbaseGetTempFileURLResult {
|
|
57
63
|
code?: string;
|
|
58
64
|
message?: string;
|
|
@@ -66,11 +72,32 @@ export interface ICloudbaseGetTempFileURLResult {
|
|
|
66
72
|
requestId?: string;
|
|
67
73
|
}
|
|
68
74
|
|
|
75
|
+
export interface ICloudbaseCopyFileParams {
|
|
76
|
+
fileList: Array<{
|
|
77
|
+
srcPath: string
|
|
78
|
+
dstPath: string
|
|
79
|
+
overwrite?: boolean
|
|
80
|
+
removeOriginal?: boolean
|
|
81
|
+
}>
|
|
82
|
+
customReqOpts?: ICustomReqOpts;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export interface ICloudbaseCopyFileResult {
|
|
87
|
+
fileList: Array<{
|
|
88
|
+
fileId?: string
|
|
89
|
+
code?: string
|
|
90
|
+
message?: string
|
|
91
|
+
}>
|
|
92
|
+
requestId?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
69
95
|
export type ICloudbaseGetTempFileURL = (params: ICloudbaseGetTempFileURLParams, callback?: Function) => Promise<ICloudbaseGetTempFileURLResult>;
|
|
70
96
|
|
|
71
97
|
export interface ICloudbaseDownloadFileParams {
|
|
72
98
|
fileID: string;
|
|
73
99
|
tempFilePath?: string;
|
|
100
|
+
customReqOpts?: ICustomReqOpts;
|
|
74
101
|
}
|
|
75
102
|
|
|
76
103
|
export interface ICloudbaseDownloadFileResult {
|
|
@@ -88,7 +115,9 @@ export interface ICloudbaseFileMetaData {
|
|
|
88
115
|
authorization: string;
|
|
89
116
|
fileId: string;
|
|
90
117
|
cosFileId: string;
|
|
91
|
-
download_url: string
|
|
118
|
+
download_url: string;
|
|
119
|
+
code?: string;
|
|
120
|
+
message?: string;
|
|
92
121
|
}
|
|
93
122
|
|
|
94
123
|
export interface ICloudbaseFileMetaDataRes {
|