Some updates, typescripting some more APIs, as well as fixing a lot of Router creation which did not specify the 'new' operator.
This commit is contained in:
parent
c382b86fb2
commit
67d9495481
|
@ -15,7 +15,7 @@ A package that handles all common components across the Budibase organisation. Y
|
||||||
1. Create a file: `Headline.svelte`
|
1. Create a file: `Headline.svelte`
|
||||||
2. Create a Svench file: `Headline.svench`
|
2. Create a Svench file: `Headline.svench`
|
||||||
3. Build component and add variants to the Svench file.
|
3. Build component and add variants to the Svench file.
|
||||||
4. Once done, re-export the file in `src/index.js`.
|
4. Once done, re-export the file in `src/index.ts`.
|
||||||
5. Publish, update the package in the main project and profit.
|
5. Publish, update the package in the main project and profit.
|
||||||
|
|
||||||
## Guidelines
|
## Guidelines
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { terser } from "rollup-plugin-terser"
|
||||||
import postcss from "rollup-plugin-postcss"
|
import postcss from "rollup-plugin-postcss"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: "src/index.js",
|
input: "src/index.ts",
|
||||||
output: {
|
output: {
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
format: "esm",
|
format: "esm",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/// <reference types="cypress" />
|
/// <reference types="cypress" />
|
||||||
// ***********************************************************
|
// ***********************************************************
|
||||||
// This example plugins/index.js can be used to load plugins
|
// This example plugins/index.ts can be used to load plugins
|
||||||
//
|
//
|
||||||
// You can change the location of this file or turn off loading
|
// You can change the location of this file or turn off loading
|
||||||
// the plugins file with the 'pluginsFile' configuration option.
|
// the plugins file with the 'pluginsFile' configuration option.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// ***********************************************************
|
// ***********************************************************
|
||||||
// This example support/index.js is processed and
|
// This example support/index.ts is processed and
|
||||||
// loaded automatically before your test files.
|
// loaded automatically before your test files.
|
||||||
//
|
//
|
||||||
// This is a great place to put global configuration and
|
// This is a great place to put global configuration and
|
||||||
|
|
|
@ -8,7 +8,7 @@ their settings, and know how to correctly interact with them.
|
||||||
|
|
||||||
### Component Definitions
|
### Component Definitions
|
||||||
|
|
||||||
The object key is the name of the component, as exported by `index.js`.
|
The object key is the name of the component, as exported by `index.ts`.
|
||||||
|
|
||||||
- **name** - the name displayed in the builder
|
- **name** - the name displayed in the builder
|
||||||
- **description** - not currently used
|
- **description** - not currently used
|
||||||
|
|
|
@ -19,7 +19,7 @@ const ignoredWarnings = [
|
||||||
]
|
]
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: "src/index.js",
|
input: "src/index.ts",
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { Layout, Select, Body } from "@budibase/bbui"
|
import { Layout, Select, Body } from "@budibase/bbui"
|
||||||
import { componentStore } from "stores/index.js"
|
import { componentStore } from "stores/index.ts"
|
||||||
import DevToolsStat from "./DevToolsStat.svelte"
|
import DevToolsStat from "./DevToolsStat.svelte"
|
||||||
|
|
||||||
const ReadableBindingMap = {
|
const ReadableBindingMap = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { Layout, Toggle } from "@budibase/bbui"
|
import { Layout, Toggle } from "@budibase/bbui"
|
||||||
import DevToolsStat from "./DevToolsStat.svelte"
|
import DevToolsStat from "./DevToolsStat.svelte"
|
||||||
import { componentStore } from "stores/index.js"
|
import { componentStore } from "stores/index.ts"
|
||||||
import { getSettingsDefinition } from "utils/componentProps.js"
|
import { getSettingsDefinition } from "utils/componentProps.js"
|
||||||
|
|
||||||
let showEnrichedSettings = true
|
let showEnrichedSettings = true
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
script: "dist/index.js",
|
script: "dist/index.ts",
|
||||||
instances: "max",
|
instances: "max",
|
||||||
exec_mode: "cluster",
|
exec_mode: "cluster",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
const { outputProcessing } = require("../../utilities/rowProcessor")
|
import { outputProcessing } from "../../utilities/rowProcessor"
|
||||||
const { InternalTables } = require("../../db/utils")
|
import { InternalTables } from "../../db/utils"
|
||||||
const { getFullUser } = require("../../utilities/users")
|
import { getFullUser } from "../../utilities/users"
|
||||||
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
import { roles, context } from "@budibase/backend-core"
|
||||||
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the attributes that are session based to the current user.
|
* Add the attributes that are session based to the current user.
|
||||||
*/
|
*/
|
||||||
const addSessionAttributesToUser = ctx => {
|
const addSessionAttributesToUser = (ctx: any) => {
|
||||||
if (ctx.user) {
|
if (ctx.user) {
|
||||||
ctx.body.license = ctx.user.license
|
ctx.body.license = ctx.user.license
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchSelf = async ctx => {
|
export async function fetchSelf(ctx: any) {
|
||||||
let userId = ctx.user.userId || ctx.user._id
|
let userId = ctx.user.userId || ctx.user._id
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (!userId || !ctx.isAuthenticated) {
|
if (!userId || !ctx.isAuthenticated) {
|
||||||
|
@ -27,8 +26,8 @@ exports.fetchSelf = async ctx => {
|
||||||
// forward the csrf token from the session
|
// forward the csrf token from the session
|
||||||
user.csrfToken = ctx.user.csrfToken
|
user.csrfToken = ctx.user.csrfToken
|
||||||
|
|
||||||
if (getAppId()) {
|
if (context.getAppId()) {
|
||||||
const db = getAppDB()
|
const db = context.getAppDB()
|
||||||
// remove the full roles structure
|
// remove the full roles structure
|
||||||
delete user.roles
|
delete user.roles
|
||||||
try {
|
try {
|
||||||
|
@ -41,10 +40,10 @@ exports.fetchSelf = async ctx => {
|
||||||
...user,
|
...user,
|
||||||
...metadata,
|
...metadata,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
let response
|
let response
|
||||||
// user didn't exist in app, don't pretend they do
|
// user didn't exist in app, don't pretend they do
|
||||||
if (user.roleId === BUILTIN_ROLE_IDS.PUBLIC) {
|
if (user.roleId === roles.BUILTIN_ROLE_IDS.PUBLIC) {
|
||||||
response = {}
|
response = {}
|
||||||
}
|
}
|
||||||
// user has a role of some sort, return them
|
// user has a role of some sort, return them
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../controllers/analytics")
|
const controller = require("../controllers/analytics")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get("/api/bbtel", controller.isEnabled)
|
router.get("/api/bbtel", controller.isEnabled)
|
||||||
router.post("/api/bbtel/ping", controller.ping)
|
router.post("/api/bbtel/ping", controller.ping)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/apikeys")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/keys", authorized(BUILDER), controller.fetch)
|
.get("/api/keys", authorized(BUILDER), controller.fetch)
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
const Router = require("@koa/router")
|
|
||||||
const controller = require("../controllers/auth")
|
|
||||||
|
|
||||||
const router = Router()
|
|
||||||
|
|
||||||
router.get("/api/self", controller.fetchSelf)
|
|
||||||
|
|
||||||
module.exports = router
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import Router from "@koa/router"
|
||||||
|
import * as controller from "../controllers/auth"
|
||||||
|
|
||||||
|
const router = new Router()
|
||||||
|
|
||||||
|
router.get("/api/self", controller.fetchSelf)
|
||||||
|
|
||||||
|
export default router
|
|
@ -13,7 +13,7 @@ const {
|
||||||
} = require("../../middleware/appInfo")
|
} = require("../../middleware/appInfo")
|
||||||
const { automationValidator } = require("./utils/validators")
|
const { automationValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get(
|
.get(
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/backup")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
|
router.get("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/cloud")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/cloud/export", authorized(BUILDER), controller.exportApps)
|
.get("/api/cloud/export", authorized(BUILDER), controller.exportApps)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/component")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
"/api/:appId/components/definitions",
|
"/api/:appId/components/definitions",
|
||||||
|
|
|
@ -11,7 +11,7 @@ const {
|
||||||
datasourceQueryValidator,
|
datasourceQueryValidator,
|
||||||
} = require("./utils/validators")
|
} = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/deploy")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/deployments", authorized(BUILDER), controller.fetchDeployments)
|
.get("/api/deployments", authorized(BUILDER), controller.fetchDeployments)
|
||||||
|
|
|
@ -4,7 +4,7 @@ const env = require("../../environment")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function redirectPath(path) {
|
function redirectPath(path) {
|
||||||
router
|
router
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/integration")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/integrations", authorized(BUILDER), controller.fetch)
|
.get("/api/integrations", authorized(BUILDER), controller.fetch)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const controller = require("../controllers/layout")
|
const controller = require("../controllers/layout")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/layouts", authorized(BUILDER), controller.save)
|
.post("/api/layouts", authorized(BUILDER), controller.save)
|
||||||
|
|
|
@ -7,7 +7,7 @@ const {
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.post(
|
.post(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const migrationsController = require("../controllers/migrations")
|
const migrationsController = require("../controllers/migrations")
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
const { internalApi } = require("@budibase/backend-core/auth")
|
const { internalApi } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
router
|
router
|
||||||
|
|
|
@ -4,7 +4,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const { permissionValidator } = require("./utils/validators")
|
const { permissionValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/permission/builtin", authorized(BUILDER), controller.fetchBuiltin)
|
.get("/api/permission/builtin", authorized(BUILDER), controller.fetchBuiltin)
|
||||||
|
|
|
@ -16,7 +16,7 @@ const {
|
||||||
generateQueryValidation,
|
generateQueryValidation,
|
||||||
} = require("../controllers/query/validation")
|
} = require("../controllers/query/validation")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/queries", authorized(BUILDER), queryController.fetch)
|
.get("/api/queries", authorized(BUILDER), queryController.fetch)
|
||||||
|
|
|
@ -4,7 +4,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const { roleValidator } = require("./utils/validators")
|
const { roleValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/roles", authorized(BUILDER), roleValidator(), controller.save)
|
.post("/api/roles", authorized(BUILDER), roleValidator(), controller.save)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const controller = require("../controllers/routing")
|
const controller = require("../controllers/routing")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
// gets correct structure for user role
|
// gets correct structure for user role
|
||||||
|
|
|
@ -4,7 +4,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const { screenValidator } = require("./utils/validators")
|
const { screenValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/screens", authorized(BUILDER), controller.fetch)
|
.get("/api/screens", authorized(BUILDER), controller.fetch)
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/script")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.post("/api/script", authorized(BUILDER), controller.save)
|
router.post("/api/script", authorized(BUILDER), controller.save)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ const {
|
||||||
} = require("@budibase/backend-core/permissions")
|
} = require("@budibase/backend-core/permissions")
|
||||||
const { tableValidator } = require("./utils/validators")
|
const { tableValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@ const controller = require("../controllers/templates")
|
||||||
const authorized = require("../../middleware/authorized")
|
const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/templates", authorized(BUILDER), controller.fetch)
|
.get("/api/templates", authorized(BUILDER), controller.fetch)
|
||||||
|
|
|
@ -6,7 +6,7 @@ const {
|
||||||
PermissionTypes,
|
PermissionTypes,
|
||||||
} = require("@budibase/backend-core/permissions")
|
} = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get(
|
.get(
|
||||||
|
|
|
@ -9,7 +9,7 @@ const {
|
||||||
PermissionLevels,
|
PermissionLevels,
|
||||||
} = require("@budibase/backend-core/permissions")
|
} = require("@budibase/backend-core/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/views/export", authorized(BUILDER), viewController.exportView)
|
.get("/api/views/export", authorized(BUILDER), viewController.exportView)
|
||||||
|
|
|
@ -4,7 +4,7 @@ const authorized = require("../../middleware/authorized")
|
||||||
const { BUILDER } = require("@budibase/backend-core/permissions")
|
const { BUILDER } = require("@budibase/backend-core/permissions")
|
||||||
const { webhookValidator } = require("./utils/validators")
|
const { webhookValidator } = require("./utils/validators")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/webhooks", authorized(BUILDER), controller.fetch)
|
.get("/api/webhooks", authorized(BUILDER), controller.fetch)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
script: "./dist/index.js",
|
script: "./dist/index.ts",
|
||||||
instances: "max",
|
instances: "max",
|
||||||
exec_mode: "cluster",
|
exec_mode: "cluster",
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,7 +30,7 @@ function cleanupDevInfo(info: any) {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.generateAPIKey = async (ctx: any) => {
|
export async function generateAPIKey(ctx: any) {
|
||||||
let userId
|
let userId
|
||||||
let apiKey
|
let apiKey
|
||||||
if (env.isTest() && ctx.request.body.userId) {
|
if (env.isTest() && ctx.request.body.userId) {
|
||||||
|
@ -54,7 +54,7 @@ exports.generateAPIKey = async (ctx: any) => {
|
||||||
ctx.body = cleanupDevInfo(devInfo)
|
ctx.body = cleanupDevInfo(devInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchAPIKey = async (ctx: any) => {
|
export async function fetchAPIKey(ctx: any) {
|
||||||
const db = tenancy.getGlobalDB()
|
const db = tenancy.getGlobalDB()
|
||||||
const id = dbCore.generateDevInfoID(ctx.user._id)
|
const id = dbCore.generateDevInfoID(ctx.user._id)
|
||||||
let devInfo
|
let devInfo
|
||||||
|
@ -103,7 +103,7 @@ const sanitiseUserUpdate = (ctx: any) => {
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getSelf = async (ctx: any) => {
|
export async function getSelf(ctx: any) {
|
||||||
if (!ctx.user) {
|
if (!ctx.user) {
|
||||||
ctx.throw(403, "User not logged in")
|
ctx.throw(403, "User not logged in")
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ exports.getSelf = async (ctx: any) => {
|
||||||
addSessionAttributesToUser(ctx)
|
addSessionAttributesToUser(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.updateSelf = async (ctx: any) => {
|
export async function updateSelf(ctx: any) {
|
||||||
const db = tenancy.getGlobalDB()
|
const db = tenancy.getGlobalDB()
|
||||||
const user = await db.get(ctx.user._id)
|
const user = await db.get(ctx.user._id)
|
||||||
let passwordChange = false
|
let passwordChange = false
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
const { generateTemplateID } = require("@budibase/backend-core/db")
|
import {
|
||||||
const {
|
|
||||||
TemplateMetadata,
|
TemplateMetadata,
|
||||||
TemplateBindings,
|
TemplateBindings,
|
||||||
GLOBAL_OWNER,
|
GLOBAL_OWNER,
|
||||||
} = require("../../../constants")
|
} from "../../../constants"
|
||||||
const { getTemplates } = require("../../../constants/templates")
|
import { getTemplates } from "../../../constants/templates"
|
||||||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
import { tenancy, db as dbCore } from "@budibase/backend-core"
|
||||||
|
|
||||||
exports.save = async ctx => {
|
export async function save(ctx: any) {
|
||||||
const db = getGlobalDB()
|
const db = tenancy.getGlobalDB()
|
||||||
let template = ctx.request.body
|
let template = ctx.request.body
|
||||||
if (!template.ownerId) {
|
if (!template.ownerId) {
|
||||||
template.ownerId = GLOBAL_OWNER
|
template.ownerId = GLOBAL_OWNER
|
||||||
}
|
}
|
||||||
if (!template._id) {
|
if (!template._id) {
|
||||||
template._id = generateTemplateID(template.ownerId)
|
template._id = dbCore.generateTemplateID(template.ownerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await db.put(template)
|
const response = await db.put(template)
|
||||||
|
@ -24,9 +23,9 @@ exports.save = async ctx => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.definitions = async ctx => {
|
export async function definitions(ctx: any) {
|
||||||
const bindings = {}
|
const bindings: any = {}
|
||||||
const info = {}
|
const info: any = {}
|
||||||
for (let template of TemplateMetadata.email) {
|
for (let template of TemplateMetadata.email) {
|
||||||
bindings[template.purpose] = template.bindings
|
bindings[template.purpose] = template.bindings
|
||||||
info[template.purpose] = {
|
info[template.purpose] = {
|
||||||
|
@ -45,30 +44,33 @@ exports.definitions = async ctx => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetch = async ctx => {
|
export async function fetch(ctx: any) {
|
||||||
ctx.body = await getTemplates()
|
ctx.body = await getTemplates()
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchByType = async ctx => {
|
export async function fetchByType(ctx: any) {
|
||||||
|
// @ts-ignore
|
||||||
ctx.body = await getTemplates({
|
ctx.body = await getTemplates({
|
||||||
type: ctx.params.type,
|
type: ctx.params.type,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchByOwner = async ctx => {
|
export async function fetchByOwner(ctx: any) {
|
||||||
|
// @ts-ignore
|
||||||
ctx.body = await getTemplates({
|
ctx.body = await getTemplates({
|
||||||
ownerId: ctx.params.ownerId,
|
ownerId: ctx.params.ownerId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = async ctx => {
|
export async function find(ctx: any) {
|
||||||
|
// @ts-ignore
|
||||||
ctx.body = await getTemplates({
|
ctx.body = await getTemplates({
|
||||||
id: ctx.params.id,
|
id: ctx.params.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async ctx => {
|
export async function destroy(ctx: any) {
|
||||||
const db = getGlobalDB()
|
const db = tenancy.getGlobalDB()
|
||||||
await db.remove(ctx.params.id, ctx.params.rev)
|
await db.remove(ctx.params.id, ctx.params.rev)
|
||||||
ctx.message = `Template ${ctx.params.id} deleted.`
|
ctx.message = `Template ${ctx.params.id} deleted.`
|
||||||
ctx.status = 200
|
ctx.status = 200
|
|
@ -4,7 +4,7 @@ const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const { updateTenantId } = require("@budibase/backend-core/tenancy")
|
const { updateTenantId } = require("@budibase/backend-core/tenancy")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function buildAuthValidation() {
|
function buildAuthValidation() {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
|
|
@ -5,7 +5,7 @@ const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
const { Configs } = require("../../../constants")
|
const { Configs } = require("../../../constants")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function smtpValidation() {
|
function smtpValidation() {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
|
|
@ -5,7 +5,7 @@ const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const { adminOnly } = require("@budibase/backend-core/auth")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function buildEmailSendValidation() {
|
function buildEmailSendValidation() {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
|
|
@ -2,7 +2,7 @@ const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/global/roles")
|
const controller = require("../../controllers/global/roles")
|
||||||
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/global/roles", builderOrAdmin, controller.fetch)
|
.get("/api/global/roles", builderOrAdmin, controller.fetch)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
const Router = require("@koa/router")
|
import Router from "@koa/router"
|
||||||
const controller = require("../../controllers/global/self")
|
import * as controller from "../../controllers/global/self"
|
||||||
const { builderOnly } = require("@budibase/backend-core/auth")
|
import { auth } from "@budibase/backend-core"
|
||||||
const { users } = require("../validation")
|
import { users } from "../validation"
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/global/self/api_key", builderOnly, controller.generateAPIKey)
|
.post("/api/global/self/api_key", auth.builderOnly, controller.generateAPIKey)
|
||||||
.get("/api/global/self/api_key", builderOnly, controller.fetchAPIKey)
|
.get("/api/global/self/api_key", auth.builderOnly, controller.fetchAPIKey)
|
||||||
.get("/api/global/self", controller.getSelf)
|
.get("/api/global/self", controller.getSelf)
|
||||||
.post(
|
.post(
|
||||||
"/api/global/self",
|
"/api/global/self",
|
||||||
|
@ -15,4 +15,4 @@ router
|
||||||
controller.updateSelf
|
controller.updateSelf
|
||||||
)
|
)
|
||||||
|
|
||||||
module.exports = router
|
export default router as any
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import Router from "@koa/router"
|
import Router from "@koa/router"
|
||||||
import controller from "../../controllers/global/templates"
|
import * as controller from "../../controllers/global/templates"
|
||||||
import { TemplatePurpose, TemplateTypes } from "../../../constants"
|
import { TemplatePurpose, TemplateTypes } from "../../../constants"
|
||||||
import { auth as authCore } from "@budibase/backend-core"
|
import { auth as authCore } from "@budibase/backend-core"
|
||||||
import Joi from "joi"
|
import Joi from "joi"
|
||||||
const { adminOnly, joiValidator } = authCore
|
const { adminOnly, joiValidator } = authCore
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function buildTemplateSaveValidation() {
|
function buildTemplateSaveValidation() {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
@ -34,4 +34,4 @@ router
|
||||||
.get("/api/global/template/:id", controller.find)
|
.get("/api/global/template/:id", controller.find)
|
||||||
.delete("/api/global/template/:id/:rev", adminOnly, controller.destroy)
|
.delete("/api/global/template/:id/:rev", adminOnly, controller.destroy)
|
||||||
|
|
||||||
module.exports = router
|
export default router
|
|
@ -8,7 +8,7 @@ const { users } = require("../validation")
|
||||||
const selfController = require("../../controllers/global/self")
|
const selfController = require("../../controllers/global/self")
|
||||||
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
const { builderOrAdmin } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function buildAdminInitValidation() {
|
function buildAdminInitValidation() {
|
||||||
return joiValidator.body(
|
return joiValidator.body(
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { joiValidator } = require("@budibase/backend-core/auth")
|
||||||
const { adminOnly } = require("@budibase/backend-core/auth")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
const Joi = require("joi")
|
const Joi = require("joi")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
function buildWorkspaceSaveValidation() {
|
function buildWorkspaceSaveValidation() {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
const { api } = require("@budibase/pro")
|
|
||||||
const userRoutes = require("./global/users")
|
|
||||||
const configRoutes = require("./global/configs")
|
|
||||||
const workspaceRoutes = require("./global/workspaces")
|
|
||||||
const templateRoutes = require("./global/templates")
|
|
||||||
const emailRoutes = require("./global/email")
|
|
||||||
const authRoutes = require("./global/auth")
|
|
||||||
const roleRoutes = require("./global/roles")
|
|
||||||
const environmentRoutes = require("./system/environment")
|
|
||||||
const tenantsRoutes = require("./system/tenants")
|
|
||||||
const statusRoutes = require("./system/status")
|
|
||||||
const selfRoutes = require("./global/self")
|
|
||||||
const licenseRoutes = require("./global/license")
|
|
||||||
const migrationRoutes = require("./system/migrations")
|
|
||||||
const accountRoutes = require("./system/accounts")
|
|
||||||
|
|
||||||
let userGroupRoutes = api.groups
|
|
||||||
exports.routes = [
|
|
||||||
configRoutes,
|
|
||||||
userRoutes,
|
|
||||||
workspaceRoutes,
|
|
||||||
authRoutes,
|
|
||||||
templateRoutes,
|
|
||||||
tenantsRoutes,
|
|
||||||
emailRoutes,
|
|
||||||
roleRoutes,
|
|
||||||
environmentRoutes,
|
|
||||||
statusRoutes,
|
|
||||||
selfRoutes,
|
|
||||||
licenseRoutes,
|
|
||||||
userGroupRoutes,
|
|
||||||
migrationRoutes,
|
|
||||||
accountRoutes,
|
|
||||||
]
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { api } from "@budibase/pro"
|
||||||
|
import userRoutes from "./global/users"
|
||||||
|
import configRoutes from "./global/configs"
|
||||||
|
import workspaceRoutes from "./global/workspaces"
|
||||||
|
import templateRoutes from "./global/templates"
|
||||||
|
import emailRoutes from "./global/email"
|
||||||
|
import authRoutes from "./global/auth"
|
||||||
|
import roleRoutes from "./global/roles"
|
||||||
|
import environmentRoutes from "./system/environment"
|
||||||
|
import tenantsRoutes from "./system/tenants"
|
||||||
|
import statusRoutes from "./system/status"
|
||||||
|
import selfRoutes from "./global/self"
|
||||||
|
import licenseRoutes from "./global/license"
|
||||||
|
import migrationRoutes from "./system/migrations"
|
||||||
|
import accountRoutes from "./system/accounts"
|
||||||
|
|
||||||
|
let userGroupRoutes = api.groups
|
||||||
|
export const routes = [
|
||||||
|
configRoutes,
|
||||||
|
userRoutes,
|
||||||
|
workspaceRoutes,
|
||||||
|
authRoutes,
|
||||||
|
templateRoutes,
|
||||||
|
tenantsRoutes,
|
||||||
|
emailRoutes,
|
||||||
|
roleRoutes,
|
||||||
|
environmentRoutes,
|
||||||
|
statusRoutes,
|
||||||
|
selfRoutes,
|
||||||
|
licenseRoutes,
|
||||||
|
userGroupRoutes,
|
||||||
|
migrationRoutes,
|
||||||
|
accountRoutes,
|
||||||
|
]
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/system/environment")
|
const controller = require("../../controllers/system/environment")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get("/api/system/environment", controller.fetch)
|
router.get("/api/system/environment", controller.fetch)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/system/status")
|
const controller = require("../../controllers/system/status")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router.get("/api/system/status", controller.fetch)
|
router.get("/api/system/status", controller.fetch)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const Router = require("@koa/router")
|
||||||
const controller = require("../../controllers/system/tenants")
|
const controller = require("../../controllers/system/tenants")
|
||||||
const { adminOnly } = require("@budibase/backend-core/auth")
|
const { adminOnly } = require("@budibase/backend-core/auth")
|
||||||
|
|
||||||
const router = Router()
|
const router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/system/tenants/:tenantId/exists", controller.exists)
|
.get("/api/system/tenants/:tenantId/exists", controller.exists)
|
||||||
|
|
Loading…
Reference in New Issue