Skip to content
11 changes: 10 additions & 1 deletion packages/client/src/v2-events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
SystemVariables,
Scope,
ActionScopes,
ConfigurableActionScopes,
parseConfigurableScope,
WorkqueueConfigWithoutQuery,
joinValues,
UUID,
Expand Down Expand Up @@ -232,7 +234,14 @@ export enum CoreWorkqueues {
}

export function hasOutboxWorkqueue(scopes: Scope[]) {
return scopes.some((scope) => ActionScopes.safeParse(scope).success)
const hasLiteralActionScopes = scopes.some(
(scope) => ActionScopes.safeParse(scope).success
)
const parsedScopes = scopes.map(parseConfigurableScope)
const hasConfigurableActionScopes = parsedScopes.some(
(scope) => ConfigurableActionScopes.safeParse(scope).success
)
return hasLiteralActionScopes || hasConfigurableActionScopes
}

export function hasDraftWorkqueue(scopes: Scope[]) {
Expand Down
3 changes: 3 additions & 0 deletions packages/commons/src/conditionals/conditionals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,9 @@ describe('"flag" conditionals', () => {
expect(validate(flag(InherentFlags.CORRECTION_REQUESTED), params)).toBe(
false
)
expect(
validate(not(flag(InherentFlags.CORRECTION_REQUESTED)), params)
).toBe(true)
})

it('validation fails if params dont include flags', () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/commons/src/events/EventConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DeclarationFormConfig } from './FormConfig'

import { FieldType } from './FieldType'
import { FieldReference } from './FieldConfig'
import { FlagConfig } from './Flag'
import { FlagConfig, InherentFlags } from './Flag'

/**
* Description of event features defined by the country. Includes configuration for process steps and forms involved.
Expand Down Expand Up @@ -141,10 +141,16 @@ export const EventConfig = z
)

for (const actionFlagId of actionFlagIds) {
if (!configuredFlagIds.includes(actionFlagId)) {
const isConfigured = configuredFlagIds.includes(actionFlagId)
const isInherent = Object.values(InherentFlags).includes(
// @ts-expect-error - actionFlagId can be a inherent flag or any string
actionFlagId
)

if (!isConfigured && !isInherent) {
ctx.addIssue({
code: 'custom',
message: `Action flag id must match a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
message: `Action flag id must match an inherent flag or a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
path: ['actions']
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/commons/src/events/Flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type FlagConfig = z.infer<typeof FlagConfig>
* Configuration for a flag action, which is executed when the action is performed.
*/
export const ActionFlagConfig = z.object({
id: CustomFlag,
id: Flag,
operation: z
.enum(['add', 'remove'])
.describe('Operation to perform on the flag.'),
Expand Down
6 changes: 6 additions & 0 deletions packages/commons/src/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ const ConfigurableRawScopes = z.discriminatedUnion('type', [
CustomActionScope
])

export const ConfigurableActionScopes = z.discriminatedUnion('type', [
// @TODO - Configure actual action scopes
RecordScope,
CustomActionScope
])

type ConfigurableRawScopes = z.infer<typeof ConfigurableRawScopes>
export type ConfigurableScopeType = ConfigurableRawScopes['type']

Expand Down
Loading