# Tillhub JavaScript SDK [![CircleCI](https://circleci.com/gh/tillhub/tillhub-sdk-javascript/tree/master.svg?style=svg)](https://circleci.com/gh/tillhub/tillhub-sdk-javascript/tree/master) [![Greenkeeper badge](https://badges.greenkeeper.io/tillhub/tillhub-sdk-javascript.svg)](https://greenkeeper.io/)

## Usage

```bash
# Run npm install and write your library name when asked. That's all!
npm install @tillhub/javascript-sdk
```

## Features

## Importing library

You can import the generated bundle to use the whole library generated by this starter:

```javascript
import * as tillhub from '@tillhub/javascript-sdk'

// configure which API to use. E.g. you can also run staging and sandbox APIs
th.init({
  base: 'https://api.tillhub.com'
})

// use any authentication method that .auth provides
th.auth.loginUsername({ username: 'client_account@client.com', password: 'xxxxxxxxxxx' })

// or when already authenticated and rehydrating state you can immediately also hydrated an
// authenticated th client
th.init({
  base: 'https://api.tillhub.com',
  credentials: {
    token: window.localStorage.getItem('th-token')
  },
  user: window.localStorage.getItem('th-user-uuid')
})
```

Additionally, you can import the transpiled modules from `dist/lib` in case you have a modular library:

```javascript
import Auth from '@tillhub/javascript-sdk/dist/lib/Auth'
```

## Development

- `npm t`: Run test suite
- `npm start`: Run `npm run build` in watch mode
- `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch)
- `npm run test:prod`: Run linting and generate coverage
- `npm run build`: Generate bundles and typings, create docs
- `npm run lint`: Lints code
- `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)

### Troubleshooting Installation Errors on macOS

If you encounter an error while installing the project on macOS, this section is just for you.ß

Error: `Cannot find module 'node-darwin-arm64/package.json'`

No need to worry—this happens when installing an x86_64 application on an ARM64 system. Here are a few solutions:

- **Run with Rosetta**: Duplicate your Terminal app, right-click it, select Get Info, and check “Open using Rosetta”. This allows you to run x86_64 applications.
- **Use x86 architecture for Node**: You can prepend your command with `arch -x86_64 [cmd]` to run it in x86 mode.
- **Consider using Node 16+**: Node.js 16 and later versions run natively on ARM processors, which might resolve the issue without additional steps.

For more information see: https://stackoverflow.com/a/67907214

### Utilities

**TODO:** The SDK will rely on inherited base handlers as utilities.

## LICENSE

Apache-2.0
