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

@proxymal/saas-sdk

v1.8.1

Published

SDK for building all types of SaaS products.

Downloads

79

Readme

saas-sdk

SDK for building all types of SaaS products.

Rest API

SDK allows you to build Rest API from scratch easily, with express-like syntax:

// app.ts

import { API } from "@proxymal/saas-sdk";
import user from "./user.routes.ts";

const api = new API();

api.expand("/api/user", user);

api.start(3000);
// user.routes.ts

import { APIModule } from "@proxymal/saas-sdk";

const routes = new APIModule();

// GET /
routes.get("/", {}, async () => ({ status: "ok", body: { test: "hello!" } }));

export default routes;

Rest API Documentation

Documentation for your Rest API can be automatically generated (OpenAPI v3 schema format) using Docs:

// app.ts

import { API, Docs } from "@proxymal/saas-sdk";
import user from "./user.routes.ts";

const api = new API();

api.expand("/api/user", user);
api.expand("/api/docs", new Docs(api));

api.start(3000);

Database & ORM

Database is works out-of-box by default, you just have to setup .env file with connection credentials:

DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=username
DB_PASSWORD=password
DB_DATABASE=database

And initialize database:

// db.ts

import { Database } from "@proxymal/saas-sdk";
import { User } from "./user.entity.ts";

const db = new Database([User]);
export default db;

With some TypeORM entity:

// user.entity.ts

import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn } from "typeorm";

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    email: string;

    @Column()
    password_hash: string;

    @CreateDateColumn()
    create_date: Date;
}

Also don't forget to add connection to the database:

// app.ts

import { API, Docs } from "@proxymal/saas-sdk";
import db from "./db.ts";
import user from "./user.routes.ts";

const api = new API();

api.expand("/api/user", user);

api.start(3000, async () => await db.init());

Entity Services API

As you connected the database and defined entities schema, you can create entity-based service for working with entity database table:

// user.service.ts

import { EntityBaseService } from "@proxymal/saas-sdk";
import { EntityTarget, ObjectLiteral } from "typeorm";
import db from "./db";
import { User } from "./user.entity.ts";

export const UserService = new (class extends EntityBaseService<User> {
    constructor(entity: EntityTarget<ObjectLiteral>) {
        super(db, entity);
    }
})(User);

Now you can work with this entity anywhere:

import { UserService } from "./user.service.ts";

// Find one row of user by it's `id`
await UserService.findOneBy({ id: 1 });

Auth API (JWT)

CRUD API

Logging API

HTML Components API

HTML Pages API (WIP)

You have to build multi-page SSR website? You can use HTML Pages API for that!

Initialize SSR rendering globally (like db.ts):

// ssr.ts

import { SSR } from "@proxymal/saas-sdk";

const ssr = new SSR({
    meta: {
        title: "SaaS",
        description: "SaaS service",
    },
    styles: ["./styles/fonts.css", "./styles/global.css", "./styles/theme.css"],
});

export default ssr;

After that define a page markup:

<!-- /pages/index.page.html -->

<meta> { "title": "SaaS – Main page" } </meta>

<template>
    <section>
        <h1>{{ title }}</h1>
    </section>
</template>

<style>
    section {
        width: 100%;

        display: flex;
    }

    h1 {
        font-size: 52px;
    }
</style>

And render your page in some route:

// website.routes.ts

import { APIModule, SSR } from "@proxymal/saas-sdk";
import ssr from "./ssr.ts";
import index from "./pages/index.page.html";

const routes = new APIModule();

// GET /
routes.get("/", {}, async () => {
    return ssr.render(index, {
        title: "Hello world",
    });
});

export default routes;

NOTE: if you are using direct import of .html files (import "file.html"), you should setup in your .d.ts file this:

declare module "*.html" {
    const value: string;
    export default value;
}