loopback-component-package

0.0.2 • Public • Published

loopback-component-package

Package/Pricing management for loopback API server

Build Status

Installation :

$ npm install loopback-component-package --save

`` then add the following to component-config.json file

{
  "loopback-component-explorer": {
    "mountPath": "/explorer"
  },
  "loopback-component-package": {
    "dataSource": "mongodb",
    "packages": [
      {
        "name": "SMS",
        "type": "monthly",
        "reset": true
      },
      {
        "name": "EMAIL",
        "type": "daily",
        "reset": false
      }
    ],
    "types":[
      "daily",
      "weekly",
      "monthly",
      "semiyearly",
      "yearly"
    ]
  }
}

usage:

do this before using package element, eg: if you let your user to send 500 SMS per month:

create the package:
  Package.createPackage('SMS-Package','monthly',true).then(function(package){ 
    //do something here 
  });
then register the package for the user:
  Package.registerPackage(package.id,500,true,0).then(function(packageUsage){ 
    //this will return a token, store the token somewhere on your app
    // because you are going to need the token from now on.
  });
then use the use method before the user sends SMS
  Package.use(token,1).then(function(usage){ 
    //it will return current package usage count
    // it will return -1 if the package reached/passed its limit
    // if it returns -1 then you won't send the SMS for that user
    // and obviously if it returns count then the user is good to go
  });

to run the test do:

$ npm install
$ npm test

Minab IT Solutions

Package Sidebar

Install

npm i loopback-component-package

Weekly Downloads

4

Version

0.0.2

License

ISC

Last publish

Collaborators

  • miqe