Skip to content

Commit

Permalink
fix(connection): import should reset auth errors (#3558)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel authored Feb 24, 2025
1 parent f9edbf0 commit c469523
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 0 additions & 4 deletions packages/jobs/lib/execution/sync.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ async function seeds(records: UnencryptedRecordData[], trackDeletes: boolean) {

const connection = await seeders.createConnectionSeed({ env, provider: 'github' });

if (!connection.id) {
throw new Error('Failed to create connection');
}

const config = await seeders.createConfigSeed(env, 'github', 'github');
const { syncConfig, sync } = await seeders.createSyncSeeds({
connectionId: connection.id,
Expand Down
15 changes: 12 additions & 3 deletions packages/server/lib/controllers/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { configService, connectionService, errorManager, NangoError, accountServ
import { NANGO_ADMIN_UUID } from './account.controller.js';
import { logContextGetter } from '@nangohq/logs';
import type { RequestLocals } from '../utils/express.js';
import { connectionCreated as connectionCreatedHook, connectionCreationStartCapCheck as connectionCreationStartCapCheckHook } from '../hooks/hooks.js';
import {
connectionCreated as connectionCreatedHook,
connectionCreationStartCapCheck as connectionCreationStartCapCheckHook,
connectionRefreshSuccess
} from '../hooks/hooks.js';
import { getOrchestrator } from '../utils/utils.js';
import { preConnectionDeletion } from '../hooks/connection/on/connection-deleted.js';

Expand Down Expand Up @@ -393,7 +397,7 @@ class ConnectionController {
connection: res.connection,
environment,
account,
auth_mode: 'API_KEY',
auth_mode: 'BASIC',
operation: res.operation,
endUser: undefined
},
Expand Down Expand Up @@ -580,7 +584,7 @@ class ConnectionController {
return;
}

if (updatedConnection && updatedConnection.connection.id && runHook) {
if (updatedConnection && runHook) {
void connectionCreatedHook(
{
connection: updatedConnection.connection,
Expand All @@ -596,6 +600,11 @@ class ConnectionController {
);
}

if (updatedConnection && updatedConnection.operation === 'override') {
// If we updated the connection we assume the connection is now correct
await connectionRefreshSuccess({ connection: updatedConnection.connection, environment, config: integration });
}

res.status(201).send({
...req.body,
connection_id: connectionId
Expand Down
6 changes: 1 addition & 5 deletions packages/server/lib/hooks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,10 @@ export const connectionRefreshSuccess = async ({
environment,
config
}: {
connection: DBConnectionDecrypted;
connection: Pick<DBConnectionDecrypted, 'id' | 'connection_id' | 'provider_config_key' | 'environment_id'>;
environment: DBEnvironment;
config: IntegrationConfig;
}): Promise<void> => {
if (!connection.id) {
return;
}

await errorNotificationService.auth.clear({
connection_id: connection.id
});
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/lib/clients/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ export class Orchestrator {
});
const startTime = Date.now();
try {
if (!connection.id) {
throw new NangoError('invalid_input', { connection });
}

let parsedInput: JsonValue = null;
try {
parsedInput = input ? JSON.parse(JSON.stringify(input)) : null;
Expand Down

0 comments on commit c469523

Please sign in to comment.