Fix frontend usage
This commit is contained in:
parent
9b0660ee27
commit
a40c51eede
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { oauth2 } from "@/stores/builder"
|
||||
import type { OAuth2Config, UpsertOAuth2Config } from "@/types"
|
||||
import type { OAuth2Config } from "@/types"
|
||||
import {
|
||||
Body,
|
||||
Divider,
|
||||
|
@ -12,6 +12,7 @@
|
|||
notifications,
|
||||
Select,
|
||||
} from "@budibase/bbui"
|
||||
import type { InsertOAuth2ConfigRequest } from "@budibase/types"
|
||||
import {
|
||||
OAuth2CredentialsMethod,
|
||||
PASSWORD_REPLACEMENT,
|
||||
|
@ -50,7 +51,7 @@
|
|||
name: requiredString("Name is required.").refine(
|
||||
val =>
|
||||
!$oauth2.configs
|
||||
.filter(c => c.id !== config.id)
|
||||
.filter(c => c._id !== config._id)
|
||||
.map(c => c.name.toLowerCase())
|
||||
.includes(val.toLowerCase()),
|
||||
{
|
||||
|
@ -63,7 +64,7 @@
|
|||
method: z.nativeEnum(OAuth2CredentialsMethod, {
|
||||
message: "Authentication method is required.",
|
||||
}),
|
||||
}) satisfies ZodType<UpsertOAuth2Config>
|
||||
}) satisfies ZodType<InsertOAuth2ConfigRequest>
|
||||
|
||||
const validationResult = validator.safeParse(config)
|
||||
errors = {}
|
||||
|
@ -91,7 +92,7 @@
|
|||
const { data: configData } = validationResult
|
||||
try {
|
||||
const connectionValidation = await oauth2.validate({
|
||||
id: config?.id,
|
||||
_id: config?._id,
|
||||
url: configData.url,
|
||||
clientId: configData.clientId,
|
||||
clientSecret: configData.clientSecret,
|
||||
|
@ -110,7 +111,11 @@
|
|||
await oauth2.create(configData)
|
||||
notifications.success("Settings created.")
|
||||
} else {
|
||||
await oauth2.edit(config!.id, configData)
|
||||
await oauth2.edit({
|
||||
...configData,
|
||||
_id: config!._id,
|
||||
_rev: config!._rev,
|
||||
})
|
||||
notifications.success("Settings saved.")
|
||||
}
|
||||
} catch (e: any) {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { API } from "@/api"
|
||||
import { BudiStore } from "@/stores/BudiStore"
|
||||
import { OAuth2Config, UpsertOAuth2Config } from "@/types"
|
||||
import { ValidateConfigRequest } from "@budibase/types"
|
||||
import { OAuth2Config } from "@/types"
|
||||
import {
|
||||
InsertOAuth2ConfigRequest,
|
||||
UpdateOAuth2ConfigRequest,
|
||||
ValidateConfigRequest,
|
||||
} from "@budibase/types"
|
||||
|
||||
interface OAuth2StoreState {
|
||||
configs: OAuth2Config[]
|
||||
|
@ -27,7 +31,8 @@ export class OAuth2Store extends BudiStore<OAuth2StoreState> {
|
|||
this.store.update(store => ({
|
||||
...store,
|
||||
configs: configs.map(c => ({
|
||||
id: c.id,
|
||||
_id: c._id,
|
||||
_rev: c._rev,
|
||||
name: c.name,
|
||||
url: c.url,
|
||||
clientId: c.clientId,
|
||||
|
@ -45,13 +50,13 @@ export class OAuth2Store extends BudiStore<OAuth2StoreState> {
|
|||
}
|
||||
}
|
||||
|
||||
async create(config: UpsertOAuth2Config) {
|
||||
async create(config: InsertOAuth2ConfigRequest) {
|
||||
await API.oauth2.create(config)
|
||||
await this.fetch()
|
||||
}
|
||||
|
||||
async edit(id: string, config: UpsertOAuth2Config) {
|
||||
await API.oauth2.update(id, config)
|
||||
async edit(config: UpdateOAuth2ConfigRequest) {
|
||||
await API.oauth2.update(config)
|
||||
await this.fetch()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
import {
|
||||
UpsertOAuth2ConfigRequest,
|
||||
OAuth2ConfigResponse,
|
||||
} from "@budibase/types"
|
||||
import { OAuth2ConfigResponse } from "@budibase/types"
|
||||
|
||||
export interface OAuth2Config extends OAuth2ConfigResponse {}
|
||||
|
||||
export interface UpsertOAuth2Config extends UpsertOAuth2ConfigRequest {}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import {
|
||||
FetchOAuth2ConfigsResponse,
|
||||
InsertOAuth2ConfigRequest,
|
||||
InsertOAuth2ConfigResponse,
|
||||
OAuth2ConfigResponse,
|
||||
UpsertOAuth2ConfigRequest,
|
||||
UpsertOAuth2ConfigResponse,
|
||||
UpdateOAuth2ConfigRequest,
|
||||
UpdateOAuth2ConfigResponse,
|
||||
ValidateConfigRequest,
|
||||
ValidateConfigResponse,
|
||||
} from "@budibase/types"
|
||||
|
@ -11,12 +13,11 @@ import { BaseAPIClient } from "./types"
|
|||
export interface OAuth2Endpoints {
|
||||
fetch: () => Promise<OAuth2ConfigResponse[]>
|
||||
create: (
|
||||
config: UpsertOAuth2ConfigRequest
|
||||
) => Promise<UpsertOAuth2ConfigResponse>
|
||||
config: InsertOAuth2ConfigRequest
|
||||
) => Promise<InsertOAuth2ConfigResponse>
|
||||
update: (
|
||||
id: string,
|
||||
config: UpsertOAuth2ConfigRequest
|
||||
) => Promise<UpsertOAuth2ConfigResponse>
|
||||
config: UpdateOAuth2ConfigRequest
|
||||
) => Promise<UpdateOAuth2ConfigResponse>
|
||||
delete: (id: string) => Promise<void>
|
||||
validate: (config: ValidateConfigRequest) => Promise<ValidateConfigResponse>
|
||||
}
|
||||
|
@ -38,8 +39,8 @@ export const buildOAuth2Endpoints = (API: BaseAPIClient): OAuth2Endpoints => ({
|
|||
*/
|
||||
create: async config => {
|
||||
return await API.post<
|
||||
UpsertOAuth2ConfigRequest,
|
||||
UpsertOAuth2ConfigResponse
|
||||
InsertOAuth2ConfigRequest,
|
||||
InsertOAuth2ConfigResponse
|
||||
>({
|
||||
url: `/api/oauth2`,
|
||||
body: {
|
||||
|
@ -51,10 +52,10 @@ export const buildOAuth2Endpoints = (API: BaseAPIClient): OAuth2Endpoints => ({
|
|||
/**
|
||||
* Updates an existing OAuth2 configuration.
|
||||
*/
|
||||
update: async (id, config) => {
|
||||
return await API.put<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>(
|
||||
update: async config => {
|
||||
return await API.put<UpdateOAuth2ConfigRequest, UpdateOAuth2ConfigResponse>(
|
||||
{
|
||||
url: `/api/oauth2/${id}`,
|
||||
url: `/api/oauth2`,
|
||||
body: {
|
||||
...config,
|
||||
},
|
||||
|
|
|
@ -28,7 +28,7 @@ const updateSchema = Joi.object({
|
|||
})
|
||||
|
||||
const validationSchema = Joi.object({
|
||||
name: Joi.string().required(),
|
||||
_id: Joi.string().required(),
|
||||
...baseSchema,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue