Libraries
A library is used to organize code. Standard packages (and test packages) can use libraries, and a single library can be used by multiple packages to promote code reuse.
There are three types of libraries:
- Standard library - for functions that are used by more than one package.
- Environment library - for configuration settings that are specific to one environment (e.g. sandbox or production)
- Test library - for test data or mocks, as explained in Testing.
Although the organization of code in packages and libraries is not strictly enforced, as a best practice, standard libraries should only contain functions, and environment libraries should only contain configuration settings, typically collected in a single object, for example:
const CALENDARIFIC_SETTINGS = {
countryCode: 'AT',
year: moment().add(1, "year").year(),
maxNrOfHolidays: 100,
// ...
}
The object is then referred to from the package that uses the environment library.
Since configuration settings are typically specific to one environment, the transfer assistant only allows you to transfer an environment library when it does not yet exist in the target environment.
During execution of a (standard) package, the script of the package itself is combined will the scripts of all the
libraries it uses. That means that the AutomatorScript does not support the import and export keywords that are
available in standard JavaScript, because there is no need for them. All functions of all libraries are available to the
main package at runtime, and library functions can also call each other.