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

@govuk-pay/pay-js-commons

v6.0.12

Published

Reusable js scripts for GOV.UK Pay Node.js projects

Downloads

1,490

Readme

GOV.UK Pay JS Commons

Reusable js scripts for GOV.UK Pay Node.js projects

Browsered scripts

This is a collection of client side scripts we use throughout GOV.UK Pay in the browser. We call it browsered because they are written in Node.js and browsered by Browserify to make them safe for all our browsers. We browserify within the microservice when it’s compiled.

List of scripts

Field Validation

This is a collection of validators that can be applied to inputs that will check the values and display errors using the GOV.UK elements styling.

Validators:

Required

This requires a value from a given input

<form data-validate>
  <div class="govuk-form-group">
    <label for="name">Your name</label>
    <input name="name" data-validate="required" value="" />
  </div>
</form>

Currency

This requires the value is a valid currency amount i.e. “10” or ”9.99”.

<form data-validate>
  <div class="govuk-form-group">
    <label for="amount">Amount</label>
    <input name="amount" data-validate="required currency" value="" />
  </div>
</form>

Email

This requires the value is a valid email address with a TLD on the end (as technically an email doesn’t need one).

<form data-validate>
  <div class="govuk-form-group">
    <label for="email">Your email address</label>
    <input name="email" data-validate="email" value="" />
  </div>
</form>

Phone

This requires the value is a 11 digit phone number, it isn’t concerned with spacing, so 077 777 777 77 and 07777777777 are both valid.

<form data-validate>
  <div class="govuk-form-group">
    <label for="phone">Phone number</label>
    <input name="phone" data-validate="phone" value="" />
  </div>
</form>

HTTPS

This requires a link to begin with https://

<form data-validate>
  <div class="govuk-form-group">
    <label for="url">Return URL</label>
    <input name="url" data-validate="https" value="" />
  </div>
</form>

Number is less than maximum value

This requires the value is less than £100,000 as that has been deemed sensible…

<form data-validate>
  <div class="govuk-form-group">
    <label for="price">Amount</label>
    <input name="price" data-validate="belowMaxAmount" value="" />
  </div>
</form>

Password

This requires a password be at least 10 chars

<form data-validate>
  <div class="govuk-form-group">
    <label for="password">Password</label>
    <input name="password" data-validate="passwordLessThanTenChars" value="" />
  </div>
</form>

Maximum character limit

This requires a value be less than a certain number of characters. This limit is set within a data-attribute

<form data-validate>
  <div class="govuk-form-group">
    <label for="title">Title</label>
    <input name="title" data-validate="isFieldGreaterThanMaxLengthChars" data-validate-max-length="255" value="" />
  </div>
</form>

NAXSI

This checks whether a field contains characters than would cause NAXSI to get upset, meaning characters that look like code injection i.e. < > ; : ` ( ) " \' = | , ~ [ ]

<form data-validate>
  <div class="govuk-form-group">
    <label for="title">Title</label>
    <input name="title" data-validate="isNaxsiSafe" value="" />
  </div>
</form>

Utilities

Nunjucks filters

These are small functions that power the nunjucks filters but can also be used for server side stuff too.

These get loaded in to the Nunjucks environment and then can apply changes to variables in templates.

For example if a country comes in as ISO code EN it can be converted to it’s name like so

  <p>{{ countryCode | countryISOtoName }}</p>

Or a pence value can be converted to GBP

  <dl>
    <dt>Amount:</dt>
    <dd>{{ amount | penceToPounds }}</dd>
  </dl>

Axios base client

Used in our Node.js apps to call APIs such as connector or ledger.

Uses the NPM Axios library.

The base client provides the following configuration options:

  • onRequestStart - Callback function before starting a API request. Mainly used for logging.
  • onSuccessResponse - Callback function when request has completed successfully.
  • onFailureResponse - Callback function when request has failed.
  • acceptAllStatusCodes - boolean
    • By default all non 2xx responses are considered failed requests.
    • Set this to true and all status codes are considered a successful request. You code will then need to handle the response appropriately. Currently, only pay-frontend requires this to be set to true.

Built in in retry functionality

If a GET request provides a response with the error message ECONNRESET - the the Axios base client will automatically try that request another 2 times - 3 times in total.

By default, on each failed request, it will call the onFailureResponse callback.

If acceptAllStatusCodes=true, then it will call the onSuccessResponse callback.

Releasing

After a pull request is merged, Concourse will automatically create a new release pull request that increments the package version.

This pull request must be reviewed and merged by a developer.

Once the release pull request is merged, GitHub Actions will publish the new versioned package to NPM.

IMPORTANT: Other pull requests will be blocked from merging until the release pull request is merged or closed.