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

@serverless/sdk

Package Overview
Dependencies
Maintainers
6
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serverless/sdk - npm Package Compare versions

Comparing version 0.5.10 to 0.5.11

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

### [0.5.11](https://github.com/serverless/console/compare/@serverless/sdk@0.5.10...@serverless/sdk@0.5.11) (2023-04-21)
### Bug Fixes
- Ensure to report unexpected parsing issues ([0864381](https://github.com/serverless/console/commit/0864381355f42e1acb52247c97dd3054a9deba98))
### Maintenance Improvements
- Optimise JSON string detection ([f38b906](https://github.com/serverless/console/commit/f38b90631f2c15c1e230ede7b049fed76dfd2b67))
- Optimize error data detection ([45c4a65](https://github.com/serverless/console/commit/45c4a6593e445aa6cd370fe2741f63f7f2c8ed7d))
- Remove obsolete debug log ([3034aa7](https://github.com/serverless/console/commit/3034aa7c5750c80a881f159bdcba8294a2f3a846))
### [0.5.10](https://github.com/serverless/console/compare/@serverless/sdk@0.5.9...@serverless/sdk@0.5.10) (2023-04-20)

@@ -7,0 +19,0 @@

57

lib/structured-log-to-event.js
'use strict';
const isObject = require('type/object/is');
const { debuglog } = require('util');
const createErrorCapturedEvent = require('./create-error-captured-event');
const createWarningCapturedEvent = require('./create-warning-captured-event');
const reportError = require('./report-error');
const safeJsonParse = (logLine) => {
try {
return JSON.parse(logLine);
} catch {
return null;
}
};
const supportedLevels = new Set(['WARN', 'ERROR']);
const parseLogLevel = (level) => {
if (typeof level === 'string') {
const levelUpperCase = level.toUpperCase();
if (levelUpperCase !== 'ERROR' && levelUpperCase !== 'WARN') {
throw new Error('Unsupported level');
}
return levelUpperCase;
if (supportedLevels.has(levelUpperCase)) return levelUpperCase;
} else if (typeof level === 'number') {
if (level <= 30) {
throw new Error('Unsupported level');
}
if (level <= 40) {
return 'WARN';
}
return 'ERROR';
if (level <= 30) return null;
if (level <= 40) return 'WARN';
if (level > 40) return 'ERROR';
}
throw new Error('Unsupported level');
return null;
};

@@ -82,3 +83,3 @@

const [errKey, errObj] = Object.entries(logLineParsed).find(
([, value]) => isObject(value) && 'message' in value && 'stack' in value
([, value]) => value && value.message && value.stack
);

@@ -122,15 +123,21 @@

try {
const logLineParsed = JSON.parse(logLine.toString());
if ('level' in logLineParsed) {
debuglog('LOG LEVEL', logLineParsed.level);
const logLevel = parseLogLevel(logLineParsed.level);
if (logLevel === 'ERROR') {
if (typeof logLine !== 'string') return;
if (logLine[0] !== '{') return;
const logLineParsed = safeJsonParse(logLine);
if (!logLineParsed) return;
if (!logLineParsed.level) return;
const logLevel = parseLogLevel(logLineParsed.level);
switch (logLevel) {
case 'ERROR':
handleErrorLog(logLineParsed);
} else if (logLevel === 'WARN') {
return;
case 'WARN':
handleWarningLog(logLineParsed);
}
return;
default:
throw new Error(`Unsupported log level: ${logLevel}`);
}
} catch (err) {
// Not a structured logline
} catch (error) {
reportError(error);
}
};
{
"name": "@serverless/sdk",
"repository": "serverless/console",
"version": "0.5.10",
"version": "0.5.11",
"author": "Serverless, Inc.",

@@ -6,0 +6,0 @@ "dependencies": {

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