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

@inventsable/gatekeeper

v1.0.0

Published

Utilities for Moore auth and decryption

Downloads

2

Readme

@inventsable/gatekeeper

Installation

npm i @inventsable/gatekeeper
import {
  encrypt,
  decrypt,
  getAWSSecrets,
  parseJWTString,
  login,
  makeRequest,
  requestFromServer,
  isJSON,
} from "@inventsable/gatekeeper";

API

async login(username, password, url) ⇒ Object | Error

Thenable method for remote OAuth access to Moore's SSO system

Kind: global function

| Param | Type | Default | Description | | -------- | ------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------- | | username | String | | Exact string of user to log in | | password | String | | Exact string of password associated to user | | url | String | https://dev-sso.gomsi.net/auth/realms/sso/protocol/openid-connect/token | (optional) URL of SSO auth origin to query |

const loginToken = await login(process.env.username, process.env.password);
console.log("\r\nResult of login:");
console.log(loginToken);

parseJWTString(stringValue) ⇒ Object | Error

Shorthand method to parse JWT (JSON web token) string contents and retrieve original data object

Kind: global function
Returns: Object | Error - The parsed object result or error when invalid

| Param | Type | Description | | ----------- | ------------------- | ----------------------------------------------------------------------- | | stringValue | String | The contents of an access_token, refresh_token, or valid JSON Web Token |

// Parsing the login token retrieved from the login function above
const parsedToken = parseJWTString(loginToken.access_token);
console.log("\r\nJWT parsing:");
console.log(parsedToken);

async makeRequest(data, headers, asJSON) ⇒ Object | Error

Thenable shorthand method for POST with dynamic body and header content

Kind: global function
Returns: Object | Error - Response from server

| Param | Type | Default | Description | | ------- | -------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------- | | data | Object | | Key/value pairs to append to request body on POST with exception to "url" key/value which serves as destination | | headers | Array | | (optional) Array of Object with explicit "key" and "value" key/values to append as headers | | asJSON | Boolean | false | (optional) Whether to return as original or parsed JSON format |

// Encrypting the parsedToken sub value, then sending it with proper credentials to Moore's server:
const serverResponse = await makeRequest({
  sub: encrypt(parsedToken.sub, secret), // "secret" is the getAWSSecrets passphrase
  url: "https://moorepass.com/get-token.php",
}).catch((err) => {
  console.error(err);
});
console.log("\r\nServer response:");
console.log(serverResponse);

async requestFromServer(url, requestOptions, asJSON) ⇒ Object

Kind: global function
Returns: Object - Request event response

| Param | Type | Default | Description | | -------------- | -------------------- | ----------------- | -------------------------------------------------------------------------------- | | url | String | | Destination of HTTP request | | requestOptions | Object | | Valid HTTP request options, such as method: "POST", body, headers, redirect, etc | | asJSON | Boolean | true | (optional) Whether to return as original or parsed JSON format |

// A very basic POST request:
let requestOptions = {
  method: "POST",
  headers: myHeaders, // new Headers()
  body: urlencoded, // new URLSearchParams()
  redirect: "follow",
};
let response = await requestFromServer(url, requestOptions, asJSON);

isJSON(text) ⇒ Boolean

Shorthand to determine whether data is string or stringified JSON

Kind: global function
Returns: Boolean - Whether data is valid JSON format and can be parsed

| Param | Type | Description | | ----- | ------------------- | -------------------------------------------------------- | | text | String | Data to query and check if created from JSON.stringify() |

let realData = isJSON(someVariable) ? JSON.parse(data) : data;
// realData is now reliably a parsed object rather than a potential string or object

async getAWSSecrets(config) ⇒ Object | Error

Thenable method for querying AWS Key Manager contents, later to be used for all decryption and encryption. By default this assumes the existence of environment variables containing the 4 required keys designated below, but these can be passed as the parameter to the function in a destructured options/config format

Kind: global function
Returns: Object | Error - The server response if credentials were valid, or message outlining any errors

Prerequisites: Must include config option as first parameter or .ENV variables with of the keys: region, secret_name, secret_access_id, and secret_access_key.

| Param | Type | Description | | ------ | ------------------- | ---------------------------------------------------------------------------------------------------------------- | | config | Object | (optional) Valid AWS credentials, including "region", "secret_name", "secret_access_id", and "secret_access_key" |

// Query AWS SecretsManager to obtain a secure passphrase used later encryption/decryption.
let secret = await getAWSSecrets();
console.log("\r\n AWS Key Manager response:", secret);
secret = secret["token-login"];

// The below is redundant. If ENV vars already exist, they're inherited. Should only need to use object destructuring for config if these values would be coming from somewhere other than ENV variables (but no sense to expose them here, even in a private NPM package and Git repo)
let secretAlt = await getAWSSecrets({
  region: process.env.region,
  secret_name: process.env.secret_name,
  secret_access_id: process.env.secret_access_id,
  secret_access_key: process.env.secret_access_key,
});