@unito/integration-cli 0.55.1 → 0.55.4

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.
package/README.md CHANGED
@@ -27,6 +27,6 @@ COMMANDS
27
27
 
28
28
  ## Terms and Conditions
29
29
 
30
- By using the Integration Debugger, you agree to be bound by our terms and conditions.
30
+ By using the Integration CLI, you agree to be bound by our terms and conditions.
31
31
  Please ensure you have read and understood the Unito Software Development Kit Agreement before using the API.
32
32
  The full agreement can be found at [Unito SDK Agreement](https://unito.io/sdk-agreement/).
@@ -4,6 +4,7 @@ import { Error as APIError } from '@unito/integration-api';
4
4
  import indexRouter from './routes/index';
5
5
  import { extractCredentials } from './middlewares/credentials';
6
6
  import { extractCorrelationId } from './middlewares/correlationId';
7
+ import { extractAdditionalLoggingContext } from './middlewares/additionalLoggingContext';
7
8
  import { logger } from './logger';
8
9
 
9
10
  // Express Server initialization
@@ -21,7 +22,7 @@ app.use((req: express.Request, res: express.Response, next: express.NextFunction
21
22
  const loggerLevel = res.statusCode >= 500 ? 'error' : 'info';
22
23
 
23
24
  // eslint-disable-next-line
24
- logger[loggerLevel](`${req.method} ${req.originalUrl} ${res.statusCode}`, res.locals.correlationId);
25
+ logger[loggerLevel](`${req.method} ${req.originalUrl} ${res.statusCode}`);
25
26
  });
26
27
  }
27
28
 
@@ -37,6 +38,9 @@ app.use(extractCorrelationId);
37
38
  // Load the routes.
38
39
  app.use('/', indexRouter);
39
40
 
41
+ // Extract the additional logging context.
42
+ app.use(extractAdditionalLoggingContext);
43
+
40
44
  // Must be the (last - 1) handler.
41
45
  app.use((err: Error, _req: express.Request, res: express.Response, next: express.NextFunction) => {
42
46
  if (res.headersSent) {
@@ -7,30 +7,48 @@ enum LogLevel {
7
7
  }
8
8
 
9
9
  export class Logger {
10
- private send(logLevel: LogLevel, message: string, correlationId: string) {
10
+ private metadata: { [key: string]: string } = {};
11
+
12
+ private send(logLevel: LogLevel, message: string) {
11
13
  console[logLevel](
12
14
  // Datadog automatically parses JSON-formatted logs
13
15
  JSON.stringify({
14
16
  message: message,
15
- correlation_id: correlationId,
17
+ ...this.metadata,
16
18
  }),
17
19
  );
18
20
  }
19
21
 
20
- public log(message: string, correlationId: string) {
21
- this.send(LogLevel.LOG, message, correlationId);
22
+ public log(message: string) {
23
+ this.send(LogLevel.LOG, message);
24
+ }
25
+
26
+ public error(message: string) {
27
+ this.send(LogLevel.ERROR, message);
22
28
  }
23
- public error(message: string, correlationId: string) {
24
- this.send(LogLevel.ERROR, message, correlationId);
29
+
30
+ public warn(message: string) {
31
+ this.send(LogLevel.WARN, message);
25
32
  }
26
- public warn(message: string, correlationId: string) {
27
- this.send(LogLevel.WARN, message, correlationId);
33
+
34
+ public info(message: string) {
35
+ this.send(LogLevel.INFO, message);
28
36
  }
29
- public info(message: string, correlationId: string) {
30
- this.send(LogLevel.INFO, message, correlationId);
37
+
38
+ public debug(message: string) {
39
+ this.send(LogLevel.DEBUG, message);
31
40
  }
32
- public debug(message: string, correlationId: string) {
33
- this.send(LogLevel.DEBUG, message, correlationId);
41
+
42
+ public decorate(metadata: { [key: string]: string }) {
43
+ this.metadata = metadata;
44
+ }
45
+
46
+ public setMeta(key: string, value: string) {
47
+ this.metadata[key] = value;
48
+ }
49
+
50
+ public clearMeta() {
51
+ this.metadata = {};
34
52
  }
35
53
  }
36
54
 
@@ -0,0 +1,22 @@
1
+ import express from 'express';
2
+ import { logger } from '../logger';
3
+
4
+ export const extractAdditionalLoggingContext = (req: express.Request, res: express.Response, next: express.NextFunction) => {
5
+ const additionalLoggingContextHeader = req.header('X-Unito-Additional-Logging-Context');
6
+
7
+ let additionalLoggingContext;
8
+
9
+ if (typeof additionalLoggingContextHeader === 'string') {
10
+ try {
11
+ additionalLoggingContext = JSON.parse(additionalLoggingContextHeader);
12
+ } catch (error) {
13
+ logger.warn(`Failed parsing header X-Unito-Additional-Logging-Context: ${additionalLoggingContext}`);
14
+ }
15
+ }
16
+
17
+ for (const [key, value] of Object.entries(additionalLoggingContext || {})) {
18
+ logger.setMeta(key, String(value));
19
+ }
20
+
21
+ next();
22
+ };
@@ -1,18 +1,13 @@
1
1
  import express from 'express';
2
2
  import * as uuid from 'uuid';
3
+ import { logger } from '../logger';
3
4
 
4
5
  export const extractCorrelationId = (req: express.Request, res: express.Response, next: express.NextFunction) => {
5
6
  const correlationIdHeader = req.header('X-Unito-Correlation-Id');
6
7
 
7
- let correlationId;
8
+ const correlationId = correlationIdHeader ?? uuid.v4();
8
9
 
9
- if (correlationIdHeader) {
10
- correlationId = correlationIdHeader;
11
- } else {
12
- correlationId = uuid.v4();
13
- }
14
-
15
- res.locals.correlationId = correlationId;
10
+ logger.setMeta('correlation_id', correlationId);
16
11
 
17
12
  next();
18
13
  };
@@ -32,13 +32,9 @@ class Upgrade extends baseCommand_1.BaseCommand {
32
32
  //
33
33
  // Global command options
34
34
  //
35
- const packageName = '@unitoio/integration-cli';
35
+ const packageName = '@unito/integration-cli';
36
36
  const execOptions = { env: { ...process.env } };
37
- const npmOptions = [
38
- '--global',
39
- '--registry=https://npm.pkg.github.com/unitoio',
40
- '--//npm.pkg.github.com/:_authToken=$UNITO_GITHUB_PKG_TOKEN',
41
- ].join(' ');
37
+ const npmOptions = ['--global'].join(' ');
42
38
  //
43
39
  // Current version
44
40
  //
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.55.1",
2
+ "version": "0.55.4",
3
3
  "commands": {
4
4
  "activity": {
5
5
  "id": "activity",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-cli",
3
- "version": "0.55.1",
3
+ "version": "0.55.4",
4
4
  "description": "Integration CLI",
5
5
  "bin": {
6
6
  "integration-cli": "./bin/run"
@@ -38,7 +38,7 @@
38
38
  "@oclif/core": "2.x",
39
39
  "@typescript-eslint/eslint-plugin": "6.x",
40
40
  "@typescript-eslint/parser": "6.13.x",
41
- "@unito/integration-debugger": "0.22.7",
41
+ "@unito/integration-debugger": "0.22.8",
42
42
  "@unito/integrations-platform-client": "0.44.4",
43
43
  "ajv": "8.x",
44
44
  "ajv-formats": "2.x",
@@ -1,81 +0,0 @@
1
- {
2
- "$id": "https://unito.io/integration_cli/automation.schema.json",
3
- "title": "Automation",
4
- "type": "object",
5
- "description": "The configuration of the automation of an integration",
6
- "additionalProperties": false,
7
- "properties": {
8
- "headers": {
9
- "type": "object",
10
- "description": "The headers to add to the request",
11
- "required": ["authorizationHeaderPrefix"],
12
- "properties": {
13
- "authorizationHeaderPrefix": {
14
- "type": "string",
15
- "description": "The value of the Authorization header. e.g \"Bearer\""
16
- }
17
- },
18
- "additionalProperties": {
19
- "type": "string",
20
- "description": "Custom headers values"
21
- }
22
- },
23
- "items": {
24
- "type": "object",
25
- "description": "The items to generate",
26
- "additionalProperties": {
27
- "type": "object",
28
- "additionalProperties": false,
29
- "properties": {
30
- "collection": {
31
- "$ref": "#/$defs/endpoint"
32
- },
33
- "item": {
34
- "$ref": "#/$defs/endpoint"
35
- }
36
- }
37
- }
38
- }
39
- },
40
- "$defs": {
41
- "endpoint": {
42
- "type": "object",
43
- "description": "The endpoint to generate",
44
- "additionalProperties": false,
45
- "required": ["endpointURI", "idKey"],
46
- "properties": {
47
- "endpointURI": {
48
- "type": "string",
49
- "description": "Endpoint of the resource e.g /foo/bar/resource"
50
- },
51
- "idKey": {
52
- "type": "string",
53
- "description": "Which field is the unique identifier (id) of your item"
54
- },
55
- "keyToResponse": {
56
- "type": "string",
57
- "description": "Key to Access Nested Item (if applicable) like \"data\" that will lead to the item"
58
- },
59
- "usedId": {
60
- "type": "string",
61
- "default": ""
62
- },
63
- "directParent": {
64
- "type": "string",
65
- "default": ""
66
- },
67
- "httpMethod": {
68
- "type": "string",
69
- "description": "The verb of the HTTP request",
70
- "default": "GET",
71
- "enum": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
72
- "tsEnumNames": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]
73
- },
74
- "body": {
75
- "type": "string",
76
- "default": ""
77
- }
78
- }
79
- }
80
- }
81
- }