Merge codeday/jason => codeday/isai

This commit is contained in:
Jason Casareno
2022-08-01 14:46:06 -07:00
6 changed files with 28 additions and 24 deletions

View File

@@ -348,7 +348,8 @@ const newSendRequest = async () => {
const ensureMethodInEndpoint = () => { const ensureMethodInEndpoint = () => {
if ( if (
!/^http[s]?:\/\//.test(newEndpoint.value) && !/^http[s]?:\/\//.test(newEndpoint.value) &&
!newEndpoint.value.startsWith("<<") !newEndpoint.value.startsWith("<<") &&
!newEndpoint.value.startsWith("{{")
) { ) {
const domain = newEndpoint.value.split(/[/:#?]+/)[0] const domain = newEndpoint.value.split(/[/:#?]+/)[0]
if (domain === "localhost" || /([0-9]+\.)*[0-9]/.test(domain)) { if (domain === "localhost" || /([0-9]+\.)*[0-9]/.test(domain)) {

View File

@@ -3,7 +3,7 @@
<div <div
class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperMobileSecondaryStickyFold sm:top-upperSecondaryStickyFold" class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperMobileSecondaryStickyFold sm:top-upperSecondaryStickyFold"
> >
<label class="font-semibold text-secondaryLight"> Variables </label> <label class="font-semibold text-secondaryLight"> My Variables </label>
<div class="flex"> <div class="flex">
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
@@ -15,28 +15,28 @@
</div> </div>
<div> <div>
<div <div
v-for="(vari, index) in workingVars" v-for="(variable, index) in workingVars"
:key="`vari-${vari.id}-${index}`" :key="`vari-${variable.id}-${index}`"
class="flex border-b divide-x divide-dividerLight border-dividerLight draggable-content group" class="flex border-b divide-x divide-dividerLight border-dividerLight draggable-content group"
> >
<SmartEnvInput <SmartEnvInput
v-model="vari.key" v-model="variable.key"
:placeholder="`${t('count.parameter', { count: index + 1 })}`" :placeholder="`${t('count.parameter', { count: index + 1 })}`"
@change=" @change="
updateVar(index, { updateVar(index, {
id: vari.id, id: variable.id,
key: $event, key: $event,
value: vari.value, value: variable.value,
}) })
" "
/> />
<SmartEnvInput <SmartEnvInput
v-model="vari.value" v-model="variable.value"
:placeholder="`${t('count.value', { count: index + 1 })}`" :placeholder="`${t('count.value', { count: index + 1 })}`"
@change=" @change="
updateVar(index, { updateVar(index, {
id: vari.id, id: variable.id,
key: vari.key, key: variable.key,
value: $event, value: $event,
}) })
" "

View File

@@ -116,6 +116,8 @@ const aggregateEnvs = useReadonlyStream(aggregateEnvs$, []) as Ref<
> >
const aggregateVars = useReadonlyStream(restVars$, []) as Ref<HoppRESTVar[]> const aggregateVars = useReadonlyStream(restVars$, []) as Ref<HoppRESTVar[]>
const aggregateVars = useReadonlyStream(restVars$, []) as Ref<HoppRESTVar[]>
const envVars = computed(() => const envVars = computed(() =>
props.envs props.envs
? props.envs.map((x) => ({ ? props.envs.map((x) => ({

View File

@@ -14,7 +14,7 @@ import {
HoppRESTHeader, HoppRESTHeader,
HoppRESTParam, HoppRESTParam,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { parseTemplateStringV } from "@hoppscotch/data/src/pathVariables" import { parseTemplateStringV } from "@hoppscotch/data/src/variables"
import { arrayFlatMap, arraySort } from "../functional/array" import { arrayFlatMap, arraySort } from "../functional/array"
import { toFormData } from "../functional/formData" import { toFormData } from "../functional/formData"
import { tupleToRecord } from "../functional/record" import { tupleToRecord } from "../functional/record"

View File

@@ -14,9 +14,8 @@ export type Variables = {
value: string value: string
}[] }[]
const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>" const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}" const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}"
/** /**
* How much times can we expand environment variables * How much times can we expand environment variables

View File

@@ -16,7 +16,7 @@ export type Variables = {
}[] }[]
const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>" const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<<myVariable>>"
const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}" const REGEX_MY_VAR = /{{([^}]*)}}/g // "{{myVariable}}"
/** /**
* How much times can we expand environment variables * How much times can we expand environment variables
@@ -32,9 +32,9 @@ const ENV_EXPAND_LOOP = "ENV_EXPAND_LOOP" as const
export function parseTemplateStringEV( export function parseTemplateStringEV(
str: string, str: string,
variables: Environment["variables"], variables: Environment["variables"],
pathVariables: Variables myVariables: Variables
) { ) {
if (!variables || !str || !pathVariables) { if (!variables || !str || !myVariables) {
return E.right(str) return E.right(str)
} }
@@ -49,10 +49,13 @@ export function parseTemplateStringEV(
depth++ depth++
} }
while (result.match(REGEX_PATHVAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { /**
* TODO: Create an error state when there is a suspected loop while recursively expanding these variables
*/
while (result.match(REGEX_MY_VAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) {
result = decodeURI(encodeURI(result)).replace( result = decodeURI(encodeURI(result)).replace(
REGEX_PATHVAR, REGEX_MY_VAR,
(_, p1) => pathVariables.find((x) => x.key === p1)?.value || "" (_, p1) => myVariables.find((x) => x.key === p1)?.value || ""
) )
} }
@@ -62,15 +65,14 @@ export function parseTemplateStringEV(
} }
/** /**
* @deprecated Use `parseTemplateStringE` instead * @deprecated Use `parseTemplateStringEV` instead
*/ */
export const parseTemplateStringV = ( export const parseTemplateStringV = (
str: string, str: string,
variables: Environment["variables"], variables: Environment["variables"],
pathVariables: Variables myVariables: Variables
) => ) =>
pipe( pipe(
parseTemplateStringEV(str, variables, pathVariables), parseTemplateStringEV(str, variables, myVariables),
E.getOrElse(() => str) E.getOrElse(() => str)
) )