feat: collection level headers and authorization (#3505)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
Environment,
|
||||
HoppCollection,
|
||||
HoppGQLRequest,
|
||||
HoppRESTRequest,
|
||||
} from "@hoppscotch/data"
|
||||
import { Environment, HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
import { HoppGQLDocument } from "~/helpers/graphql/document"
|
||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
||||
@@ -14,15 +9,15 @@ import { PersistableTabState } from "~/services/tab"
|
||||
type VUEX_DATA = {
|
||||
postwoman: {
|
||||
settings?: SettingsDef
|
||||
collections?: HoppCollection<HoppRESTRequest>[]
|
||||
collectionsGraphql?: HoppCollection<HoppGQLRequest>[]
|
||||
collections?: HoppCollection[]
|
||||
collectionsGraphql?: HoppCollection[]
|
||||
environments?: Environment[]
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS = getDefaultSettings()
|
||||
|
||||
export const REST_COLLECTIONS_MOCK: HoppCollection<HoppRESTRequest>[] = [
|
||||
export const REST_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
{
|
||||
v: 1,
|
||||
name: "Echo",
|
||||
@@ -44,7 +39,7 @@ export const REST_COLLECTIONS_MOCK: HoppCollection<HoppRESTRequest>[] = [
|
||||
},
|
||||
]
|
||||
|
||||
export const GQL_COLLECTIONS_MOCK: HoppCollection<HoppGQLRequest>[] = [
|
||||
export const GQL_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
{
|
||||
v: 1,
|
||||
name: "Echo",
|
||||
|
||||
@@ -3,7 +3,9 @@ import {
|
||||
GQLHeader,
|
||||
HoppGQLAuth,
|
||||
HoppGQLRequest,
|
||||
HoppRESTAuth,
|
||||
HoppRESTRequest,
|
||||
HoppRESTHeaders,
|
||||
} from "@hoppscotch/data"
|
||||
import { entityReference } from "verzod"
|
||||
import { z } from "zod"
|
||||
@@ -62,12 +64,18 @@ const HoppGQLRequestSchema = entityReference(HoppGQLRequest)
|
||||
const HoppRESTCollectionSchema = HoppCollectionSchemaCommonProps.extend({
|
||||
folders: z.array(z.lazy(() => HoppRESTCollectionSchema)),
|
||||
requests: z.optional(z.array(HoppRESTRequestSchema)),
|
||||
|
||||
auth: z.optional(HoppRESTAuth),
|
||||
headers: z.optional(HoppRESTHeaders),
|
||||
}).strict()
|
||||
|
||||
// @ts-expect-error recursive schema
|
||||
const HoppGQLCollectionSchema = HoppCollectionSchemaCommonProps.extend({
|
||||
folders: z.array(z.lazy(() => HoppGQLCollectionSchema)),
|
||||
requests: z.optional(z.array(HoppGQLRequestSchema)),
|
||||
|
||||
auth: z.optional(HoppGQLAuth),
|
||||
headers: z.optional(z.array(GQLHeader)),
|
||||
}).strict()
|
||||
|
||||
export const VUEX_SCHEMA = z.object({
|
||||
@@ -276,6 +284,23 @@ const validGqlOperations = [
|
||||
"authorization",
|
||||
] as const
|
||||
|
||||
const HoppInheritedPropertySchema = z
|
||||
.object({
|
||||
auth: z.object({
|
||||
parentID: z.string(),
|
||||
parentName: z.string(),
|
||||
inheritedAuth: z.union([HoppRESTAuth, HoppGQLAuth]),
|
||||
}),
|
||||
headers: z.array(
|
||||
z.object({
|
||||
parentID: z.string(),
|
||||
parentName: z.string(),
|
||||
inheritedHeader: z.union([HoppRESTHeaders, GQLHeader]),
|
||||
})
|
||||
),
|
||||
})
|
||||
.strict()
|
||||
|
||||
export const GQL_TAB_STATE_SCHEMA = z
|
||||
.object({
|
||||
lastActiveTabID: z.string(),
|
||||
@@ -291,6 +316,7 @@ export const GQL_TAB_STATE_SCHEMA = z
|
||||
response: z.optional(z.nullable(GQLResponseEventSchema)),
|
||||
responseTabPreference: z.optional(z.string()),
|
||||
optionTabPreference: z.optional(z.enum(validGqlOperations)),
|
||||
inheritedProperties: z.optional(HoppInheritedPropertySchema),
|
||||
})
|
||||
.strict(),
|
||||
})
|
||||
@@ -462,6 +488,7 @@ export const REST_TAB_STATE_SCHEMA = z
|
||||
testResults: z.optional(z.nullable(HoppTestResultSchema)),
|
||||
responseTabPreference: z.optional(z.string()),
|
||||
optionTabPreference: z.optional(z.enum(validRestOperations)),
|
||||
inheritedProperties: z.optional(HoppInheritedPropertySchema),
|
||||
})
|
||||
.strict(),
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Ref, computed, effectScope, markRaw, ref, watch } from "vue"
|
||||
import { getI18n } from "~/modules/i18n"
|
||||
import MiniSearch from "minisearch"
|
||||
import {
|
||||
cascadeParentCollectionForHeaderAuth,
|
||||
graphqlCollectionStore,
|
||||
restCollectionStore,
|
||||
} from "~/newstore/collections"
|
||||
@@ -229,7 +230,7 @@ export class CollectionsSpotlightSearcherService
|
||||
|
||||
private getRESTFolderFromFolderPath(
|
||||
folderPath: string
|
||||
): HoppCollection<HoppRESTRequest> | undefined {
|
||||
): HoppCollection | undefined {
|
||||
try {
|
||||
const folderIndicies = folderPath.split("/").map((x) => parseInt(x))
|
||||
|
||||
@@ -253,7 +254,7 @@ export class CollectionsSpotlightSearcherService
|
||||
|
||||
private getGQLFolderFromFolderPath(
|
||||
folderPath: string
|
||||
): HoppCollection<HoppGQLRequest> | undefined {
|
||||
): HoppCollection | undefined {
|
||||
try {
|
||||
const folderIndicies = folderPath.split("/").map((x) => parseInt(x))
|
||||
|
||||
@@ -300,10 +301,15 @@ export class CollectionsSpotlightSearcherService
|
||||
this.restTab.setActiveTab(possibleTab.value.id)
|
||||
} else {
|
||||
const req = this.getRESTFolderFromFolderPath(folderPath.join("/"))
|
||||
?.requests[reqIndex]
|
||||
?.requests[reqIndex] as HoppRESTRequest
|
||||
|
||||
if (!req) return
|
||||
|
||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||
folderPath.join("/"),
|
||||
"rest"
|
||||
)
|
||||
|
||||
this.restTab.createNewTab(
|
||||
{
|
||||
request: req,
|
||||
@@ -313,6 +319,10 @@ export class CollectionsSpotlightSearcherService
|
||||
folderPath: folderPath.join("/"),
|
||||
requestIndex: reqIndex,
|
||||
},
|
||||
inheritedProperties: {
|
||||
auth,
|
||||
headers,
|
||||
},
|
||||
},
|
||||
true
|
||||
)
|
||||
@@ -322,10 +332,14 @@ export class CollectionsSpotlightSearcherService
|
||||
const reqIndex = folderPath.pop()!
|
||||
|
||||
const req = this.getGQLFolderFromFolderPath(folderPath.join("/"))
|
||||
?.requests[reqIndex]
|
||||
?.requests[reqIndex] as HoppGQLRequest
|
||||
|
||||
if (!req) return
|
||||
|
||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||
folderPath.join("/"),
|
||||
"graphql"
|
||||
)
|
||||
this.gqlTab.createNewTab({
|
||||
saveContext: {
|
||||
originLocation: "user-collection",
|
||||
@@ -334,6 +348,10 @@ export class CollectionsSpotlightSearcherService
|
||||
},
|
||||
request: req,
|
||||
isDirty: false,
|
||||
inheritedProperties: {
|
||||
auth,
|
||||
headers,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user