From b10f38aa1088757ceda42dfc503c6dd9d6ca40a9 Mon Sep 17 00:00:00 2001
From: Thomas Bonnin <233326+TBonnin@users.noreply.github.com>
Date: Wed, 27 Nov 2024 08:31:01 -0500
Subject: [PATCH] fix(cli): show on-events scripts in nango deploy output
(#3067)
`on-events` scripts were not shown in the CLI `nango deploy` output.
Now:
`setup` and `cleanup` are the on-event scripts. Note that the versioning
scheme for `on-events` is different from syncs/actions, not sure why.
How to test:
1. install cli local package: `npm install PATH/TO/REPO/packages/cli
-g`. Might need to uninstall it before.
2. Have a integration setup with some `on-events` scripts
3. Run `nango deploy dev`
---
.../sync/deploy/postDeploy.integration.test.ts | 4 +++-
packages/shared/lib/models/NangoConfig.ts | 1 +
packages/shared/lib/services/flow.service.ts | 3 ++-
.../lib/services/on-event-scripts.service.ts | 15 ++++++++++++---
.../lib/services/sync/config/config.service.ts | 3 ++-
.../lib/services/sync/config/deploy.service.ts | 12 +++++++++++-
packages/types/lib/nangoYaml/index.ts | 2 +-
7 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts b/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts
index eb7dc590bd..552c3cc42c 100644
--- a/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts
+++ b/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts
@@ -141,7 +141,8 @@ describe(`POST ${endpoint}`, () => {
isSuccess(res.json);
expect(res.json).toStrictEqual([
- { models: ['Output'], name: 'test', providerConfigKey: 'unauthenticated', type: 'sync', version: '1' }
+ { models: ['Output'], name: 'test', providerConfigKey: 'unauthenticated', type: 'sync', version: '1' },
+ { models: [], name: 'test', providerConfigKey: 'unauthenticated', type: 'on-event', version: '0.0.1' }
]);
expect(res.res.status).toBe(200);
@@ -151,6 +152,7 @@ describe(`POST ${endpoint}`, () => {
expect(syncConfigs).toStrictEqual([
{
actions: [],
+ 'on-events': [],
provider: 'unauthenticated',
providerConfigKey: 'unauthenticated',
syncs: [
diff --git a/packages/shared/lib/models/NangoConfig.ts b/packages/shared/lib/models/NangoConfig.ts
index 80f7439e96..28991fcfb1 100644
--- a/packages/shared/lib/models/NangoConfig.ts
+++ b/packages/shared/lib/models/NangoConfig.ts
@@ -139,4 +139,5 @@ export interface StandardNangoConfig {
provider?: string;
syncs: NangoSyncConfig[];
actions: NangoSyncConfig[];
+ [`on-events`]: NangoSyncConfig[];
}
diff --git a/packages/shared/lib/services/flow.service.ts b/packages/shared/lib/services/flow.service.ts
index be3b3a6cae..c923e33a64 100644
--- a/packages/shared/lib/services/flow.service.ts
+++ b/packages/shared/lib/services/flow.service.ts
@@ -62,7 +62,8 @@ class FlowService {
const std: StandardNangoConfig = {
providerConfigKey,
actions: [],
- syncs: []
+ syncs: [],
+ [`on-events`]: []
};
for (const item of [...integration.actions, ...integration.syncs]) {
diff --git a/packages/shared/lib/services/on-event-scripts.service.ts b/packages/shared/lib/services/on-event-scripts.service.ts
index d69eddc3d2..d68da35c3b 100644
--- a/packages/shared/lib/services/on-event-scripts.service.ts
+++ b/packages/shared/lib/services/on-event-scripts.service.ts
@@ -25,8 +25,8 @@ export const onEventScriptService = {
environment: DBEnvironment;
account: DBTeam;
onEventScriptsByProvider: OnEventScriptsByProvider[];
- }): Promise {
- await db.knex.transaction(async (trx) => {
+ }): Promise<(OnEventScript & { providerConfigKey: string })[]> {
+ return db.knex.transaction(async (trx) => {
const onEventInserts: Omit[] = [];
// Deactivate all previous scripts for the environment
@@ -84,8 +84,17 @@ export const onEventScriptService = {
}
}
if (onEventInserts.length > 0) {
- await trx.insert(onEventInserts).into(TABLE);
+ type R = Awaited>;
+ const res = await trx
+ .with('inserted', (qb) => {
+ qb.insert(onEventInserts).into(TABLE).returning('*');
+ })
+ .select(['inserted.*', '_nango_configs.unique_key as providerConfigKey'])
+ .from('inserted')
+ .join('_nango_configs', 'inserted.config_id', '_nango_configs.id');
+ return res;
}
+ return [];
});
},
getByConfig: async (configId: number, event: OnEventType): Promise => {
diff --git a/packages/shared/lib/services/sync/config/config.service.ts b/packages/shared/lib/services/sync/config/config.service.ts
index 77b5db05a4..30098ded39 100644
--- a/packages/shared/lib/services/sync/config/config.service.ts
+++ b/packages/shared/lib/services/sync/config/config.service.ts
@@ -24,7 +24,8 @@ function convertSyncConfigToStandardConfig(syncConfigs: ExtendedSyncConfig[]): S
actions: [],
providerConfigKey: syncConfig.unique_key,
provider: syncConfig.provider,
- syncs: []
+ syncs: [],
+ [`on-events`]: []
};
}
diff --git a/packages/shared/lib/services/sync/config/deploy.service.ts b/packages/shared/lib/services/sync/config/deploy.service.ts
index ad2f1677ea..076011fbc3 100644
--- a/packages/shared/lib/services/sync/config/deploy.service.ts
+++ b/packages/shared/lib/services/sync/config/deploy.service.ts
@@ -180,7 +180,17 @@ export async function deploy({
}
if (onEventScriptsByProvider) {
- await onEventScriptService.update({ environment, account, onEventScriptsByProvider });
+ const updated = await onEventScriptService.update({ environment, account, onEventScriptsByProvider });
+ const result: SyncDeploymentResult[] = updated.map((u) => {
+ return {
+ name: u.name,
+ version: u.version,
+ providerConfigKey: u.providerConfigKey,
+ type: 'on-event',
+ models: []
+ };
+ });
+ deployResults.push(...result);
}
for (const id of idsToMarkAsInactive) {
diff --git a/packages/types/lib/nangoYaml/index.ts b/packages/types/lib/nangoYaml/index.ts
index ca14c0ecc2..711c41d71e 100644
--- a/packages/types/lib/nangoYaml/index.ts
+++ b/packages/types/lib/nangoYaml/index.ts
@@ -1,7 +1,7 @@
export type HTTP_METHOD = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
export type SyncTypeLiteral = 'incremental' | 'full';
export type ScriptFileType = 'actions' | 'syncs' | 'on-events' | 'post-connection-scripts'; // post-connection-scripts is deprecated
-export type ScriptTypeLiteral = 'action' | 'sync';
+export type ScriptTypeLiteral = 'action' | 'sync' | 'on-event';
// --------------
// YAML V1