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

deo-youzan

v2.0.1

Published

nodejs sdk for www.youzan.com

Downloads

38

Readme

npm download npm version travis build codecov coverage

nodejs sdk(pull/push) for www.youzan.com (koudaitong)

This is inspired by Frank Fan's work but now it's been revamped

Important upgrade

It's not compatible with v0.1.4 and below, please update your code where necessary.

APIs & Webhook

See Youzan API Doc for pulling API

See Push数据推送服务 for push notification

Installation

$ npm install deo-youzan

General Usage

Pull:

var youzan = require('deo-youzan');


// If you need proxy, set the global request
var request = require('request');
request = request.defaults({proxy: 'your proxy'});

// Get an api object for a certain appid/appsecret
var kdt = youzan(appid, appsecret);

// Normally you can use it as the api 'method' in the API doc
// e.g. method: kdt.trades.sold.get

const params = {
  fields: 'tid,pay_time,created,trade_memo,receiver_mobile,orders',
  status: 'WAIT_SELLER_SEND_GOODS'
}

kdt.trades.sold.get(params, function (error, response, body) {
  // error: if any error happens or we detect it's an error response
  // response: if you want to do your own logic with the response
  // body: the json format of the response's body
});

// Some may need extra files path parameter
// e.g. method: kdt.item.add

const params = {
  // ...
}

const filePaths = [
  // ...
]

kdt.item.add(params, filePaths, function(err, res, body) {
  // ...
});

Extend Usage:

Except the all the API in the official document, we provide some extend functions to ease the usage:

kdt.trades.sold.get.all: This will grab all the trades matching the given param and return them as an Array. Since it contains multiple http requests, we default it to retry 3 times when failure encounted.


Push:

For testing purpose, bring up a service and config you 推送网址 as http://yourip:3000 , recommend to try ngrok if you're testing on your own machine:

node app.js 'your appid' 'your appsecrect' 3000

for use, you need to install express:

npm install express body-parser express-validator --save

then plug in the handler, can have a look at app.js

/*
The webhook handles notification in the following order:
  1. if a test message, response 200 and terminate
  2. validate the request body, if malformed, response 400 and terminate
  3. validate the signature, if not valid, response 403 and terminate
  4. remove sign, test, parse msg of the request body and parse the req object to user provided function for your own logic
*/
'use strict';
var express = require('express');
var app = express();
var handler = require('deo-youzan/lib/webhook');
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');


// we need a appid/appsecrect mapping
let kdt = {
  'your appid1': 'your appsecrect1',
  'your appid2': 'your appsecrect2',
};

// youzan sends notification with application/json
app.use(bodyParser.json());
// we need this to validate the message format
app.use(expressValidator([]));

app.post('/', handler(kdt, function(req) {
  console.log(req.body);
  // TODO: process the request here, feel free to replace this function to match your logic
}));

testing

npm test

License

license