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

@hmcts/div-document-express-handler

v1.1.0

Published

A module to assist serving documents to the public

Downloads

66

Readme

Divorce Document Express Handler

License: MIT

A simple module to handle getting documents

Getting started

Attach document handler to express app

Attach the document get route to the app like so:

const { initDocumentHandler } = require('@hmcts/div-document-express-handler');
const express = require('express');
const idam = require('services/idam');

const app = express();

const middleware = [ idam.protect() ];
const args = {
  // string to define path to attach document donwload handler, default: '/document-download/:documentId' *optional*
  uri: '/document-download/:documentId',
  // only allow files that include the following strings *optional*
  // can be a function or an array
  documentWhiteList: (req, res) => {
    return ['fileName1IncludesString', 'fileName2IncludesString'];
  },
  // string to specifiy auth token cookie, default: '__auth-token' *optional*
  authorizationTokenCookieName: '__auth-token',
  // string to specify the service to fetch the documents from *required*
  documentServiceUrl: 'service-url',
  // array to paths where file collections are stored *required*
  // this is used to get the file id from the session given the file name. all downloadable
  // files must be included in these paths
  sessionFileCollectionsPaths: ['case.data.d8', 'files']
};
initDocumentHandler(app, middleware, args);

Generate urls and file types from file system

Here is an example how to generate file urls and types:

const { Page } = require('@hmcts/one-per-page');
const { createUris } = require('@hmcts/div-document-express-handler');

class Step extends Page {
  static get path() {
    return 'some-path';
  }

  get downloadableFiles() {
    const args = {
      // string to define uri where document donwload handler is attached, default: '/document-download/:documentId' *optional*
      uri: 'some-url',
      // only allow files that include the following strings *optional*
      documentWhiteList: ['someOtherFile']
    };
    // The first argument is an array of files expected the following format:
    // this.req.session.files = [
    //   {
    //     "id": "401ab79e-34cb-4570-9f2f-4cf9357dc1ec",
    //     "value": {
    //       "DocumentFileName" : "someOtherFile1552043698652633"
    //     }
    //   },
    //   {
    //     "id": "401ab79e-34cb-4570-9f2f-4cf9357dc1ec",
    //     "value": {
    //       "DocumentFileName" : "someFile1552043698652633"
    //     }
    //   }
    // ]
    return createUris(this.req.session.files, args);
  }
}

module.exports = Step;

To render output using look-and-feel:

template.html:

{% from "look-and-feel/components/document-list.njk" import documentList %}

<h3 class="heading-small" id="subsection-title">Download your documents</h3>

{{ documentList(downloadableFiles, content.files) }}

main.scss:

@import 'look-and-feel/all';

or to import specific styles for document-list

@import 'look-and-feel/document-list';

content.json:

  {
    "en": {
      "files": {
        "d8petition": "Original Petition",
        "aosinvitation": "Respondent Response",
        "co-respondentaosinvitation": "Co-Respondent Response"
      }
    }
  }

This will print the file list out.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Standard API

We follow RESTful API standards.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.