Code Monkey home page Code Monkey logo

openlaw-client's Introduction

openlaw

npm version

Shared JavaScript libraries for the OpenLaw project

The OpenLaw JavaScript APIs allow you to integrate and build on the OpenLaw protocol.

The class APIClient library is an interface for querying, saving, and changing data in an OpenLaw instance as well as for user authentication. The interface serves as a convenient wrapper to the OpenLaw REST API.

The Openlaw object library is an interface to interact directly with an OpenLaw legal agreement and its contents, including its various variable types.

Documentation

Check out the guide for getting started, the complete reference for using the OpenLaw JavaScript APIs, and other information about how to use the OpenLaw application at our docs.

Installation

$ npm install openlaw --save

Ways to Use

/**
 * ES2015: import for bundlers like webpack
 */

// import both modules
import { APIClient, Openlaw } from "openlaw";
// OR import only `Openlaw`
import { Openlaw } from "openlaw";
// OR import only `APIClient`
import { APIClient } from "openlaw";


/**
 * CommonJS
 */

// require() for Node.js (or bundlers that support CommonJS-style modules)
const { APIClient, Openlaw } = require('openlaw');


/**
 * Browser: available as a browser global: `openlaw`
 */

<script src="https://unpkg.com/openlaw/dist/umd/openlaw.js"></script>

<script>
  const Openlaw = openlaw.Openlaw;
  const APIClient = openlaw.APIClient;
</script>


/**
 * Browser, with ES Modules (https://caniuse.com/#search=Modules)
 */

// in your app
import { Openlaw, APIClient } from './path/to/openlaw/index.esm.js';

// then, in your HTML
<script type="module" src="./app.js"></script>

Example Usage

APIClient

import { APIClient } from "openlaw";

// Include the root URL for the OpenLaw instance.
apiClient = new APIClient("https://lib.openlaw.io/api/v1/default");

/*
Most of the APIClient method calls can only be made by a logged in
user with a StandardUser role or an Admin role. Log in before making
those calls.
*/
apiClient.login("[email protected]", "password");

apiClient.getTemplate("Advisor Agreement").then((result) => {
  console.log(result);
});
/*
{
  "id": "d76ede8ca437f6da06b1e09f115393318faf29fdc5bdaaf0b2e889886136edf4",
  "title": "Advisor Agreement",
  "content": "This Advisor Agreement is entered into between [[Company Name: Text]] (\"Corporation\") and [[Advisor Name]] (\"Advisor\") as of [[Effective Date: Date]] (\"Effective Date\"). Company and Advisor agree as follows:  \n\n^ **Services**. Advisor agrees to consult with and advise Company from time to time, at Company's request (the \"Services\"). {{No Services \"Do you want to limit the advisor's services?\"  While this Agreement is is effect, Advisor will not provide services to any company active in the field of [[Noncompete Field \"What field should the advisor not participate in?\"]].}}\n\n...**COMPANY:**\n[[Company Signatory Email: Identity]]\n\n___________________\nName:  [[Company Signatory]]\nAddress:  [[Company Address: Address]]\n\n\n**ADVISOR:**\n[[Advisor Email: Identity]]\n\n___________________\nName [[Advisor Name]]      \nAddress: [[Advisor Address: Address]]\n",
  "templateType": "agreement"
}
*/

Openlaw

import { Openlaw } from "openlaw";

const compiledTemplate = Openlaw.compileTemplate(
  'This Advisor Agreement is entered into between [[Company Name]] ("Corporation") and [[Advisor Name]] ("Advisor") as of [[Effective Date: Date]] ("Effective Date"). Company and Advisor agree as follows: \n\n^**Services**. Advisor agrees to consult with and advise Company from time to time, at Company\'s request (the "Services").'
);

console.log(compiledTemplate);
/*
{
  isError: false,
  errorMessage: "",
  compiledTemplate: CompiledTemplate
}
*/

Troubleshooting

(Project maintainers only)

Before the first time you run npm run build or npm run build:prod, run sbt fullOptJS from the project root directory to generate the client.js file. Otherwise, you will see an error like the following:

ERROR in Entry module not found: Error: Can't resolve '/$YOUR_DIR/openlaw-client/target/scala-2.12/client.js' in '/$YOUR_DIR/openlaw-client'.

Publishing Releases

(Project maintainers only)

Run npm run release which will walk you through the process of updating the semantic version, and drafting a GitHub release. Once the release is published on GitHub, the CI/CD should detect it and handle the publication to NPM.

More detailed documentation about the release process is here.

Contributing

See information about contributing here.

Code Formatting

We adhere to standardized code formatting via Prettier and scalafmt. All PRs will be automatically checked for adherence. If they do not adhere to standardized formatting, they should be corrected prior to being merged.

The best way is let your editor handle everything for you everytime you hit save, see the Scalafmt Installation Docs or the OpenLaw developer setup documentation.

To manually verify, can run make lint-style to check and make lint-style-fix to automatically repair all files.

License

Copyright 2019 Aaron Wright, David Roon, and ConsenSys AG.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

openlaw-client's People

Contributors

adridadou avatar craig-openlaw avatar craigwblake avatar dependabot-preview[bot] avatar dependabot[bot] avatar eyalperry88 avatar fforbeck avatar happy0 avatar jdville03 avatar joshma91 avatar jtrein avatar mingfang avatar mroth avatar outkaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openlaw-client's Issues

POST https://lib.openlaw.io/api/v1/default/upload/contract 500

const result = await apiClient.uploadContract(uploadParams);
console.log("results..", result);

In my uploadParams

{templateId: "6e8fdcdc6f0eaafe7dc88b56b90aa85a6e8ea53bcfbc18dca3b9743ca6c1e5d9", title: "OPENLEASE", text: "<%↵[[Seller Address: EthAddress]]↵[[Buyer Address:…↵[[Tenant Signatory Email: Identity | Signature]]", creator: "Peter", parameters: {…}, …}
templateId: "6e8fdcdc6f0eaafe7dc88b56b90aa85a6e8ea53bcfbc18dca3b9743ca6c1e5d9"
title: "OPENLEASE"
text: "<%↵[[Seller Address: EthAddress]]↵[[Buyer Address: EthAddress]]↵[[Purchased Item]]↵[[Purchase Price: Number]]↵[[@Purchase Price in Wei = Purchase Price * 1000000000000000000]]↵[[Record Contract:EthereumCall(↵contract: "0x0831eE46d34bcD4c5139f0104089AA68F401acEA";↵interface:[{"constant":false,"inputs":[{"name":"_descr","type":"string"},{"name":"_price","type":"uint256"},{"name":"_seller","type":"address"},{"name":"_buyer","type":"address"}],"name":"recordContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}];↵network:"Rinkeby";↵function:"recordContract";↵arguments: Purchased Item, Purchase Price in Wei, Seller Address, Buyer Address)]]↵%>↵\centered ** BILL OF LEASE **↵Landlord at Ethereum address [[Seller Address]] ("Seller") agrees for rent a **[[Purchased Item]]**, and tenant at Ethereum address [[Buyer Address]]  ("Buyer") agrees to pay [[Purchase Price]] ether per month located at the contract address "0x0831eE46d34bcD4c5139f0104089AA68F401acEA".↵[[Record Contract]]↵Landlord:↵[[Landlord Signatory Email: Identity | Signature]]↵________________↵Tenant:↵[[Tenant Signatory Email: Identity | Signature]]"
creator: "Peter"
parameters: {Seller Address: "0xb4742932bDAe0caeCf8Eb2AAcb34384433d74226", Buyer Address: "0xb4742932bDAe0caeCf8Eb2AAcb34384433d74226", Purchased Item: "House", Purchase Price: "0.1", Seller Signatory Email: "[email protected]", …}
overriddenParagraphs: {}
agreements: {}
readonlyEmails: []
editEmails: []
draftId: "628092cfd9de0608225c864556ec367f8566c994e30de58132e5b5b1327ce070"
__proto__: Object

The response was Empty list of emails

i can't upload the contract

Add function to get the serviceName

As discussed with @jtrein in openlawteam/openlaw-core#180

It would be good if we could access the serviceName variable value with a new function in ol client.

We would call it as early as we know the serviceName. It could be used as a prop, or we could just call the function on render inside of ExternalSignature.

repeat build performance of build:esm phase

Encountered this separately while working on the other build stuff, carving out as a separate issue to remind myself for the future.

Currently the build:esm phase (which is prerequisite of running release) is defined via npm scripts such as:

  "scripts": {
    /* snip */
    "build:esm": "npm run build:esm:apiclient && npm run build:esm:openlaw && npm run build:esm:index",
    "build:esm:openlaw": "npx cpy --rename=openlaw.js 'target/scala-2.12/client.js' 'dist/esm/lib/' && npx terser dist/esm/lib/openlaw.js -cm --module -o dist/esm/lib/openlaw.js",
    "build:esm:apiclient": "npx cpy --rename=apiclient.js 'js/src/APIClient.js' 'dist/esm/lib/' && npx babel dist/esm/lib/apiclient.js -o dist/esm/lib/apiclient.js && npx terser dist/esm/lib/apiclient.js -cm --module -o dist/esm/lib/apiclient.js",
    "build:esm:index": "npx cpy --rename=index.js 'js/src/index.esm.js' 'dist/esm/lib/'",
    /* snip */
  },

The disadvantage of this method is there is no awareness of what files have already been built and are up to date, thus every time the phase is invoked the entire thing re-runs whether or not the dependencies have changed.

Replicating the same via a standard Makefile enables only changed files to need to be rebuilt, and for jobs to be run in parallel.

Example Makefile (yeah, I know I like using variables...)

ESM_LIB=dist/esm/lib
JS_SRC=js/src
SCALA_TARGET=target/scala-2.12

build_esm: ${ESM_LIB}/openlaw.js ${ESM_LIB}/apiclient.js ${ESM_LIB}/index.js

${ESM_LIB}/openlaw.js: ${SCALA_TARGET}/client.js ${ESM_LIB}
	npx terser $< -cm --module -o $@

${ESM_LIB}/apiclient.js: ${JS_SRC}/APIClient.js ${ESM_LIB}
	npx babel $< | npx terser -cm --module -o $@

${ESM_LIB}/index.js: ${JS_SRC}/index.esm.js ${ESM_LIB}
	cp $< $@

${ESM_LIB}:
	mkdir -p $@

Comparative benchmarks on my workstation

npm run build:esm make -j4 build_esm
initial build 31.6s 23.1s
change APIClient.js 31.6s 1.4s
no changes 31.6s 0.0s

(It's worth noting my workstation is fairly fast, and the actual numbers when run on our standard CI hardware are roughly double this, so the ratio difference becomes potentially more dramatic on a CI server or laptop.):

Note, I don't believe we should switch to a Makefile here, as currently this works via just NPM such that it doesn't matter if someone is on a Windows machine (which may not have Make installed). However, I strongly suspect there is a way to get JS build tools to do something similar.

We already have both webpack and rollup as a dev dependency here, so I'd be loathe to install yet another build tool. Perhaps one of them can handle it? Leaving this as notes for myself in the future to look into and tackle this!

CC FE folx (@jtrein @jdville03 @sophiacodes) if you know the best practice/tool here, feel free to drop some notes to help me out when I get around to this one day.

Trouble importing APIClient from openlaw npm package

Hi, I am trying to incorporate openlaw into my project. I've installed openlaw using npm, but as soon as I try to import the APIClient into my react component using
import { APIClient, Openlaw } from "openlaw";

I get this error:

Starting the development server...


<--- Last few GCs --->

[20276:00000179AF5DAE30]    87321 ms: Mark-sweep 1301.0 (1441.3) -> 1286.4 (1438.8) MB, 2155.7 / 0.0 ms  (average mu = 0.115, current mu = 0.083) allocation failure scavenge might not succeed
[20276:00000179AF5DAE30]    87424 ms: Scavenge 1300.7 (1438.8) -> 1287.9 (1441.3) MB, 5.5 / 0.0 ms  (average mu = 0.115, current mu = 0.083) allocation failure


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 000001A4F19DC5C1]
Security context: 0x00631041e6e9 <JSObject>
    1: next [0000006310419FB9](this=0x01d8eb6bcce1 <Array Iterator map = 00000138CD906141>)
    2: StubFrame [pc: 000001A4F19D5D8B]
    3: StubFrame [pc: 000001A4F198B75A]
    4: validate [0000021A631CA679] [C:\repos\ProjectPegasus\node_modules\@babel\types\lib\definitions\utils.js:~199] [pc=000001A4F26786D8](this=0x021a631c7849 <Object map = 000001B9B2544...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF699C9DD8A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 00007FF699C78886 node::MakeCallback+4534
 3: 00007FF699C79200 node_module_register+2032
 4: 00007FF699F930DE v8::internal::FatalProcessOutOfMemory+846
 5: 00007FF699F9300F v8::internal::FatalProcessOutOfMemory+639
 6: 00007FF69A179804 v8::internal::Heap::MaxHeapGrowingFactor+9620
 7: 00007FF69A1707E6 v8::internal::ScavengeJob::operator=+24550
 8: 00007FF69A16EE3C v8::internal::ScavengeJob::operator=+17980
 9: 00007FF69A177B87 v8::internal::Heap::MaxHeapGrowingFactor+2327
10: 00007FF69A177C06 v8::internal::Heap::MaxHeapGrowingFactor+2454
11: 00007FF69A2A1EA7 v8::internal::Factory::NewFillerObject+55
12: 00007FF69A31F096 v8::internal::operator<<+73494
13: 000001A4F19DC5C1
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

Has anyone encountered this before? Is there something else that I need to do?

Deal does not render in browser, isDeal should return true.

Source
From the community slack User: Tristan Roberts
Instance: etherizeit.openlaw.io
Relevant code
https://pastebin.com/Y0HdG7bi
@jdville03 or whovever else spots. Message @mcchan1 for the user's full zip file.

Problem:
Deal package of templates not rendering in the browser. A single template renders as expected.
"isDeal" returns false.

Expected Behavior:

  • Deal package of templates should render in browser.
  • "isDeal" should return "true"

Was able to replicate as follows:

  1. "test-deal" on the user's OL instance works from the OpenLaw app.
  2. isDeal returns "false" when it should return "true"
  3. User's Create.js file works as expected when only one template.
  4. When 'test-deal' was the template. console logged executionResult in the user's executeTemplate and previewTemplate and an error was returned.

checkValidity should return error object

While working on openlaw-elements, I am attempting to successfully use checkValidity to validate a type like Period.

My issue is that the error object that is returned is not predictable, or reliable for property access. The error object that is returned when checking the Period (for example) type is:

Screen Shot 2019-07-08 at 1 03 04 PM

In my opinion, it would be much better to mirror the style of the executionResult object that returns a reliable isError: ..., errorMessage: ... keys/values.

Example usage

const { errorMessage } = checkValidity(name, value, executionResult);

if (errorMessage) {
  this.setState({ errorMessage });
  // more handling ...
}

For me, this is a blocker on the front-end, because we cannot know if there's an error.

import from openlaw fails

I'm getting the following error when trying to run:

import { APIClient, Openlaw } from 'openlaw';
inside of my App.js from create-react-app.

This is the stack trace:
image

Make wart remover and ScalaJS play nicely

Wart remover and Scala JS don't play well together - wart remover thinks JsExport, etc are signs of an error. There used to be a wart remover plugin specifically for ScalaJS, but it seems deprecated. At some point we should still enable Wart Remover for the project (we may have to make a custom ruleset disabling some of their basic rules).

clean up JS build sytem (details TBD)

As mroth mentioned, right now the JS build system is very difficult to reason about as we have a few overlapping tools with complex rulesets. We should clean this up.

For example, it's possible (and even likely) that we may not need to use both rollup and webpack, since they have overlapping functionality.

Timestamp Bug

Hi, I am using the openlaw js client and it seems like the timestamp is incorrect I am assuming its supposed to be a unix timestamp? This is the response I get when calling executing await apiClient.getTemplateVersions(openLawConfig.templateName, 20, 1);

image

In unix this would be:

image

In the documentation as well, this timestamp is similar:
image

getAccessToken call not working, returning 404 error.

Problem/Enhancement

getAccessToken call not working, returning 404 error. Original 404 error was on the app.openlaw.io instance. I get the same error for this call on the 'develop' and 'app-rc' instance. Tried with multiple templates, but I'm testing it out on "OpenLaw API Tutorial Sale Agreement" template on the 'develop' instance.

Wireframes

image

Pages

Acceptance Criteria

  • getAccessToken call does not return 404 error

Special QA Instructions

[Optional: Anything special QA should know about this? ]

Related Tasks

[Optional: Link to other tasks that are related.]

rollup.js silently fails after undocumented timeout

RollupJS appears to silently fail (no error output, does not cause with error code) if a process takes longer than some timeout period (60 seconds if my current guess). I don't see anything obvious in its documentation about this though. This is causing the release phase of our CI scripts to proceed missing needed files.

We need to be able to:

a) enable error reporting so a build will fail rather than silently proceed missing some files,
b) configure the timeout to allow time for our giant slow conversion to run on server that are not so strong.

Any ideas as to how to approach this? (We are also running a somewhat older version of rollupJS, its possible this is improved in a future version? I didnt want to blindly upgrade it though since there are breaking changes mentioned in the changelog and the config files for it are kinda a mystery to me.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.