# @clerksystems/yoctopus

> Plugin based WebSocket server. Mostly everything in Yoctopus is done through the use of (small) plugins. A plugins can define event listeners and endpoints.

Latest version **1.0.0** (published 2019-05-02) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @clerksystems/yoctopus
pnpm add @clerksystems/yoctopus
yarn add @clerksystems/yoctopus
bun add @clerksystems/yoctopus
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-05-02 |
| First published | 2019-05-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 116 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | kevinkleine |

## Links

- npm: https://www.npmjs.com/package/@clerksystems/yoctopus
- npm.io page: https://npm.io/package/@clerksystems/yoctopus

## Dependencies (6)

- [ws](https://npm.io/package/ws.md) ^6.1.0
- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [secretary](https://npm.io/package/secretary.md) git+ssh://git@bitbucket.org/clerksystems/secretary.git
- [validator](https://npm.io/package/validator.md) ^10.11.0
- [opensslparser](https://npm.io/package/opensslparser.md) git+ssh://git@bitbucket.org/clerksystems/opensslparser.git

## Recent versions

- 1.0.0 (latest) — 2019-05-02

## README

# Yoctopus

## Description
Plugin based WebSocket server. Mostly everything in Yoctopus is done through the use of (small) plugins. A plugins can define event listeners and endpoints. 

When a websocket connection is made, it is given a data store. In that store each plugin gets it own public namespace in which it can privately set predeclared variables called `settings`. As plugins can read (or listen to changes to) each others' settings, they are easy to combine. (A use case might be an authentication plugin upon which's settings certain endpoints are forbidden.)

## Initializing Yoctopus

``` javascript
const server = new Yoctopus( {
	port,           // port to host the server on
	keyPath,        // path to ssl key
	certPath,       // path to ssl cert
	caPath,         // path to ssl ca
} );

await server.plugin( pluginConfig, endpointAlias );
await server.start();
```


## Plugin Config
``` js
{
	name: 'test-plugin'
,   settings    :	{
						'some-setting'	: 'type'
					}
,   listeners   :	{
						server	: {
									onConnectionOpened  : ({ request, notify, socket, connectionSettings, ...staticEndpointArguments }) => {}
								,   onConnectionChanged : ({ request, notify, connectionSettings, ...staticEndpointArguments }) => {}
								,   onConnectionClosed  : ({ request, notify, connectionSettings, ...staticEndpointArguments }) => {}
								,   onRequestReceived   : ({ request, notify, connectionSettings, ...staticEndpointArguments }) => {}
								,   onResponsePrepared  : ({ request, notify, connectionSettings, ...staticEndpointArguments }) => {}
								,   onResponseSent      : ({ request, notify, connectionSettings, ...staticEndpointArguments }) => {}
								}
					,	plugins	: {
									pluginName	: {
													setting	: ({ value, setting, connectionId }) => {}
												}
								}
					}
,   endpoints   :	{
					'endpoint-name' : {
						'method': {
							requirements: {
								'plugin.key': expectedValue
							}
						,	requestFormat: {
								'key': 'type'
							}
						,	handler : ({ request, connectionSettings, ...staticEndpointArguments }) => {}
						}
					}
				}
}
```

## Plugin Alias
Endpoint names are automatically prefixed with the plugin name. For example: an endpoint `user`, defined by a plugin called `fb-auth` will become accessible as `fb-auth:user`.

Calling endpoints in this required `plugin-name:endpoint`-format can be a bit tedious. It also makes it hard to switch plugins. Which is why aliasing can be a good idea.

You can make an endpoint alias, allowing the endpoint to be accessed in the global namespace without the prefixed plugin name, simply by supplying a JSON object defining the endpoint mapping.

``` javascript
{
	endpointAliases: {
		'endpoint name': 'global endpoint name'
	}
}
```

In the case of our `fb-auth:user` endpoint, let's assume we'd rather have the endpoint as `account`. We'd then have to define the following map:

``` javascript
{
	endpointAliases: {
		'user': 'account'
	}
}
```

                                                                               
                                                                               
                                 *#(##((((###/                                 
                              (/*(***,*/(/,****##                              
                            ,(*((((,*,,,,,,,,,,/(#/                            
                           (/**((//*////..,,,//*/((%                           
                          *(//*,,,,,/////..,,,,**////                          
                          %#/////*,,.//*,,.,,//(*((/#                          
                          %(((///,,,...,/....///((((%                          
                          #(##/,,,,//.......,,//*((#%                          
                          %%%%(//,/,,....//..,,*(%%#%                          
                           &&@%(*,,,,./...,,,.,/#&&%                           
                            %#*%%%/,/*,//**,*%%#,(%                            
                    //(/(   ///#@@@(#/,,**(/@@@(*/*   (/(//                    
                    */(///* #@%.&@@@%*,*,,#@&(@@@@# ,(////*                    
             /*/*/ #%%%/%/, /@@@@@@(%/,,,,#/@@&&@@/ ,/#/#%%# *//*/             
            /*(% .. %##/#(%   (%#%%****,*,,*###%(   %(%*%%% ...##*/            
           .(/#*     (#**(%.    /(/,(/,,,./,/(*     #(/*/#     (#//.           
            ,*(#/     #(//(#/((*(,,,./...,*,,/*,#%#(###(#     #/(**            
            (#//*(//    ###%(,***(///....//....,,,*####    **(/**((            
              (////(/*((((/(**(.,///,,.....////*,**/(((/,*(*/***(              
                 (//*//**/((**/*,,,,.,.....*////..*(((//(/***/                 
                    ((,%#%((*,,,*.,////......,,,,.*/(%#%,/(                    
                 (/#/#  &//**/,*,,,*///....*/,,,,,,,,/&  (*#/(                 
                 (/(/  /##*(#((**(/,*,,.,,,/////(((/*(/,  *///                 
                #/%//&%(#((*   ((/***/**/*****(*   *(*/(#&*/%(#                
                 (%/(//*///,   ,%/*/((* ,#(//(%.   ,((/////*%/                 
                 #//(///*/     /#(((#     (/*(#*     (/***/*/#                 
                           ((#**/((##     #(**/**#(#                           
                           (##/&/(/#,     .(/#/@/(#(                           
                          #((%/&%###       #(#&&*%((#                          
                          /((*(%#(#%       ((%(*##(                          
                           *((%/%%&.       .&%&/%((*.                          
                            ,(#(/(           (//#(,

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