@cloudbase/app 2.8.26-beta.0 → 2.8.28-beta.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/dist/cjs/constants/common.d.ts +11 -11
- package/dist/cjs/constants/common.js +42 -48
- package/dist/cjs/index.js +18 -5
- package/dist/cjs/libs/request.js +4 -4
- package/dist/esm/constants/common.d.ts +11 -11
- package/dist/esm/constants/common.js +39 -43
- package/dist/esm/index.js +19 -6
- package/dist/esm/libs/request.js +5 -5
- package/package.json +4 -4
- package/src/constants/common.ts +46 -46
- package/src/index.ts +36 -13
- package/src/libs/request.ts +9 -4
package/src/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { adapters, constants, utils, helpers } from '@cloudbase/utilities'
|
|
2
2
|
import { SDKAdapterInterface, CloudbaseAdapter, IRequestConfig } from '@cloudbase/adapter-interface'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ICloudbaseConfig,
|
|
5
|
+
ICloudbaseUpgradedConfig,
|
|
6
|
+
ICloudbase,
|
|
7
|
+
ICloudbaseExtension,
|
|
8
|
+
KV,
|
|
9
|
+
ICloudbasePlatformInfo,
|
|
10
|
+
} from '@cloudbase/types'
|
|
4
11
|
import { ICloudbaseAuth } from '@cloudbase/types/auth'
|
|
5
12
|
import adapterForWxMp from '@cloudbase/adapter-wx_mp'
|
|
6
13
|
import { registerComponent, registerHook } from './libs/component'
|
|
@@ -13,14 +20,14 @@ import { initRequest, getRequestByEnvId } from './libs/request'
|
|
|
13
20
|
import {
|
|
14
21
|
getSdkName,
|
|
15
22
|
setSdkVersion,
|
|
16
|
-
setEndPoint,
|
|
17
23
|
setRegionLevelEndpoint,
|
|
18
24
|
setSdkName,
|
|
19
25
|
setGatewayEndPointWithEnv,
|
|
20
|
-
setEndPointWithKey,
|
|
21
|
-
getEndPointWithKey,
|
|
22
|
-
type ISetEndPointWithKey,
|
|
23
26
|
type EndPointKey,
|
|
27
|
+
type ISetEndPointWithKey,
|
|
28
|
+
setEndPointInfo,
|
|
29
|
+
getEndPointInfo,
|
|
30
|
+
getSdkVersion,
|
|
24
31
|
} from './constants/common'
|
|
25
32
|
export { getBaseEndPoint } from './constants/common'
|
|
26
33
|
const { useAdapters, useDefaultAdapter } = adapters
|
|
@@ -48,12 +55,14 @@ class Cloudbase implements ICloudbase {
|
|
|
48
55
|
public oauthInstance: any
|
|
49
56
|
public requestClient: any
|
|
50
57
|
public oauthClient: any
|
|
58
|
+
public version: string
|
|
51
59
|
private cloudbaseConfig: ICloudbaseConfig
|
|
52
60
|
|
|
53
61
|
constructor(config?: ICloudbaseConfig) {
|
|
54
62
|
this.cloudbaseConfig = config ? config : this.cloudbaseConfig
|
|
55
63
|
this.authInstance = null
|
|
56
64
|
this.oauthInstance = null
|
|
65
|
+
this.version = getSdkVersion()
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
get config() {
|
|
@@ -76,7 +85,6 @@ class Cloudbase implements ICloudbase {
|
|
|
76
85
|
return getRequestByEnvId(this.cloudbaseConfig.env)
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
|
|
80
88
|
@catchErrorsDecorator({
|
|
81
89
|
mode: 'sync',
|
|
82
90
|
title: 'Cloudbase 初始化失败',
|
|
@@ -92,7 +100,7 @@ class Cloudbase implements ICloudbase {
|
|
|
92
100
|
throw new Error(JSON.stringify({
|
|
93
101
|
code: ERRORS.INVALID_PARAMS,
|
|
94
102
|
msg: 'env must not be specified',
|
|
95
|
-
}))
|
|
103
|
+
}),)
|
|
96
104
|
}
|
|
97
105
|
// 初始化时若未兼容平台,则使用默认adapter
|
|
98
106
|
if (!Platform.adapter) {
|
|
@@ -101,7 +109,9 @@ class Cloudbase implements ICloudbase {
|
|
|
101
109
|
|
|
102
110
|
const reqConfig: IRequestConfig = {
|
|
103
111
|
timeout: config.timeout || 5000,
|
|
104
|
-
timeoutMsg: `[${getSdkName()}][REQUEST TIMEOUT] request had been abort since didn't finished within${
|
|
112
|
+
timeoutMsg: `[${getSdkName()}][REQUEST TIMEOUT] request had been abort since didn't finished within${
|
|
113
|
+
config.timeout / 1000
|
|
114
|
+
}s`,
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
this.requestClient = new Platform.adapter.reqClass(reqConfig)
|
|
@@ -115,13 +125,13 @@ class Cloudbase implements ICloudbase {
|
|
|
115
125
|
const { env, persistence, debug, timeout, oauthClient } = this.cloudbaseConfig
|
|
116
126
|
initCache({ env, persistence, debug, platformInfo: this.platform })
|
|
117
127
|
|
|
118
|
-
|
|
119
128
|
setRegionLevelEndpoint(env, config.region || '')
|
|
120
129
|
setGatewayEndPointWithEnv(env)
|
|
121
130
|
|
|
122
131
|
const app = new Cloudbase(this.cloudbaseConfig)
|
|
123
132
|
initRequest({ env, region: config.region || '', timeout, oauthClient, _fromApp: app })
|
|
124
133
|
app.requestClient = this.requestClient
|
|
134
|
+
;(this as any)?.fire?.('cloudbase_init', app)
|
|
125
135
|
return app
|
|
126
136
|
}
|
|
127
137
|
|
|
@@ -151,7 +161,7 @@ class Cloudbase implements ICloudbase {
|
|
|
151
161
|
throw new Error(JSON.stringify({
|
|
152
162
|
code: ERRORS.INVALID_PARAMS,
|
|
153
163
|
msg: `extension:${name} must be registered before invoke`,
|
|
154
|
-
}))
|
|
164
|
+
}),)
|
|
155
165
|
}
|
|
156
166
|
|
|
157
167
|
return await ext.invoke(opts, this)
|
|
@@ -173,22 +183,35 @@ class Cloudbase implements ICloudbase {
|
|
|
173
183
|
|
|
174
184
|
public registerVersion(version: string) {
|
|
175
185
|
setSdkVersion(version)
|
|
186
|
+
this.version = version
|
|
176
187
|
}
|
|
177
188
|
|
|
178
189
|
public registerSdkName(name: string) {
|
|
179
190
|
setSdkName(name)
|
|
180
191
|
}
|
|
181
192
|
|
|
193
|
+
/** 设置 tcb api 的 endpoint */
|
|
182
194
|
public registerEndPoint(url: string, protocol?: 'http' | 'https') {
|
|
183
|
-
|
|
195
|
+
setEndPointInfo({ baseUrl: url, protocol, env: this.config.env, endPointKey: 'CLOUD_API' })
|
|
184
196
|
}
|
|
185
197
|
|
|
198
|
+
/** 设置网关/tcb api的 endPoint,通过 key 指定 */
|
|
186
199
|
public registerEndPointWithKey(props: ISetEndPointWithKey) {
|
|
187
|
-
|
|
200
|
+
setEndPointInfo({
|
|
201
|
+
env: this.config.env,
|
|
202
|
+
endPointKey: props.key,
|
|
203
|
+
baseUrl: props.url,
|
|
204
|
+
protocol: props.protocol,
|
|
205
|
+
})
|
|
188
206
|
}
|
|
189
207
|
|
|
208
|
+
/** 拿网关/tcb api的 endPoint,通过 key 指定 */
|
|
190
209
|
public getEndPointWithKey(key: EndPointKey) {
|
|
191
|
-
|
|
210
|
+
const info = getEndPointInfo(this.config.env, key)
|
|
211
|
+
return {
|
|
212
|
+
BASE_URL: info.baseUrl,
|
|
213
|
+
PROTOCOL: info.protocol,
|
|
214
|
+
}
|
|
192
215
|
}
|
|
193
216
|
|
|
194
217
|
private useDefaultAdapter() {
|
package/src/libs/request.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DATA_VERSION, getSdkVersion,
|
|
1
|
+
import { DATA_VERSION, getSdkVersion, getBaseEndPoint, getEndPointInfo } from '../constants/common'
|
|
2
2
|
import {
|
|
3
3
|
IRequestOptions,
|
|
4
4
|
SDKRequestInterface,
|
|
@@ -131,7 +131,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
public getBaseEndPoint() {
|
|
134
|
-
return getBaseEndPoint()
|
|
134
|
+
return getBaseEndPoint(this.config.env)
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
public async getOauthAccessTokenV2(oauthClient: any): Promise<IGetAccessTokenResult> {
|
|
@@ -233,11 +233,16 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
233
233
|
...inQuery,
|
|
234
234
|
...formatQuery,
|
|
235
235
|
})
|
|
236
|
-
|
|
236
|
+
|
|
237
|
+
const { baseUrl: BASE_URL, protocol: PROTOCOL } = getEndPointInfo(this.config.env, 'CLOUD_API')
|
|
237
238
|
// 生成请求 url
|
|
238
239
|
let newUrl
|
|
239
240
|
if (options.pathname) {
|
|
240
|
-
newUrl = formatUrl(
|
|
241
|
+
newUrl = formatUrl(
|
|
242
|
+
PROTOCOL,
|
|
243
|
+
`${getBaseEndPoint(this.config.env)?.replace(/^https?:/, '')}/${options.pathname}`,
|
|
244
|
+
formatQuery,
|
|
245
|
+
)
|
|
241
246
|
} else {
|
|
242
247
|
newUrl = formatUrl(PROTOCOL, BASE_URL, formatQuery)
|
|
243
248
|
}
|