diff --git a/packages/hoppscotch-common/src/components/environments/ImportExport.vue b/packages/hoppscotch-common/src/components/environments/ImportExport.vue index 0f11f6580..337c2aac3 100644 --- a/packages/hoppscotch-common/src/components/environments/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/environments/ImportExport.vue @@ -36,6 +36,7 @@ import { TeamEnvironment } from "~/helpers/teams/TeamEnvironment" import { computed } from "vue" import { useReadonlyStream } from "~/composables/stream" import { initializeDownloadFile } from "~/helpers/import-export/export" +import { transformEnvironmentVariables } from "~/helpers/import-export/export/environment" import { environmentsExporter } from "~/helpers/import-export/export/environments" import { gistExporter } from "~/helpers/import-export/export/gist" import { platform } from "~/platform" @@ -73,10 +74,12 @@ const isTeamEnvironment = computed(() => { const environmentJson = computed(() => { if (isTeamEnvironment.value && props.teamEnvironments) { - return props.teamEnvironments.map((x) => x.environment) + return props.teamEnvironments.map(({ environment }) => + transformEnvironmentVariables(environment) + ) } - return myEnvironments.value + return myEnvironments.value.map(transformEnvironmentVariables) }) const workspaceType = computed(() => diff --git a/packages/hoppscotch-common/src/components/environments/my/Details.vue b/packages/hoppscotch-common/src/components/environments/my/Details.vue index 5bcba730a..eaf245a66 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Details.vue @@ -352,12 +352,15 @@ watch( env: { key: e.key, value: e.secret - ? (secretEnvironmentService.getSecretEnvironmentVariable( + ? secretEnvironmentService.getSecretEnvironmentVariable( props.editingEnvironmentIndex === "Global" ? "Global" : workingEnvID.value, index - )?.value ?? "") + )?.value ?? + // @ts-expect-error `value` field can exist for secret environment variables as inferred while importing + e.value ?? + "" : e.value, secret: e.secret, }, diff --git a/packages/hoppscotch-common/src/components/environments/teams/Details.vue b/packages/hoppscotch-common/src/components/environments/teams/Details.vue index 215c8f613..cde3ff194 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Details.vue @@ -311,10 +311,13 @@ watch( env: { key: e.key, value: e.secret - ? (secretEnvironmentService.getSecretEnvironmentVariable( + ? secretEnvironmentService.getSecretEnvironmentVariable( editingID.value ?? "", index - )?.value ?? "") + )?.value ?? + // @ts-expect-error `value` field can exist for secret environment variables as inferred while importing + e.value ?? + "" : e.value, secret: e.secret, }, @@ -352,10 +355,6 @@ const removeEnvironmentVariable = (id: number) => { const isLoading = ref(false) const saveEnvironment = async () => { - if (isLoading.value) { - return - } - isLoading.value = true if (!editingName.value) { diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts b/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts index ef95fcd27..3fe79b713 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts @@ -19,11 +19,41 @@ const getEnvironmentJSON = ( ? environmentIndex : environmentObj.id + // Eliminate `value` field from secret environment variables prior to export + const transformedEnvironment = transformEnvironmentVariables(newEnvironment) + return environmentId !== null - ? JSON.stringify(newEnvironment, null, 2) + ? JSON.stringify(transformedEnvironment, null, 2) : undefined } +// Apply necessary transformations prior to environment exports +export const transformEnvironmentVariables = ({ + id, + v, + name, + variables, +}: Environment) => { + return { + id, + v, + name, + variables: variables.map((variable) => { + const { key, secret } = variable + + // Eliminate `value` field for secret environment variables + if (secret) { + return { + key, + secret, + } + } + + return variable + }), + } +} + export const exportAsJSON = async ( environmentObj: Environment | TeamEnvironment, environmentIndex?: number | "Global" | null diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts index f77753695..7af363114 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts @@ -13,6 +13,7 @@ const postmanEnvSchema = z.object({ z.object({ key: z.string(), value: z.string(), + type: z.string(), }) ), }) @@ -34,6 +35,7 @@ export const postmanEnvImporter = (contents: string[]) => { values: entry.values?.map((valueEntry) => ({ ...valueEntry, value: String(valueEntry.value), + type: String(valueEntry.type), })), })) } @@ -52,7 +54,11 @@ export const postmanEnvImporter = (contents: string[]) => { id: uniqueID(), v: 1, name, - variables: values.map((entires) => ({ ...entires, secret: false })), + variables: values.map(({ key, value, type }) => ({ + key, + value, + secret: type === "secret", + })), }) )