npm package: @keethealth/api-client
Description: KeetHealth API Client
Author: Keet Health
Latest version: 0.18.0

![Travis Build](https://travis-ci.com/keethealth/keet-api-client.svg?token=JGSpFizRtbmExQ5WUA66&branch=master)

# Keet Health Node Module Boilerplate

Adatped from [Babel Starter Kit](https://github.com/kriasoft/babel-starter-kit)

Boilerplate for developing Keet Health modules in Node.js, using:

- ESlint
- Babel
- Rollup
- Jest
- TravisCI

## Table of Contents

- [File Structure](#file-structure)
- [Updating for different projects](#updating-for-different-projects)
- [Quick Start](#quick-start)
- [Available Scripts](#available-scripts)
- [Troubleshooting](#troubleshooting)

## File Structure

```
|-- src/            # where the magic happens
|---- index.js      # entry file
|-- dist/           # directory for built items
|-- tools/          # build tools
|-- test/           # module tests
|-- bin/            # executables
|-- .env            # environment variables
|-- .eslintrc.json  # linting rules because messy code hurts my soul
|-- .gitignore      # file patterns to not commit, currently configured only for macOS
|-- .travis.yml     # Travis CI config file
|-- package.json    # node package dependencies
|-- static.json     # necessary for client-side routing
|-- yarn.lock       # auto generated yarn file, do not touch
```

## Updating for different projects

This module is intended to be a pure node.js boilerplate without dependencies on DOM or other frameworks/libraries.
When you need to update this repo to support other libraries in JS (i.e. React), you should create a new branch and make changes there.

Then, clone from that branch:

```
git checkout -b react

## ...Commit changes

git clone -b react --single-branch https://github.com/keethealth/keet-module-boilerplate.git
```

## Quick Start

#### Cloning

```
git clone https://github.com/keethealth/keet-module-boilerplate.git <module-name>

rm -rf .git && git init
git remote add origin <keethealth/module-name.git>
git remote -v
```

#### Initialization

```
cd <module-name>
yarn init
```

Yarn will ask you a series of questions to edit `package.json`.  
All questions are already answered by the existing `package.json`, but you will need to change these:

```
question name (@keethealth/keet-module-boilerplate): <module-name>
question version (0.0.1):
question description (A project template for authoring and publishing Keet Health libraries):
question repository url (keethealth/keet-module-boilerplate): keethealth/<module-name>
```

#### Install Dependencies & Build

`yarn && yarn build`

You should now have a `dist` folder at `path/to/module/dist`

#### Development

To link this package:

```
yarn link
```

Learn more about this command at https://yarnpkg.com/lang/en/docs/cli/link/

Go to the app you want to test this module with and link this local package:

```
cd ../<app-name>
yarn link <module-name>
```

This will create a symlink in your project so that it will resolve `import '<module-name'` using your local project instead of the `node_modules` folder.

When you are done and would like to test the package on npm, run the following in your app directory:

```
yarn unlink <module-name>
```

To completely remove the symlink, run the following in the local package directory:

```
yarn unlink
```

Run watch to rebuild bundle on changes made instead of running build manually each time:

```
yarn watch
```

#### Testing locally

```javascript
npx babel-node

babel > const Client = require('./src/Client').default
babel > const apiUrl = 'https://api.keetdev.com'
babel > const accessToken = /* put your token here */
babel > const Api = new Client({ apiUrl, getCurrentSession: () => Promise.resolve({ accessToken }) })
babel > Api.profile.read().then(response => { console.log('response', JSON.stringify(response, null, 2)) })

```

## Publishing to npm

Build the package:

```
yarn build
```

Publish the package to npm:

```
yarn publish --access public
```

You will be prompted to bump the version. Ensure that you follow [semantic versioning](https://semver.org/) strictly.

This publishes the package as a public scoped package under the `@keethealth` scope.

[Read more about scoped packages](https://docs.npmjs.com/misc/scope)

## Available Scripts

In the project directory, you can run:

### `yarn test`

Launches the test runner in the interactive watch mode.

To see test coverage, run `yarn test --coverage`.

### `yarn build`

Builds the app for production to the `dist` folder.

## Troubleshooting