Skip to content

Commit

Permalink
Merge branch 'release/2024.3.0' of github.com:hoppscotch/hoppscotch i…
Browse files Browse the repository at this point in the history
…nto feat/mod-enter-to-import-curl
  • Loading branch information
anwarulislam committed Mar 29, 2024
2 parents 3d46fde + 787aab6 commit b953352
Show file tree
Hide file tree
Showing 19 changed files with 770 additions and 166 deletions.
3 changes: 3 additions & 0 deletions packages/hoppscotch-common/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
parserOptions: {
sourceType: "module",
requireConfigFile: false,
ecmaFeatures: {
jsx: false,
},
},
extends: [
"@vue/typescript/recommended",
Expand Down
12 changes: 6 additions & 6 deletions packages/hoppscotch-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@
"@types/splitpanes": "2.2.6",
"@types/uuid": "9.0.7",
"@types/yargs-parser": "21.0.3",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"@typescript-eslint/eslint-plugin": "7.3.1",
"@typescript-eslint/parser": "7.3.1",
"@vitejs/plugin-vue": "4.5.1",
"@vue/compiler-sfc": "3.3.10",
"@vue/eslint-config-typescript": "12.0.0",
"@vue/runtime-core": "3.3.10",
"autoprefixer": "10.4.16",
"cross-env": "7.0.3",
"dotenv": "16.3.1",
"eslint": "8.55.0",
"eslint-plugin-prettier": "5.0.1",
"eslint-plugin-vue": "9.19.2",
"eslint": "8.57.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-vue": "9.24.0",
"glob": "10.3.10",
"npm-run-all": "4.1.5",
"openapi-types": "12.1.3",
Expand All @@ -164,4 +164,4 @@
"vitest": "0.34.6",
"vue-tsc": "1.8.24"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@
<script setup lang="ts">
import { useI18n } from "@composables/i18n"
import { HoppCollection, HoppRESTAuth, HoppRESTHeaders } from "@hoppscotch/data"
import { clone } from "lodash-es"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { PersistenceService } from "~/services/persistence"
import {
GQLHeader,
HoppCollection,
HoppGQLAuth,
HoppRESTAuth,
HoppRESTHeaders,
} from "@hoppscotch/data"
import { useVModel } from "@vueuse/core"
import { useService } from "dioc/vue"
import { clone } from "lodash-es"
import { ref, watch } from "vue"
import { useVModel } from "@vueuse/core"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { PersistenceService } from "~/services/persistence"
const persistenceService = useService(PersistenceService)
const t = useI18n()
Expand All @@ -84,6 +90,9 @@ export type EditingProperties = {
inheritedProperties?: HoppInheritedProperty
}
type HoppCollectionAuth = HoppRESTAuth | HoppGQLAuth
type HoppCollectionHeaders = HoppRESTHeaders | GQLHeader[]
const props = withDefaults(
defineProps<{
show: boolean
Expand All @@ -109,8 +118,8 @@ const emit = defineEmits<{
}>()
const editableCollection = ref<{
headers: HoppRESTHeaders
auth: HoppRESTAuth
headers: HoppCollectionHeaders
auth: HoppCollectionAuth
}>({
headers: [],
auth: {
Expand All @@ -122,15 +131,16 @@ const editableCollection = ref<{
watch(
editableCollection,
(updatedEditableCollection) => {
if (props.show) {
if (props.show && props.editingProperties) {
const unsavedCollectionProperties: EditingProperties = {
collection: updatedEditableCollection,
isRootCollection: props.editingProperties?.isRootCollection ?? false,
path: props.editingProperties?.path,
inheritedProperties: props.editingProperties?.inheritedProperties,
}
persistenceService.setLocalConfig(
"unsaved_collection_properties",
JSON.stringify(<EditingProperties>{
collection: updatedEditableCollection,
isRootCollection: props.editingProperties?.isRootCollection,
path: props.editingProperties?.path,
inheritedProperties: props.editingProperties?.inheritedProperties,
})
JSON.stringify(unsavedCollectionProperties)
)
}
},
Expand All @@ -146,10 +156,10 @@ watch(
(show) => {
if (show && props.editingProperties?.collection) {
editableCollection.value.auth = clone(
props.editingProperties.collection.auth as HoppRESTAuth
props.editingProperties.collection.auth as HoppCollectionAuth
)
editableCollection.value.headers = clone(
props.editingProperties.collection.headers as HoppRESTHeaders
props.editingProperties.collection.headers as HoppCollectionHeaders
)
} else {
editableCollection.value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ import { GQLTabService } from "~/services/tab/graphql"
import { computed } from "vue"
import {
HoppCollection,
HoppGQLAuth,
HoppGQLRequest,
makeGQLRequest,
} from "@hoppscotch/data"
Expand Down Expand Up @@ -226,7 +225,7 @@ const editingRequest = ref<HoppGQLRequest | null>(null)
const editingRequestIndex = ref<number | null>(null)
const editingProperties = ref<{
collection: HoppCollection | null
collection: Partial<HoppCollection> | null
isRootCollection: boolean
path: string
inheritedProperties?: HoppInheritedProperty
Expand Down Expand Up @@ -265,8 +264,9 @@ onMounted(() => {
)
if (unsavedCollectionPropertiesString) {
const unsavedCollectionProperties: EditingProperties<"GraphQL"> =
JSON.parse(unsavedCollectionPropertiesString)
const unsavedCollectionProperties: EditingProperties = JSON.parse(
unsavedCollectionPropertiesString
)
const auth = unsavedCollectionProperties.collection?.auth
Expand Down Expand Up @@ -610,7 +610,7 @@ const editProperties = ({
if (collectionIndex === null || collection === null) return
const parentIndex = collectionIndex.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
let inheritedProperties = {}
let inheritedProperties = undefined
if (parentIndex) {
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
Expand All @@ -621,7 +621,7 @@ const editProperties = ({
inheritedProperties = {
auth,
headers,
} as HoppInheritedProperty
}
}
editingProperties.value = {
Expand All @@ -635,11 +635,15 @@ const editProperties = ({
}
const setCollectionProperties = (newCollection: {
collection: HoppCollection
collection: Partial<HoppCollection> | null
path: string
isRootCollection: boolean
}) => {
const { collection, path, isRootCollection } = newCollection
if (!collection) {
return
}
if (isRootCollection) {
editGraphqlCollection(parseInt(path), collection)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ watch(
const selectedTeamID = collectionsType.value.selectedTeam?.id
selectedTeamID &&
debouncedSearch(newFilterText, selectedTeamID)?.catch((_) => {})
debouncedSearch(newFilterText, selectedTeamID)?.catch(() => {})
}
},
{
Expand Down Expand Up @@ -414,14 +414,11 @@ onMounted(() => {
)
if (unsavedCollectionPropertiesString) {
const unsavedCollectionProperties: EditingProperties<"REST"> = JSON.parse(
const unsavedCollectionProperties: EditingProperties = JSON.parse(
unsavedCollectionPropertiesString
)
// casting because the type `EditingProperties["collection"]["auth"] and the usage in Properties.vue is different. there it's casted as an any.
// FUTURE-TODO: look into this
// @ts-expect-error because of the above reason
const auth = unsavedCollectionProperties.collection?.auth as HoppRESTAuth
const auth = unsavedCollectionProperties.collection?.auth
if (auth?.authType === "oauth-2") {
const grantTypeInfo = auth.grantTypeInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const selectOAuth2AuthType = () => {
? existingGrantTypeInfo
: defaultGrantTypeInfo
auth.value = <HoppGQLAuth>{
auth.value = {
...auth.value,
authType: "oauth-2",
addTo: "HEADERS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ const selectOAuth2AuthType = () => {
? existingGrantTypeInfo
: defaultGrantTypeInfo
auth.value = <HoppRESTAuth>{
auth.value = {
...auth.value,
authType: "oauth-2",
addTo: "HEADERS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,14 +913,16 @@ const generateOAuthToken = async () => {
if (
grantTypesInvolvingRedirect.includes(auth.value.grantTypeInfo.grantType)
) {
const authConfig: PersistedOAuthConfig = {
source: props.source,
context: props.isCollectionProperty
? { type: "collection-properties", metadata: {} }
: { type: "request-tab", metadata: {} },
grant_type: auth.value.grantTypeInfo.grantType,
}
persistenceService.setLocalConfig(
"oauth_temp_config",
JSON.stringify(<PersistedOAuthConfig>{
source: props.source,
context: props.isCollectionProperty
? { type: "collection-properties", metadata: {} }
: { type: "request-tab" },
})
JSON.stringify(authConfig)
)
}
Expand Down
59 changes: 47 additions & 12 deletions packages/hoppscotch-common/src/helpers/import-export/import/hopp.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { pipe, flow } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import {
HoppCollection,
HoppRESTRequest,
getDefaultGQLRequest,
getDefaultRESTRequest,
translateToNewRESTCollection,
} from "@hoppscotch/data"
import * as A from "fp-ts/Array"
import * as O from "fp-ts/Option"
import * as RA from "fp-ts/ReadonlyArray"
import * as A from "fp-ts/Array"
import { translateToNewRESTCollection, HoppCollection } from "@hoppscotch/data"
import * as TE from "fp-ts/TaskEither"
import { flow, pipe } from "fp-ts/function"

import { IMPORTER_INVALID_FILE_FORMAT } from "."
import { HoppGQLRequest, translateToNewGQLCollection } from "@hoppscotch/data"
import { safeParseJSON } from "~/helpers/functional/json"
import { translateToNewGQLCollection } from "@hoppscotch/data"
import { entityReference } from "verzod"
import { z } from "zod"
import { IMPORTER_INVALID_FILE_FORMAT } from "."

export const hoppRESTImporter = (content: string[]) =>
pipe(
Expand All @@ -32,8 +36,24 @@ export const hoppRESTImporter = (content: string[]) =>
* else translate it into one.
*/
const validateCollection = (collection: unknown) => {
const result = entityReference(HoppCollection).safeParse(collection)
if (result.success) return O.some(result.data)
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(request)

return requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultRESTRequest()
}
)

return O.some({
...collectionSchemaParsedResult.value,
requests,
})
}

return O.some(translateToNewRESTCollection(collection))
}
Expand Down Expand Up @@ -64,9 +84,24 @@ export const hoppGQLImporter = (content: string) =>
* @returns the collection if it is valid, else a translated version of the collection
*/
export const validateGQLCollection = (collection: unknown) => {
const result = z.array(entityReference(HoppCollection)).safeParse(collection)
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
const requestSchemaParsedResult = HoppGQLRequest.safeParse(request)

return requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultGQLRequest()
}
)

if (result.success) return O.some(result.data)
return O.some({
...collectionSchemaParsedResult.value,
requests,
})
}

return O.some(translateToNewGQLCollection(collection))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { ref } from "vue"
import {
HoppRESTAuth,
HoppRESTHeader,
HoppRESTRequest,
getDefaultRESTRequest,
} from "@hoppscotch/data"
import axios from "axios"
import { Service } from "dioc"
import * as E from "fp-ts/Either"
import { Ref, ref } from "vue"

import { runGQLQuery } from "../backend/GQLClient"
import {
GetCollectionChildrenDocument,
Expand All @@ -7,15 +17,10 @@ import {
GetSingleRequestDocument,
} from "../backend/graphql"
import { TeamCollection } from "./TeamCollection"
import { HoppRESTAuth, HoppRESTHeader } from "@hoppscotch/data"

import * as E from "fp-ts/Either"
import { platform } from "~/platform"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
import { TeamRequest } from "./TeamRequest"
import { Service } from "dioc"
import axios from "axios"
import { Ref } from "vue"
import { platform } from "~/platform"

type CollectionSearchMeta = {
isSearchResult?: boolean
Expand Down Expand Up @@ -150,12 +155,21 @@ function convertToTeamTree(
if (isAlreadyInserted) return

if (parentCollection) {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(
request.request
)

const effectiveRequest =
requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultRESTRequest()

parentCollection.requests = parentCollection.requests || []
parentCollection.requests.push({
id: request.id,
collectionID: request.collectionID,
title: request.title,
request: request.request,
request: effectiveRequest,
})
}
})
Expand Down

0 comments on commit b953352

Please sign in to comment.