diff --git a/api/README.md b/api/README.md
deleted file mode 100644
index 634af1d..0000000
--- a/api/README.md
+++ /dev/null
@@ -1,606 +0,0 @@
-[back to hoodie-store-server](../README.md)
-
-# hoodie-store-server/api
-
-> Store API to manage databases and data.
-
-After registering the `@hoodie/store-server` hapi plugin, the `Store` API becomes available at `server.plugins.store.api`, so for example to create a new database with a plugin, use `server.plugins.store.api.create('mydb')` It can also be required directly.
-
-## Example
-
-```js
-var PouchDB = require('pouchdb')
-var Store = require('@hoodie/store-server/api')(PouchDB)
-
-Store.open('mydb')
-
-.then(function (store) {
- store.findAll().then(function (docs) {})
-})
-```
-
-## API
-
-- [Factory](#factory)
-- [Store.open](#storeopen)
-- [Store.create()](#storecreate)
-- [Store.exists()](#storeexists)
-- [Store.destroy()](#storedestroy)
-- [Store.grant()](#storegrant)
-- [Store.revoke()](#storerevoke)
-- [Store.hasAccess()](#storehasaccess)
-- [Store.replicate()](#storereplicate)
-- [Store.cancelReplication()](#storecancelreplication)
-- [Instance](#instance)
-- [Events](#events)
-
-### Factory
-
-```js
-var StoreFactory = require('@hoodie/store-server/api')
-var PouchDB = require('pouchdb')
-var Store = StoreFactory(PouchDB)
-```
-
-
-
-
-
Argument
-
Type
-
Description
-
Required
-
-
-
-
PouchDB
-
PouchDB Constructor
-
- PouchDB constructor as returned by require('pouchdb').
- Note that you can set defaults to a PouchDB constructor using PouchDB.defaults(options)
-
-
-Example
-
-```js
-Store.destroy('mydb')
- .then(function (dbName) {
- console.log('Store "mydb" has been destroyed')
- })
- .catch(function (error) {
- if (error.status === 404) {
- console.log('Store "mydb" does not exist')
- } else {
- console.log('Something unexpected happened:', error)
- }
- })
-```
-
-### Store.grant()
-
-```js
-Store.grant(dbName, options)
-```
-
-Every store is private by default. Read and write access must be granted
-explicitly. A store can be set to public read / write, or read / write
-access can be granted to specific roles only.
-
-Behaviors in detail:
-
-- Once access was granted to a role it can no longer be public read / write.
-- Once access was granted to `'public'`, all other roles will be removed
-- Granting access to an existing role has no effect
-
-
-
-
-
Argument
-
Type
-
Description
-
Required
-
-
-
-
name
-
String
-
- Name of database.
-
-
Yes
-
-
-
options.access
-
String, Array
-
- Can be 'read', 'write' or ['read', 'write'].
-
-
Yes
-
-
-
options.role
-
String, Array
-
- Give access to one or multiple roles.
-
-
No
-
-
-
-Resolves without arguments. Rejects with
-
-
-
-
Missing Error
-
404
-
Store does not exist
-
-
-
-Example
-
-```js
-Store.grant('foo', {
- access: 'read'
-})
- .then(function () {
- console.log('"foo" can now be read by everyone');
- })
- .catch(function (error) {
- console.log('Something unexpected happened:', error)
- })
-```
-
-
-### Store.revoke()
-
-```js
-Store.revoke(dbName, options)
-```
-
-Revoke read / write access entirely or from one / multiple roles.
-
-
-
-
-
Argument
-
Type
-
Description
-
Required
-
-
-
-
name
-
String
-
- Name of database.
-
-
Yes
-
-
-
options.access
-
String, Array
-
- Can be 'read', 'write' or ['read', 'write'].
-
-
Yes
-
-
-
options.role
-
String, Array
-
- Revoke access from one or multiple roles.
-
-
No
-
-
-
-Resolves without arguments. Rejects with
-
-
-
-
Missing Error
-
404
-
Store does not exist
-
-
-
-Example
-
-```js
-Store.revoke('foo', {
- access: 'read'
-})
- .then(function () {
- console.log('"foo" can no longer be read by anyone');
- })
- .catch(function (error) {
- console.log('Something unexpected happened:', error)
- })
-```
-
-### Store.hasAccess()
-
-```js
-Store.hasAccess(dbName, options)
-```
-
-Checks if the given role has access to given database.
-
-
-
-
-
Argument
-
Type
-
Description
-
Required
-
-
-
-
name
-
String
-
- Name of database.
-
-
Yes
-
-
-
options.access
-
String, Array
-
- Can be 'read', 'write' or ['read', 'write'].
- If array passed, checks for access for both.
-
-
Yes
-
-
-
options.role
-
String, Array
-
- If Array passed, checks if any of the roles has access
-
-
No
-
-
-
-Resolves with `true` / `false` depending on whether database exists or not.
-
-Example
-
-```js
-Store.hasAccess('foo', {
- access: 'read'
-})
- .then(function (hasAccess) {
- if (hasAccess) {
- console.log('"foo" can be read by everyone');
- } else {
- console.log('"foo" cannot be read by everyone');
- }
- })
- .catch(function (error) {
- console.log('Something unexpected happened:', error)
- })
-```
-
-### Store.replicate
-
-**Important:** Make sure you have the [pouchdb-replication](http://npm.im/pouchdb-replication) package installed
-
-```js
-Store.replicate(source, target, options)
-```
-
-Options are the same as [PouchDB.replication](https://pouchdb.com/api.html#replication). The only difference is that replications with `{live: true}` will be persisted and resumed. Because of that, Store.replicate does not return a replication instance, but a Promise which resolves with a replication instance.
-
-### Store.cancelReplication
-
-```js
-Store.cancelReplication(source, target)
-```
-
-Cancels a live replication removes it from the store so it will no longer be resumed. Returns a promise.
-
-### Instance
-
-A Store instance has the [Hoodie Store API](https://github.com/hoodiehq/pouchdb-hoodie-api#api) (as returned by `db.hoodieApi()`).
-To get a Store instance call [`Store.open`](#storeopen)
-
-```js
-// all methods return promises
-store.add(object)
-store.add([object1, id2])
-store.find(id)
-store.find(object) // with id property
-store.findOrAdd(id, object)
-store.findOrAdd(object)
-store.findOrAdd([object1, id2])
-store.findAll()
-store.findAll(filterFunction)
-store.update(id, changedProperties)
-store.update(id, updateFunction)
-store.update(object)
-store.update([object1, id2])
-store.updateOrAdd(id, object)
-store.updateOrAdd(object)
-store.updateOrAdd([object1, id2])
-store.updateAll(changedProperties)
-store.updateAll(updateFunction)
-store.remove(id)
-store.remove(object)
-store.remove([object1, id2])
-store.removeAll()
-store.removeAll(filterFunction)
-store.clear()
-
-// events
-store.on('add', function(object, options) {})
-store.on('update', function(object, options) {})
-store.on('remove', function(object, options) {})
-store.on('change', function(eventName, object, options) {})
-store.on('clear', function() {})
-store.one(eventName, eventHandlerFunction)
-store.off(eventName, eventHandlerFunction)
-
-// original PouchDB (http://pouchdb.com/api.html) instance used for the store
-store.db
-```
-
-### Events
-
-
-
-
-
- Event
-
-
- Description
-
-
- Arguments
-
-
-
-
-
create
-
New store created successfully
-
name
-
-
-
destroy
-
Existing store destroyed
-
name
-
-
-
-## How things work
-
-[PouchDB](https://pouchdb.com) only implements APIs on a database level without
-any kind of access control. In order to keep track of all databases, access
-settings and replications, we create a meta database `hoodie-store`. Every
-database that gets created using `Store.create()` will also create a document
-in `hoodie-store` with `_id` being `db_`. All continuous replications
-are stored with as`replication__`.
-
-The database documents have an `access` property which we use for access control
-on database level.
-
-The replication documents are stored with `source`, `target` and `options`
-properties. On server start continuous replications are started for all
-replication documents.
-
-### Note on CouchDB
-
-CouchDB comes with its own REST API, so if it’s accessible at a public URL people
-can directly access it. For that reason we set `/_security` on each database
-created by Hoodie so that it’s only readable by CouchDB admins.
diff --git a/api/index.js b/api/index.js
deleted file mode 100644
index ea2b576..0000000
--- a/api/index.js
+++ /dev/null
@@ -1,98 +0,0 @@
-module.exports = StoreAPIFactory
-
-var hoodieApi = require('pouchdb-hoodie-api')
-var request = require('request').defaults({json: true})
-
-var create = require('./store/create')
-var destroy = require('./store/destroy')
-var exists = require('./store/exists')
-var open = require('./store/open')
-
-var grantAccess = require('./store/grant')
-var hasAccess = require('./store/has-access')
-var revokeAccess = require('./store/revoke')
-
-var replicate = require('./store/replicate')
-var cancelReplication = require('./store/cancel-replication')
-
-var replicationIdPrefix = require('./utils/to-replication-id').prefix
-var toCouchDbUrl = require('./utils/pouchdb-options-to-couchdb-url')
-
-function StoreAPIFactory (PouchDB) {
- if (typeof PouchDB !== 'function') {
- throw new Error('Store API Factory requires PouchDB as first argument')
- }
-
- // https://github.com/hoodiehq/pouchdb-hoodie-api
- PouchDB.plugin(hoodieApi)
-
- var metaDb = new PouchDB('hoodie-store')
- var replicationsMap = {}
- var adapter = new PouchDB('hack', {skip_setup: true}).adapter
- var usesHttpAdapter = adapter === 'http' || adapter === 'https'
- var couchDbUrl = toCouchDbUrl(metaDb.__opts)
-
- var replicationsReady = metaDb.allDocs({
- include_docs: true,
- startkey: replicationIdPrefix,
- endkey: replicationIdPrefix + '\uffff'
- }).then(function (result) {
- return result.rows.forEach(function (row) {
- if (replicationsMap[row.id]) {
- return
- }
-
- replicationsMap[row.id] = PouchDB.replicate(row.doc.source, row.doc.target, row.doc.options)
- })
- })
-
- if (usesHttpAdapter) {
- replicationsReady = replicationsReady.then(function () {
- return new Promise(function (resolve, reject) {
- request({
- method: 'put',
- url: couchDbUrl + 'hoodie-store/_security',
- body: {
- members: {
- roles: ['_hoodie_admin_only']
- }
- }
- }, function (error, response, data) {
- if (error) {
- return reject(error)
- }
-
- if (response.statusCode >= 400) {
- return reject(new Error(data.reason))
- }
-
- resolve()
- })
- })
- })
- }
-
- var state = {
- PouchDB: PouchDB,
- metaDb: metaDb,
- couchDbUrl: couchDbUrl,
- usesHttpAdapter: usesHttpAdapter,
- replicationsReady: replicationsReady,
- replicationsMap: replicationsMap
- }
- var Store = {}
-
- // set adapter to http for both http & https
- Store.adapter = usesHttpAdapter ? 'http' : adapter
- Store.create = create.bind(null, state)
- Store.destroy = destroy.bind(null, state)
- Store.exists = exists.bind(null, state)
- Store.open = open.bind(null, state)
- Store.grant = grantAccess.bind(null, state)
- Store.hasAccess = hasAccess.bind(null, state)
- Store.revoke = revokeAccess.bind(null, state)
- Store.replicate = replicate.bind(null, state)
- Store.cancelReplication = cancelReplication.bind(null, state)
-
- return Store
-}
diff --git a/api/store/cancel-replication.js b/api/store/cancel-replication.js
deleted file mode 100644
index 784e4f1..0000000
--- a/api/store/cancel-replication.js
+++ /dev/null
@@ -1,29 +0,0 @@
-module.exports = cancelReplication
-
-var toReplicationId = require('../utils/to-replication-id')
-
-function cancelReplication (state, source, target, options) {
- var id = toReplicationId(source, target, options)
-
- state.replicationsReady
-
- .then(function () {
- var replication = state.replicationsMap[id]
-
- if (!replication) {
- return
- }
-
- state.metaDb.get(id)
-
- .then(function (doc) {
- doc._deleted = true
- return state.metaDb.put(doc)
- })
-
- .then(function () {
- delete state.replicationsMap[id]
- replication.cancel()
- })
- })
-}
diff --git a/api/store/create.js b/api/store/create.js
deleted file mode 100644
index e246d7b..0000000
--- a/api/store/create.js
+++ /dev/null
@@ -1,84 +0,0 @@
-module.exports = createStore
-
-var pathResolve = require('path').resolve
-
-var _ = require('lodash')
-var mkdirp = require('mkdirp')
-
-var addRolePrivilege = require('../utils/add-role-privilege')
-var errors = require('../utils/errors')
-var getRoleOption = require('../utils/get-role-option')
-var setSecurity = require('../utils/couchdb-set-security')
-var storeExists = require('./exists')
-var toDbId = require('../utils/to-db-id')
-
-function createStore (state, name, options) {
- return storeExists(state, name)
-
- .then(function (doesExist) {
- if (doesExist) {
- throw errors.CONFLICT
- }
-
- var doc = {
- _id: toDbId(name),
- access: {
- read: {
- role: []
- },
- write: {
- role: []
- }
- }
- }
-
- if (options) {
- _.concat(options.access).forEach(function (privilege) {
- addRolePrivilege(doc.access, getRoleOption(options), privilege)
- })
- }
-
- return state.metaDb.put(doc)
-
- .then(function () {
- if (!state.usesHttpAdapter) {
- var db = new state.PouchDB(name)
- return db.info()
-
- // TODO: remove once https://github.com/pouchdb/pouchdb/issues/5668 is resolved
- // also remove mkdirp from package.json unless it’s used somewhere else
- .catch(function (error) {
- if (error.name === 'OpenError') {
- var path = db.__opts.prefix ? db.__opts.prefix + name : name
- return new Promise(function (resolve, reject) {
- mkdirp(pathResolve(path), function (error) {
- if (error) {
- return reject(error)
- }
-
- resolve()
- })
- })
-
- .then(function () {
- return new state.PouchDB(name).info()
- })
- }
- throw error
- })
- }
-
- return new state.PouchDB(name).info().then(function () {
- var options = {
- couchDbUrl: state.couchDbUrl,
- dbName: name
- }
- return setSecurity(options)
- })
- })
- })
-
- .then(function () {
- return name
- })
-}
diff --git a/api/store/destroy.js b/api/store/destroy.js
deleted file mode 100644
index 3e56ee3..0000000
--- a/api/store/destroy.js
+++ /dev/null
@@ -1,24 +0,0 @@
-module.exports = destroyStore
-
-var getDocOrFalse = require('../utils/get-doc-or-false')
-
-function destroyStore (state, name) {
- return getDocOrFalse(state.metaDb, name)
-
- .then(function (doc) {
- if (doc === false) {
- throw new Error(`Database "${name}" does not exist`)
- }
-
- doc._deleted = true
- return state.metaDb.put(doc)
- })
-
- .then(function () {
- return new state.PouchDB(name).destroy()
- })
-
- .then(function () {
- return name
- })
-}
diff --git a/api/store/exists.js b/api/store/exists.js
deleted file mode 100644
index 4f17138..0000000
--- a/api/store/exists.js
+++ /dev/null
@@ -1,11 +0,0 @@
-module.exports = storeExists
-
-var getDocOrFalse = require('../utils/get-doc-or-false')
-
-function storeExists (state, name) {
- return getDocOrFalse(state.metaDb, name)
-
- .then(function (result) {
- return !!result
- })
-}
diff --git a/api/store/grant.js b/api/store/grant.js
deleted file mode 100644
index 449eda8..0000000
--- a/api/store/grant.js
+++ /dev/null
@@ -1,19 +0,0 @@
-module.exports = grantAccess
-
-var _ = require('lodash')
-
-var addRolePrivilege = require('../utils/add-role-privilege')
-var getRoleOption = require('../utils/get-role-option')
-var toDbId = require('../utils/to-db-id')
-
-function grantAccess (state, name, options) {
- return state.metaDb.get(toDbId(name))
-
- .then(function (doc) {
- _.concat(options.access).forEach(function (privilege) {
- addRolePrivilege(doc.access, getRoleOption(options), privilege)
- })
-
- return state.metaDb.put(doc)
- })
-}
diff --git a/api/store/has-access.js b/api/store/has-access.js
deleted file mode 100644
index 342e71b..0000000
--- a/api/store/has-access.js
+++ /dev/null
@@ -1,18 +0,0 @@
-module.exports = hasAccess
-
-var _ = require('lodash')
-
-var getRoleOption = require('../utils/get-role-option')
-var hasRolePrivilege = require('../utils/has-role-privilege')
-var toDbId = require('../utils/to-db-id')
-
-function hasAccess (state, name, options) {
- return state.metaDb.get(toDbId(name))
-
- .then(function (doc) {
- var privileges = _.concat(options.access)
- return privileges.filter(function (privilege) {
- return hasRolePrivilege(doc.access, getRoleOption(options), privilege)
- }).length === privileges.length
- })
-}
diff --git a/api/store/open.js b/api/store/open.js
deleted file mode 100644
index f5c78f9..0000000
--- a/api/store/open.js
+++ /dev/null
@@ -1,16 +0,0 @@
-module.exports = openStore
-
-var errors = require('../utils/errors')
-var storeExists = require('./exists')
-
-function openStore (state, name) {
- return storeExists(state, name)
-
- .then(function (exists) {
- if (!exists) {
- throw errors.MISSING
- }
-
- return new state.PouchDB(name).hoodieApi()
- })
-}
diff --git a/api/store/replicate.js b/api/store/replicate.js
deleted file mode 100644
index 470b3fc..0000000
--- a/api/store/replicate.js
+++ /dev/null
@@ -1,50 +0,0 @@
-module.exports = replicate
-
-var toReplicationId = require('../utils/to-replication-id')
-var errors = require('../utils/errors')
-
-function replicate (state, source, target, options) {
- if (!options) {
- options = {}
- }
-
- // load PouchDB replication plugin as needed
- if (!state.PouchDB.replicate) {
- try {
- state.PouchDB.plugin(require('pouchdb-replication'))
- } catch (error) {
- if (error.message === 'Cannot find module \'pouchdb-replication\'') {
- return Promise.reject(errors.REPLICATION_PACKAGE_MISSING)
- }
-
- throw error
- }
- }
-
- if (!options.live) {
- var replication = state.PouchDB.replicate(source, target, options)
-
- return Promise.resolve({
- replication: replication
- })
- }
-
- var id = toReplicationId(source, target, options)
-
- return state.metaDb.put({
- _id: id,
- source: source,
- target: target,
- options: options
- })
-
- .then(function (doc) {
- var replication = state.PouchDB.replicate(source, target, options)
-
- state.replicationsMap[id] = replication
-
- return {
- replication: replication
- }
- })
-}
diff --git a/api/store/revoke.js b/api/store/revoke.js
deleted file mode 100644
index 1c2d8db..0000000
--- a/api/store/revoke.js
+++ /dev/null
@@ -1,19 +0,0 @@
-module.exports = revokeAccess
-
-var _ = require('lodash')
-
-var getRoleOption = require('../utils/get-role-option')
-var removeRolePrivilege = require('../utils/remove-role-privilege')
-var toDbId = require('../utils/to-db-id')
-
-function revokeAccess (state, name, options) {
- return state.metaDb.get(toDbId(name))
-
- .then(function (doc) {
- _.concat(options.access).forEach(function (privilege) {
- removeRolePrivilege(doc.access, getRoleOption(options), privilege)
- })
-
- return state.metaDb.put(doc)
- })
-}
diff --git a/api/utils/add-role-privilege.js b/api/utils/add-role-privilege.js
deleted file mode 100644
index a1f1f24..0000000
--- a/api/utils/add-role-privilege.js
+++ /dev/null
@@ -1,19 +0,0 @@
-module.exports = addRolePrivilege
-
-var _ = require('lodash')
-
-/**
- * If setting privilege to true (everyone has access) or
- * if the current setting already is true, then set the privilege to true.
- * Otherwise merge the current and added roles to an array, avoiding duplicates.
- */
-function addRolePrivilege (access, role, privilege) {
- if (role === true || access[privilege].role === true) {
- access[privilege] = {
- role: true
- }
- return
- }
-
- access[privilege].role = _.union(access[privilege].role, _.concat(role))
-}
diff --git a/api/utils/couchdb-set-security.js b/api/utils/couchdb-set-security.js
deleted file mode 100644
index 2d5795e..0000000
--- a/api/utils/couchdb-set-security.js
+++ /dev/null
@@ -1,27 +0,0 @@
-module.exports = setSecurity
-
-var request = require('request').defaults({json: true})
-
-function setSecurity (options) {
- return new Promise(function (resolve, reject) {
- request({
- method: 'put',
- url: options.couchDbUrl + encodeURIComponent(options.dbName) + '/_security',
- body: {
- members: {
- roles: ['_hoodie_admin_only']
- }
- }
- }, function (error, response, data) {
- if (error) {
- return reject(error)
- }
-
- if (response.statusCode >= 400) {
- return reject(new Error(data.reason))
- }
-
- resolve()
- })
- })
-}
diff --git a/api/utils/errors.js b/api/utils/errors.js
deleted file mode 100644
index 487aa72..0000000
--- a/api/utils/errors.js
+++ /dev/null
@@ -1,26 +0,0 @@
-module.exports = {}
-
-function hoodieError (options) {
- var error = new Error(options.message)
- error.name = options.name || error.name
- error.status = options.status
-
- return error
-}
-
-module.exports.MISSING = hoodieError({
- name: 'Missing',
- message: 'Store does not exist',
- status: 404
-})
-
-module.exports.CONFLICT = hoodieError({
- name: 'Conflict',
- message: 'Store already exists',
- status: 409
-})
-
-module.exports.REPLICATION_PACKAGE_MISSING = hoodieError({
- message: 'pouchdb-replication package missing: npm.im/pouchdb-replication',
- status: 500
-})
diff --git a/api/utils/get-doc-or-false.js b/api/utils/get-doc-or-false.js
deleted file mode 100644
index 049c837..0000000
--- a/api/utils/get-doc-or-false.js
+++ /dev/null
@@ -1,15 +0,0 @@
-module.exports = getDocOrFalse
-
-var toDbId = require('./to-db-id')
-
-function getDocOrFalse (metaDb, name) {
- return metaDb.get(toDbId(name))
-
- .catch(function (error) {
- if (error.status === 404) {
- return false
- }
-
- throw error
- })
-}
diff --git a/api/utils/get-role-option.js b/api/utils/get-role-option.js
deleted file mode 100644
index f7c7041..0000000
--- a/api/utils/get-role-option.js
+++ /dev/null
@@ -1,5 +0,0 @@
-module.exports = parseRoleOption
-
-function parseRoleOption (options) {
- return options.hasOwnProperty('role') ? options.role : true
-}
diff --git a/api/utils/has-role-privilege.js b/api/utils/has-role-privilege.js
deleted file mode 100644
index 3fc428a..0000000
--- a/api/utils/has-role-privilege.js
+++ /dev/null
@@ -1,15 +0,0 @@
-module.exports = hasRolePrivilege
-
-var _ = require('lodash')
-
-function hasRolePrivilege (access, role, privilege) {
- if (access[privilege].role === true) {
- return true
- }
-
- if (role === true) {
- return false
- }
-
- return _.intersection(access[privilege].role, _.concat(role)).length > 0
-}
diff --git a/api/utils/remove-role-privilege.js b/api/utils/remove-role-privilege.js
deleted file mode 100644
index 0327e9d..0000000
--- a/api/utils/remove-role-privilege.js
+++ /dev/null
@@ -1,23 +0,0 @@
-module.exports = removeRolePrivilege
-
-var _ = require('lodash')
-
-/**
- * An empty array means that nobody has access. If the current setting is true,
- * access cannot be revoked for a role, so it remains true. Otherwise all passed
- * roles are removed from the once that currently have access
- */
-function removeRolePrivilege (access, role, privilege) {
- if (role === true) {
- access[privilege] = {
- role: []
- }
- return
- }
-
- if (access[privilege].role === true) {
- access[privilege].role = true
- }
-
- _.pullAll(access[privilege].role, _.concat(role))
-}
diff --git a/api/utils/to-db-id.js b/api/utils/to-db-id.js
deleted file mode 100644
index 5d2abf1..0000000
--- a/api/utils/to-db-id.js
+++ /dev/null
@@ -1,5 +0,0 @@
-module.exports = toDbId
-
-function toDbId (name) {
- return 'db_' + name
-}
diff --git a/api/utils/to-replication-id.js b/api/utils/to-replication-id.js
deleted file mode 100644
index a82c1a0..0000000
--- a/api/utils/to-replication-id.js
+++ /dev/null
@@ -1,9 +0,0 @@
-module.exports = toReplicationId
-
-var toId = require('to-id')
-
-toReplicationId.prefix = 'replication_'
-
-function toReplicationId (source, target, options) {
- return toReplicationId.prefix + toId(source) + '_' + toId(target)
-}
diff --git a/index.js b/index.js
index 2d16517..74c7677 100644
--- a/index.js
+++ b/index.js
@@ -8,9 +8,9 @@ var url = require('url')
var boom = require('boom')
var hapiToExpress = require('@gr2m/hapi-to-express')
+var StoreFactory = require('@hoodie/store-server-api')
-var StoreFactory = require('./api')
-var toCouchDbUrl = require('./api/utils/pouchdb-options-to-couchdb-url')
+var toCouchDbUrl = require('./utils/pouchdb-options-to-couchdb-url')
var validDbName = /^[a-z]/ // must begin with a lowercase letter
diff --git a/api/utils/pouchdb-options-to-couchdb-url.js b/utils/pouchdb-options-to-couchdb-url.js
similarity index 100%
rename from api/utils/pouchdb-options-to-couchdb-url.js
rename to utils/pouchdb-options-to-couchdb-url.js