Context in edge extension modules

All library modules in edge extensions are provided a context object when they are executed. This document covers the properties provided by the context object and the role they play in library modules.

Adobe Request Context (arc)

The arc property is an object that provides information about the event triggering the rule. The sections below cover the various sub-properties contained in this object.

event

The event object represents the event that triggered the rule. event contains a single property, rule, which itself contains the following values:

logger.log(context.arc.event);
Property Description
rule.xdm The XDM object of the event.
rule.data The custom data layer.

request

Not to be confused with a request from the client device, request is a slightly modified object that comes from Adobe Experience Platform Edge Network.

logger.log(context.arc.request)

The request object has two top-level properties: body and head. The body property contains Experience Data Model (XDM) information and can be inspected in Adobe Experience Platform Debugger when you navigate to Launch and select the Edge Trace tab.

ruleStash

ruleStash is an object that will collect every result from action modules.

logger.log(context.arc.ruleStash);

Each extension has its own namespace. For example, if your extension has the name send-beacon, all results from send-beacon actions will be stored on the ruleStash['send-beacon'] namespace.

The namespace is unique for each extension, and has a value of undefined at the beginning.

The namespace is overridden with the returned result from each action. For example, consider a transform extension containing two actions: generate-fullname and generate-fulladdress. These two actions are then added to a rule.

If the result of the generate-fullname action is Firstname Lastname, then the rule stash will appear as follows after the action is completed:

{
  transform: 'Firstname Lastname'
}

If the result of the generate-address action is 3900 Adobe Way, then the rule stash will appear as follows after the action is completed:

{
  transform: '3900 Adobe Way'
}

Notice that “Firstname Lastname” no longer exists within the rule stash, because the generate-address action overrode it with a new value.

If you want ruleStash to store the results from both actions inside the transform namespace, you can write your action module similar to the following example:

module.exports = (context) => {
  let transformRuleStash = context.arc.ruleStash.transform;

  if (!transformRuleStash) {
    transformRuleStash = {};
  }

  transformRuleStash.fullName = 'Firstname Lastname';

  return transformRuleStash;
}

The first time this action is executed, ruleStash starts as undefined and is therefore initialized as an empty object. The next time when the action is executed, it receives ruleStash that was returned when the action was previously called. Using an object as ruleStash allows you to add new data without losing data previously set by other actions from our extension.

You must be careful to always return the full extension rule stash when using this strategy. If you were to return only a value instead, it will overwrite any other properties you may have set.

Utilities

The utils property represents an object that provides utilities specific to the Platform Launch runtime.

logger

The logger utility allows you to log messages that will be shown during debugging sessions when using Adobe Experience Cloud Debugger.

context.utils.logger.error('Error!');

The logger has the following methods, where message is the message you want to log:

Method Description
log(message) Logs a message to the console.
info(message) Logs an informational message to the console.
warn(message) Logs a warning message to the console.
error(message) Logs an error message to the console.
debug(message) Logs a debug message to the console. This is visible only when verbose logging is enabled within your browser console.

fetch

This utility implements the Fetch API. You can use the function to make requests to third-party endpoints.

context.utils.fetch('http://example.com/movies.json')
  .then(response => response.json())

getBuildInfo

This utility returns an object containing information about the build of the current Platform Launch runtime library.

logger.log(context.utils.getBuildInfo().turbineBuildDate);

The object contains the following values:

Property Description
turbineVersion The Turbine version used inside the current library.
turbineBuildDate The ISO 8601 date when the version of Turbine used inside the container was built.
buildDate The ISO 8601 date when the current library was built.
environment The environment for which this library was built. Possible values include development, staging, and production.

The following is an example getBuildInfo object to demonstrate the values it returns:

{
  turbineVersion: "1.0.0",
  turbineBuildDate: "2016-07-01T18:10:34Z",
  buildDate: "2016-03-30T16:27:10Z",
  environment: "development"
}

getExtensionSettings

This utility returns the settings object that was last saved from the extension configuration view.

logger.log(context.utils.getExtensionSettings());

getSettings

This utility returns the settings object that was last saved from the corresponding library module view.

logger.log(context.utils.getSettings());

getRule

This utility returns an object containing information about the rule that is triggering the module.

logger.log(context.utils.getRule());

The object will contain the following values:

Property Description
id The rule ID.
name The rule name.

On this page

Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now
Adobe Maker Awards Banner

Time to shine!

Apply now for the 2021 Adobe Experience Maker Awards.

Apply now