From 84bb5b29f01a5e8cf9167f859413b0da86d1f2be Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 13 Feb 2023 15:13:12 +0800 Subject: [PATCH] feat(core): enable creating a new connector with specified id (#3099) --- packages/core/src/routes/connector.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/core/src/routes/connector.ts b/packages/core/src/routes/connector.ts index 48e73143f..9bd1889d6 100644 --- a/packages/core/src/routes/connector.ts +++ b/packages/core/src/routes/connector.ts @@ -128,16 +128,18 @@ export default function connectorRoutes( router.post( '/connectors', koaGuard({ - body: Connectors.createGuard.pick({ - config: true, - connectorId: true, - metadata: true, - syncProfile: true, - }), + body: Connectors.createGuard + .pick({ + config: true, + connectorId: true, + metadata: true, + syncProfile: true, + }) + .merge(Connectors.createGuard.pick({ id: true }).partial()), // `id` is optional }), async (ctx, next) => { const { - body: { connectorId, metadata, config, syncProfile }, + body: { id: proposedId, connectorId, metadata, config, syncProfile }, } = ctx.guard; const connectorFactories = await loadConnectorFactories(); @@ -190,7 +192,7 @@ export default function connectorRoutes( validateConfig(config, rawConnector.configGuard); } - const insertConnectorId = generateConnectorId(); + const insertConnectorId = proposedId ?? generateConnectorId(); await insertConnector({ id: insertConnectorId, connectorId,