nango 0.40.0 → 0.40.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.
- package/dist/cli.d.ts +16 -4
- package/dist/cli.js +76 -124
- package/dist/cli.js.map +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +38 -23
- package/dist/index.js.map +1 -1
- package/dist/services/compile.service.d.ts +14 -9
- package/dist/services/compile.service.js +71 -67
- package/dist/services/compile.service.js.map +1 -1
- package/dist/services/compile.service.unit.test.js +17 -7
- package/dist/services/compile.service.unit.test.js.map +1 -1
- package/dist/services/config.service.d.ts +16 -7
- package/dist/services/config.service.js +84 -55
- package/dist/services/config.service.js.map +1 -1
- package/dist/services/config.service.unit.test.d.ts +1 -0
- package/dist/services/config.service.unit.test.js +147 -0
- package/dist/services/config.service.unit.test.js.map +1 -0
- package/dist/services/deploy.service.d.ts +14 -5
- package/dist/services/deploy.service.js +81 -71
- package/dist/services/deploy.service.js.map +1 -1
- package/dist/services/dryrun.service.js +11 -11
- package/dist/services/dryrun.service.js.map +1 -1
- package/dist/services/migration.service.js +23 -26
- package/dist/services/migration.service.js.map +1 -1
- package/dist/services/model.service.d.ts +38 -8
- package/dist/services/model.service.js +129 -167
- package/dist/services/model.service.js.map +1 -1
- package/dist/services/model.service.unit.test.d.ts +1 -0
- package/dist/services/model.service.unit.test.js +138 -0
- package/dist/services/model.service.unit.test.js.map +1 -0
- package/dist/services/parser.service.d.ts +1 -2
- package/dist/services/parser.service.js +3 -4
- package/dist/services/parser.service.js.map +1 -1
- package/dist/services/verification.service.d.ts +9 -2
- package/dist/services/verification.service.js +20 -22
- package/dist/services/verification.service.js.map +1 -1
- package/dist/sync.unit.cli-test.js +157 -222
- package/dist/sync.unit.cli-test.js.map +1 -1
- package/dist/templates/action.ejs +2 -47
- package/dist/templates/nango.yaml +1 -2
- package/dist/templates/sync.ejs +1 -4
- package/dist/utils/layoutMode.d.ts +7 -0
- package/dist/utils/layoutMode.js +41 -0
- package/dist/utils/layoutMode.js.map +1 -0
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +4 -127
- package/dist/utils.js.map +1 -1
- package/lib/nango.yaml.schema.v2.json +183 -178
- package/package.json +7 -6
- package/dist/nango-sync.d.ts +0 -299
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function compileAllFiles({ debug, scriptName, providerConfigKey, type }: {
|
|
1
|
+
import type { NangoYamlParsed } from '@nangohq/types';
|
|
2
|
+
export declare function compileAllFiles({ debug, fullPath, scriptName, providerConfigKey, type }: {
|
|
3
3
|
debug: boolean;
|
|
4
|
+
fullPath: string;
|
|
4
5
|
scriptName?: string;
|
|
5
6
|
providerConfigKey?: string;
|
|
6
7
|
type?: string;
|
|
7
8
|
}): Promise<boolean>;
|
|
8
|
-
export declare function compileSingleFile({
|
|
9
|
+
export declare function compileSingleFile({ fullPath, file, parsed, tsconfig, debug }: {
|
|
10
|
+
fullPath: string;
|
|
9
11
|
file: ListedFile;
|
|
10
12
|
tsconfig: string;
|
|
11
|
-
|
|
12
|
-
modelNames: string[];
|
|
13
|
+
parsed: NangoYamlParsed;
|
|
13
14
|
debug: boolean;
|
|
14
15
|
}): Promise<boolean>;
|
|
15
16
|
export interface ListedFile {
|
|
@@ -17,10 +18,14 @@ export interface ListedFile {
|
|
|
17
18
|
outputPath: string;
|
|
18
19
|
baseName: string;
|
|
19
20
|
}
|
|
20
|
-
export declare function getFileToCompile(filePath
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
export declare function getFileToCompile({ fullPath, filePath }: {
|
|
22
|
+
fullPath: string;
|
|
23
|
+
filePath: string;
|
|
24
|
+
}): ListedFile;
|
|
25
|
+
export declare function listFilesToCompile({ fullPath, scriptDirectory, scriptName, parsed, debug }: {
|
|
26
|
+
fullPath: string;
|
|
27
|
+
scriptDirectory?: string | undefined;
|
|
23
28
|
scriptName?: string | undefined;
|
|
24
|
-
|
|
29
|
+
parsed: NangoYamlParsed;
|
|
25
30
|
debug?: boolean;
|
|
26
31
|
}): ListedFile[];
|
|
@@ -4,28 +4,26 @@ import * as tsNode from 'ts-node';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { build } from 'tsup';
|
|
7
|
-
import {
|
|
8
|
-
import configService from './config.service.js';
|
|
7
|
+
import { localFileService } from '@nangohq/shared';
|
|
9
8
|
import { getNangoRootPath, printDebug } from '../utils.js';
|
|
10
|
-
import {
|
|
11
|
-
import modelService from './model.service.js';
|
|
9
|
+
import { loadYamlAndGeneratedModel } from './model.service.js';
|
|
12
10
|
import parserService from './parser.service.js';
|
|
11
|
+
import { getProviderConfigurationFromPath } from '@nangohq/nango-yaml';
|
|
13
12
|
const ALLOWED_IMPORTS = ['url', 'crypto', 'zod', 'node:url', 'node:crypto'];
|
|
14
|
-
export async function compileAllFiles({ debug, scriptName, providerConfigKey, type }) {
|
|
13
|
+
export async function compileAllFiles({ debug, fullPath, scriptName, providerConfigKey, type }) {
|
|
15
14
|
const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
|
|
16
|
-
const distDir = '
|
|
15
|
+
const distDir = path.join(fullPath, 'dist');
|
|
17
16
|
if (!fs.existsSync(distDir)) {
|
|
18
17
|
if (debug) {
|
|
19
18
|
printDebug(`Creating ${distDir} directory`);
|
|
20
19
|
}
|
|
21
20
|
fs.mkdirSync(distDir);
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
await modelService.createModelFile();
|
|
22
|
+
const res = loadYamlAndGeneratedModel({ fullPath, debug });
|
|
23
|
+
if (!res.success) {
|
|
24
|
+
return false;
|
|
28
25
|
}
|
|
26
|
+
const parsed = res.response;
|
|
29
27
|
const compilerOptions = JSON.parse(tsconfig).compilerOptions;
|
|
30
28
|
const compiler = tsNode.create({
|
|
31
29
|
skipProject: true, // when installed locally we don't want ts-node to pick up the package tsconfig.json file
|
|
@@ -34,22 +32,16 @@ export async function compileAllFiles({ debug, scriptName, providerConfigKey, ty
|
|
|
34
32
|
if (debug) {
|
|
35
33
|
printDebug(`Compiler options: ${JSON.stringify(compilerOptions, null, 2)}`);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
if (!loadSuccess || !config) {
|
|
39
|
-
console.log(chalk.red(error?.message));
|
|
40
|
-
throw new Error('Error loading config');
|
|
41
|
-
}
|
|
42
|
-
let scriptDirectory = process.cwd();
|
|
35
|
+
let scriptDirectory;
|
|
43
36
|
if (scriptName && providerConfigKey && type) {
|
|
44
|
-
scriptDirectory = localFileService.resolveTsFileLocation({ scriptName, providerConfigKey, type });
|
|
45
|
-
console.log(chalk.green(`Compiling ${scriptName}.ts in ${scriptDirectory}`));
|
|
37
|
+
scriptDirectory = localFileService.resolveTsFileLocation({ scriptName, providerConfigKey, type }).replace(fullPath, '');
|
|
38
|
+
console.log(chalk.green(`Compiling ${scriptName}.ts in ${fullPath}${scriptDirectory}`));
|
|
46
39
|
}
|
|
47
|
-
const integrationFiles = listFilesToCompile({ scriptName,
|
|
40
|
+
const integrationFiles = listFilesToCompile({ scriptName, fullPath, scriptDirectory, parsed, debug });
|
|
48
41
|
let success = true;
|
|
49
|
-
const modelNames = configService.getModelNames(config);
|
|
50
42
|
for (const file of integrationFiles) {
|
|
51
43
|
try {
|
|
52
|
-
const completed = await compile({
|
|
44
|
+
const completed = await compile({ fullPath, file, parsed, compiler, debug });
|
|
53
45
|
if (!completed) {
|
|
54
46
|
if (scriptName && file.inputPath.includes(scriptName)) {
|
|
55
47
|
success = false;
|
|
@@ -64,13 +56,19 @@ export async function compileAllFiles({ debug, scriptName, providerConfigKey, ty
|
|
|
64
56
|
}
|
|
65
57
|
return success;
|
|
66
58
|
}
|
|
67
|
-
export async function compileSingleFile({
|
|
59
|
+
export async function compileSingleFile({ fullPath, file, parsed, tsconfig, debug = false }) {
|
|
68
60
|
try {
|
|
69
61
|
const compiler = tsNode.create({
|
|
70
62
|
skipProject: true, // when installed locally we don't want ts-node to pick up the package tsconfig.json file
|
|
71
63
|
compilerOptions: JSON.parse(tsconfig).compilerOptions
|
|
72
64
|
});
|
|
73
|
-
const result = await compile({
|
|
65
|
+
const result = await compile({
|
|
66
|
+
fullPath,
|
|
67
|
+
file,
|
|
68
|
+
parsed,
|
|
69
|
+
compiler,
|
|
70
|
+
debug
|
|
71
|
+
});
|
|
74
72
|
return result;
|
|
75
73
|
}
|
|
76
74
|
catch (error) {
|
|
@@ -79,15 +77,16 @@ export async function compileSingleFile({ file, config, modelNames, tsconfig, de
|
|
|
79
77
|
return false;
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
function compileImportedFile(filePath, compiler,
|
|
80
|
+
function compileImportedFile({ fullPath, filePath, compiler, parsed, type }) {
|
|
83
81
|
let finalResult = true;
|
|
84
82
|
const importedFiles = parserService.getImportedFiles(filePath);
|
|
85
|
-
if (!parserService.callsAreUsedCorrectly(filePath, type,
|
|
83
|
+
if (!parserService.callsAreUsedCorrectly(filePath, type, Array.from(parsed.models.keys()))) {
|
|
86
84
|
return false;
|
|
87
85
|
}
|
|
88
86
|
for (const importedFile of importedFiles) {
|
|
89
87
|
const importedFilePath = path.resolve(path.dirname(filePath), importedFile);
|
|
90
|
-
const
|
|
88
|
+
const importedFilePathWithoutExtension = path.join(path.dirname(importedFilePath), path.basename(importedFilePath, path.extname(importedFilePath)));
|
|
89
|
+
const importedFilePathWithExtension = importedFilePathWithoutExtension + '.ts';
|
|
91
90
|
/// if it is a library import then we can skip it
|
|
92
91
|
if (!fs.existsSync(importedFilePathWithExtension)) {
|
|
93
92
|
// if the library is not allowed then we should let the user know
|
|
@@ -98,12 +97,11 @@ function compileImportedFile(filePath, compiler, type, modelNames) {
|
|
|
98
97
|
}
|
|
99
98
|
continue;
|
|
100
99
|
}
|
|
101
|
-
const cwd = process.cwd();
|
|
102
100
|
// if the file is not in the nango-integrations directory
|
|
103
101
|
// then we should not compile it
|
|
104
102
|
// if the parts of the path are shorter than the current that means it is higher
|
|
105
103
|
// than the nango-integrations directory
|
|
106
|
-
if (importedFilePathWithExtension.split(path.sep).length
|
|
104
|
+
if (importedFilePathWithExtension.split(path.sep).length < fullPath.split(path.sep).length) {
|
|
107
105
|
const importedFileName = path.basename(importedFilePathWithExtension);
|
|
108
106
|
console.log(chalk.red(`All imported files must live within the nango-integrations directory. Please move "${importedFileName}" into the nango-integrations directory.`));
|
|
109
107
|
return false;
|
|
@@ -113,18 +111,18 @@ function compileImportedFile(filePath, compiler, type, modelNames) {
|
|
|
113
111
|
}
|
|
114
112
|
compiler.compile(fs.readFileSync(importedFilePathWithExtension, 'utf8'), importedFilePathWithExtension);
|
|
115
113
|
console.log(chalk.green(`Compiled "${importedFilePathWithExtension}" successfully`));
|
|
116
|
-
finalResult = compileImportedFile(
|
|
114
|
+
finalResult = compileImportedFile({ fullPath, filePath: importedFilePathWithExtension, compiler, type, parsed });
|
|
117
115
|
}
|
|
118
116
|
return finalResult;
|
|
119
117
|
}
|
|
120
|
-
async function compile({
|
|
121
|
-
const providerConfiguration =
|
|
118
|
+
async function compile({ fullPath, file, parsed, compiler, debug = false }) {
|
|
119
|
+
const providerConfiguration = getProviderConfigurationFromPath({ filePath: file.inputPath, parsed });
|
|
122
120
|
if (!providerConfiguration) {
|
|
123
121
|
return false;
|
|
124
122
|
}
|
|
125
123
|
const syncConfig = [...providerConfiguration.syncs, ...providerConfiguration.actions].find((sync) => sync.name === file.baseName);
|
|
126
|
-
const type = syncConfig?.type ||
|
|
127
|
-
const success = compileImportedFile(file.inputPath, compiler, type,
|
|
124
|
+
const type = syncConfig?.type || 'sync';
|
|
125
|
+
const success = compileImportedFile({ fullPath, filePath: file.inputPath, compiler, type, parsed });
|
|
128
126
|
if (!success) {
|
|
129
127
|
return false;
|
|
130
128
|
}
|
|
@@ -134,70 +132,76 @@ async function compile({ file, config, modelNames, compiler, debug = false }) {
|
|
|
134
132
|
const basename = path.basename(file.outputPath, extname);
|
|
135
133
|
const fileNameWithExtension = `${basename}-${providerConfiguration.providerConfigKey}${extname}`;
|
|
136
134
|
const outputPath = path.join(dirname, fileNameWithExtension);
|
|
135
|
+
if (debug) {
|
|
136
|
+
printDebug(`Compiling ${file.inputPath} -> ${outputPath}`);
|
|
137
|
+
}
|
|
137
138
|
await build({
|
|
138
139
|
entryPoints: [file.inputPath],
|
|
139
|
-
tsconfig: getNangoRootPath()
|
|
140
|
+
tsconfig: path.join(getNangoRootPath(), 'tsconfig.dev.json'),
|
|
140
141
|
skipNodeModulesBundle: true,
|
|
141
142
|
silent: !debug,
|
|
142
|
-
outDir:
|
|
143
|
+
outDir: path.join(fullPath, 'dist'),
|
|
144
|
+
outExtension: () => ({ js: '.js' }),
|
|
143
145
|
onSuccess: async () => {
|
|
144
146
|
if (fs.existsSync(file.outputPath)) {
|
|
145
147
|
await fs.promises.rename(file.outputPath, outputPath);
|
|
146
148
|
console.log(chalk.green(`Compiled "${file.inputPath}" successfully`));
|
|
147
149
|
}
|
|
150
|
+
else {
|
|
151
|
+
console.log(chalk.red(`Failed to compile "${file.inputPath}"`));
|
|
152
|
+
}
|
|
148
153
|
return;
|
|
149
154
|
}
|
|
150
155
|
});
|
|
151
156
|
return true;
|
|
152
157
|
}
|
|
153
|
-
export function getFileToCompile(filePath) {
|
|
158
|
+
export function getFileToCompile({ fullPath, filePath }) {
|
|
159
|
+
const baseName = path.basename(filePath, '.ts');
|
|
154
160
|
return {
|
|
155
161
|
inputPath: filePath,
|
|
156
|
-
outputPath:
|
|
157
|
-
baseName
|
|
162
|
+
outputPath: path.join(fullPath, '/dist/', `${baseName}.js`),
|
|
163
|
+
baseName
|
|
158
164
|
};
|
|
159
165
|
}
|
|
160
|
-
export function listFilesToCompile({
|
|
166
|
+
export function listFilesToCompile({ fullPath, scriptDirectory, scriptName, parsed, debug }) {
|
|
161
167
|
let files = [];
|
|
162
168
|
if (scriptName) {
|
|
163
169
|
if (debug) {
|
|
164
170
|
printDebug(`Compiling ${scriptName}.ts`);
|
|
165
171
|
}
|
|
166
|
-
files = [
|
|
172
|
+
files = [path.join(fullPath, scriptDirectory || '', `${scriptName}.ts`)];
|
|
167
173
|
}
|
|
168
174
|
else {
|
|
169
|
-
files = glob.sync(`${
|
|
175
|
+
files = glob.sync(`${fullPath}/*.ts`);
|
|
170
176
|
// models.ts is the one expected file
|
|
171
177
|
if (files.length === 1 && debug) {
|
|
172
|
-
printDebug(`No files found in the root: ${
|
|
178
|
+
printDebug(`No files found in the root: ${fullPath}`);
|
|
173
179
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
files
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
printDebug(`Found nested sync files in ${syncPath}`);
|
|
188
|
-
}
|
|
189
|
-
if (glob.sync(`${cwd || process.cwd()}/${actionPath}/*.ts`).length > 0) {
|
|
190
|
-
printDebug(`Found nested action files in ${actionPath}`);
|
|
191
|
-
}
|
|
192
|
-
if (glob.sync(`${cwd || process.cwd()}/${postConnectionPath}/*.ts`).length > 0) {
|
|
193
|
-
printDebug(`Found nested post connection script files in ${postConnectionPath}`);
|
|
194
|
-
}
|
|
180
|
+
parsed.integrations.forEach((integration) => {
|
|
181
|
+
const syncPath = `${integration.providerConfigKey}/syncs`;
|
|
182
|
+
const actionPath = `${integration.providerConfigKey}/actions`;
|
|
183
|
+
const postConnectionPath = `${integration.providerConfigKey}/post-connection-scripts`;
|
|
184
|
+
files = [
|
|
185
|
+
...files,
|
|
186
|
+
...glob.sync(`${fullPath}/${syncPath}/*.ts`),
|
|
187
|
+
...glob.sync(`${fullPath}/${actionPath}/*.ts`),
|
|
188
|
+
...glob.sync(`${fullPath}/${postConnectionPath}/*.ts`)
|
|
189
|
+
];
|
|
190
|
+
if (debug) {
|
|
191
|
+
if (glob.sync(`${fullPath}/${syncPath}/*.ts`).length > 0) {
|
|
192
|
+
printDebug(`Found nested sync files in ${syncPath}`);
|
|
195
193
|
}
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
if (glob.sync(`${fullPath}/${actionPath}/*.ts`).length > 0) {
|
|
195
|
+
printDebug(`Found nested action files in ${actionPath}`);
|
|
196
|
+
}
|
|
197
|
+
if (glob.sync(`${fullPath}/${postConnectionPath}/*.ts`).length > 0) {
|
|
198
|
+
printDebug(`Found nested post connection script files in ${postConnectionPath}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
198
202
|
}
|
|
199
203
|
return files.map((filePath) => {
|
|
200
|
-
return getFileToCompile(filePath);
|
|
204
|
+
return getFileToCompile({ fullPath, filePath });
|
|
201
205
|
});
|
|
202
206
|
}
|
|
203
207
|
//# sourceMappingURL=compile.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.service.js","sourceRoot":"","sources":["../../lib/services/compile.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"compile.service.js","sourceRoot":"","sources":["../../lib/services/compile.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAA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CAAC;IACpD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,33 +1,43 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { describe, expect, it } from 'vitest';
|
|
2
3
|
import { getFileToCompile, listFilesToCompile } from './compile.service';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import path from 'node:path';
|
|
5
5
|
const thisFolder = path.dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
describe('listFiles', () => {
|
|
7
7
|
it('should list files with glob', () => {
|
|
8
|
-
const files = listFilesToCompile({
|
|
8
|
+
const files = listFilesToCompile({ fullPath: thisFolder, parsed: { integrations: [], models: new Map(), yamlVersion: 'v2' } });
|
|
9
9
|
expect(files.length).toBeGreaterThan(1);
|
|
10
10
|
expect(files[0]).toStrictEqual({
|
|
11
11
|
baseName: 'verification.service',
|
|
12
12
|
inputPath: `${thisFolder}/verification.service.ts`,
|
|
13
|
-
outputPath:
|
|
13
|
+
outputPath: `${thisFolder}/dist/verification.service.js`
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
it('should list files with syncName', () => {
|
|
17
|
-
const files = listFilesToCompile({ scriptName: 'compile.service',
|
|
17
|
+
const files = listFilesToCompile({ scriptName: 'compile.service', scriptDirectory: '', fullPath: thisFolder, parsed: {} });
|
|
18
18
|
expect(files.length).toBe(1);
|
|
19
19
|
expect(files[0]).toStrictEqual({
|
|
20
20
|
baseName: 'compile.service',
|
|
21
21
|
inputPath: `${thisFolder}/compile.service.ts`,
|
|
22
|
-
outputPath:
|
|
22
|
+
outputPath: `${thisFolder}/dist/compile.service.js`
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('should list files in subdirectory', () => {
|
|
26
|
+
const parent = path.join(thisFolder, '..');
|
|
27
|
+
const files = listFilesToCompile({ scriptName: 'compile.service', fullPath: parent, scriptDirectory: 'services', parsed: {} });
|
|
28
|
+
expect(files.length).toBe(1);
|
|
29
|
+
expect(files[0]).toStrictEqual({
|
|
30
|
+
baseName: 'compile.service',
|
|
31
|
+
inputPath: `${parent}/services/compile.service.ts`,
|
|
32
|
+
outputPath: `${parent}/dist/compile.service.js`
|
|
23
33
|
});
|
|
24
34
|
});
|
|
25
35
|
it('should add correct invalid path ', () => {
|
|
26
|
-
const file = getFileToCompile('foobar.ts');
|
|
36
|
+
const file = getFileToCompile({ filePath: 'foobar.ts', fullPath: thisFolder });
|
|
27
37
|
expect(file).toStrictEqual({
|
|
28
38
|
baseName: 'foobar',
|
|
29
39
|
inputPath: 'foobar.ts',
|
|
30
|
-
outputPath:
|
|
40
|
+
outputPath: `${thisFolder}/dist/foobar.js`
|
|
31
41
|
});
|
|
32
42
|
});
|
|
33
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.service.unit.test.js","sourceRoot":"","sources":["../../lib/services/compile.service.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.service.unit.test.js","sourceRoot":"","sources":["../../lib/services/compile.service.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IAC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MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,EAAqB,EAAE,CAAC,CAAC;QAClJ,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YAC3B,QAAQ,EAAE,iBAAiB;YAC3B,SAAS,EAAE,GAAG,MAAM,8BAA8B;YAClD,UAAU,EAAE,GAAG,MAAM,0BAA0B;SAClD,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QACxC,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;QAC/E,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC;YACvB,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,WAAW;YACtB,UAAU,EAAE,GAAG,UAAU,iBAAiB;SAC7C,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { NangoYamlParsed } from '@nangohq/types';
|
|
2
|
+
import type { ServiceResponse } from '@nangohq/shared';
|
|
3
|
+
export interface ValidationMessage {
|
|
4
|
+
msg: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
code?: string | undefined;
|
|
7
|
+
params?: Record<string, any> | undefined;
|
|
6
8
|
}
|
|
7
|
-
declare
|
|
8
|
-
|
|
9
|
+
export declare function load(fullPath: string, debug?: boolean): ServiceResponse<NangoYamlParsed>;
|
|
10
|
+
/**
|
|
11
|
+
* Output validation errors to console
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateAndOutput(yaml: any): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Use AJV to validate a nango.yaml against json schema
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateYaml(yaml: any): ValidationMessage[];
|
|
@@ -2,72 +2,101 @@ import fs from 'fs';
|
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import addErrors from 'ajv-errors';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
|
-
import { loadLocalNangoConfig, loadStandardConfig, nangoConfigFile, determineVersion, NangoError } from '@nangohq/shared';
|
|
6
5
|
import { getNangoRootPath, printDebug } from '../utils.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import { NangoError } from '@nangohq/shared';
|
|
7
|
+
import { determineVersion, loadNangoYaml } from '@nangohq/nango-yaml';
|
|
8
|
+
export function load(fullPath, debug = false) {
|
|
9
|
+
if (debug) {
|
|
10
|
+
printDebug(`Loading ${fullPath}`);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const parser = loadNangoYaml({ fullPath });
|
|
14
|
+
if (debug) {
|
|
15
|
+
printDebug(`Config file found`);
|
|
13
16
|
}
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
return { success: false, error:
|
|
17
|
+
const valid = validateAndOutput(parser.raw);
|
|
18
|
+
if (!valid) {
|
|
19
|
+
return { success: false, error: new NangoError('failed_to_parse_nango_yaml'), response: null };
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
+
parser.parse();
|
|
22
|
+
if (parser.errors.length > 0) {
|
|
23
|
+
for (const error of parser.errors) {
|
|
24
|
+
console.log(chalk.underline(chalk.white(error.path)));
|
|
25
|
+
console.log(` ${chalk.red('error')} ${error.message}${error.code ? chalk.dim(` [${error.code}]`) : ''}`);
|
|
26
|
+
console.log('');
|
|
27
|
+
}
|
|
28
|
+
return { success: false, error: new NangoError('failed_to_parse_nango_yaml'), response: null };
|
|
21
29
|
}
|
|
22
|
-
if (
|
|
23
|
-
|
|
30
|
+
if (parser.warnings.length > 0) {
|
|
31
|
+
parser.warnings.forEach((warn) => {
|
|
32
|
+
console.log(chalk.underline(chalk.white(warn.path)));
|
|
33
|
+
console.log(`${chalk.yellow(warn.message)} [${warn.code}]`);
|
|
34
|
+
console.log('');
|
|
35
|
+
});
|
|
24
36
|
}
|
|
25
|
-
return { success: true, error: null, response:
|
|
37
|
+
return { success: true, error: null, response: parser.parsed };
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const syncs = config.syncs || [];
|
|
30
|
-
const actions = config.actions || [];
|
|
31
|
-
const allSyncs = [...syncs, ...actions];
|
|
32
|
-
const models = allSyncs.reduce((acc, sync) => {
|
|
33
|
-
const models = sync.models || [];
|
|
34
|
-
const names = models.map((model) => model.name);
|
|
35
|
-
return [...acc, ...names];
|
|
36
|
-
}, []);
|
|
37
|
-
return [...acc, ...models];
|
|
38
|
-
}, []);
|
|
39
|
-
return modelNames;
|
|
39
|
+
catch {
|
|
40
|
+
return { success: false, error: new NangoError('error_loading_nango_config'), response: null };
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Output validation errors to console
|
|
45
|
+
*/
|
|
46
|
+
export function validateAndOutput(yaml) {
|
|
47
|
+
const errors = validateYaml(yaml);
|
|
48
|
+
if (errors.length <= 0) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const messages = [];
|
|
52
|
+
for (const error of errors) {
|
|
53
|
+
if (error.path) {
|
|
54
|
+
messages.push(chalk.underline(chalk.white(error.path.substring(1).split('/').join(' > '))));
|
|
46
55
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
messages.push(` ${chalk.red('error')} ${error.msg}${error.code ? chalk.dim(` [${error.code}]`) : ''}`);
|
|
57
|
+
if (error.params) {
|
|
58
|
+
for (const [key, val] of Object.entries(error.params)) {
|
|
59
|
+
messages.push(chalk.dim(` ${key}: ${val}`));
|
|
60
|
+
}
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
messages.push('');
|
|
63
|
+
}
|
|
64
|
+
console.log(`${chalk.red(`nango.yaml validation failed`)}\n\n${messages.join('\n')}`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Use AJV to validate a nango.yaml against json schema
|
|
69
|
+
*/
|
|
70
|
+
export function validateYaml(yaml) {
|
|
71
|
+
const ajv = new Ajv({ allErrors: true });
|
|
72
|
+
addErrors(ajv);
|
|
73
|
+
if (!yaml || !('integrations' in yaml)) {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
msg: 'Invalid file format, you should have at least an `integrations` property at the root level. Check our documentation https://docs.nango.dev/reference/integration-configuration'
|
|
63
77
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
const version = determineVersion(yaml);
|
|
81
|
+
const validationFile = version === 'v1' ? 'nango.yaml.schema.v1.json' : 'nango.yaml.schema.v2.json';
|
|
82
|
+
const schema = fs.readFileSync(`${getNangoRootPath()}/lib/${validationFile}`, 'utf8');
|
|
83
|
+
const validate = ajv.compile(JSON.parse(schema));
|
|
84
|
+
if (validate(yaml)) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const messages = [];
|
|
88
|
+
for (const error of validate.errors) {
|
|
89
|
+
if (!error.message || error.message === ' ') {
|
|
90
|
+
continue;
|
|
67
91
|
}
|
|
68
|
-
|
|
92
|
+
const code = error.keyword !== 'errorMessage' ? error.keyword : undefined;
|
|
93
|
+
messages.push({
|
|
94
|
+
msg: error.message,
|
|
95
|
+
path: error.instancePath,
|
|
96
|
+
code,
|
|
97
|
+
params: error.params && Object.keys(error.params).length > 0 && !('errors' in error.params) ? error.params : undefined
|
|
98
|
+
});
|
|
69
99
|
}
|
|
100
|
+
return messages;
|
|
70
101
|
}
|
|
71
|
-
const configService = new ConfigService();
|
|
72
|
-
export default configService;
|
|
73
102
|
//# sourceMappingURL=config.service.js.map
|