@unito/integration-cli 0.58.1 → 0.58.2

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.
@@ -4,13 +4,13 @@ export declare namespace env {
4
4
  export declare let plugins: string[];
5
5
  declare let _extends: string[];
6
6
  export { _extends as extends };
7
+ export declare let rules: {
8
+ 'no-console': string;
9
+ };
10
+ export declare let ignorePatterns: string[];
7
11
  export declare let overrides: {
8
12
  files: string[];
9
13
  rules: {
10
14
  '@typescript-eslint/no-floating-promises': string;
11
15
  };
12
16
  }[];
13
- export declare let rules: {
14
- 'no-console': string;
15
- };
16
- export declare let ignorePatterns: string[];
package/dist/.eslintrc.js CHANGED
@@ -10,14 +10,6 @@ module.exports = {
10
10
  'eslint:recommended',
11
11
  'plugin:@typescript-eslint/recommended',
12
12
  ],
13
- overrides: [
14
- {
15
- 'files': ['test/**/*.test.ts'],
16
- 'rules': {
17
- '@typescript-eslint/no-floating-promises': 'off'
18
- }
19
- }
20
- ],
21
13
  rules: {
22
14
  'no-console': 'off',
23
15
  },
@@ -1,3 +1,3 @@
1
1
  node_modules
2
2
  dist
3
- .eslintrc.js
3
+ eslint.config.js
@@ -35,4 +35,4 @@ RUN --mount=type=secret,id=npmrc,target=.npmrc npm ci --omit=dev
35
35
  RUN npm install --omit=dev
36
36
 
37
37
  ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
38
- CMD ["node", "./src/index.js"]
38
+ CMD ["node", "./index.js"]
@@ -0,0 +1,7 @@
1
+ import eslint from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+
4
+ export default tseslint.config(
5
+ eslint.configs.recommended,
6
+ ...tseslint.configs.recommended,
7
+ );
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "integration-boilerplate",
3
+ "type": "module",
3
4
  "version": "0.0.1",
4
5
  "description": "Integration Boilerplate",
6
+ "license": "LicenseRef-LICENSE",
5
7
  "scripts": {
6
8
  "compile": "tsc",
7
- "dev": "nodemon --watch \"src/**\" --ext ts --exec \"node --inspect --no-lazy -r ts-node/register/transpile-only src/index.ts\"",
8
- "lint": "eslint --resolve-plugins-relative-to . --fix src --ext .ts && prettier --write src",
9
+ "dev": "tsx watch --no-warnings src/index.ts",
10
+ "lint": "eslint --fix src && prettier --write src",
9
11
  "ci:audit": "check-audit",
10
- "ci:eslint": "eslint --resolve-plugins-relative-to . src --ext .ts",
12
+ "ci:eslint": "eslint src",
11
13
  "ci:lint": "npm run ci:prettier && npm run ci:eslint || (echo \"Please run eslint and/or prettier and commit the changes\" && exit 1)",
12
14
  "ci:prettier": "prettier --cache --ignore-unknown --check src",
13
15
  "ci:test": "NODE_ENV=test mocha"
@@ -19,25 +21,16 @@
19
21
  "engines": {
20
22
  "node": ">=20.0.0"
21
23
  },
22
- "license": "LicenseRef-LICENSE",
23
24
  "dependencies": {
24
- "@unito/integration-api": "^0.x",
25
- "express": "^5.0.0-beta.1",
26
- "uuid": "9.x"
25
+ "@unito/integration-sdk": "^0.x"
27
26
  },
28
27
  "devDependencies": {
29
- "@types/express": "4.x",
30
- "@types/mocha": "10.x",
31
28
  "@types/node": "20.x",
32
- "@types/uuid": "9.x",
33
- "@typescript-eslint/eslint-plugin": "5.x",
34
- "@typescript-eslint/parser": "5.x",
29
+ "typescript-eslint": "7.x",
35
30
  "eslint": "8.x",
36
- "mocha": "10.x",
37
- "nodemon": "2.x",
38
31
  "npm-audit-resolver": "^3.0.0-RC.0",
39
32
  "prettier": "2.x",
40
- "ts-node": "10.x",
33
+ "tsx": "4.x",
41
34
  "typescript": "5.x"
42
35
  }
43
36
  }
@@ -0,0 +1,10 @@
1
+ import { GetCredentialAccountHandler } from '@unito/integration-sdk';
2
+
3
+ export const getCredentialAccount: GetCredentialAccountHandler = async () => {
4
+ return {
5
+ id: 'me',
6
+ displayName: 'Me',
7
+ emails: [],
8
+ partition: undefined,
9
+ };
10
+ };
@@ -0,0 +1,8 @@
1
+ import { GetItemHandler } from '@unito/integration-sdk';
2
+
3
+ export const getItem: GetItemHandler = async () => {
4
+ return {
5
+ fields: {},
6
+ relations: [],
7
+ };
8
+ };
@@ -1,92 +1,11 @@
1
- import express from 'express';
2
- import { Error as APIError } from '@unito/integration-api';
1
+ import { Integration } from '@unito/integration-sdk';
3
2
 
4
- import indexRouter from './routes/index';
5
- import { extractCredentials } from './middlewares/credentials';
6
- import { extractCorrelationId } from './middlewares/correlationId';
7
- import { extractAdditionalLoggingContext } from './middlewares/additionalLoggingContext';
8
- import { logger } from './logger';
3
+ import * as meHandler from './handlers/me.js';
4
+ import * as rootHandler from './handlers/root.js';
9
5
 
10
- // Express Server initialization
11
- const app: express.Application = express();
6
+ const integration = new Integration();
12
7
 
13
- // Parse query strings with https://github.com/ljharb/qs.
14
- app.set('query parser', 'extended');
8
+ integration.addHandler('/', rootHandler);
9
+ integration.addHandler('/me', meHandler);
15
10
 
16
- app.use(express.json());
17
-
18
- // Must be one of the first handlers (to catch all the errors).
19
- app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
20
- if (req.originalUrl !== '/health') {
21
- res.on('finish', function () {
22
- const loggerLevel = res.statusCode >= 500 ? 'error' : 'info';
23
-
24
- // eslint-disable-next-line
25
- logger[loggerLevel](`${req.method} ${req.originalUrl} ${res.statusCode}`);
26
- });
27
- }
28
-
29
- next();
30
- });
31
-
32
- // Extract and validate the credentials.
33
- app.use(extractCredentials);
34
-
35
- // Extract the correlation id.
36
- app.use(extractCorrelationId);
37
-
38
- // Load the routes.
39
- app.use('/', indexRouter);
40
-
41
- // Extract the additional logging context.
42
- app.use(extractAdditionalLoggingContext);
43
-
44
- // Must be the (last - 1) handler.
45
- app.use((err: Error, _req: express.Request, res: express.Response, next: express.NextFunction) => {
46
- if (res.headersSent) {
47
- return next(err);
48
- }
49
-
50
- const originalError: APIError = {
51
- code: err.name,
52
- message: err.message,
53
- };
54
-
55
- res.status(500).json({
56
- code: '500',
57
- message: 'Oops! Something went wrong',
58
- originalError: originalError,
59
- } as APIError);
60
- });
61
-
62
- // Must be the last handler.
63
- app.use((req: express.Request, res: express.Response, _next: express.NextFunction) => {
64
- const error: APIError = {
65
- code: '404',
66
- message: `Path ${req.path} not found.`,
67
- };
68
-
69
- res.status(404).json(error);
70
- });
71
-
72
- // eslint-disable-next-line
73
- const instance = app.listen(process.env.PORT || 9200, () => console.log(`Server started on port ${process.env.PORT || 9200}.`));
74
-
75
- // Trap exit signals.
76
- ['SIGTERM', 'SIGINT', 'SIGUSR2'].forEach(signalType => {
77
- process.once(signalType, async () => {
78
- // eslint-disable-next-line
79
- console.log(`Received termination signal ${signalType}. Exiting.`);
80
-
81
- try {
82
- if (instance) {
83
- instance.close();
84
- }
85
- } catch (e) {
86
- // eslint-disable-next-line
87
- console.error('Failed to gracefully exit', e);
88
- }
89
-
90
- process.exit();
91
- });
92
- });
11
+ integration.start();
@@ -1,10 +1,5 @@
1
1
  {
2
- "ts-node": {
3
- "logError": true
4
- },
5
2
  "compilerOptions": {
6
- "allowJs": true,
7
- "allowSyntheticDefaultImports": true,
8
3
  "baseUrl": ".",
9
4
  "declaration": true,
10
5
  "declarationMap": true,
@@ -15,23 +10,20 @@
15
10
  "incremental": true,
16
11
  "isolatedModules": false,
17
12
  "lib": ["dom", "ES2022"],
18
- "module": "commonjs",
19
- "moduleResolution": "node",
13
+ "module": "NodeNext",
20
14
  "noImplicitAny": true,
21
15
  "noFallthroughCasesInSwitch": true,
22
16
  "noUnusedLocals": true,
23
17
  "outDir": "dist",
24
18
  "pretty": true,
25
- "resolveJsonModule": true,
26
- "rootDir": ".",
19
+ "moduleResolution": "NodeNext",
20
+ "rootDir": "./src",
27
21
  "skipLibCheck": true,
28
22
  "sourceMap": true,
29
23
  "strict": true,
30
24
  "strictFunctionTypes": true,
31
25
  "strictNullChecks": true,
32
26
  "strictPropertyInitialization": false,
33
- "target": "ES2022"
34
- },
35
- "include": ["src/**/*"],
36
- "exclude": ["node_modules"]
27
+ "target": "esnext"
28
+ }
37
29
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.58.1",
2
+ "version": "0.58.2",
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.58.1",
3
+ "version": "0.58.2",
4
4
  "description": "Integration CLI",
5
5
  "bin": {
6
6
  "integration-cli": "./bin/run"
@@ -1,74 +0,0 @@
1
- module.exports = {
2
- 'env': {
3
- 'browser': true,
4
- 'es6': true,
5
- 'node': true
6
- },
7
- 'parser': '@typescript-eslint/parser',
8
- 'parserOptions': {
9
- 'project': './tsconfig.json',
10
- },
11
- 'plugins': [
12
- '@typescript-eslint'
13
- ],
14
- extends: [
15
- 'eslint:recommended',
16
- 'plugin:@typescript-eslint/recommended',
17
- ],
18
- ignorePatterns: [
19
- 'node_modules',
20
- 'dist',
21
- '.eslintrc.js'
22
- ],
23
- 'rules': {
24
- '@typescript-eslint/no-loss-of-precision': 0,
25
- '@typescript-eslint/no-explicit-any': 0,
26
- '@typescript-eslint/ban-ts-comment': 0,
27
- '@typescript-eslint/ban-ts-ignore': 0,
28
- '@typescript-eslint/explicit-module-boundary-types': 0,
29
- '@typescript-eslint/no-var-requires': 0,
30
- '@typescript-eslint/no-floating-promises': 2,
31
- '@typescript-eslint/no-unused-vars': 0,
32
- // We need null in connectors because in some API, adding null to a field makes the API remove the value to the field
33
- '@typescript-eslint/no-non-null-assertion': 0,
34
- '@typescript-eslint/prefer-namespace-keyword': 0,
35
- '@typescript-eslint/no-namespace': 0,
36
- '@typescript-eslint/no-inferrable-types': 0,
37
- '@typescript-eslint/naming-convention': [
38
- 1,
39
- {
40
- selector: [
41
- 'classProperty',
42
- 'objectLiteralProperty',
43
- 'typeProperty',
44
- 'classMethod',
45
- 'objectLiteralMethod',
46
- 'typeMethod',
47
- 'accessor',
48
- 'enumMember'
49
- ],
50
- format: null,
51
- modifiers: ['requiresQuotes']
52
- }
53
- ],
54
- 'no-whitespace-before-property': 2,
55
- 'no-trailing-spaces': 2,
56
- 'no-extra-boolean-cast': 0,
57
- 'no-inner-declarations': 0,
58
- 'no-useless-escape': 0,
59
- 'no-case-declarations': 0,
60
- 'space-unary-ops': [2,
61
- {
62
- 'words': true,
63
- 'nonwords': false,
64
- },
65
- ],
66
- 'space-before-function-paren': [2, {
67
- 'anonymous': 'always',
68
- 'named': 'never',
69
- 'asyncArrow': 'always'
70
- }],
71
- 'object-curly-spacing': [2, 'always'],
72
- 'no-console': 2,
73
- }
74
- };
@@ -1,55 +0,0 @@
1
- enum LogLevel {
2
- ERROR = 'error',
3
- WARN = 'warn',
4
- INFO = 'info',
5
- LOG = 'log',
6
- DEBUG = 'debug',
7
- }
8
-
9
- export class Logger {
10
- private metadata: { [key: string]: string } = {};
11
-
12
- private send(logLevel: LogLevel, message: string) {
13
- console[logLevel](
14
- // Datadog automatically parses JSON-formatted logs
15
- JSON.stringify({
16
- message: message,
17
- ...this.metadata,
18
- }),
19
- );
20
- }
21
-
22
- public log(message: string) {
23
- this.send(LogLevel.LOG, message);
24
- }
25
-
26
- public error(message: string) {
27
- this.send(LogLevel.ERROR, message);
28
- }
29
-
30
- public warn(message: string) {
31
- this.send(LogLevel.WARN, message);
32
- }
33
-
34
- public info(message: string) {
35
- this.send(LogLevel.INFO, message);
36
- }
37
-
38
- public debug(message: string) {
39
- this.send(LogLevel.DEBUG, message);
40
- }
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 = {};
52
- }
53
- }
54
-
55
- export const logger = new Logger();
@@ -1,22 +0,0 @@
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: ${additionalLoggingContextHeader}`);
14
- }
15
- }
16
-
17
- for (const [key, value] of Object.entries(additionalLoggingContext || {})) {
18
- logger.setMeta(key, String(value));
19
- }
20
-
21
- next();
22
- };
@@ -1,13 +0,0 @@
1
- import express from 'express';
2
- import * as uuid from 'uuid';
3
- import { logger } from '../logger';
4
-
5
- export const extractCorrelationId = (req: express.Request, res: express.Response, next: express.NextFunction) => {
6
- const correlationIdHeader = req.header('X-Unito-Correlation-Id');
7
-
8
- const correlationId = correlationIdHeader ?? uuid.v4();
9
-
10
- logger.setMeta('correlation_id', correlationId);
11
-
12
- next();
13
- };
@@ -1,38 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
-
3
- // This interface contains the different variables defined in the authorization methods
4
- // of your integration (in the Integrations Platform registry).
5
- //
6
- // For example, if you add a "custom" authorization method in the registry with the variable "apiKey",
7
- // you must add "apiKey: string" to this interface.
8
- //
9
- // For your convenience, this interface is initialized for an integration that can either have:
10
- //
11
- // * No authentication.
12
- // * API key authentication (Bearer <accessToken>).
13
- // * OAuth 2 authentication (Bearer <accessToken>).
14
- //
15
- export interface Credentials {
16
- accessToken?: string;
17
- }
18
-
19
- export const extractCredentials = (req: Request, res: Response, next: NextFunction) => {
20
- const credentialsHeader = req.header('X-Unito-Credentials');
21
-
22
- let credentials: Credentials | null = null;
23
-
24
- if (credentialsHeader) {
25
- try {
26
- credentials = JSON.parse(Buffer.from(credentialsHeader, 'base64').toString('utf8'));
27
- } catch {
28
- return res.status(400).json({ code: 400, message: 'Error parsing credentials' });
29
- }
30
- }
31
-
32
- // You can add additional verifications here to make sure you received
33
- // all the necessary information to authenticate a user.
34
-
35
- res.locals.credentials = credentials;
36
-
37
- next();
38
- };
@@ -1,59 +0,0 @@
1
- import { Credentials } from './middlewares/credentials';
2
-
3
- export interface RequestOptions {
4
- queryParams?: { [key: string]: string };
5
- method?: 'POST' | 'GET' | 'PATCH';
6
- body?: Record<string, unknown>;
7
- credentials?: Credentials;
8
- }
9
-
10
- const apiUrl = 'https://path_to_your_api';
11
-
12
- export async function get<T>(endpoint: string, options: RequestOptions): Promise<T> {
13
- return fetchWrapper(endpoint, options);
14
- }
15
-
16
- export async function post<T>(endpoint: string, options: RequestOptions): Promise<T> {
17
- return fetchWrapper<T>(endpoint, {
18
- ...options,
19
- method: 'POST',
20
- });
21
- }
22
-
23
- export async function patch<T>(endpoint: string, options: RequestOptions): Promise<T> {
24
- return fetchWrapper<T>(endpoint, {
25
- ...options,
26
- method: 'PATCH',
27
- });
28
- }
29
-
30
- async function fetchWrapper<T>(endpoint: string, options: RequestOptions): Promise<T> {
31
- let absoluteUrl = [apiUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
32
-
33
- if (options.queryParams) {
34
- absoluteUrl = `${absoluteUrl}?${new URLSearchParams(options.queryParams)}`;
35
- }
36
-
37
- const headers: { [key: string]: string } = {
38
- 'Content-Type': 'application/json',
39
- Accept: 'application/json',
40
- };
41
-
42
- if (options.credentials?.accessToken) {
43
- headers['Authorization'] = `Bearer ${options.credentials?.accessToken}`;
44
- }
45
-
46
- const response = await fetch(absoluteUrl, {
47
- method: options.method,
48
- headers,
49
- body: options.body ? JSON.stringify(options.body) : undefined,
50
- });
51
-
52
- if (response.status === 200) {
53
- return (await response.json()) as T;
54
- }
55
-
56
- const textResult = await response.text();
57
-
58
- throw new Error(textResult);
59
- }
@@ -1,11 +0,0 @@
1
- import { Router } from 'express';
2
-
3
- import { router as rootRouter } from './root';
4
- import { router as meRouter } from './me';
5
-
6
- const router = Router();
7
-
8
- router.use('/', rootRouter);
9
- router.use('/me', meRouter);
10
-
11
- export default router;
@@ -1,15 +0,0 @@
1
- import { Request, Response, Router } from 'express';
2
-
3
- import { CredentialAccount } from '@unito/integration-api';
4
-
5
- export const router = Router();
6
-
7
- router.get('/', async (_req: Request, res: Response<CredentialAccount>) => {
8
- const account: CredentialAccount = {
9
- id: 'me',
10
- displayName: 'Me',
11
- emails: [],
12
- };
13
-
14
- res.json(account);
15
- });
@@ -1,12 +0,0 @@
1
- import { Request, Response, Router } from 'express';
2
-
3
- import { Item } from '@unito/integration-api';
4
-
5
- export const router = Router();
6
-
7
- router.get('/', (_req: Request, res: Response<Item>) => {
8
- return res.send({
9
- fields: {},
10
- relations: [],
11
- });
12
- });