Socket
Socket
Sign inDemoInstall

@squiz/component-logger-lib

Package Overview
Dependencies
Maintainers
52
Versions
325
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@squiz/component-logger-lib - npm Package Compare versions

Comparing version 1.69.0 to 1.70.0

6

CHANGELOG.md
# @squiz/component-logger-lib
## 1.70.0
### Minor Changes
- c719a29: Don't throw error if Logging API fails
## 1.69.0

@@ -4,0 +10,0 @@

11

lib/component-logger.js

@@ -75,4 +75,10 @@ "use strict";

try {
const url = `${this.config.logUrl.replace(/\/+$/, '')}/${this.config.tenantId}`;
await superagent_1.default.post(url).set('x-api-key', this.config.key).send(this.batch);
const url = `${this.config.logUrl.replace(/\/+$/, '')}`;
await superagent_1.default
.post(url)
.set({
'x-dxp-tenant': this.config.tenantId,
'x-api-key': this.config.key,
})
.send(this.batch);
this.batch = [];

@@ -82,3 +88,2 @@ }

console.error(err);
throw err;
}

@@ -85,0 +90,0 @@ }

@@ -17,3 +17,6 @@ "use strict";

jest.mock('superagent', () => ({
post: () => {
post: (url) => {
if (url === 'fail-logging-api-url') {
throw Error('logging failed');
}
return postMock;

@@ -34,2 +37,3 @@ },

});
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn());
beforeAll(() => {

@@ -40,2 +44,3 @@ jest.useFakeTimers();

afterAll(() => {
consoleErrorSpy.mockReset();
jest.useRealTimers();

@@ -82,4 +87,7 @@ });

await logger.flush();
expect(postSpy).toBeCalledWith('some-log-url/some-tenant-id');
expect(postSetSpy).toBeCalledWith('x-api-key', 'some-key');
expect(postSpy).toBeCalledWith('some-log-url');
expect(postSetSpy).toBeCalledWith({
'x-api-key': 'some-key',
'x-dxp-tenant': 'some-tenant-id',
});
});

@@ -99,3 +107,3 @@ it('should strip off extra "/" on the logUrl', async () => {

await logger.flush();
expect(postSpy).toBeCalledWith('some-log-url/some-tenant-id');
expect(postSpy).toBeCalledWith('some-log-url');
});

@@ -332,3 +340,17 @@ it('should not include "tags" in payload if tags is not configured', async () => {

});
it('should not throw error if logging API fails', async () => {
const loggerConfig = {
enabled: true,
logUrl: 'fail-logging-api-url',
key: 'some-key',
tenantId: 'some-tenant-id',
tags: 'some-tags',
serviceName: 'some-service',
};
const logger = new component_logger_1.ComponentLogger(loggerConfig);
await logger.error('some error message', '123');
await logger.flush();
expect(consoleErrorSpy).toBeCalledWith(new Error('logging failed'));
});
});
//# sourceMappingURL=component-logger.spec.js.map
{
"name": "@squiz/component-logger-lib",
"version": "1.69.0",
"version": "1.70.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -14,3 +14,6 @@ import { ComponentLogger, MAX_TAG_LENGTH } from './component-logger';

jest.mock('superagent', () => ({
post: () => {
post: (url: string) => {
if (url === 'fail-logging-api-url') {
throw Error('logging failed');
}
return postMock;

@@ -34,2 +37,4 @@ },

const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn());
beforeAll(() => {

@@ -41,2 +46,3 @@ jest.useFakeTimers();

afterAll(() => {
consoleErrorSpy.mockReset();
jest.useRealTimers();

@@ -89,4 +95,7 @@ });

expect(postSpy).toBeCalledWith('some-log-url/some-tenant-id');
expect(postSetSpy).toBeCalledWith('x-api-key', 'some-key');
expect(postSpy).toBeCalledWith('some-log-url');
expect(postSetSpy).toBeCalledWith({
'x-api-key': 'some-key',
'x-dxp-tenant': 'some-tenant-id',
});
});

@@ -110,3 +119,3 @@

expect(postSpy).toBeCalledWith('some-log-url/some-tenant-id');
expect(postSpy).toBeCalledWith('some-log-url');
});

@@ -384,2 +393,19 @@

});
it('should not throw error if logging API fails', async () => {
const loggerConfig = <ComponentLoggerConfig>{
enabled: true,
logUrl: 'fail-logging-api-url',
key: 'some-key',
tenantId: 'some-tenant-id',
tags: 'some-tags',
serviceName: 'some-service',
};
const logger = new ComponentLogger(loggerConfig);
await logger.error('some error message', '123');
await logger.flush();
expect(consoleErrorSpy).toBeCalledWith(new Error('logging failed'));
});
});

@@ -86,8 +86,13 @@ import superagent from 'superagent';

try {
const url = `${this.config.logUrl.replace(/\/+$/, '')}/${this.config.tenantId}`;
await superagent.post(url).set('x-api-key', this.config.key).send(this.batch);
const url = `${this.config.logUrl.replace(/\/+$/, '')}`;
await superagent
.post(url)
.set({
'x-dxp-tenant': this.config.tenantId,
'x-api-key': this.config.key,
})
.send(this.batch);
this.batch = [];
} catch (err) {
console.error(err);
throw err;
}

@@ -94,0 +99,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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