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

@fimwise/sdk

v1.0.8

Published

The @fimwise/sdk offers client SDKs for building bot tasks in JavaScript/TypeScript

Downloads

3

Readme

Fimwise Javascript/Typescript SDK

The @fimwise/sdk offers client SDKs for building bot tasks in JavaScript/TypeScript.

Building bot tasks in JavaScript primarily involves the following steps:

  1. Setting up the @fimwise/sdk package.
  2. Configuring authentication.
  3. Developing your bot.
  4. Run your bot.

Setting up @fimwise/sdk package

Obtain the package from npm:

npm i @fimwise/sdk

or

yarn add @fimwise/sdk

Authentication configuration

Create a client from the Fimwise Cloud server to authenticate and authorize access from the bot. Upon creating the client, you will receive the following information:

  • Client ID: Key for authentication.
  • Secret Key: Secret for the key above.

Note: The Secret Key is only displayed once after client creation. If lost, reset the client to generate a new one.

You can specify this information in a credentials.jsonfile:

{
  "$schema": "https://fimwise.com/schemas/credentials.schema.json",
  "clientId": "client id",
  "secretKey": "secret key"
}

Place this file in the root of your project:

│   credentials.json <-- place here
│   package.json
├───node_modules
└───src
        index.js

Developing your first bot

Logs the task input and responds with the "Hello World" message:

import { startSimpleBot } from '@fimwise/sdk';

await startSimpleBot(async ({input}) => {
  console.log("The task input is: ", input)
  return {
    message: "Hello world"
  }
})

To run this bot, simply call npm start or node index.js as with any normal Node.js project.

Requesting resources

We provide several apis for getting resources from our server such as request, task, budget...

import { requestApi } from "@fimwise/sdk";

const request = await requestApi.getRequest("de4df841-1c6d-4c99-81a2-1ac3ab9077c9");
console.log("Found request: ", request);

Developing a more complex bot

Checks for new requests and, if the supplier is available, sends an email to them. Otherwise, it rechecks later:

import { Bot, TaskBase, TaskContext } from '@fimwise/sdk';

class SendMailTask extends TaskBase {
  protected async handle({ input, log }: TaskContext) {
    const { requestId, subject, supplierId } = input;
    log('info', `Received a new request ${requestId}`);

    if (await this.checkSupplierAvailable(supplierId)) {
      await this.sendMail(subject, supplierId);
      log('info', `An email was sent to supplier ${supplierId} to notify a new request`);
    } else {
      log('warn', `Supplier ${supplierId} is not available, recheck it later`);
      return recallTaskAfter();
    }
  }

  private async checkSupplierAvailable(supplierId: string) {
    // TODO: some logic here
    return true;
  }

  private async sendMail(subject: string, supplierId: string) {
    // TODO: some logic here
  }
}

const bot = await Bot.builder()
  .task(new SendMailTask())
  .concurrency(2)// can handle 2 tasks in the same time
  .interval(1000)// check available task each 1 second
  .name("SendMailBot")
  .build();

await bot.start();