{"_id":"@dixxanta08/stategate","_rev":"3-5b20bc709820a17ccd6b4b93724928f4","name":"@dixxanta08/stategate","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@dixxanta08/stategate","version":"0.1.0","keywords":["state-machine","orders","backend","ecommerce","fsm"],"license":"MIT","_id":"@dixxanta08/stategate@0.1.0","maintainers":[{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"}],"homepage":"https://github.com/dixxanta08/stategate","bugs":{"url":"https://github.com/dixxanta08/stategate/issues"},"dist":{"shasum":"cfbec1d80dde05fe11eaaa664a43cc47a3ae3328","tarball":"https://registry.npmjs.org/@dixxanta08/stategate/-/stategate-0.1.0.tgz","fileCount":12,"integrity":"sha512-CRseEemO5luGZGuad2pdamZXwcFuCNFtTSE2Aosgsodyp1OBVULWl5kHF9Ni4BpHirjVgzV8D34Ckc3EZqC9yw==","signatures":[{"sig":"MEUCIQDcWyhvkyvLM0Y0vrAMTkU+mEUBcMfnI07amvSoHSr4RgIgJ8j2REcvywJkdY7a4e9Paj4cd9zUtWAgFMlKC2pRmmw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11896},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"7d7ff9c2455370808ed7003c84a57c4efa9a50e4","scripts":{"test":"jest","build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"},"repository":{"url":"git+https://github.com/dixxanta08/stategate.git","type":"git"},"_npmVersion":"9.4.2","description":"Deterministic state machine for backend workflows","directories":{},"_nodeVersion":"22.19.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.1.2","@types/jest":"^29.5.12"},"_npmOperationalInternal":{"tmp":"tmp/stategate_0.1.0_1770600455994_0.6676435898814184","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@dixxanta08/stategate","version":"0.1.1","keywords":["state-machine","orders","backend","ecommerce","fsm"],"license":"MIT","_id":"@dixxanta08/stategate@0.1.1","maintainers":[{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"}],"homepage":"https://github.com/dixxanta08/stategate","bugs":{"url":"https://github.com/dixxanta08/stategate/issues"},"dist":{"shasum":"df3ed554bc61a5449795f874c71042548c42a72f","tarball":"https://registry.npmjs.org/@dixxanta08/stategate/-/stategate-0.1.1.tgz","fileCount":12,"integrity":"sha512-vXz1hwGjqpFrcbUYsBxbAstPJvZNlwxHE6vZd1PwC2vNN8+r1cn+RzLNZ5cxqykMjLbGcTWPm5KOsKkRPLTR9Q==","signatures":[{"sig":"MEQCIDPXl+6SOxiYgqiJX8mncgSn1aN5bw3VfYXdY5m7NIHBAiAJBXHIFHYEsswQb0FxpijcGPLlnET5phXcV4YUBeZj6g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16942},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"36a580610446df06501653b0634d8f77b0b832b8","scripts":{"test":"jest","build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"},"repository":{"url":"git+https://github.com/dixxanta08/stategate.git","type":"git"},"_npmVersion":"9.4.2","description":"Deterministic state machine for backend workflows","directories":{},"_nodeVersion":"22.19.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.1.2","@types/jest":"^29.5.12"},"_npmOperationalInternal":{"tmp":"tmp/stategate_0.1.1_1770600908462_0.9299565137682482","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@dixxanta08/stategate","version":"0.1.2","description":"Deterministic state machine for backend workflows","main":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/dixxanta08/stategate.git"},"homepage":"https://github.com/dixxanta08/stategate","bugs":{"url":"https://github.com/dixxanta08/stategate/issues"},"keywords":["state-machine","orders","backend","ecommerce","fsm"],"license":"MIT","scripts":{"build":"tsc","test":"jest","prepublishOnly":"npm run build"},"devDependencies":{"@types/jest":"^29.5.12","jest":"^30.2.0","ts-jest":"^29.1.2"},"gitHead":"7ade29a3bf06503921a39541900aeb2e1f26d66c","_id":"@dixxanta08/stategate@0.1.2","_nodeVersion":"22.19.0","_npmVersion":"9.4.2","dist":{"integrity":"sha512-DN7lTHPlSL6TPuK/V3t/CQoI2y9o7ZmiSthi6Q8RoUPz5e15ae2w+tsC62YatzHHyHwYZZG2lOg0safL0sunBQ==","shasum":"a99aa8dfb4370e1e1fe8c1f27264590292635138","tarball":"https://registry.npmjs.org/@dixxanta08/stategate/-/stategate-0.1.2.tgz","fileCount":12,"unpackedSize":14106,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIC9VP8slRzO//MQKA+QLdIrsZyt0TH4xRKAmItWOrud6AiEAgpLYBKri+kdI7zrWsKQ7yzh6DiKM7EgaVURFo83AT0Y="}]},"_npmUser":{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"},"directories":{},"maintainers":[{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/stategate_0.1.2_1770601151449_0.8149073223202021"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-09T01:27:35.886Z","modified":"2026-02-09T01:39:11.731Z","0.1.0":"2026-02-09T01:27:36.159Z","0.1.1":"2026-02-09T01:35:08.621Z","0.1.2":"2026-02-09T01:39:11.603Z"},"bugs":{"url":"https://github.com/dixxanta08/stategate/issues"},"license":"MIT","homepage":"https://github.com/dixxanta08/stategate","keywords":["state-machine","orders","backend","ecommerce","fsm"],"repository":{"type":"git","url":"git+https://github.com/dixxanta08/stategate.git"},"description":"Deterministic state machine for backend workflows","maintainers":[{"name":"dixxanta08","email":"dixantashrestha08@gmail.com"}],"readme":"[![npm version](https://badge.fury.io/js/%40dixxanta08%2Fstategate.svg)](https://badge.fury.io/js/%40dixxanta08%2Fstategate)\r\n\r\n# Stategate\r\n\r\nA flexible, type-safe state machine library for JavaScript/TypeScript projects. Easily manage entity state transitions, enforce business rules, and hook into lifecycle events.\r\n\r\n## Features\r\n\r\n- Type-safe state transitions\r\n- Abortable transitions with custom handlers\r\n- Global hooks for before/after/error/invalid transitions\r\n- Extensible event system\r\n- Designed for use in Node.js and browser environments\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @dixxanta08/stategate\r\n```\r\n\r\n## Usage\r\n\r\n```typescript\r\nimport { StateMachine } from \"@dixxanta08/stategate\";\r\n\r\nconst config = {\r\n  initialState: \"pending\",\r\n  transitions: {\r\n    pending: {\r\n      approved: {\r\n        isAbortable: true,\r\n        onBefore: async (entity) => {\r\n          // Custom logic before transition\r\n        },\r\n        onAfter: async (entity) => {\r\n          // Custom logic after transition\r\n        },\r\n        onAbort: (payload) => {\r\n          console.log(\"Transition aborted\", payload);\r\n        },\r\n        details: {\r\n          label: \"Approve\",\r\n          description: \"Approve the entity\",\r\n          allowedActors: \"admin\",\r\n        },\r\n      },\r\n    },\r\n    approved: {\r\n      archived: {\r\n        onBefore: async (entity) => {\r\n          // Custom logic\r\n        },\r\n      },\r\n    },\r\n  },\r\n  globalHooks: {\r\n    beforeTransition: [\r\n      async (payload) => {\r\n        console.log(\"Before transition\", payload);\r\n      },\r\n    ],\r\n    afterTransition: [\r\n      async (payload) => {\r\n        console.log(\"After transition\", payload);\r\n      },\r\n    ],\r\n    onInvalidTransition: (payload) => {\r\n      console.error(\"Invalid transition\", payload);\r\n    },\r\n    onError: (error, payload) => {\r\n      console.error(\"Transition error\", error, payload);\r\n    },\r\n  },\r\n};\r\n\r\nconst entity = { status: \"pending\" };\r\nconst machine = new StateMachine(config);\r\n\r\nmachine.transition(entity, \"approved\", { actor: \"admin\" });\r\n```\r\n\r\n## API\r\n\r\n### StateMachine\r\n\r\n- `constructor(config: MachineConfig)` — Initialize with a machine config\r\n- `transition(entity, nextState, context?)` — Perform a state transition\r\n- `on(event, callback)` — Register event handler\r\n- `emit(event)` — Trigger event handlers\r\n\r\n### Types\r\n\r\n- `MachineConfig` — State machine configuration\r\n- `TransitionConfig` — Per-transition settings\r\n- `TransitionPayload` — Transition event payload\r\n- `AbortTransition`, `InvalidTransition` — Custom error classes\r\n\r\n## Upcoming Updates\r\n\r\n- Visualizer for state machines\r\n- Built-in validation for transitions and configs\r\n- Metrics/telemetry hooks\r\n- Pre-built common workflows (orders, tasks, etc.)\r\n- Enhanced error handling and cancellation chaining\r\n\r\nStay tuned for more features!\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}