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

@bhtbot/bhtbotservice

v0.0.22

Published

BHT-Bot Service Framework

Downloads

52

Readme

BHT Bot Service Framework

Purpose

This library is meant to kickstart new BHT-Bot Service Applications and reduce any existing and future redundancies.

You can setup a new Service in just a few lines of code. All you have to care about is the implementation of your specific Service Implementations, while Service Communication and Types are offered by the framework.

Service communication is build w

The framework contains CommonJS and ES-Modules bundles.

Get in touch

Here are some starting points if you want to get in touch with the code

Examples:

Tests:

  • Most of the features are also represented in extensive Tests, so you might find it helpful to take a look at src/lib/service.spec.ts

Specs:

Quick start a service

Install

Install Dependency to your (node)app

$ npm i @bhtbot/bhtbotservice
or
$ yarn add @bhtbot/bhtbotservice

Init | Config | Port | Middleware

Inititalize the Service on a port, specified by process environment

import {Service, AppConfig} from '@bhtbot/bhtbotservice';
const config = new AppConfig();
config.port = process.env.CATS_PORT ? Number(process.env.CATS_PORT) : 3000;
const service = new Service('catService', config);

Other Options for config can be found here: https://beuthbot.github.io/bhtbot_serviceframework/classes/appconfig.html

For example, if you need to enable another Middleware for your service (like CORS in this example):

//...
import * as cors from 'cors';
//...
const config = new AppConfig();
config.addMiddleWare(cors());
const service = new Service('catService', config);

Content Serives (Basic Endpoint)

This framework is especially meant for building "Content Services". The syntax of those requests is defined by the Gateway.

The current structure of such gateway requests is defined in https://beuthbot.github.io/bhtbot_serviceframework/classes/gatewayrequest.html

If you want to handle gateway requests, just listen for an endpoint name of your choice like so

/* Listen on endpoint /cat */
service.endpoint('cat', async (req: GatewayRequest, answ: GatewayAnswer)=>{
    return answ.setContent((await queryCat()).url).setCacheable(false);
})

In this simple use case we just return the provided answer with the generated output as content. In most use cases, a content service won't do any more communication-related stuff within the service itself.

Utility Services (Advanced Endpoints)

If you happen to build a custom "Utility Service" you will probably need other Endpoints, because the default endpoint is bound to the gateway request structures, such as having an user, entities and intents

File Upload

Accept files as input for your service

  service.fileUploadEndpoint('upload', async (request, answer) => {
    const fileKeys = Object.keys(request.files);
    const firstFile: UploadedFile = <UploadedFile>request.files[fileKeys[0]];
    return answer.setContent(firstFile.name);
  });

File Answer

For passing Files as response of Gateway-Requests

service.endpoint(testEndpoint, async (_request, _answer) => {
    return FileAnswer.fromPath(testFilePathOGG);
});

Arbitrary Endpoints

If you need any special endpoint that can't be created with the given tools, feel free to register them like you usually would within an express server

service.expressApp.get('/custom', function(req, res) {
    res.send('Hello Custom endpoint')
})

Contribution

Since this is a university project which will be passed to new students every semester with their own philosophies and goals, this framework is subject of heavy (breaking) changes.

To keep everybody in sync, any rules and changes made to the project must be visible within this repository.

All rules and pipelines must be implemented as a script withing package.json

Building

For development you can use convenient watchers that will rebuild on file change

$ npm watch:build
$ npm watch:test

Release builds are triggered by

$ npm build:main
$ npm build:module

Lint & beautify

Some code cleanup is done by fix scripts and validated by test scripts

$npm run fix:prettier
$npm run fix:lint
$npm run test:prettier
$npm run test:lint
$npm run test:spelling

Test

There are unit tests as well as coverage checks

$ npm run test: unit
$ npm run cov

Releasing

Deployment

The final release script combines all the steps into a single pipeline which also heightens the build version in package.json and commits the version as a tag for the repository.

This will also generate the docs with npm run doc which will be published to github pages

$ # npm run reset-hard # BEWARE: this will clear your working tree. make sure every changes you want to publish are commited
$ npm run prepare-release

Publishing

After the build pipeline is finished, you will be provided with information about how to publish, which essentially means pushing your code to the git repository and publishing the build to npmjs

$ git push --tags
$ npm publish

Versioning / Changelog

The Patch-Versioning is done automagically by the prepare-release script. Feature and Major releases can be set manually or with help of npm run standard-version You should also consider adding notes to the CHANGELOG.md

Credits

Credits to Bitjson for providing a mature Typescript starter template https://github.com/bitjson/typescript-starter

Initial Work by Dennis Walz