@budibase/backend-core
Advanced tools
Comparing version 1.0.49-alpha.5 to 1.0.49-alpha.6
module.exports = { | ||
...require("./src/db/utils"), | ||
...require("./src/db/constants"), | ||
...require("./src/db"), | ||
...require("./src/db/views"), | ||
} |
@@ -1,1 +0,1 @@ | ||
module.exports = require("./src/tenancy/deprovision") | ||
module.exports = require("./src/context/deprovision") |
{ | ||
"name": "@budibase/backend-core", | ||
"version": "1.0.49-alpha.5", | ||
"version": "1.0.49-alpha.6", | ||
"description": "Budibase backend core libraries used in server and worker", | ||
@@ -44,3 +44,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "beefc0158cc41174467c0034db32a618178ff9f1" | ||
"gitHead": "7f6bc74ccc8f66f1a44c045f47bdb6604dcbb0b8" | ||
} |
@@ -35,1 +35,5 @@ exports.SEPARATOR = "_" | ||
} | ||
exports.APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR | ||
exports.APP_DEV = exports.APP_DEV_PREFIX = | ||
exports.DocumentTypes.APP_DEV + exports.SEPARATOR |
@@ -5,4 +5,10 @@ const { newid } = require("../hashing") | ||
const env = require("../environment") | ||
const { StaticDatabases, SEPARATOR, DocumentTypes } = require("./constants") | ||
const { | ||
StaticDatabases, | ||
SEPARATOR, | ||
DocumentTypes, | ||
APP_PREFIX, | ||
APP_DEV, | ||
} = require("./constants") | ||
const { | ||
getTenantId, | ||
@@ -16,5 +22,10 @@ getTenantIDFromAppID, | ||
const { checkSlashesInUrl } = require("../helpers") | ||
const { | ||
isDevApp, | ||
isProdAppID, | ||
isDevAppID, | ||
getDevelopmentAppID, | ||
getProdAppID, | ||
} = require("./conversions") | ||
const NO_APP_ERROR = "No app provided" | ||
const UNICODE_MAX = "\ufff0" | ||
@@ -29,6 +40,11 @@ | ||
exports.DocumentTypes = DocumentTypes | ||
exports.APP_PREFIX = DocumentTypes.APP + SEPARATOR | ||
exports.APP_DEV = exports.APP_DEV_PREFIX = DocumentTypes.APP_DEV + SEPARATOR | ||
exports.APP_PREFIX = APP_PREFIX | ||
exports.APP_DEV = exports.APP_DEV_PREFIX = APP_DEV | ||
exports.SEPARATOR = SEPARATOR | ||
exports.getTenantIDFromAppID = getTenantIDFromAppID | ||
exports.isDevApp = isDevApp | ||
exports.isProdAppID = isProdAppID | ||
exports.isDevAppID = isDevAppID | ||
exports.getDevelopmentAppID = getDevelopmentAppID | ||
exports.getProdAppID = getProdAppID | ||
@@ -58,23 +74,2 @@ /** | ||
exports.isDevAppID = appId => { | ||
if (!appId) { | ||
throw NO_APP_ERROR | ||
} | ||
return appId.startsWith(exports.APP_DEV_PREFIX) | ||
} | ||
exports.isProdAppID = appId => { | ||
if (!appId) { | ||
throw NO_APP_ERROR | ||
} | ||
return appId.startsWith(exports.APP_PREFIX) && !exports.isDevAppID(appId) | ||
} | ||
function isDevApp(app) { | ||
if (!app) { | ||
throw NO_APP_ERROR | ||
} | ||
return exports.isDevAppID(app.appId) | ||
} | ||
/** | ||
@@ -164,25 +159,2 @@ * Generates a new workspace ID. | ||
/** | ||
* Convert a development app ID to a deployed app ID. | ||
*/ | ||
exports.getDeployedAppID = appId => { | ||
// if dev, convert it | ||
if (appId.startsWith(exports.APP_DEV_PREFIX)) { | ||
const id = appId.split(exports.APP_DEV_PREFIX)[1] | ||
return `${exports.APP_PREFIX}${id}` | ||
} | ||
return appId | ||
} | ||
/** | ||
* Convert a deployed app ID to a development app ID. | ||
*/ | ||
exports.getDevelopmentAppID = appId => { | ||
if (!appId.startsWith(exports.APP_DEV_PREFIX)) { | ||
const id = appId.split(exports.APP_PREFIX)[1] | ||
return `${exports.APP_DEV_PREFIX}${id}` | ||
} | ||
return appId | ||
} | ||
exports.getCouchUrl = () => { | ||
@@ -233,3 +205,3 @@ if (!env.COUCH_DB_URL) return | ||
let tenantId = getTenantId() | ||
if (!env.MULTI_TENANCY || tenantId == DEFAULT_TENANT_ID) { | ||
if (!env.MULTI_TENANCY || tenantId === DEFAULT_TENANT_ID) { | ||
// just get all DBs when: | ||
@@ -259,7 +231,6 @@ // - single tenancy | ||
* enumerate the entire CouchDB cluster and get the list of databases (every app). | ||
* NOTE: this operation is fine in self hosting, but cannot be used when hosting many | ||
* different users/companies apps as there is no security around it - all apps are returned. | ||
* @return {Promise<object[]>} returns the app information document stored in each app database. | ||
*/ | ||
exports.getAllApps = async (CouchDB, { dev, all, idsOnly } = {}) => { | ||
exports.getAllApps = async ({ dev, all, idsOnly } = {}) => { | ||
const CouchDB = getCouch() | ||
let tenantId = getTenantId() | ||
@@ -320,4 +291,4 @@ if (!env.MULTI_TENANCY && !tenantId) { | ||
*/ | ||
exports.getDeployedAppIDs = async CouchDB => { | ||
return (await exports.getAllApps(CouchDB, { idsOnly: true })).filter( | ||
exports.getProdAppIDs = async () => { | ||
return (await exports.getAllApps({ idsOnly: true })).filter( | ||
id => !exports.isDevAppID(id) | ||
@@ -330,4 +301,4 @@ ) | ||
*/ | ||
exports.getDevAppIDs = async CouchDB => { | ||
return (await exports.getAllApps(CouchDB, { idsOnly: true })).filter(id => | ||
exports.getDevAppIDs = async () => { | ||
return (await exports.getAllApps({ idsOnly: true })).filter(id => | ||
exports.isDevAppID(id) | ||
@@ -337,3 +308,4 @@ ) | ||
exports.dbExists = async (CouchDB, dbName) => { | ||
exports.dbExists = async dbName => { | ||
const CouchDB = getCouch() | ||
let exists = false | ||
@@ -340,0 +312,0 @@ try { |
@@ -6,4 +6,5 @@ const { | ||
DEFAULT_TENANT_ID, | ||
updateAppId, | ||
} = require("../tenancy") | ||
const ContextFactory = require("../tenancy/FunctionContext") | ||
const ContextFactory = require("../context/FunctionContext") | ||
const { getTenantIDFromAppID } = require("../db/utils") | ||
@@ -25,3 +26,4 @@ | ||
updateTenantId(tenantId) | ||
updateAppId(appId) | ||
}) | ||
} |
const { setTenantId } = require("../tenancy") | ||
const ContextFactory = require("../tenancy/FunctionContext") | ||
const ContextFactory = require("../context/FunctionContext") | ||
const { buildMatcherRegex, matches } = require("./matchers") | ||
@@ -4,0 +4,0 @@ |
@@ -1,2 +0,1 @@ | ||
const { getDB } = require("../db") | ||
const { cloneDeep } = require("lodash/fp") | ||
@@ -10,2 +9,4 @@ const { BUILTIN_PERMISSION_IDS } = require("./permissions") | ||
} = require("../db/utils") | ||
const { getAppDB } = require("../context") | ||
const { getDB } = require("../db") | ||
@@ -115,7 +116,6 @@ const BUILTIN_IDS = { | ||
* to check if the role inherits any others. | ||
* @param {string} appId The app in which to look for the role. | ||
* @param {string|null} roleId The level ID to lookup. | ||
* @returns {Promise<Role|object|null>} The role object, which may contain an "inherits" property. | ||
*/ | ||
exports.getRole = async (appId, roleId) => { | ||
exports.getRole = async roleId => { | ||
if (!roleId) { | ||
@@ -133,3 +133,3 @@ return null | ||
try { | ||
const db = getDB(appId) | ||
const db = getAppDB() | ||
const dbRole = await db.get(exports.getDBRoleID(roleId)) | ||
@@ -151,7 +151,7 @@ role = Object.assign(role, dbRole) | ||
*/ | ||
async function getAllUserRoles(appId, userRoleId) { | ||
async function getAllUserRoles(userRoleId) { | ||
if (!userRoleId) { | ||
return [BUILTIN_IDS.BASIC] | ||
} | ||
let currentRole = await exports.getRole(appId, userRoleId) | ||
let currentRole = await exports.getRole(userRoleId) | ||
let roles = currentRole ? [currentRole] : [] | ||
@@ -166,3 +166,3 @@ let roleIds = [userRoleId] | ||
roleIds.push(currentRole.inherits) | ||
currentRole = await exports.getRole(appId, currentRole.inherits) | ||
currentRole = await exports.getRole(currentRole.inherits) | ||
roles.push(currentRole) | ||
@@ -176,3 +176,2 @@ } | ||
* to determine if a user can access something that requires a specific role. | ||
* @param {string} appId The ID of the application from which roles should be obtained. | ||
* @param {string} userRoleId The user's role ID, this can be found in their access token. | ||
@@ -183,9 +182,5 @@ * @param {object} opts Various options, such as whether to only retrieve the IDs (default true). | ||
*/ | ||
exports.getUserRoleHierarchy = async ( | ||
appId, | ||
userRoleId, | ||
opts = { idOnly: true } | ||
) => { | ||
exports.getUserRoleHierarchy = async (userRoleId, opts = { idOnly: true }) => { | ||
// special case, if they don't have a role then they are a public user | ||
const roles = await getAllUserRoles(appId, userRoleId) | ||
const roles = await getAllUserRoles(userRoleId) | ||
return opts.idOnly ? roles.map(role => role._id) : roles | ||
@@ -196,7 +191,6 @@ } | ||
* Given an app ID this will retrieve all of the roles that are currently within that app. | ||
* @param {string} appId The ID of the app to retrieve the roles from. | ||
* @return {Promise<object[]>} An array of the role objects that were found. | ||
*/ | ||
exports.getAllRoles = async appId => { | ||
const db = getDB(appId) | ||
const db = appId ? getDB(appId) : getAppDB() | ||
const body = await db.allDocs( | ||
@@ -229,4 +223,3 @@ getRoleParams(null, { | ||
/** | ||
* This retrieves the required role/ | ||
* @param appId | ||
* This retrieves the required role | ||
* @param permLevel | ||
@@ -238,7 +231,6 @@ * @param resourceId | ||
exports.getRequiredResourceRole = async ( | ||
appId, | ||
permLevel, | ||
{ resourceId, subResourceId } | ||
) => { | ||
const roles = await exports.getAllRoles(appId) | ||
const roles = await exports.getAllRoles() | ||
let main = [], | ||
@@ -264,4 +256,3 @@ sub = [] | ||
class AccessController { | ||
constructor(appId) { | ||
this.appId = appId | ||
constructor() { | ||
this.userHierarchies = {} | ||
@@ -284,3 +275,3 @@ } | ||
if (!roleIds) { | ||
roleIds = await exports.getUserRoleHierarchy(this.appId, userRoleId) | ||
roleIds = await exports.getUserRoleHierarchy(userRoleId) | ||
this.userHierarchies[userRoleId] = roleIds | ||
@@ -287,0 +278,0 @@ } |
module.exports = { | ||
...require("./context"), | ||
...require("../context"), | ||
...require("./tenancy"), | ||
} |
const { getDB } = require("../db") | ||
const { SEPARATOR, StaticDatabases, DocumentTypes } = require("../db/constants") | ||
const { getTenantId, DEFAULT_TENANT_ID, isMultiTenant } = require("./context") | ||
const { getTenantId, DEFAULT_TENANT_ID, isMultiTenant } = require("../context") | ||
const env = require("../environment") | ||
@@ -5,0 +5,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161524
74
4084