Skip to content

Commit

Permalink
fix(persistence-service): add fallbacks for environments related sche…
Browse files Browse the repository at this point in the history
…mas (#3832)
  • Loading branch information
jamesgeorge007 committed Feb 15, 2024
1 parent ed6e9b6 commit 4bd54b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/hoppscotch-common/src/newstore/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion packages/hoppscotch-common/src/services/persistence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion packages/hoppscotch-data/src/environment/v/1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
])
),
Expand Down

0 comments on commit 4bd54b1

Please sign in to comment.