Skip to content

Commit 6ec05ff

Browse files
committed
first commit
0 parents  commit 6ec05ff

File tree

11 files changed

+539
-0
lines changed

11 files changed

+539
-0
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v6
17+
with:
18+
node-version-file: '.nvmrc'
19+
check-latest: true
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Build
26+
run: npm run build

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
id-token: write # Required for OIDC
10+
contents: read
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-node@v6
19+
with:
20+
node-version-file: '.nvmrc'
21+
check-latest: true
22+
cache: 'npm'
23+
registry-url: 'https://registry.npmjs.org'
24+
- run: npm ci
25+
- run: npm run build
26+
- run: npm publish

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# Environment
8+
.env
9+
.env.*
10+
!.env.example
11+
12+
# Logs and debug
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
.pnpm-debug.log*
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
22+
# IDE / editor
23+
.idea/
24+
.vscode/
25+
*.swp
26+
*.swo
27+
*~
28+
29+
# Optional npm cache
30+
.npm
31+
32+
# Optional eslint cache
33+
.eslintcache
34+
35+
# TypeScript incremental
36+
*.tsbuildinfo

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

package-lock.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@roostorg/coop-integration-example",
3+
"version": "1.0.0",
4+
"description": "Example package to show how a custom integration and signal can be used in COOP this is meant to be a reference repository and provide basic determination",
5+
"type": "module",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"files": [
9+
"dist",
10+
"README.md",
11+
"roost-example-logo.png",
12+
"roost-example-with-background.png"
13+
],
14+
"scripts": {
15+
"build": "tsc",
16+
"prepare": "npm run build",
17+
"prepublishOnly": "npm run build"
18+
},
19+
"keywords": [
20+
"coop",
21+
"integration",
22+
"plugin",
23+
"example"
24+
],
25+
"author": "Roostorg",
26+
"license": "apache-2.0",
27+
"repository": {
28+
"type": "git",
29+
"url": "https://github.com/roostorg/coop-integration-example.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/roostorg/coop-integration-example/issues"
33+
},
34+
"homepage": "https://github.com/roostorg/coop-integration-example#readme",
35+
"peerDependencies": {
36+
"@roostorg/types": ">=1.0.0"
37+
},
38+
"devDependencies": {
39+
"@roostorg/types": "^1.1.1",
40+
"typescript": "^5.0.0"
41+
},
42+
"engines": {
43+
"node": ">=18"
44+
}
45+
}

roost-example-logo.png

7.69 KB
Loading

roost-example-with-background.png

7.92 KB
Loading

0 commit comments

Comments
 (0)