npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wxcloud/cloud-sdk

v1.0.4

Published

wx cloud sdk

Downloads

75

Readme

@wxcloud/cloud-sdk

微信云开发团队提供了Web SDK,支持在 Web 中访问云开发资源。 但 Web SDK 只支持常规 Web 应用(即浏览器环境)的开发,不兼容其他类 Web 平台。由于类 Web 平台在网络络请求、本地存储等特性上与浏览器环境有明显差异,现提供 @wxcloud/cloud-sdk 以支持跨端适配的能力。在传入不同平台适配对象之后,在其他类 Web 平台也可以访问微信云开发资源。

安装

npm install @wxcloud/cloud-sdk --save

使用

@wxcloud/cloud-sdk 导出了 useAdapterinitCloud 方法。先通过 useAdapter 传入跨端的适配对象,然后调用 initCloud 获取 cloud 对象,即引入 Web SDK 时自动挂载在 window 下的 cloud 。

const { useAdapter, initCloud } = require('@wxcloud/cloud-sdk')
import { adapters } from './example/adapters'

// platform 可传入标识平台的字符
useAdapter({ adapters, platform: 'platform' })
const cloud = initCloud()

在浏览器环境中使用可以不调用 useAdapter

const { initCloud } = require('@wxcloud/cloud-sdk')

const cloud = initCloud()

适配对象

目前需要适配的对象有 sessionStorage、localStorage、network、reqClass、webSocketClass。 其需要实现的接口如下所示:

interface IWXCloudSdkAdapterInterface {
  reqClass: IRequestEngine
  sessionStorage: IStorageAdapter
  localStorage: IStorageAdapter
  webSocketClass: IWebSocketAdapter
  network: INetworkAdapter
}

type onNetworkStatusChangeCb = (res: {
  isConnected: boolean
  networkType: 'wifi' | '4g' | '3g' | '2g' | 'unknown' | 'none'
}) => void

interface INetworkAdapter {
  getNetWorkType: () => string
  onNetworkStatusChange: (cb: onNetworkStatusChangeCb) => void
}

interface IStorageAdapter {
  setItem: (key: string, value: string) => void
  getItem: (key: string) => string | null
}

interface IWebSocketAdapter {
  new (url: string, protocols?: string[]): IWebSocketAdapter
  readyState: number
  send: (data: string | ArrayBuffer) => void
  close: (code?: number | undefined, reason?: string | undefined) => void
}

对于适配逻辑较复杂的 reqClass, @wxcloud/cloud-sdk 提供 requestAdapterWrapper 包装方法来降低适配难度。 对于开发者,只需要完成以下 IRequestAdapterInterface 接口的实现后传入 requestAdapterWrapper 即可。

interface IRequestParam {
  url: string
  data: string | ArrayBuffer
  header: AnyObject
  method: string
  dataType: string
  responseType: string
  timeout: number
}

interface IRequestAdapterCallbackResponse {
  statusCode: number | string
  response: string | object
  headers: { [key: string]: any }
  statusMessage: string
}

type IRequestAdapterInterface = (req: IRequestParam, cb: (resp: IRequestAdapterCallbackResponse) => void) => void

为方便开发者理解适配器需完成的逻辑,我们以在微信小程序中使用 @wxcloud/cloud-sdk 为例,提供了所需适配对象的完整适配实现,具体可参考 example/adapters.js

支持 customDomain

由于 第三方 Cookie 限制,在浏览器环境中使用登录模式时,需要开发者自建服务器转发 https://servicewechat.com/wxa-qbase/ 的请求。在非浏览器环境内,支持在实例化 cloud.Cloud 时传入 customDomain 指定转发的域名,如果未传入,默认直接请求 https://servicewechat.com/wxa-qbase/

cosnt c = new cloud.Cloud({
  identityless: true,
  resourceAppid: 'appid', // miniprogram appid
  resourceEnv: 'env',
  config: { // optional
    customDomain: 'https://user-sever.com'
  }
})

说明

  • downloadFile、uploadFile 暂不支持适配。
  • 公众号登录相关的 api 在微信客户端之外调用无法正常完成相应逻辑。

对于 @wxcloud/cloud-sdk 的问题,欢迎在微信开放社区发帖提问。