uniapp-request-sdk 1.3.4 → 1.3.6
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/index.d.ts +12 -0
- package/dist/index.esm.js +20 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ interface IParams {
|
|
|
17
17
|
token?: string;
|
|
18
18
|
/** 向APP得到token的event事件名称,默认getToken */
|
|
19
19
|
tokenEventName?: string;
|
|
20
|
+
/** token的header名称,默认Authorization */
|
|
21
|
+
tokenHeader?: string;
|
|
22
|
+
/** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
|
|
23
|
+
tokenPrefix?: string;
|
|
24
|
+
/** 自定义得到token的函数,默认使用从客户端获取token的方式 */
|
|
25
|
+
getTokenFun: () => Promise<string>;
|
|
20
26
|
}
|
|
21
27
|
declare class UniRequest {
|
|
22
28
|
/** 基准路径 */
|
|
@@ -31,6 +37,12 @@ declare class UniRequest {
|
|
|
31
37
|
private retryDelay;
|
|
32
38
|
private token?;
|
|
33
39
|
private tokenEventName;
|
|
40
|
+
/** token的header名称,默认Authorization */
|
|
41
|
+
private tokenHeader;
|
|
42
|
+
/** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
|
|
43
|
+
private tokenPrefix;
|
|
44
|
+
/** 自定义得到token的函数 */
|
|
45
|
+
private getTokenFun?;
|
|
34
46
|
constructor(params?: IParams);
|
|
35
47
|
private rejectHandler;
|
|
36
48
|
setParams(params?: IParams): void;
|
package/dist/index.esm.js
CHANGED
|
@@ -20,6 +20,20 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
20
20
|
});
|
|
21
21
|
return Constructor;
|
|
22
22
|
}
|
|
23
|
+
function _defineProperty(obj, key, value) {
|
|
24
|
+
key = _toPropertyKey(key);
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
23
37
|
function _toPrimitive(input, hint) {
|
|
24
38
|
if (typeof input !== "object" || input === null) return input;
|
|
25
39
|
var prim = input[Symbol.toPrimitive];
|
|
@@ -68,6 +82,10 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
68
82
|
this.timeout = 10000;
|
|
69
83
|
this.retryDelay = 3000;
|
|
70
84
|
this.tokenEventName = 'getToken';
|
|
85
|
+
/** token的header名称,默认Authorization */
|
|
86
|
+
this.tokenHeader = 'Authorization';
|
|
87
|
+
/** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
|
|
88
|
+
this.tokenPrefix = 'Bearer ';
|
|
71
89
|
if (params) {
|
|
72
90
|
Object.keys(params).forEach(function (key) {
|
|
73
91
|
if (params[key] !== void 0) {
|
|
@@ -106,9 +124,7 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
106
124
|
} else {
|
|
107
125
|
url = "".concat(params.url, "?t=").concat(Date.now());
|
|
108
126
|
}
|
|
109
|
-
var header = Object.assign(Object.assign(Object.assign({}, this.header), params.header), {
|
|
110
|
-
Authorization: "Bearer ".concat(this.token)
|
|
111
|
-
});
|
|
127
|
+
var header = Object.assign(Object.assign(Object.assign({}, this.header), params.header), _defineProperty({}, this.tokenHeader, "".concat(this.tokenPrefix).concat(this.token)));
|
|
112
128
|
var requestedToken = false;
|
|
113
129
|
var retryCount = 0;
|
|
114
130
|
return new Promise(function (res, rej) {
|
|
@@ -128,7 +144,7 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
128
144
|
}
|
|
129
145
|
} else if (statusCode === 403 && !requestedToken) {
|
|
130
146
|
// #ifndef H5
|
|
131
|
-
getToken(_this3.tokenEventName).then(function (token) {
|
|
147
|
+
(_this3.getTokenFun ? _this3.getTokenFun() : getToken(_this3.tokenEventName)).then(function (token) {
|
|
132
148
|
_this3.token = token;
|
|
133
149
|
requestedToken = true;
|
|
134
150
|
delayRetryFcuntion();
|