@mpxjs/api-proxy 2.9.52 → 2.9.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.52",
3
+ "version": "2.9.53",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "homepage": "https://github.com/didi/mpx#readme",
39
39
  "dependencies": {
40
40
  "@mpxjs/utils": "^2.9.50",
41
- "axios": "^1.6.7"
41
+ "axios": "^1.7.3"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@react-native-async-storage/async-storage": "^1.23.1",
@@ -64,5 +64,5 @@
64
64
  "optional": true
65
65
  }
66
66
  },
67
- "gitHead": "d8b89e0ba1f29a16244b247f6c7a8d8197e0d732"
67
+ "gitHead": "505776958d34f5fea4e0b6141a0dc83ef572eb08"
68
68
  }
@@ -1,6 +1,4 @@
1
- import { getEnvObj } from './utils'
2
-
3
- const envObj = getEnvObj()
1
+ import { ENV_OBJ } from './utils'
4
2
 
5
3
  // 特别指定的不进行Promise封装的方法
6
4
  const blackList = [
@@ -71,14 +69,14 @@ function promisify (listObj, whiteList, customBlackList) {
71
69
  const obj = args[0] || {}
72
70
  // 不需要转换 or 用户已定义回调,则不处理
73
71
  if (!promisifyFilter(key) || obj.success || obj.fail) {
74
- return listObj[key].apply(envObj, args)
72
+ return listObj[key].apply(ENV_OBJ, args)
75
73
  } else { // 其他情况进行转换
76
74
  if (!args[0]) args.unshift(obj)
77
75
  let returned
78
76
  const promise = new Promise((resolve, reject) => {
79
77
  obj.success = resolve
80
78
  obj.fail = reject
81
- returned = listObj[key].apply(envObj, args)
79
+ returned = listObj[key].apply(ENV_OBJ, args)
82
80
  })
83
81
  promise.__returned = returned
84
82
  return promise
@@ -1,3 +1,5 @@
1
+ import { hasOwn, noop, getEnvObj } from '@mpxjs/utils'
2
+
1
3
  /**
2
4
  *
3
5
  * @param {Object} options 原参数
@@ -12,16 +14,6 @@
12
14
  * d: 4 // 增加 d
13
15
  * })
14
16
  */
15
- const hasOwnProperty = Object.prototype.hasOwnProperty
16
-
17
- function type (n) {
18
- return Object.prototype.toString.call(n).slice(8, -1)
19
- }
20
-
21
- function hasOwn (obj, key) {
22
- return hasOwnProperty.call(obj, key)
23
- }
24
-
25
17
  function changeOpts (options, updateOrRemoveOpt = {}, extraOpt = {}) {
26
18
  let opts = {}
27
19
 
@@ -53,31 +45,6 @@ const handleSuccess = (opts, getOptions = noop, thisObj) => {
53
45
  }
54
46
  }
55
47
 
56
- function getEnvObj () {
57
- switch (__mpx_mode__) {
58
- case 'wx':
59
- return wx
60
- case 'ali':
61
- return my
62
- case 'swan':
63
- return swan
64
- case 'qq':
65
- return qq
66
- case 'tt':
67
- return tt
68
- case 'jd':
69
- return jd
70
- case 'qa':
71
- return qa
72
- case 'dd':
73
- return dd
74
- case 'web':
75
- case 'ios':
76
- case 'android':
77
- return {}
78
- }
79
- }
80
-
81
48
  function warn (msg) {
82
49
  console.warn && console.warn(`[@mpxjs/api-proxy warn]:\n ${msg}`)
83
50
  }
@@ -87,20 +54,10 @@ function error (msg) {
87
54
  }
88
55
  function envError (method) {
89
56
  return () => {
90
- console.error && console.error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
57
+ throw Error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
91
58
  }
92
59
  }
93
60
 
94
- function noop () {
95
- }
96
-
97
- function makeMap (arr) {
98
- return arr.reduce((obj, item) => {
99
- obj[item] = true
100
- return obj
101
- }, {})
102
- }
103
-
104
61
  function defineUnsupportedProps (resObj, props) {
105
62
  const defineProps = {}
106
63
  props.forEach((item) => {
@@ -125,16 +82,11 @@ const ENV_OBJ = getEnvObj()
125
82
  export {
126
83
  changeOpts,
127
84
  handleSuccess,
128
- getEnvObj,
129
85
  error,
130
86
  envError,
131
87
  warn,
132
- noop,
133
- makeMap,
134
88
  isBrowser,
135
- hasOwn,
136
89
  throwSSRWarning,
137
90
  ENV_OBJ,
138
- type,
139
91
  defineUnsupportedProps
140
92
  }
package/src/install.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as platformApi from './platform'
2
- import { getEnvObj } from './common/js'
2
+ import { ENV_OBJ } from './common/js'
3
3
  import promisify from './common/js/promisify'
4
4
 
5
5
  export default function install (target, options = {}) {
@@ -9,8 +9,7 @@ export default function install (target, options = {}) {
9
9
  blackList = [], // 强制不变成 promise 格式的 api
10
10
  custom = {} // 自定义转化规则
11
11
  } = options
12
- const envObj = getEnvObj()
13
- const transedApi = Object.assign({}, envObj, platformApi)
12
+ const transedApi = Object.assign({}, ENV_OBJ, platformApi)
14
13
  const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
15
14
  Object.assign(target, transedApi, promisedApi, custom[__mpx_mode__])
16
15
  }
@@ -1,4 +1,5 @@
1
- import { ENV_OBJ, changeOpts, noop } from '../../../common/js'
1
+ import { ENV_OBJ, changeOpts } from '../../../common/js'
2
+ import { noop } from '@mpxjs/utils'
2
3
 
3
4
  function showActionSheet (options = {}) {
4
5
  const opts = changeOpts(options, {
@@ -1,4 +1,5 @@
1
- import { ENV_OBJ, noop } from '../../../common/js'
1
+ import { ENV_OBJ } from '../../../common/js'
2
+ import { noop } from '@mpxjs/utils'
2
3
 
3
4
  function createSelectorQuery (options = {}) {
4
5
  const selectorQuery = ENV_OBJ.createSelectorQuery(options)
@@ -1,4 +1,5 @@
1
- import { ENV_OBJ, changeOpts, error, noop } from '../../../common/js'
1
+ import { ENV_OBJ, changeOpts, error } from '../../../common/js'
2
+ import { noop } from '@mpxjs/utils'
2
3
 
3
4
  const TIPS_NAME = '支付宝环境 mpx'
4
5
 
@@ -1,4 +1,5 @@
1
- import { webHandleSuccess, webHandleFail, type } from '../../../common/js'
1
+ import { webHandleSuccess, webHandleFail } from '../../../common/js'
2
+ import { type } from '@mpxjs/utils'
2
3
 
3
4
  const socketTasks = new Set()
4
5
 
@@ -1,4 +1,6 @@
1
- import { webHandleSuccess, webHandleFail, hasOwn, isBrowser, throwSSRWarning } from '../../../common/js'
1
+
2
+ import { webHandleSuccess, webHandleFail, isBrowser, throwSSRWarning } from '../../../common/js'
3
+ import { hasOwn } from '@mpxjs/utils'
2
4
 
3
5
  function setStorage (options = {}) {
4
6
  if (!isBrowser) {
@@ -1,5 +1,6 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage'
2
- import { envError, webHandleSuccess, webHandleFail, hasOwn, defineUnsupportedProps } from '../../../common/js'
2
+ import { hasOwn } from '@mpxjs/utils'
3
+ import { envError, webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../common/js'
3
4
  function setStorage (options) {
4
5
  const { key, data, success, fail, complete } = options
5
6
  let obj = {}
@@ -1,4 +1,4 @@
1
- import { ENV_OBJ, changeOpts, envError, handleSuccess } from '../../../common/js'
1
+ import { ENV_OBJ, changeOpts, envError, handleSuccess, defineUnsupportedProps } from '../../../common/js'
2
2
 
3
3
  function getSystemInfo (options = {}) {
4
4
  const opts = changeOpts(options)
@@ -32,7 +32,11 @@ function getSystemInfoSync () {
32
32
  return res
33
33
  }
34
34
 
35
- const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
35
+ const getDeviceInfo = function () {
36
+ const res = ENV_OBJ.getDeviceBaseInfo
37
+ defineUnsupportedProps(res, ['deviceAbi', 'benchmarkLevel', 'cpuType'])
38
+ return res
39
+ }
36
40
 
37
41
  const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
38
42
 
@@ -1,4 +1,5 @@
1
- import { webHandleSuccess, webHandleFail, hasOwn } from '../../../common/js'
1
+ import { webHandleSuccess, webHandleFail } from '../../../common/js'
2
+ import { hasOwn } from '@mpxjs/utils'
2
3
  import Vue from 'vue'
3
4
 
4
5
  function setTabBarStyle (options = {}) {
@@ -71,7 +71,6 @@ export default class Toast {
71
71
  this.title.textContent = opts.title || ''
72
72
 
73
73
  this.toast.classList.add('show')
74
-
75
74
  opts.duration >= 0 && this.hide({ duration: opts.duration }, type)
76
75
 
77
76
  const errMsg = type === 'loading' ? 'showLoading:ok' : 'showToast:ok'