@moneylion/engine-api
v1.3.1
Published
Interface to engine.tech API
Downloads
186
Maintainers
Keywords
Readme
Engine API
This is a Javascript interface to the Engine API service.
Getting Started
Install the library
npm add @moneylion/engine-api
Request an authentication token and API endpoint from Engine.
Creating a Client Instance
Normally you won't have to create a client instance, but you can do so if you want to make a request that this library doesn't support.
import { Client } from "@moneylion/engine-api";
new Client(endpoint, authentication_token);
This provides get
, post
, and patch
methods that accept a REST endpoint and a request body.
The request body will be serialized to JSON before being sent.
If you want to pass a body as a string or use a different HTTP method, use the request
method.
client.request("/endpoint", "DELETE", "body as a string");
Creating a Lead
To create a lead, you can do the following:
import { Lead } from "@moneylion/engine-api";
new Lead(endpoint, authentication_token).create(lead);
This will return a promise that resolves with the UUID of the lead that was just created. It will not create a rate table yet. In order to create a rate table you can do the following:
import { Lead } from "@moneylion/engine-api";
new Lead(endpoint, authentication_token).getRateTable(lead);
This will return a promise that resolves with an AsyncRateTable.
You can use the AsyncRateTable.resolve()
method to turn it into a real RateTable.
You can also use getRateTableBlocking
which will resolve with a RateTable, but you will potentially spend longer waiting for network requests.
You can do the lead creation and rate table fetch in one step using the createAndGetRateTable
and createAndGetRateTableBlocking
methods.
Updating a Lead
To update a lead, you can do the following:
import { Lead } from "@moneylion/engine-api";
new Lead(endpoint, authentication_token).update(leadUuid, updatedLead);
This returns a promise but will not resolve with a rate table and will instead resolve the lead UUID back to you when it finishes.
Rate Tables
Rate tables are returned when you create a lead. If you would like to retrieve a rate table manually you can request it by its UUID.
import { AsyncRateTable } from "@moneylion/engine-api";
new AsyncRateTable({ uuid: rateTableUuid, host: endpoint, api_token: authentication_token }).resolve();
// You can also pass a pre-created client instead of endpoint and token
new AsyncRateTable({ uuid: rateTableUuid, client: client }).resolve();
// You can also pass a RateTable object instead of a uuid.
new AsyncRateTable({ rateTable: rateTable, client: client }).resolve();
For Contributors
This is a relatively normal NPM and Typescript project.
npm install
to install dependenciesnpm run build
to build the projectnpm test
to run the tests
Publishing to NPM
Run the following steps to publish the library to NPM.
- Update the version number in
package.json
. Commit this change. npm run build
- This will run Typescript to compile the Javascript.npm publish --access=public
. This will publish the library.