···11+# @roostorg/coop-integration-example
22+33+Example [COOP](https://github.com/roostorg/coop) integration plugin. Reference repository showing how to build a custom integration and signals for use in COOP.
44+55+- **Integration config** – saving and loading per-org config (e.g. “True percentage”)
66+- **Routing rules** – using the plugin signal in conditions
77+- **Automated enforcement** – the same signal in enforcement rules
88+99+## What it provides
1010+1111+- **Integration:** `COOP_INTEGRATION_EXAMPLE`
1212+- **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.
1313+- **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”).
1414+1515+## Install
1616+1717+**From this repo (development):**
1818+1919+```bash
2020+git clone https://github.com/roostorg/coop-integration-example.git
2121+cd coop-integration-example
2222+npm install
2323+npm run build
2424+```
2525+2626+**From npm:**
2727+2828+```bash
2929+npm install @roostorg/coop-integration-example
3030+```
3131+3232+## Configure in COOP
3333+3434+In your COOP `integrations.config.json` (or `INTEGRATIONS_CONFIG_PATH`), add:
3535+3636+**Local path (development):**
3737+If you cloned this repo next to your COOP server directory, use a path relative to the server (e.g. from `server/`):
3838+3939+```json
4040+{
4141+ "integrations": [
4242+ { "package": "../coop-integration-example", "enabled": true }
4343+ ]
4444+}
4545+```
4646+4747+**From npm:**
4848+4949+```json
5050+{
5151+ "integrations": [
5252+ { "package": "@roostorg/coop-integration-example", "enabled": true }
5353+ ]
5454+}
5555+```
5656+5757+Restart the COOP server so it loads the plugin.
5858+5959+## Use in the app
6060+6161+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.
6262+2. **Rules (routing or enforcement)** – when adding a condition:
6363+ - **Random Signal Selection**: Pick that signal; the condition uses your configured percentage (true/false).
6464+ - **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.
6565+6666+## Contract
6767+6868+This package implements the COOP plugin contract from `@roostorg/types`:
6969+7070+- **Default export:** `CoopIntegrationPlugin` with `manifest` and `createSignals(context)`.
7171+- **Manifest:** `id`, `name`, `version`, `requiresConfig`, `configurationFields`, `signalTypeIds`, `modelCard` (with required sections `modelDetails` and `technicalIntegration`).
7272+- **createSignals:** Returns two descriptors:
7373+ - `RANDOM_SIGNAL_SELECTION`: `run(input)` uses `context.getCredential(orgId)` for true percentage; returns `{ outputType: { scalarType: 'BOOLEAN' }, score: boolean }`.
7474+ - `RANDOM_SCORE`: `run()` returns `{ outputType: { scalarType: 'NUMBER' }, score: number }` in [0, 1]; no config. Threshold is set in the rule (above/below).
7575+7676+## Publishing
7777+7878+CI runs on push/PR (build only). To publish to npm:
7979+8080+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`.
8181+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`.
8282+8383+You can also trigger **Publish to npm** manually from the Actions tab (workflow_dispatch).