Type flag endpoints

This commit is contained in:
Andrew Kingston 2024-12-02 15:23:48 +00:00
parent 417286b16d
commit 1b6e6ed7db
No known key found for this signature in database
3 changed files with 18 additions and 10 deletions

View File

@ -10,14 +10,11 @@ export function createFlagsStore() {
set(flags)
},
updateFlag: async (flag, value) => {
await API.updateFlag({
flag,
value,
})
await API.updateFlag(flag, value)
await actions.fetch()
},
toggleUiFeature: async feature => {
await API.toggleUiFeature({ value: feature })
await API.toggleUiFeature(feature)
},
}

View File

@ -1,4 +1,13 @@
export const buildFlagEndpoints = API => ({
import { Flags, SetFlagRequest } from "@budibase/types"
import { BaseAPIClient } from "./types"
export interface FlagEndpoints {
getFlags: () => Promise<Flags>
updateFlag: (flag: string, value: any) => Promise<{ message: string }>
toggleUiFeature: (value: string) => Promise<{ message: string }>
}
export const buildFlagEndpoints = (API: BaseAPIClient): FlagEndpoints => ({
/**
* Gets the current user flags object.
*/
@ -13,8 +22,8 @@ export const buildFlagEndpoints = API => ({
* @param flag the flag to update
* @param value the value to set the flag to
*/
updateFlag: async ({ flag, value }) => {
return await API.post({
updateFlag: async (flag, value) => {
return await API.post<SetFlagRequest, { message: string }>({
url: "/api/users/flags",
body: {
flag,
@ -26,7 +35,7 @@ export const buildFlagEndpoints = API => ({
* Allows us to experimentally toggle a beta UI feature through a cookie.
* @param value the feature to toggle
*/
toggleUiFeature: async ({ value }) => {
toggleUiFeature: async value => {
return await API.post({
url: `/api/beta/${value}`,
})

View File

@ -10,6 +10,7 @@ import { ConfigEndpoints } from "./configs"
import { DatasourceEndpoints } from "./datasources"
import { EnvironmentVariableEndpoints } from "./environmentVariables"
import { EventEndpoints } from "./events"
import { FlagEndpoints } from "./flags"
export enum HTTPMethod {
POST = "POST",
@ -81,4 +82,5 @@ export type APIClient = BaseAPIClient &
ConfigEndpoints &
DatasourceEndpoints &
EnvironmentVariableEndpoints &
EventEndpoints
EventEndpoints &
FlagEndpoints