PR comments and fixes.

This commit is contained in:
mike12345567 2024-12-05 11:36:56 +00:00
parent 83448febf4
commit 48379021ef
7 changed files with 25 additions and 14 deletions

View File

@ -1,6 +1,10 @@
import { Ctx } from "@budibase/types" import { Ctx } from "@budibase/types"
import { Middleware, Next } from "koa"
export default async (ctx: Ctx, next: any) => { // this middleware exists purely to be overridden by middlewares supplied by the @budibase/pro library
const middleware = (async (ctx: Ctx, next: Next) => {
// Placeholder for audit log middleware // Placeholder for audit log middleware
return next() return next()
} }) as Middleware
export default middleware

View File

@ -8,6 +8,7 @@ import {
GetTenantIdOptions, GetTenantIdOptions,
TenantResolutionStrategy, TenantResolutionStrategy,
} from "@budibase/types" } from "@budibase/types"
import { Next, Middleware } from "koa"
export default function ( export default function (
allowQueryStringPatterns: EndpointMatcher[], allowQueryStringPatterns: EndpointMatcher[],
@ -17,7 +18,7 @@ export default function (
const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns) const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns)
const noTenancyOptions = buildMatcherRegex(noTenancyPatterns) const noTenancyOptions = buildMatcherRegex(noTenancyPatterns)
return async function (ctx: Ctx, next: any) { return async function (ctx: Ctx, next: Next) {
const allowNoTenant = const allowNoTenant =
opts.noTenancyRequired || !!matches(ctx, noTenancyOptions) opts.noTenancyRequired || !!matches(ctx, noTenancyOptions)
const tenantOpts: GetTenantIdOptions = { const tenantOpts: GetTenantIdOptions = {
@ -32,5 +33,5 @@ export default function (
const tenantId = getTenantIDFromCtx(ctx, tenantOpts) const tenantId = getTenantIDFromCtx(ctx, tenantOpts)
ctx.set(Header.TENANT_ID, tenantId as string) ctx.set(Header.TENANT_ID, tenantId as string)
return doInTenant(tenantId, next) return doInTenant(tenantId, next)
} } as Middleware
} }

View File

@ -58,12 +58,9 @@ if (apiEnabled()) {
}) })
) )
.use(pro.licensing()) .use(pro.licensing())
// @ts-ignore
.use(currentApp) .use(currentApp)
.use(auth.auditLog) .use(auth.auditLog)
// @ts-ignore
.use(migrations) .use(migrations)
// @ts-ignore
.use(cleanup) .use(cleanup)
// authenticated routes // authenticated routes

View File

@ -1,8 +1,9 @@
import { UserCtx } from "@budibase/types" import { UserCtx } from "@budibase/types"
import { checkMissingMigrations } from "../appMigrations" import { checkMissingMigrations } from "../appMigrations"
import env from "../environment" import env from "../environment"
import { Middleware, Next } from "koa"
export default async (ctx: UserCtx, next: any) => { const middleware = (async (ctx: UserCtx, next: Next) => {
const { appId } = ctx const { appId } = ctx
// migrations can be disabled via environment variable if you // migrations can be disabled via environment variable if you
@ -16,4 +17,6 @@ export default async (ctx: UserCtx, next: any) => {
} }
return checkMissingMigrations(ctx, next, appId) return checkMissingMigrations(ctx, next, appId)
} }) as Middleware
export default middleware

View File

@ -1,8 +1,9 @@
import { Ctx } from "@budibase/types" import { Ctx } from "@budibase/types"
import { context } from "@budibase/backend-core" import { context } from "@budibase/backend-core"
import { tracer } from "dd-trace" import { tracer } from "dd-trace"
import { Middleware, Next } from "koa"
export default async (ctx: Ctx, next: any) => { const middleware = (async (ctx: Ctx, next: Next) => {
const resp = await next() const resp = await next()
const current = context.getCurrentContext() const current = context.getCurrentContext()
@ -30,4 +31,6 @@ export default async (ctx: Ctx, next: any) => {
} }
return resp return resp
} }) as Middleware
export default middleware

View File

@ -13,8 +13,9 @@ import env from "../environment"
import { isWebhookEndpoint, isBrowser, isApiKey } from "./utils" import { isWebhookEndpoint, isBrowser, isApiKey } from "./utils"
import { UserCtx, ContextUser } from "@budibase/types" import { UserCtx, ContextUser } from "@budibase/types"
import tracer from "dd-trace" import tracer from "dd-trace"
import { Middleware, Next } from "koa"
export default async (ctx: UserCtx, next: any) => { const middleware = (async (ctx: UserCtx, next: Next) => {
// try to get the appID from the request // try to get the appID from the request
let requestAppId = await utils.getAppIdFromCtx(ctx) let requestAppId = await utils.getAppIdFromCtx(ctx)
if (!requestAppId) { if (!requestAppId) {
@ -116,4 +117,6 @@ export default async (ctx: UserCtx, next: any) => {
return next() return next()
}) })
} }) as Middleware
export default middleware

View File

@ -47,7 +47,7 @@ export interface BBRequest<RequestBody> extends Request {
export interface Ctx<RequestBody = any, ResponseBody = any> extends Context { export interface Ctx<RequestBody = any, ResponseBody = any> extends Context {
request: BBRequest<RequestBody> request: BBRequest<RequestBody>
body: ResponseBody body: ResponseBody
userAgent: UserAgentContext["userAgent"] userAgent?: UserAgentContext["userAgent"]
state: { nonce?: string } state: { nonce?: string }
} }