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

@evokegroup/aws

v3.0.3

Published

AWS utilities

Downloads

29

Readme

@evokegroup/aws

AWS utilities

Requires NodeJS 18+

Class: LambdaEvent

Properties

| Property | Type | Description | | -------- | ---- | ----------- | | event | object | The event data from Lambda |

Class: ApiGatewayEvent

extends LambdaEvent

Properties

| Property | Type | Description | | -------- | ---- | ----------- | | headers | object | The event headers | | stageVariables | object | The stage variables sent into the event by API Gateway |

Methods

getBody()

Returns the event request body.

setBody(value)

Overwrite the event request body.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | value | * | | The body value. Will be stringified. |

getBodyJSON()

Returns the event request body as JSON or Error if the data cannot be parsed.

isJsonRequest()

Returns true if the Content-Type header is set to application/json

getHeader(name)

Gets a header by a case-insensitive name.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | name | string | | The case-insensitive header name |

setHeader(name, value)

Sets a header.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | name | string | | The case-insensitive header name | | value | string | | The header value |

getStage()

Gets the stage sent by API Gateway

getStageVariable(name)

Gets a stage variable by name. Returns null if not found.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | name | string | | The stage variable name |

setStageVariable(name, value)

Overrides a stage variable.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | name | string | | The stage variable name | | value | string | | The stage variable value |

Class: Config

Base class for configurations classes that can pass their configuration values via an object

Methods

init(config = this)

Initializes the configuration properties.

set(config = {})

Sets properties.

initProperty(name, value)

Initializes a single property

| Parameter | Type | Description | | --------- | ---- | ----------- | | name | string | The property name | | value | * | The default property value |

getTypedEnvValueOrDefault(value, defaultValue)

Attempts to convert value to the defaultValue type. If defaultValue is a function, value will be passed as the argument and the result will be returned.

| Parameter | Type | Description | | --------- | ---- | ----------- | | value | * | The value | | defaultValue | * | The default typed value to fallback on |

Class: EnvironmentConfig

extends Config

Base class for configurations classes using environment variables (process.env)

Class: LambdaConfig

extends EnvironmentConfig

Base class for configurations classes within a Lambda function

constructor(event)

| Parameters | Type | Default | Description | | ---------- | ---- | ------- | ----------- | | event | EvokeAws.LambdaEvent, object | | The event data passed to the Lambda function |

const { LambdaConfig, SuccessResponse } = require('@evokegroup/aws');

class MyConfig extends LambdaConfig {
  site = null;
  environment = null;

  constructor(event) {
    super(event); 
    this.init();
  }
}

export const handler = async (event) => {
  return new Promise((resolve, reject) => {
    const config = new MyConfig(event);
    // do stuff
    resolve(SuccessResponse.json());
  });
};

Properties

event

The EvokeAws.LambdaEvent created from the event data passed to the function

Class: ApiGatewayConfig

extends EnvironmentConfig

Base class for configurations classes within a Lambda function being exexuted via API Gateway and using stage variables

Class: LambdaResponse

A basic Lambda response object.

{
  statusCode: 200,
  headers: {
    "Access-Control-Allow-Origin": "*"
  },
  body: "Hello world",
  isBase64Encoded: false
}

constructor(object)

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | statusCode | number | 200 | The HTTP status code | | headers | object | { "Access-Control-Allow-Origin": "*" } | The response headers. These headers will be merged with the default headers. | | body | string | | The response body | | isBase64Encoded | boolean | false | The body is base64 encoded |

// Return a base64 encoded Buffer
import { LambdaResponse } from '@evokegroup/aws';
export const handler = async (event) => {
  return new Promise((resolve, reject) => {
    resolve(LambdaResponse.json({ body: Buffer.from('data', 'ascii'), isBase64Encoded: true }));
  });
}

Methods

serialize()

Serializes the response.

toJSON()

See serialize.

Class: JsonResponse

extends LambdaResponse

Base class for JSON-based responses.

{
  statusCode: 200,
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Content-Type": "application/json"
  },
  body: "{\"success\":true,\"message\":\"OK\",\"data\":{}}",
  isBase64Encoded: false
}

constructor(object)

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | statusCode | number | 200 | The HTTP status code | | headers | object | { "Access-Control-Allow-Origin": "*" } | The response headers. These headers will be merged with the default headers. | | message | string | "" | | | data | object | null | |

Class: SuccessResponse

extends JsonResponse

Creates a JsonResponse with a default statusCode = 200 and body success = true.

constructor(object)

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | statusCode | number | 400 | The HTTP status code | | headers | object | { "Content-Type": "application/json" } | See EvokeAws.LambdaResponse | | message | string | "" | The response message | | data | object | null | An object to send back in the response |

const { SuccessResponse } = require('@evokegroup/aws');

export const handler = async (event) => {
  return new Promise((resolve, reject) => {
    resolve(SuccessResponse.json());
  });
};

Class: ErrorResponse

extends JsonResponse

Creates a JsonResponse with a default statusCode = 400 and body success = false.

{
  statusCode: 400,
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Content-Type": "application/json"
  },
  body: "{\"success\":false,\"message\":\"An error has occurred.\",\"data\":null}",
  isBase64Encoded: false
}

constructor(object)

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | statusCode | number | 400 | The HTTP status code | | headers | object | { "Content-Type": "application/json" } | See EvokeAws.LambdaResponse | | message | string | "" | The response message | | data | object | null | An object to send back in the response | | err | object | null | Any error information |

const { ErrorResponse } = require('@evokegroup/aws');

export const handler = async (event) => {
  return new Promise((resolve, reject) => {
    resolve(ErrorResponse.json({ statusCode: 403, message: 'Unauthorized' }));
  });
};