diff --git a/packages/hoppscotch-common/src/components/collections/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/ImportExport.vue index 511d03a09..fa3f96f78 100644 --- a/packages/hoppscotch-common/src/components/collections/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/ImportExport.vue @@ -48,7 +48,7 @@ import { getTeamCollectionJSON } from "~/helpers/backend/helpers" import { platform } from "~/platform" import { initializeDownloadCollection } from "~/helpers/import-export/export" -import { collectionsGistExporter } from "~/helpers/import-export/export/gistExport" +import { gistExporter } from "~/helpers/import-export/export/gist" import { myCollectionsExporter } from "~/helpers/import-export/export/myCollections" import { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections" @@ -470,11 +470,11 @@ const HoppGistCollectionsExporter: ImporterOrExporter = { icon: IconGithub, disabled: !currentUser.value ? true - : currentUser.value.provider !== "github.com", + : currentUser.value?.provider !== "github.com", title: // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - currentUser?.value.provider === "github.com" + currentUser?.value?.provider === "github.com" ? "export.create_secret_gist_tooltip_text" : "export.require_github", applicableTo: ["personal-workspace", "team-workspace"], @@ -497,10 +497,7 @@ const HoppGistCollectionsExporter: ImporterOrExporter = { } if (E.isRight(collectionJSON)) { - const res = await collectionsGistExporter( - collectionJSON.right, - accessToken - ) + const res = await gistExporter(collectionJSON.right, accessToken) console.log(JSON.stringify(res, null, 2)) @@ -608,3 +605,4 @@ const getCollectionJSON = async () => { return E.left("INVALID_SELECTED_TEAM_OR_INVALID_COLLECTION_TYPE") } +~/helpers/import-export/export/gist diff --git a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue index 313f4a9d3..7eb1bbbf7 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue @@ -31,7 +31,7 @@ import { } from "~/newstore/collections" import { hoppGqlCollectionsImporter } from "~/helpers/import-export/import/hoppGql" import { gqlCollectionsExporter } from "~/helpers/import-export/export/gqlCollections" -import { gqlCollectionsGistExporter } from "~/helpers/import-export/export/gqlCollectionsGistExporter" +import { gistExporter } from "~/helpers/import-export/export/gist" import { computed } from "vue" import { hoppGQLImporter } from "~/helpers/import-export/import/hopp" @@ -165,13 +165,13 @@ const GqlCollectionsGistExporter: ImporterOrExporter = { title: // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - currentUser?.value.provider === "github.com" + currentUser?.value?.provider === "github.com" ? "export.create_secret_gist_tooltip_text" : "export.require_github", icon: IconUser, disabled: !currentUser.value ? true - : currentUser.value.provider !== "github.com", + : currentUser.value?.provider !== "github.com", applicableTo: ["personal-workspace"], isLoading: isGqlCollectionGistExportInProgress, }, @@ -190,7 +190,7 @@ const GqlCollectionsGistExporter: ImporterOrExporter = { const accessToken = currentUser.value?.accessToken if (accessToken) { - const res = await gqlCollectionsGistExporter( + const res = await gistExporter( JSON.stringify(gqlCollections.value), accessToken ) diff --git a/packages/hoppscotch-common/src/components/environments/ImportExport.vue b/packages/hoppscotch-common/src/components/environments/ImportExport.vue index daf14f7e6..6dec55f76 100644 --- a/packages/hoppscotch-common/src/components/environments/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/environments/ImportExport.vue @@ -40,7 +40,7 @@ import { initializeDownloadCollection } from "~/helpers/import-export/export" import { computed } from "vue" import { useReadonlyStream } from "~/composables/stream" import { environmentsExporter } from "~/helpers/import-export/export/environments" -import { environmentsGistExporter } from "~/helpers/import-export/export/environmentsGistExport" +import { gistExporter } from "~/helpers/import-export/export/gist" import { platform } from "~/platform" const t = useI18n() @@ -265,13 +265,13 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = { title: // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - currentUser?.value.provider === "github.com" + currentUser?.value?.provider === "github.com" ? "export.create_secret_gist_tooltip_text" : "export.require_github", icon: IconUser, disabled: !currentUser.value ? true - : currentUser.value.provider !== "github.com", + : currentUser.value?.provider !== "github.com", applicableTo: ["personal-workspace", "team-workspace"], isLoading: isEnvironmentGistExportInProgress, }, @@ -290,9 +290,10 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = { const accessToken = currentUser.value?.accessToken if (accessToken) { - const res = await environmentsGistExporter( + const res = await gistExporter( JSON.stringify(environmentJson.value), - accessToken + accessToken, + "hoppscotch-environment.json" ) if (E.isLeft(res)) { diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts b/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts deleted file mode 100644 index 4f6a66fe2..000000000 --- a/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as E from "fp-ts/Either" -import { createGist } from "~/helpers/gist" - -export const environmentsGistExporter = async ( - environmentsJSON: string, - accessToken: string -) => { - const res = await createGist( - environmentsJSON, - "hoppscotch-collections.json", - accessToken - )() - - if (E.isLeft(res)) { - return E.left(res.left) - } - return E.right(res.right.data.html_url as string) -} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/gistExport.ts b/packages/hoppscotch-common/src/helpers/import-export/export/gist.ts similarity index 55% rename from packages/hoppscotch-common/src/helpers/import-export/export/gistExport.ts rename to packages/hoppscotch-common/src/helpers/import-export/export/gist.ts index d29902c1d..18b5ddc2c 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/export/gistExport.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/export/gist.ts @@ -1,19 +1,16 @@ import { createGist } from "~/helpers/gist" import * as E from "fp-ts/Either" -export const collectionsGistExporter = async ( - collectionJSON: string, - accessToken: string +export const gistExporter = async ( + JSONFileContents: string, + accessToken: string, + fileName = "hoppscotch-collections.json" ) => { if (!accessToken) { return E.left("Invalid User") } - const res = await createGist( - collectionJSON, - "hoppscotch-collections.json", - accessToken - )() + const res = await createGist(JSONFileContents, fileName, accessToken)() if (E.isLeft(res)) { return E.left(res.left) diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts b/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts deleted file mode 100644 index 5541d0a36..000000000 --- a/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as E from "fp-ts/Either" -import { createGist } from "~/helpers/gist" - -export const gqlCollectionsGistExporter = async ( - gqlCollectionsJSON: string, - accessToken: string -) => { - const res = await createGist( - gqlCollectionsJSON, - "hoppscotch-collections.json", - accessToken - )() - - if (E.isLeft(res)) { - return E.left(res.left) - } - return E.right(res.right.data.html_url as string) -}