Code Monkey home page Code Monkey logo

monetize-npm-cli's Introduction

monetize-npm-cli

monetize-npm-cli is a modular CLI that helps monetize npm packages using the Web Monetization API and different providers.


Install

npm install -g monetize-npm-cli

Usage

Run file

To run your app while monetizing the supported npm packages

monetize-npm-cli yourFile.js

Help

To view help page with all details

monetize-npm-cli --help

Login to your Provider

To login to your web monetization provider

monetize-npm-cli --login

This will default to coil-extension if no provider is provided. See help for more details.


Logout from your Provider

To logout from your web monetization provider

monetize-npm-cli --logout

This will default to coil-extension if no provider is provided. See help for more details.


List packages

To list all packages supporting web monetization

monetize-npm-cli --list

Use help to get full list of supported commands


API

The aim of this CLI is to mimic the web monetization API given here as much as it could. Instead of document.monetization, user gets globalThis.monetization.

globalThis.monetization itself is a proxy of an object which contains all the information and is not accessible globally.

Exposed Methods

getState

document.monetization.state => globalThis.monetization.getState(name, version) name and version are defined in package.json of each package.

addEventListener

There can be four listeners set up monetizationpending, monetizationstart, monetizationstop, monetizationprogress. Let identify them by listenerIdentifier.

document.monetization.addEventListener(listenerIdentifier, foo) => globalThis.monetization.addEventListener(name, version, listenerIdentifier, foo)

removeEventListener

globalThis.monetization.removeEventListener(name, version, listenerIdentifier, foo) If foo is not passed, all the listeners for that package are removed.


Currently only coil-extension is supported as a provider. You read more about it here


Add Support for web monetization to Packages

For packages to support web monetization, they must add a webMonetization key in thier package.json file

{
  "webMonetization": {
    "wallet": "$yourWalletAddressGoesHere"
  }
}

Providers

This app currently comes with only coil-extension provider as its the only provider existing right now, but support for more can be easily added as this CLI has been made keeping modularity in mind.

Create a provider module

To create a provider module compatible with this CLI, it must have 3 exposed methods.

  1. login()
  2. logout()
  3. monetize(monetizationPackages[,timeout])

monetizationPackages

monetizationPackages is a proxy object passed to a provider module to start monetization

// monetizationPackages
{
    packages:[
        {
          name: "",
          version: "",
          webMonetization: {
              wallet:""
          },
          state: "",
        //   These arrays contain event listeners
          monetizationpending: [],
          monetizationstart: [],
          monetizationstop: [],
          monetizationprogress: [],
        }
    ],
    invokeListener(data){
        // data is the response argument received when any event is fired
        // monetizationpending || monetizationstart || monetizationstop || monetizationprogress
        // Pass args as an array
    }
}

Create an issue on this repo to add support for your provider module.

monetize-npm-cli's People

Contributors

projectescape avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.