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

@reddotpay/rdp2.0-auditlog

v1.2.2

Published

Audit logger for RDP2.0 products

Downloads

28

Readme

RDP2.0-Auditlog

npm (scoped)

Audit log npm package for RDP2.0 products

Install

  1. npm install @reddotpay/rdp2.0-auditlog dotenv
  2. npm install aws-sdk --save-dev
  3. refer to Sample Environment File for environment variables
Sample Environment File
ENVIRONMENT=development | staging | production
DISPLAY_AUDITLOG=true (To toggle auditlog in local)
CONSOLE_LOG=true (To toggle console log for unit testing)

Requirements

AWS Role can refer to Policy below.

Policy
BackendFunctionRole
	Type: AWS::IAM::Role
	Properties:
		AssumeRolePolicyDocument:
		Version: '2012-10-17'
		Statement:
		-
			Effect: Allow
			Action:
			- 'sts:AssumeRole'
			Principal:
				Service:
				- lambda.amazonaws.com

		Policies:
		-
			PolicyName: {Product}BackendFunctionRole
			PolicyDocument:
				Version: '2012-10-17'
				Statement:
				-
					Effect: Allow
					Action:
					- 'logs:*'
					Resource: '*'

Usage

Primary Function

/*
    DATA TYPE
    summmary {string} - description of log / error
    variable {any} - the variable to log
    error {object} - error object return in catch block
    event {object} - lambda event
    response {object} - response that is return to frontend
*/

Function 1: rdp.log(summary, variable); - equivalent to console.log
Function 2: rdp.error(summary, error); - equivalent to console.error
Function 3: await rdp.audit(event, response); - only called once before return response
Example
// index.js

const rdp = require('@reddotpay/rdp2.0-auditlog');

exports.handler = (event) => {
    /*
        All the Lambda Routes
    */
    const product = 'Product Name';

    // use one of the below
    rdp.audit(event, response); <==== fn 3
    rdp.auditRdp2(product, event, response); <==== for RDP 2 calls through API gateway
    rdp.auditRdp2Lambda(product, event, response); <==== for RDP 2 direct lambda invocation

    return response;
}
// models/test.js

const axios = require('axios');
const rdp = require('@reddotpay/rdp2.0-auditlog');

class test {
    async get(input) {
        try {
            rdp.log('test get route>>', input); <==== fn 1
            ...
        } catch (e) {
            rdp.error('test get route error>>', e); <==== fn 2
            ...
        }

        return;
    }

    async post(input) {
        try {
            rdp.log('test get route>>', input); <==== fn 1
            ...
        } catch (e) {
            rdp.error('test get route error>>', e); <==== fn 2
            ...
        }

        return;
    }
}
Response
{
  product: 'productName',
  summary: `${httpMethod} ${path}`,
  type: 'info || error'
  createdAt: new Date().toUTCString(),
  sortDate: new Date().toJSON(),
  user: {
    companyId: requestContext.authorizer.companyid,
    groupId: requestContext.authorizer.groupid,
    userId: requestContext.authorizer.uuid,
    username: requestContext.authorizer.username,
  },
  traceId: 'X-Amzn-Trace-Id',
  stacktraceArray: [
    // list of logs in chronological order
  ],
  request: {
    headers,
    queryStringParameters,
    body,
  },
  response: {
    // return response
  },
}

Masking Function

rdp.maskReturnDefault();
rdp.maskEmail(email);
rdp.maskCard(cardNumber);
rdp.maskString(string);
rdp.maskObject(object);
Example
const maskReturnDefault = rdp.maskReturnDefault();
// ****************
remarks: default is always 16 asterisk

const maskedEmail = rdp.maskEmail('[email protected]');
// use*****@domain.com

const maskedCard = rdp.maskCard('1111222233334444');
// 111122******4444

const maskedString = rdp.maskString('teststring');
// **********

const maskedObject = rdp.maskObject({
    key1: "value1",
    key2: [1, 2, 3],
    key3: {
        nestedKey1: "nestedValue1",
        nestedKey2: "nestedValue2",
    },
});
/*
{
    key1: ****************,
    key2: ****************,
    key3: ****************,
}
*/