diff --git a/packages/bruno-app/src/components/ShareCollection/index.js b/packages/bruno-app/src/components/ShareCollection/index.js index 5e958dd31..86f28ca16 100644 --- a/packages/bruno-app/src/components/ShareCollection/index.js +++ b/packages/bruno-app/src/components/ShareCollection/index.js @@ -10,8 +10,10 @@ import { cloneDeep } from 'lodash'; import { transformCollectionToSaveToExportAsFile } from 'utils/collections/index'; import { useSelector } from 'react-redux'; import { findCollectionByUid, areItemsLoading } from 'utils/collections/index'; +import { useApp } from 'providers/App'; const ShareCollection = ({ onClose, collectionUid }) => { + const { version } = useApp(); const collection = useSelector((state) => findCollectionByUid(state.collections.collections, collectionUid)); const isCollectionLoading = areItemsLoading(collection); @@ -39,7 +41,7 @@ const ShareCollection = ({ onClose, collectionUid }) => { const handleExportBrunoCollection = () => { const collectionCopy = cloneDeep(collection); - exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy)); + exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy), version); onClose(); }; @@ -51,7 +53,7 @@ const ShareCollection = ({ onClose, collectionUid }) => { const handleExportOpenCollection = () => { const collectionCopy = cloneDeep(collection); - exportOpenCollection(transformCollectionToSaveToExportAsFile(collectionCopy)); + exportOpenCollection(transformCollectionToSaveToExportAsFile(collectionCopy), version); onClose(); }; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ExportCollection/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ExportCollection/index.js deleted file mode 100644 index cdc400b65..000000000 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ExportCollection/index.js +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import exportBrunoCollection from 'utils/collections/export'; -import exportPostmanCollection from 'utils/exporters/postman-collection'; -import cloneDeep from 'lodash/cloneDeep'; -import Modal from 'components/Modal'; -import { transformCollectionToSaveToExportAsFile } from 'utils/collections/index'; - -const ExportCollection = ({ onClose, collection }) => { - const handleExportBrunoCollection = () => { - const collectionCopy = cloneDeep(collection); - exportBrunoCollection(transformCollectionToSaveToExportAsFile(collectionCopy)); - onClose(); - }; - - const handleExportPostmanCollection = () => { - const collectionCopy = cloneDeep(collection); - exportPostmanCollection(collectionCopy); - onClose(); - }; - - return ( - -
-
- Bruno Collection -
-
- Postman Collection -
-
-
- ); -}; - -export default ExportCollection; diff --git a/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js b/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js index 6fdd98336..85d49ab99 100644 --- a/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js +++ b/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js @@ -57,8 +57,8 @@ const WorkspaceOverview = ({ workspace }) => { setImportCollectionLocationModalOpen(true); }; - const handleImportCollectionLocation = (convertedCollection, collectionLocation) => { - dispatch(importCollection(convertedCollection, collectionLocation)) + const handleImportCollectionLocation = (convertedCollection, collectionLocation, options = {}) => { + dispatch(importCollection(convertedCollection, collectionLocation, options)) .then(() => { setImportCollectionLocationModalOpen(false); setImportData(null); diff --git a/packages/bruno-app/src/utils/collections/export.js b/packages/bruno-app/src/utils/collections/export.js index 53d4dc63b..669446a29 100644 --- a/packages/bruno-app/src/utils/collections/export.js +++ b/packages/bruno-app/src/utils/collections/export.js @@ -93,7 +93,7 @@ export const deleteSecretsInEnvs = (envs) => { }); }; -export const exportCollection = (collection) => { +export const exportCollection = (collection, version) => { // delete uids delete collection.uid; @@ -105,6 +105,9 @@ export const exportCollection = (collection) => { deleteSecretsInEnvs(collection.environments); transformItem(collection.items); + collection.exportedAt = new Date().toISOString(); + collection.exportedUsing = version ? `Bruno/${version}` : 'Bruno'; + const fileName = `${collection.name}.json`; const fileBlob = new Blob([JSON.stringify(collection, null, 2)], { type: 'application/json' }); diff --git a/packages/bruno-app/src/utils/exporters/opencollection.js b/packages/bruno-app/src/utils/exporters/opencollection.js index d3fcc5b55..93f996540 100644 --- a/packages/bruno-app/src/utils/exporters/opencollection.js +++ b/packages/bruno-app/src/utils/exporters/opencollection.js @@ -3,9 +3,18 @@ import jsyaml from 'js-yaml'; import { brunoToOpenCollection } from '@usebruno/converters'; import { sanitizeName } from 'utils/common/regex'; -export const exportCollection = (collection) => { +export const exportCollection = (collection, version) => { const openCollection = brunoToOpenCollection(collection); + if (!openCollection.extensions) { + openCollection.extensions = {}; + } + if (!openCollection.extensions.bruno) { + openCollection.extensions.bruno = {}; + } + openCollection.extensions.bruno.exportedAt = new Date().toISOString(); + openCollection.extensions.bruno.exportedUsing = version ? `Bruno/${version}` : 'Bruno'; + const yamlContent = jsyaml.dump(openCollection, { indent: 2, lineWidth: -1, diff --git a/packages/bruno-app/src/utils/importers/bruno-collection.js b/packages/bruno-app/src/utils/importers/bruno-collection.js index 6757d0e8a..c5ebc007b 100644 --- a/packages/bruno-app/src/utils/importers/bruno-collection.js +++ b/packages/bruno-app/src/utils/importers/bruno-collection.js @@ -1,9 +1,16 @@ import { BrunoError } from 'utils/common/error'; import { validateSchema, transformItemsInCollection, updateUidsInCollection, hydrateSeqInCollection } from './common'; +const stripExportMetadata = (collection) => { + delete collection.exportedAt; + delete collection.exportedUsing; + return collection; +}; + export const processBrunoCollection = async (jsonData) => { try { - let collection = hydrateSeqInCollection(jsonData); + let collection = stripExportMetadata(jsonData); + collection = hydrateSeqInCollection(collection); collection = updateUidsInCollection(collection); collection = transformItemsInCollection(collection); await validateSchema(collection); diff --git a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts index 159c8566a..3cdbf6688 100644 --- a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts +++ b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts @@ -145,12 +145,33 @@ export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollecti openCollection.bundled = true; - const extensions: { ignore?: string[] } = {}; + const brunoExtension: { + ignore?: string[]; + presets?: { + requestType?: string; + requestUrl?: string; + }; + } = {}; + if ((collection.brunoConfig as BrunoConfig)?.ignore?.length) { - extensions.ignore = (collection.brunoConfig as BrunoConfig).ignore; + brunoExtension.ignore = (collection.brunoConfig as BrunoConfig).ignore; } - if (Object.keys(extensions).length > 0) { - openCollection.extensions = extensions; + + const presets = (collection.brunoConfig as BrunoConfig)?.presets; + if (presets?.requestType || presets?.requestUrl) { + brunoExtension.presets = {}; + if (presets.requestType) { + brunoExtension.presets.requestType = presets.requestType; + } + if (presets.requestUrl) { + brunoExtension.presets.requestUrl = presets.requestUrl; + } + } + + if (Object.keys(brunoExtension).length > 0) { + openCollection.extensions = { + bruno: brunoExtension + }; } return openCollection; diff --git a/packages/bruno-converters/src/opencollection/common/auth.ts b/packages/bruno-converters/src/opencollection/common/auth.ts index 3266f434e..c6a24c479 100644 --- a/packages/bruno-converters/src/opencollection/common/auth.ts +++ b/packages/bruno-converters/src/opencollection/common/auth.ts @@ -60,16 +60,16 @@ const fromOpenCollectionOAuth2 = (auth: AuthOAuth2): BrunoAuth => { clientSecret: base.clientSecret || null, scope: base.scope || null, state: base.state || null, - pkce: base.pkce || null, + pkce: base.pkce ?? false, credentialsPlacement: base.credentialsPlacement || null, credentialsId: base.credentialsId || null, tokenPlacement: base.tokenPlacement || null, tokenHeaderPrefix: base.tokenHeaderPrefix || null, tokenQueryKey: base.tokenQueryKey || null, refreshTokenUrl: base.refreshTokenUrl || null, - autoRefreshToken: base.autoRefreshToken || null, - autoFetchToken: base.autoFetchToken || null, - additionalParameters: null + autoRefreshToken: base.autoRefreshToken ?? false, + autoFetchToken: base.autoFetchToken ?? false, + additionalParameters: {} }, wsse: null, apikey: null diff --git a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts index 89e187748..76a8c476b 100644 --- a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts +++ b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts @@ -7,9 +7,16 @@ import { fromOpenCollectionFolder } from "./folder"; import { fromOpenCollectionEnvironments } from "./environment"; const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => { - const extensions = oc.extensions; - const ignoreList = extensions && Array.isArray(extensions.ignore) - ? extensions.ignore as string[] + const brunoExtension = oc.extensions?.bruno as { + ignore?: string[]; + presets?: { + requestType?: string; + requestUrl?: string; + }; + } | undefined; + + const ignoreList = brunoExtension && Array.isArray(brunoExtension.ignore) + ? brunoExtension.ignore : ['node_modules', '.git']; const brunoConfig: BrunoConfig = { @@ -19,6 +26,16 @@ const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => { ignore: ignoreList }; + if (brunoExtension?.presets?.requestType || brunoExtension?.presets?.requestUrl) { + brunoConfig.presets = {}; + if (brunoExtension.presets.requestType) { + brunoConfig.presets.requestType = brunoExtension.presets.requestType; + } + if (brunoExtension.presets.requestUrl) { + brunoConfig.presets.requestUrl = brunoExtension.presets.requestUrl; + } + } + const config = oc.config; if (!config) { return brunoConfig; diff --git a/packages/bruno-converters/src/opencollection/types.ts b/packages/bruno-converters/src/opencollection/types.ts index 34c9492e7..07d5d6848 100644 --- a/packages/bruno-converters/src/opencollection/types.ts +++ b/packages/bruno-converters/src/opencollection/types.ts @@ -171,6 +171,10 @@ export interface BrunoConfig { name?: string; type?: string; ignore?: string[]; + presets?: { + requestType?: string; + requestUrl?: string; + }; protobuf?: { protoFiles?: { path: string }[]; importPaths?: { path: string; disabled?: boolean }[];