Merge branch 'master' of github.com:Budibase/budibase into fix/automation-webhook-improvements

This commit is contained in:
mike12345567 2024-12-13 17:55:32 +00:00
commit eb69bbd3cb
37 changed files with 167 additions and 84 deletions

View File

@ -1,10 +1,11 @@
import { events, context } from "@budibase/backend-core"
import { context, events } from "@budibase/backend-core"
import {
AnalyticsPingRequest,
App,
PingSource,
Ctx,
AnalyticsEnabledResponse,
AnalyticsPingRequest,
AnalyticsPingResponse,
App,
Ctx,
PingSource,
} from "@budibase/types"
import { DocumentType, isDevAppID } from "../../db/utils"
@ -15,9 +16,12 @@ export const isEnabled = async (ctx: Ctx<void, AnalyticsEnabledResponse>) => {
}
}
export const ping = async (ctx: Ctx<AnalyticsPingRequest, void>) => {
export const ping = async (
ctx: Ctx<AnalyticsPingRequest, AnalyticsPingResponse>
) => {
const body = ctx.request.body
let pingType: PingSource | undefined
switch (body.source) {
case PingSource.APP: {
const db = context.getAppDB({ skip_setup: true })
@ -29,13 +33,18 @@ export const ping = async (ctx: Ctx<AnalyticsPingRequest, void>) => {
} else {
await events.serve.servedApp(appInfo, body.timezone, body.embedded)
}
pingType = PingSource.APP
break
}
case PingSource.BUILDER: {
await events.serve.servedBuilder(body.timezone)
pingType = PingSource.BUILDER
break
}
}
ctx.status = 200
ctx.body = {
message: "pong",
source: pingType,
}
}

View File

@ -68,6 +68,9 @@ import {
ImportToUpdateAppRequest,
ImportToUpdateAppResponse,
SetRevertableAppVersionRequest,
AddAppSampleDataResponse,
UnpublishAppResponse,
SetRevertableAppVersionResponse,
} from "@budibase/types"
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
import sdk from "../../sdk"
@ -175,7 +178,9 @@ async function createInstance(appId: string, template: AppTemplate) {
return { _id: appId }
}
export const addSampleData = async (ctx: UserCtx<void, void>) => {
export const addSampleData = async (
ctx: UserCtx<void, AddAppSampleDataResponse>
) => {
const db = context.getAppDB()
try {
@ -188,7 +193,7 @@ export const addSampleData = async (ctx: UserCtx<void, void>) => {
await db.bulkDocs([...defaultDbDocs])
}
ctx.status = 200
ctx.body = { message: "Sample tables added." }
}
export async function fetch(ctx: UserCtx<void, FetchAppsResponse>) {
@ -528,7 +533,6 @@ export async function create(
await appPostCreate(ctx, newApplication)
await cache.bustCache(cache.CacheKey.CHECKLIST)
ctx.body = newApplication
ctx.status = 200
}
// This endpoint currently operates as a PATCH rather than a PUT
@ -551,7 +555,6 @@ export async function update(
const app = await updateAppPackage(ctx.request.body, ctx.params.appId)
await events.app.updated(app)
ctx.status = 200
ctx.body = app
builderSocket?.emitAppMetadataUpdate(ctx, {
theme: app.theme,
@ -592,7 +595,6 @@ export async function updateClient(
}
const app = await updateAppPackage(appPackageUpdates, ctx.params.appId)
await events.app.versionUpdated(app, currentVersion, updatedToVersion)
ctx.status = 200
ctx.body = app
}
@ -624,7 +626,6 @@ export async function revertClient(
}
const app = await updateAppPackage(appPackageUpdates, ctx.params.appId)
await events.app.versionReverted(app, currentVersion, revertedToVersion)
ctx.status = 200
ctx.body = app
}
@ -689,11 +690,10 @@ export async function destroy(ctx: UserCtx<void, DeleteAppResponse>) {
await preDestroyApp(ctx)
const result = await destroyApp(ctx)
await postDestroyApp(ctx)
ctx.status = 200
ctx.body = result
}
export async function unpublish(ctx: UserCtx<void, void>) {
export async function unpublish(ctx: UserCtx<void, UnpublishAppResponse>) {
const prodAppId = dbCore.getProdAppID(ctx.params.appId)
const dbExists = await dbCore.dbExists(prodAppId)
@ -705,8 +705,8 @@ export async function unpublish(ctx: UserCtx<void, void>) {
await preDestroyApp(ctx)
await unpublishApp(ctx)
await postDestroyApp(ctx)
ctx.status = 204
builderSocket?.emitAppUnpublish(ctx)
ctx.body = { message: "App unpublished." }
}
export async function sync(ctx: UserCtx<void, SyncAppResponse>) {
@ -802,7 +802,6 @@ export async function duplicateApp(
duplicateAppId: newApplication?.appId,
sourceAppId,
}
ctx.status = 200
}
export async function updateAppPackage(
@ -830,7 +829,7 @@ export async function updateAppPackage(
}
export async function setRevertableVersion(
ctx: UserCtx<SetRevertableAppVersionRequest, void>
ctx: UserCtx<SetRevertableAppVersionRequest, SetRevertableAppVersionResponse>
) {
if (!env.isDev()) {
ctx.status = 403
@ -840,8 +839,7 @@ export async function setRevertableVersion(
const app = await sdk.applications.metadata.get()
app.revertableVersion = ctx.request.body.revertableVersion
await db.put(app)
ctx.status = 200
ctx.body = { message: "Revertable version updated." }
}
async function migrateAppNavigation() {

View File

@ -62,7 +62,6 @@ export async function create(
const createdAutomation = await sdk.automations.create(automation)
ctx.status = 200
ctx.body = {
message: "Automation created successfully",
automation: createdAutomation,
@ -84,7 +83,6 @@ export async function update(
const updatedAutomation = await sdk.automations.update(automation)
ctx.status = 200
ctx.body = {
message: `Automation ${automation._id} updated successfully.`,
automation: updatedAutomation,

View File

@ -182,7 +182,6 @@ export async function update(
}
}
ctx.status = 200
ctx.message = "Datasource saved successfully."
ctx.body = {
datasource: await sdk.datasources.removeSecretSingle(datasource),
@ -290,8 +289,7 @@ export async function destroy(ctx: UserCtx<void, DeleteDatasourceResponse>) {
await db.remove(datasourceId, ctx.params.revId)
await events.datasource.deleted(datasource)
ctx.message = `Datasource deleted.`
ctx.status = 200
ctx.body = { message: `Datasource deleted.` }
builderSocket?.emitDatasourceDeletion(ctx, datasourceId)
}

View File

@ -29,7 +29,6 @@ export async function save(
layout._rev = response.rev
ctx.body = layout
ctx.status = 200
}
export async function destroy(ctx: UserCtx<void, DeleteLayoutResponse>) {
@ -51,5 +50,4 @@ export async function destroy(ctx: UserCtx<void, DeleteLayoutResponse>) {
await db.remove(layoutId, layoutRev)
await events.layout.deleted(layoutId)
ctx.body = { message: "Layout deleted successfully" }
ctx.status = 200
}

View File

@ -4,6 +4,7 @@ import {
Ctx,
FetchOldMigrationResponse,
GetOldMigrationStatus,
RuneOldMigrationResponse,
RunOldMigrationRequest,
} from "@budibase/types"
import {
@ -11,18 +12,19 @@ import {
getLatestEnabledMigrationId,
} from "../../appMigrations"
export async function migrate(ctx: Ctx<RunOldMigrationRequest, void>) {
export async function migrate(
ctx: Ctx<RunOldMigrationRequest, RuneOldMigrationResponse>
) {
const options = ctx.request.body
// don't await as can take a while, just return
migrationImpl(options)
ctx.status = 200
ctx.body = { message: "Migration started." }
}
export async function fetchDefinitions(
ctx: Ctx<void, FetchOldMigrationResponse>
) {
ctx.body = MIGRATIONS
ctx.status = 200
}
export async function getMigrationStatus(
@ -41,5 +43,4 @@ export async function getMigrationStatus(
!latestMigrationId || latestAppliedMigration >= latestMigrationId
ctx.body = { migrated }
ctx.status = 200
}

View File

@ -99,7 +99,7 @@ export async function getDependantResources(
export async function addPermission(ctx: UserCtx<void, AddPermissionResponse>) {
const params: AddPermissionRequest = ctx.params
await sdk.permissions.updatePermissionOnRole(params, PermissionUpdateType.ADD)
ctx.status = 200
ctx.body = { message: "Permission added." }
}
export async function removePermission(
@ -110,5 +110,5 @@ export async function removePermission(
params,
PermissionUpdateType.REMOVE
)
ctx.status = 200
ctx.body = { message: "Permission removed." }
}

View File

@ -104,7 +104,6 @@ const _import = async (
...importResult,
datasourceId,
}
ctx.status = 200
}
export { _import as import }
@ -455,6 +454,5 @@ export async function destroy(ctx: UserCtx<void, DeleteQueryResponse>) {
const datasource = await sdk.datasources.get(query.datasourceId)
await db.remove(ctx.params.queryId, ctx.params.revId)
ctx.body = { message: `Query deleted.` }
ctx.status = 200
await events.query.deleted(datasource, query)
}

View File

@ -234,8 +234,7 @@ export async function destroy(ctx: UserCtx<void, DeleteRoleResponse>) {
// clean up inherits
await removeRoleFromOthers(roleId)
ctx.message = `Role ${ctx.params.roleId} deleted successfully`
ctx.status = 200
ctx.body = { message: `Role ${ctx.params.roleId} deleted successfully` }
builderSocket?.emitRoleDeletion(ctx, role)
}

View File

@ -71,7 +71,6 @@ export async function patch(
if (!row) {
ctx.throw(404, "Row not found")
}
ctx.status = 200
ctx.eventEmitter?.emitRow({
eventName: EventType.ROW_UPDATE,
@ -110,7 +109,6 @@ export const save = async (ctx: UserCtx<SaveRowRequest, SaveRowResponse>) => {
: await quotas.addRow(() =>
sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id)
)
ctx.status = 200
ctx.eventEmitter?.emitRow({
eventName: EventType.ROW_SAVE,
@ -223,7 +221,6 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
export async function destroy(ctx: UserCtx<DeleteRowRequest>) {
let response, row
ctx.status = 200
if (isDeleteRows(ctx.request.body)) {
response = await deleteRows(ctx)
@ -275,7 +272,6 @@ export async function search(ctx: Ctx<SearchRowRequest, SearchRowResponse>) {
rows: undefined,
}
ctx.status = 200
ctx.body = await sdk.rows.search(searchParams)
}

View File

@ -1,10 +1,16 @@
import { RowActionTriggerRequest, Ctx } from "@budibase/types"
import {
RowActionTriggerRequest,
Ctx,
RowActionTriggerResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
export async function run(ctx: Ctx<RowActionTriggerRequest, void>) {
export async function run(
ctx: Ctx<RowActionTriggerRequest, RowActionTriggerResponse>
) {
const { tableId, actionId } = ctx.params
const { rowId } = ctx.request.body
await sdk.rowActions.run(tableId, actionId, rowId, ctx.user)
ctx.status = 200
ctx.body = { message: "Row action triggered." }
}

View File

@ -123,7 +123,6 @@ export async function destroy(ctx: UserCtx<void, DeleteScreenResponse>) {
ctx.body = {
message: "Screen deleted successfully",
}
ctx.status = 200
builderSocket?.emitScreenDeletion(ctx, id)
}

View File

@ -136,7 +136,6 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
if (isImport) {
await events.table.imported(savedTable)
}
ctx.status = 200
ctx.message = `Table ${table.name} saved successfully.`
ctx.eventEmitter?.emitTable(EventType.TABLE_SAVE, appId, { ...savedTable })
ctx.body = savedTable
@ -153,7 +152,6 @@ export async function destroy(ctx: UserCtx<void, DeleteTableResponse>) {
await events.table.deleted(deletedTable)
ctx.eventEmitter?.emitTable(EventType.TABLE_DELETE, appId, deletedTable)
ctx.status = 200
ctx.table = deletedTable
ctx.body = { message: `Table ${tableId} deleted.` }
builderSocket?.emitTableDeletion(ctx, deletedTable)
@ -169,7 +167,6 @@ export async function bulkImport(
// can only be done in the builder, but in the future we may need to
// think about events for bulk items
ctx.status = 200
ctx.body = { message: `Bulk rows created.` }
}
@ -180,7 +177,6 @@ export async function csvToJson(
const result = await jsonFromCsvString(csvString)
ctx.status = 200
ctx.body = result
}
@ -190,7 +186,6 @@ export async function validateNewTableImport(
const { rows, schema } = ctx.request.body
if (isRows(rows) && isSchema(schema)) {
ctx.status = 200
ctx.body = validateSchema(rows, schema, PROTECTED_INTERNAL_COLUMNS)
} else {
ctx.status = 422
@ -224,7 +219,6 @@ export async function validateExistingTableImport(
}
if (tableId && isRows(rows) && isSchema(schema)) {
ctx.status = 200
ctx.body = validateSchema(rows, schema, protectedColumnNames)
} else {
ctx.status = 422
@ -245,6 +239,5 @@ export async function migrate(
})
}
ctx.status = 200
ctx.body = { message: `Column ${oldColumn} migrated.` }
}

View File

@ -112,7 +112,7 @@ export async function run({
response: ctx.body,
id: ctx.body._id,
revision: ctx.body._rev,
success: ctx.status === 200,
success: !!ctx.body._id,
}
} catch (err) {
return {

View File

@ -94,7 +94,7 @@ export async function run({
return {
response: ctx.body,
row: ctx.row,
success: ctx.status === 200,
success: ctx.body.ok,
}
} catch (err) {
return {

View File

@ -152,7 +152,7 @@ export async function run({
return {
rows,
success: ctx.status === 200,
success: true,
}
} catch (err) {
return {

View File

@ -166,7 +166,7 @@ export async function run({
response: ctx.message,
id: ctx.body._id,
revision: ctx.body._rev,
success: ctx.status === 200,
success: !!ctx.body._id,
}
} catch (err) {
return {

View File

@ -96,7 +96,7 @@ describe("Test a query step automation", () => {
)
.run()
expect(result.steps[0].outputs.success).toBe(false)
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
expect(result.steps[0].outputs.rows.length).toBe(0)
})
@ -125,7 +125,7 @@ describe("Test a query step automation", () => {
)
.run()
expect(result.steps[0].outputs.success).toBe(false)
expect(result.steps[0].outputs.success).toBe(true)
expect(result.steps[0].outputs.rows).toBeDefined()
expect(result.steps[0].outputs.rows.length).toBe(0)
})

View File

@ -48,7 +48,7 @@ export class ApplicationAPI extends TestAPI {
unpublish = async (appId: string): Promise<void> => {
await this._post(`/api/applications/${appId}/unpublish`, {
expectations: { status: 204 },
expectations: { status: 200 },
})
}

View File

@ -12,3 +12,7 @@ export interface AnalyticsPingRequest {
timezone: string
embedded?: boolean
}
export interface AnalyticsPingResponse {
message: string
source?: PingSource
}

View File

@ -44,6 +44,10 @@ export interface FetchAppPackageResponse {
hasLock: boolean
}
export interface AddAppSampleDataResponse {
message: string
}
export type FetchAppsResponse = App[]
export interface PublishResponse {
@ -61,6 +65,10 @@ export interface DeleteAppResponse {
ok: boolean
}
export interface UnpublishAppResponse {
message: string
}
export interface ImportToUpdateAppRequest {
encryptionPassword?: string
}
@ -71,6 +79,9 @@ export interface ImportToUpdateAppResponse {
export interface SetRevertableAppVersionRequest {
revertableVersion: string
}
export interface SetRevertableAppVersionResponse {
message: string
}
export interface ExportAppDumpRequest {
excludeRows: boolean

View File

@ -29,7 +29,9 @@ export interface AddedPermission {
reason?: string
}
export interface AddPermissionResponse {}
export interface AddPermissionResponse {
message: string
}
export interface AddPermissionRequest {
roleId: string
@ -38,4 +40,6 @@ export interface AddPermissionRequest {
}
export interface RemovePermissionRequest extends AddPermissionRequest {}
export interface RemovePermissionResponse {}
export interface RemovePermissionResponse {
message: string
}

View File

@ -21,6 +21,9 @@ export interface RowActionsResponse {
export interface RowActionTriggerRequest {
rowId: string
}
export interface RowActionTriggerResponse {
message: string
}
export interface RowActionPermissionsResponse
extends RowActionPermissionsData {}

View File

@ -2,12 +2,19 @@ export interface LoginRequest {
username: string
password: string
}
export interface LoginResponse {
message: string
userId?: string
}
export interface LogoutResponse {
message: string
}
export interface SetInitInfoRequest extends Record<string, any> {}
export interface SetInitInfoResponse {
message: string
}
export interface GetInitInfoResponse extends Record<string, any> {}

View File

@ -7,12 +7,22 @@ export interface CreateEnvironmentVariableRequest {
production: string
development: string
}
export interface CreateEnvironmentVariableResponse {
message: string
}
export interface UpdateEnvironmentVariableRequest {
production: string
development: string
}
export interface UpdateEnvironmentVariableResponse {
message: string
}
export interface GetEnvironmentVariablesResponse {
variables: string[]
}
export interface DeleteEnvironmentVariablesResponse {
message: string
}

View File

@ -5,3 +5,6 @@ export enum EventPublishType {
export interface PostEventPublishRequest {
type: EventPublishType
}
export interface PostEventPublishResponse {
message: string
}

View File

@ -5,6 +5,9 @@ import { QuotaUsage } from "../../../documents"
export interface ActivateLicenseKeyRequest {
licenseKey: string
}
export interface ActivateLicenseKeyResponse {
message: string
}
export interface GetLicenseKeyResponse {
licenseKey: string
@ -15,11 +18,20 @@ export interface GetLicenseKeyResponse {
export interface ActivateOfflineLicenseTokenRequest {
offlineLicenseToken: string
}
export interface ActivateOfflineLicenseTokenResponse {
message: string
}
export interface GetOfflineLicenseTokenResponse {
offlineLicenseToken: string
}
// REFRESH
export interface RefreshOfflineLicenseResponse {
message: string
}
// IDENTIFIER
export interface GetOfflineIdentifierResponse {

View File

@ -1,6 +1,9 @@
import { Migration, MigrationOptions } from "../../../sdk"
export interface RunOldMigrationRequest extends MigrationOptions {}
export interface RuneOldMigrationResponse {
message: string
}
export type FetchOldMigrationResponse = Migration[]

View File

@ -1,5 +1,8 @@
import { MigrationDefinition, MigrationOptions } from "../../../sdk"
export interface RunGlobalMigrationRequest extends MigrationOptions {}
export interface RunGlobalMigrationResponse {
message: string
}
export type FetchMigrationDefinitionsResponse = MigrationDefinition[]

View File

@ -110,6 +110,9 @@ export interface AddSSoUserRequest {
ssoId: string
email: string
}
export interface AddSSoUserResponse {
message: string
}
export interface CreateAdminUserResponse {
_id: string

View File

@ -22,6 +22,8 @@ import {
GetInitInfoResponse,
PasswordResetResponse,
PasswordResetUpdateResponse,
SetInitInfoResponse,
LoginResponse,
} from "@budibase/types"
import env from "../../../environment"
import { Next } from "koa"
@ -59,7 +61,10 @@ async function passportCallback(
ctx.set(Header.TOKEN, token)
}
export const login = async (ctx: Ctx<LoginRequest, void>, next: Next) => {
export const login = async (
ctx: Ctx<LoginRequest, LoginResponse>,
next: Next
) => {
const email = ctx.request.body.username
const user = await userSdk.db.getUserByEmail(email)
@ -74,7 +79,10 @@ export const login = async (ctx: Ctx<LoginRequest, void>, next: Next) => {
await context.identity.doInUserContext(user, ctx, async () => {
await events.auth.login("local", user.email)
})
ctx.status = 200
ctx.body = {
message: "Login successful",
userId: user.userId,
}
}
)(ctx, next)
}
@ -88,10 +96,14 @@ export const logout = async (ctx: UserCtx<void, LogoutResponse>) => {
// INIT
export const setInitInfo = (ctx: UserCtx<SetInitInfoRequest, void>) => {
export const setInitInfo = (
ctx: UserCtx<SetInitInfoRequest, SetInitInfoResponse>
) => {
const initInfo = ctx.request.body
setCookie(ctx, initInfo, Cookie.Init)
ctx.status = 200
ctx.body = {
message: "Init info updated.",
}
}
export const getInitInfo = (ctx: UserCtx<void, GetInitInfoResponse>) => {

View File

@ -2,10 +2,13 @@ import {
UserCtx,
PostEventPublishRequest,
EventPublishType,
PostEventPublishResponse,
} from "@budibase/types"
import { events } from "@budibase/backend-core"
export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
export async function publish(
ctx: UserCtx<PostEventPublishRequest, PostEventPublishResponse>
) {
switch (ctx.request.body.type) {
case EventPublishType.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED:
await events.environmentVariable.upgradePanelOpened(ctx.user._id!)
@ -13,5 +16,5 @@ export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
default:
ctx.throw(400, "Invalid publish event type.")
}
ctx.status = 200
ctx.body = { message: "Event published." }
}

View File

@ -1,29 +1,33 @@
import { licensing, quotas } from "@budibase/pro"
import {
ActivateLicenseKeyRequest,
ActivateLicenseKeyResponse,
ActivateOfflineLicenseTokenRequest,
ActivateOfflineLicenseTokenResponse,
GetLicenseKeyResponse,
GetOfflineIdentifierResponse,
GetOfflineLicenseTokenResponse,
GetQuotaUsageResponse,
RefreshOfflineLicenseResponse,
UserCtx,
} from "@budibase/types"
// LICENSE KEY
export async function activateLicenseKey(
ctx: UserCtx<ActivateLicenseKeyRequest>
ctx: UserCtx<ActivateLicenseKeyRequest, ActivateLicenseKeyResponse>
) {
const { licenseKey } = ctx.request.body
await licensing.keys.activateLicenseKey(licenseKey)
ctx.status = 200
ctx.body = {
message: "License activated.",
}
}
export async function getLicenseKey(ctx: UserCtx<void, GetLicenseKeyResponse>) {
const licenseKey = await licensing.keys.getLicenseKey()
if (licenseKey) {
ctx.body = { licenseKey: "*" }
ctx.status = 200
} else {
ctx.status = 404
}
@ -37,11 +41,16 @@ export async function deleteLicenseKey(ctx: UserCtx<void, void>) {
// OFFLINE LICENSE
export async function activateOfflineLicenseToken(
ctx: UserCtx<ActivateOfflineLicenseTokenRequest, void>
ctx: UserCtx<
ActivateOfflineLicenseTokenRequest,
ActivateOfflineLicenseTokenResponse
>
) {
const { offlineLicenseToken } = ctx.request.body
await licensing.offline.activateOfflineLicenseToken(offlineLicenseToken)
ctx.status = 200
ctx.body = {
message: "License token activated.",
}
}
export async function getOfflineLicenseToken(
@ -50,7 +59,6 @@ export async function getOfflineLicenseToken(
const offlineLicenseToken = await licensing.offline.getOfflineLicenseToken()
if (offlineLicenseToken) {
ctx.body = { offlineLicenseToken: "*" }
ctx.status = 200
} else {
ctx.status = 404
}
@ -66,14 +74,17 @@ export async function getOfflineLicenseIdentifier(
) {
const identifierBase64 = await licensing.offline.getIdentifierBase64()
ctx.body = { identifierBase64 }
ctx.status = 200
}
// LICENSES
export const refresh = async (ctx: UserCtx<void, void>) => {
export const refresh = async (
ctx: UserCtx<void, RefreshOfflineLicenseResponse>
) => {
await licensing.cache.refresh()
ctx.status = 200
ctx.body = {
message: "License refreshed.",
}
}
// USAGE
@ -82,5 +93,4 @@ export const getQuotaUsage = async (
ctx: UserCtx<void, GetQuotaUsageResponse>
) => {
ctx.body = await quotas.getQuotaUsage()
ctx.status = 200
}

View File

@ -4,6 +4,7 @@ import {
AcceptUserInviteRequest,
AcceptUserInviteResponse,
AddSSoUserRequest,
AddSSoUserResponse,
BulkUserRequest,
BulkUserResponse,
CheckInviteResponse,
@ -93,7 +94,9 @@ export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
}
}
export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest, void>) => {
export const addSsoSupport = async (
ctx: Ctx<AddSSoUserRequest, AddSSoUserResponse>
) => {
const { email, ssoId } = ctx.request.body
try {
// Status is changed to 404 from getUserDoc if user is not found
@ -113,7 +116,7 @@ export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest, void>) => {
email,
ssoId,
})
ctx.status = 200
ctx.body = { message: "SSO support added." }
} catch (err: any) {
ctx.throw(err.status || 400, err)
}

View File

@ -19,7 +19,6 @@ export const save = async (
metadata = await accounts.metadata.saveMetadata(metadata)
ctx.body = metadata
ctx.status = 200
}
export const destroy = async (ctx: Ctx<void, void>) => {

View File

@ -1,23 +1,23 @@
import {
FetchMigrationDefinitionsResponse,
RunGlobalMigrationRequest,
RunGlobalMigrationResponse,
UserCtx,
} from "@budibase/types"
const { migrate, MIGRATIONS } = require("../../../migrations")
export const runMigrations = async (
ctx: UserCtx<RunGlobalMigrationRequest, void>
ctx: UserCtx<RunGlobalMigrationRequest, RunGlobalMigrationResponse>
) => {
const options = ctx.request.body
// don't await as can take a while, just return
migrate(options)
ctx.status = 200
ctx.body = { message: "Migration started." }
}
export const fetchDefinitions = async (
ctx: UserCtx<void, FetchMigrationDefinitionsResponse>
) => {
ctx.body = MIGRATIONS
ctx.status = 200
}

View File

@ -36,7 +36,7 @@ describe("/api/system/migrations", () => {
it("runs migrations", async () => {
const res = await config.api.migrations.runMigrations()
expect(res.text).toBe("OK")
expect(res.body.message).toBeDefined()
expect(migrateFn).toHaveBeenCalledTimes(1)
})
})