Skip to main content

Cicero API

Modules

cicero-engine

Clause Engine

cicero-core

Cicero Core - defines the core data types for Cicero.

Classes

Clause

A Clause is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

Contract

A Contract is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

Metadata

Defines the metadata for a Template, including the name, version, README markdown.

Template

A template for a legal clause or contract. A Template has a template model, request/response transaction types, a template grammar (natural language for the template) as well as Ergo code for the business logic of the template.

TemplateInstance

A TemplateInstance is an instance of a Clause or Contract template. It is executable business logic, linked to a natural language (legally enforceable) template. A TemplateInstance must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the TemplateInstance by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

CompositeArchiveLoader

Manages a set of archive loaders, delegating to the first archive loader that accepts a URL.

Functions

isPNG(buffer)Boolean

Checks whether the file is PNG

getMimeType(buffer)Object

Returns the mime-type of the file

cicero-engine

Clause Engine

cicero-engine.Engine

Engine class. Stateless execution of clauses against a request object, returning a response to the caller.

Kind: static class of cicero-engine
Access: public

new Engine()

Create the Engine.

engine.trigger(clause, request, state, [currentTime], [utcOffset]) ⇒ Promise

Send a request to a clause for execution

Kind: instance method of Engine
Returns: Promise - a promise that resolves to a result for the clause

ParamTypeDescription
clauseClausethe clause
requestobjectthe request, a JS object that can be deserialized using the Composer serializer.
stateobjectthe contract state, a JS object that can be deserialized using the Composer serializer.
[currentTime]stringthe definition of 'now', defaults to current time
[utcOffset]numberUTC Offset for this execution, defaults to local offset

engine.invoke(clause, clauseName, params, state, [currentTime], [utcOffset]) ⇒ Promise

Invoke a specific clause for execution

Kind: instance method of Engine
Returns: Promise - a promise that resolves to a result for the clause

ParamTypeDescription
clauseClausethe clause
clauseNamestringthe clause name
paramsobjectthe clause parameters, a JS object whose fields that can be deserialized using the Composer serializer.
stateobjectthe contract state, a JS object that can be deserialized using the Composer serializer.
[currentTime]stringthe definition of 'now', defaults to current time
[utcOffset]numberUTC Offset for this execution, defaults to local offset

engine.init(clause, [currentTime], [utcOffset], params) ⇒ Promise

Initialize a clause

Kind: instance method of Engine
Returns: Promise - a promise that resolves to a result for the clause initialization

ParamTypeDescription
clauseClausethe clause
[currentTime]stringthe definition of 'now', defaults to current time
[utcOffset]numberUTC Offset for this execution, defaults to local offset
paramsobjectthe clause parameters, a JS object whose fields that can be deserialized using the Composer serializer.

engine.getErgoEngine() ⇒ ErgoEngine

Provides access to the underlying Ergo engine.

Kind: instance method of Engine
Returns: ErgoEngine - the Ergo Engine for this Engine

cicero-core

Cicero Core - defines the core data types for Cicero.

Clause

A Clause is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

Kind: global class
Access: public

Contract

A Contract is executable business logic, linked to a natural language (legally enforceable) template. A Clause must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the clause (an instance of the template model) by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

Kind: global class
Access: public

Metadata

Defines the metadata for a Template, including the name, version, README markdown.

Kind: global class
Access: public

Create the Metadata.

Note: Only to be called by framework code. Applications should retrieve instances from [Template](#Template)

ParamTypeDescription
packageJsonobjectthe JS object for package.json (required)
readmeStringthe README.md for the template (may be null)
samplesobjectthe sample markdown for the template in different locales,
requestobjectthe JS object for the sample request
logoBufferthe bytes data for the image represented as an object whose keys are the locales and whose values are the sample markdown. For example: { default: 'default sample markdown', en: 'sample text in english', fr: 'example de texte français' } Locale keys (with the exception of default) conform to the IETF Language Tag specification (BCP 47). THe default key represents sample template text in a non-specified language, stored in a file called sample.md.

metadata.getTemplateType() ⇒ number

Returns either a 0 (for a contract template), or 1 (for a clause template)

Kind: instance method of Metadata
Returns: number - the template type

metadata.getLogo() ⇒ Buffer

Returns the logo at the root of the template

Kind: instance method of Metadata
Returns: Buffer - the bytes data of logo

metadata.getAuthor() ⇒ *

Returns the author for this template.

Kind: instance method of Metadata
Returns: * - the author information

metadata.getRuntime() ⇒ string

Returns the name of the runtime target for this template, or null if this template has not been compiled for a specific runtime.

Kind: instance method of Metadata
Returns: string - the name of the runtime

metadata.getCiceroVersion() ⇒ string

Returns the version of Cicero that this template is compatible with. i.e. which version of the runtime was this template built for? The version string conforms to the semver definition

Kind: instance method of Metadata
Returns: string - the semantic version

metadata.satisfiesCiceroVersion(version) ⇒ string

Only returns true if the current cicero version satisfies the target version of this template

Kind: instance method of Metadata
Returns: string - the semantic version

ParamTypeDescription
versionstringthe cicero version to check against

metadata.getSamples() ⇒ object

Returns the samples for this template.

Kind: instance method of Metadata
Returns: object - the sample files for the template

metadata.getRequest() ⇒ object

Returns the sample request for this template.

Kind: instance method of Metadata
Returns: object - the sample request for the template

metadata.getSample(locale) ⇒ string

Returns the sample for this template in the given locale. This may be null. If no locale is specified returns the default sample if it has been specified.

Kind: instance method of Metadata
Returns: string - the sample file for the template in the given locale or null

ParamTypeDefaultDescription
localestringnullthe IETF language code for the language.

metadata.getREADME() ⇒ String

Returns the README.md for this template. This may be null if the template does not have a README.md

Kind: instance method of Metadata
Returns: String - the README.md file for the template or null

metadata.getPackageJson() ⇒ object

Returns the package.json for this template.

Kind: instance method of Metadata
Returns: object - the Javascript object for package.json

metadata.getName() ⇒ string

Returns the name for this template.

Kind: instance method of Metadata
Returns: string - the name of the template

metadata.getDisplayName() ⇒ string

Returns the display name for this template.

Kind: instance method of Metadata
Returns: string - the display name of the template

metadata.getKeywords() ⇒ Array

Returns the keywords for this template.

Kind: instance method of Metadata
Returns: Array - the keywords of the template

metadata.getDescription() ⇒ string

Returns the description for this template.

Kind: instance method of Metadata
Returns: string - the description of the template

metadata.getVersion() ⇒ string

Returns the version for this template.

Kind: instance method of Metadata
Returns: string - the description of the template

metadata.getIdentifier() ⇒ string

Returns the identifier for this template, formed from name@version.

Kind: instance method of Metadata
Returns: string - the identifier of the template

metadata.createTargetMetadata(runtimeName) ⇒ object

Return new Metadata for a target runtime

Kind: instance method of Metadata
Returns: object - the new Metadata

ParamTypeDescription
runtimeNamestringthe target runtime name

metadata.toJSON() ⇒ object

Return the whole metadata content, for hashing

Kind: instance method of Metadata
Returns: object - the content of the metadata object

Metadata.checkImage(buffer)

Check the buffer is a png file with the right size

Kind: static method of Metadata

ParamTypeDescription
bufferBufferthe buffer object

Metadata.checkImageDimensions(buffer, mimeType)

Checks if dimensions for the image are correct.

Kind: static method of Metadata

ParamTypeDescription
bufferBufferthe buffer object
mimeTypestringthe mime type of the object

Template

A template for a legal clause or contract. A Template has a template model, request/response transaction types, a template grammar (natural language for the template) as well as Ergo code for the business logic of the template.

Kind: global abstract class
Access: public

new Template(packageJson, readme, samples, request, logo, options, authorSignature)

Create the Template. Note: Only to be called by framework code. Applications should retrieve instances from fromArchive or fromDirectory.

ParamTypeDescription
packageJsonobjectthe JS object for package.json
readmeStringthe readme in markdown for the template (optional)
samplesobjectthe sample text for the template in different locales
requestobjectthe JS object for the sample request
logoBufferthe bytes data of logo
optionsObjecte.g., { warnings: true }
authorSignatureObjectobject containing template hash, timestamp, author's certificate, signature

template.validate(options)

Verifies that the template is well formed. Compiles the Ergo logic. Throws an exception with the details of any validation errors.

Kind: instance method of Template

ParamTypeDescription
optionsObjecte.g., { verify: true }

template.getTemplateModel() ⇒ ClassDeclaration

Returns the template model for the template

Kind: instance method of Template
Returns: ClassDeclaration - the template model for the template
Throws:

  • Error if no template model is found, or multiple template models are found

template.getIdentifier() ⇒ String

Returns the identifier for this template

Kind: instance method of Template
Returns: String - the identifier of this template

template.getMetadata() ⇒ Metadata

Returns the metadata for this template

Kind: instance method of Template
Returns: Metadata - the metadata for this template

template.getName() ⇒ String

Returns the name for this template

Kind: instance method of Template
Returns: String - the name of this template

template.getDisplayName() ⇒ string

Returns the display name for this template.

Kind: instance method of Template
Returns: string - the display name of the template

template.getVersion() ⇒ String

Returns the version for this template

Kind: instance method of Template
Returns: String - the version of this template. Use semver module to parse.

template.getDescription() ⇒ String

Returns the description for this template

Kind: instance method of Template
Returns: String - the description of this template

template.getHash() ⇒ string

Gets a content based SHA-256 hash for this template. Hash is based on the metadata for the template plus the contents of all the models and all the script files.

Kind: instance method of Template
Returns: string - the SHA-256 hash in hex format

template.verifyTemplateSignature()

verifies the signature stored in the template object using the template hash and timestamp

Kind: instance method of Template

template.signTemplate(p12File, passphrase, timestamp)

signs a string made up of template hash and time stamp using private key derived from the keystore

Kind: instance method of Template

ParamTypeDescription
p12FileStringencoded string of p12 keystore file
passphraseStringpassphrase for the keystore file
timestampNumbertimestamp of the moment of signature is done

template.toArchive([language], [options]) ⇒ Promise.<Buffer>

Persists this template to a Cicero Template Archive (cta) file.

Kind: instance method of Template
Returns: Promise.<Buffer> - the zlib buffer

ParamTypeDescription
[language]stringtarget language for the archive (should be 'ergo')
[options]ObjectJSZip options and keystore object containing path and passphrase for the keystore

template.getParserManager() ⇒ ParserManager

Provides access to the parser manager for this template. The parser manager can convert template data to and from natural language text.

Kind: instance method of Template
Returns: ParserManager - the ParserManager for this template

template.getLogicManager() ⇒ LogicManager

Provides access to the template logic for this template. The template logic encapsulate the code necessary to execute the clause or contract.

Kind: instance method of Template
Returns: LogicManager - the LogicManager for this template

template.getIntrospector() ⇒ Introspector

Provides access to the Introspector for this template. The Introspector is used to reflect on the types defined within this template.

Kind: instance method of Template
Returns: Introspector - the Introspector for this template

template.getFactory() ⇒ Factory

Provides access to the Factory for this template. The Factory is used to create the types defined in this template.

Kind: instance method of Template
Returns: Factory - the Factory for this template

template.getSerializer() ⇒ Serializer

Provides access to the Serializer for this template. The Serializer is used to serialize instances of the types defined within this template.

Kind: instance method of Template
Returns: Serializer - the Serializer for this template

template.getRequestTypes() ⇒ Array

Provides a list of the input types that are accepted by this Template. Types use the fully-qualified form.

Kind: instance method of Template
Returns: Array - a list of the request types

template.getResponseTypes() ⇒ Array

Provides a list of the response types that are returned by this Template. Types use the fully-qualified form.

Kind: instance method of Template
Returns: Array - a list of the response types

template.getEmitTypes() ⇒ Array

Provides a list of the emit types that are emitted by this Template. Types use the fully-qualified form.

Kind: instance method of Template
Returns: Array - a list of the emit types

template.getStateTypes() ⇒ Array

Provides a list of the state types that are expected by this Template. Types use the fully-qualified form.

Kind: instance method of Template
Returns: Array - a list of the state types

template.hasLogic() ⇒ boolean

Returns true if the template has logic, i.e. has more than one script file.

Kind: instance method of Template
Returns: boolean - true if the template has logic

Template.fromDirectory(path, [options]) ⇒ Promise.<Template>

Builds a Template from the contents of a directory. The directory must include a package.json in the root (used to specify the name, version and description of the template).

Kind: static method of Template
Returns: Promise.<Template> - a Promise to the instantiated template

ParamTypeDefaultDescription
pathStringto a local directory
[options]Object
an optional set of options to configure the instance.

Template.fromArchive(buffer, [options]) ⇒ Promise.<Template>

Create a template from an archive.

Kind: static method of Template
Returns: Promise.<Template> - a Promise to the template

ParamTypeDefaultDescription
bufferBufferthe buffer to a Cicero Template Archive (cta) file
[options]Object
an optional set of options to configure the instance.

Template.fromUrl(url, [options]) ⇒ Promise

Create a template from an URL.

Kind: static method of Template
Returns: Promise - a Promise to the template

ParamTypeDefaultDescription
urlStringthe URL to a Cicero Template Archive (cta) file
[options]Object
an optional set of options to configure the instance.

Template.instanceOf(classDeclaration, fqt) ⇒ boolean

Check to see if a ClassDeclaration is an instance of the specified fully qualified type name.

Kind: static method of Template
Returns: boolean - True if classDeclaration an instance of the specified fully qualified type name, false otherwise.
Internal:

ParamTypeDescription
classDeclarationClassDeclarationThe class to test
fqtStringThe fully qualified type name.

TemplateInstance

A TemplateInstance is an instance of a Clause or Contract template. It is executable business logic, linked to a natural language (legally enforceable) template. A TemplateInstance must be constructed with a template and then prior to execution the data for the clause must be set. Set the data for the TemplateInstance by either calling the setData method or by calling the parse method and passing in natural language text that conforms to the template grammar.

Kind: global abstract class
Access: public

new TemplateInstance(template)

Create the Clause and link it to a Template.

ParamTypeDescription
templateTemplatethe template for the clause

templateInstance.setData(data)

Set the data for the clause

Kind: instance method of TemplateInstance

ParamTypeDescription
dataobjectthe data for the clause, must be an instance of the template model for the clause's template. This should be a plain JS object and will be deserialized and validated into the Concerto object before assignment.

templateInstance.getData() ⇒ object

Get the data for the clause. This is a plain JS object. To retrieve the Concerto object call getConcertoData().

Kind: instance method of TemplateInstance
Returns: object - - the data for the clause, or null if it has not been set

templateInstance.getEngine() ⇒ object

Get the current Ergo engine

Kind: instance method of TemplateInstance
Returns: object - - the data for the clause, or null if it has not been set

templateInstance.getDataAsConcertoObject() ⇒ object

Get the data for the clause. This is a Concerto object. To retrieve the plain JS object suitable for serialization call toJSON() and retrieve the data property.

Kind: instance method of TemplateInstance
Returns: object - - the data for the clause, or null if it has not been set

templateInstance.parse(input, [currentTime], [utcOffset], [fileName])

Set the data for the clause by parsing natural language text.

Kind: instance method of TemplateInstance

ParamTypeDescription
inputstringthe text for the clause
[currentTime]stringthe definition of 'now', defaults to current time
[utcOffset]numberUTC Offset for this execution, defaults to local offset
[fileName]stringthe fileName for the text (optional)

templateInstance.draft([options], [currentTime], [utcOffset]) ⇒ string

Generates the natural language text for a contract or clause clause; combining the text from the template and the instance data.

Kind: instance method of TemplateInstance
Returns: string - the natural language text for the contract or clause; created by combining the structure of the template with the JSON data for the clause.

ParamTypeDescription
[options]*text generation options.
[currentTime]stringthe definition of 'now', defaults to current time
[utcOffset]numberUTC Offset for this execution, defaults to local offset

templateInstance.formatCiceroMark(ciceroMarkParsed, options, format) ⇒ string

Format CiceroMark

Kind: instance method of TemplateInstance
Returns: string - the result of parsing and printing back the text

ParamTypeDescription
ciceroMarkParsedobjectthe parsed CiceroMark DOM
optionsobjectparameters to the formatting
formatstringto the text generation

templateInstance.getIdentifier() ⇒ String

Returns the identifier for this clause. The identifier is the identifier of the template plus '-' plus a hash of the data for the clause (if set).

Kind: instance method of TemplateInstance
Returns: String - the identifier of this clause

templateInstance.getTemplate() ⇒ Template

Returns the template for this clause

Kind: instance method of TemplateInstance
Returns: Template - the template for this clause

templateInstance.getLogicManager() ⇒ LogicManager

Returns the template logic for this clause

Kind: instance method of TemplateInstance
Returns: LogicManager - the template for this clause

templateInstance.toJSON() ⇒ object

Returns a JSON representation of the clause

Kind: instance method of TemplateInstance
Returns: object - the JS object for serialization

TemplateInstance.ciceroFormulaEval(logicManager, clauseId, ergoEngine, name) ⇒ *

Constructs a function for formula evaluation based for this template instance

Kind: static method of TemplateInstance
Returns: * - A function from formula code + input data to result

ParamTypeDescription
logicManager*the logic manager
clauseIdstringthis instance identifier
ergoEngine*the evaluation engine
namestringthe name of the formula

TemplateInstance.rebuildParser(parserManager, logicManager, ergoEngine, templateName, grammar)

Utility to rebuild a parser when the grammar changes

Kind: static method of TemplateInstance

ParamTypeDescription
parserManager*the parser manager
logicManager*the logic manager
ergoEngine*the evaluation engine
templateNamestringthis template name
grammarstringthe new grammar

CompositeArchiveLoader

Manages a set of archive loaders, delegating to the first archive loader that accepts a URL.

Kind: global class

new CompositeArchiveLoader()

Create the CompositeArchiveLoader. Used to delegate to a set of ArchiveLoaders.

compositeArchiveLoader.addArchiveLoader(archiveLoader)

Adds a ArchiveLoader implementation to the ArchiveLoader

Kind: instance method of CompositeArchiveLoader

ParamTypeDescription
archiveLoaderArchiveLoaderThe archive to add to the CompositeArchiveLoader

compositeArchiveLoader.clearArchiveLoaders()

Remove all registered ArchiveLoaders

Kind: instance method of CompositeArchiveLoader

compositeArchiveLoader.accepts(url) ⇒ boolean

Returns true if this ArchiveLoader can process the URL

Kind: instance abstract method of CompositeArchiveLoader
Returns: boolean - true if this ArchiveLoader accepts the URL

ParamTypeDescription
urlstringthe URL

compositeArchiveLoader.load(url, options) ⇒ Promise

Load a Archive from a URL and return it

Kind: instance method of CompositeArchiveLoader
Returns: Promise - a promise to the Archive

ParamTypeDescription
urlstringthe url to get
optionsobjectadditional options

isPNG(buffer) ⇒ Boolean

Checks whether the file is PNG

Kind: global function
Returns: Boolean - whether the file in PNG

ParamTypeDescription
bufferBufferbuffer of the file

getMimeType(buffer) ⇒ Object

Returns the mime-type of the file

Kind: global function
Returns: Object - the mime-type of the file

ParamTypeDescription
bufferBufferbuffer of the file