diff --git a/packages/hoppscotch-common/src/helpers/fb/index.ts b/packages/hoppscotch-common/src/helpers/fb/index.ts index 1e8af88d7..9b82c20f5 100644 --- a/packages/hoppscotch-common/src/helpers/fb/index.ts +++ b/packages/hoppscotch-common/src/helpers/fb/index.ts @@ -1,7 +1,6 @@ import { initializeApp } from "firebase/app" import { platform } from "~/platform" import { initAnalytics } from "./analytics" -import { initCollections } from "./collections" import { initHistory } from "./history" import { initSettings } from "./settings" @@ -25,7 +24,7 @@ export function initializeFirebase() { platform.auth.performAuthInit() initSettings() - initCollections() + platform.sync.collections.initCollectionsSync() initHistory() platform.sync.environments.initEnvironmentsSync() initAnalytics() diff --git a/packages/hoppscotch-common/src/platform/collections.ts b/packages/hoppscotch-common/src/platform/collections.ts new file mode 100644 index 000000000..107ba4af6 --- /dev/null +++ b/packages/hoppscotch-common/src/platform/collections.ts @@ -0,0 +1,3 @@ +export type CollectionsPlatformDef = { + initCollectionsSync: () => void +} diff --git a/packages/hoppscotch-common/src/platform/index.ts b/packages/hoppscotch-common/src/platform/index.ts index 5a0203dc7..5845f4065 100644 --- a/packages/hoppscotch-common/src/platform/index.ts +++ b/packages/hoppscotch-common/src/platform/index.ts @@ -1,12 +1,14 @@ import { AuthPlatformDef } from "./auth" import { UIPlatformDef } from "./ui" import { EnvironmentsPlatformDef } from "./environments" +import { CollectionsPlatformDef } from "./collections" export type PlatformDef = { ui?: UIPlatformDef auth: AuthPlatformDef sync: { environments: EnvironmentsPlatformDef + collections: CollectionsPlatformDef } } diff --git a/packages/hoppscotch-web/package.json b/packages/hoppscotch-web/package.json index 06607c0f8..a5a1835e9 100644 --- a/packages/hoppscotch-web/package.json +++ b/packages/hoppscotch-web/package.json @@ -28,7 +28,8 @@ "stream-browserify": "^3.0.0", "util": "^0.12.4", "vue": "^3.2.41", - "workbox-window": "^6.5.4" + "workbox-window": "^6.5.4", + "@hoppscotch/data": "workspace:^0.4.4" }, "devDependencies": { "@intlify/vite-plugin-vue-i18n": "^6.0.1", diff --git a/packages/hoppscotch-common/src/helpers/fb/collections.ts b/packages/hoppscotch-web/src/collections.ts similarity index 86% rename from packages/hoppscotch-common/src/helpers/fb/collections.ts rename to packages/hoppscotch-web/src/collections.ts index 8f8cff180..d20412fd6 100644 --- a/packages/hoppscotch-common/src/helpers/fb/collections.ts +++ b/packages/hoppscotch-web/src/collections.ts @@ -9,14 +9,22 @@ import { translateToNewRESTCollection, translateToNewGQLCollection, } from "@hoppscotch/data" -import { platform } from "~/platform" + +import { def as platformAuth } from "./firebase/auth" + import { restCollections$, graphqlCollections$, setRESTCollections, setGraphqlCollections, -} from "~/newstore/collections" -import { getSettingSubject, settingsStore } from "~/newstore/settings" +} from "@hoppscotch/common/newstore/collections" + +import { + getSettingSubject, + settingsStore, +} from "@hoppscotch/common/newstore/settings" + +import { CollectionsPlatformDef } from "@hoppscotch/common/platform/collections" type CollectionFlags = "collectionsGraphql" | "collections" @@ -40,11 +48,8 @@ let loadedRESTCollections = false */ let loadedGraphqlCollections = false -export async function writeCollections( - collection: any[], - flag: CollectionFlags -) { - const currentUser = platform.auth.getCurrentUser() +async function writeCollections(collection: any[], flag: CollectionFlags) { + const currentUser = platformAuth.getCurrentUser() if (currentUser === null) throw new Error("User not logged in to write collections") @@ -68,11 +73,11 @@ export async function writeCollections( } } -export function initCollections() { - const currentUser$ = platform.auth.getCurrentUserStream() +function initCollectionsSync() { + const currentUser$ = platformAuth.getCurrentUserStream() const restCollSub = restCollections$.subscribe((collections) => { - const currentUser = platform.auth.getCurrentUser() + const currentUser = platformAuth.getCurrentUser() if ( loadedRESTCollections && @@ -84,7 +89,7 @@ export function initCollections() { }) const gqlCollSub = graphqlCollections$.subscribe((collections) => { - const currentUser = platform.auth.getCurrentUser() + const currentUser = platformAuth.getCurrentUser() if ( loadedGraphqlCollections && @@ -177,8 +182,12 @@ export function initCollections() { gqlCollSub.unsubscribe() currentUserSub.unsubscribe() - initCollections() + initCollectionsSync() } } ) } + +export const def: CollectionsPlatformDef = { + initCollectionsSync, +} diff --git a/packages/hoppscotch-web/src/main.ts b/packages/hoppscotch-web/src/main.ts index 5945e25ac..e223e6493 100644 --- a/packages/hoppscotch-web/src/main.ts +++ b/packages/hoppscotch-web/src/main.ts @@ -1,10 +1,12 @@ import { createHoppApp } from "@hoppscotch/common" import { def as authDef } from "./firebase/auth" import { def as envDef } from "./environments" +import { def as collectionsDef } from "./collections" createHoppApp("#app", { auth: authDef, sync: { environments: envDef, + collections: collectionsDef, }, }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa87bc638..daa4f49b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -876,6 +876,7 @@ importers: packages/hoppscotch-web: specifiers: '@hoppscotch/common': workspace:^ + '@hoppscotch/data': workspace:^0.4.4 '@hoppscotch/ui': workspace:^ '@intlify/vite-plugin-vue-i18n': ^6.0.1 '@rushstack/eslint-patch': ^1.1.4 @@ -913,6 +914,7 @@ importers: workbox-window: ^6.5.4 dependencies: '@hoppscotch/common': link:../hoppscotch-common + '@hoppscotch/data': link:../hoppscotch-data '@hoppscotch/ui': link:../hoppscotch-ui buffer: 6.0.3 firebase: 9.8.4 @@ -1474,11 +1476,6 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/helper-environment-visitor/7.18.9: - resolution: {integrity: sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==} - engines: {node: '>=6.9.0'} - dev: true - /@babel/helper-explode-assignable-expression/7.18.6: resolution: {integrity: sha512-eyAYAsQmB80jNfg4baAtLeWAQHfHFiR483rzFK+BhETlGZaQC9bsfrugfXDCbRHLQbIA7U5NxhhOxN7p/dWIcg==} engines: {node: '>=6.9.0'} @@ -1494,14 +1491,6 @@ packages: '@babel/types': 7.18.7 dev: true - /@babel/helper-function-name/7.21.0: - resolution: {integrity: sha512-HfK1aMRanKHpxemaY2gqBmL04iAPOPRj7DxtNbiDOrJK+gdwkiNRVpCpUJYbUT+aZyemKN8brqTOxzCaG6ExRg==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/template': 7.20.7 - '@babel/types': 7.21.2 - dev: true - /@babel/helper-hoist-variables/7.18.6: resolution: {integrity: sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==} engines: {node: '>=6.9.0'} @@ -1670,14 +1659,6 @@ packages: '@babel/types': 7.20.7 dev: true - /@babel/parser/7.21.2: - resolution: {integrity: sha512-URpaIJQwEkEC2T9Kn+Ai6Xe/02iNaVCuT/PtoRz3GPVJVDpPd7mLo+VddTbhCRU9TXqW5mSrQfXZyi8kDKOVpQ==} - engines: {node: '>=6.0.0'} - hasBin: true - dependencies: - '@babel/types': 7.21.2 - dev: true - /@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/7.18.6_@babel+core@7.18.6: resolution: {integrity: sha512-Dgxsyg54Fx1d4Nge8UnvTrED63vrwOdPmyvPzlNN/boaliRP54pm3pGzZD1SJUwrBA+Cs/xdG8kXX6Mn/RfISQ==} engines: {node: '>=6.9.0'} @@ -2623,24 +2604,6 @@ packages: - supports-color dev: true - /@babel/traverse/7.21.2: - resolution: {integrity: sha512-ts5FFU/dSUPS13tv8XiEObDu9K+iagEKME9kAbaP7r0Y9KtZJZ+NGndDvWoRAYNpeWafbpFeki3q9QoMD6gxyw==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/code-frame': 7.18.6 - '@babel/generator': 7.21.1 - '@babel/helper-environment-visitor': 7.18.9 - '@babel/helper-function-name': 7.21.0 - '@babel/helper-hoist-variables': 7.18.6 - '@babel/helper-split-export-declaration': 7.18.6 - '@babel/parser': 7.21.2 - '@babel/types': 7.21.2 - debug: 4.3.4 - globals: 11.12.0 - transitivePeerDependencies: - - supports-color - dev: true - /@babel/types/7.18.7: resolution: {integrity: sha512-QG3yxTcTIBoAcQmkCs+wAPYZhu7Dk9rXKacINfNbdJDNERTbLQbHGyVG8q/YGMPeCJRIhSY0+fTc5+xuh6WPSQ==} engines: {node: '>=6.9.0'} @@ -5142,8 +5105,8 @@ packages: - supports-color dev: true - /@intlify/bundle-utils/5.0.1: - resolution: {integrity: sha512-qF6reZHDm+h7jUId2npzwNZYCvrUcr0bAYnJXgiShKBxTFpxOq7nrqy7UrRWj8M2w4GTCJczeQZmQGFxc/GdFA==} + /@intlify/bundle-utils/5.2.0: + resolution: {integrity: sha512-rIfoNUTBoZK6IfaEeuoYMQZSuAXhPyZoy+UsdZj+V4eM632ynN1bGt5ttkpGO8xe0c+esfYslgJxBz//bdu4qg==} engines: {node: '>= 12'} peerDependencies: petite-vue-i18n: '*' @@ -5154,19 +5117,17 @@ packages: vue-i18n: optional: true dependencies: - '@babel/parser': 7.21.2 - '@babel/traverse': 7.21.2 '@intlify/message-compiler': 9.3.0-beta.16 '@intlify/shared': 9.3.0-beta.16 + acorn: 8.8.2 + estree-walker: 2.0.2 jsonc-eslint-parser: 1.4.1 source-map: 0.6.1 yaml-eslint-parser: 0.3.2 - transitivePeerDependencies: - - supports-color dev: true - /@intlify/bundle-utils/5.0.1_vue-i18n@9.2.2: - resolution: {integrity: sha512-qF6reZHDm+h7jUId2npzwNZYCvrUcr0bAYnJXgiShKBxTFpxOq7nrqy7UrRWj8M2w4GTCJczeQZmQGFxc/GdFA==} + /@intlify/bundle-utils/5.2.0_vue-i18n@9.2.2: + resolution: {integrity: sha512-rIfoNUTBoZK6IfaEeuoYMQZSuAXhPyZoy+UsdZj+V4eM632ynN1bGt5ttkpGO8xe0c+esfYslgJxBz//bdu4qg==} engines: {node: '>= 12'} peerDependencies: petite-vue-i18n: '*' @@ -5177,16 +5138,14 @@ packages: vue-i18n: optional: true dependencies: - '@babel/parser': 7.21.2 - '@babel/traverse': 7.21.2 '@intlify/message-compiler': 9.3.0-beta.16 '@intlify/shared': 9.3.0-beta.16 + acorn: 8.8.2 + estree-walker: 2.0.2 jsonc-eslint-parser: 1.4.1 source-map: 0.6.1 vue-i18n: 9.2.2_vue@3.2.37 yaml-eslint-parser: 0.3.2 - transitivePeerDependencies: - - supports-color dev: true /@intlify/core-base/9.2.2: @@ -5243,7 +5202,7 @@ packages: vue-i18n: optional: true dependencies: - '@intlify/bundle-utils': 5.0.1_vue-i18n@9.2.2 + '@intlify/bundle-utils': 5.2.0_vue-i18n@9.2.2 '@intlify/shared': 9.3.0-beta.16 '@rollup/pluginutils': 4.2.1 debug: 4.3.4 @@ -5270,7 +5229,7 @@ packages: vue-i18n: optional: true dependencies: - '@intlify/bundle-utils': 5.0.1 + '@intlify/bundle-utils': 5.2.0 '@intlify/shared': 9.3.0-beta.16 '@rollup/pluginutils': 4.2.1 debug: 4.3.4