Misc system APIs typing.
This commit is contained in:
parent
95b7b14ff6
commit
165ff4e768
|
@ -0,0 +1,4 @@
|
||||||
|
import { Account, AccountMetadata } from "../../../documents"
|
||||||
|
|
||||||
|
export interface SaveAccountRequest extends Account {}
|
||||||
|
export interface SaveAccountResponse extends AccountMetadata {}
|
|
@ -1,8 +1,11 @@
|
||||||
export interface GetEnvironmentResponse {
|
export interface GetEnvironmentResponse {
|
||||||
multiTenancy: boolean
|
multiTenancy: boolean
|
||||||
|
offlineMode: boolean
|
||||||
cloud: boolean
|
cloud: boolean
|
||||||
accountPortalUrl: string
|
accountPortalUrl?: string
|
||||||
baseUrl: string
|
|
||||||
disableAccountPortal: boolean
|
disableAccountPortal: boolean
|
||||||
|
baseUrl?: string
|
||||||
isDev: boolean
|
isDev: boolean
|
||||||
|
maintenance: { type: string }[]
|
||||||
|
passwordMinLength?: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
export * from "./environment"
|
export * from "./environment"
|
||||||
export * from "./status"
|
export * from "./status"
|
||||||
export * from "./ops"
|
export * from "./ops"
|
||||||
|
export * from "./account"
|
||||||
|
export * from "./log"
|
||||||
|
export * from "./migration"
|
||||||
|
export * from "./restore"
|
||||||
|
export * from "./tenant"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export type GetLogResponse = Buffer
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { MigrationDefinition, MigrationOptions } from "../../../sdk"
|
||||||
|
|
||||||
|
export interface RunGlobalMigrationRequest extends MigrationOptions {}
|
||||||
|
|
||||||
|
export type FetchMigrationDefinitionsResponse = MigrationDefinition[]
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface SystemRestoreResponse {
|
||||||
|
message: string
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface GetTenantInfoResponse {
|
||||||
|
exists: boolean
|
||||||
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
import { tenancy, db as dbCore } from "@budibase/backend-core"
|
|
||||||
import { BBContext } from "@budibase/types"
|
|
||||||
|
|
||||||
export async function save(ctx: BBContext) {
|
|
||||||
const db = tenancy.getGlobalDB()
|
|
||||||
const workspaceDoc = ctx.request.body
|
|
||||||
|
|
||||||
// workspace does not exist yet
|
|
||||||
if (!workspaceDoc._id) {
|
|
||||||
workspaceDoc._id = dbCore.generateWorkspaceID()
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await db.put(workspaceDoc)
|
|
||||||
ctx.body = {
|
|
||||||
_id: response.id,
|
|
||||||
_rev: response.rev,
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
ctx.throw(err.status, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetch(ctx: BBContext) {
|
|
||||||
const db = tenancy.getGlobalDB()
|
|
||||||
const response = await db.allDocs(
|
|
||||||
dbCore.getWorkspaceParams(undefined, {
|
|
||||||
include_docs: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
ctx.body = response.rows.map(row => row.doc)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function find(ctx: BBContext) {
|
|
||||||
const db = tenancy.getGlobalDB()
|
|
||||||
try {
|
|
||||||
ctx.body = await db.get(ctx.params.id)
|
|
||||||
} catch (err: any) {
|
|
||||||
ctx.throw(err.status, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function destroy(ctx: BBContext) {
|
|
||||||
const db = tenancy.getGlobalDB()
|
|
||||||
const { id, rev } = ctx.params
|
|
||||||
|
|
||||||
try {
|
|
||||||
await db.remove(id, rev)
|
|
||||||
ctx.body = { message: "Workspace deleted successfully" }
|
|
||||||
} catch (err: any) {
|
|
||||||
ctx.throw(err.status, err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,15 @@
|
||||||
import { Account, AccountMetadata, Ctx } from "@budibase/types"
|
import {
|
||||||
|
Account,
|
||||||
|
AccountMetadata,
|
||||||
|
Ctx,
|
||||||
|
SaveAccountRequest,
|
||||||
|
SaveAccountResponse,
|
||||||
|
} from "@budibase/types"
|
||||||
import * as accounts from "../../../sdk/accounts"
|
import * as accounts from "../../../sdk/accounts"
|
||||||
|
|
||||||
export const save = async (ctx: Ctx<Account, AccountMetadata>) => {
|
export const save = async (
|
||||||
|
ctx: Ctx<SaveAccountRequest, SaveAccountResponse>
|
||||||
|
) => {
|
||||||
const account = ctx.request.body as Account
|
const account = ctx.request.body as Account
|
||||||
let metadata: AccountMetadata = {
|
let metadata: AccountMetadata = {
|
||||||
_id: accounts.metadata.formatAccountMetadataId(account.accountId),
|
_id: accounts.metadata.formatAccountMetadataId(account.accountId),
|
||||||
|
@ -14,7 +22,7 @@ export const save = async (ctx: Ctx<Account, AccountMetadata>) => {
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
export const destroy = async (ctx: any) => {
|
export const destroy = async (ctx: Ctx<void, void>) => {
|
||||||
const accountId = accounts.metadata.formatAccountMetadataId(
|
const accountId = accounts.metadata.formatAccountMetadataId(
|
||||||
ctx.params.accountId
|
ctx.params.accountId
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Ctx, MaintenanceType } from "@budibase/types"
|
import { Ctx, GetEnvironmentResponse, MaintenanceType } from "@budibase/types"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { env as coreEnv, db as dbCore } from "@budibase/backend-core"
|
import { env as coreEnv, db as dbCore } from "@budibase/backend-core"
|
||||||
import nodeFetch from "node-fetch"
|
import nodeFetch from "node-fetch"
|
||||||
|
@ -38,13 +38,13 @@ async function isSqsMissing() {
|
||||||
return !(await isSqsAvailable())
|
return !(await isSqsAvailable())
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetch = async (ctx: Ctx) => {
|
export const fetch = async (ctx: Ctx<void, GetEnvironmentResponse>) => {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
multiTenancy: !!env.MULTI_TENANCY,
|
multiTenancy: !!env.MULTI_TENANCY,
|
||||||
offlineMode: !!coreEnv.OFFLINE_MODE,
|
offlineMode: !!coreEnv.OFFLINE_MODE,
|
||||||
cloud: !env.SELF_HOSTED,
|
cloud: !env.SELF_HOSTED,
|
||||||
accountPortalUrl: env.ACCOUNT_PORTAL_URL,
|
accountPortalUrl: env.ACCOUNT_PORTAL_URL,
|
||||||
disableAccountPortal: env.DISABLE_ACCOUNT_PORTAL,
|
disableAccountPortal: !!env.DISABLE_ACCOUNT_PORTAL,
|
||||||
baseUrl: env.PLATFORM_URL,
|
baseUrl: env.PLATFORM_URL,
|
||||||
isDev: env.isDev() && !env.isTest(),
|
isDev: env.isDev() && !env.isTest(),
|
||||||
maintenance: [],
|
maintenance: [],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { UserCtx } from "@budibase/types"
|
import { GetLogResponse, UserCtx } from "@budibase/types"
|
||||||
import { installation, logging } from "@budibase/backend-core"
|
import { installation, logging } from "@budibase/backend-core"
|
||||||
|
|
||||||
export async function getLogs(ctx: UserCtx) {
|
export async function getLogs(ctx: UserCtx<void, GetLogResponse>) {
|
||||||
const logReadStream = logging.system.getLogReadStream()
|
const logReadStream = logging.system.getLogReadStream()
|
||||||
|
|
||||||
const { installId } = await installation.getInstall()
|
const { installId } = await installation.getInstall()
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
|
import {
|
||||||
|
FetchMigrationDefinitionsResponse,
|
||||||
|
RunGlobalMigrationRequest,
|
||||||
|
UserCtx,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
const { migrate, MIGRATIONS } = require("../../../migrations")
|
const { migrate, MIGRATIONS } = require("../../../migrations")
|
||||||
|
|
||||||
export const runMigrations = async (ctx: any) => {
|
export const runMigrations = async (
|
||||||
|
ctx: UserCtx<RunGlobalMigrationRequest, void>
|
||||||
|
) => {
|
||||||
const options = ctx.request.body
|
const options = ctx.request.body
|
||||||
// don't await as can take a while, just return
|
// don't await as can take a while, just return
|
||||||
migrate(options)
|
migrate(options)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchDefinitions = async (ctx: any) => {
|
export const fetchDefinitions = async (
|
||||||
|
ctx: UserCtx<void, FetchMigrationDefinitionsResponse>
|
||||||
|
) => {
|
||||||
ctx.body = MIGRATIONS
|
ctx.body = MIGRATIONS
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { BBContext } from "@budibase/types"
|
import { SystemRestoreResponse, UserCtx } from "@budibase/types"
|
||||||
import { cache } from "@budibase/backend-core"
|
import { cache } from "@budibase/backend-core"
|
||||||
|
|
||||||
export async function systemRestored(ctx: BBContext) {
|
export async function systemRestored(
|
||||||
|
ctx: UserCtx<void, SystemRestoreResponse>
|
||||||
|
) {
|
||||||
if (!env.SELF_HOSTED) {
|
if (!env.SELF_HOSTED) {
|
||||||
ctx.throw(405, "This operation is not allowed in cloud.")
|
ctx.throw(405, "This operation is not allowed in cloud.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { UserCtx } from "@budibase/types"
|
import { GetTenantInfoResponse, UserCtx } from "@budibase/types"
|
||||||
import * as tenantSdk from "../../../sdk/tenants"
|
import * as tenantSdk from "../../../sdk/tenants"
|
||||||
|
|
||||||
export async function destroy(ctx: UserCtx) {
|
export async function destroy(ctx: UserCtx<void, void>) {
|
||||||
const user = ctx.user!
|
const user = ctx.user!
|
||||||
const tenantId = ctx.params.tenantId
|
const tenantId = ctx.params.tenantId
|
||||||
|
|
||||||
|
@ -18,6 +18,6 @@ export async function destroy(ctx: UserCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function info(ctx: UserCtx) {
|
export async function info(ctx: UserCtx<void, GetTenantInfoResponse>) {
|
||||||
ctx.body = await tenantSdk.tenantInfo(ctx.params.tenantId)
|
ctx.body = await tenantSdk.tenantInfo(ctx.params.tenantId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
import Router from "@koa/router"
|
|
||||||
import * as controller from "../../controllers/global/workspaces"
|
|
||||||
import { auth } from "@budibase/backend-core"
|
|
||||||
import Joi from "joi"
|
|
||||||
|
|
||||||
const router: Router = new Router()
|
|
||||||
|
|
||||||
function buildWorkspaceSaveValidation() {
|
|
||||||
// prettier-ignore
|
|
||||||
return auth.joiValidator.body(Joi.object({
|
|
||||||
_id: Joi.string().optional(),
|
|
||||||
_rev: Joi.string().optional(),
|
|
||||||
name: Joi.string().required(),
|
|
||||||
users: Joi.array().required(),
|
|
||||||
managers: Joi.array().required(),
|
|
||||||
roles: Joi.object({
|
|
||||||
default: Joi.string().optional(),
|
|
||||||
app: Joi.object()
|
|
||||||
.pattern(/.*/, Joi.string())
|
|
||||||
.required()
|
|
||||||
.unknown(true),
|
|
||||||
}).unknown(true).optional(),
|
|
||||||
}).required().unknown(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
router
|
|
||||||
.post(
|
|
||||||
"/api/global/workspaces",
|
|
||||||
auth.adminOnly,
|
|
||||||
buildWorkspaceSaveValidation(),
|
|
||||||
controller.save
|
|
||||||
)
|
|
||||||
.delete("/api/global/workspaces/:id", auth.adminOnly, controller.destroy)
|
|
||||||
.get("/api/global/workspaces", controller.fetch)
|
|
||||||
.get("/api/global/workspaces/:id", controller.find)
|
|
||||||
|
|
||||||
export default router
|
|
|
@ -2,7 +2,6 @@ import Router from "@koa/router"
|
||||||
import { api as pro } from "@budibase/pro"
|
import { api as pro } from "@budibase/pro"
|
||||||
import userRoutes from "./global/users"
|
import userRoutes from "./global/users"
|
||||||
import configRoutes from "./global/configs"
|
import configRoutes from "./global/configs"
|
||||||
import workspaceRoutes from "./global/workspaces"
|
|
||||||
import templateRoutes from "./global/templates"
|
import templateRoutes from "./global/templates"
|
||||||
import emailRoutes from "./global/email"
|
import emailRoutes from "./global/email"
|
||||||
import authRoutes from "./global/auth"
|
import authRoutes from "./global/auth"
|
||||||
|
@ -24,7 +23,6 @@ export const routes: Router[] = [
|
||||||
configRoutes,
|
configRoutes,
|
||||||
userRoutes,
|
userRoutes,
|
||||||
pro.users,
|
pro.users,
|
||||||
workspaceRoutes,
|
|
||||||
authRoutes,
|
authRoutes,
|
||||||
templateRoutes,
|
templateRoutes,
|
||||||
tenantsRoutes,
|
tenantsRoutes,
|
||||||
|
|
Loading…
Reference in New Issue