@cloudbase/app 2.25.2 → 2.25.4
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 +34 -22
- package/dist/esm/libs/request.d.ts +3 -2
- package/dist/esm/libs/request.js +34 -22
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -4
- package/src/libs/request.ts +28 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/app",
|
|
3
|
-
"version": "2.25.
|
|
3
|
+
"version": "2.25.4",
|
|
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.4",
|
|
35
|
+
"@cloudbase/utilities": "2.25.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "cb3b43f79a34d6216a45f065ab940c4225fe55d5"
|
|
38
38
|
}
|
package/src/libs/request.ts
CHANGED
|
@@ -81,11 +81,12 @@ function beforeEach(): IAppendedRequestInfo {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
export interface IGateWayOptions {
|
|
84
|
-
name
|
|
84
|
+
name?: string
|
|
85
85
|
data?: any
|
|
86
|
-
path
|
|
86
|
+
path?: string
|
|
87
87
|
method: string
|
|
88
88
|
header?: {}
|
|
89
|
+
url?: string
|
|
89
90
|
}
|
|
90
91
|
export interface ICloudbaseRequest {
|
|
91
92
|
post: (options: IRequestOptions) => Promise<ResponseObject>
|
|
@@ -290,7 +291,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
290
291
|
const PROTOCOL = url.protocol
|
|
291
292
|
|
|
292
293
|
if (endPointMode === 'GATEWAY') {
|
|
293
|
-
if (/^(database)
|
|
294
|
+
if (/^((database)\.)|(auth\.wsWebSign)/.test(action)) {
|
|
294
295
|
const url = getEndPointInfo(this.config.env, 'CLOUD_API')
|
|
295
296
|
BASE_URL = `${url.baseUrl.match(/\/\/([^/?#]*)/)[0]}/web`
|
|
296
297
|
}
|
|
@@ -392,12 +393,12 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
392
393
|
}
|
|
393
394
|
|
|
394
395
|
public async gateWay(options: IGateWayOptions, customReqOpts?: ICustomReqOpts) {
|
|
395
|
-
const { name, data, path = '', method, header = {} } = options
|
|
396
|
+
const { url, name, data, path = '', method, header = {} } = options
|
|
396
397
|
|
|
397
|
-
if (!name || !path) {
|
|
398
|
+
if ((!name || !path) && !url) {
|
|
398
399
|
throw new Error(JSON.stringify({
|
|
399
400
|
code: ERRORS.INVALID_PARAMS,
|
|
400
|
-
msg: '[gateWay] invalid function name or path',
|
|
401
|
+
msg: '[gateWay] invalid function name or path or url',
|
|
401
402
|
}),)
|
|
402
403
|
}
|
|
403
404
|
let jsonData
|
|
@@ -412,7 +413,26 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
412
413
|
|
|
413
414
|
const requestId = utils.generateRequestId()
|
|
414
415
|
const { baseUrl, protocol } = getEndPointInfo(this.config.env, 'GATEWAY')
|
|
415
|
-
|
|
416
|
+
let endpoint = `${protocol}${baseUrl}${url || `/${path}/${name}`}`
|
|
417
|
+
|
|
418
|
+
const isGetAndHead = ['GET', 'HEAD'].includes(method?.toUpperCase?.())
|
|
419
|
+
|
|
420
|
+
if (isGetAndHead) {
|
|
421
|
+
try {
|
|
422
|
+
let dataParse = {}
|
|
423
|
+
try {
|
|
424
|
+
dataParse = JSON.parse(data as any)
|
|
425
|
+
} catch (error) {
|
|
426
|
+
dataParse = data || {}
|
|
427
|
+
}
|
|
428
|
+
endpoint = `${endpoint}${endpoint.includes('?') ? '&' : '?'}${Object.keys(dataParse)
|
|
429
|
+
.map(key => `${key}=${dataParse[key]}`)
|
|
430
|
+
.join('&')}`
|
|
431
|
+
} catch (error) {
|
|
432
|
+
//
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
416
436
|
const response = await this.fetch({
|
|
417
437
|
method: method || 'POST',
|
|
418
438
|
headers: {
|
|
@@ -420,7 +440,7 @@ export class CloudbaseRequest implements ICloudbaseRequest {
|
|
|
420
440
|
'X-Request-Id': requestId,
|
|
421
441
|
...header,
|
|
422
442
|
},
|
|
423
|
-
body: jsonData,
|
|
443
|
+
...(isGetAndHead ? {} : { body: jsonData }),
|
|
424
444
|
url: endpoint,
|
|
425
445
|
customReqOpts,
|
|
426
446
|
})
|