Skip to content

Commit

Permalink
Merge branch 'usebruno:main' into handle-invalid-auth-in-pm-export
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaikumar-bruno authored Dec 30, 2024
2 parents e9378d7 + 78aa0d0 commit 4b277aa
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 50 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"ts-jest": "^29.0.5"
},
"scripts": {
"setup": "node ./scripts/setup.js",
"dev": "concurrently --kill-others \"npm run dev:web\" \"npm run dev:electron\"",
"dev:web": "npm run dev --workspace=packages/bruno-app",
"build:web": "npm run build --workspace=packages/bruno-app",
Expand All @@ -51,6 +52,6 @@
"prepare": "husky install"
},
"overrides": {
"rollup":"3.29.5"
"rollup": "3.29.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const formatResponse = (data, mode, filter) => {
}

if (data === null) {
return data;
return 'null';
}

if (mode.includes('json')) {
let isValidJSON = false;

try {
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object';
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'
} catch (error) {
console.log('Error parsing JSON: ', error.message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) =>
// update existing values
variables = variables?.map?.(variable => ({
...variable,
value: stringifyIfNot(globalEnvironmentVariables?.[variable?.name])
value: globalEnvironmentVariables?.[variable?.name]
}));

// add new env values
Expand All @@ -201,7 +201,7 @@ export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) =>
variables.push({
uid: uuid(),
name: key,
value: stringifyIfNot(value),
value,
type: 'text',
secret: false,
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/utils/collections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ export const getGlobalEnvironmentVariables = ({ globalEnvironments, activeGlobal
const environment = globalEnvironments?.find(env => env?.uid === activeGlobalEnvironmentUid);
if (environment) {
each(environment.variables, (variable) => {
if (variable.name && variable.value && variable.enabled) {
if (variable.name && variable.enabled) {
variables[variable.name] = variable.value;
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/bruno-app/src/utils/curl/curl-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getDataString(request) {
console.error('Failed to parse JSON data:', error);
return { data: request.data.toString() };
}
} else if (contentType && contentType.includes('application/xml')) {
} else if (contentType && (contentType.includes('application/xml') || contentType.includes('text/plain'))) {
return { data: request.data };
}

Expand Down Expand Up @@ -174,14 +174,14 @@ const curlToJson = (curlCommand) => {
}

if (request.auth) {
if(request.auth.mode === 'basic'){
if (request.auth.mode === 'basic') {
requestJson.auth = {
mode: 'basic',
basic: {
username: repr(request.auth.basic?.username),
password: repr(request.auth.basic?.password)
}
}
};
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-app/src/utils/importers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export const transformItemsInCollection = (collection) => {
// from 5 feb 2024, multipartFormData needs to have a type
// this was introduced when we added support for file uploads
// below logic is to make older collection exports backward compatible
let multipartFormData = _.get(item, 'request.body.multipartForm');
let multipartFormData = get(item, 'request.body.multipartForm');
if (multipartFormData) {
_.each(multipartFormData, (form) => {
each(multipartFormData, (form) => {
if (!form.type) {
form.type = 'text';
}
Expand Down
3 changes: 1 addition & 2 deletions packages/bruno-cli/src/runner/prepare-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ const prepareRequest = (item = {}, collection = {}) => {
if (request.body.mode === 'multipartForm') {
axiosRequest.headers['content-type'] = 'multipart/form-data';
const enabledParams = filter(request.body.multipartForm, (p) => p.enabled);
const collectionPath = process.cwd();
axiosRequest.data = createFormData(enabledParams, collectionPath);
axiosRequest.data = enabledParams;
}

if (request.body.mode === 'graphql') {
Expand Down
22 changes: 11 additions & 11 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
// rename item
ipcMain.handle('renderer:rename-item', async (event, oldPath, newPath, newName) => {
const tempDir = path.join(os.tmpdir(), `temp-folder-${Date.now()}`);
const parentDir = path.dirname(oldPath);
const isWindowsOSAndNotWSLAndItemHasSubDirectories = isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath);
let parentDirUnwatched = false;
let parentDirRewatched = false;
// const parentDir = path.dirname(oldPath);
const isWindowsOSAndNotWSLAndItemHasSubDirectories = isDirectory(oldPath) && isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath);
// let parentDirUnwatched = false;
// let parentDirRewatched = false;

try {
// Normalize paths if they are WSL paths
Expand All @@ -376,8 +376,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
moveRequestUid(bruFile, newBruFilePath);
}

watcher.unlinkItemPathInWatcher(parentDir);
parentDirUnwatched = true;
// watcher.unlinkItemPathInWatcher(parentDir);
// parentDirUnwatched = true;

/**
* If it is windows OS
Expand All @@ -396,8 +396,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
} else {
await fs.renameSync(oldPath, newPath);
}
watcher.addItemPathInWatcher(parentDir);
parentDirRewatched = true;
// watcher.addItemPathInWatcher(parentDir);
// parentDirRewatched = true;

return newPath;
}
Expand All @@ -424,9 +424,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
} catch (error) {
// in case an error occurs during the rename file operations after unlinking the parent dir
// and the rewatch fails, we need to add it back to watcher
if (parentDirUnwatched && !parentDirRewatched) {
watcher.addItemPathInWatcher(parentDir);
}
// if (parentDirUnwatched && !parentDirRewatched) {
// watcher.addItemPathInWatcher(parentDir);
// }

// in case the rename file operations fails, and we see that the temp dir exists
// and the old path does not exist, we need to restore the data from the temp dir to the old path
Expand Down
8 changes: 6 additions & 2 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,15 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
try {
// Filter out ZWNBSP character
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d

// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
data = data.replace(/^\uFEFF/, '');
if (!disableParsingResponseJson) {
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
data = JSON.parse(data);
}
} catch { }
} catch {
console.log('Failed to parse response data as JSON');
}

return { data, dataBuffer };
};
Expand Down
2 changes: 2 additions & 0 deletions packages/bruno-tests/collection/echo/echo multipart.bru
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ post {
}

body:multipart-form {
foo: {"bar":"baz"} @contentType(application/json--test)
form-data-key: {{form-data-key}}
form-data-stringified-object: {{form-data-stringified-object}}
file: @file(bruno.png)
Expand All @@ -19,6 +20,7 @@ body:multipart-form {
assert {
res.body: contains form-data-value
res.body: contains {"foo":123}
res.body: contains Content-Type: application/json--test
}

script:pre-request {
Expand Down
24 changes: 0 additions & 24 deletions packages/bruno-tests/collection/multipart/mixed-content-types.bru

This file was deleted.

95 changes: 95 additions & 0 deletions scripts/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const icons = {
clean: '🧹',
delete: '🗑️',
install: '📦',
build: '🔨',
success: '✅',
error: '❌',
working: '⚡'
};

const execCommand = (command, description) => {
try {
console.log(`\n${icons.working} ${description}...`);
execSync(command, { stdio: 'inherit' });
console.log(`${icons.success} ${description} completed`);
} catch (error) {
console.error(`${icons.error} ${description} failed`);
throw error;
}
};

const glob = function (startPath, pattern) {
let results = [];

// Ensure start path exists
if (!fs.existsSync(startPath)) {
return results;
}

const files = fs.readdirSync(startPath);
for (const file of files) {
const filename = path.join(startPath, file);
const stat = fs.lstatSync(filename);

// If directory, recurse into it
if (stat.isDirectory()) {
// Skip node_modules recursion to avoid unnecessary deep scanning
if (file === 'node_modules') {
if (file === pattern) {
results.push(filename);
}
continue;
}
results = results.concat(glob(filename, pattern));
}

// If file matches pattern, add to results
if (file === pattern) {
results.push(filename);
}
}

return results;
};

async function setup() {
try {
// Clean up node_modules (if exists)
console.log(`\n${icons.clean} Cleaning up node_modules directories...`);
const nodeModulesPaths = glob('.', 'node_modules');
for (const dir of nodeModulesPaths) {
console.log(`${icons.delete} Removing ${dir}`);
fs.rmSync(dir, { recursive: true, force: true });
}

// Install dependencies
execCommand('npm i --legacy-peer-deps', 'Installing dependencies');

// Build packages
execCommand('npm run build:graphql-docs', 'Building graphql-docs');
execCommand('npm run build:bruno-query', 'Building bruno-query');
execCommand('npm run build:bruno-common', 'Building bruno-common');

// Bundle JS sandbox libraries
execCommand(
'npm run sandbox:bundle-libraries --workspace=packages/bruno-js',
'Bundling JS sandbox libraries'
);

console.log(`\n${icons.success} Setup completed successfully!\n`);
} catch (error) {
console.error(`\n${icons.error} Setup failed:`);
console.error(error);
process.exit(1);
}
}

setup().catch(error => {
console.error(error);
process.exit(1);
});

0 comments on commit 4b277aa

Please sign in to comment.