Skip to content

Latest commit

 

History

History
 
 

api

Cloudmos API

How to run

  1. Make sure you have a valid Akash database first.
  2. Make sure you have a valid User database. If the user database is empty, the necessary tables will be created automatically.
  3. Create a .env file with the necessary environment variables.
  4. Run npm install to install dependencies.
  5. Start the app with npm start.

You can make sure the api is working by accessing the status endpoint: http://localhost:3080/status

Environment Variables

When running the api locally the following environment variables can be set in a .env file.

Name Value Note
Network mainnet or testnet Specify if the api should be in mainnet or testnet mode. Default: mainnet.
RestApiNodeUrl ex: "https://api.akashnet.net" Rest api to use. Will default to "https://rest.cosmos.directory/akash" for mainnet and "https://api.testnet-02.aksh.pw:443" for testnet.
ServerOrigin ex: http://localhost:3080 Origin of the api server. Will be used to populate the swagger server list.
HealthchecksEnabled true or false Specify if the Scheduler should send health check pings.
SentryDSN ex: "https://[email protected]/1234" Sentry DSN used when initializing Sentry
AkashDatabaseCS ex: postgres://user:password@localhost:5432/cloudmos-akash Akash Database Connection String
AkashTestnetDatabaseCS ex: postgres://user:password@localhost:5432/cloudmos-akash-testnet Akash Testnet Database Connection String
UserDatabaseCS ex: postgres://user:password@localhost:5432/cloudmos-users User Database Connection String
Auth0JWKSUri ex: 'https://1a2b3c.us.auth0.com/.well-known/jwks.json'
Auth0Audience ex: 'https://api.cloudmos.io'
Auth0Issuer ex: 'https://dev-5aprb0lr.us.auth0.com/'
Auth0Issuer ex: 'https://auth.cloudmos.io/'
StripeSecretKey ex: sk_test_12aw315wdawd3...293d12d32df8jf
WebsiteUrl http://localhost:3001

Testing

Project is configured to use Jest for testing. It is intended to be covered with unit and functional tests where applicable.

Running tests

To execute both unit and functional tests, run:

npm test

To run unit tests exclusively, use:

npm run test:unit

To run only functional tests, use:

npm run test:functional

Watch Mode

To automatically re-run tests upon any changes, use the following watch mode commands:

npm test:watch
npm run test:unit:watch
npm run test:functional:watch

Collecting Coverage

To collect and view test coverage, use the following commands:

npm test:coverage
npm run test:unit:coverage
npm run test:functional:coverage

Contributing to Tests

Unit Tests: Focus on testing individual functions and components in isolation, without external dependencies.

Test File Structure: For consistency, each component tested with unit tests should reside in its own directory, named after the component. Place the test file alongside the component, suffixed with .spec. For example:

Functional Tests: Aim to evaluate the system's behavior as a whole, including endpoints, workers, and workflows. Place functional tests in the test/functional directory.

src/
  components/
    myComponent/
      myComponent.ts
      myComponent.spec.ts

Changes from beta to v1 (February 2024)

Api Versioning

The public api version will now be included in the url like so: api.cloudmos.io/v1/<endpoint>

Changes that are backward compatible like adding new endpoint will be done in the existing version. Changes that are not backward compatible, such as removing an endpoint, will be done in a new version. When releasing a new version, a list of breaking changes will be made available. We will keep the old version available for a while to give users enough time to migrate their applications to the latest version.

Swagger Documentation

A swagger documentation is now available at https://api.cloudmos.io/v1/swagger. You can use it to see the list of available endpoints and try them directly in your browser.

Route Changes

The /api prefix was removed from every public endpoints and instead the version should be used (ex: /v1/<endpoint>)

Here is a list of endpoints that have changed in this release. Old endpoints will temporarily redirect to the new ones. In future releases, the versioning system will be used instead of redirects.

Old New
/dashboardData /dashboard-data
/getNetworkCapacity /network-capacity
/getMainnetNodes /nodes/mainnet
/getSandboxNodes /nodes/sandbox
/getTestnetNodes /nodes/testnet
/getProviderAttributesSchema /provider-attributes-schema
/getMainnetVersion /version/mainnet
/getSandboxVersion /version/sandbox
/getTestnetVersion /version/testnet
/getProviderGraphData/<dataName> /provider-graph-data/<dataName>
/getProviderActiveLeasesGraphData/<address> /provider-active-leases-graph-data/<address>
/getGraphData/<dataName> /graph-data/<dataName>
/marketData /market-data
/predicted-block-date/<height>/<blockWindow> /predicted-block-date/<height>?blockWindow=<blockWindow>
/predicted-date-height/<timestamp>/<blockWindow> /predicted-date-height/<timestamp>?blockWindow=<blockWindow>
/providers/<provider>/deployments/<skip>/<take>/<status> /providers/<provider>/deployments/<skip>/<take>?status=<status>