-
Notifications
You must be signed in to change notification settings - Fork 2
feat: typescript and tests #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
node_modules/ | ||
.vscode | ||
node_modules | ||
**/*.js | ||
**/*.js.map | ||
**/*.d.ts | ||
!example.js | ||
!typedoc.js | ||
!scripts/* | ||
coverage | ||
.nyc_output | ||
doc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# ILP Plugin | ||
> A generic handle to ILP | ||
> An ILP plugin loader | ||
|
||
[](https://npmjs.org/package/ilp-plugin) | ||
[](https://circleci.com/gh/interledgerjs/ilp-plugin) | ||
[](https://standardjs.com) | ||
[](https://snyk.io/test/github/interledgerjs/ilp-plugin) | ||
|
||
The script below will get ILP credentials with no setup whatsoever. You can | ||
The script below will create an instance of an ILP plugin with no setup whatsoever. You can | ||
use this anywhere that you need an ILP plugin created from details in the | ||
environment. | ||
environment or by specifying the detauls in code. | ||
|
||
## Changes in v4 | ||
- The parameter `options.name` has been deprecated. | ||
- The env parameter `ILP_CREDENTIALS` has been deprecated in favour of `ILP_OPTIONS`. | ||
- The module now includes type definitions for `Plugin` and related types and therefore exports both the type definitions and the `createPlugin` and `isPlugin` functions. | ||
|
||
## Examples | ||
|
||
Javascript: | ||
```js | ||
const plugin = require('ilp-plugin')() | ||
|
||
|
@@ -22,9 +30,29 @@ async function run () { | |
run() | ||
``` | ||
|
||
First, the script checks whether `ILP_CREDENTIALS` is defined in the environment. | ||
`ILP_CREDENTIALS` must contain a JSON object with the options passed into the | ||
constructor of `ilp-plugin-btp` or the module name in `ILP_PLUGIN`. | ||
TypeScript: | ||
```typescript | ||
import createPlugin, { DataHandler } from '..' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a README example, should it import from |
||
const plugin = createPlugin() | ||
const echo: DataHandler = (data: Buffer) => { | ||
return Promise.resolve(data) | ||
} | ||
|
||
async function run () { | ||
plugin.registerDataHandler(echo) | ||
await plugin.connect() | ||
await plugin.sendData(/* ... */) | ||
process.exit(0) | ||
} | ||
|
||
run() | ||
``` | ||
|
||
If no parameters are provided it will attempt to find the config in environment variables. If these are not found it will load a plugin that attempts to connect to a local [moneyd](../moneyd) instance on port 7768. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant link to the moneyd repo so you can find instructions for running it (right now the link is broken) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe say "connect to a local moneyd instance on port 7768 using ilp-plugin-btp", just to be explicit about the default plugin. |
||
|
||
The Environment variables that can be set are: | ||
|
||
- `ILP_PLUGIN` : The name/path of the plugin module | ||
- `ILP_PLUGIN_OPTIONS` : The options passed to the constructor, serialized as a JSON object. | ||
|
||
By default, a random secret will be generated and the plugin will connect to | ||
`btp+ws://localhost:7768`. | ||
The options object passed is a subset of the account configuration object proveded to `ilp-connector`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const plugin = require('.')() | ||
|
||
async function run () { | ||
await plugin.connect() | ||
await plugin.sendData(/* ... */) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this example intended to be runnable? If so, there should be some dummy data here. |
||
process.exit(0) | ||
} | ||
|
||
run() |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/detauls/defaults