Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added no op event to workflow runner #2884

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/backoffice-v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ballerine/backoffice-v2

## 0.7.80

### Patch Changes

- @ballerine/workflow-browser-sdk@0.6.76
- @ballerine/workflow-node-sdk@0.6.76

## 0.7.79

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions apps/backoffice-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ballerine/backoffice-v2",
"version": "0.7.79",
"version": "0.7.80",
"description": "Ballerine - Backoffice",
"homepage": "https://github.com/ballerine-io/ballerine",
"type": "module",
Expand Down Expand Up @@ -55,8 +55,8 @@
"@ballerine/common": "0.9.57",
"@ballerine/react-pdf-toolkit": "^1.2.48",
"@ballerine/ui": "^0.5.48",
"@ballerine/workflow-browser-sdk": "0.6.75",
"@ballerine/workflow-node-sdk": "0.6.75",
"@ballerine/workflow-browser-sdk": "0.6.76",
"@ballerine/workflow-node-sdk": "0.6.76",
"@botpress/webchat": "^2.1.10",
"@botpress/webchat-generator": "^0.2.9",
"@fontsource/inter": "^4.5.15",
Expand Down
6 changes: 6 additions & 0 deletions apps/kyb-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# kyb-app

## 0.3.92

### Patch Changes

- @ballerine/workflow-browser-sdk@0.6.76

## 0.3.91

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions apps/kyb-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/kyb-app",
"private": true,
"version": "0.3.91",
"version": "0.3.92",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -18,7 +18,7 @@
"@ballerine/blocks": "0.2.28",
"@ballerine/common": "^0.9.57",
"@ballerine/ui": "0.5.49",
"@ballerine/workflow-browser-sdk": "0.6.75",
"@ballerine/workflow-browser-sdk": "0.6.76",
"@lukemorales/query-key-factory": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@rjsf/core": "^5.9.0",
Expand Down
6 changes: 6 additions & 0 deletions examples/headless-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ballerine/headless-example

## 0.3.75

### Patch Changes

- @ballerine/workflow-browser-sdk@0.6.76

## 0.3.74

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/headless-example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/headless-example",
"private": true,
"version": "0.3.74",
"version": "0.3.75",
"type": "module",
"scripts": {
"spellcheck": "cspell \"*\"",
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@ballerine/common": "0.9.57",
"@ballerine/workflow-browser-sdk": "0.6.75",
"@ballerine/workflow-browser-sdk": "0.6.76",
"@felte/reporter-svelte": "^1.1.5",
"@felte/validator-zod": "^1.0.13",
"@fontsource/inter": "^4.5.15",
Expand Down
6 changes: 6 additions & 0 deletions packages/workflow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ballerine/workflow-core

## 0.6.76

### Patch Changes

- Added no op event to workflow runner

## 0.6.75

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/workflow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/workflow-core",
"author": "Ballerine <dev@ballerine.com>",
"version": "0.6.75",
"version": "0.6.76",
"description": "workflow-core",
"module": "./dist/esm/index.js",
"main": "./dist/cjs/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/workflow-core/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ export const pluginsRegistry = {
new (...args: any[]) => any
>
>;

export const BUILT_IN_ACTION = {
NO_OP: 'NO_OP'
} as const;

export type BuiltInAction = (typeof BUILT_IN_ACTION)[keyof typeof BUILT_IN_ACTION];
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StateMachine } from 'xstate';
import { ruleValidator, TDefintionRules } from './rule-validator';
import { AnyRecord } from '@ballerine/common';
import { AnyRecord, isObject } from '@ballerine/common';
import { BUILT_IN_EVENT } from '../../built-in-event';

type TTransitionEvent = string;

Expand All @@ -9,6 +10,9 @@ type TTransitionOption =
target: string;
cond?: TDefintionRules;
}
| {
actions: string;
}
| string;
type TTransitionOptions = TTransitionOption[];
export const statesValidator = (
Expand Down Expand Up @@ -63,7 +67,22 @@ export const validateTransitionOnEvent = ({
currentState: string;
transition: TTransitionOption;
}) => {
const targetState = typeof transition === 'string' ? transition : transition.target;
const getTargetState = () => {
if (typeof transition === 'string') {
return transition;
}

if (isObject(transition) && 'target' in transition) {
return transition.target;
}

throw Error(`Unexpected transition object: ${JSON.stringify(transition)}`);
}
const targetState = getTargetState();

if (isObject(transition) && 'actions' in transition && transition.actions === BUILT_IN_EVENT.NO_OP) {
return;
}

if (!stateNames.includes(targetState)) {
throw new Error(`Invalid transition from ${currentState} to ${targetState}`);
Expand Down
11 changes: 10 additions & 1 deletion packages/workflow-core/src/lib/workflow-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { search } from 'jmespath';
import * as jsonLogic from 'json-logic-js';
import type { ActionFunction, MachineOptions, StateMachine } from 'xstate';
import { assign, createMachine, interpret } from 'xstate';
import { pluginsRegistry } from './constants';
import { BUILT_IN_ACTION, pluginsRegistry } from './constants';
import { HttpError } from './errors';
import { BUILT_IN_EVENT } from './index';
import { logger } from './logger';
Expand Down Expand Up @@ -464,9 +464,16 @@ export class WorkflowRunner {
}
}

const noOp = () => {
logger.log(`${BUILT_IN_ACTION.NO_OP} action fired`, {
state
})
}

const actions: MachineOptions<any, any>['actions'] = {
...workflowActions,
...stateActions,
[BUILT_IN_ACTION.NO_OP]: noOp
};

const guards: MachineOptions<any, any>['guards'] = {
Expand Down Expand Up @@ -541,6 +548,8 @@ export class WorkflowRunner {
},
);

const state = this.#__currentState;

return createMachine(
{
predictableActionArguments: true,
Expand Down
Loading
Loading