@unito/integration-sdk 1.0.22 → 1.0.24

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.
@@ -117,6 +117,7 @@ class Logger {
117
117
  ...this.metadata,
118
118
  ...metadata,
119
119
  message,
120
+ status: logLevel,
120
121
  });
121
122
  if (process.env.NODE_ENV === 'development') {
122
123
  console[logLevel](JSON.stringify(processedMessage, null, 2));
@@ -997,14 +998,10 @@ class Integration {
997
998
  app.use(express.json());
998
999
  // Must be one of the first handlers (to catch all the errors).
999
1000
  app.use(middleware$2);
1001
+ // Instantiate internal middlewares.
1000
1002
  app.use(middleware);
1001
1003
  app.use(middleware$a);
1002
1004
  app.use(middleware$9);
1003
- app.use(middleware$8);
1004
- app.use(middleware$6);
1005
- app.use(middleware$5);
1006
- app.use(middleware$4);
1007
- app.use(middleware$7);
1008
1005
  // Making sure we log all incoming requests (except to '/health'), prior any processing.
1009
1006
  app.use((req, res, next) => {
1010
1007
  if (req.originalUrl !== '/health') {
@@ -1012,6 +1009,13 @@ class Integration {
1012
1009
  }
1013
1010
  next();
1014
1011
  });
1012
+ // Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
1013
+ // middlewares such as the logger, the correlationId, and the error handling.
1014
+ app.use(middleware$8);
1015
+ app.use(middleware$6);
1016
+ app.use(middleware$5);
1017
+ app.use(middleware$4);
1018
+ app.use(middleware$7);
1015
1019
  // Load handlers as needed.
1016
1020
  if (this.handlers.length) {
1017
1021
  for (const handler of this.handlers) {
@@ -114,14 +114,10 @@ export default class Integration {
114
114
  app.use(express.json());
115
115
  // Must be one of the first handlers (to catch all the errors).
116
116
  app.use(finishMiddleware);
117
+ // Instantiate internal middlewares.
117
118
  app.use(requestStartTimeMiddleware);
118
119
  app.use(correlationIdMiddleware);
119
120
  app.use(loggerMiddleware);
120
- app.use(credentialsMiddleware);
121
- app.use(secretsMiddleware);
122
- app.use(filtersMiddleware);
123
- app.use(selectsMiddleware);
124
- app.use(signalMiddleware);
125
121
  // Making sure we log all incoming requests (except to '/health'), prior any processing.
126
122
  app.use((req, res, next) => {
127
123
  if (req.originalUrl !== '/health') {
@@ -129,6 +125,13 @@ export default class Integration {
129
125
  }
130
126
  next();
131
127
  });
128
+ // Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
129
+ // middlewares such as the logger, the correlationId, and the error handling.
130
+ app.use(credentialsMiddleware);
131
+ app.use(secretsMiddleware);
132
+ app.use(filtersMiddleware);
133
+ app.use(selectsMiddleware);
134
+ app.use(signalMiddleware);
132
135
  // Load handlers as needed.
133
136
  if (this.handlers.length) {
134
137
  for (const handler of this.handlers) {
@@ -89,6 +89,7 @@ export default class Logger {
89
89
  ...this.metadata,
90
90
  ...metadata,
91
91
  message,
92
+ status: logLevel,
92
93
  });
93
94
  if (process.env.NODE_ENV === 'development') {
94
95
  console[logLevel](JSON.stringify(processedMessage, null, 2));
@@ -33,35 +33,35 @@ describe('Logger', () => {
33
33
  logger.log('test');
34
34
  assert.strictEqual(logSpy.mock.calls.length, 1);
35
35
  assert.deepEqual(logSpy.mock.calls[0]?.arguments, [
36
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
36
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'log' }),
37
37
  ]);
38
38
  const errorSpy = testContext.mock.method(global.console, 'error', () => { });
39
39
  assert.strictEqual(errorSpy.mock.calls.length, 0);
40
40
  logger.error('test');
41
41
  assert.strictEqual(errorSpy.mock.calls.length, 1);
42
42
  assert.deepEqual(errorSpy.mock.calls[0]?.arguments, [
43
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
43
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'error' }),
44
44
  ]);
45
45
  const warnSpy = testContext.mock.method(global.console, 'warn', () => { });
46
46
  assert.strictEqual(warnSpy.mock.calls.length, 0);
47
47
  logger.warn('test');
48
48
  assert.strictEqual(warnSpy.mock.calls.length, 1);
49
49
  assert.deepEqual(warnSpy.mock.calls[0]?.arguments, [
50
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
50
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'warn' }),
51
51
  ]);
52
52
  const infoSpy = testContext.mock.method(global.console, 'info', () => { });
53
53
  assert.strictEqual(infoSpy.mock.calls.length, 0);
54
54
  logger.info('test');
55
55
  assert.strictEqual(infoSpy.mock.calls.length, 1);
56
56
  assert.deepEqual(infoSpy.mock.calls[0]?.arguments, [
57
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
57
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'info' }),
58
58
  ]);
59
59
  const debugSpy = testContext.mock.method(global.console, 'debug', () => { });
60
60
  assert.strictEqual(debugSpy.mock.calls.length, 0);
61
61
  logger.debug('test');
62
62
  assert.strictEqual(debugSpy.mock.calls.length, 1);
63
63
  assert.deepEqual(debugSpy.mock.calls[0]?.arguments, [
64
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
64
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'debug' }),
65
65
  ]);
66
66
  });
67
67
  it('merges message payload with metadata', testContext => {
@@ -77,6 +77,7 @@ describe('Logger', () => {
77
77
  http: { method: 'GET' },
78
78
  error: { code: '200', message: 'Page Not Found' },
79
79
  message: 'test',
80
+ status: 'log',
80
81
  }),
81
82
  ]);
82
83
  });
@@ -92,6 +93,7 @@ describe('Logger', () => {
92
93
  correlation_id: '123456789',
93
94
  http: { status_code: 200 },
94
95
  message: 'test',
96
+ status: 'log',
95
97
  }),
96
98
  ]);
97
99
  });
@@ -108,6 +110,7 @@ describe('Logger', () => {
108
110
  http: { method: 'GET', status_code: 200 },
109
111
  error_context: { error_code: 200, error_message: 'Page Not Found' },
110
112
  message: 'test',
113
+ status: 'log',
111
114
  }),
112
115
  ]);
113
116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -130,14 +130,10 @@ export default class Integration {
130
130
  // Must be one of the first handlers (to catch all the errors).
131
131
  app.use(finishMiddleware);
132
132
 
133
+ // Instantiate internal middlewares.
133
134
  app.use(requestStartTimeMiddleware);
134
135
  app.use(correlationIdMiddleware);
135
136
  app.use(loggerMiddleware);
136
- app.use(credentialsMiddleware);
137
- app.use(secretsMiddleware);
138
- app.use(filtersMiddleware);
139
- app.use(selectsMiddleware);
140
- app.use(signalMiddleware);
141
137
 
142
138
  // Making sure we log all incoming requests (except to '/health'), prior any processing.
143
139
  app.use((req, res, next) => {
@@ -147,6 +143,14 @@ export default class Integration {
147
143
  next();
148
144
  });
149
145
 
146
+ // Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
147
+ // middlewares such as the logger, the correlationId, and the error handling.
148
+ app.use(credentialsMiddleware);
149
+ app.use(secretsMiddleware);
150
+ app.use(filtersMiddleware);
151
+ app.use(selectsMiddleware);
152
+ app.use(signalMiddleware);
153
+
150
154
  // Load handlers as needed.
151
155
  if (this.handlers.length) {
152
156
  for (const handler of this.handlers) {
@@ -111,6 +111,7 @@ export default class Logger {
111
111
  ...this.metadata,
112
112
  ...metadata,
113
113
  message,
114
+ status: logLevel,
114
115
  });
115
116
 
116
117
  if (process.env.NODE_ENV === 'development') {
@@ -42,7 +42,7 @@ describe('Logger', () => {
42
42
  logger.log('test');
43
43
  assert.strictEqual(logSpy.mock.calls.length, 1);
44
44
  assert.deepEqual(logSpy.mock.calls[0]?.arguments, [
45
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
45
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'log' }),
46
46
  ]);
47
47
 
48
48
  const errorSpy = testContext.mock.method(global.console, 'error', () => {});
@@ -50,7 +50,7 @@ describe('Logger', () => {
50
50
  logger.error('test');
51
51
  assert.strictEqual(errorSpy.mock.calls.length, 1);
52
52
  assert.deepEqual(errorSpy.mock.calls[0]?.arguments, [
53
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
53
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'error' }),
54
54
  ]);
55
55
 
56
56
  const warnSpy = testContext.mock.method(global.console, 'warn', () => {});
@@ -58,7 +58,7 @@ describe('Logger', () => {
58
58
  logger.warn('test');
59
59
  assert.strictEqual(warnSpy.mock.calls.length, 1);
60
60
  assert.deepEqual(warnSpy.mock.calls[0]?.arguments, [
61
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
61
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'warn' }),
62
62
  ]);
63
63
 
64
64
  const infoSpy = testContext.mock.method(global.console, 'info', () => {});
@@ -66,7 +66,7 @@ describe('Logger', () => {
66
66
  logger.info('test');
67
67
  assert.strictEqual(infoSpy.mock.calls.length, 1);
68
68
  assert.deepEqual(infoSpy.mock.calls[0]?.arguments, [
69
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
69
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'info' }),
70
70
  ]);
71
71
 
72
72
  const debugSpy = testContext.mock.method(global.console, 'debug', () => {});
@@ -74,7 +74,7 @@ describe('Logger', () => {
74
74
  logger.debug('test');
75
75
  assert.strictEqual(debugSpy.mock.calls.length, 1);
76
76
  assert.deepEqual(debugSpy.mock.calls[0]?.arguments, [
77
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
77
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'debug' }),
78
78
  ]);
79
79
  });
80
80
 
@@ -92,6 +92,7 @@ describe('Logger', () => {
92
92
  http: { method: 'GET' },
93
93
  error: { code: '200', message: 'Page Not Found' },
94
94
  message: 'test',
95
+ status: 'log',
95
96
  }),
96
97
  ]);
97
98
  });
@@ -109,6 +110,7 @@ describe('Logger', () => {
109
110
  correlation_id: '123456789',
110
111
  http: { status_code: 200 },
111
112
  message: 'test',
113
+ status: 'log',
112
114
  }),
113
115
  ]);
114
116
  });
@@ -127,6 +129,7 @@ describe('Logger', () => {
127
129
  http: { method: 'GET', status_code: 200 },
128
130
  error_context: { error_code: 200, error_message: 'Page Not Found' },
129
131
  message: 'test',
132
+ status: 'log',
130
133
  }),
131
134
  ]);
132
135
  });