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

ideariver.services.server

v1.0.2

Published

A robust Node.js library for building scalable backend services with a focus on security, modularity, and extensibility. It provides a comprehensive solution for handling CRUD operations, authentication, and middleware management, built on top of Express

Downloads

5

Readme

IdeaRiver Services Server

A robust Node.js library for building scalable backend services with a focus on security, modularity, and extensibility. It provides a comprehensive solution for handling CRUD operations, authentication, and middleware management, built on top of Express and TypeORM.

Features

  • Abstracted CRUD Operations: Simplifies the implementation of Create, Read, Update, Delete (CRUD) functionalities.
  • OpenID Connect Authentication: Seamlessly integrates with Keycloak for secure authentication and authorization.
  • Middleware Support: Offers customizable pre- and post-processing through middleware.
  • Security Enhancements: Includes rate limiting, Helmet for security headers, and CSRF protection.
  • Database Support: Works out of the box with PostgreSQL and SQLite databases.
  • Extensive Test Coverage: Comes with Jest and Supertest tests to ensure reliability.

Installation

Install the library via npm:

npm install ideariver.services.server

Configuration

To use the library, create a .env file in your project root:

env
Copy code
KEYCLOAK_CLIENT_ID=my-client
KEYCLOAK_CLIENT_SECRET=my-client-secret
KEYCLOAK_REALM=MyRealm
KEYCLOAK_SERVER=http://localhost:8080/realms/MyRealm/.well-known/openid-configuration
PORT=3000
APP_ENV=dev
SSL_EN=false
CORS_EN=false
CSURF_EN=false
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100

Usage

Import and set up the library in your project:

import { OpenID } from "ideariver.services.server";
import express from "express";

const app = express();
const openIDService = new OpenID();

app.use(express.json());

app.get("/protected", openIDService.authorize, (req, res) => {
  res.json({ message: "Protected route accessed" });
});

app.listen(process.env.PORT, () => {
  console.log(`Server running on port ${process.env.PORT}`);
});

Building Your Project

To compile your TypeScript code:


npm run build

Running Tests

Execute tests using Jest:

npm run test

API Documentation

OpenID Class

The OpenID class provides methods to integrate with Keycloak for handling authentication.

Methods

  • init(): Initializes the Keycloak client.
  • authorize(req, res, next): Middleware to protect routes using JWTs.
  • getKeycloakToken(username, password, scopes): Retrieves an access token from Keycloak.
  • refreshToken(refreshToken): Refreshes an existing access token.

AbstractCrudController Class

Provides a base class for implementing CRUD operations with customizable middleware.

Usage Example

Copy code
import { AbstractCrudController } from 'ideariver.services.server';
import { Entity, PrimaryGeneratedColumn, Column, Repository } from 'typeorm';

@Entity()
class MyEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;

@Column()
name!: string;
}

class MyEntityController extends AbstractCrudController<MyEntity> {
constructor(repository: Repository<MyEntity>) {
super(repository);
}
}

AbstractValidator Class

A base class for validating requests using class-validator and class-transformer.

Usage Example

Copy code
import { AbstractValidator } from 'ideariver.services.server';
import { IsString } from 'class-validator';

class MyEntity {
@IsString()
name!: string;
}

class MyEntityValidator extends AbstractValidator<MyEntity> {
constructor() {
super(MyEntity);
}
}

Contributing

We welcome contributions! Please follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -b feature-branch).
  • Make your changes.
  • Commit your changes (git commit -m 'Add new feature').
  • Push to the branch (git push origin feature-branch).
  • Open a Pull Request.

License

This project is licensed under the MIT License.