From 55aa337f62f5a5e96d97a81c8b900a4aad10982f Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Fri, 3 Dec 2021 11:14:22 +0000 Subject: [PATCH] Add import to existing DS and add cookie support to curl import --- .../modals/CreateDatasourceModal.svelte | 6 ++++- .../modals/ImportRestQueriesModal.svelte | 10 +++++--- .../[selectedDatasource]/index.svelte | 25 ++++++++++++++++++- .../controllers/query/import/sources/curl.ts | 16 ++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index d52bdb4785..32c8d0502d 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -80,7 +80,11 @@ {#if integration.type === "REST"} - + modal.show()} + /> {/if} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte index a500b24719..cd6cef42d1 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte @@ -16,9 +16,10 @@ import { datasources, queries } from "stores/backend" import { writable } from "svelte/store" - export let modal + export let navigateDatasource = false export let datasourceId export let createDatasource = false + export let onCancel const data = writable({ url: "", @@ -67,7 +68,10 @@ await queries.fetch() await datasources.select(datasourceId) - $goto(`./datasource/${datasourceId}`) + if (navigateDatasource) { + $goto(`./datasource/${datasourceId}`) + } + notifications.success(`Imported successfully.`) analytics.captureEvent(Events.QUERIES.REST.IMPORTED, { importType: lastTouched, @@ -84,7 +88,7 @@ importQueries()} - onCancel={() => modal.show()} + {onCancel} confirmText={"Import"} cancelText="Back" size="L" diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte index 6cbe0c8359..40d0583532 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -17,7 +17,9 @@ import CreateExternalTableModal from "./modals/CreateExternalTableModal.svelte" import ICONS from "components/backend/DatasourceNavigator/icons" import { capitalise } from "helpers" + import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte" + let importQueriesModal let relationshipModal let createExternalTableModal let selectedFromRelationship, selectedToRelationship @@ -131,6 +133,15 @@ /> + + {#if datasource.source === "REST"} + + {/if} + + @@ -246,7 +257,14 @@
Queries - +
+ {#if datasource.source === "REST"} + + {/if} + +
{#each $queries.list.filter(query => query.datasourceId === datasource._id) as query} @@ -293,6 +311,11 @@ margin: 0 0 var(--spacing-s) 0; } + .query-buttons { + display: flex; + gap: var(--spacing-l); + } + .query-list { display: flex; flex-direction: column; diff --git a/packages/server/src/api/controllers/query/import/sources/curl.ts b/packages/server/src/api/controllers/query/import/sources/curl.ts index fd1a25d5db..e4289016c5 100644 --- a/packages/server/src/api/controllers/query/import/sources/curl.ts +++ b/packages/server/src/api/controllers/query/import/sources/curl.ts @@ -27,6 +27,17 @@ const parseBody = (curl: any) => { return undefined } +const parseCookie = (curl: any) => { + if (curl.cookies){ + return Object.entries(curl.cookies).reduce((acc, entry) => { + const [key, value] = entry + return acc + `${key}=${value}; ` + }, "") + } + + return null +} + /** * Curl * https://curl.se/docs/manpage.html @@ -61,6 +72,11 @@ export class Curl extends ImportSource { const headers = this.curl.headers const requestBody = parseBody(this.curl) + const cookieHeader = parseCookie(this.curl) + if (cookieHeader) { + headers["Cookie"] = cookieHeader + } + const query = this.constructQuery( datasourceId, name,