Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eslint pass #3406

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ export default tseslint.config(
'no-unused-vars': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',

'@typescript-eslint/restrict-template-expressions': [
'error',
Expand All @@ -122,11 +120,11 @@ export default tseslint.config(

'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-invalid-void-type': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/only-throw-error': 'warn',
'@typescript-eslint/only-throw-error': 'error',

'@typescript-eslint/no-unused-vars': [
'error',
Expand Down Expand Up @@ -161,6 +159,8 @@ export default tseslint.config(
'@typescript-eslint/no-deprecated': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ interface RunArgs {
optionalEnvironment?: string;
optionalProviderConfigKey?: string;
}
export interface DryRunServiceInterface {
run: (options: RunArgs, debug?: boolean) => Promise<string | void>;
}
export interface NangoProps {
scriptType: 'sync' | 'action' | 'webhook' | 'on-event';
host?: string;
Expand Down Expand Up @@ -290,7 +287,6 @@ export interface NangoProps {
rawDeleteOutput?: Map<string, unknown[]> | undefined;
stubbedMetadata?: Metadata | undefined;
abortSignal?: AbortSignal;
dryRunService?: DryRunServiceInterface;
syncConfig: DBSyncConfig;
runnerFlags: RunnerFlags;
debug: boolean;
Expand Down Expand Up @@ -325,7 +321,6 @@ export declare class NangoAction {
syncJobId?: number;
dryRun?: boolean;
abortSignal?: AbortSignal;
dryRunService?: DryRunServiceInterface;
syncConfig?: DBSyncConfig;
runnerFlags: RunnerFlags;
connectionId: string;
Expand Down
21 changes: 11 additions & 10 deletions packages/cli/lib/services/dryrun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface RunArgs extends GlobalOptions {
connectionId: string;
lastSyncDate?: string;
useServerLastSyncDate?: boolean;
input?: unknown;
metadata?: Metadata;
input?: string;
metadata?: string;
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
optionalEnvironment?: string;
optionalProviderConfigKey?: string;
saveResponses?: boolean;
Expand Down Expand Up @@ -221,8 +221,8 @@ export class DryRunService {
let normalizedInput;

if (actionInput) {
if (actionInput.toString().includes('@') && actionInput.toString().endsWith('.json')) {
const fileContents = readFile(actionInput.toString());
if (actionInput.startsWith('@') && actionInput.endsWith('.json')) {
const fileContents = readFile(actionInput);
if (!fileContents) {
console.log(chalk.red('The file could not be read. Please make sure it exists.'));
return;
Expand All @@ -235,9 +235,9 @@ export class DryRunService {
}
} else {
try {
normalizedInput = JSON.parse(actionInput as string);
normalizedInput = JSON.parse(actionInput);
} catch {
normalizedInput = actionInput;
throw new Error('Failed to parse --input');
}
}

Expand All @@ -252,8 +252,8 @@ export class DryRunService {
}

if (rawStubbedMetadata) {
if (rawStubbedMetadata.toString().includes('@') && rawStubbedMetadata.toString().endsWith('.json')) {
const fileContents = readFile(rawStubbedMetadata.toString());
if (rawStubbedMetadata.startsWith('@') && rawStubbedMetadata.endsWith('.json')) {
const fileContents = readFile(rawStubbedMetadata);
if (!fileContents) {
console.log(chalk.red('The metadata file could not be read. Please make sure it exists.'));
return;
Expand All @@ -266,9 +266,9 @@ export class DryRunService {
}
} else {
try {
stubbedMetadata = JSON.parse(rawStubbedMetadata as unknown as string);
stubbedMetadata = JSON.parse(rawStubbedMetadata);
} catch {
stubbedMetadata = rawStubbedMetadata;
throw new Error('fail to parse --metadata');
}
}
}
Expand Down Expand Up @@ -340,6 +340,7 @@ export class DryRunService {
};
}
console.log('---');

const results = await this.runScript({
syncName,
nangoProps,
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/lib/services/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Nango } from '@nangohq/node';
import type { ProxyConfiguration } from '@nangohq/runner-sdk';
import { InvalidRecordSDKError, NangoActionBase, NangoSyncBase } from '@nangohq/runner-sdk';
import type { AdminAxiosProps } from '@nangohq/node';
import type { DryRunServiceInterface, Metadata, NangoProps, UserLogParameters } from '@nangohq/types';
import type { Metadata, NangoProps, UserLogParameters } from '@nangohq/types';
import type { AxiosResponse } from 'axios';
import type { DryRunService } from './dryrun.service';

const logLevelToLogger = {
info: 'info',
Expand All @@ -17,10 +18,10 @@ const logLevelToLogger = {

export class NangoActionCLI extends NangoActionBase {
nango: Nango;
dryRunService: DryRunServiceInterface;
dryRunService: DryRunService;
dryRun = true;

constructor(props: NangoProps, cliProps: { dryRunService: DryRunServiceInterface }) {
constructor(props: NangoProps, cliProps: { dryRunService: DryRunService }) {
super(props);

this.dryRunService = cliProps.dryRunService;
Expand Down Expand Up @@ -87,7 +88,7 @@ export class NangoActionCLI extends NangoActionBase {

export class NangoSyncCLI extends NangoSyncBase {
nango: Nango;
dryRunService: DryRunServiceInterface;
dryRunService: DryRunService;
dryRun = true;

logMessages: { counts: { updated: number; added: number; deleted: number }; messages: unknown[] } = {
Expand All @@ -99,7 +100,7 @@ export class NangoSyncCLI extends NangoSyncBase {
rawDeleteOutput = new Map<string, unknown[]>();
stubbedMetadata?: Metadata | undefined = undefined;

constructor(props: NangoProps, cliProps: { stubbedMetadata?: Metadata | undefined; dryRunService: DryRunServiceInterface }) {
constructor(props: NangoProps, cliProps: { stubbedMetadata?: Metadata | undefined; dryRunService: DryRunService }) {
super(props);

if (cliProps.stubbedMetadata) {
Expand Down
1 change: 0 additions & 1 deletion packages/connect-ui/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */

import type { ApiError, Endpoint, GetConnectSession, GetPublicListIntegrations, GetPublicProvider } from '@nangohq/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ exports.config = { transaction: false };
exports.up = async function (knex) {
let id = 0;

// eslint-disable-next-line no-constant-condition
while (true) {
const environments = await knex.select('*').from('_nango_environments').where('id', '>', id).orderBy('id').limit(100);

Expand Down
2 changes: 1 addition & 1 deletion packages/persist/lib/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ tracer.use('elasticsearch', {
});
tracer.use('express');
tracer.use('dns', {
enabled: false
enabled: true
});
5 changes: 0 additions & 5 deletions packages/runner-sdk/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ interface RunArgs {
optionalEnvironment?: string;
optionalProviderConfigKey?: string;
}
export interface DryRunServiceInterface {
run: (options: RunArgs, debug?: boolean) => Promise<string | void>;
}
export interface NangoProps {
scriptType: 'sync' | 'action' | 'webhook' | 'on-event';
host?: string;
Expand Down Expand Up @@ -247,7 +244,6 @@ export interface NangoProps {
rawDeleteOutput?: Map<string, unknown[]> | undefined;
stubbedMetadata?: Metadata | undefined;
abortSignal?: AbortSignal;
dryRunService?: DryRunServiceInterface;
syncConfig: DBSyncConfig;
runnerFlags: RunnerFlags;
debug: boolean;
Expand Down Expand Up @@ -282,7 +278,6 @@ export declare class NangoAction {
syncJobId?: number;
dryRun?: boolean;
abortSignal?: AbortSignal;
dryRunService?: DryRunServiceInterface;
syncConfig?: DBSyncConfig;
runnerFlags: RunnerFlags;
connectionId: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/lib/idle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function idle(): Promise<Result<void>> {
try {
await retryWithBackoff(
async () => {
return await httpFetch({
await httpFetch({
method: 'POST',
url: `${jobsServiceUrl}/runners/${envs.RUNNER_NODE_ID}/idle`
});
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/lib/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function register(): Promise<Result<void>> {
try {
await retryWithBackoff(
async () => {
return await httpFetch({
await httpFetch({
method: 'POST',
url: `${jobsServiceUrl}/runners/${envs.RUNNER_NODE_ID}/register`,
data: JSON.stringify({ url: envs.RUNNER_URL })
Expand Down
2 changes: 1 addition & 1 deletion packages/scheduler/lib/workers/cleanup/cleanup.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class CleanupChild {

async start(): Promise<void> {
logger.info('Starting cleanup...');
// eslint-disable-next-line no-constant-condition

while (!this.cancelled) {
await this.clean();
await setTimeout(this.tickIntervalMs);
Expand Down
2 changes: 1 addition & 1 deletion packages/scheduler/lib/workers/monitor/monitor.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class MonitorChild {

async start(): Promise<void> {
logger.info('Starting monitor...');
// eslint-disable-next-line no-constant-condition

while (!this.cancelled) {
await this.expires();
await setTimeout(this.tickIntervalMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class SchedulingChild {

async start(): Promise<void> {
logger.info('Starting scheduling...');
// eslint-disable-next-line no-constant-condition

while (!this.cancelled) {
await this.schedule();
await setTimeout(this.tickIntervalMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const postInternalConnectSessions = asyncWrapper<PostInternalConnectSessi
const body: PostInternalConnectSessions['Body'] = valBody.data;

// req.body is never but we want to fake it on purpose
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment

req.body = {
allowed_integrations: body.allowed_integrations,
end_user: body.end_user,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/refreshConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function exec(): Promise<void> {

let cursor = undefined;
const limit = 1000;
// eslint-disable-next-line no-constant-condition

while (true) {
const staleConnections = await connectionService.getStaleConnections({ days: 1, limit, cursor });
logger.info(`${cronName} found ${staleConnections.length} stale connections`);
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/webhook/checkr-webhook-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function validate(integration: ProviderConfig, headerSignature: string, rawBody:

const route: WebhookHandler = async (nango, integration, headers, body, rawBody, logContextGetter: LogContextGetter) => {
const signature = headers['x-checkr-signature'];
if (!signature) {
logger.error('missing signature', { configId: integration.id });
return;
}

logger.info('received', { configId: integration.id });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Webhook route unit tests', () => {
const createdHash = crypto.createHash('sha256').update(combinedSignature).digest('hex');
const headers = { 'x-hubspot-signature': createdHash };

await HubspotWebhookRouting.default(nangoMock as unknown as Nango, integration as ProviderConfig, headers, body, body.toString(), logContextGetter);
await HubspotWebhookRouting.default(nangoMock as unknown as Nango, integration as ProviderConfig, headers, body, '', logContextGetter);

expect(nangoMock.executeScriptForWebhooks).toHaveBeenCalledTimes(body.length);

Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Webhook route unit tests', () => {
const createdHash = crypto.createHash('sha256').update(combinedSignature).digest('hex');
const headers = { 'x-hubspot-signature': createdHash };

await HubspotWebhookRouting.default(nangoMock as unknown as Nango, integration as ProviderConfig, headers, body, body.toString(), logContextGetter);
await HubspotWebhookRouting.default(nangoMock as unknown as Nango, integration as ProviderConfig, headers, body, '', logContextGetter);

expect(nangoMock.executeScriptForWebhooks).toHaveBeenCalledTimes(body.length);

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/webhook/internal-nango.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface InternalNango {
getWebhooks: (environment_id: number, nango_config_id: number) => Promise<SyncConfig[]>;
executeScriptForWebhooks(
integration: ProviderConfig,
body: any,
body: Record<string, any>,
webhookType: string,
connectionIdentifier: string,
logContextGetter: LogContextGetter,
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/webhook/linear-webhook-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function validate(integration: ProviderConfig, headerSignature: string, rawBody:

const route: WebhookHandler = async (nango, integration, headers, body, rawBody, logContextGetter: LogContextGetter) => {
const signature = headers['linear-signature'];
if (!signature) {
logger.error('missing signature', { configId: integration.id });
return;
}

logger.info('received', { configId: integration.id });

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/webhook/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { InternalNango } from './internal-nango.js';
export type WebhookHandler<T = any> = (
internalNango: InternalNango,
integration: ProviderConfig,
headers: Record<string, any>,
headers: Record<string, string>,
body: T,
rawBody: string,
logContextGetter: LogContextGetter
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/services/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ class ConnectionService {
const { success, error, response: connection } = await this.getConnection(connectionId, providerConfigKey, environmentId);

if (!success || !connection) {
throw error;
throw error as NangoError;
}

const shouldRefresh = await this.shouldRefreshCredentials(
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/lib/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class NangoError extends Error {

case 'generic_error_support':
this.status = 500;
this.message = 'An error occurred. Please contact support with this unique id: ' + this.payload;
this.message = `An error occurred. Please contact support with this unique id: ${JSON.stringify(this.payload)}`;
break;

case 'sync_interval_too_short':
Expand Down Expand Up @@ -454,7 +454,7 @@ export class NangoError extends Error {

case 'deploy_missing_json_schema_model':
this.status = 400;
this.message = String(this.payload);
this.message = JSON.stringify(this.payload);
break;

case 'invalid_action_input':
Expand Down Expand Up @@ -504,7 +504,7 @@ export class NangoError extends Error {

case 'wsse_token_generation_error':
this.status = 500;
this.message = `An error occured while generating an WSSE token`;
this.message = `An error occurred while generating an WSSE token`;
break;

case 'script_aborted':
Expand Down
4 changes: 0 additions & 4 deletions packages/types/lib/runner/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export interface RunArgs {
optionalProviderConfigKey?: string;
}

export interface DryRunServiceInterface {
run: (options: RunArgs, debug?: boolean) => Promise<string | void>;
}

export interface NangoProps {
scriptType: 'sync' | 'action' | 'webhook' | 'on-event';
host?: string;
Expand Down
6 changes: 5 additions & 1 deletion packages/webapp/src/pages/Environment/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,13 @@ export const EnvironmentSettings: React.FC = () => {
const entries = Array.from(formData.entries());
for (let i = 0; i < entries.length - 1; i = i + 2) {
const [[, header], [, value]] = entries.slice(i, i + 2);
if (typeof header !== 'string') {
continue;
}

newOtlpHeaders = {
...newOtlpHeaders,
[header.toString()]: value
[header]: value
};
}
return newOtlpHeaders;
Expand Down
Loading
Loading