Before you begin, ensure you have met the following requirements in local:
requirements with docker:
cat .env.sample
cp .env.sample.env
by default in the sample file the url are set to work with the mongodb provided in the docker compose file.
cp contract-agent.config.sample.json contract-agent.config.json
pnpm install
This will install all the necessary dependencies for your project.
pnpm dev
This command will use nodemon to watch for changes and restart your application when changes are detected.
pnpm gen-types
This command will generate TypeScript types based on your Mongoose models.
pnpm gen-swagger
This command will generate Swagger documentation, accessible at http://localhost:{port}/docs/#/
pnpm gen-docs
This command will generate documentation using TypeDoc for the source code and save it in a "docs" folder.
pnpm build
This command will clean the build/
directory and compile your TypeScript code.
pnpm start
This command will start your application using the compiled code.
git clone https://github.com/Prometheus-X-association/contract-manager.git
cd contract-manager
#example
NODE_ENV="development"
MONGO_USERNAME=""
MONGO_PASSWORD=""
MONGO_URL="mongodb://contract-manager-mongodb:27017/contract"
MONGO_TEST_URL="mongodb://contract-manager-mongodb:27017/test-contract"
SERVER_PORT=8888
SECRET_AUTH_KEY="abc123"
SECRET_SESSION_KEY="abc123Session"
CATALOG_REGISTRY_URL="https://registry.visionstrust.com/static/references/rules"
SERVER_BASE_URL=""
CATALOG_REGISTRY_FILE_EXT=""
LOGS_KEY=""
USE_CONTRACT_AGENT =true
CATALOG_AUTHORIZATION_KEY="123"
docker network create ptx
docker-compose up -d
docker-compose build
and restart with: docker-compose up -d
docker run -d -p your-port:your-port --name contract-manager contract-manager
after running docker-compose build
cd terraform
terraform init
terraform apply
terraform output contract_manager_service_ip
- Replace placeholder values in the
kubernetes_secret
resource with actual values from your.env
.- Ensure the
server_port
value matches the port used in your application.- Adjust the
host_path
in thekubernetes_persistent_volume
resource to an appropriate path on your Kubernetes nodes.
Install Helm: Ensure Helm is installed on your machine. You can install it following the instructions here.
Package the Helm chart:
helm package ./path/to/contract-manager
Deploy the Helm chart:
helm install contract-manager ./path/to/contract-manager
Verify the deployment:
kubectl get all -n contract-manager
Retrieve Service IP:
kubectl get svc -n contract-manager
- Replace placeholder values in the
values.yaml
file with actual values from your.env
.- Ensure the
server_port
value matches the port used in your application.- Configure your MongoDB connection details in the values.yaml file to point to your managed MongoDB instance.
pnpm test
This command will run your tests using Mocha, with test files located at ./src/tests/!(*.agent).test.ts
.
To enable the Contract Agent, add the following line to your .env
file:
USE_CONTRACT_AGENT=true
contract-agent.config.json
)The configuration file is a JSON document consisting of sections, where each section describes the configuration for a specific DataProvider. Below is a detailed explanation of the available attributes:
source
: The name of the target collection or table that the DataProvider connects to.url
: The base URL of the database host.dbName
: The name of the database to be used.watchChanges
: A boolean that enables or disables change monitoring for the DataProvider. When enabled, events will be fired upon detecting changes.hostsProfiles
: A boolean indicating whether the DataProvider hosts the profiles.existingDataCheck
: A boolean that enables the creation of profiles when the module is initialized.Here’s an example of a JSON configuration:
{
"dataProviderConfig": [
{
"source": "contracts",
"url": "mongodb://contract-manager-mongodb:27017",
"dbName": "contract"
},
{
"source": "profiles",
"url": "mongodb://contract-manager-mongodb:27017",
"dbName": "contract",
"watchChanges": false,
"hostsProfiles": true
}
]
}
pnpm test-agent
or
docker exec -it contract-manager pnpm test-agent
This command will run your tests using Mocha, with test files located at ./src/tests/*.agent.test.ts
.
POST /contracts
First create the contract to create the profile
headers:
{"x-ptx-catalog-key": process.env.CATALOG_AUTHORIZATION_KEY, Content-Type: application/json}
the x-ptx-catalog-key is needed if you have set up the optional variable CATALOG_AUTHORIZATION_KEY in you .env
input:
{ "role": "ecosystem", "contract": { "ecosystem": "test-ecosystem", "orchestrator": "", "serviceOfferings": [ { "participant": "participant-1", "serviceOffering": "allowed-service", "policies": [ { "description": "allowed-policy", "permission": [ { "action": "read", "target": "http://contract-target/policy", "duty": [], "constraint": [] }, { "action": "use", "target": "http://contract-target/service", "duty": [], "constraint": [] } ], "prohibition": [] } ], } ], "purpose": [], "members": [], "revokedMembers": [], "dataProcessings": [], } }
output :
{ "ecosystem": "test-ecosystem", "orchestrator": "", "serviceOfferings": [ { "participant": "participant-1", "serviceOffering": "allowed-service", "policies": [ { "description": "allowed-policy", "permission": [ { "action": "read", "target": "http://contract-target/policy", "duty": [], "constraint": [] }, { "action": "use", "target": "http://contract-target/service", "duty": [], "constraint": [] } ], "prohibition": [] } ], "_id": "67dc5c77a4e381ca892935d7" } ], "rolesAndObligations": [ { "role": "ecosystem", "policies": [ { "permission": [], "prohibition": [] } ], "_id": "67dc5ead968a8212c516f18b" } ], "dataProcessings": [], "purpose": [], "members": [], "revokedMembers": [], "status": "pending", "_id": "67dc5c77a4e381ca892935d6", "createdAt": "2025-03-20T18:20:39.850Z", "updatedAt": "2025-03-20T18:20:39.850Z", "__v": 0 }
POST /negotiation/contract/negotiate
headers:
{"x-ptx-catalog-key": process.env.CATALOG_AUTHORIZATION_KEY, Content-Type: application/json}
the x-ptx-catalog-key is needed if you have set up the optional variable CATALOG_AUTHORIZATION_KEY in you .env
input:
{ "profileId": "participant-1", "contractData": { "_id": "67c70ff1e8ccfc4faadc683a", "ecosystem": "test-ecosystem", "@context": "http://www.w3.org/ns/odrl/2/", "@type": "Offer", "serviceOfferings": [ { "participant": "test", "serviceOffering": "test-service", "policies": [ { "description": "test-policy", "permission": [ { "action": "use", "target": "test-target", "constraint": [], "duty": [] } ], "prohibition": [] } ] } ], "status": "signed" } }
output :
{ "canAccept": false, "reason": "Contract contains unacceptable policies or services", "unacceptablePolicies": [ "test-policy" ], "unacceptableServices": [ "test-service" ] }
PUT /negotiation/profile/preferences
headers:
{"x-ptx-catalog-key": process.env.CATALOG_AUTHORIZATION_KEY, Content-Type: application/json}
the x-ptx-catalog-key is needed if you have set up the optional variable CATALOG_AUTHORIZATION_KEY in you .env
input:
{ "profileId": "participant-1", "preferences": { "policies": [{ "policy": "test-policy", "frequency": 1 }], "services": ["test-service"], "ecosystems": ["test-ecosystem"] } }
output :
{ "message": "Profile preferences updated successfully." }
For more information see the Tests definition.
This project is licensed under MIT License