{"id":20726386,"url":"https://github.com/nocode-js/sequential-workflow-machine","last_synced_at":"2025-10-29T15:31:23.909Z","repository":{"id":106206563,"uuid":"609486686","full_name":"nocode-js/sequential-workflow-machine","owner":"nocode-js","description":"Powerful sequential workflow machine for front-end and back-end applications.","archived":false,"fork":false,"pushed_at":"2024-08-17T13:32:44.000Z","size":192,"stargazers_count":48,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-07T12:12:52.842Z","etag":null,"topics":["javascript","lowcode","nocode","typescript","workflow","workflow-engine","workflows"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nocode-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-04T10:22:37.000Z","updated_at":"2025-01-17T12:09:27.000Z","dependencies_parsed_at":"2024-11-22T08:30:53.740Z","dependency_job_id":null,"html_url":"https://github.com/nocode-js/sequential-workflow-machine","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"938a9e403bc77849902099f0ae5e22706a285054"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nocode-js%2Fsequential-workflow-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nocode-js%2Fsequential-workflow-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nocode-js%2Fsequential-workflow-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nocode-js%2Fsequential-workflow-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nocode-js","download_url":"https://codeload.github.com/nocode-js/sequential-workflow-machine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238845379,"owners_count":19540328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","lowcode","nocode","typescript","workflow","workflow-engine","workflows"],"created_at":"2024-11-17T04:24:44.200Z","updated_at":"2025-10-29T15:31:23.416Z","avatar_url":"https://github.com/nocode-js.png","language":"TypeScript","readme":"# Sequential Workflow Machine\n\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fnocode-js%2Fsequential-workflow-machine%2Fbadge%3Fref%3Dmain\u0026style=flat-square)](https://actions-badge.atrox.dev/b4rtaz/sequential-workflow-machine/goto?ref=main) [![License: MIT](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](/LICENSE) [![View this project on NPM](https://img.shields.io/npm/v/sequential-workflow-machine.svg?style=flat-square)](https://npmjs.org/package/sequential-workflow-machine)\n\nThe powerful sequential workflow machine for frontend and backend applications. It provides a simple API for creating its own step execution handlers (activities). It supports multiple types of activities. Internally it uses the [xstate](https://github.com/statelyai/xstate) library.\n\nThis machine uses the same data model as the [Sequential Workflow Designer](https://github.com/nocode-js/sequential-workflow-designer). So you can create a workflow definition in the designer and then run it by this machine easily.\n\n📝 Check the [documentation](https://nocode-js.com/docs/category/sequential-workflow-machine) for more details.\n\n## 🚀 Installation\n\nInstall the following packages by NPM command:\n\n```\nnpm i sequential-workflow-model sequential-workflow-machine\n```\n\n## 🎬 Usage\n\nYou can use the machine in a JavaScript or TypeScript application. We recommend using TypeScript because a workflow uses a lot of data structures and it's hard to maintain data integrity.\n\nAt the beginning, you need to define the type of your workflow definition.\n\n```ts\nimport { Definition } from 'sequential-workflow-model';\n\ninterface MyDefinition extends Definition {\n  properties: {\n    verbose: boolean;\n  };\n}\n```\n\nNext, define your step types.\n\n```ts\nimport { Step } from 'sequential-workflow-model';\n\ninterface DownloadHtmlStep extends Step {\n  componentType: 'task';\n  type: 'downloadHtml';\n  properties: {\n    pageUrl: string;\n  };\n}\n\n// ...\n```\n\nPrepare the workflow definition.\n\n```ts\nconst definition: MyDefinition = {\n  properties: {\n    verbose: true,\n  },\n  sequence: [\n    {\n      id: '0x00001',\n      componentType: 'task',\n      type: 'downloadHtml',\n      name: 'Download google.com',\n      properties: {\n        pageUrl: 'https://www.google.com',\n      },\n    },\n  ],\n};\n```\n\nPrepare the global state interface.\n\n```ts\ninterface WorkflowGlobalState {\n  html: string | null;\n}\n```\n\nPrepare activities for your steps. The machine supports multiple types of activities. The basic activity is the atom activity. It's a simple handler that executes an atomic step and updates the global state.\n\n```ts\nimport { createAtomActivity } from 'sequential-workflow-machine';\n\ninterface DownloadHtmlStepState {\n  attempt: number;\n}\n\nconst downloadHtmlActivity = createAtomActivity\u003cDownloadHtmlStep, WorkflowGlobalState, DownloadHtmlStepState\u003e('downloadHtml', {\n  init: () =\u003e ({\n    attempt: 0,\n  }),\n  handler: async (step: DownloadHtmlStep, globalState: WorkflowGlobalState, activityState: DownloadHtmlStepState) =\u003e {\n    globalState.html = await downloadHtml(step.properties.pageUrl);\n    activityState.attempt++;\n  },\n});\n```\n\nNow we can create the activity set. The activity set is a collection of all supported activities.\n\n```ts\nimport { createActivitySet } from 'sequential-workflow-machine';\n\nconst activitySet = createActivitySet\u003cWorkflowGlobalState\u003e([\n  downloadHtmlActivity,\n]);\n```\n\nFinally, we can create the workflow machine and run it.\n\n```ts\nimport { createWorkflowMachineBuilder } from 'sequential-workflow-machine';\n\nconst builder = createWorkflowMachineBuilder\u003cWorkflowGlobalState\u003e(activitySet);\nconst machine = builder.build(definition);\nconst interpreter = machine.create({\n  init: () =\u003e {\n    return {\n      html: null,\n    };\n  }\n});\ninterpreter.onChange(() =\u003e { /* ... */ });\ninterpreter.onDone(() =\u003e { /* ... */ });\ninterpreter.start();\n```\n\nThat's it!\n\n## 💡 License\n\nThis project is released under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnocode-js%2Fsequential-workflow-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnocode-js%2Fsequential-workflow-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnocode-js%2Fsequential-workflow-machine/lists"}