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

moesif-alexa-skills

v1.1.2

Published

API Monitoring Middleware for Alexa Skills and Lambda

Downloads

6

Readme

Moesif AWS Alexa Skills Middleware

NPM

Built Software License Source Code

Alexa Skills Middleware (NodeJS) to automatically log API calls from your AWS Lambda functions and sends to Moesif for API analytics and log analysis.

Designed for AWS Lambda functions that use the Alexa Skills Kit as a trigger.

This middleware expects the Alexa skills format.

Source Code on GitHub

Package on NPMJS

How to install

npm install --save moesif-alexa-skills

How to use

The following shows how import Moesif and use:

1. Import the module:

// Import Modules
'use strict'
const moesif = require('moesif-alexa-skills');

const moesifOptions = {
    applicationId: 'Your Moesif Application Id',
};

exports.handler = function (event, context, callback) {
    callback(null, {
        statusCode: '200',
        body: JSON.stringify({key: 'hello world'}),
        headers: {
            'Content-Type': 'application/json',
        },
    });
};

exports.handler = moesif(moesifOptions, exports.handler);

2. Enter Moesif Application Id

Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking Installation.

Repo file structure

  • lib/index.js the middleware lib
  • index.js sample AWS Lambda function using the middleware

Configuration options

identifyUser

Type: (event, context) => String identifyUser is a function that takes AWS lambda event and context objects as arguments and returns a userId. This helps us attribute requests to unique users. By default, Moesif will use event.session.user.userId

options.identifyUser = function (event, context) {
  // your code here, must return a string
  return event.requestContext.identity.cognitoIdentityId
}

getSessionToken

Type: (event, context) => String getSessionToken a function that takes AWS lambda event and context objects as arguments and returns a session token (i.e. such as an API key). By default, Moesif will use event.session.sessionId

options.getSessionToken = function (event, context) {
  // your code here, must return a string.
  return event.headers['Authorization'];
}

getTags

Type: (event, context) => String getTags is a function that takes AWS lambda event and context objects as arguments and returns a comma-separated string containing a list of tags. See Moesif documentation for full list of tags.

options.getTags = function (event, context) {
  // your code here. must return a comma-separated string.
  if (event.path.startsWith('/users') && event.httpMethod == 'GET'){
    return 'user'
  }
  return 'random_tag_1, random_tag2'
}

getApiVersion

Type: (event, context) => String getApiVersion is a function that takes AWS lambda event and context objects as arguments and returns a string to tag requests with a specific version of your API. By default, Moesif will use event.version

options.getApiVersion = function (event, context) {
  // your code here. must return a string.
  return '1.0.5'
}

skip

Type: (event, context) => Boolean skip is a function that takes AWS lambda event and context objects as arguments and returns true if the event should be skipped (i.e. not logged) The default is shown below and skips requests to the root path "/".

options.skip = function (event, context) {
  // your code here. must return a boolean.
  if (event.path === '/') {
    // Skip probes to home page.
    return true;
  }
  return false
}

maskContent

Type: MoesifEventModel => MoesifEventModel maskContent is a function that takes the final Moesif event model (rather than the AWS lambda event/context objects) as an argument before being sent to Moesif. With maskContent, you can make modifications to headers or body such as removing certain header or body fields.

options.maskContent = function(moesifEvent) {
  // remove any field that you don't want to be sent to Moesif.
  return moesifEvent;
}

updateUser method

A method is attached to the moesif middleware object to update the users profile or metadata.

'use strict'
const moesif = require('moesif-alexa-skills');

const moesifOptions = {
    applicationId: 'Your Moesif application_id',

};
var moesifMiddleware = moesif(options);
var user = {
  userId: 'your user id',  // required.
  metadata: {
    email: '[email protected]',
    name: 'George'
  }
}

moesifMiddleware.updateUser(user, callback);

The metadata field can be any custom data you want to set on the user. The userId field is required.

Other integrations

To view more more documentation on integration options, please visit the Integration Options Documentation.