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

bitspider-retailer-sdk

v0.5.0

Published

A SDK for develop Retailer Service. Retailer service decide what task to excute and how to parse the receive data.

Downloads

19

Readme

bitspider-retailer-sdk

A SDK for develop Retailer Service. Retailer service decide what task to excute and how to parse the receive data.

Installation

This is a Node.js module and available through the npmjs.com.

If you didn't install NodeJS before, please install Node.js before you continue. Node.js 10.x or higher is required.

Run following command to install:

npm install bitspider-retailer-sdk

Getting Started

Before continue, make sure you have a running Munew application. If you don't have, please follow Install Munew to install it

Create index.js, and copy follow code to it

const baseRetailerService = require("bitspider-retailer-sdk");

const triggerFun = async function(){
  return {
    tasks: [
      baseRetailerService.generateTask({
        url: "http://exampleblog.munew.io/"
      })]
  }
}
const parseFun = async function({req}){
  const data = req.body;
  // You can add your logic to parse and decide whether need to add additional tasks
  // For this example, I store get data to disk
  return {
    data: data
  }
}
// You must set `GLOBAL_ID` and `MUNEW_BASE_URL`
baseRetailerService.setConfigs({
  GLOBAL_ID: "c29pOjoxNTkyNzk1NTI1NjAzOjpmZmFkNTI4Zi02NzYyLTRlNmQtOGQyYS05Njk1NzM0YjhkM2Q=",
  MUNEW_BASE_URL: "http://localhost:9099",
});
baseRetailerService.init();
baseRetailerService.trigger(triggerFun);
baseRetailerService.parse(parseFun);
baseRetailerService.express();
baseRetailerService.routers();
baseRetailerService.listen();

Change the GLOBAL_ID and MUNEW_BASE_URL.

Now run node index.js, and open http://localhost:8081, now you start your Retailer Service, click trigger to add your trigger task.

Please take a look of Example Blog Node

If you want to save data to mongodb

baseRetailerService.setConfigs({
  GLOBAL_ID: "c29pOjoxNTkyNzk1NTI1NjAzOjpmZmFkNTI4Zi02NzYyLTRlNmQtOGQyYS05Njk1NzM0YjhkM2Q=",
  MUNEW_BASE_URL: "http://localhost:9099",
  CONNECTOR_TYPE: "mongodb",
  MONGODB_URL: "mongodb://[email protected]:47987/retailer"
});

APIs

Please download API Doc, and open it in your browser

Will host to a server in future

Schemas

Task

{
  "type": "object",
  "required": ["url", "soi"],
  "properties": {
    "url": {
      "type": "string",
      "description": "web page url that need to be processed"
    },
    "soi": {
      "type": "object",
      "required": ["globalId"],
      "additionalProperties": false,
      "properties": {
        "globalId": {
          "type": "string",
          "description": "The **global id** of your Retailer Service"
        }
      }
    },
    "priority": {
      "type": "integer",
      "minimum": 1,
      "default": 100,
      "description": "Priority of this task. Only compare priority for same Retailer Service, doesn't compare cross Retailer Service. Bigger value low priority. Priority value 1 is higher than priority value 2."
    },
    "suitableAgents": {
      "type": "array",
      "description": "What kind of agents can execute this task",
      "default": ["HEADLESSBROWSER"],
      "items": {
        "type": "string",
        "enum": ["HEADLESSBROWSER", "SERVICE"]
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true,
      "description": "Additional metadata for this task",
      "properties": {
        "script": {
          "type": "string",
          "description": "Code want to execute after **window.onload**. If you need agent to execute your code, Only work with **HEADLESSBROSWER** agent"
        }
      }
    }
  }
}

TriggerFunReturn

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "tasks": {
      "type": "array",
      "description": "`tasks`: Send `tasks` to **Munew** application",
      "items": {
        "$ref": "#schema/task"
      }
    }
  }
}

ParseFunReturn

{
  "type": "object",
  "additionalProperties": false,
  "required": [],
  "properties": {
    "tasks": {
      "type": "array",
      "description": "Send `tasks` to **Munew** application",
      "items": {
        "$ref": "#schema/task"
      }
    },
    "key": {
      "type": "string",
      "description": "Key value for the data you want to save. Default is `data`."
    },
    "data": {
      "type": ["integer", "string", "object", "array"],
      "description": "Data need to save. It will be appended to the `key`. If `data` is empty or `undefined` or `null`, then nothing will be saved. `data` will be saved to `DATA_PATH`"
    },
    "response": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "status": {
          "type": "number",
          "default": 200,
          "description": "HTTP Status. Any value big than 300 will be considered of fail"
        },
        "data": {
          "type": ["integer", "string", "object", "array"],
          "description": "Data want to send back. Only use when you want to return an error, and you can add the reason of error, it is useful for troubleshoot"
        }
      }
    }
  }
}