add synchronous webhook functionality
This commit is contained in:
parent
dcfb65b92d
commit
c86c2b4096
8 changed files with 73 additions and 12 deletions
|
@ -90,6 +90,10 @@ export const useScimIntegration = () => {
|
||||||
return useFeature(Feature.SCIM)
|
return useFeature(Feature.SCIM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useSyncWebhook = () => {
|
||||||
|
return useFeature(Feature.SYNC_WEBHOOKS)
|
||||||
|
}
|
||||||
|
|
||||||
// QUOTAS
|
// QUOTAS
|
||||||
|
|
||||||
export const setAutomationLogsQuota = (value: number) => {
|
export const setAutomationLogsQuota = (value: number) => {
|
||||||
|
|
|
@ -7,17 +7,40 @@
|
||||||
Icon,
|
Icon,
|
||||||
notifications,
|
notifications,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { automationStore } from "builderStore"
|
import { automationStore, selectedAutomation } from "builderStore"
|
||||||
import { admin } from "stores/portal"
|
import { admin, licensing } from "stores/portal"
|
||||||
import { externalActions } from "./ExternalActions"
|
import { externalActions } from "./ExternalActions"
|
||||||
|
import { TriggerStepID, ActionStepID } from "constants/backend/automations"
|
||||||
|
|
||||||
export let blockIdx
|
export let blockIdx
|
||||||
|
export let lastStep
|
||||||
|
|
||||||
|
let syncWebhooksEnabled = $licensing.syncWebhooksEnabled
|
||||||
|
let collectBlockAllowedSteps = [TriggerStepID.APP, TriggerStepID.WEBHOOK]
|
||||||
|
let collectBlockExists = $selectedAutomation.definition.steps.some(
|
||||||
|
step => step.stepId === ActionStepID.COLLECT
|
||||||
|
)
|
||||||
|
$: console.log($licensing)
|
||||||
|
$: console.log(syncWebhooksEnabled)
|
||||||
const disabled = {
|
const disabled = {
|
||||||
SEND_EMAIL_SMTP: {
|
SEND_EMAIL_SMTP: {
|
||||||
disabled: !$admin.checklist.smtp.checked,
|
disabled: !$admin.checklist.smtp.checked,
|
||||||
message: "Please configure SMTP",
|
message: "Please configure SMTP",
|
||||||
},
|
},
|
||||||
|
COLLECT: {
|
||||||
|
disabled:
|
||||||
|
!collectBlockAllowedSteps.includes(
|
||||||
|
$selectedAutomation.definition.trigger.stepId
|
||||||
|
) ||
|
||||||
|
!lastStep ||
|
||||||
|
!syncWebhooksEnabled ||
|
||||||
|
collectBlockExists,
|
||||||
|
message: !collectBlockAllowedSteps.includes(
|
||||||
|
$selectedAutomation.definition.trigger.stepId
|
||||||
|
)
|
||||||
|
? "Only available for App Action or Webhook triggers"
|
||||||
|
: "Only available as the last step",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let selectedAction
|
let selectedAction
|
||||||
|
|
|
@ -226,7 +226,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Modal bind:this={actionModal} width="30%">
|
<Modal bind:this={actionModal} width="30%">
|
||||||
<ActionModal {blockIdx} />
|
<ActionModal {lastStep} {blockIdx} />
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal bind:this={webhookModal} width="30%">
|
<Modal bind:this={webhookModal} width="30%">
|
||||||
|
|
|
@ -20,6 +20,7 @@ export const ActionStepID = {
|
||||||
FILTER: "FILTER",
|
FILTER: "FILTER",
|
||||||
QUERY_ROWS: "QUERY_ROWS",
|
QUERY_ROWS: "QUERY_ROWS",
|
||||||
LOOP: "LOOP",
|
LOOP: "LOOP",
|
||||||
|
COLLECT: "COLLECT",
|
||||||
// these used to be lowercase step IDs, maintain for backwards compat
|
// these used to be lowercase step IDs, maintain for backwards compat
|
||||||
discord: "discord",
|
discord: "discord",
|
||||||
slack: "slack",
|
slack: "slack",
|
||||||
|
|
|
@ -103,6 +103,9 @@ export const createLicensingStore = () => {
|
||||||
const auditLogsEnabled = license.features.includes(
|
const auditLogsEnabled = license.features.includes(
|
||||||
Constants.Features.AUDIT_LOGS
|
Constants.Features.AUDIT_LOGS
|
||||||
)
|
)
|
||||||
|
const syncWebhooksEnabled = license.features.includes(
|
||||||
|
Constants.Features.SYNC_WEBHOOKS
|
||||||
|
)
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -117,6 +120,7 @@ export const createLicensingStore = () => {
|
||||||
environmentVariablesEnabled,
|
environmentVariablesEnabled,
|
||||||
auditLogsEnabled,
|
auditLogsEnabled,
|
||||||
enforceableSSO,
|
enforceableSSO,
|
||||||
|
syncWebhooksEnabled,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -70,6 +70,7 @@ export const Features = {
|
||||||
ENFORCEABLE_SSO: "enforceableSSO",
|
ENFORCEABLE_SSO: "enforceableSSO",
|
||||||
BRANDING: "branding",
|
BRANDING: "branding",
|
||||||
SCIM: "scim",
|
SCIM: "scim",
|
||||||
|
SYNC_WEBHOOKS: "syncWebhooks",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Role IDs
|
// Role IDs
|
||||||
|
|
|
@ -6,8 +6,11 @@ import {
|
||||||
WebhookActionType,
|
WebhookActionType,
|
||||||
BBContext,
|
BBContext,
|
||||||
Automation,
|
Automation,
|
||||||
|
AutomationActionStepId,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
import * as pro from "@budibase/pro"
|
||||||
|
|
||||||
const toJsonSchema = require("to-json-schema")
|
const toJsonSchema = require("to-json-schema")
|
||||||
const validate = require("jsonschema").validate
|
const validate = require("jsonschema").validate
|
||||||
|
|
||||||
|
@ -78,15 +81,39 @@ export async function trigger(ctx: BBContext) {
|
||||||
if (webhook.action.type === WebhookActionType.AUTOMATION) {
|
if (webhook.action.type === WebhookActionType.AUTOMATION) {
|
||||||
// trigger with both the pure request and then expand it
|
// trigger with both the pure request and then expand it
|
||||||
// incase the user has produced a schema to bind to
|
// incase the user has produced a schema to bind to
|
||||||
await triggers.externalTrigger(target, {
|
|
||||||
body: ctx.request.body,
|
let hasCollectBlock = target.definition.steps.some(
|
||||||
...ctx.request.body,
|
(step: any) => step.stepId === AutomationActionStepId.COLLECT
|
||||||
appId: prodAppId,
|
)
|
||||||
})
|
|
||||||
}
|
if (hasCollectBlock && (await pro.features.isSyncWebhookEnabled())) {
|
||||||
ctx.status = 200
|
const response = await triggers.externalTrigger(
|
||||||
ctx.body = {
|
target,
|
||||||
message: "Webhook trigger fired successfully",
|
{
|
||||||
|
body: ctx.request.body,
|
||||||
|
...ctx.request.body,
|
||||||
|
appId: prodAppId,
|
||||||
|
},
|
||||||
|
{ getResponses: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
let collectedValue = response.steps.find(
|
||||||
|
(step: any) => step.stepId === AutomationActionStepId.COLLECT
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx.status = 200
|
||||||
|
ctx.body = collectedValue.outputs
|
||||||
|
} else {
|
||||||
|
await triggers.externalTrigger(target, {
|
||||||
|
body: ctx.request.body,
|
||||||
|
...ctx.request.body,
|
||||||
|
appId: prodAppId,
|
||||||
|
})
|
||||||
|
ctx.status = 200
|
||||||
|
ctx.body = {
|
||||||
|
message: "Webhook trigger fired successfully",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.status === 404) {
|
if (err.status === 404) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ export enum Feature {
|
||||||
ENFORCEABLE_SSO = "enforceableSSO",
|
ENFORCEABLE_SSO = "enforceableSSO",
|
||||||
BRANDING = "branding",
|
BRANDING = "branding",
|
||||||
SCIM = "scim",
|
SCIM = "scim",
|
||||||
|
SYNC_WEBHOOKS = "syncWebhooks",
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }
|
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }
|
||||||
|
|
Loading…
Reference in a new issue