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

@3kles/3kles-coreion

v2.0.0

Published

3Kles Generic Ion Service

Downloads

106

Readme

@3kles/3kles-coreion

This package contains interface and class to interact with ION API Gateway based on 3kles-corebe

Models

IMIRequest is an interface for request

  • path (string): Path of the request
  • method (string): HTTP method like GET, POST, PUT, DELETE...
  • body (any): Object passed in request
  • contentType (string): Request content type like application/json
  • params ([key:string]:any): List of request parameters
  • query ([key:string]:any): List of URL query
  • cookie (string): Request cookie
  • authorization (string): Request authorization (see Authentication)

IIonRoute is an interface for ION Route

  • middleware (string): Middleware name for this route
  • routingKey (string): Routing key
  • routes (ServiceParams): Define route from ServiceParams (path, method, option...)

IIonMessage is an interface for ION Message

  • key (string): Message key
  • data (any): Message data
  • params ([key:string]:any): Message parameters
  • query ([key:string]:any): Message query

IError is an interface for error

  • status (number): HTTP Error status (401,404,500...)
  • message (string): Error message

Authentication

AuthService is a class to manage Authentication for ION API Gateway based on AuthToken

  • authenticate: Method with request in parameters and generate ION token
  • getIONBEServiceToken: Check if token exist and not expired else generate new ION token
  • isTokenExpired: Check is token expired
  • loadIONBEServiceToken: Generate token from ionapi file information
  • checkAuth: Method to check request authorization

Connector

IONConnector is a class to manage connection with ION based on HttpAPI

  • buildRequest: Create ION request from paramters and data
  • executeRequest: Execute ION request with authorization

Broker

IONBroker is a service that extends from AbstractGenericService from @3kles/3kles-corebe to do CRUD operations

  • listen: Method to subscribe exchange and queue passed in option

App

IONApp is a class to create IONApp based on GenericApp

  • startBroker: Start listening for broker list
  • addBroker: Add IonBroker in broker list

Install

npm

npm install @3kles/3kles-coreion --save

How to use

How to create an app

const authService = new AuthService(null);

const iONConnector = new IONConnector(authService, {
    protocol: 'https',
    context: 'IONSERVICES',
    middleware: '/process/application'
});

class ParserCustom implements IParserResponse {
    parseResponse(data: any) {
        const response = Buffer.concat(data).toString();
        try {
            return JSON.parse(response);
        } catch (_) {
            return response;
        }
    }
}

iONConnector.setResponseParser(new ParserCustom());
iONConnector.setErrorParser(new ParserCustom());

const endpoints: IIonRoute[] = [
    {
        routes: {
            ping: {
                method: 'GET',
                path: '/ping',
                option: {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: '/ping'
                },
            },
        }
    },
    {
        routingKey: 'pulse.alert',
        middleware: 'pulse/alert',
        routes: {
            create: {
                method: 'POST',
                path: '/create',
                option: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/alert/create'
                },
            },
            cancel: {
                method: 'POST',
                path: '/cancel',
                option: {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/alert/cancel'
                },
            },
            redistribute: {
                method: 'POST',
                path: '/redistribute',
                option: {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/alert/redistribute'
                },
            }
        }
    },
    {
        routingKey: 'pulse.notification',
        middleware: 'pulse/notification',
        routes: {
            create: {
                method: 'POST',
                path: '/create',
                option: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/notification/create'
                },
            },
            cancel: {
                method: 'POST',
                path: '/cancel',
                option: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/notification/cancel'
                },
            }
        }
    },
    {
        routingKey: 'pulse.workflow',
        middleware: 'pulse/workflow',
        routes: {
            cancel: {
                method: 'POST',
                path: '/cancel',
                option: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/workflow/cancel'
                },
            },
            start: {
                method: 'POST',
                path: '/start',
                option: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/workflow/start'
                },
            },
            interface: {
                method: 'GET',
                path: '/start',
                option: {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    path: 'v1/pulse/workflow/interface'
                },
            },
        }
    },
];

(async () => {
    const broker = await MessageBroker.initInstance('0', { prefetch: 50 });
    const app = new IonApp();

    endpoints.forEach(endpoint => {
        app.addRoute(new SecureRouter(authService,
            new GenericController(new GenericService(iONConnector, endpoint.routes))).router,
            endpoint.middleware || undefined);

        if (endpoint.routingKey) {
            app.addIonBroker(new IonBroker(broker, iONConnector, endpoint));
        }

    });
    const port = process.env.PORT ? +process.env.PORT : 80;
    app.startApp(port);
    app.startBroker();
})();
    app.startBroker();
})();

Check the documentation here.