mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 09:58:04 +08:00
refactor: init orpc contract (#30885)
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
This commit is contained in:
3
web/contract/base.ts
Normal file
3
web/contract/base.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { oc } from '@orpc/contract'
|
||||
|
||||
export const base = oc.$route({ inputStructure: 'detailed' })
|
||||
34
web/contract/console.ts
Normal file
34
web/contract/console.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import type { SystemFeatures } from '@/types/feature'
|
||||
import { type } from '@orpc/contract'
|
||||
import { base } from './base'
|
||||
|
||||
export const systemFeaturesContract = base
|
||||
.route({
|
||||
path: '/system-features',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<unknown>())
|
||||
.output(type<SystemFeatures>())
|
||||
|
||||
export const billingUrlContract = base
|
||||
.route({
|
||||
path: '/billing/invoices',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(type<unknown>())
|
||||
.output(type<{ url: string }>())
|
||||
|
||||
export const bindPartnerStackContract = base
|
||||
.route({
|
||||
path: '/billing/partners/{partnerKey}/tenants',
|
||||
method: 'PUT',
|
||||
})
|
||||
.input(type<{
|
||||
params: {
|
||||
partnerKey: string
|
||||
}
|
||||
body: {
|
||||
click_id: string
|
||||
}
|
||||
}>())
|
||||
.output(type<unknown>())
|
||||
56
web/contract/marketplace.ts
Normal file
56
web/contract/marketplace.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import type { CollectionsAndPluginsSearchParams, MarketplaceCollection, PluginsSearchParams } from '@/app/components/plugins/marketplace/types'
|
||||
import type { Plugin, PluginsFromMarketplaceResponse } from '@/app/components/plugins/types'
|
||||
import { type } from '@orpc/contract'
|
||||
import { base } from './base'
|
||||
|
||||
export const collectionsContract = base
|
||||
.route({
|
||||
path: '/collections',
|
||||
method: 'GET',
|
||||
})
|
||||
.input(
|
||||
type<{
|
||||
query?: CollectionsAndPluginsSearchParams & { page?: number, page_size?: number }
|
||||
}>(),
|
||||
)
|
||||
.output(
|
||||
type<{
|
||||
data?: {
|
||||
collections?: MarketplaceCollection[]
|
||||
}
|
||||
}>(),
|
||||
)
|
||||
|
||||
export const collectionPluginsContract = base
|
||||
.route({
|
||||
path: '/collections/{collectionId}/plugins',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(
|
||||
type<{
|
||||
params: {
|
||||
collectionId: string
|
||||
}
|
||||
body?: CollectionsAndPluginsSearchParams
|
||||
}>(),
|
||||
)
|
||||
.output(
|
||||
type<{
|
||||
data?: {
|
||||
plugins?: Plugin[]
|
||||
}
|
||||
}>(),
|
||||
)
|
||||
|
||||
export const searchAdvancedContract = base
|
||||
.route({
|
||||
path: '/{kind}/search/advanced',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
params: {
|
||||
kind: 'plugins' | 'bundles'
|
||||
}
|
||||
body: Omit<PluginsSearchParams, 'type'>
|
||||
}>())
|
||||
.output(type<{ data: PluginsFromMarketplaceResponse }>())
|
||||
19
web/contract/router.ts
Normal file
19
web/contract/router.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { InferContractRouterInputs } from '@orpc/contract'
|
||||
import { billingUrlContract, bindPartnerStackContract, systemFeaturesContract } from './console'
|
||||
import { collectionPluginsContract, collectionsContract, searchAdvancedContract } from './marketplace'
|
||||
|
||||
export const marketplaceRouterContract = {
|
||||
collections: collectionsContract,
|
||||
collectionPlugins: collectionPluginsContract,
|
||||
searchAdvanced: searchAdvancedContract,
|
||||
}
|
||||
|
||||
export type MarketPlaceInputs = InferContractRouterInputs<typeof marketplaceRouterContract>
|
||||
|
||||
export const consoleRouterContract = {
|
||||
systemFeatures: systemFeaturesContract,
|
||||
billingUrl: billingUrlContract,
|
||||
bindPartnerStack: bindPartnerStackContract,
|
||||
}
|
||||
|
||||
export type ConsoleInputs = InferContractRouterInputs<typeof consoleRouterContract>
|
||||
Reference in New Issue
Block a user