@mpxjs/api-proxy
Advanced tools
Comparing version 2.9.9 to 2.9.11-test.0
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133417
111
3566
1
1