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 5.0.3 to 5.0.4

lib/log-validator.js

37

lib/firehose-instance.js

@@ -20,2 +20,5 @@ /* eslint-disable max-len */

/**
* @private
*/
get batchSize() {

@@ -31,2 +34,5 @@ return {

/**
* @private
*/
get logRoleArn() {

@@ -36,2 +42,5 @@ return process.env.TRACE_LOG_ROLE_ARN;

/**
* @private
*/
get deliveryStreamName() {

@@ -41,2 +50,5 @@ return process.env.TRACE_FIREHOSE_DELIVERY_STREAM;

/**
* @private
*/
get roleSessionName() {

@@ -47,5 +59,5 @@ return `role-session-${process.env.JANIS_SERVICE_NAME}`;

/**
* Set Instance of Firehose Wrapper when is not set
*
*/
* Set Instance of Firehose Wrapper when is not set
* @private
*/
async ensureFirehoseInstance() {

@@ -69,2 +81,5 @@

/**
* @private
*/
validCredentials() {

@@ -76,2 +91,5 @@ return firehoseInstance

/**
* @private
*/
async getCredentials() {

@@ -99,3 +117,3 @@

/**
* @param {Array<Array<LogData>>} logs
* @param {LogData[]} logs
* @returns

@@ -114,2 +132,6 @@ */

/**
* @type {LogData[]}
* @private
*/
this.recordsToPut = logs;

@@ -120,2 +142,5 @@

/**
* @private
*/
async put(retry = 1) {

@@ -145,2 +170,6 @@

/**
* @param {LogData[]} records
* @private
*/
async putRecordBatch(records) {

@@ -147,0 +176,0 @@

7

lib/helpers/utils.js

@@ -15,3 +15,3 @@ /* eslint-disable no-restricted-syntax */

Object.keys(log).forEach(key => {
object[key] = fields.includes(key)
object[key] = fields[key]
? '***' // Save redacted property

@@ -34,3 +34,6 @@ : hideFieldsFromLog(log[key], fields);

return process.env.JANIS_TRACE_PRIVATE_FIELDS.split(',').map(field => field.trim());
return process.env.JANIS_TRACE_PRIVATE_FIELDS.split(',').reduce((accum, field) => {
accum[field.trim()] = true;
return accum;
}, {});
};

@@ -37,0 +40,0 @@

@@ -25,13 +25,8 @@ 'use strict';

const { ApiSession } = require('@janiscommerce/api-session');
const { default: axios } = require('axios');
const { ApiSession } = require('@janiscommerce/api-session');
const { struct } = require('@janiscommerce/superstruct');
const crypto = require('crypto');
const logger = require('lllog')();
const logStruct = require('./log-struct');
const logValidator = require('./log-validator');

@@ -63,3 +58,7 @@ const LogError = require('./log-error');

static shouldAddLogs() {
return ['beta', 'qa', 'prod'].includes(getEnv());
return {
beta: true,
qa: true,
prod: true
}[getEnv()];
}

@@ -94,11 +93,6 @@

logs = logs.map(log => ({
...log,
client: log.client || client
}));
if(process.env.JANIS_TRACE_EXTENSION_ENABLED)
return this.addLogsLocally(logs);
return this.addLogsLocally(logs, client);
return this.sendToTrace(logs);
return this.sendToTrace(logs, client);
}

@@ -112,5 +106,5 @@

*/
static async sendToTrace(logs) {
static async sendToTrace(logs, client) {
logs = this.getValidatedLogs(logs);
logs = this.getValidatedLogs(logs, client);

@@ -128,3 +122,3 @@ if(!logs.length)

static async addLogsLocally(logs) {
static async addLogsLocally(logs, client) {

@@ -135,3 +129,3 @@ const MAX_LOGS_PER_BATCH = 100;

const formattedLogs = this.getValidatedLogs(logs.slice(offset, offset + MAX_LOGS_PER_BATCH));
const formattedLogs = this.getValidatedLogs(logs.slice(offset, offset + MAX_LOGS_PER_BATCH), client);

@@ -155,8 +149,10 @@ try {

static getValidatedLogs(logs) {
static getValidatedLogs(logs, client) {
const privateFields = getTracePrivateFields();
return logs.map(log => {
try {
return this.format(this.validate(log));
return this.format(this.validate(log, client), privateFields);
} catch(err) {

@@ -170,22 +166,25 @@ logger.error('Validation Error while creating Trace logs', err);

static validate(log) {
static validate(log, client) {
try {
if(log.dateCreated && typeof log.dateCreated === 'string')
log.dateCreated = new Date(log.dateCreated);
if(log.dateCreated && log.dateCreated instanceof Date)
log.dateCreated = log.dateCreated.toISOString();
if(!log.id)
log.id = crypto.randomUUID();
const Struct = struct.partial(logStruct, {
id: crypto.randomUUID(),
service: this.serviceName
});
if(!log.service)
log.service = this.serviceName;
return Struct(log);
if(!log.client)
log.client = client;
} catch(err) {
throw new LogError(err.message, LogError.codes.INVALID_LOG);
}
const result = logValidator(log);
if(result !== true)
throw new LogError(result[0].message, LogError.codes.INVALID_LOG);
return log;
}
static format({ log = {}, userCreated, dateCreated, ...restOfLog }) {
static format({ log = {}, userCreated, dateCreated, ...restOfLog }, privateFields) {

@@ -198,20 +197,20 @@ if(typeof log === 'string')

if(getTracePrivateFields())
log = hideFieldsFromLog(log, getTracePrivateFields());
if(privateFields)
log = hideFieldsFromLog(log, privateFields);
const functionName = process.env.JANIS_FUNCTION_NAME;
const apiRequestLogId = process.env.JANIS_API_REQUEST_LOG_ID;
if(!log.functionName && process.env.JANIS_FUNCTION_NAME)
log.functionName = process.env.JANIS_FUNCTION_NAME;
log = {
...functionName && { functionName },
...apiRequestLogId && { apiRequestLogId },
...log
};
if(!log.apiRequestLogId && process.env.JANIS_API_REQUEST_LOG_ID)
log.apiRequestLogId = process.env.JANIS_API_REQUEST_LOG_ID;
return {
...restOfLog,
...Object.keys(log).length && { log: JSON.stringify(log) },
...userCreated !== null && { userCreated },
dateCreated: dateCreated || new Date().toISOString()
};
if(Object.keys(log).length)
restOfLog.log = JSON.stringify(log);
if(userCreated)
restOfLog.userCreated = userCreated;
restOfLog.dateCreated = (dateCreated || new Date()).toISOString();
return restOfLog;
}

@@ -218,0 +217,0 @@

{
"name": "@janiscommerce/log",
"version": "5.0.3",
"version": "5.0.4",
"description": "A package for creating logs in Janis Trace Service",

@@ -45,6 +45,6 @@ "main": "lib/log.js",

"@janiscommerce/api-session": "^3.3.1",
"@janiscommerce/superstruct": "^1.2.1",
"axios": "^0.27.2",
"fastest-validator": "^1.17.0",
"lllog": "^1.1.2"
}
}
export = FirehoseInstance;
declare class FirehoseInstance {
get batchSize(): {
1: number;
2: number;
3: number;
4: number;
5: number;
};
get logRoleArn(): string;
get deliveryStreamName(): string;
get roleSessionName(): string;
/**
* @private
*/
private get batchSize();
/**
* @private
*/
private get logRoleArn();
/**
* @private
*/
private get deliveryStreamName();
/**
* @private
*/
private get roleSessionName();
/**
* Set Instance of Firehose Wrapper when is not set
*
* @private
*/
ensureFirehoseInstance(): Promise<void>;
validCredentials(): boolean;
getCredentials(): Promise<{
accessKeyId: string;
secretAccessKey: string;
sessionToken: string;
expiration: any;
}>;
private ensureFirehoseInstance;
/**
* @param {Array<Array<LogData>>} logs
* @private
*/
private validCredentials;
/**
* @private
*/
private getCredentials;
/**
* @param {LogData[]} logs
* @returns
*/
putRecords(logs: Array<Array<LogData>>): Promise<any>;
recordsToPut: any;
put(retry?: number): any;
putRecordBatch(records: any): Promise<any>;
putRecords(logs: LogData[]): Promise<any>;
/**
* @type {LogData[]}
* @private
*/
private recordsToPut;
/**
* @private
*/
private put;
/**
* @param {LogData[]} records
* @private
*/
private putRecordBatch;
}
export function getEnv(): string;
export function getTracePrivateFields(): string[];
export function getTracePrivateFields(): {};
export function hideFieldsFromLog(log: any, fields: any): any;

@@ -11,3 +11,3 @@ export = Log;

static get serviceName(): string;
static shouldAddLogs(): boolean;
static shouldAddLogs(): any;
/**

@@ -39,7 +39,7 @@ * Send logs to Local extension server or Firehose, based on JANIS_TRACE_EXTENSION_ENABLED env var

*/
static sendToTrace(logs: LogData[]): Promise<any>;
static sendToTrace(logs: LogData[], client: any): Promise<any>;
static putFirehoseRecords(formattedLogs: any): Promise<any>;
static addLogsLocally(logs: any): Promise<void>;
static getValidatedLogs(logs: any): any;
static validate(log: any): any;
static addLogsLocally(logs: any, client: any): Promise<void>;
static getValidatedLogs(logs: any, client: any): any;
static validate(log: any, client: any): any;
static format({ log, userCreated, dateCreated, ...restOfLog }: {

@@ -50,6 +50,4 @@ [x: string]: any;

dateCreated: any;
}): {
dateCreated: any;
userCreated: any;
log: string;
}, privateFields: any): {
[x: string]: any;
};

@@ -56,0 +54,0 @@ /**

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