0.3.2 • Published 1 year ago

savvi v0.3.2

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

savvi.js

Savvi Node.js SDK (Proof-of-Concept)

CLI

Install

npm install --location=global 'ssh://git@github.com/savvi-legal/savvi.js'

Usage

savvi [flags]
flagdescription
--askalias for --env, --user, and --org
--envask for and set the current environment url (staging, prod, etc)
--userask for and set the current user email
--passwordforces password auth (rather than secure second-factor)
--logoutforces re-authentication
--orgask for and set the current org
--impersonateask 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: "me@example.com" });
}

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:

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:

TEST_USERNAME=YOUR_EMAIL+test@savvi.legal
TEST_PASSWORD=test-password-1234
TEST_ORG=1411011163

Node.js

node tests/some-test-name.js

Browser (Vanilla)

  1. Build the relevant test and env files
    npm run webpack
    npm run genenv
    rsync -avhP ./tests/ ./public/tests/
  2. 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>
  3. Run the localhost server
    npm run start
    open https://localhost:3000/tests/