@unito/integration-sdk 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,8 +67,10 @@ const LOGMETA_BLACKLIST = [
67
67
  * Logger class that can be configured with metadata add creation and when logging to add additional context to your logs.
68
68
  */
69
69
  class Logger {
70
+ isDisabled;
70
71
  metadata;
71
- constructor(metadata = {}) {
72
+ constructor(metadata = {}, isDisabled = false) {
73
+ this.isDisabled = isDisabled;
72
74
  this.metadata = structuredClone(metadata);
73
75
  }
74
76
  /**
@@ -142,6 +144,9 @@ class Logger {
142
144
  this.metadata = {};
143
145
  }
144
146
  send(logLevel, message, metadata) {
147
+ if (this.isDisabled) {
148
+ return;
149
+ }
145
150
  // We need to provide the date to Datadog. Otherwise, the date is set to when they receive the log.
146
151
  const date = Date.now();
147
152
  if (message.length > MAX_LOG_MESSAGE_SIZE) {
@@ -188,6 +193,7 @@ class Logger {
188
193
  return prunedMetadata;
189
194
  }
190
195
  }
196
+ const NULL_LOGGER = new Logger({}, true);
191
197
 
192
198
  /**
193
199
  * The Cache class provides caching capabilities that can be used across your integration.
@@ -1511,5 +1517,6 @@ exports.Cache = Cache;
1511
1517
  exports.Handler = Handler;
1512
1518
  exports.HttpErrors = httpErrors;
1513
1519
  exports.Integration = Integration;
1520
+ exports.NULL_LOGGER = NULL_LOGGER;
1514
1521
  exports.Provider = Provider;
1515
1522
  exports.getApplicableFilters = getApplicableFilters;
@@ -9,4 +9,4 @@ export type { Filter } from './middlewares/filters.js';
9
9
  export * as HttpErrors from './httpErrors.js';
10
10
  export { getApplicableFilters } from './helpers.js';
11
11
  export * from './resources/context.js';
12
- export { type default as Logger } from './resources/logger.js';
12
+ export { type default as Logger, NULL_LOGGER } from './resources/logger.js';
package/dist/src/index.js CHANGED
@@ -7,4 +7,5 @@ export { Provider, } from './resources/provider.js';
7
7
  export * as HttpErrors from './httpErrors.js';
8
8
  export { getApplicableFilters } from './helpers.js';
9
9
  export * from './resources/context.js';
10
+ export { NULL_LOGGER } from './resources/logger.js';
10
11
  /* c8 ignore stop */
@@ -10,8 +10,9 @@ type ForbidenMetadataKey = 'message';
10
10
  * Logger class that can be configured with metadata add creation and when logging to add additional context to your logs.
11
11
  */
12
12
  export default class Logger {
13
+ private isDisabled;
13
14
  private metadata;
14
- constructor(metadata?: Metadata);
15
+ constructor(metadata?: Metadata, isDisabled?: boolean);
15
16
  /**
16
17
  * Logs a message with the 'log' log level.
17
18
  * @param message The message to be logged.
@@ -68,4 +69,5 @@ export default class Logger {
68
69
  private static snakifyKeys;
69
70
  private static pruneSensitiveMetadata;
70
71
  }
72
+ export declare const NULL_LOGGER: Logger;
71
73
  export {};
@@ -39,8 +39,10 @@ const LOGMETA_BLACKLIST = [
39
39
  * Logger class that can be configured with metadata add creation and when logging to add additional context to your logs.
40
40
  */
41
41
  export default class Logger {
42
+ isDisabled;
42
43
  metadata;
43
- constructor(metadata = {}) {
44
+ constructor(metadata = {}, isDisabled = false) {
45
+ this.isDisabled = isDisabled;
44
46
  this.metadata = structuredClone(metadata);
45
47
  }
46
48
  /**
@@ -114,6 +116,9 @@ export default class Logger {
114
116
  this.metadata = {};
115
117
  }
116
118
  send(logLevel, message, metadata) {
119
+ if (this.isDisabled) {
120
+ return;
121
+ }
117
122
  // We need to provide the date to Datadog. Otherwise, the date is set to when they receive the log.
118
123
  const date = Date.now();
119
124
  if (message.length > MAX_LOG_MESSAGE_SIZE) {
@@ -160,3 +165,4 @@ export default class Logger {
160
165
  return prunedMetadata;
161
166
  }
162
167
  }
168
+ export const NULL_LOGGER = new Logger({}, true);
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { describe, it } from 'node:test';
3
- import { default as Logger } from '../../src/resources/logger.js';
3
+ import { default as Logger, NULL_LOGGER } from '../../src/resources/logger.js';
4
4
  describe('Logger', () => {
5
5
  it('metadata', () => {
6
6
  let metadata = { correlation_id: 'test' };
@@ -140,4 +140,22 @@ describe('Logger', () => {
140
140
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200, jwt: '[REDACTED]' });
141
141
  assert.deepEqual(actual['user']['contact'], { email: '[REDACTED]', first_name: '[REDACTED]' });
142
142
  });
143
+ it(`NULL_LOGGER should not log`, testContext => {
144
+ const logger = NULL_LOGGER;
145
+ const logSpy = testContext.mock.method(global.console, 'log', () => { });
146
+ const errorSpy = testContext.mock.method(global.console, 'error', () => { });
147
+ const warnSpy = testContext.mock.method(global.console, 'warn', () => { });
148
+ const infoSpy = testContext.mock.method(global.console, 'info', () => { });
149
+ const debugSpy = testContext.mock.method(global.console, 'debug', () => { });
150
+ logger.log('test');
151
+ logger.info('test');
152
+ logger.warn('test');
153
+ logger.error('test');
154
+ logger.debug('test');
155
+ assert.strictEqual(logSpy.mock.calls.length, 0);
156
+ assert.strictEqual(errorSpy.mock.calls.length, 0);
157
+ assert.strictEqual(warnSpy.mock.calls.length, 0);
158
+ assert.strictEqual(infoSpy.mock.calls.length, 0);
159
+ assert.strictEqual(debugSpy.mock.calls.length, 0);
160
+ });
143
161
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
package/src/index.ts CHANGED
@@ -15,5 +15,5 @@ export type { Filter } from './middlewares/filters.js';
15
15
  export * as HttpErrors from './httpErrors.js';
16
16
  export { getApplicableFilters } from './helpers.js';
17
17
  export * from './resources/context.js';
18
- export { type default as Logger } from './resources/logger.js';
18
+ export { type default as Logger, NULL_LOGGER } from './resources/logger.js';
19
19
  /* c8 ignore stop */
@@ -50,8 +50,10 @@ const LOGMETA_BLACKLIST = [
50
50
  */
51
51
  export default class Logger {
52
52
  private metadata: Metadata;
53
-
54
- constructor(metadata: Metadata = {}) {
53
+ constructor(
54
+ metadata: Metadata = {},
55
+ private isDisabled: boolean = false,
56
+ ) {
55
57
  this.metadata = structuredClone(metadata);
56
58
  }
57
59
 
@@ -138,6 +140,10 @@ export default class Logger {
138
140
  }
139
141
 
140
142
  private send(logLevel: LogLevel, message: string, metadata?: Metadata): void {
143
+ if (this.isDisabled) {
144
+ return;
145
+ }
146
+
141
147
  // We need to provide the date to Datadog. Otherwise, the date is set to when they receive the log.
142
148
  const date = Date.now();
143
149
 
@@ -191,3 +197,5 @@ export default class Logger {
191
197
  return prunedMetadata;
192
198
  }
193
199
  }
200
+
201
+ export const NULL_LOGGER = new Logger({}, true);
@@ -1,6 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { describe, it } from 'node:test';
3
- import { default as Logger, Metadata } from '../../src/resources/logger.js';
3
+ import { default as Logger, Metadata, NULL_LOGGER } from '../../src/resources/logger.js';
4
4
 
5
5
  describe('Logger', () => {
6
6
  it('metadata', () => {
@@ -168,4 +168,26 @@ describe('Logger', () => {
168
168
  assert.deepEqual(actual['http'], { method: 'GET', status_code: 200, jwt: '[REDACTED]' });
169
169
  assert.deepEqual(actual['user']['contact'], { email: '[REDACTED]', first_name: '[REDACTED]' });
170
170
  });
171
+
172
+ it(`NULL_LOGGER should not log`, testContext => {
173
+ const logger = NULL_LOGGER;
174
+
175
+ const logSpy = testContext.mock.method(global.console, 'log', () => {});
176
+ const errorSpy = testContext.mock.method(global.console, 'error', () => {});
177
+ const warnSpy = testContext.mock.method(global.console, 'warn', () => {});
178
+ const infoSpy = testContext.mock.method(global.console, 'info', () => {});
179
+ const debugSpy = testContext.mock.method(global.console, 'debug', () => {});
180
+
181
+ logger.log('test');
182
+ logger.info('test');
183
+ logger.warn('test');
184
+ logger.error('test');
185
+ logger.debug('test');
186
+
187
+ assert.strictEqual(logSpy.mock.calls.length, 0);
188
+ assert.strictEqual(errorSpy.mock.calls.length, 0);
189
+ assert.strictEqual(warnSpy.mock.calls.length, 0);
190
+ assert.strictEqual(infoSpy.mock.calls.length, 0);
191
+ assert.strictEqual(debugSpy.mock.calls.length, 0);
192
+ });
171
193
  });