fix: env var parsing in importers and param import issues in postman

This commit is contained in:
Andrew Bastin
2022-01-14 15:01:06 +05:30
parent 67934fd19a
commit f4d98b9f43
2 changed files with 22 additions and 12 deletions

View File

@@ -33,8 +33,8 @@ const parseInsomniaDoc = (content: string) =>
TO.tryCatch(() => convert(content)) TO.tryCatch(() => convert(content))
const replaceVarTemplating = flow( const replaceVarTemplating = flow(
S.replace(/{{\s+/g, "<<"), S.replace(/{{\s*/g, "<<"),
S.replace(/\s+}}/g, ">>") S.replace(/\s*}}/g, ">>")
) )
const getFoldersIn = ( const getFoldersIn = (

View File

@@ -3,6 +3,7 @@ import {
FormParam, FormParam,
Item, Item,
ItemGroup, ItemGroup,
QueryParam,
RequestAuthDefinition, RequestAuthDefinition,
VariableDefinition, VariableDefinition,
} from "postman-collection" } from "postman-collection"
@@ -28,8 +29,8 @@ const safeParseJSON = (jsonStr: string) => O.tryCatch(() => JSON.parse(jsonStr))
const isPMItem = (x: unknown): x is Item => Item.isItem(x) const isPMItem = (x: unknown): x is Item => Item.isItem(x)
const replacePMVarTemplating = flow( const replacePMVarTemplating = flow(
S.replace(/{{/g, "<<"), S.replace(/{{\s*/g, "<<"),
S.replace(/}}/g, ">>") S.replace(/\s*}}/g, ">>")
) )
const isPMItemGroup = (x: unknown): x is ItemGroup<Item> => const isPMItemGroup = (x: unknown): x is ItemGroup<Item> =>
@@ -54,17 +55,22 @@ const getHoppReqHeaders = (item: Item): HoppRESTHeader[] =>
}) })
) )
const getHoppReqParams = (item: Item): HoppRESTParam[] => const getHoppReqParams = (item: Item): HoppRESTParam[] => {
pipe( return pipe(
item.request.headers.all(), item.request.url.query.all(),
A.map((header) => { A.filter(
(param): param is QueryParam & { key: string } =>
param.key !== undefined && param.key !== null && param.key.length > 0
),
A.map((param) => {
return <HoppRESTHeader>{ return <HoppRESTHeader>{
key: replacePMVarTemplating(header.key), key: replacePMVarTemplating(param.key),
value: replacePMVarTemplating(header.value), value: replacePMVarTemplating(param.value ?? ""),
active: !header.disabled, active: !param.disabled,
} }
}) })
) )
}
type PMRequestAuthDef< type PMRequestAuthDef<
AuthType extends RequestAuthDefinition["type"] = RequestAuthDefinition["type"] AuthType extends RequestAuthDefinition["type"] = RequestAuthDefinition["type"]
@@ -198,7 +204,11 @@ const getHoppReqBody = (item: Item): HoppRESTReqBody => {
} }
const getHoppReqURL = (item: Item): string => const getHoppReqURL = (item: Item): string =>
pipe(item.request.url.toString(true), S.replace(/\?.+/g, "")) pipe(
item.request.url.toString(true),
S.replace(/\?.+/g, ""),
replacePMVarTemplating
)
const getHoppRequest = (item: Item): HoppRESTRequest => { const getHoppRequest = (item: Item): HoppRESTRequest => {
return makeRESTRequest({ return makeRESTRequest({