diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts index f3f4f9b4..914c4703 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts @@ -22,12 +22,23 @@ export const hoppEnvImporter = (contents: string[]) => { return unwrappedContent.map((contentEntry) => { return { ...contentEntry, - variables: contentEntry.variables?.map((valueEntry) => ({ - ...valueEntry, - ...("initialValue" in valueEntry - ? { value: String(valueEntry.initialValue) } - : {}), - })), + variables: contentEntry.variables?.map((valueEntry) => { + if ("value" in valueEntry) { + return { + ...valueEntry, + value: String(valueEntry.value), + } + } + + if ("initialValue" in valueEntry) { + return { + ...valueEntry, + initialValue: String(valueEntry.initialValue), + } + } + + return valueEntry + }), } }) } diff --git a/packages/hoppscotch-data/src/environment/v/2.ts b/packages/hoppscotch-data/src/environment/v/2.ts index cfab8e0f..7033dc9f 100644 --- a/packages/hoppscotch-data/src/environment/v/2.ts +++ b/packages/hoppscotch-data/src/environment/v/2.ts @@ -1,4 +1,4 @@ -import { boolean, z } from "zod" +import { z } from "zod" import { defineVersion } from "verzod" import { V1_SCHEMA } from "./1" @@ -23,14 +23,16 @@ export default defineVersion({ ...old, v: 2, variables: old.variables.map((variable) => { + const { key, secret } = variable + // if the variable is secret, set initialValue and currentValue to empty string // else set initialValue and currentValue to value // and delete value return { - ...variable, - initialValue: variable.secret ? "" : variable.value, - currentValue: variable.secret ? "" : variable.value, - value: undefined, + key, + secret, + initialValue: secret ? "" : variable.value, + currentValue: secret ? "" : variable.value, } }), } diff --git a/packages/hoppscotch-selfhost-desktop/src/platform/environments/environments.sync.ts b/packages/hoppscotch-selfhost-desktop/src/platform/environments/environments.sync.ts index fb409420..98e7a103 100644 --- a/packages/hoppscotch-selfhost-desktop/src/platform/environments/environments.sync.ts +++ b/packages/hoppscotch-selfhost-desktop/src/platform/environments/environments.sync.ts @@ -97,7 +97,12 @@ export const storeSyncDefinition: StoreSyncDefinitionOf< setGlobalVariables({ entries }) { const backendId = getGlobalVariableID() if (backendId) { - updateUserEnvironment(backendId, { name: "", variables: entries })() + updateUserEnvironment(backendId, { + name: "", + variables: entries, + id: "", + v: 2, + })() } }, clearGlobalVariables() { diff --git a/packages/hoppscotch-selfhost-web/src/platform/environments/desktop/sync.ts b/packages/hoppscotch-selfhost-web/src/platform/environments/desktop/sync.ts index 8b902357..4ec26761 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/environments/desktop/sync.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/environments/desktop/sync.ts @@ -22,11 +22,13 @@ import { } from "./api" import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service" import { getService } from "@hoppscotch/common/modules/dioc" +import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service" export const environmentsMapper = createMapper() export const globalEnvironmentMapper = createMapper() const secretEnvironmentService = getService(SecretEnvironmentService) +const currentEnvironmentValueService = getService(CurrentValueService) export const storeSyncDefinition: StoreSyncDefinitionOf< typeof environmentsStore @@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf< id ) + currentEnvironmentValueService.updateEnvironmentID( + environmentsStore.value.environments[lastCreatedEnvIndex].id, + id + ) + environmentsStore.value.environments[lastCreatedEnvIndex].id = id removeDuplicateEntry(id) } diff --git a/packages/hoppscotch-selfhost-web/src/platform/environments/web/sync.ts b/packages/hoppscotch-selfhost-web/src/platform/environments/web/sync.ts index 8b902357..4ec26761 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/environments/web/sync.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/environments/web/sync.ts @@ -22,11 +22,13 @@ import { } from "./api" import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service" import { getService } from "@hoppscotch/common/modules/dioc" +import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service" export const environmentsMapper = createMapper() export const globalEnvironmentMapper = createMapper() const secretEnvironmentService = getService(SecretEnvironmentService) +const currentEnvironmentValueService = getService(CurrentValueService) export const storeSyncDefinition: StoreSyncDefinitionOf< typeof environmentsStore @@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf< id ) + currentEnvironmentValueService.updateEnvironmentID( + environmentsStore.value.environments[lastCreatedEnvIndex].id, + id + ) + environmentsStore.value.environments[lastCreatedEnvIndex].id = id removeDuplicateEntry(id) }