Reference

class Client(token, config, isUserProvidedToken=false)

exported from Client

Arguments:
  • token (string)

  • config (ClientConfig)

  • isUserProvidedToken (boolean)

Client.getAuthHeader()

Returns the authorization header object with the Bearer token.

Returns:

Record<string, string> – An object containing the Authorization header with the Bearer token

Example

const client = Client.getInstance();
const headers = {
  'Content-Type': 'application/json',
  ...client.getAuthHeader()
};
// headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer token...' }
Client.getClientId()

Returns the client ID configured for this client instance.

Returns:

string – The client ID string

Example

const client = Client.getInstance();
const clientId = client.getClientId();
console.log(clientId); // e.g., 'client123'
Client.getClientSource()

Returns the client source identifier for this client instance.

Returns:

string – The client source string

Example

const client = Client.getInstance();
const source = client.getClientSource();
console.log(source); // e.g., 'web', 'mobile', 'sdk'
Client.getDomain()

Returns the domain URL configured for the client.

Returns:

string – The domain URL string

Example

const client = Client.getInstance();
const apiDomain = client.getDomain();
console.log(apiDomain); // e.g., 'https://api.example.com'
async Client.refreshToken()

Refreshes the authentication token if it’s about to expire. Only refreshes if the token was not provided by the user and is expiring within 60 seconds.

Returns:

Promise<void> – A promise that resolves when the token refresh is complete

Example

const client = Client.getInstance();
// Ensure token is fresh before making API requests
await client.refreshToken();
// Proceed with API requests...
static async Client.getClient(config)

Initializes and returns a Client instance with the provided configuration.

Arguments:
  • config (ClientConfig) – The client configuration object

Returns:

Promise<void> – A promise that resolves when the client is initialized

Example

// Initialize with authentication URL
await Client.getClient({
  host: 'https://api.example.com',
  authUrl: 'https://auth.example.com',
  clientId: 'client123',
  orgId: 'org456'
});

// Initialize with existing token
await Client.getClient({
  token: 'existing-jwt-token',
  clientId: 'client123'
});

// Initialize with API key
await Client.getClient({
  apiKey: 'your-api-key',
  clientId: 'client123',
  orgId: 'org456'
});
static Client.getInstance()

Returns the singleton instance of the Client.

Returns:

Client – The singleton Client instance

Example

// First initialize the client
await Client.getClient({
  clientId: 'client123',
  orgId: 'org456'
});

// Then get the instance
const client = Client.getInstance();
// Use the client...
async request.makeApiRequest<T>(config)

Makes an API request with standardized headers and token refresh.

Type parameters:

T – The expected response data type

Arguments:
  • config (RequestConfig) – The request configuration including method, URL, data, params, and optional headers

Returns:

Promise<T> – A promise that resolves to the response data of type T

Example

interface UserData {
  id: string;
  name: string;
  email: string;
}

const userData = await makeApiRequest<UserData>({
  method: 'GET',
  url: 'https://api.example.com/users/123',
  headers: { 'X-Custom-Header': 'value' }
});
console.log(userData.name); // Typed access to the response data
utils.findExpiryTime(token)

Extracts the expiration time from a JWT token and give the token expiry time.

Arguments:
  • token (string) – The JWT token to extract the expiration time from

Returns:

any – The expiration time value from the token’s payload

Example

const jwtToken = 'your-token';
const expiryTime = findExpiryTime(jwtToken);
console.log(new Date(expiryTime * 1000).toISOString()); // Convert to date if it's a Unix timestamp

API

async Factor.retrieveFactor(payload)

Retrieves a factor details by making a POST request to the factor API endpoint.

Arguments:
  • payload (FactorRequest) – The factor request data to be sent to the API

Returns:

Promise<FactorResponse> – A promise that resolves to the FactorResponse returned by the API

Example

const factorRequest = {
   "activity": {
     "factorId": 12345
   }
 };

 OR

 const factorRequest = {
   "time" : {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa",
     "stateProvince": "new york"
   },
   "activity": {
     "type":"natural gas"
   },
   "includeDetails": true
 };
const factor = await retrieveFactor(factorRequest);
async Fugitive.calculate(payload)

Performs scope 1 fugitve emission calculations by making a POST request to the fugitive API endpoint.

Arguments:
  • payload (CommonRequest) – The request data to be sent to the API

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const request = {
   "time": {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa"
   },
   "activity": {
     "type": "R134A",
     "value": 150,
     "unit": "kg"
   },
   "includeDetails": false
 };
const result = await calculate(request);
async Calculation.calculate(payload)

Performs emission calculations by making a POST request to the generic calculation API endpoint.

Arguments:
  • payload (CalculationRequest) – The calculation request data to be sent to the API

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const calculationRequest = {
   "time" : {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa",
     "stateProvince": "new york"
   },
   "activity": {
     "type":"Waste Combusted - Steel Cans:Default factor",
     "unit": "kg",
     "value": 1223123.121
   },
   "includeDetails": true
 };
const result = await calculate(calculationRequest);
async Location.calculate(payload)

Performs scope 2 purchased energy Emission calculations by making a POST request to the location API endpoint.

Arguments:
  • payload (LocationRequest) – The location request data to be sent to the API

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const calculationRequest = {
   "time" : {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa",
     "stateProvince": "new york"
   },
   "activity": {
     "type":"electricity",
     "unit": "kwh",
     "value": 14123143
   },
   "includeDetails": true
 };
const result = await calculate(calculationRequest);
async Mobile.calculate(payload)

Performs Scope 1 mobile emissions related calculations by making a POST request to the mobile API endpoint.

Arguments:
  • payload (CommonRequest) – The request data to be sent to the mobile API

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const request = {
   "time": {
     "date": "2022-01-01"
   },
   "location": {
     "country": "USA",
     "stateProvince": "new york"
   },
   "activity": {
     "type": "Diesel Fuel",
     "value": 1500000,
     "unit": "l"
   },
   "includeDetails": false
 };
const result = await calculate(request);
async Stationary.calculate(payload)

Performs Scope 1 stationary calculations by making a POST request to the stationary API endpoint.

Arguments:
  • payload (CommonRequest) – The request data to be sent to the stationary API

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const request = {
   "time" : {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa",
     "stateProvince": "new york"
   },
   "activity": {
     "type":"Coal - Lignite",
     "unit": "KJ",
     "value": 3
   },
   "includeDetails": true
 };
const result = await calculate(request);
async TransportationAndDistribution.calculate(payload)

Performs Scope 3 transportation and distribution emission calculations by making a POST request to the transportation and distribution API endpoint.

Arguments:
  • payload (CalculationRequest) – The calculation request data for transportation and distribution operations

Returns:

Promise<EmissionResponse | EmissionResponseWithDetails> – A promise that resolves to the emission calculation result. Returns EmissionResponseWithDetails if includeDetails is true, otherwise EmissionResponse

Example

const request = {
   "time" : {
     "date": "2025-01-04"
   },
   "location": {
     "country": "usa"
   },
   "activity": {
     "type": "Freight - Cargo Ship - Bulk Carrier - 0-9999 dwt",
     "unit": ["t","km"],
     "value": [1.0,1.0]
   },
   "includeDetails": true
 };
const result = await calculate(request);

Metadata APIs

getTypes

async Factor.getTypes()

Retrieves available emission factor types by making a GET request to the API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available emission factor types

Example

const types = await getTypes();
async Calculation.getTypes()

Retrieves available calculation types by making a GET request to the calculation types API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available calculation types

Example

const types = await getTypes();
async Location.getTypes()

Retrieves available location-based calculation types by making a GET request to the location types API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available location-based calculation types

Example

const types = await getTypes();
async Mobile.getTypes()

Retrieves available mobile emission calculation types by making a GET request to the API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available mobile emission types

Example

// Get all available mobile emission types
const types = await getTypes();
async Stationary.getTypes()

Retrieves available stationary emission calculation types by making a GET request to the API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available stationary emission types

Example

const types = await getTypes();
async TransportationAndDistribution.getTypes()

Retrieves available transportation and distribution calculation types by making a GET request to the API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available transportation and distribution calculation types

Example

const types = await getTypes();
async Fugitive.getTypes()

Retrieves available fugitive emission calculation types by making a GET request to the API endpoint.

Returns:

Promise<TypeResponse> – A promise that resolves to a TypeResponse containing the available fugitive emission types

Example

const types = await getTypes();

getArea

async Factor.getArea()

Retrieves information about geographical areas supported by the factor API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async Factor.getSearchArea()

Retrieves information about geographical areas supported by the factor search API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getSearchArea();
async Calculation.getArea()

Retrieves information about geographical areas supported by the calculation API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async Location.getArea()

Retrieves information about geographical areas supported by the location-based calculation API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async Mobile.getArea()

Retrieves information about geographical areas supported by the mobile emissions API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async Stationary.getArea()

Retrieves information about geographical areas supported by the stationary emissions API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async TransportationAndDistribution.getArea()

Retrieves information about geographical areas supported by the transportation and distribution API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();
async Fugitive.getArea()

Retrieves information about geographical areas supported by the fugitive emissions API.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the supported geographical areas

Example

const areas = await getArea();

getUnits

async Factor.getUnits(type)

Retrieves available units for a specific emission factor type.

Arguments:
  • type (string) – The emission factor type to get units for (e.g., “Natural Gas - Scope 3:AAA”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

// Get units for the "Natural Gas - Scope 3:AAA" emission factor type with subtype
const units = await getUnits("Natural Gas - Scope 3:AAA");

// Get units for the "HFC-263fb" emission factor type without subtype
const units = await getUnits("HFC-263fb");
async Calculation.getUnits(type)

Retrieves available units for a specific calculation type.

Arguments:
  • type (string) – The calculation type to get units for

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

// Get units for the "Natural Gas - Scope 3:AAA" emission calculation type with subtype
const units = await getUnits("Natural Gas - Scope 3:AAA");

// Get units for the "HFC-263fb" emission calculation type without subtype
const units = await getUnits("HFC-263fb");
async Location.getUnits(type)

Retrieves available units for a specific location-based calculation type.

Arguments:
  • type (string) – The location-based calculation type to get units for (e.g., “electricity”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

// Get units for the "electricity" location type
const units = await getUnits("electricity");
async Mobile.getUnits(type)

Retrieves available units for a specific mobile emission type.

Arguments:
  • type (string) – The mobile emission type to get units for (e.g., “Diesel Fuel”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

Get units for the "Cars:B20:(NE)" emission mobile type with subtype
const units = await getUnits("Cars:B20:(NE)");

Get units for the "Cars by Size - Large Car - Hybrid" emission mobile type without subtype
const units = await getUnits("Cars by Size - Large Car - Hybrid");
async Stationary.getUnits(type)

Retrieves available units for a specific stationary emission type.

Arguments:
  • type (string) – The stationary emission type to get units for (e.g., “Coal - Lignite”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

Get units for the "Petroleum Based Greases - NC:A" emission stationary type with subtype
const units = await getUnits("Petroleum Based Greases - NC:A");

Get units for the "Jet Kerosene" emission stationary type without subtype
const units = await getUnits("Jet Kerosene");
async TransportationAndDistribution.getUnits(type)

Retrieves available units for a specific transportation and distribution calculation type.

Arguments:
  • type (string) – The transportation and distribution calculation type to get units for (e.g., “Freight - Cargo Ship”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

// Get units for the "Business Travel - Cars:Diesel - Small" transportation and distribution type without subtype
const units = await getUnits("Business Travel - Cars:Diesel - Small");

// Get units for the "Business Travel - Cars" transportation and distribution type with subtype
const units = await getUnits("Business Travel - Cars");
async Fugitive.getUnits(type)

Retrieves available units for a specific fugitive emission type.

Arguments:
  • type (string) – The fugitive emission type to get units for (e.g., “R134A”)

Returns:

Promise<UnitResponse> – A promise that resolves to a UnitResponse containing the available units

Example

// Get units for the "Natural Gas - Scope 3:AAA" emission fugitive type with subtype
const units = await getUnits("Natural Gas - Scope 3:AAA");

// Get units for the "R-426A" emission fugitive type without subtype
const units = await getUnits("R-426A");

Usage API

async Usage.getUsage(history=false)

Retrieves current billing period or historical usage data for the user by making a GET request to the API endpoint.

Arguments:
  • history (boolean) – Flag to retrieve current billing or historical usage data.

Returns:

Promise<UsageResponse> – A promise that resolves to a UsageResponse containing the organization’s usage data

Example

const usage = await getUsage();

Interfaces

interface Api.LocationRequestWithoutFactorId

Request parameters for location-based calculations without specifying a factor ID. Used for calculating emissions or other metrics based on location data.

LocationRequestWithoutFactorId

exported from interfaces.Api

interface Api.LocationRequestWithFactorId

Request parameters for location-based calculations with a specific factor ID. Used when the emission factor is already known and doesn’t need to be determined by location.

LocationRequestWithFactorId

exported from interfaces.Api

interface Api.CommonRequestWithoutFactorId

Common request parameters for calculations without specifying a factor ID. Used for general-purpose calculations based on location, time, and activity data.

CommonRequestWithoutFactorId

exported from interfaces.Api

interface Api.CommonRequestWithFactorId

Common request parameters for calculations with a specific factor ID. Used when the emission factor is already known and doesn’t need to be determined by location.

CommonRequestWithFactorId

exported from interfaces.Api

interface Api.GenericCalculationRequestWithoutFactorId

Request parameters for generic calculations without specifying a factor ID. Used for calculations that may involve multiple units or complex activity data.

GenericCalculationRequestWithoutFactorId

exported from interfaces.Api

interface Api.GenericCalculationRequestWithFactorId

Request parameters for generic calculations with a specific factor ID. Used for complex calculations where the emission factor is already known.

GenericCalculationRequestWithFactorId

exported from interfaces.Api

interface Api.FactorRequestWithoutFactorId

Request parameters for retrieving factor information without specifying a factor ID. Used to look up appropriate emission factors based on location, time, and activity type.

FactorRequestWithoutFactorId

exported from interfaces.Api

interface Api.FactorRequestWithFactorId

Request parameters for retrieving specific factor information by ID. Used when the exact factor to retrieve is already known.

FactorRequestWithFactorId

exported from interfaces.Api

interface Api.SearchRequest

Request parameters for searching factors or activities. Used to find relevant factors or activities based on location, time, and search criteria.

SearchRequest

exported from interfaces.Api

interface common.Location
Represents a geographical location.

Location

exported from interfaces.common

interface common.Time
Represents a point in time with date information.

Time

exported from interfaces.common

interface common.Activity
Represents an activity with type, value, and unit of measurement.

Activity

exported from interfaces.common

interface common.ActivityWithFactorId
Represents an activity identified by a factor ID instead of a type.

ActivityWithFactorId

exported from interfaces.common

interface common.CombinedUnitsActivity
Represents an activity that can have single or multiple values and units.

CombinedUnitsActivity

exported from interfaces.common

interface common.CombinedUnitsActivityWithFactorId
Represents an activity with factor ID that can have single or multiple values and units.

CombinedUnitsActivityWithFactorId

exported from interfaces.common

interface common.FactorActivity
Represents a factor activity with a type and optional unit.

FactorActivity

exported from interfaces.common

interface common.FactorActivityWithFactorId
Represents a factor activity identified by a factor ID instead of a type.

FactorActivityWithFactorId

exported from interfaces.common

interface common.SearchActivity
Represents a search query for activities.

SearchActivity

exported from interfaces.common

interface common.Pagination
Represents pagination parameters for paginated results.

Pagination

exported from interfaces.common

interface Config.RequestConfig
Configuration for making HTTP requests.

RequestConfig

exported from interfaces.Config

interface Config.ClientConfig
Configuration for initializing a client instance.

ClientConfig

exported from interfaces.Config