Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(persistence-service): add fallbacks for environments related schemas (#3832)

James George4bd54b12cde4
diff --git a/packages/hoppscotch-common/src/newstore/environments.ts b/packages/hoppscotch-common/src/newstore/environments.ts
index a63206582..3c5672655 100644
--- a/packages/hoppscotch-common/src/newstore/environments.ts
+++ b/packages/hoppscotch-common/src/newstore/environments.ts
@@ -568,7 +568,18 @@ export function getLegacyGlobalEnvironment(): Environment | null {
}
export function getGlobalVariables(): Environment["variables"] {
- return environmentsStore.value.globals
+ return environmentsStore.value.globals.map(
+ (env: Environment["variables"][number]) => {
+ if (env.key && "value" in env && !("secret" in env)) {
+ return {
+ ...(env as Environment["variables"][number]),
+ secret: false,
+ }
+ }
+
+ return env
+ }
+ ) as Environment["variables"]
}
export function getGlobalVariableID() {
diff --git a/packages/hoppscotch-common/src/services/persistence/index.ts b/packages/hoppscotch-common/src/services/persistence/index.ts
index 74291bebb..d96b722f0 100644
--- a/packages/hoppscotch-common/src/services/persistence/index.ts
+++ b/packages/hoppscotch-common/src/services/persistence/index.ts
@@ -425,7 +425,10 @@ export class PersistenceService extends Service {
if (globalIndex !== -1) {
const globalEnv = environmentsData[globalIndex]
- globalEnv.variables.forEach((variable) => addGlobalEnvVariable(variable))
+ globalEnv.variables.forEach(
+ (variable: Environment["variables"][number]) =>
+ addGlobalEnvVariable(variable)
+ )
// Remove global from environments
environmentsData.splice(globalIndex, 1)
diff --git a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
index b6ac61ac5..bb4c03799 100644
--- a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
+++ b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts
@@ -233,7 +233,7 @@ const EnvironmentVariablesSchema = z.union([
z.object({
key: z.string(),
value: z.string(),
- secret: z.literal(false),
+ secret: z.literal(false).catch(false),
}),
z.object({
key: z.string(),
diff --git a/packages/hoppscotch-data/src/environment/v/1.ts b/packages/hoppscotch-data/src/environment/v/1.ts
index 6ab68d79f..01562abe9 100644
--- a/packages/hoppscotch-data/src/environment/v/1.ts
+++ b/packages/hoppscotch-data/src/environment/v/1.ts
@@ -15,7 +15,7 @@ export const V1_SCHEMA = z.object({
z.object({
key: z.string(),
value: z.string(),
- secret: z.literal(false),
+ secret: z.literal(false).catch(false),
}),
])
),