From 57e0f0c0c4fb7505ccd505cd1e6a7ec9544a6f7b Mon Sep 17 00:00:00 2001 From: "Peter C." Date: Thu, 5 Oct 2023 09:45:08 +0200 Subject: [PATCH] updated insomnia importer --- .../utils/importers/insomnia-collection.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/bruno-app/src/utils/importers/insomnia-collection.js b/packages/bruno-app/src/utils/importers/insomnia-collection.js index b402e8903..8b7b7fb6a 100644 --- a/packages/bruno-app/src/utils/importers/insomnia-collection.js +++ b/packages/bruno-app/src/utils/importers/insomnia-collection.js @@ -41,6 +41,16 @@ const addSuffixToDuplicateName = (item, index, allItems) => { return nameSuffix !== 0 ? `${item.name}_${nameSuffix}` : item.name; }; +const regexVariable = new RegExp('{{.*?}}', 'g'); + +const normalizeVariables = (value) => { + const variables = value.match(regexVariable) || []; + each(variables, (variable) => { + value = value.replace(variable, variable.replace('_.', '').replaceAll(' ', '')); + }); + return value; +}; + const transformInsomniaRequestItem = (request, index, allRequests) => { const name = addSuffixToDuplicateName(request, index, allRequests); @@ -51,6 +61,11 @@ const transformInsomniaRequestItem = (request, index, allRequests) => { request: { url: request.url, method: request.method, + auth: { + mode: 'none', + basic: null, + bearer: null + }, headers: [], params: [], body: { @@ -84,7 +99,22 @@ const transformInsomniaRequestItem = (request, index, allRequests) => { }); }); - const mimeType = get(request, 'body.mimeType', ''); + const authType = get(request, 'authentication.type', ''); + + if (authType === 'basic') { + brunoRequestItem.request.auth.mode = 'basic'; + brunoRequestItem.request.auth.basic = { + username: normalizeVariables(get(request, 'authentication.username', '')), + password: normalizeVariables(get(request, 'authentication.password', '')) + }; + } else if (authType === 'bearer') { + brunoRequestItem.request.auth.mode = 'bearer'; + brunoRequestItem.request.auth.bearer = { + token: normalizeVariables(get(request, 'authentication.token', '')) + }; + } + + const mimeType = get(request, 'body.mimeType', '').split(';')[0]; if (mimeType === 'application/json') { brunoRequestItem.request.body.mode = 'json';