React Storefront
|

Sandbox Properties

During processing of requests served by the Moovweb XDN, user code has read and write access to sandbox global which contains different properties injected there by Moovweb XDN. Properties are objects, values and functions that user code can use to influence the results of the processing.

Global objects

console

This object offers the following JavaScript's console-like methods:

  • trace
  • debug
  • log
  • info
  • warn
  • error
  • time
  • timeEnd

The output is not written into any console but rather to an internal array which can be accessed by invoking moovGetLogs function. Each log line has a format of [UTC ISO timestamp] [log level] [request or response] [message].

process

This object sandboxes access to NodeJS's process object. At the moment it only offers env.NODE_ENV value.

Global variables

  • debugEnabled: flag indicating if the user code is running in production; it is always set to true when running in cloud and always set to false when running in CLI
  • rawHeaders: raw HTTP headers of either request or response, depending on the phase
  • requestRawHeaders: raw HTTP headers of the request, available during the response phase
  • body: UTF-8 string of either request or response body, depending on the phase; best-effort converted from rawBody
  • rawBody: binary request or response body, depending on the phase
  • requestBody: UTF-8 string of response body; only available during the response phase; best-effort converted from requestRawBody
  • rawBody: binary request body; only available during the response phase
  • moovModeVersion: string with the version of the mode of the user code
  • moovErrorHtml: an HTML template set by user code if it desires to customize error pages; MoovJS will replace values for request ID (##RID##), error (##ERROR##), URL (##URL##) and stack trace (##STACK_TRACE##)

Functions

Note that all outstanding asynchronous actions and times are cancelled once the request is finished processing.

  • moovGetLogs: returns an array of log strings that were created by using console methods.
  • clearImmediate: cancels the action specified by setImmediate
  • clearInterval: cancels the timer created by setInterval
  • clearTimeout: cancels the timer created by setTimeout
  • setImmediate: sets an action for immediate asynchronous execution
  • setInterval: sets a timer for repeated asynchronous execution
  • setTimeout: sets a timer for one time asynchronous execution
  • moovUseAsyncTransformer: signals to MoovJS that asynchronous response transformation will be used
  • moovSendAsyncResponse: sends asynchronous response result
  • moovSkipUpstream: signals to MoovJS to skip going upstream on its own; used only when all the data comes from manual fetches or the responses are synthetic