# ssb-social-index

> scuttlebot plugin for getting reduced state based on the author's social graph

Latest version **1.1.1** (published 2021-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ssb-social-index
pnpm add ssb-social-index
yarn add ssb-social-index
bun add ssb-social-index
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-11-23 |
| First published | 2019-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Secure Scuttlebutt Consortium |
| Maintainers | chereseeriepa, happy0, staltz, arj03, pfrazee, mixmix, cel, christianbundy, aljoscha-meyer |

## Links

- npm: https://www.npmjs.com/package/ssb-social-index
- Repository: https://github.com/ssbc/ssb-social-index
- Issues: https://github.com/ssbc/ssb-social-index/issues
- npm.io page: https://npm.io/package/ssb-social-index

## Dependencies (4)

- [bipf](https://npm.io/package/bipf.md) ^1.4.0
- [ssb-ref](https://npm.io/package/ssb-ref.md) ^2.7.1
- [pull-defer](https://npm.io/package/pull-defer.md) ^0.2.3
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.6.9

## Recent versions

- 1.1.1 (latest) — 2021-11-23
- 1.2.0 — 2021-07-07
- 1.1.0 — 2021-01-26
- 1.0.0 — 2019-03-26
- 0.1.0 — 2019-03-25
- 0.0.1 — 2019-03-24

## README

# ssb-social-index

[scuttlebot](http://scuttlebutt.nz/) plugin for indexing reduced state based on the author's social graph.

## Usage

This module exports a function that takes some options as an argument. It then returns a plugin that provides certain indexes determined by those options (see the API section below).

```js
const Server = require('scuttlebot')
const config = { ... } // needs options

// Install the plugin
Server
  .use(require('ssb-backlinks')) // required if not using ssb-db2
  .use(require('ssb-social-index')({
    namespace: 'edits',
    type: 'update',
    destField: 'root'
  }))

// Start the server
const server = Server(config)
```

In this fictional example, we'd pick up messages of form:
```js
{
  type: 'update',
  root: '%aleq2po323j12j3s1l2j3s123z',
  update: {
    title: 'Scuttle Camp ~~One~~ Two'
  }
}
```

and provide social index methods at `server.edits[METHOD]`

## API

The function exported by this module takes an option object with three mandatory fields:

```js
{
  namespace: 'foo',
  type: 'bar',
  destField: 'baz'
}
```

These options will produce a plugin named `'foo'` that indexes over messages of type `'bar'`, matching `dest` arguments in the provided functions against a field called `'baz'` on the `'bar'` messages.

For all exposed functions, the `dest` argument must be a FeedId/MessageId.

After calling the exported plugin with all options set to `'about'`, you get a plugin with the following API.

### `server.about.socialValue({ key, dest }, cb)`

Where `dest` is a FeedId/ MessageId which is being described by some `about` messages, and `key` is the specific `about` property you want to know e.g.

```js
server.about.socialValue({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }, (err, value) => {
  console.log(value)
  // => 'Richard'
})
```

The default algorithm for the socialValue is based of the following priorities:
1. the most recent value I have set for that `dest`/ `key` (if it exists)
2. the most recent value that the 'owner' `dest` set for that key (if they've self assigned it)
3. the most recent + 'popular' value for the `dest` / `key` (from all data in your network)

You can however provide your own custom algorithm using the option `getSocialValue`. (See code for details)

### `server.about.latestValue({ key, dest }, cb)`

Same as socialValue, except only gets the most recent value that's been announced by anyone for this `dest` / `key`

### `server.about.socialValues({ key, dest }, cb)`

Returns the most abouts for all people who have published things for this `key` / `dest`

```js
server.about.socialValues({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }, (err, values) => {
  console.log(values)
  // => {
     '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519': 'Richard',
     '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Dick'
  }
})
```

### `server.about.latestValues({ keys, dest }, cb)`

NOTE - takes `keys` an Array of properties to return about a `dest`
Uses the same algorithm as latestValue, except you can get more than one value at once.

e.g.
```js
server.about.latestValues({ keys: ['title', 'image', 'location'], dest: '%Z1Kk8Aj8Bnw5+t4d73kRPHMA0Nj2bL1bx7n7obZhVZg=.sha256' }, (err, values) => {
  console.log(values)
  // => {
    title: 'Picnic Birthday Party',
    image: '&asrg0Mb/w3lLC+yZIJr/4aY0nkWT9Wn+32zrqhaIvy4=.sha256',
    location: 'Scorching Bay'
  }
})
```

### `server.about.socialValueStream({ key, dest })` => source

Similar to socialValue, except served over a stream. If the value changes a new value is sent down the stream

```js
pull(
  server.about.socialValueStream({ key: 'avatar', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }),
  pull.drain(avatar => {
    console.log(avatar)
    // => '&asrg0Mb/w3lLC+yZIJr/4aY0nkWT9Wn+32zrqhaIvy4=.sha256'
    // (later) => '&gwEYOFxfKxHSviAqeGub34eOIGXuuwn3G6odVNW9UtQ=.sha256'
  })
)
```

### `server.about.socialValuesStream({ key, dest })` => source

Similar to socialValues, except served over a stream. If the values change **only the new values** are emitted.

```js
pull(
  server.about.socialValueStream({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }),
  pull.drain(title => {
    console.log(title)
    // => {
    //   '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519': 'Richard',
    //   '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Dick'
    // }
    // (later) => {
    //   '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Rich'
    // }
  })
)
```

### `server.about.latestValueStream({ key, dest, authorId = null })` => source

Same as latestValue expect a stream. First value emitted is the current value, subsequent are new values.

```js
pull(
  server.about.socialValueStream({ key: 'title', dest: '%Z1Kk8Aj8Bnw5+t4d73kRPHMA0Nj2bL1bx7n7obZhVZg=.sha256' }),
  pull.drain(title => {
    console.log(title)
    // => 'Picnic Birthday Party'
    // (later) => 'Beach Party'
  })
)
```

If `authorId` is present, this provides a stream of values for a particular `dest` `key`, as asserted by that particular `authorId`

### `server.about.read({ reverse = false, limit, live, old, dest })` => source

A stream of all about messages that target `dest`

## License

MIT

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