refactor: updates based on the provider methods signature changes
This commit is contained in:
@@ -292,20 +292,19 @@ const saveRequestAs = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultHandle = await workspaceService.updateRESTRequest(
|
const updateRequestResult = await workspaceService.updateRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
updatedRequest
|
updatedRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(resultHandle)) {
|
if (E.isLeft(updateRequestResult)) {
|
||||||
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = resultHandle.right
|
if (updateRequestResult.right.type === "invalid") {
|
||||||
|
// REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND
|
||||||
|
|
||||||
if (result.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -544,9 +544,18 @@ const saveRequest = async () => {
|
|||||||
if (E.isLeft(updateRequestResult)) {
|
if (E.isLeft(updateRequestResult)) {
|
||||||
// INVALID_REQUEST_HANDLE
|
// INVALID_REQUEST_HANDLE
|
||||||
showSaveRequestModal.value = true
|
showSaveRequestModal.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!tab.value.document.isDirty) {
|
const resultHandle = updateRequestResult.right
|
||||||
tab.value.document.isDirty = true
|
|
||||||
|
if (resultHandle.type === "invalid") {
|
||||||
|
// REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND
|
||||||
|
|
||||||
|
if (resultHandle.reason === "REQUEST_PATH_NOT_FOUND") {
|
||||||
|
// REQUEST_PATH_NOT_FOUND
|
||||||
|
tab.value.document.saveContext = undefined
|
||||||
|
await saveRequest()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,9 +139,7 @@ import IconImport from "~icons/lucide/folder-down"
|
|||||||
import IconHelpCircle from "~icons/lucide/help-circle"
|
import IconHelpCircle from "~icons/lucide/help-circle"
|
||||||
import IconPlus from "~icons/lucide/plus"
|
import IconPlus from "~icons/lucide/plus"
|
||||||
import {
|
import {
|
||||||
cascadeParentCollectionForHeaderAuth,
|
|
||||||
navigateToFolderWithIndexPath,
|
navigateToFolderWithIndexPath,
|
||||||
restCollectionStore,
|
|
||||||
restCollections$,
|
restCollections$,
|
||||||
saveRESTRequestAs,
|
saveRESTRequestAs,
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
@@ -256,12 +254,9 @@ const displayConfirmModal = (show: boolean) => {
|
|||||||
const addNewRootCollection = async (name: string) => {
|
const addNewRootCollection = async (name: string) => {
|
||||||
modalLoadingState.value = true
|
modalLoadingState.value = true
|
||||||
|
|
||||||
const newCollectionID = restCollectionState.value.length.toString()
|
|
||||||
|
|
||||||
const result = await workspaceService.createRESTRootCollection(
|
const result = await workspaceService.createRESTRootCollection(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
name,
|
{ name }
|
||||||
newCollectionID
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -306,19 +301,13 @@ const onRemoveRootCollection = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result =
|
const result = await workspaceService.removeRESTCollection(collectionHandle)
|
||||||
await workspaceService.removeRESTRootCollection(collectionHandle)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
|
||||||
// COLLECTION_INVALIDATED
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
toast.success(t("state.deleted"))
|
toast.success(t("state.deleted"))
|
||||||
displayConfirmModal(false)
|
displayConfirmModal(false)
|
||||||
}
|
}
|
||||||
@@ -370,10 +359,24 @@ const onAddRequest = async (requestName: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const cascadingAuthHeadersHandleResult =
|
||||||
requestHandle.value.data.collectionID,
|
await workspaceService.getRESTCollectionLevelAuthHeadersView(
|
||||||
"rest"
|
collectionHandle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
|
||||||
|
// INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
|
||||||
|
|
||||||
|
if (cascadingAuthHeadersHandle.value.type === "invalid") {
|
||||||
|
// COLLECTION_INVALIDATED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { auth, headers } = cascadingAuthHeadersHandle.value.data
|
||||||
|
|
||||||
tabs.createNewTab({
|
tabs.createNewTab({
|
||||||
request: newRequest,
|
request: newRequest,
|
||||||
@@ -396,7 +399,7 @@ const addChildCollection = (parentCollectionIndexPath: string) => {
|
|||||||
displayModalAddChildColl(true)
|
displayModalAddChildColl(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onAddChildCollection = async (childCollectionName: string) => {
|
const onAddChildCollection = async (newChildCollectionName: string) => {
|
||||||
const parentCollectionIndexPath = editingCollectionIndexPath.value
|
const parentCollectionIndexPath = editingCollectionIndexPath.value
|
||||||
|
|
||||||
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
@@ -418,7 +421,7 @@ const onAddChildCollection = async (childCollectionName: string) => {
|
|||||||
|
|
||||||
const result = await workspaceService.createRESTChildCollection(
|
const result = await workspaceService.createRESTChildCollection(
|
||||||
collectionHandle,
|
collectionHandle,
|
||||||
childCollectionName
|
{ name: newChildCollectionName }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -466,29 +469,15 @@ const onEditRootCollection = async (newCollectionName: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
const result = await workspaceService.updateRESTCollection(collectionHandle, {
|
||||||
const updatedCollection = navigateToFolderWithIndexPath(
|
name: newCollectionName,
|
||||||
restCollectionStore.value.state,
|
})
|
||||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
|
||||||
) as HoppCollection
|
|
||||||
|
|
||||||
updatedCollection.name = newCollectionName
|
|
||||||
|
|
||||||
const result = await workspaceService.editRESTCollection(
|
|
||||||
collectionHandle,
|
|
||||||
updatedCollection
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
|
||||||
// COLLECTION_INVALIDATED
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
displayModalEditCollection(false)
|
displayModalEditCollection(false)
|
||||||
toast.success(t("collection.renamed"))
|
toast.success(t("collection.renamed"))
|
||||||
}
|
}
|
||||||
@@ -505,7 +494,7 @@ const editChildCollection = (payload: {
|
|||||||
displayModalEditChildCollection(true)
|
displayModalEditChildCollection(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEditChildCollection = async (newCollectionName: string) => {
|
const onEditChildCollection = async (newChildCollectionName: string) => {
|
||||||
const collectionIndexPath = editingChildCollectionIndexPath.value
|
const collectionIndexPath = editingChildCollectionIndexPath.value
|
||||||
|
|
||||||
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
@@ -525,29 +514,15 @@ const onEditChildCollection = async (newCollectionName: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
const result = await workspaceService.updateRESTCollection(collectionHandle, {
|
||||||
const updatedCollection = navigateToFolderWithIndexPath(
|
name: newChildCollectionName,
|
||||||
restCollectionStore.value.state,
|
})
|
||||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
|
||||||
) as HoppCollection
|
|
||||||
|
|
||||||
updatedCollection.name = newCollectionName
|
|
||||||
|
|
||||||
const result = await workspaceService.editRESTCollection(
|
|
||||||
collectionHandle,
|
|
||||||
updatedCollection
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
|
||||||
// COLLECTION_INVALIDATED
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
displayModalEditChildCollection(false)
|
displayModalEditChildCollection(false)
|
||||||
toast.success(t("collection.renamed"))
|
toast.success(t("collection.renamed"))
|
||||||
}
|
}
|
||||||
@@ -580,7 +555,7 @@ const onRemoveChildCollection = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.removeRESTChildCollection(
|
const result = await workspaceService.removeRESTCollection(
|
||||||
parentCollectionHandle
|
parentCollectionHandle
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -589,11 +564,6 @@ const onRemoveChildCollection = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
|
||||||
// COLLECTION_INVALIDATED
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
toast.success(t("state.deleted"))
|
toast.success(t("state.deleted"))
|
||||||
displayConfirmModal(false)
|
displayConfirmModal(false)
|
||||||
}
|
}
|
||||||
@@ -635,11 +605,6 @@ const onRemoveRequest = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const possibleTab = tabs.getTabRefWithSaveContext({
|
const possibleTab = tabs.getTabRefWithSaveContext({
|
||||||
originLocation: "workspace-user-collection",
|
originLocation: "workspace-user-collection",
|
||||||
requestHandle,
|
requestHandle,
|
||||||
@@ -669,6 +634,23 @@ const onRemoveRequest = async () => {
|
|||||||
const selectRequest = async (requestIndexPath: string) => {
|
const selectRequest = async (requestIndexPath: string) => {
|
||||||
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collectionIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
|
props.workspaceHandle,
|
||||||
|
collectionIndexPath
|
||||||
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(collectionHandleResult)) {
|
||||||
|
// INVALID_WORKSPACE_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const collectionHandle = collectionHandleResult.right
|
||||||
|
|
||||||
|
if (collectionHandle.value.type === "invalid") {
|
||||||
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
requestIndexPath
|
requestIndexPath
|
||||||
@@ -686,15 +668,30 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = requestHandle.value.data.request as HoppRESTRequest
|
const request = requestHandle.value.data.request
|
||||||
|
|
||||||
// If there is a request with this save context, switch into it
|
// If there is a request with this save context, switch into it
|
||||||
let possibleTab = null
|
let possibleTab = null
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const cascadingAuthHeadersHandleResult =
|
||||||
collectionIndexPath,
|
await workspaceService.getRESTCollectionLevelAuthHeadersView(
|
||||||
"rest"
|
collectionHandle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
|
||||||
|
// INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
|
||||||
|
|
||||||
|
if (cascadingAuthHeadersHandle.value.type === "invalid") {
|
||||||
|
// COLLECTION_INVALIDATED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { auth, headers } = cascadingAuthHeadersHandle.value.data
|
||||||
|
|
||||||
possibleTab = tabs.getTabRefWithSaveContext({
|
possibleTab = tabs.getTabRefWithSaveContext({
|
||||||
originLocation: "workspace-user-collection",
|
originLocation: "workspace-user-collection",
|
||||||
requestHandle,
|
requestHandle,
|
||||||
@@ -766,7 +763,7 @@ const editRequest = (payload: {
|
|||||||
displayModalEditRequest(true)
|
displayModalEditRequest(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEditRequest = async (newReqName: string) => {
|
const onEditRequest = async (newRequestName: string) => {
|
||||||
const requestID = editingRequestIndexPath.value
|
const requestID = editingRequestIndexPath.value
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
@@ -786,22 +783,16 @@ const onEditRequest = async (newReqName: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedRequest = {
|
const result = await workspaceService.updateRESTRequest(requestHandle, {
|
||||||
...requestHandle.value.data.request,
|
name: newRequestName,
|
||||||
name: newReqName,
|
})
|
||||||
} as HoppRESTRequest
|
|
||||||
|
|
||||||
const result = await workspaceService.updateRESTRequest(
|
|
||||||
requestHandle,
|
|
||||||
updatedRequest
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_REQUEST_HANDLE
|
// INVALID_REQUEST_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
if (result.right.type === "invalid") {
|
||||||
// REQUEST_INVALIDATED
|
// REQUEST_INVALIDATED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -830,18 +821,6 @@ const editCollectionProperties = async (collectionIndexPath: string) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
} as HoppInheritedProperty
|
} as HoppInheritedProperty
|
||||||
// Have a provider level implementation that returns a view that says what the headesd and auth are
|
|
||||||
if (parentIndex) {
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
|
||||||
parentIndex,
|
|
||||||
"rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
inheritedProperties = {
|
|
||||||
auth,
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
const collectionHandleResult = await workspaceService.getCollectionHandle(
|
||||||
props.workspaceHandle,
|
props.workspaceHandle,
|
||||||
@@ -860,6 +839,32 @@ const editCollectionProperties = async (collectionIndexPath: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parentIndex) {
|
||||||
|
const cascadingAuthHeadersHandleResult =
|
||||||
|
await workspaceService.getRESTCollectionLevelAuthHeadersView(
|
||||||
|
collectionHandle
|
||||||
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
|
||||||
|
// INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
|
||||||
|
|
||||||
|
if (cascadingAuthHeadersHandle.value.type === "invalid") {
|
||||||
|
// COLLECTION_INVALIDATED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { auth, headers } = cascadingAuthHeadersHandle.value.data
|
||||||
|
|
||||||
|
inheritedProperties = {
|
||||||
|
auth,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const collection = navigateToFolderWithIndexPath(
|
const collection = navigateToFolderWithIndexPath(
|
||||||
restCollectionState.value,
|
restCollectionState.value,
|
||||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||||
@@ -899,35 +904,35 @@ const setCollectionProperties = async (updatedCollectionProps: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're sure that the collection exists in the given `collectionIndexPath` as there's a validation happening in `getCollectionHandle` above
|
const result = await workspaceService.updateRESTCollection(collectionHandle, {
|
||||||
const collection = navigateToFolderWithIndexPath(
|
|
||||||
restCollectionStore.value.state,
|
|
||||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
|
||||||
) as HoppCollection
|
|
||||||
|
|
||||||
const updatedCollection = {
|
|
||||||
...collection,
|
|
||||||
auth,
|
auth,
|
||||||
headers,
|
headers,
|
||||||
}
|
})
|
||||||
|
|
||||||
const result = await workspaceService.editRESTCollection(
|
|
||||||
collectionHandle,
|
|
||||||
updatedCollection
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
const cascadingAuthHeadersHandleResult =
|
||||||
|
await workspaceService.getRESTCollectionLevelAuthHeadersView(
|
||||||
|
collectionHandle
|
||||||
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(cascadingAuthHeadersHandleResult)) {
|
||||||
|
// INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cascadingAuthHeadersHandle = cascadingAuthHeadersHandleResult.right
|
||||||
|
|
||||||
|
if (cascadingAuthHeadersHandle.value.type === "invalid") {
|
||||||
// COLLECTION_INVALIDATED
|
// COLLECTION_INVALIDATED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { auth: cascadedAuth, headers: cascadedHeaders } =
|
const { auth: cascadedAuth, headers: cascadedHeaders } =
|
||||||
cascadeParentCollectionForHeaderAuth(collectionIndexPath, "rest")
|
cascadingAuthHeadersHandle.value.data
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
updateInheritedPropertiesForAffectedRequests(
|
updateInheritedPropertiesForAffectedRequests(
|
||||||
|
|||||||
@@ -17,3 +17,19 @@ export type HoppInheritedProperty = {
|
|||||||
inheritedHeader: HoppRESTHeader | GQLHeader
|
inheritedHeader: HoppRESTHeader | GQLHeader
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModifiedAuth<T, AuthType> = {
|
||||||
|
[K in keyof T]: K extends 'inheritedAuth' ? Extract<T[K], AuthType> : T[K]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ModifiedHeaders<T, HeaderType> = {
|
||||||
|
[K in keyof T]: K extends 'inheritedHeader' ? Extract<T[K], HeaderType> : T[K]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ModifiedHoppInheritedProperty<AuthType, HeaderType> = {
|
||||||
|
auth: ModifiedAuth<HoppInheritedProperty['auth'], AuthType>
|
||||||
|
headers: ModifiedHeaders<HoppInheritedProperty['headers'][number], HeaderType>[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HoppInheritedRESTProperty = ModifiedHoppInheritedProperty<HoppRESTAuth, HoppRESTHeader>
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { WorkspaceProvider } from "./provider"
|
|||||||
import { HandleRef } from "./handle"
|
import { HandleRef } from "./handle"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Workspace, WorkspaceCollection, WorkspaceRequest } from "./workspace"
|
import { Workspace, WorkspaceCollection, WorkspaceRequest } from "./workspace"
|
||||||
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
import { RESTCollectionChildrenView, RESTCollectionLevelAuthHeadersView, RootRESTCollectionView } from "./view"
|
||||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
|
||||||
export type WorkspaceError<ServiceErr> =
|
export type WorkspaceError<ServiceErr> =
|
||||||
@@ -170,8 +170,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
public async createRESTRootCollection(
|
public async createRESTRootCollection(
|
||||||
workspaceHandle: HandleRef<Workspace>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
collectionName: string,
|
newCollection: Partial<HoppCollection>
|
||||||
newCollectionID: string
|
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
@@ -192,8 +191,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
const result = await provider.createRESTRootCollection(
|
const result = await provider.createRESTRootCollection(
|
||||||
workspaceHandle,
|
workspaceHandle,
|
||||||
collectionName,
|
newCollection
|
||||||
newCollectionID
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -205,7 +203,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
public async createRESTChildCollection(
|
public async createRESTChildCollection(
|
||||||
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collectionName: string
|
newChildCollection: Partial<HoppCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
@@ -226,7 +224,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
const result = await provider.createRESTChildCollection(
|
const result = await provider.createRESTChildCollection(
|
||||||
parentCollectionHandle,
|
parentCollectionHandle,
|
||||||
collectionName
|
newChildCollection
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -236,14 +234,11 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.right(result.right)
|
return E.right(result.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async editRESTCollection(
|
public async updateRESTCollection(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
updatedCollection: HoppCollection
|
updatedCollection: Partial<HoppCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
> {
|
||||||
if (collectionHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
@@ -257,7 +252,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.editRESTCollection(
|
const result = await provider.updateRESTCollection(
|
||||||
collectionHandle,
|
collectionHandle,
|
||||||
updatedCollection
|
updatedCollection
|
||||||
)
|
)
|
||||||
@@ -266,16 +261,13 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
}
|
}
|
||||||
|
|
||||||
return E.right(result.right)
|
return E.right(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeRESTRootCollection(
|
public async removeRESTCollection(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
> {
|
||||||
if (collectionHandle.value.type === "invalid") {
|
if (collectionHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
@@ -289,44 +281,13 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.removeRESTRootCollection(collectionHandle)
|
const result = await provider.removeRESTCollection(collectionHandle)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
}
|
}
|
||||||
|
|
||||||
return E.right(result.right)
|
return E.right(undefined)
|
||||||
}
|
|
||||||
|
|
||||||
public async removeRESTChildCollection(
|
|
||||||
parentCollectionHandle: HandleRef<WorkspaceCollection>
|
|
||||||
): Promise<
|
|
||||||
E.Either<
|
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
if (parentCollectionHandle.value.type === "invalid") {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
|
||||||
parentCollectionHandle.value.data.providerID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await provider.removeRESTChildCollection(
|
|
||||||
parentCollectionHandle
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
|
||||||
}
|
|
||||||
|
|
||||||
return E.right(result.right)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createRESTRequest(
|
public async createRESTRequest(
|
||||||
@@ -365,10 +326,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
public async removeRESTRequest(
|
public async removeRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<boolean>
|
|
||||||
>
|
|
||||||
> {
|
> {
|
||||||
if (requestHandle.value.type === "invalid") {
|
if (requestHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
@@ -388,16 +346,16 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
}
|
}
|
||||||
|
|
||||||
return E.right(result.right)
|
return E.right(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateRESTRequest(
|
public async updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: Partial<HoppRESTRequest>
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<boolean>
|
HandleRef<boolean>["value"]
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (requestHandle.value.type === "invalid") {
|
if (requestHandle.value.type === "invalid") {
|
||||||
@@ -483,6 +441,36 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.right(result.right)
|
return E.right(result.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getRESTCollectionLevelAuthHeadersView(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
|
): Promise<
|
||||||
|
E.Either<
|
||||||
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
|
HandleRef<RESTCollectionLevelAuthHeadersView>
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
if (collectionHandle.value.type === "invalid") {
|
||||||
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const provider = this.registeredProviders.get(
|
||||||
|
collectionHandle.value.data.providerID
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!provider) {
|
||||||
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const result =
|
||||||
|
await provider.getRESTCollectionLevelAuthHeadersView(collectionHandle)
|
||||||
|
|
||||||
|
if (E.isLeft(result)) {
|
||||||
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
|
}
|
||||||
|
|
||||||
|
return E.right(result.right)
|
||||||
|
}
|
||||||
|
|
||||||
public registerWorkspaceProvider(provider: WorkspaceProvider) {
|
public registerWorkspaceProvider(provider: WorkspaceProvider) {
|
||||||
if (this.registeredProviders.has(provider.providerID)) {
|
if (this.registeredProviders.has(provider.providerID)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ import {
|
|||||||
WorkspaceDecor,
|
WorkspaceDecor,
|
||||||
WorkspaceRequest,
|
WorkspaceRequest,
|
||||||
} from "./workspace"
|
} from "./workspace"
|
||||||
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
import {
|
||||||
|
RESTCollectionLevelAuthHeadersView,
|
||||||
|
RESTCollectionChildrenView,
|
||||||
|
RootRESTCollectionView,
|
||||||
|
} from "./view"
|
||||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
|
||||||
export interface WorkspaceProvider {
|
export interface WorkspaceProvider {
|
||||||
@@ -33,38 +37,34 @@ export interface WorkspaceProvider {
|
|||||||
getRESTCollectionChildrenView(
|
getRESTCollectionChildrenView(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<RESTCollectionChildrenView>>>
|
): Promise<E.Either<unknown, HandleRef<RESTCollectionChildrenView>>>
|
||||||
// getRESTCollectionAuthHeaders(
|
getRESTCollectionLevelAuthHeadersView(
|
||||||
// collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
// ): Promise<E.Either<unknown, HandleRef<RESTCollectionAuthHeadersView>>>
|
): Promise<E.Either<unknown, HandleRef<RESTCollectionLevelAuthHeadersView>>>
|
||||||
|
|
||||||
createRESTRootCollection(
|
createRESTRootCollection(
|
||||||
workspaceHandle: HandleRef<Workspace>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
collectionName: string,
|
newCollection: Partial<HoppCollection>
|
||||||
newCollectionID: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
createRESTChildCollection(
|
createRESTChildCollection(
|
||||||
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collectionName: string
|
newChildCollection: Partial<HoppCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
editRESTCollection(
|
updateRESTCollection(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
updatedCollection: HoppCollection
|
updatedCollection: Partial<HoppCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, void>>
|
||||||
removeRESTRootCollection(
|
removeRESTCollection(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, void>>
|
||||||
removeRESTChildCollection(
|
|
||||||
parentCollectionHandle: HandleRef<WorkspaceCollection>
|
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
|
||||||
createRESTRequest(
|
createRESTRequest(
|
||||||
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
request: HoppRESTRequest
|
newRequest: HoppRESTRequest
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
||||||
updateRESTRequest(
|
updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: Partial<HoppRESTRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>["value"]>>
|
||||||
removeRESTRequest(
|
removeRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
): Promise<E.Either<unknown, void>>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { HoppCollection, makeCollection } from "@hoppscotch/data"
|
import {
|
||||||
|
HoppCollection,
|
||||||
|
HoppGQLAuth,
|
||||||
|
HoppRESTAuth,
|
||||||
|
HoppRESTHeaders,
|
||||||
|
makeCollection,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
import { Service } from "dioc"
|
import { Service } from "dioc"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Ref, computed, markRaw, ref, shallowRef } from "vue"
|
import { Ref, computed, markRaw, ref, shallowRef } from "vue"
|
||||||
@@ -24,6 +30,7 @@ import { platform } from "~/platform"
|
|||||||
import { HandleRef } from "~/services/new-workspace/handle"
|
import { HandleRef } from "~/services/new-workspace/handle"
|
||||||
import { WorkspaceProvider } from "~/services/new-workspace/provider"
|
import { WorkspaceProvider } from "~/services/new-workspace/provider"
|
||||||
import {
|
import {
|
||||||
|
RESTCollectionLevelAuthHeadersView,
|
||||||
RESTCollectionChildrenView,
|
RESTCollectionChildrenView,
|
||||||
RESTCollectionViewItem,
|
RESTCollectionViewItem,
|
||||||
RootRESTCollectionView,
|
RootRESTCollectionView,
|
||||||
@@ -43,6 +50,9 @@ import {
|
|||||||
resolveSaveContextOnCollectionReorder,
|
resolveSaveContextOnCollectionReorder,
|
||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
|
import { HoppGQLHeader } from "~/helpers/graphql"
|
||||||
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
|
import { computedAsync } from "@vueuse/core"
|
||||||
|
|
||||||
export class PersonalWorkspaceProviderService
|
export class PersonalWorkspaceProviderService
|
||||||
extends Service
|
extends Service
|
||||||
@@ -88,8 +98,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public createRESTRootCollection(
|
public createRESTRootCollection(
|
||||||
workspaceHandle: HandleRef<Workspace>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
collectionName: string,
|
newCollection: Partial<HoppCollection>
|
||||||
newCollectionID: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
||||||
if (
|
if (
|
||||||
workspaceHandle.value.type !== "ok" ||
|
workspaceHandle.value.type !== "ok" ||
|
||||||
@@ -113,8 +122,12 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newCollectionName = newCollection.name as string
|
||||||
|
const newCollectionID =
|
||||||
|
this.restCollectionState.value.state.length.toString()
|
||||||
|
|
||||||
const newRootCollection = makeCollection({
|
const newRootCollection = makeCollection({
|
||||||
name: collectionName,
|
name: newCollectionName,
|
||||||
folders: [],
|
folders: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
headers: [],
|
headers: [],
|
||||||
@@ -138,7 +151,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
providerID: this.providerID,
|
providerID: this.providerID,
|
||||||
workspaceID: workspaceHandle.value.data.workspaceID,
|
workspaceID: workspaceHandle.value.data.workspaceID,
|
||||||
collectionID: newCollectionID,
|
collectionID: newCollectionID,
|
||||||
name: collectionName,
|
name: newCollectionName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -147,13 +160,13 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public createRESTChildCollection(
|
public createRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collectionName: string
|
newChildCollection: Partial<HoppCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollectionHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollectionHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
parentCollectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
@@ -162,9 +175,9 @@ export class PersonalWorkspaceProviderService
|
|||||||
E.right(
|
E.right(
|
||||||
computed(() => {
|
computed(() => {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollectionHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollectionHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
parentCollectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: "invalid" as const,
|
type: "invalid" as const,
|
||||||
@@ -173,9 +186,10 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, workspaceID } =
|
const { collectionID, providerID, workspaceID } =
|
||||||
parentCollHandle.value.data
|
parentCollectionHandle.value.data
|
||||||
|
|
||||||
addRESTFolder(collectionName, collectionID)
|
const newCollectionName = newChildCollection.name as string
|
||||||
|
addRESTFolder(newCollectionName, collectionID)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
type: "HOPP_CREATE_COLLECTION",
|
type: "HOPP_CREATE_COLLECTION",
|
||||||
@@ -190,7 +204,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
providerID,
|
providerID,
|
||||||
workspaceID,
|
workspaceID,
|
||||||
collectionID,
|
collectionID,
|
||||||
name: collectionName,
|
name: newCollectionName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -198,186 +212,111 @@ export class PersonalWorkspaceProviderService
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public editRESTCollection(
|
public updateRESTCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
updatedCollection: HoppCollection
|
updatedCollection: Partial<HoppCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
): Promise<E.Either<unknown, void>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collectionHandle.value.type !== "ok" ||
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
collectionHandle.value.data.providerID !== this.providerID ||
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
collectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
const { collectionID } = collectionHandle.value.data
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "WORKSPACE_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID } = collHandle.value.data
|
const collection = navigateToFolderWithIndexPath(
|
||||||
|
this.restCollectionState.value.state,
|
||||||
const collection: HoppCollection | null =
|
collectionID.split("/").map((id) => parseInt(id))
|
||||||
navigateToFolderWithIndexPath(
|
|
||||||
this.restCollectionState.value.state,
|
|
||||||
collectionID.split("/").map((id) => parseInt(id))
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!collection) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "COLLECTION_NOT_FOUND" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const isRootCollection = collectionID.split("/").length === 1
|
|
||||||
|
|
||||||
if (isRootCollection) {
|
|
||||||
editRESTCollection(parseInt(collectionID), updatedCollection)
|
|
||||||
} else {
|
|
||||||
editRESTFolder(collectionID, updatedCollection)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
public removeRESTRootCollection(
|
const newCollection = {
|
||||||
collHandle: HandleRef<WorkspaceCollection>
|
...collection,
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
...updatedCollection,
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
const isRootCollection = collectionID.split("/").length === 1
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
collHandle.value.type !== "ok" ||
|
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
|
||||||
collHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "WORKSPACE_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID } = collHandle.value.data
|
if (isRootCollection) {
|
||||||
|
editRESTCollection(parseInt(collectionID), newCollection)
|
||||||
|
} else {
|
||||||
|
editRESTFolder(collectionID, newCollection)
|
||||||
|
}
|
||||||
|
|
||||||
const collectionIndex = parseInt(collectionID)
|
return Promise.resolve(E.right(undefined))
|
||||||
|
|
||||||
const collectionToRemove = navigateToFolderWithIndexPath(
|
|
||||||
restCollectionStore.value.state,
|
|
||||||
[collectionIndex]
|
|
||||||
)
|
|
||||||
|
|
||||||
removeRESTCollection(
|
|
||||||
collectionIndex,
|
|
||||||
collectionToRemove ? collectionToRemove.id : undefined
|
|
||||||
)
|
|
||||||
|
|
||||||
resolveSaveContextOnCollectionReorder({
|
|
||||||
lastIndex: collectionIndex,
|
|
||||||
newIndex: -1,
|
|
||||||
folderPath: "", // root collection
|
|
||||||
length: this.restCollectionState.value.state.length,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeRESTChildCollection(
|
public removeRESTCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
): Promise<E.Either<unknown, void>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
collectionHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
collectionHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
collectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
const { collectionID } = collectionHandle.value.data
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
parentCollHandle.value.type !== "ok" ||
|
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "COLLECTION_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID } = parentCollHandle.value.data
|
const isRootCollection = collectionID.split("/").length === 1
|
||||||
|
|
||||||
const folderToRemove = path
|
if (isRootCollection) {
|
||||||
? navigateToFolderWithIndexPath(
|
const collectionIndex = parseInt(collectionID)
|
||||||
restCollectionStore.value.state,
|
|
||||||
collectionID.split("/").map((id) => parseInt(id))
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
removeRESTFolder(
|
const collectionToRemove = navigateToFolderWithIndexPath(
|
||||||
collectionID,
|
restCollectionStore.value.state,
|
||||||
folderToRemove ? folderToRemove.id : undefined
|
[collectionIndex]
|
||||||
)
|
|
||||||
|
|
||||||
const parentFolder = collectionID.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
|
|
||||||
resolveSaveContextOnCollectionReorder({
|
|
||||||
lastIndex: this.pathToLastIndex(collectionID),
|
|
||||||
newIndex: -1,
|
|
||||||
folderPath: parentFolder,
|
|
||||||
length: getFoldersByPath(
|
|
||||||
this.restCollectionState.value.state,
|
|
||||||
parentFolder
|
|
||||||
).length,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
removeRESTCollection(
|
||||||
|
collectionIndex,
|
||||||
|
collectionToRemove ? collectionToRemove.id : undefined
|
||||||
|
)
|
||||||
|
|
||||||
|
resolveSaveContextOnCollectionReorder({
|
||||||
|
lastIndex: collectionIndex,
|
||||||
|
newIndex: -1,
|
||||||
|
folderPath: "", // root collection
|
||||||
|
length: this.restCollectionState.value.state.length,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const folderToRemove = path
|
||||||
|
? navigateToFolderWithIndexPath(
|
||||||
|
restCollectionStore.value.state,
|
||||||
|
collectionID.split("/").map((id) => parseInt(id))
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
removeRESTFolder(
|
||||||
|
collectionID,
|
||||||
|
folderToRemove ? folderToRemove.id : undefined
|
||||||
|
)
|
||||||
|
|
||||||
|
const parentFolder = collectionID.split("/").slice(0, -1).join("/") // Remove last folder to get parent folder
|
||||||
|
resolveSaveContextOnCollectionReorder({
|
||||||
|
lastIndex: this.pathToLastIndex(collectionID),
|
||||||
|
newIndex: -1,
|
||||||
|
folderPath: parentFolder,
|
||||||
|
length: getFoldersByPath(
|
||||||
|
this.restCollectionState.value.state,
|
||||||
|
parentFolder
|
||||||
|
).length,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(E.right(undefined))
|
||||||
}
|
}
|
||||||
|
|
||||||
public createRESTRequest(
|
public createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
newRequest: HoppRESTRequest
|
newRequest: HoppRESTRequest
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollectionHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollectionHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
parentCollectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
@@ -386,9 +325,9 @@ export class PersonalWorkspaceProviderService
|
|||||||
E.right(
|
E.right(
|
||||||
computed(() => {
|
computed(() => {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollectionHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollectionHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
parentCollectionHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: "invalid" as const,
|
type: "invalid" as const,
|
||||||
@@ -397,7 +336,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, workspaceID } =
|
const { collectionID, providerID, workspaceID } =
|
||||||
parentCollHandle.value.data
|
parentCollectionHandle.value.data
|
||||||
|
|
||||||
const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
|
const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
|
||||||
|
|
||||||
@@ -427,7 +366,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public removeRESTRequest(
|
public removeRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
): Promise<E.Either<unknown, void>> {
|
||||||
if (
|
if (
|
||||||
requestHandle.value.type !== "ok" ||
|
requestHandle.value.type !== "ok" ||
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
requestHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -436,43 +375,23 @@ export class PersonalWorkspaceProviderService
|
|||||||
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
const { collectionID, requestID } = requestHandle.value.data
|
||||||
E.right(
|
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
requestHandle.value.type !== "ok" ||
|
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
|
||||||
requestHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "REQUEST_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID, requestID } = requestHandle.value.data
|
const requestToRemove = navigateToFolderWithIndexPath(
|
||||||
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
|
restCollectionStore.value.state,
|
||||||
|
collectionID.split("/").map((id) => parseInt(id))
|
||||||
|
)?.requests[requestIndex]
|
||||||
|
|
||||||
const requestToRemove = navigateToFolderWithIndexPath(
|
removeRESTRequest(collectionID, requestIndex, requestToRemove?.id)
|
||||||
restCollectionStore.value.state,
|
|
||||||
collectionID.split("/").map((id) => parseInt(id))
|
|
||||||
)?.requests[requestIndex]
|
|
||||||
|
|
||||||
removeRESTRequest(collectionID, requestIndex, requestToRemove?.id)
|
return Promise.resolve(E.right(undefined))
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateRESTRequest(
|
public updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: Partial<HoppRESTRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>["value"]>> {
|
||||||
if (
|
if (
|
||||||
requestHandle.value.type !== "ok" ||
|
requestHandle.value.type !== "ok" ||
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
requestHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -481,45 +400,36 @@ export class PersonalWorkspaceProviderService
|
|||||||
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
const { collectionID, requestID, request } = requestHandle.value.data
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
requestHandle.value.type !== "ok" ||
|
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
|
||||||
requestHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "REQUEST_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID, requestID } = requestHandle.value.data
|
try {
|
||||||
|
const newRequest: HoppRESTRequest = {
|
||||||
|
...request,
|
||||||
|
...updatedRequest,
|
||||||
|
}
|
||||||
|
const requestIndex = parseInt(requestID)
|
||||||
|
editRESTRequest(collectionID, requestIndex, newRequest)
|
||||||
|
|
||||||
try {
|
platform.analytics?.logEvent({
|
||||||
const requestIndex = parseInt(requestID)
|
type: "HOPP_SAVE_REQUEST",
|
||||||
editRESTRequest(collectionID, requestIndex, updatedRequest)
|
platform: "rest",
|
||||||
|
createdNow: false,
|
||||||
platform.analytics?.logEvent({
|
workspaceType: "personal",
|
||||||
type: "HOPP_SAVE_REQUEST",
|
})
|
||||||
platform: "rest",
|
} catch (err) {
|
||||||
createdNow: false,
|
return Promise.resolve(
|
||||||
workspaceType: "personal",
|
E.right({
|
||||||
})
|
type: "invalid" as const,
|
||||||
} catch (err) {
|
reason: "REQUEST_PATH_NOT_FOUND" as const,
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "REQUEST_PATH_NOT_FOUND" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: true,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(
|
||||||
|
E.right({
|
||||||
|
type: "ok",
|
||||||
|
data: true,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,6 +676,117 @@ export class PersonalWorkspaceProviderService
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getRESTCollectionLevelAuthHeadersView(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
|
): Promise<E.Either<never, HandleRef<RESTCollectionLevelAuthHeadersView>>> {
|
||||||
|
return Promise.resolve(
|
||||||
|
E.right(
|
||||||
|
computed(() => {
|
||||||
|
if (
|
||||||
|
collectionHandle.value.type === "invalid" ||
|
||||||
|
collectionHandle.value.data.providerID !== this.providerID ||
|
||||||
|
collectionHandle.value.data.workspaceID !== "personal"
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
type: "invalid" as const,
|
||||||
|
reason: "INVALID_COLLECTION_HANDLE" as const,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { collectionID } = collectionHandle.value.data
|
||||||
|
|
||||||
|
let auth: HoppInheritedProperty["auth"] = {
|
||||||
|
parentID: collectionID ?? "",
|
||||||
|
parentName: "",
|
||||||
|
inheritedAuth: {
|
||||||
|
authType: "none",
|
||||||
|
authActive: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const headers: HoppInheritedProperty["headers"] = []
|
||||||
|
|
||||||
|
if (!collectionID) return { type: "ok", data: { auth, headers } }
|
||||||
|
|
||||||
|
const path = collectionID.split("/").map((i) => parseInt(i))
|
||||||
|
|
||||||
|
// Check if the path is empty or invalid
|
||||||
|
if (!path || path.length === 0) {
|
||||||
|
console.error("Invalid path:", collectionID)
|
||||||
|
return { type: "ok", data: { auth, headers } }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through the path and get the last parent folder with authType other than 'inherit'
|
||||||
|
for (let i = 0; i < path.length; i++) {
|
||||||
|
const parentFolder = navigateToFolderWithIndexPath(
|
||||||
|
this.restCollectionState.value.state,
|
||||||
|
[...path.slice(0, i + 1)] // Create a copy of the path array
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if parentFolder is undefined or null
|
||||||
|
if (!parentFolder) {
|
||||||
|
console.error("Parent folder not found for path:", path)
|
||||||
|
return { type: "ok", data: { auth, headers } }
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentFolderAuth = parentFolder.auth as
|
||||||
|
| HoppRESTAuth
|
||||||
|
| HoppGQLAuth
|
||||||
|
const parentFolderHeaders = parentFolder.headers as
|
||||||
|
| HoppRESTHeaders
|
||||||
|
| HoppGQLHeader[]
|
||||||
|
|
||||||
|
// check if the parent folder has authType 'inherit' and if it is the root folder
|
||||||
|
if (
|
||||||
|
parentFolderAuth?.authType === "inherit" &&
|
||||||
|
[...path.slice(0, i + 1)].length === 1
|
||||||
|
) {
|
||||||
|
auth = {
|
||||||
|
parentID: [...path.slice(0, i + 1)].join("/"),
|
||||||
|
parentName: parentFolder.name,
|
||||||
|
inheritedAuth: auth.inheritedAuth,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentFolderAuth?.authType !== "inherit") {
|
||||||
|
auth = {
|
||||||
|
parentID: [...path.slice(0, i + 1)].join("/"),
|
||||||
|
parentName: parentFolder.name,
|
||||||
|
inheritedAuth: parentFolderAuth,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update headers, overwriting duplicates by key
|
||||||
|
if (parentFolderHeaders) {
|
||||||
|
const activeHeaders = parentFolderHeaders.filter((h) => h.active)
|
||||||
|
activeHeaders.forEach((header) => {
|
||||||
|
const index = headers.findIndex(
|
||||||
|
(h) => h.inheritedHeader?.key === header.key
|
||||||
|
)
|
||||||
|
const currentPath = [...path.slice(0, i + 1)].join("/")
|
||||||
|
if (index !== -1) {
|
||||||
|
// Replace the existing header with the same key
|
||||||
|
headers[index] = {
|
||||||
|
parentID: currentPath,
|
||||||
|
parentName: parentFolder.name,
|
||||||
|
inheritedHeader: header,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
headers.push({
|
||||||
|
parentID: currentPath,
|
||||||
|
parentName: parentFolder.name,
|
||||||
|
inheritedHeader: header,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { type: "ok", data: { auth, headers } }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
public getWorkspaceHandle(
|
public getWorkspaceHandle(
|
||||||
workspaceID: string
|
workspaceID: string
|
||||||
): Promise<E.Either<unknown, HandleRef<Workspace>>> {
|
): Promise<E.Either<unknown, HandleRef<Workspace>>> {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { Ref } from "vue"
|
import { Ref } from "vue"
|
||||||
|
import { HoppInheritedRESTProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
|
|
||||||
|
export type RESTCollectionLevelAuthHeadersView = {
|
||||||
|
auth: HoppInheritedRESTProperty["auth"]
|
||||||
|
headers: HoppInheritedRESTProperty["headers"]
|
||||||
|
}
|
||||||
|
|
||||||
export type RESTCollectionViewCollection = {
|
export type RESTCollectionViewCollection = {
|
||||||
collectionID: string
|
collectionID: string
|
||||||
|
|||||||
Reference in New Issue
Block a user