diff --git a/packages/backend-core/src/middleware/auditLog.ts b/packages/backend-core/src/middleware/auditLog.ts index 9b76bb10b7..2febbf879c 100644 --- a/packages/backend-core/src/middleware/auditLog.ts +++ b/packages/backend-core/src/middleware/auditLog.ts @@ -1,6 +1,6 @@ -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" -export default async (ctx: BBContext | any, next: any) => { +export default async (ctx: Ctx, next: any) => { // Placeholder for audit log middleware return next() } diff --git a/packages/backend-core/src/middleware/csrf.ts b/packages/backend-core/src/middleware/csrf.ts index cced4d5f7d..e20841cca0 100644 --- a/packages/backend-core/src/middleware/csrf.ts +++ b/packages/backend-core/src/middleware/csrf.ts @@ -1,6 +1,6 @@ import { Header } from "../constants" import { buildMatcherRegex, matches } from "./matchers" -import { BBContext, EndpointMatcher } from "@budibase/types" +import { Ctx, EndpointMatcher } from "@budibase/types" /** * GET, HEAD and OPTIONS methods are considered safe operations @@ -36,7 +36,7 @@ export default function ( opts: { noCsrfPatterns: EndpointMatcher[] } = { noCsrfPatterns: [] } ) { const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns) - return async (ctx: BBContext | any, next: any) => { + return async (ctx: Ctx, next: any) => { // don't apply for excluded paths const found = matches(ctx, noCsrfOptions) if (found) { diff --git a/packages/backend-core/src/middleware/internalApi.ts b/packages/backend-core/src/middleware/internalApi.ts index dc73cd6b66..b240738aee 100644 --- a/packages/backend-core/src/middleware/internalApi.ts +++ b/packages/backend-core/src/middleware/internalApi.ts @@ -1,11 +1,11 @@ import { Header } from "../constants" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" import { isValidInternalAPIKey } from "../utils" /** * API Key only endpoint. */ -export default async (ctx: BBContext, next: any) => { +export default async (ctx: Ctx, next: any) => { const apiKey = ctx.request.headers[Header.API_KEY] if (!apiKey) { ctx.throw(403, "Unauthorized") diff --git a/packages/backend-core/src/middleware/matchers.ts b/packages/backend-core/src/middleware/matchers.ts index 757d93a60d..8ed0b4d608 100644 --- a/packages/backend-core/src/middleware/matchers.ts +++ b/packages/backend-core/src/middleware/matchers.ts @@ -1,4 +1,4 @@ -import { BBContext, EndpointMatcher, RegexMatcher } from "@budibase/types" +import { Ctx, EndpointMatcher, RegexMatcher } from "@budibase/types" const PARAM_REGEX = /\/:(.*?)(\/.*)?$/g @@ -27,7 +27,7 @@ export const buildMatcherRegex = ( }) } -export const matches = (ctx: BBContext, options: RegexMatcher[]) => { +export const matches = (ctx: Ctx, options: RegexMatcher[]) => { return options.find(({ regex, method }) => { const urlMatch = regex.test(ctx.request.url) const methodMatch = diff --git a/packages/backend-core/src/middleware/passport/local.ts b/packages/backend-core/src/middleware/passport/local.ts index f1d72cab7a..40e6d294c1 100644 --- a/packages/backend-core/src/middleware/passport/local.ts +++ b/packages/backend-core/src/middleware/passport/local.ts @@ -2,7 +2,7 @@ import { UserStatus } from "../../constants" import { compare } from "../../utils" import * as users from "../../users" import { authError } from "./utils" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" const INVALID_ERR = "Invalid credentials" const EXPIRED = "This account has expired. Please reset your password" @@ -20,7 +20,7 @@ export const options = { * @returns The authenticated user, or errors if they occur */ export async function authenticate( - ctx: BBContext, + ctx: Ctx, email: string, password: string, done: Function diff --git a/packages/backend-core/src/middleware/tenancy.ts b/packages/backend-core/src/middleware/tenancy.ts index 22b7cc213d..e0c1be2a03 100644 --- a/packages/backend-core/src/middleware/tenancy.ts +++ b/packages/backend-core/src/middleware/tenancy.ts @@ -3,7 +3,7 @@ import { getTenantIDFromCtx } from "../tenancy" import { buildMatcherRegex, matches } from "./matchers" import { Header } from "../constants" import { - BBContext, + Ctx, EndpointMatcher, GetTenantIdOptions, TenantResolutionStrategy, @@ -17,7 +17,7 @@ export default function ( const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns) const noTenancyOptions = buildMatcherRegex(noTenancyPatterns) - return async function (ctx: BBContext | any, next: any) { + return async function (ctx: Ctx, next: any) { const allowNoTenant = opts.noTenancyRequired || !!matches(ctx, noTenancyOptions) const tenantOpts: GetTenantIdOptions = { diff --git a/packages/backend-core/src/tenancy/tenancy.ts b/packages/backend-core/src/tenancy/tenancy.ts index 8835960ca5..6096b45800 100644 --- a/packages/backend-core/src/tenancy/tenancy.ts +++ b/packages/backend-core/src/tenancy/tenancy.ts @@ -6,7 +6,7 @@ import { getPlatformURL, } from "../context" import { - BBContext, + Ctx, TenantResolutionStrategy, GetTenantIdOptions, } from "@budibase/types" @@ -37,7 +37,7 @@ export const isUserInAppTenant = (appId: string, user?: any) => { const ALL_STRATEGIES = Object.values(TenantResolutionStrategy) export const getTenantIDFromCtx = ( - ctx: BBContext, + ctx: Ctx, opts: GetTenantIdOptions ): string | undefined => { // exit early if not multi-tenant diff --git a/packages/backend-core/src/utils/tests/utils.spec.ts b/packages/backend-core/src/utils/tests/utils.spec.ts index 4dc3855c35..b5c6283ce2 100644 --- a/packages/backend-core/src/utils/tests/utils.spec.ts +++ b/packages/backend-core/src/utils/tests/utils.spec.ts @@ -5,7 +5,7 @@ import * as db from "../../db" import { Header } from "../../constants" import { newid } from "../../utils" import env from "../../environment" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" describe("utils", () => { const config = new DBTestConfiguration() @@ -109,7 +109,7 @@ describe("utils", () => { }) describe("isServingBuilder", () => { - let ctx: BBContext + let ctx: Ctx const expectResult = (result: boolean) => expect(utils.isServingBuilder(ctx)).toBe(result) @@ -133,7 +133,7 @@ describe("utils", () => { }) describe("isServingBuilderPreview", () => { - let ctx: BBContext + let ctx: Ctx const expectResult = (result: boolean) => expect(utils.isServingBuilderPreview(ctx)).toBe(result) @@ -157,7 +157,7 @@ describe("utils", () => { }) describe("isPublicAPIRequest", () => { - let ctx: BBContext + let ctx: Ctx const expectResult = (result: boolean) => expect(utils.isPublicApiRequest(ctx)).toBe(result) diff --git a/packages/backend-core/tests/core/utilities/structures/koa.ts b/packages/backend-core/tests/core/utilities/structures/koa.ts index f9883dc1b9..c804d3b5f2 100644 --- a/packages/backend-core/tests/core/utilities/structures/koa.ts +++ b/packages/backend-core/tests/core/utilities/structures/koa.ts @@ -1,8 +1,8 @@ import { createMockContext, createMockCookies } from "@shopify/jest-koa-mocks" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" -export const newContext = (): BBContext => { - const ctx = createMockContext() as any +export const newContext = (): Ctx => { + const ctx = createMockContext() as Ctx return { ...ctx, path: "/", diff --git a/packages/server/src/middleware/appInfo.ts b/packages/server/src/middleware/appInfo.ts index 75e40ed473..b62047ec5b 100644 --- a/packages/server/src/middleware/appInfo.ts +++ b/packages/server/src/middleware/appInfo.ts @@ -1,5 +1,5 @@ import { isDevAppID, isProdAppID } from "../db/utils" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" export enum AppType { DEV = "dev", @@ -7,7 +7,7 @@ export enum AppType { } export function middleware({ appType }: { appType?: AppType } = {}) { - return (ctx: BBContext, next: any) => { + return (ctx: Ctx, next: any) => { const appId = ctx.appId if (appType === AppType.DEV && appId && !isDevAppID(appId)) { ctx.throw(400, "Only apps in development support this endpoint") diff --git a/packages/server/src/middleware/joi-validator.ts b/packages/server/src/middleware/joi-validator.ts index 5d783acc80..df09c3efa7 100644 --- a/packages/server/src/middleware/joi-validator.ts +++ b/packages/server/src/middleware/joi-validator.ts @@ -1,9 +1,9 @@ import Joi from "joi" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" function validate(schema: Joi.Schema, property: string) { // Return a Koa middleware function - return (ctx: BBContext, next: any) => { + return (ctx: Ctx, next: any) => { if (!schema) { return next() } diff --git a/packages/server/src/middleware/resourceId.ts b/packages/server/src/middleware/resourceId.ts index 1ad0b2a0c1..b57a8c2d85 100644 --- a/packages/server/src/middleware/resourceId.ts +++ b/packages/server/src/middleware/resourceId.ts @@ -1,4 +1,4 @@ -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" export class ResourceIdGetter { parameter: string @@ -26,7 +26,7 @@ export class ResourceIdGetter { const parameter = this.parameter, main = this.main, sub = this.sub - return (ctx: BBContext, next: any) => { + return (ctx: Ctx, next: any) => { // @ts-ignore const request = ctx.request[parameter] || ctx[parameter] if (request == null) { diff --git a/packages/server/src/middleware/selfhost.ts b/packages/server/src/middleware/selfhost.ts index fd2ca6517b..3571931835 100644 --- a/packages/server/src/middleware/selfhost.ts +++ b/packages/server/src/middleware/selfhost.ts @@ -1,9 +1,9 @@ import env from "../environment" -import { BBContext } from "@budibase/types" +import { Ctx } from "@budibase/types" // if added as a middleware will stop requests unless builder is in self host mode // or cloud is in self host -export default async (ctx: BBContext, next: any) => { +export default async (ctx: Ctx, next: any) => { if (env.SELF_HOSTED) { await next() return diff --git a/packages/types/src/sdk/auth.ts b/packages/types/src/sdk/auth.ts index 5bc75e8377..94180143f9 100644 --- a/packages/types/src/sdk/auth.ts +++ b/packages/types/src/sdk/auth.ts @@ -1,4 +1,4 @@ -import { BBContext } from "./koa" +import { Ctx } from "./koa" import { Hosting } from "./hosting" export interface AuthToken { @@ -32,7 +32,7 @@ export interface ScannedSession { } export interface PlatformLogoutOpts { - ctx: BBContext + ctx: Ctx userId: string keepActiveSession?: boolean }