0.0.3 • Published 11 months ago

@dotinc/brease-sdk v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

BreaseSDK Typescript SDK 1.0.0

The Typescript SDK for BreaseSDK.

  • API version: 1.0.0
  • SDK version: 1.0.0

Table of Contents

About the API

Business rule engine as a service

Installation

npm install brease-sdk  

Authentication

To see whether an endpoint needs a specific type of authentication check the endpoint's documentation.

Bearer Authentication with Refresh Tokens

The BreaseSDK API uses bearer tokens for authentication, but these bearer tokens have a short expiration time. Refresh tokens have longer duration, and they have the ability to obtain new bearer tokens. The bearer and refresh token can be set when initializing the SDK like this:

sdk = new BreaseSDK('YOUR_REFRESH_TOKEN', 'YOUR_BEARER_TOKEN')

Or at a later stage:

sdk = new BreaseSDK()
sdk.setBearerToken('YOUR_BEARER_TOKEN');
sdk.setRefreshToken('YOUR_REFRESH_TOKEN');

After the refresh token has been set, the SDK will automatically refresh the bearer token when needed.

Sample Usage

Here is a simple program demonstrating usage of this SDK. It is also available in the sample.js file in this directory.

import { BreaseSDK } from './src';


const sdk = new BreaseSDK();

(async () => {
  const result = await sdk.Context
    .getAllRules('sit eu');
  console.log(result);
})();
 

Environments

Here is the list of all available environments:

DEFAULT = 'https://api.brease.run',
PRODUCTION = 'https://api.brease.run',
SANDBOX = 'https://api-sandbox.brease.run',
LOCAL = 'http://localhost:4400'

How to set the environment:

const sdk = new BreaseSDK();
sdk.setEnvironment(Environment.DEFAULT);

BreaseSDK Services

A list of all services and services methods.

Auth

MethodDescription
refreshToken
getToken

Context

MethodDescription
evaluateRules
getAllRules
addRule
removeRule
replaceRule

All Methods

refreshToken

  • HTTP Method: POST
  • Endpoint: /refreshToken

Required Parameters

| input | object | Request body. |

Return Type

TokenPair

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = { refreshToken: 'consequat ullamco fugiat in qui', tempor_6: false };
  const result = await sdk.Auth.refreshToken(input);
  console.log(result);
})();

getToken

  • HTTP Method: POST
  • Endpoint: /token

Return Type

TokenPair

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const result = await sdk.Auth.getToken();
  console.log(result);
})();

evaluateRules

  • HTTP Method: POST
  • Endpoint: /{contextID}/evaluate

Required Parameters

NameTypeDescription
contextIdstring
inputobjectRequest body.

Optional Parameters

Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'}

NameTypeDescription

Return Type

ApiEvaluateRulesResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = {
    object: { culpa_2: 6295902.049742624, minim46f: -88004539, ullamco3c9: 76261108.73322713 },
    overrideCode: 'pariatur deserunt',
    overrideRules: [
      { ad97f: -53863233, nisi_7: 91986864.75789964, voluptate_cd: true },
      { ad_b: -59749957, Lorem2c: 83969542 },
    ],
  };
  const result = await sdk.Context.evaluateRules(input, 'tempor nulla do');
  console.log(result);
})();

getAllRules

  • HTTP Method: GET
  • Endpoint: /{contextID}/rules

Required Parameters

NameTypeDescription
contextIdstring

Optional Parameters

Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'}

NameTypeDescription
compileCodeboolean

Return Type

ApiAllRulesResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const result = await sdk.Context.getAllRules('labore', { compileCode: true });
  console.log(result);
})();

addRule

  • HTTP Method: POST
  • Endpoint: /{contextID}/rules/add

Required Parameters

NameTypeDescription
contextIdstring
inputobjectRequest body.

Optional Parameters

Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'}

NameTypeDescription

Return Type

ApiAddRuleResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = {
    non_8: -34219647.53904709,
    nostrud343: 44759955.66098803,
    nulla_0: 'enim',
    rule: { in_b31: -6948673.539965317, pariatur_bd: 'exercitation' },
  };
  const result = await sdk.Context.addRule(input, 'adipisicing fugiat sed');
  console.log(result);
})();

removeRule

  • HTTP Method: DELETE
  • Endpoint: /{contextID}/rules/{id}

Required Parameters

NameTypeDescription
contextIdstring
idstring

Optional Parameters

Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'}

NameTypeDescription

Return Type

Returns a dict object.

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const result = await sdk.Context.removeRule(
    'aute dolore quis culpa officia',
    'ad ipsum occaecat nisi Ut',
  );
  console.log(result);
})();

replaceRule

  • HTTP Method: PUT
  • Endpoint: /{contextID}/rules/{id}

Required Parameters

NameTypeDescription
contextIdstring
idstring
inputobjectRequest body.

Optional Parameters

Optional parameters are passed as part of the last parameter to the method. Ex. {optionalParam1 : 'value1', optionalParam2: 'value2'}

NameTypeDescription

Return Type

ApiReplaceRuleResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = {
    commodod_8: 'id Lorem Excepteur',
    deserunt_a8_: false,
    etdc: true,
    rule: { et47: -45443070, pariatur8: false, qui_65: -12569830 },
    veniam_8: 86406750.67036757,
  };
  const result = await sdk.Context.replaceRule(input, 'et Ut tempor labore', 'pariatur Ut esse');
  console.log(result);
})();
0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago