@brease/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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 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 can also be found in the examples/src/index.ts file in this directory.

When running the sample make sure to use npm install to install all the dependencies.

import { BreaseSDK } from '@brease/sdk';


const sdk = new BreaseSDK();

(async () => {
  const result = await sdk.Context
    .getAllRules('esse');
  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

Method Description
refreshToken
getToken

Context

Method Description
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: 'cillum pariatur nulla Ut' };
  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

Name Type Description
contextId string
input object Request body.

Optional Parameters

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

Name Type Description

Return Type

ApiEvaluateRulesResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = {
    object: {
      description: 'Value of any type, including null',
      nullable: true,
      originalName: 'object',
      modelName: 'Object',
      title: 'Object',
    },
    overrideCode: 'ullamco exercitation quis Duis occaecat',
    overrideRules: [],
  };
  const result = await sdk.Context.evaluateRules(input, 'mollit amet esse in');
  console.log(result);
})();

getAllRules

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

Required Parameters

Name Type Description
contextId string

Optional Parameters

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

Name Type Description
compileCode boolean

Return Type

ApiAllRulesResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

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

addRule

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

Required Parameters

Name Type Description
contextId string
input object Request body.

Optional Parameters

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

Name Type Description

Return Type

ApiAddRuleResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = { rule: {} };
  const result = await sdk.Context.addRule(input, 'pariatur incididunt proident');
  console.log(result);
})();

removeRule

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

Required Parameters

Name Type Description
contextId string
id string

Optional Parameters

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

Name Type Description

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('in elit in', 'culpa sunt');
  console.log(result);
})();

replaceRule

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

Required Parameters

Name Type Description
contextId string
id string
input object Request body.

Optional Parameters

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

Name Type Description

Return Type

ApiReplaceRuleResponse

Example Usage Code Snippet

import { BreaseSDK } from './src';

const sdk = new BreaseSDK();

(async () => {
  const input = { rule: {} };
  const result = await sdk.Context.replaceRule(input, 'incididunt', 'ex nulla anim qui Ut');
  console.log(result);
})();

Readme

Keywords

none

Package Sidebar

Install

npm i @brease/sdk

Weekly Downloads

1

Version

0.0.3

License

none

Unpacked Size

464 kB

Total Files

940

Last publish

Collaborators

  • nadilas