@ultramedia/jssdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

wechat's media platform jssdk utilities

Travis npm bundle size npm version Known Vulnerabilities NPM license

Installation

npm i @ultramedia/jssdk

Usage

// express
const app = require('express')()
const {Sdk, Config} = require('@ultramedia/jssdk')

const config = Config({
  apps: [{key: 'app id', secret: 'app secret'}]
})

const sdk = Sdk(config)

app.post('/config/:appid', (req, res, next) => {
  const {appid} = req.params
  const {key, secret} = config.getApp(appid)
  sdk.createConfig(key, secret).then(data => res.json(data))
})

mock for testing

const {mock} = require('@ultramedia/jssdk')

describe('suite', () => {
  let unmock;
  beforeAll(() => {
    unmock = mock()
  })
  afterAll(() => {
    unmock()
  })

  it('test', () => {
    console.log('all http requests for wechat server will be mocked')
  })
})

mock data:

// when fetch access_token from wechat's server, mock response will be:
{access_token: 'access_token', expires_in: 7200}

// when fetch ticket from wechat's server, mock response will be:
{ticket: 'ticket', expires_in: 7200}

API

const {Config, Sdk, mock} = require('@ultramedia/jssdk')

Types declaration in: index.d.ts

Changes

v0.1.x

  • add typescript declaration file.
  • rename createSdk to Sdk from exports. (break change)

Readme

Keywords

Package Sidebar

Install

npm i @ultramedia/jssdk

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

14.1 kB

Total Files

17

Last publish

Collaborators

  • xxlive