|
| 1 | +# @roostorg/coop-integration-example |
| 2 | + |
| 3 | +Example [COOP](https://github.com/roostorg/coop) integration plugin. Reference repository showing how to build a custom integration and signals for use in COOP. |
| 4 | + |
| 5 | +- **Integration config** – saving and loading per-org config (e.g. “True percentage”) |
| 6 | +- **Routing rules** – using the plugin signal in conditions |
| 7 | +- **Automated enforcement** – the same signal in enforcement rules |
| 8 | + |
| 9 | +## What it provides |
| 10 | + |
| 11 | +- **Integration:** `COOP_INTEGRATION_EXAMPLE` |
| 12 | +- **Signal 1 – Random Signal Selection** (`RANDOM_SIGNAL_SELECTION`): Returns `true` or `false` at random. The probability (0–100%) comes from the org’s integration config (“True percentage”). Set e.g. `70` in Org settings → Integrations; the signal returns `true` about 70% of the time. Use this to test config saving and boolean conditions. |
| 13 | +- **Signal 2 – Random Score** (`RANDOM_SCORE`): Returns a random number between 0 and 1. No integration config needed. In the rule builder you set a **threshold** (e.g. `0.5`) and choose **above** or **below**. Use this to test numeric score conditions (e.g. “score ≥ 0.5” or “score < 0.3”). |
| 14 | + |
| 15 | +## Install |
| 16 | + |
| 17 | +**From this repo (development):** |
| 18 | + |
| 19 | +```bash |
| 20 | +git clone https://github.com/roostorg/coop-integration-example.git |
| 21 | +cd coop-integration-example |
| 22 | +npm install |
| 23 | +npm run build |
| 24 | +``` |
| 25 | + |
| 26 | +**From npm:** |
| 27 | + |
| 28 | +```bash |
| 29 | +npm install @roostorg/coop-integration-example |
| 30 | +``` |
| 31 | + |
| 32 | +## Configure in COOP |
| 33 | + |
| 34 | +In your COOP `integrations.config.json` (or `INTEGRATIONS_CONFIG_PATH`), add: |
| 35 | + |
| 36 | +**Local path (development):** |
| 37 | +If you cloned this repo next to your COOP server directory, use a path relative to the server (e.g. from `server/`): |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "integrations": [ |
| 42 | + { "package": "../coop-integration-example", "enabled": true } |
| 43 | + ] |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +**From npm:** |
| 48 | + |
| 49 | +```json |
| 50 | +{ |
| 51 | + "integrations": [ |
| 52 | + { "package": "@roostorg/coop-integration-example", "enabled": true } |
| 53 | + ] |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +Restart the COOP server so it loads the plugin. |
| 58 | + |
| 59 | +## Use in the app |
| 60 | + |
| 61 | +1. **Org settings → Integrations** – you should see “COOP Integration Example”. Open it and set **True percentage (0–100)** (e.g. `70`) for Random Signal Selection. Save. |
| 62 | +2. **Rules (routing or enforcement)** – when adding a condition: |
| 63 | + - **Random Signal Selection**: Pick that signal; the condition uses your configured percentage (true/false). |
| 64 | + - **Random Score**: Pick “Random Score”, then set a **threshold** (e.g. `0.5`) and choose **above** or **below**. The rule compares the random score to your threshold. |
| 65 | + |
| 66 | +## Contract |
| 67 | + |
| 68 | +This package implements the COOP plugin contract from `@roostorg/types`: |
| 69 | + |
| 70 | +- **Default export:** `CoopIntegrationPlugin` with `manifest` and `createSignals(context)`. |
| 71 | +- **Manifest:** `id`, `name`, `version`, `requiresConfig`, `configurationFields`, `signalTypeIds`, `modelCard` (with required sections `modelDetails` and `technicalIntegration`). |
| 72 | +- **createSignals:** Returns two descriptors: |
| 73 | + - `RANDOM_SIGNAL_SELECTION`: `run(input)` uses `context.getCredential(orgId)` for true percentage; returns `{ outputType: { scalarType: 'BOOLEAN' }, score: boolean }`. |
| 74 | + - `RANDOM_SCORE`: `run()` returns `{ outputType: { scalarType: 'NUMBER' }, score: number }` in [0, 1]; no config. Threshold is set in the rule (above/below). |
| 75 | + |
| 76 | +## Publishing |
| 77 | + |
| 78 | +CI runs on push/PR (build only). To publish to npm: |
| 79 | + |
| 80 | +1. Create a [GitHub release](https://github.com/roostorg/coop-integration-example/releases) (tag e.g. `v1.0.1`). The **Publish to npm** workflow runs on release and runs `npm publish --access public`. |
| 81 | +2. Add **NPM_TOKEN** in this repo’s secrets (Settings → Secrets and variables → Actions): an npm [automation token](https://docs.npmjs.com/creating-and-viewing-access-tokens) with publish permission for `@roostorg/coop-integration-example`. |
| 82 | + |
| 83 | +You can also trigger **Publish to npm** manually from the Actions tab (workflow_dispatch). |
| 84 | + |
| 85 | +## License |
| 86 | + |
| 87 | +ISC |
0 commit comments