Replacing BBContext where its still used in backend-core and middlewares.
This commit is contained in:
parent
ecf4ea5826
commit
cb49beb317
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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: "/",
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue