Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

feat: typescript and tests #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ jobs:
name: Install
command: npm install

- run:
name: Lint
command: npm run lint

- run:
name: Test
command: npm test

- run:
name: Upload Test Coverage to codecov.io
command: npm run codecov

- run:
name: Upload Lockfile (Greenkeeper)
command: greenkeeper-lockfile-upload
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
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
44 changes: 36 additions & 8 deletions README.md
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

[![NPM Package](https://img.shields.io/npm/v/ilp-plugin.svg?style=flat)](https://npmjs.org/package/ilp-plugin)
[![CircleCI](https://circleci.com/gh/interledgerjs/ilp-plugin.svg?style=shield)](https://circleci.com/gh/interledgerjs/ilp-plugin)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Known Vulnerabilities](https://snyk.io/test/github/interledgerjs/ilp-plugin/badge.svg)](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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/detauls/defaults


## 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')()

Expand All @@ -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 '..'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a README example, should it import from ilp-plugin instead of a relative path?

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.
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The 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`.
9 changes: 9 additions & 0 deletions example.js
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(/* ... */)
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
20 changes: 0 additions & 20 deletions index.d.ts

This file was deleted.

20 changes: 0 additions & 20 deletions index.js

This file was deleted.

Loading