Skip to content

Commit

Permalink
Merge branch 'master' into alan/delete-integration-connections-cached
Browse files Browse the repository at this point in the history
  • Loading branch information
nalanj authored Nov 27, 2024
2 parents b6fd8c6 + b10f38a commit 9fc8c93
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ describe(`POST ${endpoint}`, () => {
isSuccess(res.json);

expect(res.json).toStrictEqual<typeof res.json>([
{ 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);

Expand All @@ -151,6 +152,7 @@ describe(`POST ${endpoint}`, () => {
expect(syncConfigs).toStrictEqual([
{
actions: [],
'on-events': [],
provider: 'unauthenticated',
providerConfigKey: 'unauthenticated',
syncs: [
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/models/NangoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@ export interface StandardNangoConfig {
provider?: string;
syncs: NangoSyncConfig[];
actions: NangoSyncConfig[];
[`on-events`]: NangoSyncConfig[];
}
3 changes: 2 additions & 1 deletion packages/shared/lib/services/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class FlowService {
const std: StandardNangoConfig = {
providerConfigKey,
actions: [],
syncs: []
syncs: [],
[`on-events`]: []
};

for (const item of [...integration.actions, ...integration.syncs]) {
Expand Down
15 changes: 12 additions & 3 deletions packages/shared/lib/services/on-event-scripts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const onEventScriptService = {
environment: DBEnvironment;
account: DBTeam;
onEventScriptsByProvider: OnEventScriptsByProvider[];
}): Promise<void> {
await db.knex.transaction(async (trx) => {
}): Promise<(OnEventScript & { providerConfigKey: string })[]> {
return db.knex.transaction(async (trx) => {
const onEventInserts: Omit<OnEventScript, 'id' | 'created_at' | 'updated_at'>[] = [];

// Deactivate all previous scripts for the environment
Expand Down Expand Up @@ -84,8 +84,17 @@ export const onEventScriptService = {
}
}
if (onEventInserts.length > 0) {
await trx.insert(onEventInserts).into(TABLE);
type R = Awaited<ReturnType<typeof onEventScriptService.update>>;
const res = await trx
.with('inserted', (qb) => {
qb.insert(onEventInserts).into(TABLE).returning('*');
})
.select<R>(['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<OnEventScript[]> => {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/lib/services/sync/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function convertSyncConfigToStandardConfig(syncConfigs: ExtendedSyncConfig[]): S
actions: [],
providerConfigKey: syncConfig.unique_key,
provider: syncConfig.provider,
syncs: []
syncs: [],
[`on-events`]: []
};
}

Expand Down
12 changes: 11 additions & 1 deletion packages/shared/lib/services/sync/config/deploy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/lib/nangoYaml/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9fc8c93

Please sign in to comment.