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

@bebapps/rapyd-sdk

v0.0.4

Published

An un-official [Rapyd](https://rapyd.net) SDK for Node.js.

Downloads

125

Readme

@bebapps/rapyd-sdk

An un-official Rapyd SDK for Node.js.

Installation

To install the SDK you'll need to have the npm CLI installed - then run the following command in your project's root directory.

npm install --save @bebapps/rapid-sdk

RapidClient

The core of the SDK is made up from the RapidClient class. It handles authorization, parameter encoding, signing and making requests, error handling, webhook verification, and more.

The RapidClient class takes in your Rapid secret key and access key, as well as an optional base URL (defaults to: "sandboxapi.rapyd.net").

import { RapidClient } from '@bebapps/rapid-sdk';

const rapid = new RapidClient(
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxx',
);

// ...

Making API requests

If you like calling the Rapid API directly (using hard coded URL paths and parameters) you can make use of the convenience methods exposed on the RapidClient class.

import { Wallet } from '@bebapps/rapid-sdk/dist/generated/wallet/types/Wallet';

// ...

const response = await rapid.get('/v1/user/{}', 'ewallet_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
const wallet = await response.data<Wallet>();

console.log(wallet); // { id: 'ewallet_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', type: 'person', status: 'ACT', [...] }

You may notice the use of {} in the path. These are auto-encoded placeholders. When you use a placeholder in the path, you must also provide the same number of arguments following the path containing the placeholder values. These values will automatically be URL encoded, so if these parameter values are coming from unsanitized user-input - you can sleep easy.

Validating webhook requests

This SDK can also be used to validate incoming webhooks from Rapid. If you'd like a real-world example, checkout the Beb Pay store service verify webhook function.

Using auto-generated APIs

Part of the magic this SDK provides is auto-generated APIs. These APIs are fully typed from the official Rapid documentation, so it can updated with a simple re-publish of the package.

Because the APIs are auto-generated, the source for them cannot be found in the repository. Instead, you can use a tool like UNPKG to navigate through the contents of the published npm package.

Here's an example of creating a wallet using the auto-generated Wallet API.

import { createWallet } from '@bebapps/rapyd-sdk/dist/generated/wallet/apis/Wallet';

const wallet = await createWallet(rapid, {
  contact: {
    contact_type: 'personal',
  },
  ewallet_reference_id: userId,
});

console.log(wallet); // { id: 'ewallet_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', type: 'person', status: 'ACT', [...] }

The advantage to these auto-generated APIs is that you use them all exactly the same way: you provide your RapidClient instance, and an object containing all the parameters the API takes. It combines the path, query, and body parameters into one object. This means you can make the most of Intellisense functionality in your IDE to provide you with helpful suggestions and display documentation as you type.

Error handling

By default, calling the response.data() function will automatically throw an error if the response contained an error code. The JavaScript Error message contains the message from the server (which usually contains super useful human-readable explanations) but also exposes the Rapid Error code on the code field on errors generated by the SDK.

import { WalletError } from '@bebapps/rapyd-sdk/dist/generated/wallet/enums/WalletError';

// ...

try {
  const wallet = await createWallet(rapid, {
    contact: {
      contact_type: 'personal',
    },
    ewallet_reference_id: userId,
  });
} catch (err) {
  switch (err.code) {
    case WalletError.ERROR_CREATE_USER_EWALLET_REFERENCE_ID_ALREADY_EXISTS: {
      console.log('Oh no, this user already has a wallet! Derp!');
      break;
    }
    default: {
      console.log('All other errors end up here!');
      break;
    }
  }
}

Want to build your own SDK?

The code that generates all the auto-generated APIs for this SDK helpfully publishes the "references" it pulls from the Rapid API documentation website. This file is included in the npm package, so you can helpfully download the references.json file from UNPKG.