1
0
Fork 0
mirror of synced 2024-07-10 16:55:46 +12:00

add synchronous webhook functionality

This commit is contained in:
Peter Clement 2023-05-12 15:57:34 +01:00
parent dcfb65b92d
commit c86c2b4096
8 changed files with 73 additions and 12 deletions

View file

@ -90,6 +90,10 @@ export const useScimIntegration = () => {
return useFeature(Feature.SCIM)
}
export const useSyncWebhook = () => {
return useFeature(Feature.SYNC_WEBHOOKS)
}
// QUOTAS
export const setAutomationLogsQuota = (value: number) => {

View file

@ -7,17 +7,40 @@
Icon,
notifications,
} from "@budibase/bbui"
import { automationStore } from "builderStore"
import { admin } from "stores/portal"
import { automationStore, selectedAutomation } from "builderStore"
import { admin, licensing } from "stores/portal"
import { externalActions } from "./ExternalActions"
import { TriggerStepID, ActionStepID } from "constants/backend/automations"
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 = {
SEND_EMAIL_SMTP: {
disabled: !$admin.checklist.smtp.checked,
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

View file

@ -226,7 +226,7 @@
{/if}
<Modal bind:this={actionModal} width="30%">
<ActionModal {blockIdx} />
<ActionModal {lastStep} {blockIdx} />
</Modal>
<Modal bind:this={webhookModal} width="30%">

View file

@ -20,6 +20,7 @@ export const ActionStepID = {
FILTER: "FILTER",
QUERY_ROWS: "QUERY_ROWS",
LOOP: "LOOP",
COLLECT: "COLLECT",
// these used to be lowercase step IDs, maintain for backwards compat
discord: "discord",
slack: "slack",

View file

@ -103,6 +103,9 @@ export const createLicensingStore = () => {
const auditLogsEnabled = license.features.includes(
Constants.Features.AUDIT_LOGS
)
const syncWebhooksEnabled = license.features.includes(
Constants.Features.SYNC_WEBHOOKS
)
store.update(state => {
return {
...state,
@ -117,6 +120,7 @@ export const createLicensingStore = () => {
environmentVariablesEnabled,
auditLogsEnabled,
enforceableSSO,
syncWebhooksEnabled,
}
})
},

View file

@ -70,6 +70,7 @@ export const Features = {
ENFORCEABLE_SSO: "enforceableSSO",
BRANDING: "branding",
SCIM: "scim",
SYNC_WEBHOOKS: "syncWebhooks",
}
// Role IDs

View file

@ -6,8 +6,11 @@ import {
WebhookActionType,
BBContext,
Automation,
AutomationActionStepId,
} from "@budibase/types"
import sdk from "../../sdk"
import * as pro from "@budibase/pro"
const toJsonSchema = require("to-json-schema")
const validate = require("jsonschema").validate
@ -78,15 +81,39 @@ export async function trigger(ctx: BBContext) {
if (webhook.action.type === WebhookActionType.AUTOMATION) {
// trigger with both the pure request and then expand it
// incase the user has produced a schema to bind to
await triggers.externalTrigger(target, {
body: ctx.request.body,
...ctx.request.body,
appId: prodAppId,
})
}
ctx.status = 200
ctx.body = {
message: "Webhook trigger fired successfully",
let hasCollectBlock = target.definition.steps.some(
(step: any) => step.stepId === AutomationActionStepId.COLLECT
)
if (hasCollectBlock && (await pro.features.isSyncWebhookEnabled())) {
const response = await triggers.externalTrigger(
target,
{
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) {
if (err.status === 404) {

View file

@ -8,6 +8,7 @@ export enum Feature {
ENFORCEABLE_SSO = "enforceableSSO",
BRANDING = "branding",
SCIM = "scim",
SYNC_WEBHOOKS = "syncWebhooks",
}
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }