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

ravelin

v0.2.3

Published

Server-side JS library for the Ravelin API. Ravelin is a fraud detection tool.

Downloads

7

Readme

ravelin-node

Server-side JS library for the Ravelin API. Ravelin is a fraud detection tool.

import Ravelin from 'ravelin';

const client = new Ravelin({
	secretKey: 'sk_live_XXXXXXXX',
});

const result = await client.sendEventAndScore('order', {
	customerId: '0ec0253d-d80c-4987-985e-29f374a3b2fd',
	order: {
		orderId: 'c04edd43-534f-44a1-a31d-a647f27d15f1',
		currency: 'GBP',
		price: 1000,
		items: [
			{ sku: 'cuvva-motor-1hour', quantity: 1 },
		],
	},
});

console.log(result.action); // => ALLOW/REVIEW/PREVENT

Installation

$ npm install --save ravelin

API

All methods return promises. Traditional Node callbacks are not supported.

This API is intended to be pretty hands-off and avoid defining any specific events, or the structure of the parameters for events. By being reasonably flexible, the hope is that most future API changes will "just work" without requiring any modifications to the library.

new Ravelin(options)

First, set up a client by creating an instance of Ravelin.

Options:

This is the only option at the moment. If there is another option you want, open an issue explaining the use-case.

const client = new Ravelin({
	secretKey: 'sk_live_XXXXXXXX',
});

sendEvent(name, params)

Events are sent with a name and various parameters. These are exactly as-defined in the Ravelin docs. For example, the POST /v2/paymentmethod event would be sendEvent('paymentmethod', {...}).

The timestamp parameter, if not defined, will be set to the current time.

Any Date objects provided in the parameters will be converted into unix timestamps before being sent to Ravelin. If you want a particular date to avoid this behavior, you should convert it to a string or number before passing it.

The returned promise will resolve with undefined. (i.e. nothing is returned, but you can still check for errors)

await client.sendEvent('customer', {
	customer: {
		customerId: '0ec0253d-d80c-4987-985e-29f374a3b2fd',
		givenName: 'Gilbert J',
		familyName: 'Loomis',
		location: {
			latitude: 39.75,
			longitude: -84.19,
		},
	},
});

sendEventAndScore(name, params)

Exactly the same as sendEvent, but the promise resolves with the score object, as defined in the Ravelin docs.

const result = await client.sendEventAndScore('order', {
	customerId: '0ec0253d-d80c-4987-985e-29f374a3b2fd',
	order: {
		orderId: 'c04edd43-534f-44a1-a31d-a647f27d15f1',
		currency: 'GBP',
		price: 1000,
		items: [
			{ sku: 'cuvva-motor-1hour', quantity: 1 },
		],
	},
});

console.log(result.action); // => ALLOW/REVIEW/PREVENT

sendBackfillEvent(name, params)

Exactly the same as sendEvent, but not subject to rate limiting. The timestamp parameter is required and will not be set for you automatically.

See the Ravelin docs for important notes about the implications of backfilling data while also sending live events.

await client.sendBackfillEvent('order', {
	timestamp: new Date('1897-04-01T10:12:14.572-08:00'),
	customerId: '0ec0253d-d80c-4987-985e-29f374a3b2fd',
	order: {
		orderId: '5570a366-cc57-4ea7-abfd-1e41211db62f',
		currency: 'USD',
		price: 100000,
		items: [
			{ sku: 'first-insurance-policy', quantity: 1 },
		],
	},
});

Notes

  • event parameters must never contain a recursive reference
  • all null values will be removed entirely, and will not be sent to Ravelin

Support

Please open an issue on this repository.

Authors

License

MIT licensed - see LICENSE file