1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
🦑 JavaScript client library for Ocean Protocol
Go to file
2020-04-30 00:44:50 +00:00
.github Standardize contrib guidelines across public repos 2018-11-30 15:34:50 +01:00
plugins tweak printWidth 2019-11-22 12:14:17 +01:00
scripts hotfix for typedoc spec generation 2020-01-22 17:44:38 +01:00
src Merge pull request #400 from oceanprotocol/bug/fix_compute_issues 2020-04-14 19:38:50 +03:00
test Merge pull request #400 from oceanprotocol/bug/fix_compute_issues 2020-04-14 19:38:50 +03:00
.editorconfig setup eslint & prettier 2019-06-24 13:06:46 +02:00
.eslintrc consolidate test files 2020-01-30 22:32:50 +01:00
.gitignore ignore editor configs 2020-01-21 13:06:07 +01:00
.npmignore ignore more files in npm package 2019-07-31 13:08:48 +02:00
.nvmrc lint fixes, bump Ocean components 2019-12-09 10:49:53 +01:00
.prettierrc tweak printWidth 2019-11-22 12:14:17 +01:00
.travis.yml bump brizo & events-handler 2020-04-14 18:42:32 +03:00
CHANGELOG.md Release 2.1.1 2020-04-14 19:02:09 +02:00
library.json bump to Brizo v0.9.0 2020-02-03 17:14:55 +01:00
LICENSE Initial commit 2018-08-20 15:42:24 +02:00
MIGRATION.md Disable versions test. 2020-03-06 14:26:26 +01:00
package-lock.json chore(package): update lockfile package-lock.json 2020-04-30 00:44:50 +00:00
package.json fix(package): update uuid to version 8.0.0 2020-04-30 00:44:46 +00:00
README.md consolidate test files 2020-01-30 22:32:50 +01:00
tsconfig.json add allowSyntheticDefaultImports 2019-11-22 12:14:16 +01:00
webpack.common.js format all the things 2019-06-24 13:06:46 +02:00
webpack.config.js format all the things 2019-06-24 13:06:46 +02:00
webpack.development.js format all the things 2019-06-24 13:06:46 +02:00
webpack.parts.js format all the things 2019-06-24 13:06:46 +02:00
webpack.production.js format all the things 2019-06-24 13:06:46 +02:00

banner

Squid-js

🦑 JavaScript client library for Ocean Protocol oceanprotocol.com

npm Travis (.com) GitHub contributors Maintainability Test Coverage js oceanprotocol Greenkeeper badge


🐲🦑 THERE COULD BE DRAGONS AND SQUIDS. If you run into problems, please open up a new issue. 🦑🐲



Get started

Start by adding the package to your dependencies:

npm i @oceanprotocol/squid

The package exposes Ocean and Logger which you can import in your code like this:

// ES6
import { Ocean, Logger } from '@oceanprotocol/squid'

// ES2015
const { Ocean, Logger } = require('@oceanprotocol/squid')

You can then connect to running Keeper, Aquarius, Brizo instances, e.g.:

const ocean: Ocean = await Ocean.getInstance({
    // the node of the blockchain to connect to, could also be infura
    nodeUri: 'http://localhost:8545',
    // the uri of aquarius
    aquariusUri: 'http://localhost:5000',
    // the uri of brizo
    brizoUri: 'http://localhost:8030',
    // address that brizo uses
    brizoAddress: '0x00bd138abd70e2f00903268f3db08f2d25677c9e'
    // the uri to the parity node you want to use for encryption and decryption
    parityUri: 'http://localhost:9545',
    // the uri of the secret store that holds the keys
    secretStoreUri: 'http://localhost:12001'
})

For an overview of endpoint configurations making up various Ocean networks, please refer to .env.local.example from commons.

Optionally, you can initialize an Aquarius connection without relying on the rest of Ocean to be loaded. This is useful for outputting asset metadata stored in Aquarius without the need to configure Web3 and all other Ocean Protocol network connections.

import { Ocean, Aquarius, Logger } from 'squid'

const aquarius = new Aquarius('http://localhost:5000', Logger)
const asset = aquarius.retrieveDDO('did:op:e6fda48e8d814d5d9655645aac3c046cc87528dbc1a9449799e579d7b83d1360')

const ocean = await Ocean.getInstance({ ... })
// Aquarius will still be available under ocean.aquarius, just later
const asset = ocean.aquarius.retrieveDDO('did:op:e6fda48e8d814d5d9655645aac3c046cc87528dbc1a9449799e579d7b83d1360')

Examples

You can see how squid-js is used on:

Documentation

Docs: squid-js API Reference →

Alternatively, you can generate the raw TypeDoc documentation locally by running:

# will output to ./doc folder
npm run doc

Migration Guide

Instructions on how to migrate between breaking versions:

Development

To start development you need to:

npm i
npm start

Testing

Unit Tests

For unit tests, running ganache-cli is required before starting the tests. It's best to start it on a different port so it doesn't clash with anything running in Barge:

npm i -g ganache-cli
ganache-cli --port 18545
export ETH_PORT=18545

To start unit tests, run:

npm test

or to watch for changes:

npm run test:watch

to create code coverage information:

npm run test:cover

Integration Tests

A locally running Ocean network is required. To do so before running the tests, use Barge:

git clone https://github.com/oceanprotocol/barge
cd barge

./start_ocean.sh --no-commons

In another terminal window, run this script and export the seed phrase:

# copies the contract artifacts once the local Ocean network is up and running
./scripts/keeper.sh

# export Spree accounts seed phrase
export SEED_WORDS="taxi music thumb unique chat sand crew more leg another off lamp"

Once everything is up, run the integration tests:

# integration tests work with the spree network and the SEED_WORDS in previous step are required.
# Make sure to reset `ETH_PORT` to 8545 (or whatever port is used in `spree1)
npm run test:integration

to generate code coverage information during test, run:

npm run test:integration:cover

Code Style

Project follows eslint-config-oceanprotocol. For linting and auto-formatting you can use:

# lint all ts with eslint
npm run lint

# auto format all ts with prettier, taking all configs into account
npm run format

Production build

To create a production build:

npm run build

Releases

From a clean master branch you can run any release task doing the following:

  • bumps the project version in package.json, package-lock.json
  • auto-generates and updates the CHANGELOG.md file from commit messages
  • creates a Git tag
  • commits and pushes everything
  • creates a GitHub release with commit messages as description
  • Git tag push will trigger Travis to do a npm release

You can execute the script using arguments to bump the version accordingly:

  • To bump a patch version: npm run release
  • To bump a minor version: npm run release minor
  • To bump a major version: npm run release major

For the GitHub releases steps a GitHub personal access token, exported as GITHUB_TOKEN is required. Setup

License

Copyright 2019 Ocean Protocol Foundation Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.