Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(piece-sets): required actions a flow must contain to publish (#15952)

Abdul17589082dfc6
diff --git a/brain/knowledge/decisions/000043-publish-checks-required-actions-never-visibility.md b/brain/knowledge/decisions/000043-publish-checks-required-actions-never-visibility.md
new file mode 100644
index 00000000000..2ddcc2e676f
--- /dev/null
+++ b/brain/knowledge/decisions/000043-publish-checks-required-actions-never-visibility.md
@@ -0,0 +1,17 @@
+---
+status: accepted
+---
+
+# Publish checks required actions, never visibility
+
+## Decision
+A piece set's **required actions** are checked on every publish (`LOCK_AND_PUBLISH`), on the server and in the builder. What the set **hides** is still not checked at publish: a flow that uses a hidden piece, trigger or action publishes and runs.
+
+## Context
+Embed vendors need every published flow to contain their own app's actions. Piece sets already hide items in the builder, but an API call or an import can still use a hidden item. Zapier Enterprise and Power Platform both block publishing on hidden items; we looked at doing the same in the same hook.
+
+## Why
+Checking visibility at publish would be a functional breaking change: flows that publish today would start failing after the upgrade, and the rule has no escape for flows built before a piece was hidden. Required actions are new, so checking them breaks nothing. Rejected: enforcing both in one release.
+
+## Consequences
+The trigger limit ("users can only start from these triggers") holds in the builder only. Published flows keep running when a rule changes; the rule applies at the next publish. Approval (`flowApprovalRequestService.approve`) does not check again. A required action that is not in the latest piece version is ignored, so a piece update never locks users out.
diff --git a/brain/knowledge/pieces-engine/piece-sets.md b/brain/knowledge/pieces-engine/piece-sets.md
index 8add8ef26cb..db8e5899a41 100644
--- a/brain/knowledge/pieces-engine/piece-sets.md
+++ b/brain/knowledge/pieces-engine/piece-sets.md
@@ -7,25 +7,31 @@ icon: 🗂️
A named, reusable piece/action/trigger visibility configuration a platform admin defines once and assigns to many projects. Visibility is **derived at read time** — nothing is written when a new piece or action is installed.
### Model
-- **PieceSetConfig** — `{ pieces: PieceSelection, selectedActions: Record<piece, action[]>, selectedTriggers: Record<piece, trigger[]> }`.
+- **PieceSetConfig** — `{ pieces: PieceSelection, selectedActions: Record<piece, action[]>, selectedTriggers: Record<piece, trigger[]>, requiredActions: RequiredActions }`.
+- **Component** — an action or a trigger of a piece. `selectedActions` and `selectedTriggers` are the two component lists. _Avoid_: "step" (a step is a component placed in a flow).
- **PieceSelection** — `{ mode: 'include_all' | 'exclude_all', exceptions: string[] }`. `include_all` = everything present and future except exceptions (auto-includes new pieces); `exclude_all` = only exceptions, hiding future pieces.
- **Selected components** — a piece key present in `selectedActions`/`selectedTriggers` means "curated": only listed components visible, new ones stay hidden. Absent key = all visible incl. future.
+- **Required actions** — `{ mode: 'any' | 'all', actions: Record<piece, action[]> }`: a flow can publish only if it contains at least one (`any`, the default) or every (`all`) listed action, in a step that is not skipped. Actions only, never triggers.
- **Default Set** — one per platform (`isDefault`, `key: 'default'`); unassigned projects resolve to it. Can't be deleted; projects reassign to it rather than being removed.
- Shared pure resolvers `isPieceVisible` / `isComponentVisible` live in `core/shared/.../ee/piece-set/` (used by both server and web).
### Entities & services
- `piece_set` entity — `platformId` (CASCADE), `name`, `key` (embed handle, unique per platform, auto `kebabCase(name)-<random>`), `isDefault` (partial unique index), `config` jsonb. Projects reference it via `project.pieceSetId` (FK SET NULL).
-- `pieceSetService` — CRUD + `getOrCreateDefaultPieceSet` (distributed lock), `duplicate`, `assignProject(s)` / `removeProjectAssignment`. `update` runs `pieceSetConfig.applyUpdate` (declarative merge, never touches unreferenced component keys).
-- Routes `/v1/piece-sets` (platformAdminOnly). Update uses **ComponentIntent**: `{ mode: 'all' }` resets a piece to all; `{ mode: 'selected', selected }` sets the allow-list (empty array = hide all).
+- `pieceSetService` — CRUD + `getOrCreateDefaultPieceSet` (distributed lock), `getForProject` (the project's set, or the Default Set when `pieceSetId` is null), `duplicate`, `assignProject(s)` / `removeProjectAssignment`. `update` runs `pieceSetConfig.applyUpdate` (declarative merge, never touches unreferenced component keys).
+- Routes `/v1/piece-sets` (platformAdminOnly), except `GET /v1/piece-sets/projects/:projectId`, which any member of that project can read. Update uses **ComponentSelection**: `{ mode: 'all' }` resets a piece to all; `{ mode: 'selected', selected }` sets the allow-list (empty array = hide all).
### Gotchas
+- **`requiredActions.actions` has one empty state.** `[piece]: []` means "nothing required from this piece", the opposite of `selectedActions`, where `[]` means "hide all". The save removes empty keys, and an empty record skips the check. The skip is explicit: "any of zero actions" would otherwise fail every publish.
+- **Required actions are checked against the latest piece version.** Names not in the latest version (from `pieceMetadataService.get` **without** `projectId`, or hidden actions would look removed) are ignored, so a piece update never locks users out. A step inside a skipped loop or branch does not count.
+- **Approval does not re-check required actions.** The check runs in `LOCK_AND_PUBLISH` before `routePublish`; `flowApprovalRequestService.approve` publishes through `setPublishedVersion`, so a rule added while a request waits is not applied to it.
+- **A connection replace skips the required-actions check.** When it republishes, `handleLockedVersion` passes `skipRequiredActionsCheck: true` to `LOCK_AND_PUBLISH`, so a flow that misses a required action still gets the new connection. The flow content does not change, and the rule applies at its next normal publish.
- EE/Cloud only, gated behind `platform.plan.managePiecesEnabled`. On CE / flag off, piece sets are inert and filtering falls back to legacy project-plan allow/block lists.
- The **whole** `/v1/piece-sets` module is behind that flag, `GET` included — so on a locked plan the web list query is `enabled: false`, the table is simply empty, and row actions never render. Only toolbar/entry points need a UI guard. `PiecesLockedBanner` renders at the top of both the Pieces and the Piece Sets pages, since the same flag gates both; the details route redirects back to `/platform/pieces/piece-sets` rather than hanging on a spinner waiting for a query that will never run.
- There is **no** install-time sync and no `onPieceCreated` hook — resolution is purely read-time. See ADR 0001 (visibility derived, not materialized).
- Embed auth: a v4 JWT carries a `pieceSet` key claim; legacy v2/v3 tokens carry `piecesTags` (only the first tag honored, resolved to `key = tag`, else Default). Enforcement (`applyProjectPieceAccess`) runs unconditionally, not gated by the flag.
- **`usePieces({ skipProjectFilter: true })` is not a caching flag — it silently turns piece-set filtering off.** It drops `projectId` from `GET /v1/pieces`, and `resolveVisibility` (`ee/pieces/filters/piece-filtering-utils.ts`) bails to `null` the moment *either* `platformId` or `projectId` is nil, so the response is the unfiltered platform catalog. `platformId` still comes from the principal, so this is not a tenancy hole — but any surface using it advertises pieces a restricted project's flows and MCP server will not actually expose. Correct for platform-admin screens (the piece-set editor has to list pieces you have not permitted yet) and for a marketing-style showcase; wrong anywhere the list implies "what you can use here". The absence of `projectId` is easy to miss at the call site because the flag reads like a client-side concern. The mirror-image trap: with the flag off, `usePieces` scopes to `authenticationSession.getProjectId()` — the *session's* project — so a platform-admin screen inspecting some other project (the MCP Reach tab, with its project picker) must pass `projectId` explicitly or it will quietly render the admin's own project's pieces under another project's name.
-- **A piece set gates visibility, not execution.** `isPieceVisible` / `isComponentVisible` are only consulted when listing pieces, so a flow built before a piece was excluded — or one in a project later reassigned to a stricter set — keeps running that piece, and a step calling a now-hidden action still executes. The piece vanishes from the builder, which reads as "off" but is not. Publish validation and the pre-run checks do not consult the set either.
+- **A piece set gates visibility, not execution.** `isPieceVisible` / `isComponentVisible` are only consulted when listing pieces, so a flow built before a piece was excluded — or one in a project later reassigned to a stricter set — keeps running that piece, and a step calling a now-hidden action still executes. The piece vanishes from the builder, which reads as "off" but is not. Publish checks only the set's required actions, not what it hides (decision `000043`).
- Migration is three ordered steps: create table + backfill (`1807...`), then `CREATE INDEX CONCURRENTLY` (`1808...`, non-transactional), then the breaking drop of legacy platform piece-filter columns (`1809...`). Legacy `tag`/`piece_tag` tables are kept only because the backfill reads them once via raw SQL.
- The three `GET /v1/pieces*` routes are `securityAccess.unscoped(ALL_PRINCIPAL_TYPES)` but accept a `projectId` **query param** that picks which project's piece set filters the result — the route security does not scope it. The handlers assert membership themselves via `rbacService.assertPrinicpalAccessToProject` (membership only, no permission, skipped for principals with no platformId since visibility is already inert for them). Any new route that takes `projectId` for visibility must do the same: `resolvePieceSetForProject` looks the project up by id alone. That assertion carries the same two carve-outs `resolveVisibility` needs, both pinned by tests. It is **edition-gated** to EE/Cloud: `projectId` reaches *nothing* but `resolveVisibility` (not the search or sort path), so on CE the param is inert and an ungated membership check could only turn a working 200 into a 403/404. And it skips an **empty** `projectId` as well as a nil one, because `isNil('')` is false and `''` would otherwise reach `projectService.getOneOrThrow('')` and 404 — the web can produce exactly that, since `qs.stringify` serializes a null `projectId` as `projectId=` (so pass `getProjectId() ?? undefined`, never `getProjectId()!`). What remains: on EE/Cloud a nonexistent or soft-deleted project id answers 404 while a real project you are not a member of answers 403, which is a project-existence oracle for any authenticated user.
diff --git a/bun.lock b/bun.lock
index 9b9387dfb51..1c37066b2a9 100644
--- a/bun.lock
+++ b/bun.lock
@@ -188,7 +188,7 @@
},
"packages/core/utils": {
"name": "@activepieces/core-utils",
- "version": "0.8.6",
+ "version": "0.9.0",
"dependencies": {
"deepmerge-ts": "8.0.2",
"ipaddr.js": "2.3.0",
diff --git a/packages/core/shared/src/index.ts b/packages/core/shared/src/index.ts
index b4240af65a6..9b342b63a32 100755
--- a/packages/core/shared/src/index.ts
+++ b/packages/core/shared/src/index.ts
@@ -75,5 +75,7 @@ export * from './lib/ee/secret-managers'
export * from './lib/ee/scim'
export * from './lib/ee/embed-subdomain'
export * from './lib/ee/piece-set'
+export * from './lib/ee/piece-set/required-actions-util'
+export * from './lib/ee/piece-set/piece-set-config-util'
export * from './lib/ee/flow-approval'
export * from './lib/management/project/project-requests'
diff --git a/packages/core/shared/src/lib/ee/piece-set/index.ts b/packages/core/shared/src/lib/ee/piece-set/index.ts
index 184397f7c1e..55035574e2b 100644
--- a/packages/core/shared/src/lib/ee/piece-set/index.ts
+++ b/packages/core/shared/src/lib/ee/piece-set/index.ts
@@ -25,10 +25,22 @@ export const PieceSelection = z.object({
})
export type PieceSelection = z.infer<typeof PieceSelection>
+export enum RequiredActionsMode {
+ ANY = 'any',
+ ALL = 'all',
+}
+
+export const RequiredActions = z.object({
+ mode: z.enum(RequiredActionsMode).default(RequiredActionsMode.ANY),
+ actions: z.record(z.string(), z.array(z.string())).default({}),
+})
+export type RequiredActions = z.infer<typeof RequiredActions>
+
export const PieceSetConfig = z.object({
pieces: PieceSelection.default({ mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }),
selectedActions: z.record(z.string(), z.array(z.string())).default({}),
selectedTriggers: z.record(z.string(), z.array(z.string())).default({}),
+ requiredActions: RequiredActions.default({ mode: RequiredActionsMode.ANY, actions: {} }),
})
export type PieceSetConfig = z.infer<typeof PieceSetConfig>
@@ -43,11 +55,11 @@ export const PieceSet = z.object({
})
export type PieceSet = z.infer<typeof PieceSet>
-export const ComponentIntent = z.discriminatedUnion('mode', [
+export const ComponentSelection = z.discriminatedUnion('mode', [
z.object({ mode: z.literal('all') }),
z.object({ mode: z.literal('selected'), selected: z.array(z.string()) }),
])
-export type ComponentIntent = z.infer<typeof ComponentIntent>
+export type ComponentSelection = z.infer<typeof ComponentSelection>
export const CreatePieceSetRequestBody = z.object({
name: z.string().min(1, { message: formErrors.required }),
@@ -59,8 +71,12 @@ export const UpdatePieceSetRequestBody = z.object({
name: z.string().min(1, { message: formErrors.required }).optional(),
key: z.string().optional(),
pieces: PieceSelection.optional(),
- actions: z.record(z.string(), ComponentIntent).optional(),
- triggers: z.record(z.string(), ComponentIntent).optional(),
+ actions: z.record(z.string(), ComponentSelection).optional(),
+ triggers: z.record(z.string(), ComponentSelection).optional(),
+ requiredActions: z.object({
+ mode: z.enum(RequiredActionsMode).optional(),
+ actions: z.record(z.string(), z.array(z.string())).optional(),
+ }).optional(),
})
export type UpdatePieceSetRequestBody = z.infer<typeof UpdatePieceSetRequestBody>
diff --git a/packages/core/shared/src/lib/ee/piece-set/piece-set-config-util.ts b/packages/core/shared/src/lib/ee/piece-set/piece-set-config-util.ts
new file mode 100644
index 00000000000..2b069e34adb
--- /dev/null
+++ b/packages/core/shared/src/lib/ee/piece-set/piece-set-config-util.ts
@@ -0,0 +1,68 @@
+import { apId, isNil, unique } from '@activepieces/core-utils'
+import { requiredActionsUtil } from './required-actions-util'
+import { ComponentSelection, PieceSelectionMode, PieceSetConfig, RequiredActions, RequiredActionsMode, UpdatePieceSetRequestBody } from './index'
+
+function buildDefaultSet(platformId: string) {
+ return {
+ id: apId(),
+ platformId,
+ name: 'Default',
+ key: 'default',
+ isDefault: true,
+ generatedForProjectId: null,
+ config: emptyConfig(),
+ }
+}
+
+function emptyConfig(): PieceSetConfig {
+ return {
+ pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
+ selectedActions: {},
+ selectedTriggers: {},
+ requiredActions: { mode: RequiredActionsMode.ANY, actions: {} },
+ }
+}
+
+function applyUpdate({ current, request }: { current: PieceSetConfig, request: UpdatePieceSetRequestBody }): PieceSetConfig {
+ const configWithUpdatedVisibility: PieceSetConfig = {
+ ...current,
+ pieces: request.pieces ?? current.pieces,
+ selectedActions: applyComponentSelections({ current: current.selectedActions, selections: request.actions }),
+ selectedTriggers: applyComponentSelections({ current: current.selectedTriggers, selections: request.triggers }),
+ }
+ return {
+ ...configWithUpdatedVisibility,
+ requiredActions: applyRequiredActionsUpdate({ config: configWithUpdatedVisibility, request: request.requiredActions }),
+ }
+}
+
+function applyComponentSelections({ current, selections }: { current: SelectedComponents, selections: Record<string, ComponentSelection> | undefined }): SelectedComponents {
+ if (isNil(selections)) {
+ return current
+ }
+ return Object.entries(selections).reduce<SelectedComponents>((acc, [piece, selection]) => {
+ if (selection.mode === 'all') {
+ return Object.fromEntries(Object.entries(acc).filter(([key]) => key !== piece))
+ }
+ return { ...acc, [piece]: unique(selection.selected) }
+ }, current)
+}
+
+function applyRequiredActionsUpdate({ config, request }: { config: PieceSetConfig, request: UpdatePieceSetRequestBody['requiredActions'] }): RequiredActions {
+ const current = config.requiredActions
+ return {
+ mode: request?.mode ?? current.mode,
+ actions: requiredActionsUtil.removeExcludedRequiredActions({
+ config,
+ requiredActions: { ...current.actions, ...request?.actions },
+ }),
+ }
+}
+
+export const pieceSetConfigUtil = {
+ buildDefaultSet,
+ emptyConfig,
+ applyUpdate,
+}
+
+type SelectedComponents = Record<string, string[]>
diff --git a/packages/core/shared/src/lib/ee/piece-set/required-actions-util.ts b/packages/core/shared/src/lib/ee/piece-set/required-actions-util.ts
new file mode 100644
index 00000000000..19d4c200eb6
--- /dev/null
+++ b/packages/core/shared/src/lib/ee/piece-set/required-actions-util.ts
@@ -0,0 +1,121 @@
+import { FlowActionType, flowStructureUtil, FlowVersion, Step } from '@activepieces/core-execution'
+import { unique } from '@activepieces/core-utils'
+import { isComponentVisible, isPieceVisible, PieceSetConfig, RequiredActions, RequiredActionsMode } from './index'
+
+function dropUnavailableActionsInLatestPieceVersion({ actions, actionExists }: { actions: ActionsGroupedByPiece, actionExists: ActionExistence }): ActionsGroupedByPiece {
+ return filterActionsPerPiece({ actions, keep: ({ pieceName, actionName }) => actionExists[pieceName]?.[actionName] === true })
+}
+
+function removeExcludedRequiredActions({ config, requiredActions }: { config: PieceSetConfig, requiredActions: ActionsGroupedByPiece }): ActionsGroupedByPiece {
+ return filterActionsPerPiece({ actions: requiredActions, keep: ({ pieceName, actionName }) => isActionIncluded({ config, pieceName, actionName }) })
+}
+
+function findExcludedRequiredActions({ config, requiredActions }: { config: PieceSetConfig, requiredActions: ActionsGroupedByPiece }): ActionsGroupedByPiece {
+ return filterActionsPerPiece({ actions: requiredActions, keep: ({ pieceName, actionName }) => !isActionIncluded({ config, pieceName, actionName }) })
+}
+
+function checkRequiredActionsExistInFlowVersion({ requiredActions, flowVersion, actionExists }: CheckRequiredActionsExistInFlowVersionParams): RequiredActionsCheckResult {
+ const availableRequiredActionsInLatestPieceVersion = dropUnavailableActionsInLatestPieceVersion({ actions: requiredActions.actions, actionExists })
+ const required = ungroupActionsByPiece(availableRequiredActionsInLatestPieceVersion)
+ if (required.length === 0) {
+ return { passed: true, mode: requiredActions.mode, requiredActions: availableRequiredActionsInLatestPieceVersion, missingActions: {}, skippedActions: {} }
+ }
+ const steps = flowStructureUtil.getAllSteps(flowVersion.trigger)
+ const skippedStepNames = flowStructureUtil.getSkippedStepNames({ trigger: flowVersion.trigger })
+ const pieceActionSteps = getPieceActionsInFlowVersion({ steps }).map((step) => ({ ...step, skipped: skippedStepNames.has(step.stepName) }))
+ const nonSkippedActionsInFlowVersion = new Set(pieceActionSteps.filter((step) => !step.skipped).map(concatPieceNameAndActionName))
+ const skippedActionsInFlowVersion = new Set(pieceActionSteps.filter((step) => step.skipped).map(concatPieceNameAndActionName))
+ const requiredActionsNotInFlowVersion = required.filter((step) => !nonSkippedActionsInFlowVersion.has(concatPieceNameAndActionName(step)))
+ const passed = requiredActions.mode === RequiredActionsMode.ALL ? requiredActionsNotInFlowVersion.length === 0 : requiredActionsNotInFlowVersion.length < required.length
+ return {
+ passed,
+ mode: requiredActions.mode,
+ requiredActions: availableRequiredActionsInLatestPieceVersion,
+ missingActions: passed ? {} : groupActionsByPiece(requiredActionsNotInFlowVersion.filter((ref) => !skippedActionsInFlowVersion.has(concatPieceNameAndActionName(ref)))),
+ skippedActions: passed ? {} : groupActionsByPiece(requiredActionsNotInFlowVersion.filter((ref) => skippedActionsInFlowVersion.has(concatPieceNameAndActionName(ref)))),
+ }
+}
+
+function buildRequiredActionsMissingErrorMessage(result: RequiredActionsCheckResult): string {
+ const list = formatActionList([...ungroupActionsByPiece(result.missingActions), ...ungroupActionsByPiece(result.skippedActions)])
+ const lead = result.mode === RequiredActionsMode.ALL
+ ? 'This flow needs these actions to publish'
+ : 'This flow needs one of these actions to publish'
+ return `${lead}: ${list}`
+}
+
+function buildExcludedRequiredActionsErrorMessage(excludedRequiredActions: ActionsGroupedByPiece): string {
+ return `Required actions must be included in the piece set: ${formatActionList(ungroupActionsByPiece(excludedRequiredActions))}`
+}
+
+function formatActionList(refs: ActionAndPieceNames[]): string {
+ return refs
+ .map((ref) => `${ref.pieceName} · ${ref.actionName}`)
+ .join(', ')
+}
+
+function getPieceActionsInFlowVersion({ steps }: { steps: Step[] }): (ActionAndPieceNames & { stepName: string })[] {
+ return steps.flatMap((step) => {
+ if (step.type !== FlowActionType.PIECE || step.settings.actionName === undefined) {
+ return []
+ }
+ return [{ pieceName: step.settings.pieceName, actionName: step.settings.actionName, stepName: step.name }]
+ })
+}
+
+function filterActionsPerPiece({ actions, keep }: { actions: ActionsGroupedByPiece, keep: (action: ActionAndPieceNames) => boolean }): ActionsGroupedByPiece {
+ const keptActionsPerPiece = Object.entries(actions).map(([pieceName, actionNames]) => {
+ const keptActionNames = unique(actionNames).filter((actionName) => keep({ pieceName, actionName }))
+ return [pieceName, keptActionNames] as const
+ })
+ const piecesWithKeptActions = keptActionsPerPiece.filter(([, actionNames]) => actionNames.length > 0)
+ return Object.fromEntries(piecesWithKeptActions)
+}
+
+function isActionIncluded({ config, pieceName, actionName }: { config: PieceSetConfig } & ActionAndPieceNames): boolean {
+ return isPieceVisible({ pieces: config.pieces, name: pieceName })
+ && isComponentVisible({ selected: config.selectedActions[pieceName], name: actionName })
+}
+
+function ungroupActionsByPiece(actions: ActionsGroupedByPiece): ActionAndPieceNames[] {
+ return Object.entries(actions).flatMap(([pieceName, names]) => names.map((actionName) => ({ pieceName, actionName })))
+}
+
+function groupActionsByPiece(refs: ActionAndPieceNames[]): ActionsGroupedByPiece {
+ return refs.reduce<ActionsGroupedByPiece>((acc, ref) => ({ ...acc, [ref.pieceName]: [...(acc[ref.pieceName] ?? []), ref.actionName] }), {})
+}
+
+function concatPieceNameAndActionName(ref: ActionAndPieceNames): string {
+ return JSON.stringify([ref.pieceName, ref.actionName])
+}
+
+export const requiredActionsUtil = {
+ checkRequiredActionsExistInFlowVersion,
+ buildRequiredActionsMissingErrorMessage,
+ buildExcludedRequiredActionsErrorMessage,
+ removeExcludedRequiredActions,
+ findExcludedRequiredActions,
+}
+
+type ActionsGroupedByPiece = Record<string, string[]>
+
+type ActionAndPieceNames = {
+ pieceName: string
+ actionName: string
+}
+
+type CheckRequiredActionsExistInFlowVersionParams = {
+ requiredActions: RequiredActions
+ flowVersion: FlowVersion
+ actionExists: ActionExistence
+}
+
+export type ActionExistence = Record<string, Record<string, boolean>>
+
+export type RequiredActionsCheckResult = {
+ passed: boolean
+ mode: RequiredActionsMode
+ requiredActions: ActionsGroupedByPiece
+ missingActions: ActionsGroupedByPiece
+ skippedActions: ActionsGroupedByPiece
+}
diff --git a/packages/core/shared/test/ee/piece-set-config-util.test.ts b/packages/core/shared/test/ee/piece-set-config-util.test.ts
new file mode 100644
index 00000000000..6b72c979647
--- /dev/null
+++ b/packages/core/shared/test/ee/piece-set-config-util.test.ts
@@ -0,0 +1,129 @@
+import { PieceSelectionMode, PieceSetConfig, RequiredActionsMode } from '../../src/lib/ee/piece-set'
+import { pieceSetConfigUtil } from '../../src/lib/ee/piece-set/piece-set-config-util'
+import { requiredActionsUtil } from '../../src/lib/ee/piece-set/required-actions-util'
+
+const base: PieceSetConfig = {
+ pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
+ selectedActions: {},
+ selectedTriggers: {},
+ requiredActions: { mode: RequiredActionsMode.ANY, actions: {} },
+}
+
+describe('pieceSetConfigUtil.applyUpdate', () => {
+ it('replaces the pieces selection wholesale when provided', () => {
+ const result = pieceSetConfigUtil.applyUpdate({
+ current: base,
+ request: { pieces: { mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] } },
+ })
+ expect(result.pieces).toEqual({ mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] })
+ })
+
+ it('leaves the pieces selection untouched when not provided', () => {
+ const current = { ...base, pieces: { mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] } }
+ const result = pieceSetConfigUtil.applyUpdate({ current, request: { actions: {} } })
+ expect(result.pieces).toEqual(current.pieces)
+ })
+
+ it('sets a selected allow-list and dedupes', () => {
+ const result = pieceSetConfigUtil.applyUpdate({
+ current: base,
+ request: { actions: { slack: { mode: 'selected', selected: ['a', 'a', 'b'] } } },
+ })
+ expect(result.selectedActions).toEqual({ slack: ['a', 'b'] })
+ })
+
+ it('keeps an empty selected array (hide-all) rather than deleting the key', () => {
+ const result = pieceSetConfigUtil.applyUpdate({
+ current: base,
+ request: { actions: { slack: { mode: 'selected', selected: [] } } },
+ })
+ expect(result.selectedActions).toEqual({ slack: [] })
+ })
+
+ it('mode "all" deletes the piece key (reset to all)', () => {
+ const current = { ...base, selectedActions: { slack: ['a'], gmail: ['b'] } }
+ const result = pieceSetConfigUtil.applyUpdate({
+ current,
+ request: { actions: { slack: { mode: 'all' } } },
+ })
+ expect(result.selectedActions).toEqual({ gmail: ['b'] })
+ })
+
+ it('merges per-piece: only referenced keys change', () => {
+ const current = { ...base, selectedActions: { slack: ['a'], gmail: ['b'] } }
+ const result = pieceSetConfigUtil.applyUpdate({
+ current,
+ request: { actions: { slack: { mode: 'selected', selected: ['c'] } } },
+ })
+ expect(result.selectedActions).toEqual({ slack: ['c'], gmail: ['b'] })
+ })
+
+ it('handles triggers the same way as actions', () => {
+ const result = pieceSetConfigUtil.applyUpdate({
+ current: base,
+ request: { triggers: { slack: { mode: 'selected', selected: ['new_message'] } } },
+ })
+ expect(result.selectedTriggers).toEqual({ slack: ['new_message'] })
+ })
+})
+
+describe('pieceSetConfigUtil.emptyConfig', () => {
+ it('is fully permissive (include_all, no component selections)', () => {
+ expect(pieceSetConfigUtil.emptyConfig()).toEqual({
+ pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
+ selectedActions: {},
+ selectedTriggers: {},
+ requiredActions: { mode: RequiredActionsMode.ANY, actions: {} },
+ })
+ })
+})
+
+describe('pieceSetConfigUtil.applyUpdate requiredActions', () => {
+ it('replaces the list of a piece in the request, dedupes it, and keeps other pieces', () => {
+ const current = { ...base, requiredActions: { mode: RequiredActionsMode.ANY, actions: { gmail: ['send'] } } }
+ const result = pieceSetConfigUtil.applyUpdate({
+ current,
+ request: { requiredActions: { actions: { slack: ['post', 'post'] } } },
+ })
+ expect(result.requiredActions.actions).toEqual({ gmail: ['send'], slack: ['post'] })
+ })
+
+ it('removes the piece key when its list is empty', () => {
+ const current = { ...base, requiredActions: { mode: RequiredActionsMode.ANY, actions: { slack: ['post'] } } }
+ const result = pieceSetConfigUtil.applyUpdate({ current, request: { requiredActions: { actions: { slack: [] } } } })
+ expect(result.requiredActions.actions).toEqual({})
+ })
+
+ it('changes the mode only when the request has one', () => {
+ const current = { ...base, requiredActions: { mode: RequiredActionsMode.ANY, actions: { slack: ['post'] } } }
+ expect(pieceSetConfigUtil.applyUpdate({ current, request: { requiredActions: { mode: RequiredActionsMode.ALL } } }).requiredActions)
+ .toEqual({ mode: RequiredActionsMode.ALL, actions: { slack: ['post'] } })
+ expect(pieceSetConfigUtil.applyUpdate({ current, request: { requiredActions: {} } }).requiredActions.mode).toBe(RequiredActionsMode.ANY)
+ })
+
+ it('removes required actions that the same update hides', () => {
+ const current = { ...base, requiredActions: { mode: RequiredActionsMode.ANY, actions: { slack: ['post', 'read'] } } }
+ const result = pieceSetConfigUtil.applyUpdate({
+ current,
+ request: { actions: { slack: { mode: 'selected', selected: ['read'] } } },
+ })
+ expect(result.requiredActions.actions).toEqual({ slack: ['read'] })
+ })
+
+ it('removes required actions of a piece that becomes excluded', () => {
+ const current = { ...base, requiredActions: { mode: RequiredActionsMode.ANY, actions: { slack: ['post'] } } }
+ const result = pieceSetConfigUtil.applyUpdate({
+ current,
+ request: { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: ['slack'] } },
+ })
+ expect(result.requiredActions.actions).toEqual({})
+ })
+})
+
+describe('requiredActionsUtil.findExcludedRequiredActions', () => {
+ it('returns only the actions the config excludes', () => {
+ const config = { ...base, selectedActions: { slack: ['read'] } }
+ expect(requiredActionsUtil.findExcludedRequiredActions({ config, requiredActions: { slack: ['post', 'read'], gmail: ['send'] } }))
+ .toEqual({ slack: ['post'] })
+ })
+})
diff --git a/packages/core/shared/test/ee/required-actions-util.test.ts b/packages/core/shared/test/ee/required-actions-util.test.ts
new file mode 100644
index 00000000000..ff662ebe555
--- /dev/null
+++ b/packages/core/shared/test/ee/required-actions-util.test.ts
@@ -0,0 +1,138 @@
+import { FlowAction, FlowActionType, FlowTriggerType, FlowVersion, FlowVersionState, LoopOnItemsAction, PieceAction } from '@activepieces/core-execution'
+import { RequiredActionsMode } from '../../src/lib/ee/piece-set'
+import { requiredActionsUtil } from '../../src/lib/ee/piece-set/required-actions-util'
+
+const CRM = '@activepieces/piece-crm'
+const BILLING = '@activepieces/piece-billing'
+const actionExists = { [CRM]: { create_deal: true, update_contact: true, log_call: false }, [BILLING]: { create_invoice: true } }
+
+function pieceStep({ name, pieceName, actionName, skip, nextAction }: { name: string, pieceName: string, actionName: string, skip?: boolean, nextAction?: FlowAction }): PieceAction {
+ return {
+ name,
+ type: FlowActionType.PIECE,
+ valid: true,
+ displayName: name,
+ skip,
+ lastUpdatedDate: '2026-09-28T00:00:00.000Z',
+ settings: {
+ pieceName,
+ pieceVersion: '0.0.1',
+ actionName,
+ input: {},
+ propertySettings: {},
+ errorHandlingOptions: {},
+ },
+ nextAction,
+ }
+}
+
+function loopStep({ name, skip, firstLoopAction }: { name: string, skip?: boolean, firstLoopAction?: FlowAction }): LoopOnItemsAction {
+ return {
+ name,
+ type: FlowActionType.LOOP_ON_ITEMS,
+ valid: true,
+ displayName: name,
+ skip,
+ lastUpdatedDate: '2026-09-28T00:00:00.000Z',
+ settings: { items: '' },
+ firstLoopAction,
+ }
+}
+
+function flowWith(head?: FlowAction): FlowVersion {
+ return {
+ id: 'version',
+ created: '2026-09-28T00:00:00.000Z',
+ updated: '2026-09-28T00:00:00.000Z',
+ flowId: 'flow',
+ displayName: 'Flow',
+ updatedBy: null,
+ valid: true,
+ schemaVersion: null,
+ agentIds: [],
+ state: FlowVersionState.DRAFT,
+ connectionIds: [],
+ backupFiles: null,
+ notes: [],
+ trigger: {
+ name: 'trigger',
+ type: FlowTriggerType.EMPTY,
+ valid: true,
+ displayName: 'Trigger',
+ lastUpdatedDate: '2026-09-28T00:00:00.000Z',
+ settings: {},
+ nextAction: head,
+ },
+ }
+}
+
+function rule(mode: RequiredActionsMode, actions: Record<string, string[]>) {
+ return { mode, actions }
+}
+
+describe('requiredActionsUtil.checkRequiredActionsExistInFlowVersion', () => {
+ it('passes when there is no rule', () => {
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, {}), flowVersion: flowWith(), actionExists })
+ expect(result.passed).toBe(true)
+ })
+
+ it('any: passes with one of the required actions', () => {
+ const flowVersion = flowWith(pieceStep({ name: 'step_1', pieceName: BILLING, actionName: 'create_invoice' }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['create_deal'], [BILLING]: ['create_invoice'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(true)
+ })
+
+ it('any: fails with none of them and lists all as missing', () => {
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['create_deal'], [BILLING]: ['create_invoice'] }), flowVersion: flowWith(), actionExists })
+ expect(result.passed).toBe(false)
+ expect(result.missingActions).toEqual({ [CRM]: ['create_deal'], [BILLING]: ['create_invoice'] })
+ })
+
+ it('all: fails when one is missing and lists only that one', () => {
+ const flowVersion = flowWith(pieceStep({ name: 'step_1', pieceName: CRM, actionName: 'create_deal' }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ALL, { [CRM]: ['create_deal', 'update_contact'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(false)
+ expect(result.missingActions).toEqual({ [CRM]: ['update_contact'] })
+ })
+
+ it('does not count a skipped step and reports it as skipped', () => {
+ const flowVersion = flowWith(pieceStep({ name: 'step_1', pieceName: CRM, actionName: 'create_deal', skip: true }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['create_deal'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(false)
+ expect(result.skippedActions).toEqual({ [CRM]: ['create_deal'] })
+ expect(result.missingActions).toEqual({})
+ })
+
+ it('does not count a step inside a skipped loop', () => {
+ const flowVersion = flowWith(loopStep({ name: 'step_1', skip: true, firstLoopAction: pieceStep({ name: 'step_2', pieceName: CRM, actionName: 'create_deal' }) }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['create_deal'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(false)
+ expect(result.skippedActions).toEqual({ [CRM]: ['create_deal'] })
+ })
+
+ it('counts a step inside a loop that is not skipped', () => {
+ const flowVersion = flowWith(loopStep({ name: 'step_1', firstLoopAction: pieceStep({ name: 'step_2', pieceName: CRM, actionName: 'create_deal' }) }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['create_deal'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(true)
+ })
+
+ it('ignores actions that are not in the latest piece version', () => {
+ const flowVersion = flowWith(pieceStep({ name: 'step_1', pieceName: CRM, actionName: 'create_deal' }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ALL, { [CRM]: ['create_deal', 'log_call'] }), flowVersion, actionExists })
+ expect(result.passed).toBe(true)
+ expect(result.requiredActions).toEqual({ [CRM]: ['create_deal'] })
+ })
+
+ it('passes when every required action was removed from its piece', () => {
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ANY, { [CRM]: ['log_call'] }), flowVersion: flowWith(), actionExists })
+ expect(result.passed).toBe(true)
+ })
+})
+
+describe('requiredActionsUtil.buildRequiredActionsMissingErrorMessage', () => {
+ it('lists missing and skipped actions in one readable line', () => {
+ const flowVersion = flowWith(pieceStep({ name: 'step_1', pieceName: CRM, actionName: 'create_deal', skip: true }))
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions: rule(RequiredActionsMode.ALL, { [CRM]: ['create_deal', 'update_contact'] }), flowVersion, actionExists })
+ expect(requiredActionsUtil.buildRequiredActionsMissingErrorMessage(result)).toBe(`This flow needs these actions to publish: ${CRM} · update_contact, ${CRM} · create_deal`)
+ })
+})
diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json
index 152abf24ca8..85e05056233 100644
--- a/packages/core/utils/package.json
+++ b/packages/core/utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/core-utils",
- "version": "0.8.6",
+ "version": "0.9.0",
"type": "commonjs",
"main": "./dist/src/index.js",
"scripts": {
diff --git a/packages/core/utils/src/lib/activepieces-error.ts b/packages/core/utils/src/lib/activepieces-error.ts
index d6621c427a7..fa5efb87e50 100644
--- a/packages/core/utils/src/lib/activepieces-error.ts
+++ b/packages/core/utils/src/lib/activepieces-error.ts
@@ -51,6 +51,7 @@ export type ApErrorParams =
| TriggerFailedErrorParams
| ValidationErrorParams
| AgentRunSupersededErrorParams
+ | RequiredActionsMissingErrorParams
| FileTooLargeErrorParams
| InvitationOnlySignUpParams
| UserIsInActiveErrorParams
@@ -333,6 +334,17 @@ ErrorCode.AGENT_RUN_SUPERSEDED,
}
>
+export type RequiredActionsMissingErrorParams = BaseErrorParams<
+ErrorCode.REQUIRED_ACTIONS_MISSING,
+{
+ message: string
+ mode: 'any' | 'all'
+ requiredActions: Record<string, string[]>
+ missingActions: Record<string, string[]>
+ skippedActions: Record<string, string[]>
+}
+>
+
export type FileTooLargeErrorParams = BaseErrorParams<
ErrorCode.FILE_TOO_LARGE,
{
@@ -601,6 +613,7 @@ export enum ErrorCode {
USER_NOT_FOUND_ON_PLATFORM = 'USER_NOT_FOUND_ON_PLATFORM',
VALIDATION = 'VALIDATION',
AGENT_RUN_SUPERSEDED = 'AGENT_RUN_SUPERSEDED',
+ REQUIRED_ACTIONS_MISSING = 'REQUIRED_ACTIONS_MISSING',
FILE_TOO_LARGE = 'FILE_TOO_LARGE',
INVALID_LICENSE_KEY = 'INVALID_LICENSE_KEY',
EMAIL_ALREADY_HAS_ACTIVATION_KEY = 'EMAIL_ALREADY_HAS_ACTIVATION_KEY',
diff --git a/packages/server/api/src/app/app-connection/app-connection-service/app-connection.handler.ts b/packages/server/api/src/app/app-connection/app-connection-service/app-connection.handler.ts
index 89e840dfdc4..d89b3c7ddfa 100644
--- a/packages/server/api/src/app/app-connection/app-connection-service/app-connection.handler.ts
+++ b/packages/server/api/src/app/app-connection/app-connection-service/app-connection.handler.ts
@@ -413,6 +413,7 @@ async function handleLockedVersion(flow: PopulatedFlow, userId: UserId, projectI
type: FlowOperationType.LOCK_AND_PUBLISH,
request: { status },
},
+ skipRequiredActionsCheck: true,
})
}
diff --git a/packages/server/api/src/app/app.ts b/packages/server/api/src/app/app.ts
index f7cf77e54b8..03fbccd3482 100644
--- a/packages/server/api/src/app/app.ts
+++ b/packages/server/api/src/app/app.ts
@@ -54,6 +54,7 @@ import { appearanceHelper } from './ee/helper/appearance-helper'
import { licenseKeyUsageReportModule } from './ee/license-key-usage-report/license-key-usage-report-module'
import { managedAuthnModule } from './ee/managed-authn/managed-authn-module'
import { oauthAppModule } from './ee/oauth-apps/oauth-app.module'
+import { pieceSetRequiredActions } from './ee/pieces/piece-set/piece-set-required-actions'
import { pieceSetModule } from './ee/pieces/piece-set/piece-set.module'
import { platformPieceModule } from './ee/pieces/platform-piece-module'
import { adminPlatformModule } from './ee/platform/admin/admin-platform.controller'
@@ -379,7 +380,7 @@ export const setupApp = async (app: FastifyInstance): Promise<FastifyInstance> =
publishHooksFactory.set(eeFlowPublishHook)
billingProvider.set(autumnBillingProvider)
resumePageHooks.set((log) => ({ getTheme: (params) => appearanceHelper.getTheme({ ...params, log }) }))
- flowPublishHooks.set(() => ({ assertReferencesResolve: assertAgentsResolveInProject }))
+ flowPublishHooks.set((log) => ({ assertReferencesResolve: assertAgentsResolveInProject, findMissingRequiredActions: (params) => pieceSetRequiredActions(log).findMissing(params) }))
aiUsageHooks.set(agentConversationCreditsHooks)
exceptionHandler.initializeSentry(system.get(AppSystemProp.SENTRY_DSN))
systemJobHandlers.registerJobHandler(SystemJobName.HARD_DELETE_PLATFORM, (data) => platformTeardownJobs(app.log).hardDeletePlatformHandler(data))
@@ -419,7 +420,7 @@ export const setupApp = async (app: FastifyInstance): Promise<FastifyInstance> =
publishHooksFactory.set(eeFlowPublishHook)
billingProvider.set(autumnBillingProvider)
resumePageHooks.set((log) => ({ getTheme: (params) => appearanceHelper.getTheme({ ...params, log }) }))
- flowPublishHooks.set(() => ({ assertReferencesResolve: assertAgentsResolveInProject }))
+ flowPublishHooks.set((log) => ({ assertReferencesResolve: assertAgentsResolveInProject, findMissingRequiredActions: (params) => pieceSetRequiredActions(log).findMissing(params) }))
aiUsageHooks.set(agentConversationCreditsHooks)
break
case ApEdition.COMMUNITY:
diff --git a/packages/server/api/src/app/database/migration/postgres/1860000000000-AddPieceSetRequiredActions.ts b/packages/server/api/src/app/database/migration/postgres/1860000000000-AddPieceSetRequiredActions.ts
new file mode 100644
index 00000000000..2bd190aa0f0
--- /dev/null
+++ b/packages/server/api/src/app/database/migration/postgres/1860000000000-AddPieceSetRequiredActions.ts
@@ -0,0 +1,32 @@
+import { QueryRunner } from 'typeorm'
+import { Migration } from '../../migration'
+
+export class AddPieceSetRequiredActions1860000000000 implements Migration {
+ name = 'AddPieceSetRequiredActions1860000000000'
+ breaking = false
+ release = '0.93.0'
+
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`
+ ALTER TABLE "piece_set"
+ ALTER COLUMN "config" SET DEFAULT '{"pieces":{"mode":"include_all","exceptions":[]},"selectedActions":{},"selectedTriggers":{},"requiredActions":{"mode":"any","actions":{}}}'
+ `)
+ await queryRunner.query(`
+ UPDATE "piece_set"
+ SET "config" = jsonb_set("config", '{requiredActions}', '{"mode":"any","actions":{}}'::jsonb)
+ WHERE "config" -> 'requiredActions' IS NULL
+ `)
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`
+ UPDATE "piece_set"
+ SET "config" = "config" - 'requiredActions'
+ WHERE "config" -> 'requiredActions' = '{"mode":"any","actions":{}}'::jsonb
+ `)
+ await queryRunner.query(`
+ ALTER TABLE "piece_set"
+ ALTER COLUMN "config" SET DEFAULT '{"pieces":{"mode":"include_all","exceptions":[]},"selectedActions":{},"selectedTriggers":{}}'
+ `)
+ }
+}
diff --git a/packages/server/api/src/app/database/postgres-connection.ts b/packages/server/api/src/app/database/postgres-connection.ts
index 95a4f7ba471..ec995e2fa61 100644
--- a/packages/server/api/src/app/database/postgres-connection.ts
+++ b/packages/server/api/src/app/database/postgres-connection.ts
@@ -448,6 +448,7 @@ import { AddFlowTombstoneIndex1856000000000 } from './migration/postgres/1856000
import { AddWaitpointDeadLetteredAt1857000000000 } from './migration/postgres/1857000000000-AddWaitpointDeadLetteredAt'
import { AddAgentFolderId1858000000000 } from './migration/postgres/1858000000000-AddAgentFolderId'
import { AddPlatformModelTier1859000000000 } from './migration/postgres/1859000000000-AddPlatformModelTier'
+import { AddPieceSetRequiredActions1860000000000 } from './migration/postgres/1860000000000-AddPieceSetRequiredActions'
const getSslConfig = (): boolean | TlsOptions => {
const useSsl = system.get(AppSystemProp.POSTGRES_USE_SSL)
@@ -911,6 +912,7 @@ export const getMigrations = (): (new () => Migration)[] => {
AddWaitpointDeadLetteredAt1857000000000,
AddAgentFolderId1858000000000,
AddPlatformModelTier1859000000000,
+ AddPieceSetRequiredActions1860000000000,
]
return migrations
}
diff --git a/packages/server/api/src/app/ee/flows/flow-approval/flow-approval-request.service.ts b/packages/server/api/src/app/ee/flows/flow-approval/flow-approval-request.service.ts
index c368b506457..bc25f9ce263 100644
--- a/packages/server/api/src/app/ee/flows/flow-approval/flow-approval-request.service.ts
+++ b/packages/server/api/src/app/ee/flows/flow-approval/flow-approval-request.service.ts
@@ -1,4 +1,4 @@
-import { ActivepiecesError, apId, ApId, ApplicationEventName, Cursor, ErrorCode, Flow, FlowApprovalRequest, FlowApprovalRequestState, FlowOperationType, FlowStatus, FlowVersionState, isNil, PlatformId, PopulatedFlowApprovalRequest, Principal, PrincipalType, ProjectId, SeekPage, TelemetryEventName, UserId } from '@activepieces/shared'
+import { ActivepiecesError, apId, ApId, ApplicationEventName, Cursor, ErrorCode, Flow, FlowApprovalRequest, FlowApprovalRequestState, FlowOperationType, FlowStatus, FlowVersion, FlowVersionState, isNil, PlatformId, PopulatedFlowApprovalRequest, Principal, PrincipalType, ProjectId, SeekPage, TelemetryEventName, UserId } from '@activepieces/shared'
import { FastifyBaseLogger, FastifyRequest } from 'fastify'
import { repoFactory } from '../../../core/db/repo-factory'
import { transaction } from '../../../core/db/transaction'
@@ -17,19 +17,15 @@ import { FlowApprovalRequestEntity } from './flow-approval-request.entity'
const flowApprovalRequestRepo = repoFactory(FlowApprovalRequestEntity)
export const flowApprovalRequestService = (log: FastifyBaseLogger) => ({
- async submitForApproval({ flow, userId, projectId, platformId, requestedStatus }: SubmitParams): Promise<FlowApprovalRequest> {
- const draft = await flowVersionService(log).getFlowVersionOrThrow({
- flowId: flow.id,
- versionId: undefined,
- })
+ async submitForApproval({ flow, flowVersionToPublish, userId, projectId, platformId, requestedStatus }: SubmitParams): Promise<FlowApprovalRequest> {
return transaction(async (entityManager) => {
- const lockedVersion = draft.state === FlowVersionState.LOCKED
- ? draft
+ const lockedVersion = flowVersionToPublish.state === FlowVersionState.LOCKED
+ ? flowVersionToPublish
: await flowVersionService(log).applyOperation({
userId,
projectId,
platformId,
- flowVersion: draft,
+ flowVersion: flowVersionToPublish,
userOperation: { type: FlowOperationType.LOCK_FLOW, request: {} },
entityManager,
})
@@ -308,6 +304,7 @@ function assertRowsAffected(affected: number | null | undefined): void {
type SubmitParams = {
flow: Flow
+ flowVersionToPublish: FlowVersion
userId: UserId | null
projectId: ProjectId
platformId: PlatformId
diff --git a/packages/server/api/src/app/ee/flows/flow-approval/flow-publish-hook.ts b/packages/server/api/src/app/ee/flows/flow-approval/flow-publish-hook.ts
index d0ff758798a..903a08f5682 100644
--- a/packages/server/api/src/app/ee/flows/flow-approval/flow-publish-hook.ts
+++ b/packages/server/api/src/app/ee/flows/flow-approval/flow-publish-hook.ts
@@ -22,8 +22,8 @@ export const eeFlowPublishHook = (log: FastifyBaseLogger): PublishHooks => ({
const hasOverride = await userHasPublishSensitivePermission({ userId, projectId, log })
return hasOverride ? 'PUBLISH_NOW' : 'NEEDS_APPROVAL'
},
- async submitForApproval({ flow, userId, projectId, platformId, requestedStatus }: SubmitForApprovalParams) {
- await flowApprovalRequestService(log).submitForApproval({ flow, userId, projectId, platformId, requestedStatus })
+ async submitForApproval({ flow, flowVersionToPublish, userId, projectId, platformId, requestedStatus }: SubmitForApprovalParams) {
+ await flowApprovalRequestService(log).submitForApproval({ flow, flowVersionToPublish, userId, projectId, platformId, requestedStatus })
},
})
diff --git a/packages/server/api/src/app/ee/pieces/filters/piece-filtering-utils.ts b/packages/server/api/src/app/ee/pieces/filters/piece-filtering-utils.ts
index bd56be33523..8bfda3faebf 100644
--- a/packages/server/api/src/app/ee/pieces/filters/piece-filtering-utils.ts
+++ b/packages/server/api/src/app/ee/pieces/filters/piece-filtering-utils.ts
@@ -1,11 +1,10 @@
import { isNil } from '@activepieces/core-utils'
import { PieceMetadataModel, PieceMetadataModelSummary } from '@activepieces/pieces-framework'
-import { ApEdition, isComponentVisible, isPieceVisible, PieceSet, PieceSetConfig } from '@activepieces/shared'
+import { ApEdition, isComponentVisible, isPieceVisible, PieceSetConfig } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
import { system } from '../../../helper/system/system'
import { PieceMetadataSchema } from '../../../pieces/metadata/piece-metadata-entity'
-import { projectRepo } from '../../../project/project-repo'
-import { pieceSetRepo, pieceSetService } from '../piece-set/piece-set.service'
+import { pieceSetService } from '../piece-set/piece-set.service'
export async function resolveVisibility({ platformId, projectId, log }: ResolveVisibilityParams): Promise<VisibilityPolicy | null> {
const edition = system.getEdition()
@@ -15,7 +14,7 @@ export async function resolveVisibility({ platformId, projectId, log }: ResolveV
if (isNil(platformId) || isNil(projectId)) {
return null
}
- const pieceSet = await resolvePieceSetForProject({ log, projectId, platformId })
+ const pieceSet = await pieceSetService(log).getForProject({ projectId, platformId })
return buildPolicy(pieceSet.config)
}
@@ -47,16 +46,6 @@ function buildPolicy(config: PieceSetConfig): VisibilityPolicy {
}
}
-async function resolvePieceSetForProject({ log, projectId, platformId }: ResolvePieceSetForProjectParams): Promise<PieceSet> {
- const project = await projectRepo().findOneBy({ id: projectId })
- const pieceSetId = project?.pieceSetId ?? null
-
- return isNil(pieceSetId)
- ? pieceSetService(log).getOrCreateDefaultPieceSet(platformId)
- : (await pieceSetRepo().findOneBy({ id: pieceSetId, platformId }))
- ?? pieceSetService(log).getOrCreateDefaultPieceSet(platformId)
-}
-
export type VisibilityPolicy = {
isPieceVisible(name: string): boolean
filterPieces(pieces: PieceMetadataSchema[]): PieceMetadataSchema[]
@@ -69,9 +58,3 @@ type ResolveVisibilityParams = {
projectId: string | undefined
log: FastifyBaseLogger
}
-
-type ResolvePieceSetForProjectParams = {
- log: FastifyBaseLogger
- projectId: string
- platformId: string
-}
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set-config.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set-config.ts
deleted file mode 100644
index 2c5c74b243e..00000000000
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set-config.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { apId, isNil, unique } from '@activepieces/core-utils'
-import { ComponentIntent, PieceSelectionMode, PieceSetConfig, UpdatePieceSetRequestBody } from '@activepieces/shared'
-
-export const pieceSetConfig = {
- buildDefaultSet(platformId: string) {
- return {
- id: apId(),
- platformId,
- name: 'Default',
- key: 'default',
- isDefault: true,
- generatedForProjectId: null,
- config: emptyConfig(),
- }
- },
-
- emptyConfig,
-
- applyUpdate({ current, request }: { current: PieceSetConfig, request: UpdatePieceSetRequestBody }): PieceSetConfig {
- return {
- pieces: request.pieces ?? current.pieces,
- selectedActions: applyComponentIntents({ current: current.selectedActions, intents: request.actions }),
- selectedTriggers: applyComponentIntents({ current: current.selectedTriggers, intents: request.triggers }),
- }
- },
-}
-
-function emptyConfig(): PieceSetConfig {
- return {
- pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
- selectedActions: {},
- selectedTriggers: {},
- }
-}
-
-function applyComponentIntents({ current, intents }: { current: ComponentMap, intents: Record<string, ComponentIntent> | undefined }): ComponentMap {
- if (isNil(intents)) {
- return current
- }
- return Object.entries(intents).reduce<ComponentMap>((acc, [piece, intent]) => {
- if (intent.mode === 'all') {
- return Object.fromEntries(Object.entries(acc).filter(([key]) => key !== piece))
- }
- return { ...acc, [piece]: unique(intent.selected) }
- }, current)
-}
-
-type ComponentMap = Record<string, string[]>
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set-required-actions.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set-required-actions.ts
new file mode 100644
index 00000000000..f40355e7b57
--- /dev/null
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set-required-actions.ts
@@ -0,0 +1,28 @@
+import { FlowVersion, RequiredActionsCheckResult, requiredActionsUtil } from '@activepieces/shared'
+import { FastifyBaseLogger } from 'fastify'
+import { pieceMetadataService } from '../../../pieces/metadata/piece-metadata-service'
+import { platformPlanService } from '../../platform/platform-plan/platform-plan.service'
+import { pieceSetService } from './piece-set.service'
+
+export const pieceSetRequiredActions = (log: FastifyBaseLogger) => ({
+ async findMissing({ projectId, platformId, flowVersion }: FindMissingParams): Promise<RequiredActionsCheckResult | null> {
+ const plan = await platformPlanService(log).getOrCreateForPlatform(platformId)
+ if (!plan.managePiecesEnabled) {
+ return null
+ }
+ const pieceSet = await pieceSetService(log).getForProject({ projectId, platformId })
+ const { requiredActions } = pieceSet.config
+ if (Object.keys(requiredActions.actions).length === 0) {
+ return null
+ }
+ const actionExists = await pieceMetadataService(log).checkActionsExist({ actions: requiredActions.actions, platformId })
+ const result = requiredActionsUtil.checkRequiredActionsExistInFlowVersion({ requiredActions, flowVersion, actionExists })
+ return result.passed ? null : result
+ },
+})
+
+type FindMissingParams = {
+ projectId: string
+ platformId: string
+ flowVersion: FlowVersion
+}
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
index fa266284b92..cda92a348db 100644
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.controller.ts
@@ -2,6 +2,7 @@ import { AssignProjectsRequestBody, CreatePieceSetRequestBody, DuplicatePieceSet
import { FastifyPluginAsyncZod } from 'fastify-type-provider-zod'
import { StatusCodes } from 'http-status-codes'
import { z } from 'zod'
+import { ProjectResourceType } from '../../../core/security/authorization/common'
import { securityAccess } from '../../../core/security/authorization/fastify-security'
import { pieceSetService } from './piece-set.service'
@@ -26,6 +27,10 @@ export const pieceSetController: FastifyPluginAsyncZod = async (app) => {
return reply.status(StatusCodes.CREATED).send(set)
})
+ app.get('/projects/:projectId', GetProjectPieceSet, async (req) => {
+ return service.getForProject({ projectId: req.projectId, platformId: req.principal.platform.id })
+ })
+
app.get('/:id', GetPieceSet, async (req) => {
return service.getOne({ id: req.params.id, platformId: req.principal.platform.id })
})
@@ -103,6 +108,20 @@ const GetPieceSet = {
},
}
+const GetProjectPieceSet = {
+ config: {
+ security: securityAccess.project([PrincipalType.USER, PrincipalType.SERVICE], undefined, {
+ type: ProjectResourceType.PARAM,
+ }),
+ },
+ schema: {
+ tags: ['piece-sets'],
+ security: [SERVICE_KEY_SECURITY_OPENAPI],
+ summary: 'Get the piece set that applies to a project',
+ params: z.object({ projectId: z.string() }),
+ },
+}
+
const UpdatePieceSet = {
config: { security: platformAdminSecurity },
schema: {
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.entity.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.entity.ts
index db8862a4aa3..3e47e33fefc 100644
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.entity.ts
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.entity.ts
@@ -1,4 +1,4 @@
-import { PieceSelectionMode, PieceSet, Platform } from '@activepieces/shared'
+import { PieceSelectionMode, PieceSet, Platform, RequiredActionsMode } from '@activepieces/shared'
import { EntitySchema } from 'typeorm'
import {
ApIdSchema,
@@ -33,7 +33,7 @@ export const PieceSetEntity = new EntitySchema<PieceSetSchema>({
},
config: {
type: 'jsonb',
- default: { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }, selectedActions: {}, selectedTriggers: {} },
+ default: { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }, selectedActions: {}, selectedTriggers: {}, requiredActions: { mode: RequiredActionsMode.ANY, actions: {} } },
},
},
indices: [
diff --git a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
index cbba6d32e11..12d36b8e4bf 100644
--- a/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
+++ b/packages/server/api/src/app/ee/pieces/piece-set/piece-set.service.ts
@@ -1,5 +1,5 @@
import { ActivepiecesError, apId, ErrorCode, isNil, kebabCase, SeekPage, spreadIfDefined, tryCatch } from '@activepieces/core-utils'
-import { CreatePieceSetRequestBody, PieceSet, PieceSetConfig, UpdatePieceSetRequestBody } from '@activepieces/shared'
+import { CreatePieceSetRequestBody, PieceSet, PieceSetConfig, pieceSetConfigUtil, requiredActionsUtil, UpdatePieceSetRequestBody } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
import { EntityManager, In } from 'typeorm'
import { repoFactory } from '../../../core/db/repo-factory'
@@ -8,7 +8,7 @@ import { isUniqueViolation } from '../../../core/db/unique-violation'
import { distributedLock } from '../../../database/redis-connections'
import { buildPaginator } from '../../../helper/pagination/build-paginator'
import { paginationHelper } from '../../../helper/pagination/pagination-utils'
-import { pieceSetConfig } from './piece-set-config'
+import { projectRepo } from '../../../project/project-repo'
import { PieceSetEntity } from './piece-set.entity'
export const pieceSetRepo = repoFactory(PieceSetEntity)
@@ -45,6 +45,11 @@ type DeleteParams = {
platformId: string
}
+type GetForProjectParams = {
+ projectId: string
+ platformId: string
+}
+
type AssignProjectParams = {
pieceSet: PieceSet
projectId: string
@@ -70,12 +75,19 @@ export const pieceSetService = (log: FastifyBaseLogger) => ({
const existing = await pieceSetRepo().findOneBy({ platformId, isDefault: true })
if (!isNil(existing)) return existing
- await pieceSetRepo().save(pieceSetConfig.buildDefaultSet(platformId))
+ await pieceSetRepo().save(pieceSetConfigUtil.buildDefaultSet(platformId))
return pieceSetRepo().findOneByOrFail({ platformId, isDefault: true })
},
})
},
+ async getForProject({ projectId, platformId }: GetForProjectParams): Promise<PieceSet> {
+ const project = await projectRepo().findOneBy({ id: projectId, platformId })
+ const pieceSetId = project?.pieceSetId ?? null
+ const assigned = isNil(pieceSetId) ? null : await pieceSetRepo().findOneBy({ id: pieceSetId, platformId })
+ return isNil(assigned) ? this.getOrCreateDefaultPieceSet(platformId) : assigned
+ },
+
async list({ platformId, cursor, limit = 10 }: ListParams): Promise<SeekPage<PieceSet>> {
const boundedLimit = Math.min(limit, MAX_PIECE_SET_PAGE_SIZE)
const decodedCursor = paginationHelper.decodeCursor(cursor ?? null)
@@ -114,7 +126,7 @@ export const pieceSetService = (log: FastifyBaseLogger) => ({
key: resolveKey({ key, name }),
isDefault,
generatedForProjectId,
- config: config ?? pieceSetConfig.emptyConfig(),
+ config: config ?? pieceSetConfigUtil.emptyConfig(),
}))
if (error) {
rethrowKeyConflict(error)
@@ -125,7 +137,14 @@ export const pieceSetService = (log: FastifyBaseLogger) => ({
async update({ id, platformId, request }: UpdateParams): Promise<PieceSet> {
const existing = await this.getOne({ id, platformId })
- const updatedConfig = pieceSetConfig.applyUpdate({ current: existing.config, request })
+ const updatedConfig = pieceSetConfigUtil.applyUpdate({ current: existing.config, request })
+ const excludedRequired = requiredActionsUtil.findExcludedRequiredActions({ config: updatedConfig, requiredActions: request.requiredActions?.actions ?? {} })
+ if (Object.keys(excludedRequired).length > 0) {
+ throw new ActivepiecesError({
+ code: ErrorCode.VALIDATION,
+ params: { message: requiredActionsUtil.buildExcludedRequiredActionsErrorMessage(excludedRequired) },
+ })
+ }
const { error } = await tryCatch(() => pieceSetRepo().update({ id, platformId }, {
...spreadIfDefined('name', request.name),
diff --git a/packages/server/api/src/app/flows/flow/flow-publish-hooks.ts b/packages/server/api/src/app/flows/flow/flow-publish-hooks.ts
index cd1d82ce806..ab48bfd5000 100644
--- a/packages/server/api/src/app/flows/flow/flow-publish-hooks.ts
+++ b/packages/server/api/src/app/flows/flow/flow-publish-hooks.ts
@@ -1,4 +1,4 @@
-import { Flow, FlowStatus, PlatformId, ProjectId, UserId } from '@activepieces/shared'
+import { Flow, FlowStatus, FlowVersion, PlatformId, ProjectId, RequiredActionsCheckResult, UserId } from '@activepieces/shared'
import { EntityManager } from 'typeorm'
import { hooksFactory } from '../../helper/hooks-factory'
@@ -22,6 +22,9 @@ export const flowPublishHooks = hooksFactory.create<FlowPublishHooks>(() => ({
async assertReferencesResolve(): Promise<void> {
return
},
+ async findMissingRequiredActions(): Promise<RequiredActionsCheckResult | null> {
+ return null
+ },
}))
export type RoutePublishParams = {
@@ -33,6 +36,7 @@ export type RoutePublishParams = {
export type SubmitForApprovalParams = {
flow: Flow
+ flowVersionToPublish: FlowVersion
userId: UserId | null
projectId: ProjectId
platformId: PlatformId
@@ -41,4 +45,5 @@ export type SubmitForApprovalParams = {
export type FlowPublishHooks = {
assertReferencesResolve(params: { projectId: ProjectId, agentExternalIds: string[], entityManager: EntityManager }): Promise<void>
+ findMissingRequiredActions(params: { projectId: ProjectId, platformId: PlatformId, flowVersion: FlowVersion }): Promise<RequiredActionsCheckResult | null>
}
diff --git a/packages/server/api/src/app/flows/flow/flow.service.ts b/packages/server/api/src/app/flows/flow/flow.service.ts
index 9a4dc341685..bee19066f86 100644
--- a/packages/server/api/src/app/flows/flow/flow.service.ts
+++ b/packages/server/api/src/app/flows/flow/flow.service.ts
@@ -1,6 +1,6 @@
import { ActivepiecesError, apId, assertNotNullOrUndefined, Cursor, ErrorCode, FlowId, FlowVersionId, isNil, Metadata, PlatformId, ProjectId, SeekPage, tryCatch, UserId } from '@activepieces/core-utils'
import { apDayjs, apDayjsDuration } from '@activepieces/server-utils'
-import { CreateFlowRequest, Flow, FlowCreator, FlowOperationRequest, FlowOperationStatus, FlowOperationType, flowPieceUtil, FlowStatus, FlowTriggerType, FlowVersion, FlowVersionState, PopulatedFlow, SharedTemplate, TelemetryEventName, TemplateStatus, TemplateType, TriggerSource, UncategorizedFolderId, UserWithMetaInformation } from '@activepieces/shared'
+import { CreateFlowRequest, Flow, FlowCreator, FlowOperationRequest, FlowOperationStatus, FlowOperationType, flowPieceUtil, FlowStatus, FlowTriggerType, FlowVersion, FlowVersionState, PopulatedFlow, requiredActionsUtil, SharedTemplate, TelemetryEventName, TemplateStatus, TemplateType, TriggerSource, UncategorizedFolderId, UserWithMetaInformation } from '@activepieces/shared'
import dayjs from 'dayjs'
import { FastifyBaseLogger } from 'fastify'
import { EntityManager, In, IsNull, Not } from 'typeorm'
@@ -329,6 +329,7 @@ export const flowService = (log: FastifyBaseLogger) => ({
previousFlow,
ip,
emitEvents = true,
+ skipRequiredActionsCheck = false,
}: UpdateParams): Promise<PopulatedFlow> {
const flowBeforeOperation = emitEvents
? previousFlow ?? await this.getOnePopulatedOrThrow({ id, projectId })
@@ -348,11 +349,21 @@ export const flowService = (log: FastifyBaseLogger) => ({
switch (operation.type) {
case FlowOperationType.LOCK_AND_PUBLISH: {
const flow = await this.getOneOrThrow({ id, projectId })
+ const flowVersionToPublish = await flowVersionService(log).getFlowVersionOrThrow({ flowId: id, versionId: undefined })
+ if (!skipRequiredActionsCheck) {
+ await assertRequiredActionsPresent({
+ projectId,
+ platformId,
+ flowVersion: flowVersionToPublish,
+ log,
+ })
+ }
const requestedStatus = operation.request.status ?? FlowStatus.ENABLED
const route = await publishHooksFactory.get(log).routePublish({ flow, projectId, platformId, userId })
if (route === 'NEEDS_APPROVAL') {
await publishHooksFactory.get(log).submitForApproval({
flow,
+ flowVersionToPublish,
userId,
projectId,
platformId,
@@ -365,6 +376,7 @@ export const flowService = (log: FastifyBaseLogger) => ({
userId,
projectId,
platformId,
+ flowVersionToPublish,
})
const isRepublish = !isNil(previouslyPublishedVersion) && flowPublishUtils.isSameTrigger({
published: previouslyPublishedVersion.trigger,
@@ -478,14 +490,10 @@ export const flowService = (log: FastifyBaseLogger) => ({
userId,
projectId,
platformId,
+ flowVersionToPublish,
}: UpdatePublishedVersionIdParams): Promise<PopulatedFlow> {
const flowToUpdate = await this.getOneOrThrow({ id, projectId })
- const flowVersionToPublish = await flowVersionService(log).getFlowVersionOrThrow({
- flowId: id,
- versionId: undefined,
- })
-
if (flowToUpdate.status === FlowStatus.ENABLED && !isNil(flowToUpdate.publishedVersionId)) {
await triggerSourceService(log).disable({
flowId: flowToUpdate.id,
@@ -738,6 +746,23 @@ export const flowService = (log: FastifyBaseLogger) => ({
})
+async function assertRequiredActionsPresent({ projectId, platformId, flowVersion, log }: AssertRequiredActionsParams): Promise<void> {
+ const result = await flowPublishHooks.get(log).findMissingRequiredActions({ projectId, platformId, flowVersion })
+ if (isNil(result)) {
+ return
+ }
+ throw new ActivepiecesError({
+ code: ErrorCode.REQUIRED_ACTIONS_MISSING,
+ params: {
+ message: requiredActionsUtil.buildRequiredActionsMissingErrorMessage(result),
+ mode: result.mode,
+ requiredActions: result.requiredActions,
+ missingActions: result.missingActions,
+ skippedActions: result.skippedActions,
+ },
+ })
+}
+
const lockFlowVersionIfNotLocked = async ({
flowVersion,
userId,
@@ -922,6 +947,7 @@ type UpdateParams = EventEmissionParams & {
operation: FlowOperationRequest
platformId: PlatformId
previousFlow?: PopulatedFlow
+ skipRequiredActionsCheck?: boolean
}
type UpdatePublishedVersionIdParams = {
@@ -929,6 +955,7 @@ type UpdatePublishedVersionIdParams = {
userId: UserId | null
platformId: PlatformId
projectId: ProjectId
+ flowVersionToPublish: FlowVersion
}
type SetPublishedVersionParams = {
@@ -972,6 +999,13 @@ type ExistsByProjectAndStatusParams = {
entityManager: EntityManager
}
+type AssertRequiredActionsParams = {
+ projectId: ProjectId
+ platformId: PlatformId
+ flowVersion: FlowVersion
+ log: FastifyBaseLogger
+}
+
type UpdateMetadataParams = {
id: FlowId
projectId: ProjectId
diff --git a/packages/server/api/src/app/helper/error-handler.ts b/packages/server/api/src/app/helper/error-handler.ts
index 849b235069a..1ee9d9d2663 100644
--- a/packages/server/api/src/app/helper/error-handler.ts
+++ b/packages/server/api/src/app/helper/error-handler.ts
@@ -111,6 +111,7 @@ const statusCodeMap: Partial<Record<ErrorCode, StatusCodes>> = {
[ErrorCode.INVALID_GIT_CREDENTIALS]: StatusCodes.BAD_REQUEST,
[ErrorCode.INVALID_OTP]: StatusCodes.GONE,
[ErrorCode.VALIDATION]: StatusCodes.CONFLICT,
+ [ErrorCode.REQUIRED_ACTIONS_MISSING]: StatusCodes.BAD_REQUEST,
[ErrorCode.FILE_TOO_LARGE]: StatusCodes.REQUEST_TOO_LONG,
[ErrorCode.INVITATION_ONLY_SIGN_UP]: StatusCodes.FORBIDDEN,
[ErrorCode.AUTHENTICATION]: StatusCodes.UNAUTHORIZED,
diff --git a/packages/server/api/src/app/pieces/metadata/piece-metadata-service.ts b/packages/server/api/src/app/pieces/metadata/piece-metadata-service.ts
index 4df977e366a..60e669d3da1 100644
--- a/packages/server/api/src/app/pieces/metadata/piece-metadata-service.ts
+++ b/packages/server/api/src/app/pieces/metadata/piece-metadata-service.ts
@@ -1,7 +1,7 @@
import { ActivepiecesError, apId, assertNotNullOrUndefined, ErrorCode, isNil, LocalesEnum, PlatformId } from '@activepieces/core-utils'
import { PieceMetadata, PieceMetadataModel, PieceMetadataModelSummary, PiecePackageInformation, pieceTranslation } from '@activepieces/pieces-framework'
import { apVersionUtil } from '@activepieces/server-utils'
-import { EXACT_VERSION_REGEX, flowPieceUtil, PackageType, PieceAudienceFilter, PieceCategory, PieceOrderBy, PiecePackage, PieceSortBy, PieceType, PrivatePiecePackage, PublicPiecePackage, SuggestionType } from '@activepieces/shared'
+import { ActionExistence, EXACT_VERSION_REGEX, flowPieceUtil, PackageType, PieceAudienceFilter, PieceCategory, PieceOrderBy, PiecePackage, PieceSortBy, PieceType, PrivatePiecePackage, PublicPiecePackage, SuggestionType } from '@activepieces/shared'
import dayjs from 'dayjs'
import { FastifyBaseLogger } from 'fastify'
import semVer from 'semver'
@@ -77,6 +77,33 @@ export const pieceMetadataService = (log: FastifyBaseLogger) => {
}
return policy.filterPieceComponents(piece)
},
+ async checkActionsExist({ actions, platformId }: CheckActionsExistParams): Promise<ActionExistence> {
+ const latestVersions = await Promise.all(Object.keys(actions).map((name) => findExactVersion(log, { name, version: undefined, platformId })))
+ const lookups = latestVersions.flatMap((latest) => isNil(latest) ? [] : actions[latest.name].map((actionName) => ({ ...latest, actionName })))
+ if (lookups.length === 0) {
+ return {}
+ }
+ const rows: { pieceName: string, actionName: string, exists: boolean }[] = await pieceRepos().query(
+ `
+ SELECT lookup.piece_name AS "pieceName",
+ lookup.action_name AS "actionName",
+ (pm."actions" -> lookup.action_name) IS NOT NULL
+ AND (pm."actions" -> lookup.action_name ->> 'audience') IS DISTINCT FROM 'ai' AS "exists"
+ FROM unnest($1::varchar[], $2::varchar[], $3::varchar[], $4::varchar[]) AS lookup(piece_name, version, platform_id, action_name)
+ LEFT JOIN "piece_metadata" AS pm
+ ON pm."name" = lookup.piece_name
+ AND pm."version" = lookup.version
+ AND pm."platformId" IS NOT DISTINCT FROM lookup.platform_id
+ `,
+ [
+ lookups.map((lookup) => lookup.name),
+ lookups.map((lookup) => lookup.version),
+ lookups.map((lookup) => lookup.platformId ?? null),
+ lookups.map((lookup) => lookup.actionName),
+ ],
+ )
+ return rows.reduce<ActionExistence>((acc, row) => ({ ...acc, [row.pieceName]: { ...acc[row.pieceName], [row.actionName]: row.exists } }), {})
+ },
async getOrThrow({ version, name, platformId, locale }: GetOrThrowParams): Promise<PieceMetadataModel> {
const piece = await this.get({ version, name, platformId })
if (isNil(piece)) {
@@ -569,6 +596,11 @@ type ListParams = {
audience?: PieceAudienceFilter
}
+type CheckActionsExistParams = {
+ actions: Record<string, string[]>
+ platformId: string
+}
+
type GetOrThrowParams = {
name: string
version?: string
diff --git a/packages/server/api/test/integration/ee/flow-approval/flow-approval.test.ts b/packages/server/api/test/integration/ee/flow-approval/flow-approval.test.ts
index 55280ff09da..6700315ec21 100644
--- a/packages/server/api/test/integration/ee/flow-approval/flow-approval.test.ts
+++ b/packages/server/api/test/integration/ee/flow-approval/flow-approval.test.ts
@@ -147,11 +147,12 @@ describe('flow-approval — routing', () => {
describe('flow-approval — submitForApproval race', () => {
it('two concurrent submits produce exactly one PENDING row', async () => {
const ctx = await setupSensitiveCtx()
- const { flow } = await createDraftFlow(ctx)
+ const { flow, version } = await createDraftFlow(ctx)
const results = await Promise.allSettled([
flowApprovalRequestService(app!.log).submitForApproval({
flow,
+ flowVersionToPublish: version,
userId: ctx.user.id,
projectId: ctx.project.id,
platformId: ctx.platform.id,
@@ -159,6 +160,7 @@ describe('flow-approval — submitForApproval race', () => {
}),
flowApprovalRequestService(app!.log).submitForApproval({
flow,
+ flowVersionToPublish: version,
userId: ctx.user.id,
projectId: ctx.project.id,
platformId: ctx.platform.id,
@@ -180,10 +182,11 @@ describe('flow-approval — submitForApproval race', () => {
describe('flow-approval — submitForApproval supersession', () => {
it('resubmitting updates the existing PENDING row in place and re-points it at the newly locked version', async () => {
const ctx = await setupSensitiveCtx()
- const { flow } = await createDraftFlow(ctx)
+ const { flow, version } = await createDraftFlow(ctx)
const first = await flowApprovalRequestService(app!.log).submitForApproval({
flow,
+ flowVersionToPublish: version,
userId: ctx.user.id,
projectId: ctx.project.id,
platformId: ctx.platform.id,
@@ -200,6 +203,7 @@ describe('flow-approval — submitForApproval supersession', () => {
const second = await flowApprovalRequestService(app!.log).submitForApproval({
flow,
+ flowVersionToPublish: newDraft,
userId: ctx.user.id,
projectId: ctx.project.id,
platformId: ctx.platform.id,
diff --git a/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts b/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
index d6404ab7feb..6a23063ce8e 100644
--- a/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
+++ b/packages/server/api/test/integration/ee/piece-sets/piece-sets.test.ts
@@ -1,5 +1,5 @@
import { apId } from '@activepieces/core-utils'
-import { PieceSelectionMode, PieceSet, PrincipalType } from '@activepieces/shared'
+import { PieceSelectionMode, PieceSet, PrincipalType, RequiredActionsMode } from '@activepieces/shared'
import { FastifyInstance } from 'fastify'
import { StatusCodes } from 'http-status-codes'
import { databaseConnection } from '../../../../src/app/database/database-connection'
@@ -41,7 +41,7 @@ async function setupPlatformWithoutPieceSets() {
return { mockOwner, mockPlatform, token }
}
-const emptyConfig = { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }, selectedActions: {}, selectedTriggers: {} }
+const emptyConfig = { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }, selectedActions: {}, selectedTriggers: {}, requiredActions: { mode: RequiredActionsMode.ANY, actions: {} } }
describe('Piece Sets API', () => {
describe('Feature Gate', () => {
diff --git a/packages/server/api/test/integration/ee/piece-sets/required-actions.test.ts b/packages/server/api/test/integration/ee/piece-sets/required-actions.test.ts
new file mode 100644
index 00000000000..1336917b1aa
--- /dev/null
+++ b/packages/server/api/test/integration/ee/piece-sets/required-actions.test.ts
@@ -0,0 +1,235 @@
+import { apId } from '@activepieces/core-utils'
+import { DefaultProjectRole, ErrorCode, FlowActionType, FlowAction, FlowOperationType, FlowStatus, FlowTriggerType, FlowVersionState, PackageType, PieceSelectionMode, PieceSet, PieceType, RequiredActionsMode } from '@activepieces/shared'
+import dayjs from 'dayjs'
+import { FastifyInstance } from 'fastify'
+import { StatusCodes } from 'http-status-codes'
+import { db } from '../../../helpers/db'
+import { createMockConnection, createMockFlow, createMockFlowVersion, createMockPieceMetadata, createMockProject } from '../../../helpers/mocks'
+import { createMemberContext, createTestContext, TestContext } from '../../../helpers/test-context'
+import { setupTestEnvironment, teardownTestEnvironment } from '../../../helpers/test-setup'
+
+const CRM = '@activepieces/piece-required-crm'
+
+let app: FastifyInstance | null = null
+
+beforeAll(async () => {
+ app = await setupTestEnvironment()
+})
+
+afterAll(async () => {
+ await teardownTestEnvironment()
+})
+
+async function saveCrmPiece(): Promise<void> {
+ await db.save('piece_metadata', createMockPieceMetadata({
+ name: CRM,
+ version: '0.0.1',
+ pieceType: PieceType.OFFICIAL,
+ packageType: PackageType.REGISTRY,
+ actions: {
+ create_deal: { name: 'create_deal', displayName: 'Create deal', description: '', props: {}, requireAuth: false },
+ update_contact: { name: 'update_contact', displayName: 'Update contact', description: '', props: {}, requireAuth: false },
+ ask_agent: { name: 'ask_agent', displayName: 'Ask agent', description: '', props: {}, requireAuth: false, audience: 'ai' },
+ },
+ }))
+}
+
+async function createSetWithRule({ ctx, actions, mode = RequiredActionsMode.ANY }: { ctx: TestContext, actions: Record<string, string[]>, mode?: RequiredActionsMode }): Promise<PieceSet> {
+ const set = (await ctx.post('/v1/piece-sets', { name: `Set ${apId()}` })).json<PieceSet>()
+ await ctx.post(`/v1/piece-sets/${set.id}`, { requiredActions: { mode, actions } })
+ await ctx.post(`/v1/piece-sets/${set.id}/projects`, { projectIds: [ctx.project.id] })
+ return set
+}
+
+function crmStep({ name, actionName, skip }: { name: string, actionName: string, skip?: boolean }): FlowAction {
+ return {
+ name,
+ type: FlowActionType.PIECE,
+ valid: true,
+ displayName: name,
+ skip,
+ lastUpdatedDate: dayjs().toISOString(),
+ settings: {
+ pieceName: CRM,
+ pieceVersion: '0.0.1',
+ actionName,
+ input: {},
+ propertySettings: {},
+ errorHandlingOptions: {},
+ },
+ }
+}
+
+async function saveDraftFlow({ ctx, head }: { ctx: TestContext, head?: FlowAction }): Promise<string> {
+ const flow = createMockFlow({ projectId: ctx.project.id, status: FlowStatus.DISABLED })
+ await db.save('flow', flow)
+ await db.save('flow_version', createMockFlowVersion({
+ flowId: flow.id,
+ updatedBy: ctx.user.id,
+ state: FlowVersionState.DRAFT,
+ trigger: {
+ type: FlowTriggerType.EMPTY,
+ name: 'trigger',
+ settings: {},
+ valid: false,
+ displayName: 'Select Trigger',
+ lastUpdatedDate: dayjs().toISOString(),
+ nextAction: head,
+ },
+ }))
+ return flow.id
+}
+
+describe('Required actions', () => {
+ describe('GET /v1/piece-sets/projects/:projectId', () => {
+ it('returns the Default Set with an empty rule for a project with no set', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ const response = await ctx.get(`/v1/piece-sets/projects/${ctx.project.id}`)
+ expect(response.statusCode).toBe(StatusCodes.OK)
+ const body = response.json<PieceSet>()
+ expect(body.isDefault).toBe(true)
+ expect(body.config.requiredActions).toEqual({ mode: RequiredActionsMode.ANY, actions: {} })
+ })
+
+ it('returns the assigned set to a project member', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ const set = await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ const member = await createMemberContext(app!, ctx, { projectRole: DefaultProjectRole.VIEWER })
+ const response = await member.get(`/v1/piece-sets/projects/${ctx.project.id}`)
+ expect(response.statusCode).toBe(StatusCodes.OK)
+ expect(response.json<PieceSet>().id).toBe(set.id)
+ })
+
+ it('refuses a member of another project', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ const member = await createMemberContext(app!, ctx, { projectRole: DefaultProjectRole.VIEWER })
+ const otherProject = createMockProject({ platformId: ctx.platform.id, ownerId: ctx.user.id })
+ await db.save('project', otherProject)
+ const response = await member.get(`/v1/piece-sets/projects/${otherProject.id}`)
+ expect(response.statusCode).toBe(StatusCodes.FORBIDDEN)
+ })
+ })
+
+ describe('Save rules', () => {
+ it('rejects requiring an action the set excludes', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ const set = (await ctx.post('/v1/piece-sets', { name: 'Excluded' })).json<PieceSet>()
+ await ctx.post(`/v1/piece-sets/${set.id}`, { actions: { [CRM]: { mode: 'selected', selected: ['update_contact'] } } })
+ const response = await ctx.post(`/v1/piece-sets/${set.id}`, { requiredActions: { actions: { [CRM]: ['create_deal'] } } })
+ expect(response.statusCode).toBe(StatusCodes.CONFLICT)
+ })
+
+ it('removes a required action when the same piece is excluded', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ const set = (await ctx.post('/v1/piece-sets', { name: 'Prune' })).json<PieceSet>()
+ await ctx.post(`/v1/piece-sets/${set.id}`, { requiredActions: { actions: { [CRM]: ['create_deal'] } } })
+ const response = await ctx.post(`/v1/piece-sets/${set.id}`, { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [CRM] } })
+ expect(response.json<PieceSet>().config.requiredActions.actions).toEqual({})
+ })
+ })
+
+ describe('Publish', () => {
+ it('rejects a flow without the required action', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ const flowId = await saveDraftFlow({ ctx })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.statusCode).toBe(StatusCodes.BAD_REQUEST)
+ const body = response.json()
+ expect(body.code).toBe(ErrorCode.REQUIRED_ACTIONS_MISSING)
+ expect(body.params.missingActions).toEqual({ [CRM]: ['create_deal'] })
+ expect(typeof body.params.message).toBe('string')
+ })
+
+ it('rejects a flow whose required step is skipped', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ const flowId = await saveDraftFlow({ ctx, head: crmStep({ name: 'step_1', actionName: 'create_deal', skip: true }) })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.json().params.skippedActions).toEqual({ [CRM]: ['create_deal'] })
+ })
+
+ it('does not block a flow that has the required action', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ const flowId = await saveDraftFlow({ ctx, head: crmStep({ name: 'step_1', actionName: 'create_deal' }) })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.json().code).not.toBe(ErrorCode.REQUIRED_ACTIONS_MISSING)
+ })
+
+ it('ignores a required action that is not in the latest piece version', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ const set = await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ await db.save('piece_set', { ...set, config: { ...set.config, requiredActions: { mode: RequiredActionsMode.ANY, actions: { [CRM]: ['log_call'] } } } })
+ const flowId = await saveDraftFlow({ ctx })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.json().code).not.toBe(ErrorCode.REQUIRED_ACTIONS_MISSING)
+ })
+
+ it('ignores a required action that only AI agents can use', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ await createSetWithRule({ ctx, actions: { [CRM]: ['ask_agent'] } })
+ const flowId = await saveDraftFlow({ ctx })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.json().code).not.toBe(ErrorCode.REQUIRED_ACTIONS_MISSING)
+ })
+
+ it('does not check when the plan has no Manage pieces', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: false } })
+ await saveCrmPiece()
+ await db.save('piece_set', {
+ id: apId(),
+ platformId: ctx.platform.id,
+ name: 'Default',
+ key: 'default',
+ isDefault: true,
+ generatedForProjectId: null,
+ config: {
+ pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
+ selectedActions: {},
+ selectedTriggers: {},
+ requiredActions: { mode: RequiredActionsMode.ANY, actions: { [CRM]: ['create_deal'] } },
+ },
+ })
+ const flowId = await saveDraftFlow({ ctx })
+ const response = await ctx.post(`/v1/flows/${flowId}`, { type: FlowOperationType.LOCK_AND_PUBLISH, request: {} })
+ expect(response.json().code).not.toBe(ErrorCode.REQUIRED_ACTIONS_MISSING)
+ })
+ })
+
+ describe('Connection replace', () => {
+ it('does not refuse the replace when a republished flow misses a required action', async () => {
+ const ctx = await createTestContext(app!, { plan: { managePiecesEnabled: true } })
+ await saveCrmPiece()
+ await createSetWithRule({ ctx, actions: { [CRM]: ['create_deal'] } })
+ const source = createMockConnection({ platformId: ctx.platform.id, projectIds: [ctx.project.id], pieceName: CRM }, ctx.user.id)
+ const target = createMockConnection({ platformId: ctx.platform.id, projectIds: [ctx.project.id], pieceName: CRM }, ctx.user.id)
+ await db.save('app_connection', [source, target])
+ const flow = createMockFlow({ projectId: ctx.project.id, status: FlowStatus.DISABLED })
+ await db.save('flow', flow)
+ const publishedVersion = createMockFlowVersion({
+ flowId: flow.id,
+ displayName: 'Deal sync',
+ state: FlowVersionState.LOCKED,
+ connectionIds: [source.externalId],
+ })
+ await db.save('flow_version', publishedVersion)
+ await db.update('flow', flow.id, { publishedVersionId: publishedVersion.id })
+
+ const response = await ctx.post('/v1/app-connections/replace', {
+ sourceAppConnectionId: source.id,
+ targetAppConnectionId: target.id,
+ projectId: ctx.project.id,
+ applyToPublishedVersions: true,
+ })
+
+ expect(response.statusCode).toBe(StatusCodes.NO_CONTENT)
+ })
+ })
+})
diff --git a/packages/server/api/test/unit/app/ee/pieces/piece-set-config.test.ts b/packages/server/api/test/unit/app/ee/pieces/piece-set-config.test.ts
deleted file mode 100644
index a151de7cf29..00000000000
--- a/packages/server/api/test/unit/app/ee/pieces/piece-set-config.test.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { PieceSelectionMode, PieceSetConfig } from '@activepieces/shared'
-import { pieceSetConfig } from '../../../../../src/app/ee/pieces/piece-set/piece-set-config'
-
-const base: PieceSetConfig = {
- pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
- selectedActions: {},
- selectedTriggers: {},
-}
-
-describe('pieceSetConfig.applyUpdate', () => {
- it('replaces the pieces selection wholesale when provided', () => {
- const result = pieceSetConfig.applyUpdate({
- current: base,
- request: { pieces: { mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] } },
- })
- expect(result.pieces).toEqual({ mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] })
- })
-
- it('leaves the pieces selection untouched when not provided', () => {
- const current = { ...base, pieces: { mode: PieceSelectionMode.EXCLUDE_ALL, exceptions: ['slack'] } }
- const result = pieceSetConfig.applyUpdate({ current, request: { actions: {} } })
- expect(result.pieces).toEqual(current.pieces)
- })
-
- it('sets a selected allow-list and dedupes', () => {
- const result = pieceSetConfig.applyUpdate({
- current: base,
- request: { actions: { slack: { mode: 'selected', selected: ['a', 'a', 'b'] } } },
- })
- expect(result.selectedActions).toEqual({ slack: ['a', 'b'] })
- })
-
- it('keeps an empty selected array (hide-all) rather than deleting the key', () => {
- const result = pieceSetConfig.applyUpdate({
- current: base,
- request: { actions: { slack: { mode: 'selected', selected: [] } } },
- })
- expect(result.selectedActions).toEqual({ slack: [] })
- })
-
- it('mode "all" deletes the piece key (reset to all)', () => {
- const current = { ...base, selectedActions: { slack: ['a'], gmail: ['b'] } }
- const result = pieceSetConfig.applyUpdate({
- current,
- request: { actions: { slack: { mode: 'all' } } },
- })
- expect(result.selectedActions).toEqual({ gmail: ['b'] })
- })
-
- it('merges per-piece: only referenced keys change', () => {
- const current = { ...base, selectedActions: { slack: ['a'], gmail: ['b'] } }
- const result = pieceSetConfig.applyUpdate({
- current,
- request: { actions: { slack: { mode: 'selected', selected: ['c'] } } },
- })
- expect(result.selectedActions).toEqual({ slack: ['c'], gmail: ['b'] })
- })
-
- it('handles triggers the same way as actions', () => {
- const result = pieceSetConfig.applyUpdate({
- current: base,
- request: { triggers: { slack: { mode: 'selected', selected: ['new_message'] } } },
- })
- expect(result.selectedTriggers).toEqual({ slack: ['new_message'] })
- })
-})
-
-describe('pieceSetConfig.emptyConfig', () => {
- it('is fully permissive (include_all, no component selections)', () => {
- expect(pieceSetConfig.emptyConfig()).toEqual({
- pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] },
- selectedActions: {},
- selectedTriggers: {},
- })
- })
-})