Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
chore: move environments firebase things to hoppscotch-web (#2939)
Akash K3fa40525385f
diff --git a/packages/hoppscotch-common/src/helpers/fb/index.ts b/packages/hoppscotch-common/src/helpers/fb/index.tsindex 7463c3b8a..1e8af88d7 100644--- a/packages/hoppscotch-common/src/helpers/fb/index.ts+++ b/packages/hoppscotch-common/src/helpers/fb/index.ts@@ -2,7 +2,6 @@ import { initializeApp } from "firebase/app"import { platform } from "~/platform"import { initAnalytics } from "./analytics"import { initCollections } from "./collections"-import { initEnvironments } from "./environments"import { initHistory } from "./history"import { initSettings } from "./settings"@@ -28,7 +27,7 @@ export function initializeFirebase() {initSettings()initCollections()initHistory()- initEnvironments()+ platform.sync.environments.initEnvironmentsSync()initAnalytics()initialized = truediff --git a/packages/hoppscotch-common/src/platform/environments.ts b/packages/hoppscotch-common/src/platform/environments.tsnew file mode 100644index 000000000..6ba4f0f2c--- /dev/null+++ b/packages/hoppscotch-common/src/platform/environments.ts@@ -0,0 +1,3 @@+export type EnvironmentsPlatformDef = {+ initEnvironmentsSync: () => void+}diff --git a/packages/hoppscotch-common/src/platform/index.ts b/packages/hoppscotch-common/src/platform/index.tsindex 94e9a2734..5a0203dc7 100644--- a/packages/hoppscotch-common/src/platform/index.ts+++ b/packages/hoppscotch-common/src/platform/index.ts@@ -1,9 +1,13 @@import { AuthPlatformDef } from "./auth"import { UIPlatformDef } from "./ui"+import { EnvironmentsPlatformDef } from "./environments"export type PlatformDef = {ui?: UIPlatformDefauth: AuthPlatformDef+ sync: {+ environments: EnvironmentsPlatformDef+ }}export let platform: PlatformDefdiff --git a/packages/hoppscotch-common/src/helpers/fb/environments.ts b/packages/hoppscotch-web/src/environments.tssimilarity index 86%rename from packages/hoppscotch-common/src/helpers/fb/environments.tsrename to packages/hoppscotch-web/src/environments.tsindex be34b184a..823dd7b88 100644--- a/packages/hoppscotch-common/src/helpers/fb/environments.ts+++ b/packages/hoppscotch-web/src/environments.ts@@ -6,14 +6,18 @@ import {onSnapshot,setDoc,} from "firebase/firestore"-import { platform } from "~/platform"+import { def as platformAuth } from "./firebase/auth"import {environments$,globalEnv$,replaceEnvironments,setGlobalEnvVariables,-} from "~/newstore/environments"-import { getSettingSubject, settingsStore } from "~/newstore/settings"+} from "@hoppscotch/common/newstore/environments"+import {+ getSettingSubject,+ settingsStore,+} from "@hoppscotch/common/newstore/settings"+import { EnvironmentsPlatformDef } from "@hoppscotch/common/platform/environments"/*** Used locally to prevent infinite loop when environment sync update@@ -32,7 +36,7 @@ let loadedEnvironments = falselet loadedGlobals = trueasync function writeEnvironments(environment: Environment[]) {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (currentUser === null)throw new Error("Cannot write environments when signed out")@@ -57,7 +61,7 @@ async function writeEnvironments(environment: Environment[]) {}async function writeGlobalEnvironment(variables: Environment["variables"]) {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (currentUser === null)throw new Error("Cannot write global environment when signed out")@@ -81,11 +85,11 @@ async function writeGlobalEnvironment(variables: Environment["variables"]) {}}-export function initEnvironments() {- const currentUser$ = platform.auth.getCurrentUserStream()+export function initEnvironmentsSync() {+ const currentUser$ = platformAuth.getCurrentUserStream()const envListenSub = environments$.subscribe((envs) => {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (currentUser &&@@ -97,7 +101,7 @@ export function initEnvironments() {})const globalListenSub = globalEnv$.subscribe((vars) => {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (currentUser && settingsStore.value.syncEnvironments && loadedGlobals) {writeGlobalEnvironment(vars)@@ -171,8 +175,12 @@ export function initEnvironments() {globalListenSub.unsubscribe()currentUserSub.unsubscribe()- initEnvironments()+ initEnvironmentsSync()}})}++export const def: EnvironmentsPlatformDef = {+ initEnvironmentsSync,+}diff --git a/packages/hoppscotch-web/src/main.ts b/packages/hoppscotch-web/src/main.tsindex 9114700af..5945e25ac 100644--- a/packages/hoppscotch-web/src/main.ts+++ b/packages/hoppscotch-web/src/main.ts@@ -1,6 +1,10 @@import { createHoppApp } from "@hoppscotch/common"import { def as authDef } from "./firebase/auth"+import { def as envDef } from "./environments"createHoppApp("#app", {auth: authDef,+ sync: {+ environments: envDef,+ },})