Skip to content

Functions

This document explains all the functions of eLegere Script.

Abstract

Each function section includes:

  • The syntax of the function.
  • The parameters of the function.
  • What the function returns.

Logging Functions

Logging functions are used to show various notifications to the eLegere user. They can also be used by the designers to debug their application.

logInfo void

Description
1
logInfo(arg: any): void

The function creates a void object. The function shows the object to the user that triggered the script through the info notification.

Parameters

arg

any The value shown the user inside the notification's body. If the value is an object or array, it will be stringified through JSON.stringify().

logError void

Description
1
logError(arg: any): void

The function creates a void object. The function shows the object through an error notification to the user that triggered the script.

Parameters

arg

any The value shown to the user inside the notification's body. If the value is an object or array, it will be stringified through JSON.stringify().

logDebug void

Description
1
logdebug(arg: any): void

The function creates a void object. The function shows the object through a debug notification to the user that triggered the script.

Parameters

arg

any The value shown to the user inside the notification's body. If the value is an object or array, it will be stringified through JSON.stringify().

The elegere Object

The object elegere initializes Environments, Domains, and Applications objects. These objects perform actions on eLegere applications.

Environment, Domain, and Applications

The Environment, Domain, and Applications functions are functions returning new objects Environment, Domain, and Application as result.

As alternative to the parameters, the context object retrieves information from to the logged User and session.

getEnvironment Promise<Environment>

Description
1
elegere.getEnvironment(url: string, username: string, password: string): Promise<Environment>

The function connects to a eLegere instance by authenticating from the URL using username and password as credentials.

For example:

1
const myEnvironment = elegere.getEnvironment (context.Url, "j.doe@vesenda.com", "S3cretP@ssword")
Parameters

url

string A URL pointing to the eLegere instance.

username

string Username for logging into the eLegere instance.

password

string Password for logging into the eLegere instance.

Return Value

Promise of an Environment object.

getEnvironmentFromToken Promise<Environment>

Description
1
elegere.getEnvironmentFromToken(url: string, sessionToken: string, domainId: string): Promise<Environment>

The function connects to a eLegere instance through the URL. Authentication occurs through two tokens: an already valid session token and the token of the domainId. The function returns an Environment object.

For example:

1
const myEnvironment_fromToken = elegere.getEnvironmentFromToken(context.Url, context.SessionToken, context.DomainId)
Parameters

url

string URL pointing to the eLegere instance.

sessionToken

string Session token of the login. The function uses the session token to authenticate and perform actions in the Environment.

domainId

string A string of random characters identifying the Domain in which the actual session is running.

Return Value

Promise of an Environment object.

getApplication Promise<Application>

1
elegere.getApplication(applicationId: string, domainId: string, url: string, username: string, password: string): Promise<Application>

The function identifies a specific Application of eLegere. Identification works through Application ID and Domain ID after authentication with username and password.

For example:

1
const myApplication = elegere.getApplication(context.ApplicationId, context.DomainId, context.Url, "j.doe@vesenda.com", "S3cretP@ssword")
Parameters

applicationId

string Id of the Application connected to the APIs.

domainId

string Id of the Domain of the Application.

url

string Url pointing to the eLegere instance.

username

string Username that the function employs for logging in.

password

string Password that the function employs for logging in.

Return Value

A Promise for an Application object.

getApplicationFromToken Promise<Application>

1
elegere.getApplicationFromToken(applicationId: string, domainId: string, url: string, sessionToken: string): Promise<Application>

The function identifies a specific Application of eLegere. Identification works through Application ID and Domain ID after authentication through the Session Token.

For example:

1
const myApplication_fromToken = elegere.getApplicationFromToken(context.ApplicationId, context.DomainId, context.Url, context.SessionToken)

Parameters

applicationId

string Id of the Application connected to the APIs.

domainId

string Id of the Domain of the Application.

url

string The Url pointing to the eLegere instance.

sessionToken

string The Session Token that the function employs for logging in.

Return Value

A Promise for an Application object.

HTTP Request Helpers

The Http Request Helpers are functions that process endpoints of APIs.

eLegere scripts also include helper function for making GET/POST http requests to external APIs.

get Promise<any>

1
elegere.get(url: string, config: object): Promise<any>

Performs a GET request to URL supplied.

For example:

1
const randomUser = await elegere.get("https://randomuser.me/api/")
Parameters

url

string The Url to which the function sends the request.

config

object The list of the configuration parameters requested. The parameter includes:

  • "header" It sends a HTTP request including the headers. Each key in the header object stands for the header key. Each value correspond to the value in the header object.
  • "auth" If the user needs authentication through Basic HTTP, it supplies username and password. This parameter overrides any Authorization header.
Return Value

A Promise to wait any sort of Object when ready.

post Promise<any>

1
elegere.post(url: string, data: object, config: config): Promise<any>

Performs a POST request to the URL supplied.

For example:

1
const creationResult = await elegere.post("https://website.that.doesnt.exist/createUser", { firstName: "John", lastName: "Doe})
Parameters

url

string The Url to which the function sends the request.

data

object The data that the functions includes in the request body.

config

object The list of the configuration parameters requested. The parameter includes:

  • "header" It sends a HTTP request including the headers. Each key in the header object stands for the header key. Each value correspond to the value in the header object.
  • "auth" If the user needs authentication through Basic HTTP, it supplies username and password. This parameter overrides any Authorization header.
Return Value

A Promise to wait any sort of Object when ready.


Date Time Converters

Date functions simplify the conversion from standard formats to eLegere date format.

Users can find the required offset in milliseconds through the context TimezoneMSOffset object.

datetimeToNumber number

1
elegere.datetimeToNumber(javascriptDate: Date): number

Converts a JavaScript date to a 14-digit eLegere date.

An Example:

1
2
3
    const javascriptDate = new Date(); // Creates a date indicating the current time.

    const elegereDate = elegere.datetimeToNumber(javascriptDate); // elegereDate is 20220429113122
Parameters

date

Date The original JavaScript date that the function takes.

Return Value

The function yields the original date in the 14-digit eLegere format.

numberToDatetime Date

1
elegere.numberToDatetime(elegereDate: number): Date

Converts the 14-digit eLegere date into a JavaScript date.

An Example:

1
2
3
    const elegereDate = 20060709180000; // eLegere date indicating a date in the past

    const javascriptDate = elegere.numberToDatetime(elegereDate); // the javascript date can be used to communicate with other APIs
Parameters

elegereDate

number The date in eLegere format that the function converts in JavaScript date format.

Return Value

The function yields the date in JavaScript format.

NumberEstToUtc number

1
elegere.NumberEstToUtc(elegereDate: number; timezoneOffset: number): number

The function converts eLegere Eastern Standard Time date in custom format (14-digits) to UTC time zone.

For example:

1
const elegereDatetime_inUtc = elegere.numberEstToUtc(20220425120000, context.MsTimezoneOffset)
Parameters

elegereDate

number The Est date in eLegere custom format (14-digits) that the function converts in UTC date format.

timezoneOffset

number The millisecond offset value of the source time zone.

Return Value

The function yields the eLegere date in UTC time zone.

NumberUtcToEst Date

1
elegere.NumberUtcToEst(elegereDate: number, timezoneOffset: number): Date

The function converts eLegere UTC date in custom format (14-digits) to Est time zone.

For example:

1
const elegereDatetime_inEst = elegere.numberUtcToEst(20220425100000, context.MsTimezoneOffset)
Parameters

elegereDate

number The Est date in eLegere custom format (14-digits) that the function converts in Est date format.

timezoneOffset

number The millisecond offset value of the source time zone.

Return value

The function yields the eLegere date in Est time zone.

datetimeEstToUtc Date

1
elegere.datetimeEstToUtc(javascriptDate: Date, timezoneOffset: number): Date

The function converts a Est JavaScript date format in UTC time zone. The function considers the source time zone's milliseconds offset.

For example:

1
const javascriptDate_inUtc = elegere.datetimeEstToUtc(new Date(), context.MsTimezoneOffset)
Parameters

date

Date The original JavaScript date that the function takes for conversion.

timezoneOffset

number The millisecond offset value of the source time zone.

Return Value

The function yields the eLegere date in UTC time zone format.

dateTimeUTCtoEst Date

1
elegere.dateTimeUTCtoEst(javascriptDate: Date, timezoneOffset: number): Date

The function converts a UTC JavaScript date format in Est time zone. The function considers the source time zone's milliseconds offset.

For example:

1
const javascriptDate_inEst = elegere.datetimeUtcToEst(new Date(), context.MsTimezoneOffset)
Parameters

date

number The JavaScript date that the function takes for conversion.

timezoneOffset

number The millisecond offset value of the source time zone.

Return Value

The function yields the JavaScript date in Est time zone.