diff --git a/package-lock.json b/package-lock.json index 79f3de50..cf7a7d95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12178,6 +12178,14 @@ "xml2js": "^0.4.5" } }, + "node_modules/parse-curl": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/parse-curl/-/parse-curl-0.2.6.tgz", + "integrity": "sha512-ENhXeIxG4A6wFvYSU87b0o3Tp6U+Wup069GYhXCn0ZP/E7evfvomTSM/MeEOs3QTyuye+u2r7fFRj6nX0q9kQA==", + "dependencies": { + "shellwords": "^0.1.0" + } + }, "node_modules/parse-headers": { "version": "2.0.5", "dev": true, @@ -14515,6 +14523,11 @@ "node": ">=8" } }, + "node_modules/shellwords": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", + "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==" + }, "node_modules/side-channel": { "version": "1.0.4", "license": "MIT", @@ -16470,6 +16483,7 @@ "mousetrap": "^1.6.5", "nanoid": "3.3.4", "next": "12.3.3", + "parse-curl": "^0.2.6", "path": "^0.12.7", "platform": "^1.3.6", "posthog-node": "^2.1.0", @@ -20540,6 +20554,7 @@ "mousetrap": "^1.6.5", "nanoid": "3.3.4", "next": "12.3.3", + "parse-curl": "*", "path": "^0.12.7", "platform": "^1.3.6", "posthog-node": "^2.1.0", @@ -25603,6 +25618,14 @@ "xml2js": "^0.4.5" } }, + "parse-curl": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/parse-curl/-/parse-curl-0.2.6.tgz", + "integrity": "sha512-ENhXeIxG4A6wFvYSU87b0o3Tp6U+Wup069GYhXCn0ZP/E7evfvomTSM/MeEOs3QTyuye+u2r7fFRj6nX0q9kQA==", + "requires": { + "shellwords": "^0.1.0" + } + }, "parse-headers": { "version": "2.0.5", "dev": true @@ -27036,6 +27059,11 @@ "version": "3.0.0", "dev": true }, + "shellwords": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", + "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==" + }, "side-channel": { "version": "1.0.4", "requires": { diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index c3f82569..77ff96b6 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -42,6 +42,7 @@ "mousetrap": "^1.6.5", "nanoid": "3.3.4", "next": "12.3.3", + "parse-curl": "^0.2.6", "path": "^0.12.7", "platform": "^1.3.6", "posthog-node": "^2.1.0", diff --git a/packages/bruno-app/src/components/Sidebar/NewRequest/index.js b/packages/bruno-app/src/components/Sidebar/NewRequest/index.js index 2e54b56a..f6bcdfeb 100644 --- a/packages/bruno-app/src/components/Sidebar/NewRequest/index.js +++ b/packages/bruno-app/src/components/Sidebar/NewRequest/index.js @@ -11,6 +11,7 @@ import { addTab } from 'providers/ReduxStore/slices/tabs'; import HttpMethodSelector from 'components/RequestPane/QueryUrl/HttpMethodSelector'; import { getDefaultRequestPaneTab } from 'utils/collections'; import StyledWrapper from './StyledWrapper'; +import { getRequestFromCurlCommand } from 'utils/curl'; const NewRequest = ({ collection, item, isEphemeral, onClose }) => { const dispatch = useDispatch(); @@ -21,7 +22,8 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => { requestName: '', requestType: 'http-request', requestUrl: '', - requestMethod: 'GET' + requestMethod: 'GET', + curlCommand: '' }, validationSchema: Yup.object({ requestName: Yup.string() @@ -35,6 +37,14 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => { const trimmedValue = value ? value.trim().toLowerCase() : ''; return !['collection', 'folder'].includes(trimmedValue); } + }), + curlCommand: Yup.string() + .min(1, 'must be at least 1 character') + .required('curlCommand is required') + .test({ + name: 'curlCommand', + message: `Invalid cURL Command`, + test: (value) => getRequestFromCurlCommand(value) !== null }) }), onSubmit: (values) => { @@ -61,6 +71,22 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => { onClose(); }) .catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request')); + } else if (values.requestType === 'from-curl') { + const request = getRequestFromCurlCommand(values.curlCommand); + dispatch( + newHttpRequest({ + requestName: values.requestName, + requestType: 'http-request', + requestUrl: request.url, + requestMethod: request.method, + collectionUid: collection.uid, + itemUid: item ? item.uid : null, + headers: request.headers, + body: request.body + }) + ) + .then(() => onClose()) + .catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request')); } else { dispatch( newHttpRequest({ @@ -124,9 +150,22 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => { + + + + -