jsPolicy SDK
While there are many ways to write policies, you can use the jsPolicy SDK to get up and running faster and build on best practices. The jsPolicy SDK provides a project structure, some development and testing tools as well as some guidance on how to efficiently write, test and publish policies using TypeScript (or JavaScript).
Using jsPolicy SDK#
The jsPolicy SDK project on GitHub is desined as a template for you to get started with.
1. Clone Template Project#
So, to use jsPolicy SDK, clone the project:
2. Install Dev Dependencies#
This project has several devDependencies defined in the package.json, so let's install them:
3. Write & Compile Policies#
The project is structured like this:
To compile the policies defined in src/policies to ready-to-use JsPolicy + JsPolicyBundle combos, run:
For a more efficient hot reloading workflow, run:
To also apply the policies after each iterative compile process, run:
4. Test Policies#
The project is configured to use Jest and execute all files in tests/ as test suites. You can run the tests with this command:
5. Publish Policy Logic#
If you want to share policy logic from your lib/ folder, make sure you export the functions you want to make available by adding these functions in src/index.ts and then publish the project: