@mpxjs/api-proxy 2.9.11-test.0 → 2.9.14

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.11-test.0",
3
+ "version": "2.9.14",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "dependencies": {
40
40
  "axios": "^0.21.1"
41
41
  },
42
- "gitHead": "d244d661acb081b709fc99ca8f6add541f793877"
42
+ "gitHead": "e8ab845a544d2db0619a6a7d6c04d9d384d1a6ca"
43
43
  }
@@ -1,4 +1,4 @@
1
- import { genFromMap, getEnvObj, noop } from './utils'
1
+ import { getEnvObj, noop } from './utils'
2
2
 
3
3
  const envObj = getEnvObj()
4
4
 
@@ -20,6 +20,7 @@ const blackList = [
20
20
  'createAnimationVideo',
21
21
  'createSelectorQuery',
22
22
  'createIntersectionObserver',
23
+ 'getPerformance',
23
24
  'hideKeyboard',
24
25
  'stopPullDownRefresh',
25
26
  'createWorker',
@@ -47,7 +48,6 @@ function promisify (listObj, whiteList, customBlackList) {
47
48
  const result = {}
48
49
  const whiteListMap = getMapFromList(whiteList)
49
50
  const blackListMap = getMapFromList(blackList.concat(customBlackList))
50
- const fromMap = genFromMap()
51
51
 
52
52
  function promisifyFilter (key) {
53
53
  if (whiteListMap && whiteListMap[key] !== undefined) {
@@ -69,7 +69,7 @@ function promisify (listObj, whiteList, customBlackList) {
69
69
 
70
70
  result[key] = function (...args) {
71
71
  if (promisifyFilter(key)) {
72
- if (!args[0] || fromMap[args[0]]) {
72
+ if (!args[0]) {
73
73
  args.unshift({ success: noop, fail: noop })
74
74
  }
75
75
  const obj = args[0]
@@ -49,15 +49,6 @@ const handleSuccess = (opts, getOptions = noop, thisObj) => {
49
49
  }
50
50
  }
51
51
 
52
- function genFromMap () {
53
- const result = {}
54
- const platforms = ['wx', 'ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd']
55
- platforms.forEach((platform) => {
56
- result[`__mpx_src_mode_${platform}__`] = platform
57
- })
58
- return result
59
- }
60
-
61
52
  function getEnvObj () {
62
53
  switch (__mpx_mode__) {
63
54
  case 'wx':
@@ -81,29 +72,6 @@ function getEnvObj () {
81
72
  }
82
73
  }
83
74
 
84
- function getEnvStr () {
85
- switch (__mpx_mode__) {
86
- case 'wx':
87
- return 'wx'
88
- case 'ali':
89
- return 'ali'
90
- case 'swan':
91
- return 'swan'
92
- case 'qq':
93
- return 'qq'
94
- case 'tt':
95
- return 'tt'
96
- case 'jd':
97
- return 'jd'
98
- case 'qa':
99
- return 'qa'
100
- case 'dd':
101
- return 'dd'
102
- case 'web':
103
- return 'web'
104
- }
105
- }
106
-
107
75
  function warn (msg) {
108
76
  console.warn && console.warn(`[@mpxjs/api-proxy warn]:\n ${msg}`)
109
77
  }
@@ -135,9 +103,7 @@ function throwSSRWarning (info) {
135
103
  export {
136
104
  changeOpts,
137
105
  handleSuccess,
138
- genFromMap,
139
106
  getEnvObj,
140
- getEnvStr,
141
107
  error,
142
108
  envError,
143
109
  warn,
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import install, { getProxy } from './install'
2
+ import promisify from './common/js/promisify'
2
3
  export * from './platform'
3
- export { getProxy }
4
+ export { getProxy, promisify }
4
5
  export default install
package/src/install.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as platformApi from './platform'
2
- import { getEnvObj, getEnvStr } from './common/js'
2
+ import { getEnvObj } from './common/js'
3
3
  import promisify from './common/js/promisify'
4
4
 
5
5
  export default function install (target, options = {}) {
@@ -7,52 +7,12 @@ export default function install (target, options = {}) {
7
7
  usePromise = false, // 是否转为 promise 格式
8
8
  whiteList = [], // 强制变成 promise 格式的 api
9
9
  blackList = [], // 强制不变成 promise 格式的 api
10
- custom = {}, // 自定义转化规则
11
- fallbackMap = {} // 对于不支持的API,允许配置一个映射表,接管不存在的API
10
+ custom = {} // 自定义转化规则
12
11
  } = options
13
-
14
- let transedApi = {}
15
- const envStr = getEnvStr()
16
-
17
- if (__mpx_env__ === 'web') {
18
- transedApi = platformApi
19
- } else {
20
- const envObj = getEnvObj()
21
- Object.keys(envObj).concat(Object.keys(platformApi)).forEach((key) => {
22
- transedApi[key] = platformApi[key] || envObj[key]
23
- })
24
- }
25
-
12
+ const envObj = getEnvObj()
13
+ const transedApi = Object.assign({}, envObj, platformApi)
26
14
  const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
27
- const allApi = Object.assign({}, transedApi, promisedApi)
28
-
29
- Object.keys(allApi).forEach(api => {
30
- try {
31
- if (typeof allApi[api] !== 'function') {
32
- target[api] = allApi[api]
33
- return
34
- }
35
- target[api] = (...args) => {
36
- return allApi[api].apply(target, args)
37
- }
38
- } catch (e) {
39
- } // 支付宝不支持重写 call 方法
40
- })
41
- if (custom[envStr]) {
42
- Object.keys(custom[envStr])
43
- .forEach(k => {
44
- target[k] = (...args) => {
45
- return custom[envStr][k].apply(target, args)
46
- }
47
- })
48
- }
49
- // Fallback Map option
50
- Object.keys(fallbackMap)
51
- .forEach(k => {
52
- if (!target[k]) {
53
- target[k] = fallbackMap[k]
54
- }
55
- })
15
+ Object.assign(target, transedApi, promisedApi, custom[__mpx_mode__])
56
16
  }
57
17
 
58
18
  export function getProxy (options = {}) {
@@ -1,4 +1,4 @@
1
- import { changeOpts, handleSuccess } from '../../../common/js'
1
+ import { changeOpts, envError, handleSuccess } from '../../../common/js'
2
2
 
3
3
  function canvasToTempFilePath (options = {}) {
4
4
  handleSuccess(options, res => {
@@ -10,7 +10,11 @@ function canvasToTempFilePath (options = {}) {
10
10
 
11
11
  my.canvasToTempFilePath(options)
12
12
  }
13
+ const createCanvasContext = envError('createCanvasContext')
14
+ const canvasGetImageData = envError('canvasGetImageData')
13
15
 
14
16
  export {
15
- canvasToTempFilePath
17
+ createCanvasContext,
18
+ canvasToTempFilePath,
19
+ canvasGetImageData
16
20
  }
@@ -1,6 +1,6 @@
1
1
  import { webHandleSuccess, webHandleFail, isBrowser, throwSSRWarning } from '../../../../common/js'
2
2
 
3
- export function getNetworkType ({ success, fail = () => {}, complete = () => {} }) {
3
+ export function getNetworkType ({ success, fail = () => {}, complete = () => {} } = {}) {
4
4
  if (!isBrowser) {
5
5
  throwSSRWarning('getNetworkType API is running in non browser environments')
6
6
  return
@@ -1,4 +1,5 @@
1
1
  import Preview from './Preview'
2
+ import { envError } from '../../../common/js'
2
3
 
3
4
  let preview = null
4
5
 
@@ -6,7 +7,13 @@ let preview = null
6
7
  * 预览图片
7
8
  * @param {Object} options - 预览图片的配置项
8
9
  */
9
- export const previewImage = (options) => {
10
+ const previewImage = (options) => {
10
11
  if (!preview) preview = new Preview()
11
12
  preview.show(options)
12
13
  }
14
+ const compressImage = envError('compressImage')
15
+
16
+ export {
17
+ previewImage,
18
+ compressImage
19
+ }
@@ -93,6 +93,5 @@ export default class Toast {
93
93
  this.toast.classList.remove('show')
94
94
  this.toast.remove() // hide 则卸载
95
95
  }, duration)
96
- // return Promise.resolve({ errMsg }) todo 验证一下
97
96
  }
98
97
  }