<commit_before>[back to hoodie-server-account](../README.md)

# hoodie-server-account/api

`hoodie-server-account/api` is a JavaScript API for all things account
on top of CouchDB’s REST API.

After registering the `hoodie-server-acctoun` hapi plugin, the account API
becomes available at `server.plugins.account.api`. It can also be directly
required using

```js
var api = require ('hoodie-server-account/api')({
  url: couchdbUrl
})
```

## Example

```js
var AccountApi = require('hoodie-server-account/api')
var PouchDB = require('pouchdb')

PouchDB.plugin(require('pouchdb-users'))
PouchDB.plugin(require('pouchdb-admins'))

var db = new PouchDB('http://localhost:5984/_users')

var api = new AccountApi({
  db: db,
  secret: 'secret123'
})

api.accounts.findAll().then(logAccountStats)
api.accounts.on('change', logAccountChange)
```

## API

`hoodie-server-account/api` is a subset of [hoodie-client-account/admin](https://github.com/hoodiehq/hoodie-client-account/tree/master/admin).
If you see any inconsistencies, please [create an issue](https://github.com/hoodiehq/hoodie-server-account/issues/new?title=API+inconsistency)

- [Constructor](#constructor)
- [api.sessions.add()](#apisessionsadd)
- [api.sessions.find()](#apisessionsfind)
- [api.sessions.findAll()](#apisessionsfindall)
- [api.sessions.remove()](#apisessionsremove)
- [api.sessions.removeAll()](#apisessionsremoveall)
- [api.accounts.add()](#apiaccountsadd)
- [api.accounts.find()](#apiaccountsfind)
- [api.accounts.findAll()](#apiaccountsfindall)
- [api.accounts.update()](#apiaccountsupdate)
- [api.accounts.updateAll()](#apiaccountsupdateall)
- [api.accounts.remove()](#apiaccountsremove)
- [api.accounts.removeAll()](#apiaccountsremoveall)
- [api.requests.add()](#apirequestsadd)
- [api.requests.find()](#apirequestsfind)
- [api.requests.findAll()](#apirequestsfindall)
- [api.requests.remove()](#apirequestsremove)
- [api.requests.removeAll()](#apirequestsremoveall)
- [api.account()](#apiaccount)
- [api.account().profile.find()](#apiaccountprofilefind)
- [api.account().profile.update()](#apiaccountprofileupdate)
- [api.account().tokens.add()](#apiaccounttokensadd)
- [api.account().tokens.find()](#apiaccounttokensfind)
- [api.account().tokens.findAll()](#apiaccounttokensfindall)
- [api.account().tokens.remove()](#apiaccounttokensremove)
- [api.account().roles.add()](#apiaccountrolesadd)
- [api.account().roles.findAll()](#apiaccountrolesfindall)
- [api.account().roles.remove()](#apiaccountrolesremove)
- [Events](#events)

### Constructor

---

🐕 **TO BE DONE**: _create issue and link it here_

---

```js
new AccountApi(options)
```

<table>
  <thead>
    <tr>
      <th>Argument</th>
      <th>Type</th>
      <th>Description</th>
      <th>Required</th>
    </tr>
  </thead>
  <tr>
    <th align="left"><code>options.db</code></th>
    <td>Object</td>
    <td>
      PouchDB instance with
      <a href="https://github.com/hoodiehq/pouchdb-users">pouchdb-users</a>
      plugin
    </td>
    <td>Yes</td>
  </tr>
  <tr>
    <th align="left"><code>options.secret</code></th>
    <td>String</td>
    <td>
      Server secret, like CouchDB’s <code>couch_httpd_auth.secret</code>
    </td>
    <td>Yes</td>
  </tr>
  <tr>
    <th align="left"><code>options.admins</code></th>
    <td>Object</td>
    <td>
      Map of admin accounts, same format as CouchDB’s <code>admins</code>
      configuration
    </td>
    <td>No</td>
  </tr>
</table>

Returns an `api` instance.

Examples

```js
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-users'))
var db = new PouchDB('http://localhost:5984/_users')
db.useAsAuthenticationDB().then(function () {
  var api = new AccountApi({<commit_msg>docs(api): remove obsolete `options.admins` from Constructor<commit_after>[back to hoodie-server-account](../README.md)

# hoodie-server-account/api

`hoodie-server-account/api` is a JavaScript API for all things account
on top of CouchDB’s REST API.

After registering the `hoodie-server-acctoun` hapi plugin, the account API
becomes available at `server.plugins.account.api`. It can also be directly
required using

```js
var api = require ('hoodie-server-account/api')({
  url: couchdbUrl
})
```

## Example

```js
var AccountApi = require('hoodie-server-account/api')
var PouchDB = require('pouchdb')

PouchDB.plugin(require('pouchdb-users'))
PouchDB.plugin(require('pouchdb-admins'))

var db = new PouchDB('http://localhost:5984/_users')

var api = new AccountApi({
  db: db,
  secret: 'secret123'
})

api.accounts.findAll().then(logAccountStats)
api.accounts.on('change', logAccountChange)
```

## API

`hoodie-server-account/api` is a subset of [hoodie-client-account/admin](https://github.com/hoodiehq/hoodie-client-account/tree/master/admin).
If you see any inconsistencies, please [create an issue](https://github.com/hoodiehq/hoodie-server-account/issues/new?title=API+inconsistency)

- [Constructor](#constructor)
- [api.sessions.add()](#apisessionsadd)
- [api.sessions.find()](#apisessionsfind)
- [api.sessions.findAll()](#apisessionsfindall)
- [api.sessions.remove()](#apisessionsremove)
- [api.sessions.removeAll()](#apisessionsremoveall)
- [api.accounts.add()](#apiaccountsadd)
- [api.accounts.find()](#apiaccountsfind)
- [api.accounts.findAll()](#apiaccountsfindall)
- [api.accounts.update()](#apiaccountsupdate)
- [api.accounts.updateAll()](#apiaccountsupdateall)
- [api.accounts.remove()](#apiaccountsremove)
- [api.accounts.removeAll()](#apiaccountsremoveall)
- [api.requests.add()](#apirequestsadd)
- [api.requests.find()](#apirequestsfind)
- [api.requests.findAll()](#apirequestsfindall)
- [api.requests.remove()](#apirequestsremove)
- [api.requests.removeAll()](#apirequestsremoveall)
- [api.account()](#apiaccount)
- [api.account().profile.find()](#apiaccountprofilefind)
- [api.account().profile.update()](#apiaccountprofileupdate)
- [api.account().tokens.add()](#apiaccounttokensadd)
- [api.account().tokens.find()](#apiaccounttokensfind)
- [api.account().tokens.findAll()](#apiaccounttokensfindall)
- [api.account().tokens.remove()](#apiaccounttokensremove)
- [api.account().roles.add()](#apiaccountrolesadd)
- [api.account().roles.findAll()](#apiaccountrolesfindall)
- [api.account().roles.remove()](#apiaccountrolesremove)
- [Events](#events)

### Constructor

---

🐕 **TO BE DONE**: _create issue and link it here_

---

```js
new AccountApi(options)
```

<table>
  <thead>
    <tr>
      <th>Argument</th>
      <th>Type</th>
      <th>Description</th>
      <th>Required</th>
    </tr>
  </thead>
  <tr>
    <th align="left"><code>options.db</code></th>
    <td>Object</td>
    <td>
      PouchDB instance with
      <a href="https://github.com/hoodiehq/pouchdb-users">pouchdb-users</a>
      plugin
    </td>
    <td>Yes</td>
  </tr>
  <tr>
    <th align="left"><code>options.secret</code></th>
    <td>String</td>
    <td>
      Server secret, like CouchDB’s <code>couch_httpd_auth.secret</code>
    </td>
    <td>Yes</td>
  </tr>
</table>

Returns an `api` instance.

Examples

```js
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-users'))
var db = new PouchDB('http://localhost:5984/_users')
db.useAsAuthenticationDB().then(function () {
  var api = new AccountApi({
{'fraction_non_alphanumeric': 0.19151296630148384, 'fraction_numerical': 0.0030508944667868533, 'mean_word_length': 4.945589447650454, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 101, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1818496', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2543, 'n_words': 394}