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

@staart/manager

v1.2.15

Published

[![Staart API](https://raw.githubusercontent.com/staart/staart.js.org/master/assets/svg/api.svg?sanitize=true)](https://staart.js.org/api)

Downloads

12

Readme

Staart API

Staart is a Node.js backend starter for SaaS startups written in TypeScript. It has built-in user management and authentication, billing, organizations, GDPR tools, and more.

| | Status | | - | - | | Build | GitHub Actions Travis CI Circle CI Azure Pipelines | | Dependencies | Dependencies Dev dependencies Vulnerabilities | | Community | Contributors GitHub Type definitions npm package version |

Staart is build to work with Staart UI, the frontend starter for SaaS.

⭐ Features

🔐 Security

  • [x] Authentication and user management with JWT
  • [x] Two-factor authentication with TOTP
  • [x] Setup multiple emails for each account
  • [x] OAuth2 login with third-party accounts
  • [x] Location-based login verification
  • [x] Security event logging and history

💳 SaaS

  • [x] Subscriptions management with Stripe
  • [x] Organizations, teams, and user permissions
  • [x] Invoices, billing, credit cards, payments
  • [x] Rich HTML transactional emails with SES
  • [x] GDPR-proof data export and delete
  • [ ] Affiliates and commission management
  • [x] API gateway with API keys and rate limits
  • [x] Auto-join members with domain verification

👩‍💻 Developer utilities

  • [x] Decorators and class syntax with OvernightJS
  • [x] Injection-proof helpers for querying databases
  • [x] Data pagination and CRUD utilities for all tables
  • [x] Authorization helpers (can a user do this?)
  • [x] TypeScript interfaces for tables (ORM)
  • [x] Caching and invalidation for common queries
  • [x] User impersonation for super-admin
  • [x] Easy redirect rules in YAML
  • [x] Store server logs in ElasticSearch every minute

🛠 Usage

  1. Use this template or fork this repository
  2. Install dependencies with yarn or npm i
  3. Add a .env file based on config.ts.
  4. Create MariaDB/MySQL tables based on schema.sql
  5. Add your controllers in the ./src/controllers directory
  6. Generate your app.ts file using yarn generate-routes
  7. Build with yarn build and deploy with yarn start

Updating Staart

To update your installation of Staart, run the following:

node setup/update.js

If you've used the "Use this template" option on GitHub, you might have to force pull from staart/api the first time since the histories wouldn't match. You can use the flag --allow-unrelated-histories in this case.

💻 Docs

View docs site →

View TypeDoc →

View API demo →

View frontend demo →

👩‍💼 Getting started

After forking this repository, you can get started by writing your first endpoint. We do this by creating a new file in the ./src/controllers folder. For example, create api.ts:

import { Request, Response } from "express";
import asyncHandler from "express-async-handler";
import { Get, Controller, ClassWrapper, Middleware } from "@overnightjs/core";
import { authHandler, validator } from "../helpers/middleware";
import Joi from "@hapi/joi";

@Controller("api")
@ClassWrapper(asyncHandler)
export class ApiController {
  @Get("hello")
  @Middleware(
    validator(
      { name: Joi.string().min(3).required() },
      "query"
    )
  )
  async sayHello(req: Request, res: Response) {
    const name = req.query.name;
    if (name === "Anand")
      return res.json({ text: `Hello, ${name}!`; });
    throw new Error("404/user-not-found");
  }
}

The above code 20 lines of code with create a new endpoint which can be accessed at example.com/api/hello?name=Anand, which will respond with a JSON object with the text "Hello, Anand!".

Staart code is easily understandable. You create a new controller, api, which means all routes in this class will have the prefix /api. Then, you create an HTTP GET method hello and use our built-in validator to say that the query parameter name must be a string of at least 3 characters.

With the asyncHandler, you can use async functions and Staart will handle errors for you. In this case, if the provided name is Anand, your function returns a JSON response "Hello, Anand!" and otherwise sends an error 404.

Helpers

For common tasks such as finding users or authorizing API keys, Staart provides various helper functions.

Let's look at what you need to do if you want to let users be able to delete organizations. For this, you want to check where a user is actually allowed to delete that organization, if they're logged in, and make sure nobody can brute force this endpoint.

import { can } from "../helpers/authorization";
import { Authorizations } from "../interfaces/enum";
import { INSUFFICIENT_PERMISSION } from "@staart/errors";
import { authHandler, bruteForceHandler } from "../helpers/middleware";
import { deleteOrganization } from "../crud/organization";

// Your controller here
@Get("delete/:id")
@Middleware(authHandler)
@Middleware(bruteForceHandler)
async deleteOrg(req: Request, res: Response) {
  const orgId = req.params.id;
  const userId = res.locals.token.id;
  if (await can(userId, Authorizations.DELETE, "organization", orgId)) {
    await deleteOrganization(orgId);
    return res.status(204);
  }
  throw new Error(INSUFFICIENT_PERMISSION);
}

In the above example, the Staart helpers and middleware used are:

  • Authentication (authHandler): Checks if a user's token is valid and adds res.locals.token; and if it isn't, sends a 401 Unauthorized error.
  • Brute force prevention (bruteForceHandler): Prevents users from making too many requests in a short time, can be configured via ./src/config.ts
  • Authorization (can): Returns whether a user is allowed to perform an action based on their permissions

Of course, we actually prefer to write our logic in the rest folder and only the handler as a controller. For a deeper dive into Staart, look at our Wiki docs.

👥 Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

🏗️ Built with Staart

🏁 Staart Ecosystem

The Staart ecosystem consists of open-source projects to build your SaaS startup, written in TypeScript.

| Package | | | | - | - | - | | 🛠️ Staart API | Node.js backend with RESTful APIs | Build status Docs npm package version | | 🌐 Staart UI | Frontend Vue.js Progressive Web App | Build status Docs npm package version | | 📑 Staart Site | Static site generator for docs/helpdesk | Build status Docs npm package version | | 📱 Staart Native | React Native app for Android and iOS | Build status Docs npm package version | | 🎨 Staart.css | Sass/CSS framework and utilities | Build status Docs npm package version | | 📦 Staart Packages | Helper functions and utility packages | Build status Custom badge |

💝 Sponsors

The development of Staart projects is supported by these wonderful companies. Find us on OpenCollective

📄 License