Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mpxjs/api-proxy

Package Overview
Dependencies
Maintainers
13
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mpxjs/api-proxy - npm Package Compare versions

Comparing version 2.9.9 to 2.9.11-test.0

src/common/js/promisify.js

4

package.json
{
"name": "@mpxjs/api-proxy",
"version": "2.9.9",
"version": "2.9.11-test.0",
"description": "convert miniprogram API at each end",

@@ -42,3 +42,3 @@ "module": "src/index.js",

},
"gitHead": "7ec6526f024c00f9c6b935c631bfdc61be27b69b"
"gitHead": "d244d661acb081b709fc99ca8f6add541f793877"
}

@@ -1,3 +0,2 @@

export * from './ToPromise'
export * from './web'
export * from './utils'

@@ -32,3 +32,2 @@ /**

opts = Object.assign({}, opts, extraOpt)
return opts

@@ -81,5 +80,30 @@ }

return dd
case 'web':
return {}
}
}
function getEnvStr () {
switch (__mpx_mode__) {
case 'wx':
return 'wx'
case 'ali':
return 'ali'
case 'swan':
return 'swan'
case 'qq':
return 'qq'
case 'tt':
return 'tt'
case 'jd':
return 'jd'
case 'qa':
return 'qa'
case 'dd':
return 'dd'
case 'web':
return 'web'
}
}
function warn (msg) {

@@ -92,2 +116,7 @@ console.warn && console.warn(`[@mpxjs/api-proxy warn]:\n ${msg}`)

}
function envError (method) {
return () => {
console.error && console.error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
}
}

@@ -114,3 +143,5 @@ function noop () {

getEnvObj,
getEnvStr,
error,
envError,
warn,

@@ -117,0 +148,0 @@ noop,

@@ -1,75 +0,4 @@

import transformApi from './mini/transform'
import promisify from './mini/promisify'
export default function install (target, options = {}) {
const {
usePromise = false, // 是否转为 promise 格式
whiteList = [], // 强制变成 promise 格式的 api
blackList = [], // 强制不变成 promise 格式的 api
platform = {},
exclude = ['shareImageMessage'], // 强制不进行代理的api,临时fix微信分享朋友圈白屏
custom = {}, // 自定义转化规则
fallbackMap = {} // 对于不支持的API,允许配置一个映射表,接管不存在的API
} = options
let { from = '', to = '' } = platform
/* eslint-disable camelcase, no-undef */
if (typeof __mpx_src_mode__ !== 'undefined') {
if (from && from !== __mpx_src_mode__) {
console.warn && console.warn('the platform from field inconsistent with the current environment value\n')
}
from = `__mpx_src_mode_${__mpx_src_mode__}__`
} else {
if (!from) {
from = 'wx'
console.warn && console.warn('the platform from field is empty, wx will be used by default\n')
}
from = `__mpx_src_mode_${from}__`
}
if (typeof __mpx_mode__ !== 'undefined') {
to = __mpx_mode__
} else if (!to) {
console.warn && console.warn('the platform to field is empty, ali will be used by default\n')
to = 'wx'
}
/* eslint-enable */
const transedApi = transformApi({
exclude,
from,
to,
custom
})
const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
const allApi = Object.assign({}, transedApi, promisedApi)
Object.keys(allApi).forEach(api => {
try {
if (typeof allApi[api] !== 'function') {
target[api] = allApi[api]
return
}
target[api] = (...args) => {
return allApi[api].apply(target, args)
}
} catch (e) {
} // 支付宝不支持重写 call 方法
})
// Fallback Map option
Object.keys(fallbackMap)
.forEach(k => {
if (!target[k]) {
target[k] = fallbackMap[k]
}
})
}
export function getProxy (options = {}) {
const apiProxy = {}
install(apiProxy, options)
return apiProxy
}
import install, { getProxy } from './install'
export * from './platform'
export { getProxy }
export default install
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc