refactor(common): route mock server and published docs operations through platform backend (#6036)
This commit is contained in:
parent
59c1b595a6
commit
f690d5969a
17 changed files with 220 additions and 158 deletions
|
|
@ -300,11 +300,7 @@ import {
|
||||||
CreatePublishedDocsArgs,
|
CreatePublishedDocsArgs,
|
||||||
UpdatePublishedDocsArgs,
|
UpdatePublishedDocsArgs,
|
||||||
} from "~/helpers/backend/graphql"
|
} from "~/helpers/backend/graphql"
|
||||||
import {
|
import { platform } from "~/platform"
|
||||||
createPublishedDoc,
|
|
||||||
deletePublishedDoc,
|
|
||||||
updatePublishedDoc,
|
|
||||||
} from "~/helpers/backend/mutations/PublishedDocs"
|
|
||||||
|
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
|
|
@ -976,7 +972,7 @@ const handlePublish = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
createPublishedDoc(doc),
|
platform.backend.createPublishedDoc(doc),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Error publishing documentation:", error)
|
console.error("Error publishing documentation:", error)
|
||||||
|
|
@ -1032,7 +1028,7 @@ const handleUpdate = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
updatePublishedDoc(id, doc),
|
platform.backend.updatePublishedDoc(id, doc),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Error updating documentation:", error)
|
console.error("Error updating documentation:", error)
|
||||||
|
|
@ -1077,7 +1073,7 @@ const handleDelete = async () => {
|
||||||
|
|
||||||
isProcessingPublish.value = true
|
isProcessingPublish.value = true
|
||||||
await pipe(
|
await pipe(
|
||||||
deletePublishedDoc(publishedDocId.value),
|
platform.backend.deletePublishedDoc(publishedDocId.value),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Error deleting documentation:", error)
|
console.error("Error deleting documentation:", error)
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ import { useReadonlyStream } from "@composables/stream"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { refAutoReset } from "@vueuse/core"
|
import { refAutoReset } from "@vueuse/core"
|
||||||
import { computed, ref, watch } from "vue"
|
import { computed, ref, watch } from "vue"
|
||||||
import { MockServer } from "~/helpers/backend/graphql"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { copyToClipboard as copyToClipboardHelper } from "~/helpers/utils/clipboard"
|
import { copyToClipboard as copyToClipboardHelper } from "~/helpers/utils/clipboard"
|
||||||
import {
|
import {
|
||||||
mockServers$,
|
mockServers$,
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ import { useReadonlyStream } from "@composables/stream"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { computed, ref, watch } from "vue"
|
import { computed, ref, watch } from "vue"
|
||||||
import { TippyComponent } from "vue-tippy"
|
import { TippyComponent } from "vue-tippy"
|
||||||
import { MockServer } from "~/helpers/backend/graphql"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { showCreateMockServerModal$ } from "~/newstore/mockServers"
|
import { showCreateMockServerModal$ } from "~/newstore/mockServers"
|
||||||
import { useMockServer } from "~/composables/useMockServer"
|
import { useMockServer } from "~/composables/useMockServer"
|
||||||
import MockServerCreatedInfo from "~/components/mockServer/MockServerCreatedInfo.vue"
|
import MockServerCreatedInfo from "~/components/mockServer/MockServerCreatedInfo.vue"
|
||||||
|
|
|
||||||
|
|
@ -169,9 +169,9 @@ import { pipe } from "fp-ts/function"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { ref, watch } from "vue"
|
import { ref, watch } from "vue"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
import { updateMockServer as updateMockServerMutation } from "~/helpers/backend/mutations/MockServer"
|
import { platform } from "~/platform"
|
||||||
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
||||||
import type { MockServer } from "~/newstore/mockServers"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { updateMockServer as updateMockServerInStore } from "~/newstore/mockServers"
|
import { updateMockServer as updateMockServerInStore } from "~/newstore/mockServers"
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
|
|
@ -228,7 +228,7 @@ const updateMockServer = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
updateMockServerMutation(props.mockServer.id, payload),
|
platform.backend.updateMockServer(props.mockServer.id, payload),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
@ -259,7 +259,9 @@ const toggleMockServer = async () => {
|
||||||
const newActiveState = !isActive.value
|
const newActiveState = !isActive.value
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
updateMockServerMutation(props.mockServer.id, { isActive: newActiveState }),
|
platform.backend.updateMockServer(props.mockServer.id, {
|
||||||
|
isActive: newActiveState,
|
||||||
|
}),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { refAutoReset } from "@vueuse/core"
|
import { refAutoReset } from "@vueuse/core"
|
||||||
import { MockServer } from "~/helpers/backend/graphql"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { copyToClipboard as copyToClipboardHelper } from "~/helpers/utils/clipboard"
|
import { copyToClipboard as copyToClipboardHelper } from "~/helpers/utils/clipboard"
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ import { useMockServerStatus } from "~/composables/mockServer"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
||||||
import type { MockServer } from "~/newstore/mockServers"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -223,10 +223,6 @@ import {
|
||||||
|
|
||||||
import MockServerEditMockServer from "~/components/mockServer/EditMockServer.vue"
|
import MockServerEditMockServer from "~/components/mockServer/EditMockServer.vue"
|
||||||
import MockServerLogs from "~/components/mockServer/MockServerLogs.vue"
|
import MockServerLogs from "~/components/mockServer/MockServerLogs.vue"
|
||||||
import {
|
|
||||||
deleteMockServer as deleteMockServerMutation,
|
|
||||||
updateMockServer as updateMockServerMutation,
|
|
||||||
} from "~/helpers/backend/mutations/MockServer"
|
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
import IconCheck from "~icons/lucide/check"
|
import IconCheck from "~icons/lucide/check"
|
||||||
|
|
@ -275,7 +271,9 @@ const toggleMockServer = async (mockServer: MockServer) => {
|
||||||
const newActiveState = !mockServer.isActive
|
const newActiveState = !mockServer.isActive
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
updateMockServerMutation(mockServer.id, { isActive: newActiveState }),
|
platform.backend.updateMockServer(mockServer.id, {
|
||||||
|
isActive: newActiveState,
|
||||||
|
}),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
@ -317,7 +315,7 @@ const confirmDelete = async () => {
|
||||||
confirmDeleteMockServer.value = false
|
confirmDeleteMockServer.value = false
|
||||||
|
|
||||||
await pipe(
|
await pipe(
|
||||||
deleteMockServerMutation(mockServer.id),
|
platform.backend.deleteMockServer(mockServer.id),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from "vue"
|
import { ref, onMounted } from "vue"
|
||||||
import { useI18n } from "~/composables/i18n"
|
import { useI18n } from "~/composables/i18n"
|
||||||
import {
|
import { platform } from "~/platform"
|
||||||
getMockServerLogs,
|
|
||||||
deleteMockServerLog,
|
|
||||||
} from "~/helpers/backend/queries/MockServerLogs"
|
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { pipe } from "fp-ts/function"
|
import { pipe } from "fp-ts/function"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
|
|
@ -141,7 +138,7 @@ const logToDelete = ref<string | null>(null)
|
||||||
const fetchLogs = async () => {
|
const fetchLogs = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
await pipe(
|
await pipe(
|
||||||
getMockServerLogs(props.mockServerID),
|
platform.backend.getMockServerLogs(props.mockServerID),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
@ -169,7 +166,7 @@ const confirmRemoveLog = (id: string) => {
|
||||||
const confirmDelete = async () => {
|
const confirmDelete = async () => {
|
||||||
if (logToDelete.value) {
|
if (logToDelete.value) {
|
||||||
await pipe(
|
await pipe(
|
||||||
deleteMockServerLog(logToDelete.value),
|
platform.backend.deleteMockServerLog(logToDelete.value),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import { mockServers$ } from "~/newstore/mockServers"
|
import { mockServers$ } from "~/newstore/mockServers"
|
||||||
import type { MockServer } from "~/newstore/mockServers"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composable to get mock server status for collections
|
* Composable to get mock server status for collections
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,9 @@ import { useService } from "dioc/vue"
|
||||||
import { pipe } from "fp-ts/function"
|
import { pipe } from "fp-ts/function"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { MockServer, WorkspaceType } from "~/helpers/backend/graphql"
|
import { WorkspaceType } from "~/helpers/backend/graphql"
|
||||||
import {
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
createMockServer as createMockServerMutation,
|
import { platform } from "~/platform"
|
||||||
updateMockServer,
|
|
||||||
} from "~/helpers/backend/mutations/MockServer"
|
|
||||||
import {
|
import {
|
||||||
createTeamEnvironment,
|
createTeamEnvironment,
|
||||||
updateTeamEnvironment,
|
updateTeamEnvironment,
|
||||||
|
|
@ -31,7 +29,6 @@ import {
|
||||||
} from "~/newstore/mockServers"
|
} from "~/newstore/mockServers"
|
||||||
import { TeamCollectionsService } from "~/services/team-collection.service"
|
import { TeamCollectionsService } from "~/services/team-collection.service"
|
||||||
import { WorkspaceService } from "~/services/workspace.service"
|
import { WorkspaceService } from "~/services/workspace.service"
|
||||||
import { platform } from "~/platform"
|
|
||||||
|
|
||||||
export function useMockServer() {
|
export function useMockServer() {
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
|
@ -259,7 +256,7 @@ export function useMockServer() {
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const result = await pipe(
|
const result = await pipe(
|
||||||
createMockServerMutation(
|
platform.backend.createMockServer(
|
||||||
mockServerName.trim(),
|
mockServerName.trim(),
|
||||||
workspaceType,
|
workspaceType,
|
||||||
workspaceID,
|
workspaceID,
|
||||||
|
|
@ -307,7 +304,9 @@ export function useMockServer() {
|
||||||
const newActiveState = !mockServer.isActive
|
const newActiveState = !mockServer.isActive
|
||||||
|
|
||||||
return await pipe(
|
return await pipe(
|
||||||
updateMockServer(mockServer.id, { isActive: newActiveState }),
|
platform.backend.updateMockServer(mockServer.id, {
|
||||||
|
isActive: newActiveState,
|
||||||
|
}),
|
||||||
TE.match(
|
TE.match(
|
||||||
() => {
|
() => {
|
||||||
toast.error(t("error.something_went_wrong"))
|
toast.error(t("error.something_went_wrong"))
|
||||||
|
|
|
||||||
|
|
@ -6,36 +6,10 @@ import {
|
||||||
CreateMockServerDocument,
|
CreateMockServerDocument,
|
||||||
UpdateMockServerDocument,
|
UpdateMockServerDocument,
|
||||||
DeleteMockServerDocument,
|
DeleteMockServerDocument,
|
||||||
GetTeamMockServersDocument,
|
|
||||||
WorkspaceType,
|
WorkspaceType,
|
||||||
} from "../graphql"
|
} from "../graphql"
|
||||||
|
|
||||||
// Types for mock server
|
import type { MockServer } from "../types/MockServer"
|
||||||
export type MockServer = {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
subdomain: string
|
|
||||||
serverUrlPathBased?: string
|
|
||||||
serverUrlDomainBased?: string | null
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
workspaceID?: string | null
|
|
||||||
delayInMs?: number
|
|
||||||
isPublic: boolean
|
|
||||||
isActive: boolean
|
|
||||||
createdOn: Date
|
|
||||||
updatedOn: Date
|
|
||||||
creator?: {
|
|
||||||
uid: string
|
|
||||||
}
|
|
||||||
collection?: {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
requests?: any[]
|
|
||||||
}
|
|
||||||
// Legacy fields for backward compatibility
|
|
||||||
userUid?: string
|
|
||||||
collectionID?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateMockServerError =
|
type CreateMockServerError =
|
||||||
| "mock_server/invalid_collection"
|
| "mock_server/invalid_collection"
|
||||||
|
|
@ -174,42 +148,6 @@ export const deleteMockServer = (id: string) =>
|
||||||
(error) => (error as Error).message as DeleteMockServerError
|
(error) => (error as Error).message as DeleteMockServerError
|
||||||
)
|
)
|
||||||
|
|
||||||
export const getTeamMockServers = (
|
|
||||||
teamID: string,
|
|
||||||
skip?: number,
|
|
||||||
take?: number
|
|
||||||
) =>
|
|
||||||
TE.tryCatch(
|
|
||||||
async () => {
|
|
||||||
const result = await client
|
|
||||||
.value!.query(GetTeamMockServersDocument, {
|
|
||||||
teamID,
|
|
||||||
skip,
|
|
||||||
take,
|
|
||||||
})
|
|
||||||
.toPromise()
|
|
||||||
|
|
||||||
if (result.error) {
|
|
||||||
throw new Error(
|
|
||||||
result.error.message || "Failed to get team mock servers"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.data) {
|
|
||||||
throw new Error("No data returned from get team mock servers query")
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = result.data.teamMockServers
|
|
||||||
// Map the GraphQL response to frontend format
|
|
||||||
return data.map((mockServer: any) => ({
|
|
||||||
...mockServer,
|
|
||||||
userUid: mockServer.creator?.uid || "", // Legacy field
|
|
||||||
collectionID: mockServer.collection?.id || "", // Legacy field
|
|
||||||
})) as MockServer[]
|
|
||||||
},
|
|
||||||
(error) => (error as Error).message as CreateMockServerError
|
|
||||||
)
|
|
||||||
|
|
||||||
// Centralized mapper for backend GraphQL error tokens to user-facing messages.
|
// Centralized mapper for backend GraphQL error tokens to user-facing messages.
|
||||||
export const getErrorMessage = (err: GQLError<string> | string | Error) => {
|
export const getErrorMessage = (err: GQLError<string> | string | Error) => {
|
||||||
const t = getI18n()
|
const t = getI18n()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {
|
||||||
type TeamPublishedDocsListQuery,
|
type TeamPublishedDocsListQuery,
|
||||||
PublishedDocDocument,
|
PublishedDocDocument,
|
||||||
PublishedDocs,
|
PublishedDocs,
|
||||||
|
type PublishedDocQuery as GqlPublishedDocQuery,
|
||||||
} from "../graphql"
|
} from "../graphql"
|
||||||
import {
|
import {
|
||||||
HoppCollection,
|
HoppCollection,
|
||||||
|
|
@ -241,7 +242,7 @@ export const getPublishedDocByID = (id: string) =>
|
||||||
throw result.left
|
throw result.left
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = result.right as PublishedDocQuery
|
const data = result.right as GqlPublishedDocQuery
|
||||||
return data.publishedDoc
|
return data.publishedDoc
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { WorkspaceType } from "~/helpers/backend/graphql"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canonical MockServer type used across the frontend.
|
||||||
|
* Shared by BackendPlatformDef, newstore/mockServers, and mutation helpers.
|
||||||
|
*/
|
||||||
|
export type MockServer = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
subdomain: string
|
||||||
|
serverUrlPathBased?: string
|
||||||
|
serverUrlDomainBased?: string | null
|
||||||
|
workspaceType: WorkspaceType
|
||||||
|
workspaceID?: string | null
|
||||||
|
delayInMs?: number
|
||||||
|
isPublic: boolean
|
||||||
|
isActive: boolean
|
||||||
|
createdOn: Date | string
|
||||||
|
updatedOn: Date | string
|
||||||
|
creator?: {
|
||||||
|
uid: string
|
||||||
|
} | null
|
||||||
|
collection?: {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
requests?: any[]
|
||||||
|
} | null
|
||||||
|
// Legacy fields for backward compatibility
|
||||||
|
userUid?: string
|
||||||
|
collectionID?: string
|
||||||
|
}
|
||||||
|
|
@ -2,41 +2,13 @@ import { pipe } from "fp-ts/function"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { BehaviorSubject } from "rxjs"
|
import { BehaviorSubject } from "rxjs"
|
||||||
import { pluck } from "rxjs/operators"
|
import { pluck } from "rxjs/operators"
|
||||||
import {
|
|
||||||
getMyMockServers,
|
|
||||||
getTeamMockServers,
|
|
||||||
} from "~/helpers/backend/queries/MockServer"
|
|
||||||
import { getService } from "~/modules/dioc"
|
import { getService } from "~/modules/dioc"
|
||||||
import { WorkspaceService } from "~/services/workspace.service"
|
import { WorkspaceService } from "~/services/workspace.service"
|
||||||
|
import { platform } from "~/platform"
|
||||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||||
|
|
||||||
export type WorkspaceType = "USER" | "TEAM"
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
|
import { WorkspaceType } from "~/helpers/backend/graphql"
|
||||||
export type MockServer = {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
subdomain: string
|
|
||||||
serverUrlPathBased?: string
|
|
||||||
serverUrlDomainBased?: string | null
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
workspaceID?: string | null
|
|
||||||
delayInMs?: number
|
|
||||||
isPublic: boolean
|
|
||||||
isActive: boolean
|
|
||||||
createdOn: Date
|
|
||||||
updatedOn: Date
|
|
||||||
creator?: {
|
|
||||||
uid: string
|
|
||||||
}
|
|
||||||
collection?: {
|
|
||||||
id: string
|
|
||||||
title: string
|
|
||||||
requests?: any[]
|
|
||||||
} | null
|
|
||||||
// Legacy fields for backward compatibility
|
|
||||||
userUid?: string
|
|
||||||
collectionID?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CreateMockServerInput = {
|
export type CreateMockServerInput = {
|
||||||
name: string
|
name: string
|
||||||
|
|
@ -179,7 +151,7 @@ export function loadMockServers(skip?: number, take?: number) {
|
||||||
}
|
}
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
return pipe(
|
return pipe(
|
||||||
getMyMockServers(skip, take),
|
platform.backend.getMyMockServers(skip, take),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Failed to load mock servers:", error)
|
console.error("Failed to load mock servers:", error)
|
||||||
|
|
@ -195,7 +167,7 @@ export function loadMockServers(skip?: number, take?: number) {
|
||||||
// Fallback to user mock servers if workspace service is not available
|
// Fallback to user mock servers if workspace service is not available
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
return pipe(
|
return pipe(
|
||||||
getMyMockServers(skip, take),
|
platform.backend.getMyMockServers(skip, take),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Failed to load mock servers:", error)
|
console.error("Failed to load mock servers:", error)
|
||||||
|
|
@ -218,7 +190,7 @@ export function loadTeamMockServers(
|
||||||
) {
|
) {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
return pipe(
|
return pipe(
|
||||||
getTeamMockServers(teamID, skip, take),
|
platform.backend.getTeamMockServers(teamID, skip, take),
|
||||||
TE.match(
|
TE.match(
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error("Failed to load team mock servers:", error)
|
console.error("Failed to load team mock servers:", error)
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,31 @@ import * as E from "fp-ts/lib/Either"
|
||||||
|
|
||||||
import { GQLError } from "~/helpers/backend/GQLClient"
|
import { GQLError } from "~/helpers/backend/GQLClient"
|
||||||
import {
|
import {
|
||||||
|
AcceptTeamInvitationMutation,
|
||||||
|
CreatePublishedDocMutation,
|
||||||
|
CreatePublishedDocsArgs,
|
||||||
CreateShortcodeMutation,
|
CreateShortcodeMutation,
|
||||||
|
CreateTeamInvitationMutation,
|
||||||
|
CreateTeamMutation,
|
||||||
|
DeletePublishedDocMutation,
|
||||||
GetInviteDetailsQuery,
|
GetInviteDetailsQuery,
|
||||||
GetInviteDetailsQueryVariables,
|
GetInviteDetailsQueryVariables,
|
||||||
|
GetMockServerLogsQuery,
|
||||||
GetMyTeamsQuery,
|
GetMyTeamsQuery,
|
||||||
|
PublishedDocQuery,
|
||||||
GetUserShortcodesQuery,
|
GetUserShortcodesQuery,
|
||||||
TeamAccessRole,
|
TeamAccessRole,
|
||||||
|
TeamPublishedDocsListQuery,
|
||||||
|
UpdatePublishedDocMutation,
|
||||||
|
UpdatePublishedDocsArgs,
|
||||||
|
UserPublishedDocsListQuery,
|
||||||
|
WorkspaceType,
|
||||||
} from "~/helpers/backend/graphql"
|
} from "~/helpers/backend/graphql"
|
||||||
|
|
||||||
import { useGQLQuery } from "~/composables/graphql"
|
import { useGQLQuery } from "~/composables/graphql"
|
||||||
import { Email } from "~/helpers/backend/types/Email"
|
import { Email } from "~/helpers/backend/types/Email"
|
||||||
|
import type { MockServer } from "~/helpers/backend/types/MockServer"
|
||||||
import { TeamName } from "~/helpers/backend/types/TeamName"
|
import { TeamName } from "~/helpers/backend/types/TeamName"
|
||||||
import {
|
|
||||||
AcceptTeamInvitationMutation,
|
|
||||||
CreateTeamInvitationMutation,
|
|
||||||
CreateTeamMutation,
|
|
||||||
} from "../helpers/backend/graphql"
|
|
||||||
|
|
||||||
export type BackendPlatformDef = {
|
export type BackendPlatformDef = {
|
||||||
// Read actions via GQL queries
|
// Read actions via GQL queries
|
||||||
|
|
@ -69,4 +78,85 @@ export type BackendPlatformDef = {
|
||||||
request: HoppRESTRequest,
|
request: HoppRESTRequest,
|
||||||
properties?: string
|
properties?: string
|
||||||
) => TE.TaskEither<GQLError<string>, CreateShortcodeMutation>
|
) => TE.TaskEither<GQLError<string>, CreateShortcodeMutation>
|
||||||
|
|
||||||
|
// Mock server operations
|
||||||
|
createMockServer: (
|
||||||
|
name: string,
|
||||||
|
workspaceType?: WorkspaceType,
|
||||||
|
workspaceID?: string,
|
||||||
|
delayInMs?: number,
|
||||||
|
isPublic?: boolean,
|
||||||
|
collectionID?: string,
|
||||||
|
autoCreateCollection?: boolean,
|
||||||
|
autoCreateRequestExample?: boolean
|
||||||
|
) => TE.TaskEither<string, MockServer>
|
||||||
|
|
||||||
|
updateMockServer: (
|
||||||
|
id: string,
|
||||||
|
input: {
|
||||||
|
name?: string
|
||||||
|
isActive?: boolean
|
||||||
|
delayInMs?: number
|
||||||
|
isPublic?: boolean
|
||||||
|
}
|
||||||
|
) => TE.TaskEither<string, MockServer>
|
||||||
|
|
||||||
|
deleteMockServer: (id: string) => TE.TaskEither<string, boolean>
|
||||||
|
|
||||||
|
getMockServer: (id: string) => TE.TaskEither<string, MockServer>
|
||||||
|
|
||||||
|
getMyMockServers: (
|
||||||
|
skip?: number,
|
||||||
|
take?: number
|
||||||
|
) => TE.TaskEither<string, MockServer[]>
|
||||||
|
|
||||||
|
getTeamMockServers: (
|
||||||
|
teamID: string,
|
||||||
|
skip?: number,
|
||||||
|
take?: number
|
||||||
|
) => TE.TaskEither<string, MockServer[]>
|
||||||
|
|
||||||
|
getMockServerLogs: (
|
||||||
|
mockServerID: string,
|
||||||
|
skip?: number,
|
||||||
|
take?: number
|
||||||
|
) => TE.TaskEither<string, GetMockServerLogsQuery["mockServerLogs"]>
|
||||||
|
|
||||||
|
deleteMockServerLog: (logID: string) => TE.TaskEither<string, boolean>
|
||||||
|
|
||||||
|
// Published docs operations
|
||||||
|
createPublishedDoc: (
|
||||||
|
doc: CreatePublishedDocsArgs
|
||||||
|
) => TE.TaskEither<GQLError<string>, CreatePublishedDocMutation>
|
||||||
|
|
||||||
|
updatePublishedDoc: (
|
||||||
|
id: string,
|
||||||
|
doc: UpdatePublishedDocsArgs
|
||||||
|
) => TE.TaskEither<GQLError<string>, UpdatePublishedDocMutation>
|
||||||
|
|
||||||
|
deletePublishedDoc: (
|
||||||
|
id: string
|
||||||
|
) => TE.TaskEither<GQLError<string>, DeletePublishedDocMutation>
|
||||||
|
|
||||||
|
getPublishedDocByID: (
|
||||||
|
id: string
|
||||||
|
) => TE.TaskEither<string, PublishedDocQuery["publishedDoc"]>
|
||||||
|
|
||||||
|
getUserPublishedDocs: (
|
||||||
|
skip?: number,
|
||||||
|
take?: number
|
||||||
|
) => TE.TaskEither<
|
||||||
|
string,
|
||||||
|
UserPublishedDocsListQuery["userPublishedDocsList"]
|
||||||
|
>
|
||||||
|
|
||||||
|
getTeamPublishedDocs: (
|
||||||
|
teamID: string,
|
||||||
|
collectionID?: string,
|
||||||
|
skip?: number,
|
||||||
|
take?: number
|
||||||
|
) => TE.TaskEither<
|
||||||
|
string,
|
||||||
|
TeamPublishedDocsListQuery["teamPublishedDocsList"]
|
||||||
|
>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,31 @@ import {
|
||||||
TeamAccessRole,
|
TeamAccessRole,
|
||||||
} from "../../helpers/backend/graphql"
|
} from "../../helpers/backend/graphql"
|
||||||
|
|
||||||
|
import {
|
||||||
|
createMockServer,
|
||||||
|
updateMockServer,
|
||||||
|
deleteMockServer,
|
||||||
|
} from "../../helpers/backend/mutations/MockServer"
|
||||||
|
import {
|
||||||
|
getMockServer,
|
||||||
|
getMyMockServers,
|
||||||
|
getTeamMockServers,
|
||||||
|
} from "../../helpers/backend/queries/MockServer"
|
||||||
|
import {
|
||||||
|
getMockServerLogs,
|
||||||
|
deleteMockServerLog,
|
||||||
|
} from "../../helpers/backend/queries/MockServerLogs"
|
||||||
|
import {
|
||||||
|
createPublishedDoc,
|
||||||
|
updatePublishedDoc,
|
||||||
|
deletePublishedDoc,
|
||||||
|
} from "../../helpers/backend/mutations/PublishedDocs"
|
||||||
|
import {
|
||||||
|
getPublishedDocByID,
|
||||||
|
getUserPublishedDocs,
|
||||||
|
getTeamPublishedDocs,
|
||||||
|
} from "../../helpers/backend/queries/PublishedDocs"
|
||||||
|
|
||||||
const getInviteDetails = <GetInviteDetailsError extends string>(
|
const getInviteDetails = <GetInviteDetailsError extends string>(
|
||||||
inviteID: string
|
inviteID: string
|
||||||
) => {
|
) => {
|
||||||
|
|
@ -129,4 +154,18 @@ export const def: BackendPlatformDef = {
|
||||||
createTeamInvitation,
|
createTeamInvitation,
|
||||||
acceptTeamInvitation,
|
acceptTeamInvitation,
|
||||||
createShortcode,
|
createShortcode,
|
||||||
|
createMockServer,
|
||||||
|
updateMockServer,
|
||||||
|
deleteMockServer,
|
||||||
|
getMockServer,
|
||||||
|
getMyMockServers,
|
||||||
|
getTeamMockServers,
|
||||||
|
getMockServerLogs,
|
||||||
|
deleteMockServerLog,
|
||||||
|
createPublishedDoc,
|
||||||
|
updatePublishedDoc,
|
||||||
|
deletePublishedDoc,
|
||||||
|
getPublishedDocByID,
|
||||||
|
getUserPublishedDocs,
|
||||||
|
getTeamPublishedDocs,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,15 @@ import {
|
||||||
isLiveVersion,
|
isLiveVersion,
|
||||||
CURRENT_VERSION_TAG,
|
CURRENT_VERSION_TAG,
|
||||||
} from "../documentation.service"
|
} from "../documentation.service"
|
||||||
import {
|
import { platform } from "~/platform"
|
||||||
getUserPublishedDocs,
|
|
||||||
getTeamPublishedDocs,
|
|
||||||
} from "~/helpers/backend/queries/PublishedDocs"
|
|
||||||
|
|
||||||
vi.mock("~/helpers/backend/queries/PublishedDocs", () => ({
|
vi.mock("~/platform", () => ({
|
||||||
getUserPublishedDocs: vi.fn(),
|
platform: {
|
||||||
getTeamPublishedDocs: vi.fn(),
|
backend: {
|
||||||
|
getUserPublishedDocs: vi.fn(),
|
||||||
|
getTeamPublishedDocs: vi.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe("DocumentationService", () => {
|
describe("DocumentationService", () => {
|
||||||
|
|
@ -88,6 +89,7 @@ describe("DocumentationService", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
vi.resetAllMocks()
|
||||||
container = new TestContainer()
|
container = new TestContainer()
|
||||||
service = container.bind(DocumentationService)
|
service = container.bind(DocumentationService)
|
||||||
})
|
})
|
||||||
|
|
@ -479,7 +481,7 @@ describe("DocumentationService", () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
vi.mocked(getUserPublishedDocs).mockReturnValue(() =>
|
vi.mocked(platform.backend.getUserPublishedDocs).mockReturnValue(() =>
|
||||||
Promise.resolve(E.right(mockDocs as any))
|
Promise.resolve(E.right(mockDocs as any))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -514,7 +516,7 @@ describe("DocumentationService", () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
vi.mocked(getTeamPublishedDocs).mockReturnValue(() =>
|
vi.mocked(platform.backend.getTeamPublishedDocs).mockReturnValue(() =>
|
||||||
Promise.resolve(E.right(mockDocs as any))
|
Promise.resolve(E.right(mockDocs as any))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -538,7 +540,7 @@ describe("DocumentationService", () => {
|
||||||
|
|
||||||
it("should handle error when fetching user published docs", async () => {
|
it("should handle error when fetching user published docs", async () => {
|
||||||
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {})
|
||||||
vi.mocked(getUserPublishedDocs).mockReturnValue(() =>
|
vi.mocked(platform.backend.getUserPublishedDocs).mockReturnValue(() =>
|
||||||
Promise.resolve(E.left("user/not_authenticated"))
|
Promise.resolve(E.left("user/not_authenticated"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -553,7 +555,7 @@ describe("DocumentationService", () => {
|
||||||
|
|
||||||
it("should handle error when fetching team published docs", async () => {
|
it("should handle error when fetching team published docs", async () => {
|
||||||
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {})
|
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {})
|
||||||
vi.mocked(getTeamPublishedDocs).mockReturnValue(() =>
|
vi.mocked(platform.backend.getTeamPublishedDocs).mockReturnValue(() =>
|
||||||
Promise.resolve(E.left("team/not_required" as any))
|
Promise.resolve(E.left("team/not_required" as any))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -635,7 +637,7 @@ describe("DocumentationService", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mock the first call to be slow
|
// Mock the first call to be slow
|
||||||
vi.mocked(getUserPublishedDocs)
|
vi.mocked(platform.backend.getUserPublishedDocs)
|
||||||
.mockReturnValueOnce(() => slowPromise as any)
|
.mockReturnValueOnce(() => slowPromise as any)
|
||||||
.mockReturnValueOnce(() => Promise.resolve(E.right(fastDocs as any)))
|
.mockReturnValueOnce(() => Promise.resolve(E.right(fastDocs as any)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
import { Service } from "dioc"
|
import { Service } from "dioc"
|
||||||
import { reactive, computed, ref } from "vue"
|
import { reactive, computed, ref } from "vue"
|
||||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import {
|
|
||||||
getUserPublishedDocs,
|
|
||||||
getTeamPublishedDocs,
|
|
||||||
} from "~/helpers/backend/queries/PublishedDocs"
|
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
// Types for documentation
|
// Types for documentation
|
||||||
export type DocumentationType = "collection" | "request"
|
export type DocumentationType = "collection" | "request"
|
||||||
|
|
@ -284,7 +281,7 @@ export class DocumentationService extends Service {
|
||||||
const requestId = ++this.fetchRequestId
|
const requestId = ++this.fetchRequestId
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await getUserPublishedDocs()()
|
const result = await platform.backend.getUserPublishedDocs()()
|
||||||
|
|
||||||
// If a newer request has started, ignore this result
|
// If a newer request has started, ignore this result
|
||||||
if (requestId !== this.fetchRequestId) return
|
if (requestId !== this.fetchRequestId) return
|
||||||
|
|
@ -330,7 +327,7 @@ export class DocumentationService extends Service {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch all published docs for the team (collectionID is optional now)
|
// Fetch all published docs for the team (collectionID is optional now)
|
||||||
const result = await getTeamPublishedDocs(teamID)()
|
const result = await platform.backend.getTeamPublishedDocs(teamID)()
|
||||||
|
|
||||||
// If a newer request has started, ignore this result
|
// If a newer request has started, ignore this result
|
||||||
if (requestId !== this.fetchRequestId) return
|
if (requestId !== this.fetchRequestId) return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue