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