Skip to content

Commit

Permalink
fix(syncConfigs): handle new model_schema + display in the UI (#2404)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes
https://linear.app/nango/issue/NAN-1270/missing-data-in-api-ref-generation
Fixes https://linear.app/nango/issue/NAN-1292/show-types-in-ui

- Correctly show new model in the UI 
You can test using your own scripts and try with a new provider checking
the available templates

- Update `config.service.ts` to return a StandardNangoConfig without
going through unnecessary parsing
We were fetching from the DB and then passing through the parsing again
for no reason except outputting the same type. It's confusing and
prevent me to get rid of the nango-config.service.ts, so I slightly
rewrote the formatter to make it output the right format directly. I
also grouped the 3 functions that were querying the same data with
different params.
  • Loading branch information
bodinsamuel committed Jun 27, 2024
1 parent 183086d commit 1f8cd76
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 535 deletions.
6 changes: 3 additions & 3 deletions packages/server/lib/controllers/config.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { isHosted } from '@nangohq/utils';
import type { Template as ProviderTemplate, AuthModeType } from '@nangohq/types';
import {
flowService,
getConfigWithEndpointsByProviderConfigKey,
errorManager,
NangoError,
analytics,
Expand All @@ -22,7 +21,8 @@ import {
getUniqueSyncsByProviderConfig,
getActionsByProviderConfigKey,
getFlowConfigsByParams,
getGlobalWebhookReceiveUrl
getGlobalWebhookReceiveUrl,
getSyncConfigsAsStandardConfig
} from '@nangohq/shared';
import { getOrchestrator, parseConnectionConfigParamsFromTemplate } from '../utils/utils.js';
import type { RequestLocals } from '../utils/express.js';
Expand Down Expand Up @@ -386,7 +386,7 @@ class ConfigController {
if (includeFlows && !isHosted) {
const availablePublicFlows = flowService.getAllAvailableFlowsAsStandardConfig();
const [publicFlows] = availablePublicFlows.filter((flow) => flow.providerConfigKey === config.provider);
const allFlows = await getConfigWithEndpointsByProviderConfigKey(environmentId, providerConfigKey);
const allFlows = await getSyncConfigsAsStandardConfig(environmentId, providerConfigKey);

if (availablePublicFlows.length && publicFlows && allFlows) {
const { disabledFlows, flows } = getEnabledAndDisabledFlows(publicFlows, allFlows);
Expand Down
9 changes: 4 additions & 5 deletions packages/server/lib/controllers/flow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import {
deployPreBuilt as deployPreBuiltSyncConfig,
syncManager,
remoteFileService,
getAllSyncsAndActions,
getNangoConfigIdAndLocationFromId,
getConfigWithEndpointsByProviderConfigKeyAndName,
getSyncsByConnectionIdsAndEnvironmentIdAndSyncName,
enableScriptConfig as enableConfig,
disableScriptConfig as disableConfig,
environmentService
environmentService,
getSyncConfigsAsStandardConfig
} from '@nangohq/shared';
import { logContextGetter } from '@nangohq/logs';
import type { RequestLocals } from '../utils/express.js';
Expand Down Expand Up @@ -179,7 +178,7 @@ class FlowController {
try {
const environmentId = res.locals['environment'].id;

const nangoConfigs = await getAllSyncsAndActions(environmentId);
const nangoConfigs = await getSyncConfigsAsStandardConfig(environmentId);

res.send(nangoConfigs);
} catch (e) {
Expand Down Expand Up @@ -277,7 +276,7 @@ class FlowController {

const flow = flowService.getSingleFlowAsStandardConfig(flowName);
const provider = await configService.getProviderName(providerConfigKey);
const flowConfig = await getConfigWithEndpointsByProviderConfigKeyAndName(environment.id, providerConfigKey, flowName);
const flowConfig = await getSyncConfigsAsStandardConfig(environment.id, providerConfigKey, flowName);

res.send({ flowConfig, unEnabledFlow: flow, provider });
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/lib/models/NangoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface NangoIntegrationDataV1 {
type?: ScriptTypeLiteral;
runs: string;
returns: string[];
input?: string;
input?: string | undefined;
track_deletes?: boolean;
auto_start?: boolean;
attributes?: object;
Expand Down Expand Up @@ -127,7 +127,7 @@ export interface NangoSyncConfig {
id?: number;

// v2 additions
input?: NangoSyncModel;
input?: NangoSyncModel | undefined;
sync_type?: SyncType;
nango_yaml_version?: string;
webhookSubscriptions?: string[];
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/lib/models/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { JSONSchema7 } from 'json-schema';
import type { HTTP_VERB, Timestamps, TimestampsAndDeleted } from './Generic.js';
import type { NangoProps } from '../sdk/sync.js';
import type { NangoIntegrationData } from './NangoConfig.js';
import type { NangoConfigMetadata, NangoSyncEndpoint, ScriptTypeLiteral } from '@nangohq/types';
import type { NangoConfigMetadata, NangoModel, NangoSyncEndpoint, ScriptTypeLiteral } from '@nangohq/types';
import type { LogContext } from '@nangohq/logs';

export enum SyncStatus {
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface SyncConfig extends TimestampsAndDeleted {
file_location: string;
nango_config_id: number;
models: string[];
model_schema: SyncModelSchema[];
model_schema: SyncModelSchema[] | NangoModel[];
active: boolean;
runs: string;
track_deletes: boolean;
Expand All @@ -100,7 +100,7 @@ export interface SyncConfig extends TimestampsAndDeleted {
pre_built?: boolean | null;
is_public?: boolean | null;
endpoints?: NangoSyncEndpoint[];
input?: string | SyncModelSchema | undefined;
input?: string | undefined;
sync_type?: SyncType | undefined;
webhook_subscriptions: string[] | null;
enabled: boolean;
Expand Down
Loading

0 comments on commit 1f8cd76

Please sign in to comment.