1.0.0 • Published 5 months ago

@decisionrules/decisionrules v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

DecisionRules

Jest CI

Decisionrules.io library that allows you to integrate DecisionRules Solver, Management and Business Intelligence API to you application as easily as possible.

Table of contents

  1. Instalation
  2. Usage and examples
  3. API

Instalation

npm i @decisionrules/decisionrules

Usage and example

You can start using library by defining DecisionRules instance and providing valid DecisionRulesOptions.

Init example

import DecisionRules from "@decisionrules/decisionrules"

const opt = {
  solverKey: "solver_key_string",
  managementKey: "_management_key_string",
  businessIntKey: "business-intelligence_key_string",
  host: HostEnum | "domain",
  bi_host: HostEnum | "bi_domain"
};

const dr = new DecisionRules(opt);

Solver API call example

Calls can be done with solve method on DecisionRules class that returns a Promise.

const solverOpt = {
  cols: {
    includedConditionCols: ["c1", "c2"],
    excludedConditionCols: ["c3", "c4"]
  },
  debug: false,
  corrId: "mycorrId",
  strategy: STANDARD,
  audit: true,
  auditTtl: "14"
}

const result = await dr.solve(ruleId, version, solverOpt);

Management API example

Management API can be used through management object on DecisionRules class. All methods return a Promise

const rule = await dr.management.getRule(ruleId, version);

Business Intelligence API exapmle

const auditLogsOptions = {
  page: "10",
  page_size: "5",
  limit: "10",
  corrIds: ["mycorId"],
  rules: ["myruleId"],
  solver_keys: ["1234abcd],
  tags: ["t1",t2],
  date_gte: "2023-02",
  date_lte: "2023-02",
  order: "asc",
  include_debug: "false,
  status_code: "200"
}

const logs = await dr.bi.getAuditLogs(auditLogsOptions);

API

All methods described below are exposed on DecisionRules class.

Methods throws DecisionRulesErrorException if something went wrong down on API call or general Error class if library encountered some sort of error.

Solver API

DecisionRules.solve

const result = await dr.solve(ruleId, version, options);
// => Promise<any>

Arguments:

argtypeoptional
ruleIdstringno
versionstringyes
optionsSolverOptionsyes

SolverOptions

Object that defines solver behavior if needed.

argstypeoptional
debugbooleanyes
corrIdstringyes
strategystringyes
auditstringyes
auditTtlstringyes
colsobjectyes
cols.includedConditionColsstring[]yes
cols.excludedConditionColsstring[]yes

Management API

DecisionRules.management.getRule

Gets all of the infromation stored about the rule, including its content, version or input and output schemas. If the version is specified, gets the version irrespective of the rule status. If the version is not specified, gets the latest published version.

const result = await dr.management.getRule(ruleId, version);
// => Promise<any>

Arguments:

argstypeoptional
ruleIdstringno
versionstringyes

DecisionRules.management.updateRuleStatus

Changes rule status from pending to published and vice versa. If the version is not specified, the latest version will be used.

const result = await dr.management.updateRuleStatus(ruleId, status, version)
// => Promise<any>
argstypeoptional
ruleIdstringno
statusstringno
versionstringyes

DecisionRules.management.updateRule

Changes the rule according to the body of the request.

Note that there are a few attributes of the rule that cannot be updated by the PUT endpoint. Namely, you cannot use PUT to change the rule ID, version and rule alias. Also, you cannot change the date of last update, since it gets updated automatically.

const result = await dr.management.updateRule(ruleId, rule, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
ruleanyno
versionstringyes

DecisionRules.management.createRule

Creates rule based on the body of the request. The body must be formatted according to the example below.

const result = await dr.management.createRule(rule);
// => Promise<any>
argstypeoptional
ruleanyno

DecisionRules.management.deleteRule

Deletes the rule.

const result = await dr.management.deleteRule(ruleId, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
versionstringyes

DecisionRules.management.getRulesForSpace

Gets all types of rules and ruleflows in space

The desired space is determined by Management API Key. This endpoint also gets set of rules used in every ruleflow.

const result = await dr.management.getRulesForSpace();
// => Promise<any>

DecisionRules.management.getTags

This method allows you to get all rules/rule flows with certain tags. Desired space is derived from Management API Key.

const result = await dr.management.getTags(tags);
// => Promise<any>
argstypeoptional
tagsstring[]no

DecisionRules.management.updateTags

If you specify the version, the tag/tags will be added to the specified version. If the version is not specified, the tag/tags will be added to all the versions with given ID.

const result = await dr.management.updateTags(ruleId, tags, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
tagsanyno
versionstringyes

DecisionRules.management.deleteTags

If you specify the version, the tag/tags will be deleted from the specified version. If the version is not specified, the tag/tags will be deleted from all the versions with given ID.

const result = await dr.management.deleteTags(ruleId, tags, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
tagsstring[]no
versionstringyes

DecisionRules.management.exportFolder

Export folder with all rules. If no nodeId is set, then will be exported root directory.

const result = await dr.management.exportFolder(nodeId);
// => Promise<any>
argstypeoptional
nodeIdstringno

DecisionRules.management.importFolder

Import folder with all rules into specific folder. If no targetNodeId is set, then will be imported into root directory.

const result = await dr.management.importFolder(targetNodeId);
// => Promise<any>
argstypeoptional
targetNodeIdstringno
dataanyno

DecisionRules.management.findDuplicates

Look for decision table by id and optionally version. If the decision table is found, it is returned together with an array of duplicates.

const result = await dr.management.findDuplicates(ruleId, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
versionstringyes

DecisionRules.management.findDependencies

Look for dependencies by id or alias and optionally version. If the rule is found, it is returned together with an array of dependencies.

const result = await dr.management.findDependencies(ruleId, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
versionstringyes

DecisionRules.management.lockRule

Locks rule for editation. For input data refer to our docs.

const result = await dr.management.lockRule(ruleId, data, version);
// => Promise<any>
argstypeoptional
ruleIdstringno
dataanyno
versionstringyes

Business Intelligence API

DecisionRules.bi.getAuditLogs

This function allows you to fetch audit logs from your rule solver, including metadata of the solver run as well as the input and output data.

const result = await dr.bi.getAuditLogs(auditLogsOpt);
// => Promise<any>
argstypeoptional
auditLogsOptDecisionRulesAuditOptno

DecisionRules.bi.deleteAuditLogs

This function allows you to delete audit logs from the database when you no longer need them.

Not all atributes from DecisionRulesAuditOpt are valid for deleting audit logs. Please refer to our docs for more info.

const result = await dr.bi.deleteAuditLogs(auditLogsOpt);
// => Promise<any>
argstypeoptional
auditLogsOptDecisionRulesAuditOptno

DecisionRulesAuditOpt

Object that defined business intelligence query behavior.

argstypeoptional
pagestringyes
page_sizestringyes
limitstringyes
corrIdsstring[]yes
rulesstring[]yes
solver_keysstring[]yes
tagsstring[]yes
date_gtestringyes
date_ltestringyes
orderstringyes
include_debugstringyes
status_codestringyes
1.0.0

5 months ago