add synchronous webhook functionality
This commit is contained in:
parent
dcfb65b92d
commit
c86c2b4096
|
@ -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) => {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -226,7 +226,7 @@
|
|||
{/if}
|
||||
|
||||
<Modal bind:this={actionModal} width="30%">
|
||||
<ActionModal {blockIdx} />
|
||||
<ActionModal {lastStep} {blockIdx} />
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={webhookModal} width="30%">
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
|
@ -70,6 +70,7 @@ export const Features = {
|
|||
ENFORCEABLE_SSO: "enforceableSSO",
|
||||
BRANDING: "branding",
|
||||
SCIM: "scim",
|
||||
SYNC_WEBHOOKS: "syncWebhooks",
|
||||
}
|
||||
|
||||
// Role IDs
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue