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

swipelime-client-node

v0.3.0

Published

swipelime-client-node is the official swipelime Node.js client library

Downloads

92

Readme

swipelime-client-node

License: MIT

Official Node.js Client Library for swipelime.

See the API documentation for more information and example usage.

Getting the API credentials

To use the package, you'll need to have API credentials. To get an API account, please contact us.

Installation

npm i swipelime-client-node

Requirements

The package officially supports Node.js version 20 an above.

Usage

Import the package and construct a Client. The first argument is an object of your API credentials. With the second argument you can specify the environment you will connect to. You'll need to add a ServiceHandler to the client to handle the tenant.

Be careful not to expose your credentials, for example when sharing source code.

An example using async/await and ES Modules:

import { Client } from 'swipelime-client-node';

const username = 'insert-your-username-here';
const password = 'insert-your-password-here';
const client = new Client({ username, password }, { environment: 'test' });

(async () => {
    const serviceHandler = await client.addServiceHandler({ tenantId: 'insert-tenant-id-here' });
})();

This example is for demonstration purposes only. In production code, the API credentials should NOT be hard-coded, but instead fetched from a configuration file or environment variable.

You will need to add listeners to get the events or commands to process The newTasks event will be called when you receive new tasks from the swipelime API. The tasks is an array containing TaskEvent and/or TaskCommand objects.

serviceHandler.emitter.on('newTasks', (tasks) =>
{
	tasks.forEach(async (task) =>
	{
		// Process the task here
	});
})

You will receive TaskEvent task when the swipelime API is reporting that something has happened in the system. You can check the data for useful information and react to it in your system. After you done processing it you will need to confirm it with the confirm function.

if(task instanceof TaskEvent)
{
	// Test event
	if(task.data.eventType === 'test')
	{
		console.log('test event has arrived');
	}

	await task.confirm();

	console.log('test event has been confirmed');
}

You will receive TaskCommand task when the swipelime API is requesting data from your system. You will need to gather the data and call the matching function for the command type. For example if you receive the test command you will need to call serviceHandler.confirmTestCommand. You do not need to confirm the TaskCommand because calling the function will automatically does it for you.

else if(task instanceof TaskCommand)
{
	// Test command
	if(task.data.commandType === 'test')
	{
		console.log('test command has arrived');

		await serviceHandler.confirmTestCommand(task);

		console.log('test command has been confirmed');
	}
}

You have the option to just refuse to give us the information when you receive the command. This is possible by calling the task.refuse function. It is also a good idea to refuse any unknown or not implemented commands so it don't fill up the queue.

else
{
	task.refuse();
}

Example project

You can find an example typescript project here, which demonstrates the usage of swipelime client.