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

@mpxjs/api-proxy

Package Overview
Dependencies
Maintainers
3
Versions
168
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 1.0.0 to 1.0.1

src/proxy.js

2

package.json
{
"name": "@mpxjs/api-proxy",
"version": "1.0.0",
"version": "1.0.1",
"description": "convert miniprogram API at each end",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,2 +9,4 @@ # mpx-api-proxy

```js
// 使用 mpx 生态
import mpx from '@mpxjs/core'

@@ -16,2 +18,9 @@ import apiProxy from '@mpxjs/api-proxy'

```js
// 单独使用
import apiProxy from '@mpxjs/api-proxy'
apiProxy(target, options) // target 为要抹平的对象
```
## Options

@@ -18,0 +27,0 @@

import { proxyWxToAliApi } from './platform'
import proxyAll from './proxy'
import getPromisifyList from './promisify'

@@ -13,12 +14,18 @@

if (typeof __mpx_src_mode__ !== 'undefined') {
fromMode = __mpx_src_mode__
from = __mpx_src_mode__
}
if (typeof __mpx_mode__ !== 'undefined') {
toMode = __mpx_mode__
to = __mpx_mode__
}
/* eslint-enable */
// 代理所有 api
proxyAll()
// 转换各端 api
if (from === 'wx' && to === 'ali') {
proxyWxToAliApi(target)
}
// 变为 promise 格式
if (usePromise) {

@@ -25,0 +32,0 @@ Object.assign(target, getPromisifyList(whiteList, from, to))

@@ -10,2 +10,6 @@ import { changeOpts, handleSuccess, error, warn, noop } from '../utils'

const wxToAliApi = {
/**
* 基础
*/
getSystemInfo (options) {

@@ -41,2 +45,6 @@ const opts = changeOpts(options)

/**
* 界面
*/
showToast (options) {

@@ -140,2 +148,6 @@ const opts = changeOpts(options, {

/**
* 网络
*/
request (options) {

@@ -178,2 +190,6 @@ const opts = changeOpts(options, {

/**
* 数据缓存
*/
setStorageSync (key, data) {

@@ -198,2 +214,6 @@ ALI_OBJ.setStorageSync({

/**
* 媒体
*/
saveImageToPhotosAlbum (key) {

@@ -243,2 +263,6 @@ warn(`如果想要保存在线图片链接,可以直接使用 ${TIPS_NAME}.saveImage`)

/**
* 位置
*/
getLocation (options) {

@@ -261,2 +285,6 @@ if (options.aliType === undefined && options.type) {

/**
* 文件
*/
saveFile (options) {

@@ -322,2 +350,6 @@ const opts = changeOpts(options, {

/**
* 设备
*/
addPhoneContact (options) {

@@ -427,2 +459,6 @@ const opts = changeOpts(options, {

/**
* 开放接口
*/
login (options) {

@@ -506,2 +542,6 @@ let opts

/**
* 画布
*/
createCanvasContext (canvasId) {

@@ -566,2 +606,46 @@ let ctx = ALI_OBJ.createCanvasContext(canvasId)

ctx.getImageData(opts)
},
/**
* WXML
*/
createSelectorQuery (options) {
let query = ALI_OBJ.createSelectorQuery(options)
let cbs = []
if (query) {
const apiArr = ['select', 'selectAll', 'selectViewport']
const cacheExec = query.exec || noop
apiArr.forEach(key => {
const cacheKey = query[key] || noop
query[key] = dom => {
const selected = cacheKey.call(query, dom)
const cacheBoundingClientRect = selected.boundingClientRect
selected.boundingClientRect = (...args) => {
if (typeof args[0] === 'function') {
cbs.push(args[0])
// error('请将 boundingClientRect 中的回调函数放入 exec 中使用')
}
return cacheBoundingClientRect.call(selected)
}
return selected
}
})
query.exec = (fn = noop) => {
return cacheExec.call(query, res => {
cbs.forEach((cb, idx) => {
cb.call(this, res[idx])
})
cbs = []
fn.call(this, res)
})
}
query.in = () => query
}
return query
}

@@ -568,0 +652,0 @@ }

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