# hex-sdk dev document

## Setup

Firstly install the dependencies by:

```js
$ npm install
```

To build the app:

```js
$ npm run build
```

To build the app and watch for changes:

```js
$ npm run watch
```

To run tests:

```js
$ npm test
```

## Non-prod Environments

If you are a Terminal dev, you can run this against non-prod environments as well by passing in the environment type:

```ts
export enum EnvironmentTypes {
  dev = 'dev',
  staging = 'staging',
  live = 'live'
}
```

### TerminalHttpProvider

```js
new TerminalHttpProvider({
  host: 'https://yourethnodeurl.io',
  apiKey: 'yourApiKey',
  // projectId is not required to log but we suggest
  // using it for the best experience
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
  environment: EnvironmentTypes.dev
});
```

### TerminalWebsocketProvider

```js
new TerminalWebsocketProvider({
  host: 'wss://yourethnodeurl.io',
  apiKey: 'yourApiKey',
  // projectId is not required to log but we suggest
  // using it for the best experience
  projectId: 'YOUR_TERMINAL_PROJECT_ID',
  // source can be a dynamic string as well
  source: SourceType.Terminal,
  environment: EnvironmentTypes.dev
});
```

### MetaMask

```ts
export interface IMetaMaskOptions {
  apiKey: string;
  projectId?: string | undefined;
  environmentType?: EnvironmentTypes | undefined;
}
```

```js
window.terminal.sdk.metamask.startLogging({
  apiKey: 'YOUR_API_KEY',
  projectId: 'YOUR_PROJECT_ID',
  environmentType: 'dev'
});
```

### TerminalApolloLink

```js
// JS/Typescript
import {
  ApolloClient,
  ApolloLink,
  HttpLink,
} from 'apollo-boost';

// Node
const { ApolloClient, ApolloLink, HttpLink } = require('apollo-boost');

const client = new ApolloClient({
  link: ApolloLink.from([
    new TerminalApolloLink({
      uri: 'yourgraphqlurl.io/graphql'
      apiKey: 'yourApiKey',
      projectId: 'YOUR_TERMINAL_PROJECT_ID',
      // source can be a dynamic string as well
      source: SourceType.Terminal,
      environment: EnvironmentTypes.dev
    });,
    // compose with other links...
    new HttpLink({ uri: 'yourgraphqlurl.io/graphql' })
  ]),
});
```


## Publish

If you want to publish the app to `npm` firstly make sure you have tests for all your changes, secondly make sure you `npm pack` it locally with the new version updated in the `package.json`, then upload this `tgz` file into `test-apps` deleting the old one. Now install it on the `node` `package.json` and make sure it works as expected. You should also do this with a basic web app if you changed any of the `MetaMask` provider logic. Also make sure you update the public `README.md` with any docs which support this feature you have added and finally the `CHANGELOG.md`.

### MetaMask

`MetaMask` inject `web3` into the browser and our quite persistent in this. This means for our provider to be able to work with the injected `web3` instance we had to do a custom approach. On every `sdk` publich we should be running `npm run gulp` and dropping the new latest script into https://console.cloud.google.com/storage/browser/terminal-sdk/metamask/latest/?organizationId=1025847849015&project=terminal-services and also create a new folder with the latest version and drop the versioned script in the folder you have created here https://console.cloud.google.com/storage/browser/terminal-sdk/metamask/?organizationId=1025847849015&project=terminal-services. When you upload these files to GC make sure you add the `allUsers` permission to the `js` file.

The `gulp` will drop all the files you need in `metamask-scripts` folder.

### Final steps

Once you done all of that and you're happy that it is working exactly how it should just run

```js
$ npm run publish-sdk
```
