Socket
Socket
Sign inDemoInstall

@noths/cloud-utils

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@noths/cloud-utils

Functional cloud utilities for NOTHS Serverless Cloud Applications


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Cloud Utilities

A collection of helpful Node.JS utility functions which are used across Lambda (and other) serverless functions.

Secrets

Wraps function execution with encrypted secrets from AWS SSM Parameter Store using a specific key, provided that the executing IAM Role has sufficient privileges to do so.

import { withParameters } from '@noths/cloud-utils';

const SECRET_KEY = '/path/to/ssm/encrypted/secret';

const ALIAS = 'SUPER_SECRET_KEY';

const myFn = async ({ [ALIAS]: key }, a, b) => {
  return thirdPartyApi(key).someOperation(a, b);
};

export default withParameters({ [ALIAS]: SECRET_KEY })(myFn);

Elsewhere in the application, this function can be consumed as:

import myFn from './some-file';

const handler = async (a, b, ...other) => {
  const { result } = await myFn(a, b);
  return result;
};

Errors

Provides a helpful utility for optionally wrapping low-level, native error objects from libraries with application errors which can be:

  • Serialized and surfaced to consumer applications.
  • Filtered inside logs using JSONPath to provide custom application error metrics.
import { withProperties } from '@noths/cloud-utils/tools/errors';

export const FOOBAR_ERROR = 'FoobarError';

const errors = {
  ...(withProperties(FOOBAR_ERROR, { statusCode: 400, message: 'A foobar error occurred' })),
};

export default errors;

When you need to throw an error of this type inside your application, you can instantiate it like so:

import Errors, { FOOBAR_ERROR } from './errors';

const { [FOOBAR_ERROR]: LogicalError } = Errors;

const fn = (cb) => {
  someOperation((err, data) => {
    if (err) {
      throw new LogicalError('overrides default message', err);
    } else {
      cb(data);
    }
  })
};

Logger

Simple logger for serializing objects and application errors into JSON lines for inspection and JSONPath filtering.

import Logger from '@noths/cloud-utils/tools/logger';

const TIME_TAKEN = 'ExecutionTimeTaken';

const reporter = (time) => ({ time, type: TIME_TAKEN });

const handler = async () => {
  const start = +new Date();
  const data = await processor();
  const end = +new Date();
  Logger.info(reporter(end - start));
  return data;
};

There are two environment variables you can set, in-order to control the logger:

  • LOG_LEVEL - The level of logging to produce output for.

Responders

HTTP Responders wrap response objects from Lambda Proxy functions (or any other mechanism), enabling the easy serialization of Javascript objects whether it is a success or failure.

import { success, failure } from '@noths/cloud-utils/tools/responders';

// Object containing security HTTP headers & CORS
import headers from './headers';

export const handler = async (event, context, cb) => {
  try {
    const result = await processor(event);
    const response = success({ code: 201, headers, body: result });
    cb(null, response);
  } catch (err) {
    if (err.statusCode) {
      // application error
      cb(null, failure(event, err));
    } else {
      // native error
      cb(err);
    }
  }
};

FAQs

Package last updated on 29 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc