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

ananse

v1.9.8

Published

Ananse is a lightweight NodeJs framework with batteries included for building efficient, scalable and maintainable USSD applications.

Downloads

246

Readme

https://nodei.co/npm/ananse.png?downloads=true&downloadRank=true&stars=true

contributions welcome

Ananse is a lightweight NodeJs/Typescript framework with batteries included for building efficient, scalable and maintainable USSD applications. It provides intuitive and flexible APIs for building USSD menus.

Ananse has built-in support for session state management, menu routing, input validation, pagination and command line simulator.

Features

  • Intuitive menu routing
  • Supports any USSD gateway (Wigal, Hubtel, AfricasTalking, etc)
  • Session state management
  • Session storage
  • Input validation
  • Pagination
  • Command line simulator
  • E2E Testing with Japa

Installation

Use your favour nodejs package manager to install anase.

npm install ananse

Base Usage

Ananse comes with a built-in HTTP server suitable for a new project. An ExpressJs wrapper is also available for use in existing projects.

Configuration

The configure exposes several options to configure the framework - the ussd gateway, session storage and pagination options.


import { Ananse } from "ananse";

const ananse = new Ananse().configure({
  gateway: "wigal", // USSD gateway to use, eg. hubtel, africas_talking.
  session: { type: "redis" }, // Database to store session data. Eg. mysql, postgres and redis
});

export default ananse;

Define the Menus

There are two ways to define menus Ananse - functional and class based menus. While both offers the same API features, class based menus are recommended for complex applications.

Each menu must have a unique name/id, this is similar to route path in expressJS. Ananse uses the id in navigating the user between menus in the application. It is recommended to define menu ids in enum for easy debugging.

Functional menus are automatically discovered by the framework. However, class menus must be added manually.

//
// Functional style menu definition
//
MenuRouter
  .menu(MenuType.account_type)
  .start()
  .message("Choose account type")
  .actions([
    {
      choice: "1",
      display: "1. Customer",
      next_menu: async (req: Request, _res: Response) => {
        return MenuType.account_login
      },
    },
    {
      choice: "2",
      display: "2. Sales Executive",
      next_menu: MenuType.sales_executive,
    },
  ]);

After defining a class based menu, it must be added to the list of menu routes using the MenuRouter.add([menu-class], [menu-id]).

//
// Class based menus
//
import { BaseMenu, MenuAction, Request, Response } from "ananse";
import { MenuType } from "../../enums";

export class AmountTypeMenu extends BaseMenu {
  async nextMenu() {
    return MenuType.account_type;
  }

  async message() {
    return "Choose account type";
  }

  async actions(): Promise<MenuAction[]> {
    return [
      {
        choice: "1",
        display: "1. Customer",
        next_menu: async (req: Request, _res: Response) => {
          return MenuType.account_login
        },
      },
      {
        choice: "2",
        display: "2. Sales Executive",
        next_menu: MenuType.sales_executive,
      },
    ];
  }
}

// Add the menu to the list of ananse routes
MenuRouter.add(AmountTypeMenu, MenuType.account_type);

Start the Server

Ananse can be added to an existing express application by simply mount a new route for it.


import ananse from "./ussd";

const app = express();

app.get('/ussd', (req, res) => {
  return ananse.express(req, res);
})

To use the built-in HTTP server, simply call the listen function with the port number.

import ananse from "./ussd";

ananse.listen(3000, "localhost", () => {
    console.log("Ananse server listening on port 3000");
});

Sample projects

For more examples, refer to the available sample projects.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Ananse is MIT licensed

TODOs

Documentation

  • Core components
    • validation
    • forms
    • menus
    • forms
    • pagination
    • simulator
    • japa e2e testing
    • design philosophy

Pending Features

  • Simplify navigation to use stack data structure
  • GUI menu builder
  • Vscode extension