Compare commits

..

1 Commits

Author SHA1 Message Date
nivedin
d28bc580c6 fix: gql history schema error 2023-12-19 16:36:04 +05:30
14 changed files with 113 additions and 223 deletions

View File

@@ -676,16 +676,9 @@ export const INFRA_CONFIG_RESET_FAILED = 'infra_config/reset_failed' as const;
*/
export const INFRA_CONFIG_INVALID_INPUT = 'infra_config/invalid_input' as const;
/**
* Infra Config service (auth provider/mailer/audit logs) not configured
* (InfraConfigService)
*/
export const INFRA_CONFIG_SERVICE_NOT_CONFIGURED =
'infra_config/service_not_configured' as const;
/**
* Error message for when the database table does not exist
* (InfraConfigService)
*/
export const DATABASE_TABLE_NOT_EXIST =
'Database migration not found. Please check the documentation for assistance: https://docs.hoppscotch.io/documentation/self-host/community-edition/install-and-build#running-migrations';
'Database migration not performed. Please check the FAQ for assistance: https://docs.hoppscotch.io/support/getting-started/faq';

View File

@@ -15,13 +15,11 @@ import {
INFRA_CONFIG_NOT_LISTED,
INFRA_CONFIG_RESET_FAILED,
INFRA_CONFIG_UPDATE_FAILED,
INFRA_CONFIG_SERVICE_NOT_CONFIGURED,
} from 'src/errors';
import { throwErr, validateEmail, validateSMTPUrl } from 'src/utils';
import { ConfigService } from '@nestjs/config';
import { ServiceStatus, stopApp } from './helper';
import { EnableAndDisableSSOArgs, InfraConfigArgs } from './input-args';
import { AuthProvider } from 'src/auth/helper';
@Injectable()
export class InfraConfigService implements OnModuleInit {
@@ -126,7 +124,7 @@ export class InfraConfigService implements OnModuleInit {
cast(dbInfraConfig: DBInfraConfig) {
return <InfraConfig>{
name: dbInfraConfig.name,
value: dbInfraConfig.value ?? '',
value: dbInfraConfig.value,
};
}
@@ -184,38 +182,6 @@ export class InfraConfigService implements OnModuleInit {
}
}
/**
* Check if the service is configured or not
* @param service Service can be Auth Provider, Mailer, Audit Log etc.
* @returns Either true or false
*/
isServiceConfigured(service: AuthProvider) {
switch (service) {
case AuthProvider.GOOGLE:
return (
this.configService.get<string>('INFRA.GOOGLE_CLIENT_ID') &&
this.configService.get<string>('INFRA.GOOGLE_CLIENT_SECRET')
);
case AuthProvider.GITHUB:
return (
this.configService.get<string>('INFRA.GITHUB_CLIENT_ID') &&
!this.configService.get<string>('INFRA.GITHUB_CLIENT_SECRET')
);
case AuthProvider.MICROSOFT:
return (
this.configService.get<string>('INFRA.MICROSOFT_CLIENT_ID') &&
!this.configService.get<string>('INFRA.MICROSOFT_CLIENT_SECRET')
);
case AuthProvider.EMAIL:
return (
this.configService.get<string>('INFRA.MAILER_SMTP_URL') &&
this.configService.get<string>('INFRA.MAILER_ADDRESS_FROM')
);
default:
return false;
}
}
/**
* Enable or Disable SSO for login/signup
* @param provider Auth Provider to enable or disable
@@ -229,21 +195,15 @@ export class InfraConfigService implements OnModuleInit {
let updatedAuthProviders = allowedAuthProviders;
for (let i = 0; i < providerInfo.length; i++) {
const { provider, status } = providerInfo[i];
providerInfo.forEach(({ provider, status }) => {
if (status === ServiceStatus.ENABLE) {
const isConfigured = this.isServiceConfigured(provider);
if (!isConfigured) {
throwErr(INFRA_CONFIG_SERVICE_NOT_CONFIGURED);
}
updatedAuthProviders.push(provider);
} else if (status === ServiceStatus.DISABLE) {
updatedAuthProviders = updatedAuthProviders.filter(
(p) => p !== provider,
);
}
}
});
updatedAuthProviders = [...new Set(updatedAuthProviders)];
@@ -326,9 +286,6 @@ export class InfraConfigService implements OnModuleInit {
}
}
/**
* Validate the values of the InfraConfigs
*/
validateEnvValues(
infraConfigs: {
name: InfraConfigEnumForClient | InfraConfigEnum;
@@ -345,24 +302,6 @@ export class InfraConfigService implements OnModuleInit {
const isValidEmail = validateEmail(infraConfigs[i].value);
if (!isValidEmail) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.GOOGLE_CLIENT_ID:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.GOOGLE_CLIENT_SECRET:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.GITHUB_CLIENT_ID:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.GITHUB_CLIENT_SECRET:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.MICROSOFT_CLIENT_ID:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
case InfraConfigEnumForClient.MICROSOFT_CLIENT_SECRET:
if (!infraConfigs[i].value) return E.left(INFRA_CONFIG_INVALID_INPUT);
break;
default:
break;
}

View File

@@ -121,7 +121,7 @@
"generate_token": "Generate Token",
"graphql_headers": "Authorization Headers are sent as part of the payload to connection_init",
"include_in_url": "Include in URL",
"inherited_from": "Inherited {auth} from parent collection {collection} ",
"inherited_from": "Inherited from {auth} from Parent Collection {collection} ",
"learn": "Learn how",
"oauth": {
"redirect_auth_server_returned_error": "Auth Server returned an error state",
@@ -295,7 +295,6 @@
"incorrect_email": "Incorrect email",
"invalid_link": "Invalid link",
"invalid_link_description": "The link you clicked is invalid or expired.",
"invalid_embed_link": "The embed does not exist or is invalid.",
"json_parsing_failed": "Invalid JSON",
"json_prettify_invalid_body": "Couldn't prettify an invalid body, solve json syntax errors and try again",
"network_error": "There seems to be a network error. Please try again.",
@@ -314,12 +313,10 @@
"export": {
"as_json": "Export as JSON",
"create_secret_gist": "Create secret Gist",
"create_secret_gist_tooltip_text": "Export as secret Gist",
"failed": "Something went wrong while exporting",
"secret_gist_success": "Successfully exported as secret Gist",
"gist_created": "Gist created",
"require_github": "Login with GitHub to create secret gist",
"title": "Export",
"success": "Successfully exported"
"title": "Export"
},
"filter": {
"all": "All",

View File

@@ -9,10 +9,7 @@
</template>
<script setup lang="ts">
import { HoppCollection } from "@hoppscotch/data"
import * as E from "fp-ts/Either"
import { PropType, computed, ref } from "vue"
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
import { UrlSource } from "~/helpers/import-export/import/import-sources/UrlSource"
@@ -27,9 +24,11 @@ import {
} from "~/helpers/import-export/import/importers"
import { defineStep } from "~/composables/step-components"
import { PropType, computed, ref } from "vue"
import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast"
import { HoppCollection } from "@hoppscotch/data"
import { appendRESTCollections, restCollections$ } from "~/newstore/collections"
import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue"
import { GetMyTeamsQuery } from "~/helpers/backend/graphql"
@@ -49,7 +48,7 @@ import { getTeamCollectionJSON } from "~/helpers/backend/helpers"
import { platform } from "~/platform"
import { initializeDownloadCollection } from "~/helpers/import-export/export"
import { gistExporter } from "~/helpers/import-export/export/gist"
import { collectionsGistExporter } from "~/helpers/import-export/export/gistExport"
import { myCollectionsExporter } from "~/helpers/import-export/export/myCollections"
import { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections"
@@ -84,8 +83,6 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser()
)
const myCollections = useReadonlyStream(restCollections$, [])
const showImportFailedError = () => {
toast.error(t("import.failed"))
}
@@ -471,13 +468,8 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
icon: IconGithub,
disabled: !currentUser.value
? true
: currentUser.value?.provider !== "github.com",
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
: currentUser.value.provider !== "github.com",
title: t("export.create_secret_gist"),
applicableTo: ["personal-workspace", "team-workspace"],
isLoading: isHoppGistCollectionExporterInProgress,
},
@@ -494,27 +486,13 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
}
if (E.isRight(collectionJSON)) {
if (!JSON.parse(collectionJSON.right).length) {
isHoppGistCollectionExporterInProgress.value = false
return toast.error(t("error.no_collections_to_export"))
}
const res = await gistExporter(collectionJSON.right, accessToken)
if (E.isLeft(res)) {
toast.error(t("export.failed"))
return
}
toast.success(t("export.secret_gist_success"))
collectionsGistExporter(collectionJSON.right, accessToken)
platform.analytics?.logEvent({
type: "HOPP_EXPORT_COLLECTION",
exporter: "gist",
platform: "rest",
})
platform.io.openExternalLink(res.right)
}
isHoppGistCollectionExporterInProgress.value = false
@@ -582,6 +560,8 @@ const selectedTeamID = computed(() => {
: undefined
})
const myCollections = useReadonlyStream(restCollections$, [])
const getCollectionJSON = async () => {
if (
props.collectionsType.type === "team-collections" &&

View File

@@ -9,16 +9,15 @@
</template>
<script setup lang="ts">
import { HoppCollection } from "@hoppscotch/data"
import * as E from "fp-ts/Either"
import { ref } from "vue"
import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast"
import { HoppCollection } from "@hoppscotch/data"
import { ImporterOrExporter } from "~/components/importExport/types"
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource"
import * as E from "fp-ts/Either"
import IconFolderPlus from "~icons/lucide/folder-plus"
import IconUser from "~icons/lucide/user"
import { initializeDownloadCollection } from "~/helpers/import-export/export"
@@ -31,7 +30,7 @@ import {
} from "~/newstore/collections"
import { hoppGqlCollectionsImporter } from "~/helpers/import-export/import/hoppGql"
import { gqlCollectionsExporter } from "~/helpers/import-export/export/gqlCollections"
import { gistExporter } from "~/helpers/import-export/export/gist"
import { gqlCollectionsGistExporter } from "~/helpers/import-export/export/gqlCollectionsGistExporter"
import { computed } from "vue"
import { hoppGQLImporter } from "~/helpers/import-export/import/hopp"
@@ -43,10 +42,6 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser()
)
const gqlCollections = useReadonlyStream(graphqlCollections$, [])
const isGqlCollectionGistExportInProgress = ref(false)
const GqlCollectionsHoppImporter: ImporterOrExporter = {
metadata: {
id: "import.from_json",
@@ -124,6 +119,8 @@ const GqlCollectionsGistImporter: ImporterOrExporter = {
}),
}
const gqlCollections = useReadonlyStream(graphqlCollections$, [])
const GqlCollectionsHoppExporter: ImporterOrExporter = {
metadata: {
id: "export.as_json",
@@ -162,35 +159,29 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
metadata: {
id: "export.as_gist",
name: "export.create_secret_gist",
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
title: !currentUser
? "export.require_github"
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser.provider !== "github.com"
? `export.require_github`
: "export.create_secret_gist",
icon: IconUser,
disabled: !currentUser.value
? true
: currentUser.value?.provider !== "github.com",
: currentUser.value.provider !== "github.com",
applicableTo: ["personal-workspace"],
isLoading: isGqlCollectionGistExportInProgress,
},
action: async () => {
if (!gqlCollections.value.length) {
return toast.error(t("error.no_collections_to_export"))
}
if (!currentUser.value) {
toast.error(t("profile.no_permission"))
return
}
isGqlCollectionGistExportInProgress.value = true
const accessToken = currentUser.value?.accessToken
if (accessToken) {
const res = await gistExporter(
const res = await gqlCollectionsGistExporter(
JSON.stringify(gqlCollections.value),
accessToken
)
@@ -200,7 +191,7 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
return
}
toast.success(t("export.secret_gist_success"))
toast.success(t("export.success"))
platform.analytics?.logEvent({
type: "HOPP_EXPORT_COLLECTION",
@@ -210,8 +201,6 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
platform.io.openExternalLink(res.right)
}
isGqlCollectionGistExportInProgress.value = false
},
}

View File

@@ -9,17 +9,15 @@
</template>
<script setup lang="ts">
import { Environment } from "@hoppscotch/data"
import * as E from "fp-ts/Either"
import { ref } from "vue"
import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast"
import { Environment } from "@hoppscotch/data"
import { ImporterOrExporter } from "~/components/importExport/types"
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource"
import { hoppEnvImporter } from "~/helpers/import-export/import/hoppEnv"
import * as E from "fp-ts/Either"
import {
appendEnvironments,
addGlobalEnvVariable,
@@ -41,7 +39,7 @@ import { initializeDownloadCollection } from "~/helpers/import-export/export"
import { computed } from "vue"
import { useReadonlyStream } from "~/composables/stream"
import { environmentsExporter } from "~/helpers/import-export/export/environments"
import { gistExporter } from "~/helpers/import-export/export/gist"
import { environmentsGistExporter } from "~/helpers/import-export/export/environmentsGistExport"
import { platform } from "~/platform"
const t = useI18n()
@@ -60,8 +58,6 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser()
)
const isEnvironmentGistExportInProgress = ref(false)
const isTeamEnvironment = computed(() => {
return props.environmentType === "TEAM_ENV"
})
@@ -266,44 +262,35 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
currentUser?.provider === "github.com"
? "export.create_secret_gist"
: "export.require_github",
icon: IconUser,
disabled: !currentUser.value
? true
: currentUser.value?.provider !== "github.com",
: currentUser.value.provider !== "github.com",
applicableTo: ["personal-workspace", "team-workspace"],
isLoading: isEnvironmentGistExportInProgress,
},
action: async () => {
if (!environmentJson.value.length) {
return toast.error(t("error.no_environments_to_export"))
}
if (!currentUser.value) {
toast.error(t("profile.no_permission"))
return
}
isEnvironmentGistExportInProgress.value = true
const accessToken = currentUser.value?.accessToken
if (accessToken) {
const res = await gistExporter(
const res = await environmentsGistExporter(
JSON.stringify(environmentJson.value),
accessToken,
"hoppscotch-environment.json"
accessToken
)
if (E.isLeft(res)) {
toast.error(t("export.failed"))
isEnvironmentGistExportInProgress.value = false
return
}
toast.success(t("export.secret_gist_success"))
toast.success(t("export.success"))
platform.analytics?.logEvent({
type: "HOPP_EXPORT_ENVIRONMENT",
@@ -312,8 +299,6 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
platform.io.openExternalLink(res.right)
}
isEnvironmentGistExportInProgress.value = false
},
}

View File

@@ -0,0 +1,18 @@
import * as E from "fp-ts/Either"
import { createGist } from "~/helpers/gist"
export const environmentsGistExporter = async (
environmentsJSON: string,
accessToken: string
) => {
const res = await createGist(
environmentsJSON,
"hoppscotch-collections.json",
accessToken
)()
if (E.isLeft(res)) {
return E.left(res.left)
}
return E.right(res.right.data.html_url as string)
}

View File

@@ -1,19 +0,0 @@
import * as E from "fp-ts/Either"
import { createGist } from "~/helpers/gist"
export const gistExporter = async (
JSONFileContents: string,
accessToken: string,
fileName = "hoppscotch-collections.json"
) => {
if (!accessToken) {
return E.left("Invalid User")
}
const res = await createGist(JSONFileContents, fileName, accessToken)()
if (E.isLeft(res)) {
return E.left(res.left)
}
return E.right(res.right.data.html_url as string)
}

View File

@@ -0,0 +1,22 @@
import { createGist } from "~/helpers/gist"
import * as E from "fp-ts/Either"
export const collectionsGistExporter = async (
collectionJSON: string,
accessToken: string
) => {
if (!accessToken) {
return E.left("Invalid User")
}
const res = await createGist(
collectionJSON,
"hoppscotch-collections.json",
accessToken
)()
if (E.isLeft(res)) {
return E.left(res.left)
}
return E.right(true)
}

View File

@@ -0,0 +1,18 @@
import * as E from "fp-ts/Either"
import { createGist } from "~/helpers/gist"
export const gqlCollectionsGistExporter = async (
gqlCollectionsJSON: string,
accessToken: string
) => {
const res = await createGist(
gqlCollectionsJSON,
"hoppscotch-collections.json",
accessToken
)()
if (E.isLeft(res)) {
return E.left(res.left)
}
return E.right(res.right.data.html_url as string)
}

View File

@@ -4,7 +4,6 @@ import {
HoppRESTRequest,
HoppCollection,
makeCollection,
HoppGQLAuth,
} from "@hoppscotch/data"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
import { cloneDeep } from "lodash-es"
@@ -12,9 +11,6 @@ import { resolveSaveContextOnRequestReorder } from "~/helpers/collection/request
import { getService } from "~/modules/dioc"
import { RESTTabService } from "~/services/tab/rest"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { HoppRESTAuth } from "@hoppscotch/data"
import { HoppRESTHeaders } from "@hoppscotch/data"
import { HoppGQLHeader } from "~/helpers/graphql"
const defaultRESTCollectionState = {
state: [
@@ -67,12 +63,6 @@ export function navigateToFolderWithIndexPath(
return target !== undefined ? target : null
}
/**
* Used to obtain the inherited auth and headers for a given folder path, used for both REST and GraphQL
* @param folderPath the path of the folder to cascade the auth from
* @param type the type of collection
* @returns the inherited auth and headers for the given folder path
*/
export function cascadeParentCollectionForHeaderAuth(
folderPath: string | undefined,
type: "rest" | "graphql"
@@ -113,16 +103,10 @@ export function cascadeParentCollectionForHeaderAuth(
return { auth, headers }
}
const parentFolderAuth = parentFolder.auth as HoppRESTAuth | HoppGQLAuth
const parentFolderHeaders = parentFolder.headers as
| HoppRESTHeaders
| HoppGQLHeader[]
const parentFolderAuth = parentFolder.auth
const parentFolderHeaders = parentFolder.headers
// 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
) {
if (parentFolderAuth?.authType === "inherit" && path.length === 1) {
auth = {
parentID: [...path.slice(0, i + 1)].join("/"),
parentName: parentFolder.name,

View File

@@ -1,19 +1,7 @@
<template>
<div class="flex flex-col justify-center">
<div
v-if="invalidLink"
class="flex flex-1 flex-col items-center justify-center p-8"
>
<icon-lucide-alert-triangle class="svg-icons mb-2 opacity-75" />
<h1 class="heading text-center">
{{ t("error.invalid_link") }}
</h1>
<p class="mt-2 text-center">
{{ t("error.invalid_embed_link") }}
</p>
</div>
<div class="flex flex-col flex-1 w-full">
<Embeds
v-else-if="!invalidLink && tab"
v-if="tab"
v-model:modelTab="tab"
:properties="properties"
:shared-request-i-d="sharedRequestID"
@@ -40,9 +28,6 @@ import {
import { HoppTab } from "~/services/tab"
import { HoppRESTDocument } from "~/helpers/rest/document"
import { applySetting } from "~/newstore/settings"
import { useI18n } from "~/composables/i18n"
const t = useI18n()
const route = useRoute()

View File

@@ -244,13 +244,9 @@ export class PersistenceService extends Service {
private setupSettingsPersistence() {
const settingsKey = "settings"
let settingsData = JSON.parse(
window.localStorage.getItem(settingsKey) ?? "null"
window.localStorage.getItem(settingsKey) || "{}"
)
if (!settingsData) {
settingsData = getDefaultSettings()
}
// Validate data read from localStorage
const result = SETTINGS_SCHEMA.safeParse(settingsData)
if (result.success) {

View File

@@ -36,7 +36,7 @@ const SettingsDefSchema = z.object({
httpUser: z.boolean(),
httpPassword: z.boolean(),
bearerToken: z.boolean(),
oauth2Token: z.optional(z.boolean()),
oauth2Token: z.boolean(),
}),
THEME_COLOR: ThemeColorSchema,
BG_COLOR: BgColorSchema,
@@ -103,10 +103,13 @@ export const LOCAL_STATE_SCHEMA = z.union([
.strict(),
])
export const SETTINGS_SCHEMA = SettingsDefSchema.extend({
EXTENSIONS_ENABLED: z.optional(z.boolean()),
PROXY_ENABLED: z.optional(z.boolean()),
})
export const SETTINGS_SCHEMA = z.union([
z.object({}).strict(),
SettingsDefSchema.extend({
EXTENSIONS_ENABLED: z.optional(z.boolean()),
PROXY_ENABLED: z.optional(z.boolean()),
}),
])
export const REST_HISTORY_ENTRY_SCHEMA = z
.object({
@@ -205,7 +208,7 @@ export const MQTT_REQUEST_SCHEMA = z.nullable(
z
.object({
endpoint: z.string(),
clientID: z.optional(z.string()),
clientID: z.string(),
})
.strict()
)