diff --git a/packages/hoppscotch-common/.eslintrc.js b/packages/hoppscotch-common/.eslintrc.js index f7b487189..1e467a047 100644 --- a/packages/hoppscotch-common/.eslintrc.js +++ b/packages/hoppscotch-common/.eslintrc.js @@ -69,5 +69,7 @@ module.exports = { "Do not use 'localStorage' directly. Please use the PersistenceService", }, ], + eqeqeq: 1, + "no-else-return": 1, }, } diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 1749f60ae..6f5573d38 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -273,6 +273,9 @@ "variable": "Variable", "variable_list": "Variable List" }, + "graphql_collections": { + "title": "GraphQL Collections" + }, "error": { "browser_support_sse": "This browser doesn't seems to have Server Sent Events support.", "check_console_details": "Check console log for details.", @@ -308,7 +311,8 @@ "create_secret_gist": "Create secret Gist", "gist_created": "Gist created", "require_github": "Login with GitHub to create secret gist", - "title": "Export" + "title": "Export", + "failed": "Something went wrong while exporting" }, "filter": { "all": "All", @@ -375,6 +379,7 @@ "from_openapi_description": "Import from OpenAPI specification file (YML/JSON)", "from_postman": "Import from Postman", "from_postman_description": "Import from Postman collection", + "from_file": "Import from File", "from_url": "Import from URL", "gist_url": "Enter Gist URL", "import_from_url_invalid_fetch": "Couldn't get data from the url", @@ -382,7 +387,14 @@ "import_from_url_invalid_type": "Unsupported type. accepted values are 'hoppscotch', 'openapi', 'postman', 'insomnia'", "import_from_url_success": "Collections Imported", "json_description": "Import collections from a Hoppscotch Collections JSON file", - "title": "Import" + "title": "Import", + "hoppscotch_environment": "Hoppscotch Environment", + "hoppscotch_environment_description": "Import Hoppscotch Environment JSON file", + "postman_environment": "Postman Environment", + "postman_environment_description": "Import Postman Environment JSON file", + "environments_from_gist": "Import From Gist", + "environments_from_gist_description": "Import Hoppscotch Environments From Gist", + "gql_collections_from_gist_description": "Import GraphQL Collections From Gist" }, "inspections": { "description": "Inspect possible errors", diff --git a/packages/hoppscotch-common/src/components/app/Inspection.vue b/packages/hoppscotch-common/src/components/app/Inspection.vue index ec93a902f..e44bd75c8 100644 --- a/packages/hoppscotch-common/src/components/app/Inspection.vue +++ b/packages/hoppscotch-common/src/components/app/Inspection.vue @@ -92,9 +92,8 @@ const getHighestSeverity = computed(() => { }, { severity: 0 } ) - } else { - return { severity: 0 } } + return { severity: 0 } }) const severityColor = (severity: number) => { diff --git a/packages/hoppscotch-common/src/components/collections/Collection.vue b/packages/hoppscotch-common/src/components/collections/Collection.vue index 59d44f4c6..e3fd3f458 100644 --- a/packages/hoppscotch-common/src/components/collections/Collection.vue +++ b/packages/hoppscotch-common/src/components/collections/Collection.vue @@ -290,13 +290,13 @@ const collectionIcon = computed(() => { if (props.isSelected) return IconCheckCircle else if (!props.isOpen) return IconFolder else if (props.isOpen) return IconFolderOpen - else return IconFolder + return IconFolder }) const collectionName = computed(() => { if ((props.data as HoppCollection).name) return (props.data as HoppCollection).name - else return (props.data as TeamCollection).title + return (props.data as TeamCollection).title }) watch( @@ -424,9 +424,8 @@ const isCollLoading = computed(() => { props.data.id ) { return collectionMoveLoading.includes(props.data.id) - } else { - return false } + return false }) const resetDragState = () => { diff --git a/packages/hoppscotch-common/src/components/collections/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/ImportExport.vue index ea0cafbf7..dbe682904 100644 --- a/packages/hoppscotch-common/src/components/collections/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/ImportExport.vue @@ -1,361 +1,568 @@ diff --git a/packages/hoppscotch-common/src/components/collections/MyCollections.vue b/packages/hoppscotch-common/src/components/collections/MyCollections.vue index 07a58eb82..207cd0082 100644 --- a/packages/hoppscotch-common/src/components/collections/MyCollections.vue +++ b/packages/hoppscotch-common/src/components/collections/MyCollections.vue @@ -538,13 +538,12 @@ const isSelected = ({ props.picked.folderPath === folderPath && props.picked.requestIndex === requestIndex ) - } else { - return ( - props.picked && - props.picked.pickedType === "my-folder" && - props.picked.folderPath === folderPath - ) } + return ( + props.picked && + props.picked.pickedType === "my-folder" && + props.picked.folderPath === folderPath + ) } const tabs = useService(RESTTabService) @@ -741,11 +740,10 @@ class MyCollectionsAdapter implements SmartTreeAdapter { status: "loaded", data: data, } as ChildrenResult - } else { - return { - status: "loaded", - data: [], - } + } + return { + status: "loaded", + data: [], } }) } diff --git a/packages/hoppscotch-common/src/components/collections/Request.vue b/packages/hoppscotch-common/src/components/collections/Request.vue index 07a5edebc..01e1ba0f4 100644 --- a/packages/hoppscotch-common/src/components/collections/Request.vue +++ b/packages/hoppscotch-common/src/components/collections/Request.vue @@ -374,9 +374,8 @@ const updateLastItemOrder = (e: DragEvent) => { const isRequestLoading = computed(() => { if (props.requestMoveLoading.length > 0 && props.requestID) { return props.requestMoveLoading.includes(props.requestID) - } else { - return false } + return false }) const resetDragState = () => { diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index 8a08609ea..381addd9c 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -141,9 +141,8 @@ const reqName = computed(() => { return props.request.name } else if (props.mode === "rest") { return restRequestName.value - } else { - return gqlRequestName.value } + return gqlRequestName.value }) const requestName = ref(reqName.value) @@ -480,21 +479,20 @@ const getErrorMessage = (err: GQLError) => { console.error(err) if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_coll/short_title": - return t("collection.name_length_insufficient") - case "team/invalid_coll_id": - return t("team.invalid_id") - case "team/not_required_role": - return t("profile.no_permission") - case "team_req/not_required_role": - return t("profile.no_permission") - case "Forbidden resource": - return t("profile.no_permission") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_coll/short_title": + return t("collection.name_length_insufficient") + case "team/invalid_coll_id": + return t("team.invalid_id") + case "team/not_required_role": + return t("profile.no_permission") + case "team_req/not_required_role": + return t("profile.no_permission") + case "Forbidden resource": + return t("profile.no_permission") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/collections/TeamCollections.vue b/packages/hoppscotch-common/src/components/collections/TeamCollections.vue index 7e53bc5cd..acf503fe6 100644 --- a/packages/hoppscotch-common/src/components/collections/TeamCollections.vue +++ b/packages/hoppscotch-common/src/components/collections/TeamCollections.vue @@ -554,13 +554,12 @@ const isSelected = ({ props.picked.pickedType === "teams-request" && props.picked.requestID === requestID ) - } else { - return ( - props.picked && - props.picked.pickedType === "teams-folder" && - props.picked.folderID === folderID - ) } + return ( + props.picked && + props.picked.pickedType === "teams-folder" && + props.picked.folderID === folderID + ) } const active = computed(() => tabs.currentActiveTab.value.document.saveContext) @@ -726,82 +725,78 @@ class TeamCollectionsAdapter implements SmartTreeAdapter { return { status: "loading", } - } else { - const data = this.data.value.map((item, index) => ({ - id: item.id, + } + const data = this.data.value.map((item, index) => ({ + id: item.id, + data: { + isLastItem: index === this.data.value.length - 1, + type: "collections", data: { - isLastItem: index === this.data.value.length - 1, - type: "collections", - data: { - parentIndex: null, - data: item, - }, + parentIndex: null, + data: item, }, - })) - return { - status: "loaded", - data: cloneDeep(data), - } as ChildrenResult - } - } else { - const parsedID = id.split("/")[id.split("/").length - 1] + }, + })) + return { + status: "loaded", + data: cloneDeep(data), + } as ChildrenResult + } + const parsedID = id.split("/")[id.split("/").length - 1] - !props.teamLoadingCollections.includes(parsedID) && - emit("expand-team-collection", parsedID) + !props.teamLoadingCollections.includes(parsedID) && + emit("expand-team-collection", parsedID) - if (props.teamLoadingCollections.includes(parsedID)) { - return { - status: "loading", - } - } else { - const items = this.findCollInTree(this.data.value, parsedID) - if (items) { - const data = [ - ...(items.children - ? items.children.map((item, index) => ({ - id: `${id}/${item.id}`, - data: { - isLastItem: - items.children && items.children.length > 1 - ? index === items.children.length - 1 - : false, - type: "folders", - data: { - parentIndex: parsedID, - data: item, - }, - }, - })) - : []), - ...(items.requests - ? items.requests.map((item, index) => ({ - id: `${id}/${item.id}`, - data: { - isLastItem: - items.requests && items.requests.length > 1 - ? index === items.requests.length - 1 - : false, - type: "requests", - data: { - parentIndex: parsedID, - data: item, - }, - }, - })) - : []), - ] - return { - status: "loaded", - data: cloneDeep(data), - } as ChildrenResult - } else { - return { - status: "loaded", - data: [], - } - } + if (props.teamLoadingCollections.includes(parsedID)) { + return { + status: "loading", } } + const items = this.findCollInTree(this.data.value, parsedID) + if (items) { + const data = [ + ...(items.children + ? items.children.map((item, index) => ({ + id: `${id}/${item.id}`, + data: { + isLastItem: + items.children && items.children.length > 1 + ? index === items.children.length - 1 + : false, + type: "folders", + data: { + parentIndex: parsedID, + data: item, + }, + }, + })) + : []), + ...(items.requests + ? items.requests.map((item, index) => ({ + id: `${id}/${item.id}`, + data: { + isLastItem: + items.requests && items.requests.length > 1 + ? index === items.requests.length - 1 + : false, + type: "requests", + data: { + parentIndex: parsedID, + data: item, + }, + }, + })) + : []), + ] + return { + status: "loaded", + data: cloneDeep(data), + } as ChildrenResult + } + return { + status: "loaded", + data: [], + } }) } } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue index 9b7a90764..06007c488 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue @@ -271,7 +271,7 @@ const collectionIcon = computed(() => { if (isSelected.value) return IconCheckCircle else if (!showChildren.value && !props.isFiltered) return IconFolder else if (!showChildren.value || props.isFiltered) return IconFolderOpen - else return IconFolder + return IconFolder }) const pick = () => { diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue index c692718ea..4621404e4 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue @@ -253,7 +253,7 @@ const collectionIcon = computed(() => { if (isSelected.value) return IconCheckCircle else if (!showChildren.value && !props.isFiltered) return IconFolder else if (showChildren.value || !props.isFiltered) return IconFolderOpen - else return IconFolder + return IconFolder }) const pick = () => { diff --git a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue index c78f57e51..f01036cec 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue @@ -1,299 +1,227 @@ diff --git a/packages/hoppscotch-common/src/components/collections/graphql/index.vue b/packages/hoppscotch-common/src/components/collections/graphql/index.vue index 31a42c65c..848579b99 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/index.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/index.vue @@ -137,7 +137,7 @@ @hide-modal="displayModalEditRequest(false)" /> diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index fdaa768fd..3ea3157e5 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -140,17 +140,13 @@ @hide-modal="showConfirmModal = false" @resolve="resolveConfirmModal" /> + + ([]) const requestMoveLoading = ref([]) -// Export - Import refs -const collectionJSON = ref("") -const exportingTeamCollections = ref(false) -const creatingGistCollection = ref(false) -const importingMyCollections = ref(false) - // TeamList-Adapter const workspaceService = useService(WorkspaceService) const teamListAdapter = workspaceService.acquireTeamListAdapter(null) @@ -414,14 +400,12 @@ const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, { }) const hasTeamWriteAccess = computed(() => { - if (!collectionsType.value.selectedTeam) return false + if (collectionsType.value.type !== "team-collections") { + return false + } - if ( - collectionsType.value.type === "team-collections" && - collectionsType.value.selectedTeam.myRole !== "VIEWER" - ) - return true - else return false + const role = collectionsType.value.selectedTeam?.myRole + return role === "OWNER" || role === "EDITOR" }) const filteredCollections = computed(() => { @@ -1071,7 +1055,7 @@ const onRemoveCollection = () => { const collectionIndex = editingCollectionIndex.value const collectionToRemove = - collectionIndex || collectionIndex == 0 + collectionIndex || collectionIndex === 0 ? navigateToFolderWithIndexPath(restCollectionStore.value.state, [ collectionIndex, ]) @@ -1470,9 +1454,8 @@ const checkIfCollectionIsAParentOfTheChildren = ( ) if (isEqual(slicedDestinationCollectionPath, collectionDraggedPath)) { return true - } else { - return false } + return false } return false @@ -1493,9 +1476,8 @@ const isMoveToSameLocation = ( if (isEqual(draggedItemParentPathArr, destinationPathArr)) { return true - } else { - return false } + return false } } @@ -1675,25 +1657,22 @@ const isSameSameParent = ( const dragedItemParent = draggedItemIndex.slice(0, -1) return dragedItemParent.join("/") === destinationCollectionIndex - } else { - if (destinationItemPath === null) return false - const destinationItemIndex = pathToIndex(destinationItemPath) - - // length of 1 means the request is in the root - if (draggedItemIndex.length === 1 && destinationItemIndex.length === 1) { - return true - } else if (draggedItemIndex.length === destinationItemIndex.length) { - const dragedItemParent = draggedItemIndex.slice(0, -1) - const destinationItemParent = destinationItemIndex.slice(0, -1) - if (isEqual(dragedItemParent, destinationItemParent)) { - return true - } else { - return false - } - } else { - return false - } } + if (destinationItemPath === null) return false + const destinationItemIndex = pathToIndex(destinationItemPath) + + // length of 1 means the request is in the root + if (draggedItemIndex.length === 1 && destinationItemIndex.length === 1) { + return true + } else if (draggedItemIndex.length === destinationItemIndex.length) { + const dragedItemParent = draggedItemIndex.slice(0, -1) + const destinationItemParent = destinationItemIndex.slice(0, -1) + if (isEqual(dragedItemParent, destinationItemParent)) { + return true + } + return false + } + return false } /** @@ -1835,33 +1814,6 @@ const updateCollectionOrder = (payload: { } } // Import - Export Collection functions -/** - * Export the whole my collection or specific team collection to JSON - */ -const getJSONCollection = async () => { - if (collectionsType.value.type === "my-collections") { - collectionJSON.value = JSON.stringify(myCollections.value, null, 2) - } else { - if (!collectionsType.value.selectedTeam) return - exportingTeamCollections.value = true - pipe( - await getTeamCollectionJSON(collectionsType.value.selectedTeam.id), - E.match( - (err) => { - toast.error(`${getErrorMessage(err)}`) - exportingTeamCollections.value = false - }, - (result) => { - const { exportCollectionsToJSON } = result - collectionJSON.value = exportCollectionsToJSON - exportingTeamCollections.value = false - } - ) - ) - } - - return collectionJSON.value -} /** * Create a downloadable file from a collection and prompts the user to download it. @@ -1930,90 +1882,6 @@ const exportData = async ( } } -const exportJSONCollection = async () => { - platform.analytics?.logEvent({ - type: "HOPP_EXPORT_COLLECTION", - exporter: "json", - platform: "rest", - }) - - await getJSONCollection() - - const parsedCollections = JSON.parse(collectionJSON.value) - - if (!parsedCollections.length) { - return toast.error(t("error.no_collections_to_export")) - } - - initializeDownloadCollection(collectionJSON.value, null) -} - -const createCollectionGist = async () => { - if (!currentUser.value || !currentUser.value.accessToken) { - toast.error(t("profile.no_permission").toString()) - return - } - - platform.analytics?.logEvent({ - type: "HOPP_EXPORT_COLLECTION", - exporter: "gist", - platform: "rest", - }) - - creatingGistCollection.value = true - await getJSONCollection() - - pipe( - createCollectionGists(collectionJSON.value, currentUser.value.accessToken), - TE.match( - (err) => { - toast.error(t("error.something_went_wrong").toString()) - console.error(err) - creatingGistCollection.value = false - }, - (result) => { - toast.success(t("export.gist_created").toString()) - creatingGistCollection.value = false - window.open(result.data.html_url) - } - ) - )() -} - -const importToTeams = async (collection: HoppCollection[]) => { - if (!hasTeamWriteAccess.value) { - toast.error(t("team.no_access").toString()) - return - } - - if (!collectionsType.value.selectedTeam) return - - importingMyCollections.value = true - - platform.analytics?.logEvent({ - type: "HOPP_EXPORT_COLLECTION", - exporter: "import-to-teams", - platform: "rest", - }) - - pipe( - importJSONToTeam( - JSON.stringify(collection), - collectionsType.value.selectedTeam.id - ), - TE.match( - (err: GQLError) => { - toast.error(`${getErrorMessage(err)}`) - importingMyCollections.value = false - }, - () => { - importingMyCollections.value = false - displayModalImportExport(false) - } - ) - )() -} - const shareRequest = ({ request }: { request: HoppRESTRequest }) => { if (currentUser.value) { // opens the share request modal @@ -2054,37 +1922,36 @@ const getErrorMessage = (err: GQLError) => { console.error(err) if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_coll/short_title": - return t("collection.name_length_insufficient") - case "team/invalid_coll_id": - case "bug/team_coll/no_coll_id": - case "team_req/invalid_target_id": - return t("team.invalid_coll_id") - case "team/not_required_role": - return t("profile.no_permission") - case "team_req/not_required_role": - return t("profile.no_permission") - case "Forbidden resource": - return t("profile.no_permission") - case "team_req/not_found": - return t("team.no_request_found") - case "bug/team_req/no_req_id": - return t("team.no_request_found") - case "team/collection_is_parent_coll": - return t("team.parent_coll_move") - case "team/target_and_destination_collection_are_same": - return t("team.same_target_destination") - case "team/target_collection_is_already_root_collection": - return t("collection.invalid_root_move") - case "team_req/requests_not_from_same_collection": - return t("request.different_collection") - case "team/team_collections_have_different_parents": - return t("collection.different_parent") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_coll/short_title": + return t("collection.name_length_insufficient") + case "team/invalid_coll_id": + case "bug/team_coll/no_coll_id": + case "team_req/invalid_target_id": + return t("team.invalid_coll_id") + case "team/not_required_role": + return t("profile.no_permission") + case "team_req/not_required_role": + return t("profile.no_permission") + case "Forbidden resource": + return t("profile.no_permission") + case "team_req/not_found": + return t("team.no_request_found") + case "bug/team_req/no_req_id": + return t("team.no_request_found") + case "team/collection_is_parent_coll": + return t("team.parent_coll_move") + case "team/target_and_destination_collection_are_same": + return t("team.same_target_destination") + case "team/target_collection_is_already_root_collection": + return t("collection.invalid_root_move") + case "team_req/requests_not_from_same_collection": + return t("request.different_collection") + case "team/team_collections_have_different_parents": + return t("collection.different_parent") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/environments/Add.vue b/packages/hoppscotch-common/src/components/environments/Add.vue index 3e7c0f8dd..3d81d1116 100644 --- a/packages/hoppscotch-common/src/components/environments/Add.vue +++ b/packages/hoppscotch-common/src/components/environments/Add.vue @@ -205,15 +205,14 @@ const addEnvironment = async () => { const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_environment/not_found": - return t("team_environment.not_found") - case "Forbidden resource": - return t("profile.no_permission") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_environment/not_found": + return t("team_environment.not_found") + case "Forbidden resource": + return t("profile.no_permission") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/environments/ImportExport.vue b/packages/hoppscotch-common/src/components/environments/ImportExport.vue index 71455d143..3c9162fe7 100644 --- a/packages/hoppscotch-common/src/components/environments/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/environments/ImportExport.vue @@ -1,154 +1,60 @@ diff --git a/packages/hoppscotch-common/src/components/environments/Selector.vue b/packages/hoppscotch-common/src/components/environments/Selector.vue index ed5e11c72..1b6c0d206 100644 --- a/packages/hoppscotch-common/src/components/environments/Selector.vue +++ b/packages/hoppscotch-common/src/components/environments/Selector.vue @@ -453,12 +453,11 @@ const isEnvActive = (id: string | number) => { } else { if (selectedEnvironmentIndex.value.type === "MY_ENV") { return selectedEnv.value.index === id - } else { - return ( - selectedEnvironmentIndex.value.type === "TEAM_ENV" && - selectedEnv.value.teamEnvID === id - ) } + return ( + selectedEnvironmentIndex.value.type === "TEAM_ENV" && + selectedEnv.value.teamEnvID === id + ) } } @@ -503,40 +502,36 @@ const selectedEnv = computed(() => { name: props.modelValue.environment.environment.name, teamEnvID: props.modelValue.environment.id, } - } else { - return { type: "global", name: "Global" } - } - } else { - if (selectedEnvironmentIndex.value.type === "MY_ENV") { - const environment = - myEnvironments.value[selectedEnvironmentIndex.value.index] - return { - type: "MY_ENV", - index: selectedEnvironmentIndex.value.index, - name: environment.name, - variables: environment.variables, - } - } else if (selectedEnvironmentIndex.value.type === "TEAM_ENV") { - const teamEnv = teamEnvironmentList.value.find( - (env) => - env.id === - (selectedEnvironmentIndex.value.type === "TEAM_ENV" && - selectedEnvironmentIndex.value.teamEnvID) - ) - if (teamEnv) { - return { - type: "TEAM_ENV", - name: teamEnv.environment.name, - teamEnvID: selectedEnvironmentIndex.value.teamEnvID, - variables: teamEnv.environment.variables, - } - } else { - return { type: "NO_ENV_SELECTED" } - } - } else { - return { type: "NO_ENV_SELECTED" } } + return { type: "global", name: "Global" } } + if (selectedEnvironmentIndex.value.type === "MY_ENV") { + const environment = + myEnvironments.value[selectedEnvironmentIndex.value.index] + return { + type: "MY_ENV", + index: selectedEnvironmentIndex.value.index, + name: environment.name, + variables: environment.variables, + } + } else if (selectedEnvironmentIndex.value.type === "TEAM_ENV") { + const teamEnv = teamEnvironmentList.value.find( + (env) => + env.id === + (selectedEnvironmentIndex.value.type === "TEAM_ENV" && + selectedEnvironmentIndex.value.teamEnvID) + ) + if (teamEnv) { + return { + type: "TEAM_ENV", + name: teamEnv.environment.name, + teamEnvID: selectedEnvironmentIndex.value.teamEnvID, + variables: teamEnv.environment.variables, + } + } + return { type: "NO_ENV_SELECTED" } + } + return { type: "NO_ENV_SELECTED" } }) // Set the selected environment as initial scope value @@ -584,13 +579,12 @@ const envQuickPeekActions = ref(null) const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_environment/not_found": - return t("team_environment.not_found") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_environment/not_found": + return t("team_environment.not_found") + default: + return t("error.something_went_wrong") } } @@ -599,9 +593,8 @@ const globalEnvs = useReadonlyStream(globalEnv$, []) const environmentVariables = computed(() => { if (selectedEnv.value.variables) { return selectedEnv.value.variables - } else { - return [] } + return [] }) const editGlobalEnv = () => { diff --git a/packages/hoppscotch-common/src/components/environments/my/Details.vue b/packages/hoppscotch-common/src/components/environments/my/Details.vue index 77c34db51..d40e232c3 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Details.vue @@ -198,9 +198,8 @@ const workingEnv = computed(() => { type: "MY_ENV", index: props.editingEnvironmentIndex, }) - } else { - return null } + return null }) const envList = useReadonlyStream(environments$, []) || props.envVars() @@ -226,12 +225,11 @@ const liveEnvs = computed(() => { return [ ...vars.value.map((x) => ({ ...x.env, source: editingName.value! })), ] - } else { - return [ - ...vars.value.map((x) => ({ ...x.env, source: editingName.value! })), - ...globalVars.value.map((x) => ({ ...x, source: "Global" })), - ] } + return [ + ...vars.value.map((x) => ({ ...x.env, source: editingName.value! })), + ...globalVars.value.map((x) => ({ ...x, source: "Global" })), + ] }) watch( diff --git a/packages/hoppscotch-common/src/components/environments/my/index.vue b/packages/hoppscotch-common/src/components/environments/my/index.vue index f14b4fca6..46116da3f 100644 --- a/packages/hoppscotch-common/src/components/environments/my/index.vue +++ b/packages/hoppscotch-common/src/components/environments/my/index.vue @@ -68,7 +68,7 @@ @hide-modal="displayModalEdit(false)" /> diff --git a/packages/hoppscotch-common/src/components/environments/teams/Details.vue b/packages/hoppscotch-common/src/components/environments/teams/Details.vue index 9287a83d8..2f15917ed 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Details.vue @@ -205,11 +205,8 @@ const evnExpandError = computed(() => { const liveEnvs = computed(() => { if (evnExpandError.value) { return [] - } else { - return [ - ...vars.value.map((x) => ({ ...x.env, source: editingName.value! })), - ] } + return [...vars.value.map((x) => ({ ...x.env, source: editingName.value! }))] }) watch( @@ -338,13 +335,12 @@ const hideModal = () => { const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_environment/not_found": - return t("team_environment.not_found") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_environment/not_found": + return t("team_environment.not_found") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue index d024230ba..4bff99337 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue @@ -184,13 +184,12 @@ const duplicateEnvironments = () => { const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_environment/not_found": - return t("team_environment.not_found") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_environment/not_found": + return t("team_environment.not_found") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/environments/teams/index.vue b/packages/hoppscotch-common/src/components/environments/teams/index.vue index ea4914012..c5429ef13 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/index.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/index.vue @@ -107,7 +107,7 @@ @hide-modal="displayModalEdit(false)" /> { const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - switch (err.error) { - case "team_environment/not_found": - return t("team_environment.not_found") - default: - return t("error.something_went_wrong") - } + } + switch (err.error) { + case "team_environment/not_found": + return t("team_environment.not_found") + default: + return t("error.something_went_wrong") } } diff --git a/packages/hoppscotch-common/src/components/graphql/TypeLink.vue b/packages/hoppscotch-common/src/components/graphql/TypeLink.vue index 845c32522..6b4e1c885 100644 --- a/packages/hoppscotch-common/src/components/graphql/TypeLink.vue +++ b/packages/hoppscotch-common/src/components/graphql/TypeLink.vue @@ -26,7 +26,7 @@ const isScalar = computed(() => { function resolveRootType(type: GraphQLType) { let t = type as any - while (t.ofType != null) t = t.ofType + while (t.ofType !== null) t = t.ofType return t } diff --git a/packages/hoppscotch-common/src/components/history/rest/Card.vue b/packages/hoppscotch-common/src/components/history/rest/Card.vue index e4c2f95c7..dbc6bc0ae 100644 --- a/packages/hoppscotch-common/src/components/history/rest/Card.vue +++ b/packages/hoppscotch-common/src/components/history/rest/Card.vue @@ -121,7 +121,8 @@ const duration = computed(() => { return responseDuration > 0 ? `${t("request.duration")}: ${responseDuration}ms` : t("error.no_duration") - } else return t("error.no_duration") + } + return t("error.no_duration") }) const entryStatus = computed(() => { diff --git a/packages/hoppscotch-common/src/components/http/BodyParameters.vue b/packages/hoppscotch-common/src/components/http/BodyParameters.vue index b4e4d6de7..b898e304c 100644 --- a/packages/hoppscotch-common/src/components/http/BodyParameters.vue +++ b/packages/hoppscotch-common/src/components/http/BodyParameters.vue @@ -339,7 +339,7 @@ const deleteBodyParam = (index: number) => { } workingParams.value = workingParams.value.filter( - (_, arrIndex) => arrIndex != index + (_, arrIndex) => arrIndex !== index ) } diff --git a/packages/hoppscotch-common/src/components/http/CodegenModal.vue b/packages/hoppscotch-common/src/components/http/CodegenModal.vue index e4b0fdac7..7c488bd40 100644 --- a/packages/hoppscotch-common/src/components/http/CodegenModal.vue +++ b/packages/hoppscotch-common/src/components/http/CodegenModal.vue @@ -214,10 +214,9 @@ const requestCode = computed(() => { if (O.isSome(result)) { errorState.value = false return result.value - } else { - errorState.value = true - return "" } + errorState.value = true + return "" }) // Template refs diff --git a/packages/hoppscotch-common/src/components/http/RawBody.vue b/packages/hoppscotch-common/src/components/http/RawBody.vue index 0417f8d6c..f829eef17 100644 --- a/packages/hoppscotch-common/src/components/http/RawBody.vue +++ b/packages/hoppscotch-common/src/components/http/RawBody.vue @@ -126,19 +126,19 @@ const linewrapEnabled = ref(true) const rawBodyParameters = ref(null) const codemirrorValue: Ref = - typeof rawParamsBody.value == "string" + typeof rawParamsBody.value === "string" ? ref(rawParamsBody.value) : ref(undefined) watch(rawParamsBody, (newVal) => { - typeof newVal == "string" + typeof newVal === "string" ? (codemirrorValue.value = newVal) : (codemirrorValue.value = undefined) }) // propagate the edits from codemirror back to the body watch(codemirrorValue, (updatedValue) => { - if (updatedValue && updatedValue != rawParamsBody.value) { + if (updatedValue && updatedValue !== rawParamsBody.value) { rawParamsBody.value = updatedValue } }) @@ -185,7 +185,7 @@ const prettifyRequestBody = () => { if (body.value.contentType.endsWith("json")) { const jsonObj = JSON.parse(rawParamsBody.value as string) prettifyBody = JSON.stringify(jsonObj, null, 2) - } else if (body.value.contentType == "application/xml") { + } else if (body.value.contentType === "application/xml") { prettifyBody = prettifyXML(rawParamsBody.value as string) } rawParamsBody.value = prettifyBody diff --git a/packages/hoppscotch-common/src/components/http/URLEncodedParams.vue b/packages/hoppscotch-common/src/components/http/URLEncodedParams.vue index 2d36f565e..14ca424e4 100644 --- a/packages/hoppscotch-common/src/components/http/URLEncodedParams.vue +++ b/packages/hoppscotch-common/src/components/http/URLEncodedParams.vue @@ -242,7 +242,7 @@ const urlEncodedParamsRaw = pluckRef(body, "body") const urlEncodedParams = computed({ get() { - return typeof urlEncodedParamsRaw.value == "string" + return typeof urlEncodedParamsRaw.value === "string" ? parseRawKeyValueEntries(urlEncodedParamsRaw.value) : [] }, diff --git a/packages/hoppscotch-common/src/components/importExport/Base.vue b/packages/hoppscotch-common/src/components/importExport/Base.vue new file mode 100644 index 000000000..ddf17caa3 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/Base.vue @@ -0,0 +1,163 @@ + + diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue new file mode 100644 index 000000000..0be3a87b2 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue @@ -0,0 +1,75 @@ + + + diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSourcesList.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSourcesList.vue new file mode 100644 index 000000000..54d186b56 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSourcesList.vue @@ -0,0 +1,33 @@ + + + diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/FileImport.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/FileImport.vue new file mode 100644 index 000000000..97c373257 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/FileImport.vue @@ -0,0 +1,95 @@ + + + diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/MyCollectionImport.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/MyCollectionImport.vue new file mode 100644 index 000000000..44319b7d4 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/MyCollectionImport.vue @@ -0,0 +1,65 @@ + + + diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue new file mode 100644 index 000000000..db4f86bac --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue @@ -0,0 +1,95 @@ + + + diff --git a/packages/hoppscotch-common/src/components/importExport/types.ts b/packages/hoppscotch-common/src/components/importExport/types.ts new file mode 100644 index 000000000..9efb4eb60 --- /dev/null +++ b/packages/hoppscotch-common/src/components/importExport/types.ts @@ -0,0 +1,23 @@ +import { Component, Ref } from "vue" +import { defineStep } from "~/composables/step-components" + +// TODO: move the metadata except disabled and isLoading to importers.ts +export type ImporterOrExporter = { + metadata: { + id: string + name: string + icon: any + title: string + disabled: boolean + applicableTo: Array<"personal-workspace" | "team-workspace" | "url-import"> + isLoading?: Ref + } + supported_sources?: { + id: string + name: string + icon: Component + step: ReturnType + }[] + component?: ReturnType + action?: (...args: any[]) => any +} diff --git a/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue b/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue index 7c28c11d9..e1faa8c1a 100644 --- a/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue +++ b/packages/hoppscotch-common/src/components/lenses/renderers/JSONLensRenderer.vue @@ -313,9 +313,8 @@ const jsonResponseBodyText = computed(() => { ), E.map(JSON.stringify) ) - } else { - return E.right(responseBodyText.value) } + return E.right(responseBodyText.value) }) const jsonBodyText = computed(() => diff --git a/packages/hoppscotch-common/src/components/lenses/renderers/mixins/TextContentRendererMixin.js b/packages/hoppscotch-common/src/components/lenses/renderers/mixins/TextContentRendererMixin.js index a01d610d8..f040d7928 100644 --- a/packages/hoppscotch-common/src/components/lenses/renderers/mixins/TextContentRendererMixin.js +++ b/packages/hoppscotch-common/src/components/lenses/renderers/mixins/TextContentRendererMixin.js @@ -5,12 +5,11 @@ export default { computed: { responseBodyText() { if (typeof this.response.body === "string") return this.response.body - else { - const res = new TextDecoder("utf-8").decode(this.response.body) - // HACK: Temporary trailing null character issue from the extension fix - return res.replace(/\0+$/, "") - } + const res = new TextDecoder("utf-8").decode(this.response.body) + + // HACK: Temporary trailing null character issue from the extension fix + return res.replace(/\0+$/, "") }, }, } diff --git a/packages/hoppscotch-common/src/components/profile/UserDelete.vue b/packages/hoppscotch-common/src/components/profile/UserDelete.vue index 6b3121d0b..8a54c1a24 100644 --- a/packages/hoppscotch-common/src/components/profile/UserDelete.vue +++ b/packages/hoppscotch-common/src/components/profile/UserDelete.vue @@ -26,7 +26,7 @@

{{ t("error.danger_zone") }} @@ -45,7 +45,7 @@

{{ t("error.danger_zone") }} @@ -173,8 +173,8 @@ const deleteUserAccount = async () => { const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") - } else { - return t("error.something_went_wrong") } + + return t("error.something_went_wrong") } diff --git a/packages/hoppscotch-common/src/components/realtime/LogEntry.vue b/packages/hoppscotch-common/src/components/realtime/LogEntry.vue index 015502e86..907af3766 100644 --- a/packages/hoppscotch-common/src/components/realtime/LogEntry.vue +++ b/packages/hoppscotch-common/src/components/realtime/LogEntry.vue @@ -269,12 +269,12 @@ const ast = computed(() => const editorText = computed(() => { if (selectedTab.value === "json") return jsonBodyText.value - else return logPayload.value + return logPayload.value }) const editorMode = computed(() => { if (selectedTab.value === "json") return "application/ld+json" - else return "text/plain" + return "text/plain" }) const { cursor } = useCodemirror( diff --git a/packages/hoppscotch-common/src/components/smart/EnvInput.vue b/packages/hoppscotch-common/src/components/smart/EnvInput.vue index e8b02dcca..2ab85602b 100644 --- a/packages/hoppscotch-common/src/components/smart/EnvInput.vue +++ b/packages/hoppscotch-common/src/components/smart/EnvInput.vue @@ -124,9 +124,8 @@ onClickOutside(autoCompleteWrapper, () => { const uniqueAutoCompleteSource = computed(() => { if (props.autoCompleteSource) { return [...new Set(props.autoCompleteSource)] - } else { - return [] } + return [] }) const suggestions = computed(() => { @@ -139,9 +138,8 @@ const suggestions = computed(() => { return uniqueAutoCompleteSource.value.filter((suggestion) => suggestion.toLowerCase().includes(props.modelValue.toLowerCase()) ) - } else { - return uniqueAutoCompleteSource.value ?? [] } + return uniqueAutoCompleteSource.value ?? [] }) const updateModelValue = (value: string) => { diff --git a/packages/hoppscotch-common/src/components/teams/Edit.vue b/packages/hoppscotch-common/src/components/teams/Edit.vue index f0e6b5e68..dda42cf4a 100644 --- a/packages/hoppscotch-common/src/components/teams/Edit.vue +++ b/packages/hoppscotch-common/src/components/teams/Edit.vue @@ -276,7 +276,8 @@ const teamDetails = useGQLQuery({ }, }, ] - } else return [] + } + return [] }), }) diff --git a/packages/hoppscotch-common/src/components/teams/Invite.vue b/packages/hoppscotch-common/src/components/teams/Invite.vue index c8ddfec31..6feaed7c4 100644 --- a/packages/hoppscotch-common/src/components/teams/Invite.vue +++ b/packages/hoppscotch-common/src/components/teams/Invite.vue @@ -570,17 +570,16 @@ const sendInvites = async () => { const getErrorMessage = (error: SendInvitesErrorType) => { if (error.type === "network_error") { return t("error.network_error") - } else { - switch (error.error) { - case "team/invalid_id": - return t("team.invalid_id") - case "team/member_not_found": - return t("team.member_not_found") - case "team_invite/already_member": - return t("team.already_member") - case "team_invite/member_has_invite": - return t("team.member_has_invite") - } + } + switch (error.error) { + case "team/invalid_id": + return t("team.invalid_id") + case "team/member_not_found": + return t("team.member_not_found") + case "team_invite/already_member": + return t("team.already_member") + case "team_invite/member_has_invite": + return t("team.member_has_invite") } } diff --git a/packages/hoppscotch-common/src/components/teams/MemberStack.vue b/packages/hoppscotch-common/src/components/teams/MemberStack.vue index 76eddaabe..155f8a9c4 100644 --- a/packages/hoppscotch-common/src/components/teams/MemberStack.vue +++ b/packages/hoppscotch-common/src/components/teams/MemberStack.vue @@ -57,9 +57,8 @@ const maxMembersHardLimit = 6 const slicedTeamMembers = computed(() => { if (props.showCount && props.teamMembers.length > maxMembersSoftLimit) { return props.teamMembers.slice(0, maxMembersSoftLimit) - } else { - return props.teamMembers } + return props.teamMembers }) const remainingSlicedMembers = computed( diff --git a/packages/hoppscotch-common/src/composables/lens-actions.ts b/packages/hoppscotch-common/src/composables/lens-actions.ts index 9e02ac3c9..54b366cd6 100644 --- a/packages/hoppscotch-common/src/composables/lens-actions.ts +++ b/packages/hoppscotch-common/src/composables/lens-actions.ts @@ -155,11 +155,10 @@ export function useResponseBody(response: HoppRESTResponse): { ) return "" if (typeof response.body === "string") return response.body - else { - const res = new TextDecoder("utf-8").decode(response.body) - // HACK: Temporary trailing null character issue from the extension fix - return res.replace(/\0+$/, "") - } + + const res = new TextDecoder("utf-8").decode(response.body) + // HACK: Temporary trailing null character issue from the extension fix + return res.replace(/\0+$/, "") }) return { responseBodyText, diff --git a/packages/hoppscotch-common/src/composables/step-components.ts b/packages/hoppscotch-common/src/composables/step-components.ts new file mode 100644 index 000000000..da858434b --- /dev/null +++ b/packages/hoppscotch-common/src/composables/step-components.ts @@ -0,0 +1,69 @@ +import { computed, defineComponent, ref } from "vue" + +export function useSteps() { + type Step = ReturnType + + const steps: Step[] = [] + + const currentStepIndex = ref(0) + + const currentStep = computed(() => { + return steps[currentStepIndex.value] + }) + + const backHistoryIndexes = ref([0]) + + const hasPreviousStep = computed(() => { + return currentStepIndex.value > 0 + }) + + const addStep = (step: Step) => { + steps.push(step) + } + + const goToNextStep = () => { + currentStepIndex.value++ + backHistoryIndexes.value.push(currentStepIndex.value) + } + + const goToStep = (stepId: string) => { + currentStepIndex.value = steps.findIndex((step) => step.id === stepId) + backHistoryIndexes.value.push(currentStepIndex.value) + } + + const goToPreviousStep = () => { + if (backHistoryIndexes.value.length !== 1) { + backHistoryIndexes.value.pop() + currentStepIndex.value = + backHistoryIndexes.value[backHistoryIndexes.value.length - 1] + } + } + + return { + steps, + currentStep, + addStep, + goToPreviousStep, + goToNextStep, + goToStep, + hasPreviousStep, + } +} + +export function defineStep< + StepComponent extends ReturnType, +>( + id: string, + component: StepComponent, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + props: () => InstanceType["$props"] +) { + const step = { + id, + component, + props, + } + + return step +} diff --git a/packages/hoppscotch-common/src/helpers/RESTExtURLParams.ts b/packages/hoppscotch-common/src/helpers/RESTExtURLParams.ts index 453100bfb..6efccd8cd 100644 --- a/packages/hoppscotch-common/src/helpers/RESTExtURLParams.ts +++ b/packages/hoppscotch-common/src/helpers/RESTExtURLParams.ts @@ -10,7 +10,7 @@ export function translateExtURLParams( initialReq?: HoppRESTRequest ): HoppRESTRequest { if (urlParams.v) return parseV1ExtURL(urlParams, initialReq) - else return parseV0ExtURL(urlParams, initialReq) + return parseV0ExtURL(urlParams, initialReq) } function parseV0ExtURL( diff --git a/packages/hoppscotch-common/src/helpers/backend/GQLClient.ts b/packages/hoppscotch-common/src/helpers/backend/GQLClient.ts index 15a1c420a..9f055dd7c 100644 --- a/packages/hoppscotch-common/src/helpers/backend/GQLClient.ts +++ b/packages/hoppscotch-common/src/helpers/backend/GQLClient.ts @@ -325,7 +325,8 @@ export const runAuthOnlyGQLSubscription = flow( ) { sub.unsubscribe() return null - } else return res + } + return res }), filter((res): res is Exclude => res !== null) ) diff --git a/packages/hoppscotch-common/src/helpers/backend/helpers.ts b/packages/hoppscotch-common/src/helpers/backend/helpers.ts index 6a101ecb3..8ef746079 100644 --- a/packages/hoppscotch-common/src/helpers/backend/helpers.ts +++ b/packages/hoppscotch-common/src/helpers/backend/helpers.ts @@ -132,17 +132,10 @@ export const teamCollToHoppRESTColl = ( * @param teamID - ID of the team * @returns Either of the JSON string of the collection or the error */ -export const getTeamCollectionJSON = async (teamID: string) => { - const data = await runGQLQuery({ +export const getTeamCollectionJSON = async (teamID: string) => + await runGQLQuery({ query: ExportAsJsonDocument, variables: { teamID, }, }) - - if (E.isLeft(data)) { - return E.left(data.left) - } - - return E.right(data.right) -} diff --git a/packages/hoppscotch-common/src/helpers/collection/collection.ts b/packages/hoppscotch-common/src/helpers/collection/collection.ts index 8e55c3e5d..a0f14df14 100644 --- a/packages/hoppscotch-common/src/helpers/collection/collection.ts +++ b/packages/hoppscotch-common/src/helpers/collection/collection.ts @@ -164,11 +164,10 @@ export function getFoldersByPath( if (pathArray.length === 1) { return currentCollection.folders - } else { - for (let i = 1; i < pathArray.length; i++) { - const folder = currentCollection.folders[pathArray[i]] - if (folder) currentCollection = folder - } + } + for (let i = 1; i < pathArray.length; i++) { + const folder = currentCollection.folders[pathArray[i]] + if (folder) currentCollection = folder } return currentCollection.folders diff --git a/packages/hoppscotch-common/src/helpers/collection/request.ts b/packages/hoppscotch-common/src/helpers/collection/request.ts index ec7b819f4..8bd4237a9 100644 --- a/packages/hoppscotch-common/src/helpers/collection/request.ts +++ b/packages/hoppscotch-common/src/helpers/collection/request.ts @@ -63,11 +63,10 @@ export function getRequestsByPath( if (pathArray.length === 1) { return currentCollection.requests - } else { - for (let i = 1; i < pathArray.length; i++) { - const folder = currentCollection.folders[pathArray[i]] - if (folder) currentCollection = folder - } + } + for (let i = 1; i < pathArray.length; i++) { + const folder = currentCollection.folders[pathArray[i]] + if (folder) currentCollection = folder } return currentCollection.requests diff --git a/packages/hoppscotch-common/src/helpers/curl/sub_helpers/method.ts b/packages/hoppscotch-common/src/helpers/curl/sub_helpers/method.ts index 4b43a0e77..11b6cee79 100644 --- a/packages/hoppscotch-common/src/helpers/curl/sub_helpers/method.ts +++ b/packages/hoppscotch-common/src/helpers/curl/sub_helpers/method.ts @@ -51,7 +51,7 @@ const getMethodByDeduction = (parsedArguments: parser.Arguments) => { )(parsedArguments) ) return O.some("POST") - else return O.none + return O.none } /** diff --git a/packages/hoppscotch-common/src/helpers/editor/linting/rawKeyValue.ts b/packages/hoppscotch-common/src/helpers/editor/linting/rawKeyValue.ts index 14cd36526..bd83c0efa 100644 --- a/packages/hoppscotch-common/src/helpers/editor/linting/rawKeyValue.ts +++ b/packages/hoppscotch-common/src/helpers/editor/linting/rawKeyValue.ts @@ -16,9 +16,8 @@ const linter: LinterDefinition = (text) => { severity: "error", }, ]) - } else { - return Promise.resolve([]) } + return Promise.resolve([]) } export default linter diff --git a/packages/hoppscotch-common/src/helpers/gist.ts b/packages/hoppscotch-common/src/helpers/gist.ts index 9f854952c..2fad46aa6 100644 --- a/packages/hoppscotch-common/src/helpers/gist.ts +++ b/packages/hoppscotch-common/src/helpers/gist.ts @@ -1,14 +1,9 @@ import axios from "axios" import * as TE from "fp-ts/TaskEither" -/** - * Create an gist on GitHub with the collection JSON - * @param collectionJSON - JSON string of the collection - * @param accessToken - GitHub access token - * @returns Either of the response of the GitHub Gist API or the error - */ -export const createCollectionGists = ( - collectionJSON: string, +export const createGist = ( + content: string, + filename: string, accessToken: string ) => { return TE.tryCatch( @@ -17,8 +12,8 @@ export const createCollectionGists = ( "https://api.github.com/gists", { files: { - "hoppscotch-collections.json": { - content: collectionJSON, + [filename]: { + content: content, }, }, }, diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/environments.ts b/packages/hoppscotch-common/src/helpers/import-export/export/environments.ts new file mode 100644 index 000000000..c8554b625 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/environments.ts @@ -0,0 +1,5 @@ +import { Environment } from "@hoppscotch/data" + +export const environmentsExporter = (myEnvironments: Environment[]) => { + return JSON.stringify(myEnvironments, null, 2) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts b/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts new file mode 100644 index 000000000..4f6a66fe2 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/environmentsGistExport.ts @@ -0,0 +1,18 @@ +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/gistExport.ts new file mode 100644 index 000000000..56b24e6d8 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/gistExport.ts @@ -0,0 +1,22 @@ +import { createGist } from "~/helpers/gist" +import * as E from "fp-ts/Either" + +export const collectionsGistExporter = async ( + collectionJSON: string, + accessToken: string +) => { + if (!accessToken) { + return E.left("Invalid User") + } + + const res = await createGist( + collectionJSON, + "hoppscotch-collections.json", + accessToken + )() + + if (E.isLeft(res)) { + return E.left(res.left) + } + return E.right(true) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollections.ts b/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollections.ts new file mode 100644 index 000000000..d7e5efcb7 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollections.ts @@ -0,0 +1,7 @@ +import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" + +export const gqlCollectionsExporter = ( + gqlCollections: HoppCollection[] +) => { + return JSON.stringify(gqlCollections, null, 2) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts b/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts new file mode 100644 index 000000000..5541d0a36 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/gqlCollectionsGistExporter.ts @@ -0,0 +1,18 @@ +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) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/hopp.ts b/packages/hoppscotch-common/src/helpers/import-export/export/hopp.ts deleted file mode 100644 index 1e74d6bfe..000000000 --- a/packages/hoppscotch-common/src/helpers/import-export/export/hopp.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data" -import { pipe } from "fp-ts/function" -import * as TE from "fp-ts/TaskEither" -import { HoppExporter } from "." - -const exporter: HoppExporter> = (content) => - pipe(content, JSON.stringify, TE.right) - -export default exporter diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/index.ts b/packages/hoppscotch-common/src/helpers/import-export/export/index.ts index 1ec1894c9..23e7fe5b2 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/export/index.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/export/index.ts @@ -1,18 +1,32 @@ -import * as TE from "fp-ts/TaskEither" -import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data" +import * as E from "fp-ts/Either" -export type HoppExporter = (content: T) => TE.TaskEither +/** + * Create a downloadable file from a collection and prompts the user to download it. + * @param collectionJSON - JSON string of the collection + * @param name - Name of the collection set as the file name + */ +export const initializeDownloadCollection = ( + collectionJSON: string, + name: string | null +) => { + const file = new Blob([collectionJSON], { type: "application/json" }) + const a = document.createElement("a") + const url = URL.createObjectURL(file) + a.href = url -export type HoppExporterDefinition = { - name: string - exporter: () => Promise> + if (name) { + a.download = `${name}.json` + } else { + a.download = `${url.split("/").pop()!.split("#")[0].split("?")[0]}.json` + } + + document.body.appendChild(a) + a.click() + + setTimeout(() => { + document.body.removeChild(a) + URL.revokeObjectURL(url) + }, 1000) + + return E.right("state.download_started") } - -export const RESTCollectionExporters: HoppExporterDefinition< - HoppCollection ->[] = [ - { - name: "Hoppscotch REST Collection JSON", - exporter: () => import("./hopp").then((m) => m.default), - }, -] diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/myCollections.ts b/packages/hoppscotch-common/src/helpers/import-export/export/myCollections.ts new file mode 100644 index 000000000..a49b1dd3e --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/myCollections.ts @@ -0,0 +1,7 @@ +import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" + +export const myCollectionsExporter = ( + myCollections: HoppCollection[] +) => { + return JSON.stringify(myCollections, null, 2) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/teamCollections.ts b/packages/hoppscotch-common/src/helpers/import-export/export/teamCollections.ts new file mode 100644 index 000000000..daf5e25a4 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/export/teamCollections.ts @@ -0,0 +1,5 @@ +import { getTeamCollectionJSON } from "~/helpers/backend/helpers" + +export const teamCollectionsExporter = (teamID: string) => { + return getTeamCollectionJSON(teamID) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/gist.ts b/packages/hoppscotch-common/src/helpers/import-export/import/gist.ts deleted file mode 100644 index a42cb3d4b..000000000 --- a/packages/hoppscotch-common/src/helpers/import-export/import/gist.ts +++ /dev/null @@ -1,52 +0,0 @@ -import IconGithub from "~icons/lucide/github" -import { pipe } from "fp-ts/function" -import * as TE from "fp-ts/TaskEither" -import * as TO from "fp-ts/TaskOption" -import * as O from "fp-ts/Option" -import axios from "axios" -import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data" -import { step } from "../steps" -import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "." - -// TODO: Add validation to output -const fetchGist = ( - url: string -): TO.TaskOption[]> => - pipe( - TO.tryCatch(() => - axios.get(`https://api.github.com/gists/${url.split("/").pop()}`, { - headers: { - Accept: "application/vnd.github.v3+json", - }, - }) - ), - TO.chain((res) => - pipe( - O.tryCatch(() => - JSON.parse((Object.values(res.data.files)[0] as any).content) - ), - TO.fromOption - ) - ) - ) - -export default defineImporter({ - id: "gist", - name: "import.from_gist", - icon: IconGithub, - applicableTo: ["my-collections", "team-collections"], - steps: [ - step({ - stepName: "URL_IMPORT", - metadata: { - caption: "import.from_gist_description", - placeholder: "import.gist_url", - }, - }), - ] as const, - importer: ([content]) => - pipe( - fetchGist(content), - TE.fromTaskOption(() => IMPORTER_INVALID_FILE_FORMAT) - ), -}) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts b/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts index 259ea59be..88818e24d 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts @@ -1,4 +1,3 @@ -import IconFolderPlus from "~icons/lucide/folder-plus" import { pipe, flow } from "fp-ts/function" import * as TE from "fp-ts/TaskEither" import * as O from "fp-ts/Option" @@ -9,38 +8,23 @@ import { HoppRESTRequest, } from "@hoppscotch/data" import { isPlainObject as _isPlainObject } from "lodash-es" -import { step } from "../steps" -import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "." + +import { IMPORTER_INVALID_FILE_FORMAT } from "." import { safeParseJSON } from "~/helpers/functional/json" -export default defineImporter({ - id: "hoppscotch", - name: "import.from_json", - icon: IconFolderPlus, - applicableTo: ["my-collections", "team-collections", "url-import"], - steps: [ - step({ - stepName: "FILE_IMPORT", - metadata: { - caption: "import.from_json_description", - acceptedFileTypes: "application/json", - }, - }), - ] as const, - importer: ([content]) => - pipe( - safeParseJSON(content), - O.chain( - flow( - makeCollectionsArray, - RA.map(validateCollection), - O.sequenceArray, - O.map(RA.toArray) - ) - ), - TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT) +export const hoppRESTImporter = (content: string) => + pipe( + safeParseJSON(content), + O.chain( + flow( + makeCollectionsArray, + RA.map(validateCollection), + O.sequenceArray, + O.map(RA.toArray) + ) ), -}) + TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT) + ) /** * checks if a value is a plain object @@ -63,9 +47,8 @@ const isValidCollection = ( const validateCollection = (collection: unknown) => { if (isValidCollection(collection)) { return O.some(collection) - } else { - return O.some(translateToNewRESTCollection(collection)) } + return O.some(translateToNewRESTCollection(collection)) } /** diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts new file mode 100644 index 000000000..0e961b72a --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts @@ -0,0 +1,37 @@ +import * as TE from "fp-ts/TaskEither" +import * as O from "fp-ts/Option" + +import { IMPORTER_INVALID_FILE_FORMAT } from "." +import { safeParseJSON } from "~/helpers/functional/json" + +import { z } from "zod" + +const hoppEnvSchema = z.object({ + id: z.string().optional(), + name: z.string(), + variables: z.array( + z.object({ + key: z.string(), + value: z.string(), + }) + ), +}) + +export const hoppEnvImporter = (content: string) => { + const parsedContent = safeParseJSON(content) + + // parse json from the environments string + if (O.isNone(parsedContent)) { + return TE.left(IMPORTER_INVALID_FILE_FORMAT) + } + + const validationResult = z.array(hoppEnvSchema).safeParse(parsedContent.value) + + if (!validationResult.success) { + return TE.left(IMPORTER_INVALID_FILE_FORMAT) + } + + const environments = validationResult.data + + return TE.right(environments) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/hoppGql.ts b/packages/hoppscotch-common/src/helpers/import-export/import/hoppGql.ts new file mode 100644 index 000000000..6277be89a --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/hoppGql.ts @@ -0,0 +1,12 @@ +import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" +import * as E from "fp-ts/Either" + +// TODO: add zod validation +export const hoppGqlCollectionsImporter = ( + content: string +): E.Either<"INVALID_JSON", HoppCollection[]> => { + return E.tryCatch( + () => JSON.parse(content) as HoppCollection[], + () => "INVALID_JSON" + ) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/FileSource.ts b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/FileSource.ts new file mode 100644 index 000000000..b40755fcc --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/FileSource.ts @@ -0,0 +1,18 @@ +import FileImportVue from "~/components/importExport/ImportExportSteps/FileImport.vue" +import { defineStep } from "~/composables/step-components" + +import { v4 as uuidv4 } from "uuid" + +export function FileSource(metadata: { + acceptedFileTypes: string + caption: string + onImportFromFile: (content: string) => any | Promise +}) { + const stepID = uuidv4() + + return defineStep(stepID, FileImportVue, () => ({ + acceptedFileTypes: metadata.acceptedFileTypes, + caption: metadata.caption, + onImportFromFile: metadata.onImportFromFile, + })) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts new file mode 100644 index 000000000..ff97bb45f --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts @@ -0,0 +1,45 @@ +import axios from "axios" +import UrlImport from "~/components/importExport/ImportExportSteps/UrlImport.vue" +import { defineStep } from "~/composables/step-components" + +import * as E from "fp-ts/Either" +import { z } from "zod" + +import { v4 as uuidv4 } from "uuid" + +export function GistSource(metadata: { + caption: string + onImportFromGist: ( + importResult: E.Either + ) => any | Promise +}) { + const stepID = uuidv4() + + return defineStep(stepID, UrlImport, () => ({ + caption: metadata.caption, + onImportFromURL: (gistResponse) => { + const fileSchema = z.object({ + files: z.record(z.object({ content: z.string() })), + }) + + const parseResult = fileSchema.safeParse(gistResponse) + + if (!parseResult.success) { + metadata.onImportFromGist(E.left("INVALID_GIST")) + return + } + + const content = Object.values(parseResult.data.files)[0].content + + metadata.onImportFromGist(E.right(content)) + }, + fetchLogic: fetchGistFromUrl, + })) +} + +const fetchGistFromUrl = (url: string) => + axios.get(`https://api.github.com/gists/${url.split("/").pop()}`, { + headers: { + Accept: "application/vnd.github.v3+json", + }, + }) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/UrlSource.ts b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/UrlSource.ts new file mode 100644 index 000000000..961dc8056 --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/UrlSource.ts @@ -0,0 +1,21 @@ +import UrlImport from "~/components/importExport/ImportExportSteps/UrlImport.vue" +import { defineStep } from "~/composables/step-components" + +import { v4 as uuidv4 } from "uuid" + +export function UrlSource(metadata: { + caption: string + onImportFromURL: (content: string) => any | Promise + fetchLogic?: (url: string) => Promise +}) { + const stepID = uuidv4() + + return defineStep(stepID, UrlImport, () => ({ + caption: metadata.caption, + onImportFromURL: (content: unknown) => { + if (typeof content === "string") { + metadata.onImportFromURL(content) + } + }, + })) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/importers.ts b/packages/hoppscotch-common/src/helpers/import-export/import/importers.ts index de7a22f02..8f7ec3e55 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/importers.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/importers.ts @@ -1,22 +1,5 @@ -import HoppRESTCollImporter from "./hopp" -import OpenAPIImporter from "./openapi" -import PostmanImporter from "./postman" -import InsomniaImporter from "./insomnia" -import GistImporter from "./gist" -import MyCollectionsImporter from "./myCollections" - -export const RESTCollectionImporters = [ - HoppRESTCollImporter, - OpenAPIImporter, - PostmanImporter, - InsomniaImporter, - GistImporter, - MyCollectionsImporter, -] as const - -export const URLImporters = [ - HoppRESTCollImporter, - OpenAPIImporter, - PostmanImporter, - InsomniaImporter, -] as const +export { hoppRESTImporter } from "./hopp" +export { hoppOpenAPIImporter } from "./openapi" +export { hoppPostmanImporter } from "./postman" +export { hoppInsomniaImporter } from "./insomnia" +export { toTeamsImporter } from "./myCollections" diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts b/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts index d4a139ad0..2ecca47d5 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/insomnia.ts @@ -1,4 +1,3 @@ -import IconInsomnia from "~icons/hopp/insomnia" import { convert, ImportRequest } from "insomnia-importers" import { pipe, flow } from "fp-ts/function" import { @@ -16,8 +15,7 @@ import * as A from "fp-ts/Array" import * as S from "fp-ts/string" import * as TO from "fp-ts/TaskOption" import * as TE from "fp-ts/TaskEither" -import { step } from "../steps" -import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "." +import { IMPORTER_INVALID_FILE_FORMAT } from "." // TODO: Insomnia allows custom prefixes for Bearer token auth, Hoppscotch doesn't. We just ignore the prefix for now @@ -210,27 +208,10 @@ const getHoppCollections = (doc: InsomniaDoc) => getHoppFolder(f, doc.data.resources) ) -export default defineImporter({ - id: "insomnia", - name: "import.from_insomnia", - applicableTo: ["my-collections", "team-collections", "url-import"], - icon: IconInsomnia, - steps: [ - step({ - stepName: "FILE_IMPORT", - metadata: { - caption: "import.from_insomnia_description", - acceptedFileTypes: ".json, .yaml", - }, - }), - ] as const, - importer: ([fileContent]) => - pipe( - fileContent, - parseInsomniaDoc, - - TO.map(getHoppCollections), - - TE.fromTaskOption(() => IMPORTER_INVALID_FILE_FORMAT) - ), -}) +export const hoppInsomniaImporter = (fileContent: string) => + pipe( + fileContent, + parseInsomniaDoc, + TO.map(getHoppCollections), + TE.fromTaskOption(() => IMPORTER_INVALID_FILE_FORMAT) + ) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/myCollections.ts b/packages/hoppscotch-common/src/helpers/import-export/import/myCollections.ts index 3bcfaef74..a8f5fcc78 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/myCollections.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/myCollections.ts @@ -1,23 +1,5 @@ -import IconUser from "~icons/lucide/user" -import * as TE from "fp-ts/TaskEither" -import * as A from "fp-ts/Array" -import { pipe } from "fp-ts/function" -import { step } from "../steps" -import { defineImporter } from "." -import { getRESTCollection } from "~/newstore/collections" +import { importJSONToTeam } from "~/helpers/backend/mutations/TeamCollection" -export default defineImporter({ - id: "myCollections", - name: "import.from_my_collections", - icon: IconUser, - applicableTo: ["team-collections"], - steps: [ - step({ - stepName: "TARGET_MY_COLLECTION", - metadata: { - caption: "import.from_my_collections_description", - }, - }), - ] as const, - importer: ([content]) => pipe(content, getRESTCollection, A.of, TE.of), -}) +export function toTeamsImporter(content: string, teamID: string) { + return importJSONToTeam(content, teamID) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts index d0a60cf18..e5f9fc9aa 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts @@ -1,4 +1,3 @@ -import IconOpenAPI from "~icons/lucide/file" import { OpenAPI, OpenAPIV2, @@ -25,8 +24,7 @@ import * as S from "fp-ts/string" import * as O from "fp-ts/Option" import * as TE from "fp-ts/TaskEither" import * as RA from "fp-ts/ReadonlyArray" -import { step } from "../steps" -import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "." +import { IMPORTER_INVALID_FILE_FORMAT } from "." export const OPENAPI_DEREF_ERROR = "openapi/deref_error" as const @@ -167,14 +165,12 @@ const parseOpenAPIV3BodyFormData = ( contentType, body: keys.map((key) => `${key}: `).join("\n"), } - } else { - return { - contentType, - body: keys.map( - (key) => - { key, value: "", isFile: false, active: true } - ), - } + } + return { + contentType, + body: keys.map( + (key) => { key, value: "", isFile: false, active: true } + ), } } @@ -233,10 +229,9 @@ const resolveOpenAPIV3SecurityObj = ( } else if (scheme.scheme === "bearer") { // Bearer return { authType: "bearer", authActive: true, token: "" } - } else { - // Unknown/Unsupported Scheme - return { authType: "none", authActive: true } } + // Unknown/Unsupported Scheme + return { authType: "none", authActive: true } } else if (scheme.type === "apiKey") { if (scheme.in === "header") { return { @@ -301,17 +296,16 @@ const resolveOpenAPIV3SecurityObj = ( scope: _schemeData.join(" "), token: "", } - } else { - return { - authType: "oauth-2", - authActive: true, - accessTokenURL: "", - authURL: "", - clientID: "", - oidcDiscoveryURL: "", - scope: _schemeData.join(" "), - token: "", - } + } + return { + authType: "oauth-2", + authActive: true, + accessTokenURL: "", + authURL: "", + clientID: "", + oidcDiscoveryURL: "", + scope: _schemeData.join(" "), + token: "", } } else if (scheme.type === "openIdConnect") { return { @@ -339,7 +333,7 @@ const resolveOpenAPIV3SecurityScheme = ( | undefined if (!scheme) return { authType: "none", authActive: true } - else return resolveOpenAPIV3SecurityObj(scheme, schemeData) + return resolveOpenAPIV3SecurityObj(scheme, schemeData) } const resolveOpenAPIV3Security = ( @@ -439,17 +433,16 @@ const resolveOpenAPIV2SecurityScheme = ( scope: _schemeData.join(" "), token: "", } - } else { - return { - authType: "oauth-2", - authActive: true, - accessTokenURL: "", - authURL: "", - clientID: "", - oidcDiscoveryURL: "", - scope: _schemeData.join(" "), - token: "", - } + } + return { + authType: "oauth-2", + authActive: true, + accessTokenURL: "", + authURL: "", + clientID: "", + oidcDiscoveryURL: "", + scope: _schemeData.join(" "), + token: "", } } @@ -614,44 +607,29 @@ const parseOpenAPIDocContent = (str: string) => ) ) -export default defineImporter({ - id: "openapi", - name: "import.from_openapi", - applicableTo: ["my-collections", "team-collections", "url-import"], - icon: IconOpenAPI, - steps: [ - step({ - stepName: "FILE_IMPORT", - metadata: { - caption: "import.from_openapi_description", - acceptedFileTypes: ".json, .yaml, .yml", - }, - }), - ] as const, - importer: ([fileContent]) => - pipe( - // See if we can parse JSON properly - fileContent, - parseOpenAPIDocContent, - TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT), - // Try validating, else the importer is invalid file format - TE.chainW((obj) => - pipe( - TE.tryCatch( - () => SwaggerParser.validate(obj), - () => IMPORTER_INVALID_FILE_FORMAT - ) +export const hoppOpenAPIImporter = (fileContent: string) => + pipe( + // See if we can parse JSON properly + fileContent, + parseOpenAPIDocContent, + TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT), + // Try validating, else the importer is invalid file format + TE.chainW((obj) => + pipe( + TE.tryCatch( + () => SwaggerParser.validate(obj), + () => IMPORTER_INVALID_FILE_FORMAT ) - ), - // Deference the references - TE.chainW((obj) => - pipe( - TE.tryCatch( - () => SwaggerParser.dereference(obj), - () => OPENAPI_DEREF_ERROR - ) - ) - ), - TE.chainW(convertOpenApiDocToHopp) + ) ), -}) + // Deference the references + TE.chainW((obj) => + pipe( + TE.tryCatch( + () => SwaggerParser.dereference(obj), + () => OPENAPI_DEREF_ERROR + ) + ) + ), + TE.chainW(convertOpenApiDocToHopp) + ) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts index a1c4ab538..416dbcf98 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts @@ -1,4 +1,3 @@ -import IconPostman from "~icons/hopp/postman" import { Collection as PMCollection, Item, @@ -25,8 +24,7 @@ import * as S from "fp-ts/string" import * as A from "fp-ts/Array" import * as O from "fp-ts/Option" import * as TE from "fp-ts/TaskEither" -import { step } from "../steps" -import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "." +import { IMPORTER_INVALID_FILE_FORMAT } from "." import { PMRawLanguage } from "~/types/pm-coll-exts" import { stringArrayJoin } from "~/helpers/functional/array" @@ -298,28 +296,13 @@ const getHoppFolder = (ig: ItemGroup): HoppCollection => export const getHoppCollection = (coll: PMCollection) => getHoppFolder(coll) -export default defineImporter({ - id: "postman", - name: "import.from_postman", - applicableTo: ["my-collections", "team-collections", "url-import"], - icon: IconPostman, - steps: [ - step({ - stepName: "FILE_IMPORT", - metadata: { - caption: "import.from_postman_description", - acceptedFileTypes: ".json", - }, - }), - ] as const, - importer: ([fileContent]) => - pipe( - // Try reading - fileContent, - readPMCollection, +export const hoppPostmanImporter = (fileContent: string) => + pipe( + // Try reading + fileContent, + readPMCollection, - O.map(flow(getHoppCollection, A.of)), + O.map(flow(getHoppCollection, A.of)), - TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT) - ), -}) + TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT) + ) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts new file mode 100644 index 000000000..2978a501e --- /dev/null +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts @@ -0,0 +1,46 @@ +import * as TE from "fp-ts/TaskEither" +import * as O from "fp-ts/Option" + +import { IMPORTER_INVALID_FILE_FORMAT } from "." +import { safeParseJSON } from "~/helpers/functional/json" + +import { z } from "zod" +import { Environment } from "@hoppscotch/data" + +const postmanEnvSchema = z.object({ + name: z.string(), + values: z.array( + z.object({ + key: z.string(), + value: z.string(), + }) + ), +}) + +export const postmanEnvImporter = (content: string) => { + const parsedContent = safeParseJSON(content) + + // parse json from the environments string + if (O.isNone(parsedContent)) { + return TE.left(IMPORTER_INVALID_FILE_FORMAT) + } + + const validationResult = postmanEnvSchema.safeParse(parsedContent.value) + + if (!validationResult.success) { + return TE.left(IMPORTER_INVALID_FILE_FORMAT) + } + + const postmanEnv = validationResult.data + + const environment: Environment = { + name: postmanEnv.name, + variables: [], + } + + postmanEnv.values.forEach(({ key, value }) => + environment.variables.push({ key, value }) + ) + + return TE.right(environment) +} diff --git a/packages/hoppscotch-common/src/helpers/import-export/steps.ts b/packages/hoppscotch-common/src/helpers/import-export/steps.ts deleted file mode 100644 index 64c967dde..000000000 --- a/packages/hoppscotch-common/src/helpers/import-export/steps.ts +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Defines which type of content a Step returns. - * Add an entry here when you define a step - */ -export type StepDefinition = { - FILE_IMPORT: { - returnType: string - metadata: { - caption: string - acceptedFileTypes: string - } - } // String content of the file - TARGET_MY_COLLECTION: { - returnType: number - metadata: { - caption: string - } - } // folderPath - URL_IMPORT: { - returnType: string - metadata: { - caption: string - placeholder: string - } - } // String content of the url -} - -export type StepReturnValue = StepDefinition[keyof StepDefinition]["returnType"] - -/** - * Defines what the data structure of a step - */ -export type Step = - StepDefinition[T]["metadata"] extends never - ? { - name: T - caption?: string - metadata: undefined - } - : { - name: T - caption?: string - metadata: StepDefinition[T]["metadata"] - } - -/** - * The return output value of an individual step - */ -export type StepReturnType = T extends Step - ? StepDefinition[U]["returnType"] - : never - -export type StepMetadata = T extends Step - ? StepDefinition[U]["metadata"] - : never - -/** - * Defines the value of the output list generated by a step - */ -export type StepsOutputList = { - [K in keyof T]: StepReturnType -} - -type StepFuncInput = - StepDefinition[T]["metadata"] extends never - ? { - stepName: T - caption?: string - } - : { - stepName: T - caption?: string - metadata: StepDefinition[T]["metadata"] - } - -/** Use this function to define a step */ -export const step = (input: StepFuncInput) => - >{ - name: input.stepName, - metadata: (input as any).metadata ?? undefined, - caption: input.caption, - } diff --git a/packages/hoppscotch-common/src/helpers/new-codegen/har.ts b/packages/hoppscotch-common/src/helpers/new-codegen/har.ts index 787286284..c98a49e7e 100644 --- a/packages/hoppscotch-common/src/helpers/new-codegen/har.ts +++ b/packages/hoppscotch-common/src/helpers/new-codegen/har.ts @@ -62,27 +62,25 @@ const buildHarPostParams = ( ), RA.toArray ) - } else { - // FormData has its own format - return req.body.body.flatMap((entry) => { - if (entry.isFile) { - // We support multiple files - return entry.value.map( - (file) => - { - name: entry.key, - fileName: entry.key, // TODO: Blob doesn't contain file info, anyway to bring file name here ? - contentType: file.type, - } - ) - } else { - return { - name: entry.key, - value: entry.value, - } - } - }) } + // FormData has its own format + return req.body.body.flatMap((entry) => { + if (entry.isFile) { + // We support multiple files + return entry.value.map( + (file) => + { + name: entry.key, + fileName: entry.key, // TODO: Blob doesn't contain file info, anyway to bring file name here ? + contentType: file.type, + } + ) + } + return { + name: entry.key, + value: entry.value, + } + }) } const buildHarPostData = (req: HoppRESTRequest): Har.PostData | undefined => { diff --git a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts index a1bbba3fc..8f6e7f0bd 100644 --- a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts +++ b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts @@ -319,7 +319,7 @@ export default class NewTeamCollectionAdapter { if (!parentCollection) return - if (parentCollection.children != null) { + if (parentCollection.children !== null) { parentCollection.children.push(collection) } else { parentCollection.children = [collection] @@ -997,7 +997,7 @@ export default class NewTeamCollectionAdapter { if (!collection) return - if (collection.children != null) return + if (collection.children !== null) return this.loadingCollections$.next([ ...this.loadingCollections$.getValue(), diff --git a/packages/hoppscotch-common/src/modules/theming.ts b/packages/hoppscotch-common/src/modules/theming.ts index 2ae48eab5..64d8fa421 100644 --- a/packages/hoppscotch-common/src/modules/theming.ts +++ b/packages/hoppscotch-common/src/modules/theming.ts @@ -31,7 +31,8 @@ const applyColorMode = (app: App) => { const selection = computed>(() => { if (currentLocalPreference.value === "system") { return systemPrefersDark.value ? "dark" : "light" - } else return currentLocalPreference.value + } + return currentLocalPreference.value }) watch( diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.ts index 2f1c5838f..0a25ee5ad 100644 --- a/packages/hoppscotch-common/src/newstore/collections.ts +++ b/packages/hoppscotch-common/src/newstore/collections.ts @@ -1342,7 +1342,7 @@ function removeDuplicateCollectionsFromPath< : undefined if (collectionPath && parentCollection) { - if (type == "collection") { + if (type === "collection") { parentCollection.folders = removeDuplicatesFromAnArrayById( idToRemove, parentCollection.folders @@ -1367,7 +1367,7 @@ function removeDuplicateCollectionsFromPath< (entry) => entry.id === idToRemove ) - if (duplicateEntries.length == 2) { + if (duplicateEntries.length === 2) { const duplicateEntryIndex = arrayWithID.findIndex( (entry) => entry.id === idToRemove ) diff --git a/packages/hoppscotch-common/src/newstore/environments.ts b/packages/hoppscotch-common/src/newstore/environments.ts index 691c88665..71b1bbb65 100644 --- a/packages/hoppscotch-common/src/newstore/environments.ts +++ b/packages/hoppscotch-common/src/newstore/environments.ts @@ -47,18 +47,16 @@ const dispatchers = defineDispatchers({ return { selectedEnvironmentIndex, } - } else { - return { - selectedEnvironmentIndex: { - type: "NO_ENV_SELECTED", - }, - } } - } else { return { - selectedEnvironmentIndex, + selectedEnvironmentIndex: { + type: "NO_ENV_SELECTED", + }, } } + return { + selectedEnvironmentIndex, + } }, appendEnvironments( { environments }: EnvironmentStore, @@ -309,7 +307,7 @@ const dispatchers = defineDispatchers({ const newEnvironments = [...environments] - if (entries.length == 2) { + if (entries.length === 2) { const indexToRemove = environments.findIndex((e) => e.id === id) newEnvironments.splice(indexToRemove, 1) } @@ -350,9 +348,8 @@ export const currentEnvironment$: Observable = return env } else if (selectedEnvironmentIndex.type === "MY_ENV") { return environments[selectedEnvironmentIndex.index] - } else { - return selectedEnvironmentIndex.environment } + return selectedEnvironmentIndex.environment }) ) @@ -422,9 +419,8 @@ export function getCurrentEnvironment(): Environment { return environmentsStore.value.environments[ environmentsStore.value.selectedEnvironmentIndex.index ] - } else { - return environmentsStore.value.selectedEnvironmentIndex.environment } + return environmentsStore.value.selectedEnvironmentIndex.environment } export function getSelectedEnvironmentIndex() { @@ -469,7 +465,7 @@ export function getLocalIndexByEnvironmentID(id: string) { (env) => env.id === id ) - return envIndex != -1 ? envIndex : null + return envIndex !== -1 ? envIndex : null } export function addGlobalEnvVariable(entry: Environment["variables"][number]) { @@ -678,10 +674,9 @@ export function getEnvironment(selectedEnv: SelectedEnv) { environmentsStore.value.selectedEnvironmentIndex.type === "TEAM_ENV" ) { return environmentsStore.value.selectedEnvironmentIndex.environment - } else { - return { - name: "N0_ENV", - variables: [], - } + } + return { + name: "N0_ENV", + variables: [], } } diff --git a/packages/hoppscotch-common/src/newstore/history.ts b/packages/hoppscotch-common/src/newstore/history.ts index 1f5518221..880c12382 100644 --- a/packages/hoppscotch-common/src/newstore/history.ts +++ b/packages/hoppscotch-common/src/newstore/history.ts @@ -167,7 +167,7 @@ const RESTHistoryDispatchers = defineDispatchers({ removeDuplicateEntry(currentVal: RESTHistoryType, { id }: { id: string }) { const entries = currentVal.state.filter((e) => e.id === id) - if (entries.length == 2) { + if (entries.length === 2) { const indexToRemove = currentVal.state.findIndex((e) => e.id === id) currentVal.state.splice(indexToRemove, 1) @@ -230,7 +230,7 @@ const GQLHistoryDispatchers = defineDispatchers({ removeDuplicateEntry(currentVal: GraphqlHistoryType, { id }: { id: string }) { const entries = currentVal.state.filter((e) => e.id === id) - if (entries.length == 2) { + if (entries.length === 2) { const indexToRemove = currentVal.state.findIndex((e) => e.id === id) currentVal.state.splice(indexToRemove, 1) diff --git a/packages/hoppscotch-common/src/pages/import.vue b/packages/hoppscotch-common/src/pages/import.vue index fb8f9b212..0f750644c 100644 --- a/packages/hoppscotch-common/src/pages/import.vue +++ b/packages/hoppscotch-common/src/pages/import.vue @@ -16,12 +16,18 @@ import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data" import { appendRESTCollections } from "~/newstore/collections" import { useI18n } from "@composables/i18n" import { useToast } from "@composables/toast" -import { URLImporters } from "~/helpers/import-export/import/importers" import { IMPORTER_INVALID_FILE_FORMAT } from "~/helpers/import-export/import" import { OPENAPI_DEREF_ERROR } from "~/helpers/import-export/import/openapi" import { isOfType } from "~/helpers/functional/primtive" import { TELeftType } from "~/helpers/functional/taskEither" +import { + hoppRESTImporter, + hoppPostmanImporter, + hoppInsomniaImporter, + hoppOpenAPIImporter, +} from "~/helpers/import-export/import/importers" + const route = useRoute() const router = useRouter() const toast = useToast() @@ -30,16 +36,33 @@ const t = useI18n() const IMPORTER_INVALID_TYPE = "importer_invalid_type" as const const IMPORTER_INVALID_FETCH = "importer_invalid_fetch" as const +// TODO: move this to importers after moving the importer metadatas from respective components to imports/*.ts file +const URLImporters = [ + { + id: "hoppscotch", + importer: hoppRESTImporter, + }, + { + id: "postman", + importer: hoppPostmanImporter, + }, + { + id: "insomnia", + importer: hoppInsomniaImporter, + }, + { + id: "openapi", + importer: hoppOpenAPIImporter, + }, +] + const importCollections = (url: unknown, type: unknown) => pipe( TE.Do, TE.bind("importer", () => pipe( URLImporters, - RA.findFirst( - (importer) => - importer.applicableTo.includes("url-import") && importer.id === type - ), + RA.findFirst((importer) => importer.id === type), TE.fromOption(() => IMPORTER_INVALID_TYPE) ) ), @@ -56,7 +79,7 @@ const importCollections = (url: unknown, type: unknown) => content.data, TO.fromPredicate(isOfType("string")), TE.fromTaskOption(() => IMPORTER_INVALID_FILE_FORMAT), - TE.chain((data) => importer.importer([data])) + TE.chain((data) => importer.importer(data)) ) ) ) diff --git a/packages/hoppscotch-common/src/pages/join-team.vue b/packages/hoppscotch-common/src/pages/join-team.vue index 42125c4f8..e4abd2e3b 100644 --- a/packages/hoppscotch-common/src/pages/join-team.vue +++ b/packages/hoppscotch-common/src/pages/join-team.vue @@ -210,7 +210,7 @@ export default defineComponent({ const loadingCurrentUser = computed(() => { if (!probableUser.value) return false else if (!currentUser.value) return true - else return false + return false }) return { @@ -264,21 +264,20 @@ export default defineComponent({ getErrorMessage(error: GQLError) { if (error.type === "network_error") { return this.t("error.network_error") - } else { - switch (error.error) { - case "team_invite/not_valid_viewer": - return this.t("team.not_valid_viewer") - case "team_invite/not_found": - return this.t("team.not_found") - case "team_invite/no_invite_found": - return this.t("team.no_invite_found") - case "team_invite/already_member": - return this.t("team.already_member") - case "team_invite/email_do_not_match": - return this.t("team.email_do_not_match") - default: - return this.t("error.something_went_wrong") - } + } + switch (error.error) { + case "team_invite/not_valid_viewer": + return this.t("team.not_valid_viewer") + case "team_invite/not_found": + return this.t("team.not_found") + case "team_invite/no_invite_found": + return this.t("team.no_invite_found") + case "team_invite/already_member": + return this.t("team.already_member") + case "team_invite/email_do_not_match": + return this.t("team.email_do_not_match") + default: + return this.t("error.something_went_wrong") } }, }, diff --git a/packages/hoppscotch-common/src/pages/profile.vue b/packages/hoppscotch-common/src/pages/profile.vue index 431ed8d33..5a0589e97 100644 --- a/packages/hoppscotch-common/src/pages/profile.vue +++ b/packages/hoppscotch-common/src/pages/profile.vue @@ -235,7 +235,7 @@ const probableUser = useReadonlyStream( const loadingCurrentUser = computed(() => { if (!probableUser.value) return false else if (!currentUser.value) return true - else return false + return false }) const displayName = ref(currentUser.value?.displayName || "") diff --git a/packages/hoppscotch-common/src/platform/std/interceptors/browser.ts b/packages/hoppscotch-common/src/platform/std/interceptors/browser.ts index b4381e99a..4ddc479fd 100644 --- a/packages/hoppscotch-common/src/platform/std/interceptors/browser.ts +++ b/packages/hoppscotch-common/src/platform/std/interceptors/browser.ts @@ -76,15 +76,14 @@ async function runRequest( }) } else if (axios.isCancel(e)) { return E.left("cancellation") - } else { - return E.left({ - humanMessage: { - heading: (t) => t("error.network_fail"), - description: (t) => t("helpers.network_fail"), - }, - error: e, - }) } + return E.left({ + humanMessage: { + heading: (t) => t("error.network_fail"), + description: (t) => t("helpers.network_fail"), + }, + error: e, + }) } } diff --git a/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts b/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts index ba87da41c..033e23865 100644 --- a/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts +++ b/packages/hoppscotch-common/src/platform/std/interceptors/extension.ts @@ -103,9 +103,8 @@ export class ExtensionInterceptorService public extensionVersion = computed(() => { if (this.extensionStatus.value === "available") { return window.__POSTWOMAN_EXTENSION_HOOK__?.getVersion() - } else { - return null } + return null }) /** @@ -197,11 +196,10 @@ export class ExtensionInterceptorService if (this.extensionStatus.value === "available" && version) { const { major, minor } = version return `${t("settings.extensions")}: v${major}.${minor}` - } else { - return `${t("settings.extensions")}: ${t( - "settings.extension_ver_not_reported" - )}` } + return `${t("settings.extensions")}: ${t( + "settings.extension_ver_not_reported" + )}` }) } diff --git a/packages/hoppscotch-common/src/platform/std/interceptors/proxy.ts b/packages/hoppscotch-common/src/platform/std/interceptors/proxy.ts index cba95aaef..f3bd7bfda 100644 --- a/packages/hoppscotch-common/src/platform/std/interceptors/proxy.ts +++ b/packages/hoppscotch-common/src/platform/std/interceptors/proxy.ts @@ -80,15 +80,14 @@ async function runRequest( } catch (e) { if (axios.isCancel(e)) { return E.left("cancellation") - } else { - return E.left({ - humanMessage: { - heading: (t) => t("error.network_fail"), - description: (t) => t("helpers.network_fail"), - }, - error: e, - }) } + return E.left({ + humanMessage: { + heading: (t) => t("error.network_fail"), + description: (t) => t("helpers.network_fail"), + }, + error: e, + }) } } diff --git a/packages/hoppscotch-common/src/services/spotlight/searchers/collections.searcher.ts b/packages/hoppscotch-common/src/services/spotlight/searchers/collections.searcher.ts index 04f763737..10e8f1389 100644 --- a/packages/hoppscotch-common/src/services/spotlight/searchers/collections.searcher.ts +++ b/packages/hoppscotch-common/src/services/spotlight/searchers/collections.searcher.ts @@ -117,9 +117,8 @@ export class CollectionsSpotlightSearcherService return "graphql" } else if (url.pathname === "/") { return "rest" - } else { - return "other" } + return "other" } catch (e) { return "other" } diff --git a/packages/hoppscotch-common/src/services/spotlight/searchers/history.searcher.ts b/packages/hoppscotch-common/src/services/spotlight/searchers/history.searcher.ts index 75c96e8ef..492be5126 100644 --- a/packages/hoppscotch-common/src/services/spotlight/searchers/history.searcher.ts +++ b/packages/hoppscotch-common/src/services/spotlight/searchers/history.searcher.ts @@ -190,23 +190,22 @@ export class HistorySpotlightSearcherService }, }, } - } else { - // Assume gql - const entry = - graphqlHistoryStore.value.state[parseInt(x.id.split("-")[1])] + } + // Assume gql + const entry = + graphqlHistoryStore.value.state[parseInt(x.id.split("-")[1])] - return { - id: x.id, - icon: markRaw(IconHistory), - score: x.score, - text: { - type: "custom", - component: markRaw(SpotlightGQLHistoryEntry), - componentProps: { - historyEntry: entry, - }, + return { + id: x.id, + icon: markRaw(IconHistory), + score: x.score, + text: { + type: "custom", + component: markRaw(SpotlightGQLHistoryEntry), + componentProps: { + historyEntry: entry, }, - } + }, } }) },