3.2.1 • Published 2 months ago

@genability/api v3.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Genability Javascript SDK

This SDK enables faster integration of the Genability APIs into your Node.js, React, Angular, Web Browser and other Javascript compatible applications.

Node.js CI

Table of Contents

  1. Genability API credentials
  2. Basic web front end use
  3. Basic npm usage
  4. NodeJS backend proxy example
  5. Maven Plugin for NodeJS
  6. API usage

Genability API Credentials

If you don't have one already, you'll need a Genability account, as well an App ID and App Key, before you get started.

Integrations

Basic web front end use:

Include the library with a script tag:

<script src="/@genability/api/dist/main.js"></script>

Instantiate Genability API Client

For frontend use, the API client will send requests to the url specified in the proxy option. Your backend proxy must provide Genability API credentials and forward the request to https://api.genability.com. Do not include your Genability API credentials in user-facing frontend code.

const GenAPIClient = Genability.Client.configure({ proxy: '/genability-api' });

Instantiate a request object

const territoriesRequest = new Genability.restApis.GetTerritoriesRequest();
territoriesRequest.masterTariffId = '522';

Call the API method

GenAPIClient.territories.getTerritories(territoriesRequest);

Basic npm usage

Prerequisites: Node.js (^10.12.0, or >=12.0.0) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)

You can install genability sdk using npm:

$ npm install @genability/api --save

Import Genability API client

import { Genability } from '@genability/api';

Instantiate Genability API Client

For frontend use, you must specify a proxy url and provide credentials on the backend..

For backend use in node or other environments, you can provide Genability API credentials to the client in several ways. The client will search for credentials in the following order:

  1. Credentials explicitly provided to the API client
  2. Credentials stored as environment variables GEN_APP_ID and GEN_APP_KEY
  3. Credentials stored in a credentials.json file in the .genability folder in the user's home directory, in this format:
{
  "profileName" : {
    "appId":"", // Your Genability appId,
    "appKey":"" // Your Genability appKey
  }
}

If the API client doesn't find credentials in any of these places, the request will be sent without any credentials.

Instantiate a client, and optionally provide credentials, like this:

const GenAPIClient = Genability.Client.configure({
  profileName: '',// Optionally specify a profile name to use from your 
                  // ~/.genability/credentials.js file
  credentials: {  // Optionally provide credentials explicitly
    appId: '',    // Your Genability App ID
    appKey: '',   // Your Genability App Key
    jwtToken: '', // A JWT token — this can be used to authenticate  requests to a serverless proxy function
    proxyReq: '', // A function used to create an Axios request interceptor for all requests created by 
                  // the API, should requests to a proxy function need to be modified
  }
});

The credentials option also accepts a function which returns an object with the above properties.

Instantiate a request object

import { restApis } from '@genability/api';
const territoriesRequest = new restApis.GetTerritoriesRequest();
territoriesRequest.masterTariffId = '522';

Call the API method

Genability.territories.getTerritories(territoriesRequest);

NodeJS backend proxy example

Include http-proxy-middleware in package.json

Instantiate proxy middleware

const createProxyMiddleware = require('http-proxy-middleware').createProxyMiddleware;

Create ExpressJS Route

const genabilityAuthString = Buffer.from(`yourGenabilityAppId:yourGenabilityAppKey}`).toString('base64');

app.use('/genability-api', createProxyMiddleware({
    target: 'https://api.genability.com',
    changeOrigin: true,
    onProxyReq: function (proxyReq) {
        proxyReq.setHeader('Authorization', 'Basic ' + genabilityAuthString);
    },
    pathRewrite: {
        '^/genability-api': '/',
    },
}));

Maven Plugin for NodeJS

A useful way to use the Genability Javascript SDK in a project with a Java backend is to include the frontend-maven-plugin. This plugin will install NodeJS and NPM and enable running npm install on every build of the Java project.

Include frontend-maven-plugin in pom.xml

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.10.0</version>
    
    <configuration>
      <workingDirectory>src/main/webapp</workingDirectory>
    </configuration>
    
    <executions>
      <execution>
        <id>install node and npm</id>
        <goals>
          <goal>install-node-and-npm</goal>
        </goals>
        <configuration>
          <!-- See https://nodejs.org/en/download/ for latest node and npm (lts) versions -->
          <nodeVersion>v12.18.0</nodeVersion>
          <npmVersion>6.14.4</npmVersion>
        </configuration>
      </execution>
    
      <execution>
        <id>npm install</id>
        <goals>
          <goal>npm</goal>
        </goals>
        <!-- Optional configuration which provides for running any npm command -->
        <configuration>
          <arguments>install</arguments>
        </configuration>
      </execution>
    </executions>
</plugin>

Include package.json

Given the example above you would create your package.json in src/main/webapp.

Map node_modules to static route

The node_modules then need to be mapped to a static file path in your web server. Here is an example mapping using the Spring framework:

<mvc:resources mapping="/static/**" location="/node_modules/" />

The packages in your node_modules will then be available to you in your front end Javascript in the /static path.

API usage

API EndpointRequest Params typeList of params and sample response
properties
getPropertyKeysnew api.GetPropertyKeysRequest()https://developer.genability.com/api-reference/shared-api/property-key/#get-a-list-of-property-keys
getPropertyKeystringhttps://developer.genability.com/api-reference/shared-api/property-key/#get-one-property-key
lses
getLoadServingEntitiesnew api.GetLoadServingEntitiesRequest()https://developer.genability.com/api-reference/tariff-api/load-serving-entity/
getLoadServingEntitynumberhttps://developer.genability.com/api-reference/tariff-api/load-serving-entity/
tariffs
getTariffsnew api.GetTariffsRequest()https://developer.genability.com/api-reference/tariff-api/tariff/#get-a-list-of-tariffs
getTariffnumber, new api.GetTariffsRequest()(optional)https://developer.genability.com/api-reference/tariff-api/tariff/#get-one-tariff
getTariffHistorynumberhttps://developer.genability.com/api-reference/tariff-api/tariff-history/
calculation
runCalculationnew api.GetCalculatedCostRequest()https://developer.genability.com/api-reference/calculation-api/cost-calculation/#run-a-calculation
territories
getTerritoriesnew api.GetTerritoriesRequest()https://developer.genability.com/api-reference/tariff-api/territory/#get-a-list-of-territories
getTerritorynumberhttps://developer.genability.com/api-reference/tariff-api/territory/#get-one-territory
seasons
getSeasonGroupsnew api.GetSeasonGroupsRequest()https://developer.genability.com/api-reference/tariff-api/season/#get-a-list-of-season-groups-for-an-lse
timeofuses
getTimeOfUsenumberhttps://developer.genability.com/api-reference/tariff-api/time-of-use/#get-a-single-time-of-use-definition
getTimeOfUseGroupnumber,numberhttps://developer.genability.com/api-reference/tariff-api/time-of-use/#get-a-time-of-use-group
getTimeOfUseGroupIntervalsnumber,numberhttps://developer.genability.com/api-reference/tariff-api/time-of-use/#get-a-groups-intervals
getTimeOfUseGroupsnumberhttps://developer.genability.com/api-reference/tariff-api/time-of-use/#get-a-tous-intervals
lookups
getLookupValuesnew api.GetLookupsRequest() (optional)https://developer.genability.com/api-reference/tariff-api/lookup/#get-lookup-values
getPropertyLookupValuesstring , new api.GetLookupsRequest() (optional)https://developer.genability.com/api-reference/tariff-api/lookup/#get-property-lookup-values
getPropertyLookupStatsstringhttps://developer.genability.com/api-reference/tariff-api/lookup/#get-property-lookup-stats
typicals
getBaselinesBestnew api.GetBaselinesBestRequest()https://developer.genability.com/api-reference/shared-api/typical-baseline/#get-best-baseline
3.2.2

2 months ago

3.2.1

12 months ago

3.0.4

2 years ago

3.1.0

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago

0.2.10

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.71

3 years ago

0.1.70

3 years ago

0.1.69

3 years ago

0.1.68

3 years ago

0.1.67

3 years ago

0.1.66

3 years ago

0.1.65

3 years ago

0.1.64

3 years ago

0.1.63

3 years ago

0.1.62

3 years ago

0.1.61

3 years ago

0.1.60

3 years ago

0.1.59

3 years ago

0.1.58

3 years ago

0.1.57

3 years ago

0.1.56

3 years ago

0.1.55

3 years ago

0.1.54

3 years ago

0.1.53

3 years ago

0.1.52

3 years ago

0.1.51

3 years ago

0.1.50

3 years ago

0.1.49

3 years ago

0.1.48

3 years ago

0.1.47

3 years ago

0.1.46

3 years ago

0.1.45

3 years ago

0.1.44

3 years ago

0.1.42

3 years ago

0.1.41

3 years ago

0.1.40

4 years ago

0.1.39

4 years ago

0.1.38

4 years ago

0.1.37

4 years ago

0.1.36

4 years ago

0.1.35

4 years ago

0.1.34

4 years ago

0.1.33

4 years ago

0.1.32

4 years ago

0.1.31

4 years ago

0.1.30

4 years ago

0.1.29

4 years ago

0.1.28

4 years ago

0.1.27

4 years ago

0.1.26

4 years ago

0.1.25

4 years ago

0.1.24

4 years ago

0.1.23

4 years ago

0.1.22

4 years ago

0.1.21

4 years ago

0.1.19

4 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago