@repobit/dex-launch
v3.0.0
Published
Client for Adobe Launch
Downloads
1,725
Readme
@repobit/dex-launch
Adobe Launch Loader
Adobe Launch Loader is a lightweight utility that simplifies the process of dynamically loading Adobe Launch scripts based on a specified environment. It leverages constants and script-loading functions from the dex-utils package to construct the correct URL for the Adobe Launch script and then load it asynchronously into your application.
Overview
The Adobe Launch Loader provides a single abstract class with a static method to load the Adobe Launch script. By specifying an environment (such as 'prod', 'stage', or 'dev'), the loader builds the script URL using predefined constants and loads the script into the document. This enables seamless integration with Adobe Launch without hardcoding script URLs in your code.
Key Features
Dynamic Script Loading:
Automatically builds and loads the Adobe Launch script URL based on the given environment.Environment Flexibility:
Supports multiple environments through a mapping of environment keys to script paths.Asynchronous Operation:
Uses asynchronous loading, ensuring that your application can continue operating while the script is being loaded.Easy Integration:
Requires minimal configuration and integrates seamlessly with your existing project using the dex-utils package.
Installation
npm install @repobit/dex-launchLaunch Class
Type: Abstract Class
Static Methods:
load(environment: string): Promise
- Description: Constructs the Adobe Launch script URL based on the provided environment and asynchronously loads the script using the loadScript utility from dex-utils.
- Parameters: environment: string – The current environment (e.g., 'prod', 'stage', or 'dev').
- Return Type:
Returns a
Promise<void>which resolves when the script has been successfully loaded.
Use Case:
Call this method during your application initialization to dynamically load the Adobe Launch script appropriate for your environment. This approach helps keep your configuration dynamic and decoupled from your codebase.
Usage Example
Below is an example of how to use the Adobe Launch Loader in your application:
import Launch from '@repobit/dex-launch';
// Load the Adobe Launch script for the production environment
await Launch.load('prod');
// After loading, the Adobe Launch script is available for use in your application.If one wishes to use both Launch and Target in the same project, I recommend using a structure similar to the one below:
import Launch from '@repobit/dex-launch';
import Target from '@repobit/dex-target';
const target = new Target();
try {
await Launch.load('prod');
} catch (e) {
Target.abort();
}Since Target is dependent on Launch, it is better to Abort all Target operations when we are sure that Launch will not load.
