Merge branch 'master' into bug/budi-7008-i-was-able-to-send-two-invitations-to-the-same-user-email-2
This commit is contained in:
commit
3d73891f5e
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "2.13.5",
|
"version": "2.13.6",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function populateFromDB(appId: string) {
|
||||||
return doWithDB(
|
return doWithDB(
|
||||||
appId,
|
appId,
|
||||||
(db: Database) => {
|
(db: Database) => {
|
||||||
return db.get(DocumentType.APP_METADATA)
|
return db.get<App>(DocumentType.APP_METADATA)
|
||||||
},
|
},
|
||||||
{ skip_setup: true }
|
{ skip_setup: true }
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { ContextMap } from "./types"
|
||||||
export default class Context {
|
export default class Context {
|
||||||
static storage = new AsyncLocalStorage<ContextMap>()
|
static storage = new AsyncLocalStorage<ContextMap>()
|
||||||
|
|
||||||
static run(context: ContextMap, func: any) {
|
static run<T>(context: ContextMap, func: () => T) {
|
||||||
return Context.storage.run(context, () => func())
|
return Context.storage.run(context, () => func())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,17 +98,17 @@ function updateContext(updates: ContextMap): ContextMap {
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
async function newContext(updates: ContextMap, task: any) {
|
async function newContext<T>(updates: ContextMap, task: () => T) {
|
||||||
// see if there already is a context setup
|
// see if there already is a context setup
|
||||||
let context: ContextMap = updateContext(updates)
|
let context: ContextMap = updateContext(updates)
|
||||||
return Context.run(context, task)
|
return Context.run(context, task)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function doInAutomationContext(params: {
|
export async function doInAutomationContext<T>(params: {
|
||||||
appId: string
|
appId: string
|
||||||
automationId: string
|
automationId: string
|
||||||
task: any
|
task: () => T
|
||||||
}): Promise<any> {
|
}): Promise<T> {
|
||||||
const tenantId = getTenantIDFromAppID(params.appId)
|
const tenantId = getTenantIDFromAppID(params.appId)
|
||||||
return newContext(
|
return newContext(
|
||||||
{
|
{
|
||||||
|
@ -144,10 +144,10 @@ export async function doInTenant<T>(
|
||||||
return newContext(updates, task)
|
return newContext(updates, task)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function doInAppContext(
|
export async function doInAppContext<T>(
|
||||||
appId: string | null,
|
appId: string | null,
|
||||||
task: any
|
task: () => T
|
||||||
): Promise<any> {
|
): Promise<T> {
|
||||||
if (!appId && !env.isTest()) {
|
if (!appId && !env.isTest()) {
|
||||||
throw new Error("appId is required")
|
throw new Error("appId is required")
|
||||||
}
|
}
|
||||||
|
@ -165,10 +165,10 @@ export async function doInAppContext(
|
||||||
return newContext(updates, task)
|
return newContext(updates, task)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function doInIdentityContext(
|
export async function doInIdentityContext<T>(
|
||||||
identity: IdentityContext,
|
identity: IdentityContext,
|
||||||
task: any
|
task: () => T
|
||||||
): Promise<any> {
|
): Promise<T> {
|
||||||
if (!identity) {
|
if (!identity) {
|
||||||
throw new Error("identity is required")
|
throw new Error("identity is required")
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,9 @@ export function getAuditLogsDB(): Database {
|
||||||
*/
|
*/
|
||||||
export function getAppDB(opts?: any): Database {
|
export function getAppDB(opts?: any): Database {
|
||||||
const appId = getAppId()
|
const appId = getAppId()
|
||||||
|
if (!appId) {
|
||||||
|
throw new Error("Unable to retrieve app DB - no app ID.")
|
||||||
|
}
|
||||||
return getDB(appId, opts)
|
return getDB(appId, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,7 @@ export class DatabaseImpl implements Database {
|
||||||
|
|
||||||
private readonly couchInfo = getCouchInfo()
|
private readonly couchInfo = getCouchInfo()
|
||||||
|
|
||||||
constructor(dbName?: string, opts?: DatabaseOpts, connection?: string) {
|
constructor(dbName: string, opts?: DatabaseOpts, connection?: string) {
|
||||||
if (dbName == null) {
|
|
||||||
throw new Error("Database name cannot be undefined.")
|
|
||||||
}
|
|
||||||
this.name = dbName
|
this.name = dbName
|
||||||
this.pouchOpts = opts || {}
|
this.pouchOpts = opts || {}
|
||||||
if (connection) {
|
if (connection) {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import env from "../environment"
|
|
||||||
import { directCouchQuery, DatabaseImpl } from "./couch"
|
import { directCouchQuery, DatabaseImpl } from "./couch"
|
||||||
import { CouchFindOptions, Database } from "@budibase/types"
|
import { CouchFindOptions, Database, DatabaseOpts } from "@budibase/types"
|
||||||
|
|
||||||
const dbList = new Set()
|
export function getDB(dbName: string, opts?: DatabaseOpts): Database {
|
||||||
|
|
||||||
export function getDB(dbName?: string, opts?: any): Database {
|
|
||||||
return new DatabaseImpl(dbName, opts)
|
return new DatabaseImpl(dbName, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +11,7 @@ export function getDB(dbName?: string, opts?: any): Database {
|
||||||
export async function doWithDB<T>(
|
export async function doWithDB<T>(
|
||||||
dbName: string,
|
dbName: string,
|
||||||
cb: (db: Database) => Promise<T>,
|
cb: (db: Database) => Promise<T>,
|
||||||
opts = {}
|
opts?: DatabaseOpts
|
||||||
) {
|
) {
|
||||||
const db = getDB(dbName, opts)
|
const db = getDB(dbName, opts)
|
||||||
// need this to be async so that we can correctly close DB after all
|
// need this to be async so that we can correctly close DB after all
|
||||||
|
@ -22,13 +19,6 @@ export async function doWithDB<T>(
|
||||||
return await cb(db)
|
return await cb(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allDbs() {
|
|
||||||
if (!env.isTest()) {
|
|
||||||
throw new Error("Cannot be used outside test environment.")
|
|
||||||
}
|
|
||||||
return [...dbList]
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function directCouchAllDbs(queryString?: string) {
|
export async function directCouchAllDbs(queryString?: string) {
|
||||||
let couchPath = "/_all_dbs"
|
let couchPath = "/_all_dbs"
|
||||||
if (queryString) {
|
if (queryString) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ad9a0085bee0c4f3184acd86cadd872ea9917e88
|
Subproject commit e202f415d9fa540d08cc2ba6e27394fbc22f357b
|
|
@ -337,7 +337,7 @@ export async function destroy(ctx: UserCtx) {
|
||||||
if (datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE) {
|
if (datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE) {
|
||||||
await destroyInternalTablesBySourceId(datasourceId)
|
await destroyInternalTablesBySourceId(datasourceId)
|
||||||
} else {
|
} else {
|
||||||
const queries = await db.allDocs(getQueryParams(datasourceId, null))
|
const queries = await db.allDocs(getQueryParams(datasourceId))
|
||||||
await db.bulkDocs(
|
await db.bulkDocs(
|
||||||
queries.rows.map((row: any) => ({
|
queries.rows.map((row: any) => ({
|
||||||
_id: row.id,
|
_id: row.id,
|
||||||
|
|
|
@ -27,6 +27,10 @@ interface KoaRateLimitOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
const PREFIX = "/api/public/v1"
|
const PREFIX = "/api/public/v1"
|
||||||
|
|
||||||
|
// type can't be known - untyped libraries
|
||||||
|
let limiter: any, rateLimitStore: any
|
||||||
|
if (!env.DISABLE_RATE_LIMITING) {
|
||||||
// allow a lot more requests when in test
|
// allow a lot more requests when in test
|
||||||
const DEFAULT_API_REQ_LIMIT_PER_SEC = env.isTest() ? 100 : 10
|
const DEFAULT_API_REQ_LIMIT_PER_SEC = env.isTest() ? 100 : 10
|
||||||
|
|
||||||
|
@ -37,7 +41,6 @@ function getApiLimitPerSecond(): number {
|
||||||
return parseInt(env.API_REQ_LIMIT_PER_SEC)
|
return parseInt(env.API_REQ_LIMIT_PER_SEC)
|
||||||
}
|
}
|
||||||
|
|
||||||
let rateLimitStore: any = null
|
|
||||||
if (!env.isTest()) {
|
if (!env.isTest()) {
|
||||||
const { password, host, port } = redis.utils.getRedisConnectionDetails()
|
const { password, host, port } = redis.utils.getRedisConnectionDetails()
|
||||||
let options: KoaRateLimitOptions = {
|
let options: KoaRateLimitOptions = {
|
||||||
|
@ -61,17 +64,22 @@ if (!env.isTest()) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// rate limiting, allows for 2 requests per second
|
// rate limiting, allows for 2 requests per second
|
||||||
const limiter = RateLimit.middleware({
|
limiter = RateLimit.middleware({
|
||||||
interval: { sec: 1 },
|
interval: { sec: 1 },
|
||||||
// per ip, per interval
|
// per ip, per interval
|
||||||
max: getApiLimitPerSecond(),
|
max: getApiLimitPerSecond(),
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
console.log("**** PUBLIC API RATE LIMITING DISABLED ****")
|
||||||
|
}
|
||||||
|
|
||||||
const publicRouter = new Router({
|
const publicRouter = new Router({
|
||||||
prefix: PREFIX,
|
prefix: PREFIX,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (limiter) {
|
||||||
publicRouter.use(limiter)
|
publicRouter.use(limiter)
|
||||||
|
}
|
||||||
|
|
||||||
function addMiddleware(
|
function addMiddleware(
|
||||||
endpoints: any,
|
endpoints: any,
|
||||||
|
|
|
@ -94,7 +94,7 @@ export async function externalTrigger(
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
params: { fields: Record<string, any>; timeout?: number },
|
params: { fields: Record<string, any>; timeout?: number },
|
||||||
{ getResponses }: { getResponses?: boolean } = {}
|
{ getResponses }: { getResponses?: boolean } = {}
|
||||||
) {
|
): Promise<any> {
|
||||||
if (
|
if (
|
||||||
automation.definition != null &&
|
automation.definition != null &&
|
||||||
automation.definition.trigger != null &&
|
automation.definition.trigger != null &&
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
VirtualDocumentType,
|
VirtualDocumentType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
DatabaseQueryOpts,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { FieldTypes } from "../constants"
|
import { FieldTypes } from "../constants"
|
||||||
export { DocumentType, VirtualDocumentType } from "@budibase/types"
|
export { DocumentType, VirtualDocumentType } from "@budibase/types"
|
||||||
|
@ -229,7 +230,10 @@ export function getAutomationMetadataParams(otherProps: any = {}) {
|
||||||
/**
|
/**
|
||||||
* Gets parameters for retrieving a query, this is a utility function for the getDocParams function.
|
* Gets parameters for retrieving a query, this is a utility function for the getDocParams function.
|
||||||
*/
|
*/
|
||||||
export function getQueryParams(datasourceId?: Optional, otherProps: any = {}) {
|
export function getQueryParams(
|
||||||
|
datasourceId?: Optional,
|
||||||
|
otherProps: Partial<DatabaseQueryOpts> = {}
|
||||||
|
) {
|
||||||
if (datasourceId == null) {
|
if (datasourceId == null) {
|
||||||
return getDocParams(DocumentType.QUERY, null, otherProps)
|
return getDocParams(DocumentType.QUERY, null, otherProps)
|
||||||
}
|
}
|
||||||
|
@ -256,7 +260,7 @@ export function generateMetadataID(type: string, entityId: string) {
|
||||||
export function getMetadataParams(
|
export function getMetadataParams(
|
||||||
type: string,
|
type: string,
|
||||||
entityId?: Optional,
|
entityId?: Optional,
|
||||||
otherProps: any = {}
|
otherProps: Partial<DatabaseQueryOpts> = {}
|
||||||
) {
|
) {
|
||||||
let docId = `${type}${SEPARATOR}`
|
let docId = `${type}${SEPARATOR}`
|
||||||
if (entityId != null) {
|
if (entityId != null) {
|
||||||
|
@ -269,7 +273,9 @@ export function generateMemoryViewID(viewName: string) {
|
||||||
return `${DocumentType.MEM_VIEW}${SEPARATOR}${viewName}`
|
return `${DocumentType.MEM_VIEW}${SEPARATOR}${viewName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMemoryViewParams(otherProps: any = {}) {
|
export function getMemoryViewParams(
|
||||||
|
otherProps: Partial<DatabaseQueryOpts> = {}
|
||||||
|
) {
|
||||||
return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
|
return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ const environment = {
|
||||||
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
|
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
|
||||||
DISABLE_THREADING: process.env.DISABLE_THREADING,
|
DISABLE_THREADING: process.env.DISABLE_THREADING,
|
||||||
DISABLE_AUTOMATION_LOGS: process.env.DISABLE_AUTOMATION_LOGS,
|
DISABLE_AUTOMATION_LOGS: process.env.DISABLE_AUTOMATION_LOGS,
|
||||||
|
DISABLE_RATE_LIMITING: process.env.DISABLE_RATE_LIMITING,
|
||||||
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||||
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
||||||
SELF_HOSTED: process.env.SELF_HOSTED,
|
SELF_HOSTED: process.env.SELF_HOSTED,
|
||||||
|
|
|
@ -510,13 +510,14 @@ class TestConfiguration {
|
||||||
// create dev app
|
// create dev app
|
||||||
// clear any old app
|
// clear any old app
|
||||||
this.appId = null
|
this.appId = null
|
||||||
await context.doInAppContext(null, async () => {
|
this.app = await context.doInAppContext(null, async () => {
|
||||||
this.app = await this._req(
|
const app = await this._req(
|
||||||
{ name: appName },
|
{ name: appName },
|
||||||
null,
|
null,
|
||||||
controllers.app.create
|
controllers.app.create
|
||||||
)
|
)
|
||||||
this.appId = this.app?.appId!
|
this.appId = app.appId!
|
||||||
|
return app
|
||||||
})
|
})
|
||||||
return await context.doInAppContext(this.appId, async () => {
|
return await context.doInAppContext(this.appId, async () => {
|
||||||
// create production app
|
// create production app
|
||||||
|
@ -525,7 +526,7 @@ class TestConfiguration {
|
||||||
this.allApps.push(this.prodApp)
|
this.allApps.push(this.prodApp)
|
||||||
this.allApps.push(this.app)
|
this.allApps.push(this.app)
|
||||||
|
|
||||||
return this.app
|
return this.app!
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +538,7 @@ class TestConfiguration {
|
||||||
|
|
||||||
return context.doInAppContext(prodAppId, async () => {
|
return context.doInAppContext(prodAppId, async () => {
|
||||||
const db = context.getProdAppDB()
|
const db = context.getProdAppDB()
|
||||||
return await db.get(dbCore.DocumentType.APP_METADATA)
|
return await db.get<App>(dbCore.DocumentType.APP_METADATA)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ class Orchestrator {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute() {
|
async execute(): Promise<any> {
|
||||||
// this will retrieve from context created at start of thread
|
// this will retrieve from context created at start of thread
|
||||||
this._context.env = await sdkUtils.getEnvironmentVariables()
|
this._context.env = await sdkUtils.getEnvironmentVariables()
|
||||||
let automation = this._automation
|
let automation = this._automation
|
||||||
|
|
|
@ -7,7 +7,9 @@ export enum PlanType {
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
PREMIUM = "premium",
|
PREMIUM = "premium",
|
||||||
PREMIUM_PLUS = "premium_plus",
|
PREMIUM_PLUS = "premium_plus",
|
||||||
|
/** @deprecated */
|
||||||
BUSINESS = "business",
|
BUSINESS = "business",
|
||||||
|
ENTERPRISE_BASIC = "enterprise_basic",
|
||||||
ENTERPRISE = "enterprise",
|
ENTERPRISE = "enterprise",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
"test:self:ci": "yarn run test --testPathIgnorePatterns=\\.integration\\. \\.cloud\\. \\.licensing\\.",
|
"test:self:ci": "yarn run test --testPathIgnorePatterns=\\.integration\\. \\.cloud\\. \\.licensing\\.",
|
||||||
"serve:test:self:ci": "start-server-and-test dev:built http://localhost:4001/health test:self:ci",
|
"serve:test:self:ci": "start-server-and-test dev:built http://localhost:4001/health test:self:ci",
|
||||||
"serve": "start-server-and-test dev:built http://localhost:4001/health",
|
"serve": "start-server-and-test dev:built http://localhost:4001/health",
|
||||||
"dev:built": "cd ../ && yarn dev:built"
|
"dev:built": "cd ../ && DISABLE_RATE_LIMITING=1 yarn dev:built"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@budibase/types": "^2.3.17",
|
"@budibase/types": "^2.3.17",
|
||||||
|
|
Loading…
Reference in New Issue