Main body of PR comments - still need to move a bit to pro.
This commit is contained in:
parent
ae0391c304
commit
f6fc63f1a8
|
@ -1,61 +0,0 @@
|
||||||
exports.SEPARATOR = "_"
|
|
||||||
exports.UNICODE_MAX = "\ufff0"
|
|
||||||
|
|
||||||
const PRE_APP = "app"
|
|
||||||
const PRE_DEV = "dev"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can be used to create a few different forms of querying a view.
|
|
||||||
*/
|
|
||||||
exports.ViewModes = {
|
|
||||||
ALL: "all",
|
|
||||||
AUTOMATION: "auto",
|
|
||||||
STATUS: "status",
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.ViewNames = {
|
|
||||||
USER_BY_EMAIL: "by_email",
|
|
||||||
BY_API_KEY: "by_api_key",
|
|
||||||
USER_BY_BUILDERS: "by_builders",
|
|
||||||
LINK: "by_link",
|
|
||||||
ROUTING: "screen_routes",
|
|
||||||
AUTO_LOGS: "auto_log",
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.DocumentTypes = {
|
|
||||||
USER: "us",
|
|
||||||
WORKSPACE: "workspace",
|
|
||||||
CONFIG: "config",
|
|
||||||
TEMPLATE: "template",
|
|
||||||
APP: PRE_APP,
|
|
||||||
DEV: PRE_DEV,
|
|
||||||
APP_DEV: `${PRE_APP}${exports.SEPARATOR}${PRE_DEV}`,
|
|
||||||
APP_METADATA: `${PRE_APP}${exports.SEPARATOR}metadata`,
|
|
||||||
ROLE: "role",
|
|
||||||
MIGRATIONS: "migrations",
|
|
||||||
DEV_INFO: "devinfo",
|
|
||||||
AUTOMATION_LOG: "log_au",
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.StaticDatabases = {
|
|
||||||
GLOBAL: {
|
|
||||||
name: "global-db",
|
|
||||||
docs: {
|
|
||||||
apiKeys: "apikeys",
|
|
||||||
usageQuota: "usage_quota",
|
|
||||||
licenseInfo: "license_info",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// contains information about tenancy and so on
|
|
||||||
PLATFORM_INFO: {
|
|
||||||
name: "global-info",
|
|
||||||
docs: {
|
|
||||||
tenants: "tenants",
|
|
||||||
install: "install",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR
|
|
||||||
exports.APP_DEV = exports.APP_DEV_PREFIX =
|
|
||||||
exports.DocumentTypes.APP_DEV + exports.SEPARATOR
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
export const SEPARATOR = "_"
|
||||||
|
export const UNICODE_MAX = "\ufff0"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used to create a few different forms of querying a view.
|
||||||
|
*/
|
||||||
|
export enum AutomationViewModes {
|
||||||
|
ALL = "all",
|
||||||
|
AUTOMATION = "automation",
|
||||||
|
STATUS = "status",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ViewNames {
|
||||||
|
USER_BY_EMAIL = "by_email",
|
||||||
|
BY_API_KEY = "by_api_key",
|
||||||
|
USER_BY_BUILDERS = "by_builders",
|
||||||
|
LINK = "by_link",
|
||||||
|
ROUTING = "screen_routes",
|
||||||
|
AUTOMATION_LOGS = "automation_logs",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum DocumentTypes {
|
||||||
|
USER = "us",
|
||||||
|
WORKSPACE = "workspace",
|
||||||
|
CONFIG = "config",
|
||||||
|
TEMPLATE = "template",
|
||||||
|
APP = "app",
|
||||||
|
DEV = "dev",
|
||||||
|
APP_DEV = "app_dev",
|
||||||
|
APP_METADATA = "app_metadata",
|
||||||
|
ROLE = "role",
|
||||||
|
MIGRATIONS = "migrations",
|
||||||
|
DEV_INFO = "devinfo",
|
||||||
|
AUTOMATION_LOG = "log_au",
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StaticDatabases = {
|
||||||
|
GLOBAL: {
|
||||||
|
name: "global-db",
|
||||||
|
docs: {
|
||||||
|
apiKeys: "apikeys",
|
||||||
|
usageQuota: "usage_quota",
|
||||||
|
licenseInfo: "license_info",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// contains information about tenancy and so on
|
||||||
|
PLATFORM_INFO: {
|
||||||
|
name: "global-info",
|
||||||
|
docs: {
|
||||||
|
tenants: "tenants",
|
||||||
|
install: "install",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR
|
||||||
|
export const APP_DEV = exports.DocumentTypes.APP_DEV + exports.SEPARATOR
|
||||||
|
export const APP_DEV_PREFIX = APP_DEV
|
|
@ -1,7 +1,7 @@
|
||||||
import { newid } from "../hashing"
|
import { newid } from "../hashing"
|
||||||
import { DEFAULT_TENANT_ID, Configs } from "../constants"
|
import { DEFAULT_TENANT_ID, Configs } from "../constants"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { SEPARATOR, DocumentTypes, UNICODE_MAX } from "./constants"
|
import { SEPARATOR, DocumentTypes, UNICODE_MAX, ViewNames } from "./constants"
|
||||||
import { getTenantId, getGlobalDBName, getGlobalDB } from "../tenancy"
|
import { getTenantId, getGlobalDBName, getGlobalDB } from "../tenancy"
|
||||||
import fetch from "node-fetch"
|
import fetch from "node-fetch"
|
||||||
import { doWithDB, allDbs } from "./index"
|
import { doWithDB, allDbs } from "./index"
|
||||||
|
@ -58,7 +58,7 @@ export function getDocParams(
|
||||||
/**
|
/**
|
||||||
* Retrieve the correct index for a view based on default design DB.
|
* Retrieve the correct index for a view based on default design DB.
|
||||||
*/
|
*/
|
||||||
export function getQueryIndex(viewName: string) {
|
export function getQueryIndex(viewName: ViewNames) {
|
||||||
return `database/${viewName}`
|
return `database/${viewName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,13 @@ import {
|
||||||
isProdAppID,
|
isProdAppID,
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
} from "../../db/utils"
|
} from "../../db/utils"
|
||||||
import { Automation, MetadataErrors } from "../../definitions/common"
|
import { Automation } from "../../definitions/common"
|
||||||
import { app } from "@budibase/backend-core/cache"
|
import { app } from "@budibase/backend-core/cache"
|
||||||
import { backOff } from "../../utilities"
|
import { backOff } from "../../utilities"
|
||||||
import * as env from "../../environment"
|
import * as env from "../../environment"
|
||||||
import { logs } from "@budibase/pro"
|
import { logs } from "@budibase/pro"
|
||||||
import {
|
import { AppMetadataErrors } from "@budibase/types"
|
||||||
AutomationResults,
|
import { AutomationResults, AutomationStatus } from "@budibase/types"
|
||||||
AutomationStatus,
|
|
||||||
} from "../../definitions/automation"
|
|
||||||
|
|
||||||
const { logAlert } = require("@budibase/backend-core/logging")
|
const { logAlert } = require("@budibase/backend-core/logging")
|
||||||
|
|
||||||
|
@ -75,9 +73,9 @@ async function updateAppMetadataWithErrors(
|
||||||
const autoId = `${parts[parts.length - 3]}${SEPARATOR}${
|
const autoId = `${parts[parts.length - 3]}${SEPARATOR}${
|
||||||
parts[parts.length - 2]
|
parts[parts.length - 2]
|
||||||
}`
|
}`
|
||||||
let errors: MetadataErrors = {}
|
let errors: AppMetadataErrors = {}
|
||||||
if (metadata.automationErrors) {
|
if (metadata.automationErrors) {
|
||||||
errors = metadata.automationErrors as MetadataErrors
|
errors = metadata.automationErrors as AppMetadataErrors
|
||||||
}
|
}
|
||||||
if (!Array.isArray(errors[autoId])) {
|
if (!Array.isArray(errors[autoId])) {
|
||||||
errors[autoId] = []
|
errors[autoId] = []
|
||||||
|
|
|
@ -43,12 +43,6 @@ const DocumentTypes = {
|
||||||
USER_FLAG: "flag",
|
USER_FLAG: "flag",
|
||||||
}
|
}
|
||||||
|
|
||||||
const ViewModes = {
|
|
||||||
ALL: "all",
|
|
||||||
AUTOMATION: "auto",
|
|
||||||
STATUS: "status",
|
|
||||||
}
|
|
||||||
|
|
||||||
const InternalTables = {
|
const InternalTables = {
|
||||||
USER_METADATA: "ta_users",
|
USER_METADATA: "ta_users",
|
||||||
}
|
}
|
||||||
|
@ -75,7 +69,6 @@ exports.USER_METDATA_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${InternalTables.
|
||||||
exports.LINK_USER_METADATA_PREFIX = `${DocumentTypes.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
exports.LINK_USER_METADATA_PREFIX = `${DocumentTypes.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
||||||
exports.TABLE_ROW_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${DocumentTypes.TABLE}`
|
exports.TABLE_ROW_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${DocumentTypes.TABLE}`
|
||||||
exports.ViewNames = ViewNames
|
exports.ViewNames = ViewNames
|
||||||
exports.ViewModes = ViewModes
|
|
||||||
exports.InternalTables = InternalTables
|
exports.InternalTables = InternalTables
|
||||||
exports.DocumentTypes = DocumentTypes
|
exports.DocumentTypes = DocumentTypes
|
||||||
exports.SEPARATOR = SEPARATOR
|
exports.SEPARATOR = SEPARATOR
|
||||||
|
@ -365,32 +358,6 @@ exports.generateAutomationLogID = (isoDate, status, automationId) => {
|
||||||
return `${DocumentTypes.AUTOMATION_LOG}${SEPARATOR}${isoDate}${SEPARATOR}${automationId}${SEPARATOR}${status}`
|
return `${DocumentTypes.AUTOMATION_LOG}${SEPARATOR}${isoDate}${SEPARATOR}${automationId}${SEPARATOR}${status}`
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getAutomationLogParams = (
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
{ status, automationId } = {},
|
|
||||||
otherProps = {}
|
|
||||||
) => {
|
|
||||||
const automationBase = automationId ? `${automationId}${SEPARATOR}` : ""
|
|
||||||
const statusBase = status ? `${status}${SEPARATOR}` : ""
|
|
||||||
let base
|
|
||||||
if (status && automationId) {
|
|
||||||
base = `${ViewModes.ALL}${SEPARATOR}${statusBase}${automationBase}`
|
|
||||||
} else if (status) {
|
|
||||||
base = `${ViewModes.STATUS}${SEPARATOR}${statusBase}`
|
|
||||||
} else if (automationId) {
|
|
||||||
base = `${ViewModes.AUTOMATION}${SEPARATOR}${automationBase}`
|
|
||||||
} else {
|
|
||||||
base = `${DocumentTypes.AUTOMATION_LOG}${SEPARATOR}`
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...otherProps,
|
|
||||||
descending: true,
|
|
||||||
startkey: `${base}${endDate}${UNICODE_MAX}`,
|
|
||||||
endkey: `${base}${startDate}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This can be used with the db.allDocs to get a list of IDs
|
* This can be used with the db.allDocs to get a list of IDs
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
export enum AutomationStatus {
|
|
||||||
SUCCESS = "success",
|
|
||||||
ERROR = "error",
|
|
||||||
STOPPED = "stopped",
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AutomationResults {
|
|
||||||
automationId: string
|
|
||||||
status: string
|
|
||||||
trigger?: any
|
|
||||||
steps: {
|
|
||||||
stepId: string
|
|
||||||
inputs: {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
outputs: {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AutomationLog extends AutomationResults {
|
|
||||||
createdAt: string
|
|
||||||
_id: string
|
|
||||||
_rev: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AutomationLogPage {
|
|
||||||
data: AutomationLog[]
|
|
||||||
hasNextPage: boolean
|
|
||||||
nextPage?: string
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { AutomationStatus } from "./automation"
|
|
||||||
|
|
||||||
export { Query, Datasource } from "./datasource"
|
export { Query, Datasource } from "./datasource"
|
||||||
|
|
||||||
export interface Base {
|
export interface Base {
|
||||||
|
@ -105,5 +103,3 @@ export interface Automation extends Base {
|
||||||
trigger?: AutomationStep
|
trigger?: AutomationStep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MetadataErrors = { [key: string]: string[] }
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Document } from "../document"
|
import { Document } from "../document"
|
||||||
|
|
||||||
|
export type AppMetadataErrors = { [key: string]: string[] }
|
||||||
|
|
||||||
export interface App extends Document {
|
export interface App extends Document {
|
||||||
appId: string
|
appId: string
|
||||||
type: string
|
type: string
|
||||||
|
@ -12,6 +14,7 @@ export interface App extends Document {
|
||||||
tenantId: string
|
tenantId: string
|
||||||
status: string
|
status: string
|
||||||
revertableVersion?: string
|
revertableVersion?: string
|
||||||
|
automationErrors?: AppMetadataErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppInstance {
|
export interface AppInstance {
|
||||||
|
|
|
@ -17,3 +17,34 @@ export interface AutomationTrigger {
|
||||||
id: string
|
id: string
|
||||||
stepId: string
|
stepId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AutomationStatus {
|
||||||
|
SUCCESS = "success",
|
||||||
|
ERROR = "error",
|
||||||
|
STOPPED = "stopped",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AutomationResults {
|
||||||
|
automationId: string
|
||||||
|
status: string
|
||||||
|
trigger?: any
|
||||||
|
steps: {
|
||||||
|
stepId: string
|
||||||
|
inputs: {
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
outputs: {
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AutomationLog extends AutomationResults, Document {
|
||||||
|
_rev: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AutomationLogPage {
|
||||||
|
data: AutomationLog[]
|
||||||
|
hasNextPage: boolean
|
||||||
|
nextPage?: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue