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);
async RealEstate.calculate(payload)

Performs scope 3 Real estate emission calculations by making a POST request to the real estate 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": "Commercial Real Estate:Industrial distribution warehouse",
     "value": 17000.123,
     "unit": "m2"
   },
   "includeDetails": false
 };
const result = await calculate(request);
async EconomicActivity.calculate(payload)

Performs scope 3 Spend based emission calculations by making a POST request to the economic activity 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": "accomodation",
     "value": 1500.12,
     "unit": "usd"
   },
   "includeDetails": false
 };
const result = await calculate(request);

Global Metadata API

The global Metadata API provides a unified way to query metadata across different endpoints without calling endpoint-specific methods.

  • getTypes/postTypes and getArea/postArea: Accept an optional endpoint parameter to query metadata for specific endpoints

  • getUnits/postUnits: Accept an optional type parameter to query units for specific emission types

Supported endpoints (for getTypes/postTypes and getArea/postArea): calculation, location, stationary, mobile, fugitive, factor, search, transportation-and-distribution, economic-activity, real-estate

getTypes

async Metadata.getTypes(endpoint)

Retrieves available emission source types for a specific endpoint using GET request.

Arguments:
  • endpoint (string) – The endpoint name to retrieve types for. Defaults to ‘calculation’ if not provided.

Returns:

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

Example

// Get types for calculation endpoint (default)
const types = await getTypes();

// Get types for a specific endpoint
const locationTypes = await getTypes('location');
async Metadata.postTypes(endpoint)

Retrieves available emission source types for a specific endpoint using POST request.

Arguments:
  • endpoint (string) – The endpoint name to retrieve types for. Defaults to ‘calculation’ if not provided.

Returns:

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

Example

// Get types for calculation endpoint (default)
const types = await postTypes();

// Get types for a specific endpoint
const stationaryTypes = await postTypes('stationary');

getArea

async Metadata.getArea(endpoint)

Retrieves available geographic locations for a specific endpoint using GET request.

Arguments:
  • endpoint (string) – The endpoint name to retrieve locations for. Defaults to ‘calculation’ if not provided.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the available locations

Example

// Get areas for calculation endpoint (default)
const areas = await getArea();

// Get areas for a specific endpoint
const mobileAreas = await getArea('mobile');
async Metadata.postArea(endpoint)

Retrieves available geographic locations for a specific endpoint using POST request.

Arguments:
  • endpoint (string) – The endpoint name to retrieve locations for. Defaults to ‘calculation’ if not provided.

Returns:

Promise<AreaResponse> – A promise that resolves to an AreaResponse containing the available locations

Example

// Get areas for calculation endpoint (default)
const areas = await postArea();

// Get areas for a specific endpoint
const fugitiveAreas = await postArea('fugitive');

getUnits

async Metadata.getUnits(type)

Retrieves available measurement units for a specific type using GET request.

Arguments:
  • type (string) – The emission source type to retrieve units for. If not provided, returns the full UOM table.

Returns:

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

Example

// Get all units
const allUnits = await getUnits();

// Get units for a specific type
const naturalGasUnits = await getUnits('Natural Gas');
async Metadata.postUnits(type)

Retrieves available measurement units for a specific type using POST request.

Arguments:
  • type (string) – The emission source type to retrieve units for. If not provided, returns the full UOM table.

Returns:

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

Example

// Get all units
const allUnits = await postUnits();

// Get units for a specific type
const jetKeroseneUnits = await postUnits('Jet Kerosene');

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