# broker-graph

> Experimental service for resource discovery.

Latest version **0.1.0** (published 2021-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install broker-graph
pnpm add broker-graph
yarn add broker-graph
bun add broker-graph
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-03-02 |
| First published | 2021-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 4.1 MB |
| Known vulnerabilities | 0 (+5 in 4 direct dependencies) |
| Install scripts | no |
| Author | Peter Hamilton |
| Maintainers | phamilton |

## Links

- npm: https://www.npmjs.com/package/broker-graph
- npm.io page: https://npm.io/package/broker-graph

## Dependencies (10)

- [cors](https://npm.io/package/cors.md) ~2.7.1
- [uuid](https://npm.io/package/uuid.md) ~3.0.1
- [mingo](https://npm.io/package/mingo.md) ~0.9.1
- [express](https://npm.io/package/express.md) ^4.17.1
- [firebase](https://npm.io/package/firebase.md) ^8.2.9
- [js-cookie](https://npm.io/package/js-cookie.md) ~2.1.3
- [socket.io](https://npm.io/package/socket.io.md) ~1.7.2
- [uri-template](https://npm.io/package/uri-template.md) ~1.0.1
- [firebase-admin](https://npm.io/package/firebase-admin.md) ~5.10.0
- [socket.io-client](https://npm.io/package/socket.io-client.md) ~1.7.2

## Recent versions

- 0.1.0 (latest) — 2021-03-02

## README

# Broker Graph

Broker Graph is an implementation of [concepts](docs/CONCEPTS.md) developed during my graduate work at the University of Toronto. The description of these concepts and the prototype code is **shared to support future research**. This project is **no longer being actively developed as of 2018**.

- [Broker Graph Concepts](docs/CONCEPTS.md) - Write-up of Broker Graph concepts and motivations.
- [Architecture](docs/ARCHITECTURE.md) - High level details of the implementation architecture.
- [Development](docs/DEVELOPMENT.md) - Instructions for building the code.
- [API Documentation](https://peter-hamilton.github.io/broker-graph/) - JSDoc generated *partial* API documentation.

![Formation of Broker Graph relationships](docs/img/BrokerGraphFormation.gif)
## Getting Started

### Setup Server

1. Create a Firebase Javascript Realtime Database ([Instructions](https://firebase.google.com/docs/database/web/start))
   - Firebase Security Rules: Test Mode
   - Follow the instructions for [Initializing the Realtime Database JavaScript SDK](https://firebase.google.com/docs/database/web/start#initialize_the_javascript_sdk). Save the `config` object for a future step.
   - Follow instructions for [generating a private key](https://firebase.google.com/docs/admin/setup#initialize-sdk). Save the key securely.
2. Install Node.js dependencies:

    ```bash
    # Install Broker Graph
    npm install broker-graph
    # Install server dependencies
    npm install express socket.io
    ```

3. Initialize BrokerServer, pasting the Firebase config from step 1. `host` should be the URL of the server.

    ```javascript
    // Initialize express http server
    var app = require('express')()
    var server = require('http').createServer(app);
    server.listen(port, function() {
      console.log('Listening on port ' + port);
    });

    // Initialize Socket.io
    var io = require('socket.io')(server);

    // Initialize Broker Server
    brokerServer = new require('broker-graph').server(io, app, {
      firebaseConfig: {/*firebase config*/},
      firebaseAdminKey: {/*admin key object*/},
      host: "http://HOST:PORT"
    });
    brokerServer.ready.then(() => {
      //Register applications
      brokerServer.registerApplication(
      {
        id: "myApp",
        meta: {/*define general application info*/},
        resources: {/*define static resources*/}
      });
      //Array of Applications can also be passed in BrokerServer `applications` argument
    });
    ```

### Include Broker Graph Client

Broker Graph client can be imported into Node.js applications or included in HTML websites, using a webpack bundled module.

**Node.js**:

Install Node.js dependencies using npm:

    ```npm install broker-graph```

Import module:

```javascript
const Broker = require('broker-graph').client;
```

**HTML**:

Add `broker.js` file and include script in html file:

```html
<script type="text/javascript" src="broker.js"></script>
```

### Initialize a Broker

```javascript
let broker = new Broker({
    host: "http://[server:port]",
    application: "[my_app]",
    firebaseConfig: {/*Copy firebase config*/},
    meta: {
      title: "My App",
      //broker instance info...
    }
    });

broker.ready.then(()=>
{
  // Promise resolves when Broker client is initialized and ready to handle operations.
  // broker.[operation()]...
});

```

---
_Source: https://npm.io/package/broker-graph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
