@cloudbase/app 2.25.1 → 2.25.3
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/libs/request.d.ts +3 -2
- package/dist/cjs/libs/request.js +27 -34
- package/dist/esm/libs/request.d.ts +3 -2
- package/dist/esm/libs/request.js +27 -34
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -4
- package/src/libs/request.ts +25 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/app",
|
|
3
|
-
"version": "2.25.
|
|
3
|
+
"version": "2.25.3",
|
|
4
4
|
"description": "cloudbase javascript sdk core",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@cloudbase/adapter-interface": "^0.7.1",
|
|
33
33
|
"@cloudbase/adapter-wx_mp": "^1.2.1",
|
|
34
|
-
"@cloudbase/types": "2.25.
|
|
35
|
-
"@cloudbase/utilities": "2.25.
|
|
34
|
+
"@cloudbase/types": "2.25.3",
|
|
35
|
+
"@cloudbase/utilities": "2.25.3"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2bf2f90d89b7e9b2a4bd232836f32b5f46868bb5"
|
|
38
38
|
}
|
package/src/libs/request.ts
CHANGED
|
@@ -48,19 +48,18 @@ function bindHooks(instance: SDKRequestInterface, name: string, hooks: IRequestB
|
|
|
48
48
|
Object.assign(headers, appendedHeaders)
|
|
49
49
|
})
|
|
50
50
|
const originData = options.data
|
|
51
|
-
originData
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
})()
|
|
51
|
+
originData && (() => {
|
|
52
|
+
if (isFormData(originData)) {
|
|
53
|
+
Object.keys(data).forEach((key) => {
|
|
54
|
+
(originData as FormData).append(key, data[key])
|
|
55
|
+
})
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
options.data = {
|
|
59
|
+
...originData,
|
|
60
|
+
...data,
|
|
61
|
+
}
|
|
62
|
+
})()
|
|
64
63
|
options.headers = {
|
|
65
64
|
...(options.headers || {}),
|
|
66
65
|
...headers,
|
|
@@ -81,11 +80,12 @@ function beforeEach(): IAppendedRequestInfo {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
export interface IGateWayOptions {
|
|
84
|
-
name
|
|
83
|
+
name?: string
|
|
85
84
|
data?: any
|
|
86
|
-
path
|
|
85
|
+
path?: string
|
|
87
86
|
method: string
|
|
88
87
|
header?: {}
|
|
88
|
+
url?: string
|
|
89
89
|
}
|
|
90
90
|
export interface ICloudbaseRequest {
|
|
91
91
|
post: (options: IRequestOptions) => Promise<ResponseObject>
|
|
@@ -277,11 +277,10 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
277
277
|
}
|
|
278
278
|
// 尝试解析响应数据为 JSON
|
|
279
279
|
parse && (formatQuery.parse = true)
|
|
280
|
-
inQuery
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
})
|
|
280
|
+
inQuery && (formatQuery = {
|
|
281
|
+
...inQuery,
|
|
282
|
+
...formatQuery,
|
|
283
|
+
})
|
|
285
284
|
|
|
286
285
|
const endPointMode = this.config.endPointMode || 'CLOUD_API'
|
|
287
286
|
|
|
@@ -290,7 +289,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
290
289
|
const PROTOCOL = url.protocol
|
|
291
290
|
|
|
292
291
|
if (endPointMode === 'GATEWAY') {
|
|
293
|
-
if (/^(database)
|
|
292
|
+
if (/^((database)\.)|(auth\.wsWebSign)/.test(action)) {
|
|
294
293
|
const url = getEndPointInfo(this.config.env, 'CLOUD_API')
|
|
295
294
|
BASE_URL = `${url.baseUrl.match(/\/\/([^/?#]*)/)[0]}/web`
|
|
296
295
|
}
|
|
@@ -392,12 +391,12 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
392
391
|
}
|
|
393
392
|
|
|
394
393
|
public async gateWay(options: IGateWayOptions, customReqOpts?: ICustomReqOpts) {
|
|
395
|
-
const { name, data, path = '', method, header = {} } = options
|
|
394
|
+
const { url, name, data, path = '', method, header = {} } = options
|
|
396
395
|
|
|
397
|
-
if (!name || !path) {
|
|
396
|
+
if ((!name || !path) && !url) {
|
|
398
397
|
throw new Error(JSON.stringify({
|
|
399
398
|
code: ERRORS.INVALID_PARAMS,
|
|
400
|
-
msg: '[gateWay] invalid function name or path',
|
|
399
|
+
msg: '[gateWay] invalid function name or path or url',
|
|
401
400
|
}),)
|
|
402
401
|
}
|
|
403
402
|
let jsonData
|
|
@@ -412,7 +411,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
412
411
|
|
|
413
412
|
const requestId = utils.generateRequestId()
|
|
414
413
|
const { baseUrl, protocol } = getEndPointInfo(this.config.env, 'GATEWAY')
|
|
415
|
-
const endpoint = `${protocol}${baseUrl}
|
|
414
|
+
const endpoint = `${protocol}${baseUrl}${url || `/${path}/${name}`}`
|
|
416
415
|
const response = await this.fetch({
|
|
417
416
|
method: method || 'POST',
|
|
418
417
|
headers: {
|
|
@@ -420,7 +419,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
420
419
|
'X-Request-Id': requestId,
|
|
421
420
|
...header,
|
|
422
421
|
},
|
|
423
|
-
body: jsonData,
|
|
422
|
+
...(['GET', 'HEAD'].includes(method?.toUpperCase?.()) ? {} : { body: jsonData }),
|
|
424
423
|
url: endpoint,
|
|
425
424
|
customReqOpts,
|
|
426
425
|
})
|