Compare commits
4 Commits
feat/pat-u
...
fix/secret
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3da14d392 | ||
|
|
5f9f9addaf | ||
|
|
63cbaabf07 | ||
|
|
40e8696a9a |
@@ -165,7 +165,7 @@ import { environmentsStore } from "~/newstore/environments"
|
|||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { SecretEnvironmentService } from "~/services/secret-environment.service"
|
import { SecretEnvironmentService } from "~/services/secret-environment.service"
|
||||||
import { uniqueId } from "lodash-es"
|
import { uniqueID } from "~/helpers/utils/uniqueID"
|
||||||
|
|
||||||
type EnvironmentVariable = {
|
type EnvironmentVariable = {
|
||||||
id: number
|
id: number
|
||||||
@@ -277,7 +277,7 @@ const workingEnv = computed(() => {
|
|||||||
} as Environment
|
} as Environment
|
||||||
} else if (props.action === "new") {
|
} else if (props.action === "new") {
|
||||||
return {
|
return {
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
name: "",
|
name: "",
|
||||||
variables: props.envVars(),
|
variables: props.envVars(),
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ watch(
|
|||||||
: "variables"
|
: "variables"
|
||||||
|
|
||||||
if (props.editingEnvironmentIndex !== "Global") {
|
if (props.editingEnvironmentIndex !== "Global") {
|
||||||
editingID.value = workingEnv.value?.id ?? uniqueId()
|
editingID.value = workingEnv.value?.id || uniqueID()
|
||||||
}
|
}
|
||||||
vars.value = pipe(
|
vars.value = pipe(
|
||||||
workingEnv.value?.variables ?? [],
|
workingEnv.value?.variables ?? [],
|
||||||
@@ -416,14 +416,12 @@ const saveEnvironment = () => {
|
|||||||
|
|
||||||
const variables = pipe(
|
const variables = pipe(
|
||||||
filteredVariables,
|
filteredVariables,
|
||||||
A.map((e) =>
|
A.map((e) => (e.secret ? { key: e.key, secret: e.secret } : e))
|
||||||
e.secret ? { key: e.key, secret: e.secret, value: undefined } : e
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const environmentUpdated: Environment = {
|
const environmentUpdated: Environment = {
|
||||||
v: 1,
|
v: 1,
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
name: editingName.value,
|
name: editingName.value,
|
||||||
variables,
|
variables,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ const saveEnvironment = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterdVariables = pipe(
|
const filteredVariables = pipe(
|
||||||
vars.value,
|
vars.value,
|
||||||
A.filterMap(
|
A.filterMap(
|
||||||
flow(
|
flow(
|
||||||
@@ -371,17 +371,15 @@ const saveEnvironment = async () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const secretVariables = pipe(
|
const secretVariables = pipe(
|
||||||
filterdVariables,
|
filteredVariables,
|
||||||
A.filterMapWithIndex((i, e) =>
|
A.filterMapWithIndex((i, e) =>
|
||||||
e.secret ? O.some({ key: e.key, value: e.value, varIndex: i }) : O.none
|
e.secret ? O.some({ key: e.key, value: e.value, varIndex: i }) : O.none
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const variables = pipe(
|
const variables = pipe(
|
||||||
filterdVariables,
|
filteredVariables,
|
||||||
A.map((e) =>
|
A.map((e) => (e.secret ? { key: e.key, secret: e.secret } : e))
|
||||||
e.secret ? { key: e.key, secret: e.secret, value: undefined } : e
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const environmentUpdated: Environment = {
|
const environmentUpdated: Environment = {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { NonSecretEnvironment } from "@hoppscotch/data"
|
import { NonSecretEnvironment } from "@hoppscotch/data"
|
||||||
import { safeParseJSONOrYAML } from "~/helpers/functional/yaml"
|
import { safeParseJSONOrYAML } from "~/helpers/functional/yaml"
|
||||||
import { uniqueId } from "lodash-es"
|
import { uniqueID } from "~/helpers/utils/uniqueID"
|
||||||
|
|
||||||
const insomniaResourcesSchema = z.object({
|
const insomniaResourcesSchema = z.object({
|
||||||
resources: z.array(
|
resources: z.array(
|
||||||
@@ -67,7 +67,7 @@ export const insomniaEnvImporter = (contents: string[]) => {
|
|||||||
|
|
||||||
if (parsedInsomniaEnv.success) {
|
if (parsedInsomniaEnv.success) {
|
||||||
const environment: NonSecretEnvironment = {
|
const environment: NonSecretEnvironment = {
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
v: 1,
|
v: 1,
|
||||||
name: parsedInsomniaEnv.data.name,
|
name: parsedInsomniaEnv.data.name,
|
||||||
variables: Object.entries(parsedInsomniaEnv.data.data).map(
|
variables: Object.entries(parsedInsomniaEnv.data.data).map(
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Environment } from "@hoppscotch/data"
|
import { Environment } from "@hoppscotch/data"
|
||||||
import * as O from "fp-ts/Option"
|
import * as O from "fp-ts/Option"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { uniqueId } from "lodash-es"
|
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { safeParseJSON } from "~/helpers/functional/json"
|
import { safeParseJSON } from "~/helpers/functional/json"
|
||||||
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
||||||
|
import { uniqueID } from "~/helpers/utils/uniqueID"
|
||||||
|
|
||||||
const postmanEnvSchema = z.object({
|
const postmanEnvSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
@@ -49,7 +49,7 @@ export const postmanEnvImporter = (contents: string[]) => {
|
|||||||
// Convert `values` to `variables` to match the format expected by the system
|
// Convert `values` to `variables` to match the format expected by the system
|
||||||
const environments: Environment[] = validationResult.data.map(
|
const environments: Environment[] = validationResult.data.map(
|
||||||
({ name, values }) => ({
|
({ name, values }) => ({
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
v: 1,
|
v: 1,
|
||||||
name,
|
name,
|
||||||
variables: values.map((entires) => ({ ...entires, secret: false })),
|
variables: values.map((entires) => ({ ...entires, secret: false })),
|
||||||
|
|||||||
3
packages/hoppscotch-common/src/helpers/utils/uniqueID.ts
Normal file
3
packages/hoppscotch-common/src/helpers/utils/uniqueID.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const uniqueID = (length = 16) => {
|
||||||
|
return Math.random().toString(36).substring(2, length)
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Environment } from "@hoppscotch/data"
|
import { Environment } from "@hoppscotch/data"
|
||||||
import { cloneDeep, isEqual, uniqueId } from "lodash-es"
|
import { cloneDeep, isEqual } from "lodash-es"
|
||||||
import { combineLatest, Observable } from "rxjs"
|
import { combineLatest, Observable } from "rxjs"
|
||||||
import { distinctUntilChanged, map, pluck } from "rxjs/operators"
|
import { distinctUntilChanged, map, pluck } from "rxjs/operators"
|
||||||
|
import { uniqueID } from "~/helpers/utils/uniqueID"
|
||||||
import { getService } from "~/modules/dioc"
|
import { getService } from "~/modules/dioc"
|
||||||
import DispatchingStore, {
|
import DispatchingStore, {
|
||||||
defineDispatchers,
|
defineDispatchers,
|
||||||
@@ -22,7 +23,7 @@ const defaultEnvironmentsState = {
|
|||||||
environments: [
|
environments: [
|
||||||
{
|
{
|
||||||
v: 1,
|
v: 1,
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
name: "My Environment Variables",
|
name: "My Environment Variables",
|
||||||
variables: [],
|
variables: [],
|
||||||
},
|
},
|
||||||
@@ -100,7 +101,7 @@ const dispatchers = defineDispatchers({
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
v: 1,
|
v: 1,
|
||||||
id: "",
|
id: uniqueID(),
|
||||||
name,
|
name,
|
||||||
variables,
|
variables,
|
||||||
},
|
},
|
||||||
@@ -123,7 +124,7 @@ const dispatchers = defineDispatchers({
|
|||||||
...environments,
|
...environments,
|
||||||
{
|
{
|
||||||
...cloneDeep(newEnvironment),
|
...cloneDeep(newEnvironment),
|
||||||
id: uniqueId(),
|
id: uniqueID(),
|
||||||
name: `${newEnvironment.name} - Duplicate`,
|
name: `${newEnvironment.name} - Duplicate`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { InferredEntity, createVersionedEntity } from "verzod"
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import V0_VERSION from "./v/0"
|
import V0_VERSION from "./v/0"
|
||||||
import V1_VERSION from "./v/1"
|
import V1_VERSION, { uniqueID } from "./v/1"
|
||||||
|
|
||||||
const versionedObject = z.object({
|
const versionedObject = z.object({
|
||||||
v: z.number(),
|
v: z.number(),
|
||||||
@@ -165,7 +165,7 @@ export const translateToNewEnvironment = (x: any): Environment => {
|
|||||||
if (x.v && x.v === EnvironmentSchemaVersion) return x
|
if (x.v && x.v === EnvironmentSchemaVersion) return x
|
||||||
|
|
||||||
// Legacy
|
// Legacy
|
||||||
const id = x.id ?? ""
|
const id = x.id || uniqueID()
|
||||||
const name = x.name ?? "Untitled"
|
const name = x.name ?? "Untitled"
|
||||||
const variables = (x.variables ?? []).map(translateToNewEnvironmentVariables)
|
const variables = (x.variables ?? []).map(translateToNewEnvironmentVariables)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { z } from "zod"
|
|||||||
import { defineVersion } from "verzod"
|
import { defineVersion } from "verzod"
|
||||||
import { V0_SCHEMA } from "./0"
|
import { V0_SCHEMA } from "./0"
|
||||||
|
|
||||||
|
export const uniqueID = () => Math.random().toString(36).substring(2, 16)
|
||||||
|
|
||||||
export const V1_SCHEMA = z.object({
|
export const V1_SCHEMA = z.object({
|
||||||
v: z.literal(1),
|
v: z.literal(1),
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
@@ -28,7 +30,7 @@ export default defineVersion({
|
|||||||
const result: z.infer<typeof V1_SCHEMA> = {
|
const result: z.infer<typeof V1_SCHEMA> = {
|
||||||
...old,
|
...old,
|
||||||
v: 1,
|
v: 1,
|
||||||
id: old.id ?? "",
|
id: old.id || uniqueID(),
|
||||||
variables: old.variables.map((variable) => {
|
variables: old.variables.map((variable) => {
|
||||||
return {
|
return {
|
||||||
...variable,
|
...variable,
|
||||||
|
|||||||
Reference in New Issue
Block a user