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

@ministryofjustice/fb-client

v2.1.7

Published

Form Builder clients for Email, SMS, Submitter, User Data Store, User File Store, and JSON Web Token (for Node)

Downloads

9

Readme

Client

Clients for Email, SMS, Submitter, User Data Store, User File Store, and JWT.

JSON Web Token client

Base client for requests to endpoints which require a JSON Web Token for authentication.

Using a client

const FBJWTClient = require('@ministryofjustice/fb-client/user/jwt/client')

const jwtClient = new FBJWTClient(serviceSecret, serviceSlug, microserviceUrl, [errorClass])

Service Secret

A serviceSecret is required.

The constructor will throw an error if no serviceSecret is provided.

Service Slug

A serviceSlug is required.

The constructor will throw an error if no serviceSlug is provided.

Microservice URL

A microserviceUrl is required.

The constructor will throw an error if no microserviceUrl is provided.

Error Class

An errorClass is optional.

Extending

class FBMyClient extends FBJWTClient {
  constructor (serviceSecret, serviceSlug, microserviceUrl, [myVar]) {
    super(serviceSecret, serviceSlug, microserviceUrl)
    this.myVar = myVar // assign the optional constructor argument
  }
}

const myClient = new FBMyClient('service_secret', 'myservice', 'http://myservice', ['my var'])
// a custom error class extending the base error class
class FBAnotherClientError extends FBJWTClient.prototype.ErrorClass {}

class FBAnotherClient extends FBJWTClient {
  constructor (serviceSecret, serviceSlug, microserviceUrl) {
    super(serviceSecret, serviceSlug, microserviceUrl, FBAnotherClientError)
  }
}

Methods

  • generateAccessToken

    Generate a JWT access token

  • createEndpointUrl

    Create the URL for an endpoint

  • sendGet

    Dispatch GET requests to an endpoint

  • sendPost

    Dispatch POST requests to an endpoint

  • encrypt

    Encrypt data with AES 256

  • decrypt

    Decrypt data

  • encryptUserIdAndToken

    Encrypt the user ID and token using the service secret

  • decryptUserIdAndToken

    Decrypt the user ID and token using the service secret

  • handleRequestError

    This function will be invoked with an error an argument when the transaction fails

  • createRequestOptions

    Create request options, whether GET or POST

  • throwRequestError

    This function can be invoked to throw request errors

JSON Web Token client implementations

Data Store client

Client for requests to datastore endpoints.

Using a client

const FBUserDataStoreClient = require('@ministryofjustice/fb-client/user/datastore/client')

const userDataStoreClient = new FBUserDataStoreClient(serviceSecret, serviceSlug, userDataStoreUrl)

Fetching and storing

// fetch user data
const userData = await userDataStoreClient.getData(userId, userToken)

// store user data
await userDataStoreClient.setData(userId, userToken, userData)

File Store client

Client for requests to filestore endpoints.

Using a client

const FBUserFileStoreClient = require('@ministryofjustice/fb-client/user/filestore/client')

const userFileStoreClient = new FBUserFileStoreClient(serviceSecret, serviceSlug, userFileStoreUrl)

Fetching and storing

Fetching
// fetch user file
const userFile = await userFileStoreClient.fetch(userId, userToken, fingerprint)
Storing

Define a policy:

const policy = { [max_size], [expires], [allowed_types] }

Either:

// store user file from file data
const uploadDetails = await userFileStoreClient.store(userId, userToken, file, policy)

Or:

// store user file from file path
const uploadDetails = await userFileStoreClient.storeFromPath(userId, userToken, filePath, policy)