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

hsi-sdk

v3.4.1

Published

HSI SDK includes functions for calculations # Installation

Downloads

1

Readme

HSI-SDK

HSI SDK includes functions for calculations

Installation

npm install heeros/hsi-sdk

Releasing & building

  1. Run npm run build:dist to bundle the sources into fresh distributions
  2. PR the built distributions & merge to main branch
  3. From the top of the main branch, execute
npm version <patch|minor|major> && git push && git push --tags

Structure & importing

The library provides 2 different modules for importing:

  • hsi-sdk --> module that doesn't expect any dependencies to AWS (fits for client side)
  • hsi-sdk/backend --> module that expects aws-sdk as a dependency (fits for backend side)

Depending on your use case, import/require either of the modules.

Components

Serializer

Module providing functions to serialize/de-serialize provided supported values as base64 data. For more in-depth details on how to use, see the written unit tests.

Can be used for example, to "stringify" the LastEvaluatedKey returned from DynamoDb for more convenient usage in the client side.

Usage
const { serializer } = require('hsi-sdk')
const serializedData = serializer.encode('foobar') // from string to token
const originalData = serializer.decode(serializedData, 'string') // from token to string

DynamoDB

QueryBuilder

Helper function, to provide functional API for generating DynamoDB queries. For more in-depth details on how to use, see the written unit tests in the test/lib/dynamodb/query-builder.test.js

Usage
const { dynamodb } = require('hsi-sdk')
const query = dynamodb.QueryBuilder()
      .fromTable('some-table')
      .fromIndex('some-index')
      .byKey({ zoo: 'some-key', jar: 'some-sort-key' }, { jar: { queryType: 'range' } }) // second arg provided, to configure expression
      .filterBy({
          foo: 'foo-val',
          bar: 'bar-val',
          ruta: { baga: 'baga-val' }
        },
        { foo: { queryType: 'lt' }, 'ruta.baga': { queryType: 'gt' }
      })
      .withExclusiveStartKey('some-starting-key')
      .withLimit(5)
      .includeAttributes(['foo', 'bar'])
      .build()

Filters

Module providing helper functionality for generating filter expressions

getFilterExpression

Usage
const { dynamodb: { filters } } = require('hsi-sdk')
const res = filters.getFilterExpression({ foo: 'bar', zoo: 'jar' })

// res equals:
/*
{
    filterExpression: '#foo = :foo and #zoo = :zoo',
    expressionAttributeNames: {
        '#foo': 'foo',
        '#zoo': 'zoo'
    },
    expressionAttributeValues: {
        ':foo': 'bar',
        ':zoo': 'jar'
    }
}
*/

Authorization

authorizedResource

This function expects to receive object containing Lambda API handlers & performs authorization checks for each based on provided parameters.

The argument object expects the following properties:

  • apiHandlers - Object containing the API handlers
  • subjects - Array of subjects describing the target contexts of the authorization
  • scopeResolver - Optional promise returning function, to provide ability to resolve the possible scope for the authorization (ie. tt/la code)
  • errorHandler - Optional function to handler authorization errors, ie. you can pass the error.throw* functions from the lambda-sdk here
Usage
const { authorization } = require('hsi-sdk')
const { error } = require('lambda-sdk')

const create = (params, event) => 'some handler responding to POST'

const authorizedHandlers = authorization.authorizedResource({
  apiHandlers: { create },
  subjects: ['settings'],
  scopeResolver: async (params) => 'for-example-some-resolved-ttla-combo',
  errorHandler: error.throwForbidden
})

States

States module includes functions that are dependant on resource statuses.

getRestrictions

This function accepts a status as an argument & returns an object illustrating possible restrictions related to the status (ie. whether certain fields should be read-only in the specified status).

The object returned follows following structure:

{
  _all: { readOnly: true },
  dueDate: { readOnly: false },
  noteDate: { readOnly: false },
  'product.domesticAccountNumber': { readOnly: false },
  'product.vat.code': { readOnly: false },
  'product.accountingObjectList': { readOnly: false }
}

The above example translates to:

  1. set all fields as "read-only"
  2. exclude dueDate & set it as editable
  3. exclude noteDate & set it as editable
  4. exclude product.domesticAccountNumber & set it as editable
  5. exclude product.vat.code & set it as editable
  6. exclude product.accountingObjectList & set it as editable

The property names are designed to follow dot-notation in complex fields, so they are easier to map in client side projects to form field names. However, fields containing arrays still require explicit handling.