savvi
v0.3.2
Published
Node.js SDK for Savvi's API
Downloads
1
Readme
savvi.js
Savvi Node.js SDK (Proof-of-Concept)
CLI
Install
npm install --location=global 'ssh://[email protected]/savvi-legal/savvi.js'
Usage
savvi [flags]
| flag | description | | ------------- | ---------------------------------------------------------------- | | --ask | alias for --env, --user, and --org | | --env | ask for and set the current environment url (staging, prod, etc) | | --user | ask for and set the current user email | | --password | forces password auth (rather than secure second-factor) | | --logout | forces re-authentication | | --org | ask for and set the current org | | --impersonate | ask for user and org to impersonate |
You'll get a login link that looks like this:
https://dev.savvilegal.dev/c/12345/#/?access_token=<ACCESS_TOKEN>&id_token=<ID_TOKEN>
SDK
Install
npm install --save 'github:savvi-legal/savvi.js#v1'
<script src="./dist/savvi.js"></script>
<!-- TODO -->
<script src="https://unpkg.com/savvi"></script>
Usage
Node.js
"use strict";
let Savvi = require("savvi");
async function main() {
await Savvi.init({ env: "sandbox" });
await Savvi.login({ email: "[email protected]" });
}
main().catch(console.error);
WebPack
You can build the main library like this:
# build savvi.js
npx webpack-cli build -c ./webpack.config.js
You can build the ./example/app.js
(TODO) like so:
# build example app.js
npx webpack-cli build -c ./webpack.config.example-app.js
npm run genenv
rsync -avhP ./example/app.js public/app.js
And serve it up like so:
npm run start
Then open the example app or tests:
- https://localhost:3000/
- https://localhost:3000/tests/
Documentation
npm run jsdoc
The generated documentation will be in the docs/
folder.
API (proof-of-concept)
// Login with credentials, or initialize with id_token
Savvi.init({
// 'http://localhost:3000/api'
env = 'https://dev.savvilegal.dev/api'
});
Savvi.login({ email, password, id_token });
// Auto-prefixed for the environment. Ex: `https://dev.savvy.legal/api${url}`
Savvi.request({ url: '/user/accounts' })
// Inspect / Debug current id_token
Savvi.Auth.inspect();
// Inspect / Debug current access_token
Savvi.Orgs.inspect();
// Get list of accounts
Savvi.Orgs.list(query);
// Invite new user to account
Savvi.Orgs.invite(account_id, { email });
// Act on behalf of the given organization
Savvi.Orgs.createSession(account_id, { email });
// Manage Workflow Library and Instances
Savvi#Org.Library.list();
Savvi#Org.Partners.add({ code });
Savvi#Org.Partners.list();
Savvi#Org.Partners.remove({ id });
Savvi#Org.Todos.list();
Savvi#Org.Todos.remove({ id });
Savvi#Org.Workflows.open({ template_id });
Savvi#Org.Workflows.list();
Savvi#Org.Workflows.close({ project_id });
Savvi.Public.Partners.get({ code });
// 3rd party tools for testing
Savvi.Box.upsert(token, stream, filename = Path.basename(stream.path));
Testing
Tests can be run in node.js or the browser. Either way, you'll want to set some ENVs:
.env
:
[email protected]
TEST_PASSWORD=test-password-1234
TEST_ORG=1411011163
Node.js
node tests/some-test-name.js
Browser (Vanilla)
- Build the relevant test and env files
npm run webpack npm run genenv rsync -avhP ./tests/ ./public/tests/
- Edit the test runner to include / exclude the tests you want to run.
vim ./public/tests/index.html
- <script src="./tests/some-test-1.js"></script> + <script src="./tests/better-test-2.js"></script>
- Run the localhost server
npm run start
open https://localhost:3000/tests/