Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@janiscommerce/log

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@janiscommerce/log - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

lib/firehose-instance.js

10

CHANGELOG.md

@@ -10,2 +10,10 @@ # Changelog

## [3.3.0] - 2020-07-29
### Added
- serverlessConfiguration getter to easily get sls hooks.
- FirehoseInstance to cache the instance
### Changed
- Upgraded sinon, nyc and eslint devDependencies
## [3.2.0] - 2020-05-19

@@ -17,3 +25,3 @@ ### Removed

### Fixed
- Unit tests improoves
- Unit tests improoves
- Errors that was not handled correctly

@@ -20,0 +28,0 @@

69

lib/log.js
'use strict';
const EventEmmiter = require('events');
const { STS, Firehose } = require('./aws-wrappers');
const { arrayChunk } = require('./helpers/utils');
const Validator = require('./helpers/validator');
const LogError = require('./log-error');
const serverlessConfiguration = require('./serverless-configuration');
const FirehoseInstance = require('./firehose-instance');
const ARN_DURATION = 1800; // 30 min
const MAX_ATTEMPTS = 3;
const MAX_TIMEOUT = 500;
const DELIVERY_STREAM_PREFIX = 'JanisTraceFirehose';
const LOGS_BATCH_LIMIT = 500;
const sts = new STS();

@@ -31,6 +28,2 @@ const emitter = new EventEmmiter();

static get roleArn() {
return process.env.LOG_ROLE_ARN;
}
static get envs() {

@@ -123,3 +116,3 @@

const firehose = await this.getFirehoseInstance();
const firehose = await FirehoseInstance.getFirehoseInstance();

@@ -150,50 +143,14 @@ await Promise.all(

static async getFirehoseInstance() {
if(!this.validCredentials()) {
const firehoseParams = {
region: process.env.AWS_DEFAULT_REGION,
httpOptions: { timeout: MAX_TIMEOUT }
};
if(this.roleArn) {
firehoseParams.credentials = await this.getCredentials();
this.credentialsExpiration = new Date(firehoseParams.credentials.expiration);
}
this.firehose = new Firehose(firehoseParams);
}
return this.firehose;
/**
* Returns the sls helpers needed for serverles configuration.
*
* @readonly
* @static
* @memberof Log
*/
static get serverlessConfiguration() {
return serverlessConfiguration();
}
static validCredentials() {
return this.firehose
&& this.credentialsExpiration
&& this.credentialsExpiration >= new Date();
}
static async getCredentials() {
const assumedRole = await sts.assumeRole({
RoleArn: this.roleArn,
RoleSessionName: this.serviceName,
DurationSeconds: ARN_DURATION
});
if(!assumedRole)
throw new LogError('Failed to assume role, invalid response.', LogError.codes.ASSUME_ROLE_ERROR);
const { Credentials, Expiration } = assumedRole;
return {
accessKeyId: Credentials.AccessKeyId,
secretAccessKey: Credentials.SecretAccessKey,
sessionToken: Credentials.SessionToken,
expiration: Expiration
};
}
}
module.exports = Log;
{
"name": "@janiscommerce/log",
"version": "3.2.0",
"version": "3.3.0",
"description": "A package for creating logs in Firehose",

@@ -21,3 +21,3 @@ "main": "lib/log.js",

"devDependencies": {
"eslint": "^6.8.0",
"eslint": "^7.5.0",
"eslint-config-airbnb-base": "^13.1.0",

@@ -28,4 +28,4 @@ "eslint-plugin-import": "^2.20.2",

"mocha": "^7.1.1",
"nyc": "^15.0.1",
"sinon": "^7.3.2"
"nyc": "^15.1.0",
"sinon": "^9.0.2"
},

@@ -39,2 +39,3 @@ "files": [

"dependencies": {
"@janiscommerce/settings": "^1.0.1",
"@janiscommerce/superstruct": "^1.1.1",

@@ -41,0 +42,0 @@ "aws-sdk": "^2.498.0",

@@ -15,3 +15,3 @@ # log

### ENV variables
**`JANIS_SERVICE_NAME`** (required): The name of the service that will create the log.
**`JANIS_SERVICE_NAME`** (required): The name of the service that will create the log.
**`JANIS_ENV`** (required): The stage name that will used as prefix for trace firehose delivery stream.

@@ -21,4 +21,4 @@ **`LOG_ROLE_ARN`** (required): The ARN to assume the trace role in order to put records in Firehose.

## API
### **`add(clientCode, logs)`**
Parameters: `clientCode [String]`, `logs [Object] or [Object array]`
### **`add(clientCode, logs)`**
Parameters: `clientCode [String]`, `logs [Object] or [Object array]`
Puts the recieved log or logs into the janis-trace-firehose

@@ -58,3 +58,3 @@

### **`on(event, callback)`**
### **`on(event, callback)`**
Parameters: `event [String]`, `callback [Function]`

@@ -65,5 +65,5 @@ Calls a callback when the specified event is emitted.

The errors are informed with a `LogError`.
This object has a code that can be useful for a correct error handling.
The codes are the following:
The errors are informed with a `LogError`.
This object has a code that can be useful for a correct error handling.
The codes are the following:

@@ -155,2 +155,23 @@ | Code | Description |

console.error(`An error occurred while creating the log ${err.message}`);
});
});
```
### Serverless configuration
Returns an array with the hooks needed for Log's serverless configuration according to [Serverless Helper](https://www.npmjs.com/package/sls-helper-plugin-janis). In `path/to/root/serverless.js` add:
```js
'use strict';
const { helper } = require('sls-helper'); // eslint-disable-line
const functions = require('./serverless/functions.json');
const Log = require('@janiscommerce/log');
module.exports = helper({
hooks: [
// other hooks
...functions,
...Log.serverlessConfiguration
]
});
```
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