diff --git a/packages/hoppscotch-app/newstore/localpersistence.ts b/packages/hoppscotch-app/newstore/localpersistence.ts index a6f7a033a..83c654fb9 100644 --- a/packages/hoppscotch-app/newstore/localpersistence.ts +++ b/packages/hoppscotch-app/newstore/localpersistence.ts @@ -321,6 +321,8 @@ function setupRequestPersistence() { } window.localStorage.setItem("restRequest", JSON.stringify(reqClone)) }) + + console.log("localRequest", localRequest) } export function setupLocalPersistence() { diff --git a/packages/hoppscotch-data/src/rest/index.ts b/packages/hoppscotch-data/src/rest/index.ts index c4fa6d9c0..08993887e 100644 --- a/packages/hoppscotch-data/src/rest/index.ts +++ b/packages/hoppscotch-data/src/rest/index.ts @@ -8,7 +8,7 @@ import { lodashIsEqualEq, mapThenEq, undefinedEq } from "../utils/eq" export * from "./content-types" export * from "./HoppRESTAuth" -export const RESTReqSchemaVersion = "1" +export const RESTReqSchemaVersion = "2" export type HoppRESTParam = { key: string @@ -16,6 +16,11 @@ export type HoppRESTParam = { active: boolean } +export type HoppRESTVar = { + key: string + value: string +} + export type HoppRESTHeader = { key: string value: string @@ -51,6 +56,7 @@ export interface HoppRESTRequest { method: string endpoint: string params: HoppRESTParam[] + vars: HoppRESTVar[] headers: HoppRESTHeader[] preRequestScript: string testScript: string @@ -74,6 +80,10 @@ export const HoppRESTRequestEq = Eq.struct({ (arr) => arr.filter((p) => p.key !== "" && p.value !== ""), lodashIsEqualEq ), + vars: mapThenEq( + (arr) => arr.filter((p) => p.key !== "" && p.value !== ""), + lodashIsEqualEq + ), method: S.Eq, name: S.Eq, preRequestScript: S.Eq, @@ -126,6 +136,9 @@ export function safelyExtractRESTRequest( if (x.hasOwnProperty("params") && Array.isArray(x.params)) req.params = x.params // TODO: Deep nested checks + if (x.hasOwnProperty("vars") && Array.isArray(x.vars)) + req.vars = x.vars // TODO: Deep nested checks + if (x.hasOwnProperty("headers") && Array.isArray(x.headers)) req.headers = x.headers // TODO: Deep nested checks } @@ -186,6 +199,19 @@ export function translateToNewRequest(x: any): HoppRESTRequest { }) ) + const vars: HoppRESTVar[] = (x?.vars ?? []).map( + ({ + key, + value, + }: { + key: string + value: string + }) => ({ + key, + value, + }) + ) + const name = x?.name ?? "Untitled request" const method = x?.method ?? "" @@ -201,6 +227,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest { endpoint, headers, params, + vars, method, preRequestScript, testScript,