uniapp-request-sdk 1.3.3 → 1.3.5

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 CHANGED
@@ -15,8 +15,12 @@ interface IParams {
15
15
  retryDelay?: number;
16
16
  /** token,APP初始化给到小程序的token */
17
17
  token?: string;
18
- /** 向APP得到token的event事件名称,默认getLoginInfo */
18
+ /** 向APP得到token的event事件名称,默认getToken */
19
19
  tokenEventName?: string;
20
+ /** token的header名称,默认Authorization */
21
+ tokenHeader?: string;
22
+ /** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
23
+ tokenPrefix?: string;
20
24
  }
21
25
  declare class UniRequest {
22
26
  /** 基准路径 */
@@ -31,6 +35,10 @@ declare class UniRequest {
31
35
  private retryDelay;
32
36
  private token?;
33
37
  private tokenEventName;
38
+ /** token的header名称,默认Authorization */
39
+ private tokenHeader;
40
+ /** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
41
+ private tokenPrefix;
34
42
  constructor(params?: IParams);
35
43
  private rejectHandler;
36
44
  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];
@@ -49,7 +63,7 @@ function getToken(eventName) {
49
63
  var timeout = setTimeout(rej, 5000);
50
64
  uni.sendNativeEvent(eventName, {}, function (resData) {
51
65
  clearTimeout(timeout);
52
- res(resData === null || resData === void 0 ? void 0 : resData.token);
66
+ res(resData);
53
67
  });
54
68
  });
55
69
  }
@@ -67,7 +81,11 @@ var UniRequest = /*#__PURE__*/function () {
67
81
  /** 超时时间 */
68
82
  this.timeout = 10000;
69
83
  this.retryDelay = 3000;
70
- this.tokenEventName = 'getLoginInfo';
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniapp-request-sdk",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "用于uniapp小程序的请求库的sdk",
5
5
  "main": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",