@unito/integration-cli 0.57.1 → 0.58.0
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/dist/.eslintrc.d.ts +6 -0
- package/dist/.eslintrc.js +9 -2
- package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/src/index.ts +1 -3
- package/dist/src/commands/activity.d.ts +2 -2
- package/dist/src/commands/activity.js +2 -2
- package/dist/src/commands/dev.d.ts +8 -4
- package/dist/src/commands/dev.js +42 -5
- package/dist/src/commands/encrypt.d.ts +1 -1
- package/dist/src/commands/encrypt.js +1 -1
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +3 -3
- package/dist/src/commands/invite.d.ts +1 -1
- package/dist/src/commands/invite.js +2 -2
- package/dist/src/commands/login.d.ts +1 -1
- package/dist/src/commands/login.js +1 -1
- package/dist/src/commands/oauth2.d.ts +3 -3
- package/dist/src/commands/oauth2.js +19 -14
- package/dist/src/commands/publish.d.ts +2 -2
- package/dist/src/commands/publish.js +12 -12
- package/dist/src/commands/test.js +32 -8
- package/dist/src/commands/upgrade.js +3 -3
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.js +35 -18
- package/dist/src/resources/configuration.js +0 -2
- package/dist/src/resources/credentials.d.ts +3 -0
- package/dist/src/resources/credentials.js +26 -0
- package/dist/src/resources/integrations.d.ts +1 -0
- package/dist/src/resources/integrations.js +37 -2
- package/dist/src/resources/oauth2Helper.d.ts +4 -0
- package/dist/src/resources/oauth2Helper.js +30 -0
- package/dist/src/services/integrationsPlatform.d.ts +1 -0
- package/dist/src/services/integrationsPlatform.js +5 -1
- package/dist/src/services/oauth2Helper.d.ts +78 -3
- package/dist/src/services/oauth2Helper.js +229 -29
- package/dist/test/commands/activity.test.js +12 -9
- package/dist/test/commands/dev.test.js +59 -10
- package/dist/test/commands/encrypt.test.js +6 -7
- package/dist/test/commands/init.test.js +7 -9
- package/dist/test/commands/invite.test.js +11 -11
- package/dist/test/commands/login.test.js +20 -23
- package/dist/test/commands/oauth2.test.js +6 -2
- package/dist/test/commands/publish.test.js +152 -218
- package/dist/test/commands/test.test.js +65 -13
- package/dist/test/commands/upgrade.test.js +4 -6
- package/dist/test/errors.test.js +36 -36
- package/dist/test/helpers/integrations.d.ts +26 -0
- package/dist/test/helpers/integrations.js +25 -0
- package/dist/test/helpers/styles.d.ts +1 -0
- package/dist/test/helpers/styles.js +8 -0
- package/dist/test/oauth2Helper/oauth2Helper.test.js +112 -128
- package/dist/test/resources/configuration.test.js +24 -24
- package/dist/test/resources/decryption.test.js +9 -9
- package/dist/test/resources/globalConfiguration.test.js +4 -4
- package/dist/test/resources/integrations.test.js +37 -0
- package/dist/test/resources/oauth2Helper.test.js +55 -0
- package/dist/test/services/integrationsPlatform.test.js +20 -20
- package/oclif.manifest.json +64 -9
- package/package.json +10 -14
- package/dist/integrationGenerator/errors.d.ts +0 -2
- package/dist/integrationGenerator/errors.js +0 -6
- package/dist/integrationGenerator/index.d.ts +0 -2
- package/dist/integrationGenerator/index.js +0 -5
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.dockerignore +0 -3
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.eslintrc.js +0 -74
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierignore +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierrc +0 -7
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.unito.json +0 -1
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +0 -38
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/README.md +0 -21
- package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/index.ts +0 -94
- package/dist/integrationGenerator/integrationBoilerplate/package.json +0 -43
- package/dist/integrationGenerator/integrationBoilerplate/src/logger.ts +0 -55
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +0 -22
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/correlationId.ts +0 -13
- package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/credentials.ts +0 -38
- package/dist/integrationGenerator/integrationBoilerplate/src/request.ts +0 -59
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/index.ts +0 -11
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/me.ts +0 -15
- package/dist/integrationGenerator/integrationBoilerplate/src/routes/root.ts +0 -12
- package/dist/integrationGenerator/integrationBoilerplate/tsconfig.json +0 -37
- package/dist/integrationGenerator/src/index.d.ts +0 -1
- package/dist/integrationGenerator/src/index.js +0 -5
- package/dist/integrationGenerator/src/resources/index.d.ts +0 -1
- package/dist/integrationGenerator/src/resources/index.js +0 -5
- package/dist/integrationGenerator/src/resources/integration.d.ts +0 -9
- package/dist/integrationGenerator/src/resources/integration.js +0 -60
- package/dist/integrationGenerator/test/resources/integration.test.js +0 -51
- package/dist/src/oauth2Helper/oauth2Helper.d.ts +0 -63
- package/dist/src/oauth2Helper/oauth2Helper.js +0 -235
- package/dist/src/oauth2Helper/types.d.ts +0 -22
- package/dist/src/oauth2Helper/types.js +0 -2
- package/dist/test/mocha.hooks.d.ts +0 -2
- package/dist/test/mocha.hooks.js +0 -37
- package/dist/test/services/oauth2Helper.test.js +0 -85
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.dockerignore +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.eslintrc.js +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.nvmrc +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierignore +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.prettierrc +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/.unito.json +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/Dockerfile +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate → boilerplate}/README.md +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/package.json +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/logger.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/additionalLoggingContext.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/correlationId.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/middlewares/credentials.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/request.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/index.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/me.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/src/routes/root.ts +0 -0
- /package/dist/{integrationGenerator/integrationBoilerplate/integrationBoilerplate → boilerplate}/tsconfig.json +0 -0
- /package/dist/{integrationGenerator/test/resources/integration.test.d.ts → test/resources/integrations.test.d.ts} +0 -0
- /package/dist/test/{services → resources}/oauth2Helper.test.d.ts +0 -0
|
@@ -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();
|
package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts
DELETED
|
@@ -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,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
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ts-node": {
|
|
3
|
-
"logError": true
|
|
4
|
-
},
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"allowJs": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"baseUrl": ".",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"emitDecoratorMetadata": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"experimentalDecorators": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"incremental": true,
|
|
16
|
-
"isolatedModules": false,
|
|
17
|
-
"lib": ["dom", "ES2022"],
|
|
18
|
-
"module": "commonjs",
|
|
19
|
-
"moduleResolution": "node",
|
|
20
|
-
"noImplicitAny": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
-
"noUnusedLocals": true,
|
|
23
|
-
"outDir": "dist",
|
|
24
|
-
"pretty": true,
|
|
25
|
-
"resolveJsonModule": true,
|
|
26
|
-
"rootDir": ".",
|
|
27
|
-
"skipLibCheck": true,
|
|
28
|
-
"sourceMap": true,
|
|
29
|
-
"strict": true,
|
|
30
|
-
"strictFunctionTypes": true,
|
|
31
|
-
"strictNullChecks": true,
|
|
32
|
-
"strictPropertyInitialization": false,
|
|
33
|
-
"target": "ES2022"
|
|
34
|
-
},
|
|
35
|
-
"include": ["src/**/*"],
|
|
36
|
-
"exclude": ["node_modules"]
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as Resources from './resources';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as Integration from './integration';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates an integration skeleton with the specified name.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} integrationName - The name of the integration.
|
|
5
|
-
* @param {string} [destinationPath] - The destination path where the integration skeleton will be generated. If not provided, a default path will be used.
|
|
6
|
-
* @returns {string} - The path of the generated integration skeleton.
|
|
7
|
-
* @throws {Error} - If an integration with the same name already exists.
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateIntegrationSkeleton(integrationName: string, destinationPath?: string): Promise<string>;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateIntegrationSkeleton = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const errors_1 = require("../../errors");
|
|
8
|
-
/**
|
|
9
|
-
* Generates an integration skeleton with the specified name.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} integrationName - The name of the integration.
|
|
12
|
-
* @param {string} [destinationPath] - The destination path where the integration skeleton will be generated. If not provided, a default path will be used.
|
|
13
|
-
* @returns {string} - The path of the generated integration skeleton.
|
|
14
|
-
* @throws {Error} - If an integration with the same name already exists.
|
|
15
|
-
*/
|
|
16
|
-
async function generateIntegrationSkeleton(integrationName, destinationPath) {
|
|
17
|
-
const srcPath = path.join(__dirname, `../../integrationBoilerplate`);
|
|
18
|
-
// istanbul ignore next
|
|
19
|
-
const destPath = destinationPath ?? path.join(__dirname, `../../outputIntegrations`);
|
|
20
|
-
const targetFolder = `${destPath}/${integrationName.toLowerCase().replace(/ /g, '_')}`;
|
|
21
|
-
if (!fs.existsSync(targetFolder)) {
|
|
22
|
-
await fs.promises.mkdir(targetFolder, { recursive: true });
|
|
23
|
-
await copyFilesAndFolders(srcPath, targetFolder, ['node_modules', 'dist']);
|
|
24
|
-
// The .npmrc file is created here because it will be excluded during the CLI package's publishing process by npm.
|
|
25
|
-
// This step is necessary to ensure that the correct registry and auth token settings are present
|
|
26
|
-
// when installing package dependencies.
|
|
27
|
-
const npmrcContent = [
|
|
28
|
-
'@unitoio:registry=https://npm.pkg.github.com/unitoio',
|
|
29
|
-
'//npm.pkg.github.com/:_authToken=${UNITO_GITHUB_PKG_TOKEN}',
|
|
30
|
-
'engine-strict=true',
|
|
31
|
-
'strict-ssl=true',
|
|
32
|
-
].join('\n');
|
|
33
|
-
await fs.promises.writeFile(path.join(targetFolder, '.npmrc'), npmrcContent);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
throw new errors_1.AlreadyExistingIntegrationError(`Integration already exists with this name: ${integrationName}`);
|
|
37
|
-
}
|
|
38
|
-
return targetFolder;
|
|
39
|
-
}
|
|
40
|
-
exports.generateIntegrationSkeleton = generateIntegrationSkeleton;
|
|
41
|
-
async function copyFilesAndFolders(source, destination, excludedFolders) {
|
|
42
|
-
const files = await fs.promises.readdir(source);
|
|
43
|
-
for (const file of files) {
|
|
44
|
-
/* istanbul ignore next */
|
|
45
|
-
if (excludedFolders.includes(file)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const sourcePath = path.join(source, file);
|
|
49
|
-
const destPath = path.join(destination, file);
|
|
50
|
-
const stats = await fs.promises.stat(sourcePath);
|
|
51
|
-
/* istanbul ignore else */
|
|
52
|
-
if (stats.isFile()) {
|
|
53
|
-
await fs.promises.copyFile(sourcePath, destPath);
|
|
54
|
-
}
|
|
55
|
-
else if (stats.isDirectory()) {
|
|
56
|
-
await fs.promises.mkdir(destPath);
|
|
57
|
-
await copyFilesAndFolders(sourcePath, destPath, excludedFolders);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const sinon = tslib_1.__importStar(require("sinon"));
|
|
7
|
-
const tmp_1 = tslib_1.__importDefault(require("tmp"));
|
|
8
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
-
const Integration = tslib_1.__importStar(require("../../src/resources/integration"));
|
|
10
|
-
describe('Integration Resource Generation', () => {
|
|
11
|
-
let tempDir;
|
|
12
|
-
const boilerplatePath = path.join(__dirname, '../../integrationBoilerplate');
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
sinon.restore();
|
|
15
|
-
});
|
|
16
|
-
describe('generateIntegrationSkeleton', () => {
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
tempDir = tmp_1.default.dirSync({ prefix: 'outputIntegrations-' }).name;
|
|
19
|
-
});
|
|
20
|
-
afterEach(async () => {
|
|
21
|
-
await fs_1.default.promises.rm(tempDir, { recursive: true });
|
|
22
|
-
sinon.restore();
|
|
23
|
-
});
|
|
24
|
-
it('should not create a new integration directory if it already exists', async () => {
|
|
25
|
-
const existingIntegrationName = 'existingIntegration';
|
|
26
|
-
await Integration.generateIntegrationSkeleton(existingIntegrationName, tempDir);
|
|
27
|
-
try {
|
|
28
|
-
await Integration.generateIntegrationSkeleton(existingIntegrationName, tempDir);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
(0, chai_1.expect)(e).to.eql(new Error(`Integration already exists with this name: ${existingIntegrationName}`));
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
it('should create a new integration directory if it does not exist', async () => {
|
|
35
|
-
const integrationName = 'NewIntegration';
|
|
36
|
-
const result = await Integration.generateIntegrationSkeleton(integrationName, tempDir);
|
|
37
|
-
(0, chai_1.expect)(result).equal(path.join(tempDir, integrationName.toLowerCase()));
|
|
38
|
-
(0, chai_1.expect)(fs_1.default.existsSync(result)).to.be.true;
|
|
39
|
-
const expectedFiles = await fs_1.default.promises.readdir(boilerplatePath);
|
|
40
|
-
expectedFiles.push('.npmrc');
|
|
41
|
-
const createdFiles = await fs_1.default.promises.readdir(result);
|
|
42
|
-
(0, chai_1.expect)(createdFiles).to.deep.eq(expectedFiles.sort());
|
|
43
|
-
createdFiles.forEach(createdField => (0, chai_1.expect)(expectedFiles.includes(createdField)));
|
|
44
|
-
});
|
|
45
|
-
it('generates an .npmrc file', async () => {
|
|
46
|
-
const result = await Integration.generateIntegrationSkeleton('foo', tempDir);
|
|
47
|
-
const npmrc = await fs_1.default.promises.readFile(`${result}/.npmrc`, 'utf-8');
|
|
48
|
-
(0, chai_1.expect)(npmrc).to.include('//npm.pkg.github.com/:_authToken=${UNITO_GITHUB_PKG_TOKEN}');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as openUrl from 'openurl';
|
|
2
|
-
import { Oauth2Response, Oauth2Payload } from './types';
|
|
3
|
-
export declare const open: typeof openUrl;
|
|
4
|
-
declare class OAuth2Helper {
|
|
5
|
-
private server;
|
|
6
|
-
private clientId;
|
|
7
|
-
private clientSecret;
|
|
8
|
-
private providerAuthorizationUrl;
|
|
9
|
-
private tokenUrl;
|
|
10
|
-
private scopes;
|
|
11
|
-
private grantType;
|
|
12
|
-
private requestContentType;
|
|
13
|
-
private responseContentType;
|
|
14
|
-
private refreshToken?;
|
|
15
|
-
private code;
|
|
16
|
-
private serverUrl;
|
|
17
|
-
private tokenRequestParameters;
|
|
18
|
-
private refreshRequestParameters;
|
|
19
|
-
/**
|
|
20
|
-
* Constructs an instance of OAuthHelper.
|
|
21
|
-
* @param clientId The client ID for your OAuth application.
|
|
22
|
-
* @param clientSecret The client secret for your OAuth application.
|
|
23
|
-
* @param authorizationUrl The URL for the authorization endpoint of the provider.
|
|
24
|
-
* @param scopes The scopes required for the OAuth authorization.
|
|
25
|
-
* @param providerTokenUrl The URL for the token endpoint of the provider.
|
|
26
|
-
*/
|
|
27
|
-
constructor(authorizationInfo: Oauth2Payload);
|
|
28
|
-
/**
|
|
29
|
-
* Handles the authorization request and redirects the user to the provider's authorization page.
|
|
30
|
-
* @param req The express Request object.
|
|
31
|
-
* @param res The express Response object.
|
|
32
|
-
*/
|
|
33
|
-
private handleAuthorize;
|
|
34
|
-
/**
|
|
35
|
-
* Handles the callback request from the provider and stores the authorization code.
|
|
36
|
-
* @param req The express Request object.
|
|
37
|
-
* @param res The express Response object.
|
|
38
|
-
*/
|
|
39
|
-
private handleCallback;
|
|
40
|
-
private encodeBody;
|
|
41
|
-
/**
|
|
42
|
-
* Handles the token request to exchange the authorization code for an access token.
|
|
43
|
-
* @param req The express Request object.
|
|
44
|
-
* @param res The express Response object.
|
|
45
|
-
*/
|
|
46
|
-
private handleToken;
|
|
47
|
-
updateToken(): Promise<Oauth2Response>;
|
|
48
|
-
/**
|
|
49
|
-
* Starts the Express server for handling OAuth callbacks.
|
|
50
|
-
* @returns The URL of the server.
|
|
51
|
-
*/
|
|
52
|
-
startServer(): string;
|
|
53
|
-
/**
|
|
54
|
-
* Stops the Express server.
|
|
55
|
-
*/
|
|
56
|
-
stopServer(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Waits for the authorization code to be set.
|
|
59
|
-
* @returns A promise that resolves when the code is set.
|
|
60
|
-
*/
|
|
61
|
-
callbackIsDone(): Promise<boolean>;
|
|
62
|
-
}
|
|
63
|
-
export default OAuth2Helper;
|