Skip to content

Commit

Permalink
fix(eslint): pass #6 (#1871)
Browse files Browse the repository at this point in the history
## Describe your changes

- Frontend eslint was not configured correctly
- Manually fix some Eslint errors
  • Loading branch information
bodinsamuel committed Mar 19, 2024
1 parent 3c02fa9 commit dbe5ce1
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 299 deletions.
31 changes: 31 additions & 0 deletions .eslintrc
Expand Up @@ -68,6 +68,37 @@
]
},
"overrides": [
{
"files": [
"packages/frontend/**/*.ts"
],
"env": {
"browser": true,
"es6": true,
"node": false
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true,
"jsx": false
},
"project": "packages/frontend/tsconfig.json"
},
"rules": {
"no-console": "off",
"@typescript-eslint/no-misused-promises": [
"warn",
{
"checksVoidReturn": {
"arguments": false,
"attributes": false
}
}
]
}
},
{
"files": [
"packages/webapp/**/*.tsx"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/cli.ts
Expand Up @@ -316,7 +316,7 @@ export const tscWatch = async (debug = false) => {
const integrationFiles = glob.sync(`./*.ts`);
for (const file of integrationFiles) {
// strip the file to just the last part
const strippedFile = file.replace(/^.*[\\\/]/, '');
const strippedFile = file.replace(/^.*[\\/]/, '');
compileFile(strippedFile);
}
return;
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/lib/services/compile.service.ts
Expand Up @@ -30,13 +30,14 @@ class CompileService {
await modelService.createModelFile();
}

const compilerOptions = (JSON.parse(tsconfig) as { compilerOptions: Record<string, any> }).compilerOptions;
const compiler = tsNode.create({
skipProject: true, // when installed locally we don't want ts-node to pick up the package tsconfig.json file
compilerOptions: JSON.parse(tsconfig).compilerOptions
compilerOptions
});

if (debug) {
printDebug(`Compiler options: ${JSON.stringify(JSON.parse(tsconfig).compilerOptions, null, 2)}`);
printDebug(`Compiler options: ${JSON.stringify(compilerOptions, null, 2)}`);
}

const integrationFiles = syncName ? [`./${syncName}.ts`] : glob.sync(`./*.ts`);
Expand All @@ -61,7 +62,7 @@ class CompileService {
continue;
}

const syncConfig = [...providerConfiguration?.syncs, ...providerConfiguration?.actions].find(
const syncConfig = [...(providerConfiguration?.syncs || []), ...(providerConfiguration?.actions || [])].find(
(sync) => sync.name === path.basename(filePath, '.ts')
);
const type = syncConfig?.type || SyncConfigType.SYNC;
Expand All @@ -73,7 +74,7 @@ class CompileService {
continue;
}
const result = compiler.compile(fs.readFileSync(filePath, 'utf8'), filePath);
const jsFilePath = filePath.replace(/\/[^\/]*$/, `/dist/${path.basename(filePath.replace('.ts', '.js'))}`);
const jsFilePath = filePath.replace(/\/[^/]*$/, `/dist/${path.basename(filePath.replace('.ts', '.js'))}`);

fs.writeFileSync(jsFilePath, result);
console.log(chalk.green(`Compiled "${filePath}" successfully`));
Expand Down
26 changes: 9 additions & 17 deletions packages/cli/lib/services/deploy.service.ts
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import promptly from 'promptly';
import axios, { AxiosResponse } from 'axios';
import axios, { AxiosError, AxiosResponse } from 'axios';
import type { SyncType, SyncDeploymentResult, StandardNangoConfig, IncomingFlowConfig, NangoConfigMetadata } from '@nangohq/shared';
import { SyncConfigType, localFileService, getInterval, stagingHost, cloudHost } from '@nangohq/shared';
import configService from './config.service.js';
Expand Down Expand Up @@ -159,21 +159,13 @@ class DeployService {
console.log(chalk.red('Syncs/Actions were not deployed. Exiting'));
process.exit(0);
}
} catch (err: any) {
} catch (err) {
let errorMessage;
if (!err?.response?.data) {
const {
message,
stack,
config: { method },
code,
status
} = err?.toJSON();

const errorObject = { message, stack, code, status, url, method };
if (err instanceof AxiosError) {
const errorObject = { message: err.message, stack: err.stack, code: err.code, status: err.status, url, method: err.config?.method };
errorMessage = JSON.stringify(errorObject, null, 2);
} else {
errorMessage = JSON.stringify(err.response.data, null, 2);
errorMessage = JSON.stringify(err, null, 2);
}
console.log(chalk.red(`Error deploying the syncs/actions with the following error: ${errorMessage}`));
process.exit(1);
Expand All @@ -192,17 +184,17 @@ class DeployService {
) {
await axios
.post(url, body, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
.then((response: AxiosResponse) => {
const results: SyncDeploymentResult[] = response.data;
.then((response: AxiosResponse<SyncDeploymentResult[]>) => {
const results = response.data;
if (results.length === 0) {
console.log(chalk.green(`Successfully removed the syncs/actions.`));
} else {
const nameAndVersions = results.map((result) => `${result.sync_name || result.name}@v${result.version}`);
console.log(chalk.green(`Successfully deployed the syncs/actions: ${nameAndVersions.join(', ')}!`));
}
})
.catch((err: any) => {
const errorMessage = JSON.stringify(err.response.data, null, 2);
.catch((err) => {
const errorMessage = JSON.stringify(err instanceof AxiosError ? err.response?.data : err, null, 2);
console.log(chalk.red(`Error deploying the syncs/actions with the following error: ${errorMessage}`));
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/services/verification.service.ts
Expand Up @@ -18,7 +18,7 @@ class VerificationService {
if (debug) {
printDebug(`Current full working directory is read as: ${cwd}`);
}
const currentDirectorySplit = cwd.split(/[\/\\]/);
const currentDirectorySplit = cwd.split(/[/\\]/);
const currentDirectory = currentDirectorySplit[currentDirectorySplit.length - 1];

if (debug) {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/scripts/v1-v2.js
Expand Up @@ -54,6 +54,7 @@ function convertYAML(inputYAML) {
}
data.integrations[integration].actions[taskName] = task;

// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete data.integrations[integration][taskName];
} else if (task.runs) {
change.type = 'sync';
Expand Down Expand Up @@ -101,6 +102,7 @@ function convertYAML(inputYAML) {
}
data.integrations[integration].syncs[taskName] = task;

// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete data.integrations[integration][taskName];
}
if (change.changes.length > 0) {
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/lib/index.ts
Expand Up @@ -73,7 +73,7 @@ export default class Nango {
// The websockets path is considered relative to the baseUrl, and with the protocol updated
const websocketUrl = new URL(config.websocketsPath, baseUrl);
this.websocketsBaseUrl = websocketUrl.toString().replace('https://', 'wss://').replace('http://', 'ws://');
} catch (err) {
} catch {
throw new AuthError('Invalid URL provided for the Nango host.', 'invalidHostUrl');
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class Nango {

try {
new URL(url);
} catch (err) {
} catch {
throw new AuthError('Invalid URL provided for the Nango host.', 'invalidHostUrl');
}

Expand Down Expand Up @@ -421,14 +421,15 @@ class AuthorizationModal {
const data = JSON.parse(message.data);

switch (data.message_type) {
case WSMessageType.ConnectionAck:
case WSMessageType.ConnectionAck: {
if (this.debug) {
console.log(debugLogPrefix, 'Connection ack received. Opening modal...');
}

const wsClientId = data.ws_client_id;
this.open(wsClientId);
break;
}
case WSMessageType.Error:
if (this.debug) {
console.log(debugLogPrefix, 'Error received. Rejecting authorization...');
Expand Down
4 changes: 2 additions & 2 deletions packages/jobs/lib/runner/runner.ts
Expand Up @@ -33,7 +33,7 @@ export async function getOrStartRunner(runnerId: string): Promise<Runner> {
try {
await runner.client.health.query();
healthCheck = true;
} catch (err) {
} catch {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ class RunnerCache {
}
}
return undefined;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/persist/lib/server.ts
Expand Up @@ -3,7 +3,7 @@ import type { Request, Response, NextFunction } from 'express';
import { validateRequest } from 'zod-express';
import { z } from 'zod';
import persistController from './controllers/persist.controller.js';
import { logLevelValues } from '@nangohq/shared';
import { logLevelValues, logger } from '@nangohq/shared';

export const server = express();
server.use(express.json({ limit: '100mb' }));
Expand All @@ -12,14 +12,14 @@ server.use((req: Request, res: Response, next: NextFunction) => {
const originalSend = res.send;
res.send = function (body: any) {
if (res.statusCode >= 400) {
console.log(`[Persist] [Error] ${req.method} ${req.path} ${res.statusCode} '${JSON.stringify(body)}'`);
logger.info(`[Persist] [Error] ${req.method} ${req.path} ${res.statusCode} '${JSON.stringify(body)}'`);
}
originalSend.call(this, body) as any;
return this;
};
next();
if (res.statusCode < 400) {
console.log(`[Persist] ${req.method} ${req.path} ${res.statusCode}`);
logger.info(`[Persist] ${req.method} ${req.path} ${res.statusCode}`);
}
});

Expand All @@ -39,7 +39,7 @@ server.post(
msg: z.string()
})
}),
persistController.saveActivityLog
persistController.saveActivityLog.bind(persistController)
);

const validateRecordsRequest = validateRequest({
Expand All @@ -64,9 +64,9 @@ const validateRecordsRequest = validateRequest({
})
});
const recordPath = '/environment/:environmentId/connection/:nangoConnectionId/sync/:syncId/job/:syncJobId/records';
server.post(recordPath, validateRecordsRequest, persistController.saveRecords);
server.delete(recordPath, validateRecordsRequest, persistController.deleteRecords);
server.put(recordPath, validateRecordsRequest, persistController.updateRecords);
server.post(recordPath, validateRecordsRequest, persistController.saveRecords.bind(persistController));
server.delete(recordPath, validateRecordsRequest, persistController.deleteRecords.bind(persistController));
server.put(recordPath, validateRecordsRequest, persistController.updateRecords.bind(persistController));

server.use((_req: Request, res: Response, next: NextFunction) => {
res.status(404);
Expand Down

0 comments on commit dbe5ce1

Please sign in to comment.